fix clippy and globalref and android
This commit is contained in:
parent
f7f4d86cf1
commit
2cdfa59bb6
2
external/keyring-manager
vendored
2
external/keyring-manager
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 085982c42704f9097c78e5f9848f345fbf888485
|
Subproject commit f73c27e66e43763f0f63ca9e697e77419f157a52
|
@ -133,15 +133,14 @@ async fn main() -> Result<(), String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Get client address
|
// Get client address
|
||||||
let server_addrs;
|
let server_addrs = if let Some(address_arg) = matches.value_of("address") {
|
||||||
if let Some(address_arg) = matches.value_of("address") {
|
address_arg
|
||||||
server_addrs = address_arg
|
|
||||||
.to_socket_addrs()
|
.to_socket_addrs()
|
||||||
.map_err(|e| format!("Invalid server address '{}'", e))?
|
.map_err(|e| format!("Invalid server address '{}'", e))?
|
||||||
.collect()
|
.collect()
|
||||||
} else {
|
} else {
|
||||||
server_addrs = settings.address.addrs.clone();
|
settings.address.addrs.clone()
|
||||||
}
|
};
|
||||||
let server_addr = server_addrs.first().cloned();
|
let server_addr = server_addrs.first().cloned();
|
||||||
|
|
||||||
// Create command processor
|
// Create command processor
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
|
|
||||||
use directories::*;
|
use directories::*;
|
||||||
|
|
||||||
|
|
||||||
use serde_derive::*;
|
use serde_derive::*;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::net::{SocketAddr, ToSocketAddrs};
|
use std::net::{SocketAddr, ToSocketAddrs};
|
||||||
@ -116,9 +114,7 @@ impl<'de> serde::Deserialize<'de> for NamedSocketAddrs {
|
|||||||
D: serde::Deserializer<'de>,
|
D: serde::Deserializer<'de>,
|
||||||
{
|
{
|
||||||
let s = String::deserialize(deserializer)?;
|
let s = String::deserialize(deserializer)?;
|
||||||
let addr_iter = s
|
let addr_iter = s.to_socket_addrs().map_err(serde::de::Error::custom)?;
|
||||||
.to_socket_addrs()
|
|
||||||
.map_err(serde::de::Error::custom)?;
|
|
||||||
Ok(NamedSocketAddrs {
|
Ok(NamedSocketAddrs {
|
||||||
name: s,
|
name: s,
|
||||||
addrs: addr_iter.collect(),
|
addrs: addr_iter.collect(),
|
||||||
@ -206,13 +202,12 @@ pub struct Settings {
|
|||||||
impl Settings {
|
impl Settings {
|
||||||
pub fn get_default_config_path() -> PathBuf {
|
pub fn get_default_config_path() -> PathBuf {
|
||||||
// Get default configuration file location
|
// Get default configuration file location
|
||||||
let mut default_config_path;
|
let mut default_config_path =
|
||||||
|
if let Some(my_proj_dirs) = ProjectDirs::from("org", "Veilid", "Veilid") {
|
||||||
if let Some(my_proj_dirs) = ProjectDirs::from("org", "Veilid", "Veilid") {
|
PathBuf::from(my_proj_dirs.config_dir())
|
||||||
default_config_path = PathBuf::from(my_proj_dirs.config_dir());
|
} else {
|
||||||
} else {
|
PathBuf::from("./")
|
||||||
default_config_path = PathBuf::from("./");
|
};
|
||||||
}
|
|
||||||
default_config_path.push("veilid-client.conf");
|
default_config_path.push("veilid-client.conf");
|
||||||
|
|
||||||
default_config_path
|
default_config_path
|
||||||
@ -220,13 +215,12 @@ impl Settings {
|
|||||||
|
|
||||||
pub fn get_default_log_directory() -> PathBuf {
|
pub fn get_default_log_directory() -> PathBuf {
|
||||||
// Get default configuration file location
|
// Get default configuration file location
|
||||||
let mut default_log_directory;
|
let mut default_log_directory =
|
||||||
|
if let Some(my_proj_dirs) = ProjectDirs::from("org", "Veilid", "Veilid") {
|
||||||
if let Some(my_proj_dirs) = ProjectDirs::from("org", "Veilid", "Veilid") {
|
PathBuf::from(my_proj_dirs.config_dir())
|
||||||
default_log_directory = PathBuf::from(my_proj_dirs.config_dir());
|
} else {
|
||||||
} else {
|
PathBuf::from("./")
|
||||||
default_log_directory = PathBuf::from("./");
|
};
|
||||||
}
|
|
||||||
default_log_directory.push("logs/");
|
default_log_directory.push("logs/");
|
||||||
|
|
||||||
default_log_directory
|
default_log_directory
|
||||||
|
@ -557,14 +557,14 @@ impl UI {
|
|||||||
}
|
}
|
||||||
ConnectionState::Retrying(addr, _) => {
|
ConnectionState::Retrying(addr, _) => {
|
||||||
status.append_styled(
|
status.append_styled(
|
||||||
format!("Reconnecting to {} ", addr.to_string()),
|
format!("Reconnecting to {} ", addr),
|
||||||
ColorStyle::highlight_inactive(),
|
ColorStyle::highlight_inactive(),
|
||||||
);
|
);
|
||||||
status.append_styled("|", ColorStyle::highlight_inactive());
|
status.append_styled("|", ColorStyle::highlight_inactive());
|
||||||
}
|
}
|
||||||
ConnectionState::Connected(addr, _) => {
|
ConnectionState::Connected(addr, _) => {
|
||||||
status.append_styled(
|
status.append_styled(
|
||||||
format!("Connected to {} ", addr.to_string()),
|
format!("Connected to {} ", addr),
|
||||||
ColorStyle::highlight_inactive(),
|
ColorStyle::highlight_inactive(),
|
||||||
);
|
);
|
||||||
status.append_styled("|", ColorStyle::highlight_inactive());
|
status.append_styled("|", ColorStyle::highlight_inactive());
|
||||||
|
@ -19,6 +19,13 @@ pub struct AndroidGlobals {
|
|||||||
pub ctx: GlobalRef,
|
pub ctx: GlobalRef,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Drop for AndroidGlobals {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
// Ensure we're attached before dropping GlobalRef
|
||||||
|
self.vm.attach_current_thread_as_daemon().unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref ANDROID_GLOBALS: Arc<Mutex<Option<AndroidGlobals>>> = Arc::new(Mutex::new(None));
|
pub static ref ANDROID_GLOBALS: Arc<Mutex<Option<AndroidGlobals>>> = Arc::new(Mutex::new(None));
|
||||||
}
|
}
|
||||||
@ -76,7 +83,7 @@ pub fn veilid_core_setup_android<'a>(
|
|||||||
pub fn get_android_globals() -> (JavaVM, GlobalRef) {
|
pub fn get_android_globals() -> (JavaVM, GlobalRef) {
|
||||||
let globals_locked = ANDROID_GLOBALS.lock();
|
let globals_locked = ANDROID_GLOBALS.lock();
|
||||||
let globals = globals_locked.as_ref().unwrap();
|
let globals = globals_locked.as_ref().unwrap();
|
||||||
let env = globals.vm.attach_current_thread().unwrap();
|
let env = globals.vm.attach_current_thread_as_daemon().unwrap();
|
||||||
let vm = env.get_java_vm().unwrap();
|
let vm = env.get_java_vm().unwrap();
|
||||||
let ctx = globals.ctx.clone();
|
let ctx = globals.ctx.clone();
|
||||||
(vm, ctx)
|
(vm, ctx)
|
||||||
|
@ -1455,9 +1455,9 @@ impl RPCProcessor {
|
|||||||
match eventual_value.await {
|
match eventual_value.await {
|
||||||
ReceiptEvent::Returned => Ok(true),
|
ReceiptEvent::Returned => Ok(true),
|
||||||
ReceiptEvent::Expired => Ok(false),
|
ReceiptEvent::Expired => Ok(false),
|
||||||
ReceiptEvent::Cancelled => Err(rpc_error_internal(
|
ReceiptEvent::Cancelled => {
|
||||||
"receipt was dropped before expiration".to_owned(),
|
Err(rpc_error_internal("receipt was dropped before expiration"))
|
||||||
)),
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,13 +279,13 @@ async fn test_operations() {
|
|||||||
assert_eq!(d1, d2);
|
assert_eq!(d1, d2);
|
||||||
assert!(d1 <= d2);
|
assert!(d1 <= d2);
|
||||||
assert!(d1 >= d2);
|
assert!(d1 >= d2);
|
||||||
assert!(!(d1 < d2));
|
assert!(d1 >= d2);
|
||||||
assert!(!(d1 > d2));
|
assert!(d1 <= d2);
|
||||||
assert_eq!(d2, d1);
|
assert_eq!(d2, d1);
|
||||||
assert!(d2 <= d1);
|
assert!(d2 <= d1);
|
||||||
assert!(d2 >= d1);
|
assert!(d2 >= d1);
|
||||||
assert!(!(d2 < d1));
|
assert!(d2 >= d1);
|
||||||
assert!(!(d2 > d1));
|
assert!(d2 <= d1);
|
||||||
|
|
||||||
// Verify nibbles
|
// Verify nibbles
|
||||||
assert_eq!(d1.nibble(0), 0x9u8);
|
assert_eq!(d1.nibble(0), 0x9u8);
|
||||||
|
@ -83,21 +83,19 @@ cfg_if! {
|
|||||||
else {
|
else {
|
||||||
|
|
||||||
fn get_data_dir() -> PathBuf {
|
fn get_data_dir() -> PathBuf {
|
||||||
let out;
|
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(target_os = "android")] {
|
if #[cfg(target_os = "android")] {
|
||||||
out = PathBuf::from(intf::utils::android::get_files_dir());
|
PathBuf::from(intf::utils::android::get_files_dir())
|
||||||
} else {
|
} else {
|
||||||
use directories::*;
|
use directories::*;
|
||||||
|
|
||||||
if let Some(my_proj_dirs) = ProjectDirs::from("org", "Veilid", "VeilidCoreTests") {
|
if let Some(my_proj_dirs) = ProjectDirs::from("org", "Veilid", "VeilidCoreTests") {
|
||||||
out = PathBuf::from(my_proj_dirs.data_local_dir());
|
PathBuf::from(my_proj_dirs.data_local_dir())
|
||||||
} else {
|
} else {
|
||||||
out = PathBuf::from("./");
|
PathBuf::from("./")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_table_store_path() -> String {
|
pub fn get_table_store_path() -> String {
|
||||||
|
@ -295,8 +295,8 @@ impl Address {
|
|||||||
}
|
}
|
||||||
pub fn address_string_with_port(&self, port: u16) -> String {
|
pub fn address_string_with_port(&self, port: u16) -> String {
|
||||||
match self {
|
match self {
|
||||||
Address::IPV4(v4) => format!("{}:{}", v4.to_string(), port),
|
Address::IPV4(v4) => format!("{}:{}", v4, port),
|
||||||
Address::IPV6(v6) => format!("[{}]:{}", v6.to_string(), port),
|
Address::IPV6(v6) => format!("[{}]:{}", v6, port),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn is_global(&self) -> bool {
|
pub fn is_global(&self) -> bool {
|
||||||
|
@ -262,7 +262,7 @@ impl FromStr for SplitUrl {
|
|||||||
return Err("Invalid scheme specified".to_owned());
|
return Err("Invalid scheme specified".to_owned());
|
||||||
}
|
}
|
||||||
let userinfo = {
|
let userinfo = {
|
||||||
if let Some((userinfo_str, after)) = rest.split_once("@") {
|
if let Some((userinfo_str, after)) = rest.split_once('@') {
|
||||||
rest = after;
|
rest = after;
|
||||||
Some(url_decode(userinfo_str)?)
|
Some(url_decode(userinfo_str)?)
|
||||||
} else {
|
} else {
|
||||||
|
@ -67,43 +67,40 @@ pub async fn run_veilid_server(settings: Settings, logs: VeilidLogs) -> Result<(
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
// Handle log messages on main thread for capnproto rpc
|
// Handle log messages on main thread for capnproto rpc
|
||||||
let client_log_receiver_jh = capi
|
let client_log_receiver_jh = capi.clone().and_then(|capi| {
|
||||||
.clone()
|
logs.client_log_channel
|
||||||
.map(|capi| {
|
.clone()
|
||||||
logs.client_log_channel
|
.map(|mut client_log_channel| {
|
||||||
.clone()
|
async_std::task::spawn_local(async move {
|
||||||
.map(|mut client_log_channel| {
|
// Batch messages to either 16384 chars at once or every second to minimize packets
|
||||||
async_std::task::spawn_local(async move {
|
let rate = Duration::from_secs(1);
|
||||||
// Batch messages to either 16384 chars at once or every second to minimize packets
|
let mut start = Instant::now();
|
||||||
let rate = Duration::from_secs(1);
|
let mut messages = String::new();
|
||||||
let mut start = Instant::now();
|
loop {
|
||||||
let mut messages = String::new();
|
let timeout_dur =
|
||||||
loop {
|
rate.checked_sub(start.elapsed()).unwrap_or(Duration::ZERO);
|
||||||
let timeout_dur =
|
match async_std::future::timeout(timeout_dur, client_log_channel.recv())
|
||||||
rate.checked_sub(start.elapsed()).unwrap_or(Duration::ZERO);
|
.await
|
||||||
match async_std::future::timeout(timeout_dur, client_log_channel.recv())
|
{
|
||||||
.await
|
Ok(Ok(message)) => {
|
||||||
{
|
messages += &message;
|
||||||
Ok(Ok(message)) => {
|
if messages.len() > 16384 {
|
||||||
messages += &message;
|
|
||||||
if messages.len() > 16384 {
|
|
||||||
capi.clone()
|
|
||||||
.handle_client_log(core::mem::take(&mut messages));
|
|
||||||
start = Instant::now();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(Err(_)) => break,
|
|
||||||
Err(_) => {
|
|
||||||
capi.clone()
|
capi.clone()
|
||||||
.handle_client_log(core::mem::take(&mut messages));
|
.handle_client_log(core::mem::take(&mut messages));
|
||||||
start = Instant::now();
|
start = Instant::now();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Ok(Err(_)) => break,
|
||||||
|
Err(_) => {
|
||||||
|
capi.clone()
|
||||||
|
.handle_client_log(core::mem::take(&mut messages));
|
||||||
|
start = Instant::now();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.flatten();
|
});
|
||||||
|
|
||||||
// Auto-attach if desired
|
// Auto-attach if desired
|
||||||
if auto_attach {
|
if auto_attach {
|
||||||
|
@ -363,7 +363,7 @@ impl NamedSocketAddrs {
|
|||||||
let portstr = &self.name[split + 1..];
|
let portstr = &self.name[split + 1..];
|
||||||
let port: u16 = portstr.parse::<u16>().map_err(drop)? + offset;
|
let port: u16 = portstr.parse::<u16>().map_err(drop)? + offset;
|
||||||
|
|
||||||
self.name = format!("{}:{}", hoststr, port.to_string());
|
self.name = format!("{}:{}", hoststr, port);
|
||||||
} else {
|
} else {
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
@ -684,13 +684,12 @@ impl Settings {
|
|||||||
|
|
||||||
pub fn get_default_config_path() -> PathBuf {
|
pub fn get_default_config_path() -> PathBuf {
|
||||||
// Get default configuration file location
|
// Get default configuration file location
|
||||||
let mut default_config_path;
|
let mut default_config_path =
|
||||||
|
if let Some(my_proj_dirs) = ProjectDirs::from("org", "Veilid", "Veilid") {
|
||||||
if let Some(my_proj_dirs) = ProjectDirs::from("org", "Veilid", "Veilid") {
|
PathBuf::from(my_proj_dirs.config_dir())
|
||||||
default_config_path = PathBuf::from(my_proj_dirs.config_dir());
|
} else {
|
||||||
} else {
|
PathBuf::from("./")
|
||||||
default_config_path = PathBuf::from("./");
|
};
|
||||||
}
|
|
||||||
default_config_path.push("veilid-server.conf");
|
default_config_path.push("veilid-server.conf");
|
||||||
|
|
||||||
default_config_path
|
default_config_path
|
||||||
@ -698,13 +697,12 @@ impl Settings {
|
|||||||
|
|
||||||
pub fn get_default_table_store_path() -> PathBuf {
|
pub fn get_default_table_store_path() -> PathBuf {
|
||||||
// Get default configuration file location
|
// Get default configuration file location
|
||||||
let mut default_config_path;
|
let mut default_config_path =
|
||||||
|
if let Some(my_proj_dirs) = ProjectDirs::from("org", "Veilid", "Veilid") {
|
||||||
if let Some(my_proj_dirs) = ProjectDirs::from("org", "Veilid", "Veilid") {
|
PathBuf::from(my_proj_dirs.data_local_dir())
|
||||||
default_config_path = PathBuf::from(my_proj_dirs.data_local_dir());
|
} else {
|
||||||
} else {
|
PathBuf::from("./")
|
||||||
default_config_path = PathBuf::from("./");
|
};
|
||||||
}
|
|
||||||
default_config_path.push("table_store");
|
default_config_path.push("table_store");
|
||||||
|
|
||||||
default_config_path
|
default_config_path
|
||||||
@ -712,13 +710,12 @@ impl Settings {
|
|||||||
|
|
||||||
pub fn get_default_block_store_path() -> PathBuf {
|
pub fn get_default_block_store_path() -> PathBuf {
|
||||||
// Get default configuration file location
|
// Get default configuration file location
|
||||||
let mut default_config_path;
|
let mut default_config_path =
|
||||||
|
if let Some(my_proj_dirs) = ProjectDirs::from("org", "Veilid", "Veilid") {
|
||||||
if let Some(my_proj_dirs) = ProjectDirs::from("org", "Veilid", "Veilid") {
|
PathBuf::from(my_proj_dirs.data_local_dir())
|
||||||
default_config_path = PathBuf::from(my_proj_dirs.data_local_dir());
|
} else {
|
||||||
} else {
|
PathBuf::from("./")
|
||||||
default_config_path = PathBuf::from("./");
|
};
|
||||||
}
|
|
||||||
default_config_path.push("block_store");
|
default_config_path.push("block_store");
|
||||||
|
|
||||||
default_config_path
|
default_config_path
|
||||||
@ -726,13 +723,12 @@ impl Settings {
|
|||||||
|
|
||||||
pub fn get_default_protected_store_insecure_fallback_directory() -> PathBuf {
|
pub fn get_default_protected_store_insecure_fallback_directory() -> PathBuf {
|
||||||
// Get default configuration file location
|
// Get default configuration file location
|
||||||
let mut default_config_path;
|
let mut default_config_path =
|
||||||
|
if let Some(my_proj_dirs) = ProjectDirs::from("org", "Veilid", "Veilid") {
|
||||||
if let Some(my_proj_dirs) = ProjectDirs::from("org", "Veilid", "Veilid") {
|
PathBuf::from(my_proj_dirs.data_local_dir())
|
||||||
default_config_path = PathBuf::from(my_proj_dirs.data_local_dir());
|
} else {
|
||||||
} else {
|
PathBuf::from("./")
|
||||||
default_config_path = PathBuf::from("./");
|
};
|
||||||
}
|
|
||||||
default_config_path.push("protected_store");
|
default_config_path.push("protected_store");
|
||||||
|
|
||||||
default_config_path
|
default_config_path
|
||||||
|
@ -33,21 +33,20 @@ impl VeilidLogs {
|
|||||||
if settingsr.logging.file.enabled {
|
if settingsr.logging.file.enabled {
|
||||||
let log_path = Path::new(&settingsr.logging.file.path);
|
let log_path = Path::new(&settingsr.logging.file.path);
|
||||||
|
|
||||||
let logfile;
|
let logfile = if settingsr.logging.file.append {
|
||||||
if settingsr.logging.file.append {
|
OpenOptions::new()
|
||||||
logfile = OpenOptions::new()
|
|
||||||
.create(true)
|
.create(true)
|
||||||
.append(true)
|
.append(true)
|
||||||
.open(log_path)
|
.open(log_path)
|
||||||
.map_err(|e| format!("failed to open log file: {}", e))?
|
.map_err(|e| format!("failed to open log file: {}", e))?
|
||||||
} else {
|
} else {
|
||||||
logfile = OpenOptions::new()
|
OpenOptions::new()
|
||||||
.create(true)
|
.create(true)
|
||||||
.truncate(true)
|
.truncate(true)
|
||||||
.write(true)
|
.write(true)
|
||||||
.open(log_path)
|
.open(log_path)
|
||||||
.map_err(|e| format!("failed to open log file: {}", e))?
|
.map_err(|e| format!("failed to open log file: {}", e))?
|
||||||
}
|
};
|
||||||
logs.push(WriteLogger::new(
|
logs.push(WriteLogger::new(
|
||||||
convert_loglevel(settingsr.logging.file.level),
|
convert_loglevel(settingsr.logging.file.level),
|
||||||
cb.build(),
|
cb.build(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user