From de69860e9bb1a5e9a6fd65b5a55e7cf2a381a081 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Wed, 25 Apr 2018 10:06:13 -0400 Subject: [PATCH] * only enable tor proxy dialer when tor is enabled * add docstrings --- src/yggdrasil/dial.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/yggdrasil/dial.go b/src/yggdrasil/dial.go index d9249a6..5269c16 100644 --- a/src/yggdrasil/dial.go +++ b/src/yggdrasil/dial.go @@ -11,17 +11,20 @@ import ( type Dialer = proxy.Dialer +// muxedDialer implements proxy.Dialer (aka Dialer) type muxedDialer struct { conf config.NetConfig tor Dialer direct Dialer } +// wrappedConn implements net.Conn type wrappedConn struct { c net.Conn raddr net.Addr } +// wrappedAddr implements net.Addr type wrappedAddr struct { network string addr string @@ -89,11 +92,16 @@ func (d *muxedDialer) Dial(network, addr string) (net.Conn, error) { } } +// NewDialer creates a Dialer from a NetConfig func NewDialer(c config.NetConfig) Dialer { - tor, _ := proxy.SOCKS5("tcp", c.Tor.SocksAddr, nil, proxy.Direct) - return &muxedDialer{ - conf: c, - tor: tor, - direct: proxy.Direct, + if c.Tor.Enabled { + tor, _ := proxy.SOCKS5("tcp", c.Tor.SocksAddr, nil, proxy.Direct) + return &muxedDialer{ + conf: c, + tor: tor, + direct: proxy.Direct, + } + } else { + return proxy.Direct } }