Skip to content

Commit

Permalink
Add stringer for channelID type (#2016)
Browse files Browse the repository at this point in the history
Channel names are currently byte arrays in the logs,
add stringer to convert the to string when printing

Signed-off-by: Brett Logan <brett.t.logan@ibm.com>
  • Loading branch information
Brett Logan authored Oct 15, 2020
1 parent 0ee3295 commit d43e5dd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions gossip/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ type Payload struct {
// ChannelID defines the identity representation of a chain
type ChannelID []byte

func (c ChannelID) String() string {
return string(c)
}

// MessageReplacingPolicy Returns:
// MESSAGE_INVALIDATES if this message invalidates that
// MESSAGE_INVALIDATED if this message is invalidated by that
Expand Down
8 changes: 4 additions & 4 deletions gossip/gossip/gossip_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (g *Node) JoinChan(joinMsg api.JoinChannelMessage, channelID common.Channel
// joinMsg is supposed to have been already verified
g.chanState.joinChannel(joinMsg, channelID, g.gossipMetrics.MembershipMetrics)

g.logger.Info("Joining gossip network of channel", string(channelID), "with", len(joinMsg.Members()), "organizations")
g.logger.Info("Joining gossip network of channel", channelID, "with", len(joinMsg.Members()), "organizations")
for _, org := range joinMsg.Members() {
g.learnAnchorPeers(string(channelID), org, joinMsg.AnchorPeersOf(org))
}
Expand Down Expand Up @@ -623,14 +623,14 @@ func (g *Node) SendByCriteria(msg *protoext.SignedGossipMessage, criteria SendCr
if len(criteria.Channel) > 0 {
gc := g.chanState.getGossipChannelByChainID(criteria.Channel)
if gc == nil {
return fmt.Errorf("Requested to Send for channel %s, but no such channel exists", string(criteria.Channel))
return fmt.Errorf("requested to Send for channel %s, but no such channel exists", criteria.Channel)
}
membership = gc.GetPeers()
}

peers2send := filter.SelectPeers(criteria.MaxPeers, membership, criteria.IsEligible)
if len(peers2send) < criteria.MinAck {
return fmt.Errorf("Requested to send to at least %d peers, but know only of %d suitable peers", criteria.MinAck, len(peers2send))
return fmt.Errorf("requested to send to at least %d peers, but know only of %d suitable peers", criteria.MinAck, len(peers2send))
}

results := g.comm.SendWithAck(msg, criteria.Timeout, criteria.MinAck, peers2send...)
Expand Down Expand Up @@ -742,7 +742,7 @@ func (g *Node) SelfChannelInfo(chain common.ChannelID) *protoext.SignedGossipMes
func (g *Node) PeerFilter(channel common.ChannelID, messagePredicate api.SubChannelSelectionCriteria) (filter.RoutingFilter, error) {
gc := g.chanState.getGossipChannelByChainID(channel)
if gc == nil {
return nil, errors.Errorf("Channel %s doesn't exist", string(channel))
return nil, errors.Errorf("Channel %s doesn't exist", channel)
}
return gc.PeerFilter(messagePredicate), nil
}
Expand Down
2 changes: 1 addition & 1 deletion gossip/gossip/gossip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ func TestSendByCriteria(t *testing.T) {
criteria.MinAck = 10
err = g1.SendByCriteria(msg, criteria)
require.Error(t, err)
require.Contains(t, err.Error(), "Requested to send to at least 10 peers, but know only of")
require.Contains(t, err.Error(), "requested to send to at least 10 peers, but know only of")

// We send to a minimum of 3 peers with acknowledgement, while no peer acknowledges the messages.
// Wait until g1 sees the rest of the peers in the channel
Expand Down

0 comments on commit d43e5dd

Please sign in to comment.