discover

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2019 License: Apache-2.0 Imports: 21 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var (
	//MaxBucketSize is max nodes's num  for one bucket
	MaxBucketSize = hashBits
)

Functions

func DistCmp

func DistCmp(target, a, b common.NodeID) int

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.

func LogDist

func LogDist(a, b common.NodeID) int

LogDist returns the logarithmic distance between a and b, log2(a ^ b).

func NewDBManager added in v0.1.1

func NewDBManager(rawDB dbm.DB, logger log.Logger) *dbManager

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

func (tab *DhtTable) GetBestNodes(maxSize int, needHavePubAddrFlag bool) (nodes []*common.Node)

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

func (tab *DhtTable) GetMaxConNumFromCache() int

GetMaxConNumFromCache return the max node's num from local cache

func (*DhtTable) GetMaxDialOutNum added in v0.1.1

func (tab *DhtTable) GetMaxDialOutNum() int

GetMaxDialOutNum return the max dialout num

func (*DhtTable) GetNodesNumFromKbucket added in v0.1.2

func (tab *DhtTable) GetNodesNumFromKbucket() (nodesNum int)

func (*DhtTable) IsDhtTable added in v0.1.1

func (tab *DhtTable) IsDhtTable() bool

IsDhtTable return whether current table is DhtTable or not

func (*DhtTable) LookupRandom added in v0.1.1

func (tab *DhtTable) LookupRandom() []*common.Node

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

func (tab *DhtTable) ReadNodesFromKbucket(buf []*common.Node) (nodeNum int)

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) Refresh added in v0.1.1

func (tab *DhtTable) Refresh() <-chan struct{}

func (*DhtTable) Self added in v0.1.2

func (tab *DhtTable) Self() *common.Node

Self return myself dht net info

func (*DhtTable) SetIgnoreFindFailFlag added in v0.1.2

func (tab *DhtTable) SetIgnoreFindFailFlag(flag bool)

SetIgnoreFindFailFlag set ignoreFindFailFlag.

func (*DhtTable) Start added in v0.1.1

func (tab *DhtTable) Start()

Start start dht service

func (*DhtTable) StartWithOutPing added in v0.1.2

func (tab *DhtTable) StartWithOutPing()

StartWithOutPing start dht service

func (*DhtTable) Stop added in v0.1.1

func (tab *DhtTable) Stop()

Stop shuts down the socket and aborts any running queries.

type HTTPTable

type HTTPTable struct {
	// contains filtered or unexported fields
}

HTTPTable only include seeds node

func NewHTTPTable

func NewHTTPTable(cfg common.Config, bootSvr string, log log.Logger) (*HTTPTable, error)

NewHTTPTable starts get seeds from bootnode server.

func (*HTTPTable) GetMaxConNumFromCache

func (tab *HTTPTable) GetMaxConNumFromCache() int

GetMaxConNumFromCache return the max node's num from local cache

func (*HTTPTable) GetMaxDialOutNum

func (tab *HTTPTable) GetMaxDialOutNum() int

GetMaxDialOutNum return the max dialout num

func (*HTTPTable) IsDhtTable added in v0.1.1

func (tab *HTTPTable) IsDhtTable() bool

func (*HTTPTable) LookupRandom

func (tab *HTTPTable) LookupRandom() []*common.Node

LookupRandom get seeds from bootnode server

func (*HTTPTable) ReadRandomNodes

func (tab *HTTPTable) ReadRandomNodes(buf []*common.Node, alreadyConnect map[string]bool) (nodeNum int)

ReadRandomNodes get rand seeds from local cache

func (*HTTPTable) Start

func (tab *HTTPTable) Start()

func (*HTTPTable) Stop

func (tab *HTTPTable) Stop()

type SlefInfo added in v0.1.1

type SlefInfo struct {
	Self      *common.Node
	ListenCon common.UDPConn
}

SlefInfo is myself node info

Jump to

Keyboard shortcuts

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