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
- Variables
- func Init(data string) (string, error)
- func WalletDir(data string) string
- type Ad
- type Advertiser
- type Cand
- type Host
- func (h *Host) Address() (string, error)
- func (h *Host) Balance() (outputs int, satoshis uint64)
- func (h *Host) Close()
- func (h *Host) FundBEEF(ctx context.Context, beef []byte, refuseUnmined bool) (chaincfg.Funded, error)
- func (h *Host) FundCoinbase(ctx context.Context, blocks int) (int, error)
- func (h *Host) FundTxid(ctx context.Context, txid string) (chaincfg.Funded, error)
- func (h *Host) Identity() string
- type Offer
- type Payee
- type Payout
- type Publisher
- func (p *Publisher) Advance(ctx context.Context, site string) error
- func (p *Publisher) Mint(ctx context.Context, s Settings) (string, error)
- func (p *Publisher) Site(site string) (SiteState, bool)
- func (p *Publisher) Sites() []string
- func (p *Publisher) Update(ctx context.Context, site string, s Settings) error
- type Race
- type Racer
- func (r *Racer) Open(ctx context.Context, site string, o Offer) (string, error)
- func (r *Racer) OpenRace(site string) (string, bool)
- func (r *Racer) Race(id string) (Race, bool)
- func (r *Racer) Races() []string
- func (r *Racer) Reclaim(ctx context.Context, id string) error
- func (r *Racer) Run(ctx context.Context, id string, o RunOptions) error
- type RunOptions
- type Settings
- type Settlement
- type SiteState
- type State
- type Tx
- type Watched
Constants ¶
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.
const ( CandPassed = "passed" CandFailed = "failed" )
Candidate statuses.
const Originator = "bweb"
Originator is the name the wallet is asked under.
Variables ¶
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.
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.
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.
var ErrNoHost = errors.New("the configuration has no host block (host.data)")
ErrNoHost is a configuration with no host block.
var ErrOpen = errors.New("the race is open")
ErrOpen is a race a run left open: fewer than K servers have passed.
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 ¶
Types ¶
type Ad ¶
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) 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 ¶
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).
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 ¶
NewPublisher is a publisher over an opened wallet.
func (*Publisher) Advance ¶
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 ¶
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.
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
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 (*Racer) Open ¶ added in v0.5.0
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
OpenRace is the id of the site's race that is still open, if any.
func (*Racer) Reclaim ¶ added in v0.5.0
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
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.