Browse Source

ProposalMessage wrapper, warn on unknown messages

pull/55/head
Jae Kwon 10 years ago
parent
commit
5b1c1eb0e0
4 changed files with 22 additions and 6 deletions
  1. +1
    -0
      blockchain/reactor.go
  2. +18
    -6
      consensus/reactor.go
  3. +2
    -0
      mempool/reactor.go
  4. +1
    -0
      p2p/pex_reactor.go

+ 1
- 0
blockchain/reactor.go View File

@ -270,6 +270,7 @@ func DecodeMessage(bz []byte) (msgType byte, msg interface{}, err error) {
case msgTypePeerStatus:
msg = binary.ReadBinary(bcPeerStatusMessage{}, r, n, &err)
default:
log.Warn(Fmt("Ignoring unknown message %X", bz))
msg = nil
}
return


+ 18
- 6
consensus/reactor.go View File

@ -152,9 +152,9 @@ func (conR *ConsensusReactor) Receive(chId byte, peer *p2p.Peer, msgBytes []byte
case DataChannel:
switch msg := msg_.(type) {
case *Proposal:
ps.SetHasProposal(msg)
err = conR.conS.SetProposal(msg)
case *ProposalMessage:
ps.SetHasProposal(msg.Proposal)
err = conR.conS.SetProposal(msg.Proposal)
case *PartMessage:
if msg.Type == partTypeProposalBlock {
@ -374,7 +374,7 @@ OUTER_LOOP:
// Send proposal?
if rs.Proposal != nil && !prs.Proposal {
msg := p2p.TypedMessage{msgTypeProposal, rs.Proposal}
msg := &ProposalMessage{Proposal: rs.Proposal}
peer.Send(DataChannel, msg)
ps.SetHasProposal(rs.Proposal)
continue OUTER_LOOP
@ -777,8 +777,7 @@ func DecodeMessage(bz []byte) (msgType byte, msg interface{}, err error) {
msg = binary.ReadBinary(&CommitStepMessage{}, r, n, &err)
// Messages of data
case msgTypeProposal:
r.ReadByte() // Consume the byte
msg = binary.ReadBinary(&Proposal{}, r, n, &err)
msg = binary.ReadBinary(&ProposalMessage{}, r, n, &err)
case msgTypePart:
msg = binary.ReadBinary(&PartMessage{}, r, n, &err)
case msgTypeVote:
@ -786,6 +785,7 @@ func DecodeMessage(bz []byte) (msgType byte, msg interface{}, err error) {
case msgTypeHasVote:
msg = binary.ReadBinary(&HasVoteMessage{}, r, n, &err)
default:
log.Warn(Fmt("Ignoring unknown message %X", bz))
msg = nil
}
return
@ -822,6 +822,18 @@ func (m *CommitStepMessage) String() string {
//-------------------------------------
type ProposalMessage struct {
Proposal *Proposal
}
func (m *ProposalMessage) TypeByte() byte { return msgTypeProposal }
func (m *ProposalMessage) String() string {
return fmt.Sprintf("[Proposal %v]", m.Proposal)
}
//-------------------------------------
const (
partTypeProposalBlock = byte(0x01)
partTypeProposalPOL = byte(0x02)


+ 2
- 0
mempool/reactor.go View File

@ -6,6 +6,7 @@ import (
"sync/atomic"
"github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common"
"github.com/tendermint/tendermint/events"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/types"
@ -135,6 +136,7 @@ func DecodeMessage(bz []byte) (msgType byte, msg interface{}, err error) {
case msgTypeTx:
msg = binary.ReadBinary(&TxMessage{}, r, n, &err)
default:
log.Warn(Fmt("Ignoring unknown message %X", bz))
msg = nil
}
return


+ 1
- 0
p2p/pex_reactor.go View File

@ -239,6 +239,7 @@ func DecodeMessage(bz []byte) (msg interface{}, err error) {
case msgTypeAddrs:
msg = binary.ReadBinary(&pexAddrsMessage{}, r, n, &err)
default:
log.Warn(Fmt("Ignoring unknown message %X", bz))
msg = nil
}
return


Loading…
Cancel
Save