From 3125c19f02aaf550702bd032d84b2b0dcb0735ba Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Sun, 27 Aug 2023 16:39:50 -0500 Subject: [PATCH] doc work --- build_docs.sh | 3 ++ veilid-core/Cargo.toml | 7 ++- veilid-core/src/intf/native/system.rs | 1 + .../src/network_manager/native/network_tcp.rs | 24 +++++++++ veilid-server/src/main.rs | 42 ++++++++------- veilid-tools/Cargo.toml | 54 +++++++++++++------ 6 files changed, 94 insertions(+), 37 deletions(-) create mode 100755 build_docs.sh diff --git a/build_docs.sh b/build_docs.sh new file mode 100755 index 00000000..48a42467 --- /dev/null +++ b/build_docs.sh @@ -0,0 +1,3 @@ +#!/bin/bash +cargo doc --no-deps -p veilid-core +cargo doc --no-deps -p veilid-tools \ No newline at end of file diff --git a/veilid-core/Cargo.toml b/veilid-core/Cargo.toml index 02b0fb1f..5aa252cf 100644 --- a/veilid-core/Cargo.toml +++ b/veilid-core/Cargo.toml @@ -12,10 +12,11 @@ crate-type = ["cdylib", "staticlib", "rlib"] [features] # Common features -default = ["enable-crypto-vld0"] +default = ["enable-crypto-vld0", "rt-tokio"] rt-async-std = [ "async-std", "async-std-resolver", + "trust-dns-resolver", "async_executors/async_std", "rtnetlink/smol_socket", "veilid-tools/rt-async-std", @@ -52,7 +53,9 @@ network-result-extra = ["veilid-tools/network-result-extra"] [dependencies] # Tools -veilid-tools = { path = "../veilid-tools", features = ["tracing"] } +veilid-tools = { path = "../veilid-tools", features = [ + "tracing", +], default-features = false } paste = "1.0.14" once_cell = "1.18.0" owning_ref = "0.4.1" diff --git a/veilid-core/src/intf/native/system.rs b/veilid-core/src/intf/native/system.rs index 19efca93..96b75ae8 100644 --- a/veilid-core/src/intf/native/system.rs +++ b/veilid-core/src/intf/native/system.rs @@ -18,6 +18,7 @@ cfg_if! { cfg_if! { if #[cfg(feature="rt-async-std")] { use async_std_resolver::{config, resolver, resolver_from_system_conf, AsyncStdResolver as AsyncResolver}; + use trust_dns_resolver::error::ResolveErrorKind; } else if #[cfg(feature="rt-tokio")] { use trust_dns_resolver::{config, TokioAsyncResolver as AsyncResolver, error::ResolveError, error::ResolveErrorKind}; diff --git a/veilid-core/src/network_manager/native/network_tcp.rs b/veilid-core/src/network_manager/native/network_tcp.rs index d79fa414..2ea1fbf7 100644 --- a/veilid-core/src/network_manager/native/network_tcp.rs +++ b/veilid-core/src/network_manager/native/network_tcp.rs @@ -132,6 +132,30 @@ impl Network { } }; + #[cfg(all(feature = "rt-async-std", unix))] + { + // async-std does not directly support linger on tcpsocket yet + use std::os::fd::AsRawFd; + use std::os::fd::FromRawFd; + if let Err(e) = unsafe { socket2::Socket::from_raw_fd(tcp_stream.as_raw_fd()) } + .set_linger(Some(core::time::Duration::from_secs(0))) + { + log_net!(debug "Couldn't set TCP linger: {}", e); + return; + } + } + #[cfg(all(feature = "rt-async-std", windows))] + { + // async-std does not directly support linger on tcpsocket yet + use std::os::windows::io::AsRawSocket; + if let Err(e) = unsafe { socket2::socket_from_raw(tcp_stream.as_raw_socket()) } + .set_linger(Some(core::time::Duration::from_secs(0))) + { + log_net!(debug "Couldn't set TCP linger: {}", e); + return; + } + } + #[cfg(not(feature = "rt-async-std"))] if let Err(e) = tcp_stream.set_linger(Some(core::time::Duration::from_secs(0))) { log_net!(debug "Couldn't set TCP linger: {}", e); return; diff --git a/veilid-server/src/main.rs b/veilid-server/src/main.rs index 10ce9c79..2c789bbc 100644 --- a/veilid-server/src/main.rs +++ b/veilid-server/src/main.rs @@ -19,7 +19,7 @@ use clap::{Args, Parser}; use server::*; use settings::LogLevel; use std::collections::HashMap; -use std::ffi::{OsString, OsStr}; +use std::ffi::{OsStr, OsString}; use std::path::Path; use std::str::FromStr; use tools::*; @@ -40,7 +40,6 @@ pub struct Logging { #[derive(Parser, Debug, Clone)] #[command(author, version, about)] pub struct CmdlineArgs { - /// Run in daemon mode in the background #[arg(short, long)] daemon: bool, @@ -66,7 +65,7 @@ pub struct CmdlineArgs { new_password: Option, /// Do not automatically attach the server to the Veilid network - /// + /// /// Default behaviour is to automatically attach the server to the Veilid network, this option disables this behaviour. #[arg(long, value_name = "BOOL")] no_attach: bool, @@ -75,7 +74,7 @@ pub struct CmdlineArgs { logging: Logging, /// Turn on OpenTelemetry tracing - /// + /// /// This option uses the GRPC OpenTelemetry protocol, not HTTP. The format for the endpoint is host:port, like 'localhost:4317' #[arg(long, value_name = "endpoint")] otlp: Option, @@ -85,14 +84,14 @@ pub struct CmdlineArgs { subnode_index: Option, /// Only generate a new keypair and print it - /// + /// /// Generate a new keypair for a specific crypto kind and print both the key and its secret to the terminal, then exit immediately. #[arg(long, value_name = "crypto_kind")] generate_key_pair: Option, /// Set the node ids and secret keys - /// - /// Specify node ids in typed key set format ('[VLD0:xxxx,VLD1:xxxx]') on the command line, a prompt appears to enter the secret key set interactively. + /// + /// Specify node ids in typed key set format ('\[VLD0:xxxx,VLD1:xxxx\]') on the command line, a prompt appears to enter the secret key set interactively. #[arg(long, value_name = "key_set")] set_node_id: Option, @@ -156,7 +155,7 @@ fn main() -> EyreResult<()> { // Check for one-off commands #[cfg(debug_assertions)] - if args.wait_for_debug{ + if args.wait_for_debug { use bugsalot::debugger; debugger::wait_until_attached(None).expect("state() not implemented on this platform"); } @@ -204,7 +203,9 @@ fn main() -> EyreResult<()> { println!("Enabling OTLP tracing"); settingsrw.logging.otlp.enabled = true; settingsrw.logging.otlp.grpc_endpoint = NamedSocketAddrs::from_str( - args.otlp.expect("should not be null because of default missing value").as_str(), + args.otlp + .expect("should not be null because of default missing value") + .as_str(), ) .wrap_err("failed to parse OTLP address")?; settingsrw.logging.otlp.level = LogLevel::Trace; @@ -222,10 +223,16 @@ fn main() -> EyreResult<()> { settingsrw.core.table_store.delete = true; } if let Some(password) = args.password { - settingsrw.core.protected_store.device_encryption_key_password = password; + settingsrw + .core + .protected_store + .device_encryption_key_password = password; } if let Some(new_password) = args.new_password { - settingsrw.core.protected_store.new_device_encryption_key_password = Some(new_password); + settingsrw + .core + .protected_store + .new_device_encryption_key_password = Some(new_password); } if let Some(network_key) = args.network_key { settingsrw.core.network.network_key_password = Some(network_key); @@ -241,8 +248,8 @@ fn main() -> EyreResult<()> { settingsrw.logging.terminal.enabled = false; // Split or get secret - let tks = - TypedKeyGroup::from_str(&key_set).wrap_err("failed to decode node id set from command line")?; + let tks = TypedKeyGroup::from_str(&key_set) + .wrap_err("failed to decode node id set from command line")?; let buffer = rpassword::prompt_password("Enter secret key set (will not echo): ") .wrap_err("invalid secret key")?; @@ -265,7 +272,7 @@ fn main() -> EyreResult<()> { } settingsrw.core.network.routing_table.bootstrap = bootstrap_list; }; - + #[cfg(feature = "rt-tokio")] if args.console { settingsrw.logging.console.enabled = true; @@ -299,8 +306,8 @@ fn main() -> EyreResult<()> { let mut tks = veilid_core::TypedKeyGroup::new(); let mut tss = veilid_core::TypedSecretGroup::new(); for ck in veilid_core::VALID_CRYPTO_KINDS { - let tkp = veilid_core::Crypto::generate_keypair(ck) - .wrap_err("invalid crypto kind")?; + let tkp = + veilid_core::Crypto::generate_keypair(ck).wrap_err("invalid crypto kind")?; tks.add(veilid_core::TypedKey::new(tkp.kind, tkp.value.key)); tss.add(veilid_core::TypedSecret::new(tkp.kind, tkp.value.secret)); } @@ -312,8 +319,7 @@ fn main() -> EyreResult<()> { } 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")?; + let tkp = veilid_core::Crypto::generate_keypair(ck).wrap_err("invalid crypto kind")?; println!("{}", tkp.to_string()); } return Ok(()); diff --git a/veilid-tools/Cargo.toml b/veilid-tools/Cargo.toml index b6d9faec..62c580e8 100644 --- a/veilid-tools/Cargo.toml +++ b/veilid-tools/Cargo.toml @@ -7,29 +7,40 @@ edition = "2021" [lib] # staticlib for iOS tests, cydlib for android tests, rlib for everything else -crate-type = [ "cdylib", "staticlib", "rlib" ] +crate-type = ["cdylib", "staticlib", "rlib"] [features] -default = [] -rt-async-std = [ "async-std", "async_executors/async_std" ] -rt-tokio = [ "tokio", "tokio-util", "async_executors/tokio_tp", "async_executors/tokio_io", "async_executors/tokio_timer" ] -rt-wasm-bindgen = [ "async_executors/bindgen", "async_executors/timer"] +default = ["rt-tokio"] +rt-async-std = ["async-std", "async_executors/async_std"] +rt-tokio = [ + "tokio", + "tokio-util", + "async_executors/tokio_tp", + "async_executors/tokio_io", + "async_executors/tokio_timer", +] +rt-wasm-bindgen = ["async_executors/bindgen", "async_executors/timer"] -veilid_tools_android_tests = [ "dep:paranoid-android" ] -veilid_tools_ios_tests = [ "dep:oslog", "dep:tracing-oslog" ] -tracing = [ "dep:tracing", "dep:tracing-subscriber" ] +veilid_tools_android_tests = ["dep:paranoid-android"] +veilid_tools_ios_tests = ["dep:oslog", "dep:tracing-oslog"] +tracing = ["dep:tracing", "dep:tracing-subscriber"] network-result-extra = [] network-result-info = [] [dependencies] -tracing = { version = "0.1.37", features = ["log", "attributes"], optional = true } +tracing = { version = "0.1.37", features = [ + "log", + "attributes", +], optional = true } tracing-subscriber = { version = "0.3.17", optional = true } log = { version = "0.4.20" } eyre = "0.6.8" static_assertions = "1.1.0" cfg-if = "1.0.0" thiserror = "1.0.47" -futures-util = { version = "0.3.28", default_features = false, features = ["alloc"] } +futures-util = { version = "0.3.28", default_features = false, features = [ + "alloc", +] } parking_lot = "0.12.1" once_cell = "1.18.0" stop-token = { version = "0.7.0", default-features = false } @@ -43,10 +54,15 @@ flume = { version = "0.11.0", features = ["async"] } # Dependencies for native builds only # Linux, Windows, Mac, iOS, Android [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -async-std = { version = "1.12.0", features = ["unstable"], optional = true} -tokio = { version = "1.32.0", features = ["full"], optional = true} -tokio-util = { version = "0.7.8", features = ["compat"], optional = true} -futures-util = { version = "0.3.28", default-features = false, features = ["async-await", "sink", "std", "io"] } +async-std = { version = "1.12.0", features = ["unstable"], optional = true } +tokio = { version = "1.32.0", features = ["full"], optional = true } +tokio-util = { version = "0.7.8", features = ["compat"], optional = true } +futures-util = { version = "0.3.28", default-features = false, features = [ + "async-await", + "sink", + "std", + "io", +] } chrono = "0.4.26" libc = "0.2.147" @@ -57,7 +73,7 @@ nix = "0.26.2" wasm-bindgen = "0.2.87" js-sys = "0.3.64" wasm-bindgen-futures = "0.4.37" -async_executors = { version = "0.7.0", default-features = false} +async_executors = { version = "0.7.0", default-features = false } async-lock = "2.8.0" send_wrapper = { version = "0.6.0", features = ["futures"] } @@ -85,7 +101,7 @@ tracing-oslog = { version = "0.1.2", optional = true } [dev-dependencies] serial_test = "^2.0.0" -simplelog = { version = "0.12.1", features = [ "test" ] } +simplelog = { version = "0.12.1", features = ["test"] } [target.'cfg(target_arch = "wasm32")'.dev-dependencies] console_error_panic_hook = "0.1.7" @@ -100,6 +116,10 @@ tracing-wasm = { version = "0.2.1" } wasm-opt = ["-O", "--enable-mutable-globals"] [package.metadata.ios] -build_targets = ["aarch64-apple-ios", "aarch64-apple-ios-sim", "x86_64-apple-ios"] +build_targets = [ + "aarch64-apple-ios", + "aarch64-apple-ios-sim", + "x86_64-apple-ios", +] deployment_target = "12.0" build_id_prefix = "com.veilid.veilidtools"