flow

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	OffloadBackoff  = 100 * time.Millisecond
	OffloadAttempts = 5
)

OffloadBackoff and OffloadAttempts pace Offload on a leg tunnelled through TURN-UDP: the TURN client assigns the channel towards the peer at the first write and binds it a round trip later.

View Source
var ErrNotOffloadable = errors.New("not offloadable")

ErrNotOffloadable is the error of Offload on an entry the kernel cannot carry.

Functions

func Forward

func Forward(e *Entry)

Forward pumps an entry's client conn and leg into each other, touching the entry, until either side ends; it returns on teardown.

Types

type AddrPair

type AddrPair struct{ Remote, Local netip.AddrPort }

AddrPair is the conntrack key of a conn: its remote and local address and port.

func Key

func Key(remote, local net.Addr) AddrPair

Key returns the conntrack key of a conn. A non-IP address, such as stdio's, is the zero value.

type Conntrack

type Conntrack struct {
	// contains filtered or unexported fields
}

Conntrack tracks the client conns of a server, keyed by their 5-tuple, each with an idle timer. Close closes every entry it ever tracked and refuses new ones.

func NewConntrack

func NewConntrack(idle time.Duration) *Conntrack

NewConntrack creates a conntrack whose entries time out after idle.

func (*Conntrack) Add

func (t *Conntrack) Add(e *Entry) bool

Add tracks an entry under its client's key and arms its idle timer, replacing a stale entry of the same key; false if the conntrack is closed, and the caller keeps the conns.

func (*Conntrack) Close

func (t *Conntrack) Close()

Close closes every entry and refuses new ones.

func (*Conntrack) Get

func (t *Conntrack) Get(key AddrPair) (*Entry, bool)

Get returns the entry of a key.

func (*Conntrack) Len

func (t *Conntrack) Len() int

Len returns the number of tracked entries.

func (*Conntrack) Remove

func (t *Conntrack) Remove(key AddrPair)

Remove untracks the entry of a key without closing it.

type Entry

type Entry struct {
	Client api.Conn
	// Leg is the conn the client conn is relayed to: set before Add for a forwarded entry, by
	// SetLeg later for an entry the server relays itself; nil for a conn a server hands on, like
	// TURN.
	Leg   api.Conn
	Hooks EntryHooks
	// contains filtered or unexported fields
}

Entry is a tracked client conn and, when forwarded or offloaded, its leg.

func (*Entry) Close

func (e *Entry) Close(reason string)

Close closes the entry and its conns once, and untracks it.

func (*Entry) Closed

func (e *Entry) Closed() bool

Closed reports whether the entry has closed.

func (*Entry) Disarm

func (e *Entry) Disarm()

Disarm stops the idle timer for good: something else owns the entry's lifetime from now on.

func (*Entry) LastActive

func (e *Entry) LastActive() time.Time

LastActive returns the time of the entry's last activity, in user space or, for an offloaded entry, in the kernel: the kernel's traffic since the last call counts as activity now.

func (*Entry) Offload

func (e *Entry) Offload(engine offload.Engine, punt ...offload.PuntRule) error

Offload hands the entry's datagrams to the kernel engine, both directions: a packet from the client goes out on the leg's wire and back, the packets matching the punt rules excepted. It takes a UDP client conn and a UDP or TURN-UDP leg, the latter once its channel towards the peer is bound, which Offload waits for, so it may block for a few seconds. Anything else, and a refusal of the engine (such as the offload limit), leaves the entry in user space. Offloading an offloaded entry again replaces its offload, for a leg that changed. An offloaded entry's idle check counts the kernel's traffic too, and closing the entry removes it from the engine.

func (*Entry) SetLeg

func (e *Entry) SetLeg(leg api.Conn)

SetLeg sets the leg of an entry the server relays itself, so that it can be offloaded.

func (*Entry) Touch

func (e *Entry) Touch()

Touch records activity on the entry.

type EntryHooks

type EntryHooks struct {
	// OnError is called by the forwarder on a failed write, before the entry closes.
	OnError func(msg string)
	// OnClose is called once, when the entry closes, before its conns close.
	OnClose func(reason string)
}

EntryHooks are a server's callbacks on one entry.

Jump to

Keyboard shortcuts

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