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
- func ConnModeOf(mode string) uint64
- func QUICConfig(base *quic.Config) *quic.Config
- type Acceptor
- func (a *Acceptor) ClientChanged(r coreapi.ClientRecord)
- func (a *Acceptor) ClientRemoved(id int)
- func (a *Acceptor) Close() error
- func (a *Acceptor) Forwarding(trusted []netip.Prefix, header string) coreapi.Forwarding
- func (a *Acceptor) HTTPCarriers(next http.Handler, f coreapi.Forwarding) (http.Handler, error)
- func (a *Acceptor) Kick(id int, auth bool)
- func (a *Acceptor) QUICConfig(base *quic.Config) *quic.Config
- func (a *Acceptor) RevokeLinks(match func(tunnel, visitor, provider int) bool)
- func (a *Acceptor) Serve(ctx context.Context, c net.Conn, carrier string)
- func (a *Acceptor) ServeMixed(ctx context.Context, c net.Conn, carrier string, ...)
- func (a *Acceptor) ServeQUIC(ctx context.Context, qc *quic.Conn)
- func (a *Acceptor) ServeTerminated(ctx context.Context, tc *tls.Conn, head []byte, carrier string)
- func (a *Acceptor) SetShaping(b []byte)
- func (a *Acceptor) Stall(ctx context.Context, c net.Conn)
- func (a *Acceptor) Start(ctx context.Context, h coreapi.Hooks) error
- func (a *Acceptor) WebSocket(legacy http.Handler, f coreapi.Forwarding) (http.Handler, error)
- func (a *Acceptor) WebSocketAnyProtocol(next http.Handler, f coreapi.Forwarding) (http.Handler, error)
- type CompressLimits
- type DialConfig
- type Dialer
- type Options
- type OuterSessions
- func (o *OuterSessions) Close()
- func (o *OuterSessions) Dial(ctx context.Context) (coreapi.ClientSession, error)
- func (o *OuterSessions) Hold(keep bool, hosting func() bool)
- func (o *OuterSessions) Server() string
- func (o *OuterSessions) Visitor(access []byte, mode string, relayIdle time.Duration, serverExit bool) coreapi.Visitor
- type Store
- type Visitor
- type VisitorConfig
Constants ¶
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).
const DefaultMaxLanes = 16
DefaultMaxLanes is the lanes accepted per pipe: more bring next to nothing.
const ( // DefaultRelayIdle is how long a relay stands by after the direct path // came up (§9.4a). DefaultRelayIdle = time.Minute )
const ( // DefaultUsageInterval is how often a provider reports. DefaultUsageInterval = time.Minute )
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 ¶
ConnModeOf is the wire value of a section's conn_mode.
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 ¶
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 ¶
ClientRemoved implements coreapi.Entry.
func (*Acceptor) Forwarding ¶
Forwarding implements coreapi.Entry.
func (*Acceptor) HTTPCarriers ¶
HTTPCarriers implements coreapi.Entry.
func (*Acceptor) QUICConfig ¶
QUICConfig implements coreapi.Entry.
func (*Acceptor) RevokeLinks ¶
RevokeLinks 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 ¶
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 ¶
ServeTerminated implements coreapi.Entry.
func (*Acceptor) SetShaping ¶
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) WebSocket ¶
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.
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) Dial ¶
func (o *OuterSessions) Dial(ctx context.Context) (coreapi.ClientSession, error)
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.
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.
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.