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

Method AdvertiseConnect

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

A method of P2P to connect to service peers. This method uses the Advertise() functionality of the Peer Discovery Service to advertise the service and then disovers all peers advertising the same. The peer discovery is handled by a go-routine that will read from a channel of peer address information

()

Source from the content-addressed store, hash-verified

102// The peer discovery is handled by a go-routine that will read from a channel
103// of peer address information until the peer channel closes
104func (p2p *P2P) AdvertiseConnect() {
105 // Advertise the availability of the service on this node
106 ttl, err := p2p.Discovery.Advertise(p2p.Ctx, p2p.service)
107 // Debug log
108 logrus.Debugln("Advertised the p2p Service.")
109 // Sleep to give time for the advertisement to propagate
110 time.Sleep(time.Second * 5)
111 // Debug log
112 logrus.Debugf("Service Time-to-Live is %s", ttl)
113
114 // Find all peers advertising the same service
115 peerchan, err := p2p.Discovery.FindPeers(p2p.Ctx, p2p.service)
116 // Handle any potential error
117 if err != nil {
118 logrus.WithFields(logrus.Fields{
119 "error": err.Error(),
120 }).Fatalln("P2P Peer Discovery Failed!")
121 }
122 // Trace log
123 logrus.Traceln("Discovered p2p Service Peers.")
124
125 // Connect to peers as they are discovered
126 go handlePeerDiscovery(p2p.Host, peerchan)
127 // Trace log
128 logrus.Traceln("Started Peer Connection Handler.")
129}
130
131// A method of P2P to connect to service peers.
132// This method uses the Provide() functionality of the Kademlia DHT directly to announce

Callers 1

connectP2PNetworkFunction · 0.45

Calls 2

handlePeerDiscoveryFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected