discover

package
v0.0.0-...-5d85a61 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2023 License: GPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const NodeIDBits = 512
View Source
const Version = 4

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	PrivateKey *ecdsa.PrivateKey

	AnnounceAddr *net.UDPAddr
	NodeDBPath   string
	NetRestrict  *netutil.Netlist
	Bootnodes    []*Node
	Unhandled    chan<- ReadPacket
}

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 BytesID

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

func HexID

func HexID(in string) (NodeID, error)

func MustBytesID

func MustBytesID(b []byte) NodeID

func MustHexID

func MustHexID(in string) NodeID

func PubkeyID

func PubkeyID(pub *ecdsa.PublicKey) NodeID

func (NodeID) Bytes

func (n NodeID) Bytes() []byte

func (NodeID) GoString

func (n NodeID) GoString() string

func (NodeID) MarshalText

func (n NodeID) MarshalText() ([]byte, error)

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

func (*NodeID) UnmarshalText

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

type ReadPacket

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

type Table

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

func ListenUDP

func ListenUDP(c conn, cfg Config) (*Table, error)

func (*Table) Close

func (tab *Table) Close()

func (*Table) Lookup

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

func (*Table) ReadRandomNodes

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

func (*Table) Resolve

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

func (*Table) Self

func (tab *Table) Self() *Node

Jump to

Keyboard shortcuts

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