Refactor peer creation to include geolocation data and server details
This commit is contained in:
@@ -3,6 +3,8 @@ import 'dart:convert';
|
||||
import 'package:shelf/shelf.dart';
|
||||
import 'package:shelf_router/shelf_router.dart';
|
||||
import 'package:waylume_server/wireguard/peers.dart';
|
||||
import 'package:waylume_server/wireguard/utils.dart';
|
||||
import 'package:waylume_server/core/utils.dart';
|
||||
import 'package:waylume_server/services/vpn_session_service.dart';
|
||||
|
||||
class PeerRoutes {
|
||||
@@ -21,14 +23,24 @@ class PeerRoutes {
|
||||
Future<Response> _createPeer(Request request) async {
|
||||
try {
|
||||
final peer = await createPeer();
|
||||
final config = await generateClientConfigForPeer(peer);
|
||||
final geoData = await getGeolocationData();
|
||||
String serverEndpoint = '${geoData.ip}:51820';
|
||||
String serverPublicKey = await getServerPublicKey();
|
||||
|
||||
final responseData = <String, dynamic>{
|
||||
'peer': {
|
||||
'ip': peer.ip,
|
||||
'privateKey': peer.privateKey,
|
||||
},
|
||||
'server': {
|
||||
'publicKey': serverPublicKey,
|
||||
'endpoint': serverEndpoint,
|
||||
},
|
||||
'success': true,
|
||||
};
|
||||
|
||||
return Response.ok(
|
||||
jsonEncode({
|
||||
'success': true,
|
||||
'peer': peer.toJson(),
|
||||
'config': config,
|
||||
}),
|
||||
jsonEncode(responseData),
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
);
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user