relayv2

package
v0.1.2 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: 23 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 relayv2 adapts the native v2 opaque relay route to core FrameChannel.

Index

Constants

View Source
const DefaultLifecycleObservationCapacity = 256

DefaultLifecycleObservationCapacity retains a bounded prefix until the owner attaches a consumer. Callers must opt in by assigning it explicitly.

View Source
const DialStageWebSocket = "websocket"

DialStageWebSocket identifies WebSocket handshake timing observations.

Variables

View Source
var (
	ErrClosed                       = errors.New("relay v2 transport: connection is closed")
	ErrProtocol                     = errors.New("relay v2 transport: protocol violation")
	ErrSessionRetired               = errors.New("relay v2 transport: relay session is retired")
	ErrIngressOverflow              = errors.New("relay v2 transport: session receive queue is full")
	ErrEgressOverflow               = errors.New("relay v2 transport: session send queue is full")
	ErrFrameBounds                  = errors.New("relay v2 transport: frame size is outside bounds")
	ErrLifecycleObservationCapacity = errors.New("relay v2 transport: lifecycle observation capacity must not be negative")
)
View Source
var (
	ErrHeartbeat       = connectionliveness.ErrSilent
	ErrHeartbeatConfig = errors.New("relay v2 heartbeat: invalid configuration")
)
View Source
var ErrReceiveCapacity = errors.New("relay v2 transport: invalid receive capacity")

Functions

func NewFreshRegisterInit

func NewFreshRegisterInit(
	shareID v2.ShareID,
	shareInstance v2.ShareInstance,
	pkHash v2.PKHash,
	descriptor []byte,
	resumeToken v2.ResumeToken,
) (v2.RegisterInit, error)

func ResumeInit

func ResumeInit(fresh v2.RegisterInit) (v2.RegisterInit, error)

func Stop

func Stop(ctx context.Context, config StopConfig) error

Stop confirms permanent relay revocation, including durable stop evidence, discarded unsubmitted queues and fenced publication/resume work. Success does not imply delivery settlement: bytes previously submitted to the network may still arrive on old connections. A lost response can be retried with the same ID.

Types

type BinarySocket

type BinarySocket interface {
	Read(context.Context) (websocket.MessageType, []byte, error)
	Write(context.Context, websocket.MessageType, []byte) error
	Close(websocket.StatusCode, string) error
	SetReadLimit(int64)
}

BinarySocket is the narrow WebSocket surface owned by this protocol consumer. A coder WebSocket satisfies it directly.

type Channel

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

func (*Channel) CapacityWait

func (c *Channel) CapacityWait() time.Duration

CapacityWait retains pressure briefly across local retirement so a completed handshake timeout can still be classified by its recovery owner.

func (*Channel) Close

func (c *Channel) Close() error

func (*Channel) ConfirmAdmission

func (c *Channel) ConfirmAdmission(ctx context.Context) error

ConfirmAdmission retains a provisional relay session only after its application owner has authenticated the E2E handshake. It is sender-only and carries no opaque payload, so admission cannot be inferred from arbitrary receiver bytes.

func (*Channel) Err

func (c *Channel) Err() error

func (*Channel) Recv

func (c *Channel) Recv() <-chan framechannel.Frame

func (*Channel) RelaySessionID

func (c *Channel) RelaySessionID() v2.RelaySessionID

func (*Channel) Send

func (c *Channel) Send(ctx context.Context, frame framechannel.Frame) error

func (*Channel) SendTerminal

func (c *Channel) SendTerminal(ctx context.Context, frame framechannel.Frame) error

func (*Channel) State

func (c *Channel) State() framechannel.ChannelState

type DialOptions

type DialOptions struct {
	HTTPClient *http.Client
	Header     http.Header
	Heartbeat  HeartbeatConfig
	// ReceiveCapacity is shared by every session on this physical connection.
	// Zero selects the native default; partial declarations are invalid.
	ReceiveCapacity v2.ReceiveCapacity
	// LifecycleObservationCapacity enables a producer-owned bounded stream.
	// Zero disables lifecycle observation without allocating producer work.
	LifecycleObservationCapacity int
	// SocketDialer lets deterministic tests and embedded callers own the
	// transport boundary without weakening the protocol handshake.
	SocketDialer func(context.Context, string, http.Header) (BinarySocket, error)
	ObserveStage func(DialStage)
}

type DialStage

type DialStage struct {
	Stage    string
	Duration time.Duration
	Failure  error
}

type HeartbeatConfig

type HeartbeatConfig struct {
	Interval time.Duration
	Timeout  time.Duration
}

HeartbeatConfig sets this client's probe cadence and how long its relay connection may stay without accepted inbound frames. Zero fields select the protocol values, which the relay's own silence timeout is sized against.

func (HeartbeatConfig) Normalize

func (c HeartbeatConfig) Normalize() (HeartbeatConfig, error)

