Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-bitswap
Commits
3d7d133e
Commit
3d7d133e
authored
Aug 05, 2016
by
Thomas Gardner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bitswap: add `ledger` subcommand
License: MIT Signed-off-by:
Thomas Gardner
<
tmg@fastmail.com
>
parent
3fbf157a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
0 deletions
+27
-0
bitswap.go
bitswap.go
+4
-0
decision/engine.go
decision/engine.go
+15
-0
decision/ledger.go
decision/ledger.go
+8
-0
No files found.
bitswap.go
View file @
3d7d133e
...
@@ -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.
...
...
decision/engine.go
View file @
3d7d133e
...
@@ -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
{
...
...
decision/ledger.go
View file @
3d7d133e
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment