relayset

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: AGPL-3.0 Imports: 29 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 relayset coordinates independent relay endpoint lifecycles. Each endpoint retains registration/resume authority; the set only merges ingress.

Index

Constants

View Source
const (
	AdmissionAdmitted    = "admitted"
	AdmissionParked      = "parked"
	AdmissionUnavailable = "unavailable"
)
View Source
const (
	AdmissionReasonPrimary         = "primary"
	AdmissionReasonBackup          = "backup"
	AdmissionReasonPermitReleased  = "permit_released"
	AdmissionReasonTargetReached   = "target_reached"
	AdmissionReasonBackupNotChosen = "backup_not_selected"
	AdmissionReasonPrimaryLost     = "primary_lost"
	AdmissionReasonBackupLost      = "backup_lost"
)
View Source
const (
	AuthorizationReady              = serviceauthority.AdmissionReady
	AuthorizationPendingSetup       = serviceauthority.AdmissionPendingSetup
	AuthorizationPendingAttribution = serviceauthority.AdmissionPendingAttribution
	AuthorizationExpired            = serviceauthority.AdmissionExpired
	AuthorizationTemporaryFailure   = serviceauthority.AdmissionTemporaryFailure
	AuthorizationDenied             = serviceauthority.AdmissionDenied
	AuthorizationUserActionRequired = serviceauthority.AdmissionUserActionRequired
)
View Source
const MaxAccessKeyBytes = 4096
View Source
const MaximumEndpoints = 8
View Source
const (
	ReceiverInitialWait = 10 * time.Second
)

Variables

View Source
var (
	ErrReceiverUnavailable  = errors.New("share is temporarily unavailable")
	ErrReceiverWaitExpired  = errors.New("receiver connection waiting deadline expired")
	ErrReceiverShareChanged = errors.New("receiver authenticated share descriptor changed")
	ErrReceiverShareStopped = errors.New("all relay routes for the share are stopped")
)
View Source
var ErrCandidate = errors.New("invalid sender relay candidate")
View Source
var ErrConfig = errors.New("invalid sender relay set configuration")
View Source
var ErrReceiverAuthentication = errors.New("receiver relay authentication failed")
View Source
var ErrStopped = senderRelayRecoveryStoppedError{}

Functions

func PublicURLs added in v0.1.6

func PublicURLs(candidates []Candidate) ([]string, error)

PublicURLs validates the entire publication before any candidate can register. Aliases of the same relay identity would compete for one share's ownership.

Types

type Admission

type Admission struct {
	Endpoint, Primary, State, Reason string
	Count                            int
}

type Attempt added in v0.1.6

type Attempt struct {
	ShareInstance     v2.ShareInstance
	Number            uint32
	State             AttemptState
	Failure           error
	Generation        uint64
	Slow              bool
	Resume            bool
	NextDelay         time.Duration
	ServerRetryAt     time.Time
	HandshakeDuration time.Duration
	Terminal          bool
	Duration          time.Duration
	Stage             string
	Authorization     AuthorizationState
}

type AttemptControl added in v0.1.6

type AttemptControl interface {
	Begin(context.Context) (AttemptPermit, error)
	Unavailable()
}

AttemptControl limits individual handshakes, leaving retry clocks and resume authority with the endpoint. Waiting for capacity must not consume a dial timeout.

type AttemptPermit added in v0.1.6

type AttemptPermit interface {
	Admit() bool
	Release()
	ReleaseFailed()
}

AttemptPermit tracks one in-flight handshake slot. ReleaseFailed records an actual handshake failure for in-share backup ranking, whereas Release frees the slot without penalizing the candidate (admitted, parked, auth wait, cancel).

type AttemptState added in v0.1.6

type AttemptState uint8
const (
	AttemptStarted AttemptState = iota + 1
	AttemptSucceeded
	AttemptFailed
	AttemptWaiting
	AttemptParked
	AttemptStage
	AttemptAuthorization
)

func (AttemptState) DiagnosticName added in v0.1.6

func (value AttemptState) DiagnosticName() string

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

type Authorization added in v0.1.6

type AuthorizationError added in v0.1.6

type AuthorizationError struct {
	State AuthorizationState
	Cause error
}

func (*AuthorizationError) Error added in v0.1.6

func (err *AuthorizationError) Error() string

func (*AuthorizationError) Unwrap added in v0.1.6

func (err *AuthorizationError) Unwrap() error

type AuthorizationSource added in v0.1.6

