Skip to content

Commit

Permalink
Decouple gossip.LeadershipMsg and networkMember
Browse files Browse the repository at this point in the history
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 <yacovm@il.ibm.com>
  • Loading branch information
yacovm committed Feb 7, 2017
1 parent 515adbf commit 0b0c357
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 140 deletions.
18 changes: 5 additions & 13 deletions gossip/election/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package election

import (
"bytes"
"strconv"
"sync"
"time"

Expand All @@ -35,16 +34,15 @@ type msgImpl struct {
}

func (mi *msgImpl) SenderID() string {
return string(mi.msg.GetLeadershipMsg().GetMembership().PkiID)
return string(mi.msg.GetLeadershipMsg().PkiID)
}

func (mi *msgImpl) IsProposal() bool {
return !mi.IsDeclaration()
}

func (mi *msgImpl) IsDeclaration() bool {
isDeclaration, _ := strconv.ParseBool(string(mi.msg.GetLeadershipMsg().GetMembership().Metadata))
return isDeclaration
return mi.msg.GetLeadershipMsg().IsDeclaration
}

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

metadata := []byte{}
metadata = strconv.AppendBool(metadata, isDeclaration)

leadershipMsg := &proto.LeadershipMessage{
Membership: &proto.Member{
PkiID: ai.self.PKIid,
Endpoint: ai.self.Endpoint,
Metadata: metadata,
},
PkiID: ai.self.PKIid,
IsDeclaration: isDeclaration,
Timestamp: &proto.PeerTime{
IncNumber: ai.incTime,
SeqNum: seqNum,
Expand Down
11 changes: 2 additions & 9 deletions gossip/gossip/gossip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,16 +909,9 @@ func createDataMsg(seqnum uint64, data []byte, hash string, channel common.Chain
}

func createLeadershipMsg(isDeclaration bool, channel common.ChainID, incTime uint64, seqNum uint64, endpoint string, pkiid []byte) *proto.GossipMessage {

metadata := []byte{}
metadata = strconv.AppendBool(metadata, isDeclaration)

leadershipMsg := &proto.LeadershipMessage{
Membership: &proto.Member{
PkiID: pkiid,
Endpoint: endpoint,
Metadata: metadata,
},
IsDeclaration: isDeclaration,
PkiID: pkiid,
Timestamp: &proto.PeerTime{
IncNumber: incTime,
SeqNum: seqNum,
Expand Down
2 changes: 1 addition & 1 deletion protos/gossip/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func aliveInvalidationPolicy(thisMsg *AliveMessage, thatMsg *AliveMessage) commo
}

func leaderInvalidationPolicy(thisMsg *LeadershipMessage, thatMsg *LeadershipMessage) common.InvalidationResult {
if !bytes.Equal(thisMsg.Membership.PkiID, thatMsg.Membership.PkiID) {
if !bytes.Equal(thisMsg.PkiID, thatMsg.PkiID) {
return common.MessageNoAction
}

Expand Down
Loading

0 comments on commit 0b0c357

Please sign in to comment.