From 8fe316ba20e407719e1149c14235ff561061f131 Mon Sep 17 00:00:00 2001 From: Fabio Barone Date: Mon, 26 Nov 2018 11:17:10 -0500 Subject: [PATCH] Increase BZZ version due to streamer version change; version tests --- swarm/network/protocol.go | 2 +- swarm/network/stream/syncer_test.go | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/swarm/network/protocol.go b/swarm/network/protocol.go index 66ae94a88b..5ad422db56 100644 --- a/swarm/network/protocol.go +++ b/swarm/network/protocol.go @@ -44,7 +44,7 @@ const ( // BzzSpec is the spec of the generic swarm handshake var BzzSpec = &protocols.Spec{ Name: "bzz", - Version: 7, + Version: 8, MaxMsgSize: 10 * 1024 * 1024, Messages: []interface{}{ HandshakeMsg{}, diff --git a/swarm/network/stream/syncer_test.go b/swarm/network/stream/syncer_test.go index 1787eb928f..f5116f4d1a 100644 --- a/swarm/network/stream/syncer_test.go +++ b/swarm/network/stream/syncer_test.go @@ -233,7 +233,10 @@ func testSyncBetweenNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck } } +//TestSameVersionID just checks that if the version is not changed, +//then streamer peers see each other func TestSameVersionID(t *testing.T) { + //test version ID v := uint(1) sim := simulation.New(map[string]simulation.ServiceFunc{ "streamer": func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error) { @@ -268,7 +271,7 @@ func TestSameVersionID(t *testing.T) { Retrieval: RetrievalDisabled, Syncing: SyncingAutoSubscribe, }, nil) - + //assign to each node the same version ID r.spec.Version = v bucket.Store(bucketKeyRegistry, r) @@ -279,6 +282,7 @@ func TestSameVersionID(t *testing.T) { }) defer sim.Close() + //connect just two nodes log.Info("Adding nodes to simulation") _, err := sim.AddNodesAndConnectChain(2) if err != nil { @@ -287,7 +291,8 @@ func TestSameVersionID(t *testing.T) { log.Info("Starting simulation") ctx := context.Background() - time.Sleep(1 * time.Second) + //make sure they have time to connect + time.Sleep(200 * time.Millisecond) result := sim.Run(ctx, func(ctx context.Context, sim *simulation.Simulation) error { //get the pivot node's filestore nodes := sim.UpNodeIDs() @@ -298,6 +303,7 @@ func TestSameVersionID(t *testing.T) { } registry := item.(*Registry) + //the peers should connect, thus getting the peer should not return nil if registry.getPeer(nodes[1]) == nil { t.Fatal("Expected the peer to not be nil, but it is") } @@ -309,7 +315,10 @@ func TestSameVersionID(t *testing.T) { log.Info("Simulation ended") } +//TestDifferentVersionID proves that if the streamer protocol version doesn't match, +//then the peers are not connected at streamer level func TestDifferentVersionID(t *testing.T) { + //create a variable to hold the version ID v := uint(0) sim := simulation.New(map[string]simulation.ServiceFunc{ "streamer": func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error) { @@ -345,6 +354,7 @@ func TestDifferentVersionID(t *testing.T) { Syncing: SyncingAutoSubscribe, }, nil) + //increase the version ID for each node v++ r.spec.Version = v @@ -356,6 +366,7 @@ func TestDifferentVersionID(t *testing.T) { }) defer sim.Close() + //connect the nodes log.Info("Adding nodes to simulation") _, err := sim.AddNodesAndConnectChain(2) if err != nil { @@ -364,6 +375,8 @@ func TestDifferentVersionID(t *testing.T) { log.Info("Starting simulation") ctx := context.Background() + //make sure they have time to connect + time.Sleep(200 * time.Millisecond) result := sim.Run(ctx, func(ctx context.Context, sim *simulation.Simulation) error { //get the pivot node's filestore nodes := sim.UpNodeIDs() @@ -374,6 +387,7 @@ func TestDifferentVersionID(t *testing.T) { } registry := item.(*Registry) + //getting the other peer should fail due to the different version numbers if registry.getPeer(nodes[1]) != nil { t.Fatal("Expected the peer to be nil, but it is not") }