Commit 0514504d authored by dgrisham's avatar dgrisham

bug fix: `BytesSent` in peers' ledgers now updates

When sending data to another user, the number of bytes sent to that user (saved
by the corresponding Bitswap ledger) was not updated (it was always 0). This
also meant that the debt ratio was also always 0.

The function that updates the `BytesSent` value in the ledger, `MessageSent()`,
was already implemented, however it was not called when the peer was sent data.
To fix this, a call to `MessageSent()` was made in the `taskWorker()` function,
which is where both the message in question and the Bitswap engine were
available to make the call. `MessageSent()` requires the peer's ID and
`BitSwapMessage` as its arguments, the latter of which had to be created by
making a new `BitSwapMessage`, then the block being sent was added to the new
message.

Note that, similar to the analagous call to `MessageReceived()`, records *all*
of the bytes sent to a particular user. At some point, both of these should be
updated to only record the numbers of *useful* bytes sent and received between
peers.

License: MIT
Signed-off-by: default avatarDavid Grisham <dgrisham@mines.edu>
parent e17a6dd8
......@@ -6,6 +6,8 @@ import (
"sync"
"time"
bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message"
process "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess"
procctx "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess/context"
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
......@@ -63,6 +65,12 @@ func (bs *Bitswap) taskWorker(ctx context.Context, id int) {
"Block": envelope.Block.Cid().String(),
})
// update the BS ledger to reflect sent message
// TODO: Should only track *useful* messages in ledger
outgoing := bsmsg.New(false)
outgoing.AddBlock(envelope.Block)
bs.engine.MessageSent(envelope.Peer, outgoing)
bs.wm.SendBlock(ctx, envelope)
bs.counterLk.Lock()
bs.blocksSent++
......
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