session

package
v0.35.2 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: GPL-3.0 Imports: 45 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

Overview

Package session runs the core protocol on zmux: Admission on the shared bridge ports, Establish on both sides, the client table and the sessions. It implements coreapi; nothing above it sees zmux or wire types.

Index

Constants

View Source
const (
	// DefaultCompressMaxWindow is compress_max_window (§7.4).
	DefaultCompressMaxWindow = 8 << 20
	// DefaultCompressMaxRatio is compress_max_ratio (§7.4).
	DefaultCompressMaxRatio = 4096
)

Compression of a stream (§7).

View Source
const DefaultMaxLanes = 16

DefaultMaxLanes is the lanes accepted per pipe: more bring next to nothing.

View Source
const (
	// DefaultRelayIdle is how long a relay stands by after the direct path
	// came up (§9.4a).
	DefaultRelayIdle = time.Minute
)
View Source
const (
	// DefaultUsageInterval is how often a provider reports.
	DefaultUsageInterval = time.Minute
)
View Source
const RelayDisabledReason = "relay disabled for this tunnel"

RelayDisabledReason is the reason of a LINK refused because it asked for relay only and the tunnel does not allow relaying.

Variables

This section is empty.

Functions

func ConnModeOf

func ConnModeOf(mode string) uint64

ConnModeOf is the wire value of a section's conn_mode.

func QUICConfig

func QUICConfig(base *quic.Config) *quic.Config

QUICConfig completes the QUIC configuration of a direct path.

Types

type Acceptor

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

Acceptor is the core protocol entry of the server's bridge ports.

func NewAcceptor

func NewAcceptor(store Store, opts Options) (*Acceptor, error)

NewAcceptor builds the entry over store, with a key of this process (nothing is persisted, §3.3).

func (*Acceptor) ClientChanged

func (a *Acceptor) ClientChanged(r coreapi.ClientRecord)

ClientChanged implements coreapi.Entry: §3.2's rules for the switch, §3.7 for a client that may no longer connect; a change of what CONFIG carries goes out as a new snapshot.

func (*Acceptor) ClientRemoved

func (a *Acceptor) ClientRemoved(id int)

ClientRemoved implements coreapi.Entry.

func (*Acceptor) Close

func (a *Acceptor) Close() error

Close implements coreapi.Entry.

func (*Acceptor) Forwarding

func (a *Acceptor) Forwarding(trusted []netip.Prefix, header string) coreapi.Forwarding

Forwarding implements coreapi.Entry.

func (*Acceptor) HTTPCarriers

func (a *Acceptor) HTTPCarriers(next http.Handler, f coreapi.Forwarding) (http.Handler, error)

HTTPCarriers implements coreapi.Entry.

func (*Acceptor) Kick

func (a *Acceptor) Kick(id int, auth bool)

Kick implements coreapi.Entry.

func (*Acceptor) QUICConfig

func (a *Acceptor) QUICConfig(base *quic.Config) *quic.Config

QUICConfig implements coreapi.Entry.

func (a *Acceptor) RevokeLinks(match func(tunnel, visitor, provider int) bool)

RevokeLinks implements coreapi.Entry.

func (*Acceptor) Serve

func (a *Acceptor) Serve(ctx context.Context, c net.Conn, carrier string)

Serve implements coreapi.Entry.

func (*Acceptor) ServeMixed

func (a *Acceptor) ServeMixed(ctx context.Context, c net.Conn, carrier string, other func(net.Conn, *tls.ConnectionState) bool)

ServeMixed implements coreapi.Entry.

func (*Acceptor) ServeQUIC

func (a *Acceptor) ServeQUIC(ctx context.Context, qc *quic.Conn)

ServeQUIC implements coreapi.Entry. ALPN told the new protocol from the old before this (§12), so a first stream that is no carrier just ends.

func (*Acceptor) ServeTerminated

func (a *Acceptor) ServeTerminated(ctx context.Context, tc *tls.Conn, head []byte, carrier string)

ServeTerminated implements coreapi.Entry.

func (*Acceptor) SetShaping

func (a *Acceptor) SetShaping(b []byte)

SetShaping replaces the bundle used with the clients whose switch is on, nil for none, and brings their sessions in line. A bundle that does not parse is ignored.

func (*Acceptor) Stall

func (a *Acceptor) Stall(ctx context.Context, c net.Conn)

Stall implements coreapi.Entry.

func (*Acceptor) Start

func (a *Acceptor) Start(ctx context.Context, h coreapi.Hooks) error

Start implements coreapi.Entry.

func (*Acceptor) WebSocket

func (a *Acceptor) WebSocket(legacy http.Handler, f coreapi.Forwarding) (http.Handler, error)

WebSocket implements coreapi.Entry (§12): on the bridge path the subprotocol binary is the core protocol; anything else stays with the old one.

func (*Acceptor) WebSocketAnyProtocol

func (a *Acceptor) WebSocketAnyProtocol(next http.Handler, f coreapi.Forwarding) (http.Handler, error)

WebSocketAnyProtocol implements coreapi.Entry (§12): the path is the core protocol's, so a request is accepted with the subprotocol it offered (the first of them) or with none.

type CompressLimits

type CompressLimits struct {
	MaxWindow uint64 // 0 is DefaultCompressMaxWindow
	MaxRatio  int64  // 0 is DefaultCompressMaxRatio, negative disables the check
}

CompressLimits are the receive limits of §7.4.

type DialConfig

type DialConfig struct {
	Candidates []connprofile.Candidate // from connprofile.Parse
	VKey       string
	Pin        []byte           // optional seal.NodeKeyID of the server
	Key        *ecdh.PrivateKey // nil: the key seal generates once per process
	Agent      string
	Label      string
	Timeout    time.Duration
	// Dial connects to the server, keeping -proxy and -local_ip; nil dials
	// directly.
	Dial func(ctx context.Context, network, addr string) (net.Conn, error)
	// DialQUIC opens the QUIC connection of a quic carrier, keeping
	// -local_ip; nil dials directly.
	DialQUIC func(ctx context.Context, addr string, t *tls.Config, q *quic.Config) (*quic.Conn, error)
	// Scheduler names the sending scheduler (connprofile.Schedulers);
	// "" is affinity. A scheduler_up of CONFIG replaces it (§5).
	Scheduler string
	// Pipes is connprofile.PipesMulti for several pipes in a session; any
	// other value is one pipe, the candidates tried in order.
	Pipes string
	// MaxLanes is session_max_lanes: 0 is DefaultMaxLanes, 1 no lanes.
	MaxLanes int
	// Exit serves the links the server opens; nil refuses them.
	Exit coreapi.Exit
	// PeerExit makes the exit of a link this client provides under its
	// policy (§9.3); nil refuses LINK.
	PeerExit func(coreapi.LinkPolicy) (coreapi.Exit, error)
	// Puncher makes the direct paths of links; nil is relay only.
	Puncher coreapi.Puncher
	// CompressLimits are the receive limits of compressed streams (§7.4).
	CompressLimits CompressLimits
	// CanUpdate advertises the update capability; set it only when Update
	// can start an update, so that the server's interface offers it only then.
	CanUpdate bool
	// Update decides an update request of the server (§6) and starts the
	// update when it returns true; nil refuses them.
	Update func() bool
	// Health makes the runner of a session's checks (§5.3); nil runs none.
	Health func(coreapi.HealthSink) coreapi.HealthRunner
	// MaxConfig bounds a CONFIG snapshot; 0 is 16 MiB (§4.3).
	MaxConfig int
	// ResumeTimeout is how long a session that lost all its pipes waits for
	// one (§3.8); 0 is 30 s, negative is no resume. A resume_timeout_ms of
	// CONFIG replaces it from the next session on (§5).
	ResumeTimeout time.Duration
	// UsageInterval is how often a provider reports the direct traffic of
	// its links (§9.6); 0 is DefaultUsageInterval, negative is never.
	UsageInterval time.Duration
}

DialConfig is one server profile of npc.

type Dialer

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

Dialer establishes the sessions of a profile.

func NewDialer

func NewDialer(cfg DialConfig) *Dialer

NewDialer returns a Dialer for cfg.

func (*Dialer) Dial

func (d *Dialer) Dial(ctx context.Context) (coreapi.ClientSession, error)

Dial implements coreapi.Dialer: the candidates in order, the first that establishes.

func (*Dialer) Server

func (d *Dialer) Server() string

Server implements coreapi.Dialer.

type Options

type Options struct {
	// Session is what every snapshot carries as session_options (§5).
	Session wire.SessionOptions
	// Compress are the receive limits of compressed streams (§7.4).
	Compress CompressLimits
	// MaxLanes is session_max_lanes: 0 is DefaultMaxLanes, 1 no lanes.
	MaxLanes int
	// MaxPipes limits the pipes of one client over all its sessions
	// (client_max_pipes); 0 is no limit.
	MaxPipes int
	// ResumeTimeout is how long a session that lost all its pipes waits for
	// one (§3.8); 0 is 30 s, negative is no resume.
	ResumeTimeout time.Duration
	// ShapingSource keeps the bundle current until ctx ends, through set; nil
	// is none (§13).
	ShapingSource func(ctx context.Context, set func([]byte))
	// AdmitKey is the PSK of the exchange carrier (§13); nil offers none.
	AdmitKey []byte
}

Options are the settings of the entry that are not per client.

type OuterSessions

type OuterSessions struct {

	// Hosting reports tunnels or virtual services this npc serves through
	// the session; nil is none.
	Hosting func() bool

	// Keep holds the session open whatever the visitors need
	// (p2p_visitor_keep_server).
	Keep bool
	// contains filtered or unexported fields
}

OuterSessions keeps the one session of a pure visitor to the server: dialed on demand and closed when no visitor needs it (§9.4a).

func NewOuterSessions

func NewOuterSessions(d *Dialer) *OuterSessions

NewOuterSessions returns the holder of d's session.

func (*OuterSessions) Close

func (o *OuterSessions) Close()

Close ends the session.

func (*OuterSessions) Dial

Dial implements coreapi.Dialer with the session itself: a host keeps the session through it, and the visitors that share it keep theirs.

func (*OuterSessions) Hold

func (o *OuterSessions) Hold(keep bool, hosting func() bool)

Hold implements coreapi.Outer. It is called before the session is used.

func (*OuterSessions) Server

func (o *OuterSessions) Server() string

Server implements coreapi.Dialer.

func (*OuterSessions) Visitor

func (o *OuterSessions) Visitor(access []byte, mode string, relayIdle time.Duration, serverExit bool) coreapi.Visitor

Visitor implements coreapi.Outer.

type Store

type Store interface {
	// RangeClients calls fn for every client that can connect.
	RangeClients(fn func(coreapi.ClientRecord) bool)
}

Store is what the entry reads of the stored clients. The store stays the authority: the table below is an index of it.

type Visitor

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

Visitor implements coreapi.Visitor: the link, made on demand and made again when it ended.

func NewVisitor

func NewVisitor(cfg VisitorConfig) *Visitor

NewVisitor returns the access cfg describes.

func (*Visitor) Close

func (v *Visitor) Close() error

Close implements coreapi.Visitor.

func (v *Visitor) OpenLink(ctx context.Context, r coreapi.LinkRequest) (net.Conn, error)

OpenLink implements coreapi.Visitor.

type VisitorConfig

type VisitorConfig struct {
	Outer      *OuterSessions
	Access     []byte
	Mode       uint64        // wire.ConnRelay, ConnAuto or ConnDirect
	ServerExit bool          // ask for the server as the exit of the link
	RelayIdle  time.Duration // 0 is DefaultRelayIdle
	Tick       time.Duration // 0 is one second; tests
	Timeout    time.Duration // 0 is 15 s: making the link
}

VisitorConfig is one link a visitor reaches.

Jump to

Keyboard shortcuts

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