https://github.com/creamlike1024/dn42-autopeer-daemon
https://github.com/creamlike1024/dn42-autopeer-daemon
autopeer dn42
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/creamlike1024/dn42-autopeer-daemon
- Owner: creamlike1024
- License: gpl-3.0
- Created: 2025-11-29T16:05:21.000Z (8 months ago)
- Default Branch: master
- Last Pushed: 2026-03-21T06:28:03.000Z (4 months ago)
- Last Synced: 2026-03-21T22:25:09.278Z (4 months ago)
- Topics: autopeer, dn42
- Language: Rust
- Homepage:
- Size: 94.7 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dn42-autopeer-daemon
A small daemon that automates adding and removing dn42 peers, and provides a simple API.
## Build
The program uses a bundled version of SQLite, so a C compiler is required.
You can use [cargo-zigbuild](https://github.com/rust-cross/cargo-zigbuild) to easily build the musl version.
```
cargo zigbuild --release --target x86_64-unknown-linux-musl
```
## Requirements
- Linux with `systemd` or Alpine Linux
- `wireguard-tools-openrc` package installed(for Alpine Linux)
- `wg-quick` is available
- BIRD2 installed
- Run as root (or grant sufficient permissions to complete all operations)
## How It Works
The program assumes that you have a `/etc/bird/peers` folder based on the BIRD2 configuration from the DN42 wiki.
It does the following:
- Writes peer info to `peers.db`
- Generates WireGuard and BIRD configurations and places them in `/etc/wireguard` and `/etc/bird/peers`
- On systemd-based Linux, runs `systemctl start wg-quick@` to start the tunnel and `systemctl enable wg-quick@` to enable autostart
- On Alpine Linux (OpenRC), create per-interface symlink `ln -s /etc/init.d/wg-quick /etc/init.d/wg-quick.`, then run `rc-service wg-quick. start` to start the tunnel and `rc-update add wg-quick. default` to enable autostart
- Runs `birdc configure` to reload the BIRD configuration
## Limitations
The templates are limited to using WireGuard tunnels and BIRD with MP-BGP. This is currently the popular peering method in the DN42 community.
I have only tested on Debian and Alpine Linux.
## Configuration
Fill in `config.toml`
## API
- Base URL: `http://:`
- Auth: add `Authorization: Bearer ` when `API.secret` is set. If the header is missing or invalid, the response is `401 Unauthorized` with body `Unauthorized`.
### POST `/add`
```bash
curl -sS -X POST http://127.0.0.1:4242/add \
-H "Authorization: Bearer $SECRET" \
-H "Content-Type: application/json" \
-d '{
"asn": 4242421234,
"wireguard_endpoint": null,
"wireguard_link_local": "fe80::beef",
"wireguard_public_key": "",
"wireguard_preshared_key": "",
"mtu": 1420
}'
```
**Notes on Optional Fields:**
- `wireguard_endpoint`: (Optional) If omitted or set to `null`, the daemon configures the connection in **passive mode** (it listens for incoming connections but does not actively connect). If a valid endpoint address is provided (e.g., `"peer.example.net:51820"`), it operates in **active mode**. Empty strings or invalid formats are rejected.
- `wireguard_preshared_key`: (Optional) If omitted or set to `null`, the connection will be established without a Pre-Shared Key. If a valid 32-byte Base64 encoded key is provided, the WireGuard configuration will utilize it (`PresharedKey`). Empty strings (`""`) or incorrectly formatted keys are rejected.
Responses:
- `200 OK`
- `400 Bad Request`
- `401 Unauthorized`
- `409 Conflict`
- `500 Internal Server Error`
### POST `/del`
Curl:
```bash
curl -sS -X POST http://127.0.0.1:4242/del \
-H "Authorization: Bearer $SECRET" \
-H "Content-Type: application/json" \
-d '{ "asn": 4242421234 }'
```
Responses:
- `200 OK`
- `400 Bad Request`
- `401 Unauthorized`
- `404 Not Found`
- `500 Internal Server Error`
### POST `/get`
Curl:
```bash
curl -sS -X POST http://127.0.0.1:4242/get \
-H "Authorization: Bearer $SECRET" \
-H "Content-Type: application/json" \
-d '{ "asn": 4242421234 }'
```
Responses:
- `200 OK` header: `Content-Type: application/json; charset=utf-8`; body is the peer object:
```json
{
"asn": 4242420253,
"wireguard_endpoint": null,
"wireguard_link_local": "fe80::abcd",
"wireguard_public_key": "",
"wireguard_preshared_key": null,
"mtu": 1420
}
```
- `400 Bad Request`
- `401 Unauthorized`
- `404 Not Found`
- `500 Internal Server Error`