Documentation
¶
Overview ¶
Package server: type aliases for types from ssu2 sub-packages. This file re-exports all external ssu2 types used within this package so that the implementation files need only change their package declaration.
Index ¶
- Constants
- Variables
- type Acceptor
- type DataHandler
- type HeaderProtector
- type NewTokenBlock
- type PacketRouter
- type SSU2Addr
- type SSU2Block
- type SSU2Config
- type SSU2Conn
- func DialSSU2(localAddr, remoteAddr *net.UDPAddr, config *SSU2Config) (*SSU2Conn, error)
- func DialSSU2WithConn(packetConn net.PacketConn, remoteAddr *net.UDPAddr, config *SSU2Config) (*SSU2Conn, error)
- func DialSSU2WithConnAndHandshake(packetConn net.PacketConn, remoteAddr *net.UDPAddr, config *SSU2Config) (*SSU2Conn, error)
- func DialSSU2WithConnAndHandshakeContext(ctx context.Context, packetConn net.PacketConn, remoteAddr *net.UDPAddr, ...) (*SSU2Conn, error)
- func DialSSU2WithHandshake(localAddr, remoteAddr *net.UDPAddr, config *SSU2Config) (*SSU2Conn, error)
- func DialSSU2WithHandshakeContext(ctx context.Context, localAddr, remoteAddr *net.UDPAddr, config *SSU2Config) (*SSU2Conn, error)
- func WrapSSU2Conn(underlying net.PacketConn, remoteAddr *net.UDPAddr, config *SSU2Config) (*SSU2Conn, error)
- type SSU2Listener
- func (l *SSU2Listener) Accept() (net.Conn, error)
- func (l *SSU2Listener) AddSession(connID uint64, conn *SSU2Conn)
- func (l *SSU2Listener) Addr() net.Addr
- func (l *SSU2Listener) Close() error
- func (l *SSU2Listener) Config() *SSU2Config
- func (l *SSU2Listener) GetAddr() string
- func (l *SSU2Listener) GetDroppedPackets() uint64
- func (l *SSU2Listener) RemoveSession(connID uint64)
- func (l *SSU2Listener) Router() *PacketRouter
- func (l *SSU2Listener) SessionCount() int
- func (l *SSU2Listener) Start() error
- func (l *SSU2Listener) TokenCache() *TokenCache
- func (l *SSU2Listener) Underlying() net.PacketConn
- type SSU2Packet
- type Token
- type TokenCache
Constants ¶
const ( BlockTypeDateTime = wire.BlockTypeDateTime BlockTypeOptions = wire.BlockTypeOptions BlockTypeNewToken = wire.BlockTypeNewToken BlockTypeTermination = wire.BlockTypeTermination BlockTypeRelayRequest = wire.BlockTypeRelayRequest BlockTypeRelayResponse = wire.BlockTypeRelayResponse BlockTypeRelayIntro = wire.BlockTypeRelayIntro BlockTypePeerTest = wire.BlockTypePeerTest BlockTypeACK = wire.BlockTypeACK BlockTypeAddress = wire.BlockTypeAddress BlockTypeRelayTagRequest = wire.BlockTypeRelayTagRequest BlockTypeRelayTag = wire.BlockTypeRelayTag BlockTypePathChallenge = wire.BlockTypePathChallenge BlockTypePathResponse = wire.BlockTypePathResponse BlockTypePadding = wire.BlockTypePadding MessageTypeSessionRequest = wire.MessageTypeSessionRequest MessageTypeSessionCreated = wire.MessageTypeSessionCreated MessageTypeSessionConfirmed = wire.MessageTypeSessionConfirmed MessageTypeData = wire.MessageTypeData MessageTypePeerTest = wire.MessageTypePeerTest MessageTypeRetry = wire.MessageTypeRetry MessageTypeTokenRequest = wire.MessageTypeTokenRequest MessageTypeHolePunch = wire.MessageTypeHolePunch HeaderTypeSessionRequest = wire.HeaderTypeSessionRequest HeaderTypeSessionCreated = wire.HeaderTypeSessionCreated HeaderTypeRetry = wire.HeaderTypeRetry HeaderTypeTokenRequest = wire.HeaderTypeTokenRequest HeaderTypeSessionConfirmed = wire.HeaderTypeSessionConfirmed HeaderTypeData = wire.HeaderTypeData HeaderTypePeerTest = wire.HeaderTypePeerTest HeaderTypeHolePunch = wire.HeaderTypeHolePunch ShortHeaderSize = wire.ShortHeaderSize LongHeaderSize = wire.LongHeaderSize EphemeralKeySize = wire.EphemeralKeySize MACSize = wire.MACSize MinPacketSize = wire.MinPacketSize MaxPacketSizeIPv4 = wire.MaxPacketSizeIPv4 MaxPacketSizeIPv6 = wire.MaxPacketSizeIPv6 SSU2ProtocolVersion = wire.SSU2ProtocolVersion SSU2NetworkID = wire.SSU2NetworkID TokenSize = wire.TokenSize MaxTokenCacheSize = wire.MaxTokenCacheSize )
Variables ¶
var ( NewSSU2Addr = ssu2config.NewSSU2Addr NewMockSSU2Addr = ssu2config.NewMockSSU2Addr NewSSU2Config = ssu2config.NewSSU2Config GenerateConnectionID = ssu2config.GenerateConnectionID DefaultRouterInfoValidator = ssu2config.DefaultRouterInfoValidator )
var ( NewSSU2Conn = session.NewSSU2Conn NewMockSSU2Conn = session.NewMockSSU2Conn NewPacketRouter = session.NewPacketRouter )
var ( NewSSU2Block = wire.NewSSU2Block NewSSU2Packet = wire.NewSSU2Packet NewNewTokenBlock = wire.NewNewTokenBlock ParseNewTokenBlock = wire.ParseNewTokenBlock NewTokenCacheWithMaxSize = wire.NewTokenCacheWithMaxSize SerializeBlocks = wire.SerializeBlocks DeserializeBlocks = wire.DeserializeBlocks FindBlockByType = wire.FindBlockByType ExtractConnectionID = wire.ExtractConnectionID NewHeaderProtectorFromIntroKey = wire.NewHeaderProtectorFromIntroKey )
Functions ¶
This section is empty.
Types ¶
type Acceptor ¶
type Acceptor interface {
// net.Listener embeds Accept, Close, and Addr.
net.Listener
// Start begins processing incoming packets. Call Start before Accept.
Start() error
// SessionCount returns the number of active sessions.
SessionCount() int
}
Acceptor abstracts accepting inbound SSU2 connections. *SSU2Listener satisfies this interface.
Callers that only need to accept connections can depend on Acceptor rather than on the concrete *SSU2Listener, making mocking and testing straightforward.
type DataHandler ¶
type DataHandler = session.DataHandler
type HeaderProtector ¶
type HeaderProtector = wire.HeaderProtector
type NewTokenBlock ¶
type NewTokenBlock = wire.NewTokenBlock
type PacketRouter ¶
type PacketRouter = session.PacketRouter
type SSU2Addr ¶
type SSU2Addr = ssu2config.SSU2Addr
type SSU2Config ¶
type SSU2Config = ssu2config.SSU2Config
type SSU2Conn ¶
func DialSSU2 ¶
func DialSSU2(localAddr, remoteAddr *net.UDPAddr, config *SSU2Config) (*SSU2Conn, error)
DialSSU2 creates an SSU2 connection to the remote address without performing handshake. Use DialSSU2WithHandshake for automatic handshake completion.
Design rationale: - Follows standard library pattern (net.Dial) - Uses UDP for connectionless transport - Creates minimal viable connection wrapper - Handshake is separate for flexibility (manual control)
Parameters:
- localAddr: Local UDP address to bind to (use nil for automatic)
- remoteAddr: Remote UDP address to connect to
- config: SSU2 configuration for the connection
Returns an SSU2Conn ready for handshake, or an error if creation fails.
func DialSSU2WithConn ¶
func DialSSU2WithConn(packetConn net.PacketConn, remoteAddr *net.UDPAddr, config *SSU2Config) (*SSU2Conn, error)
DialSSU2WithConn creates an SSU2 connection using an existing net.PacketConn (typically the listener socket) instead of creating a new UDP socket.
This is the recommended approach for SSU2 session multiplexing: all outbound connections share the listener's UDP socket so that handshake and data packets originate from the published listening port. This avoids:
- Firewall/netfilter EPERM errors from ephemeral source ports
- NAT binding mismatches (source port != advertised port)
- File descriptor exhaustion under sustained load
The caller is responsible for demultiplexing responses by ConnectionID. The provided PacketConn is NOT closed when the returned SSU2Conn is closed.
Parameters:
- packetConn: Existing UDP PacketConn to send/receive through
- remoteAddr: Remote UDP address to connect to
- config: SSU2 configuration for the connection
Returns an SSU2Conn ready for handshake, or an error if creation fails.
func DialSSU2WithConnAndHandshake ¶
func DialSSU2WithConnAndHandshake(packetConn net.PacketConn, remoteAddr *net.UDPAddr, config *SSU2Config) (*SSU2Conn, error)
DialSSU2WithConnAndHandshake creates an SSU2 connection over an existing PacketConn and performs the handshake automatically. This is the recommended function for multiplexed SSU2 transports.
func DialSSU2WithConnAndHandshakeContext ¶
func DialSSU2WithConnAndHandshakeContext(ctx context.Context, packetConn net.PacketConn, remoteAddr *net.UDPAddr, config *SSU2Config) (*SSU2Conn, error)
DialSSU2WithConnAndHandshakeContext creates an SSU2 connection over an existing PacketConn and performs the handshake with context support.
func DialSSU2WithHandshake ¶
func DialSSU2WithHandshake(localAddr, remoteAddr *net.UDPAddr, config *SSU2Config) (*SSU2Conn, error)
DialSSU2WithHandshake creates an SSU2 connection and performs the handshake automatically. This is the recommended function for most use cases.
func DialSSU2WithHandshakeContext ¶
func DialSSU2WithHandshakeContext(ctx context.Context, localAddr, remoteAddr *net.UDPAddr, config *SSU2Config) (*SSU2Conn, error)
DialSSU2WithHandshakeContext creates an SSU2 connection and performs the handshake with context. The context can be used to cancel the dial or handshake operations.
Design rationale: - Context enables timeout and cancellation - Follows Go standard patterns (context.Context for cancellable operations) - Automatic cleanup on handshake failure
Parameters:
- ctx: Context for cancellation and timeout
- localAddr: Local UDP address to bind to (use nil for automatic)
- remoteAddr: Remote UDP address to connect to
- config: SSU2 configuration for the connection
Returns an established SSU2Conn, or an error if dial or handshake fails.
func WrapSSU2Conn ¶
func WrapSSU2Conn(underlying net.PacketConn, remoteAddr *net.UDPAddr, config *SSU2Config) (*SSU2Conn, error)
WrapSSU2Conn wraps an existing net.PacketConn with SSU2Conn. This function provides manual control over the underlying connection.
Design rationale: - Allows reuse of existing PacketConn (e.g., with custom options) - Does NOT perform handshake (caller controls timing) - Validates connection type for safety
Parameters:
- underlying: Existing PacketConn to wrap
- remoteAddr: Remote UDP address for the connection
- config: SSU2 configuration for the connection
Returns an SSU2Conn wrapper, or an error if wrapping fails.
type SSU2Listener ¶
type SSU2Listener struct {
// contains filtered or unexported fields
}
SSU2Listener implements net.Listener for accepting SSU2 connections over UDP. It manages incoming packets, routes them to existing sessions, and creates new sessions for valid handshake packets.
Design rationale: - Uses PacketRouter to dispatch packets to appropriate sessions - Uses TokenCache to validate retry tokens and prevent spoofing - Implements net.Listener interface for compatibility with standard library - Single UDP socket shared across all sessions (multiplexing) - Worker pool limits goroutine count under traffic floods
Thread Safety: All public methods are thread-safe.
func ListenSSU2 ¶
func ListenSSU2(addr *net.UDPAddr, config *SSU2Config) (*SSU2Listener, error)
ListenSSU2 creates an SSU2 listener on the specified address. The listener is ready to accept incoming connections immediately after creation.
Design rationale: - Follows standard library pattern (net.Listen) - Creates UDP socket for connectionless transport - Starts packet routing automatically - Single socket multiplexed across all connections
Parameters:
- addr: Local UDP address to listen on
- config: SSU2 configuration for accepted connections
Returns an SSU2Listener ready to accept, or an error if creation fails.
func NewSSU2Listener ¶
func NewSSU2Listener(underlying net.PacketConn, config *SSU2Config) (*SSU2Listener, error)
NewSSU2Listener creates a new SSU2 listener wrapping the specified packet connection. The listener starts in an idle state; call Start() to begin accepting connections.
Parameters:
- underlying: UDP PacketConn to receive packets from
- config: SSU2 configuration for accepted connections
Returns a new SSU2Listener ready to start, or an error if configuration is invalid.
func WrapSSU2Listener ¶
func WrapSSU2Listener(underlying net.PacketConn, config *SSU2Config) (*SSU2Listener, error)
WrapSSU2Listener wraps an existing net.PacketConn with SSU2Listener. This function provides manual control over the underlying connection.
Design rationale: - Allows reuse of existing PacketConn (e.g., with custom socket options) - Does NOT start packet routing (caller controls timing) - Validates connection type for safety
Parameters:
- underlying: Existing PacketConn to wrap
- config: SSU2 configuration for accepted connections
Returns an SSU2Listener wrapper ready to start, or an error if wrapping fails.
func (*SSU2Listener) Accept ¶
func (l *SSU2Listener) Accept() (net.Conn, error)
Accept waits for and returns the next connection to the listener. Implements net.Listener interface.
Returns:
- net.Conn: The accepted connection
- error: If the listener is closed or an error occurs
func (*SSU2Listener) AddSession ¶
func (l *SSU2Listener) AddSession(connID uint64, conn *SSU2Conn)
AddSession registers an SSU2Conn under the given connection ID. This is primarily useful for testing and for reconnection scenarios.
func (*SSU2Listener) Addr ¶
func (l *SSU2Listener) Addr() net.Addr
Addr returns the listener's network address. Implements net.Listener interface.
Returns the SSU2 address for this listener.
func (*SSU2Listener) Close ¶
func (l *SSU2Listener) Close() error
Close closes the listener, preventing new connections from being accepted. Existing sessions are not closed; they must be closed separately. Implements net.Listener interface.
Returns error if close fails.
func (*SSU2Listener) Config ¶
func (l *SSU2Listener) Config() *SSU2Config
Config returns the SSU2Config used by this listener.
func (*SSU2Listener) GetAddr ¶
func (l *SSU2Listener) GetAddr() string
GetAddr returns the string representation of the listener's address. Implements the ssu2path.ListenerRef interface.
func (*SSU2Listener) GetDroppedPackets ¶
func (l *SSU2Listener) GetDroppedPackets() uint64
GetDroppedPackets returns the number of packets dropped due to full packetQueue. This metric indicates sustained overload where the listener cannot process incoming packets fast enough. Consider increasing packetQueueSize or packetWorkers if this counter grows under normal load.
func (*SSU2Listener) RemoveSession ¶
func (l *SSU2Listener) RemoveSession(connID uint64)
RemoveSession deregisters the session with the given connection ID.
func (*SSU2Listener) Router ¶
func (l *SSU2Listener) Router() *PacketRouter
Router returns the packet router used by this listener.
func (*SSU2Listener) SessionCount ¶
func (l *SSU2Listener) SessionCount() int
SessionCount returns the current number of active sessions. Useful for monitoring and debugging.
func (*SSU2Listener) Start ¶
func (l *SSU2Listener) Start() error
Start begins accepting connections on the listener. This starts a goroutine to read packets from the underlying connection and route them to appropriate sessions.
Returns error if the listener is already closed.
func (*SSU2Listener) TokenCache ¶
func (l *SSU2Listener) TokenCache() *TokenCache
TokenCache returns the token cache used by this listener.
func (*SSU2Listener) Underlying ¶
func (l *SSU2Listener) Underlying() net.PacketConn
Underlying returns the PacketConn used by this listener.
type SSU2Packet ¶
type SSU2Packet = wire.SSU2Packet
type TokenCache ¶
type TokenCache = wire.TokenCache