mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-10 09:52:20 +08:00

I needed the network implementation in its own package, because I'll be writing several services that will plug into _it_ that shouldn't be part of the core net package. and then there were dependency conflicts. yay. mux + identify are good examples of what i mean.
32 lines
773 B
Go
32 lines
773 B
Go
package testutil
|
|
|
|
import (
|
|
"testing"
|
|
|
|
inet "github.com/jbenet/go-ipfs/net"
|
|
in "github.com/jbenet/go-ipfs/net/ipfsnet"
|
|
peer "github.com/jbenet/go-ipfs/peer"
|
|
tu "github.com/jbenet/go-ipfs/util/testutil"
|
|
|
|
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
|
|
)
|
|
|
|
func GenNetwork(t *testing.T, ctx context.Context) *in.Network {
|
|
p := tu.RandPeerNetParamsOrFatal(t)
|
|
ps := peer.NewPeerstore()
|
|
ps.AddAddress(p.ID, p.Addr)
|
|
ps.AddPubKey(p.ID, p.PubKey)
|
|
ps.AddPrivKey(p.ID, p.PrivKey)
|
|
n, err := in.NewNetwork(ctx, ps.Addresses(p.ID), p.ID, ps)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return n
|
|
}
|
|
|
|
func DivulgeAddresses(a, b inet.Network) {
|
|
id := a.LocalPeer()
|
|
addrs := a.Peerstore().Addresses(id)
|
|
b.Peerstore().AddAddresses(id, addrs)
|
|
}
|