Rust 实现 Discovery v5
This is a rust implementation of the Discovery v5 peer discovery protocol.
Discovery v5 is a protocol designed for encrypted peer discovery. Each peer/node on the network is
identified via it's ENR (Ethereum Node Record), which
is essentially a signed key-value store containing the node's public key and optionally IP address
and port.
Discv5 employs a kademlia-like routing table to store and manage discovered peers and topics. The protocol allows for external IP discovery in NAT environments through regular PING/PONG's with discovered nodes. Nodes return the external IP address that they have received and a simple majority is chosen as our external IP address. If an external IP address is updated, this is produced as an event to notify the swarm (if one is used for this behaviour).
For a simple CLI discovery service see discv5-cli
A simple example of creating this service is as follows:
…An ENR is a signed record which is primarily used in this protocol for
identifying and connecting to peers. ENRs have OPTIONAL ip and port
fields.
If a node does not know its contactable address (i.e if it is behind a NAT), it should leave these fields empty. This is done for the following reasons:
127.0.0.1 when connecting to
non-local nodes) we cannot use this ENR
to contact the node and we therefore do not wish to advertise it to other
nodes. Putting a non-contactable address is therefore functionally
equivalent to leaving the fields empty.ENR is contactable. We do not want the scenario, where
any peer can give us any address and force us to attempt a connection to
arbitrary addresses (to check their validity) as it consumes unnecessary
bandwidth and we want to avoid DOS attacks where malicious users spam many
nodes attempting them all to send messages to a victim IP.To handle the above two cases this protocol filters out and only advertises contactable ENRs. It doesn't make sense for a discovery protocol to advertise non-contactable peers.
This is done in the following way:
127.0.0.1, or
potentially some internal subnet IP that is unreachable from our current
network) we consider this ENR invalid and will not add it to our routing
table. However we will still respond to discovery requests.暂无开放 Issues,或尚未同步最近议题。