veilid/veilid-core/src/lib.rs

133 lines
3.7 KiB
Rust
Raw Normal View History

2023-09-02 01:13:05 +00:00
//! # The Veilid Framework
2023-08-29 20:15:47 +00:00
//!
2023-09-02 01:18:45 +00:00
//! Core library used to create a Veilid node and operate it as part of an application.
2023-08-29 20:15:47 +00:00
//!
//! `veilid-core` contains all of the core logic for Veilid and can be used in mobile applications as well as desktop
//! and in-browser WebAssembly apps.
//!
//! The public API is accessed by getting a [VeilidAPI] object via a call to [api_startup] or [api_startup_json].
//!
//! From there, a [RoutingContext] object can get you access to public and private routed operations.
//!
2023-09-02 01:13:05 +00:00
//! ## Features
//!
//! The default `veilid-core` configurations are:
//!
//! * `default` - Uses `tokio` as the async runtime
//!
//! If you use `--no-default-features`, you can switch to other runtimes:
//!
//! * `default-async-std` - Uses `async-std` as the async runtime
//! * `default-wasm` - When building for the `wasm32` architecture, use this to enable `wasm-bindgen-futures` as the async runtime
//!
2021-12-08 03:09:45 +00:00
#![deny(clippy::all)]
2023-09-17 23:37:02 +00:00
#![allow(clippy::comparison_chain, clippy::upper_case_acronyms)]
2021-12-09 21:11:52 +00:00
#![deny(unused_must_use)]
2022-11-30 14:39:12 +00:00
#![recursion_limit = "256"]
2022-06-28 03:46:29 +00:00
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
#[cfg(any(feature = "rt-async-std", feature = "rt-tokio"))]
compile_error!("features \"rt-async-std\" and \"rt-tokio\" can not be specified for WASM");
} else {
#[cfg(all(feature = "rt-async-std", feature = "rt-tokio"))]
compile_error!(
"feature \"rt-async-std\" and feature \"rt-tokio\" cannot be enabled at the same time"
);
#[cfg(not(any(feature = "rt-async-std", feature = "rt-tokio")))]
compile_error!("exactly one of feature \"rt-async-std\" or feature \"rt-tokio\" must be specified");
}
}
2021-11-22 16:28:30 +00:00
#[macro_use]
extern crate alloc;
2022-06-08 01:31:05 +00:00
mod api_tracing_layer;
2021-11-22 16:28:30 +00:00
mod attachment_manager;
2022-02-07 02:18:42 +00:00
mod core_context;
2022-10-30 23:29:31 +00:00
mod crypto;
2021-11-22 16:28:30 +00:00
mod intf;
mod network_manager;
mod receipt_manager;
mod routing_table;
mod rpc_processor;
2023-05-29 19:24:57 +00:00
mod storage_manager;
mod table_store;
2021-11-22 16:28:30 +00:00
mod veilid_api;
mod veilid_config;
2022-07-01 16:13:52 +00:00
mod veilid_layer_filter;
2023-09-01 02:01:00 +00:00
mod wasm_helpers;
2021-11-22 16:28:30 +00:00
2022-06-08 01:31:05 +00:00
pub use self::api_tracing_layer::ApiTracingLayer;
2022-02-09 14:47:36 +00:00
pub use self::core_context::{api_startup, api_startup_json, UpdateCallback};
2021-11-22 16:28:30 +00:00
pub use self::veilid_api::*;
pub use self::veilid_config::*;
2022-07-01 16:13:52 +00:00
pub use self::veilid_layer_filter::*;
2022-11-27 02:37:23 +00:00
pub use veilid_tools as tools;
2021-11-22 16:28:30 +00:00
2023-08-29 20:15:47 +00:00
/// The on-the-wire serialization format for Veilid RPC
2021-11-22 16:28:30 +00:00
pub mod veilid_capnp {
include!(concat!(env!("OUT_DIR"), "/proto/veilid_capnp.rs"));
}
2023-08-29 20:15:47 +00:00
#[doc(hidden)]
2021-11-22 16:28:30 +00:00
pub mod tests;
2022-01-28 03:02:16 +00:00
2023-08-29 20:15:47 +00:00
/// Return the cargo package version of veilid-core in string format
2022-01-28 03:02:16 +00:00
pub fn veilid_version_string() -> String {
env!("CARGO_PKG_VERSION").to_owned()
}
2023-08-29 20:15:47 +00:00
/// Return the cargo package version of veilid-core in tuple format
2022-01-28 03:02:16 +00:00
pub fn veilid_version() -> (u32, u32, u32) {
(
u32::from_str(env!("CARGO_PKG_VERSION_MAJOR")).unwrap(),
u32::from_str(env!("CARGO_PKG_VERSION_MINOR")).unwrap(),
u32::from_str(env!("CARGO_PKG_VERSION_PATCH")).unwrap(),
)
}
2022-02-01 03:47:17 +00:00
2022-03-04 01:45:39 +00:00
#[cfg(target_os = "android")]
2022-12-01 19:32:02 +00:00
pub use intf::android::veilid_core_setup_android;
2022-03-04 01:45:39 +00:00
2023-08-22 01:04:21 +00:00
pub static DEFAULT_LOG_IGNORE_LIST: [&str; 23] = [
2022-06-28 03:46:29 +00:00
"mio",
2022-06-29 14:13:49 +00:00
"h2",
"hyper",
"tower",
"tonic",
2022-11-04 02:52:18 +00:00
"tokio",
"runtime",
2022-06-29 14:13:49 +00:00
"tokio_util",
"want",
2022-06-28 03:46:29 +00:00
"serial_test",
2022-02-01 03:47:17 +00:00
"async_std",
"async_io",
"polling",
"rustls",
"async_tungstenite",
"tungstenite",
"netlink_proto",
"netlink_sys",
2022-05-17 20:55:53 +00:00
"trust_dns_resolver",
"trust_dns_proto",
2022-08-22 17:27:26 +00:00
"attohttpc",
2023-08-22 01:04:21 +00:00
"ws_stream_wasm",
"keyvaluedb_web",
2022-02-01 03:47:17 +00:00
];
2022-11-30 00:22:33 +00:00
2023-06-08 18:07:09 +00:00
use cfg_if::*;
use enumset::*;
use eyre::{bail, eyre, Report as EyreReport, Result as EyreResult, WrapErr};
2023-08-29 20:15:47 +00:00
#[allow(unused_imports)]
2023-08-24 20:15:51 +00:00
use futures_util::stream::{FuturesOrdered, FuturesUnordered};
2023-07-15 20:18:13 +00:00
use parking_lot::*;
2023-06-08 18:07:09 +00:00
use schemars::{schema_for, JsonSchema};
use serde::*;
use stop_token::*;
use thiserror::Error as ThisError;
2023-07-15 20:18:13 +00:00
use tracing::*;
use veilid_tools::*;
2023-09-01 02:01:00 +00:00
use wasm_helpers::*;