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 Native Extension (New in v0.2.0):
- 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.
- Noise Handshake (XX Pattern): Secure, authenticated connections using
- 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
from kadepy import Swarm
import time
# Create a node on a random port
node = Swarm()
print(f"Node started on port {node.port}")
# Create another node to bootstrap
bootstrap_node = Swarm(port=8000)
print("Bootstrap node on port 8000")
# Bootstrap the first node
node.bootstrap("127.0.0.1", 8000)
# Announce a topic (hash)
topic_hash = b'\x00' * 32 # 32-byte hash
node.announce(topic_hash, node.port)
# Find peers for the topic
peers = node.get_peers(topic_hash)
print("Found peers:", peers)
# Keep alive
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print("Stopping...")
Architecture
KadePy follows a hybrid architecture:
-
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.
- Hyperswarm (Experimental): Native C implementation of Noise/UDX (work in progress).
- UDP Reactor: Handles non-blocking socket I/O using
-
Python Wrapper (
Swarm):- Provides a high-level API.
- Manages the C reactor lifecycle.
- Handles bootstrapping and iterative lookups.
Contributing
Contributions are welcome! Please check out the CONTRIBUTING.md guide for details.
- Fork the project.
- Create your feature branch (
git checkout -b feature/AmazingFeature). - Commit your changes (
git commit -m 'Add some AmazingFeature'). - Push to the branch (
git push origin feature/AmazingFeature). - 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kadepy-0.2.2.tar.gz.
File metadata
- Download URL: kadepy-0.2.2.tar.gz
- Upload date:
- Size: 269.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a481ff9994b45aafe02ee516c4287c57a3a3ee206ed67fa03e1047ce5905fc4d
|
|
| MD5 |
16ab456ed33de66092c7cda86d9d7d1c
|
|
| BLAKE2b-256 |
ae0bf83ff45235787e210fe8dcf52bc96c684014be2a85539139edc84ac7045e
|
File details
Details for the file kadepy-0.2.2-cp314-cp314-win_amd64.whl.
File metadata
- Download URL: kadepy-0.2.2-cp314-cp314-win_amd64.whl
- Upload date:
- Size: 242.5 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
80e1cbce78fd7694b44ed14db03e557889454a8fa4a7451326f8328f834e9430
|
|
| MD5 |
b3972f7e4673932f365173ceb543404e
|
|
| BLAKE2b-256 |
8a3ed370fb5d83f7347cb95b3d2589bf8dca1208ad625607a91f8444721eebcd
|