From 5bf5fe6c1df80f85078f8c147e9510fe7f8e4b64 Mon Sep 17 00:00:00 2001 From: Markus Linnala Date: Wed, 9 Oct 2019 18:59:46 +0300 Subject: [PATCH] cleanup: main: simplify proxy handling --- dnscrypt-proxy/main.go | 16 +++++++--------- dnscrypt-proxy/plugins.go | 10 +++++----- dnscrypt-proxy/proxy.go | 4 ++-- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/dnscrypt-proxy/main.go b/dnscrypt-proxy/main.go index 23f268a6..eeb8f82e 100644 --- a/dnscrypt-proxy/main.go +++ b/dnscrypt-proxy/main.go @@ -22,7 +22,7 @@ const ( type App struct { wg sync.WaitGroup quit chan struct{} - proxy Proxy + proxy *Proxy } func main() { @@ -52,7 +52,7 @@ func main() { } app.proxy = NewProxy() _ = ServiceManagerStartNotify() - if err := ConfigLoad(&app.proxy, svcFlag); err != nil { + if err := ConfigLoad(app.proxy, svcFlag); err != nil { dlog.Fatal(err) } if len(*svcFlag) != 0 { @@ -85,29 +85,27 @@ func main() { } func (app *App) Start(service service.Service) error { - proxy := &app.proxy - if err := InitPluginsGlobals(&proxy.pluginsGlobals, proxy); err != nil { + 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(proxy) + app.AppMain() }() } else { - app.AppMain(proxy) + app.AppMain() } return nil } -func (app *App) AppMain(proxy *Proxy) { +func (app *App) AppMain() { pidfile.Write() - proxy.StartProxy() + app.proxy.StartProxy() <-app.quit dlog.Notice("Quit signal received...") app.wg.Done() - } func (app *App) Stop(service service.Service) error { diff --git a/dnscrypt-proxy/plugins.go b/dnscrypt-proxy/plugins.go index d6b26fb0..66a0b2cd 100644 --- a/dnscrypt-proxy/plugins.go +++ b/dnscrypt-proxy/plugins.go @@ -82,7 +82,7 @@ type PluginsState struct { serverName string } -func InitPluginsGlobals(pluginsGlobals *PluginsGlobals, proxy *Proxy) error { +func (proxy *Proxy) InitPluginsGlobals() error { queryPlugins := &[]Plugin{} if len(proxy.queryMeta) != 0 { @@ -143,11 +143,11 @@ func InitPluginsGlobals(pluginsGlobals *PluginsGlobals, proxy *Proxy) error { } } - (*pluginsGlobals).queryPlugins = queryPlugins - (*pluginsGlobals).responsePlugins = responsePlugins - (*pluginsGlobals).loggingPlugins = loggingPlugins + proxy.pluginsGlobals.queryPlugins = queryPlugins + proxy.pluginsGlobals.responsePlugins = responsePlugins + proxy.pluginsGlobals.loggingPlugins = loggingPlugins - parseBlockedQueryResponse(proxy.blockedQueryResponse, pluginsGlobals) + parseBlockedQueryResponse(proxy.blockedQueryResponse, &proxy.pluginsGlobals) return nil } diff --git a/dnscrypt-proxy/proxy.go b/dnscrypt-proxy/proxy.go index 4dd4f268..2b111edb 100644 --- a/dnscrypt-proxy/proxy.go +++ b/dnscrypt-proxy/proxy.go @@ -501,8 +501,8 @@ func (proxy *Proxy) processIncomingQuery(serverInfo *ServerInfo, clientProto str pluginsState.ApplyLoggingPlugins(&proxy.pluginsGlobals) } -func NewProxy() Proxy { - return Proxy{ +func NewProxy() *Proxy { + return &Proxy{ serversInfo: NewServersInfo(), } }