Skip to main content

High-performance P2P Swarm implementation in C/Python with Signed RPC and IPC

Project description

KadePy

High-Performance Kademlia DHT Implementation for Python

KadePy is a robust and efficient Distributed Hash Table (DHT) library implementing the Kademlia protocol. It combines a high-performance C extension core for network handling and routing with a user-friendly Python wrapper.

Features

  • High Performance: Core logic (UDP reactor, routing table, storage, protocol) implemented in C for minimal overhead and maximum throughput.
  • Cross-Platform: Fully compatible with Windows, Linux, and macOS.
  • Hyperswarm Integration (v0.2.3):
    • Transparent Bridge: Automatically launches a managed Node.js bridge to leverage the battle-tested JS Hyperswarm implementation.
    • Full Compatibility: Connect seamlessly with existing Hyperswarm networks (Node.js, Holepunch).
    • Auto-Setup: Automatically handles dependency installation (npm install) and process management.
  • Native Extensions:
    • Noise Handshake (XX Pattern): Secure, authenticated connections using libsodium (Ed25519/Curve25519).
    • UDX Transport: Reliable, encrypted UDP transport with congestion control and packet ordering.
    • Holepunching: Built-in NAT traversal.
    • Private Bootstrap Mode: Run isolated nodes on fixed ports to serve as private network beacons.
  • Secure:
    • Uses XSalsa20-Poly1305 for transport encryption.
    • Implements secure random number generation.
  • Concurrency: Thread-safe architecture with a dedicated network reactor thread, releasing the GIL whenever possible.
  • Easy to Use: Simple Python API for creating nodes, storing values, and finding peers.

Installation

From Source

git clone https://github.com/ON00dev/KadePy.git
cd KadePy
pip install .

Requirements

  • Python 3.10+
  • C Compiler (GCC/Clang on Linux/macOS, MSVC on Windows)
  • Libsodium (automatically bundled on Windows if built via setup.py)

Quick Start

Basic Node (Hyperswarm)

from kadepy import Swarm
import hashlib
import time

# Create a node (automatically starts the Node.js bridge)
node = Swarm()
print("Node started!")

# Generate a topic key (32-byte bytes)
topic = hashlib.sha256(b"my-app-topic").digest()
print(f"Joining topic: {topic.hex()}")

# Join the swarm for this topic (announce=True, lookup=True by default)
node.join(topic)

# Define callback for incoming data
def on_data(data):
    print(f"Received message: {data}")
    # Reply to the sender (broadcasts to topic in this simple example)
    node.send(f"Echo: {data}")

# Register the callback
node.on("data", on_data)

# Send a message to the swarm
node.send("Hello World from KadePy!")

# Keep the process alive
try:
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    print("Stopping...")

Architecture

KadePy follows a hybrid architecture:

  1. C Extension (_core):

    • UDP Reactor: Handles non-blocking socket I/O using select (or platform specific polling).
    • Protocol: Implements Kademlia message serialization/deserialization.
    • Routing: Manages K-Buckets and node lookups.
    • Storage: In-memory key-value storage with expiration.
    • Crypto: ChaCha20 encryption and secure RNG.
    1. Hyperswarm (Experimental): Native C implementation of Noise/UDX (work in progress).
  2. Node.js Bridge (kadepy.js):

    • Bridge Process: A lightweight Node.js process managed by Python.
    • Hyperswarm: Uses the official hyperswarm library for DHT discovery and holepunching.
    • TCP IPC: Communicates with Python via a local TCP connection using JSON messages.
  3. Python Wrapper (Swarm):

    • Provides a high-level API (join, leave, send, on).
    • Manages the Node.js Bridge process lifecycle.
    • Handles data encoding/decoding (Base64/UTF-8).

Contributing

Contributions are welcome! Please check out the CONTRIBUTING.md guide for details.

  1. Fork the project.
  2. Create your feature branch (git checkout -b feature/AmazingFeature).
  3. Commit your changes (git commit -m 'Add some AmazingFeature').
  4. Push to the branch (git push origin feature/AmazingFeature).
  5. Open a Pull Request.

License

Distributed under the MIT License. See LICENSE for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kadepy-0.2.4.tar.gz (281.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kadepy-0.2.4-cp314-cp314-win_amd64.whl (250.8 kB view details)

Uploaded CPython 3.14Windows x86-64

File details

Details for the file kadepy-0.2.4.tar.gz.

File metadata

  • Download URL: kadepy-0.2.4.tar.gz
  • Upload date:
  • Size: 281.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for kadepy-0.2.4.tar.gz
Algorithm Hash digest
SHA256 0e8bd6d1ed85b138bb72f1a2e576709fbd545ad2c2866d98329e134b59c5802c
MD5 d5d2d580a7c4010ed4d095ae763161f6
BLAKE2b-256 1cbdea64bdbc0650041dcfbdd0bf465a9e3d4f0ab572c7d13ed3b815f78d9a6b

See more details on using hashes here.

File details

Details for the file kadepy-0.2.4-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: kadepy-0.2.4-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 250.8 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for kadepy-0.2.4-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 a9707a58481ccf0747624560a37a9549d1ef55ec26f226bfb2bc50e25b92ea15
MD5 cc99aee623c6fc24d5fd3055daf5a835
BLAKE2b-256 88c783ff497a1f39e329cc9b456afe854d0f333f226a9f163e87a5e56b6bb2da

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page