inbox

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: GPL-3.0, LGPL-3.0 Imports: 16 Imported by: 0

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

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

func Open(dir string, store *packstore.Store, workers int, log *slog.Logger, opts ...Option) (*Inbox, error)

func (*Inbox) Close

func (ib *Inbox) Close() error

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

func (ib *Inbox) Commit(tmpPath string, bodyHash []byte, root key.Key) (added bool, err error)

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) Discard

func (ib *Inbox) Discard(tmpPath string)

Discard removes a staged tmp file (authorization failed or oversize).

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.

func (*Inbox) WaitFor

func (ib *Inbox) WaitFor(root key.Key)

WaitFor blocks until no entries tagged with root remain unprocessed. With an empty group it returns immediately.

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).

type Option added in v0.0.6

type Option func(*Inbox)

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. Option tweaks Open.

func WithGate added in v0.0.6

func WithGate(gate func() (done func())) Option

WithGate brackets every entry's store write with gate: acquire before the WriteParallel, release after. The GC collector's BeginWrite is the intended gate — it keeps a drain's dedup hits from racing a sweep's pack removal.

Jump to

Keyboard shortcuts

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