v2

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: AGPL-3.0 Imports: 15 Imported by: 1 module, 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 v2 defines the binary relay contract for sender-authenticated shares. Endpoint wiring is deliberately outside this package so v1 cannot silently reinterpret a v2 frame or select a runtime suite with an adapter flag.

Index

Constants

View Source
const (
	CapacityWaitMagic           = "WS2Z"
	CapacityWaitBytes           = 8 + RelaySessionIDBytes + 4
	MaxCapacityWaitMilliseconds = 60_000
)
View Source
const (
	DeliveryConsumedMagic = "WS2B"
	DeliveryConsumedBytes = deliveryTotalsBytes
)
View Source
const (
	SettlementNoticeMagic = "WS2N"
	SettlementNoticeBytes = deliveryTotalsBytes
	SettlementAckMagic    = "WS2S"
	SettlementAckBytes    = deliveryTotalsBytes
)
View Source
const (
	SessionRetiredMagic = "WS2F"

	RegisterInitBytes             = 4 + 1 + 1 + 2 + ShareIDBytes + ShareInstanceBytes + PKHashBytes + DigestBytes + DigestBytes
	ChallengeBytes                = 4 + 1 + 1 + 2 + ChallengeIDBytes + ChallengeNonceBytes + 8
	RegisterProofBytes            = 4 + 1 + 1 + 2 + SenderPublicKeyBytes + SignatureBytes
	RegisteredBytes               = 4 + 1 + 3 + ShareIDBytes + ShareInstanceBytes + DigestBytes
	ResumeCredentialBytes         = 4 + 1 + 3 + ResumeTokenBytes
	StopInitBytes                 = 4 + 1 + 3 + ShareIDBytes + ShareInstanceBytes + PKHashBytes + RelayIdentityBytes + StopIDBytes
	StopProofBytes                = 4 + 1 + 3 + SenderPublicKeyBytes + SignatureBytes
	StoppedBytes                  = 4 + 1 + 3 + StopIDBytes
	JoinBytes                     = 4 + 1 + 3 + ShareIDBytes
	SessionRetiredBytes           = 4 + 1 + 3 + RelaySessionIDBytes
	DescriptorUploadHeaderBytes   = 4 + 1 + 3 + 4
	DescriptorDeliveryHeaderBytes = 4 + 1 + 3 + RelaySessionIDBytes + 4
	ErrorBytes                    = 4 + 1 + 1 + 2 + 4
	OpaqueRouteHeaderBytes        = 4 + 1 + 3 + RelaySessionIDBytes + 4
)
View Source
const (
	ConnectionProbeMagic    = "WS2H"
	ConnectionProbeAckMagic = "WS2A"
	ConnectionProbeBytes    = 16

	// Clients probe at this cadence whether or not earlier probes were
	// acknowledged, so an acknowledgement queued behind content never silences
	// the client's direction of the connection.
	ConnectionProbeInterval = 15 * time.Second
	// Either side fails a connection after this long without an accepted inbound
	// frame. Three intervals absorb a probe delayed behind one bounded physical
	// write plus network delay without treating queue pressure as loss.
	ConnectionSilenceTimeout = 45 * time.Second
)
View Source
const (
	ReceiveCreditMagic = "WS2B"
	ReceiveCreditBytes = 8 + RelaySessionIDBytes + 4 + 4
	// The receive window holds a full default eight-block response pipeline,
	// including envelopes and controls, without adding a round trip per block.
	ReceiveWindowFrames      = 256
	ReceiveWindowBytes       = 16 << 20
	ReceiveCreditBatchFrames = ReceiveWindowFrames / 4
)
View Source
const (
	SessionCreditMagic   = "WS2W"
	SessionAdmittedMagic = "WS2M"
	SessionCreditBytes   = 8 + RelaySessionIDBytes + 4 + 4
	SessionAdmittedBytes = 8 + RelaySessionIDBytes

	// Every source reserves both budgets, including the route header, before
	// writing a routed frame. Delivery clients start at zero in both roles;
	// these bounds constrain WS2W grants, not an implicit startup allowance.
	SenderWindowFrames = 64
	SenderWindowBytes  = 4 << 20
)
View Source
const (
	WireVersion              = byte(2)
	Suite                    = byte(2)
	ShareIDBytes             = 12
	ShareInstanceBytes       = 16
	PKHashBytes              = 16
	DigestBytes              = sha256.Size
	RelayIdentityBytes       = sha256.Size
	ChallengeIDBytes         = 16
	ChallengeNonceBytes      = 32
	SenderPublicKeyBytes     = 32
	SignatureBytes           = 64
	ResumeTokenBytes         = 32
	StopIDBytes              = 16
	RelaySessionIDBytes      = 8
	MaxDescriptorBytes       = 16 << 10
	MaxOpaqueCiphertextBytes = 65_536
)
View Source
const (
	ChallengeTTL = 30 * time.Second
)
View Source
const DeliveryJoinBytes = JoinBytes + ReceiveCapacityBytes
View Source
const DeliveryRegisterInitBytes = RegisterInitBytes + ReceiveCapacityBytes
View Source
const ReceiveCapacityBytes = 16

