Skip to content

Commit

Permalink
Merge "Decouple gossip.LeadershipMsg and networkMember"
Browse files Browse the repository at this point in the history
  • Loading branch information
christo4ferris authored and Gerrit Code Review committed Feb 7, 2017
2 parents acf500e + 0b0c357 commit e614654
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 e614654

Please sign in to comment.