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
6a7ad871
Commit
6a7ad871
authored
5 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
value: toString prints raw data if text/plain
parent
99890fca
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/value.cpp
+16
-7
16 additions, 7 deletions
src/value.cpp
tools/dhtnode.cpp
+13
-9
13 additions, 9 deletions
tools/dhtnode.cpp
with
29 additions
and
16 deletions
src/value.cpp
+
16
−
7
View file @
6a7ad871
...
...
@@ -45,7 +45,7 @@ Value::Filter bindFilterRaw(FilterRaw raw_filter, void* user_data) {
std
::
ostream
&
operator
<<
(
std
::
ostream
&
s
,
const
Value
&
v
)
{
auto
flags
(
s
.
flags
());
s
<<
"Value[id:"
<<
std
::
hex
<<
v
.
id
<<
std
::
dec
<<
" "
;
s
<<
"Value[id:"
<<
std
::
hex
<<
v
.
id
<<
std
::
dec
<<
' '
;
if
(
v
.
isEncrypted
())
s
<<
"encrypted "
;
else
if
(
v
.
isSigned
())
{
...
...
@@ -67,14 +67,23 @@ std::ostream& operator<< (std::ostream& s, const Value& v)
}
#endif
}
else
{
s
<<
"Data (type: "
<<
v
.
type
<<
" ): "
;
s
<<
std
::
hex
;
for
(
auto
i
:
v
.
data
)
s
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
2
)
<<
(
unsigned
)
i
;
s
<<
std
::
dec
;
if
(
v
.
user_type
.
empty
())
s
<<
"data:"
;
else
s
<<
"data("
<<
v
.
user_type
<<
"):"
;
if
(
v
.
user_type
==
"text/plain"
)
{
s
<<
'"'
;
s
.
write
((
const
char
*
)
v
.
data
.
data
(),
v
.
data
.
size
());
s
<<
'"'
;
}
else
{
s
<<
std
::
hex
;
for
(
auto
i
:
v
.
data
)
s
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
2
)
<<
(
unsigned
)
i
;
s
<<
std
::
dec
;
}
}
}
s
<<
"]"
;
s
<<
']'
;
s
.
flags
(
flags
);
return
s
;
}
...
...
This diff is collapsed.
Click to expand it.
tools/dhtnode.cpp
+
13
−
9
View file @
6a7ad871
...
...
@@ -384,10 +384,11 @@ void cmd_loop(std::shared_ptr<DhtRunner>& node, dht_params& params
else
if
(
op
==
"p"
)
{
std
::
string
v
;
iss
>>
v
;
node
->
put
(
id
,
dht
::
Value
{
auto
value
=
std
::
make_shared
<
dht
::
Value
>
(
dht
::
ValueType
::
USER_DATA
.
id
,
std
::
vector
<
uint8_t
>
{
v
.
begin
(),
v
.
end
()}
},
[
start
](
bool
ok
)
{
std
::
vector
<
uint8_t
>
{
v
.
begin
(),
v
.
end
()});
value
->
user_type
=
"text/plain"
;
node
->
put
(
id
,
std
::
move
(
value
),
[
start
](
bool
ok
)
{
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
std
::
cout
<<
"Put: "
<<
(
ok
?
"success"
:
"failure"
)
<<
", took "
<<
print_duration
(
end
-
start
)
<<
std
::
endl
;
});
...
...
@@ -399,6 +400,7 @@ void cmd_loop(std::shared_ptr<DhtRunner>& node, dht_params& params
dht
::
ValueType
::
USER_DATA
.
id
,
std
::
vector
<
uint8_t
>
{
v
.
begin
(),
v
.
end
()}
);
value
->
user_type
=
"text/plain"
;
node
->
put
(
id
,
value
,
[
start
,
value
](
bool
ok
)
{
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
auto
flags
(
std
::
cout
.
flags
());
...
...
@@ -418,10 +420,10 @@ void cmd_loop(std::shared_ptr<DhtRunner>& node, dht_params& params
}
std
::
string
v
;
iss
>>
v
;
node
->
putSigned
(
id
,
dht
::
Value
{
dht
::
ValueType
::
USER_DATA
.
id
,
std
::
vector
<
uint8_t
>
{
v
.
begin
(),
v
.
end
()}
}
,
[
start
](
bool
ok
)
{
auto
value
=
std
::
make_shared
<
dht
::
Value
>
();
value
->
data
=
{
v
.
begin
(),
v
.
end
()};
value
->
user_type
=
"text/plain"
;
node
->
putSigned
(
id
,
std
::
move
(
value
)
,
[
start
](
bool
ok
)
{
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
std
::
cout
<<
"Put signed: "
<<
(
ok
?
"success"
:
"failure"
)
<<
" (took "
<<
print_duration
(
end
-
start
)
<<
"s)"
<<
std
::
endl
;
});
...
...
@@ -434,10 +436,12 @@ void cmd_loop(std::shared_ptr<DhtRunner>& node, dht_params& params
std
::
string
tostr
;
std
::
string
v
;
iss
>>
tostr
>>
v
;
node
->
putEncrypted
(
id
,
InfoHash
(
tostr
),
dht
::
Value
{
auto
value
=
std
::
make_shared
<
dht
::
Value
>
(
dht
::
ValueType
::
USER_DATA
.
id
,
std
::
vector
<
uint8_t
>
{
v
.
begin
(),
v
.
end
()}
},
[
start
](
bool
ok
)
{
);
value
->
user_type
=
"text/plain"
;
node
->
putEncrypted
(
id
,
InfoHash
(
tostr
),
std
::
move
(
value
),
[
start
](
bool
ok
)
{
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
std
::
cout
<<
"Put encrypted: "
<<
(
ok
?
"success"
:
"failure"
)
<<
" (took "
<<
print_duration
(
end
-
start
)
<<
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