host

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 32 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 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 ErrOpen = errors.New("the race is open")

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

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 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 an advertisement is published
	// and hosting terms are asked about.
	Engine 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
	// 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) Run

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

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

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"`
}

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"`
}

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"`
}

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.

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) 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) 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.

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"`
}

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"`
	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