type AuthorizationSource interface {
	ReserveRegistrationAuthorization() Authorization
}

AuthorizationSource reserves authorization for one fresh registration. Waiting results describe the revision to watch and hold no reservation or dial slot.

type AuthorizationState added in v0.1.6

type AuthorizationState = serviceauthority.AdmissionState

type Candidate added in v0.1.6

type Candidate struct {
	PublicURL     string
	Authorization AuthorizationSource `json:"-"`
}

Candidate binds deployment registration authority to one public relay address. Only PublicURL may enter a capability; the token is not session/STOP authority.

func (Candidate) Validate added in v0.1.6

func (candidate Candidate) Validate() error

type Clock added in v0.1.6

type Clock interface {
	Now() time.Time
	// A wake signal ends local backoff. A nil wake leaves only elapsed time or cancellation.
	Wait(context.Context, time.Duration, <-chan struct{}) error
}

type Fallback added in v0.1.6

type Fallback struct {
	Active   []string
	Canaries []string
}

Fallback records the one-shot startup transition to standby canary relays after every initial active network candidate fails its first attempt.

type NetworkAdmissions

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

NetworkAdmissions coordinates only directory candidates. Configured endpoints keep independent lifetimes, and no successful published connection is evicted.

func NewNetworkAdmissions

func NewNetworkAdmissions(plan relayplan.Plan, clock Clock, serverRetryAt func(string) time.Time) *NetworkAdmissions

func (*NetworkAdmissions) Control

func (a *NetworkAdmissions) Control(url string) AttemptControl

func (*NetworkAdmissions) Observe

func (a *NetworkAdmissions) Observe(observer func(Admission))

type Receiver

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

Receiver owns relay connections for one cryptographic session. Competing initial handshakes race to publish the first usable session; losers release their authority and join the winner using a fresh authenticated lane grant.

func NewReceiver

func NewReceiver(ctx context.Context, config ReceiverConfig) (*Receiver, error)

func (*Receiver) AllRelaysStopped added in v0.1.5

func (receiver *Receiver) AllRelaysStopped() bool

AllRelaysStopped requires an explicit stop from every route in the link's resolved candidate set. Missing directory results and temporary failures leave open the possibility of joining the same share again.

func (*Receiver) Close

func (receiver *Receiver) Close()

func (*Receiver) WaitReady

func (receiver *Receiver) WaitReady(ctx context.Context) (*receiversession.Runtime, ReceiverConnection, error)

type ReceiverClock

type ReceiverClock interface {
	Now() time.Time
	Wait(context.Context, time.Duration) error
}

type ReceiverConfig

type ReceiverConfig struct {
	Clock            ReceiverClock
	Receiver         liveshare.ReceiverConfig
	Dial             func(context.Context, relayv2.ReceiverConfig) (ReceiverConnection, error)
	DialOptions      relayv2.DialOptions
	Connected        func(ReceiverConnection)
	ResolveEndpoints func(context.Context) ([]string, error)
	// contains filtered or unexported fields
}

type ReceiverConnection

type ReceiverConnection interface {
	Descriptor() []byte
	Channel() protocolsession.FrameChannel
	Endpoint() v2.RelayEndpoint
	Done() <-chan struct{}
	Err() error
	Close() error
}

ReceiverConnection is the authority needed to attach and retire one relay lane.

func DialReceiver

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

type ReceiverJoinFailure

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

ReceiverJoinFailure retains endpoint authority boundaries. One permanently rejected endpoint cannot veto recovery through an independently failed relay.

func (*ReceiverJoinFailure) Error

func (failure *ReceiverJoinFailure) Error() string

func (*ReceiverJoinFailure) RetryEndpoints

func (failure *ReceiverJoinFailure) RetryEndpoints() []string

func (*ReceiverJoinFailure) Unwrap

func (failure *ReceiverJoinFailure) Unwrap() []error

type ReceiverRecovery

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

func NewReceiverRecovery

func NewReceiverRecovery(options ReceiverRecoveryOptions) (*ReceiverRecovery, error)

func (*ReceiverRecovery) Join

func (recovery *ReceiverRecovery) Join(ctx context.Context, config ReceiverConfig) (*Receiver, error)

Join has a finite default window. An explicit caller wait limit also selects how long the caller wants to wait before any usable share has been observed.

func (*ReceiverRecovery) Replace

func (recovery *ReceiverRecovery) Replace(ctx context.Context, config ReceiverConfig) (*Receiver, error)

