Cyrille BéraudandCopilot App e9208cfbe4 http: bound name resolution and reuse the endpoints it found
Request::send waits for Resolver before doing anything else, and the
timeout a caller sets through Request::timeout is only armed later, in
connect. A system resolver that never answers therefore holds the request
for good: async_resolve has no deadline of its own, no timer covers the
wait, and the callbacks queued in Resolver are never invoked. The proxy
client reaches that path on every connectivity change, since
connectivityChanged calls getProxyInfos, so a device coming back from
sleep can sit there with no status, no listener and no error.

getProxyInfos also builds a new Resolver each time and drops the previous
one, discarding endpoints that were still perfectly usable. Resolution is
then redone from scratch at the exact moment the network stack has just
come up and is at its slowest.

Give Resolver a deadline of its own, armed as soon as a query starts, and
report timed_out to whoever is waiting. Let it also start from endpoints
that were already resolved: those answer callbacks immediately so a
connection begins without waiting, while the query still runs and
replaces them as soon as it returns. An address that went stale in the
meantime now costs one connection attempt, which Request retries against
the pending query rather than reporting as a failure.

A failed query no longer clears endpoints that are known to work, so a
transient DNS outage leaves the client with something to connect to.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
2026-09-03 07:50:51 -04:00
2025-08-16 21:22:57 -04:00
2026-08-05 16:19:46 -04:00
2025-11-19 11:19:55 -05:00
2026-05-11 09:27:56 -04:00
2026-01-17 17:09:06 -05:00
2026-05-18 10:50:23 -04:00
2026-01-13 21:41:57 -05:00
2026-05-11 09:27:56 -04:00
2026-05-18 10:36:48 -04:00
2025-11-19 11:20:02 -05:00
2026-01-13 21:41:57 -05:00
2026-03-13 11:07:01 -04:00
2026-08-05 16:35:01 -04:00
2026-08-05 16:35:01 -04:00
2026-03-08 12:26:23 -04:00
2026-03-08 12:26:23 -04:00
2026-02-22 21:42:24 -05:00
2026-08-05 16:35:01 -04:00


OpenDHT

PyPI - Version

A lightweight C++17 Distributed Hash Table implementation.

OpenDHT provides an easy to use distributed in-memory data store. Every node in the network can read and write values to the store. Values are distributed over the network, with redundancy.

  • Lightweight and scalable, designed for large networks and small devices
  • High resilience to network disruption
  • Public key cryptography layer providing optional data signature and encryption (using GnuTLS)
  • IPv4 and IPv6 support
  • Clean and powerful C++17 map API
  • Bindings for C, Rust & Python 3
  • REST API with optional HTTP client+server with push notification support

Documentation

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

How to run a node

You can help contribute to the public network by running a stable node with a public IP address. https://github.com/savoirfairelinux/opendht/wiki/Running-a-node-with-dhtnode

How-to build and install

Build instructions: see BUILD.md

Examples

C++ example

The tools directory includes simple example programs :

  • dhtnode, a command line tool, allowing to run a DHT node and 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.jami.net", "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
    });

    // wait for dht threads to end
    node.join();
    return 0;
}

Python 3 example

Install on Linux, macOS and Windows with:

pip install opendht

Using the simple, blocking API:

import opendht as dht

node = dht.DhtRunner()
node.run()

# Join the DHT network through any running node,
# here using a known bootstrap node.
node.bootstrap("bootstrap.jami.net", "4222")

# blocking call (provide callback arguments to make the call non-blocking)
node.put(dht.InfoHash.get("unique_key"), dht.Value(b'some binary data'))

results = node.get(dht.InfoHash.get("unique_key"))
for value in results:
    print(value)

Or using asyncio:

import asyncio
import opendht.aio as dht

async def dht_async_demo(key_str: str):
    # Start a new node using an async context manager.
    # It is also possible to call run()/await shutdown() manually.
    async with dht.DhtRunner(
        bootstrap=(("bootstrap.jami.net", "4222"),)
    ) as node:
        # compute key hash
        key = dht.InfoHash.get(key_str)

        # put data, waiting for completion
        await node.put(key, dht.Value(b'tata data'))

        # get all values at key
        results = await node.getAll(key)
        for value in results:
            print(value)
        
        # same operation, but stream values as they come from the network
        with node.get(key) as results:
            async for value in results:
                print(value)

        # listen for change of values at key
        with node.listen(key) as values:
            async for value, expired in values:
                print(value)
                if value.data == b'tata data':
                    break

asyncio.run(dht_async_demo("unique_key"))

Dependencies

Core dependencies:

  • msgpack-c 1.2+, used for data serialization.
  • GnuTLS 3.3+, used for cryptographic operations.
  • Nettle 2.4+, a GnuTLS dependency for crypto.
  • {fmt} 9.0+, for log formatting.

Optional dependencies for the REST API (DHT proxy client/server):

  • (optional) restinio
  • (optional) llhttp
  • (optional) jsoncpp 1.7.4-3+
  • (optional) simdutf

Build environment:

  • Build tested with GCC 9+ (GNU/Linux, Windows with MinGW), Clang/LLVM (GNU/Linux, Android, macOS, iOS).
  • Build tested with Microsoft Visual Studio 2019, 2022

License

Copyright (c) 2014-2026 Savoir-faire Linux Inc.

OpenDHT is released under the MIT License. See LICENSE for details.

Acknowledgements

This project was originally based on https://github.com/jech/dht by Juliusz Chroboczek.

S
Description
No description provided
Readme MIT
11 MiB
0 Stars 1 Watchers 0 Forks
Languages
C++ 68.1%
Python 7.7%
HTML 5.8%
Rust 5.7%
C 3.5%
Other 9.2%