recv

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 13 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 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:

  1. the frame is within bounds, is Atomic BEEF holding no more than a carrier and what it spends, and parses (package guard);
  2. the transaction comes with no proof of its own, and is a carrier with one beefcat record;
  3. 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;
  4. the carrier continues the stream: same sender, same stream, the next sequence;
  5. 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;
  6. SPV: the input satisfies that output, and the path leads to a root the reader's own header source holds;
  7. when asked, the funding output is not spent by another transaction, which is how a sender retracts;
  8. 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

View Source
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

type Refusal struct {
	Code    verify.Code
	Reason  string
	Carrier int
}

Refusal is a verdict: the stream did not verify. Carrier is the index of the carrier refused, from 0.

func (*Refusal) Error

func (r *Refusal) Error() string

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

func Receive(ctx context.Context, r io.Reader, w io.Writer, o Options) (Summary, error)

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.

Jump to

Keyboard shortcuts

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