MCPcopy Create free account
hub / github.com/DNAProject/DNA / PingHandle

Function PingHandle

p2pserver/message/utils/msg_handler.go:129–148  ·  view source on GitHub ↗

PingHandle handle ping msg from peer

(data *msgTypes.MsgPayload, p2p p2p.P2P, pid *evtActor.PID, args ...interface{})

Source from the content-addressed store, hash-verified

127
128//PingHandle handle ping msg from peer
129func PingHandle(data *msgTypes.MsgPayload, p2p p2p.P2P, pid *evtActor.PID, args ...interface{}) {
130 log.Trace("[p2p]receive ping message", data.Addr, data.Id)
131
132 ping := data.Payload.(*msgTypes.Ping)
133 remotePeer := p2p.GetPeer(data.Id)
134 if remotePeer == nil {
135 log.Debug("[p2p]remotePeer invalid in PingHandle")
136 return
137 }
138 remotePeer.SetHeight(ping.Height)
139
140 height := ledger.DefLedger.GetCurrentBlockHeight()
141 p2p.SetHeight(uint64(height))
142 msg := msgpack.NewPongMsg(uint64(height))
143
144 err := p2p.Send(remotePeer, msg)
145 if err != nil {
146 log.Warn(err)
147 }
148}
149
150///PongHandle handle pong msg from peer
151func PongHandle(data *msgTypes.MsgPayload, p2p p2p.P2P, pid *evtActor.PID, args ...interface{}) {

Callers 1

TestPingHandleFunction · 0.85

Calls 7

TraceFunction · 0.92
DebugFunction · 0.92
WarnFunction · 0.92
GetPeerMethod · 0.65
SetHeightMethod · 0.65
GetCurrentBlockHeightMethod · 0.65
SendMethod · 0.65

Tested by 1

TestPingHandleFunction · 0.68