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

Method AnnounceConnect

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

A method of P2P to connect to service peers. This method uses the Provide() functionality of the Kademlia DHT directly to announce the ability to provide the service and then disovers all peers that provide the same. The peer discovery is handled by a go-routine that will read from a channel of peer

()

Source from the content-addressed store, hash-verified

134// The peer discovery is handled by a go-routine that will read from a channel
135// of peer address information until the peer channel closes
136func (p2p *P2P) AnnounceConnect() {
137 // Generate the Service CID
138 cidvalue := generateCID(p2p.service)
139 // Trace log
140 logrus.Debug("cidvalue ", cidvalue.String())
141 logrus.Traceln("Generated the Service CID.")
142
143 // Announce that this host can provide the service CID
144 err := p2p.KadDHT.Provide(p2p.Ctx, cidvalue, true)
145 if err != nil {
146 logrus.WithFields(logrus.Fields{
147 "error": err.Error(),
148 }).Fatalln("Failed to Announce Service CID!")
149 }
150 // Debug log
151 logrus.Debugln("Announced the p2p Service.")
152 // Sleep to give time for the advertisement to propagate
153 time.Sleep(time.Second * 5)
154
155 // Find the other providers for the service CID
156 peerchan := p2p.KadDHT.FindProvidersAsync(p2p.Ctx, cidvalue, 0)
157 // Trace log
158 logrus.Traceln("Discovered p2p Service Peers.")
159
160 // Connect to peers as they are discovered
161 go handlePeerDiscovery(p2p.Host, peerchan)
162 // Debug log
163 logrus.Debugln("Started Peer Connection Handler.")
164}
165
166// A function that generates the p2p configuration options and creates a
167// libp2p host object for the given context. The created host is returned

Callers 1

connectP2PNetworkFunction · 0.45

Calls 4

generateCIDFunction · 0.70
handlePeerDiscoveryFunction · 0.70
StringMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected