From 7ce7e1e7f2ad6a5f9af23d0036c5f725af01c225 Mon Sep 17 00:00:00 2001 From: Brandon Vandegrift <798832-bmv437@users.noreply.gitlab.com> Date: Sat, 3 May 2025 17:16:44 -0400 Subject: [PATCH] Rename config structs, wasm now uses config object --- CHANGELOG.md | 7 + README-pt_BR.md | 4 +- README.md | 4 +- veilid-core/src/component.rs | 6 +- veilid-core/src/core_context.rs | 12 +- veilid-core/src/routing_table/tests/mod.rs | 2 +- veilid-core/src/storage_manager/mod.rs | 4 +- .../src/tests/common/test_veilid_config.rs | 7 +- .../src/tests/common/test_veilid_core.rs | 4 +- veilid-core/src/veilid_api/api.rs | 2 +- veilid-core/src/veilid_api/tests/fixtures.rs | 4 +- .../src/veilid_api/tests/test_types.rs | 4 +- .../src/veilid_api/types/veilid_state.rs | 2 +- veilid-core/src/veilid_config.rs | 40 +++--- veilid-python/veilid/schema/RecvMessage.json | 130 ++++++++--------- .../test-bench/src/veilid/veilid-config.ts | 136 +----------------- .../test-bench/src/veilid/veilid-core.ts | 2 +- veilid-wasm/src/veilid_client_js.rs | 9 +- .../tests/src/VeilidRoutingContext.test.ts | 2 +- veilid-wasm/tests/src/VeilidTable.test.ts | 2 +- veilid-wasm/tests/src/utils/veilid-config.ts | 2 +- veilid-wasm/tests/src/veilidClient.test.ts | 20 +-- veilid-wasm/tests/src/veilidCrypto.test.ts | 2 +- 23 files changed, 149 insertions(+), 258 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 545ef2cd..2b51a361 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ - watch_dht_values() now returns a bool rather than an expiration timestamp. Expiration renewal is now managed by veilid-core internally. Apps no longer need to renew watches! - inspect_dht_record() and cancel_dht_watch() now take an Option instead of just a ValueSubkeyRangeSet, to make things easier for automatic binding generation someday and to remove ambiguities about the semantics of the default empty set. - DHTRecordReport now uses a Vec> for seq lists, rather than using the 'ValueSubkey::MAX' sentinel value (0xFFFFFFFF) to represent a missing subkey + - Renamed config structs to better describe their purpose, and remove "Inner" from a struct that's being exposed via the API. ([!402](https://gitlab.com/veilid/veilid/-/merge_requests/402)) + - `VeilidConfig` -> `VeilidStartupOptions` + - `VeilidConfigInner` -> `VeilidConfig` - veilid-core: - Allow shutdown even if tables are closed @@ -30,6 +33,10 @@ - veilid-wasm: - **Breaking** Properly generate TypeScript types for `ValueSubkeyRangeSet`, which would previously resolve to `any`. This is breaking since it can cause type errors to correctly surface in existing applications. ([!397](https://gitlab.com/veilid/veilid/-/merge_requests/397)) + - **Breaking** `starupCore()` and `defaultConfig()` now use config objects instead of stringified JSON. + - `veilidClient.startupCore(callback, JSON.stringify(config))` now becomes `veilidClient.startupCore(callback, config)`. ([!402](https://gitlab.com/veilid/veilid/-/merge_requests/402)) + - `JSON.parse(veilidClient.defaultConfig())` is now `veilidClient.defaultConfig()` + - The `VeilidConfigInner` type is now `VeilidConfig`. - Expose the isShutdown API: https://gitlab.com/veilid/veilid/-/merge_requests/392 - CI: diff --git a/README-pt_BR.md b/README-pt_BR.md index f2ee033c..5e4996fd 100644 --- a/README-pt_BR.md +++ b/README-pt_BR.md @@ -28,7 +28,7 @@ Um exemplo básico usando `veilid-core` e `tokio` se parece com o abaixo. ```rust use std::sync::Arc; use veilid_core::VeilidUpdate::{AppMessage, Network}; -use veilid_core::{VeilidConfigBlockStore, VeilidConfigInner, VeilidConfigProtectedStore, VeilidConfigTableStore, VeilidUpdate}; +use veilid_core::{VeilidConfigBlockStore, VeilidConfig, VeilidConfigProtectedStore, VeilidConfigTableStore, VeilidUpdate}; #[tokio::main] async fn main() { @@ -46,7 +46,7 @@ async fn main() { }; }); - let config = VeilidConfigInner { + let config = VeilidConfig { program_name: "Example Veilid".into(), namespace: "veilid-example".into(), protected_store: VeilidConfigProtectedStore { diff --git a/README.md b/README.md index bede35a7..36dc2695 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ A basic example using `veilid-core` and `tokio` might look like this. ```rust use std::sync::Arc; use veilid_core::VeilidUpdate::{AppMessage, Network}; -use veilid_core::{VeilidConfigBlockStore, VeilidConfigInner, VeilidConfigProtectedStore, VeilidConfigTableStore, VeilidUpdate}; +use veilid_core::{VeilidConfigBlockStore, VeilidConfig, VeilidConfigProtectedStore, VeilidConfigTableStore, VeilidUpdate}; #[tokio::main] async fn main() { @@ -45,7 +45,7 @@ async fn main() { }; }); - let config = VeilidConfigInner { + let config = VeilidConfig { program_name: "Example Veilid".into(), namespace: "veilid-example".into(), protected_store: VeilidConfigProtectedStore { diff --git a/veilid-core/src/component.rs b/veilid-core/src/component.rs index 1f367d47..e7946dd7 100644 --- a/veilid-core/src/component.rs +++ b/veilid-core/src/component.rs @@ -25,7 +25,7 @@ pub(crate) trait VeilidComponent: pub(crate) trait VeilidComponentRegistryAccessor { fn registry(&self) -> VeilidComponentRegistry; - fn config(&self) -> VeilidConfig { + fn config(&self) -> VeilidStartupOptions { self.registry().config.clone() } fn update_callback(&self) -> UpdateCallback { @@ -65,7 +65,7 @@ struct VeilidComponentRegistryInner { #[derive(Clone, Debug)] pub(crate) struct VeilidComponentRegistry { inner: Arc>, - config: VeilidConfig, + config: VeilidStartupOptions, namespace: &'static str, program_name: &'static str, log_key: &'static str, @@ -74,7 +74,7 @@ pub(crate) struct VeilidComponentRegistry { } impl VeilidComponentRegistry { - pub fn new(config: VeilidConfig) -> Self { + pub fn new(config: VeilidStartupOptions) -> Self { let (namespace, program_name) = config.with(|c| (c.namespace.to_static_str(), c.program_name.to_static_str())); diff --git a/veilid-core/src/core_context.rs b/veilid-core/src/core_context.rs index 8a7efb50..1c27f667 100644 --- a/veilid-core/src/core_context.rs +++ b/veilid-core/src/core_context.rs @@ -30,7 +30,7 @@ impl VeilidCoreContext { config_callback: ConfigCallback, ) -> VeilidAPIResult { // Set up config from callback - let config = VeilidConfig::new_from_callback(config_callback, update_callback)?; + let config = VeilidStartupOptions::new_from_callback(config_callback, update_callback)?; Self::new_common(config).await } @@ -38,15 +38,15 @@ impl VeilidCoreContext { #[instrument(level = "trace", target = "core_context", err, skip_all)] async fn new_with_config( update_callback: UpdateCallback, - config_inner: VeilidConfigInner, + config_inner: VeilidConfig, ) -> VeilidAPIResult { // Set up config from json - let config = VeilidConfig::new_from_config(config_inner, update_callback); + let config = VeilidStartupOptions::new_from_config(config_inner, update_callback); Self::new_common(config).await } #[instrument(level = "trace", target = "core_context", err, skip_all)] - async fn new_common(config: VeilidConfig) -> VeilidAPIResult { + async fn new_common(config: VeilidStartupOptions) -> VeilidAPIResult { cfg_if! { if #[cfg(target_os = "android")] { if !crate::intf::android::is_android_ready() { @@ -260,7 +260,7 @@ pub async fn api_startup_json( config_json: String, ) -> VeilidAPIResult { // Parse the JSON config - let config: VeilidConfigInner = + let config: VeilidConfig = serde_json::from_str(&config_json).map_err(VeilidAPIError::generic)?; api_startup_config(update_callback, config).await @@ -277,7 +277,7 @@ pub async fn api_startup_json( #[instrument(level = "trace", target = "core_context", err, skip_all)] pub async fn api_startup_config( update_callback: UpdateCallback, - config: VeilidConfigInner, + config: VeilidConfig, ) -> VeilidAPIResult { // Get the program_name and namespace we're starting up in let program_name = config.program_name.clone(); diff --git a/veilid-core/src/routing_table/tests/mod.rs b/veilid-core/src/routing_table/tests/mod.rs index a855c58c..fbe11c3f 100644 --- a/veilid-core/src/routing_table/tests/mod.rs +++ b/veilid-core/src/routing_table/tests/mod.rs @@ -8,7 +8,7 @@ pub(crate) mod mock_registry { pub(crate) async fn init>(namespace: S) -> VeilidComponentRegistry { let (update_callback, config_callback) = setup_veilid_core_with_namespace(namespace); let veilid_config = - VeilidConfig::new_from_callback(config_callback, update_callback).unwrap(); + VeilidStartupOptions::new_from_callback(config_callback, update_callback).unwrap(); let registry = VeilidComponentRegistry::new(veilid_config); registry.enable_mock(); registry.register(ProtectedStore::new); diff --git a/veilid-core/src/storage_manager/mod.rs b/veilid-core/src/storage_manager/mod.rs index 4d3066c9..18eb2218 100644 --- a/veilid-core/src/storage_manager/mod.rs +++ b/veilid-core/src/storage_manager/mod.rs @@ -217,7 +217,7 @@ impl StorageManager { this } - fn local_limits_from_config(config: VeilidConfig) -> RecordStoreLimits { + fn local_limits_from_config(config: VeilidStartupOptions) -> RecordStoreLimits { let c = config.get(); RecordStoreLimits { subkey_cache_size: c.network.dht.local_subkey_cache_size as usize, @@ -237,7 +237,7 @@ impl StorageManager { } } - fn remote_limits_from_config(config: VeilidConfig) -> RecordStoreLimits { + fn remote_limits_from_config(config: VeilidStartupOptions) -> RecordStoreLimits { let c = config.get(); RecordStoreLimits { subkey_cache_size: c.network.dht.remote_subkey_cache_size as usize, diff --git a/veilid-core/src/tests/common/test_veilid_config.rs b/veilid-core/src/tests/common/test_veilid_config.rs index 3f729e6e..67782d86 100644 --- a/veilid-core/src/tests/common/test_veilid_config.rs +++ b/veilid-core/src/tests/common/test_veilid_config.rs @@ -297,8 +297,11 @@ pub fn config_callback(key: String) -> ConfigCallbackReturn { } } -pub fn get_config() -> VeilidConfig { - match VeilidConfig::new_from_callback(Arc::new(config_callback), Arc::new(update_callback)) { +pub fn get_config() -> VeilidStartupOptions { + match VeilidStartupOptions::new_from_callback( + Arc::new(config_callback), + Arc::new(update_callback), + ) { Ok(vc) => vc, Err(e) => { error!("Error: {}", e); diff --git a/veilid-core/src/tests/common/test_veilid_core.rs b/veilid-core/src/tests/common/test_veilid_core.rs index e0a4812f..68b085f0 100644 --- a/veilid-core/src/tests/common/test_veilid_core.rs +++ b/veilid-core/src/tests/common/test_veilid_core.rs @@ -26,7 +26,7 @@ pub async fn test_startup_shutdown() { pub async fn test_startup_shutdown_from_config() { trace!("test_startup_from_config: starting"); - let config = VeilidConfigInner { + let config = VeilidConfig { program_name: "VeilidCoreTests".into(), table_store: VeilidConfigTableStore { directory: get_table_store_path(), @@ -111,7 +111,7 @@ pub async fn test_startup_shutdown_from_config_multiple() { let namespaces = (0..3).map(|x| format!("ns_{}", x)).collect::>(); let mut apis = vec![]; for ns in &namespaces { - let config = VeilidConfigInner { + let config = VeilidConfig { program_name: "VeilidCoreTests".into(), namespace: ns.to_owned(), table_store: VeilidConfigTableStore { diff --git a/veilid-core/src/veilid_api/api.rs b/veilid-core/src/veilid_api/api.rs index 5e1fb4bb..d38f6d38 100644 --- a/veilid-core/src/veilid_api/api.rs +++ b/veilid-core/src/veilid_api/api.rs @@ -79,7 +79,7 @@ impl VeilidAPI { // Public Accessors /// Access the configuration that Veilid was initialized with. - pub fn config(&self) -> VeilidAPIResult { + pub fn config(&self) -> VeilidAPIResult { let inner = self.inner.lock(); let Some(context) = &inner.context else { return Err(VeilidAPIError::NotInitialized); diff --git a/veilid-core/src/veilid_api/tests/fixtures.rs b/veilid-core/src/veilid_api/tests/fixtures.rs index d94e70ab..1dafe55f 100644 --- a/veilid-core/src/veilid_api/tests/fixtures.rs +++ b/veilid-core/src/veilid_api/tests/fixtures.rs @@ -113,8 +113,8 @@ pub fn fix_peertabledata() -> PeerTableData { } } -pub fn fix_veilidconfiginner() -> VeilidConfigInner { - VeilidConfigInner { +pub fn fix_veilidconfig() -> VeilidConfig { + VeilidConfig { program_name: "Bob".to_string(), namespace: "Internets".to_string(), capabilities: VeilidConfigCapabilities { diff --git a/veilid-core/src/veilid_api/tests/test_types.rs b/veilid-core/src/veilid_api/tests/test_types.rs index 71cc1a26..5a1c46e7 100644 --- a/veilid-core/src/veilid_api/tests/test_types.rs +++ b/veilid-core/src/veilid_api/tests/test_types.rs @@ -252,7 +252,7 @@ pub fn test_veilidroutechange() { pub fn test_veilidstateconfig() { let orig = VeilidStateConfig { - config: fix_veilidconfiginner(), + config: fix_veilidconfig(), }; let copy = deserialize_json(&serialize_json(&orig)).unwrap(); @@ -289,7 +289,7 @@ pub fn test_veilidstate() { peers: vec![fix_peertabledata()], }), config: Box::new(VeilidStateConfig { - config: fix_veilidconfiginner(), + config: fix_veilidconfig(), }), }; let copy = deserialize_json(&serialize_json(&orig)).unwrap(); diff --git a/veilid-core/src/veilid_api/types/veilid_state.rs b/veilid-core/src/veilid_api/types/veilid_state.rs index 5a8225c9..4886d2de 100644 --- a/veilid-core/src/veilid_api/types/veilid_state.rs +++ b/veilid-core/src/veilid_api/types/veilid_state.rs @@ -152,7 +152,7 @@ pub struct VeilidRouteChange { #[must_use] pub struct VeilidStateConfig { /// If the Veilid node configuration has changed the full new config will be here. - pub config: VeilidConfigInner, + pub config: VeilidConfig, } /// Describe when DHT records have subkey values changed diff --git a/veilid-core/src/veilid_config.rs b/veilid-core/src/veilid_config.rs index 0269a783..ed1149ff 100644 --- a/veilid-core/src/veilid_config.rs +++ b/veilid-core/src/veilid_config.rs @@ -774,8 +774,12 @@ impl fmt::Display for VeilidConfigLogLevel { /// Top level of the Veilid configuration tree #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] +#[cfg_attr( + all(target_arch = "wasm32", target_os = "unknown"), + tsify(into_wasm_abi, from_wasm_abi) +)] #[must_use] -pub struct VeilidConfigInner { +pub struct VeilidConfig { /// An identifier used to describe the program using veilid-core. /// Used to partition storage locations in places like the ProtectedStore. /// Must be non-empty and a valid filename for all Veilid-capable systems, which means @@ -805,8 +809,8 @@ pub struct VeilidConfigInner { pub network: VeilidConfigNetwork, } -impl VeilidConfigInner { - /// Create a new 'VeilidConfigInner' for use with `setup_from_config` +impl VeilidConfig { + /// Create a new 'VeilidConfig' for use with `setup_from_config` /// Should match the application bundle name if used elsewhere in the format: /// `qualifier.organization.program_name` - for example `org.veilid.veilidchat` /// @@ -815,7 +819,7 @@ impl VeilidConfigInner { /// specified to override this location /// /// * `program_name` - Pick a program name and do not change it from release to release, - /// see `VeilidConfigInner::program_name` for details. + /// see `VeilidConfig::program_name` for details. /// * `organization_name` - Similar to program_name, but for the organization publishing this app /// * `qualifier` - Suffix for the application bundle name /// * `storage_directory` - Override for the path where veilid-core stores its content @@ -883,12 +887,12 @@ impl VeilidConfigInner { /// The configuration built for each Veilid node during API startup #[derive(Clone)] #[must_use] -pub struct VeilidConfig { +pub struct VeilidStartupOptions { update_cb: UpdateCallback, - inner: Arc>, + inner: Arc>, } -impl fmt::Debug for VeilidConfig { +impl fmt::Debug for VeilidStartupOptions { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let inner = self.inner.read(); f.debug_struct("VeilidConfig") @@ -897,8 +901,8 @@ impl fmt::Debug for VeilidConfig { } } -impl VeilidConfig { - pub(crate) fn new_from_config(config: VeilidConfigInner, update_cb: UpdateCallback) -> Self { +impl VeilidStartupOptions { + pub(crate) fn new_from_config(config: VeilidConfig, update_cb: UpdateCallback) -> Self { Self { update_cb, inner: Arc::new(RwLock::new(config)), @@ -928,7 +932,7 @@ impl VeilidConfig { cb: ConfigCallback, update_cb: UpdateCallback, ) -> VeilidAPIResult { - let mut inner = VeilidConfigInner::default(); + let mut inner = VeilidConfig::default(); // Simple config transformation macro_rules! get_config { @@ -1058,11 +1062,11 @@ impl VeilidConfig { self.update_cb.clone() } - pub fn get(&self) -> RwLockReadGuard { + pub fn get(&self) -> RwLockReadGuard { self.inner.read() } - fn safe_config_inner(&self) -> VeilidConfigInner { + fn safe_config_inner(&self) -> VeilidConfig { let mut safe_cfg = self.inner.read().clone(); // Remove secrets @@ -1073,7 +1077,7 @@ impl VeilidConfig { safe_cfg } - pub fn safe_config(&self) -> VeilidConfig { + pub fn safe_config(&self) -> VeilidStartupOptions { let mut safe_cfg = self.inner.read().clone(); // Remove secrets @@ -1081,7 +1085,7 @@ impl VeilidConfig { "".clone_into(&mut safe_cfg.protected_store.device_encryption_key_password); safe_cfg.protected_store.new_device_encryption_key_password = None; - VeilidConfig { + VeilidStartupOptions { update_cb: self.update_cb.clone(), inner: Arc::new(RwLock::new(safe_cfg)), } @@ -1089,7 +1093,7 @@ impl VeilidConfig { pub fn with(&self, f: F) -> R where - F: FnOnce(&VeilidConfigInner) -> R, + F: FnOnce(&VeilidConfig) -> R, { let inner = self.inner.read(); f(&inner) @@ -1097,7 +1101,7 @@ impl VeilidConfig { pub fn try_with_mut(&self, f: F) -> VeilidAPIResult where - F: FnOnce(&mut VeilidConfigInner) -> VeilidAPIResult, + F: FnOnce(&mut VeilidConfig) -> VeilidAPIResult, { let out = { let inner = &mut *self.inner.write(); @@ -1227,7 +1231,7 @@ impl VeilidConfig { Ok(()) } - fn validate(inner: &VeilidConfigInner) -> VeilidAPIResult<()> { + fn validate(inner: &VeilidConfig) -> VeilidAPIResult<()> { Self::validate_program_name(&inner.program_name)?; Self::validate_namespace(&inner.namespace)?; @@ -1335,5 +1339,5 @@ impl VeilidConfig { /// Return the default veilid config as a json object. #[must_use] pub fn default_veilid_config() -> String { - serialize_json(VeilidConfigInner::default()) + serialize_json(VeilidConfig::default()) } diff --git a/veilid-python/veilid/schema/RecvMessage.json b/veilid-python/veilid/schema/RecvMessage.json index 4862fc78..34aabbb8 100644 --- a/veilid-python/veilid/schema/RecvMessage.json +++ b/veilid-python/veilid/schema/RecvMessage.json @@ -2716,7 +2716,7 @@ "description": "If the Veilid node configuration has changed the full new config will be here.", "allOf": [ { - "$ref": "#/definitions/VeilidConfigInner" + "$ref": "#/definitions/VeilidConfig" } ] }, @@ -3954,6 +3954,69 @@ } ] }, + "VeilidConfig": { + "description": "Top level of the Veilid configuration tree", + "type": "object", + "required": [ + "block_store", + "capabilities", + "namespace", + "network", + "program_name", + "protected_store", + "table_store" + ], + "properties": { + "block_store": { + "description": "Configuring the block store (storage of large content-addressable content)", + "allOf": [ + { + "$ref": "#/definitions/VeilidConfigBlockStore" + } + ] + }, + "capabilities": { + "description": "Capabilities to enable for your application/node", + "allOf": [ + { + "$ref": "#/definitions/VeilidConfigCapabilities" + } + ] + }, + "namespace": { + "description": "To run multiple Veilid nodes within the same application, either through a single process running api_startup/api_startup_json multiple times, or your application running mulitple times side-by-side there needs to be a key used to partition the application's storage (in the TableStore, ProtectedStore, etc). An empty value here is the default, but if you run multiple veilid nodes concurrently, you should set this to a string that uniquely identifies this -instance- within the same 'program_name'. Must be a valid filename for all Veilid-capable systems, which means no backslashes or forward slashes in the name. Stick to a-z,0-9,_ and space and you should be fine.", + "type": "string" + }, + "network": { + "description": "Configuring how Veilid interacts with the low level network", + "allOf": [ + { + "$ref": "#/definitions/VeilidConfigNetwork" + } + ] + }, + "program_name": { + "description": "An identifier used to describe the program using veilid-core. Used to partition storage locations in places like the ProtectedStore. Must be non-empty and a valid filename for all Veilid-capable systems, which means no backslashes or forward slashes in the name. Stick to a-z,0-9,_ and space and you should be fine.\n\nCaution: If you change this string, there is no migration support. Your app's protected store and table store will very likely experience data loss. Pick a program name and stick with it. This is not a 'visible' identifier and it should uniquely identify your application.", + "type": "string" + }, + "protected_store": { + "description": "Configuring the protected store (keychain/keyring/etc)", + "allOf": [ + { + "$ref": "#/definitions/VeilidConfigProtectedStore" + } + ] + }, + "table_store": { + "description": "Configuring the table store (persistent encrypted database)", + "allOf": [ + { + "$ref": "#/definitions/VeilidConfigTableStore" + } + ] + } + } + }, "VeilidConfigApplication": { "description": "Application configuration.\n\nConfigure web access to the Progressive Web App (PWA).\n\nTo be implemented...", "type": "object", @@ -4191,69 +4254,6 @@ } } }, - "VeilidConfigInner": { - "description": "Top level of the Veilid configuration tree", - "type": "object", - "required": [ - "block_store", - "capabilities", - "namespace", - "network", - "program_name", - "protected_store", - "table_store" - ], - "properties": { - "block_store": { - "description": "Configuring the block store (storage of large content-addressable content)", - "allOf": [ - { - "$ref": "#/definitions/VeilidConfigBlockStore" - } - ] - }, - "capabilities": { - "description": "Capabilities to enable for your application/node", - "allOf": [ - { - "$ref": "#/definitions/VeilidConfigCapabilities" - } - ] - }, - "namespace": { - "description": "To run multiple Veilid nodes within the same application, either through a single process running api_startup/api_startup_json multiple times, or your application running mulitple times side-by-side there needs to be a key used to partition the application's storage (in the TableStore, ProtectedStore, etc). An empty value here is the default, but if you run multiple veilid nodes concurrently, you should set this to a string that uniquely identifies this -instance- within the same 'program_name'. Must be a valid filename for all Veilid-capable systems, which means no backslashes or forward slashes in the name. Stick to a-z,0-9,_ and space and you should be fine.", - "type": "string" - }, - "network": { - "description": "Configuring how Veilid interacts with the low level network", - "allOf": [ - { - "$ref": "#/definitions/VeilidConfigNetwork" - } - ] - }, - "program_name": { - "description": "An identifier used to describe the program using veilid-core. Used to partition storage locations in places like the ProtectedStore. Must be non-empty and a valid filename for all Veilid-capable systems, which means no backslashes or forward slashes in the name. Stick to a-z,0-9,_ and space and you should be fine.\n\nCaution: If you change this string, there is no migration support. Your app's protected store and table store will very likely experience data loss. Pick a program name and stick with it. This is not a 'visible' identifier and it should uniquely identify your application.", - "type": "string" - }, - "protected_store": { - "description": "Configuring the protected store (keychain/keyring/etc)", - "allOf": [ - { - "$ref": "#/definitions/VeilidConfigProtectedStore" - } - ] - }, - "table_store": { - "description": "Configuring the table store (persistent encrypted database)", - "allOf": [ - { - "$ref": "#/definitions/VeilidConfigTableStore" - } - ] - } - } - }, "VeilidConfigNetwork": { "type": "object", "required": [ @@ -4779,7 +4779,7 @@ "description": "If the Veilid node configuration has changed the full new config will be here.", "allOf": [ { - "$ref": "#/definitions/VeilidConfigInner" + "$ref": "#/definitions/VeilidConfig" } ] } diff --git a/veilid-wasm/example/test-bench/src/veilid/veilid-config.ts b/veilid-wasm/example/test-bench/src/veilid/veilid-config.ts index 091afd73..65478164 100644 --- a/veilid-wasm/example/test-bench/src/veilid/veilid-config.ts +++ b/veilid-wasm/example/test-bench/src/veilid/veilid-config.ts @@ -1,4 +1,4 @@ -import { VeilidConfigInner, VeilidWASMConfig } from 'veilid-wasm'; +import { veilidClient, VeilidWASMConfig } from 'veilid-wasm'; export interface VeilidConfigOptions { namespace: string; password: string; @@ -22,133 +22,11 @@ export const veildCoreInitConfig: VeilidWASMConfig = { }; export function getVeilidCoreStartupConfig(options: VeilidConfigOptions) { - const config: VeilidConfigInner = { - program_name: 'veilid-wasm-test-bench', - namespace: options.namespace, - capabilities: { - disable: [], - }, - protected_store: { - allow_insecure_fallback: true, - always_use_insecure_storage: true, - directory: '', - delete: false, - device_encryption_key_password: options.password, - // "new_device_encryption_key_password": "" - }, - table_store: { - directory: 'table_store', - delete: false, - }, - block_store: { - directory: 'block_store', - delete: false, - }, - network: { - connection_initial_timeout_ms: 2000, - connection_inactivity_timeout_ms: 60000, - max_connections_per_ip4: 32, - max_connections_per_ip6_prefix: 32, - max_connections_per_ip6_prefix_size: 56, - max_connection_frequency_per_min: 128, - client_allowlist_timeout_ms: 300000, - reverse_connection_receipt_time_ms: 5000, - hole_punch_receipt_time_ms: 5000, - network_key_password: '', - routing_table: { - node_id: [], - node_id_secret: [], - bootstrap: [ - 'ws://bootstrap.veilid.net:5150/ws' - ], - limit_over_attached: 64, - limit_fully_attached: 32, - limit_attached_strong: 16, - limit_attached_good: 8, - limit_attached_weak: 4, - }, - rpc: { - concurrency: 8, - queue_size: 1024, - max_timestamp_behind_ms: 10000, - max_timestamp_ahead_ms: 10000, - timeout_ms: 10000, - max_route_hop_count: 4, - default_route_hop_count: 1, - }, - dht: { - max_find_node_count: 20, - resolve_node_timeout_ms: 10000, - resolve_node_count: 1, - resolve_node_fanout: 4, - get_value_timeout_ms: 10000, - get_value_count: 3, - get_value_fanout: 4, - set_value_timeout_ms: 10000, - set_value_count: 5, - set_value_fanout: 4, - min_peer_count: 20, - min_peer_refresh_time_ms: 60000, - validate_dial_info_receipt_time_ms: 2000, - local_subkey_cache_size: 128, - local_max_subkey_cache_memory_mb: 256, - remote_subkey_cache_size: 0, - remote_max_records: 0, - remote_max_subkey_cache_memory_mb: 0, - remote_max_storage_space_mb: 0, - public_watch_limit: 32, - member_watch_limit: 32, - max_watch_expiration_ms: 600000, - }, - upnp: true, - detect_address_changes: true, - restricted_nat_retries: 0, - tls: { - certificate_path: '', - private_key_path: '', - connection_initial_timeout_ms: 2000, - }, - application: { - https: { - enabled: false, - listen_address: ':5150', - path: 'app', - }, - http: { - enabled: false, - listen_address: ':5150', - path: 'app', - }, - }, - protocol: { - udp: { - enabled: false, - socket_pool_size: 0, - listen_address: '', - }, - tcp: { - connect: false, - listen: false, - max_connections: 32, - listen_address: '', - }, - ws: { - connect: true, - listen: true, - max_connections: 128, - listen_address: ':5150', - path: 'ws', - }, - wss: { - connect: true, - listen: false, - max_connections: 32, - listen_address: '', - path: 'ws', - }, - }, - }, - }; + const defaultConfig = veilidClient.defaultConfig(); - return config; + defaultConfig.program_name = 'veilid-wasm-test-bench'; + defaultConfig.namespace = options.namespace; + defaultConfig.protected_store.device_encryption_key_password = options.password; + + return defaultConfig; } diff --git a/veilid-wasm/example/test-bench/src/veilid/veilid-core.ts b/veilid-wasm/example/test-bench/src/veilid/veilid-core.ts index 92161490..55ab208f 100644 --- a/veilid-wasm/example/test-bench/src/veilid/veilid-core.ts +++ b/veilid-wasm/example/test-bench/src/veilid/veilid-core.ts @@ -39,7 +39,7 @@ export async function startVeilid() { veilidClient.startupCore(async (data) => { veilidEventEmitter.emit(data.kind, data); - }, JSON.stringify(config)); + }, config); return veilidClient; } diff --git a/veilid-wasm/src/veilid_client_js.rs b/veilid-wasm/src/veilid_client_js.rs index 9f09789d..ff3b9764 100644 --- a/veilid-wasm/src/veilid_client_js.rs +++ b/veilid-wasm/src/veilid_client_js.rs @@ -81,7 +81,7 @@ impl VeilidClient { /// @param {string} json_config - called at startup to supply a JSON configuration object. pub async fn startupCore( update_callback_js: UpdateVeilidFunction, - json_config: String, + config: VeilidConfig, ) -> APIResult<()> { let update_callback_js = SendWrapper::new(update_callback_js); let update_callback = Arc::new(move |update: VeilidUpdate| { @@ -102,7 +102,7 @@ impl VeilidClient { return APIResult::Err(veilid_core::VeilidAPIError::AlreadyInitialized); } - let veilid_api = veilid_core::api_startup_json(update_callback, json_config).await?; + let veilid_api = veilid_core::api_startup_config(update_callback, config).await?; VEILID_API.replace(Some(veilid_api)); APIRESULT_UNDEFINED } @@ -220,8 +220,7 @@ impl VeilidClient { } /// Return the default veilid configuration, in string format - #[must_use] - pub fn defaultConfig() -> String { - veilid_core::default_veilid_config() + pub fn defaultConfig() -> VeilidConfig { + VeilidConfig::default() } } diff --git a/veilid-wasm/tests/src/VeilidRoutingContext.test.ts b/veilid-wasm/tests/src/VeilidRoutingContext.test.ts index e8a43263..bd49e3fb 100644 --- a/veilid-wasm/tests/src/VeilidRoutingContext.test.ts +++ b/veilid-wasm/tests/src/VeilidRoutingContext.test.ts @@ -21,7 +21,7 @@ describe('VeilidRoutingContext', () => { // if (_update.kind === 'Log') { // console.log(_update.message); // } - }, JSON.stringify(veilidCoreStartupConfig)); + }, veilidCoreStartupConfig); await veilidClient.attach(); await asyncCallWithTimeout(waitForPublicAttachment(), 10000); //console.log("---Started Up---"); diff --git a/veilid-wasm/tests/src/VeilidTable.test.ts b/veilid-wasm/tests/src/VeilidTable.test.ts index a157ff9c..f19f0f4a 100644 --- a/veilid-wasm/tests/src/VeilidTable.test.ts +++ b/veilid-wasm/tests/src/VeilidTable.test.ts @@ -18,7 +18,7 @@ describe('VeilidTable', () => { // if (_update.kind === 'Log') { // console.log(_update.message); // } - }, JSON.stringify(veilidCoreStartupConfig)); + }, veilidCoreStartupConfig); }); after('veilid shutdown', async () => { diff --git a/veilid-wasm/tests/src/utils/veilid-config.ts b/veilid-wasm/tests/src/utils/veilid-config.ts index b9ce4691..1b3d6eb2 100644 --- a/veilid-wasm/tests/src/utils/veilid-config.ts +++ b/veilid-wasm/tests/src/utils/veilid-config.ts @@ -19,7 +19,7 @@ export const veilidCoreInitConfig: VeilidWASMConfig = { }; export var veilidCoreStartupConfig = (() => { - var defaultConfig = JSON.parse(veilidClient.defaultConfig()); + var defaultConfig = veilidClient.defaultConfig(); defaultConfig.program_name = 'veilid-wasm-test'; // Ensure we are starting from scratch defaultConfig.table_store.delete = true; diff --git a/veilid-wasm/tests/src/veilidClient.test.ts b/veilid-wasm/tests/src/veilidClient.test.ts index 56d5701a..2ea76b70 100644 --- a/veilid-wasm/tests/src/veilidClient.test.ts +++ b/veilid-wasm/tests/src/veilidClient.test.ts @@ -15,7 +15,7 @@ describe('veilidClient', function () { // if (_update.kind === 'Log') { // console.log(_update.message); // } - }, JSON.stringify(veilidCoreStartupConfig)); + }, veilidCoreStartupConfig); }); after('veilid shutdown', async function () { @@ -35,17 +35,17 @@ describe('veilidClient', function () { expect(features.length).toBeGreaterThan(0); }); - it('should get config string', async function () { + it('should get config', async function () { const defaultConfig = veilidClient.defaultConfig(); - expect(typeof defaultConfig).toBe('string'); - expect(defaultConfig.length).toBeGreaterThan(0); + expect(typeof defaultConfig).toBe('object'); - const cfgObject1 = JSON.parse(defaultConfig); - const defaultConfigStr = JSON.stringify(cfgObject1); - const cfgObject2 = JSON.parse(defaultConfigStr); - const defaultConfigStr2 = JSON.stringify(cfgObject2); - - expect(defaultConfigStr).toEqual(defaultConfigStr2); + expect(defaultConfig).toHaveProperty('program_name'); + expect(defaultConfig).toHaveProperty('namespace'); + expect(defaultConfig).toHaveProperty('capabilities'); + expect(defaultConfig).toHaveProperty('protected_store'); + expect(defaultConfig).toHaveProperty('table_store'); + expect(defaultConfig).toHaveProperty('block_store'); + expect(defaultConfig).toHaveProperty('network'); }); it('should attach and detach', async function () { diff --git a/veilid-wasm/tests/src/veilidCrypto.test.ts b/veilid-wasm/tests/src/veilidCrypto.test.ts index 00d1a49d..90a6fc9d 100644 --- a/veilid-wasm/tests/src/veilidCrypto.test.ts +++ b/veilid-wasm/tests/src/veilidCrypto.test.ts @@ -15,7 +15,7 @@ describe('veilidCrypto', () => { // if (_update.kind === 'Log') { // console.log(_update.message); // } - }, JSON.stringify(veilidCoreStartupConfig)); + }, veilidCoreStartupConfig); }); after('veilid shutdown', async () => {