host

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 39 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 host is a web node's own side of the chain: the wallet that pays for what the node publishes, and the chain view it is funded and settled through. The wallet is bcommon's embedded wallet and the chain settings are bstore's, so a node's operator funds and inspects it as a bstore provider's.

Index

Constants

View Source
const (
	RaceOpen      = "open"      // terms out, the hosting output unspent
	RaceSettled   = "settled"   // the hosting output paid out by rank
	RaceClosed    = "closed"    // closed with fewer than t passing: nothing is paid; reclaim after the deadline
	RaceReclaimed = "reclaimed" // the hosting output back in the wallet
)

Race states.

View Source
const (
	CandPassed = "passed"
	CandFailed = "failed"
)

Candidate statuses.

View Source
const MaxRemittance = 256 << 10

MaxRemittance bounds a remittance on the wire: a settlement pays at most 64 ranks, and each transaction comes with one proof.

View Source
const Originator = "bweb"

Originator is the name the wallet is asked under.

Variables

View Source
var ErrBeforeDeadline = errors.New("the race's deadline has not come; a bounty is reclaimed only after it")

ErrBeforeDeadline is a reclaim asked for before the race's deadline.

View Source
var ErrInUse = errors.New("the host's data directory is in use by another bweb process (a serving node, or another command); stop it first")

ErrInUse is a data directory another bweb process holds open.

View Source
var ErrLapsed = errors.New("the race's deadline has come: bweb race reclaim takes the bounty back")

ErrLapsed is a race whose deadline came before it settled.

View Source
var ErrNoHost = errors.New("the configuration has no host block (host.data)")

ErrNoHost is a configuration with no host block.

View Source
var ErrNotAudited = errors.New("only a settled race's paid servers are audited")

ErrNotAudited is an audit of a race that is not held or not settled: only the servers a race paid are audited.

View Source
var ErrOpen = errors.New("the race is open")

ErrOpen is a race a run left open: fewer than K servers have passed.

View Source
var ErrTermOver = errors.New("the race's term is over: its servers are no longer audited")

ErrTermOver is an audit of a race whose term has run out.

View Source
var Profile = bwallet.Profile{
	FundProtocol:   siterec.Protocol,
	FundKeyID:      siterec.KeyFund,
	FundBasket:     "bweb fund",
	Version:        "bweb-host-1",
	LegacyPoolFile: "bweb-host-pool.json",
}

Profile is the wallet's profile: the fund key under bweb's protocol, key id fund, counterparty self, and the basket its coin is listed under. Changing it strands the coin a wallet holds.

Functions

func Init

func Init(data string) (string, error)

Init creates a host's wallet under data and returns its identity key. It refuses a directory that holds one.

func Price added in v0.10.0

func Price(t *web.TermsConfig, size, term uint64) uint64

Price is what a node asks, in satoshis, to serve a site of size bytes for term seconds: per_gib_day for each GiB and day, rounded up, and never less than minimum. A price past the largest satoshi count is that count.

func WalletDir

func WalletDir(data string) string

WalletDir is the wallet's directory under a data directory.

Types

type Ad struct {
	Txid   string `json:"txid"`
	Vout   uint32 `json:"vout"`
	RawHex string `json:"rawHex"`
	// BumpHex is its proof; empty until it mined.
	BumpHex string `json:"bumpHex,omitempty"`
	Height  uint32 `json:"height,omitempty"`
	Expiry  uint64 `json:"expiry"`
	// What it says, to tell when the configuration has moved on.
	URL         string `json:"url"`
	Location    string `json:"location"`
	Country     string `json:"country"`
	Subdivision string `json:"subdivision,omitempty"`
	// Published is whether the engine has taken it on the site's topic.
	Published bool `json:"published,omitempty"`
	// Coin is the wallet coin that pays its fee, kept until it mined: the
	// wallet gave it up when the transaction was built.
	Coin *bwallet.Output `json:"coin,omitempty"`
	// Renews is the advertisement it spends, kept until it mined.
	Renews *Ad `json:"renews,omitempty"`
}

