n4

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: BSD-3-Clause Imports: 15 Imported by: ? 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 n4 serves HTTP/3 over an engine's admitted peer graph.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewServer

func NewServer(e *engine.Engine, tlsConfig *tls.Config, p Policy, h http.Handler) *http3.Server

NewServer constructs HTTP/3 admission around e and h. Serve it with srv.Serve(e.PacketConn()). Connections without live leases close immediately; each request checks the lease again and returns 403 after revocation. Validate p first. An invalid policy closes connections and refuses requests.

func PeerFromContext

func PeerFromContext(ctx context.Context) (protocol.NodeKey, bool)

PeerFromContext returns the admitted connection's node key. Contexts outside NewServer return a zero key and false; callers still check current authority.

func PinnedTLS

func PinnedTLS(spkiSHA256Base64 string) *tls.Config

PinnedTLS authenticates TLS 1.3 peers by an already trusted base64 SHA-256 SPKI digest. Malformed pins, absent certificates and mismatches fail closed. Callers set ALPN. Certificate chain and hostname trust come from the pin.

Types

type LossProfile

type LossProfile string

LossProfile selects "both", "no_lower", "loss_thresh", or "off". Unknown profiles are refused by Policy.Validate.

type Policy

type Policy struct {
	Loss                              LossProfile
	InitialStreamWindow, StreamWindow uint64
	ACKDecimation                     bool
	ScaledGapLimit                    bool
}

Policy selects QUIC loss handling and receive credit. A zero StreamWindow retains default credit; otherwise InitialStreamWindow is positive and no greater than StreamWindow. Connection credit is 1.5 times stream credit.

func DefaultClientPolicy

func DefaultClientPolicy() Policy

DefaultClientPolicy returns BBRv3 with both loss switches, ACK decimation, scaled gaps and stream credit growing from 4 MiB to 128 MiB.

func DefaultServerPolicy

func DefaultServerPolicy() Policy

DefaultServerPolicy returns both loss switches and scaled gaps, default receive credit and no ACK decimation.

func (Policy) QUICConfig

func (p Policy) QUICConfig() *quic.Config

QUICConfig returns a fresh BBRv3 configuration. Call Validate before using caller-supplied policies; zero credit fields retain quic-go's defaults.

func (Policy) Validate

func (p Policy) Validate() error

Validate refuses unknown loss profiles, maximum credit outside 4-128 MiB (except zero), and initial credit inconsistent with the maximum.

type Transport

type Transport struct {
	Engine  *engine.Engine
	Policy  Policy
	Resolve func(host string) (k protocol.NodeKey, spkiSHA256Base64 string, ok bool)
	// contains filtered or unexported fields
}

Transport dials resolved node identities using one shared QUIC transport. Configure fields before use and keep them unchanged. Resolve is concurrent and supplies an already trusted SPKI pin; identity is the node key and pin. A Transport must not be copied after use. Close leaves its engine owned by the caller. Requests carry their original headers without added credentials.

func (*Transport) Close

func (t *Transport) Close() error

Close closes all host transports and the shared QUIC transport, returning their joined errors. It is idempotent and never closes the engine's adapter.

func (*Transport) CloseIdleConnections

func (t *Transport) CloseIdleConnections()

CloseIdleConnections releases idle HTTP/3 connections for every resolved host. Active requests and the shared engine remain available.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip sends an HTTPS request to a resolved peer. Unresolved hosts fail before socket access. A bodyless GET or HEAD whose dial or handshake fails retries once only after Resolve supplies a different node key or SPKI pin, within the handshake timeout. That includes the re-dial that follows a cached connection found dead. A request that fails on an established connection returns its error at once. Other requests are never replayed by this transport.

Jump to

Keyboard shortcuts

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