2018-06-20 15:06:27 +03: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 (
|
|
|
|
"context"
|
2019-02-13 15:03:23 +03:00
|
|
|
"errors"
|
2018-06-20 15:06:27 +03:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2018-09-13 12:42:19 +03:00
|
|
|
"runtime"
|
2018-06-20 15:06:27 +03:00
|
|
|
"sync"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/ethereum/go-ethereum/log"
|
2018-07-30 23:55:25 +03:00
|
|
|
"github.com/ethereum/go-ethereum/node"
|
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-25 01:59:00 +03:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
2018-10-08 21:28:44 +03:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/simulations"
|
2018-06-20 15:06:27 +03:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/simulations/adapters"
|
|
|
|
"github.com/ethereum/go-ethereum/swarm/network"
|
2018-07-30 23:55:25 +03:00
|
|
|
"github.com/ethereum/go-ethereum/swarm/network/simulation"
|
2018-06-20 15:06:27 +03:00
|
|
|
"github.com/ethereum/go-ethereum/swarm/pot"
|
2018-07-30 23:55:25 +03:00
|
|
|
"github.com/ethereum/go-ethereum/swarm/state"
|
2018-06-20 15:06:27 +03:00
|
|
|
"github.com/ethereum/go-ethereum/swarm/storage"
|
2018-11-21 22:49:13 +03:00
|
|
|
"github.com/ethereum/go-ethereum/swarm/storage/mock"
|
|
|
|
mockmem "github.com/ethereum/go-ethereum/swarm/storage/mock/mem"
|
2018-11-14 11:21:14 +03:00
|
|
|
"github.com/ethereum/go-ethereum/swarm/testutil"
|
2018-06-20 15:06:27 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type synctestConfig struct {
|
2018-09-13 12:42:19 +03:00
|
|
|
addrs [][]byte
|
|
|
|
hashes []storage.Address
|
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-25 01:59:00 +03:00
|
|
|
idToChunksMap map[enode.ID][]int
|
2018-09-13 12:42:19 +03:00
|
|
|
//chunksToNodesMap map[string][]int
|
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-25 01:59:00 +03:00
|
|
|
addrToIDMap map[string]enode.ID
|
2018-09-13 12:42:19 +03:00
|
|
|
}
|
|
|
|
|
2018-10-08 21:28:44 +03:00
|
|
|
const (
|
|
|
|
// EventTypeNode is the type of event emitted when a node is either
|
|
|
|
// created, started or stopped
|
|
|
|
EventTypeChunkCreated simulations.EventType = "chunkCreated"
|
|
|
|
EventTypeChunkOffered simulations.EventType = "chunkOffered"
|
|
|
|
EventTypeChunkWanted simulations.EventType = "chunkWanted"
|
|
|
|
EventTypeChunkDelivered simulations.EventType = "chunkDelivered"
|
|
|
|
EventTypeChunkArrived simulations.EventType = "chunkArrived"
|
|
|
|
EventTypeSimTerminated simulations.EventType = "simTerminated"
|
|
|
|
)
|
|
|
|
|
2018-09-13 12:42:19 +03:00
|
|
|
// Tests in this file should not request chunks from peers.
|
|
|
|
// This function will panic indicating that there is a problem if request has been made.
|
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-25 01:59:00 +03:00
|
|
|
func dummyRequestFromPeers(_ context.Context, req *network.Request) (*enode.ID, chan struct{}, error) {
|
2018-09-13 12:42:19 +03:00
|
|
|
panic(fmt.Sprintf("unexpected request: address %s, source %s", req.Addr.String(), req.Source.String()))
|
2018-06-20 15:06:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//This test is a syncing test for nodes.
|
|
|
|
//One node is randomly selected to be the pivot node.
|
|
|
|
//A configurable number of chunks and nodes can be
|
|
|
|
//provided to the test, the number of chunks is uploaded
|
|
|
|
//to the pivot node, and we check that nodes get the chunks
|
|
|
|
//they are expected to store based on the syncing protocol.
|
|
|
|
//Number of chunks and nodes can be provided via commandline too.
|
2018-07-30 23:55:25 +03:00
|
|
|
func TestSyncingViaGlobalSync(t *testing.T) {
|
2018-09-13 12:42:19 +03:00
|
|
|
if runtime.GOOS == "darwin" && os.Getenv("TRAVIS") == "true" {
|
|
|
|
t.Skip("Flaky on mac on travis")
|
|
|
|
}
|
2019-02-21 00:57:42 +03:00
|
|
|
|
|
|
|
if testutil.RaceEnabled {
|
|
|
|
t.Skip("Segfaults on Travis with -race")
|
|
|
|
}
|
|
|
|
|
2018-06-20 15:06:27 +03:00
|
|
|
//if nodes/chunks have been provided via commandline,
|
|
|
|
//run the tests with these values
|
|
|
|
if *nodes != 0 && *chunks != 0 {
|
|
|
|
log.Info(fmt.Sprintf("Running test with %d chunks and %d nodes...", *chunks, *nodes))
|
2018-07-30 23:55:25 +03:00
|
|
|
testSyncingViaGlobalSync(t, *chunks, *nodes)
|
2018-06-20 15:06:27 +03:00
|
|
|
} else {
|
2019-02-21 00:57:42 +03:00
|
|
|
chunkCounts := []int{4, 32}
|
|
|
|
nodeCounts := []int{32, 16}
|
|
|
|
|
2018-06-20 15:06:27 +03:00
|
|
|
//if the `longrunning` flag has been provided
|
|
|
|
//run more test combinations
|
|
|
|
if *longrunning {
|
2019-03-05 14:54:46 +03:00
|
|
|
chunkCounts = []int{64, 128}
|
|
|
|
nodeCounts = []int{32, 64}
|
2018-06-20 15:06:27 +03:00
|
|
|
}
|
2019-02-21 00:57:42 +03:00
|
|
|
|
|
|
|
for _, chunkCount := range chunkCounts {
|
|
|
|
for _, n := range nodeCounts {
|
|
|
|
log.Info(fmt.Sprintf("Long running test with %d chunks and %d nodes...", chunkCount, n))
|
|
|
|
testSyncingViaGlobalSync(t, chunkCount, n)
|
2018-06-20 15:06:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-08 21:28:44 +03:00
|
|
|
var simServiceMap = map[string]simulation.ServiceFunc{
|
2019-02-01 11:58:46 +03:00
|
|
|
"streamer": func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error) {
|
|
|
|
addr, netStore, delivery, clean, err := newNetStoreAndDeliveryWithRequestFunc(ctx, bucket, dummyRequestFromPeers)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2018-06-20 15:06:27 +03:00
|
|
|
|
2019-02-21 00:57:42 +03:00
|
|
|
store := state.NewInmemoryStore()
|
2019-02-13 15:03:23 +03:00
|
|
|
|
|
|
|
r := NewRegistry(addr.ID(), delivery, netStore, store, &RegistryOptions{
|
2019-02-01 11:58:46 +03:00
|
|
|
Retrieval: RetrievalDisabled,
|
|
|
|
Syncing: SyncingAutoSubscribe,
|
|
|
|
SyncUpdateDelay: 3 * time.Second,
|
|
|
|
}, nil)
|
2018-10-08 21:28:44 +03:00
|
|
|
|
2019-02-01 11:58:46 +03:00
|
|
|
bucket.Store(bucketKeyRegistry, r)
|
|
|
|
|
|
|
|
cleanup = func() {
|
|
|
|
r.Close()
|
|
|
|
clean()
|
|
|
|
}
|
2018-10-08 21:28:44 +03:00
|
|
|
|
2019-02-01 11:58:46 +03:00
|
|
|
return r, cleanup, nil
|
|
|
|
},
|
2018-10-08 21:28:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func testSyncingViaGlobalSync(t *testing.T, chunkCount int, nodeCount int) {
|
|
|
|
sim := simulation.New(simServiceMap)
|
2018-07-30 23:55:25 +03:00
|
|
|
defer sim.Close()
|
2018-06-20 15:06:27 +03:00
|
|
|
|
2018-07-30 23:55:25 +03:00
|
|
|
log.Info("Initializing test config")
|
2018-06-20 15:06:27 +03:00
|
|
|
|
2018-07-30 23:55:25 +03:00
|
|
|
conf := &synctestConfig{}
|
2018-06-20 15:06:27 +03:00
|
|
|
//map of discover ID to indexes of chunks expected at that ID
|
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-25 01:59:00 +03:00
|
|
|
conf.idToChunksMap = make(map[enode.ID][]int)
|
2018-06-20 15:06:27 +03:00
|
|
|
//map of overlay address to discover ID
|
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-25 01:59:00 +03:00
|
|
|
conf.addrToIDMap = make(map[string]enode.ID)
|
2018-06-20 15:06:27 +03:00
|
|
|
//array where the generated chunk hashes will be stored
|
|
|
|
conf.hashes = make([]storage.Address, 0)
|
2018-07-30 23:55:25 +03:00
|
|
|
|
2019-03-22 13:20:17 +03:00
|
|
|
ctx, cancelSimRun := context.WithTimeout(context.Background(), 3*time.Minute)
|
2018-07-30 23:55:25 +03:00
|
|
|
defer cancelSimRun()
|
|
|
|
|
2019-03-22 13:20:17 +03:00
|
|
|
filename := fmt.Sprintf("testing/snapshot_%d.json", nodeCount)
|
|
|
|
err := sim.UploadSnapshot(ctx, filename)
|
|
|
|
if err != nil {
|
2018-09-13 12:42:19 +03:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-10-08 21:28:44 +03:00
|
|
|
result := runSim(conf, ctx, sim, chunkCount)
|
|
|
|
if result.Error != nil {
|
|
|
|
t.Fatal(result.Error)
|
|
|
|
}
|
|
|
|
log.Info("Simulation ended")
|
|
|
|
}
|
|
|
|
|
|
|
|
func runSim(conf *synctestConfig, ctx context.Context, sim *simulation.Simulation, chunkCount int) simulation.Result {
|
|
|
|
|
2019-02-13 15:03:23 +03:00
|
|
|
return sim.Run(ctx, func(ctx context.Context, sim *simulation.Simulation) (err error) {
|
|
|
|
disconnected := watchDisconnections(ctx, sim)
|
|
|
|
defer func() {
|
|
|
|
if err != nil && disconnected.bool() {
|
|
|
|
err = errors.New("disconnect events received")
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2018-07-30 23:55:25 +03:00
|
|
|
nodeIDs := sim.UpNodeIDs()
|
|
|
|
for _, n := range nodeIDs {
|
|
|
|
//get the kademlia overlay address from this ID
|
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-25 01:59:00 +03:00
|
|
|
a := n.Bytes()
|
2018-07-30 23:55:25 +03:00
|
|
|
//append it to the array of all overlay addresses
|
|
|
|
conf.addrs = append(conf.addrs, a)
|
|
|
|
//the proximity calculation is on overlay addr,
|
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-25 01:59:00 +03:00
|
|
|
//the p2p/simulations check func triggers on enode.ID,
|
2018-07-30 23:55:25 +03:00
|
|
|
//so we need to know which overlay addr maps to which nodeID
|
|
|
|
conf.addrToIDMap[string(a)] = n
|
|
|
|
}
|
|
|
|
|
2018-08-27 11:49:29 +03:00
|
|
|
//get the node at that index
|
2018-07-30 23:55:25 +03:00
|
|
|
//this is the node selected for upload
|
2018-12-17 14:19:01 +03:00
|
|
|
node := sim.Net.GetRandomUpNode()
|
|
|
|
item, ok := sim.NodeItem(node.ID(), bucketKeyStore)
|
2018-07-30 23:55:25 +03:00
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("No localstore")
|
|
|
|
}
|
|
|
|
lstore := item.(*storage.LocalStore)
|
2018-12-17 14:19:01 +03:00
|
|
|
hashes, err := uploadFileToSingleNodeStore(node.ID(), chunkCount, lstore)
|
2018-07-30 23:55:25 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-10-08 21:28:44 +03:00
|
|
|
for _, h := range hashes {
|
|
|
|
evt := &simulations.Event{
|
|
|
|
Type: EventTypeChunkCreated,
|
2018-12-17 14:19:01 +03:00
|
|
|
Node: sim.Net.GetNode(node.ID()),
|
2018-10-08 21:28:44 +03:00
|
|
|
Data: h.String(),
|
|
|
|
}
|
|
|
|
sim.Net.Events().Send(evt)
|
|
|
|
}
|
2018-07-30 23:55:25 +03:00
|
|
|
conf.hashes = append(conf.hashes, hashes...)
|
|
|
|
mapKeysToNodes(conf)
|
|
|
|
|
|
|
|
// File retrieval check is repeated until all uploaded files are retrieved from all nodes
|
|
|
|
// or until the timeout is reached.
|
2018-11-21 22:49:13 +03:00
|
|
|
var globalStore mock.GlobalStorer
|
2018-07-30 23:55:25 +03:00
|
|
|
if *useMockStore {
|
2018-11-21 22:49:13 +03:00
|
|
|
globalStore = mockmem.NewGlobalStore()
|
2018-06-20 15:06:27 +03:00
|
|
|
}
|
2018-10-08 21:28:44 +03:00
|
|
|
REPEAT:
|
|
|
|
for {
|
2018-07-30 23:55:25 +03:00
|
|
|
for _, id := range nodeIDs {
|
|
|
|
//for each expected chunk, check if it is in the local store
|
|
|
|
localChunks := conf.idToChunksMap[id]
|
|
|
|
for _, ch := range localChunks {
|
|
|
|
//get the real chunk by the index in the index array
|
|
|
|
chunk := conf.hashes[ch]
|
|
|
|
log.Trace(fmt.Sprintf("node has chunk: %s:", chunk))
|
|
|
|
//check if the expected chunk is indeed in the localstore
|
|
|
|
var err error
|
|
|
|
if *useMockStore {
|
|
|
|
//use the globalStore if the mockStore should be used; in that case,
|
|
|
|
//the complete localStore stack is bypassed for getting the chunk
|
|
|
|
_, err = globalStore.Get(common.BytesToAddress(id.Bytes()), chunk)
|
|
|
|
} else {
|
|
|
|
//use the actual localstore
|
|
|
|
item, ok := sim.NodeItem(id, bucketKeyStore)
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Error accessing localstore")
|
|
|
|
}
|
|
|
|
lstore := item.(*storage.LocalStore)
|
|
|
|
_, err = lstore.Get(ctx, chunk)
|
|
|
|
}
|
|
|
|
if err != nil {
|
2018-10-19 11:50:25 +03:00
|
|
|
log.Debug(fmt.Sprintf("Chunk %s NOT found for id %s", chunk, id))
|
2018-08-06 12:33:22 +03:00
|
|
|
// Do not get crazy with logging the warn message
|
|
|
|
time.Sleep(500 * time.Millisecond)
|
2018-10-08 21:28:44 +03:00
|
|
|
continue REPEAT
|
2018-07-30 23:55:25 +03:00
|
|
|
}
|
2018-10-08 21:28:44 +03:00
|
|
|
evt := &simulations.Event{
|
|
|
|
Type: EventTypeChunkArrived,
|
|
|
|
Node: sim.Net.GetNode(id),
|
|
|
|
Data: chunk.String(),
|
|
|
|
}
|
|
|
|
sim.Net.Events().Send(evt)
|
|
|
|
log.Debug(fmt.Sprintf("Chunk %s IS FOUND for id %s", chunk, id))
|
2018-09-13 12:42:19 +03:00
|
|
|
}
|
2018-07-30 23:55:25 +03:00
|
|
|
}
|
2018-10-08 21:28:44 +03:00
|
|
|
return nil
|
2018-07-30 23:55:25 +03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2018-06-20 15:06:27 +03:00
|
|
|
|
|
|
|
//map chunk keys to addresses which are responsible
|
|
|
|
func mapKeysToNodes(conf *synctestConfig) {
|
|
|
|
nodemap := make(map[string][]int)
|
|
|
|
//build a pot for chunk hashes
|
|
|
|
np := pot.NewPot(nil, 0)
|
|
|
|
indexmap := make(map[string]int)
|
|
|
|
for i, a := range conf.addrs {
|
|
|
|
indexmap[string(a)] = i
|
|
|
|
np, _, _ = pot.Add(np, a, pof)
|
|
|
|
}
|
2018-09-13 12:42:19 +03:00
|
|
|
|
2019-01-10 14:33:51 +03:00
|
|
|
ppmap := network.NewPeerPotMap(network.NewKadParams().NeighbourhoodSize, conf.addrs)
|
2018-09-13 12:42:19 +03:00
|
|
|
|
2018-06-20 15:06:27 +03:00
|
|
|
//for each address, run EachNeighbour on the chunk hashes pot to identify closest nodes
|
|
|
|
log.Trace(fmt.Sprintf("Generated hash chunk(s): %v", conf.hashes))
|
|
|
|
for i := 0; i < len(conf.hashes); i++ {
|
2018-09-13 12:42:19 +03:00
|
|
|
var a []byte
|
2018-06-20 15:06:27 +03:00
|
|
|
np.EachNeighbour([]byte(conf.hashes[i]), pof, func(val pot.Val, po int) bool {
|
2018-09-13 12:42:19 +03:00
|
|
|
// take the first address
|
|
|
|
a = val.([]byte)
|
|
|
|
return false
|
2018-06-20 15:06:27 +03:00
|
|
|
})
|
2018-09-13 12:42:19 +03:00
|
|
|
|
|
|
|
nns := ppmap[common.Bytes2Hex(a)].NNSet
|
|
|
|
nns = append(nns, a)
|
|
|
|
|
|
|
|
for _, p := range nns {
|
|
|
|
nodemap[string(p)] = append(nodemap[string(p)], i)
|
|
|
|
}
|
2018-06-20 15:06:27 +03:00
|
|
|
}
|
|
|
|
for addr, chunks := range nodemap {
|
|
|
|
//this selects which chunks are expected to be found with the given node
|
2018-07-30 23:55:25 +03:00
|
|
|
conf.idToChunksMap[conf.addrToIDMap[addr]] = chunks
|
2018-06-20 15:06:27 +03:00
|
|
|
}
|
|
|
|
log.Debug(fmt.Sprintf("Map of expected chunks by ID: %v", conf.idToChunksMap))
|
|
|
|
}
|
|
|
|
|
|
|
|
//upload a file(chunks) to a single local node store
|
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-25 01:59:00 +03:00
|
|
|
func uploadFileToSingleNodeStore(id enode.ID, chunkCount int, lstore *storage.LocalStore) ([]storage.Address, error) {
|
2018-06-20 15:06:27 +03:00
|
|
|
log.Debug(fmt.Sprintf("Uploading to node id: %s", id))
|
|
|
|
fileStore := storage.NewFileStore(lstore, storage.NewFileStoreParams())
|
2018-07-30 23:55:25 +03:00
|
|
|
size := chunkSize
|
2018-06-20 15:06:27 +03:00
|
|
|
var rootAddrs []storage.Address
|
|
|
|
for i := 0; i < chunkCount; i++ {
|
2018-11-14 11:21:14 +03:00
|
|
|
rk, wait, err := fileStore.Store(context.TODO(), testutil.RandomReader(i, size), int64(size), false)
|
2018-07-09 15:11:49 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-07-30 23:55:25 +03:00
|
|
|
err = wait(context.TODO())
|
2018-06-20 15:06:27 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
rootAddrs = append(rootAddrs, (rk))
|
|
|
|
}
|
|
|
|
|
|
|
|
return rootAddrs, nil
|
|
|
|
}
|