checkpoint before android work
This commit is contained in:
parent
2a9522cc24
commit
82f680b35f
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -4295,6 +4295,7 @@ dependencies = [
|
|||||||
"daemonize",
|
"daemonize",
|
||||||
"directories",
|
"directories",
|
||||||
"failure",
|
"failure",
|
||||||
|
"flume",
|
||||||
"futures",
|
"futures",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"log",
|
"log",
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
use veilid_core::xx::*;
|
use veilid_core::xx::*;
|
||||||
|
|
||||||
use async_std::prelude::*;
|
use async_std::prelude::*;
|
||||||
use clap::{App, Arg, ColorChoice};
|
use clap::{Arg, ColorChoice, Command};
|
||||||
use flexi_logger::*;
|
use flexi_logger::*;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::net::ToSocketAddrs;
|
use std::net::ToSocketAddrs;
|
||||||
@ -20,7 +20,7 @@ pub mod veilid_client_capnp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_command_line(default_config_path: &OsStr) -> Result<clap::ArgMatches, String> {
|
fn parse_command_line(default_config_path: &OsStr) -> Result<clap::ArgMatches, String> {
|
||||||
let matches = App::new("veilid-cli")
|
let matches = Command::new("veilid-cli")
|
||||||
.version("0.1")
|
.version("0.1")
|
||||||
.color(ColorChoice::Auto)
|
.color(ColorChoice::Auto)
|
||||||
.about("Veilid Console Client")
|
.about("Veilid Console Client")
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
use crate::core_context::*;
|
use crate::core_context::*;
|
||||||
use crate::intf::*;
|
|
||||||
use crate::veilid_api::*;
|
use crate::veilid_api::*;
|
||||||
use crate::xx::*;
|
use crate::xx::*;
|
||||||
use log::{set_boxed_logger, set_max_level, Level, LevelFilter, Log, Metadata, Record};
|
use log::{set_boxed_logger, set_max_level, Level, LevelFilter, Log, Metadata, Record};
|
||||||
@ -8,8 +7,7 @@ use once_cell::sync::OnceCell;
|
|||||||
struct ApiLoggerInner {
|
struct ApiLoggerInner {
|
||||||
level: LevelFilter,
|
level: LevelFilter,
|
||||||
filter_ignore: Cow<'static, [Cow<'static, str>]>,
|
filter_ignore: Cow<'static, [Cow<'static, str>]>,
|
||||||
join_handle: Option<JoinHandle<()>>,
|
update_callback: UpdateCallback,
|
||||||
tx: Option<flume::Sender<(VeilidLogLevel, String)>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -21,21 +19,10 @@ static API_LOGGER: OnceCell<ApiLogger> = OnceCell::new();
|
|||||||
|
|
||||||
impl ApiLogger {
|
impl ApiLogger {
|
||||||
fn new_inner(level: LevelFilter, update_callback: UpdateCallback) -> ApiLoggerInner {
|
fn new_inner(level: LevelFilter, update_callback: UpdateCallback) -> ApiLoggerInner {
|
||||||
let (tx, rx) = flume::unbounded::<(VeilidLogLevel, String)>();
|
|
||||||
let join_handle: Option<JoinHandle<()>> = Some(spawn(async move {
|
|
||||||
while let Ok(v) = rx.recv_async().await {
|
|
||||||
(update_callback)(VeilidUpdate::Log {
|
|
||||||
log_level: v.0,
|
|
||||||
message: v.1,
|
|
||||||
})
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
ApiLoggerInner {
|
ApiLoggerInner {
|
||||||
level,
|
level,
|
||||||
filter_ignore: Default::default(),
|
filter_ignore: Default::default(),
|
||||||
join_handle,
|
update_callback,
|
||||||
tx: Some(tx),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,20 +41,8 @@ impl ApiLogger {
|
|||||||
|
|
||||||
pub async fn terminate() {
|
pub async fn terminate() {
|
||||||
if let Some(api_logger) = API_LOGGER.get() {
|
if let Some(api_logger) = API_LOGGER.get() {
|
||||||
let mut join_handle = None;
|
let mut inner = api_logger.inner.lock();
|
||||||
{
|
*inner = None;
|
||||||
let mut inner = api_logger.inner.lock();
|
|
||||||
|
|
||||||
// Terminate channel
|
|
||||||
if let Some(inner) = (*inner).as_mut() {
|
|
||||||
inner.tx = None;
|
|
||||||
join_handle = inner.join_handle.take();
|
|
||||||
}
|
|
||||||
*inner = None;
|
|
||||||
}
|
|
||||||
if let Some(jh) = join_handle {
|
|
||||||
jh.await;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear everything and we're done
|
// Clear everything and we're done
|
||||||
set_max_level(LevelFilter::Off);
|
set_max_level(LevelFilter::Off);
|
||||||
@ -139,9 +114,10 @@ impl Log for ApiLogger {
|
|||||||
|
|
||||||
let s = format!("{}{}{}", tgt, loc, record.args());
|
let s = format!("{}{}{}", tgt, loc, record.args());
|
||||||
|
|
||||||
if let Some(tx) = &inner.tx {
|
(inner.update_callback)(VeilidUpdate::Log {
|
||||||
let _ = tx.try_send((ll, s));
|
log_level: ll,
|
||||||
}
|
message: s,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,12 @@ pub use rust_fsm::*;
|
|||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(target_arch = "wasm32")] {
|
if #[cfg(target_arch = "wasm32")] {
|
||||||
pub type StateChangeCallback<T> = Arc<
|
pub type StateChangeCallback<T> = Arc<
|
||||||
dyn Fn(<T as StateMachineImpl>::State, <T as StateMachineImpl>::State) -> SystemPinBoxFuture<()>
|
dyn Fn(<T as StateMachineImpl>::State, <T as StateMachineImpl>::State)
|
||||||
+ 'static,
|
+ 'static,
|
||||||
>;
|
>;
|
||||||
} else {
|
} else {
|
||||||
pub type StateChangeCallback<T> = Arc<
|
pub type StateChangeCallback<T> = Arc<
|
||||||
dyn Fn(<T as StateMachineImpl>::State, <T as StateMachineImpl>::State) -> SystemPinBoxFuture<()>
|
dyn Fn(<T as StateMachineImpl>::State, <T as StateMachineImpl>::State)
|
||||||
+ Send
|
+ Send
|
||||||
+ Sync
|
+ Sync
|
||||||
+ 'static,
|
+ 'static,
|
||||||
@ -88,7 +88,7 @@ where
|
|||||||
(inner.callback.clone(), eventual)
|
(inner.callback.clone(), eventual)
|
||||||
};
|
};
|
||||||
if let Some(cb) = callback {
|
if let Some(cb) = callback {
|
||||||
cb(old_state, new_state).await;
|
cb(old_state, new_state);
|
||||||
}
|
}
|
||||||
eventual.resolve(new_state).await;
|
eventual.resolve(new_state).await;
|
||||||
Ok(output)
|
Ok(output)
|
||||||
|
@ -8,9 +8,9 @@ use crate::xx::*;
|
|||||||
|
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(target_arch = "wasm32")] {
|
if #[cfg(target_arch = "wasm32")] {
|
||||||
pub type UpdateCallback = Arc<dyn Fn(VeilidUpdate) -> SystemPinBoxFuture<()>>;
|
pub type UpdateCallback = Arc<dyn Fn(VeilidUpdate)>;
|
||||||
} else {
|
} else {
|
||||||
pub type UpdateCallback = Arc<dyn Fn(VeilidUpdate) -> SystemPinBoxFuture<()> + Send + Sync>;
|
pub type UpdateCallback = Arc<dyn Fn(VeilidUpdate) + Send + Sync>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ impl ServicesContext {
|
|||||||
info!("Veilid API logging initialized");
|
info!("Veilid API logging initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
trace!("startup starting");
|
info!("Veilid API starting up");
|
||||||
|
|
||||||
// Set up protected store
|
// Set up protected store
|
||||||
trace!("init protected store");
|
trace!("init protected store");
|
||||||
@ -134,12 +134,12 @@ impl ServicesContext {
|
|||||||
}
|
}
|
||||||
self.attachment_manager = Some(attachment_manager);
|
self.attachment_manager = Some(attachment_manager);
|
||||||
|
|
||||||
trace!("startup complete");
|
info!("Veilid API startup complete");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn shutdown(&mut self) {
|
pub async fn shutdown(&mut self) {
|
||||||
trace!("shutdown starting");
|
info!("Veilid API shutting down");
|
||||||
|
|
||||||
if let Some(attachment_manager) = &mut self.attachment_manager {
|
if let Some(attachment_manager) = &mut self.attachment_manager {
|
||||||
trace!("terminate attachment manager");
|
trace!("terminate attachment manager");
|
||||||
@ -162,13 +162,13 @@ impl ServicesContext {
|
|||||||
protected_store.terminate().await;
|
protected_store.terminate().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
trace!("shutdown complete");
|
info!("Veilid API shutdown complete");
|
||||||
|
|
||||||
// api logger terminate is idempotent
|
// api logger terminate is idempotent
|
||||||
ApiLogger::terminate().await;
|
ApiLogger::terminate().await;
|
||||||
|
|
||||||
// send final shutdown update
|
// send final shutdown update
|
||||||
(self.update_callback)(VeilidUpdate::Shutdown).await;
|
(self.update_callback)(VeilidUpdate::Shutdown);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,7 +221,6 @@ impl VeilidCoreContext {
|
|||||||
if #[cfg(target_os = "android")] {
|
if #[cfg(target_os = "android")] {
|
||||||
if utils::android::ANDROID_GLOBALS.lock().is_none() {
|
if utils::android::ANDROID_GLOBALS.lock().is_none() {
|
||||||
error!("Android globals are not set up");
|
error!("Android globals are not set up");
|
||||||
config.terminate().await;
|
|
||||||
return Err(VeilidAPIError::Internal { message: "Android globals are not set up".to_owned() });
|
return Err(VeilidAPIError::Internal { message: "Android globals are not set up".to_owned() });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,13 +160,9 @@ cfg_if! {
|
|||||||
|
|
||||||
pub fn setup_veilid_core() -> (UpdateCallback, ConfigCallback) {
|
pub fn setup_veilid_core() -> (UpdateCallback, ConfigCallback) {
|
||||||
(
|
(
|
||||||
Arc::new(
|
Arc::new(move |veilid_update: VeilidUpdate| {
|
||||||
move |veilid_update: VeilidUpdate| -> SystemPinBoxFuture<()> {
|
println!("update_callback: {:?}", veilid_update);
|
||||||
Box::pin(async move {
|
}),
|
||||||
trace!("update_callback: {:?}", veilid_update);
|
|
||||||
})
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Arc::new(config_callback),
|
Arc::new(config_callback),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -74,6 +74,7 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
implementation 'androidx.security:security-crypto:1.1.0-alpha03'
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.veilid.veilid">
|
package="com.veilid.veilid">
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@ -64,5 +64,6 @@ flutter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
implementation 'androidx.security:security-crypto:1.1.0-alpha03'
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ Future<VeilidConfig> getDefaultVeilidConfig() async {
|
|||||||
return VeilidConfig(
|
return VeilidConfig(
|
||||||
programName: "Veilid Plugin Test",
|
programName: "Veilid Plugin Test",
|
||||||
namespace: "",
|
namespace: "",
|
||||||
apiLogLevel: VeilidConfigLogLevel.trace,
|
apiLogLevel: VeilidConfigLogLevel.info,
|
||||||
capabilities: VeilidConfigCapabilities(
|
capabilities: VeilidConfigCapabilities(
|
||||||
protocolUDP: !kIsWeb,
|
protocolUDP: !kIsWeb,
|
||||||
protocolConnectTCP: !kIsWeb,
|
protocolConnectTCP: !kIsWeb,
|
||||||
|
@ -42,9 +42,9 @@ void setRootLogLevel(LogLevel? level) {
|
|||||||
|
|
||||||
void initLoggy() {
|
void initLoggy() {
|
||||||
Loggy.initLoggy(
|
Loggy.initLoggy(
|
||||||
logPrinter: ConsolePrinter(
|
logPrinter: StreamPrinter(ConsolePrinter(
|
||||||
const PrettyDeveloperPrinter(),
|
const PrettyDeveloperPrinter(),
|
||||||
),
|
)),
|
||||||
logOptions: getLogOptions(null),
|
logOptions: getLogOptions(null),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -90,14 +90,16 @@ class _MyAppState extends State<MyApp> with UiLoggy {
|
|||||||
// We also handle the message potentially returning null.
|
// We also handle the message potentially returning null.
|
||||||
try {
|
try {
|
||||||
veilidVersion = Veilid.instance.veilidVersionString();
|
veilidVersion = Veilid.instance.veilidVersionString();
|
||||||
} on PlatformException {
|
} on Exception {
|
||||||
veilidVersion = 'Failed to get veilid version.';
|
veilidVersion = 'Failed to get veilid version.';
|
||||||
}
|
}
|
||||||
loggy.error("Error test");
|
|
||||||
loggy.warning("Warning test");
|
// In case of hot restart shut down first
|
||||||
loggy.info("Info test");
|
try {
|
||||||
loggy.debug("Debug test");
|
await Veilid.instance.shutdownVeilidCore();
|
||||||
loggy.trace("Trace test");
|
} on Exception {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
// If the widget was removed from the tree while the asynchronous platform
|
// If the widget was removed from the tree while the asynchronous platform
|
||||||
// message was in flight, we want to discard the reply rather than calling
|
// message was in flight, we want to discard the reply rather than calling
|
||||||
|
@ -115,21 +115,17 @@ pub extern "C" fn startup_veilid_core(port: i64, config: FfiStr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let sink = stream.clone();
|
let sink = stream.clone();
|
||||||
let update_callback = Arc::new(
|
let update_callback = Arc::new(move |update: veilid_core::VeilidUpdate| {
|
||||||
move |update: veilid_core::VeilidUpdate| -> veilid_core::SystemPinBoxFuture<()> {
|
let sink = sink.clone();
|
||||||
let sink = sink.clone();
|
match update {
|
||||||
Box::pin(async move {
|
veilid_core::VeilidUpdate::Shutdown => {
|
||||||
match update {
|
sink.close();
|
||||||
veilid_core::VeilidUpdate::Shutdown => {
|
}
|
||||||
sink.close();
|
_ => {
|
||||||
}
|
sink.item_json(update);
|
||||||
_ => {
|
}
|
||||||
sink.item_json(update);
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
let res = veilid_core::api_startup_json(update_callback, config_json).await;
|
let res = veilid_core::api_startup_json(update_callback, config_json).await;
|
||||||
let veilid_api = check_err_json!(stream, res);
|
let veilid_api = check_err_json!(stream, res);
|
||||||
|
@ -32,6 +32,7 @@ url = "^2"
|
|||||||
ctrlc = "^3"
|
ctrlc = "^3"
|
||||||
lazy_static = "^1"
|
lazy_static = "^1"
|
||||||
bugsalot = "^0"
|
bugsalot = "^0"
|
||||||
|
flume = { version = "^0", features = ["async"] }
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
windows-service = "^0"
|
windows-service = "^0"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::client_api;
|
use crate::client_api;
|
||||||
use crate::settings::*;
|
use crate::settings::*;
|
||||||
use crate::veilid_logs::*;
|
use crate::veilid_logs::*;
|
||||||
use async_std::channel::{bounded, Receiver, Sender};
|
use flume::{bounded, Receiver, Sender};
|
||||||
use lazy_static::*;
|
use lazy_static::*;
|
||||||
use log::*;
|
use log::*;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
@ -31,16 +31,11 @@ pub async fn run_veilid_server(settings: Settings, logs: VeilidLogs) -> Result<(
|
|||||||
) = bounded(1);
|
) = bounded(1);
|
||||||
|
|
||||||
// Create VeilidCore setup
|
// Create VeilidCore setup
|
||||||
let update_callback = Arc::new(
|
let update_callback = Arc::new(move |change: veilid_core::VeilidUpdate| {
|
||||||
move |change: veilid_core::VeilidUpdate| -> veilid_core::SystemPinBoxFuture<()> {
|
if sender.send(change).is_err() {
|
||||||
let sender = sender.clone();
|
error!("error sending veilid update callback");
|
||||||
Box::pin(async move {
|
}
|
||||||
if sender.send(change).await.is_err() {
|
});
|
||||||
error!("error sending veilid update callback");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
);
|
|
||||||
let config_callback = settings.get_core_config_callback();
|
let config_callback = settings.get_core_config_callback();
|
||||||
|
|
||||||
// Start Veilid Core and get API
|
// Start Veilid Core and get API
|
||||||
@ -66,7 +61,7 @@ pub async fn run_veilid_server(settings: Settings, logs: VeilidLogs) -> Result<(
|
|||||||
// Handle state changes on main thread for capnproto rpc
|
// Handle state changes on main thread for capnproto rpc
|
||||||
let update_receiver_jh = capi.clone().map(|capi| {
|
let update_receiver_jh = capi.clone().map(|capi| {
|
||||||
async_std::task::spawn_local(async move {
|
async_std::task::spawn_local(async move {
|
||||||
while let Ok(change) = receiver.recv().await {
|
while let Ok(change) = receiver.recv_async().await {
|
||||||
capi.clone().handle_update(change);
|
capi.clone().handle_update(change);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user