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
- Variables
- func TokenTxid(s string) ([32]byte, error)
- type Chain
- type Counts
- type Entry
- type Found
- type HeldStore
- type Keeper
- type Local
- type Object
- type Page
- type Reader
- func (r *Reader) Ask(ctx context.Context, host string, q map[string]string) (*lookup.Answer, error)
- func (r *Reader) Counts() Counts
- func (r *Reader) EntryByC(ctx context.Context, bucket string, c [32]byte, skip string) (*Entry, error)
- func (r *Reader) Forget(root [32]byte)
- func (r *Reader) List(ctx context.Context, c Chain, prefix, after string) (*Page, error)
- func (r *Reader) Object(ctx context.Context, c Chain, key string) (*Found, error)
- func (r *Reader) ObjectNow(ctx context.Context, c Chain, key string) (*Found, error)
- func (r *Reader) Open(ctx context.Context, e *storerec.Entry, local Local) (*Object, error)
- func (r *Reader) Sources(ctx context.Context, bucket string, root [32]byte) []Source
- func (r *Reader) Tokens(ctx context.Context, c Chain) ([]*Token, error)
- func (r *Reader) VerifyEntry(ctx context.Context, bucket string, beef []byte) (*Entry, error)
- type Source
- type Token
Constants ¶
const PageList = 256
PageList is the frozen `list` page maximum.
Variables ¶
var ( // 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") // ErrHeaders is the reader's header source not answering while a proof // was checked: not a proof that fails. A reader answers it as "try // again" and names the cause; it also satisfies ErrUnavailable or // ErrNoSource where it ended the read. ErrHeaders = errors.New("reader: the header source did not answer") )
Errors a caller maps to its answers.
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.
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.
var ReadAhead = 2
ReadAhead is how many blobs WriteRange fetches ahead of the one it writes.
Functions ¶
Types ¶
type Chain ¶
Chain is a bucket chain a reader reads: the identifier, the owner and the bucket id (spec section 3.3).
type Counts ¶ added in v0.34.0
type Counts struct {
// Asked reads asked a host; Remembered reads were answered from memory.
Asked, Remembered int64
// EntriesVerified and EntriesKnown are entry carriers verified and
// carriers whose bytes had verified before.
EntriesVerified, EntriesKnown int64
}
Counts are how a reader's object reads were answered.
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.
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 Keeper ¶ added in v0.31.0
type Keeper interface {
Local
// Keep stores an object the reader fetched and held to its hash h. A
// closure's root and branches are kept only once the closure passed
// every check of Open.
Keep(h [32]byte, b []byte) error
// Held reports whether an object is held, without reading it.
Held(h [32]byte) bool
// Closure is told that every object of a closure is held locally: the
// root, the object's size, the branches, and the blobs in content order
// (repeats included). It is told at most once by a read that succeeds
// in telling it, whoever fetched the objects and whenever: a closure
// several ranged reads filled is told by the read that sees it whole.
// Until then a kept object is one no closure names, and a store may
// drop it as such. A Keeper is told of closures it already knows, and
// decides for itself what that is worth.
Closure(root [32]byte, size uint64, branches, blobs [][32]byte) error
}
Keeper is a Local that also keeps what a reader fetched from an advertiser, so the next reader of the same object is served locally. A node that began holding a bucket after an object was published has none of its pieces; with a Keeper it fills as it is read.
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) Objects ¶
Objects are the closure's distinct objects: the root, the branches, then the blobs (a publisher's Closure).
func (*Object) WriteRange ¶
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
// Memory, when positive, is how long a chain's latest token is held to
// be the latest after an answer proved it so: inside that time a key
// already proven against it is answered without asking a host
// (memory.go). Zero asks a host for every read.
Memory time.Duration
// contains filtered or unexported fields
}
Reader reads buckets.
func (*Reader) Ask ¶
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) List ¶
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 ¶
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) ObjectNow ¶ added in v0.34.0
ObjectNow is Object asking a host whatever is remembered: for a read whose answer is written down, as a copy's source is.
func (*Reader) Open ¶
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 ¶
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 ¶
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.
type Source ¶
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.