Explicit staged codecs: runtime activation requires cumulative consumption and settlement together. Neither parser accepts the live capacity-less handshake.

View Source
const ShareRouteQuery = networkendpoint.ShareRouteQuery
View Source
const WebSocketPath = networkendpoint.WebSocketPath

Variables

View Source
var (
	ErrMalformed         = errors.New("relay v2: malformed frame")
	ErrIdentity          = errors.New("relay v2: invalid identity")
	ErrMode              = errors.New("relay v2: unsupported registration mode")
	ErrPurpose           = errors.New("relay v2: invalid challenge purpose")
	ErrProof             = errors.New("relay v2: invalid sender proof")
	ErrChallengeExpired  = errors.New("relay v2: challenge expired")
	ErrChallengeConsumed = errors.New("relay v2: challenge already consumed")
	ErrChallengeBudget   = errors.New("relay v2: challenge budget exhausted")
)
View Source
var ErrRelayEndpointWhitespace = fmt.Errorf("%w: %w", ErrIdentity, networkendpoint.ErrWhitespace)

Functions

func DeliveryRegistrationPreimage

func DeliveryRegistrationPreimage(init DeliveryRegisterInit, challenge Challenge, relay RelayIdentity) ([]byte, error)

The capacity is signed for this handshake, but never becomes share ownership.

func RegistrationPreimage

func RegistrationPreimage(init RegisterInit, challenge Challenge, relayIdentity RelayIdentity) ([]byte, error)

func StopPreimage

func StopPreimage(init StopInit, challenge Challenge) ([]byte, error)

Types

type AuthorizedDescriptorUpload

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

AuthorizedDescriptorUpload proves publication authority for bounded opaque bytes, not the validity of the end-to-end object. Receivers own object authentication.

func AuthorizeDescriptorUpload

func AuthorizeDescriptorUpload(init RegisterInit, authority SenderAuthority, upload DescriptorUpload) (AuthorizedDescriptorUpload, error)

AuthorizeDescriptorUpload binds WS2U bytes to the authenticated registration digest so object formats can evolve without changing relay admission.

func (AuthorizedDescriptorUpload) ObjectFor

func (d AuthorizedDescriptorUpload) ObjectFor(init RegisterInit) ([]byte, bool)

type CapacityWait

type CapacityWait struct {
	RelaySessionID RelaySessionID
	Direction      uint8
	Milliseconds   uint32
}

CapacityWait is advisory; it cannot renew authority or suppress liveness checks. Each direction has its own lease, so a clear cannot erase opposite-flow pressure.

func ParseCapacityWait

func ParseCapacityWait(encoded []byte) (CapacityWait, error)

func (CapacityWait) MarshalBinary

