reader

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 25 Imported by: 0 modules, 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 reader is a bstore reader (spec section 15): it asks the hosts it is given the free lookup questions of spec section 11.1, verifies every token, entry and advertisement against its own headers, proves what a key names, that a key is absent and that a listing page is complete against the chain's latest token, and reads an object's closure from its advertisers, every byte held to its hash before it is released. A host that answers something that does not verify is named in the log and the next host is asked; a provider that serves wrong bytes is named and the next advertiser is asked.

Index

Constants

View Source
const PageList = 256

PageList is the frozen `list` page maximum.

Variables

View Source
var (
	// ErrUnavailable is no host answering anything that verifies: an empty
	// answer proves nothing (spec section 16.3).
	ErrUnavailable = errors.New("reader: no host answered anything that verifies")
	// ErrUnheld is a key the map names whose entry no host produces.
	ErrUnheld = errors.New("reader: the map names the key's entry and no host produces it")
	// ErrRefused is an answer that verifies and fails a check that names
	// the owner or the writer (spec section 15.4, exit 1).
	ErrRefused = errors.New("reader: refused")
	// ErrNoSource is a blob no advertiser served as its hash names it.
	ErrNoSource = errors.New("reader: no advertiser served the object")
)

Errors a caller maps to its answers.

View Source
var ErrContentHash = errors.New("reader: the content does not hash to the entry's contentHash")

ErrContentHash is a whole read whose content does not hash to the entry's contentHash (spec section 15.2 step 8): the writer's fault.

View Source
var ErrNoChain = errors.New("reader: no host answers a token of the chain that verifies")

ErrNoChain is a chain no host answers a token of that verifies.

View Source
var ReadAhead = 2

ReadAhead is how many blobs WriteRange fetches ahead of the one it writes.

Functions

func TokenTxid

func TokenTxid(s string) ([32]byte, error)

TokenTxid parses a display-order txid.

Types

type Chain

type Chain struct {
	Bucket string
	Owner  []byte
	ID     [32]byte
}

Chain is a bucket chain a reader reads: the identifier, the owner and the bucket id (spec section 3.3).

type Entry

type Entry struct {
	Entry  *storerec.Entry
	Record []byte
	C      [32]byte // hash byte order
	// BEEF is the carrier as the host answered it.
	BEEF []byte
}

Entry is an entry a reader verified: its carrier's rules (spec section 12.1) and its funding tree's proof in the reader's headers.

func (*Entry) Txid

func (e *Entry) Txid() string

Txid is the carrier's txid in display order.

type Found

type Found struct {
	Token  *Token
	Result storerec.ObjectResult
	// Entry is the put the map names, for ObjectFound.
	Entry *Entry
}

Found is what an object answer proves about a key.

type HeldStore

type HeldStore interface {
	Held(chain string) *storerec.Held
	SetHeld(chain string, h storerec.Held) error
}

HeldStore keeps, per chain, the highest token a reader verified, across restarts (spec section 15.1).

type Local

type Local interface {
	Get(h [32]byte) ([]byte, error)
}

Local is a reader's own copy of closures, tried before any advertiser.

type Object

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

Object is an object's closure opened for reading: the root and every branch fetched and checked, the blob references in content order.

func (*Object) Blobs

func (o *Object) Blobs() []chirp.Child

Blobs are the closure's blob references in content order.

func (*Object) Object

func (o *Object) Object(ctx context.Context, h [32]byte) ([]byte, error)

Object is one object of the closure, held to its hash.

func (*Object) Objects

func (o *Object) Objects() [][32]byte

Objects are the closure's distinct objects: the root, the branches, then the blobs (a publisher's Closure).

func (*Object) Size

func (o *Object) Size() uint64

Size is the object's length.

func (*Object) WriteRange

func (o *Object) WriteRange(ctx context.Context, w io.Writer, off, n uint64) error

WriteRange writes bytes [off, off+n) of the object to w, fetching each blob it overlaps whole and holding it to its hash before a byte of it is written (spec section 15.2). A whole read (off 0, n the size) also holds the content to its hash, checked before the last blob is written, so a whole object whose content hash fails is never released complete.

Blobs are fetched ReadAhead ahead of the one being written, each on a goroutine of its own, and the content hash runs on another, so reading, hashing and sending overlap; what reaches w, and when an error stops it, is what one blob at a time would give. Memory is about ReadAhead + 3 blobs.

type Page

type Page struct {
	Token   *Token
	Entries []*Entry
	// Next is the cursor the next page asks with; Done when no key of the
	// range is left.
	Next string
	Done bool
}

Page is one listing page, proven complete (spec section 11.3).

type Reader

