l4

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package l4 implements the L4 server: every client conn becomes a flow to an endpoint of the server's clusters. Flows are client-initiated only.

Index

Constants

This section is empty.

Variables

View Source
var FlowTimeout = 5 * time.Minute

FlowTimeout is the idle timeout of a flow.

Functions

This section is empty.

Types

type EventHandler

type EventHandler struct {
	// OnFlowCreated is called after a flow has been admitted, wired, and registered.
	OnFlowCreated func(ev FlowEvent)
	// OnFlowDeleted is called when a flow is being torn down, before its legs close.
	OnFlowDeleted func(ev FlowEvent)
	// OnFlowError is called when a pump exits on a write error.
	OnFlowError func(srcAddr net.Addr, protocol stnrv2.Protocol, message string)
}

EventHandler is the set of callbacks the L4 server calls on flow lifecycle events, the L4 analog of the TURN server's allocation event handlers. A flow collapses the TURN allocation/permission/channel lifecycle into a single event pair: flow setup is the allocation, the endpoint choice is the permission, and the fixed client-to-peer binding is the channel.

func NewEventHandler

func NewEventHandler(rt *objruntime.Runtime, log logging.LeveledLogger, q *turnsrv.Quota) EventHandler

NewEventHandler returns the default flow event wiring: logging and quota accounting through the shared Quota machinery of the TURN server.

type Flow

type Flow struct {
	flow.Entry
	Event FlowEvent
}

Flow is one relayed client flow and the event describing it.

type FlowEvent

type FlowEvent struct {
	// SrcAddr and DstAddr are the client's source address and the listener-side address
	// serving it.
	SrcAddr, DstAddr net.Addr
	// Protocol is the client-side transport, the listener protocol.
	Protocol stnrv2.Protocol
	// Peer is the endpoint the flow was forwarded to and PeerProtocol the protocol of the leg
	// towards it, its tag's.
	Peer         net.Addr
	PeerProtocol stnrv2.Protocol
	// Cluster is the cluster the flow was forwarded through.
	Cluster string
	// Username and Realm are the flow's quota identity, as minted by the quota gate.
	Username, Realm string
}

FlowEvent carries the context of a flow lifecycle event. It is pure data (addresses, names): safe to serialize or ship across a process boundary.

type Server

type Server struct {
	server.Base
	// contains filtered or unexported fields
}

Server is an L4 server object.

func New

func New(conf *stnrv2.ServerConfig, rt *objruntime.Runtime) (*Server, error)

New creates the L4 server of a validated config.

func (*Server) Close

func (s *Server) Close(_ bool) error

Close tears down every flow, client conns included.

func (*Server) GetConfig

func (s *Server) GetConfig() stnrv2.Config

func (*Server) Reconcile

func (s *Server) Reconcile(conf stnrv2.Config) error

Reconcile applies the spec and the policy to the next flows.

func (*Server) Serve

func (s *Server) Serve(c api.Conn) (api.Conn, api.Verdict, error)

Serve queues a client conn for the accept loop.

func (*Server) Sessions

func (s *Server) Sessions() int

Sessions returns the number of live flows.

func (*Server) Start

func (s *Server) Start() error

Start runs the accept loop.

func (*Server) Status

func (s *Server) Status() stnrv2.Status

Jump to

Keyboard shortcuts

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