2015-07-06 19:54:22 -05:00
|
|
|
// Copyright 2015 The go-ethereum Authors
|
2015-07-22 11:48:40 -05:00
|
|
|
// This file is part of the go-ethereum library.
|
2015-07-06 19:54:22 -05:00
|
|
|
//
|
2015-07-23 11:35:11 -05:00
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
2015-07-06 19:54:22 -05:00
|
|
|
// 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.
|
|
|
|
//
|
2015-07-22 11:48:40 -05:00
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
2015-07-06 19:54:22 -05:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-07-22 11:48:40 -05:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2015-07-06 19:54:22 -05:00
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
2015-07-22 11:48:40 -05:00
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
2015-07-06 19:54:22 -05:00
|
|
|
|
2015-01-27 07:33:26 -06:00
|
|
|
package discover
|
|
|
|
|
|
|
|
import (
|
2015-03-25 10:45:53 -05:00
|
|
|
"bytes"
|
|
|
|
"crypto/ecdsa"
|
2019-01-29 10:39:20 -06:00
|
|
|
crand "crypto/rand"
|
2015-08-07 19:49:28 -05:00
|
|
|
"encoding/binary"
|
2015-12-22 18:52:40 -06:00
|
|
|
"encoding/hex"
|
2015-03-25 10:45:53 -05:00
|
|
|
"errors"
|
|
|
|
"io"
|
2015-08-07 19:49:28 -05:00
|
|
|
"math/rand"
|
2015-01-27 07:33:26 -06:00
|
|
|
"net"
|
2015-03-25 10:45:53 -05:00
|
|
|
"reflect"
|
|
|
|
"sync"
|
2015-01-27 07:33:26 -06:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2016-01-22 09:08:23 -06:00
|
|
|
"github.com/davecgh/go-spew/spew"
|
2015-12-22 18:52:40 -06:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2015-04-26 17:50:18 -05:00
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
2019-04-30 06:13:22 -05:00
|
|
|
"github.com/ethereum/go-ethereum/internal/testlog"
|
|
|
|
"github.com/ethereum/go-ethereum/log"
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
2019-05-14 23:47:45 -05:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/enr"
|
2015-12-22 18:52:40 -06:00
|
|
|
"github.com/ethereum/go-ethereum/rlp"
|
2015-01-27 07:33:26 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2016-01-22 09:08:23 -06:00
|
|
|
spew.Config.DisableMethods = true
|
|
|
|
}
|
|
|
|
|
2015-04-17 18:50:31 -05:00
|
|
|
// shared test variables
|
|
|
|
var (
|
|
|
|
futureExp = uint64(time.Now().Add(10 * time.Hour).Unix())
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
testTarget = encPubkey{0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1}
|
2015-04-17 18:50:31 -05:00
|
|
|
testRemote = rpcEndpoint{IP: net.ParseIP("1.1.1.1").To4(), UDP: 1, TCP: 2}
|
|
|
|
testLocalAnnounced = rpcEndpoint{IP: net.ParseIP("2.2.2.2").To4(), UDP: 3, TCP: 4}
|
|
|
|
testLocal = rpcEndpoint{IP: net.ParseIP("3.3.3.3").To4(), UDP: 5, TCP: 6}
|
|
|
|
)
|
|
|
|
|
2015-03-25 10:45:53 -05:00
|
|
|
type udpTest struct {
|
|
|
|
t *testing.T
|
|
|
|
pipe *dgramPipe
|
|
|
|
table *Table
|
2019-01-29 10:39:20 -06:00
|
|
|
db *enode.DB
|
2019-04-30 06:13:22 -05:00
|
|
|
udp *UDPv4
|
2015-03-25 10:45:53 -05:00
|
|
|
sent [][]byte
|
|
|
|
localkey, remotekey *ecdsa.PrivateKey
|
|
|
|
remoteaddr *net.UDPAddr
|
|
|
|
}
|
2015-01-27 07:33:26 -06:00
|
|
|
|
2015-03-25 10:45:53 -05:00
|
|
|
func newUDPTest(t *testing.T) *udpTest {
|
|
|
|
test := &udpTest{
|
|
|
|
t: t,
|
|
|
|
pipe: newpipe(),
|
|
|
|
localkey: newkey(),
|
|
|
|
remotekey: newkey(),
|
2016-11-21 11:11:54 -06:00
|
|
|
remoteaddr: &net.UDPAddr{IP: net.IP{10, 0, 1, 99}, Port: 30303},
|
2015-01-27 07:33:26 -06:00
|
|
|
}
|
2019-04-30 06:13:22 -05:00
|
|
|
|
2019-01-29 10:39:20 -06:00
|
|
|
test.db, _ = enode.OpenDB("")
|
|
|
|
ln := enode.NewLocalNode(test.db, test.localkey)
|
2019-04-30 06:13:22 -05:00
|
|
|
test.udp, _ = ListenV4(test.pipe, ln, Config{
|
|
|
|
PrivateKey: test.localkey,
|
|
|
|
Log: testlog.Logger(t, log.LvlTrace),
|
|
|
|
})
|
|
|
|
test.table = test.udp.tab
|
2018-02-12 06:36:09 -06:00
|
|
|
// Wait for initial refresh so the table doesn't send unexpected findnode.
|
|
|
|
<-test.table.initDone
|
2015-03-25 10:45:53 -05:00
|
|
|
return test
|
|
|
|
}
|
|
|
|
|
2019-01-29 10:39:20 -06:00
|
|
|
func (test *udpTest) close() {
|
2019-04-30 06:13:22 -05:00
|
|
|
test.udp.Close()
|
2019-01-29 10:39:20 -06:00
|
|
|
test.db.Close()
|
|
|
|
}
|
|
|
|
|
2015-03-25 10:45:53 -05:00
|
|
|
// handles a packet as if it had been sent to the transport.
|
2019-05-14 23:47:45 -05:00
|
|
|
func (test *udpTest) packetIn(wantError error, data packetV4) {
|
2019-04-30 06:13:22 -05:00
|
|
|
test.t.Helper()
|
|
|
|
|
2019-05-14 23:47:45 -05:00
|
|
|
test.packetInFrom(wantError, test.remotekey, test.remoteaddr, data)
|
2019-01-29 10:39:20 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// handles a packet as if it had been sent to the transport by the key/endpoint.
|
2019-05-14 23:47:45 -05:00
|
|
|
func (test *udpTest) packetInFrom(wantError error, key *ecdsa.PrivateKey, addr *net.UDPAddr, data packetV4) {
|
2019-04-30 06:13:22 -05:00
|
|
|
test.t.Helper()
|
|
|
|
|
2019-05-14 23:47:45 -05:00
|
|
|
enc, _, err := test.udp.encode(key, data)
|
2015-03-25 10:45:53 -05:00
|
|
|
if err != nil {
|
2019-05-14 23:47:45 -05:00
|
|
|
test.t.Errorf("%s encode error: %v", data.name(), err)
|
2015-01-27 07:33:26 -06:00
|
|
|
}
|
2015-03-25 10:45:53 -05:00
|
|
|
test.sent = append(test.sent, enc)
|
2019-01-29 10:39:20 -06:00
|
|
|
if err = test.udp.handlePacket(addr, enc); err != wantError {
|
2019-04-30 06:13:22 -05:00
|
|
|
test.t.Errorf("error mismatch: got %q, want %q", err, wantError)
|
2015-01-27 07:33:26 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-25 10:45:53 -05:00
|
|
|
// waits for a packet to be sent by the transport.
|
2019-04-30 06:13:22 -05:00
|
|
|
// validate should have type func(X, *net.UDPAddr, []byte), where X is a packet type.
|
|
|
|
func (test *udpTest) waitPacketOut(validate interface{}) (closed bool) {
|
|
|
|
test.t.Helper()
|
|
|
|
|
|
|
|
dgram, ok := test.pipe.receive()
|
|
|
|
if !ok {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
p, _, hash, err := decodeV4(dgram.data)
|
2015-03-25 10:45:53 -05:00
|
|
|
if err != nil {
|
2019-04-30 06:13:22 -05:00
|
|
|
test.t.Errorf("sent packet decode error: %v", err)
|
|
|
|
return false
|
2015-01-27 07:33:26 -06:00
|
|
|
}
|
2015-03-25 10:45:53 -05:00
|
|
|
fn := reflect.ValueOf(validate)
|
|
|
|
exptype := fn.Type().In(0)
|
2019-04-30 06:13:22 -05:00
|
|
|
if !reflect.TypeOf(p).AssignableTo(exptype) {
|
|
|
|
test.t.Errorf("sent packet type mismatch, got: %v, want: %v", reflect.TypeOf(p), exptype)
|
|
|
|
return false
|
2015-03-25 10:45:53 -05:00
|
|
|
}
|
2019-04-30 06:13:22 -05:00
|
|
|
fn.Call([]reflect.Value{reflect.ValueOf(p), reflect.ValueOf(&dgram.to), reflect.ValueOf(hash)})
|
|
|
|
return false
|
2015-01-27 07:33:26 -06:00
|
|
|
}
|
|
|
|
|
2019-04-30 06:13:22 -05:00
|
|
|
func TestUDPv4_packetErrors(t *testing.T) {
|
2015-03-25 10:45:53 -05:00
|
|
|
test := newUDPTest(t)
|
2019-01-29 10:39:20 -06:00
|
|
|
defer test.close()
|
2015-03-25 10:45:53 -05:00
|
|
|
|
2019-05-14 23:47:45 -05:00
|
|
|
test.packetIn(errExpired, &pingV4{From: testRemote, To: testLocalAnnounced, Version: 4})
|
|
|
|
test.packetIn(errUnsolicitedReply, &pongV4{ReplyTok: []byte{}, Expiration: futureExp})
|
|
|
|
test.packetIn(errUnknownNode, &findnodeV4{Expiration: futureExp})
|
|
|
|
test.packetIn(errUnsolicitedReply, &neighborsV4{Expiration: futureExp})
|
2015-03-25 10:45:53 -05:00
|
|
|
}
|
|
|
|
|
2019-04-30 06:13:22 -05:00
|
|
|
func TestUDPv4_pingTimeout(t *testing.T) {
|
2015-03-25 10:45:53 -05:00
|
|
|
t.Parallel()
|
|
|
|
test := newUDPTest(t)
|
2019-01-29 10:39:20 -06:00
|
|
|
defer test.close()
|
2015-03-25 10:45:53 -05:00
|
|
|
|
2019-04-30 06:13:22 -05:00
|
|
|
key := newkey()
|
2015-03-25 10:45:53 -05:00
|
|
|
toaddr := &net.UDPAddr{IP: net.ParseIP("1.2.3.4"), Port: 2222}
|
2019-04-30 06:13:22 -05:00
|
|
|
node := enode.NewV4(&key.PublicKey, toaddr.IP, 0, toaddr.Port)
|
2019-05-14 23:47:45 -05:00
|
|
|
if _, err := test.udp.ping(node); err != errTimeout {
|
2015-03-25 10:45:53 -05:00
|
|
|
t.Error("expected timeout error, got", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-14 23:47:45 -05:00
|
|
|
type testPacket byte
|
|
|
|
|
|
|
|
func (req testPacket) kind() byte { return byte(req) }
|
|
|
|
func (req testPacket) name() string { return "" }
|
|
|
|
func (req testPacket) preverify(*UDPv4, *net.UDPAddr, enode.ID, encPubkey) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
func (req testPacket) handle(*UDPv4, *net.UDPAddr, enode.ID, []byte) {
|
|
|
|
}
|
|
|
|
|
2019-04-30 06:13:22 -05:00
|
|
|
func TestUDPv4_responseTimeouts(t *testing.T) {
|
2015-08-07 19:49:28 -05:00
|
|
|
t.Parallel()
|
|
|
|
test := newUDPTest(t)
|
2019-01-29 10:39:20 -06:00
|
|
|
defer test.close()
|
2015-08-07 19:49:28 -05:00
|
|
|
|
|
|
|
rand.Seed(time.Now().UnixNano())
|
|
|
|
randomDuration := func(max time.Duration) time.Duration {
|
|
|
|
return time.Duration(rand.Int63n(int64(max)))
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
nReqs = 200
|
|
|
|
nTimeouts = 0 // number of requests with ptype > 128
|
|
|
|
nilErr = make(chan error, nReqs) // for requests that get a reply
|
|
|
|
timeoutErr = make(chan error, nReqs) // for requests that time out
|
|
|
|
)
|
|
|
|
for i := 0; i < nReqs; i++ {
|
|
|
|
// Create a matcher for a random request in udp.loop. Requests
|
|
|
|
// with ptype <= 128 will not get a reply and should time out.
|
|
|
|
// For all other requests, a reply is scheduled to arrive
|
|
|
|
// within the timeout window.
|
2019-01-29 10:39:20 -06:00
|
|
|
p := &replyMatcher{
|
2015-08-07 19:49:28 -05:00
|
|
|
ptype: byte(rand.Intn(255)),
|
2019-01-29 10:39:20 -06:00
|
|
|
callback: func(interface{}) (bool, bool) { return true, true },
|
2015-08-07 19:49:28 -05:00
|
|
|
}
|
|
|
|
binary.BigEndian.PutUint64(p.from[:], uint64(i))
|
|
|
|
if p.ptype <= 128 {
|
|
|
|
p.errc = timeoutErr
|
2019-01-29 10:39:20 -06:00
|
|
|
test.udp.addReplyMatcher <- p
|
2015-08-07 19:49:28 -05:00
|
|
|
nTimeouts++
|
|
|
|
} else {
|
|
|
|
p.errc = nilErr
|
2019-01-29 10:39:20 -06:00
|
|
|
test.udp.addReplyMatcher <- p
|
2015-08-07 19:49:28 -05:00
|
|
|
time.AfterFunc(randomDuration(60*time.Millisecond), func() {
|
2019-05-14 23:47:45 -05:00
|
|
|
if !test.udp.handleReply(p.from, p.ip, testPacket(p.ptype)) {
|
2015-08-07 19:49:28 -05:00
|
|
|
t.Logf("not matched: %v", p)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
time.Sleep(randomDuration(30 * time.Millisecond))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that all timeouts were delivered and that the rest got nil errors.
|
|
|
|
// The replies must be delivered.
|
|
|
|
var (
|
|
|
|
recvDeadline = time.After(20 * time.Second)
|
|
|
|
nTimeoutsRecv, nNil = 0, 0
|
|
|
|
)
|
|
|
|
for i := 0; i < nReqs; i++ {
|
|
|
|
select {
|
|
|
|
case err := <-timeoutErr:
|
|
|
|
if err != errTimeout {
|
|
|
|
t.Fatalf("got non-timeout error on timeoutErr %d: %v", i, err)
|
|
|
|
}
|
|
|
|
nTimeoutsRecv++
|
|
|
|
case err := <-nilErr:
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("got non-nil error on nilErr %d: %v", i, err)
|
|
|
|
}
|
|
|
|
nNil++
|
|
|
|
case <-recvDeadline:
|
|
|
|
t.Fatalf("exceeded recv deadline")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if nTimeoutsRecv != nTimeouts {
|
|
|
|
t.Errorf("wrong number of timeout errors received: got %d, want %d", nTimeoutsRecv, nTimeouts)
|
|
|
|
}
|
|
|
|
if nNil != nReqs-nTimeouts {
|
|
|
|
t.Errorf("wrong number of successful replies: got %d, want %d", nNil, nReqs-nTimeouts)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-30 06:13:22 -05:00
|
|
|
func TestUDPv4_findnodeTimeout(t *testing.T) {
|
2015-01-27 07:33:26 -06:00
|
|
|
t.Parallel()
|
2015-03-25 10:45:53 -05:00
|
|
|
test := newUDPTest(t)
|
2019-01-29 10:39:20 -06:00
|
|
|
defer test.close()
|
2015-01-27 07:33:26 -06:00
|
|
|
|
2015-03-25 10:45:53 -05:00
|
|
|
toaddr := &net.UDPAddr{IP: net.ParseIP("1.2.3.4"), Port: 2222}
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
toid := enode.ID{1, 2, 3, 4}
|
|
|
|
target := encPubkey{4, 5, 6, 7}
|
2015-03-25 10:45:53 -05:00
|
|
|
result, err := test.udp.findnode(toid, toaddr, target)
|
|
|
|
if err != errTimeout {
|
|
|
|
t.Error("expected timeout error, got", err)
|
|
|
|
}
|
|
|
|
if len(result) > 0 {
|
|
|
|
t.Error("expected empty result, got", result)
|
|
|
|
}
|
|
|
|
}
|
2015-01-27 07:33:26 -06:00
|
|
|
|
2019-04-30 06:13:22 -05:00
|
|
|
func TestUDPv4_findnode(t *testing.T) {
|
2015-03-25 10:45:53 -05:00
|
|
|
test := newUDPTest(t)
|
2019-01-29 10:39:20 -06:00
|
|
|
defer test.close()
|
2015-03-25 10:45:53 -05:00
|
|
|
|
|
|
|
// put a few nodes into the table. their exact
|
2017-01-06 11:44:35 -06:00
|
|
|
// distribution shouldn't matter much, although we need to
|
2015-03-25 10:45:53 -05:00
|
|
|
// take care not to overflow any bucket.
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
nodes := &nodesByDistance{target: testTarget.id()}
|
2019-01-29 10:39:20 -06:00
|
|
|
live := make(map[enode.ID]bool)
|
|
|
|
numCandidates := 2 * bucketSize
|
|
|
|
for i := 0; i < numCandidates; i++ {
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
key := newkey()
|
2019-01-29 10:39:20 -06:00
|
|
|
ip := net.IP{10, 13, 0, byte(i)}
|
|
|
|
n := wrapNode(enode.NewV4(&key.PublicKey, ip, 0, 2000))
|
|
|
|
// Ensure half of table content isn't verified live yet.
|
|
|
|
if i > numCandidates/2 {
|
|
|
|
n.livenessChecks = 1
|
|
|
|
live[n.ID()] = true
|
|
|
|
}
|
|
|
|
nodes.push(n, numCandidates)
|
2015-01-27 07:33:26 -06:00
|
|
|
}
|
2019-01-29 10:39:20 -06:00
|
|
|
fillTable(test.table, nodes.entries)
|
2015-03-25 10:45:53 -05:00
|
|
|
|
|
|
|
// ensure there's a bond with the test node,
|
|
|
|
// findnode won't be accepted otherwise.
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
remoteID := encodePubkey(&test.remotekey.PublicKey).id()
|
2019-01-29 10:39:20 -06:00
|
|
|
test.table.db.UpdateLastPongReceived(remoteID, test.remoteaddr.IP, time.Now())
|
2018-02-16 13:16:23 -06:00
|
|
|
|
2015-03-25 10:45:53 -05:00
|
|
|
// check that closest neighbors are returned.
|
2019-04-30 06:13:22 -05:00
|
|
|
expected := test.table.closest(testTarget.id(), bucketSize, true)
|
2019-05-14 23:47:45 -05:00
|
|
|
test.packetIn(nil, &findnodeV4{Target: testTarget, Expiration: futureExp})
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
waitNeighbors := func(want []*node) {
|
2019-04-30 06:13:22 -05:00
|
|
|
test.waitPacketOut(func(p *neighborsV4, to *net.UDPAddr, hash []byte) {
|
2015-05-13 14:29:32 -05:00
|
|
|
if len(p.Nodes) != len(want) {
|
|
|
|
t.Errorf("wrong number of results: got %d, want %d", len(p.Nodes), bucketSize)
|
2015-05-13 13:03:17 -05:00
|
|
|
}
|
2019-01-29 10:39:20 -06:00
|
|
|
for i, n := range p.Nodes {
|
|
|
|
if n.ID.id() != want[i].ID() {
|
|
|
|
t.Errorf("result mismatch at %d:\n got: %v\n want: %v", i, n, expected.entries[i])
|
|
|
|
}
|
|
|
|
if !live[n.ID.id()] {
|
|
|
|
t.Errorf("result includes dead node %v", n.ID.id())
|
2015-05-13 14:29:32 -05:00
|
|
|
}
|
2015-02-09 04:02:32 -06:00
|
|
|
}
|
2015-05-13 14:29:32 -05:00
|
|
|
})
|
|
|
|
}
|
2019-01-29 10:39:20 -06:00
|
|
|
// Receive replies.
|
|
|
|
want := expected.entries
|
|
|
|
if len(want) > maxNeighbors {
|
|
|
|
waitNeighbors(want[:maxNeighbors])
|
|
|
|
want = want[maxNeighbors:]
|
|
|
|
}
|
|
|
|
waitNeighbors(want)
|
2015-01-27 07:33:26 -06:00
|
|
|
}
|
|
|
|
|
2019-04-30 06:13:22 -05:00
|
|
|
func TestUDPv4_findnodeMultiReply(t *testing.T) {
|
2015-03-25 10:45:53 -05:00
|
|
|
test := newUDPTest(t)
|
2019-01-29 10:39:20 -06:00
|
|
|
defer test.close()
|
2015-01-27 07:33:26 -06:00
|
|
|
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
rid := enode.PubkeyToIDV4(&test.remotekey.PublicKey)
|
2019-01-29 10:39:20 -06:00
|
|
|
test.table.db.UpdateLastPingReceived(rid, test.remoteaddr.IP, time.Now())
|
2018-07-03 08:24:12 -05:00
|
|
|
|
2015-03-25 10:45:53 -05:00
|
|
|
// queue a pending findnode request
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
resultc, errc := make(chan []*node), make(chan error)
|
2015-03-25 10:45:53 -05:00
|
|
|
go func() {
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
rid := encodePubkey(&test.remotekey.PublicKey).id()
|
2015-03-25 10:45:53 -05:00
|
|
|
ns, err := test.udp.findnode(rid, test.remoteaddr, testTarget)
|
|
|
|
if err != nil && len(ns) == 0 {
|
|
|
|
errc <- err
|
|
|
|
} else {
|
|
|
|
resultc <- ns
|
|
|
|
}
|
|
|
|
}()
|
2015-01-27 07:33:26 -06:00
|
|
|
|
2015-03-25 10:45:53 -05:00
|
|
|
// wait for the findnode to be sent.
|
|
|
|
// after it is sent, the transport is waiting for a reply
|
2019-04-30 06:13:22 -05:00
|
|
|
test.waitPacketOut(func(p *findnodeV4, to *net.UDPAddr, hash []byte) {
|
2015-03-25 10:45:53 -05:00
|
|
|
if p.Target != testTarget {
|
|
|
|
t.Errorf("wrong target: got %v, want %v", p.Target, testTarget)
|
|
|
|
}
|
|
|
|
})
|
2015-01-27 07:33:26 -06:00
|
|
|
|
2015-03-25 10:45:53 -05:00
|
|
|
// send the reply as two packets.
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
list := []*node{
|
2019-06-07 08:31:00 -05:00
|
|
|
wrapNode(enode.MustParse("enode://ba85011c70bcc5c04d8607d3a0ed29aa6179c092cbdda10d5d32684fb33ed01bd94f588ca8f91ac48318087dcb02eaf36773a7a453f0eedd6742af668097b29c@10.0.1.16:30303?discport=30304")),
|
|
|
|
wrapNode(enode.MustParse("enode://81fa361d25f157cd421c60dcc28d8dac5ef6a89476633339c5df30287474520caca09627da18543d9079b5b288698b542d56167aa5c09111e55acdbbdf2ef799@10.0.1.16:30303")),
|
|
|
|
wrapNode(enode.MustParse("enode://9bffefd833d53fac8e652415f4973bee289e8b1a5c6c4cbe70abf817ce8a64cee11b823b66a987f51aaa9fba0d6a91b3e6bf0d5a5d1042de8e9eeea057b217f8@10.0.1.36:30301?discport=17")),
|
|
|
|
wrapNode(enode.MustParse("enode://1b5b4aa662d7cb44a7221bfba67302590b643028197a7d5214790f3bac7aaa4a3241be9e83c09cf1f6c69d007c634faae3dc1b1221793e8446c0b3a09de65960@10.0.1.16:30303")),
|
2015-01-27 07:33:26 -06:00
|
|
|
}
|
2015-04-23 05:11:21 -05:00
|
|
|
rpclist := make([]rpcNode, len(list))
|
|
|
|
for i := range list {
|
|
|
|
rpclist[i] = nodeToRPC(list[i])
|
|
|
|
}
|
2019-05-14 23:47:45 -05:00
|
|
|
test.packetIn(nil, &neighborsV4{Expiration: futureExp, Nodes: rpclist[:2]})
|
|
|
|
test.packetIn(nil, &neighborsV4{Expiration: futureExp, Nodes: rpclist[2:]})
|
2015-01-27 07:33:26 -06:00
|
|
|
|
2015-03-25 10:45:53 -05:00
|
|
|
// check that the sent neighbors are all returned by findnode
|
|
|
|
select {
|
|
|
|
case result := <-resultc:
|
2016-11-21 11:11:54 -06:00
|
|
|
want := append(list[:2], list[3:]...)
|
|
|
|
if !reflect.DeepEqual(result, want) {
|
|
|
|
t.Errorf("neighbors mismatch:\n got: %v\n want: %v", result, want)
|
2015-03-25 10:45:53 -05:00
|
|
|
}
|
|
|
|
case err := <-errc:
|
|
|
|
t.Errorf("findnode error: %v", err)
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
t.Error("findnode did not return within 5 seconds")
|
2015-01-27 07:33:26 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-14 23:47:45 -05:00
|
|
|
// This test checks that reply matching of pong verifies the ping hash.
|
2019-04-30 06:13:22 -05:00
|
|
|
func TestUDPv4_pingMatch(t *testing.T) {
|
2019-01-29 10:39:20 -06:00
|
|
|
test := newUDPTest(t)
|
|
|
|
defer test.close()
|
|
|
|
|
|
|
|
randToken := make([]byte, 32)
|
|
|
|
crand.Read(randToken)
|
|
|
|
|
2019-05-14 23:47:45 -05:00
|
|
|
test.packetIn(nil, &pingV4{From: testRemote, To: testLocalAnnounced, Version: 4, Expiration: futureExp})
|
2019-04-30 06:13:22 -05:00
|
|
|
test.waitPacketOut(func(*pongV4, *net.UDPAddr, []byte) {})
|
|
|
|
test.waitPacketOut(func(*pingV4, *net.UDPAddr, []byte) {})
|
2019-05-14 23:47:45 -05:00
|
|
|
test.packetIn(errUnsolicitedReply, &pongV4{ReplyTok: randToken, To: testLocalAnnounced, Expiration: futureExp})
|
2019-01-29 10:39:20 -06:00
|
|
|
}
|
|
|
|
|
2019-05-14 23:47:45 -05:00
|
|
|
// This test checks that reply matching of pong verifies the sender IP address.
|
2019-04-30 06:13:22 -05:00
|
|
|
func TestUDPv4_pingMatchIP(t *testing.T) {
|
2019-01-29 10:39:20 -06:00
|
|
|
test := newUDPTest(t)
|
|
|
|
defer test.close()
|
|
|
|
|
2019-05-14 23:47:45 -05:00
|
|
|
test.packetIn(nil, &pingV4{From: testRemote, To: testLocalAnnounced, Version: 4, Expiration: futureExp})
|
2019-04-30 06:13:22 -05:00
|
|
|
test.waitPacketOut(func(*pongV4, *net.UDPAddr, []byte) {})
|
2019-01-29 10:39:20 -06:00
|
|
|
|
2019-04-30 06:13:22 -05:00
|
|
|
test.waitPacketOut(func(p *pingV4, to *net.UDPAddr, hash []byte) {
|
|
|
|
wrongAddr := &net.UDPAddr{IP: net.IP{33, 44, 1, 2}, Port: 30000}
|
2019-05-14 23:47:45 -05:00
|
|
|
test.packetInFrom(errUnsolicitedReply, test.remotekey, wrongAddr, &pongV4{
|
2019-04-30 06:13:22 -05:00
|
|
|
ReplyTok: hash,
|
|
|
|
To: testLocalAnnounced,
|
|
|
|
Expiration: futureExp,
|
|
|
|
})
|
2019-01-29 10:39:20 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-04-30 06:13:22 -05:00
|
|
|
func TestUDPv4_successfulPing(t *testing.T) {
|
2015-03-25 10:45:53 -05:00
|
|
|
test := newUDPTest(t)
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
added := make(chan *node, 1)
|
|
|
|
test.table.nodeAddedHook = func(n *node) { added <- n }
|
2019-01-29 10:39:20 -06:00
|
|
|
defer test.close()
|
2015-01-27 07:33:26 -06:00
|
|
|
|
2015-06-10 06:07:30 -05:00
|
|
|
// The remote side sends a ping packet to initiate the exchange.
|
2019-05-14 23:47:45 -05:00
|
|
|
go test.packetIn(nil, &pingV4{From: testRemote, To: testLocalAnnounced, Version: 4, Expiration: futureExp})
|
2015-02-09 04:02:32 -06:00
|
|
|
|
2019-05-14 23:47:45 -05:00
|
|
|
// The ping is replied to.
|
2019-04-30 06:13:22 -05:00
|
|
|
test.waitPacketOut(func(p *pongV4, to *net.UDPAddr, hash []byte) {
|
2015-03-25 10:45:53 -05:00
|
|
|
pinghash := test.sent[0][:macSize]
|
|
|
|
if !bytes.Equal(p.ReplyTok, pinghash) {
|
2015-04-17 18:50:31 -05:00
|
|
|
t.Errorf("got pong.ReplyTok %x, want %x", p.ReplyTok, pinghash)
|
|
|
|
}
|
|
|
|
wantTo := rpcEndpoint{
|
|
|
|
// The mirrored UDP address is the UDP packet sender
|
|
|
|
IP: test.remoteaddr.IP, UDP: uint16(test.remoteaddr.Port),
|
|
|
|
// The mirrored TCP port is the one from the ping packet
|
|
|
|
TCP: testRemote.TCP,
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(p.To, wantTo) {
|
|
|
|
t.Errorf("got pong.To %v, want %v", p.To, wantTo)
|
2015-01-27 07:33:26 -06:00
|
|
|
}
|
2015-03-25 10:45:53 -05:00
|
|
|
})
|
2015-01-27 07:33:26 -06:00
|
|
|
|
2019-05-14 23:47:45 -05:00
|
|
|
// Remote is unknown, the table pings back.
|
2019-04-30 06:13:22 -05:00
|
|
|
test.waitPacketOut(func(p *pingV4, to *net.UDPAddr, hash []byte) {
|
2018-10-12 04:47:24 -05:00
|
|
|
if !reflect.DeepEqual(p.From, test.udp.ourEndpoint()) {
|
|
|
|
t.Errorf("got ping.From %#v, want %#v", p.From, test.udp.ourEndpoint())
|
2015-04-17 18:50:31 -05:00
|
|
|
}
|
|
|
|
wantTo := rpcEndpoint{
|
|
|
|
// The mirrored UDP address is the UDP packet sender.
|
2018-10-12 04:47:24 -05:00
|
|
|
IP: test.remoteaddr.IP,
|
|
|
|
UDP: uint16(test.remoteaddr.Port),
|
2015-04-17 18:50:31 -05:00
|
|
|
TCP: 0,
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(p.To, wantTo) {
|
|
|
|
t.Errorf("got ping.To %v, want %v", p.To, wantTo)
|
|
|
|
}
|
2019-05-14 23:47:45 -05:00
|
|
|
test.packetIn(nil, &pongV4{ReplyTok: hash, Expiration: futureExp})
|
2015-04-17 18:50:31 -05:00
|
|
|
})
|
2015-03-25 10:45:53 -05:00
|
|
|
|
2019-05-14 23:47:45 -05:00
|
|
|
// The node should be added to the table shortly after getting the
|
2015-06-10 06:07:30 -05:00
|
|
|
// pong packet.
|
|
|
|
select {
|
|
|
|
case n := <-added:
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
rid := encodePubkey(&test.remotekey.PublicKey).id()
|
|
|
|
if n.ID() != rid {
|
|
|
|
t.Errorf("node has wrong ID: got %v, want %v", n.ID(), rid)
|
2015-02-09 04:02:32 -06:00
|
|
|
}
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
if !n.IP().Equal(test.remoteaddr.IP) {
|
|
|
|
t.Errorf("node has wrong IP: got %v, want: %v", n.IP(), test.remoteaddr.IP)
|
2015-06-10 06:07:30 -05:00
|
|
|
}
|
2019-07-22 02:30:09 -05:00
|
|
|
if n.UDP() != test.remoteaddr.Port {
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
t.Errorf("node has wrong UDP port: got %v, want: %v", n.UDP(), test.remoteaddr.Port)
|
2015-06-10 06:07:30 -05:00
|
|
|
}
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
if n.TCP() != int(testRemote.TCP) {
|
|
|
|
t.Errorf("node has wrong TCP port: got %v, want: %v", n.TCP(), testRemote.TCP)
|
2015-06-10 06:07:30 -05:00
|
|
|
}
|
|
|
|
case <-time.After(2 * time.Second):
|
|
|
|
t.Errorf("node was not added within 2 seconds")
|
2015-01-27 07:33:26 -06:00
|
|
|
}
|
2015-02-09 04:02:32 -06:00
|
|
|
}
|
2015-01-27 07:33:26 -06:00
|
|
|
|
2019-05-14 23:47:45 -05:00
|
|
|
// This test checks that EIP-868 requests work.
|
|
|
|
func TestUDPv4_EIP868(t *testing.T) {
|
|
|
|
test := newUDPTest(t)
|
|
|
|
defer test.close()
|
|
|
|
|
|
|
|
test.udp.localNode.Set(enr.WithEntry("foo", "bar"))
|
|
|
|
wantNode := test.udp.localNode.Node()
|
|
|
|
|
|
|
|
// ENR requests aren't allowed before endpoint proof.
|
|
|
|
test.packetIn(errUnknownNode, &enrRequestV4{Expiration: futureExp})
|
|
|
|
|
|
|
|
// Perform endpoint proof and check for sequence number in packet tail.
|
|
|
|
test.packetIn(nil, &pingV4{Expiration: futureExp})
|
|
|
|
test.waitPacketOut(func(p *pongV4, addr *net.UDPAddr, hash []byte) {
|
|
|
|
if seq := seqFromTail(p.Rest); seq != wantNode.Seq() {
|
|
|
|
t.Errorf("wrong sequence number in pong: %d, want %d", seq, wantNode.Seq())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
test.waitPacketOut(func(p *pingV4, addr *net.UDPAddr, hash []byte) {
|
|
|
|
if seq := seqFromTail(p.Rest); seq != wantNode.Seq() {
|
|
|
|
t.Errorf("wrong sequence number in ping: %d, want %d", seq, wantNode.Seq())
|
|
|
|
}
|
|
|
|
test.packetIn(nil, &pongV4{Expiration: futureExp, ReplyTok: hash})
|
|
|
|
})
|
|
|
|
|
|
|
|
// Request should work now.
|
|
|
|
test.packetIn(nil, &enrRequestV4{Expiration: futureExp})
|
|
|
|
test.waitPacketOut(func(p *enrResponseV4, addr *net.UDPAddr, hash []byte) {
|
|
|
|
n, err := enode.New(enode.ValidSchemes, &p.Record)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("invalid record: %v", err)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(n, wantNode) {
|
|
|
|
t.Fatalf("wrong node in enrResponse: %v", n)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// EIP-8 test vectors.
|
2015-12-22 18:52:40 -06:00
|
|
|
var testPackets = []struct {
|
|
|
|
input string
|
|
|
|
wantPacket interface{}
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
input: "71dbda3a79554728d4f94411e42ee1f8b0d561c10e1e5f5893367948c6a7d70bb87b235fa28a77070271b6c164a2dce8c7e13a5739b53b5e96f2e5acb0e458a02902f5965d55ecbeb2ebb6cabb8b2b232896a36b737666c55265ad0a68412f250001ea04cb847f000001820cfa8215a8d790000000000000000000000000000000018208ae820d058443b9a355",
|
2019-04-30 06:13:22 -05:00
|
|
|
wantPacket: &pingV4{
|
2015-12-22 18:52:40 -06:00
|
|
|
Version: 4,
|
|
|
|
From: rpcEndpoint{net.ParseIP("127.0.0.1").To4(), 3322, 5544},
|
|
|
|
To: rpcEndpoint{net.ParseIP("::1"), 2222, 3333},
|
|
|
|
Expiration: 1136239445,
|
|
|
|
Rest: []rlp.RawValue{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "e9614ccfd9fc3e74360018522d30e1419a143407ffcce748de3e22116b7e8dc92ff74788c0b6663aaa3d67d641936511c8f8d6ad8698b820a7cf9e1be7155e9a241f556658c55428ec0563514365799a4be2be5a685a80971ddcfa80cb422cdd0101ec04cb847f000001820cfa8215a8d790000000000000000000000000000000018208ae820d058443b9a3550102",
|
2019-04-30 06:13:22 -05:00
|
|
|
wantPacket: &pingV4{
|
2015-12-22 18:52:40 -06:00
|
|
|
Version: 4,
|
|
|
|
From: rpcEndpoint{net.ParseIP("127.0.0.1").To4(), 3322, 5544},
|
|
|
|
To: rpcEndpoint{net.ParseIP("::1"), 2222, 3333},
|
|
|
|
Expiration: 1136239445,
|
|
|
|
Rest: []rlp.RawValue{{0x01}, {0x02}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "577be4349c4dd26768081f58de4c6f375a7a22f3f7adda654d1428637412c3d7fe917cadc56d4e5e7ffae1dbe3efffb9849feb71b262de37977e7c7a44e677295680e9e38ab26bee2fcbae207fba3ff3d74069a50b902a82c9903ed37cc993c50001f83e82022bd79020010db83c4d001500000000abcdef12820cfa8215a8d79020010db885a308d313198a2e037073488208ae82823a8443b9a355c5010203040531b9019afde696e582a78fa8d95ea13ce3297d4afb8ba6433e4154caa5ac6431af1b80ba76023fa4090c408f6b4bc3701562c031041d4702971d102c9ab7fa5eed4cd6bab8f7af956f7d565ee1917084a95398b6a21eac920fe3dd1345ec0a7ef39367ee69ddf092cbfe5b93e5e568ebc491983c09c76d922dc3",
|
2019-04-30 06:13:22 -05:00
|
|
|
wantPacket: &pingV4{
|
2015-12-22 18:52:40 -06:00
|
|
|
Version: 555,
|
|
|
|
From: rpcEndpoint{net.ParseIP("2001:db8:3c4d:15::abcd:ef12"), 3322, 5544},
|
|
|
|
To: rpcEndpoint{net.ParseIP("2001:db8:85a3:8d3:1319:8a2e:370:7348"), 2222, 33338},
|
|
|
|
Expiration: 1136239445,
|
|
|
|
Rest: []rlp.RawValue{{0xC5, 0x01, 0x02, 0x03, 0x04, 0x05}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "09b2428d83348d27cdf7064ad9024f526cebc19e4958f0fdad87c15eb598dd61d08423e0bf66b2069869e1724125f820d851c136684082774f870e614d95a2855d000f05d1648b2d5945470bc187c2d2216fbe870f43ed0909009882e176a46b0102f846d79020010db885a308d313198a2e037073488208ae82823aa0fbc914b16819237dcd8801d7e53f69e9719adecb3cc0e790c57e91ca4461c9548443b9a355c6010203c2040506a0c969a58f6f9095004c0177a6b47f451530cab38966a25cca5cb58f055542124e",
|
2019-04-30 06:13:22 -05:00
|
|
|
wantPacket: &pongV4{
|
2015-12-22 18:52:40 -06:00
|
|
|
To: rpcEndpoint{net.ParseIP("2001:db8:85a3:8d3:1319:8a2e:370:7348"), 2222, 33338},
|
|
|
|
ReplyTok: common.Hex2Bytes("fbc914b16819237dcd8801d7e53f69e9719adecb3cc0e790c57e91ca4461c954"),
|
|
|
|
Expiration: 1136239445,
|
|
|
|
Rest: []rlp.RawValue{{0xC6, 0x01, 0x02, 0x03, 0xC2, 0x04, 0x05}, {0x06}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "c7c44041b9f7c7e41934417ebac9a8e1a4c6298f74553f2fcfdcae6ed6fe53163eb3d2b52e39fe91831b8a927bf4fc222c3902202027e5e9eb812195f95d20061ef5cd31d502e47ecb61183f74a504fe04c51e73df81f25c4d506b26db4517490103f84eb840ca634cae0d49acb401d8a4c6b6fe8c55b70d115bf400769cc1400f3258cd31387574077f301b421bc84df7266c44e9e6d569fc56be00812904767bf5ccd1fc7f8443b9a35582999983999999280dc62cc8255c73471e0a61da0c89acdc0e035e260add7fc0c04ad9ebf3919644c91cb247affc82b69bd2ca235c71eab8e49737c937a2c396",
|
2019-04-30 06:13:22 -05:00
|
|
|
wantPacket: &findnodeV4{
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
Target: hexEncPubkey("ca634cae0d49acb401d8a4c6b6fe8c55b70d115bf400769cc1400f3258cd31387574077f301b421bc84df7266c44e9e6d569fc56be00812904767bf5ccd1fc7f"),
|
2015-12-22 18:52:40 -06:00
|
|
|
Expiration: 1136239445,
|
|
|
|
Rest: []rlp.RawValue{{0x82, 0x99, 0x99}, {0x83, 0x99, 0x99, 0x99}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "c679fc8fe0b8b12f06577f2e802d34f6fa257e6137a995f6f4cbfc9ee50ed3710faf6e66f932c4c8d81d64343f429651328758b47d3dbc02c4042f0fff6946a50f4a49037a72bb550f3a7872363a83e1b9ee6469856c24eb4ef80b7535bcf99c0004f9015bf90150f84d846321163782115c82115db8403155e1427f85f10a5c9a7755877748041af1bcd8d474ec065eb33df57a97babf54bfd2103575fa829115d224c523596b401065a97f74010610fce76382c0bf32f84984010203040101b840312c55512422cf9b8a4097e9a6ad79402e87a15ae909a4bfefa22398f03d20951933beea1e4dfa6f968212385e829f04c2d314fc2d4e255e0d3bc08792b069dbf8599020010db83c4d001500000000abcdef12820d05820d05b84038643200b172dcfef857492156971f0e6aa2c538d8b74010f8e140811d53b98c765dd2d96126051913f44582e8c199ad7c6d6819e9a56483f637feaac9448aacf8599020010db885a308d313198a2e037073488203e78203e8b8408dcab8618c3253b558d459da53bd8fa68935a719aff8b811197101a4b2b47dd2d47295286fc00cc081bb542d760717d1bdd6bec2c37cd72eca367d6dd3b9df738443b9a355010203b525a138aa34383fec3d2719a0",
|
2019-04-30 06:13:22 -05:00
|
|
|
wantPacket: &neighborsV4{
|
2015-12-22 18:52:40 -06:00
|
|
|
Nodes: []rpcNode{
|
|
|
|
{
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
ID: hexEncPubkey("3155e1427f85f10a5c9a7755877748041af1bcd8d474ec065eb33df57a97babf54bfd2103575fa829115d224c523596b401065a97f74010610fce76382c0bf32"),
|
2015-12-22 18:52:40 -06:00
|
|
|
IP: net.ParseIP("99.33.22.55").To4(),
|
|
|
|
UDP: 4444,
|
|
|
|
TCP: 4445,
|
|
|
|
},
|
|
|
|
{
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
ID: hexEncPubkey("312c55512422cf9b8a4097e9a6ad79402e87a15ae909a4bfefa22398f03d20951933beea1e4dfa6f968212385e829f04c2d314fc2d4e255e0d3bc08792b069db"),
|
2015-12-22 18:52:40 -06:00
|
|
|
IP: net.ParseIP("1.2.3.4").To4(),
|
|
|
|
UDP: 1,
|
|
|
|
TCP: 1,
|
|
|
|
},
|
|
|
|
{
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
ID: hexEncPubkey("38643200b172dcfef857492156971f0e6aa2c538d8b74010f8e140811d53b98c765dd2d96126051913f44582e8c199ad7c6d6819e9a56483f637feaac9448aac"),
|
2015-12-22 18:52:40 -06:00
|
|
|
IP: net.ParseIP("2001:db8:3c4d:15::abcd:ef12"),
|
|
|
|
UDP: 3333,
|
|
|
|
TCP: 3333,
|
|
|
|
},
|
|
|
|
{
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
ID: hexEncPubkey("8dcab8618c3253b558d459da53bd8fa68935a719aff8b811197101a4b2b47dd2d47295286fc00cc081bb542d760717d1bdd6bec2c37cd72eca367d6dd3b9df73"),
|
2015-12-22 18:52:40 -06:00
|
|
|
IP: net.ParseIP("2001:db8:85a3:8d3:1319:8a2e:370:7348"),
|
|
|
|
UDP: 999,
|
|
|
|
TCP: 1000,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Expiration: 1136239445,
|
|
|
|
Rest: []rlp.RawValue{{0x01}, {0x02}, {0x03}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-04-30 06:13:22 -05:00
|
|
|
func TestUDPv4_forwardCompatibility(t *testing.T) {
|
2015-12-22 18:52:40 -06:00
|
|
|
testkey, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
wantNodeKey := encodePubkey(&testkey.PublicKey)
|
2015-12-22 18:52:40 -06:00
|
|
|
|
|
|
|
for _, test := range testPackets {
|
|
|
|
input, err := hex.DecodeString(test.input)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("invalid hex: %s", test.input)
|
|
|
|
}
|
2019-04-30 06:13:22 -05:00
|
|
|
packet, nodekey, _, err := decodeV4(input)
|
2015-12-22 18:52:40 -06:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("did not accept packet %s\n%v", test.input, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(packet, test.wantPacket) {
|
|
|
|
t.Errorf("got %s\nwant %s", spew.Sdump(packet), spew.Sdump(test.wantPacket))
|
|
|
|
}
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 17:59:00 -05:00
|
|
|
if nodekey != wantNodeKey {
|
|
|
|
t.Errorf("got id %v\nwant id %v", nodekey, wantNodeKey)
|
2015-12-22 18:52:40 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-25 10:45:53 -05:00
|
|
|
// dgramPipe is a fake UDP socket. It queues all sent datagrams.
|
|
|
|
type dgramPipe struct {
|
|
|
|
mu *sync.Mutex
|
|
|
|
cond *sync.Cond
|
|
|
|
closing chan struct{}
|
|
|
|
closed bool
|
2019-01-29 10:39:20 -06:00
|
|
|
queue []dgram
|
|
|
|
}
|
|
|
|
|
|
|
|
type dgram struct {
|
|
|
|
to net.UDPAddr
|
|
|
|
data []byte
|
2015-03-25 10:45:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func newpipe() *dgramPipe {
|
|
|
|
mu := new(sync.Mutex)
|
|
|
|
return &dgramPipe{
|
|
|
|
closing: make(chan struct{}),
|
|
|
|
cond: &sync.Cond{L: mu},
|
|
|
|
mu: mu,
|
2015-01-27 07:33:26 -06:00
|
|
|
}
|
2015-03-25 10:45:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// WriteToUDP queues a datagram.
|
|
|
|
func (c *dgramPipe) WriteToUDP(b []byte, to *net.UDPAddr) (n int, err error) {
|
|
|
|
msg := make([]byte, len(b))
|
|
|
|
copy(msg, b)
|
|
|
|
c.mu.Lock()
|
|
|
|
defer c.mu.Unlock()
|
|
|
|
if c.closed {
|
|
|
|
return 0, errors.New("closed")
|
|
|
|
}
|
2019-01-29 10:39:20 -06:00
|
|
|
c.queue = append(c.queue, dgram{*to, b})
|
2015-03-25 10:45:53 -05:00
|
|
|
c.cond.Signal()
|
|
|
|
return len(b), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReadFromUDP just hangs until the pipe is closed.
|
|
|
|
func (c *dgramPipe) ReadFromUDP(b []byte) (n int, addr *net.UDPAddr, err error) {
|
|
|
|
<-c.closing
|
|
|
|
return 0, nil, io.EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *dgramPipe) Close() error {
|
|
|
|
c.mu.Lock()
|
|
|
|
defer c.mu.Unlock()
|
|
|
|
if !c.closed {
|
|
|
|
close(c.closing)
|
|
|
|
c.closed = true
|
2015-01-27 07:33:26 -06:00
|
|
|
}
|
2019-04-30 06:13:22 -05:00
|
|
|
c.cond.Broadcast()
|
2015-02-09 04:02:32 -06:00
|
|
|
return nil
|
2015-01-27 07:33:26 -06:00
|
|
|
}
|
2015-03-25 10:45:53 -05:00
|
|
|
|
|
|
|
func (c *dgramPipe) LocalAddr() net.Addr {
|
2015-04-17 18:50:31 -05:00
|
|
|
return &net.UDPAddr{IP: testLocal.IP, Port: int(testLocal.UDP)}
|
2015-03-25 10:45:53 -05:00
|
|
|
}
|
|
|
|
|
2019-04-30 06:13:22 -05:00
|
|
|
func (c *dgramPipe) receive() (dgram, bool) {
|
2015-03-25 10:45:53 -05:00
|
|
|
c.mu.Lock()
|
|
|
|
defer c.mu.Unlock()
|
2019-04-30 06:13:22 -05:00
|
|
|
for len(c.queue) == 0 && !c.closed {
|
2015-03-25 10:45:53 -05:00
|
|
|
c.cond.Wait()
|
|
|
|
}
|
2019-04-30 06:13:22 -05:00
|
|
|
if c.closed {
|
|
|
|
return dgram{}, false
|
|
|
|
}
|
2015-03-25 10:45:53 -05:00
|
|
|
p := c.queue[0]
|
|
|
|
copy(c.queue, c.queue[1:])
|
|
|
|
c.queue = c.queue[:len(c.queue)-1]
|
2019-04-30 06:13:22 -05:00
|
|
|
return p, true
|
2015-03-25 10:45:53 -05:00
|
|
|
}
|