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
- Variables
- type AddSeenNodeCB
- type Attribute
- type AttributeID
- type Attributes
- type Config
- type NodeQueue
- func (nq *NodeQueue) AddNode(anode *node) (bool, *node)
- func (nq *NodeQueue) AddNodeItem(anode *node, shouldUpdate bool) bool
- func (nq *NodeQueue) Contains(nodeId enode.ID) bool
- func (nq *NodeQueue) Get(nodeId enode.ID) *node
- func (nq *NodeQueue) Length() int
- func (nq *NodeQueue) MoveBack(nodeId enode.ID) bool
- func (nq *NodeQueue) MoveFront(nodeId enode.ID) bool
- func (nq *NodeQueue) RemoveNodeItem(nodeId enode.ID) (bool, *node)
- func (nq *NodeQueue) ReplaceNodeItem(anode *node, checkReplace func(nodeInEntries *node) bool) (bool, *node)
- type ReadPacket
- type SortableNode
- type Table
- func (tab *Table) AddBootnode(n *enode.Node)
- func (tab *Table) AddSeenNode(n *node) *node
- func (tab *Table) CanAddNode(n *enode.Node) bool
- func (tab *Table) CanProcPing(id enode.ID) bool
- func (tab *Table) CanProcPong(id enode.ID) bool
- func (tab *Table) CanSendPing(id enode.ID) bool
- func (tab *Table) CanStartConnect(id enode.ID) bool
- func (tab *Table) Close()
- func (tab *Table) DoPing(n *node, ch chan *enode.Node)
- func (tab *Table) DoPongResult(n *enode.Node, duration int64, ok bool)
- func (tab *Table) GetKnownNodesSorted() []*enode.Node
- func (srv *Table) IsBlocked(id enode.ID) bool
- func (tab *Table) LookupRandom() []*enode.Node
- func (tab *Table) OnNodeChanged(nodeChanged chan struct{})
- func (tab *Table) OnPingReceived(n *enode.Node, ip net.IP, port uint16)
- func (tab *Table) ReadRandomNodes(buf []*enode.Node) (n int)
- func (tab *Table) RegisterPeer(node2 enode.Node)
- func (tab *Table) RemoveConnectedNode(nodeId enode.ID, discCount int)
- func (tab *Table) RequestPing(node *enode.Node, ch chan *enode.Node)
- func (tab *Table) Resolve(n *enode.Node) *enode.Node
- func (tab *Table) ShouldAcceptConn(id enode.ID) bool
- func (tab *Table) TargetBucketInfo(nodeId enode.ID) (bucketId int, entries, replacements *NodeQueue)
Constants ¶
const ( StateUnknown = 0 StateEntries = 1 StateReplace = 2 )
const (
LatencyCacheSize = 128
)
Timeouts
Variables ¶
var ( LatencyInvalid = int64(100 * time.Hour) TimeInvalid = time.Unix(0, 0) RevalidateInterval = 30 * time.Second )
node represents a host on the network. The fields of Node may not be modified.
Functions ¶
This section is empty.
Types ¶
type AddSeenNodeCB ¶
type AddSeenNodeCB func(n *node) *node
type AttributeID ¶
type AttributeID uint8
const ( AttrLastSeen AttributeID = 0 AttrTestAt AttributeID = 1 AttrFindAt AttributeID = 2 AttrAddAt AttributeID = 3 AttrLatency AttributeID = 4 )
type Attributes ¶
type Attributes []*Attribute
type Config ¶
type Config struct { // These settings are required and configure the UDP listener: PrivateKey *ecdsa.PrivateKey // These settings are optional: NetRestrict *netutil.Netlist // network whitelist Bootnodes []*enode.Node // list of bootstrap nodes Unhandled chan<- ReadPacket // unhandled packets are sent on this channel }
Config holds Table-related settings.
type NodeQueue ¶
type NodeQueue struct {
// contains filtered or unexported fields
}
func NewNodeQueue ¶
func (*NodeQueue) AddNodeItem ¶
func (*NodeQueue) RemoveNodeItem ¶
func (*NodeQueue) ReplaceNodeItem ¶
type ReadPacket ¶
ReadPacket is sent to the unhandled channel when it could not be processed
type SortableNode ¶
type SortableNode []*node
func (SortableNode) Len ¶
func (c SortableNode) Len() int
func (SortableNode) Less ¶
func (c SortableNode) Less(i, j int) bool
func (SortableNode) Swap ¶
func (c SortableNode) Swap(i, j int)
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
func (*Table) AddBootnode ¶
func (*Table) AddSeenNode ¶
func (tab *Table) AddSeenNode(n *node) *node
func (*Table) CanAddNode ¶
*
当收到其他节点的连接时,通过这个来检查是否允许连接,而实际上,在连接的之前,都应该使用ping/pong测试过才可以 如果我没有收到过ping/pong的测试,那么就禁止连接
func (*Table) Close ¶
func (tab *Table) Close()
Close terminates the network listener and flushes the node database.
func (*Table) GetKnownNodesSorted ¶
按延时从小到大的顺序排好
func (*Table) LookupRandom ¶
LookupRandom finds random nodes in the network.
func (*Table) OnNodeChanged ¶
func (tab *Table) OnNodeChanged(nodeChanged chan struct{})
func (*Table) OnPingReceived ¶
func (*Table) ReadRandomNodes ¶
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.