Snapshot uncommitted work: proxy UI, sing-box integration, socks bridge

- Lab app: proxy panel, node editor, configuration and detail pages,
  responsive layout, and related tests
- Add meshport-socks crate and sing-box bridge scripts/docs
- Add singbox_flutter binding and meshport_client_core package
- FFI, VPN helper (unified mac path), and Android/macOS runner updates
- Docs for architecture, client runtime, UI design, and validation
- UI design output artifacts under outputs/ui

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-12 10:06:15 +09:00
co-authored by Claude Haiku 5.5
parent 10b10e5bdf
commit 2f185f914d
123 changed files with 12180 additions and 326 deletions
@@ -0,0 +1,4 @@
/// Optional proxy engine bindings; does not load native code until open().
library;
export 'src/proxy_engine.dart';
@@ -0,0 +1,147 @@
import 'dart:convert';
import 'dart:ffi';
import 'dart:io';
import 'dart:isolate';
import 'package:ffi/ffi.dart';
abstract interface class ProxyEngine {
Future<Map<String, dynamic>> start({
required int port,
required String meshSocks,
required List<String> prefixes,
Map<String, dynamic>? profile,
});
Future<Map<String, dynamic>> status();
Future<void> stop();
Future<void> close();
}
String _libraryPath() {
if (Platform.isMacOS) {
return '${File(Platform.resolvedExecutable).parent.parent.path}/Frameworks/libmeshport_proxy.dylib';
}
if (Platform.isAndroid) return 'libmeshport_proxy.so';
throw UnsupportedError('Proxy engine currently supports macOS and Android');
}
Map<String, dynamic> _invoke(String path, int handle, String text) {
final library = DynamicLibrary.open(path);
final call = library
.lookupFunction<
Pointer<Utf8> Function(Uint64, Pointer<Utf8>),
Pointer<Utf8> Function(int, Pointer<Utf8>)
>('meshport_proxy_call');
final free = library
.lookupFunction<
Void Function(Pointer<Utf8>),
void Function(Pointer<Utf8>)
>('meshport_proxy_string_free');
final input = text.toNativeUtf8();
try {
final output = call(handle, input);
if (output == nullptr) throw StateError('Native engine response is null');
try {
return jsonDecode(output.toDartString()) as Map<String, dynamic>;
} finally {
free(output);
}
} finally {
calloc.free(input);
}
}
/// Calls run outside the UI isolate. Close is queued after in-flight operations.
class NativeProxyEngine implements ProxyEngine {
final String libraryPath;
final int _handle;
bool _closed = false;
Future<void> _tail = Future.value();
NativeProxyEngine._(this.libraryPath, this._handle);
static Future<NativeProxyEngine> open({String? libraryPath}) async {
final path = libraryPath ?? _libraryPath();
final handle = await Isolate.run(() {
final lib = DynamicLibrary.open(path);
final abi = lib.lookupFunction<Uint32 Function(), int Function()>(
'meshport_proxy_abi_version',
)();
if (abi != 1) throw StateError('Unsupported proxy engine ABI: $abi');
return lib.lookupFunction<Uint64 Function(), int Function()>(
'meshport_proxy_context_new',
)();
});
if (handle == 0) throw StateError('Could not create proxy engine context');
final engine = NativeProxyEngine._(path, handle);
try {
await engine._request({
'op': 'configure_cache',
'directory': Directory.systemTemp.path,
});
} catch (_) {
await engine.close();
rethrow;
}
return engine;
}
Future<T> _queue<T>(Future<T> Function() work) {
final result = _tail.then((_) => work());
_tail = result.then<void>((_) {}, onError: (Object _, StackTrace __) {});
return result;
}
Future<Map<String, dynamic>> _request(Map<String, dynamic> request) {
if (_closed) return Future.error(StateError('Proxy engine is closed'));
final path = libraryPath, handle = _handle, text = jsonEncode(request);
return _queue(() async {
final response = await Isolate.run(() => _invoke(path, handle, text));
if (response['ok'] != true)
throw StateError(
response['error'] as String? ?? 'Proxy engine operation failed',
);
return response['data'] as Map<String, dynamic>;
});
}
@override
Future<Map<String, dynamic>> start({
required int port,
required String meshSocks,
required List<String> prefixes,
Map<String, dynamic>? profile,
}) => _request({
'op': 'start',
'config': {
...?profile,
'listen_port': port,
'mesh_socks': meshSocks,
'mesh_cidrs': prefixes,
},
});
Future<Map<String, dynamic>> probeNode(Map<String, dynamic> options) =>
_request({
'op': 'probe_node',
'config': {'proxy': options},
});
@override
Future<Map<String, dynamic>> status() => _request({'op': 'status'});
@override
Future<void> stop() async {
await _request({'op': 'stop'});
}
@override
Future<void> close() {
if (_closed) return _tail;
_closed = true;
final path = libraryPath, handle = _handle;
return _queue(
() => Isolate.run(
() => DynamicLibrary.open(path)
.lookupFunction<Void Function(Uint64), void Function(int)>(
'meshport_proxy_context_free',
)(handle),
),
);
}
}
@@ -0,0 +1,8 @@
name: singbox_flutter
description: Managed native sing-box lifecycle bindings for MeshPort clients.
version: 0.1.0
publish_to: none
environment:
sdk: ^3.11.0
dependencies:
ffi: ^2.1.4