discover

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2020 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2015 The go-ethereum Authors This file is part of the go-ethereum library.

The go-ethereum library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

The go-ethereum library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

Package discover implements the node Discovery Protocol.

The node 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.

Copyright 2015 The go-ethereum Authors This file is part of the go-ethereum library.

The go-ethereum library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

The go-ethereum library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLogger

func SetLogger(logger *logrus.Logger)

Types

type Config

type Config struct {
	// These settings are required and configure the UDP listener:
	PrivateKey *ecdsa.PrivateKey `msg:"-"`

	// These settings are optional:
	NetRestrict *netutil.Netlist  `msg:"-"` // network whitelist
	Bootnodes   []*onode.Node     `msg:"-"` // list of bootstrap nodes
	Unhandled   chan<- ReadPacket `msg:"-"` // unhandled packets are sent on this channel
}

Config holds Table-related settings.

func (*Config) DecodeMsg

func (z *Config) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (Config) EncodeMsg

func (z Config) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (Config) MarshalMsg

func (z Config) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (Config) Msgsize

func (z Config) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Config) UnmarshalMsg

func (z *Config) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type EncPubkey

type EncPubkey [64]byte

func (*EncPubkey) DecodeMsg

func (z *EncPubkey) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*EncPubkey) EncodeMsg

func (z *EncPubkey) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*EncPubkey) MarshalMsg

func (z *EncPubkey) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*EncPubkey) Msgsize

func (z *EncPubkey) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*EncPubkey) UnmarshalMsg

func (z *EncPubkey) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Findnode

type Findnode struct {
	//Target     NodeID // doesn't need to be an actual public key
	Target     EncPubkey
	Expiration uint64
	// Ignore additional fields (for forward compatibility).
	Rest [][]byte `rlp:"tail"`
}

findnode is a query for nodes close to the given target.

func (*Findnode) DecodeMsg

func (z *Findnode) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Findnode) EncodeMsg

func (z *Findnode) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Findnode) MarshalMsg

func (z *Findnode) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*Findnode) Msgsize

func (z *Findnode) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Findnode) UnmarshalMsg

func (z *Findnode) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Neighbors

type Neighbors struct {
	Nodes      []RpcNode
	Expiration uint64
	// Ignore additional fields (for forward compatibility).
	Rest [][]byte `rlp:"tail"`
}

reply to findnode

func (*Neighbors) DecodeMsg

func (z *Neighbors) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Neighbors) EncodeMsg

func (z *Neighbors) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Neighbors) MarshalMsg

func (z *Neighbors) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*Neighbors) Msgsize

func (z *Neighbors) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Neighbors) UnmarshalMsg

func (z *Neighbors) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Ping

type Ping struct {
	Version    uint
	From, To   RpcEndpoint
	Expiration uint64
	// Ignore additional fields (for forward compatibility).
	Rest [][]byte `rlp:"tail"`
}

func (*Ping) DecodeMsg

func (z *Ping) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Ping) EncodeMsg

func (z *Ping) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Ping) MarshalMsg

func (z *Ping) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*Ping) Msgsize

func (z *Ping) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Ping) UnmarshalMsg

func (z *Ping) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Pong

type Pong struct {
	// This field should mirror the UDP envelope address
	// of the ping packet, which provides a way to discover the
	// the external address (after NAT).
	To RpcEndpoint

	ReplyTok   []byte // This contains the hash of the ping packet.
	Expiration uint64 // Absolute timestamp at which the packet becomes invalid.
	// Ignore additional fields (for forward compatibility).
	Rest [][]byte `rlp:"tail"`
}

pong is the reply to ping.

func (*Pong) DecodeMsg

func (z *Pong) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Pong) EncodeMsg

func (z *Pong) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Pong) MarshalMsg

func (z *Pong) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*Pong) Msgsize

func (z *Pong) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Pong) UnmarshalMsg

func (z *Pong) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type ReadPacket

type ReadPacket struct {
	Data []byte       `msg:"-"`
	Addr *net.UDPAddr `msg:"-"`
}

ReadPacket is sent to the unhandled channel when it could not be processed

func (*ReadPacket) DecodeMsg

func (z *ReadPacket) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (ReadPacket) EncodeMsg

func (z ReadPacket) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (ReadPacket) MarshalMsg

func (z ReadPacket) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (ReadPacket) Msgsize

func (z ReadPacket) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*ReadPacket) UnmarshalMsg

func (z *ReadPacket) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type RpcEndpoint

type RpcEndpoint struct {
	//IP  net.IP // len 4 for IPv4 or 16 for IPv6
	IP  []byte
	UDP uint16 // for discovery protocol
	TCP uint16 // for RLPx protocol
}

func (*RpcEndpoint) DecodeMsg

func (z *RpcEndpoint) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*RpcEndpoint) EncodeMsg

func (z *RpcEndpoint) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (RpcEndpoint) Equal

func (r RpcEndpoint) Equal(r1 RpcEndpoint) bool

func (*RpcEndpoint) MarshalMsg

func (z *RpcEndpoint) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*RpcEndpoint) Msgsize

func (z *RpcEndpoint) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*RpcEndpoint) UnmarshalMsg

func (z *RpcEndpoint) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type RpcNode

type RpcNode struct {
	//IP  net.IP // len 4 for IPv4 or 16 for IPv6
	IP  []byte
	UDP uint16 // for discovery protocol
	TCP uint16 // for RLPx protocol
	ID  EncPubkey
}

func (*RpcNode) DecodeMsg

func (z *RpcNode) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*RpcNode) EncodeMsg

func (z *RpcNode) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*RpcNode) MarshalMsg

func (z *RpcNode) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*RpcNode) Msgsize

func (z *RpcNode) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*RpcNode) UnmarshalMsg

func (z *RpcNode) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Table

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

func ListenUDP

func ListenUDP(c conn, ln *onode.LocalNode, cfg Config) (*Table, error)

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

func (*Table) Close

func (tab *Table) Close()

Close terminates the network listener and flushes the node database.

func (*Table) LookupRandom

func (tab *Table) LookupRandom() []*onode.Node

LookupRandom finds random nodes in the network.

func (*Table) ReadRandomNodes

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

ReadRandomNodes fills the given slice with random nodes from the table. The results are guaranteed to be unique for a single invocation, no node will appear twice.

func (*Table) Resolve

func (tab *Table) Resolve(n *onode.Node) *onode.Node

Resolve searches for a specific node with the given ID. It returns nil if the node could not be found.

Jump to

Keyboard shortcuts

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