discover

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const Version = 4

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node struct {
	IP       net.IP
	TCP, UDP uint16
	ID       NodeId
	Hash     common.Hash
}

func NewNode

func NewNode(ip net.IP, tcpPort, udpPort uint16, id NodeId) *Node

func ParseNode

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

func (*Node) String

func (n *Node) String() string

func (*Node) TcpAddr

func (n *Node) TcpAddr() *net.TCPAddr

func (*Node) UdpAddr

func (n *Node) UdpAddr() *net.UDPAddr

type NodeId

type NodeId [nodeIdLen]byte

func Hex2NodeId

func Hex2NodeId(s string) (NodeId, error)

func MustHex2NodeId

func MustHex2NodeId(in string) NodeId

func PubKey2NodeId

func PubKey2NodeId(pub ecdsa.PublicKey) NodeId

func (NodeId) String

func (id NodeId) String() string

type Table

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

func ListenUDP

func ListenUDP(priv *ecdsa.PrivateKey, laddr string, nodeDBPath string, mapper nat.Mapper) (*Table, error)

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

func NewUDP

func NewUDP(priv *ecdsa.PrivateKey, c conn, nodeDBPath string, mapper nat.Mapper) (*Table, *udp)

func (*Table) Bootstrap

func (tab *Table) Bootstrap(nodes []*Node)

Bootstrap sets the bootstrap nodes. These nodes are used to connect to the network if the table is empty. Bootstrap will also attempt to fill the table by performing random lookup operations on the network.

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