From 2063d5f980c5c3aedc881fda5edf77e6b3c6fc9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Sun, 29 Mar 2015 13:18:47 -0400 Subject: [PATCH] Update example with bootstrap Also make the example compilable. --- README.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4cf6a69f..fc8b3c76 100644 --- a/README.md +++ b/README.md @@ -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,15 +44,16 @@ 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 }); - + // here we could wait for some operations to complete // instead of ending now. // wait for dht threads to end node.join(); + return 0; } ``` -- GitLab