5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-12-23 12:15:39 +00:00

* only enable tor proxy dialer when tor is enabled

* add docstrings
This commit is contained in:
Jeff Becker 2018-04-25 10:06:13 -04:00
parent c16e354a44
commit de69860e9b
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

View File

@ -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
}
}