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
0fa8cfdb
Commit
0fa8cfdb
authored
8 years ago
by
Simon Désaulniers
Browse files
Options
Downloads
Patches
Plain Diff
tools: enable queries in dhtnode
parent
78c7cae7
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/dhtnode.cpp
+35
-7
35 additions, 7 deletions
tools/dhtnode.cpp
with
35 additions
and
7 deletions
tools/dhtnode.cpp
+
35
−
7
View file @
0fa8cfdb
...
...
@@ -50,7 +50,7 @@ void print_help() {
std
::
cout
<<
"OpenDht command line interface (CLI)"
<<
std
::
endl
;
std
::
cout
<<
"Possible commands:"
<<
std
::
endl
<<
" h, help Print this help message."
<<
std
::
endl
<<
"
q
, quit Quit the program."
<<
std
::
endl
<<
"
x
, quit Quit the program."
<<
std
::
endl
<<
" log Start/stop printing DHT logs."
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
<<
"Node information:"
<<
std
::
endl
...
...
@@ -61,8 +61,9 @@ void print_help() {
std
::
cout
<<
std
::
endl
<<
"Operations on the DHT:"
<<
std
::
endl
<<
" b ip:port Ping potential node at given IP address/port."
<<
std
::
endl
<<
" g [key] Get values at [key]."
<<
std
::
endl
<<
" l [key] Listen for value changes at [key]."
<<
std
::
endl
<<
" g [key] [where] Get values at [key]. [where] is the 'where' part of an SQL-ish string."
<<
std
::
endl
<<
" q [key] [query] Query field values at [key]. [query] is an SQL-ish string."
<<
std
::
endl
<<
" l [key] [where] Listen for value changes at [key]. [where] is the 'where' part of an SQL-ish string."
<<
std
::
endl
<<
" p [key] [str] Put string value at [key]."
<<
std
::
endl
<<
" s [key] [str] Put string value at [key], signed with our generated private key."
<<
std
::
endl
<<
" e [key] [dest] [str] Put string value at [key], encrypted for [dest] with its public key (if found)."
<<
std
::
endl
...
...
@@ -88,7 +89,7 @@ void cmd_loop(DhtRunner& dht, dht_params& params)
std
::
string
op
,
idstr
,
value
;
iss
>>
op
>>
idstr
;
if
(
op
==
"x"
||
op
==
"q"
||
op
==
"exit"
||
op
==
"quit"
)
{
if
(
op
==
"x"
||
op
==
"exit"
||
op
==
"quit"
)
{
break
;
}
else
if
(
op
==
"h"
||
op
==
"help"
)
{
print_help
();
...
...
@@ -147,7 +148,7 @@ void cmd_loop(DhtRunner& dht, dht_params& params)
continue
;
dht
::
InfoHash
id
{
idstr
};
static
const
std
::
set
<
std
::
string
>
VALID_OPS
{
"g"
,
"l"
,
"p"
,
"s"
,
"e"
,
"a"
};
static
const
std
::
set
<
std
::
string
>
VALID_OPS
{
"g"
,
"q"
,
"l"
,
"p"
,
"s"
,
"e"
,
"a"
};
if
(
VALID_OPS
.
find
(
op
)
==
VALID_OPS
.
cend
())
{
std
::
cout
<<
"Unknown command: "
<<
op
<<
std
::
endl
;
std
::
cout
<<
" (type 'h' or 'help' for a list of possible commands)"
<<
std
::
endl
;
...
...
@@ -161,6 +162,11 @@ void cmd_loop(DhtRunner& dht, dht_params& params)
auto
start
=
std
::
chrono
::
high_resolution_clock
::
now
();
if
(
op
==
"g"
)
{
std
::
string
rem
;
std
::
getline
(
iss
,
rem
);
dht
::
Where
w
{
std
::
move
(
rem
)};
dht
::
Query
q
{{},
w
};
std
::
cout
<<
q
<<
std
::
endl
;
dht
.
get
(
id
,
[
start
](
std
::
shared_ptr
<
Value
>
value
)
{
auto
now
=
std
::
chrono
::
high_resolution_clock
::
now
();
std
::
cout
<<
"Get: found value (after "
<<
print_dt
(
now
-
start
)
<<
"s)"
<<
std
::
endl
;
...
...
@@ -169,14 +175,36 @@ void cmd_loop(DhtRunner& dht, dht_params& params)
},
[
start
](
bool
ok
)
{
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
std
::
cout
<<
"Get: "
<<
(
ok
?
"completed"
:
"failure"
)
<<
" (took "
<<
print_dt
(
end
-
start
)
<<
"s)"
<<
std
::
endl
;
});
},
{},
std
::
move
(
w
));
}
else
if
(
op
==
"q"
)
{
std
::
string
rem
;
std
::
getline
(
iss
,
rem
);
dht
::
Query
q
{
std
::
move
(
rem
)};
std
::
cout
<<
q
<<
std
::
endl
;
dht
.
query
(
id
,
[
start
](
const
std
::
vector
<
std
::
shared_ptr
<
FieldValueIndex
>>&
field_value_indexes
)
{
auto
now
=
std
::
chrono
::
high_resolution_clock
::
now
();
for
(
auto
&
index
:
field_value_indexes
)
{
std
::
cout
<<
"Query: found field value index (after "
<<
print_dt
(
now
-
start
)
<<
"s)"
<<
std
::
endl
;
std
::
cout
<<
"
\t
"
<<
*
index
<<
std
::
endl
;
}
return
true
;
},
[
start
](
bool
ok
)
{
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
std
::
cout
<<
"Query: "
<<
(
ok
?
"completed"
:
"failure"
)
<<
" (took "
<<
print_dt
(
end
-
start
)
<<
"s)"
<<
std
::
endl
;
},
std
::
move
(
q
));
}
else
if
(
op
==
"l"
)
{
std
::
string
rem
;
std
::
getline
(
iss
,
rem
);
dht
::
Where
w
{
std
::
move
(
rem
)};
dht
::
Query
q
{{},
w
};
std
::
cout
<<
q
<<
std
::
endl
;
dht
.
listen
(
id
,
[](
std
::
shared_ptr
<
Value
>
value
)
{
std
::
cout
<<
"Listen: found value:"
<<
std
::
endl
;
std
::
cout
<<
"
\t
"
<<
*
value
<<
std
::
endl
;
return
true
;
});
}
,
{},
std
::
move
(
w
)
);
}
else
if
(
op
==
"p"
)
{
std
::
string
v
;
...
...
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