forked from cerc-io/plugeth
p2p/simulation: move connection methods from swarm/network/simulation (#18323)
This commit is contained in:
@@ -505,7 +505,8 @@ func testDeliveryFromNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck
|
||||
result := sim.Run(ctx, func(ctx context.Context, sim *simulation.Simulation) error {
|
||||
nodeIDs := sim.UpNodeIDs()
|
||||
//determine the pivot node to be the first node of the simulation
|
||||
sim.SetPivotNode(nodeIDs[0])
|
||||
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
|
||||
@@ -519,7 +520,7 @@ func testDeliveryFromNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck
|
||||
//...iterate the buckets...
|
||||
for id, bucketVal := range lStores {
|
||||
//...and remove the one which is the pivot node
|
||||
if id == *sim.PivotNodeID() {
|
||||
if id == pivot {
|
||||
continue
|
||||
}
|
||||
//the other ones are added to the array...
|
||||
@@ -547,7 +548,7 @@ func testDeliveryFromNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck
|
||||
}
|
||||
|
||||
//get the pivot node's filestore
|
||||
item, ok := sim.NodeItem(*sim.PivotNodeID(), bucketKeyFileStore)
|
||||
item, ok := sim.NodeItem(pivot, bucketKeyFileStore)
|
||||
if !ok {
|
||||
return fmt.Errorf("No filestore")
|
||||
}
|
||||
|
||||
@@ -278,13 +278,13 @@ func runRetrievalTest(chunkCount int, nodeCount int) error {
|
||||
}
|
||||
|
||||
//this is the node selected for upload
|
||||
node := sim.RandomUpNode()
|
||||
item, ok := sim.NodeItem(node.ID, bucketKeyStore)
|
||||
node := sim.Net.GetRandomUpNode()
|
||||
item, ok := sim.NodeItem(node.ID(), bucketKeyStore)
|
||||
if !ok {
|
||||
return fmt.Errorf("No localstore")
|
||||
}
|
||||
lstore := item.(*storage.LocalStore)
|
||||
conf.hashes, err = uploadFileToSingleNodeStore(node.ID, chunkCount, lstore)
|
||||
conf.hashes, err = uploadFileToSingleNodeStore(node.ID(), chunkCount, lstore)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -248,20 +248,20 @@ func runSim(conf *synctestConfig, ctx context.Context, sim *simulation.Simulatio
|
||||
|
||||
//get the node at that index
|
||||
//this is the node selected for upload
|
||||
node := sim.RandomUpNode()
|
||||
item, ok := sim.NodeItem(node.ID, bucketKeyStore)
|
||||
node := sim.Net.GetRandomUpNode()
|
||||
item, ok := sim.NodeItem(node.ID(), bucketKeyStore)
|
||||
if !ok {
|
||||
return fmt.Errorf("No localstore")
|
||||
}
|
||||
lstore := item.(*storage.LocalStore)
|
||||
hashes, err := uploadFileToSingleNodeStore(node.ID, chunkCount, lstore)
|
||||
hashes, err := uploadFileToSingleNodeStore(node.ID(), chunkCount, lstore)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, h := range hashes {
|
||||
evt := &simulations.Event{
|
||||
Type: EventTypeChunkCreated,
|
||||
Node: sim.Net.GetNode(node.ID),
|
||||
Node: sim.Net.GetNode(node.ID()),
|
||||
Data: h.String(),
|
||||
}
|
||||
sim.Net.Events().Send(evt)
|
||||
@@ -453,13 +453,13 @@ func testSyncingViaDirectSubscribe(t *testing.T, chunkCount int, nodeCount int)
|
||||
}
|
||||
}
|
||||
//select a random node for upload
|
||||
node := sim.RandomUpNode()
|
||||
item, ok := sim.NodeItem(node.ID, bucketKeyStore)
|
||||
node := sim.Net.GetRandomUpNode()
|
||||
item, ok := sim.NodeItem(node.ID(), bucketKeyStore)
|
||||
if !ok {
|
||||
return fmt.Errorf("No localstore")
|
||||
}
|
||||
lstore := item.(*storage.LocalStore)
|
||||
hashes, err := uploadFileToSingleNodeStore(node.ID, chunkCount, lstore)
|
||||
hashes, err := uploadFileToSingleNodeStore(node.ID(), chunkCount, lstore)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ func TestNonExistingHashesWithServer(t *testing.T) {
|
||||
|
||||
result := sim.Run(ctx, func(ctx context.Context, sim *simulation.Simulation) error {
|
||||
//check on the node's FileStore (netstore)
|
||||
id := sim.RandomUpNode().ID
|
||||
id := sim.Net.GetRandomUpNode().ID()
|
||||
item, ok := sim.NodeItem(id, bucketKeyFileStore)
|
||||
if !ok {
|
||||
t.Fatalf("No filestore")
|
||||
|
||||
Reference in New Issue
Block a user