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
- Variables
- func DeliveryRegistrationPreimage(init DeliveryRegisterInit, challenge Challenge, relay RelayIdentity) ([]byte, error)
- func RegistrationPreimage(init RegisterInit, challenge Challenge, relayIdentity RelayIdentity) ([]byte, error)
- func StopPreimage(init StopInit, challenge Challenge) ([]byte, error)
- type AuthorizedDescriptorUpload
- type CapacityWait
- type Challenge
- type ChallengeBinding
- type ChallengeID
- type ChallengeLedger
- func (l *ChallengeLedger) AuthenticateRegistration(id ChallengeID, init RegisterInit, relayIdentity RelayIdentity, ...) (SenderAuthority, error)
- func (l *ChallengeLedger) AuthenticateStop(id ChallengeID, init StopInit, relayIdentity RelayIdentity, proof StopProof) (StopAuthority, error)
- func (l *ChallengeLedger) Issue(purpose ChallengePurpose, binding ChallengeBinding) (Challenge, error)
- func (l *ChallengeLedger) Take(id ChallengeID, purpose ChallengePurpose, binding ChallengeBinding) (Challenge, error)
- type ChallengeLedgerConfig
- type ChallengeNonce
- type ChallengePurpose
- type ConnectionProbe
- type ConnectionProbeAck
- type DeliveryConsumed
- type DeliveryJoin
- type DeliveryRegisterInit
- type DescriptorDelivery
- type DescriptorUpload
- type Digest
- type ErrorCode
- type ErrorFrame
- type Join
- type OpaqueRoute
- type PKHash
- type ReceiveCapacity
- type ReceiveCredit
- type RegisterInit
- type RegisterProof
- func NewDeliveryRegisterProof(init DeliveryRegisterInit, challenge Challenge, relay RelayIdentity, ...) (RegisterProof, error)
- func NewRegisterProof(init RegisterInit, challenge Challenge, relayIdentity RelayIdentity, ...) (RegisterProof, error)
- func ParseRegisterProof(encoded []byte) (RegisterProof, error)
- type Registered
- type RegistrationMode
- type RelayEndpoint
- type RelayIdentity
- type RelaySessionID
- type ResumeCredential
- type ResumeToken
- type SenderAuthority
- type SessionAdmitted
- type SessionCredit
- type SessionRetired
- type SettlementAck
- type SettlementNotice
- type ShareID
- type ShareInstance
- type StopAuthority
- type StopID
- type StopInit
- type StopProof
- type Stopped
Constants ¶
const ( CapacityWaitMagic = "WS2Z" CapacityWaitBytes = 8 + RelaySessionIDBytes + 4 MaxCapacityWaitMilliseconds = 60_000 )
const ( DeliveryConsumedMagic = "WS2B" DeliveryConsumedBytes = deliveryTotalsBytes )
const ( SettlementNoticeMagic = "WS2N" SettlementNoticeBytes = deliveryTotalsBytes SettlementAckMagic = "WS2S" SettlementAckBytes = deliveryTotalsBytes )
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 )
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 )
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 )
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 )
const ( WireVersion = byte(2) Suite = byte(2) 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 )
const (
ChallengeTTL = 30 * time.Second
)
const DeliveryJoinBytes = JoinBytes + ReceiveCapacityBytes
const DeliveryRegisterInitBytes = RegisterInitBytes + ReceiveCapacityBytes
const ReceiveCapacityBytes = 16
Explicit staged codecs: runtime activation requires cumulative consumption and settlement together. Neither parser accepts the live capacity-less handshake.
const WebSocketPath = networkendpoint.WebSocketPath
Variables ¶
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") )
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)
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 (Challenge) MarshalBinary ¶
type ChallengeBinding ¶
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 ¶
func (l *ChallengeLedger) Take(id ChallengeID, purpose ChallengePurpose, binding ChallengeBinding) (Challenge, error)
type ChallengeLedgerConfig ¶
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 {
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 ErrorFrame ¶
func ParseError ¶
func ParseError(encoded []byte) (ErrorFrame, error)
func (ErrorFrame) MarshalBinary ¶
func (f ErrorFrame) 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 ReceiveCapacity ¶
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
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 {
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 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 {
PKHash PKHash
RelayIdentity RelayIdentity
StopID StopID
}
func ParseStopInit ¶
func (StopInit) MarshalBinary ¶
type StopProof ¶
type StopProof struct {
SenderPublicKey [SenderPublicKeyBytes]byte
Signature [SignatureBytes]byte
}
func NewStopProof ¶
func ParseStopProof ¶
func (StopProof) MarshalBinary ¶
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.