Rename speedKbps and dataCapMB parameters to bytesPerSecond and quotaBytes, respectively, in API and traffic control logic

This commit is contained in:
ImBenji
2025-08-05 13:46:13 +01:00
parent daf67bf516
commit 2d692e0bc0
4 changed files with 123 additions and 31 deletions

View File

@@ -31,11 +31,70 @@ Client applications communicate through Supabase to discover available Waylume s
- **Health Monitoring**: Continuous heartbeat system for server availability
### API Endpoints
- `POST /api/peers` - Create new VPN peer with generated keys and configuration
- `POST /api/peers/delete` - Remove VPN peer (publicKey in request body)
- `POST /api/peers/speed-limit` - Set bandwidth limits for peer (publicKey + speedKbps in request body)
- `POST /api/peers/data-cap` - Set data usage limits for peer (publicKey + dataCapMB in request body)
- `POST /api/peers/config` - Retrieve peer configuration (publicKey in request body, not implemented)
#### `POST /api/peers`
Create a new VPN peer with automatically generated WireGuard keys and IP assignment.
**Request:** No body required
**Response:**
```json
{
"success": true,
"peer": {
"privateKey": "base64_private_key",
"publicKey": "base64_public_key",
"ip": "10.0.0.x"
},
"config": "complete_wireguard_client_config"
}
```
#### `POST /api/peers/delete`
Remove a VPN peer and clean up associated WireGuard configuration.
**Request Body:**
```json
{
"publicKey": "peer_public_key_here"
}
```
#### `POST /api/peers/speed-limit`
Set bidirectional bandwidth limits for a peer (controls both upload and download speeds).
**Request Body:**
```json
{
"publicKey": "peer_public_key_here",
"bytesPerSecond": 125000
}
```
*Note: 125000 bytes/s = 1000 kbps = 1 Mbps*
**Common Speed Conversions:**
- 125 KB/s = 1 Mbps
- 1,250 KB/s = 10 Mbps
- 12,500 KB/s = 100 Mbps
#### `POST /api/peers/data-cap`
Set total data usage limits for a peer using iptables quota rules.
**Request Body:**
```json
{
"publicKey": "peer_public_key_here",
"quotaBytes": 1073741824
}
```
*Note: 1073741824 bytes = 1 GB*
**Common Data Conversions:**
- 1 GB = 1,073,741,824 bytes
- 10 GB = 10,737,418,240 bytes
- 100 GB = 107,374,182,400 bytes
#### `POST /api/peers/config`
Retrieve peer configuration (currently not implemented - returns 404).
### Security Features
- Peer isolation using iptables rules (prevents peer-to-peer communication)
@@ -130,14 +189,14 @@ curl -X POST http://localhost:3000/api/peers/delete \
```bash
curl -X POST http://localhost:3000/api/peers/speed-limit \
-H "Content-Type: application/json" \
-d '{"publicKey": "PEER_PUBLIC_KEY_HERE", "speedKbps": 1000}'
-d '{"publicKey": "PEER_PUBLIC_KEY_HERE", "bytesPerSecond": 125000}' # 125000 bytes/s = 1000 kbps
```
### Set data cap for peer
```bash
curl -X POST http://localhost:3000/api/peers/data-cap \
-H "Content-Type: application/json" \
-d '{"publicKey": "PEER_PUBLIC_KEY_HERE", "dataCapMB": 1024}'
-d '{"publicKey": "PEER_PUBLIC_KEY_HERE", "quotaBytes": 1073741824}' # 1073741824 bytes = 1024 MB
```
### Get peer config