Skip to content

Commit

Permalink
[FAB-3349] Keep gossip proto fields be with underscores
Browse files Browse the repository at this point in the history
The fields in proto message definitions should not be CamelCase but should
be with underscores.

Therefore we should change the proto field channelMAC to channel_mac
And also secretEnvelope to secret_envelope

Change-Id: I8c99ebd0d06d5a87024888e1bf6664c7131be961
Signed-off-by: Yacov Manevich <yacovm@il.ibm.com>
  • Loading branch information
yacovm committed May 2, 2017
1 parent 5b80e47 commit c220290
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 121 deletions.
14 changes: 7 additions & 7 deletions gossip/gossip/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,9 @@ func (gc *gossipChannel) handleStateInfSnapshot(m *proto.GossipMessage, sender c
}

expectedMAC := GenerateMAC(si.PkiId, gc.chainID)
if !bytes.Equal(si.ChannelMAC, expectedMAC) {
if !bytes.Equal(si.Channel_MAC, expectedMAC) {
gc.logger.Warning("Channel", chanName, ": StateInfo message", stateInf,
", has an invalid MAC. Expected", expectedMAC, ", got", si.ChannelMAC, ", sent from", sender)
", has an invalid MAC. Expected", expectedMAC, ", got", si.Channel_MAC, ", sent from", sender)
return
}
err = gc.ValidateStateInfoMessage(stateInf)
Expand Down Expand Up @@ -589,8 +589,8 @@ func (gc *gossipChannel) verifyMsg(msg proto.ReceivedMessage) bool {
if m.IsStateInfoMsg() {
si := m.GetStateInfo()
expectedMAC := GenerateMAC(si.PkiId, gc.chainID)
if !bytes.Equal(expectedMAC, si.ChannelMAC) {
gc.logger.Warning("Message contains wrong channel MAC(", si.ChannelMAC, "), expected", expectedMAC)
if !bytes.Equal(expectedMAC, si.Channel_MAC) {
gc.logger.Warning("Message contains wrong channel MAC(", si.Channel_MAC, "), expected", expectedMAC)
return false
}
return true
Expand All @@ -599,8 +599,8 @@ func (gc *gossipChannel) verifyMsg(msg proto.ReceivedMessage) bool {
if m.IsStateInfoPullRequestMsg() {
sipr := m.GetStateInfoPullReq()
expectedMAC := GenerateMAC(msg.GetConnectionInfo().ID, gc.chainID)
if !bytes.Equal(expectedMAC, sipr.ChannelMAC) {
gc.logger.Warning("Message contains wrong channel MAC(", sipr.ChannelMAC, "), expected", expectedMAC)
if !bytes.Equal(expectedMAC, sipr.Channel_MAC) {
gc.logger.Warning("Message contains wrong channel MAC(", sipr.Channel_MAC, "), expected", expectedMAC)
return false
}
return true
Expand All @@ -619,7 +619,7 @@ func (gc *gossipChannel) createStateInfoRequest() *proto.SignedGossipMessage {
Nonce: 0,
Content: &proto.GossipMessage_StateInfoPullReq{
StateInfoPullReq: &proto.StateInfoPullRequest{
ChannelMAC: GenerateMAC(gc.pkiID, gc.chainID),
Channel_MAC: GenerateMAC(gc.pkiID, gc.chainID),
},
},
}).NoopSign()
Expand Down
22 changes: 11 additions & 11 deletions gossip/gossip/channel/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ func TestChannelPeerNotInChannel(t *testing.T) {

// Ensure we don't respond to a StateInfoRequest in the wrong channel from a peer in the right org
req2 := gc.(*gossipChannel).createStateInfoRequest()
req2.GetStateInfoPullReq().ChannelMAC = GenerateMAC(pkiIDInOrg1, common.ChainID("B"))
req2.GetStateInfoPullReq().Channel_MAC = GenerateMAC(pkiIDInOrg1, common.ChainID("B"))
invalidReceivedMsg2 := &receivedMsg{
msg: req2,
PKIID: pkiIDInOrg1,
Expand Down Expand Up @@ -897,7 +897,7 @@ func TestChannelStateInfoSnapshot(t *testing.T) {

// Ensure we ignore stateInfo snapshots with StateInfo messages with wrong MACs
sim := createStateInfoMsg(4, pkiIDInOrg1, channelA)
sim.GetStateInfo().ChannelMAC = append(sim.GetStateInfo().ChannelMAC, 1)
sim.GetStateInfo().Channel_MAC = append(sim.GetStateInfo().Channel_MAC, 1)
sim = sim.NoopSign()
gc.HandleMessage(&receivedMsg{PKIID: pkiIDInOrg1, msg: stateInfoSnapshotForChannel(channelA, sim)})
assert.Empty(t, gc.GetPeers())
Expand All @@ -918,7 +918,7 @@ func TestChannelStateInfoSnapshot(t *testing.T) {
Tag: proto.GossipMessage_CHAN_OR_ORG,
Content: &proto.GossipMessage_StateInfoPullReq{
StateInfoPullReq: &proto.StateInfoPullRequest{
ChannelMAC: append(GenerateMAC(pkiIDInOrg1, channelA), 1),
Channel_MAC: append(GenerateMAC(pkiIDInOrg1, channelA), 1),
},
},
}).NoopSign(),
Expand All @@ -941,7 +941,7 @@ func TestChannelStateInfoSnapshot(t *testing.T) {
Tag: proto.GossipMessage_CHAN_OR_ORG,
Content: &proto.GossipMessage_StateInfoPullReq{
StateInfoPullReq: &proto.StateInfoPullRequest{
ChannelMAC: GenerateMAC(pkiIDInOrg1, channelA),
Channel_MAC: GenerateMAC(pkiIDInOrg1, channelA),
},
},
}).NoopSign(),
Expand Down Expand Up @@ -1043,7 +1043,7 @@ func TestInterOrgExternalEndpointDisclosure(t *testing.T) {
Tag: proto.GossipMessage_CHAN_OR_ORG,
Content: &proto.GossipMessage_StateInfoPullReq{
StateInfoPullReq: &proto.StateInfoPullRequest{
ChannelMAC: GenerateMAC(pkiID3, channelA),
Channel_MAC: GenerateMAC(pkiID3, channelA),
},
},
}).NoopSign(),
Expand Down Expand Up @@ -1074,7 +1074,7 @@ func TestInterOrgExternalEndpointDisclosure(t *testing.T) {
Tag: proto.GossipMessage_CHAN_OR_ORG,
Content: &proto.GossipMessage_StateInfoPullReq{
StateInfoPullReq: &proto.StateInfoPullRequest{
ChannelMAC: GenerateMAC(pkiID2, channelA),
Channel_MAC: GenerateMAC(pkiID2, channelA),
},
},
}).NoopSign(),
Expand Down Expand Up @@ -1284,7 +1284,7 @@ func TestChannelGetPeers(t *testing.T) {
// and ensure that the StateInfo message doesn't count
gc = NewGossipChannel(pkiIDInOrg1, orgInChannelA, cs, channelA, adapter, &joinChanMsg{})
msg := &receivedMsg{PKIID: pkiIDInOrg1, msg: createStateInfoMsg(1, pkiIDInOrg1, channelA)}
msg.GetGossipMessage().GetStateInfo().ChannelMAC = GenerateMAC(pkiIDinOrg2, channelA)
msg.GetGossipMessage().GetStateInfo().Channel_MAC = GenerateMAC(pkiIDinOrg2, channelA)
gc.HandleMessage(msg)
assert.Len(t, gc.GetPeers(), 0)
}
Expand Down Expand Up @@ -1405,10 +1405,10 @@ func createStateInfoMsg(ledgerHeight int, pkiID common.PKIidType, channel common
Tag: proto.GossipMessage_CHAN_OR_ORG,
Content: &proto.GossipMessage_StateInfo{
StateInfo: &proto.StateInfo{
ChannelMAC: GenerateMAC(pkiID, channel),
Timestamp: &proto.PeerTime{IncNumber: uint64(time.Now().UnixNano()), SeqNum: 1},
Metadata: []byte(fmt.Sprintf("%d", ledgerHeight)),
PkiId: []byte(pkiID),
Channel_MAC: GenerateMAC(pkiID, channel),
Timestamp: &proto.PeerTime{IncNumber: uint64(time.Now().UnixNano()), SeqNum: 1},
Metadata: []byte(fmt.Sprintf("%d", ledgerHeight)),
PkiId: []byte(pkiID),
},
},
}).NoopSign()
Expand Down
4 changes: 2 additions & 2 deletions gossip/gossip/chanstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (cs *channelState) isStopping() bool {
func (cs *channelState) lookupChannelForMsg(msg proto.ReceivedMessage) channel.GossipChannel {
if msg.GetGossipMessage().IsStateInfoPullRequestMsg() {
sipr := msg.GetGossipMessage().GetStateInfoPullReq()
mac := sipr.ChannelMAC
mac := sipr.Channel_MAC
pkiID := msg.GetConnectionInfo().ID
return cs.getGossipChannelByMAC(mac, pkiID)
}
Expand All @@ -80,7 +80,7 @@ func (cs *channelState) lookupChannelForGossipMsg(msg *proto.GossipMessage) chan

// Else, it's a StateInfo message.
stateInfMsg := msg.GetStateInfo()
return cs.getGossipChannelByMAC(stateInfMsg.ChannelMAC, stateInfMsg.PkiId)
return cs.getGossipChannelByMAC(stateInfMsg.Channel_MAC, stateInfMsg.PkiId)
}

func (cs *channelState) getGossipChannelByMAC(receivedMAC []byte, pkiID common.PKIidType) channel.GossipChannel {
Expand Down
6 changes: 3 additions & 3 deletions gossip/gossip/gossip_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1019,9 +1019,9 @@ func (g *gossipServiceImpl) sameOrgOrOurOrgPullFilter(msg proto.ReceivedMessage)
func (g *gossipServiceImpl) createStateInfoMsg(metadata []byte, chainID common.ChainID) (*proto.SignedGossipMessage, error) {
pkiID := g.comm.GetPKIid()
stateInfMsg := &proto.StateInfo{
ChannelMAC: channel.GenerateMAC(pkiID, chainID),
Metadata: metadata,
PkiId: g.comm.GetPKIid(),
Channel_MAC: channel.GenerateMAC(pkiID, chainID),
Metadata: metadata,
PkiId: g.comm.GetPKIid(),
Timestamp: &proto.PeerTime{
IncNumber: uint64(g.incTime.UnixNano()),
SeqNum: uint64(time.Now().UnixNano()),
Expand Down
6 changes: 3 additions & 3 deletions protos/gossip/extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func TestCheckGossipMessageTypes(t *testing.T) {
// Create State info pull request
msg = signedGossipMessage(channelID, GossipMessage_EMPTY, &GossipMessage_StateInfoPullReq{
StateInfoPullReq: &StateInfoPullRequest{
ChannelMAC: []byte{17},
Channel_MAC: []byte{17},
},
})

Expand Down Expand Up @@ -842,8 +842,8 @@ func stateInfoMessage(incNumber uint64, seqNum uint64, pkid []byte, mac []byte)
IncNumber: incNumber,
SeqNum: seqNum,
},
PkiId: pkid,
ChannelMAC: mac,
PkiId: pkid,
Channel_MAC: mac,
},
}
}
Expand Down
Loading

0 comments on commit c220290

Please sign in to comment.