Documentation ¶
Overview ¶
Package discover implements the Node Discovery Protocol.
The Node Discovery protocol provides a way to find RLPx nodes that can be connected to. It uses a Kademlia-like protocol to maintain a distributed database of the IDs and endpoints of all listening nodes.
Index ¶
- Variables
- func DistCmp(target, a, b common.NodeID) int
- func LogDist(a, b common.NodeID) int
- func NewDBManager(rawDB dbm.DB, logger log.Logger) *dbManager
- type DhtTable
- func (tab *DhtTable) GetBestNodes(maxSize int, needHavePubAddrFlag bool) (nodes []*common.Node)
- func (tab *DhtTable) GetMaxConNumFromCache() int
- func (tab *DhtTable) GetMaxDialOutNum() int
- func (tab *DhtTable) GetNodesNumFromKbucket() (nodesNum int)
- func (tab *DhtTable) IsDhtTable() bool
- func (tab *DhtTable) LookupRandom() []*common.Node
- func (tab *DhtTable) PrinttAllnodes()
- func (tab *DhtTable) ReadAllNodesFromKbucket() (buckets [][]*node)
- func (tab *DhtTable) ReadNodesFromKbucket(buf []*common.Node) (nodeNum int)
- func (tab *DhtTable) ReadRandomNodes(buf []*common.Node, alreadyConnect map[string]bool) (nodeNum int)
- func (tab *DhtTable) Refresh() <-chan struct{}
- func (tab *DhtTable) Self() *common.Node
- func (tab *DhtTable) SetIgnoreFindFailFlag(flag bool)
- func (tab *DhtTable) Start()
- func (tab *DhtTable) StartWithOutPing()
- func (tab *DhtTable) Stop()
- type HTTPTable
- func (tab *HTTPTable) GetMaxConNumFromCache() int
- func (tab *HTTPTable) GetMaxDialOutNum() int
- func (tab *HTTPTable) IsDhtTable() bool
- func (tab *HTTPTable) LookupRandom() []*common.Node
- func (tab *HTTPTable) ReadRandomNodes(buf []*common.Node, alreadyConnect map[string]bool) (nodeNum int)
- func (tab *HTTPTable) Start()
- func (tab *HTTPTable) Stop()
- type SlefInfo
Constants ¶
This section is empty.
Variables ¶
var (
//MaxBucketSize is max nodes's num for one bucket
MaxBucketSize = hashBits
)
Functions ¶
func DistCmp ¶
DistCmp compares the distances a->target and b->target. Returns -1 if a is closer to target, 1 if b is closer to target and 0 if they are equal.
Types ¶
type DhtTable ¶ added in v0.1.1
type DhtTable struct {
// contains filtered or unexported fields
}
DhtTable is the 'node table', a Kademlia-like index of neighbor nodes. The table keeps itself up-to-date by verifying the liveness of neighbors and requesting their node records when announcements of a new record version are received.
func NewDhtTable ¶ added in v0.1.1
func NewDhtTable(maxDhtDialOutNums int, self *SlefInfo, db common.P2pDBManager, cfg common.Config, log log.Logger) (*DhtTable, error)
NewDhtTable starts listening for discovery packets on the given UDP socket.
func (*DhtTable) GetBestNodes ¶ added in v0.1.2
GetBestNodes return nodes who are upnp success or in public network when needHavePubAddrFlag is true,the size of return nodes should not bigger than maxSize
func (*DhtTable) GetMaxConNumFromCache ¶ added in v0.1.1
GetMaxConNumFromCache return the max node's num from local cache
func (*DhtTable) GetMaxDialOutNum ¶ added in v0.1.1
GetMaxDialOutNum return the max dialout num
func (*DhtTable) GetNodesNumFromKbucket ¶ added in v0.1.2
func (*DhtTable) IsDhtTable ¶ added in v0.1.1
IsDhtTable return whether current table is DhtTable or not
func (*DhtTable) LookupRandom ¶ added in v0.1.1
LookupRandom finds random nodes in the network.
func (*DhtTable) PrinttAllnodes ¶ added in v0.1.1
func (tab *DhtTable) PrinttAllnodes()
PrinttAllnodes printf all nodes's netinfo in kbucket
func (*DhtTable) ReadAllNodesFromKbucket ¶ added in v0.1.2
func (tab *DhtTable) ReadAllNodesFromKbucket() (buckets [][]*node)
ReadAllNodesFromKbucket return all nodes's net info from kbucket
func (*DhtTable) ReadNodesFromKbucket ¶ added in v0.1.1
ReadNodesFromKbucket return nodes' net info from kbucket
func (*DhtTable) ReadRandomNodes ¶ added in v0.1.1
func (tab *DhtTable) ReadRandomNodes(buf []*common.Node, alreadyConnect map[string]bool) (nodeNum int)
ReadRandomNodes fills the given slice with random nodes from the table. The results are guaranteed to be unique for a single invocation, no node will appear twice.
func (*DhtTable) SetIgnoreFindFailFlag ¶ added in v0.1.2
SetIgnoreFindFailFlag set ignoreFindFailFlag.
func (*DhtTable) StartWithOutPing ¶ added in v0.1.2
func (tab *DhtTable) StartWithOutPing()
StartWithOutPing start dht service
type HTTPTable ¶
type HTTPTable struct {
// contains filtered or unexported fields
}
HTTPTable only include seeds node
func NewHTTPTable ¶
NewHTTPTable starts get seeds from bootnode server.
func (*HTTPTable) GetMaxConNumFromCache ¶
GetMaxConNumFromCache return the max node's num from local cache
func (*HTTPTable) GetMaxDialOutNum ¶
GetMaxDialOutNum return the max dialout num
func (*HTTPTable) IsDhtTable ¶ added in v0.1.1
func (*HTTPTable) LookupRandom ¶
LookupRandom get seeds from bootnode server