MCPcopy Create free account
hub / github.com/CPChain/chain / syncerLoop

Method syncerLoop

protocols/cpc/sync.go:141–174  ·  view source on GitHub ↗

syncerLoop is responsible for periodically synchronising with the network, both downloading hashes and blocks as well as handling the announcement handler.

()

Source from the content-addressed store, hash-verified

139// syncerLoop is responsible for periodically synchronising with the network, both
140// downloading hashes and blocks as well as handling the announcement handler.
141func (pm *ProtocolManager) syncerLoop() {
142 // block until account is unlocked
143 <-StartSyncerLoop
144
145 // Start and ensure cleanup of sync mechanisms
146 pm.fetcher.Start()
147 defer pm.fetcher.Stop()
148 // defer pm.downloader.Terminate()
149 defer pm.syncer.Terminate()
150
151 // Wait for different events to fire synchronisation operations
152 forceSync := time.NewTicker(forceSyncCycle)
153 defer forceSync.Stop()
154
155 for {
156 select {
157 case peer := <-pm.newPeerCh:
158 // Make sure we have peers to select from, then sync
159 if pm.peers.Len() < minDesiredPeerCount {
160 break
161 }
162 pm.syncer.AddPeer(peer)
163 // update from peers
164 go pm.synchronize(pm.peers.BestPeer())
165
166 case <-forceSync.C:
167 // Force a sync even if not enough peers are present
168 go pm.synchronize(pm.peers.BestPeer())
169
170 case <-pm.noMorePeers:
171 return
172 }
173 }
174}
175
176func (pm *ProtocolManager) SyncFromPeer(p *p2p.Peer) {
177 id := fmt.Sprintf("%x", p.ID().Bytes()[:8])

Callers 1

StartMethod · 0.95

Calls 7

synchronizeMethod · 0.95
BestPeerMethod · 0.80
StartMethod · 0.65
StopMethod · 0.65
TerminateMethod · 0.65
LenMethod · 0.65
AddPeerMethod · 0.65

Tested by

no test coverage detected