MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / RegisterNodeToBP

Function RegisterNodeToBP

rpc/mux/resolve.go:254–300  ·  view source on GitHub ↗

RegisterNodeToBP registers the current node to bp network.

(timeout time.Duration)

Source from the content-addressed store, hash-verified

252
253// RegisterNodeToBP registers the current node to bp network.
254func RegisterNodeToBP(timeout time.Duration) (err error) {
255 // get local node id
256 localNodeID, err := kms.GetLocalNodeID()
257 if err != nil {
258 err = errors.Wrap(err, "register node to BP")
259 return
260 }
261
262 // get local node info
263 localNodeInfo, err := kms.GetNodeInfo(localNodeID)
264 if err != nil {
265 err = errors.Wrap(err, "register node to BP")
266 return
267 }
268
269 log.WithField("node", localNodeInfo).Debug("construct local node info")
270
271 pingWaitCh := make(chan proto.NodeID)
272 bpNodeIDs := route.GetBPs()
273 for _, bpNodeID := range bpNodeIDs {
274 go func(ch chan proto.NodeID, id proto.NodeID) {
275 for {
276 err := PingBP(localNodeInfo, id)
277 if err == nil {
278 log.Infof("ping BP succeed: %v", localNodeInfo)
279 select {
280 case ch <- id:
281 default:
282 }
283 return
284 }
285
286 log.Warnf("ping BP failed: %v", err)
287 time.Sleep(3 * time.Second)
288 }
289 }(pingWaitCh, bpNodeID)
290 }
291
292 select {
293 case bp := <-pingWaitCh:
294 log.WithField("BP", bp).Infof("ping BP succeed")
295 case <-time.After(timeout):
296 return errors.New("ping BP timeout")
297 }
298
299 return
300}

Callers 1

initNodeFunction · 0.92

Calls 10

GetLocalNodeIDFunction · 0.92
GetNodeInfoFunction · 0.92
WithFieldFunction · 0.92
GetBPsFunction · 0.92
InfofFunction · 0.92
WarnfFunction · 0.92
PingBPFunction · 0.85
DebugMethod · 0.80
InfofMethod · 0.80
NewMethod · 0.65

Tested by

no test coverage detected