lanes

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, AGPL-3.0 Imports: 21 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 lanes owns authenticated block scheduling and the complete lifetime of admitted attempts. Selection, retirement and settlement share one state owner.

Index

Constants

View Source
const (
	MaxLogicalLanes   = 16
	MaxDemandAttempts = MaxLogicalLanes
)
View Source
const DefaultSettlementObservationCapacity = SettlementObservationCapacity(MaxLogicalLanes)
View Source
const UnhelpfulLaneRateRatio = 1.5
View Source
const UnhelpfulLaneWindow = 30 * time.Second

Variables

View Source
var (
	ErrInvalid        = errors.New("transfer lane is invalid")
	ErrInvalidRequest = errors.New("block request requires a validator")
	ErrStale          = errors.New("transfer lane epoch is stale")
	ErrBudget         = errors.New("transfer lane budget exceeded")
	ErrClosed         = errors.New("transfer lane set is closed")
	ErrNoContentRoute = errors.New("no permitted content route remains")
)

Functions

func AttemptSuperseded

func AttemptSuperseded(ctx context.Context) bool

AttemptSuperseded proves that the demand owner canceled a redundant attempt after selecting an authenticated winner. Plain cancellation, including a parent failure, cannot supply this evidence to a lane's terminal diagnostics.

func NewDemandNotAdmitted

func NewDemandNotAdmitted(cause error) error

func NewDemandReassignableAfterRetirement

func NewDemandReassignableAfterRetirement(cause error) error

Types

type Block

type Block struct {
	records.BlockRecord
	// contains filtered or unexported fields
}

Block retains the admitted route of the selected authenticated result. Retired incarnations carry Unknown so a late result cannot claim live routing.

func (Block) Route

func (block Block) Route() downloadmetrics.Route

type BlockCapacitySource

type BlockCapacitySource interface {
	TryReserveBlock(Demand) (BlockReservation, <-chan struct{}, error)
}

BlockCapacitySource reserves response storage before any request is sent. A source without storage (for example, an in-memory source) needs no claim.

type BlockReservation

type BlockReservation struct {
	Source  BlockSource
	Release func()
}

type BlockSource

type BlockSource interface {
	// Receipt reports unique sealed-object bytes before authentication. It may
	// replenish network supply, but never proves output durability.
	FetchBlock(context.Context, Demand, func(uint64)) (records.BlockRecord, error)
}

type CapacityBlock

type CapacityBlock uint8

CapacityBlock distinguishes waiting for transport supply from local holdings. Connectivity must not grow paths to solve consumer or memory backpressure.

const (
	CapacityReady CapacityBlock = iota
	CapacityNetwork
	CapacityRoute
	CapacityConsumer
)

type CapacityClaim

type CapacityClaim func() (release func(), changed <-chan struct{}, err error)

CapacityClaim reserves one physical attempt before its source is called. A nil release with a change signal means admission must wait. Release remains owned by the attempt until its plaintext is handed back or discarded.

type CapacityReadiness

type CapacityReadiness struct {
	Kind    CapacityBlock
	Changed <-chan struct{}
}

type Config

type Config struct {
	ContentRoutePolicy            ContentRoutePolicy
	ProtocolSessionID             protocolsession.ProtocolSessionID
	Now                           func() time.Time
	After                         func(time.Duration) <-chan time.Time
	SettlementObservationCapacity SettlementObservationCapacity
}

type ContentActivity

type ContentActivity struct {
	Route         Route
	UsefulBytes   uint64
	LastUsefulAt  time.Time
	AdmittedLanes uint32
}

ContentActivity counts only selected authenticated block results. Open channels, discarded race losers and ciphertext never imply useful traffic.

type ContentRoutePolicy

type ContentRoutePolicy uint8

ContentRoutePolicy is fixed before a session admits content. Keeping it on the set means replacement epochs and new lane IDs cannot bypass user intent.

const (
	ContentRouteAll ContentRoutePolicy = iota
	ContentRouteDirectOnly
	ContentRouteRelayOnly
)

