Documentation
¶
Overview ¶
Package relay implements the shared WireGuard packet forwarding data plane.
Index ¶
- Variables
- func IsProtocolViolation(err error) bool
- type Clock
- type DeadlinePolicy
- type Ingress
- type Lane
- type LaneConfig
- type LaneObserver
- type LaneRegistration
- type Packet
- type Receiver
- type ReceiverConfig
- type RemoteError
- type Scheduler
- func (s *Scheduler) CloseSession(ctx context.Context, reason protocol.CloseReason) error
- func (s *Scheduler) ObserveDeliveryReport(ctx context.Context, report protocol.DeliveryReport, receiveMicros uint64) error
- func (s *Scheduler) ObserveLaneAbandon(ctx context.Context, lane protocol.LaneGeneration) error
- func (s *Scheduler) ObserveTiming(laneID protocol.LaneID, generation uint64, pong protocol.TimingPong, ...)
- func (s *Scheduler) Register(ctx context.Context, registration LaneRegistration) error
- func (s *Scheduler) Remove(ctx context.Context, laneID protocol.LaneID, generation uint64) error
- func (s *Scheduler) RouteDeliveryReport(report protocol.DeliveryReport, complete func(bool)) bool
- func (s *Scheduler) Run(parent context.Context) (result error)
- type TransmissionStore
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidLane indicates missing resources or invalid lane generation metadata. ErrInvalidLane = errors.New("invalid relay lane") // ErrInvalidWireGuardPacket indicates a data frame without a structurally valid WireGuard packet. ErrInvalidWireGuardPacket = errors.New("invalid WireGuard packet") // ErrRemoteClosed indicates an intentional close received from the relay peer. ErrRemoteClosed = errors.New("relay session closed by peer") // ErrPingTimeout indicates that an admitted timing request received no response within its lane budget. ErrPingTimeout = errors.New("lane ping timed out") // ErrUnexpectedPong indicates a response that does not match the sole outstanding timing request. ErrUnexpectedPong = errors.New("unexpected lane pong") // ErrClockSyncRequired indicates data arrived before the generation's initial clock mapping. ErrClockSyncRequired = errors.New("initial clock sync required") // ErrUnexpectedFrame indicates a valid frame type used outside its protocol phase. ErrUnexpectedFrame = errors.New("unexpected in-session frame") // ErrLaneAbandoned marks scheduler cancellation that must discard the generation's buffered carrier bytes. ErrLaneAbandoned = errors.New("relay lane abandoned") )
var ( // ErrInvalidDeadlinePolicy indicates a zero or protocol-invalid packet lifetime. ErrInvalidDeadlinePolicy = errors.New("invalid packet deadline policy") // ErrCounterExhausted indicates that a direction-local identifier space is exhausted. ErrCounterExhausted = errors.New("relay counter exhausted") // ErrInvalidPacket indicates inconsistent relay packet metadata. ErrInvalidPacket = errors.New("invalid relay packet") )
var ( // ErrInvalidReceiver indicates missing endpoint, clock, or deduplication configuration. ErrInvalidReceiver = errors.New("invalid relay receiver") // ErrInvalidPacketDeadline indicates a deadline that cannot describe bounded in-flight work. ErrInvalidPacketDeadline = errors.New("invalid packet deadline") // ErrEndpointFailure indicates that a relay UDP endpoint could not be created, read, or written. ErrEndpointFailure = errors.New("relay UDP endpoint failure") )
var ( // ErrInvalidScheduler indicates missing ingress state. ErrInvalidScheduler = errors.New("invalid relay scheduler") // ErrInvalidRegistration indicates incomplete lane scheduling metadata. ErrInvalidRegistration = errors.New("invalid lane registration") // ErrStaleLane indicates a non-increasing connection generation. ErrStaleLane = errors.New("stale lane generation") // ErrNoActiveLane indicates that no carrier can accept a control frame. ErrNoActiveLane = errors.New("no active relay lane") )
var ( // ErrInvalidTransmissionStore indicates invalid lane transmission limits or state. ErrInvalidTransmissionStore = errors.New("invalid transmission store") // ErrInvalidTransmission indicates inconsistent retained packet metadata. ErrInvalidTransmission = errors.New("invalid transmission") // ErrInvalidDeliveryReport indicates cumulative progress that cannot describe the sent prefix. ErrInvalidDeliveryReport = errors.New("invalid delivery report") )
Functions ¶
func IsProtocolViolation ¶
IsProtocolViolation reports deterministic peer input that reconnecting the same implementation cannot repair.
Types ¶
type Clock ¶
type Clock interface {
NowMicros() uint64
}
Clock supplies process-local monotonic timestamps in protocol microseconds.
type DeadlinePolicy ¶
DeadlinePolicy assigns bounded lifetimes to WireGuard packet classes.
func (DeadlinePolicy) Lifetime ¶
func (p DeadlinePolicy) Lifetime(kind wgpacket.Kind) time.Duration
Lifetime returns the configured lifetime for kind.
func (DeadlinePolicy) Validate ¶
func (p DeadlinePolicy) Validate() error
Validate verifies that both lifetimes fit the wire protocol.
type Ingress ¶
type Ingress struct {
// contains filtered or unexported fields
}
Ingress reads accepted WireGuard datagrams into a bounded session queue.
func NewIngress ¶
func NewIngress(endpoint datagram.Endpoint, queue *packetqueue.Queue[Packet], clock Clock, deadlines DeadlinePolicy) (*Ingress, error)
NewIngress returns a UDP ingress using the process wall clock for local queue deadlines.
type Lane ¶
type Lane struct {
// contains filtered or unexported fields
}
Lane runs one full-duplex carrier generation with one carrier writer.
func NewLane ¶
func NewLane(config LaneConfig) (*Lane, error)
NewLane validates config and returns one relay lane generation.
func (*Lane) SendControl ¶
SendControl queues one fixed control frame and invokes onSent after carrier write completion.
func (*Lane) ValidateProbeProgress ¶
ValidateProbeProgress reports whether cumulative feedback matches probes exposed to this generation's carrier writer.
type LaneConfig ¶
type LaneConfig struct {
Carrier carrier.Conn
Receiver *Receiver
Store *TransmissionStore
Clock Clock
Observer LaneObserver
// SessionClose handles client shutdown frames. A nil callback rejects them in this lane direction.
SessionClose func(protocol.CloseReason)
SessionFailure func()
LaneID protocol.LaneID
Generation uint64
InitialFrames []protocol.Frame
RequireClockSync bool
ControlCapacity int
ReportInterval time.Duration
PingInterval time.Duration
PingTimeout time.Duration
WriteTimeout time.Duration
ProbeInterval time.Duration
ProbeSize int
}
LaneConfig contains the resources and immutable identity for one connection generation.
type LaneObserver ¶
type LaneObserver interface {
ObserveDeliveryReport(context.Context, protocol.DeliveryReport, uint64) error
ObserveTiming(protocol.LaneID, uint64, protocol.TimingPong, uint64)
ObserveLaneAbandon(context.Context, protocol.LaneGeneration) error
RouteDeliveryReport(protocol.DeliveryReport, func(bool)) bool
}
LaneObserver receives cumulative lane feedback parsed by any carrier reader.
type LaneRegistration ¶
type LaneRegistration struct {
LaneID protocol.LaneID
Generation uint64
PathGroupID protocol.PathGroupID
Store *TransmissionStore
Abandon context.CancelFunc
SendControl func(protocol.Frame, func()) bool
ValidateProbeProgress func(uint64, uint64) bool
}
LaneRegistration makes one lane generation eligible for packet scheduling.
type Receiver ¶
type Receiver struct {
// contains filtered or unexported fields
}
Receiver deduplicates and delivers one session direction across all lanes.
func NewReceiver ¶
func NewReceiver(config ReceiverConfig) (*Receiver, error)
NewReceiver validates config and returns session-shared inbound state.
func (*Receiver) Deliver ¶
Deliver deduplicates, deadline-checks, and writes one validated packet to UDP.
func (*Receiver) UpdateClock ¶
UpdateClock replaces the session mapping with one authenticated lane sample.
func (*Receiver) ValidateDeadline ¶
ValidateDeadline verifies that deadline maps into the receiver clock and respects the protocol lifetime bound.
type ReceiverConfig ¶
type ReceiverConfig struct {
Endpoint datagram.Endpoint
Clock Clock
ClockMapping clockmap.Mapping
DeduplicationSize int
UDPWriteTimeout time.Duration
}
ReceiverConfig defines session-shared inbound delivery state.
type RemoteError ¶
type RemoteError struct {
Value protocol.ErrorFrame
}
RemoteError preserves one machine-readable in-session error received from the peer.
func (*RemoteError) Error ¶
func (e *RemoteError) Error() string
Error returns the stable remote diagnostic without discarding its class or scope.
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler assigns session packets to dynamically registered lanes.
func NewScheduler ¶
func NewScheduler(ingress *packetqueue.Queue[Packet]) (*Scheduler, error)
NewScheduler validates resources and returns an empty multipath scheduler.
func (*Scheduler) CloseSession ¶
CloseSession writes one graceful close over an active lane and waits for carrier write completion.
func (*Scheduler) ObserveDeliveryReport ¶
func (s *Scheduler) ObserveDeliveryReport(ctx context.Context, report protocol.DeliveryReport, receiveMicros uint64) error
ObserveDeliveryReport synchronously validates and applies cumulative parsing feedback.
func (*Scheduler) ObserveLaneAbandon ¶
ObserveLaneAbandon synchronously applies one generation-specific peer abandonment request.
func (*Scheduler) ObserveTiming ¶
func (s *Scheduler) ObserveTiming(laneID protocol.LaneID, generation uint64, pong protocol.TimingPong, receiveMicros uint64)
ObserveTiming applies one lane RTT observation without blocking a carrier reader.
func (*Scheduler) Register ¶
func (s *Scheduler) Register(ctx context.Context, registration LaneRegistration) error
Register synchronously adds a lane or replaces it with a higher generation.
func (*Scheduler) Remove ¶
Remove synchronously makes one exact lane generation ineligible and drains its retained backlog.
func (*Scheduler) RouteDeliveryReport ¶
func (s *Scheduler) RouteDeliveryReport(report protocol.DeliveryReport, complete func(bool)) bool
RouteDeliveryReport routes cumulative feedback and invokes onAccepted after the carrier write completes.
type TransmissionStore ¶
type TransmissionStore struct {
// contains filtered or unexported fields
}
TransmissionStore owns queued and sent-unreported work for one lane generation.
func NewTransmissionStore ¶
func NewTransmissionStore(limits packetqueue.Limits) (*TransmissionStore, error)
NewTransmissionStore returns an empty bounded store using the process wall clock for deadline decisions.
func NewTransmissionStoreWithBudget ¶
func NewTransmissionStoreWithBudget(limits packetqueue.Limits, budget *retention.Budget) (*TransmissionStore, error)
NewTransmissionStoreWithBudget returns an empty store sharing an aggregate retention budget.
func (*TransmissionStore) Done ¶
func (s *TransmissionStore) Done() <-chan struct{}
Done closes when the generation store is drained.
func (*TransmissionStore) Ready ¶
func (s *TransmissionStore) Ready() <-chan struct{}
Ready returns a coalesced notification for available queued work.