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
2063d5f9
Commit
2063d5f9
authored
10 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
Update example with bootstrap
Also make the example compilable.
parent
30d5ad5f
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
README.md
+10
-3
10 additions, 3 deletions
README.md
with
10 additions
and
3 deletions
README.md
+
10
−
3
View file @
2063d5f9
...
...
@@ -19,14 +19,20 @@ Example
Example program launching a DHT node, connecting to the network and performing some basic operations:
```
c++
#include
<opendht.h>
#include
<vector>
int
main
()
{
int
main
()
{
dht
::
DhtRunner
node
;
// Launch a dht node on a new thread, using a
// generated RSA key pair, and listen on port 4222.
node
.
run
(
4222
,
dht
::
crypto
::
generateIdentity
(),
true
);
// Join the network through any running node,
// here using a known bootstrap node.
node
.
bootstrap
(
"bootstrap.ring.cx"
,
"4222"
);
// put some data on the dht
std
::
vector
<
uint8_t
>
some_data
(
5
,
10
);
node
.
put
(
"unique_key"
,
some_data
);
...
...
@@ -38,7 +44,7 @@ int main() {
node
.
get
(
"other_unique_key"
,
[](
const
std
::
vector
<
std
::
shared_ptr
<
dht
::
Value
>>&
values
)
{
// Callback called when values are found
for
(
const
auto
&
value
:
values
)
std
::
cout
<<
"Found value: "
<<
value
<<
std
::
endl
;
std
::
cout
<<
"Found value: "
<<
*
value
<<
std
::
endl
;
return
true
;
// return false to stop the search
});
...
...
@@ -47,6 +53,7 @@ int main() {
// wait for dht threads to end
node
.
join
();
return
0
;
}
```
...
...
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