kademlia

package
v0.0.0-...-0ce3ae6 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2018 License: Apache-2.0 Imports: 31 Imported by: 2

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

View Source
const (
	// KademliaChannel is a channel for Kademlia messages
	KademliaChannel = byte(0x00)
)
View Source
const NodeIDBits = 512

Variables

This section is empty.

Functions

func BytesID

func BytesID(b []byte) (p2p.NodeID, error)

BytesID converts a byte slice to a NodeID

func HexID

func HexID(in string) (p2p.NodeID, error)

HexID converts a hex string to a NodeID. The string may be prefixed with 0x.

func MustBytesID

func MustBytesID(b []byte) p2p.NodeID

MustBytesID converts a byte slice to a NodeID. It panics if the byte slice is not a valid NodeID.

func MustHexID

func MustHexID(in string) p2p.NodeID

MustHexID converts a hex string to a NodeID. It panics if the string is not a valid NodeID.

func PubkeyID

func PubkeyID(pub *ecdsa.PublicKey) p2p.NodeID

PubkeyID returns a marshaled representation of the given public key.

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) OnStop

func (r *KademliaReactor) OnStop()

OnStop 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 NewNode

func NewNode(id p2p.NodeID, ip net.IP) *Node

NewNode creates a new node. It is mostly meant to be used for testing purposes.

func (*Node) Incomplete

func (n *Node) Incomplete() bool

Incomplete returns true for nodes with no IP address.

type Peer

type Peer p2p.Peer

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

func (tab *Table) Lookup(targetID p2p.NodeID) []*Node

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

func (tab *Table) ReadRandomNodes(buf []*Node) (n int)

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.

func (*Table) Resolve

func (tab *Table) Resolve(targetID p2p.NodeID) *Node

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

func (*Table) Self

func (tab *Table) Self() *Node

Self returns the local node. The returned node should not be modified by the caller.

Jump to

Keyboard shortcuts

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