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
78ce3724
Commit
78ce3724
authored
Jan 20, 2017
by
Jakub Sztandera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: cleanup bitswap metrics collection
License: MIT Signed-off-by:
Jakub Sztandera
<
kubuxu@protonmail.ch
>
parent
21567705
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
14 deletions
+12
-14
bitswap.go
bitswap.go
+12
-14
No files found.
bitswap.go
View file @
78ce3724
...
...
@@ -368,9 +368,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
);
err
!=
nil
{
return
// ignore error, is either logged previously, or ErrAlreadyHaveBlock
}
bs
.
updateReceiveCounters
(
b
)
k
:=
b
.
Cid
()
log
.
Event
(
ctx
,
"Bitswap.GetBlockRequest.End"
,
k
)
...
...
@@ -386,27 +384,27 @@ func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg
var
ErrAlreadyHaveBlock
=
errors
.
New
(
"already have block"
)
func
(
bs
*
Bitswap
)
updateReceiveCounters
(
b
blocks
.
Block
)
error
{
bs
.
counterLk
.
Lock
()
defer
bs
.
counterLk
.
Unlock
()
func
(
bs
*
Bitswap
)
updateReceiveCounters
(
b
blocks
.
Block
)
{
blkLen
:=
len
(
b
.
RawData
())
bs
.
allMetric
.
Observe
(
float64
(
blkLen
))
bs
.
blocksRecvd
++
has
,
err
:=
bs
.
blockstore
.
Has
(
b
.
Cid
())
if
err
!=
nil
{
log
.
Infof
(
"blockstore.Has error: %s"
,
err
)
return
err
return
}
if
err
==
nil
&&
has
{
bs
.
allMetric
.
Observe
(
float64
(
blkLen
))
if
has
{
bs
.
dupMetric
.
Observe
(
float64
(
blkLen
))
bs
.
dupBlocksRecvd
++
bs
.
dupDataRecvd
+=
uint64
(
blkLen
)
}
bs
.
counterLk
.
Lock
()
defer
bs
.
counterLk
.
Unlock
()
bs
.
blocksRecvd
++
if
has
{
return
ErrAlreadyHaveBlock
bs
.
dupBlocksRecvd
++
bs
.
dupDataRecvd
+=
uint64
(
blkLen
)
}
return
nil
}
// Connected/Disconnected warns bitswap about peer connections
...
...
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