Skip to content

Commit

Permalink
[FAB-10222] Honor maximum peers to send if 0
Browse files Browse the repository at this point in the history
When the collection config specifies max peers, it might be 0.

Currently, gossip assumes that if the max peers is 0 then it was
omitted, and just sets the max peers to all the known peers.

Since collection membership can change in v1.2, we should be
conservative and enforce 0 max peers as 0.

Change-Id: Idef84b6d5d88a719c737aef05b65a724a3a38468
Signed-off-by: yacovm <yacovm@il.ibm.com>
yacovm committed May 19, 2018
1 parent c6d0e6c commit 9d52471
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 3 additions & 3 deletions gossip/gossip/gossip_impl.go
Original file line number Diff line number Diff line change
@@ -611,6 +611,9 @@ func (g *gossipServiceImpl) IdentityInfo() api.PeerIdentitySet {

// SendByCriteria sends a given message to all peers that match the given SendCriteria
func (g *gossipServiceImpl) SendByCriteria(msg *proto.SignedGossipMessage, criteria SendCriteria) error {
if criteria.MaxPeers == 0 {
return nil
}
if criteria.Timeout == 0 {
return errors.New("Timeout should be specified")
}
@@ -620,9 +623,6 @@ func (g *gossipServiceImpl) SendByCriteria(msg *proto.SignedGossipMessage, crite
}

membership := g.disc.GetMembership()
if criteria.MaxPeers == 0 {
criteria.MaxPeers = len(membership)
}

if len(criteria.Channel) > 0 {
gc := g.chanState.getGossipChannelByChainID(criteria.Channel)
17 changes: 16 additions & 1 deletion gossip/gossip/gossip_test.go
Original file line number Diff line number Diff line change
@@ -1144,8 +1144,23 @@ func TestSendByCriteria(t *testing.T) {
defer stopPeers(peers)
msg, _ := createDataMsg(1, []byte{}, common.ChainID("A")).NoopSign()

// We send without specifying maximum peers,
// whic sets it to the zero value, and
// this is a no-op.
criteria := SendCriteria{
IsEligible: func(discovery.NetworkMember) bool {
t.Fatal("Shouldn't have called, because when max peers is 0, the operation is a no-op")
return false
},
Timeout: time.Second * 1,
MinAck: 1,
}
assert.NoError(t, g1.SendByCriteria(msg, criteria))

// We send without specifying a timeout
criteria := SendCriteria{}
criteria = SendCriteria{
MaxPeers: 100,
}
err := g1.SendByCriteria(msg, criteria)
assert.Error(t, err)
assert.Equal(t, "Timeout should be specified", err.Error())

0 comments on commit 9d52471

Please sign in to comment.