From 7b1278980e3cb89ff0bffada8d116c5689086512 Mon Sep 17 00:00:00 2001 From: ImBenji Date: Tue, 5 Aug 2025 02:53:21 +0100 Subject: [PATCH] Specify Dockerfile in waylume-server build configuration --- README.md | 29 ++++++++++++------ lib/web/peer_routes.dart | 66 ++++++++++++++++++++++++++++++++-------- 2 files changed, 73 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index c5cb731..7e9bd1f 100644 --- a/README.md +++ b/README.md @@ -32,10 +32,10 @@ Client applications communicate through Supabase to discover available Waylume s ### API Endpoints - `POST /api/peers` - Create new VPN peer with generated keys and configuration -- `DELETE /api/peers/{publicKey}` - Remove VPN peer -- `PUT /api/peers/{publicKey}/speed-limit` - Set bandwidth limits for peer -- `PUT /api/peers/{publicKey}/data-cap` - Set data usage limits for peer -- `GET /api/peers/{publicKey}/config` - Retrieve peer configuration (not implemented) +- `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) ### Security Features - Peer isolation using iptables rules (prevents peer-to-peer communication) @@ -119,23 +119,32 @@ Response: } ``` +### Delete a peer +```bash +curl -X POST http://localhost:3000/api/peers/delete \ + -H "Content-Type: application/json" \ + -d '{"publicKey": "PEER_PUBLIC_KEY_HERE"}' +``` + ### Set speed limit for peer ```bash -curl -X PUT http://localhost:3000/api/peers/{publicKey}/speed-limit \ +curl -X POST http://localhost:3000/api/peers/speed-limit \ -H "Content-Type: application/json" \ - -d '{"speedKbps": 1000}' + -d '{"publicKey": "PEER_PUBLIC_KEY_HERE", "speedKbps": 1000}' ``` ### Set data cap for peer ```bash -curl -X PUT http://localhost:3000/api/peers/{publicKey}/data-cap \ +curl -X POST http://localhost:3000/api/peers/data-cap \ -H "Content-Type: application/json" \ - -d '{"dataCapMB": 1024}' + -d '{"publicKey": "PEER_PUBLIC_KEY_HERE", "dataCapMB": 1024}' ``` -### Delete a peer +### Get peer config ```bash -curl -X DELETE http://localhost:3000/api/peers/{publicKey} +curl -X POST http://localhost:3000/api/peers/config \ + -H "Content-Type: application/json" \ + -d '{"publicKey": "PEER_PUBLIC_KEY_HERE"}' ``` ## Network Architecture diff --git a/lib/web/peer_routes.dart b/lib/web/peer_routes.dart index 83d6704..06cd75d 100644 --- a/lib/web/peer_routes.dart +++ b/lib/web/peer_routes.dart @@ -9,10 +9,10 @@ class PeerRoutes { final router = Router(); router.post('/peers', _createPeer); - router.delete('/peers/', _deletePeer); - router.get('/peers//config', _getPeerConfig); - router.put('/peers//speed-limit', _setSpeedLimit); - router.put('/peers//data-cap', _setDataCap); + router.post('/peers/delete', _deletePeer); + router.post('/peers/config', _getPeerConfig); + router.post('/peers/speed-limit', _setSpeedLimit); + router.post('/peers/data-cap', _setDataCap); return router; } @@ -42,9 +42,21 @@ class PeerRoutes { } Future _deletePeer(Request request) async { - final publicKey = request.params['publicKey']!; - try { + final body = await request.readAsString(); + final data = jsonDecode(body) as Map; + final publicKey = data['publicKey'] as String?; + + if (publicKey == null) { + return Response.badRequest( + body: jsonEncode({ + 'success': false, + 'error': 'publicKey parameter is required', + }), + headers: {'Content-Type': 'application/json'}, + ); + } + final success = await deletePeer(publicKey); return Response.ok( @@ -66,9 +78,21 @@ class PeerRoutes { } Future _getPeerConfig(Request request) async { - final publicKey = request.params['publicKey']!; - try { + final body = await request.readAsString(); + final data = jsonDecode(body) as Map; + final publicKey = data['publicKey'] as String?; + + if (publicKey == null) { + return Response.badRequest( + body: jsonEncode({ + 'success': false, + 'error': 'publicKey parameter is required', + }), + headers: {'Content-Type': 'application/json'}, + ); + } + return Response.notFound( jsonEncode({ 'success': false, @@ -88,13 +112,22 @@ class PeerRoutes { } Future _setSpeedLimit(Request request) async { - final publicKey = request.params['publicKey']!; - try { final body = await request.readAsString(); final data = jsonDecode(body) as Map; + final publicKey = data['publicKey'] as String?; final speedKbps = data['speedKbps'] as int?; + if (publicKey == null) { + return Response.badRequest( + body: jsonEncode({ + 'success': false, + 'error': 'publicKey parameter is required', + }), + headers: {'Content-Type': 'application/json'}, + ); + } + if (speedKbps == null) { return Response.badRequest( body: jsonEncode({ @@ -126,13 +159,22 @@ class PeerRoutes { } Future _setDataCap(Request request) async { - final publicKey = request.params['publicKey']!; - try { final body = await request.readAsString(); final data = jsonDecode(body) as Map; + final publicKey = data['publicKey'] as String?; final dataCapMB = data['dataCapMB'] as int?; + if (publicKey == null) { + return Response.badRequest( + body: jsonEncode({ + 'success': false, + 'error': 'publicKey parameter is required', + }), + headers: {'Content-Type': 'application/json'}, + ); + } + if (dataCapMB == null) { return Response.badRequest( body: jsonEncode({