Commit 8c7bf926 authored by Steven Allen's avatar Steven Allen

feat: normalize message logging

parent 484399b4
......@@ -466,7 +466,7 @@ func (mq *MessageQueue) simulateDontHaveWithTimeout(wantlist []bsmsg.Entry) {
func (mq *MessageQueue) logOutgoingMessage(wantlist []bsmsg.Entry) {
// Save some CPU cycles and allocations if log level is higher than debug
if ce := sflog.Check(zap.DebugLevel, "Bitswap -> send wants"); ce == nil {
if ce := sflog.Check(zap.DebugLevel, "sent message"); ce == nil {
return
}
......@@ -474,15 +474,35 @@ func (mq *MessageQueue) logOutgoingMessage(wantlist []bsmsg.Entry) {
for _, e := range wantlist {
if e.Cancel {
if e.WantType == pb.Message_Wantlist_Have {
log.Debugw("Bitswap -> cancel-have", "local", self, "to", mq.p, "cid", e.Cid)
log.Debugw("sent message",
"type", "CANCEL_WANT_HAVE",
"cid", e.Cid,
"local", self,
"to", mq.p,
)
} else {
log.Debugw("Bitswap -> cancel-block", "local", self, "to", mq.p, "cid", e.Cid)
log.Debugw("sent message",
"type", "CANCEL_WANT_BLOCK",
"cid", e.Cid,
"local", self,
"to", mq.p,
)
}
} else {
if e.WantType == pb.Message_Wantlist_Have {
log.Debugw("Bitswap -> want-have", "local", self, "to", mq.p, "cid", e.Cid)
log.Debugw("sent message",
"type", "WANT_HAVE",
"cid", e.Cid,
"local", self,
"to", mq.p,
)
} else {
log.Debugw("Bitswap -> want-block", "local", self, "to", mq.p, "cid", e.Cid)
log.Debugw("sent message",
"type", "WANT_BLOCK",
"cid", e.Cid,
"local", self,
"to", mq.p,
)
}
}
}
......
......@@ -67,24 +67,28 @@ func (bs *Bitswap) taskWorker(ctx context.Context, id int) {
}
func (bs *Bitswap) logOutgoingBlocks(env *engine.Envelope) {
if ce := sflog.Check(zap.DebugLevel, "Bitswap -> send blocks"); ce == nil {
if ce := sflog.Check(zap.DebugLevel, "sent message"); ce == nil {
return
}
self := bs.network.Self()
for _, blockPresence := range env.Message.BlockPresences() {
c := blockPresence.Cid
switch blockPresence.Type {
case pb.Message_Have:
log.Debugw("sending message",
log.Debugw("sent message",
"type", "HAVE",
"cid", c,
"peer", env.Peer,
"local", self,
"to", env.Peer,
)
case pb.Message_DontHave:
log.Debugw("sending message",
log.Debugw("sent message",
"type", "DONT_HAVE",
"cid", c,
"peer", env.Peer,
"local", self,
"to", env.Peer,
)
default:
panic(fmt.Sprintf("unrecognized BlockPresence type %v", blockPresence.Type))
......@@ -92,10 +96,11 @@ func (bs *Bitswap) logOutgoingBlocks(env *engine.Envelope) {
}
for _, block := range env.Message.Blocks() {
log.Debugw("sending message",
log.Debugw("sent message",
"type", "BLOCK",
"cid", block.Cid(),
"peer", env.Peer,
"local", self,
"to", env.Peer,
)
}
}
......@@ -105,8 +110,6 @@ func (bs *Bitswap) sendBlocks(ctx context.Context, env *engine.Envelope) {
// throughout the network stack
defer env.Sent()
bs.logOutgoingBlocks(env)
err := bs.network.SendMessage(ctx, env.Peer, env.Message)
if err != nil {
log.Debugw("failed to send blocks message",
......@@ -116,6 +119,8 @@ func (bs *Bitswap) sendBlocks(ctx context.Context, env *engine.Envelope) {
return
}
bs.logOutgoingBlocks(env)
dataSent := 0
blocks := env.Message.Blocks()
for _, b := range blocks {
......
Markdown is supported
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