Documentation
¶
Overview ¶
Package recv is beefcat's far end: it reads a stream of carriers and writes a carrier's data only after that carrier has passed every check.
The checks, in order, for each carrier:
- the frame is within bounds, is Atomic BEEF holding no more than a carrier and what it spends, and parses (package guard);
- the transaction comes with no proof of its own, and is a carrier with one beefcat record;
- the payload follows its rules, the carrier cannot be mined, its input is one canonical signature, its lock is the key the named identity derives, and the field signature verifies over the payload;
- the carrier continues the stream: same sender, same stream, the next sequence;
- it spends a beefcat funding output of a transaction that carries its own Merkle path, a path that leads from that transaction, and an output no earlier carrier of the stream spent;
- SPV: the input satisfies that output, and the path leads to a root the reader's own header source holds;
- when asked, the funding output is not spent by another transaction, which is how a sender retracts;
- the sender is one the reader trusts, when the reader pinned any.
Everything but 6 and 7 is arithmetic on the bytes received. A carrier that fails is refused with a code from bcommon's verify vocabulary and nothing of it is written; a stream that ends before its signed last carrier is refused as truncated.
Index ¶
Constants ¶
const ( // RefusedTruncated is a stream that ended before its last carrier. RefusedTruncated verify.Code = "REFUSED-TRUNCATED" // RefusedRetracted is a carrier whose funding output another // transaction spent: the sender retracted it, or it was never the // output's one spender. RefusedRetracted verify.Code = "REFUSED-RETRACTED" // RefusedUntrusted is a sender the reader did not pin. RefusedUntrusted verify.Code = "REFUSED-UNTRUSTED" )
Codes beefcat adds to bcommon's vocabulary.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// Headers is the reader's own header source. Required.
Headers chaintracker.ChainTracker
// Trusted are the identity keys the reader takes data from. Empty
// takes any sender whose carriers verify, and Summary.Pinned is false.
Trusted [][33]byte
// Spends, when set, is asked whether each funding output is spent by
// another transaction.
Spends nodeapi.SpendSource
// Workers is how many carriers are checked at once; zero is one per
// core, at most 16. Each holds one carrier, so it also bounds memory.
Workers int
}
Options are a reader's choices.
type Refusal ¶
Refusal is a verdict: the stream did not verify. Carrier is the index of the carrier refused, from 0.
type Summary ¶
type Summary struct {
// Identity is the sender's identity key, once a carrier named one that
// its signatures bear out.
Identity [33]byte
HaveIdentity bool
// Pinned reports that Identity is one of Options.Trusted.
Pinned bool
Stream [16]byte
// Carriers and Bytes count what was verified and written.
Carriers int
Bytes int64
// Tree and Height are the funding transaction and block of the last
// carrier verified.
Tree string
Height uint32
// Unspent reports that every funding output was checked unspent.
Unspent bool
}
Summary is what was verified and written.
func Receive ¶
Receive reads a stream from r and writes its data to w. It returns what it verified and wrote, and nil only when the whole stream verified through its signed last carrier. A *Refusal is a verdict; any other error means the reader could not decide (the header source did not answer, or reading or writing failed), which is never a verdict.
A carrier's own checks need nothing of the carriers around it, so they run on several cores, a few carriers ahead of the one being written. What ties carriers together (the sender, the stream, the sequence, the funding outputs already spent) is checked in order, by the one goroutine that writes, so the verdict is the one a reader working a carrier at a time would reach: the first carrier that fails, for the first check it fails.