8 // hasAddr is used to get the address from the underlying connection
9 type hasAddr interface {
14 // yamuxAddr is used when we cannot get the underlying address
15 type yamuxAddr struct {
19 func (*yamuxAddr) Network() string {
23 func (y *yamuxAddr) String() string {
24 return fmt.Sprintf("yamux:%s", y.Addr)
27 // Addr is used to get the address of the listener.
28 func (s *Session) Addr() net.Addr {
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)
37 return &yamuxAddr{"local"}
39 return addr.LocalAddr()
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)
47 return &yamuxAddr{"remote"}
49 return addr.RemoteAddr()
52 // LocalAddr returns the local address
53 func (s *Stream) LocalAddr() net.Addr {
54 return s.session.LocalAddr()
57 // LocalAddr returns the remote address
58 func (s *Stream) RemoteAddr() net.Addr {
59 return s.session.RemoteAddr()