Skip to content

Commit ed7ed80

Browse files
Jason YellickSrinivasan Muralidharan
Jason Yellick
authored and
Srinivasan Muralidharan
committed
[FAB-2473] Fix gossip proto style 3/3
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 <[email protected]>
1 parent 953bb21 commit ed7ed80

14 files changed

+158
-158
lines changed

gossip/comm/comm_impl.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -425,24 +425,24 @@ func (c *commImpl) authenticateRemotePeer(stream stream) (*proto.ConnectionInfo,
425425
return nil, errors.New("Wrong type")
426426
}
427427

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

433-
if c.isPKIblackListed(receivedMsg.PkiID) {
433+
if c.isPKIblackListed(receivedMsg.PkiId) {
434434
c.logger.Warning("Connection attempt from", remoteAddress, "but it is black-listed")
435435
return nil, errors.New("Black-listed")
436436
}
437437
c.logger.Debug("Received", receivedMsg, "from", remoteAddress)
438-
err = c.idMapper.Put(receivedMsg.PkiID, receivedMsg.Cert)
438+
err = c.idMapper.Put(receivedMsg.PkiId, receivedMsg.Cert)
439439
if err != nil {
440440
c.logger.Warning("Identity store rejected", remoteAddress, ":", err)
441441
return nil, err
442442
}
443443

444444
connInfo := &proto.ConnectionInfo{
445-
ID: receivedMsg.PkiID,
445+
ID: receivedMsg.PkiId,
446446
Identity: receivedMsg.Cert,
447447
}
448448

@@ -566,7 +566,7 @@ func (c *commImpl) createConnectionMsg(pkiID common.PKIidType, hash []byte, cert
566566
Conn: &proto.ConnEstablish{
567567
Hash: hash,
568568
Cert: cert,
569-
PkiID: pkiID,
569+
PkiId: pkiID,
570570
},
571571
},
572572
}

gossip/comm/comm_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func handshaker(endpoint string, comm Comm, t *testing.T, sigMutator func([]byte
147147
})
148148
assert.Equal(t, expectedMsg.Envelope.Signature, msg.Envelope.Signature)
149149
}
150-
assert.Equal(t, []byte("localhost:9611"), msg.GetConn().PkiID)
150+
assert.Equal(t, []byte("localhost:9611"), msg.GetConn().PkiId)
151151
msg2Send := createGossipMsg()
152152
nonce := uint64(rand.Int())
153153
msg2Send.Nonce = nonce

gossip/discovery/discovery_impl.go

+22-22
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func (d *gossipDiscoveryImpl) InitiateSync(peerNum int) {
226226
netMember := &NetworkMember{
227227
Endpoint: pulledPeer.Endpoint,
228228
Metadata: pulledPeer.Metadata,
229-
PKIid: pulledPeer.PkiID,
229+
PKIid: pulledPeer.PkiId,
230230
InternalEndpoint: internalEndpoint,
231231
}
232232
peers2SendTo = append(peers2SendTo, netMember)
@@ -344,7 +344,7 @@ func (d *gossipDiscoveryImpl) handleMsgFromComm(m *proto.SignedGossipMessage) {
344344

345345
newDeadMembers := []*proto.SignedGossipMessage{}
346346
d.lock.RLock()
347-
if _, known := d.id2Member[string(dm.GetAliveMsg().Membership.PkiID)]; !known {
347+
if _, known := d.id2Member[string(dm.GetAliveMsg().Membership.PkiId)]; !known {
348348
newDeadMembers = append(newDeadMembers, dm)
349349
}
350350
d.lock.RUnlock()
@@ -359,7 +359,7 @@ func (d *gossipDiscoveryImpl) sendMemResponse(targetMember *proto.Member, intern
359359
targetPeer := &NetworkMember{
360360
Endpoint: targetMember.Endpoint,
361361
Metadata: targetMember.Metadata,
362-
PKIid: targetMember.PkiID,
362+
PKIid: targetMember.PkiId,
363363
InternalEndpoint: internalEndpoint,
364364
}
365365

@@ -425,7 +425,7 @@ func (d *gossipDiscoveryImpl) handleAliveMessage(m *proto.SignedGossipMessage) {
425425
return
426426
}
427427

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

491491
member := am.GetAliveMsg().Membership
492-
pkiID := member.PkiID
492+
pkiID := member.PkiId
493493
d.aliveLastTS[string(pkiID)] = &timestamp{
494494
lastSeen: time.Now(),
495495
seqNum: t.SeqNum,
@@ -504,7 +504,7 @@ func (d *gossipDiscoveryImpl) resurrectMember(am *proto.SignedGossipMessage, t p
504504
d.id2Member[string(pkiID)] = &NetworkMember{
505505
Endpoint: member.Endpoint,
506506
Metadata: member.Metadata,
507-
PKIid: member.PkiID,
507+
PKIid: member.PkiId,
508508
InternalEndpoint: internalEndpoint,
509509
}
510510

@@ -672,7 +672,7 @@ func (d *gossipDiscoveryImpl) createAliveMessage() *proto.SignedGossipMessage {
672672
Membership: &proto.Member{
673673
Endpoint: endpoint,
674674
Metadata: meta,
675-
PkiID: pkiID,
675+
PkiId: pkiID,
676676
},
677677
Timestamp: &proto.PeerTime{
678678
IncNumber: uint64(d.incTime),
@@ -710,31 +710,31 @@ func (d *gossipDiscoveryImpl) learnExistingMembers(aliveArr []*proto.SignedGossi
710710
}
711711

712712
// update member's data
713-
member := d.id2Member[string(am.Membership.PkiID)]
713+
member := d.id2Member[string(am.Membership.PkiId)]
714714
member.Endpoint = am.Membership.Endpoint
715715
member.Metadata = am.Membership.Metadata
716716
member.InternalEndpoint = internalEndpoint
717717

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

723-
if _, isKnownAsAlive := d.aliveLastTS[string(am.Membership.PkiID)]; !isKnownAsAlive {
723+
if _, isKnownAsAlive := d.aliveLastTS[string(am.Membership.PkiId)]; !isKnownAsAlive {
724724
d.logger.Warning(am.Membership, "has already expired")
725725
continue
726726
} else {
727727
d.logger.Debug("Updating aliveness data:", am)
728728
// update existing aliveness data
729-
alive := d.aliveLastTS[string(am.Membership.PkiID)]
729+
alive := d.aliveLastTS[string(am.Membership.PkiId)]
730730
alive.incTime = tsToTime(am.Timestamp.IncNumber)
731731
alive.lastSeen = time.Now()
732732
alive.seqNum = am.Timestamp.SeqNum
733733

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

754754
for _, am := range aliveMembers {
755-
if equalPKIid(am.GetAliveMsg().Membership.PkiID, d.self.PKIid) {
755+
if equalPKIid(am.GetAliveMsg().Membership.PkiId, d.self.PKIid) {
756756
continue
757757
}
758-
d.aliveLastTS[string(am.GetAliveMsg().Membership.PkiID)] = &timestamp{
758+
d.aliveLastTS[string(am.GetAliveMsg().Membership.PkiId)] = &timestamp{
759759
incTime: tsToTime(am.GetAliveMsg().Timestamp.IncNumber),
760760
lastSeen: time.Now(),
761761
seqNum: am.GetAliveMsg().Timestamp.SeqNum,
762762
}
763763

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

768768
for _, dm := range deadMembers {
769-
if equalPKIid(dm.GetAliveMsg().Membership.PkiID, d.self.PKIid) {
769+
if equalPKIid(dm.GetAliveMsg().Membership.PkiId, d.self.PKIid) {
770770
continue
771771
}
772-
d.deadLastTS[string(dm.GetAliveMsg().Membership.PkiID)] = &timestamp{
772+
d.deadLastTS[string(dm.GetAliveMsg().Membership.PkiId)] = &timestamp{
773773
incTime: tsToTime(dm.GetAliveMsg().Timestamp.IncNumber),
774774
lastSeen: time.Now(),
775775
seqNum: dm.GetAliveMsg().Timestamp.SeqNum,
776776
}
777777

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

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

796-
d.id2Member[string(member.Membership.PkiID)] = &NetworkMember{
796+
d.id2Member[string(member.Membership.PkiId)] = &NetworkMember{
797797
Endpoint: member.Membership.Endpoint,
798798
Metadata: member.Membership.Metadata,
799-
PKIid: member.Membership.PkiID,
799+
PKIid: member.Membership.PkiId,
800800
InternalEndpoint: internalEndpoint,
801801
}
802802
}
@@ -820,7 +820,7 @@ func (d *gossipDiscoveryImpl) GetMembership() []NetworkMember {
820820

821821
member := m.GetAliveMsg()
822822
response = append(response, NetworkMember{
823-
PKIid: member.Membership.PkiID,
823+
PKIid: member.Membership.PkiId,
824824
Endpoint: member.Membership.Endpoint,
825825
Metadata: member.Membership.Metadata,
826826
InternalEndpoint: internalEndpoint,

gossip/discovery/discovery_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func (g *gossipInstance) tryForwardMessage(msg *proto.SignedGossipMessage) {
226226
aliveMsg := msg.GetAliveMsg()
227227

228228
forward := false
229-
id := string(aliveMsg.Membership.PkiID)
229+
id := string(aliveMsg.Membership.PkiId)
230230
seqNum := aliveMsg.Timestamp.SeqNum
231231
if last, exists := g.comm.lastSeqs[id]; exists {
232232
if last < seqNum {

gossip/election/adapter.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type msgImpl struct {
3333
}
3434

3535
func (mi *msgImpl) SenderID() peerID {
36-
return mi.msg.GetLeadershipMsg().PkiID
36+
return mi.msg.GetLeadershipMsg().PkiId
3737
}
3838

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

137137
leadershipMsg := &proto.LeadershipMessage{
138-
PkiID: ai.selfPKIid,
138+
PkiId: ai.selfPKIid,
139139
IsDeclaration: isDeclaration,
140140
Timestamp: &proto.PeerTime{
141141
IncNumber: ai.incTime,

gossip/gossip/certstore.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func newCertStore(puller pull.Mediator, idMapper identity.Mapper, selfIdentity a
6363
puller.Add(certStore.createIdentityMessage())
6464
puller.RegisterMsgHook(pull.ResponseMsgType, func(_ []string, msgs []*proto.SignedGossipMessage, _ proto.ReceivedMessage) {
6565
for _, msg := range msgs {
66-
pkiID := common.PKIidType(msg.GetPeerIdentity().PkiID)
66+
pkiID := common.PKIidType(msg.GetPeerIdentity().PkiId)
6767
cert := api.PeerIdentityType(msg.GetPeerIdentity().Cert)
6868
if err := certStore.idMapper.Put(pkiID, cert); err != nil {
6969
certStore.logger.Warning("Failed adding identity", cert, ", reason:", err)
@@ -99,7 +99,7 @@ func (cs *certStore) validateIdentityMsg(msg *proto.SignedGossipMessage) error {
9999
if idMsg == nil {
100100
return fmt.Errorf("Identity empty: %+v", msg)
101101
}
102-
pkiID := idMsg.PkiID
102+
pkiID := idMsg.PkiId
103103
cert := idMsg.Cert
104104
calculatedPKIID := cs.mcs.GetPKIidOfCert(api.PeerIdentityType(cert))
105105
claimedPKIID := common.PKIidType(pkiID)
@@ -123,7 +123,7 @@ func (cs *certStore) createIdentityMessage() *proto.SignedGossipMessage {
123123
identity := &proto.PeerIdentity{
124124
Cert: cs.selfIdentity,
125125
Metadata: nil,
126-
PkiID: cs.idMapper.GetPKIidOfCert(cs.selfIdentity),
126+
PkiId: cs.idMapper.GetPKIidOfCert(cs.selfIdentity),
127127
}
128128
m := &proto.GossipMessage{
129129
Channel: nil,

gossip/gossip/certstore_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func testCertificateUpdate(t *testing.T, updateFactory func(uint64) proto.Receiv
124124
pullMediator := pull.NewPullMediator(config,
125125
sender,
126126
memberSvc,
127-
func(msg *proto.SignedGossipMessage) string { return string(msg.GetPeerIdentity().PkiID) },
127+
func(msg *proto.SignedGossipMessage) string { return string(msg.GetPeerIdentity().PkiId) },
128128
func(msg *proto.SignedGossipMessage) {})
129129
certStore := newCertStore(&pullerMock{
130130
Mediator: pullMediator,
@@ -191,7 +191,7 @@ func createMismatchedUpdateMessage() *proto.SignedGossipMessage {
191191
identity := &proto.PeerIdentity{
192192
// This PKI-ID is different than the cert, and the mapping between
193193
// certificate to PKI-ID in this test is simply the identity function.
194-
PkiID: []byte("A"),
194+
PkiId: []byte("A"),
195195
Cert: []byte("D"),
196196
}
197197

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

216216
func createBadlySignedUpdateMessage() *proto.SignedGossipMessage {
217217
identity := &proto.PeerIdentity{
218-
PkiID: []byte("C"),
218+
PkiId: []byte("C"),
219219
Cert: []byte("C"),
220220
}
221221

@@ -246,7 +246,7 @@ func createBadlySignedUpdateMessage() *proto.SignedGossipMessage {
246246

247247
func createValidUpdateMessage() *proto.SignedGossipMessage {
248248
identity := &proto.PeerIdentity{
249-
PkiID: []byte("B"),
249+
PkiId: []byte("B"),
250250
Cert: []byte("B"),
251251
}
252252

gossip/gossip/channel/channel.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -454,14 +454,14 @@ func (gc *gossipChannel) handleStateInfSnapshot(m *proto.GossipMessage, sender c
454454
return
455455
}
456456

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

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

@@ -586,7 +586,7 @@ type stateInfoCache struct {
586586
// Message must be a StateInfo message.
587587
func (cache stateInfoCache) Add(msg *proto.SignedGossipMessage) bool {
588588
added := cache.MessageStore.Add(msg)
589-
pkiID := msg.GetStateInfo().PkiID
589+
pkiID := msg.GetStateInfo().PkiId
590590
if added {
591591
cache.MembershipStore.Put(pkiID, msg)
592592
}

gossip/gossip/channel/channel_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ func createStateInfoMsg(ledgerHeight int, pkiID common.PKIidType, channel common
902902
StateInfo: &proto.StateInfo{
903903
Timestamp: &proto.PeerTime{IncNumber: uint64(time.Now().UnixNano()), SeqNum: 1},
904904
Metadata: []byte(fmt.Sprintf("%d", ledgerHeight)),
905-
PkiID: []byte(pkiID),
905+
PkiId: []byte(pkiID),
906906
},
907907
},
908908
}).NoopSign()

0 commit comments

Comments
 (0)