Ad is an advertisement the host minted.

type Advertiser

type Advertiser struct {

	// Served answers the sites to advertise, ids in hex.
	Served func() []string
	// Engine is the node's engine: where hosting terms and advertisements
	// are asked about, and where an advertisement is published unless
	// Submit names another place (an overlay bridge's facade, which
	// carries it on the plane to the other engines).
	Engine string
	Submit string
	// Now is the clock; Tick how often the advertiser looks (default 15 s).
	Now  func() time.Time
	Tick time.Duration
	// Metrics, when set, counts what the advertiser does.
	Metrics *web.Metrics

	// SiteBytes, when set, is a served site's size as the node's store
	// lists it: what host.terms prices by. size keeps each for a while.
	SiteBytes func(ctx context.Context, site string) (uint64, error)
	// contains filtered or unexported fields
}

Advertiser keeps the host's advertisements: one for each site Served answers, minted when there is none, renewed before it expires or when what the configuration says has changed, and published to the site's topic. A site that stops being served is not renewed; its advertisement runs out.

func NewAdvertiser

func NewAdvertiser(ctx context.Context, h *Host, cfg web.HostConfig, engine string, served func() []string) (*Advertiser, error)

NewAdvertiser is an advertiser over an opened host. cfg.URL is set.

func (*Advertiser) Ads

func (a *Advertiser) Ads() map[string]Ad

Ads is a copy of the advertisements held, by site.

func (*Advertiser) Pass

func (a *Advertiser) Pass(ctx context.Context)

Pass does what is due once: finishes what a previous run or pass left unmined, a transaction at a time, publishes what is mined and not yet taken, then mints every advertisement that is due in one transaction (in several past siterec.MaxAdsPerTx), so a node's sites take one block and one coin however many they are.

func (*Advertiser) Payouts added in v0.5.0

func (a *Advertiser) Payouts() []Payout

Payouts is a copy of the payments the host has taken.

func (*Advertiser) Routes added in v0.10.0

func (a *Advertiser) Routes() http.Handler

Routes answers the host's own routes on the node's server (web.Server.Host): the settle route and the terms.

func (*Advertiser) Run

func (a *Advertiser) Run(ctx context.Context)

Run looks at once and at every tick until ctx is done.

func (*Advertiser) TakeRemittance added in v0.10.0

func (a *Advertiser) TakeRemittance(ctx context.Context, rm *Remittance) (*Payout, error)

TakeRemittance checks a remittance and takes its payment into the wallet. It is taken only when everything it says follows from the race it names: the terms transaction is the race, names the site, is signed by the sender, who is the site's owner, and is mined under this node's headers; the prefix is base64 of the race's commitment and the suffix base64 of the rank, 1 to the race's K; the settlement spends the race's hosting output, the named output pays the key BRC-29 derives for this node with them, and it is mined under this node's headers. A payment is taken into the wallet once, ever: one sent again is answered as taken, and is not put back after the node has spent it. A payment taken is noted for the next pass, which records it and finishes the race.

type Audit added in v0.10.0

type Audit struct {
	Host string `json:"host"`
	// Ad and URL are the advertisement read at, when the server still
	// advertised the site.
	Ad      string `json:"ad,omitempty"`
	URL     string `json:"url,omitempty"`
	At      int64  `json:"at"`
	Samples int    `json:"samples"`
	Passed  int    `json:"passed"`
	Pass    bool   `json:"pass"`
	Why     string `json:"why,omitempty"`
	// Token is the bucket token its reads were proven against, hex;
	// Outcome the outcome record published for it, and the engines that
	// took it. One not published yet is published at the next run.
	Token        string   `json:"token,omitempty"`
	Outcome      string   `json:"outcome,omitempty"`
	OutcomeTaken []string `json:"outcomeTaken,omitempty"`
}

