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
e3bf5cd8
Commit
e3bf5cd8
authored
Nov 19, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added a new test for a dhthell scenario that was failing
parent
eaa7a9d5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
6 deletions
+55
-6
bitswap.go
bitswap.go
+3
-5
bitswap_test.go
bitswap_test.go
+52
-1
No files found.
bitswap.go
View file @
e3bf5cd8
...
@@ -128,7 +128,7 @@ func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.Peer) e
...
@@ -128,7 +128,7 @@ func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.Peer) e
log
.
Event
(
ctx
,
"DialPeer"
,
p
)
log
.
Event
(
ctx
,
"DialPeer"
,
p
)
err
:=
bs
.
sender
.
DialPeer
(
ctx
,
p
)
err
:=
bs
.
sender
.
DialPeer
(
ctx
,
p
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Errorf
(
"Error sender.DialPeer(%s)
"
,
p
)
log
.
Errorf
(
"Error sender.DialPeer(%s)
: %s"
,
p
,
err
)
return
return
}
}
...
@@ -153,10 +153,8 @@ func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.Peer) e
...
@@ -153,10 +153,8 @@ func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.Peer) e
func
(
bs
*
bitswap
)
run
(
ctx
context
.
Context
)
{
func
(
bs
*
bitswap
)
run
(
ctx
context
.
Context
)
{
const
batchDelay
=
time
.
Millisecond
*
3
// Time to wait before sending out wantlists to better batch up requests
// Every so often, we should resend out our current want list
const
numKeysPerBatch
=
10
rebroadcastTime
:=
time
.
Second
*
5
const
maxProvidersPerRequest
=
6
const
rebroadcastPeriod
=
time
.
Second
*
5
// Every so often, we should resend out our current want list
var
providers
<-
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
)
broadcastSignal
:=
time
.
After
(
rebroadcastPeriod
)
...
...
bitswap_test.go
View file @
e3bf5cd8
...
@@ -100,7 +100,7 @@ func TestSwarm(t *testing.T) {
...
@@ -100,7 +100,7 @@ func TestSwarm(t *testing.T) {
t
.
Log
(
"Create a ton of instances, and just a few blocks"
)
t
.
Log
(
"Create a ton of instances, and just a few blocks"
)
numInstances
:=
5
numInstances
:=
5
00
numBlocks
:=
2
numBlocks
:=
2
instances
:=
sg
.
Instances
(
numInstances
)
instances
:=
sg
.
Instances
(
numInstances
)
...
@@ -140,6 +140,57 @@ func TestSwarm(t *testing.T) {
...
@@ -140,6 +140,57 @@ func TestSwarm(t *testing.T) {
}
}
}
}
func
TestLargeFile
(
t
*
testing
.
T
)
{
if
testing
.
Short
()
{
t
.
SkipNow
()
}
net
:=
tn
.
VirtualNetwork
()
rs
:=
mock
.
VirtualRoutingServer
()
sg
:=
NewSessionGenerator
(
net
,
rs
)
bg
:=
NewBlockGenerator
()
t
.
Log
(
"Test a few nodes trying to get one file with a lot of blocks"
)
numInstances
:=
10
numBlocks
:=
100
instances
:=
sg
.
Instances
(
numInstances
)
blocks
:=
bg
.
Blocks
(
numBlocks
)
t
.
Log
(
"Give the blocks to the first instance"
)
first
:=
instances
[
0
]
for
_
,
b
:=
range
blocks
{
first
.
blockstore
.
Put
(
b
)
first
.
exchange
.
HasBlock
(
context
.
Background
(),
*
b
)
rs
.
Announce
(
first
.
peer
,
b
.
Key
())
}
t
.
Log
(
"Distribute!"
)
var
wg
sync
.
WaitGroup
for
_
,
inst
:=
range
instances
{
for
_
,
b
:=
range
blocks
{
wg
.
Add
(
1
)
// NB: executing getOrFail concurrently puts tremendous pressure on
// the goroutine scheduler
getOrFail
(
inst
,
b
,
t
,
&
wg
)
}
}
wg
.
Wait
()
t
.
Log
(
"Verify!"
)
for
_
,
inst
:=
range
instances
{
for
_
,
b
:=
range
blocks
{
if
_
,
err
:=
inst
.
blockstore
.
Get
(
b
.
Key
());
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
}
}
func
getOrFail
(
bitswap
instance
,
b
*
blocks
.
Block
,
t
*
testing
.
T
,
wg
*
sync
.
WaitGroup
)
{
func
getOrFail
(
bitswap
instance
,
b
*
blocks
.
Block
,
t
*
testing
.
T
,
wg
*
sync
.
WaitGroup
)
{
if
_
,
err
:=
bitswap
.
blockstore
.
Get
(
b
.
Key
());
err
!=
nil
{
if
_
,
err
:=
bitswap
.
blockstore
.
Get
(
b
.
Key
());
err
!=
nil
{
_
,
err
:=
bitswap
.
exchange
.
GetBlock
(
context
.
Background
(),
b
.
Key
())
_
,
err
:=
bitswap
.
exchange
.
GetBlock
(
context
.
Background
(),
b
.
Key
())
...
...
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