Commit 3d7d133e authored by Thomas Gardner's avatar Thomas Gardner

bitswap: add `ledger` subcommand

License: MIT
Signed-off-by: default avatarThomas Gardner <tmg@fastmail.com>
parent 3fbf157a
...@@ -205,6 +205,10 @@ func (bs *Bitswap) WantlistForPeer(p peer.ID) []key.Key { ...@@ -205,6 +205,10 @@ func (bs *Bitswap) WantlistForPeer(p peer.ID) []key.Key {
return out return out
} }
func (bs *Bitswap) LedgerForPeer(p peer.ID) *decision.Receipt {
return bs.engine.LedgerForPeer(p)
}
// GetBlocks returns a channel where the caller may receive blocks that // GetBlocks returns a channel where the caller may receive blocks that
// correspond to the provided |keys|. Returns an error if BitSwap is unable to // correspond to the provided |keys|. Returns an error if BitSwap is unable to
// begin this request within the deadline enforced by the context. // begin this request within the deadline enforced by the context.
......
...@@ -114,6 +114,21 @@ func (e *Engine) WantlistForPeer(p peer.ID) (out []wl.Entry) { ...@@ -114,6 +114,21 @@ func (e *Engine) WantlistForPeer(p peer.ID) (out []wl.Entry) {
return out return out
} }
func (e *Engine) LedgerForPeer(p peer.ID) *Receipt {
ledger := e.findOrCreate(p)
ledger.lk.Lock()
defer ledger.lk.Unlock()
return &Receipt{
Peer: ledger.Partner.String(),
Value: ledger.Accounting.Value(),
Sent: ledger.Accounting.BytesSent,
Recv: ledger.Accounting.BytesRecv,
Exchanged: ledger.ExchangeCount(),
}
}
func (e *Engine) taskWorker(ctx context.Context) { func (e *Engine) taskWorker(ctx context.Context) {
defer close(e.outbox) // because taskWorker uses the channel exclusively defer close(e.outbox) // because taskWorker uses the channel exclusively
for { for {
......
...@@ -49,6 +49,14 @@ type ledger struct { ...@@ -49,6 +49,14 @@ type ledger struct {
lk sync.Mutex lk sync.Mutex
} }
type Receipt struct {
Peer string
Value float64
Sent uint64
Recv uint64
Exchanged uint64
}
type debtRatio struct { type debtRatio struct {
BytesSent uint64 BytesSent uint64
BytesRecv uint64 BytesRecv uint64
......
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