crawl

package
v0.0.0-...-ac0319f Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: CC0-1.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NodeKeyPrefix     = []byte("node/")
	LocationKeyPrefix = []byte("location/")
)

Node persistence prefix keys

Functions

func LocationKey

func LocationKey(addressable string) []byte

LocationKey constructs the DB key for location persistence/caching.

func NodeKey

func NodeKey(addressable string) []byte

NodeKey constructs the DB key for node persistence.

func PingAddress

func PingAddress(address string, t int64) bool

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 NewCrawler

func NewCrawler(cfg config.Config, db db.DB) *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

func (c *Crawler) CrawlNode(nodeRPCAddr string)

!MAIN CRAWLING FUNCTIONALITY 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

func (c *Crawler) DeleteNodeIfExist(n Node) error

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

func (c *Crawler) GetGeolocation(nodeIP string) (Location, error)

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

func (c *Crawler) GetStaleNodes(t time.Time) ([]Node, error)

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

func (*Crawler) SaveNode

func (c *Crawler) SaveNode(n Node) error

SaveNode persists a node to the database by it's addressable key. An error is returned if it cannot be marshaled or the database operation fails.

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.

func (Location) Marshal

func (l Location) Marshal() ([]byte, error)

Marshal returns the MessagePack encoding of a Location.

func (*Location) Unmarshal

func (l *Location) Unmarshal(bz []byte) error

Unmarshal unmarshals a MessagePack encoding of a Location.

type Node

type Node struct {
	//Defined at Init
	IP       string `json:"ip" yaml:"ip"`
	RPCPort  string `json:"rpc_port" yaml:"rpc_port"`
	P2PPort  string `json:"p2p_port" yaml:"p2p_port"`
	LastSync string `json:"last_sync" yaml:"last_sync"`

	//Defined from Status
	Moniker         string              `json:"moniker" yaml:"moniker"`
	ID              p2p.ID              `json:"id" yaml:"id"`
	Network         string              `json:"network" yaml:"network"`
	ProtocolVersion p2p.ProtocolVersion `json:"version" yaml:"version"`

	//Types
	Other    p2p.DefaultNodeInfoOther `json:"other_info" yaml:"other_info"`
	SyncInfo coretypes.SyncInfo       `json:"sync_info" yaml:"sync_info"`
	Location Location                 `json:"location" yaml:"location"`

	//Defined from Validator Info
	ValidatorAddress       bytes.HexBytes `json:"validator_address" yaml:"validator_address"`
	ValidatorPubKeyAddress crypto.Address `json:"validator_pubkey_address" yaml:"validator_pubkey_address"`
	ValidatorPubKeyBytes   []byte         `json:"validator_pubkey_byte" yaml:"validator_pubkey_byte"`
	ValidatorVotingPower   int64          `json:"validator_voting_power" yaml:"validator_voting_power"`
}

Node represents a full-node in a Tendermint-based network that contains relevant p2p data.

func (Node) Key

func (n Node) Key() []byte

Key returns the addressable persistence key of a Node.

func (Node) Marshal

func (n Node) Marshal() ([]byte, error)

Marshal returns the MessagePack encoding of a Node.

func (*Node) Unmarshal

func (n *Node) Unmarshal(bz []byte) error

Unmarshal unmarshals a MessagePack encoding of a Node.

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 NewNodePool(reseedCap uint) *NodePool

func (*NodePool) AddNode

func (p *NodePool) AddNode(nodeRPCAddr string)

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

func (p *NodePool) DeleteNode(nodeRPCAddr string)

DeleteNode removes a node from the node pool if it exists.

func (*NodePool) HasNode

func (p *NodePool) HasNode(nodeRPCAddr string) bool

HasNode returns a boolean based on if a node RPC address exists in the node pool.

func (*NodePool) RandomNode

func (p *NodePool) RandomNode() (string, bool)

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.

func (*NodePool) Seed

func (p *NodePool) Seed(seeds []string)

Seed seeds the node pool with a given set of node IPs.

func (*NodePool) Size

func (p *NodePool) Size() int

Size returns the size of the pool.

Jump to

Keyboard shortcuts

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