Documentation ¶
Index ¶
- Variables
- func LocationKey(addressable string) []byte
- func NodeKey(addressable string) []byte
- func PingAddress(address string, t int64) bool
- type Crawler
- func (c *Crawler) Crawl()
- func (c *Crawler) CrawlNode(nodeRPCAddr string)
- func (c *Crawler) DeleteNodeIfExist(n Node) error
- func (c *Crawler) GetGeolocation(nodeIP string) (Location, error)
- func (c *Crawler) GetStaleNodes(t time.Time) ([]Node, error)
- func (c *Crawler) RecheckNodes()
- func (c *Crawler) SaveNode(n Node) error
- type Location
- type Node
- type NodePool
Constants ¶
This section is empty.
Variables ¶
var ( NodeKeyPrefix = []byte("node/") LocationKeyPrefix = []byte("location/") )
Node persistence prefix keys
Functions ¶
func LocationKey ¶
LocationKey constructs the DB key for location persistence/caching.
func PingAddress ¶
PingAddress attempts to ping a P2P Tendermint address returning true if the node is reachable and false otherwise.
Types ¶
type Crawler ¶
type Crawler struct {
// contains filtered or unexported fields
}
Crawler implements the Tendermint p2p network crawler.
func (*Crawler) Crawl ¶
func (c *Crawler) Crawl()
Crawl starts a blocking process in which a random node is selected from the node pool and crawled. For each successful crawl, it'll be persisted or updated and its peers will be added to the node pool if they do not already exist. This process continues indefinitely until all nodes are exhausted from the pool. When the pool is empty and after crawlInterval seconds since the last complete crawl, a random set of nodes from the DB are added to reseed the pool.
func (*Crawler) CrawlNode ¶
CrawlNode performs the main crawling functionality for a Tendermint node. It accepts a node RPC address and attempts to ping that node's P2P address by using the RPC address and the default P2P port of 26656. If the P2P address cannot be reached, the node is deleted if it exists in the database. Otherwise, we attempt to get additional metadata aboout the node via it's RPC address and its set of peers. For every peer that doesn't exist in the node pool, it is added.
func (*Crawler) DeleteNodeIfExist ¶
DeleteNodeIfExist removes a node by it's addressable key from the database if it exists. An error is returned if it exists and cannot be deleted.
func (*Crawler) GetGeolocation ¶
GetGeolocation returns a Location object containing geolocation information for a given node IP. It will first check to see if the location already exists in the database and return it if so. Otherwise, a query is made against IPStack and persisted. An error is returned if the location cannot be decoded or queried for.
func (*Crawler) GetStaleNodes ¶
GetStaleNodes returns all persisted nodes from that database that have a LastSync time that is older than the provided time.
NOTE: We currently query for all nodes and for each node we check the LastSync value. This should ideally be improved in case the node set size is substantially large. It may require thinking the persistence interface.
func (*Crawler) RecheckNodes ¶
func (c *Crawler) RecheckNodes()
RecheckNodes starts a blocking process where every recheckInterval seconds the crawler checks for all stale nodes that need to be rechecked. For each stale node, the node is added back into the node pool to be re-crawled and updated (or removed).
type Location ¶
type Location struct { Country string `json:"country" yaml:"country"` Region string `json:"region" yaml:"region"` City string `json:"city" yaml:"city"` Latitude string `json:"latitude" yaml:"latitude"` Longitude string `json:"longitude" yaml:"longitude"` }
Location defines geolocation information of a Tendermint node.
type Node ¶
type Node struct { Address string `json:"address" yaml:"address"` RPCPort string `json:"rpc_port" yaml:"rpc_port"` P2PPort string `json:"p2p_port" yaml:"p2p_port"` Moniker string `json:"moniker" yaml:"moniker"` ID string `json:"id" yaml:"id"` Network string `json:"network" yaml:"network"` Version string `json:"version" yaml:"version"` TxIndex string `json:"tx_index" yaml:"tx_index"` LastSync string `json:"last_sync" yaml:"last_sync"` Location Location `json:"location" yaml:"location"` }
Node represents a full-node in a Tendermint-based network that contains relevant p2p data.
type NodePool ¶
type NodePool struct {
// contains filtered or unexported fields
}
NodePool implements an abstraction over a pool of nodes for which to crawl. It also contains a collection of nodes for which to reseed the pool when it's empty. Once the reseed list has reached capacity, a random node is removed when another is added. Note, it is not thread-safe.
func NewNodePool ¶
func (*NodePool) AddNode ¶
AddNode adds a node RPC address to the node pool. In addition, it adds the node to the reseed list. If the reseed list is full, it replaces a random node.
func (*NodePool) DeleteNode ¶
DeleteNode removes a node from the node pool if it exists.
func (*NodePool) HasNode ¶
HasNode returns a boolean based on if a node RPC address exists in the node pool.
func (*NodePool) RandomNode ¶
RandomNode returns a random node, based on Golang's map semantics, from the pool.
func (*NodePool) Reseed ¶
func (p *NodePool) Reseed()
Reseed seeds the node pool with all the nodes found in the internal reseed list.