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
ab161cf6
Commit
ab161cf6
authored
9 years ago
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean up organization of receivemessage and fix race
parent
efa442ad
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
8 deletions
+21
-8
exchange/bitswap/bitswap.go
exchange/bitswap/bitswap.go
+19
-6
exchange/bitswap/wantmanager.go
exchange/bitswap/wantmanager.go
+2
-2
No files found.
exchange/bitswap/bitswap.go
View file @
ab161cf6
...
...
@@ -270,26 +270,40 @@ func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg
// TODO: this is bad, and could be easily abused.
// Should only track *useful* messages in ledger
if
len
(
incoming
.
Blocks
())
==
0
{
iblocks
:=
incoming
.
Blocks
()
if
len
(
iblocks
)
==
0
{
return
}
// quickly send out cancels, reduces chances of duplicate block receives
var
keys
[]
u
.
Key
for
_
,
block
:=
range
i
ncoming
.
B
locks
()
{
for
_
,
block
:=
range
i
b
locks
{
keys
=
append
(
keys
,
block
.
Key
())
}
bs
.
wm
.
CancelWants
(
keys
)
for
_
,
block
:=
range
i
ncoming
.
B
locks
()
{
for
_
,
block
:=
range
i
b
locks
{
bs
.
counterLk
.
Lock
()
bs
.
blocksRecvd
++
if
has
,
err
:=
bs
.
blockstore
.
Has
(
block
.
Key
());
err
==
nil
&&
has
{
has
,
err
:=
bs
.
blockstore
.
Has
(
block
.
Key
())
if
err
==
nil
&&
has
{
bs
.
dupBlocksRecvd
++
}
brecvd
:=
bs
.
blocksRecvd
bdup
:=
bs
.
dupBlocksRecvd
bs
.
counterLk
.
Unlock
()
if
has
{
continue
}
// put this after the duplicate check as a block not on our wantlist may
// have already been received.
if
_
,
found
:=
bs
.
wm
.
wl
.
Contains
(
block
.
Key
());
!
found
{
log
.
Notice
(
"received un-asked-for block: %s"
,
block
)
continue
}
log
.
Infof
(
"got block %s from %s (%d,%d)"
,
block
,
p
,
brecvd
,
bdup
)
hasBlockCtx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
hasBlockTimeout
)
...
...
@@ -302,7 +316,6 @@ func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg
// Connected/Disconnected warns bitswap about peer connections
func
(
bs
*
Bitswap
)
PeerConnected
(
p
peer
.
ID
)
{
// TODO: add to clientWorker??
bs
.
wm
.
Connected
(
p
)
}
...
...
@@ -313,7 +326,7 @@ func (bs *Bitswap) PeerDisconnected(p peer.ID) {
}
func
(
bs
*
Bitswap
)
ReceiveError
(
err
error
)
{
log
.
Debug
f
(
"Bitswap ReceiveError: %s"
,
err
)
log
.
Info
f
(
"Bitswap ReceiveError: %s"
,
err
)
// TODO log the network error
// TODO bubble the network error up to the parent context/error logger
}
...
...
This diff is collapsed.
Click to expand it.
exchange/bitswap/wantmanager.go
View file @
ab161cf6
...
...
@@ -21,7 +21,7 @@ type WantManager struct {
// synchronized by Run loop, only touch inside there
peers
map
[
peer
.
ID
]
*
msgQueue
wl
*
wantlist
.
Wantlist
wl
*
wantlist
.
ThreadSafe
network
bsnet
.
BitSwapNetwork
ctx
context
.
Context
...
...
@@ -33,7 +33,7 @@ func NewWantManager(ctx context.Context, network bsnet.BitSwapNetwork) *WantMana
connect
:
make
(
chan
peer
.
ID
,
10
),
disconnect
:
make
(
chan
peer
.
ID
,
10
),
peers
:
make
(
map
[
peer
.
ID
]
*
msgQueue
),
wl
:
wantlist
.
New
(),
wl
:
wantlist
.
New
ThreadSafe
(),
network
:
network
,
ctx
:
ctx
,
}
...
...
This diff is collapsed.
Click to expand it.
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