Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
0a436e17
Commit
0a436e17
authored
6 years ago
by
Ming Rui Zhang
Browse files
Options
Downloads
Patches
Plain Diff
peerdiscovery: modifications on tester fit for the updates
parent
763ffddf
Branches
Branches containing commit
Tags
1.9.0
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/peerdiscoverytester.cpp
+30
-12
30 additions, 12 deletions
tests/peerdiscoverytester.cpp
with
30 additions
and
12 deletions
tests/peerdiscoverytester.cpp
+
30
−
12
View file @
0a436e17
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
*/
*/
#include
"peerdiscoverytester.h"
#include
"peerdiscoverytester.h"
#include
"opendht/dhtrunner.h"
namespace
test
{
namespace
test
{
...
@@ -31,16 +32,24 @@ void PeerDiscoveryTester::testTransmission_ipv4(){
...
@@ -31,16 +32,24 @@ void PeerDiscoveryTester::testTransmission_ipv4(){
dht
::
InfoHash
data_n
=
dht
::
InfoHash
::
get
(
"applepin"
);
dht
::
InfoHash
data_n
=
dht
::
InfoHash
::
get
(
"applepin"
);
int
port
=
2222
;
int
port
=
2222
;
in_port_t
port_n
=
50000
;
in_port_t
port_n
=
50000
;
dht
::
NetId
netid
=
10
;
msgpack
::
sbuffer
sbuf
;
dht
::
NodeInsertionPack
adc
;
adc
.
nid_
=
10
;
adc
.
node_port_
=
port_n
;
adc
.
nodeid_
=
data_n
;
msgpack
::
pack
(
sbuf
,
adc
);
try
{
try
{
dht
::
PeerDiscovery
test_n
(
AF_INET
,
port
);
dht
::
PeerDiscovery
test_n
(
AF_INET
,
port
);
dht
::
PeerDiscovery
test_s
(
AF_INET
,
port
);
dht
::
PeerDiscovery
test_s
(
AF_INET
,
port
);
try
{
try
{
test_s
.
startDiscovery
([
&
](
const
dht
::
InfoHash
&
node
,
const
dht
::
SockAddr
&
addr
){
test_s
.
startDiscovery
([
&
](
std
::
string
&
type
,
msgpack
::
object
&&
obj
,
dht
::
SockAddr
&
add
){
CPPUNIT_ASSERT_EQUAL
(
data_n
,
node
);
auto
v
=
obj
.
as
<
dht
::
NodeInsertionPack
>
();
CPPUNIT_ASSERT_EQUAL
(
port_n
,
addr
.
getPort
());
CPPUNIT_ASSERT_EQUAL
(
v
.
node_port_
,
port_n
);
CPPUNIT_ASSERT_EQUAL
(
v
.
nodeid_
,
data_n
);
});
});
test_n
.
startPublish
(
data_n
,
port
_n
);
test_n
.
startPublish
(
"dht"
,
std
::
move
(
sbuf
),
data
_n
);
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
seconds
(
5
));
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
seconds
(
5
));
test_n
.
stop
();
test_n
.
stop
();
...
@@ -60,19 +69,26 @@ void PeerDiscoveryTester::testTransmission_ipv6(){
...
@@ -60,19 +69,26 @@ void PeerDiscoveryTester::testTransmission_ipv6(){
// Node for getnode id
// Node for getnode id
dht
::
InfoHash
data_n
=
dht
::
InfoHash
::
get
(
"applepin"
);
dht
::
InfoHash
data_n
=
dht
::
InfoHash
::
get
(
"applepin"
);
int
port
=
3333
;
int
port
=
2222
;
in_port_t
port_n
=
50001
;
in_port_t
port_n
=
50000
;
dht
::
NetId
netid
=
10
;
msgpack
::
sbuffer
sbuf
;
dht
::
NodeInsertionPack
adc
;
adc
.
nid_
=
10
;
adc
.
node_port_
=
port_n
;
adc
.
nodeid_
=
data_n
;
msgpack
::
pack
(
sbuf
,
adc
);
try
{
try
{
dht
::
PeerDiscovery
test_n
(
AF_INET6
,
port
);
dht
::
PeerDiscovery
test_n
(
AF_INET6
,
port
);
dht
::
PeerDiscovery
test_s
(
AF_INET6
,
port
);
dht
::
PeerDiscovery
test_s
(
AF_INET6
,
port
);
try
{
try
{
test_s
.
startDiscovery
([
&
](
const
dht
::
InfoHash
&
node
,
const
dht
::
SockAddr
&
addr
){
test_s
.
startDiscovery
([
&
](
std
::
string
&
type
,
msgpack
::
object
&&
obj
,
dht
::
SockAddr
&
add
){
CPPUNIT_ASSERT_EQUAL
(
data_n
,
node
);
auto
v
=
obj
.
as
<
dht
::
NodeInsertionPack
>
();
CPPUNIT_ASSERT_EQUAL
(
port_n
,
addr
.
getPort
());
CPPUNIT_ASSERT_EQUAL
(
v
.
node_port_
,
port_n
);
CPPUNIT_ASSERT_EQUAL
(
v
.
nodeid_
,
data_n
);
});
});
test_n
.
startPublish
(
data_n
,
port
_n
);
test_n
.
startPublish
(
"dht"
,
std
::
move
(
sbuf
),
data
_n
);
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
seconds
(
5
));
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
seconds
(
5
));
test_n
.
stop
();
test_n
.
stop
();
...
@@ -80,9 +96,11 @@ void PeerDiscoveryTester::testTransmission_ipv6(){
...
@@ -80,9 +96,11 @@ void PeerDiscoveryTester::testTransmission_ipv6(){
test_n
.
join
();
test_n
.
join
();
test_s
.
join
();
test_s
.
join
();
}
catch
(
std
::
exception
&
exception
){
}
catch
(
std
::
exception
&
exception
){
perror
(
exception
.
what
());
CPPUNIT_ASSERT
(
false
);
CPPUNIT_ASSERT
(
false
);
}
}
}
catch
(
std
::
exception
&
exception
)
{
}
catch
(
std
::
exception
&
exception
){
perror
(
exception
.
what
());
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment