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

Function FindNodeInBP

rpc/mux/resolve.go:128–159  ·  view source on GitHub ↗

FindNodeInBP find node in block producer dht service.

(id *proto.RawNodeID)

Source from the content-addressed store, hash-verified

126
127// FindNodeInBP find node in block producer dht service.
128func FindNodeInBP(id *proto.RawNodeID) (node *proto.Node, err error) {
129 bps := route.GetBPs()
130 if len(bps) == 0 {
131 err = errors.New("no available BP")
132 return
133 }
134 client := NewCaller()
135 req := &proto.FindNodeReq{
136 ID: proto.NodeID(id.String()),
137 }
138 resp := new(proto.FindNodeResp)
139 bpCount := len(bps)
140 offset := rand.Intn(bpCount)
141 method := route.DHTFindNode.String()
142
143 for i := 0; i != bpCount; i++ {
144 bp := bps[(offset+i)%bpCount]
145 err = client.CallNode(bp, method, req, resp)
146 if err == nil {
147 node = resp.Node
148 return
149 }
150
151 log.WithFields(log.Fields{
152 "method": method,
153 "bp": bp,
154 }).WithError(err).Warning("call dht rpc failed")
155 }
156
157 err = errors.Wrapf(err, "could not find node in all block producers")
158 return
159}
160
161// PingBP Send DHT.Ping Request with Anonymous ETLS session.
162func PingBP(node *proto.Node, BPNodeID proto.NodeID) (err error) {

Callers 2

GetNodeAddrFunction · 0.85
GetNodeInfoFunction · 0.85

Calls 9

CallNodeMethod · 0.95
GetBPsFunction · 0.92
NodeIDTypeAlias · 0.92
WithFieldsFunction · 0.92
WarningMethod · 0.80
WithErrorMethod · 0.80
NewCallerFunction · 0.70
NewMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected