checkpoint

This commit is contained in:
John Smith 2022-09-06 18:59:41 -04:00
parent ca6c616d66
commit a12d8da6d1
9 changed files with 103 additions and 10 deletions

View File

@ -332,9 +332,16 @@ change_log_level - change the log level for a tracing layer
} }
pub fn update_log(&mut self, log: veilid_core::VeilidStateLog) { pub fn update_log(&mut self, log: veilid_core::VeilidStateLog) {
self.inner() self.inner().ui.add_node_event(format!(
.ui "{}: {}{}",
.add_node_event(format!("{}: {}", log.log_level, log.message)); log.log_level,
log.message,
if let Some(bt) = log.backtrace {
format!("\nBacktrace:\n{}", bt);
} else {
"".to_owned()
}
));
} }
pub fn update_shutdown(&mut self) { pub fn update_shutdown(&mut self) {

View File

@ -96,6 +96,12 @@ impl<S: Subscriber + for<'a> registry::LookupSpan<'a>> Layer<S> for ApiTracingLa
let message = format!("{} {}", origin, recorder); let message = format!("{} {}", origin, recorder);
let backtrace = if log_level <= VeilidLogLevel::Error {
Some(std::backtrace::Backtrace)
} else {
None
};
(inner.update_callback)(VeilidUpdate::Log(VeilidStateLog { log_level, message })) (inner.update_callback)(VeilidUpdate::Log(VeilidStateLog { log_level, message }))
} }
} }

View File

@ -219,6 +219,7 @@ impl fmt::Display for VeilidLogLevel {
pub struct VeilidStateLog { pub struct VeilidStateLog {
pub log_level: VeilidLogLevel, pub log_level: VeilidLogLevel,
pub message: String, pub message: String,
pub backtrace: Option<String>,
} }
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]

View File

@ -223,6 +223,7 @@ class _MyAppState extends State<MyApp> with UiLoggy {
_updateStream = updateStream; _updateStream = updateStream;
_updateProcessor = processUpdates(); _updateProcessor = processUpdates();
}); });
await Veilid.instance.attach();
}, },
child: const Text('Startup'), child: const Text('Startup'),
), ),

View File

