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
- Variables
- func ServeURL(base string, root [32]byte) string
- type Advert
- type Backend
- type Export
- type Native
- func (n *Native) Advertise(ctx context.Context, root [32]byte, until uint64) (*Advert, error)
- func (n *Native) Delete(hash [32]byte) error
- func (n *Native) Get(hash [32]byte, offset, length uint64) ([]byte, error)
- func (n *Native) Has(hash [32]byte) bool
- func (n *Native) Open(hash [32]byte) (*os.File, error)
- func (n *Native) Path(hash [32]byte) string
- func (n *Native) Put(hash [32]byte, data []byte) error
- func (n *Native) ServeURL(root [32]byte) string
- func (n *Native) Size(hash [32]byte) int64
- func (n *Native) Walk(f func(hash [32]byte, size int64)) error
Constants ¶
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 ¶
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 ¶
Types ¶
type Advert ¶
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 ¶
OpenExport opens (creating) an export directory over store.
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.
func OpenNative ¶
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) Delete ¶
Delete removes an object. The front decides that nothing it advertises still names it.