Documentation
¶
Overview ¶
Package attachment replicates bounded references to externally stored images, audio, video, and arbitrary data. It intentionally never transfers media bytes: an application authorizes object access and verifies the declared digest after download.
Index ¶
- Constants
- Variables
- type Delta
- type Options
- type Reference
- type Register
- func New(replicaID string) (*Register, error)
- func NewFromClockWithOptions(state clock.State, options Options) (*Register, error)
- func NewFromSnapshot(saved snapshot.Snapshot) (*Register, error)
- func NewFromSnapshotWithOptions(saved snapshot.Snapshot, options Options) (*Register, error)
- func NewWithOptions(replicaID string, options Options) (*Register, error)
- func (r *Register) ApplyDelta(change Delta) error
- func (r *Register) ClockState() clock.State
- func (r *Register) CompactTombstones(tags []crdt.Tag) (int, error)
- func (r *Register) Delete(key string) (Delta, error)
- func (r *Register) Frontier() map[string]crdt.Tag
- func (r *Register) Get(key string) (Reference, bool)
- func (r *Register) Keys() []string
- func (r *Register) MarshalBinary() ([]byte, error)
- func (r *Register) Merge(other *Register) error
- func (r *Register) Put(key string, ref Reference) (Delta, error)
- func (r *Register) Snapshot(frontier map[string]crdt.Tag) (snapshot.Snapshot, error)
- func (r *Register) SnapshotCurrentState() (snapshot.Snapshot, error)
- func (r *Register) State() crdt.StateSnapshot
- func (r *Register) TombstoneTags() []crdt.Tag
- func (r *Register) UnmarshalBinary(data []byte) error
- func (r *Register) UnmarshalBinaryWithLimits(data []byte, limits frame.Limits) error
Constants ¶
const ( // SemanticsVersion identifies the immutable attachment-reference schema // inside an LWW-Map replication manifest. It is deliberately separate from // the outer frame format and the descriptor's inner encoding version. SemanticsVersion uint64 = 1 )
Variables ¶
var ( ErrNilRegister = errors.New("attachment: nil register") ErrInvalidReference = errors.New("attachment: invalid reference") ErrInvalidKey = errors.New("attachment: invalid key") ErrResourceLimit = errors.New("attachment: resource limit exceeded") ErrInvalidDelta = errors.New("attachment: invalid delta") ErrContentMismatch = errors.New("attachment: content does not match reference") )
Functions ¶
This section is empty.
Types ¶
type Delta ¶
type Delta struct {
// contains filtered or unexported fields
}
Delta is an opaque, joinable attachment-reference change. Its LWW-Map frame remains TypeIDLWWMapDelta, so peers must use the attachment schema ID and SemanticsVersion in their authenticated replication manifest.
func UnmarshalDelta ¶
UnmarshalDelta uses DefaultOptions and the library's default frame limits.
func UnmarshalDeltaWithLimits ¶
UnmarshalDeltaWithLimits decodes a bounded LWW-Map delta and validates the immutable attachment descriptor schema before returning it to a caller.
func (Delta) MarshalBinary ¶
MarshalBinary serializes one attachment delta using TypeIDLWWMapDelta.
type Options ¶
Options bounds metadata retained by one Register and its underlying LWW-Map. MaxObjectBytes bounds the declared external object size to prevent a replicated reference from causing an unbounded fetch or allocation in a consumer.
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions returns conservative limits for collaborative documents. A deployment with larger galleries should explicitly choose and enforce a matching storage and transport budget.
type Reference ¶
Reference describes immutable content held by an application-owned object store. ObjectID is an opaque identifier, never a signed URL or credential. Digest is the SHA-256 of the bytes that an authorized downloader must verify before decoding or rendering them.
func (Reference) Verify ¶
Verify streams one downloaded object and checks its exact byte length and SHA-256 digest. It neither buffers the object nor performs I/O beyond the supplied reader, so storage selection and authorization remain application concerns. A short, oversized, or differently hashed object returns ErrContentMismatch.
type Register ¶
type Register struct {
// contains filtered or unexported fields
}
Register resolves concurrent changes to the same key by the canonical HLC order used by lww.Map. Deletes retain metadata until the embedding application has met the LWW tombstone lifecycle requirements.
func NewFromClockWithOptions ¶
NewFromClockWithOptions restores a replica clock with explicit limits.
func NewFromSnapshot ¶
NewFromSnapshot restores using DefaultOptions.
func NewFromSnapshotWithOptions ¶
NewFromSnapshotWithOptions restores a complete attachment register. The caller must use the same limits used by its replication group.
func NewWithOptions ¶
NewWithOptions creates a register with explicit metadata and object-size limits. It never stores the referenced media bytes.
func (*Register) ApplyDelta ¶
ApplyDelta validates descriptor schema and resource limits before joining a change. Invalid input leaves both the register and its HLC unchanged.
func (*Register) ClockState ¶
ClockState returns the HLC state that must be saved atomically with a complete snapshot before the replica ID is reused.
func (*Register) CompactTombstones ¶ added in v1.0.19
CompactTombstones removes only requested delete metadata. For replicated state, invoke it only after every active member has acknowledged the exact tags in one authenticated membership epoch, a post-compaction snapshot is durable, and obsolete deltas are retired. tombstonegc.SimpleCollector may call it only for its documented local-only lifecycle. Unknown tags are ignored; invalid or live tags leave the register unchanged.
func (*Register) Delete ¶
Delete removes key and returns a tombstone delta. Replaying a delete is idempotent and remains permitted at the entry limit.
func (*Register) MarshalBinary ¶
MarshalBinary returns the canonical LWW-Map state frame. The frame stores only attachment descriptors, never image, video, audio, or data bytes.
func (*Register) Merge ¶
Merge joins another validated register without retaining caller-owned data.
func (*Register) SnapshotCurrentState ¶
SnapshotCurrentState captures complete attachment metadata, frontier, and HLC state for atomic same-replica recovery.
func (*Register) State ¶
func (r *Register) State() crdt.StateSnapshot
State reports attachment metadata counts without exposing references.
func (*Register) TombstoneTags ¶ added in v1.0.19
TombstoneTags returns retained delete tags in canonical order. The tags are evidence to report to a tombstonegc.Coordinator, not proof that a caller may remove metadata by itself.
func (*Register) UnmarshalBinary ¶
UnmarshalBinary uses the library's default outer-frame bounds.