Giter Site home page Giter Site logo

michalciolek / opendht Goto Github PK

View Code? Open in Web Editor NEW

This project forked from savoirfairelinux/opendht

0.0 2.0 0.0 655 KB

A C++11 Distributed Hash Table implementation

License: GNU General Public License v3.0

CMake 1.28% Shell 0.01% C 0.52% C++ 85.80% Python 12.39%

opendht's Introduction

OpenDHT

A lightweight C++11 Distributed Hash Table implementation originally based on https://github.com/jech/dht by Juliusz Chroboczek.

  • Light and fast C++11 Kademlia DHT library.
  • Distributed shared key->value data-store
  • Clean and powerfull distributed map API with storage of arbitrary binary values.
  • Optional public key cryptography layer providing data signature and encryption (using GnuTLS).
  • IPv4 and IPv6 support.
  • Python binding.

Documentation

See the wiki: https://github.com/savoirfairelinux/opendht/wiki

Examples

C++ example

The tools directory includes simple example programs :

  • dhtnode, a command line tool, mostly used for debuging, allowing to perform operations supported by the library (get, put etc.) with text values.
  • dhtchat, a very simple IM client working over the dht.

Example program launching a DHT node, connecting to the network and performing some basic operations:

#include <opendht.h>
#include <vector>

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);

    // put some data on the dht, signed with our generated private key
    node.putSigned("unique_key_42", some_data);

    // get data from the dht
    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;
        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;
}

Python 3 example

import opendht as dht

r = dht.DhtRunner()
r.run()

# Join the network through any running node,
# here using a known bootstrap node.
r.bootstrap("bootstrap.ring.cx", "4222")

r.put(dht.InfoHash.get("unique_key"), dht.Value(b'some binary data'))

# blocking call (provide a get_cb and an optional done_cb argument to make the call non-blocking)
results = r.get(dht.InfoHash.get("unique_key"))
for r in results:
    print(r)

How-to build and install

Using autotools

# clone the repo
git clone https://github.com/savoirfairelinux/opendht.git

# build and install
cd opendht
./autogen.sh && ./configure
make
sudo make install

Using cmake

# clone the repo
git clone https://github.com/savoirfairelinux/opendht.git

# build and install
cd opendht
mkdir build && cd build
cmake -DOPENDHT_PYTHON=ON ..
make -j
sudo make install

How-to build a simple client app

g++ main.cpp -std=c++11 -lopendht -lgnutls

Licence

Copyright (C) 2014-2015 Savoir-Faire Linux Inc.

Licenced under the GNU General Public License version 3, though the core routing library (dht.cpp) is licenced under the MIT licence.

This project is independent from another project called OpenDHT (Sean Rhea. Ph.D. Thesis, 2005), now extinct.

Dependencies

  • msgpack-c, used for data serialisation.
  • GnuTLS 3.1+, used to compute hashes and for the identity layer.
  • Nettle 2.4+, a GnuTLS dependency for crypto.
  • Build tested with GCC 4.8+ (Linux, Android, Windows with MinGW), Clang/LLVM (Linux, OS X).

opendht's People

Contributors

aberaud avatar eckoedc avatar tmatth avatar cyrilleberaud avatar benkant avatar shaundaley39 avatar

Watchers

James Cloos avatar Michał Ciołek avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.