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
297ff3d4
Commit
297ff3d4
authored
Nov 20, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
randomize rebroadcast target
parent
19da0570
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
7 additions
and
7 deletions
+7
-7
exchange/bitswap/bitswap.go
exchange/bitswap/bitswap.go
+7
-2
exchange/bitswap/strategy/interface.go
exchange/bitswap/strategy/interface.go
+0
-1
exchange/bitswap/strategy/strategy.go
exchange/bitswap/strategy/strategy.go
+0
-4
No files found.
exchange/bitswap/bitswap.go
View file @
297ff3d4
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
package
bitswap
package
bitswap
import
(
import
(
"math/rand"
"time"
"time"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
...
@@ -96,7 +97,6 @@ func (bs *bitswap) GetBlock(parent context.Context, k u.Key) (*blocks.Block, err
...
@@ -96,7 +97,6 @@ func (bs *bitswap) GetBlock(parent context.Context, k u.Key) (*blocks.Block, err
log
.
Event
(
ctx
,
"GetBlockRequestBegin"
,
&
k
)
log
.
Event
(
ctx
,
"GetBlockRequestBegin"
,
&
k
)
defer
log
.
Event
(
ctx
,
"GetBlockRequestEnd"
,
&
k
)
defer
log
.
Event
(
ctx
,
"GetBlockRequestEnd"
,
&
k
)
bs
.
wantlist
.
Add
(
k
)
promise
:=
bs
.
notifications
.
Subscribe
(
ctx
,
k
)
promise
:=
bs
.
notifications
.
Subscribe
(
ctx
,
k
)
select
{
select
{
...
@@ -171,17 +171,22 @@ func (bs *bitswap) run(ctx context.Context) {
...
@@ -171,17 +171,22 @@ func (bs *bitswap) run(ctx context.Context) {
if
len
(
wantlist
)
==
0
{
if
len
(
wantlist
)
==
0
{
continue
continue
}
}
providers
:=
bs
.
routing
.
FindProvidersAsync
(
ctx
,
wantlist
[
0
],
maxProvidersPerRequest
)
n
:=
rand
.
Intn
(
len
(
wantlist
))
providers
:=
bs
.
routing
.
FindProvidersAsync
(
ctx
,
wantlist
[
n
],
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
)
}
}
case
ks
:=
<-
bs
.
batchRequests
:
case
ks
:=
<-
bs
.
batchRequests
:
// TODO: implement batching on len(ks) > X for some X
if
len
(
ks
)
==
0
{
if
len
(
ks
)
==
0
{
log
.
Warning
(
"Received batch request for zero blocks"
)
log
.
Warning
(
"Received batch request for zero blocks"
)
continue
continue
}
}
for
_
,
k
:=
range
ks
{
bs
.
wantlist
.
Add
(
k
)
}
providers
:=
bs
.
routing
.
FindProvidersAsync
(
ctx
,
ks
[
0
],
maxProvidersPerRequest
)
providers
:=
bs
.
routing
.
FindProvidersAsync
(
ctx
,
ks
[
0
],
maxProvidersPerRequest
)
err
:=
bs
.
sendWantListTo
(
ctx
,
providers
)
err
:=
bs
.
sendWantListTo
(
ctx
,
providers
)
...
...
exchange/bitswap/strategy/interface.go
View file @
297ff3d4
...
@@ -34,6 +34,5 @@ type Strategy interface {
...
@@ -34,6 +34,5 @@ type Strategy interface {
// Values determining bitswap behavioural patterns
// Values determining bitswap behavioural patterns
GetBatchSize
()
int
GetBatchSize
()
int
GetBatchDelay
()
time
.
Duration
GetRebroadcastDelay
()
time
.
Duration
GetRebroadcastDelay
()
time
.
Duration
}
}
exchange/bitswap/strategy/strategy.go
View file @
297ff3d4
...
@@ -145,10 +145,6 @@ func (s *strategist) GetBatchSize() int {
...
@@ -145,10 +145,6 @@ func (s *strategist) GetBatchSize() int {
return
10
return
10
}
}
func
(
s
*
strategist
)
GetBatchDelay
()
time
.
Duration
{
return
time
.
Millisecond
*
3
}
func
(
s
*
strategist
)
GetRebroadcastDelay
()
time
.
Duration
{
func
(
s
*
strategist
)
GetRebroadcastDelay
()
time
.
Duration
{
return
time
.
Second
*
2
return
time
.
Second
*
2
}
}
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