-
Notifications
You must be signed in to change notification settings - Fork 3
/
warp.go
58 lines (47 loc) · 1018 Bytes
/
warp.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
46
47
48
49
50
51
52
53
54
55
56
57
58
package sshproxy
import (
"net"
)
func connWithCloser(conn net.Conn, closer func() error) net.Conn {
return &connCloser{Conn: conn, closer: closer}
}
type connCloser struct {
net.Conn
closer func() error
}
func (w *connCloser) Close() error {
return w.closer()
}
func connWithAddr(conn net.Conn, localAddr, remoteAddr net.Addr) net.Conn {
return &connAddr{Conn: conn, localAddr: localAddr, remoteAddr: remoteAddr}
}
type connAddr struct {
net.Conn
localAddr net.Addr
remoteAddr net.Addr
}
func (w *connAddr) LocalAddr() net.Addr {
if w.localAddr == nil {
return w.Conn.LocalAddr()
}
return w.localAddr
}
func (w *connAddr) RemoteAddr() net.Addr {
if w.remoteAddr == nil {
return w.Conn.RemoteAddr()
}
return w.remoteAddr
}
func newNetAddr(network, address string) net.Addr {
return &addr{network: network, address: address}
}
type addr struct {
network string
address string
}
func (a *addr) Network() string {
return a.network
}
func (a *addr) String() string {
return a.address
}