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

Function TestEncPingFindNeighbor

rpc/mux/server_test.go:272–352  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

270}
271
272func TestEncPingFindNeighbor(t *testing.T) {
273 utils.RemoveAll(PubKeyStorePath + "*")
274 defer utils.RemoveAll(PubKeyStorePath + "*")
275 log.SetLevel(log.FatalLevel)
276 addr := "127.0.0.1:0"
277 masterKey := []byte("abc")
278 dht, err := route.NewDHTService(PubKeyStorePath, new(consistent.KMSStorage), true)
279
280 server, err := NewServerWithService(ServiceMap{route.DHTRPCName: dht})
281 if err != nil {
282 log.Fatal(err)
283 }
284
285 _ = server.InitRPCServer(addr, "../keys/test.key", masterKey)
286 go server.Serve()
287
288 publicKey, err := kms.GetLocalPublicKey()
289 nonce := asymmetric.GetPubKeyNonce(publicKey, 10, 100*time.Millisecond, nil)
290 serverNodeID := proto.NodeID(nonce.Hash.String())
291 _ = kms.SetPublicKey(serverNodeID, nonce.Nonce, publicKey)
292
293 kms.SetLocalNodeIDNonce(nonce.Hash.CloneBytes(), &nonce.Nonce)
294 _ = route.SetNodeAddrCache(&proto.RawNodeID{Hash: nonce.Hash}, server.Listener.Addr().String())
295
296 client, err := rpc.DialToNodeWithPool(&nilSessionPool{}, serverNodeID, false)
297 if err != nil {
298 log.Fatal(err)
299 }
300
301 node1 := proto.NewNode()
302 _ = node1.InitNodeCryptoInfo(100 * time.Millisecond)
303
304 reqA := &proto.PingReq{
305 Node: *node1,
306 }
307
308 respA := new(proto.PingResp)
309 err = client.Call("DHT.Ping", reqA, respA)
310 if err != nil {
311 log.Fatal(err)
312 }
313 log.Debugf("respA: %v", respA)
314
315 node2 := proto.NewNode()
316 _ = node2.InitNodeCryptoInfo(100 * time.Millisecond)
317
318 reqB := &proto.PingReq{
319 Node: *node2,
320 }
321
322 respB := new(proto.PingResp)
323 err = client.Call("DHT.Ping", reqB, respB)
324 if err != nil {
325 log.Fatal(err)
326 }
327 log.Debugf("respB: %v", respB)
328
329 req := &proto.FindNeighborReq{

Callers

nothing calls this directly

Calls 15

InitNodeCryptoInfoMethod · 0.95
RemoveAllFunction · 0.92
SetLevelFunction · 0.92
NewDHTServiceFunction · 0.92
FatalFunction · 0.92
GetLocalPublicKeyFunction · 0.92
GetPubKeyNonceFunction · 0.92
NodeIDTypeAlias · 0.92
SetPublicKeyFunction · 0.92
SetLocalNodeIDNonceFunction · 0.92
SetNodeAddrCacheFunction · 0.92
DialToNodeWithPoolFunction · 0.92

Tested by

no test coverage detected