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

Method AnnounceConnect

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

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

Callers 3

NewFunction · 0.95
NewFunction · 0.95
InitSQLiteFunction · 0.45

Calls 4

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

Tested by

no test coverage detected