MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / setupKadDHT

Function setupKadDHT

IceFireDB-SQLProxy/pkg/p2p/p2p.go:330–352  ·  view source on GitHub ↗

A function that generates a Kademlia DHT object and returns it

(ctx context.Context, nodehost host.Host)

Source from the content-addressed store, hash-verified

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

Callers 1

setupHostFunction · 0.70

Calls 1

ErrorMethod · 0.45

Tested by

no test coverage detected