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

Function handlePeerDiscovery

IceFireDB-SQLite/pkg/p2p/p2p.go:419–437  ·  view source on GitHub ↗

A function that connects the given host to all peers received from a channel of peer address information. Meant to be started as a go routine.

(nodehost host.Host, peerchan <-chan peer.AddrInfo)

Source from the content-addressed store, hash-verified

417// A function that connects the given host to all peers received from a
418// channel of peer address information. Meant to be started as a go routine.
419func handlePeerDiscovery(nodehost host.Host, peerchan <-chan peer.AddrInfo) {
420 // Iterate over the peer channel
421 for peer := range peerchan {
422 // Ignore if the discovered peer is the host itself
423 if peer.ID == nodehost.ID() {
424 continue
425 }
426
427 // Connect to the peer
428 err := nodehost.Connect(context.Background(), peer)
429
430 if err != nil {
431 logrus.Debugln("p2p peer connection failed: ", err)
432 }
433
434 logrus.Debugln("p2p peer connection success: ", peer.ID)
435 log.Println("p2p peer connection success: ", peer.ID)
436 }
437}
438
439// A function that generates a CID object for a given string and returns it.
440// Uses SHA256 to hash the string and generate a multihash from it.

Callers 2

AdvertiseConnectMethod · 0.70
AnnounceConnectMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected