func logRoutingErrDifferentPeers(ctx context.Context, wanted, got peer.ID, err error) { lm := make(lgbl.DeferredMap) lm["error"] = err lm["wantedPeer"] = func() interface{} { return wanted.Pretty() } lm["gotPeer"] = func() interface{} { return got.Pretty() } log.Event(ctx, "routingError", lm) }
// create a 'Host' with a random peer to listen on the given address func makeBasicHost(listen string, secio bool) (host.Host, error) { addr, err := ma.NewMultiaddr(listen) if err != nil { return nil, err } ps := pstore.NewPeerstore() var pid peer.ID if secio { ident, err := testutil.RandIdentity() if err != nil { return nil, err } ident.PrivateKey() ps.AddPrivKey(ident.ID(), ident.PrivateKey()) ps.AddPubKey(ident.ID(), ident.PublicKey()) pid = ident.ID() } else { fakepid, err := testutil.RandPeerID() if err != nil { return nil, err } pid = fakepid } ctx := context.Background() // create a new swarm to be used by the service host netw, err := swarm.NewNetwork(ctx, []ma.Multiaddr{addr}, pid, ps, nil) if err != nil { return nil, err } log.Printf("I am %s/ipfs/%s\n", addr, pid.Pretty()) return bhost.New(netw), nil }