Audit is one challenge of a paid server during its term.

type Cand added in v0.5.0

type Cand struct {
	Host string `json:"host"`
	// Ad is the advertisement challenged, or to be; FirstAd the first of
	// its renewals, whose outpoint breaks a tie, and First that one's
	// block, which ranks the server.
	Ad      string `json:"ad"`
	FirstAd string `json:"firstAd"`
	First   uint32 `json:"first"`
	URL     string `json:"url"`
	Expiry  uint64 `json:"expiry"`
	// Status is empty until its challenge is decided.
	Status  string `json:"status,omitempty"`
	Samples int    `json:"samples,omitempty"`
	Passed  int    `json:"passed,omitempty"`
	Why     string `json:"why,omitempty"`
	At      int64  `json:"at,omitempty"`
	// Outcome is the outcome record published for the challenge, and the
	// engines that took it.
	Outcome      string   `json:"outcome,omitempty"`
	OutcomeTaken []string `json:"outcomeTaken,omitempty"`
}

Cand is one server in a race: a host key and its advertisement.

type Host

type Host struct {
	Wallet  *bwallet.Embedded
	View    *chaincfg.View
	Mainnet bool
	// contains filtered or unexported fields
}

Host is an opened host: its wallet and its view of the chain. It holds the data directory until Close.

func Open

func Open(c web.HostConfig) (*Host, error)

Open opens the wallet a configuration names and builds its chain view. It reaches nothing.

func OpenPublisher

func OpenPublisher(c web.PublisherConfig) (*Host, error)

OpenPublisher opens a publisher's wallet: the identity bweb init made under its data directory, or, with identity_file, another identity (the bucket owner's) over coin kept under the data directory.

func (*Host) Address

func (h *Host) Address() (string, error)

Address is where coin is sent to fund the host.

func (*Host) Balance

func (h *Host) Balance() (outputs int, satoshis uint64)

Balance is the wallet's coin: how many outputs, and their sum.

func (*Host) Close

func (h *Host) Close()

Close releases the data directory.

func (*Host) FundBEEF

func (h *Host) FundBEEF(ctx context.Context, beef []byte, refuseUnmined bool) (chaincfg.Funded, error)

FundBEEF takes a payment handed over as BEEF, as a wallet answers one. An unmined payment waits in the wallet until it mines, unless refuseUnmined.

func (*Host) FundCoinbase

func (h *Host) FundCoinbase(ctx context.Context, blocks int) (int, error)

FundCoinbase mines blocks to the fund address and takes their coinbase: only on a regtest chain the operator runs (settle rpc:URL, chain asset:URL).

func (*Host) FundTxid

func (h *Host) FundTxid(ctx context.Context, txid string) (chaincfg.Funded, error)

FundTxid takes a mined payment to the fund address into the wallet, by its transaction id: fetched with its proof, the proof checked against the headers.

func (*Host) Identity

func (h *Host) Identity() string

Identity is the host's identity key, hex: what its advertisements name.

type Offer added in v0.5.0

type Offer struct {
	Satoshis  uint64 // the bounty, paid out whole
	T, K      uint64 // servers that must pass before any is paid; servers paid
	Term      uint64 // seconds a paid server stays advertised and serving
	Deadline  uint64 // blocks after the hosting output mines when it may be reclaimed
	CheckC    uint64 // reads in a serving challenge
	FirstByte uint64 // the most milliseconds a read's first byte may take
}

Offer is what a publisher offers for one term of a site.

type Payee added in v0.5.0

type Payee struct {
	Rank     int    `json:"rank"`
	Host     string `json:"host"`
	Satoshis uint64 `json:"satoshis"`
	Vout     uint32 `json:"vout"`
	// URL is where its remittance goes: the address of the advertisement
	// it passed at. Remitted is set once the server took it; RemitRefused
	// says why it is not sent again; RemitTries and RemitError are the
	// sends that reached no answer.
	URL          string `json:"url,omitempty"`
	Remitted     bool   `json:"remitted,omitempty"`
	RemitRefused string `json:"remitRefused,omitempty"`
	RemitTries   int    `json:"remitTries,omitempty"`
	RemitError   string `json:"remitError,omitempty"`
}

Payee is one rank of a settlement.

type Payout added in v0.5.0

type Payout struct {
	Site     string `json:"site"`
	Race     string `json:"race"`
	Txid     string `json:"txid"`
	Vout     uint32 `json:"vout"`
	Rank     int    `json:"rank"`
	Satoshis uint64 `json:"satoshis"`
	Height   uint32 `json:"height"`
	// Until is when the term this payment bought ends, by this node's
	// clock: until then the node keeps advertising the site, whatever
	// races are open, so it stays a server the publisher can audit.
	Until int64 `json:"until,omitempty"`
}

Payout is a payment a host took from a race's settlement.

type Publisher

type Publisher struct {

	// Now is the clock a record's created time is read from.
	Now func() time.Time
	// contains filtered or unexported fields
}

Publisher mints and updates the sites of one owner.

func NewPublisher

func NewPublisher(ctx context.Context, h *Host, c web.PublisherConfig) (*Publisher, error)

NewPublisher is a publisher over an opened wallet.

func (*Publisher) Advance

func (p *Publisher) Advance(ctx context.Context, site string) error

Advance carries a site as far as it can go: the chain output mined, a wanted token built, a built token mined, the latest token at every engine. It is what a command stopped part way is finished by.

func (*Publisher) Mint

func (p *Publisher) Mint(ctx context.Context, s Settings) (string, error)

Mint starts a new site with settings and carries it through: the chain output, the first token, the engines. It returns the site's id as soon as it is fixed, which is before anything is mined.

func (*Publisher) Site

func (p *Publisher) Site(site string) (SiteState, bool)

Site is a copy of one site's state.

func (*Publisher) Sites

func (p *Publisher) Sites() []string

Sites are the ids of the sites held, sorted.

func (*Publisher) Update

func (p *Publisher) Update(ctx context.Context, site string, s Settings) error

Update asks for new settings for a site and carries them through.

type Race added in v0.5.0

type Race struct {
	Site      string `json:"site"`
	Terms     *Tx    `json:"terms"`
	Satoshis  uint64 `json:"satoshis"`
	T         uint64 `json:"t"`
	K         uint64 `json:"k"`
	Term      uint64 `json:"term"`
	Deadline  uint64 `json:"deadline"`
	CheckC    uint64 `json:"checkC"`
	FirstByte uint64 `json:"firstByte"`
	Created   uint64 `json:"created"`
	// Taken are the engines that hold the terms.
	Taken []string `json:"taken,omitempty"`
	// Tree is the funding tree outcome records are minted from, an output
	// each: TreeOutputs of them, TreeUsed spent.
	Tree        *Tx    `json:"tree,omitempty"`
	TreeOutputs uint32 `json:"treeOutputs,omitempty"`
	TreeUsed    uint32 `json:"treeUsed,omitempty"`

	Cands      []*Cand     `json:"cands,omitempty"`
	Settlement *Settlement `json:"settlement,omitempty"`
	Reclaim    *Tx         `json:"reclaim,omitempty"`
	State      string      `json:"state"`
	Note       string      `json:"note,omitempty"`
	// Settled is when the publisher saw the settlement mined, Unix
	// seconds: the paid servers' term runs from it. Audits are the
	// challenges of the paid servers during it (audit.go).
	Settled int64   `json:"settled,omitempty"`
	Audits  []Audit `json:"audits,omitempty"`
}

Race is one race as its publisher holds it. Its id is its terms transaction's id; the hosting output is that transaction's output 0 and the terms record its output 1.

func (*Race) PassedCount added in v0.5.0

func (r *Race) PassedCount() int

PassedCount is how many candidates passed.

func (*Race) TermEnd added in v0.10.0

func (rc *Race) TermEnd() int64

TermEnd is when a settled race's term runs out, Unix seconds: the term counted from the settlement, or, for a race settled before the client kept that, from the last pass it paid for. Zero for a race not settled.

type Racer added in v0.5.0

type Racer struct {
	*Publisher
	// Ref is the store a challenge reads the site's content from: the
	// publisher's own bstore gateway.
	Ref challenge.Reference
	// Private allows challenging a server at a loopback or private
	// address.
	Private bool
	// Outcomes has each challenge's outcome record published. Off, a
	// race needs no funding tree.
	Outcomes bool
	// MaxChallenges is how many servers one run challenges at most; zero
	// is 3K + 8.
	MaxChallenges int
	// Resolve answers the addresses a host name resolves to; nil is the
	// system's resolver.
	Resolve func(ctx context.Context, host string) ([]string, error)
	// contains filtered or unexported fields
}

Racer runs a publisher's races over its sites.

func NewRacer added in v0.5.0

func NewRacer(p *Publisher, ref challenge.Reference) (*Racer, error)

NewRacer is a racer over a publisher.

func (*Racer) Audit added in v0.10.0

func (r *Racer) Audit(ctx context.Context, id string) error

Audit challenges each server a settled race paid, once, while the race's term runs: at the address it advertises now, with the race's own reads and first-byte bound. A server that no longer advertises the site fails unread; one advertising an address a server paid at a better rank is dialed at fails unread, as in the race. Each challenge's outcome is published as the race's were. A challenge the publisher's own store could not judge records nothing.

func (*Racer) Open added in v0.5.0

func (r *Racer) Open(ctx context.Context, site string, o Offer) (string, error)

Open opens a race for a site: mints its terms beside a hosting output of the bounty, waits for their block, and hands them to the engines. It returns the race's id as soon as it is fixed.

func (*Racer) OpenRace added in v0.5.0

func (r *Racer) OpenRace(site string) (string, bool)

OpenRace is the id of the site's race that is still open, if any.

func (*Racer) Race added in v0.5.0

func (r *Racer) Race(id string) (Race, bool)

Race is a copy of one race.

func (*Racer) Races added in v0.5.0

func (r *Racer) Races() []string

Races are the ids of the races held, oldest first.

func (*Racer) Reclaim added in v0.5.0

func (r *Racer) Reclaim(ctx context.Context, id string) error

Reclaim spends a race's hosting output back to the wallet, once its deadline has come and nothing was paid from it.

func (*Racer) RemitPending added in v0.10.0

func (r *Racer) RemitPending(ctx context.Context, site string)

RemitPending sends again the remittances the site's settled races hold: those held or not answered when they were sent.

func (*Racer) Run added in v0.5.0

func (r *Racer) Run(ctx context.Context, id string, o RunOptions) error

Run carries a race as far as it goes now: its terms mined and at the engines; the servers that advertise found, ranked and challenged in rank order until K have passed, each challenge's outcome published; and, once K have passed (or, closing, at least t), the settlement built, mined and recorded. It answers ErrOpen when the race stays open.

func (*Racer) TermRace added in v0.10.0

func (r *Racer) TermRace(site string) (string, bool)

TermRace is the site's newest settled race whose term still runs.

type Remittance added in v0.10.0

type Remittance struct {
	Site              string `json:"site"`
	Race              string `json:"race"`
	Rank              int    `json:"rank"`
	Transaction       string `json:"transaction"`
	Terms             string `json:"terms"`
	OutputIndex       uint32 `json:"outputIndex"`
	DerivationPrefix  string `json:"derivationPrefix"`
	DerivationSuffix  string `json:"derivationSuffix"`
	SenderIdentityKey string `json:"senderIdentityKey"`
}