Replace waits through temporary outages until success, terminal rejection, or caller cancellation. The unchanged continuation owns the transfer and output.

type ReceiverRecoveryObservation

type ReceiverRecoveryObservation struct {
	Endpoint             string
	Attempt              uint32
	Phase                ReceiverRecoveryPhase
	Delay                time.Duration
	ProtocolSessionID    [16]byte
	ConnectionGeneration uint64
	Err                  error
}

type ReceiverRecoveryOptions

type ReceiverRecoveryOptions struct {
	Clock          ReceiverClock
	TimeoutContext func(context.Context, time.Duration) (context.Context, context.CancelFunc)
	InitialWait    time.Duration
	FastWindow     time.Duration
	WaitTimeout    time.Duration
	Jitter         func(time.Duration) time.Duration
	Observe        func(ReceiverRecoveryObservation)
}

A joined share keeps endpoint decisions and retry pressure across protocol generations. Neither a new session nor a lane attachment resets this owner.

type ReceiverRecoveryPhase

type ReceiverRecoveryPhase string
const (
	ReceiverRecoveryConnecting ReceiverRecoveryPhase = "connecting"
	ReceiverRecoveryRetrying   ReceiverRecoveryPhase = "retrying"
	ReceiverRecoveryWaiting    ReceiverRecoveryPhase = "waiting"
	ReceiverRecoveryConnected  ReceiverRecoveryPhase = "connected"
	ReceiverRecoveryTerminal   ReceiverRecoveryPhase = "terminal"
)

type RegistrationFailure

type RegistrationFailure struct {
	URL   string
	Cause error
}

RegistrationFailure retains endpoint identity across the aggregate readiness result, so applications can recover the rejected authority without parsing text.

func (*RegistrationFailure) Error

func (failure *RegistrationFailure) Error() string

func (*RegistrationFailure) Unwrap

func (failure *RegistrationFailure) Unwrap() error

type RegistrationState added in v0.1.6

type RegistrationState uint8
const (
	RegistrationPending RegistrationState = iota
	RegistrationNeedsUserAuthorization
	RegistrationRetrying
	RegistrationAvailable
)

type Sender

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

func NewPlannedSender added in v0.1.6

func NewPlannedSender(ctx context.Context, plan relayplan.Plan, dial SenderFactory, observeFallback func(Fallback)) (*Sender, error)

func NewSender

func NewSender(parent context.Context, urls []string, dial SenderFactory) (*Sender, error)

func (*Sender) Accept

func (s *Sender) Accept(ctx context.Context) (*relayv2.Channel, error)

func (*Sender) Cleanup

func (s *Sender) Cleanup(ctx context.Context) error

func (*Sender) ObserveStatus added in v0.1.4

func (s *Sender) ObserveStatus(observer func(SenderStatus))

