FindNodeInBP find node in block producer dht service.
(id *proto.RawNodeID)
| 126 | |
| 127 | // FindNodeInBP find node in block producer dht service. |
| 128 | func 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. |
| 162 | func PingBP(node *proto.Node, BPNodeID proto.NodeID) (err error) { |