backend

package
v0.41.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2026 License: Apache-2.0 Imports: 11 Imported by: 1 module, 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 backend is the hold-backend interface of spec section 17 and the native content-addressed backend on local disk.

A provider is a market front over a hold backend. The front receives, validates, decides, advertises and answers; the backend stores and serves. The interface is frozen (frozen.md section 11) so that a backend built later for an incumbent UHRP host targets a surface that does not move: Put, Has, Get(hash, offset, length), ServeURL and Advertise.

Index

Constants

View Source
const MaxObject = 4 << 20

MaxObject is the largest CHIRP object a native store holds: a Profile 1 blob of 4 MiB. A node is at most 65,536 bytes.

Variables

View Source
var (
	// ErrHash is bytes that do not hash to the hash they are put under.
	ErrHash = errors.New("backend: the bytes do not hash to the object's hash")
	// ErrMissing is an object the backend does not hold.
	ErrMissing = errors.New("backend: no such object")
	// ErrRange is a range outside the object.
	ErrRange = errors.New("backend: the range is outside the object")
	// ErrTooLarge is an object over the backend's bound.
	ErrTooLarge = errors.New("backend: the object is over the bound")
)

Refusals.

Functions

func ServeURL

func ServeURL(base string, root [32]byte) string

ServeURL is a root's BRC-167 root object route below base: <base>/chirp/v1/<root identifier>/objects/<root identifier>.

Types

type Advert struct {
	Txid   string // display order
	Vout   uint32
	Expiry uint64
	// BEEF is the advertisement's transaction with what it needs to verify:
	// its own proof once mined, else its ancestry.
	BEEF []byte
}

Advert is an advertisement a backend made the closure held under: the transaction that holds it, as BEEF, and where in it.

type Backend

type Backend interface {
	// Put stores one CHIRP object under its SHA-256. It is idempotent and
	// refuses bytes that do not hash to hash.
	Put(hash [32]byte, data []byte) error
	// Has reports whether the backend can serve the object now.
	Has(hash [32]byte) bool
	// Get is a byte range of a stored object. The front verifies what it
	// gets (against the object hash, or a segment against the proof tree)
	// before it uses it.
	Get(hash [32]byte, offset, length uint64) ([]byte, error)
	// ServeURL is the HTTPS URL the root's advertisement names: the root
	// object's BRC-167 route at whoever serves the bytes.
	ServeURL(root [32]byte) string
	// Advertise makes the closure held through until (Unix seconds) and
	// returns the advertisement that says so: for a native backend the
	// front leases the closure and mints its own advertisement; for a
	// bridge backend the incumbent commits or renews through its own
	// routes and the bridge returns the incumbent's advertisement.
	Advertise(ctx context.Context, root [32]byte, until uint64) (*Advert, error)
}

Backend is the hold-backend interface (spec section 17).

type Export

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

Export is a read-only view of the store for an NFS export (design 3.6): <dir>/<root hex>/<index> for each object of a held closure, the root node at index 0 and the rest in the closure's order, each a hard link to the object's file so its handle is stable while the object is kept. The provider is its one writer; the operator exports the directory read-only with the system's own NFS server. The directory must be on the store's file system.

func OpenExport

func OpenExport(dir string, store *Native) (*Export, error)

OpenExport opens (creating) an export directory over store.

func (*Export) Add

func (e *Export) Add(root [32]byte, objects [][32]byte) error

Add links a held closure's objects under its root, replacing what was there; the directory is read-only once complete.

func (*Export) Remove

func (e *Export) Remove(root [32]byte) error

Remove takes a root's view away.

type Native

type Native struct {

	// Advertiser mints the advertisement for a native backend (the front).
	Advertiser func(ctx context.Context, root [32]byte, until uint64) (*Advert, error)
	// contains filtered or unexported fields
}

Native is the native backend: a content-addressed store on local disk, one file per object at objects/<first two hex digits>/<64 hex digits>, written whole to a temporary file, synced and renamed into place, so a crash never leaves a partial object under its name. Every path is made from a hash's hex digits alone, so no input names a file outside the store.

Advertise is the front's: it leases the closure in its own records and mints the advertisement, and the native backend hands the call to it.

Writes of one store run side by side: each has its own temporary file and the rename is atomic, so two puts of one object leave the same bytes under its name whichever lands last. Concurrent fsyncs share the filesystem's journal commits, which is what makes a store on a slow-syncing disk keep up.

func OpenNative

func OpenNative(dir, baseURL string) (*Native, error)

OpenNative opens (creating) a native store under dir, serving at baseURL: the provider's public URL, below which /chirp/v1/ routes are served.

func (*Native) Advertise

func (n *Native) Advertise(ctx context.Context, root [32]byte, until uint64) (*Advert, error)

Advertise hands the call to the front, which leases and mints.

func (*Native) Delete

func (n *Native) Delete(hash [32]byte) error

Delete removes an object. The front decides that nothing it advertises still names it.

func (*Native) Get

func (n *Native) Get(hash [32]byte, offset, length uint64) ([]byte, error)

Get reads length bytes from offset.

func (*Native) Has

func (n *Native) Has(hash [32]byte) bool

Has reports whether the object's file is there.

func (*Native) Open

func (n *Native) Open(hash [32]byte) (*os.File, error)

Open opens an object's file for reading, for a route that streams it.

func (*Native) Path

func (n *Native) Path(hash [32]byte) string

Path is where an object's file is.

func (*Native) Put

func (n *Native) Put(hash [32]byte, data []byte) error

Put stores data under hash.

func (*Native) PutHashed added in v0.11.1

func (n *Native) PutHashed(hash [32]byte, data []byte) error

PutHashed is Put for a caller that has just hashed data itself: a 4 MiB piece costs a provider's take milliseconds to hash, and a store keeps what it is handed under the name it is given, so the name must be right.

func (*Native) ServeURL

func (n *Native) ServeURL(root [32]byte) string

ServeURL is the root object's route at the provider's public URL.

func (*Native) Size

func (n *Native) Size(hash [32]byte) int64

Size is an object's length, or -1 when it is not held.

func (*Native) Walk

func (n *Native) Walk(f func(hash [32]byte, size int64)) error

Walk calls f for every object file the store holds, with its size.

type RangeReporter

type RangeReporter interface {
	RangeWrong(hash [32]byte)
}

RangeReporter is optional: a backend that reads by reference implements it to be told when a ranged read came back as bytes other than the same range of the whole object, which held to its hash was right. The front then used the whole object; the backend may stop asking that server for ranges.

Jump to

Keyboard shortcuts

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