protocol

package
v3.39.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: GPL-3.0 Imports: 32 Imported by: 1

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

This section is empty.

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) ExportSessionInfoList added in v3.12.0

func (m *Mux) ExportSessionInfoList() *appctlpb.SessionInfoList

func (*Mux) SetClientDNSConfig added in v3.26.0

func (m *Mux) SetClientDNSConfig(clientDNSConfig *apicommon.ClientDNSConfig) *Mux

SetClientDNSConfig updates the client DNS configuration used by the mux.

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. Listener failures are logged. Use UpdateEndpoints to receive the errors.

func (*Mux) SetPacketDialer added in v3.23.0

func (m *Mux) SetPacketDialer(packetDialer apicommon.PacketDialer) *Mux

SetPacketDialer updates the packet dialer used by the mux.

func (*Mux) SetPacketListenerFactory added in v3.22.0

func (m *Mux) SetPacketListenerFactory(listenerFactory apicommon.PacketListenerFactory) *Mux

SetPacketListenerFactory updates the packet oriented network listener factory used by the mux.

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) SetServerTCPIdleTimeout added in v3.39.0

func (m *Mux) SetServerTCPIdleTimeout(timeout time.Duration) *Mux

SetServerTCPIdleTimeout sets how long a server TCP underlay can be idle in both directions before it is closed. Zero disables the timeout. Changes apply to existing and new underlays at the next maintenance cycle.

func (*Mux) SetServerUserHintIsMandatory added in v3.31.0

func (m *Mux) SetServerUserHintIsMandatory(userHintIsMandatory bool) *Mux

SetServerUserHintIsMandatory atomically sets whether the user hint is mandatory.

func (*Mux) SetServerUsers

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

SetServerUsers builds and atomically updates the registered users.

func (*Mux) SetStreamListenerFactory added in v3.22.0

func (m *Mux) SetStreamListenerFactory(listenerFactory apicommon.StreamListenerFactory) *Mux

SetStreamListenerFactory updates the stream oriented network listener factory used by the mux.

func (*Mux) SetTrafficPattern added in v3.28.0

func (m *Mux) SetTrafficPattern(trafficPattern *trafficpattern.Config) *Mux

SetTrafficPattern updates the traffic pattern configuration used by the mux.

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. Mux is automatically closed when accept underlay fails.

func (*Mux) UpdateEndpoints added in v3.37.0

func (m *Mux) UpdateEndpoints(endpoints []UnderlayProperties) error

UpdateEndpoints updates the configured endpoints before startup or on a client. On a running server, it adds listeners while retaining all existing endpoints. It returns listener errors without stopping the mux. Successful additions remain active even if another endpoint fails; failed endpoints can be retried.

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,
	packetDialer apicommon.PacketDialer,
	resolver apicommon.DNSResolver,
	network string,
	addr string,
	mtu int,
	block cipher.BlockCipher,
	trafficPattern *appctlpb.TrafficPattern,
) (*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) InBytes added in v3.24.0

func (b *PacketUnderlay) InBytes() int64

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) OutBytes added in v3.24.0

func (b *PacketUnderlay) OutBytes() int64

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) SessionInfos added in v3.12.0

func (b *PacketUnderlay) SessionInfos() []*appctlpb.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) DisableTime added in v3.24.0

func (c *ScheduleController) DisableTime() time.Time

DisableTime returns the underlay disable time.

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 unconditionally disables the scheduler after the given duration. Do nothing if the scheduler has already been disabled.

func (*ScheduleController) TryDisableIdle added in v3.24.0

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

TryDisableIdle tries to disable scheduling new sessions on idle underlay.

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, trafficPattern *appctlpb.TrafficPattern) *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() *appctlpb.SessionInfo

ToSessionInfo creates related SessionInfo protobuf object.

func (*Session) UserName added in v3.16.0

func (s *Session) UserName() string

UserName returns the user that owns this session, only if this is a server session.

func (*Session) Write

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

Write stores the data to send queue.

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,
	resolver apicommon.DNSResolver,
	dnsConfig *apicommon.ClientDNSConfig,
	network string,
	addr string,
	mtu int,
	block cipher.BlockCipher,
	trafficPattern *appctlpb.TrafficPattern,
) (*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) InBytes added in v3.24.0

func (b *StreamUnderlay) InBytes() int64

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) OutBytes added in v3.24.0

func (b *StreamUnderlay) OutBytes() int64

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) SessionInfos added in v3.12.0

func (b *StreamUnderlay) SessionInfos() []*appctlpb.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.
	SessionInfos() []*appctlpb.SessionInfo

	// Number of bytes received from the network.
	InBytes() int64

	// Number of bytes sent to the network.
	OutBytes() int64

	// 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.

Directories

Path Synopsis
Package serveruser authenticates server users and caches successful source-to-user associations.
Package serveruser authenticates server users and caches successful source-to-user associations.

Jump to

Keyboard shortcuts

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