https://github.com/firstbatchxyz/dnet-p2p
A shared library for local peer discovery, in Rust.
https://github.com/firstbatchxyz/dnet-p2p
mdns rust
Last synced: 7 months ago
JSON representation
A shared library for local peer discovery, in Rust.
- Host: GitHub
- URL: https://github.com/firstbatchxyz/dnet-p2p
- Owner: firstbatchxyz
- License: apache-2.0
- Created: 2025-03-11T07:44:14.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-12-11T20:36:21.000Z (8 months ago)
- Last Synced: 2025-12-13T00:13:02.018Z (8 months ago)
- Topics: mdns, rust
- Language: Rust
- Homepage:
- Size: 7.5 MB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dnet p2p
dnet p2p is a shared library that adds LAN peer-to-peer discovery. It exposes two modes (inspired from MPI terms):
- **Manager**: the manager of the local network, is able to dispatch tasks to all other. There can only be one manager.
- **Worker**: every non-manager is expected to be a worker, connected via the LAN to serve their compute power to the manager.
## Installation
Install from the source via:
```sh
cargo install --git https://github.com/firstbatchxyz/dnet-p2p
```
## Usage
### Cargo from Source
You can run DnetP2P as follows:
```sh
# worker
cargo run
# manager
cargo run -m
# passive, just monitors others
cargo run -p
```
Note that there can only be one manager at a time.
### FFI from C/C++
Include the shared library within your loader step, e.g. `-L some/directory -ldnet_p2p`. Then, include [`dnet_p2p.h`](./bindings/c/src/dnet_p2p.h) in your code.
- You can create a new service object with `dnet_p2p_new` which returns you an object pointer, and free it later with `dnet_p2p_free`.
- You can start the service with `dnet_p2p_start` which returns you a thread handle pointer, and then stop it with `dnet_p2p_stop`.
See the [header file](./bindings/c/src/dnet_p2p.h) for more specific instructions.
### FFI from Python
A utility class is provided within [`dnet_p2p.py`](./bindings/py/src/dnet_p2p.py) that wraps the function calls for the shared library using `ctypes`. It provides both context usage (i.e. `with`) and normal usage.
See the example usage at [`main.py`](./bindings/py/main.py) that you can run with:
```sh
# worker
RUST_LOG=info uv run main.py
# manager
RUST_LOG=info uv run main.py -m
```
## Testing
Run tests with:
```sh
cargo test
```
### License
See [license file](./LICENSE).