discv5

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2022 License: GPL-3.0 Imports: 35 Imported by: 1

Documentation

Overview

Package discv5 implements the RLPx v5 Topic Discovery Protocol.

The Topic 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

Examples

Constants

View Source
const Version = 4

Variables

This section is empty.

Functions

This section is empty.

Types

type Network

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

func ListenUDP

func ListenUDP(priv *ecdsa.PrivateKey, conn conn, realaddr *net.UDPAddr, nodeDBPath string, netrestrict *netutil.Netlist) (*Network, error)

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

func (*Network) Close

func (net *Network) Close()

func (*Network) Lookup

func (net *Network) Lookup(targetID NodeID) []*Node

func (*Network) ReadRandomNodes

func (net *Network) ReadRandomNodes(buf []*Node) (n int)

func (*Network) RegisterTopic

func (net *Network) RegisterTopic(topic Topic, stop <-chan struct{})

func (*Network) Resolve

func (net *Network) Resolve(targetID NodeID) *Node

func (*Network) SearchTopic

func (net *Network) SearchTopic(topic Topic, setPeriod <-chan time.Duration, found chan<- *Node, lookup chan<- bool)

func (*Network) Self

func (net *Network) Self() *Node

func (*Network) SetFallbackNodes

func (net *Network) SetFallbackNodes(nodes []*Node) error

type Node

type Node struct {
	IP       net.IP
	UDP, TCP uint16
	ID       NodeID
	// contains filtered or unexported fields
}

func MustParseNode

func MustParseNode(rawurl string) *Node

func NewNode

func NewNode(id NodeID, ip net.IP, udpPort, tcpPort uint16) *Node
Example
id := MustHexID("1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439")

n1 := NewNode(id, net.ParseIP("2001:db8:3c4d:15::abcd:ef12"), 52150, 30303)
fmt.Println("n1:", n1)
fmt.Println("n1.Incomplete() ->", n1.Incomplete())

n2 := NewNode(id, nil, 0, 0)
fmt.Println("n2:", n2)
fmt.Println("n2.Incomplete() ->", n2.Incomplete())
Output:

func ParseNode

func ParseNode(rawurl string) (*Node, error)

func (*Node) Incomplete

func (n *Node) Incomplete() bool

func (*Node) MarshalText

func (n *Node) MarshalText() ([]byte, error)

func (*Node) String

func (n *Node) String() string

func (*Node) UnmarshalText

func (n *Node) UnmarshalText(text []byte) error

type NodeID

type NodeID [nodeIDBits / 8]byte

func HexID

func HexID(in string) (NodeID, error)

func MustHexID

func MustHexID(in string) NodeID

func PubkeyID

func PubkeyID(pub *ecdsa.PublicKey) NodeID

func (NodeID) GoString

func (n NodeID) GoString() string

func (NodeID) Pubkey

func (id NodeID) Pubkey() (*ecdsa.PublicKey, error)

func (NodeID) String

func (n NodeID) String() string

func (NodeID) TerminalString

func (n NodeID) TerminalString() string

type Table

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

type Topic

type Topic string

Jump to

Keyboard shortcuts

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