Documentation ¶
Overview ¶
Package kademlia 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
- func BytesID(b []byte) (p2p.NodeID, error)
- func HexID(in string) (p2p.NodeID, error)
- func MustBytesID(b []byte) p2p.NodeID
- func MustHexID(in string) p2p.NodeID
- func PubkeyID(pub *ecdsa.PublicKey) p2p.NodeID
- type KademliaReactor
- func (r *KademliaReactor) AddPeer(p p2p.Peer)
- func (r *KademliaReactor) GetChannels() []*p2pconn.ChannelDescriptor
- func (r *KademliaReactor) OnStart() error
- func (r *KademliaReactor) OnStop()
- func (r *KademliaReactor) Receive(chID byte, src p2p.Peer, msgBytes []byte)
- func (r *KademliaReactor) RemovePeer(p p2p.Peer, reason interface{})
- type Node
- type Peer
- type Table
Constants ¶
const ( // KademliaChannel is a channel for Kademlia messages KademliaChannel = byte(0x00) )
const NodeIDBits = 512
Variables ¶
This section is empty.
Functions ¶
func MustBytesID ¶
MustBytesID converts a byte slice to a NodeID. It panics if the byte slice is not a valid NodeID.
Types ¶
type KademliaReactor ¶
type KademliaReactor struct { p2p.BaseReactor // contains filtered or unexported fields }
func NewKademliaReactor ¶
func NewKademliaReactor(seedNetAddresses []*p2p.NetAddress) *KademliaReactor
NewKademliaReactor creates new Kademlia reactor.
func (*KademliaReactor) AddPeer ¶
func (r *KademliaReactor) AddPeer(p p2p.Peer)
AddPeer implements Reactor by adding peer to the address book (if inbound) or by requesting more addresses (if outbound).
func (*KademliaReactor) GetChannels ¶
func (r *KademliaReactor) GetChannels() []*p2pconn.ChannelDescriptor
GetChannels implements Reactor
func (*KademliaReactor) OnStart ¶
func (r *KademliaReactor) OnStart() error
OnStart implements BaseService
func (*KademliaReactor) Receive ¶
func (r *KademliaReactor) Receive(chID byte, src p2p.Peer, msgBytes []byte)
Receive implements Reactor by handling incoming Kademlia messages.
func (*KademliaReactor) RemovePeer ¶
func (r *KademliaReactor) RemovePeer(p p2p.Peer, reason interface{})
RemovePeer implements Reactor.
type Node ¶
type Node struct { IP net.IP // len 4 for IPv4 or 16 for IPv6 UDP, TCP uint16 // port numbers ID p2p.NodeID // the node's public key // contains filtered or unexported fields }
Node represents a host on the network. The fields of Node may not be modified.
func (*Node) Incomplete ¶
Incomplete returns true for nodes with no IP address.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
func (*Table) Close ¶
func (tab *Table) Close()
Close terminates the network listener and flushes the node database.
func (*Table) Lookup ¶
Lookup performs a network search for nodes close to the given target. It approaches the target by querying nodes that are closer to it on each iteration. The given target does not need to be an actual node identifier.
func (*Table) ReadRandomNodes ¶
ReadRandomNodes fills the given slice with random nodes from the table. It will not write the same node more than once. The nodes in the slice are copies and can be modified by the caller.