mirror of
https://gitlab.com/veilid/veilid.git
synced 2025-07-26 16:35:24 -04:00
Merge branch 'feature/expose-is-shutdown-api' into 'main'
Expose the is_shutdown API to all bindings See merge request veilid/veilid!392
This commit is contained in:
commit
bff7a0c718
17 changed files with 135 additions and 2 deletions
|
@ -19,10 +19,15 @@
|
||||||
- veilid-flutter:
|
- veilid-flutter:
|
||||||
- Bindings updated for API changes
|
- Bindings updated for API changes
|
||||||
- Corrosion version in cmake build for linux and windows updated to 0.5.1: https://gitlab.com/veilid/veilid/-/issues/447
|
- Corrosion version in cmake build for linux and windows updated to 0.5.1: https://gitlab.com/veilid/veilid/-/issues/447
|
||||||
|
- Expose the isShutdown API: https://gitlab.com/veilid/veilid/-/merge_requests/392
|
||||||
|
|
||||||
- veilid-python:
|
- veilid-python:
|
||||||
- Fix type assertion bug in watch_dht_values
|
- Fix type assertion bug in watch_dht_values
|
||||||
- Update watchvalue integration tests
|
- Update watchvalue integration tests
|
||||||
|
- Expose the is_shutdown API: https://gitlab.com/veilid/veilid/-/merge_requests/392
|
||||||
|
|
||||||
|
- veilid-wasm:
|
||||||
|
- Expose the isShutdown API: https://gitlab.com/veilid/veilid/-/merge_requests/392
|
||||||
|
|
||||||
**Changed in Veilid 0.4.4**
|
**Changed in Veilid 0.4.4**
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,20 @@ pub async fn test_startup_shutdown() {
|
||||||
let api = api_startup(update_callback, config_callback)
|
let api = api_startup(update_callback, config_callback)
|
||||||
.await
|
.await
|
||||||
.expect("startup failed");
|
.expect("startup failed");
|
||||||
|
|
||||||
|
// Test initial state
|
||||||
|
assert!(!api.is_shutdown(), "API should not be shut down initially");
|
||||||
|
|
||||||
trace!("test_startup_shutdown: shutting down");
|
trace!("test_startup_shutdown: shutting down");
|
||||||
|
let api_clone = api.clone();
|
||||||
api.shutdown().await;
|
api.shutdown().await;
|
||||||
|
|
||||||
|
// Test state after shutdown
|
||||||
|
assert!(
|
||||||
|
api_clone.is_shutdown(),
|
||||||
|
"API should be shut down after shutdown()"
|
||||||
|
);
|
||||||
|
|
||||||
trace!("test_startup_shutdown: finished");
|
trace!("test_startup_shutdown: finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@ pub enum RequestOp {
|
||||||
args: Vec<String>,
|
args: Vec<String>,
|
||||||
},
|
},
|
||||||
GetState,
|
GetState,
|
||||||
|
IsShutdown,
|
||||||
Attach,
|
Attach,
|
||||||
Detach,
|
Detach,
|
||||||
NewPrivateRoute,
|
NewPrivateRoute,
|
||||||
|
@ -143,6 +144,9 @@ pub enum ResponseOp {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
result: ApiResult<Box<VeilidState>>,
|
result: ApiResult<Box<VeilidState>>,
|
||||||
},
|
},
|
||||||
|
IsShutdown {
|
||||||
|
value: bool,
|
||||||
|
},
|
||||||
Attach {
|
Attach {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
result: ApiResult<()>,
|
result: ApiResult<()>,
|
||||||
|
|
|
@ -619,6 +619,9 @@ impl JsonRequestProcessor {
|
||||||
RequestOp::GetState => ResponseOp::GetState {
|
RequestOp::GetState => ResponseOp::GetState {
|
||||||
result: to_json_api_result(self.api.get_state().await.map(Box::new)),
|
result: to_json_api_result(self.api.get_state().await.map(Box::new)),
|
||||||
},
|
},
|
||||||
|
RequestOp::IsShutdown => ResponseOp::IsShutdown {
|
||||||
|
value: self.api.is_shutdown(),
|
||||||
|
},
|
||||||
RequestOp::Attach => ResponseOp::Attach {
|
RequestOp::Attach => ResponseOp::Attach {
|
||||||
result: to_json_api_result(self.api.attach().await),
|
result: to_json_api_result(self.api.attach().await),
|
||||||
},
|
},
|
||||||
|
|
|
@ -137,6 +137,7 @@ abstract class Veilid {
|
||||||
void changeLogIgnore(String layer, List<String> changes);
|
void changeLogIgnore(String layer, List<String> changes);
|
||||||
Future<Stream<VeilidUpdate>> startupVeilidCore(VeilidConfig config);
|
Future<Stream<VeilidUpdate>> startupVeilidCore(VeilidConfig config);
|
||||||
Future<VeilidState> getVeilidState();
|
Future<VeilidState> getVeilidState();
|
||||||
|
Future<bool> isShutdown();
|
||||||
Future<void> attach();
|
Future<void> attach();
|
||||||
Future<void> detach();
|
Future<void> detach();
|
||||||
Future<void> shutdownVeilidCore();
|
Future<void> shutdownVeilidCore();
|
||||||
|
|
|
@ -38,6 +38,8 @@ typedef _ChangeLogIgnoreDart = void Function(Pointer<Utf8>, Pointer<Utf8>);
|
||||||
typedef _StartupVeilidCoreDart = void Function(int, int, Pointer<Utf8>);
|
typedef _StartupVeilidCoreDart = void Function(int, int, Pointer<Utf8>);
|
||||||
// fn get_veilid_state(port: i64)
|
// fn get_veilid_state(port: i64)
|
||||||
typedef _GetVeilidStateDart = void Function(int);
|
typedef _GetVeilidStateDart = void Function(int);
|
||||||
|
// fn is_shutdown(port: i64)
|
||||||
|
typedef _IsShutdownDart = void Function(int);
|
||||||
// fn attach(port: i64)
|
// fn attach(port: i64)
|
||||||
typedef _AttachDart = void Function(int);
|
typedef _AttachDart = void Function(int);
|
||||||
// fn detach(port: i64)
|
// fn detach(port: i64)
|
||||||
|
@ -1255,6 +1257,8 @@ class VeilidFFI extends Veilid {
|
||||||
_startupVeilidCore = dylib.lookupFunction<
|
_startupVeilidCore = dylib.lookupFunction<
|
||||||
Void Function(Int64, Int64, Pointer<Utf8>),
|
Void Function(Int64, Int64, Pointer<Utf8>),
|
||||||
_StartupVeilidCoreDart>('startup_veilid_core'),
|
_StartupVeilidCoreDart>('startup_veilid_core'),
|
||||||
|
_isShutdown = dylib.lookupFunction<Void Function(Int64), _IsShutdownDart>(
|
||||||
|
'is_shutdown'),
|
||||||
_getVeilidState =
|
_getVeilidState =
|
||||||
dylib.lookupFunction<Void Function(Int64), _GetVeilidStateDart>(
|
dylib.lookupFunction<Void Function(Int64), _GetVeilidStateDart>(
|
||||||
'get_veilid_state'),
|
'get_veilid_state'),
|
||||||
|
@ -1494,6 +1498,7 @@ class VeilidFFI extends Veilid {
|
||||||
final _ChangeLogIgnoreDart _changeLogIgnore;
|
final _ChangeLogIgnoreDart _changeLogIgnore;
|
||||||
final _StartupVeilidCoreDart _startupVeilidCore;
|
final _StartupVeilidCoreDart _startupVeilidCore;
|
||||||
final _GetVeilidStateDart _getVeilidState;
|
final _GetVeilidStateDart _getVeilidState;
|
||||||
|
final _IsShutdownDart _isShutdown;
|
||||||
final _AttachDart _attach;
|
final _AttachDart _attach;
|
||||||
final _DetachDart _detach;
|
final _DetachDart _detach;
|
||||||
final _ShutdownVeilidCoreDart _shutdownVeilidCore;
|
final _ShutdownVeilidCoreDart _shutdownVeilidCore;
|
||||||
|
@ -1627,6 +1632,14 @@ class VeilidFFI extends Veilid {
|
||||||
return processFutureJson(VeilidState.fromJson, recvPort.first);
|
return processFutureJson(VeilidState.fromJson, recvPort.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<bool> isShutdown() async {
|
||||||
|
final recvPort = ReceivePort('is_shutdown');
|
||||||
|
final sendPort = recvPort.sendPort;
|
||||||
|
_isShutdown(sendPort.nativePort);
|
||||||
|
return processFuturePlain<bool>(recvPort.first);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> attach() async {
|
Future<void> attach() async {
|
||||||
final recvPort = ReceivePort('attach');
|
final recvPort = ReceivePort('attach');
|
||||||
|
|
|
@ -627,6 +627,11 @@ class VeilidJS extends Veilid {
|
||||||
VeilidState.fromJson(jsonDecode(await _wrapApiPromise<String>(
|
VeilidState.fromJson(jsonDecode(await _wrapApiPromise<String>(
|
||||||
js_util.callMethod(wasm, 'get_veilid_state', []))));
|
js_util.callMethod(wasm, 'get_veilid_state', []))));
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<bool> isShutdown() async =>
|
||||||
|
await _wrapApiPromise<bool>(
|
||||||
|
js_util.callMethod(wasm, 'is_shutdown', []));
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> attach() =>
|
Future<void> attach() =>
|
||||||
_wrapApiPromise(js_util.callMethod(wasm, 'attach', []));
|
_wrapApiPromise(js_util.callMethod(wasm, 'attach', []));
|
||||||
|
|
|
@ -475,6 +475,23 @@ pub extern "C" fn get_veilid_state(port: i64) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
#[instrument(level = "trace", target = "ffi", skip_all)]
|
||||||
|
pub extern "C" fn is_shutdown(port: i64) {
|
||||||
|
DartIsolateWrapper::new(port).spawn_result(
|
||||||
|
async move {
|
||||||
|
let veilid_api = get_veilid_api().await;
|
||||||
|
if let Err(veilid_core::VeilidAPIError::NotInitialized) = veilid_api {
|
||||||
|
return APIResult::Ok(true);
|
||||||
|
}
|
||||||
|
let veilid_api = veilid_api.unwrap();
|
||||||
|
let is_shutdown = veilid_api.is_shutdown();
|
||||||
|
APIResult::Ok(is_shutdown)
|
||||||
|
}
|
||||||
|
.in_current_span(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
#[instrument(level = "trace", target = "ffi", skip_all)]
|
#[instrument(level = "trace", target = "ffi", skip_all)]
|
||||||
pub extern "C" fn attach(port: i64) {
|
pub extern "C" fn attach(port: i64) {
|
||||||
|
|
|
@ -374,6 +374,10 @@ class VeilidAPI(ABC):
|
||||||
async def get_state(self) -> VeilidState:
|
async def get_state(self) -> VeilidState:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
async def is_shutdown(self) -> bool:
|
||||||
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def attach(self):
|
async def attach(self):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -324,6 +324,9 @@ class _JsonVeilidAPI(VeilidAPI):
|
||||||
raise_api_result(await self.send_ndjson_request(Operation.GET_STATE))
|
raise_api_result(await self.send_ndjson_request(Operation.GET_STATE))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def is_shutdown(self) -> bool:
|
||||||
|
return raise_api_result(await self.send_ndjson_request(Operation.IS_SHUTDOWN))
|
||||||
|
|
||||||
async def attach(self):
|
async def attach(self):
|
||||||
raise_api_result(await self.send_ndjson_request(Operation.ATTACH))
|
raise_api_result(await self.send_ndjson_request(Operation.ATTACH))
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ from typing import Self
|
||||||
class Operation(StrEnum):
|
class Operation(StrEnum):
|
||||||
CONTROL = "Control"
|
CONTROL = "Control"
|
||||||
GET_STATE = "GetState"
|
GET_STATE = "GetState"
|
||||||
|
IS_SHUTDOWN = "IsShutdown"
|
||||||
ATTACH = "Attach"
|
ATTACH = "Attach"
|
||||||
DETACH = "Detach"
|
DETACH = "Detach"
|
||||||
NEW_PRIVATE_ROUTE = "NewPrivateRoute"
|
NEW_PRIVATE_ROUTE = "NewPrivateRoute"
|
||||||
|
|
|
@ -81,6 +81,24 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"op",
|
||||||
|
"value"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"op": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"IsShutdown"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"value": {
|
||||||
|
"type": "boolean"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"anyOf": [
|
"anyOf": [
|
||||||
|
|
|
@ -38,6 +38,20 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"op"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"op": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"IsShutdown"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
|
|
|
@ -326,6 +326,17 @@ pub fn get_veilid_state() -> Promise {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen()]
|
||||||
|
pub fn is_shutdown() -> APIResult<bool> {
|
||||||
|
let veilid_api = get_veilid_api();
|
||||||
|
if let Err(veilid_core::VeilidAPIError::NotInitialized) = veilid_api {
|
||||||
|
return APIResult::Ok(true);
|
||||||
|
}
|
||||||
|
let veilid_api = veilid_api.unwrap();
|
||||||
|
let is_shutdown = veilid_api.is_shutdown();
|
||||||
|
APIResult::Ok(is_shutdown)
|
||||||
|
}
|
||||||
|
|
||||||
#[wasm_bindgen()]
|
#[wasm_bindgen()]
|
||||||
pub fn attach() -> Promise {
|
pub fn attach() -> Promise {
|
||||||
wrap_api_future_void(async move {
|
wrap_api_future_void(async move {
|
||||||
|
|
|
@ -162,6 +162,17 @@ impl VeilidClient {
|
||||||
APIRESULT_UNDEFINED
|
APIRESULT_UNDEFINED
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check if Veilid is shutdown.
|
||||||
|
pub fn isShutdown() -> APIResult<bool> {
|
||||||
|
let veilid_api = get_veilid_api();
|
||||||
|
if let Err(veilid_core::VeilidAPIError::NotInitialized) = veilid_api {
|
||||||
|
return APIResult::Ok(true);
|
||||||
|
}
|
||||||
|
let veilid_api = veilid_api.unwrap();
|
||||||
|
let is_shutdown = veilid_api.is_shutdown();
|
||||||
|
APIResult::Ok(is_shutdown)
|
||||||
|
}
|
||||||
|
|
||||||
/// Get a full copy of the current state of Veilid.
|
/// Get a full copy of the current state of Veilid.
|
||||||
pub async fn getState() -> APIResult<VeilidState> {
|
pub async fn getState() -> APIResult<VeilidState> {
|
||||||
let veilid_api = get_veilid_api()?;
|
let veilid_api = get_veilid_api()?;
|
||||||
|
|
|
@ -60,6 +60,16 @@ export const waitForDetached = async () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const waitForShutdown = async () => {
|
||||||
|
while (true) {
|
||||||
|
let isShutdown = veilidClient.isShutdown();
|
||||||
|
if (isShutdown) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
await waitForMs(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const waitForOfflineSubkeyWrite = async (routingContext: VeilidRoutingContext, key: TypedKey) => {
|
export const waitForOfflineSubkeyWrite = async (routingContext: VeilidRoutingContext, key: TypedKey) => {
|
||||||
while ((await routingContext.inspectDhtRecord(key)).offline_subkeys.length != 0) {
|
while ((await routingContext.inspectDhtRecord(key)).offline_subkeys.length != 0) {
|
||||||
await waitForMs(200);
|
await waitForMs(200);
|
||||||
|
|
|
@ -5,8 +5,8 @@ import {
|
||||||
veilidCoreStartupConfig,
|
veilidCoreStartupConfig,
|
||||||
} from './utils/veilid-config';
|
} from './utils/veilid-config';
|
||||||
|
|
||||||
import { VeilidState, veilidClient } from '../../pkg/veilid_wasm';
|
import { VeilidState, veilidClient } from 'veilid-wasm';
|
||||||
import { asyncCallWithTimeout, waitForDetached, waitForPublicAttachment } from './utils/wait-utils';
|
import { asyncCallWithTimeout, waitForDetached, waitForPublicAttachment, waitForShutdown } from './utils/wait-utils';
|
||||||
|
|
||||||
describe('veilidClient', function () {
|
describe('veilidClient', function () {
|
||||||
before('veilid startup', async function () {
|
before('veilid startup', async function () {
|
||||||
|
@ -20,6 +20,7 @@ describe('veilidClient', function () {
|
||||||
|
|
||||||
after('veilid shutdown', async function () {
|
after('veilid shutdown', async function () {
|
||||||
await veilidClient.shutdownCore();
|
await veilidClient.shutdownCore();
|
||||||
|
await asyncCallWithTimeout(waitForShutdown(), 10000);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should print version', async function () {
|
it('should print version', async function () {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue