Skip to content

Commit fdff182

Browse files
fjlkaralabe
authored andcommitted
p2p/discv5: add deprecation warning and remove unused code (#20367)
* p2p/discv5: add deprecation warning and remove unused code * p2p/discv5: remove unused variables
1 parent 0abcf03 commit fdff182

12 files changed

Lines changed: 18 additions & 897 deletions

File tree

‎p2p/discv5/README‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This package is an early prototype of Discovery v5. Do not use this code.
2+
3+
See https://github.com/ethereum/devp2p/blob/master/discv5/discv5.md for the
4+
current Discovery v5 specification.

‎p2p/discv5/database.go‎

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,11 @@ var (
5858
nodeDBVersionKey = []byte("version") // Version of the database to flush if changes
5959
nodeDBItemPrefix = []byte("n:") // Identifier to prefix node entries with
6060

61-
nodeDBDiscoverRoot = ":discover"
62-
nodeDBDiscoverPing = nodeDBDiscoverRoot + ":lastping"
63-
nodeDBDiscoverPong = nodeDBDiscoverRoot + ":lastpong"
64-
nodeDBDiscoverFindFails = nodeDBDiscoverRoot + ":findfail"
65-
nodeDBDiscoverLocalEndpoint = nodeDBDiscoverRoot + ":localendpoint"
66-
nodeDBTopicRegTickets = ":tickets"
61+
nodeDBDiscoverRoot = ":discover"
62+
nodeDBDiscoverPing = nodeDBDiscoverRoot + ":lastping"
63+
nodeDBDiscoverPong = nodeDBDiscoverRoot + ":lastpong"
64+
nodeDBDiscoverFindFails = nodeDBDiscoverRoot + ":findfail"
65+
nodeDBTopicRegTickets = ":tickets"
6766
)
6867

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

314-
// localEndpoint returns the last local endpoint communicated to the
315-
// given remote node.
316-
func (db *nodeDB) localEndpoint(id NodeID) *rpcEndpoint {
317-
var ep rpcEndpoint
318-
if err := db.fetchRLP(makeKey(id, nodeDBDiscoverLocalEndpoint), &ep); err != nil {
319-
return nil
320-
}
321-
return &ep
322-
}
323-
324-
func (db *nodeDB) updateLocalEndpoint(id NodeID, ep rpcEndpoint) error {
325-
return db.storeRLP(makeKey(id, nodeDBDiscoverLocalEndpoint), &ep)
326-
}
327-
328313
// querySeeds retrieves random nodes to be used as potential seed nodes
329314
// for bootstrapping.
330315
func (db *nodeDB) querySeeds(n int, maxAge time.Duration) []*Node {

‎p2p/discv5/net.go‎

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,6 @@ type Network struct {
7777
nursery []*Node
7878
nodes map[NodeID]*Node // tracks active nodes with state != known
7979
timeoutTimers map[timeoutEvent]*time.Timer
80-
81-
// Revalidation queues.
82-
// Nodes put on these queues will be pinged eventually.
83-
slowRevalidateQueue []*Node
84-
fastRevalidateQueue []*Node
85-
86-
// Buffers for state transition.
87-
sendBuf []*ingressPacket
8880
}
8981

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

10698
type findnodeQuery struct {
107-
remote *Node
108-
target common.Hash
109-
reply chan<- []*Node
110-
nresults int // counter for received nodes
99+
remote *Node
100+
target common.Hash
101+
reply chan<- []*Node
111102
}
112103

113104
type topicRegisterReq struct {
@@ -650,10 +641,10 @@ loop:
650641
if net.conn != nil {
651642
net.conn.Close()
652643
}
653-
if refreshDone != nil {
654-
// TODO: wait for pending refresh.
655-
//<-refreshResults
656-
}
644+
// TODO: wait for pending refresh.
645+
// if refreshDone != nil {
646+
// <-refreshResults
647+
// }
657648
// Cancel all pending timeouts.
658649
for _, timer := range net.timeoutTimers {
659650
timer.Stop()

‎p2p/discv5/net_test.go‎

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package discv5
1818

1919
import (
20-
"fmt"
2120
"net"
2221
"testing"
2322
"time"
@@ -265,10 +264,6 @@ type preminedTestnet struct {
265264
net *Network
266265
}
267266

268-
func (tn *preminedTestnet) sendFindnode(to *Node, target NodeID) {
269-
panic("sendFindnode called")
270-
}
271-
272267
func (tn *preminedTestnet) sendFindnodeHash(to *Node, target common.Hash) {
273268
// current log distance is encoded in port number
274269
// fmt.Println("findnode query at dist", toaddr.Port)
@@ -316,10 +311,6 @@ func (tn *preminedTestnet) sendNeighbours(to *Node, nodes []*Node) {
316311
panic("sendNeighbours called")
317312
}
318313

319-
func (tn *preminedTestnet) sendTopicQuery(to *Node, topic Topic) {
320-
panic("sendTopicQuery called")
321-
}
322-
323314
func (tn *preminedTestnet) sendTopicNodes(to *Node, queryHash common.Hash, nodes []*Node) {
324315
panic("sendTopicNodes called")
325316
}
@@ -334,41 +325,6 @@ func (*preminedTestnet) localAddr() *net.UDPAddr {
334325
return &net.UDPAddr{IP: net.ParseIP("10.0.1.1"), Port: 40000}
335326
}
336327

337-
// mine generates a testnet struct literal with nodes at
338-
// various distances to the given target.
339-
func (tn *preminedTestnet) mine(target NodeID) {
340-
tn.target = target
341-
tn.targetSha = crypto.Keccak256Hash(tn.target[:])
342-
found := 0
343-
for found < bucketSize*10 {
344-
k := newkey()
345-
id := PubkeyID(&k.PublicKey)
346-
sha := crypto.Keccak256Hash(id[:])
347-
ld := logdist(tn.targetSha, sha)
348-
if len(tn.dists[ld]) < bucketSize {
349-
tn.dists[ld] = append(tn.dists[ld], id)
350-
fmt.Println("found ID with ld", ld)
351-
found++
352-
}
353-
}
354-
fmt.Println("&preminedTestnet{")
355-
fmt.Printf(" target: %#v,\n", tn.target)
356-
fmt.Printf(" targetSha: %#v,\n", tn.targetSha)
357-
fmt.Printf(" dists: [%d][]NodeID{\n", len(tn.dists))
358-
for ld, ns := range &tn.dists {
359-
if len(ns) == 0 {
360-
continue
361-
}
362-
fmt.Printf(" %d: []NodeID{\n", ld)
363-
for _, n := range ns {
364-
fmt.Printf(" MustHexID(\"%x\"),\n", n[:])
365-
}
366-
fmt.Println(" },")
367-
}
368-
fmt.Println(" },")
369-
fmt.Println("}")
370-
}
371-
372328
func injectResponse(net *Network, from *Node, ev nodeEvent, packet interface{}) {
373329
go net.reqReadPacket(ingressPacket{remoteID: from.ID, remoteAddr: from.addr(), ev: ev, data: packet})
374330
}

‎p2p/discv5/node.go‎

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,6 @@ func (n *Node) addr() *net.UDPAddr {
6666
return &net.UDPAddr{IP: n.IP, Port: int(n.UDP)}
6767
}
6868

69-
func (n *Node) setAddr(a *net.UDPAddr) {
70-
n.IP = a.IP
71-
if ipv4 := a.IP.To4(); ipv4 != nil {
72-
n.IP = ipv4
73-
}
74-
n.UDP = uint16(a.Port)
75-
}
76-
77-
// compares the given address against the stored values.
78-
func (n *Node) addrEqual(a *net.UDPAddr) bool {
79-
ip := a.IP
80-
if ipv4 := a.IP.To4(); ipv4 != nil {
81-
ip = ipv4
82-
}
83-
return n.UDP == uint16(a.Port) && n.IP.Equal(ip)
84-
}
85-
8669
// Incomplete returns true for nodes with no IP address.
8770
func (n *Node) Incomplete() bool {
8871
return n.IP == nil
@@ -326,14 +309,6 @@ func (n NodeID) Pubkey() (*ecdsa.PublicKey, error) {
326309
return p, nil
327310
}
328311

329-
func (id NodeID) mustPubkey() ecdsa.PublicKey {
330-
pk, err := id.Pubkey()
331-
if err != nil {
332-
panic(err)
333-
}
334-
return *pk
335-
}
336-
337312
// recoverNodeID computes the public key used to sign the
338313
// given hash from the signature.
339314
func recoverNodeID(hash, sig []byte) (id NodeID, err error) {

‎p2p/discv5/ntp.go‎

Lines changed: 0 additions & 126 deletions
This file was deleted.

‎p2p/discv5/sim_test.go‎

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -294,15 +294,6 @@ func (s *simulation) launchNode(log bool) *Network {
294294
return net
295295
}
296296

297-
func (s *simulation) dropNode(id NodeID) {
298-
s.mu.Lock()
299-
n := s.nodes[id]
300-
delete(s.nodes, id)
301-
s.mu.Unlock()
302-
303-
n.Close()
304-
}
305-
306297
type simTransport struct {
307298
joinTime time.Time
308299
sender NodeID
@@ -358,22 +349,6 @@ func (st *simTransport) sendPing(remote *Node, remoteAddr *net.UDPAddr, topics [
358349
return hash
359350
}
360351

361-
func (st *simTransport) sendPong(remote *Node, pingHash []byte) {
362-
raddr := remote.addr()
363-
364-
st.sendPacket(remote.ID, ingressPacket{
365-
remoteID: st.sender,
366-
remoteAddr: st.senderAddr,
367-
hash: st.nextHash(),
368-
ev: pongPacket,
369-
data: &pong{
370-
To: rpcEndpoint{IP: raddr.IP, UDP: uint16(raddr.Port), TCP: 30303},
371-
ReplyTok: pingHash,
372-
Expiration: uint64(time.Now().Unix() + int64(expiration)),
373-
},
374-
})
375-
}
376-
377352
func (st *simTransport) sendFindnodeHash(remote *Node, target common.Hash) {
378353
st.sendPacket(remote.ID, ingressPacket{
379354
remoteID: st.sender,

‎p2p/discv5/table.go‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,8 @@
1414
// You should have received a copy of the GNU Lesser General Public License
1515
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
1616

17-
// Package discv5 implements the RLPx v5 Topic Discovery Protocol.
18-
//
19-
// The Topic Discovery protocol provides a way to find RLPx nodes that
20-
// can be connected to. It uses a Kademlia-like protocol to maintain a
21-
// distributed database of the IDs and endpoints of all listening
22-
// nodes.
17+
// Package discv5 is a prototype implementation of Discvery v5.
18+
// Deprecated: do not use this package.
2319
package discv5
2420

2521
import (

0 commit comments

Comments
 (0)