wasm cleanup

This commit is contained in:
Christien Rioux 2024-11-06 21:12:11 -05:00
parent 99bc2aaa5f
commit 91e1acb1d6
63 changed files with 317 additions and 234 deletions

View File

@ -149,7 +149,7 @@ sanitize-filename = "0.5.0"
# Dependencies for native builds only
# Linux, Windows, Mac, iOS, Android
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
[target.'cfg(not(all(target_arch = "wasm32", target_os = "unknown")))'.dependencies]
# Tools
config = { version = "0.13.4", default-features = false, features = ["yaml"] }
@ -186,7 +186,7 @@ rustls = "0.21.12"
rustls-pemfile = "1.0.4"
# Dependencies for WASM builds only
[target.'cfg(target_arch = "wasm32")'.dependencies]
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
veilid-tools = { version = "0.4.1", path = "../veilid-tools", default-features = false, features = [
"rt-wasm-bindgen",
@ -221,7 +221,7 @@ tracing-wasm = "0.2.1"
keyvaluedb-web = "0.1.2"
### Configuration for WASM32 'web-sys' crate
[target.'cfg(target_arch = "wasm32")'.dependencies.web-sys]
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies.web-sys]
version = "0.3.69"
features = [
'Document',
@ -259,12 +259,12 @@ tracing-oslog = { version = "0.1.2", optional = true }
### DEV DEPENDENCIES
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
[target.'cfg(not(all(target_arch = "wasm32", target_os = "unknown")))'.dev-dependencies]
simplelog = { version = "0.12.2", features = ["test"] }
serial_test = "2.0.0"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies]
serial_test = { version = "2.0.0", default-features = false, features = [
"async",
] }

View File

@ -78,7 +78,7 @@ where
macro_rules! byte_array_type {
($name:ident, $size:expr, $encoded_size:expr) => {
#[derive(Clone, Copy, Hash, PartialOrd, Ord, PartialEq, Eq)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(into_wasm_abi))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify), tsify(into_wasm_abi))]
pub struct $name {
pub bytes: [u8; $size],
}
@ -280,17 +280,17 @@ macro_rules! byte_array_type {
byte_array_type!(CryptoKey, CRYPTO_KEY_LENGTH, CRYPTO_KEY_LENGTH_ENCODED);
#[cfg_attr(target_arch = "wasm32", declare)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type PublicKey = CryptoKey;
#[cfg_attr(target_arch = "wasm32", declare)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type SecretKey = CryptoKey;
#[cfg_attr(target_arch = "wasm32", declare)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type HashDigest = CryptoKey;
#[cfg_attr(target_arch = "wasm32", declare)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type SharedSecret = CryptoKey;
#[cfg_attr(target_arch = "wasm32", declare)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type RouteId = CryptoKey;
#[cfg_attr(target_arch = "wasm32", declare)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type CryptoKeyDistance = CryptoKey;
byte_array_type!(Signature, SIGNATURE_LENGTH, SIGNATURE_LENGTH_ENCODED);

View File

@ -2,7 +2,7 @@ use super::*;
#[derive(Clone, Copy, Default, PartialOrd, Ord, PartialEq, Eq, Hash)]
#[cfg_attr(
target_arch = "wasm32",
all(target_arch = "wasm32", target_os = "unknown"),
derive(Tsify),
tsify(from_wasm_abi, into_wasm_abi)
)]

View File

@ -6,7 +6,7 @@ use core::fmt;
use core::hash::Hash;
/// Cryptography version fourcc code
#[cfg_attr(target_arch = "wasm32", declare)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type CryptoKind = FourCC;
/// Sort best crypto kinds first
@ -52,24 +52,24 @@ pub use crypto_typed::*;
pub use crypto_typed_group::*;
pub use keypair::*;
#[cfg_attr(target_arch = "wasm32", declare)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedKey = CryptoTyped<PublicKey>;
#[cfg_attr(target_arch = "wasm32", declare)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedSecret = CryptoTyped<SecretKey>;
#[cfg_attr(target_arch = "wasm32", declare)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedKeyPair = CryptoTyped<KeyPair>;
#[cfg_attr(target_arch = "wasm32", declare)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedSignature = CryptoTyped<Signature>;
#[cfg_attr(target_arch = "wasm32", declare)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedSharedSecret = CryptoTyped<SharedSecret>;
#[cfg_attr(target_arch = "wasm32", declare)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedKeyGroup = CryptoTypedGroup<PublicKey>;
#[cfg_attr(target_arch = "wasm32", declare)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedSecretGroup = CryptoTypedGroup<SecretKey>;
#[cfg_attr(target_arch = "wasm32", declare)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedKeyPairGroup = CryptoTypedGroup<KeyPair>;
#[cfg_attr(target_arch = "wasm32", declare)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedSignatureGroup = CryptoTypedGroup<Signature>;
#[cfg_attr(target_arch = "wasm32", declare)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedSharedSecretGroup = CryptoTypedGroup<SharedSecret>;

View File

@ -1,12 +1,12 @@
use super::*;
#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
mod wasm;
#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
pub use wasm::*;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
mod native;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
pub use native::*;
pub static KNOWN_PROTECTED_STORE_KEYS: [&str; 2] = ["device_encryption_key", "_test_key"];

View File

@ -28,7 +28,7 @@
#![recursion_limit = "256"]
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
#[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 {

View File

@ -574,7 +574,7 @@ impl ConnectionManager {
// Called by low-level network when any connection-oriented protocol connection appears
// either from incoming connections.
#[cfg_attr(target_arch = "wasm32", expect(dead_code))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), expect(dead_code))]
pub(super) async fn on_accepted_protocol_network_connection(
&self,
protocol_connection: ProtocolNetworkConnection,

View File

@ -1,8 +1,8 @@
use crate::*;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
mod native;
#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
mod wasm;
mod address_check;
@ -36,16 +36,16 @@ use connection_handle::*;
use crypto::*;
use futures_util::stream::FuturesUnordered;
use hashlink::LruCache;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
use native::*;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
pub use native::{MAX_CAPABILITIES, PUBLIC_INTERNET_CAPABILITIES};
use routing_table::*;
use rpc_processor::*;
use storage_manager::*;
#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm::*;
#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
pub use wasm::{/* LOCAL_NETWORK_CAPABILITIES, */ MAX_CAPABILITIES, PUBLIC_INTERNET_CAPABILITIES,};
////////////////////////////////////////////////////////////////////////////////////////
@ -119,7 +119,7 @@ enum SendDataToExistingFlowResult {
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum StartupDisposition {
Success,
#[cfg_attr(target_arch = "wasm32", expect(dead_code))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), expect(dead_code))]
BindRetry,
}

View File

@ -4,7 +4,7 @@ use std::{io, sync::Arc};
use stop_token::prelude::*;
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
// No accept support for WASM
} else {

View File

@ -20,7 +20,7 @@ impl Address {
SocketAddr::V6(v6) => Address::IPV6(*v6.ip()),
}
}
#[cfg_attr(target_arch = "wasm32", expect(dead_code))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), expect(dead_code))]
pub fn from_ip_addr(addr: IpAddr) -> Address {
match addr {
IpAddr::V4(v4) => Address::IPV4(v4),

View File

@ -268,7 +268,7 @@ impl DialInfo {
Self::WSS(di) => di.socket_address.port(),
}
}
#[cfg_attr(target_arch = "wasm32", expect(dead_code))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), expect(dead_code))]
pub fn set_port(&mut self, port: u16) {
match self {
Self::UDP(di) => di.socket_address.set_port(port),
@ -366,7 +366,7 @@ impl DialInfo {
// This will not be used on signed dialinfo, only for bootstrapping, so we don't need to worry about
// the '0.0.0.0' address being propagated across the routing table
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
vec![SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0,0,0,0)), port)]
} else {
match split_url.host {

View File

@ -1,2 +1,2 @@
[build]
target = "wasm32-unknown-unknown"
all(target_arch = "wasm32", target_os = "unknown")

View File

@ -9,29 +9,6 @@ struct WebsocketNetworkConnectionInner {
ws_stream: CloneStream<WsStream>,
}
fn to_io(err: WsErr) -> io::Error {
match err {
WsErr::InvalidWsState { supplied: _ } => {
io::Error::new(io::ErrorKind::InvalidInput, err.to_string())
}
WsErr::ConnectionNotOpen => io::Error::new(io::ErrorKind::NotConnected, err.to_string()),
WsErr::InvalidUrl { supplied: _ } => {
io::Error::new(io::ErrorKind::InvalidInput, err.to_string())
}
WsErr::InvalidCloseCode { supplied: _ } => {
io::Error::new(io::ErrorKind::InvalidInput, err.to_string())
}
WsErr::ReasonStringToLong => io::Error::new(io::ErrorKind::InvalidInput, err.to_string()),
WsErr::ConnectionFailed { event: _ } => {
io::Error::new(io::ErrorKind::ConnectionRefused, err.to_string())
}
WsErr::InvalidEncoding => io::Error::new(io::ErrorKind::InvalidInput, err.to_string()),
WsErr::CantDecodeBlob => io::Error::new(io::ErrorKind::InvalidInput, err.to_string()),
WsErr::UnknownDataType => io::Error::new(io::ErrorKind::InvalidInput, err.to_string()),
_ => io::Error::new(io::ErrorKind::Other, err.to_string()),
}
}
#[derive(Clone)]
pub struct WebsocketNetworkConnection {
flow: Flow,
@ -65,7 +42,7 @@ impl WebsocketNetworkConnection {
)]
pub async fn close(&self) -> io::Result<NetworkResult<()>> {
#[allow(unused_variables)]
let x = self.inner.ws_meta.close().await.map_err(to_io);
let x = self.inner.ws_meta.close().await.map_err(ws_err_to_io_error);
#[cfg(feature = "verbose-tracing")]
log_net!(debug "close result: {:?}", x);
Ok(NetworkResult::value(()))
@ -83,7 +60,7 @@ impl WebsocketNetworkConnection {
.send(WsMessage::Binary(message)),
)
.await
.map_err(to_io)
.map_err(ws_err_to_io_error)
.into_network_result()?;
#[cfg(feature = "verbose-tracing")]
@ -140,7 +117,9 @@ impl WebsocketProtocolHandler {
}
let fut = SendWrapper::new(timeout(timeout_ms, async move {
WsMeta::connect(request, None).await.map_err(to_io)
WsMeta::connect(request, None)
.await
.map_err(ws_err_to_io_error)
}));
let (wsmeta, wsio) = network_result_try!(network_result_try!(fut

View File

@ -612,7 +612,7 @@ impl RoutingTable {
}
/// Return the domain's currently registered network class
#[cfg_attr(target_arch = "wasm32", expect(dead_code))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), expect(dead_code))]
pub fn get_network_class(&self, routing_domain: RoutingDomain) -> Option<NetworkClass> {
self.inner.read().get_network_class(routing_domain)
}
@ -817,7 +817,7 @@ impl RoutingTable {
}
/// Makes a filter that finds nodes with a matching inbound dialinfo
#[cfg_attr(target_arch = "wasm32", expect(dead_code))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), expect(dead_code))]
pub fn make_inbound_dial_info_entry_filter<'a>(
routing_domain: RoutingDomain,
dial_info_filter: DialInfoFilter,

View File

@ -7,7 +7,7 @@ pub trait RoutingDomainEditorCommonTrait {
protocol_type: Option<ProtocolType>,
) -> &mut Self;
fn set_relay_node(&mut self, relay_node: Option<NodeRef>) -> &mut Self;
#[cfg_attr(target_arch = "wasm32", expect(dead_code))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), expect(dead_code))]
fn add_dial_info(&mut self, dial_info: DialInfo, class: DialInfoClass) -> &mut Self;
fn setup_network(
&mut self,
@ -83,7 +83,7 @@ pub(super) enum RoutingDomainChangeCommon {
AddDialInfo {
dial_info_detail: DialInfoDetail,
},
// #[cfg_attr(target_arch = "wasm32", expect(dead_code))]
// #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), expect(dead_code))]
// RemoveDialInfoDetail {
// dial_info_detail: DialInfoDetail,
// },

View File

@ -1,4 +1,4 @@
#![cfg_attr(target_arch = "wasm32", expect(dead_code))]
#![cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), expect(dead_code))]
use super::*;

View File

@ -143,7 +143,7 @@ impl RoutingDomainDetailCommon {
pub fn network_class(&self) -> Option<NetworkClass> {
cfg_if! {
if #[cfg(target_arch = "wasm32")] {
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
Some(NetworkClass::WebApp)
} else {
if self.address_types.is_empty() {

View File

@ -52,7 +52,7 @@ impl RPCError {
pub fn map_network<M: ToString, X: ToString>(message: M) -> impl FnOnce(X) -> Self {
move |x| Self::Network(format!("{}: {}", message.to_string(), x.to_string()))
}
#[cfg_attr(target_arch = "wasm32", expect(dead_code))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), expect(dead_code))]
pub fn try_again<X: ToString>(x: X) -> Self {
Self::TryAgain(x.to_string())
}

View File

@ -5,13 +5,13 @@ pub use table_db::*;
pub mod tests;
#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
mod wasm;
#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm::*;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
mod native;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
use native::*;
use keyvaluedb::*;
@ -20,14 +20,14 @@ const ALL_TABLE_NAMES: &[u8] = b"all_table_names";
/// Description of column
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct ColumnInfo {
pub key_count: AlignedU64,
}
/// IO Stats for table
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct IOStatsInfo {
/// Number of transaction.
pub transactions: AlignedU64,
@ -51,7 +51,7 @@ pub struct IOStatsInfo {
/// Description of table
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct TableInfo {
/// Internal table name
pub table_name: String,

View File

@ -1,7 +1,7 @@
use crate::*;
cfg_if! {
if #[cfg(target_arch = "wasm32")] {
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
use keyvaluedb_web::*;
use keyvaluedb::*;
} else {

View File

@ -1,7 +1,7 @@
use crate::*;
cfg_if! {
if #[cfg(not(target_arch = "wasm32"))] {
if #[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] {
use std::fs::File;
use std::io::prelude::*;
use std::path::PathBuf;
@ -61,7 +61,7 @@ wFAbkZY9eS/x6P7qrpd7dUA=
cfg_if! {
if #[cfg(target_arch = "wasm32")] {
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
pub fn get_table_store_path() -> String {
String::new()
}
@ -207,9 +207,9 @@ pub fn config_callback(key: String) -> ConfigCallbackReturn {
"network.routing_table.node_id" => Ok(Box::new(TypedKeyGroup::new())),
"network.routing_table.node_id_secret" => Ok(Box::new(TypedSecretGroup::new())),
// "network.routing_table.bootstrap" => Ok(Box::new(Vec::<String>::new())),
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
"network.routing_table.bootstrap" => Ok(Box::new(vec!["bootstrap.veilid.net".to_string()])),
#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
"network.routing_table.bootstrap" => Ok(Box::new(vec![
"ws://bootstrap.veilid.net:5150/ws".to_string(),
])),
@ -349,12 +349,12 @@ pub async fn test_config() {
assert_eq!(inner.network.rpc.default_route_hop_count, 1u8);
assert_eq!(inner.network.routing_table.node_id.len(), 0);
assert_eq!(inner.network.routing_table.node_id_secret.len(), 0);
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
assert_eq!(
inner.network.routing_table.bootstrap,
vec!["bootstrap.veilid.net"],
);
#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
assert_eq!(
inner.network.routing_table.bootstrap,
vec!["ws://bootstrap.veilid.net:5150/ws"],

View File

@ -3,7 +3,7 @@ mod android;
pub mod common;
#[cfg(all(target_os = "ios", feature = "veilid_core_ios_tests"))]
mod ios;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
mod native;
#[allow(unused_imports)]

View File

@ -1,5 +1,5 @@
//! Test suite for Native
#![cfg(not(target_arch = "wasm32"))]
#![cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
use crate::tests::*;
use crate::*;

View File

@ -107,7 +107,7 @@ macro_rules! apibail_already_initialized {
#[derive(
ThisError, Clone, Debug, PartialOrd, PartialEq, Eq, Ord, Serialize, Deserialize, JsonSchema,
)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(into_wasm_abi))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify), tsify(into_wasm_abi))]
#[serde(tag = "kind")]
pub enum VeilidAPIError {
#[error("Not initialized")]

View File

@ -21,13 +21,13 @@ macro_rules! aligned_u64_type {
Deserialize,
JsonSchema,
)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
#[repr(C, align(8))]
#[serde(transparent)]
pub struct $name(
#[serde(with = "as_human_string")]
#[schemars(with = "String")]
#[cfg_attr(target_arch = "wasm32", tsify(type = "string"))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(type = "string"))]
u64,
);

View File

@ -2,22 +2,22 @@ use super::*;
/// Direct statement blob passed to hosting application for processing.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidAppMessage {
#[serde(with = "as_human_opt_string")]
#[schemars(with = "Option<String>")]
#[cfg_attr(target_arch = "wasm32", tsify(optional, type = "string"))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional, type = "string"))]
sender: Option<TypedKey>,
#[serde(with = "as_human_opt_string")]
#[schemars(with = "Option<String>")]
#[cfg_attr(target_arch = "wasm32", tsify(optional, type = "string"))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional, type = "string"))]
route_id: Option<RouteId>,
#[cfg_attr(not(target_arch = "wasm32"), serde(with = "as_human_base64"))]
#[cfg_attr(not(all(target_arch = "wasm32", target_os = "unknown")), serde(with = "as_human_base64"))]
#[schemars(with = "String")]
#[cfg_attr(
target_arch = "wasm32",
all(target_arch = "wasm32", target_os = "unknown"),
serde(with = "serde_bytes"),
tsify(type = "Uint8Array")
)]
@ -51,22 +51,22 @@ impl VeilidAppMessage {
/// Direct question blob passed to hosting application for processing to send an eventual AppReply.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidAppCall {
#[serde(with = "as_human_opt_string")]
#[schemars(with = "Option<String>")]
#[cfg_attr(target_arch = "wasm32", tsify(optional))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional))]
sender: Option<TypedKey>,
#[serde(with = "as_human_opt_string")]
#[schemars(with = "Option<String>")]
#[cfg_attr(target_arch = "wasm32", tsify(optional, type = "string"))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional, type = "string"))]
route_id: Option<RouteId>,
#[cfg_attr(not(target_arch = "wasm32"), serde(with = "as_human_base64"))]
#[cfg_attr(not(all(target_arch = "wasm32", target_os = "unknown")), serde(with = "as_human_base64"))]
#[schemars(with = "String")]
#[cfg_attr(
target_arch = "wasm32",
all(target_arch = "wasm32", target_os = "unknown"),
serde(with = "serde_bytes"),
tsify(type = "Uint8Array")
)]

View File

@ -3,7 +3,7 @@ use super::*;
/// DHT Record Descriptor
#[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(
target_arch = "wasm32",
all(target_arch = "wasm32", target_os = "unknown"),
derive(Tsify),
tsify(from_wasm_abi, into_wasm_abi)
)]
@ -17,7 +17,7 @@ pub struct DHTRecordDescriptor {
/// If this key is being created: Some(the secret key of the owner)
/// If this key is just being opened: None
#[schemars(with = "Option<String>")]
#[cfg_attr(target_arch = "wasm32", tsify(optional))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional))]
owner_secret: Option<SecretKey>,
/// The schema in use associated with the key
schema: DHTSchema,

View File

@ -3,7 +3,7 @@ use super::*;
/// DHT Record Report
#[derive(Default, Clone, PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(
target_arch = "wasm32",
all(target_arch = "wasm32", target_os = "unknown"),
derive(Tsify),
tsify(from_wasm_abi, into_wasm_abi)
)]
@ -67,7 +67,7 @@ impl fmt::Debug for DHTRecordReport {
Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
)]
#[cfg_attr(
target_arch = "wasm32",
all(target_arch = "wasm32", target_os = "unknown"),
derive(Tsify),
tsify(from_wasm_abi, into_wasm_abi, namespace)
)]

View File

@ -13,10 +13,10 @@ pub use value_data::*;
pub use value_subkey_range_set::*;
/// Value subkey
#[cfg_attr(target_arch = "wasm32", declare)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type ValueSubkey = u32;
/// Value sequence number
#[cfg_attr(target_arch = "wasm32", declare)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type ValueSeqNum = u32;
pub(crate) fn debug_seqs(seqs: &[ValueSeqNum]) -> String {

View File

@ -3,7 +3,7 @@ use crate::storage_manager::{MAX_RECORD_DATA_SIZE, MAX_SUBKEY_SIZE};
/// Default DHT Schema (DFLT)
#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(from_wasm_abi))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify), tsify(from_wasm_abi))]
pub struct DHTSchemaDFLT {
/// Owner subkey count
o_cnt: u16,

View File

@ -9,7 +9,11 @@ pub use smpl::*;
/// Enum over all the supported DHT Schemas
#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Serialize, Deserialize, JsonSchema)]
#[serde(tag = "kind")]
#[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(from_wasm_abi))]
#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown"),
derive(Tsify),
tsify(from_wasm_abi)
)]
pub enum DHTSchema {
DFLT(DHTSchemaDFLT),
SMPL(DHTSchemaSMPL),

View File

@ -3,7 +3,11 @@ use crate::storage_manager::{MAX_RECORD_DATA_SIZE, MAX_SUBKEY_SIZE};
/// Simple DHT Schema (SMPL) Member
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(from_wasm_abi))]
#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown"),
derive(Tsify),
tsify(from_wasm_abi)
)]
pub struct DHTSchemaSMPLMember {
/// Member key
#[schemars(with = "String")]
@ -14,7 +18,11 @@ pub struct DHTSchemaSMPLMember {
/// Simple DHT Schema (SMPL)
#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(from_wasm_abi))]
#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown"),
derive(Tsify),
tsify(from_wasm_abi)
)]
pub struct DHTSchemaSMPL {
/// Owner subkey count
o_cnt: u16,

View File

@ -2,16 +2,16 @@ use super::*;
use veilid_api::VeilidAPIResult;
#[derive(Clone, Default, PartialOrd, PartialEq, Eq, Ord, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(into_wasm_abi))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify), tsify(into_wasm_abi))]
pub struct ValueData {
/// An increasing sequence number to time-order the DHT record changes
seq: ValueSeqNum,
/// The contents of a DHT Record
#[cfg_attr(not(target_arch = "wasm32"), serde(with = "as_human_base64"))]
#[cfg_attr(not(all(target_arch = "wasm32", target_os = "unknown")), serde(with = "as_human_base64"))]
#[schemars(with = "String")]
#[cfg_attr(
target_arch = "wasm32",
all(target_arch = "wasm32", target_os = "unknown"),
serde(with = "serde_bytes"),
tsify(type = "Uint8Array")
)]

View File

@ -6,7 +6,7 @@ use range_set_blaze::*;
Clone, Default, Hash, PartialOrd, PartialEq, Eq, Ord, Serialize, Deserialize, JsonSchema,
)]
#[cfg_attr(
target_arch = "wasm32",
all(target_arch = "wasm32", target_os = "unknown"),
derive(Tsify),
tsify(from_wasm_abi, into_wasm_abi)
)]

View File

@ -5,7 +5,7 @@ use super::*;
Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
)]
#[cfg_attr(
target_arch = "wasm32",
all(target_arch = "wasm32", target_os = "unknown"),
derive(Tsify),
tsify(from_wasm_abi, into_wasm_abi, namespace)
)]
@ -27,7 +27,7 @@ impl Default for Sequencing {
Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
)]
#[cfg_attr(
target_arch = "wasm32",
all(target_arch = "wasm32", target_os = "unknown"),
derive(Tsify),
tsify(from_wasm_abi, into_wasm_abi, namespace)
)]
@ -48,7 +48,7 @@ impl Default for Stability {
Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
)]
#[cfg_attr(
target_arch = "wasm32",
all(target_arch = "wasm32", target_os = "unknown"),
derive(Tsify),
tsify(from_wasm_abi, into_wasm_abi, namespace)
)]
@ -79,11 +79,11 @@ impl Default for SafetySelection {
#[derive(
Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct SafetySpec {
/// Preferred safety route set id if it still exists.
#[schemars(with = "Option<String>")]
#[cfg_attr(target_arch = "wasm32", tsify(optional, type = "string"))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional, type = "string"))]
pub preferred_route: Option<RouteId>,
/// Must be greater than 0.
pub hop_count: usize,

View File

@ -2,7 +2,7 @@ use super::*;
/// Measurement of communications latency to this node over all RPC questions
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct LatencyStats {
/// fastest latency in the ROLLING_LATENCIES_SIZE last latencies
pub fastest: TimestampDuration,
@ -25,7 +25,7 @@ impl fmt::Display for LatencyStats {
/// Measurement of how much data has transferred to or from this node over a time span
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct TransferStats {
/// total amount transferred ever
pub total: ByteCount,
@ -50,7 +50,7 @@ impl fmt::Display for TransferStats {
/// Transfer statistics from a node to our own (down) and
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct TransferStatsDownUp {
pub down: TransferStats,
pub up: TransferStats,
@ -66,7 +66,7 @@ impl fmt::Display for TransferStatsDownUp {
/// Measurement of what states the node has been in over a time span
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct StateStats {
/// total amount of time measured
pub span: TimestampDuration,
@ -97,7 +97,7 @@ impl fmt::Display for StateStats {
/// Measurement of what state reasons the node has been in over a time span
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct StateReasonStats {
/// time spent dead due to being unable to send
pub can_not_send: TimestampDuration,
@ -139,7 +139,7 @@ impl fmt::Display for StateReasonStats {
/// Measurement of round-trip RPC question/answer performance
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct AnswerStats {
/// total amount of time measured
pub span: TimestampDuration,
@ -192,7 +192,7 @@ impl fmt::Display for AnswerStats {
/// Statistics for RPC operations performed on a node
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct RPCStats {
/// number of rpcs that have been sent in the total entry time range
pub messages_sent: u32,
@ -263,7 +263,7 @@ impl fmt::Display for RPCStats {
/// Statistics for a peer in the routing table
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct PeerStats {
/// when the peer was added to the routing table
pub time_added: Timestamp,

View File

@ -4,7 +4,7 @@ use super::*;
#[derive(
Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Copy, Serialize, Deserialize, JsonSchema,
)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(namespace))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify), tsify(namespace))]
pub enum VeilidLogLevel {
Error = 1,
Warn = 2,
@ -81,10 +81,10 @@ impl fmt::Display for VeilidLogLevel {
}
/// A VeilidCore log message with optional backtrace.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidLog {
pub log_level: VeilidLogLevel,
pub message: String,
#[cfg_attr(target_arch = "wasm32", tsify(optional))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional))]
pub backtrace: Option<String>,
}

View File

@ -3,7 +3,7 @@ use super::*;
/// Attachment abstraction for network 'signal strength'.
#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(
target_arch = "wasm32",
all(target_arch = "wasm32", target_os = "unknown"),
derive(Tsify),
tsify(namespace, from_wasm_abi, into_wasm_abi)
)]
@ -77,7 +77,7 @@ impl TryFrom<&str> for AttachmentState {
/// Describe the attachment state of the Veilid node
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidStateAttachment {
/// The overall quality of the routing table if attached, or the current state the attachment state machine.
pub state: AttachmentState,
@ -94,11 +94,11 @@ pub struct VeilidStateAttachment {
/// Describe a recently accessed peer
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct PeerTableData {
/// The node ids used by this peer
#[schemars(with = "Vec<String>")]
#[cfg_attr(target_arch = "wasm32", tsify(type = "string[]"))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(type = "string[]"))]
pub node_ids: Vec<TypedKey>,
/// The peer's human readable address.
pub peer_address: String,
@ -108,7 +108,7 @@ pub struct PeerTableData {
/// Describe the current network state of the Veilid node
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidStateNetwork {
/// If the network has been started or not.
pub started: bool,
@ -123,7 +123,7 @@ pub struct VeilidStateNetwork {
/// Describe a private route change that has happened
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidRouteChange {
/// If a private route that was allocated has died, it is listed here.
#[schemars(with = "Vec<String>")]
@ -138,7 +138,7 @@ pub struct VeilidRouteChange {
/// add the ability to change the configuration or have it changed by the Veilid node
/// itself during runtime.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidStateConfig {
/// If the Veilid node configuration has changed the full new config will be here.
pub config: VeilidConfigInner,
@ -146,7 +146,7 @@ pub struct VeilidStateConfig {
/// Describe when DHT records have subkey values changed
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidValueChange {
/// The DHT Record key that changed
#[schemars(with = "String")]
@ -167,7 +167,7 @@ pub struct VeilidValueChange {
/// An update from the veilid-core to the host application describing a change
/// to the internal state of the Veilid node.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(into_wasm_abi))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify), tsify(into_wasm_abi))]
#[serde(tag = "kind")]
pub enum VeilidUpdate {
Log(Box<VeilidLog>),
@ -184,7 +184,7 @@ from_impl_to_jsvalue!(VeilidUpdate);
/// A queriable state of the internals of veilid-core.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(into_wasm_abi))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify), tsify(into_wasm_abi))]
pub struct VeilidState {
pub attachment: Box<VeilidStateAttachment>,
pub network: Box<VeilidStateNetwork>,

View File

@ -1,7 +1,7 @@
use crate::*;
cfg_if::cfg_if! {
if #[cfg(not(target_arch = "wasm32"))] {
if #[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] {
use sysinfo::System;
use lazy_static::*;
use directories::ProjectDirs;
@ -31,12 +31,12 @@ pub type ConfigCallback = Arc<dyn Fn(String) -> ConfigCallbackReturn + Send + Sy
/// ```
///
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidConfigHTTPS {
pub enabled: bool,
pub listen_address: String,
pub path: String,
#[cfg_attr(target_arch = "wasm32", tsify(optional))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional))]
pub url: Option<String>, // Fixed URL is not optional for TLS-based protocols and is dynamically validated
}
@ -62,12 +62,12 @@ impl Default for VeilidConfigHTTPS {
/// ```
///
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidConfigHTTP {
pub enabled: bool,
pub listen_address: String,
pub path: String,
#[cfg_attr(target_arch = "wasm32", tsify(optional))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional))]
pub url: Option<String>,
}
@ -89,7 +89,7 @@ impl Default for VeilidConfigHTTP {
/// To be implemented...
///
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidConfigApplication {
pub https: VeilidConfigHTTPS,
pub http: VeilidConfigHTTP,
@ -106,19 +106,19 @@ pub struct VeilidConfigApplication {
/// ```
///
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidConfigUDP {
pub enabled: bool,
pub socket_pool_size: u32,
pub listen_address: String,
#[cfg_attr(target_arch = "wasm32", tsify(optional))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional))]
pub public_address: Option<String>,
}
impl Default for VeilidConfigUDP {
fn default() -> Self {
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
let enabled = false;
} else {
let enabled = true;
@ -144,20 +144,20 @@ impl Default for VeilidConfigUDP {
/// public_address: ''
///
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidConfigTCP {
pub connect: bool,
pub listen: bool,
pub max_connections: u32,
pub listen_address: String,
#[cfg_attr(target_arch = "wasm32", tsify(optional))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional))]
pub public_address: Option<String>,
}
impl Default for VeilidConfigTCP {
fn default() -> Self {
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
let connect = false;
let listen = false;
} else {
@ -187,7 +187,7 @@ impl Default for VeilidConfigTCP {
/// url: 'ws://localhost:5150/ws'
///
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidConfigWS {
pub connect: bool,
@ -195,14 +195,14 @@ pub struct VeilidConfigWS {
pub max_connections: u32,
pub listen_address: String,
pub path: String,
#[cfg_attr(target_arch = "wasm32", tsify(optional))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional))]
pub url: Option<String>,
}
impl Default for VeilidConfigWS {
fn default() -> Self {
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
let connect = true;
let listen = false;
} else {
@ -233,7 +233,7 @@ impl Default for VeilidConfigWS {
/// url: ''
///
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidConfigWSS {
pub connect: bool,
@ -241,7 +241,7 @@ pub struct VeilidConfigWSS {
pub max_connections: u32,
pub listen_address: String,
pub path: String,
#[cfg_attr(target_arch = "wasm32", tsify(optional))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional))]
pub url: Option<String>, // Fixed URL is not optional for TLS-based protocols and is dynamically validated
}
@ -266,7 +266,7 @@ impl Default for VeilidConfigWSS {
/// sort out which protocol is used for each peer connection.
///
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidConfigProtocol {
pub udp: VeilidConfigUDP,
@ -284,7 +284,7 @@ pub struct VeilidConfigProtocol {
/// connection_initial_timeout_ms: 2000
///
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidConfigTLS {
pub certificate_path: String,
pub private_key_path: String,
@ -301,7 +301,7 @@ impl Default for VeilidConfigTLS {
}
}
#[cfg_attr(target_arch = "wasm32", allow(unused_variables))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), allow(unused_variables))]
pub fn get_default_ssl_directory(
program_name: &str,
organization: &str,
@ -309,7 +309,7 @@ pub fn get_default_ssl_directory(
sub_path: &str,
) -> String {
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
"".to_owned()
} else {
use std::path::PathBuf;
@ -327,7 +327,7 @@ pub fn get_default_ssl_directory(
/// If you change the count/fanout/timeout parameters, you may render your node inoperable
/// for correct DHT operations.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidConfigDHT {
pub max_find_node_count: u32,
pub resolve_node_timeout_ms: u32,
@ -356,7 +356,7 @@ pub struct VeilidConfigDHT {
impl Default for VeilidConfigDHT {
fn default() -> Self {
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
let local_subkey_cache_size = 128;
let local_max_subkey_cache_memory_mb = 256;
let remote_subkey_cache_size = 64;
@ -411,13 +411,13 @@ impl Default for VeilidConfigDHT {
/// Configure RPC.
///
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidConfigRPC {
pub concurrency: u32,
pub queue_size: u32,
#[cfg_attr(target_arch = "wasm32", tsify(optional))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional))]
pub max_timestamp_behind_ms: Option<u32>,
#[cfg_attr(target_arch = "wasm32", tsify(optional))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional))]
pub max_timestamp_ahead_ms: Option<u32>,
pub timeout_ms: u32,
pub max_route_hop_count: u8,
@ -441,7 +441,7 @@ impl Default for VeilidConfigRPC {
/// Configure the network routing table.
///
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidConfigRoutingTable {
#[schemars(with = "Vec<String>")]
pub node_id: TypedKeyGroup,
@ -460,7 +460,7 @@ pub struct VeilidConfigRoutingTable {
impl Default for VeilidConfigRoutingTable {
fn default() -> Self {
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
let bootstrap = vec!["ws://bootstrap.veilid.net:5150/ws".to_string()];
} else {
let bootstrap = vec!["bootstrap.veilid.net".to_string()];
@ -481,7 +481,7 @@ impl Default for VeilidConfigRoutingTable {
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidConfigNetwork {
pub connection_initial_timeout_ms: u32,
pub connection_inactivity_timeout_ms: u32,
@ -492,7 +492,7 @@ pub struct VeilidConfigNetwork {
pub client_allowlist_timeout_ms: u32,
pub reverse_connection_receipt_time_ms: u32,
pub hole_punch_receipt_time_ms: u32,
#[cfg_attr(target_arch = "wasm32", tsify(optional))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional))]
pub network_key_password: Option<String>,
pub routing_table: VeilidConfigRoutingTable,
pub rpc: VeilidConfigRPC,
@ -532,13 +532,13 @@ impl Default for VeilidConfigNetwork {
}
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidConfigTableStore {
pub directory: String,
pub delete: bool,
}
#[cfg_attr(target_arch = "wasm32", allow(unused_variables))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), allow(unused_variables))]
fn get_default_store_path(
program_name: &str,
organization: &str,
@ -546,7 +546,7 @@ fn get_default_store_path(
store_type: &str,
) -> String {
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
"".to_owned()
} else {
use std::path::PathBuf;
@ -561,7 +561,7 @@ fn get_default_store_path(
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidConfigBlockStore {
pub directory: String,
pub delete: bool,
@ -577,14 +577,14 @@ impl Default for VeilidConfigBlockStore {
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidConfigProtectedStore {
pub allow_insecure_fallback: bool,
pub always_use_insecure_storage: bool,
pub directory: String,
pub delete: bool,
pub device_encryption_key_password: String,
#[cfg_attr(target_arch = "wasm32", tsify(optional))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional))]
pub new_device_encryption_key_password: Option<String>,
}
@ -602,14 +602,14 @@ impl Default for VeilidConfigProtectedStore {
}
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidConfigCapabilities {
pub disable: Vec<FourCC>,
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(target_arch = "wasm32", tsify(namespace, from_wasm_abi))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(namespace, from_wasm_abi))]
pub enum VeilidConfigLogLevel {
Off,
Error,
@ -698,7 +698,7 @@ impl fmt::Display for VeilidConfigLogLevel {
/// Top level of the Veilid configuration tree
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidConfigInner {
/// An identifier used to describe the program using veilid-core.
/// Used to partition storage locations in places like the ProtectedStore.

View File

@ -1,5 +1,5 @@
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
pub use tsify::*;
pub use wasm_bindgen::prelude::*;

View File

@ -1,5 +1,5 @@
//! Test suite for the Web and headless browsers.
#![cfg(target_arch = "wasm32")]
#![cfg(all(target_arch = "wasm32", target_os = "unknown"))]
#![recursion_limit = "256"]
use parking_lot::Once;

View File

@ -50,7 +50,7 @@ tracing-flame = "0.2.0"
# Dependencies for native builds only
# Linux, Windows, Mac, iOS, Android
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
[target.'cfg(not(all(target_arch = "wasm32", target_os = "unknown")))'.dependencies]
tracing-opentelemetry = "0.21"
opentelemetry = { version = "0.20" }
opentelemetry-otlp = { version = "0.13" }
@ -68,7 +68,7 @@ libc-print = { version = "0.1.23", optional = true }
# Dependencies for WASM builds only
[target.'cfg(target_arch = "wasm32")'.dependencies]
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
# Dependencies for Android builds only
[target.'cfg(target_os = "android")'.dependencies]

View File

@ -75,7 +75,7 @@ flume = { version = "0.11.0", features = ["async"] }
# Dependencies for native builds only
# Linux, Windows, Mac, iOS, Android
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
[target.'cfg(not(all(target_arch = "wasm32", target_os = "unknown")))'.dependencies]
async-io = { version = "1.13.0" }
async-std = { version = "1.12.0", features = ["unstable"], optional = true }
chrono = "0.4.38"
@ -93,7 +93,7 @@ tokio-util = { version = "0.7.11", features = ["compat"], optional = true }
tokio-stream = { version = "0.1.15", features = ["net"], optional = true }
# Dependencies for WASM builds only
[target.'cfg(target_arch = "wasm32")'.dependencies]
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
wasm-bindgen = "0.2.92"
js-sys = "0.3.70"
wasm-bindgen-futures = "0.4.42"
@ -133,11 +133,11 @@ ifstructs = "0.1.1"
### DEV DEPENDENCIES
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
[target.'cfg(not(all(target_arch = "wasm32", target_os = "unknown")))'.dev-dependencies]
simplelog = { version = "0.12.2", features = ["test"] }
serial_test = "2.0.0"
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies]
serial_test = { version = "2.0.0", default-features = false, features = [
"async",
] }

View File

@ -1,7 +1,7 @@
use super::*;
cfg_if! {
if #[cfg(target_arch = "wasm32")] {
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
pub fn interval<F, FUT>(name: &str, freq_ms: u32, callback: F) -> SendPinBoxFuture<()>
where

View File

@ -42,13 +42,12 @@ pub mod ipc;
pub mod must_join_handle;
pub mod must_join_single_future;
pub mod mutable_future;
#[cfg(not(target_arch = "wasm32"))]
pub mod network_interfaces;
pub mod network_result;
pub mod random;
pub mod single_shot_eventual;
pub mod sleep;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
pub mod socket_tools;
pub mod spawn;
pub mod split_url;
@ -59,7 +58,7 @@ pub mod timeout_or;
pub mod timestamp;
pub mod tools;
pub mod virtual_network;
#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
pub mod wasm;
pub type PinBox<T> = Pin<Box<T>>;
@ -129,7 +128,7 @@ pub use async_lock::RwLockReadGuard as AsyncRwLockReadGuard;
pub use async_lock::RwLockWriteGuard as AsyncRwLockWriteGuard;
cfg_if! {
if #[cfg(target_arch = "wasm32")] {
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
#[doc(no_inline)]
pub use async_lock::Mutex as AsyncMutex;
#[doc(no_inline)]
@ -222,7 +221,6 @@ pub use must_join_single_future::*;
#[doc(inline)]
pub use mutable_future::*;
#[doc(inline)]
#[cfg(not(target_arch = "wasm32"))]
pub use network_interfaces::*;
#[doc(inline)]
pub use network_result::*;
@ -233,7 +231,7 @@ pub use single_shot_eventual::*;
#[doc(inline)]
pub use sleep::*;
#[doc(inline)]
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
pub use socket_tools::*;
#[doc(inline)]
pub use spawn::*;
@ -252,7 +250,7 @@ pub use timestamp::*;
#[doc(inline)]
pub use tools::*;
#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
pub use wasm::*;
// Tests must be public for wasm-pack tests

View File

@ -22,7 +22,7 @@ impl<T> MustJoinHandle<T> {
self.join_handle = None;
} else if #[cfg(feature="rt-tokio")] {
self.join_handle = None;
} else if #[cfg(target_arch = "wasm32")] {
} else if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
if let Some(jh) = self.join_handle.take() {
jh.detach();
}
@ -48,7 +48,7 @@ impl<T> MustJoinHandle<T> {
let _ = jh.await;
self.completed = true;
}
} else if #[cfg(target_arch = "wasm32")] {
} else if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
drop(self.join_handle.take());
self.completed = true;
} else {
@ -94,7 +94,7 @@ impl<T: 'static> Future for MustJoinHandle<T> {
}
}
}
} else if #[cfg(target_arch = "wasm32")] {
} else if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
Poll::Ready(t)
} else {
compile_error!("needs executor implementation");

View File

@ -19,6 +19,9 @@ cfg_if::cfg_if! {
mod openbsd;
mod sockaddr_tools;
use self::openbsd::PlatformSupportOpenBSD as PlatformSupport;
} else if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
mod wasm;
use self::wasm::PlatformSupportWasm as PlatformSupport;
} else {
compile_error!("No network interfaces support for this platform!");
}

View File

@ -0,0 +1,18 @@
use super::*;
use std::io;
pub struct PlatformSupportWasm {}
impl PlatformSupportWasm {
pub fn new() -> Self {
PlatformSupportWasm {}
}
pub async fn get_interfaces(
&mut self,
interfaces: &mut BTreeMap<String, NetworkInterface>,
) -> io::Result<()> {
interfaces.clear();
Ok(())
}
}

View File

@ -25,7 +25,7 @@ pub trait IoNetworkResultExt<T> {
}
fn io_error_kind_from_error<T>(e: io::Error) -> io::Result<NetworkResult<T>> {
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
if let Some(os_err) = e.raw_os_error() {
if os_err == libc::EHOSTUNREACH || os_err == libc::ENETUNREACH {
return Ok(NetworkResult::NoConnection(e));

View File

@ -2,7 +2,7 @@ use super::*;
use std::time::Duration;
cfg_if! {
if #[cfg(target_arch = "wasm32")] {
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
use async_executors::{Bindgen, Timer};
pub async fn sleep(millis: u32) {

View File

@ -1,7 +1,7 @@
use super::*;
cfg_if! {
if #[cfg(target_arch = "wasm32")] {
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
use async_executors::{Bindgen, LocalSpawnHandleExt, SpawnHandleExt};
pub fn spawn<Out>(_name: &str, future: impl Future<Output = Out> + Send + 'static) -> MustJoinHandle<Out>

View File

@ -1,7 +1,7 @@
use crate::*;
cfg_if! {
if #[cfg(target_arch = "wasm32")] {
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
use js_sys::*;
} else {
use std::time::{Duration, SystemTime};
@ -293,7 +293,7 @@ pub async fn test_timeout() {
pub async fn test_sleep() {
info!("testing sleep");
cfg_if! {
if #[cfg(target_arch = "wasm32")] {
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
let t1 = Date::now();
sleep(1000).await;
@ -548,7 +548,7 @@ pub async fn test_all() {
test_get_random_u64().await;
test_get_random_u32().await;
test_sleep().await;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
test_must_join_single_future().await;
test_eventual().await;
test_eventual_value().await;

View File

@ -3,7 +3,7 @@ mod android;
pub mod common;
#[cfg(all(target_os = "ios", feature = "veilid_tools_ios_tests"))]
mod ios;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
mod native;
#[allow(unused_imports)]

View File

@ -1,5 +1,5 @@
//! Test suite for Native
#![cfg(not(target_arch = "wasm32"))]
#![cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
mod test_assembly_buffer;
mod test_async_peek_stream;

View File

@ -1,7 +1,7 @@
use crate::*;
cfg_if! {
if #[cfg(not(target_arch = "wasm32"))] {
if #[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] {
use network_interfaces::NetworkInterfaces;
pub async fn test_network_interfaces() {
@ -24,6 +24,6 @@ cfg_if! {
}
pub async fn test_all() {
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
test_network_interfaces().await;
}

View File

@ -1,7 +1,7 @@
use super::*;
cfg_if! {
if #[cfg(target_arch = "wasm32")] {
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
use futures_util::future::{select, Either};
pub async fn timeout<F, T>(dur_ms: u32, f: F) -> Result<T, TimeoutError>

View File

@ -1,7 +1,7 @@
use super::*;
cfg_if! {
if #[cfg(target_arch = "wasm32")] {
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
use js_sys::Date;
pub fn get_timestamp() -> u64 {

View File

@ -115,7 +115,7 @@ pub fn system_boxed<'a, Out>(
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
cfg_if! {
if #[cfg(not(target_arch = "wasm32"))] {
if #[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] {
pub fn get_concurrency() -> u32 {
std::thread::available_parallelism()
.map(|x| x.get())
@ -259,7 +259,7 @@ pub fn compatible_unspecified_socket_addr(socket_addr: &SocketAddr) -> SocketAdd
}
cfg_if! {
if #[cfg(not(target_arch = "wasm32"))] {
if #[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] {
use std::net::UdpSocket;
static IPV6_IS_SUPPORTED: Mutex<Option<bool>> = Mutex::new(None);
@ -308,7 +308,7 @@ pub fn listen_address_to_socket_addrs(listen_address: &str) -> Result<Vec<Socket
format!("{}:0", listen_address)
};
cfg_if! {
if #[cfg(target_arch = "wasm32")] {
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
use core::str::FromStr;
vec![SocketAddr::from_str(&listen_address_with_port).map_err(|e| format!("Unable to parse address: {}",e))?]
} else {
@ -481,7 +481,7 @@ pub fn is_debug_backtrace_enabled() -> bool {
cfg_if! {
if #[cfg(debug_assertions)] {
cfg_if! {
if #[cfg(target_arch = "wasm32")] {
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
let rbenv = get_wasm_global_string_value("RUST_BACKTRACE").unwrap_or_default();
}
else

View File

@ -189,7 +189,7 @@ impl RouterClient {
//////////////////////////////////////////////////////////////////////////
// Public interface
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
pub async fn router_connect_tcp<H: ToSocketAddrs>(host: H) -> io::Result<RouterClient> {
let addrs = host.to_socket_addrs()?.collect::<Vec<_>>();
@ -241,11 +241,52 @@ impl RouterClient {
))
}
#[cfg(target_arch = "wasm32")]
pub async fn router_connect_ws<H: AsRef<str>>(host: H) -> io::Result<RouterClient> {
let host = host.as_ref();
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
pub async fn router_connect_ws<R: AsRef<str>>(request: R) -> io::Result<RouterClient> {
let request = request.as_ref();
Ok(RouterClient {})
// Connect to RouterServer
let wsio_reader;
let wsio_writer;
cfg_if! {
if #[cfg(feature="rt-wasm-bindgen")] {
use ws_stream_wasm::*;
let (_wsmeta, wsio) = WsMeta::connect(request, None)
.await.map_err(ws_err_to_io_error)?;
use futures_util::io::AsyncReadExt;
(wsio_reader, wsio_writer) = wsio.into_io().split();
} else {
compile_error!("must choose an executor");
}
}
// Create channels
let (client_sender, server_receiver) = flume::unbounded::<Bytes>();
// Create stopper
let stop_source = StopSource::new();
// Create router operation waiter
let router_op_waiter = RouterOpWaiter::new();
// Spawn a client connection handler
let jh_handler = spawn(
"RouterClient server processor",
Self::run_server_processor(
wsio_reader,
wsio_writer,
server_receiver,
router_op_waiter.clone(),
stop_source.token(),
),
);
Ok(Self::new(
client_sender,
router_op_waiter,
jh_handler,
stop_source,
))
}
pub async fn disconnect(self) {

View File

@ -1,7 +1,9 @@
use super::*;
use core::sync::atomic::{AtomicI8, AtomicU32, Ordering};
use js_sys::{global, Reflect};
use std::io;
use wasm_bindgen::prelude::*;
use ws_stream_wasm::WsErr;
#[wasm_bindgen]
extern "C" {
@ -89,3 +91,26 @@ pub fn get_concurrency() -> u32 {
res
}
pub fn ws_err_to_io_error(err: WsErr) -> io::Error {
match err {
WsErr::InvalidWsState { supplied: _ } => {
io::Error::new(io::ErrorKind::InvalidInput, err.to_string())
}
WsErr::ConnectionNotOpen => io::Error::new(io::ErrorKind::NotConnected, err.to_string()),
WsErr::InvalidUrl { supplied: _ } => {
io::Error::new(io::ErrorKind::InvalidInput, err.to_string())
}
WsErr::InvalidCloseCode { supplied: _ } => {
io::Error::new(io::ErrorKind::InvalidInput, err.to_string())
}
WsErr::ReasonStringToLong => io::Error::new(io::ErrorKind::InvalidInput, err.to_string()),
WsErr::ConnectionFailed { event: _ } => {
io::Error::new(io::ErrorKind::ConnectionRefused, err.to_string())
}
WsErr::InvalidEncoding => io::Error::new(io::ErrorKind::InvalidInput, err.to_string()),
WsErr::CantDecodeBlob => io::Error::new(io::ErrorKind::InvalidInput, err.to_string()),
WsErr::UnknownDataType => io::Error::new(io::ErrorKind::InvalidInput, err.to_string()),
_ => io::Error::new(io::ErrorKind::Other, err.to_string()),
}
}

View File

@ -1,5 +1,5 @@
//! Test suite for the Web and headless browsers.
#![cfg(target_arch = "wasm32")]
#![cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use cfg_if::*;
use parking_lot::Once;

View File

@ -2,7 +2,7 @@
#![deny(clippy::all)]
#![allow(clippy::comparison_chain, clippy::upper_case_acronyms)]
#![deny(unused_must_use)]
#![cfg(target_arch = "wasm32")]
#![cfg(all(target_arch = "wasm32", target_os = "unknown"))]
#![no_std]
/// Veilid WASM Bindings for Flutter/Dart, as well as Native Javascript
@ -142,7 +142,7 @@ where
// WASM-specific
#[derive(Debug, Deserialize, Serialize)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidWASMConfigLoggingPerformance {
pub enabled: bool,
pub level: veilid_core::VeilidConfigLogLevel,
@ -152,7 +152,7 @@ pub struct VeilidWASMConfigLoggingPerformance {
}
#[derive(Debug, Deserialize, Serialize)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidWASMConfigLoggingAPI {
pub enabled: bool,
pub level: veilid_core::VeilidConfigLogLevel,
@ -160,28 +160,35 @@ pub struct VeilidWASMConfigLoggingAPI {
}
#[derive(Debug, Deserialize, Serialize)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
pub struct VeilidWASMConfigLogging {
pub performance: VeilidWASMConfigLoggingPerformance,
pub api: VeilidWASMConfigLoggingAPI,
}
#[derive(Debug, Deserialize, Serialize)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(from_wasm_abi))]
#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown"),
derive(Tsify),
tsify(from_wasm_abi)
)]
pub struct VeilidWASMConfig {
pub logging: VeilidWASMConfigLogging,
}
#[derive(Debug, Deserialize, Serialize)]
#[cfg_attr(
target_arch = "wasm32",
all(target_arch = "wasm32", target_os = "unknown"),
derive(Tsify),
tsify(from_wasm_abi, into_wasm_abi)
)]
pub struct VeilidRouteBlob {
pub route_id: veilid_core::RouteId,
#[serde(with = "veilid_core::as_human_base64")]
#[cfg_attr(target_arch = "wasm32", tsify(type = "string"))]
#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown"),
tsify(type = "string")
)]
pub blob: Vec<u8>,
}
from_impl_to_jsvalue!(VeilidRouteBlob);
@ -1587,7 +1594,7 @@ pub fn veilid_version_string() -> String {
}
#[derive(Serialize)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))]
#[tsify(into_wasm_abi)]
pub struct VeilidVersion {
pub major: u32,

View File

@ -1,7 +1,7 @@
use super::*;
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
pub use wasm_bindgen::prelude::*;
macro_rules! from_impl_to_jsvalue {