@cryptotaxi247 / kubo / commits / 67a6b1454

remove host parameter from StartOnlineServicesWithHost

PeerHost is now initialized before calling it. License: MIT Signed-off-by: vyzo <vyzo@hackzen.org>

vyzo committed Dec 13, 2018 at 09:56 UTC 67a6b1454f0902e355736c93ec0cdd3ec1a5b78b
1 file changed +10 -10
core/core.go
+10 -10
@@ -281,7 +281,7 @@ func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption Routin
281
282 n.PeerHost = peerhost
283
284 - if err := n.startOnlineServicesWithHost(ctx, peerhost, routingOption, pubsub, ipnsps); err != nil {
284 + if err := n.startOnlineServicesWithHost(ctx, routingOption, pubsub, ipnsps); err != nil {
285 return err
286 }
287
@@ -475,7 +475,7 @@ func (n *IpfsNode) HandlePeerFound(p pstore.PeerInfo) {
475
476 // startOnlineServicesWithHost is the set of services which need to be
477 // initialized with the host and _before_ we start listening.
478 -func (n *IpfsNode) startOnlineServicesWithHost(ctx context.Context, host p2phost.Host, routingOption RoutingOption, enablePubsub bool, enableIpnsps bool) error {
478 +func (n *IpfsNode) startOnlineServicesWithHost(ctx context.Context, routingOption RoutingOption, enablePubsub bool, enableIpnsps bool) error {
479 cfg, err := n.Repo.Config()
480 if err != nil {
481 return err
@@ -487,7 +487,7 @@ func (n *IpfsNode) startOnlineServicesWithHost(ctx context.Context, host p2phost
487 opts = append(opts, libp2p.DefaultTransports, libp2p.Transport(quic.NewTransport))
488 }
489
490 - svc, err := autonat.NewAutoNATService(ctx, host, opts...)
490 + svc, err := autonat.NewAutoNATService(ctx, n.PeerHost, opts...)
491 if err != nil {
492 return err
493 }
@@ -510,10 +510,10 @@ func (n *IpfsNode) startOnlineServicesWithHost(ctx context.Context, host p2phost
510 case "":
511 fallthrough
512 case "floodsub":
513 - service, err = pubsub.NewFloodSub(ctx, host, pubsubOptions...)
513 + service, err = pubsub.NewFloodSub(ctx, n.PeerHost, pubsubOptions...)
514
515 case "gossipsub":
516 - service, err = pubsub.NewGossipSub(ctx, host, pubsubOptions...)
516 + service, err = pubsub.NewGossipSub(ctx, n.PeerHost, pubsubOptions...)
517
518 default:
519 err = fmt.Errorf("Unknown pubsub router %s", cfg.Pubsub.Router)
@@ -525,15 +525,15 @@ func (n *IpfsNode) startOnlineServicesWithHost(ctx context.Context, host p2phost
525 n.PubSub = service
526 }
527
528 - // this code is necessary as the host is necessary for tests: mock network constructions
529 - // ignore the libp2p options that actually construct the routing!
528 + // this code is necessary just for tests: mock network constructions
529 + // ignore the libp2p constructor options that actually construct the routing!
530 if n.Routing == nil {
531 - r, err := routingOption(ctx, host, n.Repo.Datastore(), n.RecordValidator)
531 + r, err := routingOption(ctx, n.PeerHost, n.Repo.Datastore(), n.RecordValidator)
532 if err != nil {
533 return err
534 }
535 n.Routing = r
536 - n.PeerHost = rhost.Wrap(host, n.Routing)
536 + n.PeerHost = rhost.Wrap(n.PeerHost, n.Routing)
537 }
538
539 // TODO: I'm not a fan of type assertions like this but the
@@ -556,7 +556,7 @@ func (n *IpfsNode) startOnlineServicesWithHost(ctx context.Context, host p2phost
556 if enableIpnsps {
557 n.PSRouter = psrouter.NewPubsubValueStore(
558 ctx,
559 - host,
559 + n.PeerHost,
560 n.Routing,
561 n.PubSub,
562 n.RecordValidator,