func (ContentRoutePolicy) Allows

func (policy ContentRoutePolicy) Allows(route Route) bool

type ContentSuspension

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

ContentSuspension is an epoch-stable content-admission capability for one authenticated logical lane. Its opaque policy identity prevents an old handle from releasing a newer hold on the same lane ID.

func (*ContentSuspension) Resume

func (suspension *ContentSuspension) Resume() error

Resume releases only the hold represented by this capability. It is idempotent so concurrent admission signals cannot release a later policy.

type Demand

type Demand struct {
	LeaseID    content.LeaseID
	Descriptor content.FileRevisionDescriptor
	Index      uint64
}

type Identity

type Identity struct {
	ID    uint32
	Epoch uint32
}

type Measurement

type Measurement struct {
	UsefulBytes  uint64
	Unhelpful    bool
	BusyTime     time.Duration
	PendingBytes uint64
}

type RemainingWork

type RemainingWork struct {
	Bytes uint64
	Known bool
}

type Request

type Request struct {
	Demand   Demand
	Validate func(records.BlockRecord) error
	Claim    CapacityClaim
	Order    func() WorkOrder
	Ready    func() CapacityReadiness
}

Request binds an immutable block demand to the consumer's validation and capacity authority. Validation must return a typed fault for known failures; lane scheduling cannot infer consumer policy from diagnostic error strings.

type Route

type Route uint8

Route is the authenticated content route admitted for one lane incarnation. It is captured at admission because lane numbers carry no transport meaning and may be reused across epochs.

const (
	RouteRelay Route = iota + 1
	RouteDirect
	RouteTURN
)

func (Route) DiagnosticName

func (value Route) DiagnosticName() string

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

type RouteSupply

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

RouteSupply is the lifetime of an owner actively provisioning or recovering permitted content paths. It is not evidence that any existing lane is usable.

func (*RouteSupply) Close

func (supply *RouteSupply) Close()

type SchedulingDemand

type SchedulingDemand struct {
	QueuedBlocks         uint64
	QueuedBytes          uint64
	NetworkWaitingBytes  uint64
	CapacityWaitingBytes uint64
	InFlightBytes        uint64
	UsefulBytes          uint64
	OutputBytes          uint64
	UnfinishedBytes      uint64
	RemainingBytes       uint64
	RemainingKnown       bool
}

type Set

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

func New

func New(config Config) (*Set, error)

func (*Set) Add

func (s *Set) Add(identity Identity, route Route, lane BlockSource) error

func (*Set) BindDownloadMetrics

func (s *Set) BindDownloadMetrics(metrics *downloadmetrics.Metrics)

BindDownloadMetrics is called before content activation, once per generation.

func (*Set) Close

func (s *Set) Close()

Close is the external ownership boundary. Attempt callbacks call Stop because synchronously joining their own attempt would prevent its deferred completion.

func (*Set) CompleteObservations

func (s *Set) CompleteObservations() SettlementObservationCompletion

CompleteObservations returns the producer-owned settlement cut. Close first joins lane work so no new summary can be admitted while this result is read.

func (*Set) ContentActivity

func (s *Set) ContentActivity() []ContentActivity

func (*Set) EstimateQueuedContent

func (s *Set) EstimateQueuedContent(identity Identity) time.Duration

EstimateQueuedContent exposes scheduling evidence, not route permission. Control requests remain usable while a lane is suspended for content-only policy.

func (*Set) ExpectRoute

func (s *Set) ExpectRoute(route Route) (*RouteSupply, error)

ExpectRoute lets queued demand survive a gap between connection generations. The connectivity owner must close the capability when its recovery work ends; a forbidden route can never acquire one, regardless of transport liveness.

func (*Set) Fetch

func (s *Set) Fetch(
	ctx context.Context,
	request Request,
) (Block, error)

Fetch returns the first consumer-validated block. Canceled competing attempts retain their capacity until they exit; Close joins that remaining ownership.

