5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-10 06:20:26 +00:00

avoid the proxy.SOCK5 connection attempt unless we're actually going to use the dialer

This commit is contained in:
Arceliar 2018-06-14 09:21:35 -05:00
parent e8eaabf0c8
commit d9c9787611

View File

@ -65,13 +65,7 @@ func (iface *tcpInterface) connect(addr string) {
// Attempst to initiate a connection to the provided address, viathe provided socks proxy address. // Attempst to initiate a connection to the provided address, viathe provided socks proxy address.
func (iface *tcpInterface) connectSOCKS(socksaddr, peeraddr string) { func (iface *tcpInterface) connectSOCKS(socksaddr, peeraddr string) {
go func() { iface.call(peeraddr, &socksaddr)
dialer, err := proxy.SOCKS5("tcp", socksaddr, nil, proxy.Direct)
if err != nil {
return
}
iface.call(peeraddr, dialer)
}()
} }
// Initializes the struct. // Initializes the struct.
@ -106,7 +100,7 @@ func (iface *tcpInterface) listener() {
// If the dial is successful, it launches the handler. // If the dial is successful, it launches the handler.
// When finished, it removes the outgoing call, so reconnection attempts can be made later. // When finished, it removes the outgoing call, so reconnection attempts can be made later.
// This all happens in a separate goroutine that it spawns. // This all happens in a separate goroutine that it spawns.
func (iface *tcpInterface) call(saddr string, dialer proxy.Dialer) { func (iface *tcpInterface) call(saddr string, socksaddr *string) {
go func() { go func() {
quit := false quit := false
iface.mutex.Lock() iface.mutex.Lock()
@ -126,7 +120,12 @@ func (iface *tcpInterface) call(saddr string, dialer proxy.Dialer) {
} }
var conn net.Conn var conn net.Conn
var err error var err error
if dialer != nil { if socksaddr != nil {
var dialer proxy.Dialer
dialer, err = proxy.SOCKS5("tcp", *socksaddr, nil, proxy.Direct)
if err != nil {
return
}
conn, err = dialer.Dial("tcp", saddr) conn, err = dialer.Dial("tcp", saddr)
if err != nil { if err != nil {
return return