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

Method FindNeighbor

route/service.go:77–96  ·  view source on GitHub ↗

FindNeighbor RPC returns FindNeighborReq.Count closest node from DHT.

(req *proto.FindNeighborReq, resp *proto.FindNeighborResp)

Source from the content-addressed store, hash-verified

75
76// FindNeighbor RPC returns FindNeighborReq.Count closest node from DHT.
77func (DHT *DHTService) FindNeighbor(req *proto.FindNeighborReq, resp *proto.FindNeighborResp) (err error) {
78 if permissionCheckFunc != nil && !permissionCheckFunc(&req.Envelope, DHTFindNeighbor) {
79 err = fmt.Errorf("calling from node %s is not permitted", req.GetNodeID())
80 log.Error(err)
81 return
82 }
83
84 nodes, err := DHT.Consistent.GetNeighborsEx(string(req.ID), req.Count, req.Roles)
85 if err != nil {
86 err = fmt.Errorf("get nodes from DHT failed: %s", err)
87 log.Error(err)
88 return
89 }
90 resp.Nodes = nodes
91 log.WithFields(log.Fields{
92 "neighCount": len(nodes),
93 "req": req,
94 }).Debug("found nodes for find neighbor request")
95 return
96}
97
98// Ping RPC adds PingReq.Node to DHT.
99func (DHT *DHTService) Ping(req *proto.PingReq, resp *proto.PingResp) (err error) {

Callers

nothing calls this directly

Calls 6

ErrorFunction · 0.92
WithFieldsFunction · 0.92
ErrorfMethod · 0.80
GetNeighborsExMethod · 0.80
DebugMethod · 0.80
GetNodeIDMethod · 0.65

Tested by

no test coverage detected