Commit d13d614b authored by Christopher Ferris's avatar Christopher Ferris Committed by Gerrit Code Review
Browse files

Merge "[FAB-10222] Honor maximum peers to send if 0"

parents 2bc684ee 9d524719
......@@ -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)
......
......@@ -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())
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment