mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-26 07:11:40 +00:00
* only enable tor proxy dialer when tor is enabled
* add docstrings
This commit is contained in:
parent
c16e354a44
commit
de69860e9b
@ -11,17 +11,20 @@ import (
|
|||||||
|
|
||||||
type Dialer = proxy.Dialer
|
type Dialer = proxy.Dialer
|
||||||
|
|
||||||
|
// muxedDialer implements proxy.Dialer (aka Dialer)
|
||||||
type muxedDialer struct {
|
type muxedDialer struct {
|
||||||
conf config.NetConfig
|
conf config.NetConfig
|
||||||
tor Dialer
|
tor Dialer
|
||||||
direct Dialer
|
direct Dialer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// wrappedConn implements net.Conn
|
||||||
type wrappedConn struct {
|
type wrappedConn struct {
|
||||||
c net.Conn
|
c net.Conn
|
||||||
raddr net.Addr
|
raddr net.Addr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// wrappedAddr implements net.Addr
|
||||||
type wrappedAddr struct {
|
type wrappedAddr struct {
|
||||||
network string
|
network string
|
||||||
addr 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 {
|
func NewDialer(c config.NetConfig) Dialer {
|
||||||
|
if c.Tor.Enabled {
|
||||||
tor, _ := proxy.SOCKS5("tcp", c.Tor.SocksAddr, nil, proxy.Direct)
|
tor, _ := proxy.SOCKS5("tcp", c.Tor.SocksAddr, nil, proxy.Direct)
|
||||||
return &muxedDialer{
|
return &muxedDialer{
|
||||||
conf: c,
|
conf: c,
|
||||||
tor: tor,
|
tor: tor,
|
||||||
direct: proxy.Direct,
|
direct: proxy.Direct,
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return proxy.Direct
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user