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

Function setupKadDHT

IceFireDB-SQLite/pkg/p2p/p2p.go:329–351  ·  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

327
328// A function that generates a Kademlia DHT object and returns it
329func 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.

Callers 1

setupHostFunction · 0.70

Calls 1

ErrorMethod · 0.45

Tested by

no test coverage detected