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-dms3
Commits
4ac2c46c
Commit
4ac2c46c
authored
Sep 25, 2015
by
Juan Benet
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1752 from ipfs/feat/stat-count
allow bitswap stat to return total number of bytes wasted
parents
d3b873cc
0c742164
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
3 deletions
+8
-3
core/commands/bitswap.go
core/commands/bitswap.go
+1
-0
exchange/bitswap/bitswap.go
exchange/bitswap/bitswap.go
+5
-3
exchange/bitswap/stat.go
exchange/bitswap/stat.go
+2
-0
No files found.
core/commands/bitswap.go
View file @
4ac2c46c
...
...
@@ -156,6 +156,7 @@ var bitswapStatCmd = &cmds.Command{
fmt
.
Fprintf
(
buf
,
"
\t
provides buffer: %d / %d
\n
"
,
out
.
ProvideBufLen
,
bitswap
.
HasBlockBufferSize
)
fmt
.
Fprintf
(
buf
,
"
\t
blocks received: %d
\n
"
,
out
.
BlocksReceived
)
fmt
.
Fprintf
(
buf
,
"
\t
dup blocks received: %d
\n
"
,
out
.
DupBlksReceived
)
fmt
.
Fprintf
(
buf
,
"
\t
dup data received: %d
\n
"
,
out
.
DupDataReceived
)
fmt
.
Fprintf
(
buf
,
"
\t
wantlist [%d keys]
\n
"
,
len
(
out
.
Wantlist
))
for
_
,
k
:=
range
out
.
Wantlist
{
fmt
.
Fprintf
(
buf
,
"
\t\t
%s
\n
"
,
k
.
B58String
())
...
...
exchange/bitswap/bitswap.go
View file @
4ac2c46c
...
...
@@ -131,6 +131,7 @@ type Bitswap struct {
counterLk
sync
.
Mutex
blocksRecvd
int
dupBlocksRecvd
int
dupDataRecvd
uint64
}
type
blockRequest
struct
{
...
...
@@ -320,7 +321,7 @@ func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg
go
func
(
b
*
blocks
.
Block
)
{
defer
wg
.
Done
()
if
err
:=
bs
.
updateReceiveCounters
(
b
.
Key
()
);
err
!=
nil
{
if
err
:=
bs
.
updateReceiveCounters
(
b
);
err
!=
nil
{
return
// ignore error, is either logged previously, or ErrAlreadyHaveBlock
}
...
...
@@ -338,17 +339,18 @@ func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg
var
ErrAlreadyHaveBlock
=
errors
.
New
(
"already have block"
)
func
(
bs
*
Bitswap
)
updateReceiveCounters
(
k
key
.
Key
)
error
{
func
(
bs
*
Bitswap
)
updateReceiveCounters
(
b
*
blocks
.
Block
)
error
{
bs
.
counterLk
.
Lock
()
defer
bs
.
counterLk
.
Unlock
()
bs
.
blocksRecvd
++
has
,
err
:=
bs
.
blockstore
.
Has
(
k
)
has
,
err
:=
bs
.
blockstore
.
Has
(
b
.
Key
()
)
if
err
!=
nil
{
log
.
Infof
(
"blockstore.Has error: %s"
,
err
)
return
err
}
if
err
==
nil
&&
has
{
bs
.
dupBlocksRecvd
++
bs
.
dupDataRecvd
+=
uint64
(
len
(
b
.
Data
))
}
if
has
{
...
...
exchange/bitswap/stat.go
View file @
4ac2c46c
...
...
@@ -11,6 +11,7 @@ type Stat struct {
Peers
[]
string
BlocksReceived
int
DupBlksReceived
int
DupDataReceived
uint64
}
func
(
bs
*
Bitswap
)
Stat
()
(
*
Stat
,
error
)
{
...
...
@@ -20,6 +21,7 @@ func (bs *Bitswap) Stat() (*Stat, error) {
bs
.
counterLk
.
Lock
()
st
.
BlocksReceived
=
bs
.
blocksRecvd
st
.
DupBlksReceived
=
bs
.
dupBlocksRecvd
st
.
DupDataReceived
=
bs
.
dupDataRecvd
bs
.
counterLk
.
Unlock
()
for
_
,
p
:=
range
bs
.
engine
.
Peers
()
{
...
...
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