Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
p2p/discv5: add deprecation warning and remove unused code (ethereum#…
Browse files Browse the repository at this point in the history
…20367)

* p2p/discv5: add deprecation warning and remove unused code

* p2p/discv5: remove unused variables
  • Loading branch information
fjl authored and elizabethengelman committed Dec 30, 2019
1 parent 30af43f commit 31cec2a
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 897 deletions.
4 changes: 4 additions & 0 deletions p2p/discv5/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This package is an early prototype of Discovery v5. Do not use this code.

See https://github.com/ethereum/devp2p/blob/master/discv5/discv5.md for the
current Discovery v5 specification.
25 changes: 5 additions & 20 deletions p2p/discv5/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,11 @@ var (
nodeDBVersionKey = []byte("version") // Version of the database to flush if changes
nodeDBItemPrefix = []byte("n:") // Identifier to prefix node entries with

nodeDBDiscoverRoot = ":discover"
nodeDBDiscoverPing = nodeDBDiscoverRoot + ":lastping"
nodeDBDiscoverPong = nodeDBDiscoverRoot + ":lastpong"
nodeDBDiscoverFindFails = nodeDBDiscoverRoot + ":findfail"
nodeDBDiscoverLocalEndpoint = nodeDBDiscoverRoot + ":localendpoint"
nodeDBTopicRegTickets = ":tickets"
nodeDBDiscoverRoot = ":discover"
nodeDBDiscoverPing = nodeDBDiscoverRoot + ":lastping"
nodeDBDiscoverPong = nodeDBDiscoverRoot + ":lastpong"
nodeDBDiscoverFindFails = nodeDBDiscoverRoot + ":findfail"
nodeDBTopicRegTickets = ":tickets"
)

// newNodeDB creates a new node database for storing and retrieving infos about
Expand Down Expand Up @@ -311,20 +310,6 @@ func (db *nodeDB) updateFindFails(id NodeID, fails int) error {
return db.storeInt64(makeKey(id, nodeDBDiscoverFindFails), int64(fails))
}

// localEndpoint returns the last local endpoint communicated to the
// given remote node.
func (db *nodeDB) localEndpoint(id NodeID) *rpcEndpoint {
var ep rpcEndpoint
if err := db.fetchRLP(makeKey(id, nodeDBDiscoverLocalEndpoint), &ep); err != nil {
return nil
}
return &ep
}

func (db *nodeDB) updateLocalEndpoint(id NodeID, ep rpcEndpoint) error {
return db.storeRLP(makeKey(id, nodeDBDiscoverLocalEndpoint), &ep)
}

// querySeeds retrieves random nodes to be used as potential seed nodes
// for bootstrapping.
func (db *nodeDB) querySeeds(n int, maxAge time.Duration) []*Node {
Expand Down
23 changes: 7 additions & 16 deletions p2p/discv5/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,6 @@ type Network struct {
nursery []*Node
nodes map[NodeID]*Node // tracks active nodes with state != known
timeoutTimers map[timeoutEvent]*time.Timer

// Revalidation queues.
// Nodes put on these queues will be pinged eventually.
slowRevalidateQueue []*Node
fastRevalidateQueue []*Node

// Buffers for state transition.
sendBuf []*ingressPacket
}

// transport is implemented by the UDP transport.
Expand All @@ -104,10 +96,9 @@ type transport interface {
}

type findnodeQuery struct {
remote *Node
target common.Hash
reply chan<- []*Node
nresults int // counter for received nodes
remote *Node
target common.Hash
reply chan<- []*Node
}

type topicRegisterReq struct {
Expand Down Expand Up @@ -650,10 +641,10 @@ loop:
if net.conn != nil {
net.conn.Close()
}
if refreshDone != nil {
// TODO: wait for pending refresh.
//<-refreshResults
}
// TODO: wait for pending refresh.
// if refreshDone != nil {
// <-refreshResults
// }
// Cancel all pending timeouts.
for _, timer := range net.timeoutTimers {
timer.Stop()
Expand Down
44 changes: 0 additions & 44 deletions p2p/discv5/net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package discv5

import (
"fmt"
"net"
"testing"
"time"
Expand Down Expand Up @@ -265,10 +264,6 @@ type preminedTestnet struct {
net *Network
}

func (tn *preminedTestnet) sendFindnode(to *Node, target NodeID) {
panic("sendFindnode called")
}

func (tn *preminedTestnet) sendFindnodeHash(to *Node, target common.Hash) {
// current log distance is encoded in port number
// fmt.Println("findnode query at dist", toaddr.Port)
Expand Down Expand Up @@ -316,10 +311,6 @@ func (tn *preminedTestnet) sendNeighbours(to *Node, nodes []*Node) {
panic("sendNeighbours called")
}

func (tn *preminedTestnet) sendTopicQuery(to *Node, topic Topic) {
panic("sendTopicQuery called")
}

func (tn *preminedTestnet) sendTopicNodes(to *Node, queryHash common.Hash, nodes []*Node) {
panic("sendTopicNodes called")
}
Expand All @@ -334,41 +325,6 @@ func (*preminedTestnet) localAddr() *net.UDPAddr {
return &net.UDPAddr{IP: net.ParseIP("10.0.1.1"), Port: 40000}
}

// mine generates a testnet struct literal with nodes at
// various distances to the given target.
func (tn *preminedTestnet) mine(target NodeID) {
tn.target = target
tn.targetSha = crypto.Keccak256Hash(tn.target[:])
found := 0
for found < bucketSize*10 {
k := newkey()
id := PubkeyID(&k.PublicKey)
sha := crypto.Keccak256Hash(id[:])
ld := logdist(tn.targetSha, sha)
if len(tn.dists[ld]) < bucketSize {
tn.dists[ld] = append(tn.dists[ld], id)
fmt.Println("found ID with ld", ld)
found++
}
}
fmt.Println("&preminedTestnet{")
fmt.Printf(" target: %#v,\n", tn.target)
fmt.Printf(" targetSha: %#v,\n", tn.targetSha)
fmt.Printf(" dists: [%d][]NodeID{\n", len(tn.dists))
for ld, ns := range &tn.dists {
if len(ns) == 0 {
continue
}
fmt.Printf(" %d: []NodeID{\n", ld)
for _, n := range ns {
fmt.Printf(" MustHexID(\"%x\"),\n", n[:])
}
fmt.Println(" },")
}
fmt.Println(" },")
fmt.Println("}")
}

func injectResponse(net *Network, from *Node, ev nodeEvent, packet interface{}) {
go net.reqReadPacket(ingressPacket{remoteID: from.ID, remoteAddr: from.addr(), ev: ev, data: packet})
}
25 changes: 0 additions & 25 deletions p2p/discv5/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,6 @@ func (n *Node) addr() *net.UDPAddr {
return &net.UDPAddr{IP: n.IP, Port: int(n.UDP)}
}

func (n *Node) setAddr(a *net.UDPAddr) {
n.IP = a.IP
if ipv4 := a.IP.To4(); ipv4 != nil {
n.IP = ipv4
}
n.UDP = uint16(a.Port)
}

// compares the given address against the stored values.
func (n *Node) addrEqual(a *net.UDPAddr) bool {
ip := a.IP
if ipv4 := a.IP.To4(); ipv4 != nil {
ip = ipv4
}
return n.UDP == uint16(a.Port) && n.IP.Equal(ip)
}

// Incomplete returns true for nodes with no IP address.
func (n *Node) Incomplete() bool {
return n.IP == nil
Expand Down Expand Up @@ -326,14 +309,6 @@ func (n NodeID) Pubkey() (*ecdsa.PublicKey, error) {
return p, nil
}

func (id NodeID) mustPubkey() ecdsa.PublicKey {
pk, err := id.Pubkey()
if err != nil {
panic(err)
}
return *pk
}

// recoverNodeID computes the public key used to sign the
// given hash from the signature.
func recoverNodeID(hash, sig []byte) (id NodeID, err error) {
Expand Down
126 changes: 0 additions & 126 deletions p2p/discv5/ntp.go

This file was deleted.

25 changes: 0 additions & 25 deletions p2p/discv5/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,6 @@ func (s *simulation) launchNode(log bool) *Network {
return net
}

func (s *simulation) dropNode(id NodeID) {
s.mu.Lock()
n := s.nodes[id]
delete(s.nodes, id)
s.mu.Unlock()

n.Close()
}

type simTransport struct {
joinTime time.Time
sender NodeID
Expand Down Expand Up @@ -358,22 +349,6 @@ func (st *simTransport) sendPing(remote *Node, remoteAddr *net.UDPAddr, topics [
return hash
}

func (st *simTransport) sendPong(remote *Node, pingHash []byte) {
raddr := remote.addr()

st.sendPacket(remote.ID, ingressPacket{
remoteID: st.sender,
remoteAddr: st.senderAddr,
hash: st.nextHash(),
ev: pongPacket,
data: &pong{
To: rpcEndpoint{IP: raddr.IP, UDP: uint16(raddr.Port), TCP: 30303},
ReplyTok: pingHash,
Expiration: uint64(time.Now().Unix() + int64(expiration)),
},
})
}

func (st *simTransport) sendFindnodeHash(remote *Node, target common.Hash) {
st.sendPacket(remote.ID, ingressPacket{
remoteID: st.sender,
Expand Down
8 changes: 2 additions & 6 deletions p2p/discv5/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@
// 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 discv5 implements the RLPx v5 Topic Discovery Protocol.
//
// The Topic 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.
// Package discv5 is a prototype implementation of Discvery v5.
// Deprecated: do not use this package.
package discv5

import (
Expand Down
Loading

0 comments on commit 31cec2a

Please sign in to comment.