func (f CapacityWait) MarshalBinary() ([]byte, error)

type Challenge

type Challenge struct {
	Purpose              ChallengePurpose
	ID                   ChallengeID
	Nonce                ChallengeNonce
	ExpiresAtUnixSeconds uint64
}

func ParseChallenge

func ParseChallenge(encoded []byte) (Challenge, error)

func (Challenge) MarshalBinary

func (f Challenge) MarshalBinary() ([]byte, error)

func (Challenge) Validate

func (f Challenge) Validate() error

type ChallengeBinding

type ChallengeBinding [sha256.Size]byte

func RegistrationChallengeBinding

func RegistrationChallengeBinding(init RegisterInit, relayIdentity RelayIdentity) (ChallengeBinding, error)

func StopChallengeBinding

func StopChallengeBinding(init StopInit) (ChallengeBinding, error)

type ChallengeID

type ChallengeID [ChallengeIDBytes]byte

func ChallengeIDFromBytes

func ChallengeIDFromBytes(raw []byte) (ChallengeID, error)

type ChallengeLedger

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

ChallengeLedger is a bounded, one-use owner. Take removes a challenge before proof verification, so an invalid signature cannot turn it into a retry oracle.

func NewChallengeLedger

func NewChallengeLedger(config ChallengeLedgerConfig) (*ChallengeLedger, error)

func (*ChallengeLedger) AuthenticateRegistration

func (l *ChallengeLedger) AuthenticateRegistration(id ChallengeID, init RegisterInit, relayIdentity RelayIdentity, proof RegisterProof) (SenderAuthority, error)

func (*ChallengeLedger) AuthenticateStop

func (l *ChallengeLedger) AuthenticateStop(id ChallengeID, init StopInit, relayIdentity RelayIdentity, proof StopProof) (StopAuthority, error)

func (*ChallengeLedger) Issue

func (l *ChallengeLedger) Issue(purpose ChallengePurpose, binding ChallengeBinding) (Challenge, error)

func (*ChallengeLedger) Take

type ChallengeLedgerConfig

type ChallengeLedgerConfig struct {
	Capacity int
	Random   io.Reader
	Now      func() time.Time
}

type ChallengeNonce

type ChallengeNonce [ChallengeNonceBytes]byte

type ChallengePurpose

type ChallengePurpose uint8
const (
	ChallengeRegister ChallengePurpose = iota
	ChallengeResume
	ChallengeStop
)

type ConnectionProbe

type ConnectionProbe struct{ Nonce uint64 }

ConnectionProbe is connection-local liveness traffic, never a routed session frame. The relay answers with the newest nonce it received; every accepted inbound frame, not only an acknowledgement, proves the peer is alive.

func ParseConnectionProbe

func ParseConnectionProbe(encoded []byte) (ConnectionProbe, error)

func (ConnectionProbe) MarshalBinary

func (f ConnectionProbe) MarshalBinary() ([]byte, error)

type ConnectionProbeAck

type ConnectionProbeAck struct{ Nonce uint64 }

func ParseConnectionProbeAck

func ParseConnectionProbeAck(encoded []byte) (ConnectionProbeAck, error)

func (ConnectionProbeAck) MarshalBinary

func (f ConnectionProbeAck) MarshalBinary() ([]byte, error)

type DeliveryConsumed

type DeliveryConsumed deliveryTotals

DeliveryConsumed reports a cumulative prefix of complete WS2O envelopes taken by the destination application. The authenticated connection supplies its generation and receive direction; counters never reset within that flow. This contract is staged for the coordinated delivery-protocol cutover and is not interchangeable with the current runtime's ReceiveCredit delta message.

func ParseDeliveryConsumed

func ParseDeliveryConsumed(encoded []byte) (DeliveryConsumed, error)

func (DeliveryConsumed) MarshalBinary

func (f DeliveryConsumed) MarshalBinary() ([]byte, error)

type DeliveryJoin

type DeliveryJoin struct {
	ShareID         ShareID
	ReceiveCapacity ReceiveCapacity
}

func ParseDeliveryJoin

func ParseDeliveryJoin(encoded []byte) (DeliveryJoin, error)

func (DeliveryJoin) MarshalBinary

func (f DeliveryJoin) MarshalBinary() ([]byte, error)

type DeliveryRegisterInit

type DeliveryRegisterInit struct {
	Registration    RegisterInit
	ReceiveCapacity ReceiveCapacity
}

func ParseDeliveryRegisterInit

func ParseDeliveryRegisterInit(encoded []byte) (DeliveryRegisterInit, error)

func (DeliveryRegisterInit) MarshalBinary

func (f DeliveryRegisterInit) MarshalBinary() ([]byte, error)

type DescriptorDelivery

type DescriptorDelivery struct {
	RelaySessionID RelaySessionID
	Object         []byte
}

func ParseDescriptorDelivery

func ParseDescriptorDelivery(encoded []byte) (DescriptorDelivery, error)

func (DescriptorDelivery) MarshalBinary

func (f DescriptorDelivery) MarshalBinary() ([]byte, error)

type DescriptorUpload

type DescriptorUpload struct{ Object []byte }

func ParseDescriptorUpload

func ParseDescriptorUpload(encoded []byte) (DescriptorUpload, error)

func (DescriptorUpload) MarshalBinary

func (f DescriptorUpload) MarshalBinary() ([]byte, error)

type Digest

type Digest [DigestBytes]byte

func DigestFromBytes

func DigestFromBytes(raw []byte) (Digest, error)

type ErrorCode

type ErrorCode uint16
const (
	ErrorMalformed ErrorCode = iota + 1
	ErrorUnsupportedMode
	ErrorShareIDCollision
	ErrorAlreadyRegistered
	ErrorChallengeExpired
	ErrorInvalidProof
	ErrorDescriptorInvalid
	ErrorNotFound
	ErrorStarting
	ErrorAdmission
	ErrorStopped
	ErrorResumeStale
	ErrorAccessDenied
	ErrorAccessUnavailable
)

type ErrorFrame

type ErrorFrame struct {
	Code       ErrorCode
	RetryAfter time.Duration
}

func ParseError

func ParseError(encoded []byte) (ErrorFrame, error)

func (ErrorFrame) MarshalBinary

func (f ErrorFrame) MarshalBinary() ([]byte, error)

type Join

type Join struct{ ShareID ShareID }

func ParseJoin

func ParseJoin(encoded []byte) (Join, error)

func (Join) MarshalBinary

func (f Join) MarshalBinary() ([]byte, error)

type OpaqueRoute

type OpaqueRoute struct {
	RelaySessionID RelaySessionID
	Ciphertext     []byte
}

OpaqueRoute is the only post-join relay envelope. The authenticated WebSocket role supplies direction; no inner message discriminator is visible.

func ParseOpaqueRoute

func ParseOpaqueRoute(encoded []byte) (OpaqueRoute, error)

func (OpaqueRoute) MarshalBinary

func (f OpaqueRoute) MarshalBinary() ([]byte, error)

type PKHash

type PKHash [PKHashBytes]byte

func PKHashFromBytes

func PKHashFromBytes(raw []byte) (PKHash, error)

type ReceiveCapacity

type ReceiveCapacity struct {
	Frames       uint64
	EncodedBytes uint64
}

ReceiveCapacity bounds a connection's outstanding full WS2O frames and bytes. These are independent positive limits, not cumulative envelope totals.

func (ReceiveCapacity) Validate

func (c ReceiveCapacity) Validate() error

type ReceiveCredit

type ReceiveCredit struct {
	RelaySessionID RelaySessionID
	Frames         uint32
	Bytes          uint32
}

ReceiveCredit is the legacy Go relay/browser credit dialect. The Go delivery runtime instead declares ReceiveCapacity and reports DeliveryConsumed. The first grant opens an initially empty window; subsequent grants return capacity only after the application takes frames out of that storage.

