discover

package
v0.0.0-...-2e66602 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2021 License: GPL-3.0 Imports: 23 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

View Source
const (
	StateUnknown = 0
	StateEntries = 1
	StateReplace = 2
)
View Source
const (
	LatencyCacheSize = 128
)

Timeouts

Variables

View Source
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 Attribute

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

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 NewNodeQueue(maxsize int) *NodeQueue

func (*NodeQueue) AddNode

func (nq *NodeQueue) AddNode(anode *node) (bool, *node)

func (*NodeQueue) AddNodeItem

func (nq *NodeQueue) AddNodeItem(anode *node, shouldUpdate bool) bool

func (*NodeQueue) Contains

func (nq *NodeQueue) Contains(nodeId enode.ID) bool

func (*NodeQueue) Get

func (nq *NodeQueue) Get(nodeId enode.ID) *node

func (*NodeQueue) Length

func (nq *NodeQueue) Length() int

func (*NodeQueue) MoveBack

func (nq *NodeQueue) MoveBack(nodeId enode.ID) bool

func (*NodeQueue) MoveFront

func (nq *NodeQueue) MoveFront(nodeId enode.ID) bool

func (*NodeQueue) RemoveNodeItem

func (nq *NodeQueue) RemoveNodeItem(nodeId enode.ID) (bool, *node)

func (*NodeQueue) ReplaceNodeItem

func (nq *NodeQueue) ReplaceNodeItem(anode *node, checkReplace func(nodeInEntries *node) bool) (bool, *node)

type ReadPacket

type ReadPacket struct {
	Data []byte
	Addr *net.UDPAddr
}

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 ListenUDP

func ListenUDP(c conn, ln *enode.LocalNode, cfg Config) (*Table, error)

ListenUDP returns a new table that listens for UDP packets on laddr.

func (*Table) AddBootnode

func (tab *Table) AddBootnode(n *enode.Node)

func (*Table) AddSeenNode

func (tab *Table) AddSeenNode(n *node) *node

func (*Table) CanAddNode

func (tab *Table) CanAddNode(n *enode.Node) bool

*

当收到其他节点的连接时,通过这个来检查是否允许连接,而实际上,在连接的之前,都应该使用ping/pong测试过才可以
如果我没有收到过ping/pong的测试,那么就禁止连接

func (*Table) CanProcPing

func (tab *Table) CanProcPing(id enode.ID) bool

func (*Table) CanProcPong

func (tab *Table) CanProcPong(id enode.ID) bool

func (*Table) CanSendPing

func (tab *Table) CanSendPing(id enode.ID) bool

func (*Table) CanStartConnect

func (tab *Table) CanStartConnect(id enode.ID) bool

func (*Table) Close

func (tab *Table) Close()

Close terminates the network listener and flushes the node database.

func (*Table) DoPing

func (tab *Table) DoPing(n *node, ch chan *enode.Node)

func (*Table) DoPongResult

func (tab *Table) DoPongResult(n *enode.Node, duration int64, ok bool)

func (*Table) GetKnownNodesSorted

func (tab *Table) GetKnownNodesSorted() []*enode.Node

按延时从小到大的顺序排好

func (*Table) IsBlocked

func (srv *Table) IsBlocked(id enode.ID) bool

func (*Table) LookupRandom

func (tab *Table) LookupRandom() []*enode.Node

LookupRandom finds random nodes in the network.

func (*Table) OnNodeChanged

func (tab *Table) OnNodeChanged(nodeChanged chan struct{})

func (*Table) OnPingReceived

func (tab *Table) OnPingReceived(n *enode.Node, ip net.IP, port uint16)

func (*Table) ReadRandomNodes

func (tab *Table) ReadRandomNodes(buf []*enode.Node) (n 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 (*Table) RegisterPeer

func (tab *Table) RegisterPeer(node2 enode.Node)

func (*Table) RemoveConnectedNode

func (tab *Table) RemoveConnectedNode(nodeId enode.ID, discCount int)

func (*Table) RequestPing

func (tab *Table) RequestPing(node *enode.Node, ch chan *enode.Node)

func (*Table) Resolve

func (tab *Table) Resolve(n *enode.Node) *enode.Node

Resolve searches for a specific node with the given ID. It returns nil if the node could not be found.

func (*Table) ShouldAcceptConn

func (tab *Table) ShouldAcceptConn(id enode.ID) bool

func (*Table) TargetBucketInfo

func (tab *Table) TargetBucketInfo(nodeId enode.ID) (bucketId int, entries, replacements *NodeQueue)

Jump to

Keyboard shortcuts

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