@ -1234,7 +1234,8 @@ abstract class VeilidUpdate {
{ {
return VeilidUpdateLog( return VeilidUpdateLog(
logLevel: veilidLogLevelFromJson(json["log_level"]), logLevel: veilidLogLevelFromJson(json["log_level"]),
message: json["message"]); message: json["message"],
backtrace: json["backtrace"]);
} }
case "Attachment": case "Attachment":
{ {
@ -1258,10 +1259,12 @@ abstract class VeilidUpdate {
class VeilidUpdateLog implements VeilidUpdate { class VeilidUpdateLog implements VeilidUpdate {
final VeilidLogLevel logLevel; final VeilidLogLevel logLevel;
final String message; final String message;
final String? backtrace;
// //
VeilidUpdateLog({ VeilidUpdateLog({
required this.logLevel, required this.logLevel,
required this.message, required this.message,
required this.backtrace,
}); });
@override @override
@ -1270,6 +1273,7 @@ class VeilidUpdateLog implements VeilidUpdate {
'kind': "Log", 'kind': "Log",
'log_level': logLevel.json, 'log_level': logLevel.json,
'message': message, 'message': message,
'backtrace': backtrace
}; };
} }
} }
@ -1323,8 +1327,8 @@ class VeilidStateAttachment {
class VeilidStateNetwork { class VeilidStateNetwork {
final bool started; final bool started;
final int bpsDown; final BigInt bpsDown;
final int bpsUp; final BigInt bpsUp;
final List<PeerTableData> peers; final List<PeerTableData> peers;
VeilidStateNetwork( VeilidStateNetwork(
@ -1335,15 +1339,15 @@ class VeilidStateNetwork {
VeilidStateNetwork.fromJson(Map<String, dynamic> json) VeilidStateNetwork.fromJson(Map<String, dynamic> json)
: started = json['started'], : started = json['started'],
bpsDown = json['bps_down'], bpsDown = BigInt.parse(json['bps_down']),
bpsUp = json['bps_up'], bpsUp = BigInt.parse(json['bps_up']),
peers = json['peers'].map((j) => PeerTableData.fromJson(j)).toList(); peers = json['peers'].map((j) => PeerTableData.fromJson(j)).toList();
Map<String, dynamic> get json { Map<String, dynamic> get json {
return { return {
'started': started, 'started': started,
'bps_down': bpsDown, 'bps_down': bpsDown.toString(),
'bps_up': bpsUp, 'bps_up': bpsUp.toString(),
'peers': peers.map((p) => p.json).toList(), 'peers': peers.map((p) => p.json).toList(),
}; };
} }
@ -1563,6 +1567,8 @@ abstract class Veilid {
void changeLogLevel(String layer, VeilidConfigLogLevel logLevel); void changeLogLevel(String layer, VeilidConfigLogLevel logLevel);
Stream<VeilidUpdate> startupVeilidCore(VeilidConfig config); Stream<VeilidUpdate> startupVeilidCore(VeilidConfig config);
Future<VeilidState> getVeilidState(); Future<VeilidState> getVeilidState();
Future<void> attach();
Future<void> detach();
Future<void> shutdownVeilidCore(); Future<void> shutdownVeilidCore();
Future<String> debug(String command); Future<String> debug(String command);
String veilidVersionString(); String veilidVersionString();

View File

@ -41,6 +41,12 @@ typedef _StartupVeilidCoreDart = void Function(int, Pointer<Utf8>);
// fn get_veilid_state(port: i64) // fn get_veilid_state(port: i64)
typedef _GetVeilidStateC = Void Function(Int64); typedef _GetVeilidStateC = Void Function(Int64);
typedef _GetVeilidStateDart = void Function(int); typedef _GetVeilidStateDart = void Function(int);
// fn attach(port: i64)
typedef _AttachC = Void Function(Int64);
typedef _AttachDart = void Function(int);
// fn detach(port: i64)
typedef _DetachC = Void Function(Int64);
typedef _DetachDart = void Function(int);
// fn debug(port: i64, log_level: FfiStr) // fn debug(port: i64, log_level: FfiStr)
typedef _DebugC = Void Function(Int64, Pointer<Utf8>); typedef _DebugC = Void Function(Int64, Pointer<Utf8>);
typedef _DebugDart = void Function(int, Pointer<Utf8>); typedef _DebugDart = void Function(int, Pointer<Utf8>);
@ -249,6 +255,8 @@ class VeilidFFI implements Veilid {
final _ChangeLogLevelDart _changeLogLevel; final _ChangeLogLevelDart _changeLogLevel;
final _StartupVeilidCoreDart _startupVeilidCore; final _StartupVeilidCoreDart _startupVeilidCore;
final _GetVeilidStateDart _getVeilidState; final _GetVeilidStateDart _getVeilidState;
final _AttachDart _attach;
final _DetachDart _detach;
final _ShutdownVeilidCoreDart _shutdownVeilidCore; final _ShutdownVeilidCoreDart _shutdownVeilidCore;
final _DebugDart _debug; final _DebugDart _debug;
final _VeilidVersionStringDart _veilidVersionString; final _VeilidVersionStringDart _veilidVersionString;
@ -269,6 +277,8 @@ class VeilidFFI implements Veilid {
_getVeilidState = _getVeilidState =
dylib.lookupFunction<_GetVeilidStateC, _GetVeilidStateDart>( dylib.lookupFunction<_GetVeilidStateC, _GetVeilidStateDart>(
'get_veilid_state'), 'get_veilid_state'),
_attach = dylib.lookupFunction<_AttachC, _AttachDart>('attach'),
_detach = dylib.lookupFunction<_DetachC, _DetachDart>('detach'),
_shutdownVeilidCore = _shutdownVeilidCore =
dylib.lookupFunction<_ShutdownVeilidCoreC, _ShutdownVeilidCoreDart>( dylib.lookupFunction<_ShutdownVeilidCoreC, _ShutdownVeilidCoreDart>(
'shutdown_veilid_core'), 'shutdown_veilid_core'),
@ -327,6 +337,22 @@ class VeilidFFI implements Veilid {
return processFutureJson(VeilidState.fromJson, recvPort.first); return processFutureJson(VeilidState.fromJson, recvPort.first);
} }
@override
Future<void> attach() async {
final recvPort = ReceivePort("attach");
final sendPort = recvPort.sendPort;
_attach(sendPort.nativePort);
return processFutureVoid(recvPort.first);
}
@override
Future<void> detach() async {
final recvPort = ReceivePort("detach");
final sendPort = recvPort.sendPort;
_detach(sendPort.nativePort);
return processFutureVoid(recvPort.first);
}
@override @override
Future<void> shutdownVeilidCore() async { Future<void> shutdownVeilidCore() async {
final recvPort = ReceivePort("shutdown_veilid_core"); final recvPort = ReceivePort("shutdown_veilid_core");

View File

@ -60,6 +60,16 @@ class VeilidJS implements Veilid {
js_util.callMethod(wasm, "get_veilid_state", [])))); js_util.callMethod(wasm, "get_veilid_state", []))));
} }
@override
Future<void> attach() async {
return _wrapApiPromise(js_util.callMethod(wasm, "attach", []));
}
@override
Future<void> detach() async {
return _wrapApiPromise(js_util.callMethod(wasm, "detach", []));
}
@override @override
Future<void> shutdownVeilidCore() { Future<void> shutdownVeilidCore() {
return _wrapApiPromise( return _wrapApiPromise(

View File

@ -302,6 +302,24 @@ pub extern "C" fn get_veilid_state(port: i64) {
}); });
} }
#[no_mangle]
pub extern "C" fn attach(port: i64) {
DartIsolateWrapper::new(port).spawn_result_json(async move {
let veilid_api = get_veilid_api().await?;
veilid_api.attach().await?;
APIRESULT_VOID
});
}
#[no_mangle]
pub extern "C" fn detach(port: i64) {
DartIsolateWrapper::new(port).spawn_result_json(async move {
let veilid_api = get_veilid_api().await?;
veilid_api.detach().await?;
APIRESULT_VOID
});
}
#[no_mangle] #[no_mangle]
#[instrument] #[instrument]
pub extern "C" fn shutdown_veilid_core(port: i64) { pub extern "C" fn shutdown_veilid_core(port: i64) {

View File

@ -232,6 +232,24 @@ pub fn get_veilid_state() -> Promise {
}) })
} }
#[wasm_bindgen()]
pub fn attach() -> Promise {
wrap_api_future(async move {
let veilid_api = get_veilid_api()?;
veilid_api.attach().await?;
APIRESULT_UNDEFINED
})
}
#[wasm_bindgen()]
pub fn detach() -> Promise {
wrap_api_future(async move {
let veilid_api = get_veilid_api()?;
veilid_api.detach().await?;
APIRESULT_UNDEFINED
})
}
#[wasm_bindgen()] #[wasm_bindgen()]
pub fn shutdown_veilid_core() -> Promise { pub fn shutdown_veilid_core() -> Promise {
wrap_api_future(async move { wrap_api_future(async move {