protocol

package
v3.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2025 License: GPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Number of bytes used by metadata before encryption.
	MetadataLength = 32

	// Maximum payload that cat be attached to open session request and open session response.
	MaxSessionOpenPayload = 1024
)

Variables

View Source
var (
	UnderlayMaxConn         = metrics.RegisterMetric("underlay", "MaxConn", metrics.GAUGE)
	UnderlayActiveOpens     = metrics.RegisterMetric("underlay", "ActiveOpens", metrics.COUNTER)
	UnderlayPassiveOpens    = metrics.RegisterMetric("underlay", "PassiveOpens", metrics.COUNTER)
	UnderlayCurrEstablished = metrics.RegisterMetric("underlay", "CurrEstablished", metrics.GAUGE)
	UnderlayMalformedUDP    = metrics.RegisterMetric("underlay", "UnderlayMalformedUDP", metrics.COUNTER)
	UnderlayUnsolicitedUDP  = metrics.RegisterMetric("underlay", "UnsolicitedUDP", metrics.COUNTER)
)

Functions

func MaxFragmentSize

func MaxFragmentSize(mtu int, transport common.TransportProtocol) int

MaxFragmentSize returns the maximum payload size in a fragment.

func MaxPaddingSize

func MaxPaddingSize(mtu int, transport common.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

func NewMux(isClinet bool) *Mux

NewMux creates a new mieru v2 multiplex controller.

func (*Mux) Accept

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

func (*Mux) Addr

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

Addr is not supported by Mux.

func (*Mux) Close

func (m *Mux) Close() error

func (*Mux) DialContext

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

func (m *Mux) ExportSessionInfoTable() []string

ExportSessionInfoTable returns multiple lines of strings that display session info in a table format.

func (*Mux) SetClientMultiplexFactor

func (m *Mux) SetClientMultiplexFactor(n int) *Mux

SetClientMultiplexFactor panics if the mux is already started.

func (*Mux) SetClientUserNamePassword

func (m *Mux) SetClientUserNamePassword(username string, password []byte) *Mux

SetClientUserNamePassword panics if the mux is already started.

func (*Mux) SetDialer added in v3.8.2

func (m *Mux) SetDialer(dialer apicommon.Dialer) *Mux

SetDialer updates the dialer used by the mux.

func (*Mux) SetEndpoints

func (m *Mux) SetEndpoints(endpoints []UnderlayProperties) *Mux

SetEndpoints updates the endpoints that mux is listening to. If mux is started and new endpoints are added, mux also starts to listen to those new endpoints. In that case, old endpoints are not impacted.

func (*Mux) SetResolver added in v3.8.0

func (m *Mux) SetResolver(resolver apicommon.DNSResolver) *Mux

SetResolver updates the DNS resolver used by the mux.

func (*Mux) SetServerUsers

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

SetServerUsers updates the registered users, even if mux is already started.

func (*Mux) Start

func (m *Mux) Start() error

Start listens on all the server addresses for incoming connections. Call this method in client results in an error. This method doesn't block.

type PacketUnderlay added in v3.8.0

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

func NewPacketUnderlay added in v3.8.0

func NewPacketUnderlay(ctx context.Context, network, addr string, mtu int, block cipher.BlockCipher, resolver apicommon.DNSResolver) (*PacketUnderlay, error)

NewPacketUnderlay connects to the remote address "addr" on the network with packet encryption. "block" is the block encryption algorithm to encrypt packets.

This function is only used by proxy client.

func (*PacketUnderlay) Accept added in v3.8.0

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

Accept implements net.Listener interface.

func (*PacketUnderlay) AddSession added in v3.8.0

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

func (*PacketUnderlay) Addr added in v3.8.0

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

Addr implements net.Listener interface.

func (*PacketUnderlay) Close added in v3.8.0

func (u *PacketUnderlay) Close() error

func (*PacketUnderlay) Done added in v3.8.0

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

func (*PacketUnderlay) LocalAddr added in v3.8.0

func (u *PacketUnderlay) LocalAddr() net.Addr

func (*PacketUnderlay) MTU added in v3.8.0

func (b *PacketUnderlay) MTU() int

func (*PacketUnderlay) RemoteAddr added in v3.8.0

func (u *PacketUnderlay) RemoteAddr() net.Addr

func (*PacketUnderlay) RemoveSession added in v3.8.0

func (b *PacketUnderlay) RemoveSession(s *Session) error

func (*PacketUnderlay) RunEventLoop added in v3.8.0

func (u *PacketUnderlay) RunEventLoop(ctx context.Context) error

func (*PacketUnderlay) Scheduler added in v3.8.0

func (b *PacketUnderlay) Scheduler() *ScheduleController

func (*PacketUnderlay) SessionCount added in v3.8.0

func (b *PacketUnderlay) SessionCount() int

func (*PacketUnderlay) Sessions added in v3.8.0

func (b *PacketUnderlay) Sessions() []SessionInfo

func (*PacketUnderlay) String added in v3.8.0

func (u *PacketUnderlay) String() string

func (*PacketUnderlay) TransportProtocol added in v3.8.0

func (u *PacketUnderlay) TransportProtocol() common.TransportProtocol

type ScheduleController

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

ScheduleController controls scheduling a new client session to a underlay.

func (*ScheduleController) DecPending

func (c *ScheduleController) DecPending()

DecPending decreases the number of pending sessions by 1.

func (*ScheduleController) Idle

func (c *ScheduleController) Idle() bool

Idle returns true if the scheduling has been disabled for the given interval.

func (*ScheduleController) IncPending

func (c *ScheduleController) IncPending() (ok bool)

IncPending increases the number of pending sessions by 1. The number of pending sessions can't increase if the scheduler is disabled.

func (*ScheduleController) IsDisabled

func (c *ScheduleController) IsDisabled() bool

IsDisabled returns true if scheduling new sessions to the underlay is disabled.

func (*ScheduleController) SetRemainingTime

func (c *ScheduleController) SetRemainingTime(d time.Duration)

SetRemainingTime disables the scheduler after the given duration. Do nothing if the scheduler has already been disabled.

func (*ScheduleController) TryDisable

func (c *ScheduleController) TryDisable() (successful bool)

TryDisable tries to disable scheduling new sessions.

type Session

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

func NewSession

func NewSession(id uint32, isClient bool, mtu int, users map[string]*appctlpb.User) *Session

NewSession creates a new session.

func (*Session) Close

func (s *Session) Close() error

Close terminates the session.

func (*Session) LocalAddr

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. Read is allowed even after the session has been closed.

func (*Session) RemoteAddr

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

func (*Session) SetDeadline

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

SetDeadline implements net.Conn.

func (*Session) SetReadDeadline

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

SetReadDeadline implements net.Conn.

func (*Session) SetWriteDeadline

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

SetWriteDeadline implements net.Conn.

func (*Session) String

func (s *Session) String() string

func (*Session) ToSessionInfo

func (s *Session) ToSessionInfo() SessionInfo

ToSessionInfo creates related SessionInfo structure.

func (*Session) Write

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

Write stores the data to send queue.

type SessionInfo

type SessionInfo struct {
	ID         string
	Protocol   string
	LocalAddr  string
	RemoteAddr string
	State      string
	RecvQBuf   string
	SendQBuf   string
	LastRecv   string
	LastSend   string
}

SessionInfo provides a string representation of a Session.

type StreamUnderlay added in v3.8.0

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

func NewStreamUnderlay added in v3.8.0

func NewStreamUnderlay(ctx context.Context, dialer apicommon.Dialer, network, addr string, mtu int, block cipher.BlockCipher) (*StreamUnderlay, error)

NewStreamUnderlay connects to the remote address "addr" on the network with packet encryption. "block" is the block encryption algorithm to encrypt packets.

This function is only used by proxy client.

func (*StreamUnderlay) Accept added in v3.8.0

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

Accept implements net.Listener interface.

func (*StreamUnderlay) AddSession added in v3.8.0

func (t *StreamUnderlay) AddSession(s *Session, remoteAddr net.Addr) error

func (*StreamUnderlay) Addr added in v3.8.0

func (t *StreamUnderlay) Addr() net.Addr

func (*StreamUnderlay) Close added in v3.8.0

func (t *StreamUnderlay) Close() error

func (*StreamUnderlay) Done added in v3.8.0

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

func (*StreamUnderlay) LocalAddr added in v3.8.0

func (t *StreamUnderlay) LocalAddr() net.Addr

func (*StreamUnderlay) MTU added in v3.8.0

func (b *StreamUnderlay) MTU() int

func (*StreamUnderlay) RemoteAddr added in v3.8.0

func (t *StreamUnderlay) RemoteAddr() net.Addr

func (*StreamUnderlay) RemoveSession added in v3.8.0

func (b *StreamUnderlay) RemoveSession(s *Session) error

func (*StreamUnderlay) RunEventLoop added in v3.8.0

func (t *StreamUnderlay) RunEventLoop(ctx context.Context) error

func (*StreamUnderlay) Scheduler added in v3.8.0

func (b *StreamUnderlay) Scheduler() *ScheduleController

func (*StreamUnderlay) SessionCount added in v3.8.0

func (b *StreamUnderlay) SessionCount() int

func (*StreamUnderlay) Sessions added in v3.8.0

func (b *StreamUnderlay) Sessions() []SessionInfo

func (*StreamUnderlay) String added in v3.8.0

func (t *StreamUnderlay) String() string

func (*StreamUnderlay) TransportProtocol added in v3.8.0

func (t *StreamUnderlay) TransportProtocol() common.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

	// Returns the number of sessions.
	SessionCount() int

	// Returns detailed information of all the sessions.
	Sessions() []SessionInfo

	// Run event loop.
	// The underlay needs to be closed when this returns.
	RunEventLoop(context.Context) error

	// Return the schedule controller.
	Scheduler() *ScheduleController

	// Indicate the underlay is closed.
	Done() chan struct{}
}

Underlay contains methods implemented by a underlay network connection.

type UnderlayProperties

type UnderlayProperties interface {
	// Maximum transission unit of this network connection
	// in the current network layer.
	MTU() int

	// The transport protocol used to implement the underlay.
	TransportProtocol() common.TransportProtocol

	// LocalAddr implements net.Conn interface.
	LocalAddr() net.Addr

	// RemoteAddr implements net.Conn interface.
	RemoteAddr() net.Addr
}

UnderlayProperties defines network properties of a underlay.

func NewUnderlayProperties

func NewUnderlayProperties(mtu int, transportProtocol common.TransportProtocol, localAddr net.Addr, remoteAddr net.Addr) UnderlayProperties

NewUnderlayProperties creates a new instance of UnderlayProperties.

Jump to

Keyboard shortcuts

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