From 06381579e506922416d653ce40bae78aa6f9f563 Mon Sep 17 00:00:00 2001 From: erinn Date: Sun, 7 Oct 2018 19:31:32 -0700 Subject: [PATCH 1/2] 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 From a6ca1571ad97d9b608977d69a517424b21bc25a5 Mon Sep 17 00:00:00 2001 From: erinn Date: Sun, 7 Oct 2018 19:43:55 -0700 Subject: [PATCH 2/2] gofmt --- utils/networkresolver.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/networkresolver.go b/utils/networkresolver.go index 69b4f8e..90aefe5 100644 --- a/utils/networkresolver.go +++ b/utils/networkresolver.go @@ -1,10 +1,10 @@ package utils import ( + "github.com/yawning/bulb" "golang.org/x/net/proxy" "net" "strings" - "github.com/yawning/bulb" ) const ( @@ -76,4 +76,4 @@ func NewNym(torControlAddress string, torControlSocketType string, authenticatio _, err = c.Request("SIGNAL NEWNYM") return err -} \ No newline at end of file +}