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
a2ce7a2a
Unverified
Commit
a2ce7a2a
authored
Oct 23, 2018
by
Steven Allen
Committed by
GitHub
Oct 23, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #17 from ipfs/fix/delay-find-providers
delay finding providers
parents
5251947b
93de01c2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
14 deletions
+26
-14
bitswap.go
bitswap.go
+26
-14
No files found.
bitswap.go
View file @
a2ce7a2a
...
...
@@ -36,6 +36,7 @@ const (
// results.
// TODO: if a 'non-nice' strategy is implemented, consider increasing this value
maxProvidersPerRequest
=
3
findProviderDelay
=
1
*
time
.
Second
providerRequestTimeout
=
time
.
Second
*
10
provideTimeout
=
time
.
Second
*
15
sizeBatchRequestChan
=
32
...
...
@@ -230,14 +231,6 @@ func (bs *Bitswap) GetBlocks(ctx context.Context, keys []cid.Cid) (<-chan blocks
bs
.
wm
.
WantBlocks
(
ctx
,
keys
,
nil
,
mses
)
// NB: Optimization. Assumes that providers of key[0] are likely to
// be able to provide for all keys. This currently holds true in most
// every situation. Later, this assumption may not hold as true.
req
:=
&
blockRequest
{
Cid
:
keys
[
0
],
Ctx
:
ctx
,
}
remaining
:=
cid
.
NewSet
()
for
_
,
k
:=
range
keys
{
remaining
.
Add
(
k
)
...
...
@@ -252,13 +245,37 @@ func (bs *Bitswap) GetBlocks(ctx context.Context, keys []cid.Cid) (<-chan blocks
// can't just defer this call on its own, arguments are resolved *when* the defer is created
bs
.
CancelWants
(
remaining
.
Keys
(),
mses
)
}()
findProvsDelay
:=
time
.
NewTimer
(
findProviderDelay
)
defer
findProvsDelay
.
Stop
()
findProvsDelayCh
:=
findProvsDelay
.
C
req
:=
&
blockRequest
{
Cid
:
keys
[
0
],
Ctx
:
ctx
,
}
var
findProvsReqCh
chan
<-
*
blockRequest
for
{
select
{
case
<-
findProvsDelayCh
:
// NB: Optimization. Assumes that providers of key[0] are likely to
// be able to provide for all keys. This currently holds true in most
// every situation. Later, this assumption may not hold as true.
findProvsReqCh
=
bs
.
findKeys
findProvsDelayCh
=
nil
case
findProvsReqCh
<-
req
:
findProvsReqCh
=
nil
case
blk
,
ok
:=
<-
promise
:
if
!
ok
{
return
}
// No need to find providers now.
findProvsDelay
.
Stop
()
findProvsDelayCh
=
nil
findProvsReqCh
=
nil
bs
.
CancelWants
([]
cid
.
Cid
{
blk
.
Cid
()},
mses
)
remaining
.
Remove
(
blk
.
Cid
())
select
{
...
...
@@ -272,12 +289,7 @@ func (bs *Bitswap) GetBlocks(ctx context.Context, keys []cid.Cid) (<-chan blocks
}
}()
select
{
case
bs
.
findKeys
<-
req
:
return
out
,
nil
case
<-
ctx
.
Done
()
:
return
nil
,
ctx
.
Err
()
}
return
out
,
nil
}
func
(
bs
*
Bitswap
)
getNextSessionID
()
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