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 ¶
- func SetLogger(logger *logrus.Logger)
- type Config
- type EncPubkey
- type Findnode
- type Neighbors
- type Ping
- type Pong
- type ReadPacket
- type RpcEndpoint
- func (z *RpcEndpoint) DecodeMsg(dc *msgp.Reader) (err error)
- func (z *RpcEndpoint) EncodeMsg(en *msgp.Writer) (err error)
- func (r RpcEndpoint) Equal(r1 RpcEndpoint) bool
- func (z *RpcEndpoint) MarshalMsg(b []byte) (o []byte, err error)
- func (z *RpcEndpoint) Msgsize() (s int)
- func (z *RpcEndpoint) UnmarshalMsg(bts []byte) (o []byte, err error)
- type RpcNode
- type Table
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type EncPubkey ¶
type EncPubkey [64]byte
func (*EncPubkey) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
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) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type Neighbors ¶
type Neighbors struct { Nodes []RpcNode Expiration uint64 // Ignore additional fields (for forward compatibility). Rest [][]byte `rlp:"tail"` }
reply to findnode
func (*Neighbors) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type Ping ¶
type Ping struct { Version uint From, To RpcEndpoint Expiration uint64 // Ignore additional fields (for forward compatibility). Rest [][]byte `rlp:"tail"` }
func (*Ping) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
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) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type ReadPacket ¶
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) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
func (*Table) Close ¶
func (tab *Table) Close()
Close terminates the network listener and flushes the node database.
func (*Table) LookupRandom ¶
LookupRandom finds random nodes in the network.
func (*Table) ReadRandomNodes ¶
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.