@@ -8,9 +8,11 @@ import '../../myceliumflut_ffi_binding.dart';
88enum NodeStatus { disconnected, connecting, connected, failed }
99
1010class MyceliumService {
11- static const MethodChannel _platform = MethodChannel ("tech.threefold.mycelium/tun" );
11+ static const MethodChannel _platform =
12+ MethodChannel ("tech.threefold.mycelium/tun" );
1213
13- final StreamController <NodeStatus > _statusController = StreamController <NodeStatus >.broadcast ();
14+ final StreamController <NodeStatus > _statusController =
15+ StreamController <NodeStatus >.broadcast ();
1416 NodeStatus _status = NodeStatus .disconnected;
1517 Uint8List ? _privKey;
1618
@@ -29,7 +31,8 @@ class MyceliumService {
2931 if (isUseDylib ()) {
3032 privKey = myFFGenerateSecretKey ();
3133 } else {
32- privKey = (await _platform.invokeMethod <Uint8List >('generateSecretKey' )) as Uint8List ;
34+ privKey = (await _platform.invokeMethod <Uint8List >('generateSecretKey' ))
35+ as Uint8List ;
3336 }
3437 await file.writeAsBytes (privKey);
3538 _privKey = privKey;
@@ -59,18 +62,22 @@ class MyceliumService {
5962
6063 String ? validatePeer (String peer) {
6164 final prefixRegex = RegExp (r'^tcp://' );
62- final ipv4Regex = RegExp (r'((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)' );
63- final ipv6Regex = RegExp (r'\[(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))\]' );
65+ final ipv4Regex = RegExp (
66+ r'((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)' );
67+ final ipv6Regex = RegExp (
68+ r'\[(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))\]' );
6469 final portRegex = RegExp (r':9651$' );
6570 if (! prefixRegex.hasMatch (peer)) return 'peer must start with tcp://' ;
6671 final ipPortPart = peer.substring (peer.indexOf ('://' ) + 3 );
67- if (! ipv4Regex.hasMatch (ipPortPart) && ! ipv6Regex.hasMatch (ipPortPart)) return 'peer must contain a valid IPv4 or IPv6 address' ;
72+ if (! ipv4Regex.hasMatch (ipPortPart) && ! ipv6Regex.hasMatch (ipPortPart))
73+ return 'peer must contain a valid IPv4 or IPv6 address' ;
6874 if (! portRegex.hasMatch (ipPortPart)) return 'peer must end with :9651' ;
6975 return null ;
7076 }
7177
7278 String ? validatePeers (List <String > peers) {
73- if (peers.isEmpty || (peers.length == 1 && peers[0 ].isEmpty)) return "peers can't be empty" ;
79+ if (peers.isEmpty || (peers.length == 1 && peers[0 ].isEmpty))
80+ return "peers can't be empty" ;
7481 for (final p in peers) {
7582 final e = validatePeer (p);
7683 if (e != null ) return 'invalid peer:`$p ` $e ' ;
@@ -147,7 +154,8 @@ class MyceliumService {
147154 peerStatus = await myFFGetPeerStatus ();
148155 } else {
149156 // Android/iOS platform - use platform channel
150- final result = await _platform.invokeMethod <List <dynamic >>('getPeerStatus' );
157+ final result =
158+ await _platform.invokeMethod <List <dynamic >>('getPeerStatus' );
151159 peerStatus = result? .cast <String >() ?? [];
152160 }
153161
@@ -165,6 +173,34 @@ class MyceliumService {
165173 void dispose () {
166174 _statusController.close ();
167175 }
168- }
169176
177+ Future <List <String >> proxyConnect (String remote) async {
178+ try {
179+ if (isUseDylib ()) {
180+ return myFFProxyConnect (remote);
181+ } else {
182+ final result = await _platform.invokeMethod <List <dynamic >>(
183+ 'proxyConnect' ,
184+ {'remote' : remote},
185+ );
186+ return result? .cast <String >() ?? [];
187+ }
188+ } catch (e) {
189+ throw Exception ("Failed to proxyConnect: $e " );
190+ }
191+ }
170192
193+ Future <List <String >> proxyDisconnect () async {
194+ try {
195+ if (isUseDylib ()) {
196+ return myFFProxyDisconnect ();
197+ } else {
198+ final result =
199+ await _platform.invokeMethod <List <dynamic >>('proxyDisconnect' );
200+ return result? .cast <String >() ?? [];
201+ }
202+ } catch (e) {
203+ throw Exception ("Failed to proxyDisconnect: $e " );
204+ }
205+ }
206+ }
0 commit comments