siterec

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 9 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 siterec is bweb's record codec: the four records a site's topic carries (docs/spec.md). Each is a canonical CBOR map with unsigned-integer keys, key 0 its four-byte magic, read with bcommon's record rules: a record is refused for the first rule it breaks, in key order, and keys above the last one a version defines are preserved verbatim.

| Record | Magic | Carried as | | Site | "bws" 0x01 | a mined chain token under the bucket owner | | Terms | "bwt" 0x01 | a mined record beside a hosting output | | Advertisement | "bwa" 0x01 | a mined PushDrop, one per host and site | | Outcome | "bwo" 0x01 | an unmined carrier, by whoever audited |

Index

Constants

View Source
const (
	AKMagic       = 0
	AKHost        = 1 // the host's identity key, 33 bytes
	AKSite        = 2 // the site, 32 bytes
	AKURL         = 3 // where it serves: the scheme, the address and the port; no path
	AKLocation    = 4 // an IATA metro code, three upper-case letters
	AKCountry     = 5 // ISO 3166-1 alpha-2
	AKSubdivision = 6 // ISO 3166-2 (e.g. "US-CA"), or "" when not given
	AKExpiry      = 7 // Unix seconds after which it is not a candidate
	AKCertificate = 8 // reserved for an address certificate; empty
	AKLast        = AKCertificate
)

The serving advertisement's keys (docs/spec.md section 4). It is the payload of a mined PushDrop signed by the host's key: one per host and site, canceled by spending, renewed by a successor that spends it.

View Source
const (
	OKMagic   = 0
	OKSite    = 1 // the site, 32 bytes
	OKAdTxid  = 2 // the advertisement challenged
	OKAdVout  = 3
	OKToken   = 4 // the site's bucket token the samples were proven against, its txid
	OKSamples = 5 // samples taken
	OKPassed  = 6 // samples that passed
	OKPass    = 7 // the verdict: every sample passed
	OKAt      = 8 // Unix seconds, when the challenge ended
	OKAuditor = 9 // the key of whoever ran it, 33 bytes
	OKLast    = OKAuditor
)

The outcome record's keys (docs/spec.md section 5): what one serving challenge found, published by whoever ran it.

View Source
const (
	SKMagic    = 0
	SKSite     = 1  // the site's identifier: 32 bytes, fixed by its first token
	SKBucket   = 2  // the bstore bucket it serves: its name
	SKOwner    = 3  // the bucket's owner key, 33 bytes: the only key that signs a site record
	SKBucketID = 4  // the bucket's identifier, 32 bytes
	SKSeq      = 5  // 0 for the first token, then one more each token
	SKPrev     = 6  // the previous token's txid, hash byte order; zero at seq 0
	SKHosts    = 7  // the host names it answers to: 1 to 16, lower case, distinct, ascending
	SKIndex    = 8  // the index document a path ending in "/" serves
	SKError    = 9  // the error document's key, or "" for none
	SKPublic   = 10 // whether the site is served
	SKHeaders  = 11 // header rules, in order
	SKCreated  = 12 // Unix seconds, the owner's claim; the token's block is the proven bound
	SKLast     = SKCreated
)

The site record's keys (docs/spec.md section 2).

View Source
const (
	MaxRecord   = 16 << 10 // any record, encoded
	MaxHosts    = 16       // host names a site answers to
	MaxRules    = 32       // header rules a site sets
	MaxRuleSets = 8        // headers one rule sets
	MaxURL      = 512
	MaxHeader   = 1024 // a header rule's value
	MaxSafe     = 1<<53 - 1
)

Bounds on what a record carries.

View Source
const (
	TKMagic     = 0
	TKSite      = 1  // the site, 32 bytes
	TKTxid      = 2  // the hosting output's transaction, hash byte order
	TKVout      = 3  // its output index
	TKSatoshis  = 4  // its value: what the race pays out, all of it
	TKT         = 5  // servers that must pass before any is paid
	TKK         = 6  // servers paid, by rank
	TKTerm      = 7  // seconds a paid server must stay advertised and serving
	TKDeadline  = 8  // blocks after the hosting output mines when its owner may reclaim it unpaid
	TKCheckC    = 9  // samples in a serving challenge
	TKFirstByte = 10 // the most milliseconds a sample's first byte may take
	TKCreated   = 11 // Unix seconds, the publisher's claim
	TKLast      = TKCreated
)

The hosting terms record's keys (docs/spec.md section 3): bstore's eight hold elements, for a site and a term.

View Source
const (
	MaxK         = 64
	MinCheckC    = 1
	MaxCheckC    = 1024
	MaxTerm      = 366 * 24 * 3600
	MaxDeadline  = 52_560 // about a year of blocks
	MaxFirstByte = 60_000
	MaxSatoshis  = 2_100_000_000_000_000
)

Bounds on the race a terms record names.

Variables

View Source
var (
	MagicSite          = []byte("bws\x01")
	MagicTerms         = []byte("bwt\x01")
	MagicAdvertisement = []byte("bwa\x01")
	MagicOutcome       = []byte("bwo\x01")
)

The records' magics: four bytes, the last the version.

