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)
| 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. |
| 419 | func 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. |
no outgoing calls
no test coverage detected