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

Method Ping

route/service.go:99–135  ·  view source on GitHub ↗

Ping RPC adds PingReq.Node to DHT.

(req *proto.PingReq, resp *proto.PingResp)

Source from the content-addressed store, hash-verified

97
98// Ping RPC adds PingReq.Node to DHT.
99func (DHT *DHTService) Ping(req *proto.PingReq, resp *proto.PingResp) (err error) {
100 log.Debugf("got req: %#v", req)
101 if permissionCheckFunc != nil && !permissionCheckFunc(&req.Envelope, DHTPing) {
102 err = fmt.Errorf("calling Ping from node %s is not permitted", req.GetNodeID())
103 log.Error(err)
104 return
105 }
106
107 // BP node is not permitted to set by RPC
108 if req.Node.Role == proto.Leader || req.Node.Role == proto.Follower {
109 err = fmt.Errorf("setting %s node is not permitted", req.Node.Role.String())
110 log.Error(err)
111 return
112 }
113
114 // Checking if ID Nonce Pubkey matched
115 if !kms.IsIDPubNonceValid(req.Node.ID.ToRawNodeID(), &req.Node.Nonce, req.Node.PublicKey) {
116 err = fmt.Errorf("node: %s nonce public key not match", req.Node.ID)
117 log.Error(err)
118 return
119 }
120
121 // Checking MinNodeIDDifficulty
122 if req.Node.ID.Difficulty() < conf.GConf.MinNodeIDDifficulty {
123 err = fmt.Errorf("node: %s difficulty too low", req.Node.ID)
124 log.Error(err)
125 return
126 }
127
128 err = DHT.Consistent.Add(req.Node)
129 if err != nil {
130 err = fmt.Errorf("DHT.Consistent.Add %v failed: %s", req.Node, err)
131 } else {
132 resp.Msg = "Pong"
133 }
134 return
135}

Callers 1

OpenSQLiteDBAsGorpFunction · 0.80

Calls 9

DebugfFunction · 0.92
ErrorFunction · 0.92
IsIDPubNonceValidFunction · 0.92
ErrorfMethod · 0.80
ToRawNodeIDMethod · 0.80
GetNodeIDMethod · 0.65
StringMethod · 0.45
DifficultyMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected