From 06381579e506922416d653ce40bae78aa6f9f563 Mon Sep 17 00:00:00 2001 From: erinn Date: Sun, 7 Oct 2018 19:31:32 -0700 Subject: [PATCH] after failing a new connection, flush the onion descriptor cache and try again in case the destination has cycled since its last use --- utils/networkresolver.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/utils/networkresolver.go b/utils/networkresolver.go index ae527ff..69b4f8e 100644 --- a/utils/networkresolver.go +++ b/utils/networkresolver.go @@ -4,6 +4,7 @@ import ( "golang.org/x/net/proxy" "net" "strings" + "github.com/yawning/bulb" ) const ( @@ -53,8 +54,26 @@ func (nr *NetworkResolver) Resolve(hostname string) (net.Conn, string, error) { conn, err := torDialer.Dial("tcp", resolvedHostname+".onion:9878") if err != nil { - return nil, "", CannotDialRicochetAddressError + NewNym("127.0.0.1:9051", "tcp4", "", 9878) + + return nil, "", err } return conn, resolvedHostname, nil } + +// runs SIGNAL NEWNYM on the tor control port to flush the onion descriptors cache +func NewNym(torControlAddress string, torControlSocketType string, authentication string, onionport uint16) error { + c, err := bulb.Dial(torControlSocketType, torControlAddress) + if err != nil { + return err + } + + err = c.Authenticate(authentication) + if err != nil { + return err + } + + _, err = c.Request("SIGNAL NEWNYM") + return err +} \ No newline at end of file