Remittance is a BRC-29 remittance for one rank of a race's settlement. Transaction is the settlement and Terms the race's terms transaction, each as Atomic BEEF with its proof, in standard base64.

type RunOptions added in v0.5.0

type RunOptions struct {
	// Close settles with the servers that have passed, if at least t
	// have, and otherwise closes the race with nothing paid.
	Close bool
	// Retry challenges again the servers that failed, in this race or the
	// site's last.
	Retry bool
}

RunOptions steer one run of a race.

type Settings

type Settings struct {
	Bucket   string           `json:"bucket"`    // the bstore bucket's name
	BucketID string           `json:"bucket_id"` // its id, hex
	Hosts    []string         `json:"hosts"`
	Index    string           `json:"index"`
	Error    string           `json:"error,omitempty"`
	Public   bool             `json:"public"`
	Headers  []web.HeaderRule `json:"headers,omitempty"`
}

Settings are a site's settings as its owner gives them.

type Settlement added in v0.5.0

type Settlement struct {
	Tx     *Tx     `json:"tx"`
	Payees []Payee `json:"payees"`
	// Dropped are hosts that passed and whose advertisement was canceled
	// before settlement.
	Dropped []string `json:"dropped,omitempty"`
}

Settlement is the transaction that pays a race out.

type SiteState

type SiteState struct {
	// Tree is the transaction whose output 0 the first token spends.
	Tree *Tx `json:"tree"`
	// Token is the latest mined token, Parent the transaction it spends
	// (the tree at seq 0), Seq its sequence number and Settings what it says.
	Token    *Tx       `json:"token,omitempty"`
	Parent   *Tx       `json:"parent,omitempty"`
	Seq      uint64    `json:"seq"`
	Settings *Settings `json:"settings,omitempty"`
	// Next is a token built and not yet mined, NextSettings what it says.
	Next         *Tx       `json:"next,omitempty"`
	NextSettings *Settings `json:"nextSettings,omitempty"`
	// Want is settings asked for that no token has been built for yet.
	Want *Settings `json:"want,omitempty"`
	// Taken are the engines that hold the latest token.
	Taken []string `json:"taken,omitempty"`
}

SiteState is one site's chain as its owner holds it.

type State

type State struct {
	Identity string         `json:"identity"`
	Ads      map[string]*Ad `json:"ads"`
	// Races are the open races of the sites advertised, by terms
	// transaction; Payouts what the host has been paid from races.
	// Finished are the races done with, paid or not, the newest last: an
	// engine may list one a while longer, and it is not taken up again.
	Races    map[string]*Watched `json:"races,omitempty"`
	Payouts  []Payout            `json:"payouts,omitempty"`
	Finished []string            `json:"finished,omitempty"`
	// Paid is when the last term a race paid this node for each site
	// ends, Unix seconds: kept apart from Payouts, which keeps only the
	// newest payments of all sites.
	Paid map[string]int64 `json:"paid,omitempty"`
}

State is the host's state file, ads.json: the latest advertisement of each site, by site id in hex.

type Tx

type Tx struct {
	Txid    string          `json:"txid"`
	RawHex  string          `json:"rawHex"`
	BumpHex string          `json:"bumpHex,omitempty"`
	Height  uint32          `json:"height,omitempty"`
	Coin    *bwallet.Output `json:"coin,omitempty"` // the wallet coin it spends, until it mined
}

Tx is a transaction of a site's chain.

type Watched added in v0.5.0

type Watched struct {
	Site      string `json:"site"`
	Txid      string `json:"txid"` // the terms transaction
	Vout      uint32 `json:"vout"` // its hosting output
	TermsVout uint32 `json:"termsVout"`
	Owner     string `json:"owner"` // the publisher's key
	K         int    `json:"k"`
	Satoshis  uint64 `json:"satoshis"`
	Term      uint64 `json:"term,omitempty"`
	Seen      int64  `json:"seen"`
}

Watched is a race a host may be paid from.

Jump to

Keyboard shortcuts

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