contentflow

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: AGPL-3.0, AGPL-3.0 Imports: 21 Imported by: ? modules, 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 contentflow implements the v2 revision and file-local block operation semantics above protocolsession's authenticated opaque-message boundary.

Index

Constants

View Source
const (
	DefaultShareBlockCacheBytes   = uint64(256) << 20
	DefaultProcessBlockCacheBytes = uint64(2) << 30
)
View Source
const (
	FragmentCodecVersion        = 1
	FragmentHeaderBytes         = 52
	MaxFragmentPayloadBytes     = 65_440
	MaxFragmentCount            = 128
	MaxOperationReassemblyBytes = uint64(records.MaxBlockRecordObjectBytes)
	FragmentInactivityTimeout   = 15 * time.Second
	FragmentTombstone           = 30 * time.Second
	MaxFragmentTombstones       = 4_096
)
View Source
const (
	RevisionErrorScope       = protocolsession.OperationScopeRevision
	BlockErrorScope          = protocolsession.OperationScopeBlock
	DefaultServiceQueueDepth = 256
	DefaultServiceWorkers    = 32
)
View Source
const (
	DefaultSessionReassemblyBytes   = uint64(64) << 20
	DefaultShareReassemblyBytes     = uint64(256) << 20
	DefaultProcessReassemblyBytes   = uint64(1) << 30
	DefaultSessionReassemblyRecords = uint32(16)
	DefaultShareReassemblyRecords   = uint32(64)
	DefaultProcessReassemblyRecords = uint32(256)
)
View Source
const (
	MaxInitialRangesPerFile = 256
	MaxInitialRangesPerOpen = 1_024

	RevisionLeaseTTL        = content.LeaseTTL
	RevisionLeaseRenewAfter = content.LeaseTTL - content.LeaseRenewWindow

	MinRevisionFailureRetryAfter = protocolsession.MinOperationFailureRetryAfter
	MaxRevisionFailureRetryAfter = protocolsession.MaxOperationFailureRetryAfter

	RevisionCodeStale                uint16 = 0x3001
	RevisionCodeNotFound             uint16 = 0x3002
	RevisionCodeUnreadable           uint16 = 0x3003
	RevisionCodeUnsupportedStability uint16 = 0x3004
	RevisionCodeQuota                uint16 = 0x3005
	RevisionCodeLeaseExpired         uint16 = 0x3006
	RevisionCodeDrift                uint16 = 0x3007
	RevisionCodeInvalidLease         uint16 = 0x3008

	BlockCodeInvalidRef       uint16 = 0x4001
	BlockCodeOutOfRange       uint16 = 0x4002
	BlockCodeObjectAuth       uint16 = 0x4003
	BlockCodeFragmentConflict uint16 = 0x4004
	BlockCodeTimeout          uint16 = 0x4005
	BlockCodeCancelled        uint16 = 0x4006
)
View Source
const ReleasedLeaseTombstoneLimit = 4_096

Variables

View Source
var (
	ErrFragmentMalformed  = errors.New("authenticated block fragment is malformed")
	ErrFragmentConflict   = errors.New("authenticated block fragment conflicts with prior data")
	ErrFragmentInactivity = errors.New("block fragment reassembly made no authenticated progress before timeout")
	ErrFragmentCancelled  = errors.New("block fragment operation was cancelled")
	ErrRecordDigest       = errors.New("reassembled block record has the wrong record identity")
	ErrAssemblerClosed    = errors.New("block fragment assembler is closed")
)
View Source
var (
	ErrReassemblyBudget = errors.New("block reassembly budget exceeded")
	ErrReassemblyClosed = errors.New("block reassembly account is closed")
)
View Source
var (
	ErrInvalidOpenRequest     = errors.New("content open request is invalid")
	ErrInvalidBlockRequest    = errors.New("content block request is invalid")
	ErrInvalidLeaseRequest    = errors.New("content lease request is invalid")
	ErrInvalidCancelRequest   = errors.New("content cancel request is invalid")
	ErrInvalidOpenResults     = errors.New("content open results are invalid")
	ErrInvalidOperationResult = errors.New("content operation result is invalid")
	ErrLeaseNotOwned          = errors.New("content lease is not owned by this protocol session")

	ErrServiceClosed         = errors.New("content sender service is closed")
	ErrServiceQueueFull      = errors.New("content sender service work queue is full")
	ErrOutboundUnavailable   = errors.New("content sender outbound path is unavailable")
	ErrNonCanonicalBody      = errors.New("content operation body is not canonical CBOR")
	ErrOperationIdentity     = errors.New("content operation identity is missing")
	ErrUnexpectedMessage     = errors.New("content sender received an unsupported message kind")
	ErrRevisionStoreContract = errors.New("revision store violated the content sender contract")
)
View Source
var ErrBlockResponseInactivity = errors.New("block request made no progress while awaiting its first fragment")
View Source
var (
	ErrInvalidCacheKey = errors.New("block payload cache key is invalid")
)

