Documentation ¶
Overview ¶
Package hostdb provides a HostDB object that implements the renter.hostDB interface. The blockchain is scanned for host announcements and hosts that are found get added to the host database. The database continually scans the set of hosts it has found and updates who is online.
Index ¶
- Variables
- type HostDB
- func (hdb *HostDB) ActiveHosts() (activeHosts []modules.HostDBEntry, err error)
- func (hdb *HostDB) Alerts() (crit, err, warn []modules.Alert)
- func (hdb *HostDB) AllHosts() (allHosts []modules.HostDBEntry, err error)
- func (hdb *HostDB) CheckForIPViolations(hosts []types.SiaPublicKey) ([]types.SiaPublicKey, error)
- func (hdb *HostDB) Close() error
- func (hdb *HostDB) EstimateHostScore(entry modules.HostDBEntry, allowance modules.Allowance) (modules.HostScoreBreakdown, error)
- func (hdb *HostDB) Filter() (modules.FilterMode, map[string]types.SiaPublicKey, error)
- func (hdb *HostDB) Host(spk types.SiaPublicKey) (modules.HostDBEntry, bool, error)
- func (hdb *HostDB) IPRestriction() (int, error)
- func (hdb *HostDB) IncrementFailedInteractions(key types.SiaPublicKey) error
- func (hdb *HostDB) IncrementSuccessfulInteractions(key types.SiaPublicKey) error
- func (hdb *HostDB) InitialScanComplete() (complete bool, err error)
- func (hdb *HostDB) ProcessConsensusChange(cc modules.ConsensusChange)
- func (hdb *HostDB) RandomHosts(n int, blacklist, addressBlacklist []types.SiaPublicKey) ([]modules.HostDBEntry, error)
- func (hdb *HostDB) RandomHostsWithAllowance(n int, blacklist, addressBlacklist []types.SiaPublicKey, ...) ([]modules.HostDBEntry, error)
- func (hdb *HostDB) ScoreBreakdown(entry modules.HostDBEntry) (modules.HostScoreBreakdown, error)
- func (hdb *HostDB) SetAllowance(allowance modules.Allowance) error
- func (hdb *HostDB) SetFilterMode(fm modules.FilterMode, hosts []types.SiaPublicKey) error
- func (hdb *HostDB) SetIPRestriction(numhosts int) error
- func (hdb *HostDB) UpdateContracts(contracts []modules.RenterContract) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInitialScanIncomplete is returned whenever an operation is not // allowed to be executed before the initial host scan has finished. ErrInitialScanIncomplete = errors.New("initial hostdb scan is not yet completed") )
Functions ¶
This section is empty.
Types ¶
type HostDB ¶
type HostDB struct {
// contains filtered or unexported fields
}
The HostDB is a database of potential hosts. It assigns a weight to each host based on their hosting parameters, and then can select hosts at random for uploading files.
func New ¶
func New(g modules.Gateway, cs modules.ConsensusSet, tpool modules.TransactionPool, persistDir string) (*HostDB, <-chan error)
New returns a new HostDB.
func NewCustomHostDB ¶ added in v1.3.3
func NewCustomHostDB(g modules.Gateway, cs modules.ConsensusSet, tpool modules.TransactionPool, persistDir string, deps modules.Dependencies) (*HostDB, <-chan error)
NewCustomHostDB creates a HostDB using the provided dependencies. It loads the old persistence data, spawns the HostDB's scanning threads, and subscribes it to the consensusSet.
func (*HostDB) ActiveHosts ¶
func (hdb *HostDB) ActiveHosts() (activeHosts []modules.HostDBEntry, err error)
ActiveHosts returns a list of hosts that are currently online, sorted by weight. If hostdb is in black or white list mode, then only active hosts from the filteredTree will be returned
func (*HostDB) Alerts ¶ added in v1.5.0
Alerts implements the modules.Alerter interface for the hostdb. It returns all alerts of the hostdb.
func (*HostDB) AllHosts ¶
func (hdb *HostDB) AllHosts() (allHosts []modules.HostDBEntry, err error)
AllHosts returns all of the hosts known to the hostdb, including the inactive ones. AllHosts is not filtered by blacklist or whitelist mode.
func (*HostDB) CheckForIPViolations ¶ added in v1.3.5
func (hdb *HostDB) CheckForIPViolations(hosts []types.SiaPublicKey) ([]types.SiaPublicKey, error)
CheckForIPViolations accepts a number of host public keys and returns the ones that violate the rules of the addressFilter.
func (*HostDB) EstimateHostScore ¶ added in v1.3.0
func (hdb *HostDB) EstimateHostScore(entry modules.HostDBEntry, allowance modules.Allowance) (modules.HostScoreBreakdown, error)
EstimateHostScore takes a HostExternalSettings and returns the estimated score of that host in the hostdb, assuming no penalties for age or uptime.
func (*HostDB) Filter ¶ added in v1.4.0
func (hdb *HostDB) Filter() (modules.FilterMode, map[string]types.SiaPublicKey, error)
Filter returns the hostdb's filterMode and filteredHosts
func (*HostDB) Host ¶
func (hdb *HostDB) Host(spk types.SiaPublicKey) (modules.HostDBEntry, bool, error)
Host returns the HostSettings associated with the specified pubkey. If no matching host is found, Host returns false. For black and white list modes, the Filtered field for the HostDBEntry is set to indicate it the host is being filtered from the filtered hosttree
func (*HostDB) IPRestriction ¶ added in v1.5.0
IPRestriction returns the number of allowed hosts from the same IP address subnet or zero if the IPRestriction check is disabled.
func (*HostDB) IncrementFailedInteractions ¶ added in v1.3.0
func (hdb *HostDB) IncrementFailedInteractions(key types.SiaPublicKey) error
IncrementFailedInteractions increments the number of failed interactions with a host for a given key
func (*HostDB) IncrementSuccessfulInteractions ¶ added in v1.3.0
func (hdb *HostDB) IncrementSuccessfulInteractions(key types.SiaPublicKey) error
IncrementSuccessfulInteractions increments the number of successful interactions with a host for a given key
func (*HostDB) InitialScanComplete ¶ added in v1.3.3
InitialScanComplete returns a boolean indicating if the initial scan of the hostdb is completed.
func (*HostDB) ProcessConsensusChange ¶
func (hdb *HostDB) ProcessConsensusChange(cc modules.ConsensusChange)
ProcessConsensusChange will be called by the consensus set every time there is a change in the blockchain. Updates will always be called in order.
func (*HostDB) RandomHosts ¶
func (hdb *HostDB) RandomHosts(n int, blacklist, addressBlacklist []types.SiaPublicKey) ([]modules.HostDBEntry, error)
RandomHosts implements the HostDB interface's RandomHosts() method. It takes a number of hosts to return, and a slice of netaddresses to ignore, and returns a slice of entries. If the IP violation check was disabled, the addressBlacklist is ignored.
func (*HostDB) RandomHostsWithAllowance ¶ added in v1.3.5
func (hdb *HostDB) RandomHostsWithAllowance(n int, blacklist, addressBlacklist []types.SiaPublicKey, allowance modules.Allowance) ([]modules.HostDBEntry, error)
RandomHostsWithAllowance works as RandomHosts but uses a temporary hosttree created from the specified allowance. This is a very expensive call and should be used with caution.
func (*HostDB) ScoreBreakdown ¶ added in v1.1.1
func (hdb *HostDB) ScoreBreakdown(entry modules.HostDBEntry) (modules.HostScoreBreakdown, error)
ScoreBreakdown provdes a detailed set of scalars and bools indicating elements of the host's overall score.
func (*HostDB) SetAllowance ¶ added in v1.3.5
SetAllowance updates the allowance used by the hostdb for weighing hosts by updating the host weight function. It will completely rebuild the hosttree so it should be used with care.
func (*HostDB) SetFilterMode ¶ added in v1.4.0
func (hdb *HostDB) SetFilterMode(fm modules.FilterMode, hosts []types.SiaPublicKey) error
SetFilterMode sets the hostdb filter mode
func (*HostDB) SetIPRestriction ¶ added in v1.5.0
SetIPRestriction the number of allowed hosts from the same IP address subnet. Set to zero to disable the IPRestriction check.
func (*HostDB) UpdateContracts ¶ added in v1.5.0
func (hdb *HostDB) UpdateContracts(contracts []modules.RenterContract) error
UpdateContracts rebuilds the knownContracts of the HostBD using the provided contracts.