mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 11:15:07 +03:00 
			
		
		
		
	avoid the proxy.SOCK5 connection attempt unless we're actually going to use the dialer
This commit is contained in:
		
							parent
							
								
									e8eaabf0c8
								
							
						
					
					
						commit
						d9c9787611
					
				
					 1 changed files with 8 additions and 9 deletions
				
			
		| 
						 | 
					@ -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
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue