Documentation ¶
Index ¶
- Constants
- Variables
- func MaxFragmentSize(mtu int, transport common.TransportProtocol) int
- func MaxPaddingSize(mtu int, transport common.TransportProtocol, fragmentSize int, ...) 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) ExportSessionInfoTable() []string
- func (m *Mux) SetClientMultiplexFactor(n int) *Mux
- func (m *Mux) SetClientUserNamePassword(username string, password []byte) *Mux
- func (m *Mux) SetDialer(dialer apicommon.Dialer) *Mux
- func (m *Mux) SetEndpoints(endpoints []UnderlayProperties) *Mux
- func (m *Mux) SetResolver(resolver apicommon.DNSResolver) *Mux
- func (m *Mux) SetServerUsers(users map[string]*appctlpb.User) *Mux
- func (m *Mux) Start() error
- type PacketUnderlay
- func (b *PacketUnderlay) Accept() (net.Conn, error)
- func (u *PacketUnderlay) AddSession(s *Session, remoteAddr net.Addr) error
- func (b *PacketUnderlay) Addr() net.Addr
- func (u *PacketUnderlay) Close() error
- func (b *PacketUnderlay) Done() chan struct{}
- func (u *PacketUnderlay) LocalAddr() net.Addr
- func (b *PacketUnderlay) MTU() int
- func (u *PacketUnderlay) RemoteAddr() net.Addr
- func (b *PacketUnderlay) RemoveSession(s *Session) error
- func (u *PacketUnderlay) RunEventLoop(ctx context.Context) error
- func (b *PacketUnderlay) Scheduler() *ScheduleController
- func (b *PacketUnderlay) SessionCount() int
- func (b *PacketUnderlay) Sessions() []SessionInfo
- func (u *PacketUnderlay) String() string
- func (u *PacketUnderlay) TransportProtocol() common.TransportProtocol
- type ScheduleController
- func (c *ScheduleController) DecPending()
- func (c *ScheduleController) Idle() bool
- func (c *ScheduleController) IncPending() (ok bool)
- func (c *ScheduleController) IsDisabled() bool
- func (c *ScheduleController) SetRemainingTime(d time.Duration)
- func (c *ScheduleController) TryDisable() (successful bool)
- 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) ToSessionInfo() SessionInfo
- func (s *Session) Write(b []byte) (n int, err error)
- type SessionInfo
- type StreamUnderlay
- func (b *StreamUnderlay) Accept() (net.Conn, error)
- func (t *StreamUnderlay) AddSession(s *Session, remoteAddr net.Addr) error
- func (t *StreamUnderlay) Addr() net.Addr
- func (t *StreamUnderlay) Close() error
- func (b *StreamUnderlay) Done() chan struct{}
- func (t *StreamUnderlay) LocalAddr() net.Addr
- func (b *StreamUnderlay) MTU() int
- func (t *StreamUnderlay) RemoteAddr() net.Addr
- func (b *StreamUnderlay) RemoveSession(s *Session) error
- func (t *StreamUnderlay) RunEventLoop(ctx context.Context) error
- func (b *StreamUnderlay) Scheduler() *ScheduleController
- func (b *StreamUnderlay) SessionCount() int
- func (b *StreamUnderlay) Sessions() []SessionInfo
- func (t *StreamUnderlay) String() string
- func (t *StreamUnderlay) TransportProtocol() common.TransportProtocol
- type Underlay
- type UnderlayProperties
Constants ¶
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 ¶
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 (*Mux) DialContext ¶
DialContext returns a network connection for the client to consume. The connection may be a session established from an existing underlay.
func (*Mux) ExportSessionInfoTable ¶
ExportSessionInfoTable returns multiple lines of strings that display session info in a table format.
func (*Mux) SetClientMultiplexFactor ¶
SetClientMultiplexFactor panics if the mux is already started.
func (*Mux) SetClientUserNamePassword ¶
SetClientUserNamePassword panics if the mux is already started.
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 ¶
SetServerUsers updates the registered users, even if mux is already started.
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) AddSession ¶ added in v3.8.0
func (u *PacketUnderlay) AddSession(s *Session, remoteAddr net.Addr) error
func (*PacketUnderlay) Close ¶ added in v3.8.0
func (u *PacketUnderlay) Close() error
func (*PacketUnderlay) LocalAddr ¶ added in v3.8.0
func (u *PacketUnderlay) LocalAddr() net.Addr
func (*PacketUnderlay) RemoteAddr ¶ added in v3.8.0
func (u *PacketUnderlay) RemoteAddr() net.Addr
func (*PacketUnderlay) RemoveSession ¶ added in v3.8.0
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 ¶
NewSession creates a new session.
func (*Session) Read ¶
Read lets a user to read data from receive queue. Read is allowed even after the session has been closed.
func (*Session) RemoteAddr ¶
func (*Session) SetDeadline ¶
SetDeadline implements net.Conn.
func (*Session) SetReadDeadline ¶
SetReadDeadline implements net.Conn.
func (*Session) SetWriteDeadline ¶
SetWriteDeadline implements net.Conn.
func (*Session) ToSessionInfo ¶
func (s *Session) ToSessionInfo() SessionInfo
ToSessionInfo creates related SessionInfo structure.
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) 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) LocalAddr ¶ added in v3.8.0
func (t *StreamUnderlay) LocalAddr() net.Addr
func (*StreamUnderlay) RemoteAddr ¶ added in v3.8.0
func (t *StreamUnderlay) RemoteAddr() net.Addr
func (*StreamUnderlay) RemoveSession ¶ added in v3.8.0
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.