"Fossies" - the Fresh Open Source Software Archive

Member "mattermost-server-6.0.1/vendor/github.com/hashicorp/yamux/addr.go" (18 Oct 2021, 1214 Bytes) of package /linux/www/mattermost-server-6.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Go source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    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 // RemoteAddr returns the remote address
   58 func (s *Stream) RemoteAddr() net.Addr {
   59     return s.session.RemoteAddr()
   60 }