Documentation ¶
Index ¶
- func Factory(ctx context.Context, conf *discovery.BackendConfig) (discovery.Backend, error)
- type Backend
- func (b *Backend) AddNode(nodeStr string) error
- func (b *Backend) Close() error
- func (b *Backend) Deliver() chan string
- func (b *Backend) GetPeers() []*Peer
- func (b *Backend) HandlePacket(packet *Packet) error
- func (b *Backend) Lookup() ([]*Peer, error)
- func (b *Backend) LookupRandom() ([]*Peer, error)
- func (b *Backend) LookupTarget(target []byte) ([]*Peer, error)
- func (b *Backend) NearestPeers() ([]*Peer, error)
- func (b *Backend) NearestPeersFromTarget(target []byte) ([]*Peer, error)
- func (b *Backend) Schedule()
- func (b *Backend) SetBootnodes(bootnodes []string)
- type MockNetwork
- type MockTransport
- type Packet
- type Peer
- type Transport
- type UDPTransport
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 ¶
AddNode adds a new node to the discover process (NOTE: its a sync process) TODO. split in nodeStrToPeer and probe
func (*Backend) HandlePacket ¶
HandlePacket handles an incoming udp packet
func (*Backend) LookupRandom ¶
LookupRandom performs a lookup in a random target TODO, remove peers from lookup response, nobody uses it
func (*Backend) LookupTarget ¶
LookupTarget does a kademlia lookup around target
func (*Backend) NearestPeers ¶
func (*Backend) NearestPeersFromTarget ¶
func (*Backend) SetBootnodes ¶
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
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
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