Skip to content

Commit

Permalink
[FAB-2473] Fix gossip proto style 3/3
Browse files Browse the repository at this point in the history
https://jira.hyperledger.org/browse/FAB-2473

This is the third and final in a series of changesets to move the gossip
protos to conform with the official proto style guidelines.

This CR is the most invasive, because it changes pkiID to be pki_id,
causing the generated code to become PkiId instead of PkiId.  This is
very similar to the change from ChaincodeID to ChaincodeId, but much
smaller in scope.

Change-Id: I7ebd2db48ef464ac7f1d024a41fbd11514ca5385
Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick authored and Srinivasan Muralidharan committed Mar 5, 2017
1 parent 953bb21 commit ed7ed80
Show file tree
Hide file tree
Showing 14 changed files with 158 additions and 158 deletions.
10 changes: 5 additions & 5 deletions gossip/comm/comm_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,24 +425,24 @@ func (c *commImpl) authenticateRemotePeer(stream stream) (*proto.ConnectionInfo,
return nil, errors.New("Wrong type")
}

if receivedMsg.PkiID == nil {
if receivedMsg.PkiId == nil {
c.logger.Warning("%s didn't send a pkiID")
return nil, fmt.Errorf("%s didn't send a pkiID", remoteAddress)
}

if c.isPKIblackListed(receivedMsg.PkiID) {
if c.isPKIblackListed(receivedMsg.PkiId) {
c.logger.Warning("Connection attempt from", remoteAddress, "but it is black-listed")
return nil, errors.New("Black-listed")
}
c.logger.Debug("Received", receivedMsg, "from", remoteAddress)
err = c.idMapper.Put(receivedMsg.PkiID, receivedMsg.Cert)
err = c.idMapper.Put(receivedMsg.PkiId, receivedMsg.Cert)
if err != nil {
c.logger.Warning("Identity store rejected", remoteAddress, ":", err)
return nil, err
}

connInfo := &proto.ConnectionInfo{
ID: receivedMsg.PkiID,
ID: receivedMsg.PkiId,
Identity: receivedMsg.Cert,
}

Expand Down Expand Up @@ -566,7 +566,7 @@ func (c *commImpl) createConnectionMsg(pkiID common.PKIidType, hash []byte, cert
Conn: &proto.ConnEstablish{
Hash: hash,
Cert: cert,
PkiID: pkiID,
PkiId: pkiID,
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion gossip/comm/comm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func handshaker(endpoint string, comm Comm, t *testing.T, sigMutator func([]byte
})
assert.Equal(t, expectedMsg.Envelope.Signature, msg.Envelope.Signature)
}
assert.Equal(t, []byte("localhost:9611"), msg.GetConn().PkiID)
assert.Equal(t, []byte("localhost:9611"), msg.GetConn().PkiId)
msg2Send := createGossipMsg()
nonce := uint64(rand.Int())
msg2Send.Nonce = nonce
Expand Down
44 changes: 22 additions & 22 deletions gossip/discovery/discovery_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (d *gossipDiscoveryImpl) InitiateSync(peerNum int) {
netMember := &NetworkMember{
Endpoint: pulledPeer.Endpoint,
Metadata: pulledPeer.Metadata,
PKIid: pulledPeer.PkiID,
PKIid: pulledPeer.PkiId,
InternalEndpoint: internalEndpoint,
}
peers2SendTo = append(peers2SendTo, netMember)
Expand Down Expand Up @@ -344,7 +344,7 @@ func (d *gossipDiscoveryImpl) handleMsgFromComm(m *proto.SignedGossipMessage) {

newDeadMembers := []*proto.SignedGossipMessage{}
d.lock.RLock()
if _, known := d.id2Member[string(dm.GetAliveMsg().Membership.PkiID)]; !known {
if _, known := d.id2Member[string(dm.GetAliveMsg().Membership.PkiId)]; !known {
newDeadMembers = append(newDeadMembers, dm)
}
d.lock.RUnlock()
Expand All @@ -359,7 +359,7 @@ func (d *gossipDiscoveryImpl) sendMemResponse(targetMember *proto.Member, intern
targetPeer := &NetworkMember{
Endpoint: targetMember.Endpoint,
Metadata: targetMember.Metadata,
PKIid: targetMember.PkiID,
PKIid: targetMember.PkiId,
InternalEndpoint: internalEndpoint,
}

Expand Down Expand Up @@ -425,7 +425,7 @@ func (d *gossipDiscoveryImpl) handleAliveMessage(m *proto.SignedGossipMessage) {
return
}

pkiID := m.GetAliveMsg().Membership.PkiID
pkiID := m.GetAliveMsg().Membership.PkiId
if equalPKIid(pkiID, d.self.PKIid) {
d.logger.Debug("Got alive message about ourselves,", m)
return
Expand Down Expand Up @@ -489,7 +489,7 @@ func (d *gossipDiscoveryImpl) resurrectMember(am *proto.SignedGossipMessage, t p
defer d.lock.Unlock()

member := am.GetAliveMsg().Membership
pkiID := member.PkiID
pkiID := member.PkiId
d.aliveLastTS[string(pkiID)] = &timestamp{
lastSeen: time.Now(),
seqNum: t.SeqNum,
Expand All @@ -504,7 +504,7 @@ func (d *gossipDiscoveryImpl) resurrectMember(am *proto.SignedGossipMessage, t p
d.id2Member[string(pkiID)] = &NetworkMember{
Endpoint: member.Endpoint,
Metadata: member.Metadata,
PKIid: member.PkiID,
PKIid: member.PkiId,
InternalEndpoint: internalEndpoint,
}

Expand Down Expand Up @@ -672,7 +672,7 @@ func (d *gossipDiscoveryImpl) createAliveMessage() *proto.SignedGossipMessage {
Membership: &proto.Member{
Endpoint: endpoint,
Metadata: meta,
PkiID: pkiID,
PkiId: pkiID,
},
Timestamp: &proto.PeerTime{
IncNumber: uint64(d.incTime),
Expand Down Expand Up @@ -710,31 +710,31 @@ func (d *gossipDiscoveryImpl) learnExistingMembers(aliveArr []*proto.SignedGossi
}

// update member's data
member := d.id2Member[string(am.Membership.PkiID)]
member := d.id2Member[string(am.Membership.PkiId)]
member.Endpoint = am.Membership.Endpoint
member.Metadata = am.Membership.Metadata
member.InternalEndpoint = internalEndpoint

if _, isKnownAsDead := d.deadLastTS[string(am.Membership.PkiID)]; isKnownAsDead {
if _, isKnownAsDead := d.deadLastTS[string(am.Membership.PkiId)]; isKnownAsDead {
d.logger.Warning(am.Membership, "has already expired")
continue
}

if _, isKnownAsAlive := d.aliveLastTS[string(am.Membership.PkiID)]; !isKnownAsAlive {
if _, isKnownAsAlive := d.aliveLastTS[string(am.Membership.PkiId)]; !isKnownAsAlive {
d.logger.Warning(am.Membership, "has already expired")
continue
} else {
d.logger.Debug("Updating aliveness data:", am)
// update existing aliveness data
alive := d.aliveLastTS[string(am.Membership.PkiID)]
alive := d.aliveLastTS[string(am.Membership.PkiId)]
alive.incTime = tsToTime(am.Timestamp.IncNumber)
alive.lastSeen = time.Now()
alive.seqNum = am.Timestamp.SeqNum

if am := d.aliveMembership.MsgByID(m.GetAliveMsg().Membership.PkiID); am == nil {
if am := d.aliveMembership.MsgByID(m.GetAliveMsg().Membership.PkiId); am == nil {
d.logger.Debug("Adding", am, "to aliveMembership")
msg := &proto.SignedGossipMessage{GossipMessage: m.GossipMessage, Envelope: am.Envelope}
d.aliveMembership.Put(m.GetAliveMsg().Membership.PkiID, msg)
d.aliveMembership.Put(m.GetAliveMsg().Membership.PkiId, msg)
} else {
d.logger.Debug("Replacing", am, "in aliveMembership")
am.GossipMessage = m.GossipMessage
Expand All @@ -752,30 +752,30 @@ func (d *gossipDiscoveryImpl) learnNewMembers(aliveMembers []*proto.SignedGossip
defer d.lock.Unlock()

for _, am := range aliveMembers {
if equalPKIid(am.GetAliveMsg().Membership.PkiID, d.self.PKIid) {
if equalPKIid(am.GetAliveMsg().Membership.PkiId, d.self.PKIid) {
continue
}
d.aliveLastTS[string(am.GetAliveMsg().Membership.PkiID)] = &timestamp{
d.aliveLastTS[string(am.GetAliveMsg().Membership.PkiId)] = &timestamp{
incTime: tsToTime(am.GetAliveMsg().Timestamp.IncNumber),
lastSeen: time.Now(),
seqNum: am.GetAliveMsg().Timestamp.SeqNum,
}

d.aliveMembership.Put(am.GetAliveMsg().Membership.PkiID, &proto.SignedGossipMessage{GossipMessage: am.GossipMessage, Envelope: am.Envelope})
d.aliveMembership.Put(am.GetAliveMsg().Membership.PkiId, &proto.SignedGossipMessage{GossipMessage: am.GossipMessage, Envelope: am.Envelope})
d.logger.Infof("Learned about a new alive member: %v", am)
}

for _, dm := range deadMembers {
if equalPKIid(dm.GetAliveMsg().Membership.PkiID, d.self.PKIid) {
if equalPKIid(dm.GetAliveMsg().Membership.PkiId, d.self.PKIid) {
continue
}
d.deadLastTS[string(dm.GetAliveMsg().Membership.PkiID)] = &timestamp{
d.deadLastTS[string(dm.GetAliveMsg().Membership.PkiId)] = &timestamp{
incTime: tsToTime(dm.GetAliveMsg().Timestamp.IncNumber),
lastSeen: time.Now(),
seqNum: dm.GetAliveMsg().Timestamp.SeqNum,
}

d.deadMembership.Put(dm.GetAliveMsg().Membership.PkiID, &proto.SignedGossipMessage{GossipMessage: dm.GossipMessage, Envelope: dm.Envelope})
d.deadMembership.Put(dm.GetAliveMsg().Membership.PkiId, &proto.SignedGossipMessage{GossipMessage: dm.GossipMessage, Envelope: dm.Envelope})
d.logger.Infof("Learned about a new dead member: %v", dm)
}

Expand All @@ -793,10 +793,10 @@ func (d *gossipDiscoveryImpl) learnNewMembers(aliveMembers []*proto.SignedGossip
internalEndpoint = m.Envelope.SecretEnvelope.InternalEndpoint()
}

d.id2Member[string(member.Membership.PkiID)] = &NetworkMember{
d.id2Member[string(member.Membership.PkiId)] = &NetworkMember{
Endpoint: member.Membership.Endpoint,
Metadata: member.Membership.Metadata,
PKIid: member.Membership.PkiID,
PKIid: member.Membership.PkiId,
InternalEndpoint: internalEndpoint,
}
}
Expand All @@ -820,7 +820,7 @@ func (d *gossipDiscoveryImpl) GetMembership() []NetworkMember {

member := m.GetAliveMsg()
response = append(response, NetworkMember{
PKIid: member.Membership.PkiID,
PKIid: member.Membership.PkiId,
Endpoint: member.Membership.Endpoint,
Metadata: member.Membership.Metadata,
InternalEndpoint: internalEndpoint,
Expand Down
2 changes: 1 addition & 1 deletion gossip/discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (g *gossipInstance) tryForwardMessage(msg *proto.SignedGossipMessage) {
aliveMsg := msg.GetAliveMsg()

forward := false
id := string(aliveMsg.Membership.PkiID)
id := string(aliveMsg.Membership.PkiId)
seqNum := aliveMsg.Timestamp.SeqNum
if last, exists := g.comm.lastSeqs[id]; exists {
if last < seqNum {
Expand Down
4 changes: 2 additions & 2 deletions gossip/election/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type msgImpl struct {
}

func (mi *msgImpl) SenderID() peerID {
return mi.msg.GetLeadershipMsg().PkiID
return mi.msg.GetLeadershipMsg().PkiId
}

func (mi *msgImpl) IsProposal() bool {
Expand Down Expand Up @@ -135,7 +135,7 @@ func (ai *adapterImpl) CreateMessage(isDeclaration bool) Msg {
seqNum := ai.seqNum

leadershipMsg := &proto.LeadershipMessage{
PkiID: ai.selfPKIid,
PkiId: ai.selfPKIid,
IsDeclaration: isDeclaration,
Timestamp: &proto.PeerTime{
IncNumber: ai.incTime,
Expand Down
6 changes: 3 additions & 3 deletions gossip/gossip/certstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func newCertStore(puller pull.Mediator, idMapper identity.Mapper, selfIdentity a
puller.Add(certStore.createIdentityMessage())
puller.RegisterMsgHook(pull.ResponseMsgType, func(_ []string, msgs []*proto.SignedGossipMessage, _ proto.ReceivedMessage) {
for _, msg := range msgs {
pkiID := common.PKIidType(msg.GetPeerIdentity().PkiID)
pkiID := common.PKIidType(msg.GetPeerIdentity().PkiId)
cert := api.PeerIdentityType(msg.GetPeerIdentity().Cert)
if err := certStore.idMapper.Put(pkiID, cert); err != nil {
certStore.logger.Warning("Failed adding identity", cert, ", reason:", err)
Expand Down Expand Up @@ -99,7 +99,7 @@ func (cs *certStore) validateIdentityMsg(msg *proto.SignedGossipMessage) error {
if idMsg == nil {
return fmt.Errorf("Identity empty: %+v", msg)
}
pkiID := idMsg.PkiID
pkiID := idMsg.PkiId
cert := idMsg.Cert
calculatedPKIID := cs.mcs.GetPKIidOfCert(api.PeerIdentityType(cert))
claimedPKIID := common.PKIidType(pkiID)
Expand All @@ -123,7 +123,7 @@ func (cs *certStore) createIdentityMessage() *proto.SignedGossipMessage {
identity := &proto.PeerIdentity{
Cert: cs.selfIdentity,
Metadata: nil,
PkiID: cs.idMapper.GetPKIidOfCert(cs.selfIdentity),
PkiId: cs.idMapper.GetPKIidOfCert(cs.selfIdentity),
}
m := &proto.GossipMessage{
Channel: nil,
Expand Down
8 changes: 4 additions & 4 deletions gossip/gossip/certstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func testCertificateUpdate(t *testing.T, updateFactory func(uint64) proto.Receiv
pullMediator := pull.NewPullMediator(config,
sender,
memberSvc,
func(msg *proto.SignedGossipMessage) string { return string(msg.GetPeerIdentity().PkiID) },
func(msg *proto.SignedGossipMessage) string { return string(msg.GetPeerIdentity().PkiId) },
func(msg *proto.SignedGossipMessage) {})
certStore := newCertStore(&pullerMock{
Mediator: pullMediator,
Expand Down Expand Up @@ -191,7 +191,7 @@ func createMismatchedUpdateMessage() *proto.SignedGossipMessage {
identity := &proto.PeerIdentity{
// This PKI-ID is different than the cert, and the mapping between
// certificate to PKI-ID in this test is simply the identity function.
PkiID: []byte("A"),
PkiId: []byte("A"),
Cert: []byte("D"),
}

Expand All @@ -215,7 +215,7 @@ func createMismatchedUpdateMessage() *proto.SignedGossipMessage {

func createBadlySignedUpdateMessage() *proto.SignedGossipMessage {
identity := &proto.PeerIdentity{
PkiID: []byte("C"),
PkiId: []byte("C"),
Cert: []byte("C"),
}

Expand Down Expand Up @@ -246,7 +246,7 @@ func createBadlySignedUpdateMessage() *proto.SignedGossipMessage {

func createValidUpdateMessage() *proto.SignedGossipMessage {
identity := &proto.PeerIdentity{
PkiID: []byte("B"),
PkiId: []byte("B"),
Cert: []byte("B"),
}

Expand Down
8 changes: 4 additions & 4 deletions gossip/gossip/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,14 @@ func (gc *gossipChannel) handleStateInfSnapshot(m *proto.GossipMessage, sender c
return
}

orgID := gc.GetOrgOfPeer(stateInf.GetStateInfo().PkiID)
orgID := gc.GetOrgOfPeer(stateInf.GetStateInfo().PkiId)
if orgID == nil {
gc.logger.Warning("Couldn't find org identity of peer", stateInf.GetStateInfo().PkiID, "message sent from", sender)
gc.logger.Warning("Couldn't find org identity of peer", stateInf.GetStateInfo().PkiId, "message sent from", sender)
return
}

if !gc.IsOrgInChannel(orgID) {
gc.logger.Warning("Peer", stateInf.GetStateInfo().PkiID, "is not in an eligible org, can't process a stateInfo from it, sent from", sender)
gc.logger.Warning("Peer", stateInf.GetStateInfo().PkiId, "is not in an eligible org, can't process a stateInfo from it, sent from", sender)
return
}

Expand Down Expand Up @@ -586,7 +586,7 @@ type stateInfoCache struct {
// Message must be a StateInfo message.
func (cache stateInfoCache) Add(msg *proto.SignedGossipMessage) bool {
added := cache.MessageStore.Add(msg)
pkiID := msg.GetStateInfo().PkiID
pkiID := msg.GetStateInfo().PkiId
if added {
cache.MembershipStore.Put(pkiID, msg)
}
Expand Down
2 changes: 1 addition & 1 deletion gossip/gossip/channel/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ func createStateInfoMsg(ledgerHeight int, pkiID common.PKIidType, channel common
StateInfo: &proto.StateInfo{
Timestamp: &proto.PeerTime{IncNumber: uint64(time.Now().UnixNano()), SeqNum: 1},
Metadata: []byte(fmt.Sprintf("%d", ledgerHeight)),
PkiID: []byte(pkiID),
PkiId: []byte(pkiID),
},
},
}).NoopSign()
Expand Down
Loading

0 comments on commit ed7ed80

Please sign in to comment.