mirror of
https://gitlab.com/veilid/veilid.git
synced 2025-10-08 08:38:44 -04:00
more clippy
This commit is contained in:
parent
c7d4462e0e
commit
f596b3ce05
32 changed files with 839 additions and 853 deletions
|
@ -150,7 +150,7 @@ impl ClientApi {
|
|||
|
||||
// Process control messages for the server
|
||||
async fn process_control(self, args: Vec<String>) -> VeilidAPIResult<String> {
|
||||
if args.len() == 0 {
|
||||
if args.is_empty() {
|
||||
apibail_generic!("no control request specified");
|
||||
}
|
||||
if args[0] == "Shutdown" {
|
||||
|
@ -207,7 +207,7 @@ impl ClientApi {
|
|||
|
||||
// Avoid logging failed deserialization of large adversarial payloads from
|
||||
// http://127.0.0.1:5959 by using an initial colon to force a parse error.
|
||||
let sanitized_line = if line.len() > MAX_NON_JSON_LOGGING && !line.starts_with("{") {
|
||||
let sanitized_line = if line.len() > MAX_NON_JSON_LOGGING && !line.starts_with('{') {
|
||||
":skipped long input that's not a JSON object".to_string()
|
||||
} else {
|
||||
line.to_string()
|
||||
|
@ -265,7 +265,7 @@ impl ClientApi {
|
|||
linebuf.clear();
|
||||
|
||||
// Ignore newlines
|
||||
if line.len() == 0 {
|
||||
if line.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -289,7 +289,7 @@ impl ClientApi {
|
|||
mut writer: W,
|
||||
) -> VeilidAPIResult<Option<RequestLine>> {
|
||||
while let Ok(resp) = responses_rx.recv_async().await {
|
||||
if let Err(_) = writer.write_all(resp.as_bytes()).await {
|
||||
if (writer.write_all(resp.as_bytes()).await).is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -420,7 +420,7 @@ impl ClientApi {
|
|||
// Pass other updates to clients
|
||||
let inner = self.inner.lock();
|
||||
for ch in inner.update_channels.values() {
|
||||
if let Err(_) = ch.send(veilid_update.clone()) {
|
||||
if ch.send(veilid_update.clone()).is_err() {
|
||||
// eprintln!("failed to send update: {}", e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ use clap::{Args, Parser};
|
|||
use server::*;
|
||||
use settings::LogLevel;
|
||||
use std::collections::HashMap;
|
||||
use std::ffi::{OsStr, OsString};
|
||||
use std::ffi::OsString;
|
||||
use std::path::Path;
|
||||
use std::str::FromStr;
|
||||
use tools::*;
|
||||
|
@ -162,17 +162,11 @@ fn main() -> EyreResult<()> {
|
|||
}
|
||||
|
||||
// Attempt to load configuration
|
||||
let settings_path: Option<&OsStr> = if let Some(config_file) = &args.config_file {
|
||||
if Path::new(&config_file).exists() {
|
||||
Some(config_file)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let settings_path: Option<OsString> = args
|
||||
.config_file
|
||||
.filter(|config_file| Path::new(&config_file).exists());
|
||||
|
||||
let settings = Settings::new(settings_path).wrap_err("configuration is invalid")?;
|
||||
let settings = Settings::new(settings_path.as_deref()).wrap_err("configuration is invalid")?;
|
||||
|
||||
// write lock the settings
|
||||
let mut settingsrw = settings.write();
|
||||
|
@ -303,7 +297,7 @@ fn main() -> EyreResult<()> {
|
|||
|
||||
// --- Generate DHT Key ---
|
||||
if let Some(ckstr) = args.generate_key_pair {
|
||||
if ckstr == "" {
|
||||
if ckstr.is_empty() {
|
||||
let mut tks = veilid_core::TypedKeyGroup::new();
|
||||
let mut tss = veilid_core::TypedSecretGroup::new();
|
||||
for ck in veilid_core::VALID_CRYPTO_KINDS {
|
||||
|
@ -312,16 +306,12 @@ fn main() -> EyreResult<()> {
|
|||
tks.add(veilid_core::TypedKey::new(tkp.kind, tkp.value.key));
|
||||
tss.add(veilid_core::TypedSecret::new(tkp.kind, tkp.value.secret));
|
||||
}
|
||||
println!(
|
||||
"Public Keys:\n{}\nSecret Keys:\n{}\n",
|
||||
tks.to_string(),
|
||||
tss.to_string()
|
||||
);
|
||||
println!("Public Keys:\n{}\nSecret Keys:\n{}\n", tks, tss);
|
||||
} else {
|
||||
let ck: veilid_core::CryptoKind =
|
||||
veilid_core::FourCC::from_str(&ckstr).wrap_err("couldn't parse crypto kind")?;
|
||||
let tkp = veilid_core::Crypto::generate_keypair(ck).wrap_err("invalid crypto kind")?;
|
||||
println!("{}", tkp.to_string());
|
||||
println!("{}", tkp);
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
|
|
@ -48,7 +48,19 @@ pub async fn run_veilid_server_internal(
|
|||
) -> EyreResult<()> {
|
||||
trace!(?settings, ?server_mode);
|
||||
|
||||
let settingsr = settings.read();
|
||||
let (
|
||||
settings_auto_attach,
|
||||
settings_client_api_enabled,
|
||||
settings_client_api_listen_address_addrs,
|
||||
) = {
|
||||
let settingsr = settings.read();
|
||||
|
||||
(
|
||||
settingsr.auto_attach,
|
||||
settingsr.client_api.enabled,
|
||||
settingsr.client_api.listen_address.addrs.clone(),
|
||||
)
|
||||
};
|
||||
|
||||
// Create client api state change pipe
|
||||
let (sender, receiver): (
|
||||
|
@ -72,20 +84,19 @@ pub async fn run_veilid_server_internal(
|
|||
.wrap_err("VeilidCore startup failed")?;
|
||||
|
||||
// Start client api if one is requested
|
||||
let mut capi = if settingsr.client_api.enabled && matches!(server_mode, ServerMode::Normal) {
|
||||
let mut capi = if settings_client_api_enabled && matches!(server_mode, ServerMode::Normal) {
|
||||
let some_capi =
|
||||
client_api::ClientApi::new(veilid_api.clone(), veilid_logs.clone(), settings.clone());
|
||||
some_capi
|
||||
.clone()
|
||||
.run(settingsr.client_api.listen_address.addrs.clone());
|
||||
.run(settings_client_api_listen_address_addrs);
|
||||
Some(some_capi)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
// Drop rwlock on settings
|
||||
let auto_attach = settingsr.auto_attach || !matches!(server_mode, ServerMode::Normal);
|
||||
drop(settingsr);
|
||||
let auto_attach = settings_auto_attach || !matches!(server_mode, ServerMode::Normal);
|
||||
|
||||
// Process all updates
|
||||
let capi2 = capi.clone();
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#![allow(clippy::bool_assert_comparison)]
|
||||
|
||||
use clap::ValueEnum;
|
||||
use directories::*;
|
||||
|
||||
|
@ -714,62 +712,62 @@ impl Settings {
|
|||
}
|
||||
|
||||
// bump client api port
|
||||
(*settingsrw).client_api.listen_address.offset_port(idx)?;
|
||||
settingsrw.client_api.listen_address.offset_port(idx)?;
|
||||
|
||||
// bump protocol ports
|
||||
(*settingsrw)
|
||||
settingsrw
|
||||
.core
|
||||
.network
|
||||
.protocol
|
||||
.udp
|
||||
.listen_address
|
||||
.offset_port(idx)?;
|
||||
(*settingsrw)
|
||||
settingsrw
|
||||
.core
|
||||
.network
|
||||
.protocol
|
||||
.tcp
|
||||
.listen_address
|
||||
.offset_port(idx)?;
|
||||
(*settingsrw)
|
||||
settingsrw
|
||||
.core
|
||||
.network
|
||||
.protocol
|
||||
.ws
|
||||
.listen_address
|
||||
.offset_port(idx)?;
|
||||
if let Some(url) = &mut (*settingsrw).core.network.protocol.ws.url {
|
||||
if let Some(url) = &mut settingsrw.core.network.protocol.ws.url {
|
||||
url.offset_port(idx)?;
|
||||
}
|
||||
(*settingsrw)
|
||||
settingsrw
|
||||
.core
|
||||
.network
|
||||
.protocol
|
||||
.wss
|
||||
.listen_address
|
||||
.offset_port(idx)?;
|
||||
if let Some(url) = &mut (*settingsrw).core.network.protocol.wss.url {
|
||||
if let Some(url) = &mut settingsrw.core.network.protocol.wss.url {
|
||||
url.offset_port(idx)?;
|
||||
}
|
||||
// bump application ports
|
||||
(*settingsrw)
|
||||
settingsrw
|
||||
.core
|
||||
.network
|
||||
.application
|
||||
.http
|
||||
.listen_address
|
||||
.offset_port(idx)?;
|
||||
if let Some(url) = &mut (*settingsrw).core.network.application.http.url {
|
||||
if let Some(url) = &mut settingsrw.core.network.application.http.url {
|
||||
url.offset_port(idx)?;
|
||||
}
|
||||
(*settingsrw)
|
||||
settingsrw
|
||||
.core
|
||||
.network
|
||||
.application
|
||||
.https
|
||||
.listen_address
|
||||
.offset_port(idx)?;
|
||||
if let Some(url) = &mut (*settingsrw).core.network.application.https.url {
|
||||
if let Some(url) = &mut settingsrw.core.network.application.https.url {
|
||||
url.offset_port(idx)?;
|
||||
}
|
||||
Ok(())
|
||||
|
@ -1531,7 +1529,7 @@ mod tests {
|
|||
let settings = Settings::new(None).unwrap();
|
||||
|
||||
let s = settings.read();
|
||||
assert_eq!(s.daemon.enabled, false);
|
||||
assert!(!s.daemon.enabled);
|
||||
assert_eq!(s.daemon.pid_file, None);
|
||||
assert_eq!(s.daemon.chroot, None);
|
||||
assert_eq!(s.daemon.working_directory, None);
|
||||
|
@ -1539,51 +1537,51 @@ mod tests {
|
|||
assert_eq!(s.daemon.group, None);
|
||||
assert_eq!(s.daemon.stdout_file, None);
|
||||
assert_eq!(s.daemon.stderr_file, None);
|
||||
assert_eq!(s.client_api.enabled, true);
|
||||
assert!(s.client_api.enabled);
|
||||
assert_eq!(s.client_api.listen_address.name, "localhost:5959");
|
||||
assert_eq!(
|
||||
s.client_api.listen_address.addrs,
|
||||
listen_address_to_socket_addrs("localhost:5959").unwrap()
|
||||
);
|
||||
assert_eq!(s.auto_attach, true);
|
||||
assert_eq!(s.logging.system.enabled, false);
|
||||
assert!(s.auto_attach);
|
||||
assert!(!s.logging.system.enabled);
|
||||
assert_eq!(s.logging.system.level, LogLevel::Info);
|
||||
assert_eq!(s.logging.terminal.enabled, true);
|
||||
assert!(s.logging.terminal.enabled);
|
||||
assert_eq!(s.logging.terminal.level, LogLevel::Info);
|
||||
assert_eq!(s.logging.file.enabled, false);
|
||||
assert!(!s.logging.file.enabled);
|
||||
assert_eq!(s.logging.file.path, "");
|
||||
assert_eq!(s.logging.file.append, true);
|
||||
assert!(s.logging.file.append);
|
||||
assert_eq!(s.logging.file.level, LogLevel::Info);
|
||||
assert_eq!(s.logging.api.enabled, true);
|
||||
assert!(s.logging.api.enabled);
|
||||
assert_eq!(s.logging.api.level, LogLevel::Info);
|
||||
assert_eq!(s.logging.otlp.enabled, false);
|
||||
assert!(!s.logging.otlp.enabled);
|
||||
assert_eq!(s.logging.otlp.level, LogLevel::Trace);
|
||||
assert_eq!(
|
||||
s.logging.otlp.grpc_endpoint,
|
||||
NamedSocketAddrs::from_str("localhost:4317").unwrap()
|
||||
);
|
||||
assert_eq!(s.logging.console.enabled, false);
|
||||
assert!(!s.logging.console.enabled);
|
||||
assert_eq!(s.testing.subnode_index, 0);
|
||||
|
||||
assert_eq!(
|
||||
s.core.table_store.directory,
|
||||
Settings::get_default_table_store_path()
|
||||
);
|
||||
assert_eq!(s.core.table_store.delete, false);
|
||||
assert!(!s.core.table_store.delete);
|
||||
|
||||
assert_eq!(
|
||||
s.core.block_store.directory,
|
||||
Settings::get_default_block_store_path()
|
||||
);
|
||||
assert_eq!(s.core.block_store.delete, false);
|
||||
assert!(!s.core.block_store.delete);
|
||||
|
||||
assert_eq!(s.core.protected_store.allow_insecure_fallback, true);
|
||||
assert_eq!(s.core.protected_store.always_use_insecure_storage, true);
|
||||
assert!(s.core.protected_store.allow_insecure_fallback);
|
||||
assert!(s.core.protected_store.always_use_insecure_storage);
|
||||
assert_eq!(
|
||||
s.core.protected_store.directory,
|
||||
Settings::get_default_protected_store_directory()
|
||||
);
|
||||
assert_eq!(s.core.protected_store.delete, false);
|
||||
assert!(!s.core.protected_store.delete);
|
||||
assert_eq!(s.core.protected_store.device_encryption_key_password, "");
|
||||
assert_eq!(
|
||||
s.core.protected_store.new_device_encryption_key_password,
|
||||
|
@ -1633,8 +1631,8 @@ mod tests {
|
|||
2_000u32
|
||||
);
|
||||
//
|
||||
assert_eq!(s.core.network.upnp, true);
|
||||
assert_eq!(s.core.network.detect_address_changes, true);
|
||||
assert!(s.core.network.upnp);
|
||||
assert!(s.core.network.detect_address_changes);
|
||||
assert_eq!(s.core.network.restricted_nat_retries, 0u32);
|
||||
//
|
||||
assert_eq!(
|
||||
|
@ -1647,7 +1645,7 @@ mod tests {
|
|||
);
|
||||
assert_eq!(s.core.network.tls.connection_initial_timeout_ms, 2_000u32);
|
||||
//
|
||||
assert_eq!(s.core.network.application.https.enabled, false);
|
||||
assert!(!s.core.network.application.https.enabled);
|
||||
assert_eq!(s.core.network.application.https.listen_address.name, ":443");
|
||||
assert_eq!(
|
||||
s.core.network.application.https.listen_address.addrs,
|
||||
|
@ -1658,7 +1656,7 @@ mod tests {
|
|||
std::path::PathBuf::from("app")
|
||||
);
|
||||
assert_eq!(s.core.network.application.https.url, None);
|
||||
assert_eq!(s.core.network.application.http.enabled, false);
|
||||
assert!(!s.core.network.application.http.enabled);
|
||||
assert_eq!(s.core.network.application.http.listen_address.name, ":80");
|
||||
assert_eq!(
|
||||
s.core.network.application.http.listen_address.addrs,
|
||||
|
@ -1670,23 +1668,23 @@ mod tests {
|
|||
);
|
||||
assert_eq!(s.core.network.application.http.url, None);
|
||||
//
|
||||
assert_eq!(s.core.network.protocol.udp.enabled, true);
|
||||
assert!(s.core.network.protocol.udp.enabled);
|
||||
assert_eq!(s.core.network.protocol.udp.socket_pool_size, 0);
|
||||
assert_eq!(s.core.network.protocol.udp.listen_address.name, "");
|
||||
assert_eq!(s.core.network.protocol.udp.listen_address.addrs, vec![]);
|
||||
assert_eq!(s.core.network.protocol.udp.public_address, None);
|
||||
|
||||
//
|
||||
assert_eq!(s.core.network.protocol.tcp.connect, true);
|
||||
assert_eq!(s.core.network.protocol.tcp.listen, true);
|
||||
assert!(s.core.network.protocol.tcp.connect);
|
||||
assert!(s.core.network.protocol.tcp.listen);
|
||||
assert_eq!(s.core.network.protocol.tcp.max_connections, 32);
|
||||
assert_eq!(s.core.network.protocol.tcp.listen_address.name, "");
|
||||
assert_eq!(s.core.network.protocol.tcp.listen_address.addrs, vec![]);
|
||||
assert_eq!(s.core.network.protocol.tcp.public_address, None);
|
||||
|
||||
//
|
||||
assert_eq!(s.core.network.protocol.ws.connect, true);
|
||||
assert_eq!(s.core.network.protocol.ws.listen, true);
|
||||
assert!(s.core.network.protocol.ws.connect);
|
||||
assert!(s.core.network.protocol.ws.listen);
|
||||
assert_eq!(s.core.network.protocol.ws.max_connections, 32);
|
||||
assert_eq!(s.core.network.protocol.ws.listen_address.name, "");
|
||||
assert_eq!(s.core.network.protocol.ws.listen_address.addrs, vec![]);
|
||||
|
@ -1696,8 +1694,8 @@ mod tests {
|
|||
);
|
||||
assert_eq!(s.core.network.protocol.ws.url, None);
|
||||
//
|
||||
assert_eq!(s.core.network.protocol.wss.connect, true);
|
||||
assert_eq!(s.core.network.protocol.wss.listen, false);
|
||||
assert!(s.core.network.protocol.wss.connect);
|
||||
assert!(!s.core.network.protocol.wss.listen);
|
||||
assert_eq!(s.core.network.protocol.wss.max_connections, 32);
|
||||
assert_eq!(s.core.network.protocol.wss.listen_address.name, "");
|
||||
assert_eq!(s.core.network.protocol.wss.listen_address.addrs, vec![]);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use crate::*;
|
||||
use crate::server::*;
|
||||
use crate::settings::Settings;
|
||||
use crate::tools::*;
|
||||
use crate::veilid_logs::*;
|
||||
use crate::*;
|
||||
use futures_util::StreamExt;
|
||||
use signal_hook::consts::signal::*;
|
||||
use signal_hook_async_std::Signals;
|
||||
|
@ -84,7 +84,7 @@ pub fn run_daemon(settings: Settings, _args: CmdlineArgs) -> EyreResult<()> {
|
|||
|
||||
// Catch signals
|
||||
let signals =
|
||||
Signals::new(&[SIGHUP, SIGTERM, SIGINT, SIGQUIT]).wrap_err("failed to init signals")?;
|
||||
Signals::new([SIGHUP, SIGTERM, SIGINT, SIGQUIT]).wrap_err("failed to init signals")?;
|
||||
let handle = signals.handle();
|
||||
|
||||
let signals_task = spawn(handle_signals(signals));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue