Merge branch 'feature/veilid-config-refactor' into 'main'

Rename config structs, wasm now uses config object

See merge request veilid/veilid!402
This commit is contained in:
Christien Rioux 2025-05-06 12:29:16 -04:00
commit 287a071d1a
23 changed files with 149 additions and 258 deletions

View file

@ -5,6 +5,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<ValueSubkeyRangeSet> 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<Option<ValueSubkey>> 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
@ -31,6 +34,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:

View file

@ -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 {

View file

@ -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 {

View file

@ -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<Mutex<VeilidComponentRegistryInner>>,
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()));

View file

@ -30,7 +30,7 @@ impl VeilidCoreContext {
config_callback: ConfigCallback,
) -> VeilidAPIResult<VeilidCoreContext> {
// 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<VeilidCoreContext> {
// 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<VeilidCoreContext> {
async fn new_common(config: VeilidStartupOptions) -> VeilidAPIResult<VeilidCoreContext> {
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<VeilidAPI> {
// 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<VeilidAPI> {
// Get the program_name and namespace we're starting up in
let program_name = config.program_name.clone();

View file

@ -8,7 +8,7 @@ pub(crate) mod mock_registry {
pub(crate) async fn init<S: AsRef<str>>(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);

View file

@ -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,

View file

@ -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);

View file

@ -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::<Vec<_>>();
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 {

View file

@ -79,7 +79,7 @@ impl VeilidAPI {
// Public Accessors
/// Access the configuration that Veilid was initialized with.
pub fn config(&self) -> VeilidAPIResult<VeilidConfig> {
pub fn config(&self) -> VeilidAPIResult<VeilidStartupOptions> {
let inner = self.inner.lock();
let Some(context) = &inner.context else {
return Err(VeilidAPIError::NotInitialized);

View file

@ -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 {

View file

@ -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();

View file

@ -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

View file

@ -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<RwLock<VeilidConfigInner>>,
inner: Arc<RwLock<VeilidConfig>>,
}
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<Self> {
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<VeilidConfigInner> {
pub fn get(&self) -> RwLockReadGuard<VeilidConfig> {
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<F, R>(&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<F, R>(&self, f: F) -> VeilidAPIResult<R>
where
F: FnOnce(&mut VeilidConfigInner) -> VeilidAPIResult<R>,
F: FnOnce(&mut VeilidConfig) -> VeilidAPIResult<R>,
{
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())
}

View file

@ -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"
}
]
}

View file

@ -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": "<secret>"
},
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;
}

View file

@ -39,7 +39,7 @@ export async function startVeilid() {
veilidClient.startupCore(async (data) => {
veilidEventEmitter.emit(data.kind, data);
}, JSON.stringify(config));
}, config);
return veilidClient;
}

View file

@ -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()
}
}

View file

@ -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---");

View file

@ -18,7 +18,7 @@ describe('VeilidTable', () => {
// if (_update.kind === 'Log') {
// console.log(_update.message);
// }
}, JSON.stringify(veilidCoreStartupConfig));
}, veilidCoreStartupConfig);
});
after('veilid shutdown', async () => {

View file

@ -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;

View file

@ -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 () {

View file

@ -15,7 +15,7 @@ describe('veilidCrypto', () => {
// if (_update.kind === 'Log') {
// console.log(_update.message);
// }
}, JSON.stringify(veilidCoreStartupConfig));
}, veilidCoreStartupConfig);
});
after('veilid shutdown', async () => {