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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
3383ce7a
Commit
3383ce7a
authored
10 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
dhtnode: print operation completion time
parent
04623d09
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/dhtnode.cpp
+28
-17
28 additions, 17 deletions
tools/dhtnode.cpp
with
28 additions
and
17 deletions
tools/dhtnode.cpp
+
28
−
17
View file @
3383ce7a
...
@@ -82,6 +82,12 @@ void printLog(std::ostream& s, char const* m, va_list args) {
...
@@ -82,6 +82,12 @@ void printLog(std::ostream& s, char const* m, va_list args) {
s
.
put
(
'\n'
);
s
.
put
(
'\n'
);
}
}
template
<
class
DT
>
static
double
print_dt
(
DT
d
)
{
return
std
::
chrono
::
duration_cast
<
std
::
chrono
::
duration
<
double
>>
(
d
).
count
();
}
int
int
main
(
int
argc
,
char
**
argv
)
main
(
int
argc
,
char
**
argv
)
{
{
...
@@ -197,24 +203,25 @@ main(int argc, char **argv)
...
@@ -197,24 +203,25 @@ main(int argc, char **argv)
continue
;
continue
;
}
}
auto
start
=
std
::
chrono
::
high_resolution_clock
::
now
();
if
(
op
==
"g"
)
{
if
(
op
==
"g"
)
{
dht
.
get
(
id
,
[](
const
std
::
vector
<
std
::
shared_ptr
<
Value
>>&
values
)
{
dht
.
get
(
id
,
[
start
](
const
std
::
vector
<
std
::
shared_ptr
<
Value
>>&
values
)
{
std
::
cout
<<
"Get - found values : "
<<
std
::
endl
;
auto
now
=
std
::
chrono
::
high_resolution_clock
::
now
();
for
(
const
auto
&
a
:
values
)
{
std
::
cout
<<
"Get: found values (after "
<<
print_dt
(
now
-
start
)
<<
"s)"
<<
std
::
endl
;
for
(
const
auto
&
a
:
values
)
std
::
cout
<<
"
\t
"
<<
*
a
<<
std
::
endl
;
std
::
cout
<<
"
\t
"
<<
*
a
<<
std
::
endl
;
}
return
true
;
return
true
;
},
[](
bool
ok
)
{
},
[
start
](
bool
ok
)
{
std
::
cout
<<
"Get - done : "
<<
(
ok
?
"success"
:
"failure"
)
<<
std
::
endl
;
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
std
::
cout
<<
"Get: "
<<
(
ok
?
"completed"
:
"failure"
)
<<
" (took "
<<
print_dt
(
end
-
start
)
<<
"s)"
<<
std
::
endl
;
});
});
}
}
else
if
(
op
==
"l"
)
{
else
if
(
op
==
"l"
)
{
std
::
cout
<<
id
<<
std
::
endl
;
std
::
cout
<<
id
<<
std
::
endl
;
dht
.
listen
(
id
,
[](
const
std
::
vector
<
std
::
shared_ptr
<
Value
>>&
values
)
{
dht
.
listen
(
id
,
[](
const
std
::
vector
<
std
::
shared_ptr
<
Value
>>&
values
)
{
std
::
cout
<<
"Listen
-
found values
:
"
<<
std
::
endl
;
std
::
cout
<<
"Listen
:
found values
:
"
<<
std
::
endl
;
for
(
const
auto
&
a
:
values
)
{
for
(
const
auto
&
a
:
values
)
std
::
cout
<<
"
\t
"
<<
*
a
<<
std
::
endl
;
std
::
cout
<<
"
\t
"
<<
*
a
<<
std
::
endl
;
}
return
true
;
return
true
;
});
});
}
}
...
@@ -224,8 +231,9 @@ main(int argc, char **argv)
...
@@ -224,8 +231,9 @@ main(int argc, char **argv)
dht
.
put
(
id
,
dht
::
Value
{
dht
.
put
(
id
,
dht
::
Value
{
dht
::
ValueType
::
USER_DATA
.
id
,
dht
::
ValueType
::
USER_DATA
.
id
,
std
::
vector
<
uint8_t
>
{
v
.
begin
(),
v
.
end
()}
std
::
vector
<
uint8_t
>
{
v
.
begin
(),
v
.
end
()}
},
[](
bool
ok
)
{
},
[
start
](
bool
ok
)
{
std
::
cout
<<
"Put done !"
<<
ok
<<
std
::
endl
;
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
std
::
cout
<<
"Put: "
<<
(
ok
?
"success"
:
"failure"
)
<<
" (took "
<<
print_dt
(
end
-
start
)
<<
"s)"
<<
std
::
endl
;
});
});
}
}
else
if
(
op
==
"s"
)
{
else
if
(
op
==
"s"
)
{
...
@@ -234,8 +242,9 @@ main(int argc, char **argv)
...
@@ -234,8 +242,9 @@ main(int argc, char **argv)
dht
.
putSigned
(
id
,
dht
::
Value
{
dht
.
putSigned
(
id
,
dht
::
Value
{
dht
::
ValueType
::
USER_DATA
.
id
,
dht
::
ValueType
::
USER_DATA
.
id
,
std
::
vector
<
uint8_t
>
{
v
.
begin
(),
v
.
end
()}
std
::
vector
<
uint8_t
>
{
v
.
begin
(),
v
.
end
()}
},
[](
bool
ok
)
{
},
[
start
](
bool
ok
)
{
std
::
cout
<<
"Put signed done !"
<<
ok
<<
std
::
endl
;
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
std
::
cout
<<
"Put signed: "
<<
(
ok
?
"success"
:
"failure"
)
<<
" (took "
<<
print_dt
(
end
-
start
)
<<
"s)"
<<
std
::
endl
;
});
});
}
}
else
if
(
op
==
"e"
)
{
else
if
(
op
==
"e"
)
{
...
@@ -245,15 +254,17 @@ main(int argc, char **argv)
...
@@ -245,15 +254,17 @@ main(int argc, char **argv)
dht
.
putEncrypted
(
id
,
InfoHash
(
tostr
),
dht
::
Value
{
dht
.
putEncrypted
(
id
,
InfoHash
(
tostr
),
dht
::
Value
{
dht
::
ValueType
::
USER_DATA
.
id
,
dht
::
ValueType
::
USER_DATA
.
id
,
std
::
vector
<
uint8_t
>
{
v
.
begin
(),
v
.
end
()}
std
::
vector
<
uint8_t
>
{
v
.
begin
(),
v
.
end
()}
},
[](
bool
ok
)
{
},
[
start
](
bool
ok
)
{
std
::
cout
<<
"Put encrypted done !"
<<
ok
<<
std
::
endl
;
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
std
::
cout
<<
"Put encrypted: "
<<
(
ok
?
"success"
:
"failure"
)
<<
" (took "
<<
print_dt
(
end
-
start
)
<<
"s)"
<<
std
::
endl
;
});
});
}
}
else
if
(
op
==
"a"
)
{
else
if
(
op
==
"a"
)
{
in_port_t
port
;
in_port_t
port
;
iss
>>
port
;
iss
>>
port
;
dht
.
put
(
id
,
dht
::
Value
{
dht
::
IpServiceAnnouncement
::
TYPE
.
id
,
dht
::
IpServiceAnnouncement
(
port
)},
[](
bool
ok
)
{
dht
.
put
(
id
,
dht
::
Value
{
dht
::
IpServiceAnnouncement
::
TYPE
.
id
,
dht
::
IpServiceAnnouncement
(
port
)},
[
start
](
bool
ok
)
{
std
::
cout
<<
"Announce done !"
<<
ok
<<
std
::
endl
;
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
std
::
cout
<<
"Announce: "
<<
(
ok
?
"success"
:
"failure"
)
<<
" (took "
<<
print_dt
(
end
-
start
)
<<
"s)"
<<
std
::
endl
;
});
});
}
}
}
}
...
...
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