Functions

func DecodeLeaseRequest

func DecodeLeaseRequest(encoded []byte) (content.LeaseID, error)

func DecodeOperationComplete

func DecodeOperationComplete(encoded []byte) (uint32, error)

func EncodeBlockRequest

func EncodeBlockRequest(request BlockRequest) ([]byte, error)

func EncodeCancelReason

func EncodeCancelReason(reason CancelReason) ([]byte, error)

func EncodeLeaseRequest

func EncodeLeaseRequest(lease content.LeaseID) ([]byte, error)

func EncodeLeaseResult

func EncodeLeaseResult(lease content.RevisionLease) ([]byte, error)

func EncodeOpenRequest

func EncodeOpenRequest(request OpenRequest) ([]byte, error)

func EncodeOpenResults

func EncodeOpenResults(results OpenResults) ([]byte, error)

func EncodeOperationComplete

func EncodeOperationComplete(resultCount uint32) ([]byte, error)

func FragmentRecord

func FragmentRecord(operationID protocolsession.OperationID, object []byte) ([]protocolsession.Message, error)

func RegisterSenderHandlers

func RegisterSenderHandlers(router *protocolsession.RoleRouter, handler *SenderHandler) error

func ValidateLeaseResult

func ValidateLeaseResult(encoded []byte) error

func ValidateOpenResults

func ValidateOpenResults(encoded []byte) error

Types

type Assembler

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

func NewAssembler

func NewAssembler(sessionID protocolsession.ProtocolSessionID, hierarchy ReassemblyHierarchy, now func() time.Time) (*Assembler, error)

func (*Assembler) AcceptAuthenticated

func (a *Assembler) AcceptAuthenticated(plaintext []byte) (AssemblyResult, error)

func (*Assembler) ActiveRecords

func (a *Assembler) ActiveRecords() int

func (*Assembler) CancelOperation

func (a *Assembler) CancelOperation(operationID protocolsession.OperationID) error

func (*Assembler) Close

func (a *Assembler) Close()

Close releases all three levels of reservations immediately. The assembler cannot receive late frames once its owning ProtocolSession is gone, so retaining tombstones after this boundary would only prolong memory charges.

func (*Assembler) CompleteOperation

func (a *Assembler) CompleteOperation(operationID protocolsession.OperationID) error

func (*Assembler) SweepTimeouts

func (a *Assembler) SweepTimeouts() []protocolsession.OperationID

func (*Assembler) TryReserve

func (a *Assembler) TryReserve(bytes uint64) (*AssemblyCapacity, <-chan struct{}, error)

type AssemblyCapacity

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

AssemblyCapacity is one physical response, including its complete sealed object while authentication runs. Receipt alone cannot return these bytes.

func (*AssemblyCapacity) AcceptAuthenticated

func (capacity *AssemblyCapacity) AcceptAuthenticated(plaintext []byte) (AssemblyResult, error)

func (*AssemblyCapacity) Release

func (capacity *AssemblyCapacity) Release()

type AssemblyResult

type AssemblyResult struct {
	Status        AssemblyStatus
	OperationID   protocolsession.OperationID
	RecordID      records.RecordID
	Object        []byte
	ReceivedBytes uint64
}

type AssemblyStatus

