mirror of
https://gitlab.com/veilid/veilid.git
synced 2024-10-01 01:26:08 -04:00
add default veilid config to the api
This commit is contained in:
parent
31bb8018f6
commit
8818e63dc0
@ -88,6 +88,11 @@ pub fn veilid_version() -> (u32, u32, u32) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the default veilid config as a json object
|
||||||
|
pub fn default_veilid_config() -> String {
|
||||||
|
serialize_json(VeilidConfigInner::default())
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
pub use intf::android::veilid_core_setup_android;
|
pub use intf::android::veilid_core_setup_android;
|
||||||
|
|
||||||
|
@ -120,6 +120,7 @@ pub enum RequestOp {
|
|||||||
},
|
},
|
||||||
VeilidVersionString,
|
VeilidVersionString,
|
||||||
VeilidVersion,
|
VeilidVersion,
|
||||||
|
DefaultVeilidConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||||
@ -230,6 +231,9 @@ pub enum ResponseOp {
|
|||||||
minor: u32,
|
minor: u32,
|
||||||
patch: u32,
|
patch: u32,
|
||||||
},
|
},
|
||||||
|
DefaultVeilidConfig {
|
||||||
|
value: String,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||||
|
@ -792,6 +792,9 @@ impl JsonRequestProcessor {
|
|||||||
patch,
|
patch,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
RequestOp::DefaultVeilidConfig => ResponseOp::DefaultVeilidConfig {
|
||||||
|
value: default_veilid_config(),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Response { id, op }
|
Response { id, op }
|
||||||
|
@ -58,10 +58,9 @@ int getRemoteMaxStorageSpaceMb() {
|
|||||||
return 256;
|
return 256;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<VeilidConfig> getDefaultVeilidConfig(String programName) async {
|
Future<VeilidConfig> getDefaultVeilidConfig(String programName,
|
||||||
// ignore: do_not_use_environment
|
{String bootstrap = ''}) async =>
|
||||||
const bootstrap = String.fromEnvironment('BOOTSTRAP');
|
VeilidConfig(
|
||||||
return VeilidConfig(
|
|
||||||
programName: programName,
|
programName: programName,
|
||||||
namespace: '',
|
namespace: '',
|
||||||
capabilities: const VeilidConfigCapabilities(disable: []),
|
capabilities: const VeilidConfigCapabilities(disable: []),
|
||||||
@ -137,7 +136,8 @@ Future<VeilidConfig> getDefaultVeilidConfig(String programName) async {
|
|||||||
localMaxSubkeyCacheMemoryMb: await getLocalMaxSubkeyCacheMemoryMb(),
|
localMaxSubkeyCacheMemoryMb: await getLocalMaxSubkeyCacheMemoryMb(),
|
||||||
remoteSubkeyCacheSize: getRemoteSubkeyCacheSize(),
|
remoteSubkeyCacheSize: getRemoteSubkeyCacheSize(),
|
||||||
remoteMaxRecords: getRemoteMaxRecords(),
|
remoteMaxRecords: getRemoteMaxRecords(),
|
||||||
remoteMaxSubkeyCacheMemoryMb: await getRemoteMaxSubkeyCacheMemoryMb(),
|
remoteMaxSubkeyCacheMemoryMb:
|
||||||
|
await getRemoteMaxSubkeyCacheMemoryMb(),
|
||||||
remoteMaxStorageSpaceMb: getRemoteMaxStorageSpaceMb(),
|
remoteMaxStorageSpaceMb: getRemoteMaxStorageSpaceMb(),
|
||||||
publicWatchLimit: 32,
|
publicWatchLimit: 32,
|
||||||
memberWatchLimit: 8,
|
memberWatchLimit: 8,
|
||||||
@ -190,4 +190,3 @@ Future<VeilidConfig> getDefaultVeilidConfig(String programName) async {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
@ -162,5 +162,6 @@ abstract class Veilid {
|
|||||||
Timestamp now();
|
Timestamp now();
|
||||||
String veilidVersionString();
|
String veilidVersionString();
|
||||||
VeilidVersion veilidVersion();
|
VeilidVersion veilidVersion();
|
||||||
|
String defaultVeilidConfig();
|
||||||
Future<String> debug(String command);
|
Future<String> debug(String command);
|
||||||
}
|
}
|
||||||
|
@ -235,6 +235,9 @@ final class VeilidVersionFFI extends Struct {
|
|||||||
|
|
||||||
typedef _VeilidVersionDart = VeilidVersionFFI Function();
|
typedef _VeilidVersionDart = VeilidVersionFFI Function();
|
||||||
|
|
||||||
|
// fn default_veilid_config() -> *mut c_char
|
||||||
|
typedef _DefaultVeilidConfigDart = Pointer<Utf8> Function();
|
||||||
|
|
||||||
// Async message types
|
// Async message types
|
||||||
const int messageOk = 0;
|
const int messageOk = 0;
|
||||||
const int messageErr = 1;
|
const int messageErr = 1;
|
||||||
@ -1388,7 +1391,9 @@ class VeilidFFI extends Veilid {
|
|||||||
_veilidVersionString = dylib.lookupFunction<Pointer<Utf8> Function(),
|
_veilidVersionString = dylib.lookupFunction<Pointer<Utf8> Function(),
|
||||||
_VeilidVersionStringDart>('veilid_version_string'),
|
_VeilidVersionStringDart>('veilid_version_string'),
|
||||||
_veilidVersion = dylib.lookupFunction<VeilidVersionFFI Function(),
|
_veilidVersion = dylib.lookupFunction<VeilidVersionFFI Function(),
|
||||||
_VeilidVersionDart>('veilid_version') {
|
_VeilidVersionDart>('veilid_version'),
|
||||||
|
_defaultVeilidConfig = dylib.lookupFunction<Pointer<Utf8> Function(),
|
||||||
|
_DefaultVeilidConfigDart>('default_veilid_config') {
|
||||||
// Get veilid_flutter initializer
|
// Get veilid_flutter initializer
|
||||||
final initializeVeilidFlutter = _dylib.lookupFunction<
|
final initializeVeilidFlutter = _dylib.lookupFunction<
|
||||||
Void Function(Pointer<_DartPostCObject>),
|
Void Function(Pointer<_DartPostCObject>),
|
||||||
@ -1481,6 +1486,7 @@ class VeilidFFI extends Veilid {
|
|||||||
final _DebugDart _debug;
|
final _DebugDart _debug;
|
||||||
final _VeilidVersionStringDart _veilidVersionString;
|
final _VeilidVersionStringDart _veilidVersionString;
|
||||||
final _VeilidVersionDart _veilidVersion;
|
final _VeilidVersionDart _veilidVersion;
|
||||||
|
final _DefaultVeilidConfigDart _defaultVeilidConfig;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initializeVeilidCore(Map<String, dynamic> platformConfigJson) {
|
void initializeVeilidCore(Map<String, dynamic> platformConfigJson) {
|
||||||
@ -1714,4 +1720,12 @@ class VeilidFFI extends Veilid {
|
|||||||
version.patch,
|
version.patch,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String defaultVeilidConfig() {
|
||||||
|
final defaultVeilidConfig = _defaultVeilidConfig();
|
||||||
|
final ret = defaultVeilidConfig.toDartString();
|
||||||
|
_freeString(defaultVeilidConfig);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -705,4 +705,8 @@ class VeilidJS extends Veilid {
|
|||||||
return VeilidVersion(jsonVersion['major'] as int,
|
return VeilidVersion(jsonVersion['major'] as int,
|
||||||
jsonVersion['minor'] as int, jsonVersion['patch'] as int);
|
jsonVersion['minor'] as int, jsonVersion['patch'] as int);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String defaultVeilidConfig() =>
|
||||||
|
js_util.callMethod(wasm, 'default_veilid_config', []);
|
||||||
}
|
}
|
||||||
|
@ -1765,3 +1765,8 @@ pub extern "C" fn veilid_version() -> VeilidVersion {
|
|||||||
patch,
|
patch,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn default_veilid_config() -> *mut c_char {
|
||||||
|
veilid_core::default_veilid_config().into_ffi_value()
|
||||||
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
# Basic veilid tests
|
# Basic veilid tests
|
||||||
|
|
||||||
import socket
|
import socket
|
||||||
|
import json
|
||||||
|
import dataclasses
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import veilid
|
import veilid
|
||||||
@ -40,3 +42,19 @@ async def test_version(api_connection: veilid.VeilidAPI):
|
|||||||
|
|
||||||
vstr = await api_connection.veilid_version_string()
|
vstr = await api_connection.veilid_version_string()
|
||||||
print(f"veilid_version_string: {vstr}")
|
print(f"veilid_version_string: {vstr}")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_config(api_connection: veilid.VeilidAPI):
|
||||||
|
cfgstr = await api_connection.default_veilid_config()
|
||||||
|
print(f"default_veilid_config:\n{cfgstr}")
|
||||||
|
cfgjson = json.loads(cfgstr)
|
||||||
|
|
||||||
|
veilidConfigInstance = veilid.VeilidConfig(**cfgjson)
|
||||||
|
cfgstr2 = json.dumps(dataclasses.asdict(veilidConfigInstance))
|
||||||
|
|
||||||
|
cfgjson2 = json.loads(cfgstr2)
|
||||||
|
veilidConfigInstance2 = veilid.VeilidConfig(**cfgjson2)
|
||||||
|
|
||||||
|
assert veilidConfigInstance == veilidConfigInstance2
|
||||||
|
|
||||||
|
@ -396,3 +396,7 @@ class VeilidAPI(ABC):
|
|||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def veilid_version(self) -> types.VeilidVersion:
|
async def veilid_version(self) -> types.VeilidVersion:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
async def default_veilid_config(self) -> str:
|
||||||
|
pass
|
||||||
|
@ -432,6 +432,9 @@ class _JsonVeilidAPI(VeilidAPI):
|
|||||||
v = await self.send_ndjson_request(Operation.VEILID_VERSION)
|
v = await self.send_ndjson_request(Operation.VEILID_VERSION)
|
||||||
return VeilidVersion(v["major"], v["minor"], v["patch"])
|
return VeilidVersion(v["major"], v["minor"], v["patch"])
|
||||||
|
|
||||||
|
async def default_veilid_config(self) -> str:
|
||||||
|
return raise_api_result(await self.send_ndjson_request(Operation.DEFAULT_VEILID_CONFIG))
|
||||||
|
|
||||||
|
|
||||||
######################################################
|
######################################################
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ class Operation(StrEnum):
|
|||||||
DEBUG = "Debug"
|
DEBUG = "Debug"
|
||||||
VEILID_VERSION_STRING = "VeilidVersionString"
|
VEILID_VERSION_STRING = "VeilidVersionString"
|
||||||
VEILID_VERSION = "VeilidVersion"
|
VEILID_VERSION = "VeilidVersion"
|
||||||
|
DEFAULT_VEILID_CONFIG = "DefaultVeilidConfig"
|
||||||
|
|
||||||
|
|
||||||
class RoutingContextOperation(StrEnum):
|
class RoutingContextOperation(StrEnum):
|
||||||
|
@ -2349,6 +2349,24 @@
|
|||||||
"minimum": 0.0
|
"minimum": 0.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"op",
|
||||||
|
"value"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"op": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"DefaultVeilidConfig"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"value": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"required": [
|
"required": [
|
||||||
|
@ -1499,6 +1499,20 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"op"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"op": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"DefaultVeilidConfig"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
|
@ -1624,3 +1624,8 @@ pub fn veilid_version() -> JsValue {
|
|||||||
};
|
};
|
||||||
<JsValue as JsValueSerdeExt>::from_serde(&vv).unwrap()
|
<JsValue as JsValueSerdeExt>::from_serde(&vv).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen()]
|
||||||
|
pub fn default_veilid_config() -> String {
|
||||||
|
veilid_core::default_veilid_config()
|
||||||
|
}
|
||||||
|
@ -178,4 +178,9 @@ impl VeilidClient {
|
|||||||
pub fn versionString() -> String {
|
pub fn versionString() -> String {
|
||||||
veilid_core::veilid_version_string()
|
veilid_core::veilid_version_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the default veilid configuration in json string format.
|
||||||
|
pub fn defaultConfig() -> String {
|
||||||
|
veilid_core::default_veilid_config()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,19 @@ describe('veilidClient', () => {
|
|||||||
expect(version.length).toBeGreaterThan(0);
|
expect(version.length).toBeGreaterThan(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should get config string', async () => {
|
||||||
|
const defaultConfig = veilidClient.defaultConfig();
|
||||||
|
expect(typeof defaultConfig).toBe('string');
|
||||||
|
expect(defaultConfig.length).toBeGreaterThan(0);
|
||||||
|
|
||||||
|
const cfgObject1 = JSON.parse(defaultConfig);
|
||||||
|
const defaultConfigStr = JSON.stringify(cfgObject1);
|
||||||
|
const cfgObject2 = JSON.parse(defaultConfigStr);
|
||||||
|
const defaultConfigStr2 = JSON.stringify(cfgObject2);
|
||||||
|
|
||||||
|
expect(defaultConfigStr).toEqual(defaultConfigStr2);
|
||||||
|
});
|
||||||
|
|
||||||
it('should attach and detach', async () => {
|
it('should attach and detach', async () => {
|
||||||
await veilidClient.attach();
|
await veilidClient.attach();
|
||||||
await waitForMs(2000);
|
await waitForMs(2000);
|
||||||
|
Loading…
Reference in New Issue
Block a user