mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	* only enable tor proxy dialer when tor is enabled
* add docstrings
This commit is contained in:
		
							parent
							
								
									c16e354a44
								
							
						
					
					
						commit
						de69860e9b
					
				
					 1 changed files with 13 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -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 {
 | 
			
		||||
	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
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue