Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
15 changes: 7 additions & 8 deletions p2p/discv5/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,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 @@ -642,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
36 changes: 0 additions & 36 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 @@ -326,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 (n NodeID) mustPubkey() ecdsa.PublicKey {
pk, err := n.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.

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 Discovery v5.
// Deprecated: do not use this package.
package discv5

import (
Expand Down
75 changes: 0 additions & 75 deletions p2p/discv5/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,70 +31,6 @@ import (
"github.com/XinFinOrg/XDPoSChain/crypto"
)

type nullTransport struct{}

func (nullTransport) sendPing(remote *Node, remoteAddr *net.UDPAddr) []byte { return []byte{1} }
func (nullTransport) sendNeighbours(remote *Node, nodes []*Node) {}
func (nullTransport) localAddr() *net.UDPAddr { return new(net.UDPAddr) }
func (nullTransport) Close() {}

// func TestTable_pingReplace(t *testing.T) {
// doit := func(newNodeIsResponding, lastInBucketIsResponding bool) {
// transport := newPingRecorder()
// tab, _ := newTable(transport, NodeID{}, &net.UDPAddr{})
// defer tab.Close()
// pingSender := NewNode(MustHexID("a502af0f59b2aab7746995408c79e9ca312d2793cc997e44fc55eda62f0150bbb8c59a6f9269ba3a081518b62699ee807c7c19c20125ddfccca872608af9e370"), net.IP{}, 99, 99)
//
// // fill up the sender's bucket.
// last := fillBucket(tab, 253)
//
// // this call to bond should replace the last node
// // in its bucket if the node is not responding.
// transport.responding[last.ID] = lastInBucketIsResponding
// transport.responding[pingSender.ID] = newNodeIsResponding
// tab.bond(true, pingSender.ID, &net.UDPAddr{}, 0)
//
// // first ping goes to sender (bonding pingback)
// if !transport.pinged[pingSender.ID] {
// t.Error("table did not ping back sender")
// }
// if newNodeIsResponding {
// // second ping goes to oldest node in bucket
// // to see whether it is still alive.
// if !transport.pinged[last.ID] {
// t.Error("table did not ping last node in bucket")
// }
// }
//
// tab.mutex.Lock()
// defer tab.mutex.Unlock()
// if l := len(tab.buckets[253].entries); l != bucketSize {
// t.Errorf("wrong bucket size after bond: got %d, want %d", l, bucketSize)
// }
//
// if lastInBucketIsResponding || !newNodeIsResponding {
// if !contains(tab.buckets[253].entries, last.ID) {
// t.Error("last entry was removed")
// }
// if contains(tab.buckets[253].entries, pingSender.ID) {
// t.Error("new entry was added")
// }
// } else {
// if contains(tab.buckets[253].entries, last.ID) {
// t.Error("last entry was not removed")
// }
// if !contains(tab.buckets[253].entries, pingSender.ID) {
// t.Error("new entry was not added")
// }
// }
// }
//
// doit(true, true)
// doit(false, true)
// doit(true, false)
// doit(false, false)
// }

func TestBucket_bumpNoDuplicates(t *testing.T) {
t.Parallel()
cfg := &quick.Config{
Expand Down Expand Up @@ -137,17 +73,6 @@ func TestBucket_bumpNoDuplicates(t *testing.T) {
}
}

// fillBucket inserts nodes into the given bucket until
// it is full. The node's IDs dont correspond to their
// hashes.
func fillBucket(tab *Table, ld int) (last *Node) {
b := tab.buckets[ld]
for len(b.entries) < bucketSize {
b.entries = append(b.entries, nodeAtDistance(tab.self.sha, ld))
}
return b.entries[bucketSize-1]
}

// nodeAtDistance creates a node for which logdist(base, n.sha) == ld.
// The node's ID does not correspond to n.sha.
func nodeAtDistance(base common.Hash, ld int) (n *Node) {
Expand Down
Loading
Loading