Skip to content

Commit

Permalink
[FAB-2007] Gossip/disc: aliveMsg w/o secretEnvelope
Browse files Browse the repository at this point in the history
In preperation to the gossip layer passing to the discovery layer
Alive messages that have no secret envelopes
(i.e originated from external organizations), we need to take care
not to over-write the internal endpoint when such a message arrives.

This commit takes care of it.

Change-Id: I24544d3e902cda69f3d056def81d620937744254
Signed-off-by: Yacov Manevich <yacovm@il.ibm.com>
  • Loading branch information
yacovm committed Mar 5, 2017
1 parent 76bb2a0 commit 458f435
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
22 changes: 14 additions & 8 deletions gossip/discovery/discovery_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ func (d *gossipDiscoveryImpl) handleMsgFromComm(m *proto.SignedGossipMessage) {
d.logger.Warning("Failed deserializing GossipMessage from envelope:", err)
return
}

d.handleAliveMessage(selfInfoGossipMsg)

var internalEndpoint string
Expand Down Expand Up @@ -333,6 +334,7 @@ func (d *gossipDiscoveryImpl) handleMsgFromComm(m *proto.SignedGossipMessage) {
d.logger.Warning("Expected alive message, got", am, "instead")
return
}

d.handleAliveMessage(am)
}

Expand Down Expand Up @@ -399,6 +401,7 @@ func (d *gossipDiscoveryImpl) createMembershipResponse(targetMember *NetworkMemb
defer d.lock.RUnlock()

deadPeers := []*proto.Envelope{}

for _, dm := range d.deadMembership.ToSlice() {

if !shouldBeDisclosed(dm) {
Expand Down Expand Up @@ -502,6 +505,9 @@ func (d *gossipDiscoveryImpl) resurrectMember(am *proto.SignedGossipMessage, t p
}

var internalEndpoint string
if prevNetMem := d.id2Member[string(pkiID)]; prevNetMem != nil {
internalEndpoint = prevNetMem.InternalEndpoint
}
if am.Envelope.SecretEnvelope != nil {
internalEndpoint = am.Envelope.SecretEnvelope.InternalEndpoint()
}
Expand Down Expand Up @@ -715,7 +721,9 @@ func (d *gossipDiscoveryImpl) learnExistingMembers(aliveArr []*proto.SignedGossi
d.logger.Debug("updating", am)

var internalEndpoint string

if prevNetMem := d.id2Member[string(am.Membership.PkiId)]; prevNetMem != nil {
internalEndpoint = prevNetMem.InternalEndpoint
}
if m.Envelope.SecretEnvelope != nil {
internalEndpoint = m.Envelope.SecretEnvelope.InternalEndpoint()
}
Expand Down Expand Up @@ -804,6 +812,10 @@ func (d *gossipDiscoveryImpl) learnNewMembers(aliveMembers []*proto.SignedGossip
internalEndpoint = m.Envelope.SecretEnvelope.InternalEndpoint()
}

if prevNetMem := d.id2Member[string(member.Membership.PkiId)]; prevNetMem != nil {
internalEndpoint = prevNetMem.InternalEndpoint
}

d.id2Member[string(member.Membership.PkiId)] = &NetworkMember{
Endpoint: member.Membership.Endpoint,
Metadata: member.Membership.Metadata,
Expand All @@ -823,18 +835,12 @@ func (d *gossipDiscoveryImpl) GetMembership() []NetworkMember {

response := []NetworkMember{}
for _, m := range d.aliveMembership.ToSlice() {
var internalEndpoint string

if m.Envelope.SecretEnvelope != nil {
internalEndpoint = m.Envelope.SecretEnvelope.InternalEndpoint()
}

member := m.GetAliveMsg()
response = append(response, NetworkMember{
PKIid: member.Membership.PkiId,
Endpoint: member.Membership.Endpoint,
Metadata: member.Membership.Metadata,
InternalEndpoint: internalEndpoint,
InternalEndpoint: d.id2Member[string(m.GetAliveMsg().Membership.PkiId)].InternalEndpoint,
})
}
return response
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 @@ -358,7 +358,7 @@ func TestConnect(t *testing.T) {
inst.Connect(netMember2Connect2, false)
}

time.Sleep(time.Second * 1)
time.Sleep(time.Second * 3)
assert.Len(t, firstSentMemReqMsgs, 10)
close(firstSentMemReqMsgs)
for firstSentSelfMsg := range firstSentMemReqMsgs {
Expand Down

0 comments on commit 458f435

Please sign in to comment.