View Source
var (
	ErrHost     = errors.New("siterec: a host name is not a lower-case DNS name")
	ErrHosts    = errors.New("siterec: host names are missing, over the bound, or not distinct and ascending")
	ErrIndex    = errors.New("siterec: the index document is not a file name")
	ErrKey      = errors.New("siterec: not an object key")
	ErrRule     = errors.New("siterec: a header rule is malformed or sets a header that describes the bytes")
	ErrBucket   = errors.New("siterec: not a bstore bucket name")
	ErrOwner    = errors.New("siterec: not a canonical compressed public key, or the anyone key")
	ErrRace     = errors.New("siterec: the race's t, K and checkC are out of order")
	ErrURL      = errors.New("siterec: not an http or https URL")
	ErrLocation = errors.New("siterec: not an IATA Location, ISO 3166 country or subdivision")
	ErrCount    = errors.New("siterec: more samples passed than were taken")
)

Refusals beyond bcommon's record ones. Reason gives each a fixed label.

Functions

func Reason

func Reason(err error) string

Reason is the fixed label of a refusal: bcommon's record labels, then this package's.

func SameChain

func SameChain(prev, next *Site) bool

SameChain reports whether next may follow prev in one site's chain: the same site, bucket and owner, one more seq. The token transactions' own link (next spends prev) is the module's to check.

func Settable

func Settable(name string) bool

Settable reports whether a header rule may set name: never the headers that describe the bytes, which are the store's and proven.

func ValidHost

func ValidHost(h string) bool

ValidHost reports a lower-case DNS host name: at least two labels, each a letter-digit-hyphen label, 253 bytes at most, and a last label that is not all digits (so an IPv4 address is never a host name).

func ValidKey

func ValidKey(k string) bool

ValidKey reports an object key a site may name: a bstore object key (1 to 1,024 bytes, one line: no control character, U+2028 or U+2029) with no leading slash and no empty, "." or ".." segment.

func ValidServeURL

func ValidServeURL(s string) bool

ValidServeURL reports an origin a host may serve a site at, in its one canonical spelling: "http://" or "https://", then a host, then optionally ":" and a port from 1 to 65535 without leading zeros, and nothing else (no user information, path, trailing "/", query or fragment). The host is a lower-case DNS name (ValidHost), a dotted IPv4 address, or an IPv6 address in brackets, in its shortest lower-case form, with no zone.

Types

type Advertisement struct {
	Host        []byte
	Site        [32]byte
	URL         string
	Location    string
	Country     string
	Subdivision string
	Expiry      uint64
	Certificate []byte
	Extra       cbor.Map
}

Advertisement is a host's claim that it serves a site at an address.

func DecodeAdvertisement

func DecodeAdvertisement(raw []byte) (*Advertisement, error)

DecodeAdvertisement reads an advertisement's payload, key by key. A subdivision, when given, is in the advertised country.

func (*Advertisement) Encode

func (a *Advertisement) Encode() ([]byte, error)

Encode writes the payload canonically, refusing what DecodeAdvertisement refuses.

type Header struct{ Name, Value string }

Header is one header a rule sets.

type Outcome

type Outcome struct {
	Site    [32]byte
	AdTxid  [32]byte
	AdVout  uint32
	Token   [32]byte
	Samples uint64
	Passed  uint64
	Pass    bool
	At      uint64
	Auditor []byte
	Extra   cbor.Map
}

Outcome is one serving challenge's result.

func DecodeOutcome

func DecodeOutcome(raw []byte) (*Outcome, error)

DecodeOutcome reads an outcome record, key by key, then: passed is at most samples, and the verdict is pass exactly when every sample passed.

func (*Outcome) Encode

func (o *Outcome) Encode() ([]byte, error)

Encode writes the record canonically, refusing what DecodeOutcome refuses.

type Rule

type Rule struct {
	Prefix string
	Suffix string
	Set    []Header // distinct names, ascending by lower-cased name
}

Rule sets headers on keys with a prefix and a suffix (either may be ""). A rule matches the key served with a leading "/".

type Site

type Site struct {
	Site     [32]byte
	Bucket   string
	Owner    []byte
	BucketID [32]byte
	Seq      uint64
	Prev     [32]byte
	Hosts    []string
	Index    string
	Error    string
	Public   bool
	Headers  []Rule
	Created  uint64
	// Extra holds keys above SKLast, verbatim.
	Extra cbor.Map
}

Site is a site's settings: the S3 website configuration of one bucket, with the names it answers to. A site's key is its bucket owner's key.

func DecodeSite

func DecodeSite(raw []byte) (*Site, error)

DecodeSite reads a site record, refusing it for the first rule it breaks: the record rules (too-large, cbor, key-type, magic), then key by key in key order (missing, type, the key's own rule), then seq 0 with a non-zero prev.

func (*Site) Encode

func (s *Site) Encode() ([]byte, error)

Encode writes the record canonically. It refuses what DecodeSite refuses, so a record this package writes is one it reads.

type Terms

type Terms struct {
	Site      [32]byte
	Txid      [32]byte
	Vout      uint32
	Satoshis  uint64
	T, K      uint64
	Term      uint64
	Deadline  uint64
	CheckC    uint64
	FirstByte uint64
	Created   uint64
	Extra     cbor.Map
}

Terms is a publisher's offer to pay the first K servers that pass a serving challenge, from one hosting output, for one term of a site.

func DecodeTerms

func DecodeTerms(raw []byte) (*Terms, error)

DecodeTerms reads a terms record: key by key, then 1 <= t <= K.

func (*Terms) Encode

func (t *Terms) Encode() ([]byte, error)

Encode writes the record canonically, refusing what DecodeTerms refuses.

Jump to

Keyboard shortcuts

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