From 95d3bbfa1bd763eb2558ed8ceda3a3bb807f2c6f Mon Sep 17 00:00:00 2001 From: vyzo Date: Sat, 23 Nov 2019 17:02:08 +0200 Subject: [PATCH] test prune px with a star topology --- gossipsub_test.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/gossipsub_test.go b/gossipsub_test.go index 90041cc..9a1539b 100644 --- a/gossipsub_test.go +++ b/gossipsub_test.go @@ -9,6 +9,7 @@ import ( "time" "github.com/libp2p/go-libp2p-core/host" + "github.com/libp2p/go-libp2p-core/peerstore" ) func getGossipsub(ctx context.Context, h host.Host, opts ...Option) *PubSub { @@ -923,3 +924,53 @@ func TestGossipsubTreeTopology(t *testing.T) { checkMessageRouting(t, "fizzbuzz", []*PubSub{psubs[9], psubs[3]}, chs) } + +// this tests overlay bootstrapping through px in Gossipsub v1.1 +// we start with a star topology and rely on px through prune to build the mesh +func TestGossipsubStarTopology(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + hosts := getNetHosts(t, ctx, 20) + psubs := getGossipsubs(ctx, hosts) + + // add all peer addresses to the peerstores + // this is necessary because we can't have signed address records witout identify + // pushing them + for i := range hosts { + for j := range hosts { + if i == j { + continue + } + hosts[i].Peerstore().AddAddrs(hosts[j].ID(), hosts[j].Addrs(), peerstore.PermanentAddrTTL) + } + } + + // build the star + for i := 1; i < 20; i++ { + connect(t, hosts[0], hosts[i]) + } + + // build the mesh + var subs []*Subscription + for _, ps := range psubs { + sub, err := ps.Subscribe("test") + if err != nil { + t.Fatal(err) + } + subs = append(subs, sub) + } + + // wait a bit for the mesh to build + time.Sleep(10 * time.Second) + + // send a message from each peer and assert it was propagated + for i := 0; i < 20; i++ { + msg := []byte(fmt.Sprintf("message %d", i)) + psubs[i].Publish("test", msg) + + for _, sub := range subs { + assertReceive(t, sub, msg) + } + } +}