type LifecycleCause

type LifecycleCause string
const (
	LifecycleCauseNone            LifecycleCause = "none"
	LifecycleCauseCanceled        LifecycleCause = "canceled"
	LifecycleCauseDeadline        LifecycleCause = "deadline"
	LifecycleCauseFrameBounds     LifecycleCause = "frame_bounds"
	LifecycleCauseEgressOverflow  LifecycleCause = "egress_overflow"
	LifecycleCauseIngressOverflow LifecycleCause = "ingress_overflow"
	LifecycleCauseSessionRetired  LifecycleCause = "session_retired"
	LifecycleCauseProtocol        LifecycleCause = "protocol"
	LifecycleCauseClosed          LifecycleCause = "closed"
	LifecycleCauseTransport       LifecycleCause = "transport"
)

func (LifecycleCause) DiagnosticName

func (value LifecycleCause) DiagnosticName() string

DiagnosticName belongs to the source vocabulary; recorders accept new values.

type LifecycleContractViolation

type LifecycleContractViolation uint8

LifecycleContractViolation is a closed producer-owned reason. Consumers can distinguish an unknown enum from a malformed identity or stage shape without independently rebuilding the relay lifecycle matrix.

const (
	LifecycleContractValid LifecycleContractViolation = iota
	LifecycleContractUnknownEnum
	LifecycleContractInvalidIdentity
	LifecycleContractInvalidStageFields
)

func ValidateLifecycleTrace

func ValidateLifecycleTrace(event LifecycleTrace) LifecycleContractViolation

ValidateLifecycleTrace is the sole authority for shapes emitted by relayv2. Keeping this beside the constructors prevents diagnostic projections from narrowing valid retirement consequences as the transport evolves.

type LifecycleObservationCompletion

type LifecycleObservationCompletion struct {
	Enqueued uint64
	Loss     LifecycleObservationLoss
}

LifecycleObservationCompletion proves that stream admission has closed. Enqueued does not imply that a consumer received or projected an observation.

type LifecycleObservationLoss

type LifecycleObservationLoss struct {
	CapacityDropped uint64
}

LifecycleObservationLoss is cumulative through the producer admission cut. It describes only observations the bounded stream could not retain.

func (LifecycleObservationLoss) Total

func (loss LifecycleObservationLoss) Total() uint64

type LifecycleRetirementSource

type LifecycleRetirementSource string
const (
	LifecycleRetirementNone           LifecycleRetirementSource = "none"
	LifecycleRetirementLocalClose     LifecycleRetirementSource = "local_close"
	LifecycleRetirementTerminal       LifecycleRetirementSource = "terminal"
	LifecycleRetirementRelaySession   LifecycleRetirementSource = "relay_session"
	LifecycleRetirementLinkClose      LifecycleRetirementSource = "link_close"
	LifecycleRetirementLinkFailure    LifecycleRetirementSource = "link_failure"
	LifecycleRetirementIngressFailure LifecycleRetirementSource = "ingress_failure"
)

func (LifecycleRetirementSource) DiagnosticName

func (value LifecycleRetirementSource) DiagnosticName() string

DiagnosticName belongs to the source vocabulary; recorders accept new values.

type LifecycleStage

type LifecycleStage string
const (
	LifecycleTerminalReserved      LifecycleStage = "terminal_reserved"
	LifecycleSendAdmitted          LifecycleStage = "send_admitted"
	LifecycleSendRejected          LifecycleStage = "send_rejected"
	LifecycleSendRolledBack        LifecycleStage = "send_rolled_back"
	LifecycleRetirementDeferred    LifecycleStage = "retirement_deferred"
	LifecycleRetired               LifecycleStage = "retired"
	LifecycleTerminalSettled       LifecycleStage = "terminal_settled"
	LifecycleLinkRetiring          LifecycleStage = "link_retiring"
	LifecycleLinkClosed            LifecycleStage = "link_closed"
	LifecycleTraceDropped          LifecycleStage = "trace_dropped"
	LifecycleHeartbeatProbe        LifecycleStage = "heartbeat_probe"
	LifecycleHeartbeatAcknowledged LifecycleStage = "heartbeat_acknowledged"
	LifecycleHeartbeatFailed       LifecycleStage = "heartbeat_failed"
)

func (LifecycleStage) DiagnosticName

func (value LifecycleStage) DiagnosticName() string

DiagnosticName belongs to the source vocabulary; recorders accept new values.

type LifecycleTrace

type LifecycleTrace struct {
	LinkID           uint64
	RelaySessionID   v2.RelaySessionID
	OperationID      uint64
	Stage            LifecycleStage
	Terminal         bool
	Disposition      framechannel.SendDisposition
	RetirementSource LifecycleRetirementSource
	Cause            LifecycleCause
	DrainCause       LifecycleCause
	Dropped          uint64
	HeartbeatRound   uint64
	Wait             time.Duration
	Timeout          time.Duration
}

LifecycleTrace carries stable correlation and enum-like decisions without leaking provider error text or frame contents into operational logs.

func (LifecycleTrace) DiagnosticRecord

func (v LifecycleTrace) DiagnosticRecord() diag.Record

type ReceiverConfig

type ReceiverConfig struct {
	RelayBaseURL string
	ShareID      v2.ShareID
	Dial         DialOptions
}

type ReceiverConnection

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

func DialReceiver

func DialReceiver(ctx context.Context, config ReceiverConfig) (*ReceiverConnection, error)

func (*ReceiverConnection) Channel

func (connection *ReceiverConnection) Channel() *Channel

func (*ReceiverConnection) Close

func (connection *ReceiverConnection) Close() error

func (*ReceiverConnection) CompleteObservations

func (connection *ReceiverConnection) CompleteObservations() LifecycleObservationCompletion

CompleteObservations closes lifecycle stream admission and returns the producer-proven enqueue/loss cut owned by this relay connection.

func (*ReceiverConnection) Descriptor

func (connection *ReceiverConnection) Descriptor() []byte

func (*ReceiverConnection) Done

func (connection *ReceiverConnection) Done() <-chan struct{}

func (*ReceiverConnection) Endpoint

func (connection *ReceiverConnection) Endpoint() v2.RelayEndpoint

func (*ReceiverConnection) Err

func (connection *ReceiverConnection) Err() error

func (*ReceiverConnection) LifecycleTrace

func (connection *ReceiverConnection) LifecycleTrace() <-chan LifecycleTrace

LifecycleTrace is nil when lifecycle observations were not enabled at dial.

type RegistrationNotSentError

type RegistrationNotSentError struct {
	Cause error
}

RegistrationNotSentError proves this DialSender call failed before attempting any REGISTER/RESUME writes. Other failures may have left a remote registration. Wrappers that retry must retain uncertainty from every attempt, independently of whether dial observations are enabled.

func (*RegistrationNotSentError) Error

func (err *RegistrationNotSentError) Error() string

func (*RegistrationNotSentError) Unwrap

func (err *RegistrationNotSentError) Unwrap() error

type RegistrationStats

type RegistrationStats struct {
	BytesSent     uint64
	BytesReceived uint64
}

type RelayError

type RelayError struct {
	Code       v2.ErrorCode
	RetryAfter time.Duration
}

func (*RelayError) Error

func (err *RelayError) Error() string

type SenderConfig

type SenderConfig struct {
	RelayBaseURL     string
	Init             v2.RegisterInit
	SenderPrivateKey ed25519.PrivateKey
	Descriptor       []byte
	ResumeToken      v2.ResumeToken
	Dial             DialOptions
}

type SenderConnection

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

func DialSender

func DialSender(ctx context.Context, config SenderConfig) (_ *SenderConnection, failure error)

func (*SenderConnection) Accept

func (connection *SenderConnection) Accept(ctx context.Context) (*Channel, error)

func (*SenderConnection) Close

func (connection *SenderConnection) Close() error

func (*SenderConnection) CompleteObservations

func (connection *SenderConnection) CompleteObservations() LifecycleObservationCompletion

CompleteObservations closes lifecycle stream admission and returns the producer-proven enqueue/loss cut owned by this relay connection.

func (*SenderConnection) Done

func (connection *SenderConnection) Done() <-chan struct{}

func (*SenderConnection) Endpoint

func (connection *SenderConnection) Endpoint() v2.RelayEndpoint

func (*SenderConnection) Err

func (connection *SenderConnection) Err() error

func (*SenderConnection) LifecycleTrace

func (connection *SenderConnection) LifecycleTrace() <-chan LifecycleTrace

LifecycleTrace is nil when lifecycle observations were not enabled at dial.

func (*SenderConnection) RegistrationStats

func (connection *SenderConnection) RegistrationStats() RegistrationStats

type StopConfig

type StopConfig struct {
	RelayBaseURL     string
	ShareID          v2.ShareID
	ShareInstance    v2.ShareInstance
	PKHash           v2.PKHash
	StopID           v2.StopID
	SenderPrivateKey ed25519.PrivateKey
	Dial             DialOptions
}

type WebSocketRouteError

type WebSocketRouteError struct {
	BaseHint networkendpoint.RelayBaseHint
	// contains filtered or unexported fields
}

WebSocketRouteError identifies an observed missing route for a candidate that could have been copied from the full WebSocket endpoint.

func (*WebSocketRouteError) Error

func (err *WebSocketRouteError) Error() string

func (*WebSocketRouteError) Unwrap

func (err *WebSocketRouteError) Unwrap() error

Directories

Path Synopsis
internal
receiveledger
Package receiveledger accounts for inbound delivery on one physical connection.
Package receiveledger accounts for inbound delivery on one physical connection.

Jump to

Keyboard shortcuts

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