From 1d0ec2a110269f1f33a1342ca99438b5635b34af Mon Sep 17 00:00:00 2001 From: idk Date: Tue, 25 Dec 2018 20:12:10 -0500 Subject: [PATCH] update some dialer stuff --- Makefile | 1 + conn/conn.go | 12 +++++++++++- socks/manager.go | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f67e66f..4866319 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,7 @@ clean: deps: go get -u github.com/eyedeekay/eeproxy + go get -u github.com/eyedeekay/go-socks5 test: mkdir -p testdir && cd testdir && \ diff --git a/conn/conn.go b/conn/conn.go index 3119331..42abc5d 100644 --- a/conn/conn.go +++ b/conn/conn.go @@ -2,6 +2,7 @@ package conn import ( "bufio" + "math/rand" "os" "path/filepath" ) @@ -97,7 +98,7 @@ func NewConn(sam *sam3.SAM, addr, path string, opts []string) (*Conn, error) { if err != nil { return nil, err } - c.StreamSession, err = sam.NewStreamSession(c.I2PKeys.Addr().Base32()[0:10], c.I2PKeys, opts) + c.StreamSession, err = sam.NewStreamSession(c.I2PKeys.Addr().Base32()[0:10]+RandTunName(), c.I2PKeys, opts) if err != nil { return nil, err } @@ -111,3 +112,12 @@ func NewConn(sam *sam3.SAM, addr, path string, opts []string) (*Conn, error) { } return &c, nil } + +// RandTunName generates a random tunnel names to avoid collisions +func RandTunName() string { + b := make([]byte, 12) + for i := range b { + b[i] = "abcdefghijklmnopqrstuvwxyz"[rand.Intn(len("abcdefghijklmnopqrstuvwxyz"))] + } + return string(b) +} diff --git a/socks/manager.go b/socks/manager.go index 7fa090e..6281b4d 100644 --- a/socks/manager.go +++ b/socks/manager.go @@ -59,6 +59,7 @@ func (m Manager) DialI2P(ctx context.Context, addr string) (*sam3.SAMConn, error } func (m Manager) Dial(ctx context.Context, network, addr string) (net.Conn, error) { + log.Println("Dialing:", network, addr) return m.DialI2P(ctx, addr) }