A function that generates a PubSub Handler object and returns it Requires a node host and a routing discovery service.
(ctx context.Context, nodehost host.Host, routingdiscovery *discoveryRouting.RoutingDiscovery)
| 353 | // A function that generates a PubSub Handler object and returns it |
| 354 | // Requires a node host and a routing discovery service. |
| 355 | func setupPubSub(ctx context.Context, nodehost host.Host, routingdiscovery *discoveryRouting.RoutingDiscovery) *pubsub.PubSub { |
| 356 | // Create a new PubSub service which uses a GossipSub router |
| 357 | pubsubhandler, err := pubsub.NewGossipSub(ctx, nodehost, pubsub.WithDiscovery(routingdiscovery)) |
| 358 | // Handle any potential error |
| 359 | if err != nil { |
| 360 | logrus.WithFields(logrus.Fields{ |
| 361 | "error": err.Error(), |
| 362 | "type": "GossipSub", |
| 363 | }).Fatalln("PubSub Handler Creation Failed!") |
| 364 | } |
| 365 | |
| 366 | // Return the PubSub handler |
| 367 | return pubsubhandler |
| 368 | } |
| 369 | |
| 370 | // A function that bootstraps a given Kademlia DHT to satisfy the IPFS router |
| 371 | // interface and connects to all the bootstrap peers provided by libp2p |