func (*Set) Len

func (s *Set) Len() int

func (*Set) MeasureLane

func (s *Set) MeasureLane(identity Identity) Measurement

MeasureLane reuses completed content measurements; it never generates probes. Retire only an idle, sampled route with a demonstrably faster alternative.

func (*Set) ObserveRemainingWork

func (s *Set) ObserveRemainingWork(snapshot func() RemainingWork) func()

ObserveRemainingWork follows a job, rather than mistaking its bounded range window for the complete selection. Discovery can remain open indefinitely.

func (*Set) RecordOutput

func (s *Set) RecordOutput(bytes uint64)

Output advances after the materializer accepts a range, independently of receipt, authentication, and crash-durable checkpoint progress.

func (*Set) RecoveryDemand

func (s *Set) RecoveryDemand() []Identity

RecoveryDemand identifies exact live generations that exhausted a queued immutable read. Healthy in-flight work and consumer backpressure do not grant recovery authority. The connection owner rechecks the identity before acting.

func (*Set) Remove

func (s *Set) Remove(identity Identity) bool

func (*Set) SampleLane

func (s *Set) SampleLane(identity Identity)

SampleLane grants a bounded opportunity, not a fixed traffic share. Allocation still owns route eligibility, output-frontier priority and physical capacity.

func (*Set) SamplingEvidence

func (s *Set) SamplingEvidence(identity Identity) (lanescheduling.SamplingEvidence, bool)

func (*Set) SchedulingDemand

func (s *Set) SchedulingDemand() SchedulingDemand

func (*Set) SettlementObservations

func (s *Set) SettlementObservations() observationstream.Consumer[SettlementSummary]

SettlementObservations returns nil when settlement observation was disabled. The receive-only capability leaves publication and completion with Set.

func (*Set) Stop

func (s *Set) Stop()

Stop closes admission and cancels attempts without waiting. BlockSource callbacks use it when a lane-local failure must terminate the whole set.

func (*Set) StopSampling

func (s *Set) StopSampling(identity Identity)

func (*Set) SuspendContent

func (s *Set) SuspendContent(identity Identity) (*ContentSuspension, error)

SuspendContent removes an authenticated logical lane from content admission without detaching its control transport. The initial exact identity prevents suspending an unintended incarnation, while the returned capability follows replacements because reconnects must not bypass an active admission policy.

type SettlementObservationCapacity

type SettlementObservationCapacity int

SettlementObservationCapacity is the exact number of summaries retained while the owner-selected consumer is not receiving. Zero disables settlement accounting and stream allocation.

type SettlementObservationCompletion

type SettlementObservationCompletion struct {
	Enqueued uint64
	Loss     SettlementObservationLoss
}

type SettlementObservationLoss

type SettlementObservationLoss struct {
	CapacityDropped uint64
}

SettlementObservationLoss names every producer-owned omission without merging lane identities into a synthetic summary.

func (SettlementObservationLoss) Total

func (loss SettlementObservationLoss) Total() uint64

type SettlementSummary

type SettlementSummary struct {
	ProtocolSessionID   protocolsession.ProtocolSessionID
	Route               Route
	Lane                Identity
	DeliveredBlocks     uint64
	DeliveredBytes      uint64
	FailedBlockAttempts uint64
	ReassignedBlocks    uint64
	Incomplete          bool
}

SettlementSummary is deliberately aggregate and text-free. The source contract excludes file and block identities so diagnostics cannot become a second content-access path.

func (SettlementSummary) DiagnosticRecord

func (v SettlementSummary) DiagnosticRecord() diag.Record

type WorkOrder

type WorkOrder struct {
	Priority   WorkPriority
	Distance   uint64
	LastServed uint64
}

Distance follows the consumer's output frontier; LastServed orders independent consumers fairly without reserving a fixed share of traffic for any of them.

type WorkPriority

type WorkPriority uint8
const (
	Download WorkPriority = iota
	Preview
	Prefetch
)

Jump to

Keyboard shortcuts

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