Documentation ¶
Index ¶
- Constants
- Variables
- func MaxFragmentSize(mtu int, ipVersion util.IPVersion, transport util.TransportProtocol) int
- func MaxPaddingSize(mtu int, ipVersion util.IPVersion, transport util.TransportProtocol, ...) int
- type Mux
- func (m *Mux) Accept() (net.Conn, error)
- func (m *Mux) Addr() net.Addr
- func (m *Mux) Close() error
- func (m *Mux) DialContext(ctx context.Context) (net.Conn, error)
- func (m *Mux) ListenAndServeAll() error
- func (m *Mux) SetClientMultiplexFactor(n int) *Mux
- func (m *Mux) SetClientPassword(password []byte) *Mux
- func (m *Mux) SetEndpoints(endpoints []UnderlayProperties) *Mux
- func (m *Mux) SetServerHandler(handler util.ConnHandler) *Mux
- func (m *Mux) SetServerUsers(users map[string]*appctlpb.User) *Mux
- type Session
- func (s *Session) Close() error
- func (s *Session) LocalAddr() net.Addr
- func (s *Session) Read(b []byte) (n int, err error)
- func (s *Session) RemoteAddr() net.Addr
- func (s *Session) SetDeadline(t time.Time) error
- func (s *Session) SetReadDeadline(t time.Time) error
- func (s *Session) SetWriteDeadline(t time.Time) error
- func (s *Session) String() string
- func (s *Session) Write(b []byte) (n int, err error)
- type TCPUnderlay
- func (b *TCPUnderlay) Accept() (net.Conn, error)
- func (t *TCPUnderlay) AddSession(s *Session, remoteAddr net.Addr) error
- func (t *TCPUnderlay) Addr() net.Addr
- func (t *TCPUnderlay) Close() error
- func (b *TCPUnderlay) Done() chan struct{}
- func (t *TCPUnderlay) IPVersion() util.IPVersion
- func (t *TCPUnderlay) LocalAddr() net.Addr
- func (b *TCPUnderlay) MTU() int
- func (t *TCPUnderlay) RemoteAddr() net.Addr
- func (t *TCPUnderlay) RemoveSession(s *Session) error
- func (t *TCPUnderlay) RunEventLoop(ctx context.Context) error
- func (t *TCPUnderlay) String() string
- func (t *TCPUnderlay) TransportProtocol() util.TransportProtocol
- type UDPUnderlay
- func (b *UDPUnderlay) Accept() (net.Conn, error)
- func (u *UDPUnderlay) AddSession(s *Session, remoteAddr net.Addr) error
- func (b *UDPUnderlay) Addr() net.Addr
- func (u *UDPUnderlay) Close() error
- func (b *UDPUnderlay) Done() chan struct{}
- func (u *UDPUnderlay) IPVersion() util.IPVersion
- func (u *UDPUnderlay) LocalAddr() net.Addr
- func (b *UDPUnderlay) MTU() int
- func (u *UDPUnderlay) RemoteAddr() net.Addr
- func (u *UDPUnderlay) RemoveSession(s *Session) error
- func (u *UDPUnderlay) RunEventLoop(ctx context.Context) error
- func (u *UDPUnderlay) String() string
- func (u *UDPUnderlay) TransportProtocol() util.TransportProtocol
- type Underlay
- type UnderlayProperties
Constants ¶
const (
// Maximum protocol data unit supported in a single Write() call from application.
MaxPDU = 16 * 1024
)
Variables ¶
var ( UnderlayMaxConn = metrics.RegisterMetric("underlay", "MaxConn") UnderlayActiveOpens = metrics.RegisterMetric("underlay", "ActiveOpens") UnderlayPassiveOpens = metrics.RegisterMetric("underlay", "PassiveOpens") UnderlayCurrEstablished = metrics.RegisterMetric("underlay", "CurrEstablished") UnderlayMalformedUDP = metrics.RegisterMetric("underlay", "UnderlayMalformedUDP") UnderlayUnsolicitedUDP = metrics.RegisterMetric("underlay", "UnsolicitedUDP") )
Functions ¶
func MaxFragmentSize ¶
MaxFragmentSize returns the maximum payload size in a fragment.
func MaxPaddingSize ¶ added in v1.15.0
func MaxPaddingSize(mtu int, ipVersion util.IPVersion, transport util.TransportProtocol, fragmentSize int, existingPaddingSize int) int
MaxPaddingSize returns the maximum padding size of a segment.
Types ¶
type Mux ¶
type Mux struct {
// contains filtered or unexported fields
}
Mux manages the sessions and underlays.
func (*Mux) DialContext ¶ added in v1.15.0
DialContext returns a network connection for the client to consume. The connection may be a session established from an existing underlay.
func (*Mux) ListenAndServeAll ¶
ListenAndServeAll listens on all the server addresses and serves incoming requests. Call this method in client results in an error.
func (*Mux) SetClientMultiplexFactor ¶ added in v1.15.0
func (*Mux) SetClientPassword ¶ added in v1.15.0
func (*Mux) SetEndpoints ¶ added in v1.15.0
func (m *Mux) SetEndpoints(endpoints []UnderlayProperties) *Mux
func (*Mux) SetServerHandler ¶ added in v1.15.0
func (m *Mux) SetServerHandler(handler util.ConnHandler) *Mux
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
func NewSession ¶
NewSession creates a new session.
func (*Session) Close ¶
Close actively terminates the session. If the session is terminated by the other party, underlay is responsible to terminate the session at our end.
func (*Session) Read ¶
Read lets a user to read data from receive queue. The data boundary is preserved, i.e. no fragment read.
func (*Session) RemoteAddr ¶ added in v1.15.0
func (*Session) SetReadDeadline ¶ added in v1.15.0
func (*Session) SetWriteDeadline ¶ added in v1.15.0
type TCPUnderlay ¶
type TCPUnderlay struct {
// contains filtered or unexported fields
}
func NewTCPUnderlay ¶ added in v1.15.0
func NewTCPUnderlay(ctx context.Context, network, laddr, raddr string, mtu int, block cipher.BlockCipher) (*TCPUnderlay, error)
NewTCPUnderlay connects to the remote address "raddr" on the network "tcp" with packet encryption. If "laddr" is empty, an automatic address is used. "block" is the block encryption algorithm to encrypt packets.
func (*TCPUnderlay) AddSession ¶
func (t *TCPUnderlay) AddSession(s *Session, remoteAddr net.Addr) error
func (*TCPUnderlay) Addr ¶ added in v1.15.0
func (t *TCPUnderlay) Addr() net.Addr
func (*TCPUnderlay) Close ¶
func (t *TCPUnderlay) Close() error
func (*TCPUnderlay) IPVersion ¶
func (t *TCPUnderlay) IPVersion() util.IPVersion
func (*TCPUnderlay) LocalAddr ¶ added in v1.14.1
func (t *TCPUnderlay) LocalAddr() net.Addr
func (*TCPUnderlay) RemoteAddr ¶ added in v1.14.1
func (t *TCPUnderlay) RemoteAddr() net.Addr
func (*TCPUnderlay) RemoveSession ¶
func (t *TCPUnderlay) RemoveSession(s *Session) error
func (*TCPUnderlay) RunEventLoop ¶
func (t *TCPUnderlay) RunEventLoop(ctx context.Context) error
func (*TCPUnderlay) String ¶
func (t *TCPUnderlay) String() string
func (*TCPUnderlay) TransportProtocol ¶
func (t *TCPUnderlay) TransportProtocol() util.TransportProtocol
type UDPUnderlay ¶
type UDPUnderlay struct {
// contains filtered or unexported fields
}
func NewUDPUnderlay ¶ added in v1.15.0
func NewUDPUnderlay(ctx context.Context, network, laddr, raddr string, mtu int, block cipher.BlockCipher) (*UDPUnderlay, error)
NewUDPUnderlay connects to the remote address "raddr" on the network "udp" with packet encryption. If "laddr" is empty, an automatic address is used. "block" is the block encryption algorithm to encrypt packets.
func (*UDPUnderlay) AddSession ¶
func (u *UDPUnderlay) AddSession(s *Session, remoteAddr net.Addr) error
func (*UDPUnderlay) Close ¶
func (u *UDPUnderlay) Close() error
func (*UDPUnderlay) IPVersion ¶
func (u *UDPUnderlay) IPVersion() util.IPVersion
func (*UDPUnderlay) LocalAddr ¶ added in v1.15.0
func (u *UDPUnderlay) LocalAddr() net.Addr
func (*UDPUnderlay) RemoteAddr ¶ added in v1.15.0
func (u *UDPUnderlay) RemoteAddr() net.Addr
func (*UDPUnderlay) RemoveSession ¶
func (u *UDPUnderlay) RemoveSession(s *Session) error
func (*UDPUnderlay) RunEventLoop ¶
func (u *UDPUnderlay) RunEventLoop(ctx context.Context) error
func (*UDPUnderlay) String ¶ added in v1.14.0
func (u *UDPUnderlay) String() string
func (*UDPUnderlay) TransportProtocol ¶
func (u *UDPUnderlay) TransportProtocol() util.TransportProtocol
type Underlay ¶
type Underlay interface { // Accept incoming sessions. net.Listener // Store basic network properties. UnderlayProperties // Add a session to the underlay connection. // Optionally, the remote network address can be specified for the session. // The session is ready to use when this returns. AddSession(*Session, net.Addr) error // Remove a session from the underlay connection. // The session is destroyed when this returns. RemoveSession(*Session) error // Run event loop. // The underlay needs to be closed when this returns. RunEventLoop(context.Context) error // Indicate the underlay is closed. Done() chan struct{} }
Underlay contains methods implemented by a underlay network connection.
type UnderlayProperties ¶ added in v1.15.0
type UnderlayProperties interface { // Layer 2 MTU of this network connection. MTU() int // The IP version used to establish the underlay. IPVersion() util.IPVersion // The transport protocol used to implement the underlay. TransportProtocol() util.TransportProtocol // Implement the LocalAddr() method in net.Conn interface. LocalAddr() net.Addr // Implemeent the RemoteAddr() method in the net.Conn interface. RemoteAddr() net.Addr }
UnderlayProperties defines network properties of a underlay.