Skip to content

Commit 0b0c357

Browse files
committed
Decouple gossip.LeadershipMsg and networkMember
The proto message that is used for leader election contains Member, which contains endpoint, metadata and pkiID. There is no use of endpoint in the leader election module, and also- the use of metadata is abuse since its a []byte, but all we do is to put there a bool. I replaced the use of Member by pkiID and a bool value that was previously in the metadata. Change-Id: Id31395c5978f6b8e1791bad35d28a8a66e6cf664 Signed-off-by: Yacov Manevich <[email protected]>
1 parent 515adbf commit 0b0c357

File tree

5 files changed

+121
-140
lines changed

5 files changed

+121
-140
lines changed

gossip/election/adapter.go

+5-13
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package election
1818

1919
import (
2020
"bytes"
21-
"strconv"
2221
"sync"
2322
"time"
2423

@@ -35,16 +34,15 @@ type msgImpl struct {
3534
}
3635

3736
func (mi *msgImpl) SenderID() string {
38-
return string(mi.msg.GetLeadershipMsg().GetMembership().PkiID)
37+
return string(mi.msg.GetLeadershipMsg().PkiID)
3938
}
4039

4140
func (mi *msgImpl) IsProposal() bool {
4241
return !mi.IsDeclaration()
4342
}
4443

4544
func (mi *msgImpl) IsDeclaration() bool {
46-
isDeclaration, _ := strconv.ParseBool(string(mi.msg.GetLeadershipMsg().GetMembership().Metadata))
47-
return isDeclaration
45+
return mi.msg.GetLeadershipMsg().IsDeclaration
4846
}
4947

5048
type peerImpl struct {
@@ -136,7 +134,7 @@ func (ai *adapterImpl) Accept() <-chan Msg {
136134
verifier := func(identity []byte, signature, message []byte) error {
137135
return ai.mcs.Verify(identity, signature, message)
138136
}
139-
identity, err := ai.mcs.Get(leadershipMsg.GetMembership().PkiID)
137+
identity, err := ai.mcs.Get(leadershipMsg.PkiID)
140138
if err != nil {
141139
ai.logger.Error("Failed verify, can't get identity", leadershipMsg, ":", err)
142140
return false
@@ -174,15 +172,9 @@ func (ai *adapterImpl) CreateMessage(isDeclaration bool) Msg {
174172
ai.seqNum++
175173
seqNum := ai.seqNum
176174

177-
metadata := []byte{}
178-
metadata = strconv.AppendBool(metadata, isDeclaration)
179-
180175
leadershipMsg := &proto.LeadershipMessage{
181-
Membership: &proto.Member{
182-
PkiID: ai.self.PKIid,
183-
Endpoint: ai.self.Endpoint,
184-
Metadata: metadata,
185-
},
176+
PkiID: ai.self.PKIid,
177+
IsDeclaration: isDeclaration,
186178
Timestamp: &proto.PeerTime{
187179
IncNumber: ai.incTime,
188180
SeqNum: seqNum,

gossip/gossip/gossip_test.go

+2-9
Original file line numberDiff line numberDiff line change
@@ -909,16 +909,9 @@ func createDataMsg(seqnum uint64, data []byte, hash string, channel common.Chain
909909
}
910910

911911
func createLeadershipMsg(isDeclaration bool, channel common.ChainID, incTime uint64, seqNum uint64, endpoint string, pkiid []byte) *proto.GossipMessage {
912-
913-
metadata := []byte{}
914-
metadata = strconv.AppendBool(metadata, isDeclaration)
915-
916912
leadershipMsg := &proto.LeadershipMessage{
917-
Membership: &proto.Member{
918-
PkiID: pkiid,
919-
Endpoint: endpoint,
920-
Metadata: metadata,
921-
},
913+
IsDeclaration: isDeclaration,
914+
PkiID: pkiid,
922915
Timestamp: &proto.PeerTime{
923916
IncNumber: incTime,
924917
SeqNum: seqNum,

protos/gossip/extensions.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func aliveInvalidationPolicy(thisMsg *AliveMessage, thatMsg *AliveMessage) commo
110110
}
111111

112112
func leaderInvalidationPolicy(thisMsg *LeadershipMessage, thatMsg *LeadershipMessage) common.InvalidationResult {
113-
if !bytes.Equal(thisMsg.Membership.PkiID, thatMsg.Membership.PkiID) {
113+
if !bytes.Equal(thisMsg.PkiID, thatMsg.PkiID) {
114114
return common.MessageNoAction
115115
}
116116

0 commit comments

Comments
 (0)