Skip to content

Commit 76bb2a0

Browse files
committed
[FAB-2007] Gossip/discovery: Change Exists to Lookup
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 <[email protected]>
1 parent 48987d2 commit 76bb2a0

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

gossip/discovery/discovery.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,8 @@ func (nm NetworkMember) PreferredEndpoint() string {
9393
// Discovery is the interface that represents a discovery module
9494
type Discovery interface {
9595

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

10099
// Self returns this instance's membership information
101100
Self() NetworkMember

gossip/discovery/discovery_impl.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,12 @@ func NewDiscoveryService(bootstrapPeers []string, self NetworkMember, comm CommS
124124
return d
125125
}
126126

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

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

gossip/discovery/discovery_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -526,10 +526,11 @@ func TestGetFullMembership(t *testing.T) {
526526
}
527527
}
528528

529-
// Check that Exists() is valid
529+
// Check that Lookup() is valid
530530
for _, inst := range instances {
531531
for _, member := range inst.GetMembership() {
532-
assert.True(t, inst.Exists(member.PKIid))
532+
assert.Equal(t, string(member.PKIid), inst.Lookup(member.PKIid).Endpoint)
533+
assert.Equal(t, member.PKIid, inst.Lookup(member.PKIid).PKIid)
533534
}
534535
}
535536

0 commit comments

Comments
 (0)