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
bdd4629d
Commit
bdd4629d
authored
Mar 10, 2020
by
Dirk McCormick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: timeout when peer doesnt respond to want-block
parent
a441107f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
15 deletions
+10
-15
bitswap.go
bitswap.go
+1
-1
internal/messagequeue/donthavetimeoutmgr.go
internal/messagequeue/donthavetimeoutmgr.go
+3
-2
internal/messagequeue/messagequeue.go
internal/messagequeue/messagequeue.go
+6
-12
No files found.
bitswap.go
View file @
bdd4629d
...
@@ -125,7 +125,7 @@ func New(parent context.Context, network bsnet.BitSwapNetwork,
...
@@ -125,7 +125,7 @@ func New(parent context.Context, network bsnet.BitSwapNetwork,
var
wm
*
bswm
.
WantManager
var
wm
*
bswm
.
WantManager
// onDontHaveTimeout is called when a want-block is sent to a peer that
// onDontHaveTimeout is called when a want-block is sent to a peer that
// has an old version of Bitswap that doesn't support DONT_HAVE messages,
// has an old version of Bitswap that doesn't support DONT_HAVE messages,
//
and
no response is received within a timeout.
//
or when
no response is received within a timeout.
onDontHaveTimeout
:=
func
(
p
peer
.
ID
,
dontHaves
[]
cid
.
Cid
)
{
onDontHaveTimeout
:=
func
(
p
peer
.
ID
,
dontHaves
[]
cid
.
Cid
)
{
// Simulate a DONT_HAVE message arriving to the WantManager
// Simulate a DONT_HAVE message arriving to the WantManager
wm
.
ReceiveFrom
(
ctx
,
p
,
nil
,
nil
,
dontHaves
)
wm
.
ReceiveFrom
(
ctx
,
p
,
nil
,
nil
,
dontHaves
)
...
...
internal/messagequeue/donthavetimeoutmgr.go
View file @
bdd4629d
...
@@ -11,7 +11,8 @@ import (
...
@@ -11,7 +11,8 @@ import (
const
(
const
(
// dontHaveTimeout is used to simulate a DONT_HAVE when communicating with
// dontHaveTimeout is used to simulate a DONT_HAVE when communicating with
// a peer whose Bitswap client doesn't support the DONT_HAVE response.
// a peer whose Bitswap client doesn't support the DONT_HAVE response,
// or when the peer takes too long to respond.
// If the peer doesn't respond to a want-block within the timeout, the
// If the peer doesn't respond to a want-block within the timeout, the
// local node assumes that the peer doesn't have the block.
// local node assumes that the peer doesn't have the block.
dontHaveTimeout
=
5
*
time
.
Second
dontHaveTimeout
=
5
*
time
.
Second
...
@@ -45,7 +46,7 @@ type pendingWant struct {
...
@@ -45,7 +46,7 @@ type pendingWant struct {
// dontHaveTimeoutMgr pings the peer to measure latency. It uses the latency to
// dontHaveTimeoutMgr pings the peer to measure latency. It uses the latency to
// set a reasonable timeout for simulating a DONT_HAVE message for peers that
// set a reasonable timeout for simulating a DONT_HAVE message for peers that
// don't support DONT_HAVE
// don't support DONT_HAVE
or that take to long to respond.
type
dontHaveTimeoutMgr
struct
{
type
dontHaveTimeoutMgr
struct
{
ctx
context
.
Context
ctx
context
.
Context
shutdown
func
()
shutdown
func
()
...
...
internal/messagequeue/messagequeue.go
View file @
bdd4629d
...
@@ -392,10 +392,8 @@ func (mq *MessageQueue) sendMessage() {
...
@@ -392,10 +392,8 @@ func (mq *MessageQueue) sendMessage() {
}
}
// Make sure the DONT_HAVE timeout manager has started
// Make sure the DONT_HAVE timeout manager has started
if
!
mq
.
sender
.
SupportsHave
()
{
// Note: Start is idempotent
// Note: Start is idempotent
mq
.
dhTimeoutMgr
.
Start
()
mq
.
dhTimeoutMgr
.
Start
()
}
// Convert want lists to a Bitswap Message
// Convert want lists to a Bitswap Message
message
,
onSent
:=
mq
.
extractOutgoingMessage
(
mq
.
sender
.
SupportsHave
())
message
,
onSent
:=
mq
.
extractOutgoingMessage
(
mq
.
sender
.
SupportsHave
())
...
@@ -425,15 +423,11 @@ func (mq *MessageQueue) sendMessage() {
...
@@ -425,15 +423,11 @@ func (mq *MessageQueue) sendMessage() {
}
}
}
}
// If the peer is running an older version of Bitswap that doesn't support the
// If want-block times out, simulate a DONT_HAVE reponse.
// DONT_HAVE response, watch for timeouts on any want-blocks we sent the peer,
// This is necessary when making requests to peers running an older version of
// and if there is a timeout simulate a DONT_HAVE response.
// Bitswap that doesn't support the DONT_HAVE response, and is also useful to
// mitigate getting blocked by a peer that takes a long time to respond.
func
(
mq
*
MessageQueue
)
simulateDontHaveWithTimeout
(
msg
bsmsg
.
BitSwapMessage
)
{
func
(
mq
*
MessageQueue
)
simulateDontHaveWithTimeout
(
msg
bsmsg
.
BitSwapMessage
)
{
// If the peer supports DONT_HAVE responses, we don't need to simulate
if
mq
.
sender
.
SupportsHave
()
{
return
}
mq
.
wllock
.
Lock
()
mq
.
wllock
.
Lock
()
// Get the CID of each want-block that expects a DONT_HAVE response
// Get the CID of each want-block that expects a DONT_HAVE response
...
...
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