type Reader struct {
	// Hosts are the overlay hosts asked, in order.
	Hosts []string
	// HTTP asks hosts; Fetch reaches advertisers' URLs.
	HTTP  *http.Client
	Fetch *http.Client
	// Headers are the reader's own block headers.
	Headers chaintracker.ChainTracker
	Held    HeldStore
	Logf    func(format string, args ...any)
	Now     func() time.Time
	// MaxAnswer bounds one host answer's body.
	MaxAnswer int64
	// Spender, when set, is a spend source: the transaction that spent an
	// output, or "" while it is unspent (bcommon nodeapi). The latest
	// token's output is checked unspent with it (spec section 15.1); an
	// answer it cannot give is no evidence either way.
	Spender func(ctx context.Context, txid string, vout uint32) (string, error)
	// OnToken, when set, is handed every token a walk verifies past the one
	// held, oldest first: what it names is the map's from then on.
	OnToken func(b *storerec.Bucket)
	// WalkDir, when set, keeps a walk's progress across a restart
	// (walkstore.go).
	WalkDir string
	// contains filtered or unexported fields
}

Reader reads buckets.

func (*Reader) Ask

func (r *Reader) Ask(ctx context.Context, host string, q map[string]string) (*lookup.Answer, error)

Ask asks one host one free question of ls_bstore and returns its output-list, unverified: the caller verifies every output it uses.

func (*Reader) EntryByC

func (r *Reader) EntryByC(ctx context.Context, bucket string, c [32]byte, skip string) (*Entry, error)

EntryByC asks every host for the entry carrier whose commitment is c (`entry`, spec section 11.1) and returns the first that verifies.

func (*Reader) Forget

func (r *Reader) Forget(root [32]byte)

Forget drops a root's cached sources.

func (*Reader) List

func (r *Reader) List(ctx context.Context, c Chain, prefix, after string) (*Page, error)

List is one `list` page for prefix after a, proven complete against the latest token, every entry verified. A key the page names as unheld is listed from its entry fetched by `entry` at another host; ErrUnheld when no host produces it (spec section 16.2).

func (*Reader) Object

func (r *Reader) Object(ctx context.Context, c Chain, key string) (*Found, error)

Object is a reader's steps 1 to 5 for key (spec section 15.2): the latest token, the map's proof, the entry carrier, its writer and kind. A key the map names whose entry the answering host cannot produce is asked of every other host by `entry`; ErrUnheld when none does. A host whose answer does not verify is named and the next asked; ErrUnavailable when none answers anything that verifies.

func (*Reader) Open

func (r *Reader) Open(ctx context.Context, e *storerec.Entry, local Local) (*Object, error)

Open reads an entry's root and branches (spec section 15.2 steps 6 and 7 for the nodes): each held to its hash, the root to bstore's root rules (CheckRoot, rows C1 and C2), each branch decoded and its length the reference's, and the whole tree held to profile 1's canonical construction over the blob references by rebuilding it. Blobs are read later, each held to its hash before a byte of it is released.

func (*Reader) Sources

func (r *Reader) Sources(ctx context.Context, bucket string, root [32]byte) []Source

Sources are root's advertisers as the hosts answer them, one per advertiser (its latest expiry), latest expiry first. A host's answer is kept for a short while.

func (*Reader) Tokens

func (r *Reader) Tokens(ctx context.Context, c Chain) ([]*Token, error)

Tokens rebuilds a chain from the hosts, as the owner's anchoring tooling must (spec section 3.4): the highest token any host answers to `bucket` that verifies against the reader's headers, walked back by prev through `bucket-seq` to seq 0, each token verified, every link checked and the first token's id held to the outpoint it spends (section 15.1 and row C15). Nothing a reader remembers is used: the held token is neither read nor moved. The tokens come back in seq order from 0.

When several hosts answer different latest tokens, the highest seq that verifies is taken; with a spend source, a candidate whose output is spent is passed over (a later token spent it), and when every candidate at the highest seq is spent, or the source cannot say, the answer is an error: the tooling mints only on a token it holds evidence is the latest.

func (*Reader) VerifyEntry

func (r *Reader) VerifyEntry(ctx context.Context, bucket string, beef []byte) (*Entry, error)

VerifyEntry holds a carrier's BEEF to the carrier rules of an entry of bucket, and its funding tree's proof to the reader's headers.

type Source

type Source struct {
	Advertiser string // 66 hex
	URL        string
	Expiry     uint64
	Txid       string
}

Source is an advertiser of a root: a BRC-26 advertisement verified against the reader's headers, unexpired, of the CHIRP form for the root, by a key that is not the anyone key.

type Token

type Token struct {
	Txid   [32]byte // hash byte order
	Vout   uint32
	Bucket *storerec.Bucket
	// contains filtered or unexported fields
}

Token is a bucket token a reader verified against its own headers.

func (*Token) Tx

func (t *Token) Tx() *transaction.Transaction

Tx is the token's transaction, with its proof.

func (*Token) TxidHex

func (t *Token) TxidHex() string

TxidHex is the token's txid in display order.

Jump to

Keyboard shortcuts

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