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
eaa7a9d5
Commit
eaa7a9d5
authored
Nov 19, 2014
by
Brian Tiger Chow
Committed by
Jeromy
Dec 05, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
misc(bitswap) renaming
License: MIT Signed-off-by:
Brian Tiger Chow
<
brian@perfmode.com
>
parent
0163be78
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
17 deletions
+18
-17
bitswap.go
bitswap.go
+18
-17
No files found.
bitswap.go
View file @
eaa7a9d5
...
...
@@ -153,14 +153,14 @@ func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.Peer) e
func
(
bs
*
bitswap
)
run
(
ctx
context
.
Context
)
{
const
batchDelay
=
time
.
Millisecond
*
3
// Time to wait before sending out wantlists to better batch up requests
const
numKeysPerBatch
=
10
const
maxProvidersPerRequest
=
6
const
rebroadcastPeriod
=
time
.
Second
*
5
// Every so often, we should resend out our current want list
const
batchDelay
=
time
.
Millisecond
*
3
// Time to wait before sending out wantlists to better batch up requests
const
peersPerSend
=
6
const
threshold
=
10
var
sendlist
<-
chan
peer
.
Peer
// NB: must be initialized to zero value
var
providers
<-
chan
peer
.
Peer
// NB: must be initialized to zero value
broadcastSignal
:=
time
.
After
(
rebroadcastPeriod
)
unsent
:=
0
unsent
Keys
:=
0
for
{
select
{
...
...
@@ -169,32 +169,33 @@ func (bs *bitswap) run(ctx context.Context) {
if
len
(
wantlist
)
==
0
{
continue
}
if
sendlist
==
nil
{
if
providers
==
nil
{
// rely on semi randomness of maps
firstKey
:=
wantlist
[
0
]
sendlist
=
bs
.
routing
.
FindProvidersAsync
(
ctx
,
firstKey
,
6
)
providers
=
bs
.
routing
.
FindProvidersAsync
(
ctx
,
firstKey
,
6
)
}
err
:=
bs
.
sendWantListTo
(
ctx
,
sendlist
)
err
:=
bs
.
sendWantListTo
(
ctx
,
providers
)
if
err
!=
nil
{
log
.
Errorf
(
"error sending wantlist: %s"
,
err
)
}
sendlist
=
nil
providers
=
nil
broadcastSignal
=
time
.
After
(
rebroadcastPeriod
)
case
k
:=
<-
bs
.
blockRequests
:
if
unsent
==
0
{
sendlist
=
bs
.
routing
.
FindProvidersAsync
(
ctx
,
k
,
peersPerSend
)
if
unsent
Keys
==
0
{
providers
=
bs
.
routing
.
FindProvidersAsync
(
ctx
,
k
,
maxProvidersPerRequest
)
}
unsent
++
unsent
Keys
++
if
unsent
>=
threshold
{
// send wantlist to
sendlist
err
:=
bs
.
sendWantListTo
(
ctx
,
sendlist
)
if
unsent
Keys
>=
numKeysPerBatch
{
// send wantlist to
providers
err
:=
bs
.
sendWantListTo
(
ctx
,
providers
)
if
err
!=
nil
{
log
.
Errorf
(
"error sending wantlist: %s"
,
err
)
}
unsent
=
0
unsent
Keys
=
0
broadcastSignal
=
time
.
After
(
rebroadcastPeriod
)
sendlist
=
nil
providers
=
nil
}
else
{
// set a timeout to wait for more blocks or send current wantlist
...
...
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