]> Sergey Matveev's repositories - btrtrc.git/blobdiff - dialer.go
Drop support for go 1.20
[btrtrc.git] / dialer.go
index 32ab91f704198289e6a263e2036071456d421824..5cdf3fccac52230ae06f5c8e03701a2b0df35dde 100644 (file)
--- a/dialer.go
+++ b/dialer.go
@@ -1,45 +1,12 @@
 package torrent
 
 import (
-       "context"
-       "net"
-
-       "github.com/anacrolix/missinggo/perf"
+       "github.com/anacrolix/torrent/dialer"
 )
 
-type Dialer interface {
-       // The network is implied by the instance.
-       Dial(_ context.Context, addr string) (net.Conn, error)
-       // This is required for registering with the connection tracker (router connection table
-       // emulating rate-limiter) before dialing. TODO: What about connections that wouldn't infringe
-       // on routers, like localhost or unix sockets.
-       LocalAddr() net.Addr
-}
-
-type NetDialer struct {
-       Network string
-       Dialer  net.Dialer
-}
-
-func (me NetDialer) Dial(ctx context.Context, addr string) (_ net.Conn, err error) {
-       defer perf.ScopeTimerErr(&err)()
-       return me.Dialer.DialContext(ctx, me.Network, addr)
-}
-
-func (me NetDialer) LocalAddr() net.Addr {
-       return netDialerLocalAddr{me.Network, me.Dialer.LocalAddr}
-}
-
-type netDialerLocalAddr struct {
-       network string
-       addr    net.Addr
-}
-
-func (me netDialerLocalAddr) Network() string { return me.network }
+type (
+       Dialer        = dialer.T
+       NetworkDialer = dialer.WithNetwork
+)
 
-func (me netDialerLocalAddr) String() string {
-       if me.addr == nil {
-               return ""
-       }
-       return me.addr.String()
-}
+var DefaultNetDialer = &dialer.Default