Back to 2.0.29 beta 3 (ceed905196)

This commit is contained in:
Frank Denis 2019-10-31 17:49:48 +01:00
parent fb1fc14317
commit 3a68f90c37
9 changed files with 118 additions and 172 deletions

View file

@ -7,7 +7,6 @@ import (
"fmt"
"math/rand"
"os"
"os/signal"
"sync"
"github.com/facebookgo/pidfile"
@ -16,7 +15,7 @@ import (
)
const (
AppVersion = "2.0.31"
AppVersion = "2.0.29-beta.3"
DefaultConfigFileName = "dnscrypt-proxy.toml"
)
@ -24,7 +23,6 @@ type App struct {
wg sync.WaitGroup
quit chan struct{}
proxy *Proxy
flags *ConfigFlags
}
func main() {
@ -46,33 +44,7 @@ func main() {
WorkingDirectory: pwd,
}
svcFlag := flag.String("service", "", fmt.Sprintf("Control the system service: %q", service.ControlAction))
version := flag.Bool("version", false, "print current proxy version")
resolve := flag.String("resolve", "", "resolve a name using system libraries")
flags := ConfigFlags{}
flags.List = flag.Bool("list", false, "print the list of available resolvers for the enabled filters")
flags.ListAll = flag.Bool("list-all", false, "print the complete list of available resolvers, ignoring filters")
flags.JsonOutput = flag.Bool("json", false, "output list as JSON")
flags.Check = flag.Bool("check", false, "check the configuration file and exit")
flags.ConfigFile = flag.String("config", DefaultConfigFileName, "Path to the configuration file")
flags.Child = flag.Bool("child", false, "Invokes program as a child process")
flags.NetprobeTimeoutOverride = flag.Int("netprobe-timeout", 60, "Override the netprobe timeout")
flags.ShowCerts = flag.Bool("show-certs", false, "print DoH certificate chain hashes")
flag.Parse()
if *version {
fmt.Println(AppVersion)
os.Exit(0)
}
if resolve != nil && len(*resolve) > 0 {
Resolve(*resolve)
os.Exit(0)
}
app := &App{
quit: make(chan struct{}),
flags: &flags,
}
app := &App{}
svc, err := service.New(app, svcConfig)
if err != nil {
svc = nil
@ -80,6 +52,9 @@ func main() {
}
app.proxy = NewProxy()
_ = ServiceManagerStartNotify()
if err := ConfigLoad(app.proxy, svcFlag); err != nil {
dlog.Fatal(err)
}
if len(*svcFlag) != 0 {
if svc == nil {
dlog.Fatal("Built-in service installation is not supported on this platform")
@ -100,56 +75,43 @@ func main() {
}
return
}
app.wg.Add(1)
if svc != nil {
if err = svc.Run(); err != nil {
dlog.Fatal(err)
}
} else {
if err := ConfigLoad(app.proxy, &flags); err != nil {
dlog.Fatal(err)
}
app.signalWatch()
app.Start(nil)
}
app.wg.Wait()
dlog.Notice("Stopped.")
}
func (app *App) Start(service service.Service) error {
go func() {
if err := ConfigLoad(app.proxy, app.flags); err != nil {
dlog.Fatal(err)
}
if err := app.proxy.InitPluginsGlobals(); err != nil {
dlog.Fatal(err)
}
app.appMain()
}()
if err := app.proxy.InitPluginsGlobals(); err != nil {
dlog.Fatal(err)
}
app.quit = make(chan struct{})
app.wg.Add(1)
if service != nil {
go func() {
app.AppMain()
}()
} else {
app.AppMain()
}
return nil
}
func (app *App) AppMain() {
pidfile.Write()
app.proxy.StartProxy()
<-app.quit
dlog.Notice("Quit signal received...")
app.wg.Done()
}
func (app *App) Stop(service service.Service) error {
if pidFilePath := pidfile.GetPidfilePath(); len(pidFilePath) > 1 {
os.Remove(pidFilePath)
}
dlog.Notice("Quit signal received...")
close(app.quit)
dlog.Notice("Stopped.")
return nil
}
func (app *App) appMain() {
pidfile.Write()
app.proxy.StartProxy(app.quit)
app.wg.Done()
}
func (app *App) signalWatch() {
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt, os.Kill)
go func() {
<-quit
signal.Stop(quit)
close(app.quit)
}()
}