From ea91db2f5859f1d3b7f52020f4611a13273854e9 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sat, 9 Sep 2017 09:45:45 -0400 Subject: [PATCH] fix stuff up --- contrib/backends/nntpchand/.dir-locals.el | 8 ++++++++ .../nntpchand/src/nntpchan/cmd/nntpchan/main.go | 12 +++++++++++- .../nntpchand/src/nntpchan/lib/config/frontend.go | 8 ++++++++ .../nntpchand/src/nntpchan/lib/frontend/frontend.go | 3 +++ .../nntpchand/src/nntpchan/lib/frontend/http.go | 4 ++++ .../nntpchand/src/nntpchan/lib/network/socks.go | 2 ++ .../nntpchand/src/nntpchan/lib/nntp/conn_v1.go | 4 ++++ 7 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 contrib/backends/nntpchand/.dir-locals.el diff --git a/contrib/backends/nntpchand/.dir-locals.el b/contrib/backends/nntpchand/.dir-locals.el new file mode 100644 index 0000000..9892add --- /dev/null +++ b/contrib/backends/nntpchand/.dir-locals.el @@ -0,0 +1,8 @@ +;; thanks stack overflow +;; https://stackoverflow.com/questions/4012321/how-can-i-access-the-path-to-the-current-directory-in-an-emacs-directory-variabl +((nil . ((eval . (set (make-local-variable 'my-project-path) + (file-name-directory + (let ((d (dir-locals-find-file "."))) + (if (stringp d) d (car d)))))) + (eval . (setenv "GOPATH" my-project-path)) + (eval . (message "Project directory set to `%s'." my-project-path))))) diff --git a/contrib/backends/nntpchand/src/nntpchan/cmd/nntpchan/main.go b/contrib/backends/nntpchand/src/nntpchan/cmd/nntpchan/main.go index adabeff..b6bfc58 100644 --- a/contrib/backends/nntpchand/src/nntpchan/cmd/nntpchan/main.go +++ b/contrib/backends/nntpchand/src/nntpchan/cmd/nntpchan/main.go @@ -95,13 +95,14 @@ func Main() { } nserv.Hooks = hooks } - + var frontends []frontend.Frontend var db database.Database for _, fconf := range conf.Frontends { var f frontend.Frontend f, err = frontend.NewHTTPFrontend(fconf, db) if err == nil { go f.Serve() + frontends = append(frontends, f) } } @@ -121,6 +122,15 @@ func Main() { log.Infof("reloading config: %s", cfgFname) nserv.ReloadServer(conf.NNTP) nserv.ReloadFeeds(conf.Feeds) + for idx := range frontends { + f := frontends[idx] + for i := range conf.Frontends { + c := conf.Frontends[i] + if c != nil && c.Name() == f.Name() { + f.Reload(c) + } + } + } } else { log.Errorf("failed to reload config: %s", err) } diff --git a/contrib/backends/nntpchand/src/nntpchan/lib/config/frontend.go b/contrib/backends/nntpchand/src/nntpchan/lib/config/frontend.go index d100656..c6305e0 100644 --- a/contrib/backends/nntpchand/src/nntpchan/lib/config/frontend.go +++ b/contrib/backends/nntpchand/src/nntpchan/lib/config/frontend.go @@ -1,5 +1,9 @@ package config +import ( + "fmt" +) + type FrontendConfig struct { // bind to address BindAddr string `json:"bind"` @@ -13,6 +17,10 @@ type FrontendConfig struct { Middleware *MiddlewareConfig `json:"middleware"` } +func (cfg *FrontendConfig) Name() string { + return fmt.Sprintf("frontend-%s", cfg.BindAddr) +} + // default Frontend Configuration var DefaultFrontendConfig = FrontendConfig{ BindAddr: "127.0.0.1:18888", diff --git a/contrib/backends/nntpchand/src/nntpchan/lib/frontend/frontend.go b/contrib/backends/nntpchand/src/nntpchan/lib/frontend/frontend.go index 77da159..1967fd0 100644 --- a/contrib/backends/nntpchand/src/nntpchan/lib/frontend/frontend.go +++ b/contrib/backends/nntpchand/src/nntpchan/lib/frontend/frontend.go @@ -27,6 +27,9 @@ type Frontend interface { // reload config Reload(c *config.FrontendConfig) + + // get frontend name + Name() string } // create a new http frontend give frontend config diff --git a/contrib/backends/nntpchand/src/nntpchan/lib/frontend/http.go b/contrib/backends/nntpchand/src/nntpchan/lib/frontend/http.go index 6096911..aaf9fdb 100644 --- a/contrib/backends/nntpchand/src/nntpchan/lib/frontend/http.go +++ b/contrib/backends/nntpchand/src/nntpchan/lib/frontend/http.go @@ -33,6 +33,10 @@ type httpFrontend struct { db database.Database } +func (f *httpFrontend) Name() string { + return fmt.Sprintf("frontend-%s", f.addr) +} + // reload http frontend // reloads middleware func (f *httpFrontend) Reload(c *config.FrontendConfig) { diff --git a/contrib/backends/nntpchand/src/nntpchan/lib/network/socks.go b/contrib/backends/nntpchand/src/nntpchan/lib/network/socks.go index 44b5d4c..a20d6d3 100644 --- a/contrib/backends/nntpchand/src/nntpchan/lib/network/socks.go +++ b/contrib/backends/nntpchand/src/nntpchan/lib/network/socks.go @@ -97,6 +97,7 @@ func (sd *socksDialer) Dial(remote string) (c net.Conn, err error) { }).Warn("connect via socks proxy failed") c.Close() c = nil + err = errors.New("could not connect via socks proxy") } } else { // error reading reply @@ -106,6 +107,7 @@ func (sd *socksDialer) Dial(remote string) (c net.Conn, err error) { }).Error("failed to read socks response ", err) c.Close() c = nil + err = errors.New("socks proxy gave no reply") } } else { if err == nil { diff --git a/contrib/backends/nntpchand/src/nntpchan/lib/nntp/conn_v1.go b/contrib/backends/nntpchand/src/nntpchan/lib/nntp/conn_v1.go index c10181c..a6838ab 100644 --- a/contrib/backends/nntpchand/src/nntpchan/lib/nntp/conn_v1.go +++ b/contrib/backends/nntpchand/src/nntpchan/lib/nntp/conn_v1.go @@ -622,6 +622,10 @@ func (c *v1Conn) printfLine(format string, args ...interface{}) error { } func (c *v1Conn) readline() (line string, err error) { + if c.C == nil || c.C.R == nil { + err = errors.New("connection closed") + return + } line, err = c.C.ReadLine() log.WithFields(log.Fields{ "pkg": "nntp-conn",