github.com/anacrolix/torrent@v1.61.0/dialer/dialer.go (about) 1 package dialer 2 3 import ( 4 "context" 5 "net" 6 ) 7 8 // Dialers have the network locked in. 9 type T interface { 10 Dial(_ context.Context, addr string) (net.Conn, error) 11 DialerNetwork() string 12 } 13 14 // An interface to ease wrapping dialers that explicitly include a network parameter. 15 type WithContext interface { 16 DialContext(ctx context.Context, network, addr string) (net.Conn, error) 17 } 18 19 // Used by wrappers of standard library network types. 20 var Default = &net.Dialer{} 21 22 // Adapts a WithContext to the Dial interface in this package. 23 type WithNetwork struct { 24 Network string 25 Dialer WithContext 26 } 27 28 func (me WithNetwork) DialerNetwork() string { 29 return me.Network 30 } 31 32 func (me WithNetwork) Dial(ctx context.Context, addr string) (_ net.Conn, err error) { 33 return me.Dialer.DialContext(ctx, me.Network, addr) 34 }