A function that generates a Kademlia DHT object and returns it
(ctx context.Context, nodehost host.Host)
| 327 | |
| 328 | // A function that generates a Kademlia DHT object and returns it |
| 329 | func setupKadDHT(ctx context.Context, nodehost host.Host) (*dht.IpfsDHT, error) { |
| 330 | // Create DHT server mode option |
| 331 | dhtmode := dht.Mode(dht.ModeServer) |
| 332 | // Retrieve the list of bootstrap peer addresses |
| 333 | bootstrappeers := dht.GetDefaultBootstrapPeerAddrInfos() |
| 334 | // Create the DHT bootstrap peers option |
| 335 | dhtpeers := dht.BootstrapPeers(bootstrappeers...) |
| 336 | |
| 337 | // Trace log |
| 338 | logrus.Traceln("Generated DHT Configuration.") |
| 339 | |
| 340 | // Start a Kademlia DHT on the host in server mode |
| 341 | kaddht, err := dht.New(ctx, nodehost, dhtmode, dhtpeers) |
| 342 | // Handle any potential error |
| 343 | if err != nil { |
| 344 | logrus.WithFields(logrus.Fields{ |
| 345 | "error": err.Error(), |
| 346 | }).Fatalln("Failed to Create the Kademlia DHT!") |
| 347 | } |
| 348 | |
| 349 | // Return the KadDHT |
| 350 | return kaddht, err |
| 351 | } |
| 352 | |
| 353 | // A function that generates a PubSub Handler object and returns it |
| 354 | // Requires a node host and a routing discovery service. |