Skip to content

Commit

Permalink
[FAB-2007] Gossip/discovery: Change Exists to Lookup
Browse files Browse the repository at this point in the history
In order to support FAB-2007, the gossip layer needs to figure out
whether a remote peer has published an external endpoint or not,
to know if to send (or not) Alive messages of external organizations

Change-Id: I2e0055e163fa413295caa736098d2657f2bef65f
Signed-off-by: Yacov Manevich <yacovm@il.ibm.com>
  • Loading branch information
yacovm committed Mar 5, 2017
1 parent 48987d2 commit 76bb2a0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
5 changes: 2 additions & 3 deletions gossip/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ func (nm NetworkMember) PreferredEndpoint() string {
// Discovery is the interface that represents a discovery module
type Discovery interface {

// Exists returns whether a peer with given
// PKI-ID is known
Exists(PKIID common.PKIidType) bool
// Lookup returns a network member, or nil if not found
Lookup(PKIID common.PKIidType) *NetworkMember

// Self returns this instance's membership information
Self() NetworkMember
Expand Down
12 changes: 5 additions & 7 deletions gossip/discovery/discovery_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,12 @@ func NewDiscoveryService(bootstrapPeers []string, self NetworkMember, comm CommS
return d
}

// Exists returns whether a peer with given
// PKI-ID is known
func (d *gossipDiscoveryImpl) Exists(PKIID common.PKIidType) bool {
// Lookup returns a network member, or nil if not found
func (d *gossipDiscoveryImpl) Lookup(PKIID common.PKIidType) *NetworkMember {
d.lock.RLock()
defer d.lock.RUnlock()
_, exists := d.id2Member[string(PKIID)]
return exists
nm := d.id2Member[string(PKIID)]
return nm
}

func (d *gossipDiscoveryImpl) Connect(member NetworkMember, sendInternalEndpoint bool) {
Expand Down Expand Up @@ -291,8 +290,7 @@ func (d *gossipDiscoveryImpl) handleMsgFromComm(m *proto.SignedGossipMessage) {
return
}
if m.GetAliveMsg() == nil && m.GetMemRes() == nil && m.GetMemReq() == nil {
d.logger.Warning("Got message with wrong type (expected Alive or MembershipResponse or MembershipRequest message):", m.Content) // TODO: write only message type
d.logger.Warning(m)
d.logger.Warning("Got message with wrong type (expected Alive or MembershipResponse or MembershipRequest message):", m.GossipMessage)
return
}

Expand Down
5 changes: 3 additions & 2 deletions gossip/discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,11 @@ func TestGetFullMembership(t *testing.T) {
}
}

// Check that Exists() is valid
// Check that Lookup() is valid
for _, inst := range instances {
for _, member := range inst.GetMembership() {
assert.True(t, inst.Exists(member.PKIid))
assert.Equal(t, string(member.PKIid), inst.Lookup(member.PKIid).Endpoint)
assert.Equal(t, member.PKIid, inst.Lookup(member.PKIid).PKIid)
}
}

Expand Down

0 comments on commit 76bb2a0

Please sign in to comment.