Documentation
¶
Overview ¶
Package inbox stores authenticated packs that have been received but not yet processed into the packstore. An entry is a single self-describing file: a CBOR meta header framed by its big-endian length, followed by the raw amberpack body. Entries are content-addressed by blake3 of the body, so a re-received identical pack is idempotent. A pool of workers drains the directory into the store; setting a reference waits on the entries tagged with that root. The directory is the only durable state — on restart a scan rebuilds the in-memory view and resumes processing.
Index ¶
- type Inbox
- func (ib *Inbox) Close() error
- func (ib *Inbox) Commit(tmpPath string, bodyHash []byte, root key.Key) (added bool, err error)
- func (ib *Inbox) Discard(tmpPath string)
- func (ib *Inbox) Stage(meta Meta, body io.Reader) (tmpPath string, bodyHash []byte, n int64, err error)
- func (ib *Inbox) WaitFor(root key.Key)
- type Meta
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Inbox ¶
type Inbox struct {
// contains filtered or unexported fields
}
Inbox receives packs, persists them durably, and drains them into a packstore from a worker pool. It is safe for concurrent use.
func Open ¶
Open prepares the inbox directory tree, recovers entries left by a previous run, and starts `workers` processing goroutines. workers <= 0 means runtime.GOMAXPROCS(0). A nil log discards.
func (*Inbox) Close ¶
Close stops accepting new work, drains what is already queued, and waits for the processing goroutines to exit. Staged-but-uncommitted tmp files are left for the next Open to sweep.
func (*Inbox) Commit ¶
Commit publishes a staged tmp file under its content-addressed name and enqueues it. It is idempotent: if an entry with the same body already exists, the tmp file is discarded and added is false. root updates the barrier accounting and must equal the root staged into the file.
func (*Inbox) Stage ¶
func (ib *Inbox) Stage(meta Meta, body io.Reader) (tmpPath string, bodyHash []byte, n int64, err error)
Stage writes meta and streams body into a fresh tmp file, returning the tmp path, blake3 of the body bytes (only the body feeds the hash), and the body length. The caller authorizes the request against the hash, then calls Commit or Discard.
type Meta ¶
type Meta struct {
Ref string `cbor:"0,keyasint"`
Root []byte `cbor:"1,keyasint"` // 32-byte root key
ReceivedAt int64 `cbor:"2,keyasint"` // ns since the Unix epoch
}
Meta tags a staged pack with the (ref, root) it belongs to and when it arrived. The barrier keys on Root alone; Ref and ReceivedAt are carried for operability (which ref a pending pack was for, how old it is).