Skip to content

Commit

Permalink
[FAB-5848] Identity Pull formatting
Browse files Browse the repository at this point in the history
This change set makes identity digests be printed not in gibberish

This is how they are printed with this patch:
[gossip/pull] SendDigest -> DEBU f38 Sending IDENTITY_MSG digest: \
 [67a915badc8a2f9652aeb4c09463adf706d79e0f5393233c6473bee165ee4571 \
84ce9658381b0208178b4ee67b5267605f1641a448d3dd1401cb224aa1ec6f6e \
5a4ec05179d9bafceb546432f7458995c92c42c6fdc10fa0fdefe449c1b46eba \
a74e91e5ea97f87f9f95c0c455963ac5e9dc73a7f99154613e1c17dc7c31fbf1] \
to 172.20.0.4:7051 [90 78 192 81 121 217 186 252 235 84 100 50 247\
 69 137 149 201 44 66 198 253 193 15 160 253 239 228 73 193 180 110 186]

Change-Id: I32192cce7fd67921328c10345263e661eaa8f296
Signed-off-by: yacovm <yacovm@il.ibm.com>
  • Loading branch information
yacovm committed Aug 19, 2017
1 parent 115d9c0 commit 493aee9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
9 changes: 7 additions & 2 deletions gossip/gossip/pull/pullstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,10 @@ func (p *pullMediatorImpl) SendDigest(digest []string, nonce uint64, context int
},
}
remotePeer := context.(proto.ReceivedMessage).GetConnectionInfo()
p.logger.Debug("Sending", p.config.MsgType, "digest:", digMsg.GetDataDig().Digests, "to", remotePeer)
if p.logger.IsEnabledFor(logging.DEBUG) {
p.logger.Debug("Sending", p.config.MsgType, "digest:", digMsg.GetDataDig().FormattedDigests(), "to", remotePeer)
}

context.(proto.ReceivedMessage).Respond(digMsg)
}

Expand All @@ -295,7 +298,9 @@ func (p *pullMediatorImpl) SendReq(dest string, items []string, nonce uint64) {
},
},
}
p.logger.Debug("Sending", req, "to", dest)
if p.logger.IsEnabledFor(logging.DEBUG) {
p.logger.Debug("Sending", req.GetDataReq().FormattedDigests(), "to", dest)
}
sMsg, err := req.NoopSign()
if err != nil {
p.logger.Warning("Failed creating SignedGossipMessage:", err)
Expand Down
23 changes: 23 additions & 0 deletions protos/gossip/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package gossip

import (
"bytes"
"encoding/hex"
"errors"
"fmt"

Expand Down Expand Up @@ -542,6 +543,28 @@ func (m *SignedGossipMessage) String() string {
return fmt.Sprintf("GossipMessage: %v, Envelope: %s", gMsg, env)
}

func (dd *DataRequest) FormattedDigests() []string {
if dd.MsgType == PullMsgType_IDENTITY_MSG {
return digestsToHex(dd.Digests)
}
return dd.Digests
}

func (dd *DataDigest) FormattedDigests() []string {
if dd.MsgType == PullMsgType_IDENTITY_MSG {
return digestsToHex(dd.Digests)
}
return dd.Digests
}

func digestsToHex(digests []string) []string {
a := make([]string, len(digests))
for i, dig := range digests {
a[i] = hex.EncodeToString([]byte(dig))
}
return a
}

// Abs returns abs(a-b)
func abs(a, b uint64) uint64 {
if a > b {
Expand Down

0 comments on commit 493aee9

Please sign in to comment.