MCPcopy Create free account
hub / github.com/CPChain/chain / handleMsg

Method handleMsg

protocols/cpc/handler.go:375–416  ·  view source on GitHub ↗
(p *peer, id string, handleTxs bool, handleDporMsgs bool, dporProtocol consensus.Protocol)

Source from the content-addressed store, hash-verified

373}
374
375func (pm *ProtocolManager) handleMsg(p *peer, id string, handleTxs bool, handleDporMsgs bool, dporProtocol consensus.Protocol) (string, error) {
376
377 msg, err := p.rw.ReadMsg()
378 if err != nil {
379 return id, err
380 }
381
382 if msg.Size > ProtocolMaxMsgSize {
383 log.Warn("err when checking msg size", "size", msg.Size)
384 return id, errResp(ErrMsgTooLarge, "%v > %v", msg.Size, ProtocolMaxMsgSize)
385 }
386
387 defer msg.Discard()
388
389 // if I am a validator, do not waste time to handle tx msg
390 if msg.Code == TxMsg && !handleTxs {
391 return id, nil
392 }
393
394 switch {
395 case backend.IsSyncMsg(msg):
396 switch err = pm.handleSyncMsg(msg, p); err {
397 case nil:
398
399 default:
400 log.Warn("err when handling sync msg", "err", err)
401 }
402
403 case backend.IsDporMsg(msg) && handleDporMsgs:
404 switch id, err = dporProtocol.HandleMsg(id, p.version, p.Peer, p.rw, msg); err {
405 case nil:
406
407 default:
408 log.Warn("err when handling dpor msg", "err", err)
409 }
410
411 default:
412 log.Warn("unknown msg code", "msg", msg.Code)
413 }
414
415 return id, err
416}
417
418func (pm *ProtocolManager) handleSyncMsg(msg p2p.Msg, p *peer) error {
419 // Handle the message depending on its contents

Callers 1

handlePeerMethod · 0.95

Calls 6

handleSyncMsgMethod · 0.95
errRespFunction · 0.70
WarnMethod · 0.65
DiscardMethod · 0.65
HandleMsgMethod · 0.65
ReadMsgMethod · 0.45

Tested by

no test coverage detected