mirror of
https://github.com/SamTherapy/dnscrypt.git
synced 2024-12-22 17:00:43 +00:00
5ddb58f703
Graceful shutdown of the DNSCrypt server This PR implements Server.Shutdown(ctx context.Context) method that allows to shut down the DNSCrypt server gracefully. Some additional changes that were inadvertently made while doing that: 1. Added benchmark tests 2. Started using dns.ReadFromSessionUDP / dns.WriteToSessionUDP instead of implementing it by ourselves 3. Generally improved tests 4. Added depguard 5. Improved comments overall in the code
53 lines
1.6 KiB
Go
53 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/AdguardTeam/golibs/log"
|
|
goFlags "github.com/jessevdk/go-flags"
|
|
)
|
|
|
|
// Options - command-line options
|
|
type Options struct {
|
|
Generate GenerateArgs `command:"generate" description:"Generates DNSCrypt server configuration"`
|
|
LookupStamp LookupStampArgs `command:"lookup-stamp" description:"Performs a DNSCrypt lookup for the specified domain using an sdns:// stamp"`
|
|
Lookup LookupArgs `command:"lookup" description:"Performs a DNSCrypt lookup for the specified domain"`
|
|
Server ServerArgs `command:"server" description:"Runs a DNSCrypt resolver"`
|
|
ConvertWrapper ConvertWrapperArgs `command:"convert-dnscrypt-wrapper" description:"Converting keys generated with dnscrypt-wrapper to yaml config"`
|
|
Version struct {
|
|
} `command:"version" description:"Prints version"`
|
|
}
|
|
|
|
// VersionString will be set through ldflags, contains current version
|
|
var VersionString = "1.0"
|
|
|
|
func main() {
|
|
var opts Options
|
|
|
|
var parser = goFlags.NewParser(&opts, goFlags.Default)
|
|
_, err := parser.Parse()
|
|
if err != nil {
|
|
if flagsErr, ok := err.(*goFlags.Error); ok && flagsErr.Type == goFlags.ErrHelp {
|
|
os.Exit(0)
|
|
} else {
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
switch parser.Active.Name {
|
|
case "version":
|
|
log.Printf("dnscrypt version %s\n", VersionString)
|
|
case "generate":
|
|
generate(opts.Generate)
|
|
case "lookup-stamp":
|
|
lookupStamp(opts.LookupStamp)
|
|
case "lookup":
|
|
lookup(opts.Lookup)
|
|
case "server":
|
|
server(opts.Server)
|
|
case "convert-dnscrypt-wrapper":
|
|
convertWrapper(opts.ConvertWrapper)
|
|
default:
|
|
log.Fatalf("unknown command %s", parser.Active.Name)
|
|
}
|
|
}
|