diff options
Diffstat (limited to 'vendor/github.com/hashicorp/yamux/addr.go')
-rw-r--r-- | vendor/github.com/hashicorp/yamux/addr.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/yamux/addr.go b/vendor/github.com/hashicorp/yamux/addr.go new file mode 100644 index 0000000..be6ebca --- /dev/null +++ b/vendor/github.com/hashicorp/yamux/addr.go | |||
@@ -0,0 +1,60 @@ | |||
1 | package yamux | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | "net" | ||
6 | ) | ||
7 | |||
8 | // hasAddr is used to get the address from the underlying connection | ||
9 | type hasAddr interface { | ||
10 | LocalAddr() net.Addr | ||
11 | RemoteAddr() net.Addr | ||
12 | } | ||
13 | |||
14 | // yamuxAddr is used when we cannot get the underlying address | ||
15 | type yamuxAddr struct { | ||
16 | Addr string | ||
17 | } | ||
18 | |||
19 | func (*yamuxAddr) Network() string { | ||
20 | return "yamux" | ||
21 | } | ||
22 | |||
23 | func (y *yamuxAddr) String() string { | ||
24 | return fmt.Sprintf("yamux:%s", y.Addr) | ||
25 | } | ||
26 | |||
27 | // Addr is used to get the address of the listener. | ||
28 | func (s *Session) Addr() net.Addr { | ||
29 | return s.LocalAddr() | ||
30 | } | ||
31 | |||
32 | // LocalAddr is used to get the local address of the | ||
33 | // underlying connection. | ||
34 | func (s *Session) LocalAddr() net.Addr { | ||
35 | addr, ok := s.conn.(hasAddr) | ||
36 | if !ok { | ||
37 | return &yamuxAddr{"local"} | ||
38 | } | ||
39 | return addr.LocalAddr() | ||
40 | } | ||
41 | |||
42 | // RemoteAddr is used to get the address of remote end | ||
43 | // of the underlying connection | ||
44 | func (s *Session) RemoteAddr() net.Addr { | ||
45 | addr, ok := s.conn.(hasAddr) | ||
46 | if !ok { | ||
47 | return &yamuxAddr{"remote"} | ||
48 | } | ||
49 | return addr.RemoteAddr() | ||
50 | } | ||
51 | |||
52 | // LocalAddr returns the local address | ||
53 | func (s *Stream) LocalAddr() net.Addr { | ||
54 | return s.session.LocalAddr() | ||
55 | } | ||
56 | |||
57 | // LocalAddr returns the remote address | ||
58 | func (s *Stream) RemoteAddr() net.Addr { | ||
59 | return s.session.RemoteAddr() | ||
60 | } | ||