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
26f78574
Commit
26f78574
authored
Nov 20, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove buffer timing in bitswap in favor of manual batching
parent
44f32138
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
35 deletions
+19
-35
bitswap.go
bitswap.go
+18
-34
bitswap_test.go
bitswap_test.go
+1
-1
No files found.
bitswap.go
View file @
26f78574
...
@@ -43,7 +43,7 @@ func New(ctx context.Context, p peer.Peer,
...
@@ -43,7 +43,7 @@ func New(ctx context.Context, p peer.Peer,
routing
:
routing
,
routing
:
routing
,
sender
:
network
,
sender
:
network
,
wantlist
:
u
.
NewKeySet
(),
wantlist
:
u
.
NewKeySet
(),
b
lock
Requests
:
make
(
chan
u
.
Key
,
32
),
b
atch
Requests
:
make
(
chan
[]
u
.
Key
,
32
),
}
}
network
.
SetDelegate
(
bs
)
network
.
SetDelegate
(
bs
)
go
bs
.
run
(
ctx
)
go
bs
.
run
(
ctx
)
...
@@ -66,7 +66,10 @@ type bitswap struct {
...
@@ -66,7 +66,10 @@ type bitswap struct {
notifications
notifications
.
PubSub
notifications
notifications
.
PubSub
blockRequests
chan
u
.
Key
// Requests for a set of related blocks
// the assumption is made that the same peer is likely to
// have more than a single block in the set
batchRequests
chan
[]
u
.
Key
// strategy listens to network traffic and makes decisions about how to
// strategy listens to network traffic and makes decisions about how to
// interact with partners.
// interact with partners.
...
@@ -97,7 +100,7 @@ func (bs *bitswap) GetBlock(parent context.Context, k u.Key) (*blocks.Block, err
...
@@ -97,7 +100,7 @@ func (bs *bitswap) GetBlock(parent context.Context, k u.Key) (*blocks.Block, err
promise
:=
bs
.
notifications
.
Subscribe
(
ctx
,
k
)
promise
:=
bs
.
notifications
.
Subscribe
(
ctx
,
k
)
select
{
select
{
case
bs
.
b
lock
Requests
<-
k
:
case
bs
.
b
atch
Requests
<-
[]
u
.
Key
{
k
}
:
case
<-
parent
.
Done
()
:
case
<-
parent
.
Done
()
:
return
nil
,
parent
.
Err
()
return
nil
,
parent
.
Err
()
}
}
...
@@ -159,50 +162,31 @@ func (bs *bitswap) run(ctx context.Context) {
...
@@ -159,50 +162,31 @@ func (bs *bitswap) run(ctx context.Context) {
// Every so often, we should resend out our current want list
// Every so often, we should resend out our current want list
rebroadcastTime
:=
time
.
Second
*
5
rebroadcastTime
:=
time
.
Second
*
5
var
providers
<-
chan
peer
.
Peer
// NB: must be initialized to zero value
broadcastSignal
:=
time
.
NewTicker
(
bs
.
strategy
.
GetRebroadcastDelay
())
broadcastSignal
:=
time
.
After
(
bs
.
strategy
.
GetRebroadcastDelay
())
// Number of unsent keys for the current batch
unsentKeys
:=
0
for
{
for
{
select
{
select
{
case
<-
broadcastSignal
:
case
<-
broadcastSignal
.
C
:
unsentKeys
=
0
wantlist
:=
bs
.
wantlist
.
Keys
()
wantlist
:=
bs
.
wantlist
.
Keys
()
if
len
(
wantlist
)
==
0
{
if
len
(
wantlist
)
==
0
{
continue
continue
}
}
if
providers
==
nil
{
providers
:=
bs
.
routing
.
FindProvidersAsync
(
ctx
,
wantlist
[
0
],
maxProvidersPerRequest
)
// rely on semi randomness of maps
firstKey
:=
wantlist
[
0
]
providers
=
bs
.
routing
.
FindProvidersAsync
(
ctx
,
firstKey
,
maxProvidersPerRequest
)
}
err
:=
bs
.
sendWantListTo
(
ctx
,
providers
)
err
:=
bs
.
sendWantListTo
(
ctx
,
providers
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Errorf
(
"error sending wantlist: %s"
,
err
)
log
.
Errorf
(
"error sending wantlist: %s"
,
err
)
}
}
providers
=
nil
case
ks
:=
<-
bs
.
batchRequests
:
broadcastSignal
=
time
.
After
(
bs
.
strategy
.
GetRebroadcastDelay
())
if
len
(
ks
)
==
0
{
log
.
Warning
(
"Received batch request for zero blocks"
)
case
k
:=
<-
bs
.
blockRequests
:
continue
if
unsentKeys
==
0
{
providers
=
bs
.
routing
.
FindProvidersAsync
(
ctx
,
k
,
maxProvidersPerRequest
)
}
}
unsentKeys
++
providers
:=
bs
.
routing
.
FindProvidersAsync
(
ctx
,
ks
[
0
],
maxProvidersPerRequest
)
if
unsentKeys
>=
bs
.
strategy
.
GetBatchSize
()
{
// send wantlist to providers
err
:=
bs
.
sendWantListTo
(
ctx
,
providers
)
if
err
!=
nil
{
log
.
Errorf
(
"error sending wantlist: %s"
,
err
)
}
unsentKeys
=
0
broadcastSignal
=
time
.
After
(
bs
.
strategy
.
GetRebroadcastDelay
())
providers
=
nil
}
else
{
// set a timeout to wait for more blocks or send current wantlist
broadcastSignal
=
time
.
After
(
bs
.
strategy
.
GetBatchDelay
())
err
:=
bs
.
sendWantListTo
(
ctx
,
providers
)
if
err
!=
nil
{
log
.
Errorf
(
"error sending wantlist: %s"
,
err
)
}
}
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
return
return
...
...
bitswap_test.go
View file @
26f78574
...
@@ -345,7 +345,7 @@ func session(net tn.Network, rs mock.RoutingServer, id peer.ID) instance {
...
@@ -345,7 +345,7 @@ func session(net tn.Network, rs mock.RoutingServer, id peer.ID) instance {
routing
:
htc
,
routing
:
htc
,
sender
:
adapter
,
sender
:
adapter
,
wantlist
:
util
.
NewKeySet
(),
wantlist
:
util
.
NewKeySet
(),
b
lock
Requests
:
make
(
chan
util
.
Key
,
32
),
b
atch
Requests
:
make
(
chan
[]
util
.
Key
,
32
),
}
}
adapter
.
SetDelegate
(
bs
)
adapter
.
SetDelegate
(
bs
)
go
bs
.
run
(
context
.
TODO
())
go
bs
.
run
(
context
.
TODO
())
...
...
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