func ParseReceiveCredit

func ParseReceiveCredit(encoded []byte) (ReceiveCredit, error)

func (ReceiveCredit) MarshalBinary

func (f ReceiveCredit) MarshalBinary() ([]byte, error)

type RegisterInit

type RegisterInit struct {
	Mode             RegistrationMode
	ShareID          ShareID
	ShareInstance    ShareInstance
	PKHash           PKHash
	DescriptorDigest Digest
	ResumeTokenHash  Digest
}

func ParseRegisterInit

func ParseRegisterInit(encoded []byte) (RegisterInit, error)

func (RegisterInit) MarshalBinary

func (f RegisterInit) MarshalBinary() ([]byte, error)

func (RegisterInit) Validate

func (f RegisterInit) Validate() error

type RegisterProof

type RegisterProof struct {
	Mode            RegistrationMode
	SenderPublicKey [SenderPublicKeyBytes]byte
	Signature       [SignatureBytes]byte
}

func NewDeliveryRegisterProof

func NewDeliveryRegisterProof(init DeliveryRegisterInit, challenge Challenge, relay RelayIdentity, key ed25519.PrivateKey) (RegisterProof, error)

NewDeliveryRegisterProof binds the capacity used by the connection ledger to the same fresh challenge and authority as REGISTER or RESUME.

func NewRegisterProof

func NewRegisterProof(init RegisterInit, challenge Challenge, relayIdentity RelayIdentity, senderPrivateKey ed25519.PrivateKey) (RegisterProof, error)

func ParseRegisterProof

func ParseRegisterProof(encoded []byte) (RegisterProof, error)

func (RegisterProof) MarshalBinary

func (f RegisterProof) MarshalBinary() ([]byte, error)

type Registered

type Registered struct {
	ShareID          ShareID
	ShareInstance    ShareInstance
	DescriptorDigest Digest
}

func ParseRegistered

func ParseRegistered(encoded []byte) (Registered, error)

func (Registered) MarshalBinary

func (f Registered) MarshalBinary() ([]byte, error)

type RegistrationMode

type RegistrationMode uint8
const (
	RegistrationFresh RegistrationMode = iota
	RegistrationResume
)

type RelayEndpoint

type RelayEndpoint struct {
	DialURL     string
	IdentityURL string
	Identity    RelayIdentity
}

func NormalizeRelayEndpoint

func NormalizeRelayEndpoint(raw string) (RelayEndpoint, error)

func RelayEndpointForShare

func RelayEndpointForShare(raw string, shareID ShareID) (RelayEndpoint, error)

RelayEndpointForShare adds the public upgrade-routing hint without changing the endpoint identity authenticated by REGISTER, RESUME and STOP.

type RelayIdentity

type RelayIdentity [RelayIdentityBytes]byte

func RelayIdentityFromBytes

func RelayIdentityFromBytes(raw []byte) (RelayIdentity, error)

type RelaySessionID

type RelaySessionID [RelaySessionIDBytes]byte

func RelaySessionIDFromBytes

func RelaySessionIDFromBytes(raw []byte) (RelaySessionID, error)

type ResumeCredential

type ResumeCredential struct{ Token ResumeToken }

func ParseResumeCredential

func ParseResumeCredential(encoded []byte) (ResumeCredential, error)

func (ResumeCredential) MarshalBinary

func (f ResumeCredential) MarshalBinary() ([]byte, error)

type ResumeToken

type ResumeToken [ResumeTokenBytes]byte

type SenderAuthority

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

func (SenderAuthority) Authorizes

func (a SenderAuthority) Authorizes(init RegisterInit) bool

type SessionAdmitted

type SessionAdmitted struct{ RelaySessionID RelaySessionID }

SessionAdmitted is the registered sender's decision to retain a provisional relay session. The relay does not interpret the opaque E2E handshake itself.

func ParseSessionAdmitted

func ParseSessionAdmitted(encoded []byte) (SessionAdmitted, error)

func (SessionAdmitted) MarshalBinary

func (f SessionAdmitted) MarshalBinary() ([]byte, error)

type SessionCredit

type SessionCredit struct {
	RelaySessionID RelaySessionID
	Frames         uint32
	Bytes          uint32
}

SessionCredit grants independent frame and byte deltas for one direction of a relay session. Neither routing nor heartbeat controls consume these grants.

func ParseSessionCredit

func ParseSessionCredit(encoded []byte) (SessionCredit, error)

func (SessionCredit) MarshalBinary

func (f SessionCredit) MarshalBinary() ([]byte, error)

type SessionRetired

type SessionRetired struct{ RelaySessionID RelaySessionID }

SessionRetired is an allocation-free relay lifecycle signal. It carries no E2E authority; clients apply it only to an already materialized exact channel.

func ParseSessionRetired

func ParseSessionRetired(encoded []byte) (SessionRetired, error)

func (SessionRetired) MarshalBinary

func (f SessionRetired) MarshalBinary() ([]byte, error)

type SettlementAck

type SettlementAck deliveryTotals

SettlementAck confirms the notice's exact totals have been consumed or discarded. It cannot reopen a session or stand in for ordinary WS2B feedback. The authenticated socket supplies the destination generation and direction.

func ParseSettlementAck

func ParseSettlementAck(encoded []byte) (SettlementAck, error)

func (SettlementAck) MarshalBinary

func (f SettlementAck) MarshalBinary() ([]byte, error)

type SettlementNotice

type SettlementNotice deliveryTotals

SettlementNotice freezes a retired flow's submitted WS2O totals. The relay orders it after those frames, after revoking grants and discarding unsent data.

func ParseSettlementNotice

func ParseSettlementNotice(encoded []byte) (SettlementNotice, error)

func (SettlementNotice) MarshalBinary

func (f SettlementNotice) MarshalBinary() ([]byte, error)

type ShareID

type ShareID [ShareIDBytes]byte

func ShareIDFromBytes

func ShareIDFromBytes(raw []byte) (ShareID, error)

type ShareInstance

type ShareInstance [ShareInstanceBytes]byte

func ShareInstanceFromBytes

func ShareInstanceFromBytes(raw []byte) (ShareInstance, error)

type StopAuthority

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

func (StopAuthority) Authorizes

func (a StopAuthority) Authorizes(init StopInit) bool

type StopID

type StopID [StopIDBytes]byte

type StopInit

type StopInit struct {
	ShareID       ShareID
	ShareInstance ShareInstance
	PKHash        PKHash
	RelayIdentity RelayIdentity
	StopID        StopID
}

func ParseStopInit

func ParseStopInit(encoded []byte) (StopInit, error)

func (StopInit) MarshalBinary

func (f StopInit) MarshalBinary() ([]byte, error)

func (StopInit) Validate

func (f StopInit) Validate() error

type StopProof

type StopProof struct {
	SenderPublicKey [SenderPublicKeyBytes]byte
	Signature       [SignatureBytes]byte
}

func NewStopProof

func NewStopProof(init StopInit, challenge Challenge, senderPrivateKey ed25519.PrivateKey) (StopProof, error)

func ParseStopProof

func ParseStopProof(encoded []byte) (StopProof, error)

func (StopProof) MarshalBinary

func (f StopProof) MarshalBinary() ([]byte, error)

type Stopped

type Stopped struct{ StopID StopID }

Stopped confirms durable permanent revocation and unsubmitted-queue discard. It does not acknowledge delivery settlement or recall already-submitted bytes. StopID identifies the idempotent STOP transaction, not a delivery counter.

func ParseStopped

func ParseStopped(encoded []byte) (Stopped, error)

func (Stopped) MarshalBinary

func (f Stopped) MarshalBinary() ([]byte, error)

Jump to

Keyboard shortcuts

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