-
-
Notifications
You must be signed in to change notification settings - Fork 634
/
Copy pathdialer.go
45 lines (35 loc) · 854 Bytes
/
dialer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package torrent
import (
"context"
"net"
"github.com/anacrolix/missinggo/perf"
)
type Dialer interface {
Dial(_ context.Context, addr string) (net.Conn, error)
DialerNetwork() string
}
type NetDialer struct {
Network string
Dialer net.Dialer
}
func (me NetDialer) DialerNetwork() string {
return me.Network
}
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 }
func (me netDialerLocalAddr) String() string {
if me.addr == nil {
return ""
}
return me.addr.String()
}