type AssemblyStatus uint8
const (
	FragmentAccepted AssemblyStatus = iota + 1
	FragmentDuplicate
	RecordComplete
	FragmentTombstoned
)

type BlockCacheKey

type BlockCacheKey struct {
	ShareInstance   catalog.ShareInstance
	FileID          catalog.FileID
	FileRevision    content.FileRevision
	LocalBlockIndex uint64
}

func NewBlockCacheKey

func NewBlockCacheKey(descriptor content.FileRevisionDescriptor, index uint64) (BlockCacheKey, error)

type BlockReceivePhase

type BlockReceivePhase string

BlockReceivePhase distinguishes wire queue delay from a stalled assembly.

const (
	BlockAwaitingFirstFragment BlockReceivePhase = "awaiting_first_fragment"
	BlockReceivingFragments    BlockReceivePhase = "receiving_fragments"
)

type BlockRequest

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

func DecodeBlockRequest

func DecodeBlockRequest(encoded []byte) (BlockRequest, error)

func NewBlockRequest

func NewBlockRequest(leaseID content.LeaseID, indices []uint64) (BlockRequest, error)

func (BlockRequest) Indices

func (r BlockRequest) Indices() []uint64

func (BlockRequest) LeaseID

func (r BlockRequest) LeaseID() content.LeaseID

type BlockResponseQueue

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

BlockResponseQueue belongs to one content lane. Its zero value is ready to use. Only work already ahead of a request can justify its first-response wait: later requests, heartbeats and duplicate fragments cannot keep it alive.

func (*BlockResponseQueue) Begin

func (queue *BlockResponseQueue) Begin(parent context.Context, inactivity time.Duration) *BlockResponseWait

type BlockResponseWait

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

func (*BlockResponseWait) Close

func (wait *BlockResponseWait) Close()

func (*BlockResponseWait) Context

func (wait *BlockResponseWait) Context() context.Context

func (*BlockResponseWait) Progress

func (wait *BlockResponseWait) Progress()

Progress is called only after accepting a new authenticated fragment. The finite predecessor set makes queue allowances bounded by useful existing work, without deriving a correctness deadline from a noisy throughput estimate.

func (*BlockResponseWait) Resume

func (wait *BlockResponseWait) Resume()

func (*BlockResponseWait) Suspend

func (wait *BlockResponseWait) Suspend()

Suspend excludes local validation from the next-message inactivity clock.

type BlockWaitTimeout

type BlockWaitTimeout struct {
	Phase         BlockReceivePhase
	Waited        time.Duration
	QueueProgress uint64
}

BlockWaitTimeout preserves the decision behind an operation's retirement.

func (*BlockWaitTimeout) Error

func (failure *BlockWaitTimeout) Error() string

func (*BlockWaitTimeout) Unwrap

func (failure *BlockWaitTimeout) Unwrap() error

type CancelReason

type CancelReason uint8
const (
	CancelReasonUser CancelReason = iota + 1
	CancelReasonSuperseded
	CancelReasonOutputAbort
	CancelReasonTimeout
	CancelReasonLaneRace
)

func DecodeCancelReason

func DecodeCancelReason(encoded []byte) (CancelReason, error)

type Fragment

type Fragment struct {
	OperationID protocolsession.OperationID
	RecordID    records.RecordID
	Index       uint32
	Count       uint32
	TotalLength uint32
	Last        bool
	Payload     []byte
}

func DecodeAuthenticatedFragment

func DecodeAuthenticatedFragment(plaintext []byte) (Fragment, error)

DecodeAuthenticatedFragment must only receive plaintext returned by an OperationEnvelope opener. Its strict validation completes before any caller can use TotalLength to reserve or allocate reassembly storage.

type OpenItem

type OpenItem struct {
	FileID        catalog.FileID
	InitialRanges content.RangeSet
}

type OpenRequest

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

func DecodeOpenRequest

func DecodeOpenRequest(encoded []byte) (OpenRequest, error)

func NewOpenRequest

func NewOpenRequest(items []OpenItem) (OpenRequest, error)

func (OpenRequest) Items

func (r OpenRequest) Items() []OpenItem

