discv4

package
v0.0.0-...-8f649d9 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2020 License: LGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

Types

type Backend

type Backend struct {
	ID *ecdsa.PrivateKey
	// contains filtered or unexported fields
}

Backend is the p2p discover backend

func NewBackend

func NewBackend(logger hclog.Logger, key *ecdsa.PrivateKey, transport Transport) (*Backend, error)

NewBackend creates a new p2p discovery protocol

func (*Backend) AddNode

func (b *Backend) AddNode(nodeStr string) error

AddNode adds a new node to the discover process (NOTE: its a sync process) TODO. split in nodeStrToPeer and probe

func (*Backend) Close

func (b *Backend) Close() error

Close closes the discover

func (*Backend) Deliver

func (b *Backend) Deliver() chan string

func (*Backend) GetPeers

func (b *Backend) GetPeers() []*Peer

GetPeers return the peers

func (*Backend) HandlePacket

func (b *Backend) HandlePacket(packet *Packet) error

HandlePacket handles an incoming udp packet

func (*Backend) Lookup

func (b *Backend) Lookup() ([]*Peer, error)

Lookup does a kademlia lookup with the local key as target

func (*Backend) LookupRandom

func (b *Backend) LookupRandom() ([]*Peer, error)

LookupRandom performs a lookup in a random target TODO, remove peers from lookup response, nobody uses it

func (*Backend) LookupTarget

func (b *Backend) LookupTarget(target []byte) ([]*Peer, error)

LookupTarget does a kademlia lookup around target

func (*Backend) NearestPeers

func (b *Backend) NearestPeers() ([]*Peer, error)

func (*Backend) NearestPeersFromTarget

func (b *Backend) NearestPeersFromTarget(target []byte) ([]*Peer, error)

func (*Backend) Schedule

func (b *Backend) Schedule()

Schedule starts the discovery protocol

func (*Backend) SetBootnodes

func (b *Backend) SetBootnodes(bootnodes []string)

SetBootnodes sets the bootnodes

type MockNetwork

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

MockNetwork mocks a network of peers

func (*MockNetwork) NewTransport

func (m *MockNetwork) NewTransport() Transport

NewTransport creates a new mockup transport

type MockTransport

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

MockTransport mocks a udp transport

func (*MockTransport) Addr

func (m *MockTransport) Addr() *net.UDPAddr

Addr implements the transport interface

func (*MockTransport) PacketCh

func (m *MockTransport) PacketCh() chan *Packet

PacketCh implements the transport interface

func (*MockTransport) Shutdown

func (m *MockTransport) Shutdown()

Shutdown implements the transport interface

func (*MockTransport) WriteTo

func (m *MockTransport) WriteTo(b []byte, addr string) (time.Time, error)

WriteTo implements the transport interface

type Packet

type Packet struct {
	Buf       []byte
	From      net.Addr
	Timestamp time.Time
}

Packet is used to provide some metadata about incoming UDP packets from peers

type Peer

type Peer struct {
	ID      string
	Bytes   []byte
	UDPAddr *net.UDPAddr
	Last    *time.Time // last time pinged
	TCP     uint16
}

Peer is the discovery peer

func (*Peer) Enode

func (p *Peer) Enode() string

Enode returns an enode address

type Transport

type Transport interface {
	// Addr returns the bind address of the transport
	Addr() *net.UDPAddr

	// PacketCh returns a channel to receive incomming packets
	PacketCh() chan *Packet

	// WriteTo writes the payload to the given address
	WriteTo(b []byte, addr string) (time.Time, error)

	// Shutdown closes the listener
	Shutdown()
}

Transport is the transport used by discv4

type UDPTransport

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

UDPTransport implements the UDP Transport

func (*UDPTransport) Addr

func (u *UDPTransport) Addr() *net.UDPAddr

Addr implements the transport interface

func (*UDPTransport) PacketCh

func (u *UDPTransport) PacketCh() chan *Packet

PacketCh implements the transport interface

func (*UDPTransport) Shutdown

func (u *UDPTransport) Shutdown()

Shutdown implements the transport interface

func (*UDPTransport) WriteTo

func (u *UDPTransport) WriteTo(b []byte, addr string) (time.Time, error)

WriteTo implements the transport interface

Jump to

Keyboard shortcuts

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