@cryptotaxi247 / kubo / commits / 0514504d0

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: David Grisham <dgrisham@mines.edu>

dgrisham committed Apr 24, 2017 at 15:50 UTC 0514504d093464d4ba6f3df32bb2c28889b5c31e
1 file changed +8
exchange/bitswap/workers.go
+8
@@ -6,6 +6,8 @@ import (
6 "sync"
7 "time"
8
9 + bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message"
10 +
11 process "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess"
12 procctx "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess/context"
13 logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
@@ -63,6 +65,12 @@ func (bs *Bitswap) taskWorker(ctx context.Context, id int) {
65 "Block": envelope.Block.Cid().String(),
66 })
67
68 + // update the BS ledger to reflect sent message
69 + // TODO: Should only track *useful* messages in ledger
70 + outgoing := bsmsg.New(false)
71 + outgoing.AddBlock(envelope.Block)
72 + bs.engine.MessageSent(envelope.Peer, outgoing)
73 +
74 bs.wm.SendBlock(ctx, envelope)
75 bs.counterLk.Lock()
76 bs.blocksSent++