ObserveStatus delivers the current status immediately and subsequent aggregate transitions synchronously and in causal order while holding s.mu (and, on endpoint-driven transitions, the endpoint's registration lock). Holding the lock keeps transitions serialized and suppresses notifications atomically once StopRecovery runs. The callback must not block or reenter Sender (including via StopRecovery).

func (*Sender) ReadyRelayURL

func (s *Sender) ReadyRelayURL() string

func (*Sender) Registrations

func (s *Sender) Registrations() SenderRegistrations

Registrations freezes what is known at publication. Pending candidates can still become useful after the first relay releases the share link.

func (*Sender) Status added in v0.1.4

func (s *Sender) Status() SenderStatus

Status reads the owner's current state even when observations were dropped.

func (*Sender) StopRecovery

func (s *Sender) StopRecovery()

func (*Sender) WaitReady

func (s *Sender) WaitReady(ctx context.Context) error

func (*Sender) Wake

func (s *Sender) Wake()

type SenderAvailability

type SenderAvailability struct {
	Available uint32
	Total     uint32
	EverReady bool
	Terminal  uint32
}

SenderAvailability describes only admission through relays. Existing direct transfers have independent lifetimes and must never be inferred from this count.

type SenderConnection added in v0.1.6

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

SenderConnection keeps factories concrete while containing the narrow transport interface at the consumer boundary.

func NewSenderConnection added in v0.1.6

func NewSenderConnection(endpoint SenderTransport) SenderConnection

func (SenderConnection) Accept added in v0.1.6

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

func (SenderConnection) Close added in v0.1.6

func (connection SenderConnection) Close() error

func (SenderConnection) CompleteObservations added in v0.1.6

func (connection SenderConnection) CompleteObservations() relayv2.LifecycleObservationCompletion

func (SenderConnection) LifecycleTrace added in v0.1.6

func (connection SenderConnection) LifecycleTrace() <-chan relayv2.LifecycleTrace

type SenderDialer added in v0.1.6

type SenderDialer interface {
	Dial(context.Context, relayv2.SenderConfig) (SenderConnection, error)
}

SenderDialer owns the complete attempt outcome. RegistrationNotSentError proves no registration was sent by any internal attempt; observations never own policy.

type SenderEndpoint

type SenderEndpoint interface {
	WaitReady(context.Context) error
	ObserveRegistration(func(RegistrationState))
	Wake()
	Accept(context.Context) (*relayv2.Channel, error)
	StopRecovery()
	Cleanup(context.Context) error
}

type SenderFactory

type SenderFactory func(context.Context, string) (SenderEndpoint, error)

type SenderLifecycle added in v0.1.6

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

SenderLifecycle owns one relay's registration for the lifetime of a share.

func NewSenderLifecycle added in v0.1.6

func NewSenderLifecycle(config SenderLifecycleConfig) (*SenderLifecycle, error)

func (*SenderLifecycle) Accept added in v0.1.6

func (lifecycle *SenderLifecycle) Accept(ctx context.Context) (*relayv2.Channel, error)

func (*SenderLifecycle) Cleanup added in v0.1.6

func (lifecycle *SenderLifecycle) Cleanup(ctx context.Context) error

func (*SenderLifecycle) CompleteObservations added in v0.1.6

func (lifecycle *SenderLifecycle) CompleteObservations() relayv2.LifecycleObservationCompletion

func (*SenderLifecycle) ObserveRegistration added in v0.1.6

func (lifecycle *SenderLifecycle) ObserveRegistration(observer func(RegistrationState))

ObserveRegistration provides the current route state even when diagnostic observations are disabled or dropped. The callback must not reenter SenderLifecycle.

func (*SenderLifecycle) StopRecovery added in v0.1.6

func (lifecycle *SenderLifecycle) StopRecovery()

func (*SenderLifecycle) WaitReady added in v0.1.6

func (lifecycle *SenderLifecycle) WaitReady(ctx context.Context) error

WaitReady waits through temporary startup failures. Only authenticated readiness makes a link publishable; merely constructing a lifecycle does not.

func (*SenderLifecycle) Wake added in v0.1.6

func (lifecycle *SenderLifecycle) Wake()

Wake coalesces network/resume notifications into the single recovery owner.

type SenderLifecycleConfig added in v0.1.6

type SenderLifecycleConfig struct {
	Candidate                    Candidate
	Fresh                        v2.RegisterInit
	ResumeToken                  v2.ResumeToken
	PrivateKey                   ed25519.PrivateKey
	Descriptor                   []byte
	Initial                      SenderTransport
	Dialer                       SenderDialer
	Clock                        Clock
	LifecycleObservationCapacity int
	ObserveConnection            func(SenderConnection) func()
	ObserveAttempt               func(Attempt)
	Attempts                     AttemptControl
	// Jitter is applied only in the slow phase, keeping short outages responsive.
	Jitter func(time.Duration) time.Duration
}

type SenderRegistrations

type SenderRegistrations struct {
	// Candidates includes pending and previously admitted routes selected for this share.
	Candidates []string
	Admitted   []string
	Rejected   []string
}

type SenderStatus added in v0.1.4

type SenderStatus struct {
	Availability          SenderAvailability
	AuthorizationRequired bool
}

type SenderTransport added in v0.1.6

type SenderTransport interface {
	Accept(context.Context) (*relayv2.Channel, error)
	Close() error
}

SenderTransport is defined at the lifecycle that consumes it so recovery policy does not depend on the concrete WebSocket transport.

type StaticKey added in v0.1.6

type StaticKey string

func (StaticKey) ReserveRegistrationAuthorization added in v0.1.6

func (key StaticKey) ReserveRegistrationAuthorization() Authorization

type SystemClock added in v0.1.6

type SystemClock struct{}

func (SystemClock) Now added in v0.1.6

func (SystemClock) Now() time.Time

func (SystemClock) Wait added in v0.1.6

func (SystemClock) Wait(ctx context.Context, delay time.Duration, wake <-chan struct{}) error

Jump to

Keyboard shortcuts

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