Documentation
¶
Overview ¶
Package contentflow implements the v2 revision and file-local block operation semantics above protocolsession's authenticated opaque-message boundary.
Index ¶
- Constants
- Variables
- func DecodeLeaseRequest(encoded []byte) (content.LeaseID, error)
- func DecodeOperationComplete(encoded []byte) (uint32, error)
- func EncodeBlockRequest(request BlockRequest) ([]byte, error)
- func EncodeCancelReason(reason CancelReason) ([]byte, error)
- func EncodeLeaseRequest(lease content.LeaseID) ([]byte, error)
- func EncodeLeaseResult(lease content.RevisionLease) ([]byte, error)
- func EncodeOpenRequest(request OpenRequest) ([]byte, error)
- func EncodeOpenResults(results OpenResults) ([]byte, error)
- func EncodeOperationComplete(resultCount uint32) ([]byte, error)
- func FragmentRecord(operationID protocolsession.OperationID, object []byte) ([]protocolsession.Message, error)
- func RegisterSenderHandlers(router *protocolsession.RoleRouter, handler *SenderHandler) error
- func ValidateLeaseResult(encoded []byte) error
- func ValidateOpenResults(encoded []byte) error
- type Assembler
- func (a *Assembler) AcceptAuthenticated(plaintext []byte) (AssemblyResult, error)
- func (a *Assembler) ActiveRecords() int
- func (a *Assembler) CancelOperation(operationID protocolsession.OperationID) error
- func (a *Assembler) Close()
- func (a *Assembler) CompleteOperation(operationID protocolsession.OperationID) error
- func (a *Assembler) SweepTimeouts() []protocolsession.OperationID
- func (a *Assembler) TryReserve(bytes uint64) (*AssemblyCapacity, <-chan struct{}, error)
- type AssemblyCapacity
- type AssemblyResult
- type AssemblyStatus
- type BlockCacheKey
- type BlockReceivePhase
- type BlockRequest
- type BlockResponseQueue
- type BlockResponseWait
- type BlockWaitTimeout
- type CancelReason
- type Fragment
- type OpenItem
- type OpenRequest
- type OpenResult
- type OpenResults
- type OperationFailure
- type ProcessCacheBudget
- type ReassemblyAccount
- type ReassemblyHierarchy
- type ReassemblyLimits
- type ReassemblyUsage
- type ReceivedOpenResult
- type RecordSealer
- type RemoteLease
- type RevisionFailure
- type RevisionStore
- type SemanticOutbound
- type SenderDecisionStage
- type SenderDecisionTrace
- type SenderDecisionTraceFunc
- type SenderDecisionTracer
- type SenderHandler
- type SenderHandlerConfig
- type SenderHandlerLifecycle
- type SenderService
- func (s *SenderService) Close() error
- func (s *SenderService) Open(ctx context.Context, request OpenRequest) (OpenResults, error)
- func (s *SenderService) Release(leaseID content.LeaseID) error
- func (s *SenderService) Renew(leaseID content.LeaseID) (content.RevisionLease, error)
- func (s *SenderService) ServeBlocks(ctx context.Context, operationID protocolsession.OperationID, ...) (uint32, error)
- type SenderServiceConfig
- type SharedBlockCache
- func (c *SharedBlockCache) Close()
- func (c *SharedBlockCache) Get(ctx context.Context, key BlockCacheKey, ...) ([]byte, error)
- func (c *SharedBlockCache) InvalidateRevision(file catalog.FileID, revision content.FileRevision)
- func (c *SharedBlockCache) Stop()
- func (c *SharedBlockCache) UsedBytes() uint64
Constants ¶
const ( DefaultProcessSealedCacheBytes = uint64(2) << 30 )
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 )
const ( RevisionErrorScope = protocolsession.OperationScopeRevision BlockErrorScope = protocolsession.OperationScopeBlock DefaultServiceQueueDepth = 256 DefaultServiceWorkers = 32 )
const ( DefaultSessionReassemblyBytes = uint64(64) << 20 DefaultProcessReassemblyBytes = uint64(1) << 30 DefaultSessionReassemblyRecords = uint32(16) DefaultProcessReassemblyRecords = uint32(256) )
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 )
const ReleasedLeaseTombstoneLimit = 4_096
Variables ¶
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") )
var ( ErrReassemblyBudget = errors.New("block reassembly budget exceeded") ErrReassemblyClosed = errors.New("block reassembly account is closed") )
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") 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") )
var ErrBlockResponseInactivity = errors.New("block request made no progress while awaiting its first fragment")
var ErrInvalidCacheKey = errors.New("sealed block cache key is invalid")
Functions ¶
func DecodeOperationComplete ¶
func EncodeBlockRequest ¶
func EncodeBlockRequest(request BlockRequest) ([]byte, error)
func EncodeCancelReason ¶
func EncodeCancelReason(reason CancelReason) ([]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 FragmentRecord ¶
func FragmentRecord(operationID protocolsession.OperationID, object []byte) ([]protocolsession.Message, error)
func RegisterSenderHandlers ¶
func RegisterSenderHandlers(router *protocolsession.RoleRouter, handler *SenderHandler) error
func ValidateLeaseResult ¶
func ValidateOpenResults ¶
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 (*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 {
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 ¶
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 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 ¶
func (a *ReassemblyAccount) Usage() ReassemblyUsage
type ReassemblyHierarchy ¶
type ReassemblyHierarchy struct {
Process *ReassemblyAccount
Session *ReassemblyAccount
}
type ReassemblyLimits ¶
type ReassemblyUsage ¶
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 RecordSealer ¶
type RecordSealer interface {
SealRevision(content.FileRevisionDescriptor) ([]byte, error)
SealBlock(records.BlockRecord) (records.SealedBlock, error)
}
type RemoteLease ¶
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 (RevisionFailure) CapacityDecisionID ¶
func (failure RevisionFailure) CapacityDecisionID() revisioncapacity.CapacityDecisionID
type RevisionStore ¶
type RevisionStore interface {
OpenRevisions(context.Context, []content.OpenRevisionRequest, *revisioncapacity.SessionRegistration) ([]content.OpenRevisionResult, error)
RenewLease(content.LeaseID) (content.RevisionLease, error)
EndLease(content.LeaseID, content.LeaseEndKind) error
ValidateLease(content.LeaseID, content.FileRevisionDescriptor) error
ReadBlock(context.Context, content.LeaseID, content.BlockRef) ([]byte, error)
}
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
type SenderHandlerConfig ¶
type SenderHandlerConfig struct {
Service *SenderService
Outbound SemanticOutbound
QueueDepth int
Workers int
DecisionTracer SenderDecisionTracer
}
type SenderHandlerLifecycle ¶
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) 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
Sealer RecordSealer
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