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
b668d6ad
Commit
b668d6ad
authored
3 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
dhtrunner: add putEncrypted with public key
parent
29fab556
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
include/opendht/dhtrunner.h
+11
-0
11 additions, 0 deletions
include/opendht/dhtrunner.h
include/opendht/securedht.h
+4
-0
4 additions, 0 deletions
include/opendht/securedht.h
src/dhtrunner.cpp
+25
-0
25 additions, 0 deletions
src/dhtrunner.cpp
src/securedht.cpp
+21
-3
21 additions, 3 deletions
src/securedht.cpp
with
61 additions
and
3 deletions
include/opendht/dhtrunner.h
+
11
−
0
View file @
b668d6ad
...
...
@@ -257,6 +257,17 @@ public:
}
void
putEncrypted
(
const
std
::
string
&
key
,
InfoHash
to
,
Value
&&
value
,
DoneCallback
cb
=
{},
bool
permanent
=
false
);
void
putEncrypted
(
InfoHash
hash
,
const
std
::
shared_ptr
<
crypto
::
PublicKey
>&
to
,
std
::
shared_ptr
<
Value
>
value
,
DoneCallback
cb
=
{},
bool
permanent
=
false
);
void
putEncrypted
(
InfoHash
hash
,
const
std
::
shared_ptr
<
crypto
::
PublicKey
>&
to
,
std
::
shared_ptr
<
Value
>
value
,
DoneCallbackSimple
cb
,
bool
permanent
=
false
)
{
putEncrypted
(
hash
,
to
,
value
,
bindDoneCb
(
cb
),
permanent
);
}
void
putEncrypted
(
InfoHash
hash
,
const
std
::
shared_ptr
<
crypto
::
PublicKey
>&
to
,
Value
&&
value
,
DoneCallback
cb
=
{},
bool
permanent
=
false
);
void
putEncrypted
(
InfoHash
hash
,
const
std
::
shared_ptr
<
crypto
::
PublicKey
>&
to
,
Value
&&
value
,
DoneCallbackSimple
cb
,
bool
permanent
=
false
)
{
putEncrypted
(
hash
,
to
,
std
::
forward
<
Value
>
(
value
),
bindDoneCb
(
cb
),
permanent
);
}
/**
* Insert known nodes to the routing table, without necessarly ping them.
* Usefull to restart a node and get things running fast without putting load on the network.
...
...
This diff is collapsed.
Click to expand it.
include/opendht/securedht.h
+
4
−
0
View file @
b668d6ad
...
...
@@ -118,6 +118,10 @@ public:
void
putEncrypted
(
const
InfoHash
&
hash
,
const
InfoHash
&
to
,
Value
&&
v
,
DoneCallback
callback
,
bool
permanent
=
false
)
{
putEncrypted
(
hash
,
to
,
std
::
make_shared
<
Value
>
(
std
::
move
(
v
)),
callback
,
permanent
);
}
void
putEncrypted
(
const
InfoHash
&
hash
,
const
crypto
::
PublicKey
&
to
,
Sp
<
Value
>
val
,
DoneCallback
callback
,
bool
permanent
=
false
);
void
putEncrypted
(
const
InfoHash
&
hash
,
const
crypto
::
PublicKey
&
to
,
Value
&&
v
,
DoneCallback
callback
,
bool
permanent
=
false
)
{
putEncrypted
(
hash
,
to
,
std
::
make_shared
<
Value
>
(
std
::
move
(
v
)),
callback
,
permanent
);
}
/**
* Take ownership of the value and sign it using our private key.
...
...
This diff is collapsed.
Click to expand it.
src/dhtrunner.cpp
+
25
−
0
View file @
b668d6ad
...
...
@@ -966,6 +966,31 @@ DhtRunner::putEncrypted(const std::string& key, InfoHash to, Value&& value, Done
putEncrypted
(
InfoHash
::
get
(
key
),
to
,
std
::
forward
<
Value
>
(
value
),
std
::
move
(
cb
),
permanent
);
}
void
DhtRunner
::
putEncrypted
(
InfoHash
hash
,
const
std
::
shared_ptr
<
crypto
::
PublicKey
>&
to
,
std
::
shared_ptr
<
Value
>
value
,
DoneCallback
cb
,
bool
permanent
)
{
std
::
unique_lock
<
std
::
mutex
>
lck
(
storage_mtx
);
if
(
running
!=
State
::
Running
)
{
lck
.
unlock
();
if
(
cb
)
cb
(
false
,
{});
return
;
}
ongoing_ops
++
;
pending_ops
.
emplace
([
=
,
cb
=
std
::
move
(
cb
),
value
=
std
::
move
(
value
)
]
(
SecureDht
&
dht
)
mutable
{
dht
.
putEncrypted
(
hash
,
*
to
,
value
,
bindOpDoneCallback
(
std
::
move
(
cb
)),
permanent
);
});
cv
.
notify_all
();
}
void
DhtRunner
::
putEncrypted
(
InfoHash
hash
,
const
std
::
shared_ptr
<
crypto
::
PublicKey
>&
to
,
Value
&&
value
,
DoneCallback
cb
,
bool
permanent
)
{
putEncrypted
(
hash
,
to
,
std
::
make_shared
<
Value
>
(
std
::
move
(
value
)),
std
::
move
(
cb
),
permanent
);
}
void
DhtRunner
::
bootstrap
(
const
std
::
string
&
host
,
const
std
::
string
&
service
)
{
...
...
This diff is collapsed.
Click to expand it.
src/securedht.cpp
+
21
−
3
View file @
b668d6ad
...
...
@@ -200,8 +200,6 @@ SecureDht::findCertificate(const InfoHash& node, const std::function<void(const
auto
found
=
std
::
make_shared
<
bool
>
(
false
);
dht_
->
get
(
node
,
[
cb
,
node
,
found
,
this
](
const
std
::
vector
<
Sp
<
Value
>>&
vals
)
{
if
(
*
found
)
return
false
;
for
(
const
auto
&
v
:
vals
)
{
if
(
auto
cert
=
registerCertificate
(
node
,
v
->
data
))
{
*
found
=
true
;
...
...
@@ -212,7 +210,7 @@ SecureDht::findCertificate(const InfoHash& node, const std::function<void(const
return
false
;
}
}
return
true
;
return
!*
found
;
},
[
cb
,
found
](
bool
)
{
if
(
!*
found
and
cb
)
cb
(
nullptr
);
...
...
@@ -424,6 +422,26 @@ SecureDht::putEncrypted(const InfoHash& hash, const InfoHash& to, Sp<Value> val,
});
}
void
SecureDht
::
putEncrypted
(
const
InfoHash
&
hash
,
const
crypto
::
PublicKey
&
pk
,
Sp
<
Value
>
val
,
DoneCallback
callback
,
bool
permanent
)
{
if
(
not
key_
)
{
if
(
callback
)
callback
(
false
,
{});
return
;
}
if
(
logger_
)
logger_
->
w
(
"Encrypting data for PK: %s"
,
pk
.
getLongId
().
to_c_str
());
try
{
dht_
->
put
(
hash
,
encrypt
(
*
val
,
pk
),
callback
,
time_point
::
max
(),
permanent
);
}
catch
(
const
std
::
exception
&
e
)
{
if
(
logger_
)
logger_
->
e
(
"Error putting encrypted data: %s"
,
e
.
what
());
if
(
callback
)
callback
(
false
,
{});
}
}
void
SecureDht
::
sign
(
Value
&
v
)
const
{
...
...
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