type OpenResult

type OpenResult struct {
	FileID         catalog.FileID
	Lease          content.RevisionLease
	RevisionObject []byte
	Failure        *RevisionFailure
}

func FailedOpen

func FailedOpen(file catalog.FileID, failure RevisionFailure) (OpenResult, error)

func SuccessfulOpen

func SuccessfulOpen(file catalog.FileID, lease content.RevisionLease, object []byte) (OpenResult, error)

type OpenResults

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

func NewOpenResults

func NewOpenResults(items []OpenResult) (OpenResults, error)

func (OpenResults) Items

func (r OpenResults) Items() []OpenResult

type OperationFailure

type OperationFailure = protocolsession.OperationFailure

type ProcessCacheBudget

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

func NewProcessCacheBudget

func NewProcessCacheBudget(limit uint64) (*ProcessCacheBudget, error)

func (*ProcessCacheBudget) Close

func (b *ProcessCacheBudget) Close() error

func (*ProcessCacheBudget) Used

func (b *ProcessCacheBudget) Used() uint64

type ReassemblyAccount

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

func NewReassemblyAccount

func NewReassemblyAccount(name string, limits ReassemblyLimits) (*ReassemblyAccount, error)

func (*ReassemblyAccount) Close

func (a *ReassemblyAccount) Close() error

func (*ReassemblyAccount) Usage

type ReassemblyHierarchy

type ReassemblyHierarchy struct {
	Process *ReassemblyAccount
	Share   *ReassemblyAccount
	Session *ReassemblyAccount
}

type ReassemblyLimits

type ReassemblyLimits struct {
	Bytes   uint64
	Records uint32
}

type ReassemblyUsage

type ReassemblyUsage struct {
	Bytes   uint64
	Records uint32
}

type ReceivedOpenResult

type ReceivedOpenResult struct {
	FileID         catalog.FileID
	RevisionObject []byte
	Lease          RemoteLease
	Failure        *RevisionFailure
}

func DecodeOpenResults

func DecodeOpenResults(encoded []byte, expected []catalog.FileID) ([]ReceivedOpenResult, error)

type RecordEncoder added in v0.1.4

type RecordEncoder interface {
	EncodeRevision(content.FileRevisionDescriptor) ([]byte, error)
	EncodeBlock(records.BlockRecord) ([]byte, error)
}

type RemoteLease

type RemoteLease struct {
	ID         content.LeaseID
	TTL        time.Duration
	RenewAfter time.Duration
}

func DecodeLeaseResult

func DecodeLeaseResult(encoded []byte, expected content.LeaseID) (RemoteLease, error)

type RevisionFailure

type RevisionFailure struct {
	Code       uint16
	Retryable  bool
	RetryAfter time.Duration
	// contains filtered or unexported fields
}

func NewRevisionFailure

func NewRevisionFailure(code uint16, retryable bool, retryAfter time.Duration) (RevisionFailure, error)

func (RevisionFailure) CapacityDecisionID

func (failure RevisionFailure) CapacityDecisionID() revisioncapacity.CapacityDecisionID

type SemanticOutbound

type SemanticOutbound interface {
	SendControl(ctx context.Context, kind protocolsession.MessageKind, operationID protocolsession.OperationID, bodyWithoutSignature []byte) (protocolsession.ResponseSendResult, error)
	SendFragment(ctx context.Context, message protocolsession.Message) error
	SendOperationError(ctx context.Context, operationID protocolsession.OperationID, failure OperationFailure) error
}

SemanticOutbound keeps sender-control construction inside the lane writer. SendControl must add key 255 and sign with the exact writer-assigned sequence atomically before envelope sealing; bodyWithoutSignature is canonical CBOR.

type SenderDecisionStage

type SenderDecisionStage uint8
const (
	SenderDecisionCapacityBusy SenderDecisionStage = iota + 1
	SenderDecisionLeaseRelinquished
	SenderDecisionLeaseUndelivered
	SenderDecisionLeaseDetached
	SenderDecisionBlockLeaseReleased
	SenderDecisionBlockLeaseNotOwned
	SenderDecisionBlockLeaseExpired
	SenderDecisionBlockLeaseInvalid
)

