package testutil import ( "testing" bhost "github.com/ipfs/go-libp2p/p2p/host/basic" metrics "github.com/ipfs/go-libp2p/p2p/metrics" inet "github.com/ipfs/go-libp2p/p2p/net" swarm "github.com/ipfs/go-libp2p/p2p/net/swarm" tu "github.com/ipfs/go-libp2p/testutil" peer "gx/ipfs/QmZwZjMVGss5rqYsJVGy18gNbkTJffFyq2x1uJ4e4p3ZAt/go-libp2p-peer" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" ma "gx/ipfs/QmcobAGsCjYt5DXoq9et9L8yR8er7o7Cu3DTvpaq12jYSz/go-multiaddr" ) func GenSwarmNetwork(t *testing.T, ctx context.Context) *swarm.Network { p := tu.RandPeerNetParamsOrFatal(t) ps := peer.NewPeerstore() ps.AddPubKey(p.ID, p.PubKey) ps.AddPrivKey(p.ID, p.PrivKey) n, err := swarm.NewNetwork(ctx, []ma.Multiaddr{p.Addr}, p.ID, ps, metrics.NewBandwidthCounter()) if err != nil { t.Fatal(err) } ps.AddAddrs(p.ID, n.ListenAddresses(), peer.PermanentAddrTTL) return n } func DivulgeAddresses(a, b inet.Network) { id := a.LocalPeer() addrs := a.Peerstore().Addrs(id) b.Peerstore().AddAddrs(id, addrs, peer.PermanentAddrTTL) } func GenHostSwarm(t *testing.T, ctx context.Context) *bhost.BasicHost { n := GenSwarmNetwork(t, ctx) return bhost.New(n) } var RandPeerID = tu.RandPeerID