(p *peer, id string, handleTxs bool, handleDporMsgs bool, dporProtocol consensus.Protocol)
| 373 | } |
| 374 | |
| 375 | func (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 | |
| 418 | func (pm *ProtocolManager) handleSyncMsg(msg p2p.Msg, p *peer) error { |
| 419 | // Handle the message depending on its contents |
no test coverage detected