type SenderDecisionTrace

type SenderDecisionTrace struct {
	Stage              SenderDecisionStage
	OperationID        protocolsession.OperationID
	RequestKind        protocolsession.MessageKind
	CapacityDecisionID revisioncapacity.CapacityDecisionID
	LeaseID            content.LeaseID
}

func (SenderDecisionTrace) DiagnosticValue

func (value SenderDecisionTrace) DiagnosticValue() diag.Value

type SenderDecisionTraceFunc

type SenderDecisionTraceFunc func(SenderDecisionTrace)

func (SenderDecisionTraceFunc) TraceSenderDecision

func (function SenderDecisionTraceFunc) TraceSenderDecision(event SenderDecisionTrace)

type SenderDecisionTracer

type SenderDecisionTracer interface {
	TraceSenderDecision(SenderDecisionTrace)
}

type SenderHandler

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

func NewSenderHandler

func NewSenderHandler(config SenderHandlerConfig) (*SenderHandler, error)

func (*SenderHandler) HandleMessage

func (h *SenderHandler) HandleMessage(ctx context.Context, message protocolsession.Message) error

func (*SenderHandler) LifecycleSnapshot

func (h *SenderHandler) LifecycleSnapshot() SenderHandlerLifecycle

func (*SenderHandler) Run

func (h *SenderHandler) Run(ctx context.Context) error

type SenderHandlerConfig

type SenderHandlerConfig struct {
	Service        *SenderService
	Outbound       SemanticOutbound
	QueueDepth     int
	Workers        int
	DecisionTracer SenderDecisionTracer
}

type SenderHandlerLifecycle

type SenderHandlerLifecycle struct {
	ActiveOperations int
	RunningWorkers   int
	QueuedOperations int
}

SenderHandlerLifecycle is a point-in-time view of operation ownership. It is intentionally limited to counts: callers can diagnose drain boundaries without acquiring the generation capabilities stored in the handler's active map.

type SenderService

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

func NewSenderService

func NewSenderService(config SenderServiceConfig) (*SenderService, error)

func (*SenderService) Close

func (s *SenderService) Close() error

func (*SenderService) Open

func (s *SenderService) Open(ctx context.Context, request OpenRequest) (OpenResults, error)

func (*SenderService) Release

func (s *SenderService) Release(leaseID content.LeaseID) error

func (*SenderService) Renew

func (s *SenderService) Renew(leaseID content.LeaseID) (content.RevisionLease, error)

func (*SenderService) ServeBlocks

func (s *SenderService) ServeBlocks(
	ctx context.Context,
	operationID protocolsession.OperationID,
	request BlockRequest,
	emit func(context.Context, protocolsession.Message) error,
) (uint32, error)

type SenderServiceConfig

type SenderServiceConfig struct {
	Store           RevisionStore
	SessionCapacity *revisioncapacity.SessionRegistration
	Encoder         RecordEncoder
	Cache           *SharedBlockCache
}

type SharedBlockCache

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

func NewSharedBlockCache

func NewSharedBlockCache(share catalog.ShareInstance, maxBytes uint64, process *ProcessCacheBudget) (*SharedBlockCache, error)

func (*SharedBlockCache) Close

func (c *SharedBlockCache) Close()

Close is the external ownership boundary. A loader that needs to terminate its owner calls Stop; joining from that same callback cannot make progress.

func (*SharedBlockCache) Get

func (c *SharedBlockCache) Get(ctx context.Context, key BlockCacheKey, load func(context.Context) ([]byte, error)) ([]byte, error)

func (*SharedBlockCache) InvalidateRevision

func (c *SharedBlockCache) InvalidateRevision(file catalog.FileID, revision content.FileRevision)

func (*SharedBlockCache) Stop

func (c *SharedBlockCache) Stop()

Stop rejects new work and cancels current work without waiting. Loader callbacks use Stop when they must end the cache from inside a counted load.

func (*SharedBlockCache) UsedBytes

func (c *SharedBlockCache) UsedBytes() uint64

Jump to

Keyboard shortcuts

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