host

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 26 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 Originator = "bweb"

Originator is the name the wallet is asked under.

Variables

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 ErrNoHost = errors.New("the configuration has no host block (host.data)")

ErrNoHost is a configuration with no host block.

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

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

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

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

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.

Jump to

Keyboard shortcuts

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