Skip to content

jjacke13/hyperdht-cpp

Repository files navigation

hyperdht-cpp

A C++ implementation of HyperDHT -- wire-compatible with the JavaScript reference. Connect any device to the Hyperswarm P2P network without a Node.js runtime.

What it does

Two devices on different networks, behind NATs, find each other by public key and establish an encrypted channel. No servers, no port forwarding, no configuration.

  • DHT peer discovery -- Kademlia routing table, iterative lookups, announcements
  • NAT traversal -- UDP holepunching with 4 strategies (consistent, random, birthday paradox, blind relay)
  • End-to-end encryption -- Noise IK handshake (Ed25519) + SecretStream (XChaCha20-Poly1305)
  • Mutable/immutable storage -- signed key-value records on the DHT
  • C FFI -- 76-function extern "C" API for Python, Go, Rust, Swift, Kotlin
  • Python wrapper included -- from hyperdht import HyperDHT, KeyPair and go

Why C++

The JS HyperDHT requires Node.js (~30MB runtime). This implementation is a single shared library (~1-2MB stripped) that embeds anywhere: mobile apps, embedded devices, system daemons, game engines, or any language with C FFI.

Status

Wire-compatible with JS hyperdht@6.29.1. Live-tested in both directions on the public network.

Tests 578 unit + 6 live, ASAN/UBSan clean
API parity Full -- wire-compatible with JS hyperdht@6.29.1 (audit)
Languages C++ / C / Python / Kotlin (Swift, Go, Rust planned)
Platforms Linux, macOS, Windows, Android, ESP32

Build

nix develop && mkdir -p build && cd build && cmake .. -G Ninja && ninja && ctest -L unit

Without Nix: install cmake, ninja, libsodium, libuv, then the same cmake flow. Docker also works (docker build -t hyperdht .). On Windows, use vcpkg for the dependencies and MSVC — CI builds the static and shared variants on every push (.github/workflows/windows.yml). See BUILDING.md for full instructions (Linux, macOS, Windows, Docker, linking, troubleshooting).

Documentation

Build instructions Linux, macOS, Windows, Docker, Nix — deps, compile, link, troubleshoot
C API reference 76 functions, opaque-pointer pattern, callback-based async
C++ API reference RAII wrappers, error codes, single-threaded event loop
Python examples Server, client, holesail tunnel, 22 wrapper tests
ESP32 guide Build, flash, run HyperDHT on ESP32-S3 (echo server + client)
Android example Kotlin/JNI wrapper with echo test app
Wire protocol spec Reverse-engineered from JS, 12 sections
JS name mapping Side-by-side: createServer -> create_server -> hyperdht_server_create
Remaining work Verification tasks, production readiness, ESP32 porting plan

Bootstrap nodes

The public HyperDHT network (same nodes the JS ecosystem uses):

node1.hyperdht.org:49737
node2.hyperdht.org:49737
node3.hyperdht.org:49737

Contributing

REMAINING-WORK.md tracks hardening and production polish. JS protocol parity is complete (audit). Every network-behaviour change must be live-tested against a JS peer before landing.

License

LGPL-3.0 -- library changes must be shared; downstream apps can use any license.