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-routing
Commits
59cbce37
Commit
59cbce37
authored
Oct 26, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
benchmark secure channel
parent
b3581e8f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
19 deletions
+15
-19
kbucket/table_test.go
kbucket/table_test.go
+15
-19
No files found.
kbucket/table_test.go
View file @
59cbce37
...
...
@@ -7,16 +7,12 @@ import (
"testing"
"time"
tu
"github.com/jbenet/go-ipfs/util/testutil"
peer
"github.com/jbenet/go-ipfs/peer"
)
func
_randPeer
()
peer
.
Peer
{
id
:=
make
(
peer
.
ID
,
16
)
crand
.
Read
(
id
)
return
peer
.
WithID
(
id
)
}
func
_randID
()
ID
{
func
RandID
()
ID
{
buf
:=
make
([]
byte
,
16
)
crand
.
Read
(
buf
)
...
...
@@ -30,11 +26,11 @@ func TestBucket(t *testing.T) {
peers
:=
make
([]
peer
.
Peer
,
100
)
for
i
:=
0
;
i
<
100
;
i
++
{
peers
[
i
]
=
_r
andPeer
()
peers
[
i
]
=
tu
.
R
andPeer
()
b
.
pushFront
(
peers
[
i
])
}
local
:=
_r
andPeer
()
local
:=
tu
.
R
andPeer
()
localID
:=
ConvertPeerID
(
local
.
ID
())
i
:=
rand
.
Intn
(
len
(
peers
))
...
...
@@ -65,12 +61,12 @@ func TestBucket(t *testing.T) {
// Right now, this just makes sure that it doesnt hang or crash
func
TestTableUpdate
(
t
*
testing
.
T
)
{
local
:=
_r
andPeer
()
local
:=
tu
.
R
andPeer
()
rt
:=
NewRoutingTable
(
10
,
ConvertPeerID
(
local
.
ID
()),
time
.
Hour
)
peers
:=
make
([]
peer
.
Peer
,
100
)
for
i
:=
0
;
i
<
100
;
i
++
{
peers
[
i
]
=
_r
andPeer
()
peers
[
i
]
=
tu
.
R
andPeer
()
}
// Testing Update
...
...
@@ -82,7 +78,7 @@ func TestTableUpdate(t *testing.T) {
}
for
i
:=
0
;
i
<
100
;
i
++
{
id
:=
_r
andID
()
id
:=
R
andID
()
ret
:=
rt
.
NearestPeers
(
id
,
5
)
if
len
(
ret
)
==
0
{
t
.
Fatal
(
"Failed to find node near ID."
)
...
...
@@ -91,12 +87,12 @@ func TestTableUpdate(t *testing.T) {
}
func
TestTableFind
(
t
*
testing
.
T
)
{
local
:=
_r
andPeer
()
local
:=
tu
.
R
andPeer
()
rt
:=
NewRoutingTable
(
10
,
ConvertPeerID
(
local
.
ID
()),
time
.
Hour
)
peers
:=
make
([]
peer
.
Peer
,
100
)
for
i
:=
0
;
i
<
5
;
i
++
{
peers
[
i
]
=
_r
andPeer
()
peers
[
i
]
=
tu
.
R
andPeer
()
rt
.
Update
(
peers
[
i
])
}
...
...
@@ -108,12 +104,12 @@ func TestTableFind(t *testing.T) {
}
func
TestTableFindMultiple
(
t
*
testing
.
T
)
{
local
:=
_r
andPeer
()
local
:=
tu
.
R
andPeer
()
rt
:=
NewRoutingTable
(
20
,
ConvertPeerID
(
local
.
ID
()),
time
.
Hour
)
peers
:=
make
([]
peer
.
Peer
,
100
)
for
i
:=
0
;
i
<
18
;
i
++
{
peers
[
i
]
=
_r
andPeer
()
peers
[
i
]
=
tu
.
R
andPeer
()
rt
.
Update
(
peers
[
i
])
}
...
...
@@ -132,7 +128,7 @@ func TestTableMultithreaded(t *testing.T) {
tab
:=
NewRoutingTable
(
20
,
ConvertPeerID
(
local
),
time
.
Hour
)
var
peers
[]
peer
.
Peer
for
i
:=
0
;
i
<
500
;
i
++
{
peers
=
append
(
peers
,
_r
andPeer
())
peers
=
append
(
peers
,
tu
.
R
andPeer
())
}
done
:=
make
(
chan
struct
{})
...
...
@@ -171,7 +167,7 @@ func BenchmarkUpdates(b *testing.B) {
var
peers
[]
peer
.
Peer
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
peers
=
append
(
peers
,
_r
andPeer
())
peers
=
append
(
peers
,
tu
.
R
andPeer
())
}
b
.
StartTimer
()
...
...
@@ -187,7 +183,7 @@ func BenchmarkFinds(b *testing.B) {
var
peers
[]
peer
.
Peer
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
peers
=
append
(
peers
,
_r
andPeer
())
peers
=
append
(
peers
,
tu
.
R
andPeer
())
tab
.
Update
(
peers
[
i
])
}
...
...
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