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 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 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 Settings
- type SiteState
- type State
- type Tx
Constants ¶
const Originator = "bweb"
Originator is the name the wallet is asked under.
Variables ¶
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 ErrNoHost = errors.New("the configuration has no host block (host.data)")
ErrNoHost is a configuration with no host block.
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, a site at a time: finishes what a previous run or pass left unmined or unpublished, then mints or renews.
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) 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 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 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.