2018-06-20 12:06:27 +00:00
|
|
|
// Copyright 2018 The go-ethereum Authors
|
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package stream
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
2019-01-09 06:05:55 +00:00
|
|
|
"errors"
|
2018-06-20 12:06:27 +00:00
|
|
|
"fmt"
|
|
|
|
"sync"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2018-07-30 20:55:25 +00:00
|
|
|
"github.com/ethereum/go-ethereum/node"
|
|
|
|
"github.com/ethereum/go-ethereum/p2p"
|
2018-11-07 19:33:36 +00:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
|
|
|
"github.com/ethereum/go-ethereum/p2p/protocols"
|
2018-07-30 20:55:25 +00:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/simulations/adapters"
|
2018-06-20 12:06:27 +00:00
|
|
|
p2ptest "github.com/ethereum/go-ethereum/p2p/testing"
|
2019-04-10 14:50:58 +00:00
|
|
|
"github.com/ethereum/go-ethereum/swarm/chunk"
|
2018-06-20 12:06:27 +00:00
|
|
|
"github.com/ethereum/go-ethereum/swarm/log"
|
|
|
|
"github.com/ethereum/go-ethereum/swarm/network"
|
2018-11-07 19:33:36 +00:00
|
|
|
pq "github.com/ethereum/go-ethereum/swarm/network/priorityqueue"
|
2018-07-30 20:55:25 +00:00
|
|
|
"github.com/ethereum/go-ethereum/swarm/network/simulation"
|
|
|
|
"github.com/ethereum/go-ethereum/swarm/state"
|
2018-06-20 12:06:27 +00:00
|
|
|
"github.com/ethereum/go-ethereum/swarm/storage"
|
2018-11-14 08:21:14 +00:00
|
|
|
"github.com/ethereum/go-ethereum/swarm/testutil"
|
2018-06-20 12:06:27 +00:00
|
|
|
)
|
|
|
|
|
2018-11-06 23:04:18 +00:00
|
|
|
//Test requesting a chunk from a peer then issuing a "empty" OfferedHashesMsg (no hashes available yet)
|
|
|
|
//Should time out as the peer does not have the chunk (no syncing happened previously)
|
2018-06-20 12:06:27 +00:00
|
|
|
func TestStreamerUpstreamRetrieveRequestMsgExchangeWithoutStore(t *testing.T) {
|
2019-04-11 08:26:52 +00:00
|
|
|
tester, _, _, teardown, err := newStreamerTester(&RegistryOptions{
|
|
|
|
Syncing: SyncingDisabled, //do no syncing
|
2018-10-17 17:22:37 +00:00
|
|
|
})
|
2018-06-20 12:06:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-02-13 12:03:23 +00:00
|
|
|
defer teardown()
|
2018-06-20 12:06:27 +00: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 22:59:00 +00:00
|
|
|
node := tester.Nodes[0]
|
2018-06-20 12:06:27 +00:00
|
|
|
|
|
|
|
chunk := storage.NewChunk(storage.Address(hash0[:]), nil)
|
|
|
|
|
2018-11-06 23:04:18 +00:00
|
|
|
//test the exchange
|
2018-06-20 12:06:27 +00:00
|
|
|
err = tester.TestExchanges(p2ptest.Exchange{
|
|
|
|
Label: "RetrieveRequestMsg",
|
|
|
|
Triggers: []p2ptest.Trigger{
|
2018-11-06 23:04:18 +00:00
|
|
|
{ //then the actual RETRIEVE_REQUEST....
|
2018-06-20 12:06:27 +00:00
|
|
|
Code: 5,
|
|
|
|
Msg: &RetrieveRequestMsg{
|
2018-09-13 09:42:19 +00:00
|
|
|
Addr: chunk.Address()[:],
|
2018-06-20 12:06:27 +00: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 22:59:00 +00:00
|
|
|
Peer: node.ID(),
|
2018-06-20 12:06:27 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Expects: []p2ptest.Expect{
|
2018-11-06 23:04:18 +00:00
|
|
|
{ //to which the peer responds with offered hashes
|
2018-06-20 12:06:27 +00:00
|
|
|
Code: 1,
|
|
|
|
Msg: &OfferedHashesMsg{
|
|
|
|
HandoverProof: nil,
|
|
|
|
Hashes: nil,
|
|
|
|
From: 0,
|
|
|
|
To: 0,
|
|
|
|
},
|
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 22:59:00 +00:00
|
|
|
Peer: node.ID(),
|
2018-06-20 12:06:27 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-11-06 23:04:18 +00:00
|
|
|
//should fail with a timeout as the peer we are requesting
|
|
|
|
//the chunk from does not have the chunk
|
2019-04-11 08:26:52 +00:00
|
|
|
expectedError := `exchange #0 "RetrieveRequestMsg": timed out`
|
2018-06-20 12:06:27 +00:00
|
|
|
if err == nil || err.Error() != expectedError {
|
|
|
|
t.Fatalf("Expected error %v, got %v", expectedError, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// upstream request server receives a retrieve Request and responds with
|
|
|
|
// offered hashes or delivery if skipHash is set to true
|
|
|
|
func TestStreamerUpstreamRetrieveRequestMsgExchange(t *testing.T) {
|
2019-04-11 08:26:52 +00:00
|
|
|
tester, _, localStore, teardown, err := newStreamerTester(&RegistryOptions{
|
|
|
|
Syncing: SyncingDisabled,
|
2018-10-17 17:22:37 +00:00
|
|
|
})
|
2018-06-20 12:06:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-02-13 12:03:23 +00:00
|
|
|
defer teardown()
|
2018-06-20 12:06:27 +00: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 22:59:00 +00:00
|
|
|
node := tester.Nodes[0]
|
2018-11-06 23:04:18 +00:00
|
|
|
|
2019-04-11 08:26:52 +00:00
|
|
|
hash := storage.Address(hash1[:])
|
|
|
|
ch := storage.NewChunk(hash, hash1[:])
|
2019-04-10 14:50:58 +00:00
|
|
|
_, err = localStore.Put(context.TODO(), chunk.ModePutUpload, ch)
|
2018-09-13 09:42:19 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Expected no err got %v", err)
|
|
|
|
}
|
2018-06-20 12:06:27 +00:00
|
|
|
|
|
|
|
err = tester.TestExchanges(p2ptest.Exchange{
|
|
|
|
Label: "RetrieveRequestMsg",
|
|
|
|
Triggers: []p2ptest.Trigger{
|
|
|
|
{
|
|
|
|
Code: 5,
|
|
|
|
Msg: &RetrieveRequestMsg{
|
|
|
|
Addr: hash,
|
|
|
|
},
|
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 22:59:00 +00:00
|
|
|
Peer: node.ID(),
|
2018-06-20 12:06:27 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Expects: []p2ptest.Expect{
|
|
|
|
{
|
|
|
|
Code: 6,
|
|
|
|
Msg: &ChunkDeliveryMsg{
|
2019-04-11 08:26:52 +00:00
|
|
|
Addr: ch.Address(),
|
|
|
|
SData: ch.Data(),
|
2018-06-20 12:06:27 +00: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 22:59:00 +00:00
|
|
|
Peer: node.ID(),
|
2018-06-20 12:06:27 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-07 19:33:36 +00:00
|
|
|
// if there is one peer in the Kademlia, RequestFromPeers should return it
|
|
|
|
func TestRequestFromPeers(t *testing.T) {
|
|
|
|
dummyPeerID := enode.HexID("3431c3939e1ee2a6345e976a8234f9870152d64879f30bc272a074f6859e75e8")
|
|
|
|
|
|
|
|
addr := network.RandomAddr()
|
|
|
|
to := network.NewKademlia(addr.OAddr, network.NewKadParams())
|
|
|
|
delivery := NewDelivery(to, nil)
|
2019-01-30 13:03:11 +00:00
|
|
|
protocolsPeer := protocols.NewPeer(p2p.NewPeer(dummyPeerID, "dummy", nil), nil, nil)
|
2018-11-07 19:33:36 +00:00
|
|
|
peer := network.NewPeer(&network.BzzPeer{
|
|
|
|
BzzAddr: network.RandomAddr(),
|
|
|
|
LightNode: false,
|
|
|
|
Peer: protocolsPeer,
|
|
|
|
}, to)
|
|
|
|
to.On(peer)
|
2018-11-15 22:41:19 +00:00
|
|
|
r := NewRegistry(addr.ID(), delivery, nil, nil, nil, nil)
|
2018-11-07 19:33:36 +00:00
|
|
|
|
|
|
|
// an empty priorityQueue has to be created to prevent a goroutine being called after the test has finished
|
|
|
|
sp := &Peer{
|
|
|
|
Peer: protocolsPeer,
|
|
|
|
pq: pq.New(int(PriorityQueue), PriorityQueueCap),
|
|
|
|
streamer: r,
|
|
|
|
}
|
|
|
|
r.setPeer(sp)
|
|
|
|
req := network.NewRequest(
|
|
|
|
storage.Address(hash0[:]),
|
|
|
|
true,
|
|
|
|
&sync.Map{},
|
|
|
|
)
|
|
|
|
ctx := context.Background()
|
|
|
|
id, _, err := delivery.RequestFromPeers(ctx, req)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if *id != dummyPeerID {
|
|
|
|
t.Fatalf("Expected an id, got %v", id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RequestFromPeers should not return light nodes
|
|
|
|
func TestRequestFromPeersWithLightNode(t *testing.T) {
|
|
|
|
dummyPeerID := enode.HexID("3431c3939e1ee2a6345e976a8234f9870152d64879f30bc272a074f6859e75e8")
|
|
|
|
|
|
|
|
addr := network.RandomAddr()
|
|
|
|
to := network.NewKademlia(addr.OAddr, network.NewKadParams())
|
|
|
|
delivery := NewDelivery(to, nil)
|
|
|
|
|
|
|
|
protocolsPeer := protocols.NewPeer(p2p.NewPeer(dummyPeerID, "dummy", nil), nil, nil)
|
|
|
|
// setting up a lightnode
|
|
|
|
peer := network.NewPeer(&network.BzzPeer{
|
|
|
|
BzzAddr: network.RandomAddr(),
|
|
|
|
LightNode: true,
|
|
|
|
Peer: protocolsPeer,
|
|
|
|
}, to)
|
|
|
|
to.On(peer)
|
2018-11-15 22:41:19 +00:00
|
|
|
r := NewRegistry(addr.ID(), delivery, nil, nil, nil, nil)
|
2018-11-07 19:33:36 +00:00
|
|
|
// an empty priorityQueue has to be created to prevent a goroutine being called after the test has finished
|
|
|
|
sp := &Peer{
|
|
|
|
Peer: protocolsPeer,
|
|
|
|
pq: pq.New(int(PriorityQueue), PriorityQueueCap),
|
|
|
|
streamer: r,
|
|
|
|
}
|
|
|
|
r.setPeer(sp)
|
|
|
|
|
|
|
|
req := network.NewRequest(
|
|
|
|
storage.Address(hash0[:]),
|
|
|
|
true,
|
|
|
|
&sync.Map{},
|
|
|
|
)
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
// making a request which should return with "no peer found"
|
|
|
|
_, _, err := delivery.RequestFromPeers(ctx, req)
|
|
|
|
|
|
|
|
expectedError := "no peer found"
|
|
|
|
if err.Error() != expectedError {
|
|
|
|
t.Fatalf("expected '%v', got %v", expectedError, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
func TestStreamerDownstreamChunkDeliveryMsgExchange(t *testing.T) {
|
2019-01-24 16:23:34 +00:00
|
|
|
tester, streamer, localStore, teardown, err := newStreamerTester(&RegistryOptions{
|
2019-04-11 08:26:52 +00:00
|
|
|
Syncing: SyncingDisabled,
|
2018-10-17 17:22:37 +00:00
|
|
|
})
|
2018-06-20 12:06:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-02-13 12:03:23 +00:00
|
|
|
defer teardown()
|
2018-06-20 12:06:27 +00:00
|
|
|
|
|
|
|
streamer.RegisterClientFunc("foo", func(p *Peer, t string, live bool) (Client, error) {
|
|
|
|
return &testClient{
|
|
|
|
t: t,
|
|
|
|
}, nil
|
|
|
|
})
|
|
|
|
|
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 22:59:00 +00:00
|
|
|
node := tester.Nodes[0]
|
2018-06-20 12:06:27 +00:00
|
|
|
|
2018-11-06 23:04:18 +00:00
|
|
|
//subscribe to custom stream
|
2018-06-20 12:06:27 +00:00
|
|
|
stream := NewStream("foo", "", true)
|
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 22:59:00 +00:00
|
|
|
err = streamer.Subscribe(node.ID(), stream, NewRange(5, 8), Top)
|
2018-06-20 12:06:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Expected no error, got %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
chunkKey := hash0[:]
|
|
|
|
chunkData := hash1[:]
|
|
|
|
|
|
|
|
err = tester.TestExchanges(p2ptest.Exchange{
|
|
|
|
Label: "Subscribe message",
|
|
|
|
Expects: []p2ptest.Expect{
|
2018-11-06 23:04:18 +00:00
|
|
|
{ //first expect subscription to the custom stream...
|
2018-06-20 12:06:27 +00:00
|
|
|
Code: 4,
|
|
|
|
Msg: &SubscribeMsg{
|
|
|
|
Stream: stream,
|
|
|
|
History: NewRange(5, 8),
|
|
|
|
Priority: Top,
|
|
|
|
},
|
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 22:59:00 +00:00
|
|
|
Peer: node.ID(),
|
2018-06-20 12:06:27 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
p2ptest.Exchange{
|
2018-09-13 09:42:19 +00:00
|
|
|
Label: "ChunkDelivery message",
|
2018-06-20 12:06:27 +00:00
|
|
|
Triggers: []p2ptest.Trigger{
|
2018-11-06 23:04:18 +00:00
|
|
|
{ //...then trigger a chunk delivery for the given chunk from peer in order for
|
|
|
|
//local node to get the chunk delivered
|
2018-06-20 12:06:27 +00:00
|
|
|
Code: 6,
|
|
|
|
Msg: &ChunkDeliveryMsg{
|
|
|
|
Addr: chunkKey,
|
|
|
|
SData: chunkData,
|
|
|
|
},
|
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 22:59:00 +00:00
|
|
|
Peer: node.ID(),
|
2018-06-20 12:06:27 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Expected no error, got %v", err)
|
|
|
|
}
|
2018-09-13 09:42:19 +00:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
// wait for the chunk to get stored
|
2019-04-10 14:50:58 +00:00
|
|
|
storedChunk, err := localStore.Get(ctx, chunk.ModeGetRequest, chunkKey)
|
2018-09-13 09:42:19 +00:00
|
|
|
for err != nil {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
t.Fatalf("Chunk is not in localstore after timeout, err: %v", err)
|
|
|
|
default:
|
|
|
|
}
|
2019-04-10 14:50:58 +00:00
|
|
|
storedChunk, err = localStore.Get(ctx, chunk.ModeGetRequest, chunkKey)
|
2018-09-13 09:42:19 +00:00
|
|
|
time.Sleep(50 * time.Millisecond)
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Expected no error, got %v", err)
|
|
|
|
}
|
|
|
|
|
2018-09-13 09:42:19 +00:00
|
|
|
if !bytes.Equal(storedChunk.Data(), chunkData) {
|
2018-06-20 12:06:27 +00:00
|
|
|
t.Fatal("Retrieved chunk has different data than original")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDeliveryFromNodes(t *testing.T) {
|
2019-01-06 10:58:57 +00:00
|
|
|
testDeliveryFromNodes(t, 2, dataChunkCount, true)
|
|
|
|
testDeliveryFromNodes(t, 2, dataChunkCount, false)
|
|
|
|
testDeliveryFromNodes(t, 4, dataChunkCount, true)
|
|
|
|
testDeliveryFromNodes(t, 4, dataChunkCount, false)
|
2019-02-20 21:57:42 +00:00
|
|
|
|
|
|
|
if testutil.RaceEnabled {
|
|
|
|
// Travis cannot handle more nodes with -race; would time out.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-01-06 10:58:57 +00:00
|
|
|
testDeliveryFromNodes(t, 8, dataChunkCount, true)
|
|
|
|
testDeliveryFromNodes(t, 8, dataChunkCount, false)
|
|
|
|
testDeliveryFromNodes(t, 16, dataChunkCount, true)
|
|
|
|
testDeliveryFromNodes(t, 16, dataChunkCount, false)
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
|
|
|
|
2019-01-06 10:58:57 +00:00
|
|
|
func testDeliveryFromNodes(t *testing.T, nodes, chunkCount int, skipCheck bool) {
|
2019-02-14 06:51:57 +00:00
|
|
|
t.Helper()
|
|
|
|
t.Run(fmt.Sprintf("testDeliveryFromNodes_%d_%d_skipCheck_%t", nodes, chunkCount, skipCheck), func(t *testing.T) {
|
|
|
|
sim := simulation.New(map[string]simulation.ServiceFunc{
|
|
|
|
"streamer": func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error) {
|
|
|
|
addr, netStore, delivery, clean, err := newNetStoreAndDelivery(ctx, bucket)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
r := NewRegistry(addr.ID(), delivery, netStore, state.NewInmemoryStore(), &RegistryOptions{
|
|
|
|
SkipCheck: skipCheck,
|
|
|
|
Syncing: SyncingDisabled,
|
|
|
|
}, nil)
|
|
|
|
bucket.Store(bucketKeyRegistry, r)
|
|
|
|
|
|
|
|
cleanup = func() {
|
|
|
|
r.Close()
|
|
|
|
clean()
|
|
|
|
}
|
|
|
|
|
|
|
|
return r, cleanup, nil
|
|
|
|
},
|
|
|
|
})
|
|
|
|
defer sim.Close()
|
2018-07-30 20:55:25 +00:00
|
|
|
|
2019-02-14 06:51:57 +00:00
|
|
|
log.Info("Adding nodes to simulation")
|
|
|
|
_, err := sim.AddNodesAndConnectChain(nodes)
|
2018-07-30 20:55:25 +00:00
|
|
|
if err != nil {
|
2019-02-14 06:51:57 +00:00
|
|
|
t.Fatal(err)
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
|
|
|
|
2019-02-14 06:51:57 +00:00
|
|
|
log.Info("Starting simulation")
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
result := sim.Run(ctx, func(ctx context.Context, sim *simulation.Simulation) (err error) {
|
|
|
|
nodeIDs := sim.UpNodeIDs()
|
|
|
|
//determine the pivot node to be the first node of the simulation
|
|
|
|
pivot := nodeIDs[0]
|
|
|
|
|
|
|
|
//distribute chunks of a random file into Stores of nodes 1 to nodes
|
|
|
|
//we will do this by creating a file store with an underlying round-robin store:
|
|
|
|
//the file store will create a hash for the uploaded file, but every chunk will be
|
|
|
|
//distributed to different nodes via round-robin scheduling
|
|
|
|
log.Debug("Writing file to round-robin file store")
|
|
|
|
//to do this, we create an array for chunkstores (length minus one, the pivot node)
|
|
|
|
stores := make([]storage.ChunkStore, len(nodeIDs)-1)
|
|
|
|
//we then need to get all stores from the sim....
|
|
|
|
lStores := sim.NodesItems(bucketKeyStore)
|
|
|
|
i := 0
|
|
|
|
//...iterate the buckets...
|
|
|
|
for id, bucketVal := range lStores {
|
|
|
|
//...and remove the one which is the pivot node
|
|
|
|
if id == pivot {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
//the other ones are added to the array...
|
|
|
|
stores[i] = bucketVal.(storage.ChunkStore)
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
//...which then gets passed to the round-robin file store
|
|
|
|
roundRobinFileStore := storage.NewFileStore(newRoundRobinStore(stores...), storage.NewFileStoreParams())
|
|
|
|
//now we can actually upload a (random) file to the round-robin store
|
|
|
|
size := chunkCount * chunkSize
|
|
|
|
log.Debug("Storing data to file store")
|
|
|
|
fileHash, wait, err := roundRobinFileStore.Store(ctx, testutil.RandomReader(1, size), int64(size), false)
|
|
|
|
// wait until all chunks stored
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = wait(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 09:33:22 +00:00
|
|
|
|
2019-02-14 06:51:57 +00:00
|
|
|
//get the pivot node's filestore
|
|
|
|
item, ok := sim.NodeItem(pivot, bucketKeyFileStore)
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("No filestore")
|
|
|
|
}
|
|
|
|
pivotFileStore := item.(*storage.FileStore)
|
|
|
|
log.Debug("Starting retrieval routine")
|
|
|
|
retErrC := make(chan error)
|
|
|
|
go func() {
|
|
|
|
// start the retrieval on the pivot node - this will spawn retrieve requests for missing chunks
|
|
|
|
// we must wait for the peer connections to have started before requesting
|
|
|
|
n, err := readAll(pivotFileStore, fileHash)
|
|
|
|
log.Info(fmt.Sprintf("retrieved %v", fileHash), "read", n, "err", err)
|
|
|
|
retErrC <- err
|
|
|
|
}()
|
|
|
|
|
|
|
|
disconnected := watchDisconnections(ctx, sim)
|
|
|
|
defer func() {
|
|
|
|
if err != nil && disconnected.bool() {
|
|
|
|
err = errors.New("disconnect events received")
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
//finally check that the pivot node gets all chunks via the root hash
|
|
|
|
log.Debug("Check retrieval")
|
|
|
|
success := true
|
|
|
|
var total int64
|
|
|
|
total, err = readAll(pivotFileStore, fileHash)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
log.Info(fmt.Sprintf("check if %08x is available locally: number of bytes read %v/%v (error: %v)", fileHash, total, size, err))
|
|
|
|
if err != nil || total != int64(size) {
|
|
|
|
success = false
|
|
|
|
}
|
2018-06-20 12:06:27 +00:00
|
|
|
|
2019-02-14 06:51:57 +00:00
|
|
|
if !success {
|
|
|
|
return fmt.Errorf("Test failed, chunks not available on all nodes")
|
|
|
|
}
|
|
|
|
if err := <-retErrC; err != nil {
|
|
|
|
return fmt.Errorf("requesting chunks: %v", err)
|
|
|
|
}
|
|
|
|
log.Debug("Test terminated successfully")
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
if result.Error != nil {
|
|
|
|
t.Fatal(result.Error)
|
2019-01-09 06:05:55 +00:00
|
|
|
}
|
2018-07-30 20:55:25 +00:00
|
|
|
})
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkDeliveryFromNodesWithoutCheck(b *testing.B) {
|
|
|
|
for chunks := 32; chunks <= 128; chunks *= 2 {
|
|
|
|
for i := 2; i < 32; i *= 2 {
|
|
|
|
b.Run(
|
|
|
|
fmt.Sprintf("nodes=%v,chunks=%v", i, chunks),
|
|
|
|
func(b *testing.B) {
|
2019-01-06 10:58:57 +00:00
|
|
|
benchmarkDeliveryFromNodes(b, i, chunks, true)
|
2018-06-20 12:06:27 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkDeliveryFromNodesWithCheck(b *testing.B) {
|
|
|
|
for chunks := 32; chunks <= 128; chunks *= 2 {
|
|
|
|
for i := 2; i < 32; i *= 2 {
|
|
|
|
b.Run(
|
|
|
|
fmt.Sprintf("nodes=%v,chunks=%v", i, chunks),
|
|
|
|
func(b *testing.B) {
|
2019-01-06 10:58:57 +00:00
|
|
|
benchmarkDeliveryFromNodes(b, i, chunks, false)
|
2018-06-20 12:06:27 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-06 10:58:57 +00:00
|
|
|
func benchmarkDeliveryFromNodes(b *testing.B, nodes, chunkCount int, skipCheck bool) {
|
2018-07-30 20:55:25 +00:00
|
|
|
sim := simulation.New(map[string]simulation.ServiceFunc{
|
|
|
|
"streamer": func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error) {
|
2019-02-01 08:58:46 +00:00
|
|
|
addr, netStore, delivery, clean, err := newNetStoreAndDelivery(ctx, bucket)
|
2018-06-20 12:06:27 +00:00
|
|
|
if err != nil {
|
2018-07-30 20:55:25 +00:00
|
|
|
return nil, nil, err
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
2018-07-30 20:55:25 +00: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 22:59:00 +00:00
|
|
|
r := NewRegistry(addr.ID(), delivery, netStore, state.NewInmemoryStore(), &RegistryOptions{
|
2018-07-30 20:55:25 +00:00
|
|
|
SkipCheck: skipCheck,
|
2018-11-06 23:04:18 +00:00
|
|
|
Syncing: SyncingDisabled,
|
2018-07-30 20:55:25 +00:00
|
|
|
SyncUpdateDelay: 0,
|
2018-11-15 22:41:19 +00:00
|
|
|
}, nil)
|
2019-02-01 08:58:46 +00:00
|
|
|
bucket.Store(bucketKeyRegistry, r)
|
2018-07-30 20:55:25 +00:00
|
|
|
|
2019-02-01 08:58:46 +00:00
|
|
|
cleanup = func() {
|
|
|
|
r.Close()
|
|
|
|
clean()
|
|
|
|
}
|
2018-06-20 12:06:27 +00:00
|
|
|
|
2018-07-30 20:55:25 +00:00
|
|
|
return r, cleanup, nil
|
2018-06-20 12:06:27 +00:00
|
|
|
},
|
2018-07-30 20:55:25 +00:00
|
|
|
})
|
|
|
|
defer sim.Close()
|
2018-06-20 12:06:27 +00:00
|
|
|
|
2018-07-30 20:55:25 +00:00
|
|
|
log.Info("Initializing test config")
|
|
|
|
_, err := sim.AddNodesAndConnectChain(nodes)
|
2018-06-20 12:06:27 +00:00
|
|
|
if err != nil {
|
2018-07-30 20:55:25 +00:00
|
|
|
b.Fatal(err)
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
|
|
|
|
2019-02-13 12:03:23 +00:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
2019-01-09 06:05:55 +00:00
|
|
|
result := sim.Run(ctx, func(ctx context.Context, sim *simulation.Simulation) (err error) {
|
2018-07-30 20:55:25 +00:00
|
|
|
nodeIDs := sim.UpNodeIDs()
|
|
|
|
node := nodeIDs[len(nodeIDs)-1]
|
|
|
|
|
|
|
|
item, ok := sim.NodeItem(node, bucketKeyFileStore)
|
|
|
|
if !ok {
|
2019-02-13 12:03:23 +00:00
|
|
|
return errors.New("No filestore")
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
2018-07-30 20:55:25 +00:00
|
|
|
remoteFileStore := item.(*storage.FileStore)
|
|
|
|
|
|
|
|
pivotNode := nodeIDs[0]
|
|
|
|
item, ok = sim.NodeItem(pivotNode, bucketKeyNetStore)
|
|
|
|
if !ok {
|
2019-02-13 12:03:23 +00:00
|
|
|
return errors.New("No filestore")
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
2018-07-30 20:55:25 +00:00
|
|
|
netStore := item.(*storage.NetStore)
|
|
|
|
|
2019-01-10 11:33:51 +00:00
|
|
|
if _, err := sim.WaitTillHealthy(ctx); err != nil {
|
2018-07-30 20:55:25 +00:00
|
|
|
return err
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
2018-07-30 20:55:25 +00:00
|
|
|
|
2019-02-13 12:03:23 +00:00
|
|
|
disconnected := watchDisconnections(ctx, sim)
|
2019-01-09 06:05:55 +00:00
|
|
|
defer func() {
|
2019-02-13 12:03:23 +00:00
|
|
|
if err != nil && disconnected.bool() {
|
|
|
|
err = errors.New("disconnect events received")
|
2018-07-30 20:55:25 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
// benchmark loop
|
|
|
|
b.ResetTimer()
|
2018-06-20 12:06:27 +00:00
|
|
|
b.StopTimer()
|
2018-07-30 20:55:25 +00:00
|
|
|
Loop:
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
// uploading chunkCount random chunks to the last node
|
|
|
|
hashes := make([]storage.Address, chunkCount)
|
|
|
|
for i := 0; i < chunkCount; i++ {
|
|
|
|
// create actual size real chunks
|
|
|
|
ctx := context.TODO()
|
2018-11-14 08:21:14 +00:00
|
|
|
hash, wait, err := remoteFileStore.Store(ctx, testutil.RandomReader(i, chunkSize), int64(chunkSize), false)
|
2018-07-30 20:55:25 +00:00
|
|
|
if err != nil {
|
2019-02-13 12:03:23 +00:00
|
|
|
return fmt.Errorf("store: %v", err)
|
2018-07-30 20:55:25 +00:00
|
|
|
}
|
|
|
|
// wait until all chunks stored
|
|
|
|
err = wait(ctx)
|
|
|
|
if err != nil {
|
2019-02-13 12:03:23 +00:00
|
|
|
return fmt.Errorf("wait store: %v", err)
|
2018-07-30 20:55:25 +00:00
|
|
|
}
|
|
|
|
// collect the hashes
|
|
|
|
hashes[i] = hash
|
|
|
|
}
|
|
|
|
// now benchmark the actual retrieval
|
|
|
|
// netstore.Get is called for each hash in a go routine and errors are collected
|
|
|
|
b.StartTimer()
|
|
|
|
errs := make(chan error)
|
|
|
|
for _, hash := range hashes {
|
|
|
|
go func(h storage.Address) {
|
2019-04-10 14:50:58 +00:00
|
|
|
_, err := netStore.Get(ctx, chunk.ModeGetRequest, h)
|
2018-07-30 20:55:25 +00:00
|
|
|
log.Warn("test check netstore get", "hash", h, "err", err)
|
|
|
|
errs <- err
|
|
|
|
}(hash)
|
|
|
|
}
|
|
|
|
// count and report retrieval errors
|
|
|
|
// if there are misses then chunk timeout is too low for the distance and volume (?)
|
|
|
|
var total, misses int
|
|
|
|
for err := range errs {
|
|
|
|
if err != nil {
|
|
|
|
log.Warn(err.Error())
|
|
|
|
misses++
|
|
|
|
}
|
|
|
|
total++
|
|
|
|
if total == chunkCount {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
b.StopTimer()
|
2018-06-20 12:06:27 +00:00
|
|
|
|
2018-07-30 20:55:25 +00:00
|
|
|
if misses > 0 {
|
|
|
|
err = fmt.Errorf("%v chunk not found out of %v", misses, total)
|
2018-06-20 12:06:27 +00:00
|
|
|
break Loop
|
|
|
|
}
|
|
|
|
}
|
2019-02-13 12:03:23 +00:00
|
|
|
return err
|
2018-07-30 20:55:25 +00:00
|
|
|
})
|
|
|
|
if result.Error != nil {
|
|
|
|
b.Fatal(result.Error)
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|