Documentation
¶
Index ¶
Constants ¶
const ( // DefaultSessionTTL is the default idle timeout for UDP sessions before cleanup. DefaultSessionTTL = 30 * time.Second // DefaultMaxSessions is the default cap on concurrent UDP sessions per relay. DefaultMaxSessions = 1024 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Relay ¶
type Relay struct {
// contains filtered or unexported fields
}
Relay listens for incoming UDP packets on a dedicated port and maintains per-client sessions that relay packets to a backend through the WireGuard tunnel.
func New ¶
func New(parentCtx context.Context, cfg RelayConfig) *Relay
New creates a UDP relay for the given listener and backend target. MaxSessions caps the number of concurrent sessions; use 0 for DefaultMaxSessions. DialTimeout controls how long to wait for backend connections; use 0 for default. SessionTTL is the idle timeout before a session is reaped; use 0 for DefaultSessionTTL.
func (*Relay) Close ¶
func (r *Relay) Close()
Close stops the relay, waits for all session goroutines to exit, and cleans up remaining sessions.
func (*Relay) Serve ¶
func (r *Relay) Serve()
Serve starts the relay loop. It blocks until the context is canceled or the listener is closed.
func (*Relay) SetObserver ¶
func (r *Relay) SetObserver(obs SessionObserver)
SetObserver sets the session lifecycle observer. Must be called before Serve.
type RelayConfig ¶
type RelayConfig struct {
Logger *log.Entry
Listener net.PacketConn
Target string
Domain string
AccountID types.AccountID
ServiceID types.ServiceID
DialFunc types.DialContextFunc
DialTimeout time.Duration
SessionTTL time.Duration
MaxSessions int
AccessLog l4Logger
// Filter holds connection-level IP/geo restrictions. Nil means no restrictions.
Filter *restrict.Filter
// Geo is the geolocation lookup used for country-based restrictions.
Geo restrict.GeoResolver
}
RelayConfig holds the configuration for a UDP relay.
type SessionObserver ¶
type SessionObserver interface {
UDPSessionStarted(accountID types.AccountID)
UDPSessionEnded(accountID types.AccountID)
UDPSessionDialError(accountID types.AccountID)
UDPSessionRejected(accountID types.AccountID)
UDPPacketRelayed(direction types.RelayDirection, bytes int)
}
SessionObserver receives callbacks for UDP session lifecycle events. All methods must be safe for concurrent use.