protocolv2

package
v1.15.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2023 License: GPL-3.0 Imports: 21 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// Maximum protocol data unit supported in a single Write() call from application.
	MaxPDU = 16 * 1024
)

Variables

View Source
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

func MaxFragmentSize(mtu int, ipVersion util.IPVersion, transport util.TransportProtocol) int

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 NewMux added in v1.15.0

func NewMux(isClinet bool) *Mux

NewMux creates a new mieru v2 multiplex controller.

func (*Mux) Accept added in v1.15.0

func (m *Mux) Accept() (net.Conn, error)

func (*Mux) Addr added in v1.15.0

func (m *Mux) Addr() net.Addr

Addr is not supported by Mux.

func (*Mux) Close added in v1.15.0

func (m *Mux) Close() error

func (*Mux) DialContext added in v1.15.0

func (m *Mux) DialContext(ctx context.Context) (net.Conn, error)

DialContext returns a network connection for the client to consume. The connection may be a session established from an existing underlay.

func (*Mux) ListenAndServeAll

func (m *Mux) ListenAndServeAll() error

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 (m *Mux) SetClientMultiplexFactor(n int) *Mux

func (*Mux) SetClientPassword added in v1.15.0

func (m *Mux) SetClientPassword(password []byte) *Mux

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

func (*Mux) SetServerUsers added in v1.15.0

func (m *Mux) SetServerUsers(users map[string]*appctlpb.User) *Mux

type Session

type Session struct {
	// contains filtered or unexported fields
}

func NewSession

func NewSession(id uint32, isClient bool, mtu int) *Session

NewSession creates a new session.

func (*Session) Close

func (s *Session) Close() error

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) LocalAddr added in v1.15.0

func (s *Session) LocalAddr() net.Addr

func (*Session) Read

func (s *Session) Read(b []byte) (n int, err error)

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 (s *Session) RemoteAddr() net.Addr

func (*Session) SetDeadline added in v1.15.0

func (s *Session) SetDeadline(t time.Time) error

func (*Session) SetReadDeadline added in v1.15.0

func (s *Session) SetReadDeadline(t time.Time) error

func (*Session) SetWriteDeadline added in v1.15.0

func (s *Session) SetWriteDeadline(t time.Time) error

func (*Session) String added in v1.15.0

func (s *Session) String() string

func (*Session) Write

func (s *Session) Write(b []byte) (n int, err error)

Write stores the data to send queue.

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) Accept added in v1.15.0

func (b *TCPUnderlay) Accept() (net.Conn, error)

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) Done added in v1.15.0

func (b *TCPUnderlay) Done() chan struct{}

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) MTU

func (b *TCPUnderlay) MTU() int

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) Accept added in v1.15.0

func (b *UDPUnderlay) Accept() (net.Conn, error)

func (*UDPUnderlay) AddSession

func (u *UDPUnderlay) AddSession(s *Session, remoteAddr net.Addr) error

func (*UDPUnderlay) Addr added in v1.15.0

func (b *UDPUnderlay) Addr() net.Addr

func (*UDPUnderlay) Close

func (u *UDPUnderlay) Close() error

func (*UDPUnderlay) Done added in v1.15.0

func (b *UDPUnderlay) Done() chan struct{}

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) MTU

func (b *UDPUnderlay) MTU() int

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL