From 52ac599008466c415b90da759dab62d21fa05684 Mon Sep 17 00:00:00 2001 From: neequ57 Date: Sat, 19 Oct 2024 15:18:26 +0000 Subject: [PATCH] Add "uptime" debug command --- DEVELOPMENT.md | 20 ++ veilid-core/src/attachment_manager.rs | 17 + veilid-core/src/veilid_api/debug.rs | 22 ++ .../src/veilid_api/tests/test_types.rs | 4 + .../src/veilid_api/types/veilid_state.rs | 8 +- veilid-flutter/lib/veilid_state.dart | 8 +- veilid-flutter/lib/veilid_state.freezed.dart | 329 ++++++++++++++---- veilid-flutter/lib/veilid_state.g.dart | 12 + veilid-python/veilid/schema/RecvMessage.json | 36 +- veilid-python/veilid/state.py | 8 + 10 files changed, 379 insertions(+), 85 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 964d97b1..43e871c5 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -246,3 +246,23 @@ of the build steps configured, consult the `Earthfile`, or you may use the ```shell earthly ls ``` + +## Updating bindings + +When changing Veilid API, bindings must be updated to reflect the changes. +For each language, perform the listed steps and commit changed files. + +### Dart + +1. Update sources in `veilid-flutter/lib`, ignoring `*.freezed.*` and `*.g.*` +2. Run `dart run build_runner build` inside `veilid-flutter`, allow to delete existing files if asked + +### Python + +1. Run `cargo build --bin=veilid-server` +2. Run `./veilid-python/update_schema.sh` +3. Update sources in `veilid-python/veilid` + +### WASM + +1. Update sources in `veilid-wasm/src` diff --git a/veilid-core/src/attachment_manager.rs b/veilid-core/src/attachment_manager.rs index dc778dbe..b83cc925 100644 --- a/veilid-core/src/attachment_manager.rs +++ b/veilid-core/src/attachment_manager.rs @@ -8,6 +8,7 @@ struct AttachmentManagerInner { last_attachment_state: AttachmentState, last_routing_table_health: Option, maintain_peers: bool, + started_ts: Timestamp, attach_ts: Option, update_callback: Option, attachment_maintainer_jh: Option>, @@ -49,6 +50,7 @@ impl AttachmentManager { last_attachment_state: AttachmentState::Detached, last_routing_table_health: None, maintain_peers: false, + started_ts: Timestamp::now(), attach_ts: None, update_callback: None, attachment_maintainer_jh: None, @@ -177,6 +179,9 @@ impl AttachmentManager { } fn update_attaching_detaching_state(&self, state: AttachmentState) { + let uptime; + let attached_uptime; + let update_callback = { let mut inner = self.inner.lock(); @@ -197,6 +202,10 @@ impl AttachmentManager { unreachable!("don't use this for attached states, use update_attachment()"); } + let now = Timestamp::now(); + uptime = now - inner.started_ts; + attached_uptime = inner.attach_ts.map(|ts| now - ts); + // Get callback inner.update_callback.clone() }; @@ -207,6 +216,8 @@ impl AttachmentManager { state, public_internet_ready: false, local_network_ready: false, + uptime, + attached_uptime, }))) } } @@ -355,6 +366,10 @@ impl AttachmentManager { // } fn get_veilid_state_inner(inner: &AttachmentManagerInner) -> Box { + let now = Timestamp::now(); + let uptime = now - inner.started_ts; + let attached_uptime = inner.attach_ts.map(|ts| now - ts); + Box::new(VeilidStateAttachment { state: inner.last_attachment_state, public_internet_ready: inner @@ -367,6 +382,8 @@ impl AttachmentManager { .as_ref() .map(|x| x.local_network_ready) .unwrap_or(false), + uptime, + attached_uptime, }) } diff --git a/veilid-core/src/veilid_api/debug.rs b/veilid-core/src/veilid_api/debug.rs index 1d399438..58b4e110 100644 --- a/veilid-core/src/veilid_api/debug.rs +++ b/veilid-core/src/veilid_api/debug.rs @@ -7,6 +7,7 @@ use hashlink::LinkedHashMap; use network_manager::*; use once_cell::sync::Lazy; use routing_table::*; +use std::fmt::Write; #[derive(Default)] pub(crate) struct DebugCache { @@ -2004,6 +2005,7 @@ impl VeilidAPI { nodeinfo - display detailed information about this node dialinfo - display the dialinfo in the routing domains of this node peerinfo [routingdomain] [published|current] - display the full PeerInfo for a routing domain of this node + uptime - display node uptime Routing: buckets [dead|reliable] - Display the routing table bucket statistics (default is only non-dead nodes) @@ -2093,6 +2095,24 @@ TableDB Operations: .to_owned()) } + /// Get node uptime info. + pub async fn debug_uptime(&self, _args: String) -> VeilidAPIResult { + let mut result = String::new(); + + writeln!(result, "Uptime...").ok(); + + let state = self.get_state().await?; + + let uptime = state.attachment.uptime; + writeln!(result, " since launch: {uptime}").ok(); + + if let Some(attached_uptime) = state.attachment.attached_uptime { + writeln!(result, " since attachment: {attached_uptime}").ok(); + } + + Ok(result) + } + /// Execute an 'internal debug command'. pub async fn debug(&self, args: String) -> VeilidAPIResult { let res = { @@ -2156,6 +2176,8 @@ TableDB Operations: self.debug_punish(rest).await } else if arg == "table" { self.debug_table(rest).await + } else if arg == "uptime" { + self.debug_uptime(rest).await } else { Err(VeilidAPIError::generic("Unknown debug command")) } diff --git a/veilid-core/src/veilid_api/tests/test_types.rs b/veilid-core/src/veilid_api/tests/test_types.rs index fdb951a3..7f537018 100644 --- a/veilid-core/src/veilid_api/tests/test_types.rs +++ b/veilid-core/src/veilid_api/tests/test_types.rs @@ -213,6 +213,8 @@ pub async fn test_veilidstateattachment() { state: AttachmentState::OverAttached, public_internet_ready: true, local_network_ready: false, + uptime: TimestampDuration::new_secs(10), + attached_uptime: Some(TimestampDuration::new_secs(10)), }; let copy = deserialize_json(&serialize_json(&orig)).unwrap(); @@ -277,6 +279,8 @@ pub async fn test_veilidstate() { state: AttachmentState::OverAttached, public_internet_ready: true, local_network_ready: false, + uptime: TimestampDuration::new_secs(900), + attached_uptime: Some(TimestampDuration::new_secs(600)), }), network: Box::new(VeilidStateNetwork { started: true, diff --git a/veilid-core/src/veilid_api/types/veilid_state.rs b/veilid-core/src/veilid_api/types/veilid_state.rs index 6fb5c7bd..cc6890c3 100644 --- a/veilid-core/src/veilid_api/types/veilid_state.rs +++ b/veilid-core/src/veilid_api/types/veilid_state.rs @@ -73,11 +73,15 @@ impl TryFrom for AttachmentState { pub struct VeilidStateAttachment { /// The overall quality of the routing table if attached, or the current state the attachment state machine. pub state: AttachmentState, - /// If attached and there are enough eachable nodes in the routing table to perform all the actions of the PublicInternet RoutingDomain, + /// If attached and there are enough reachable nodes in the routing table to perform all the actions of the PublicInternet RoutingDomain, /// including things like private/safety route allocation and DHT operations. pub public_internet_ready: bool, - /// If attached and there are enough eachable nodes in the routing table to perform all the actions of the LocalNetwork RoutingDomain. + /// If attached and there are enough reachable nodes in the routing table to perform all the actions of the LocalNetwork RoutingDomain. pub local_network_ready: bool, + /// Node uptime + pub uptime: TimestampDuration, + /// Uptime since last attach, empty if the node is currently detached + pub attached_uptime: Option, } /// Describe a recently accessed peer diff --git a/veilid-flutter/lib/veilid_state.dart b/veilid-flutter/lib/veilid_state.dart index 7094cdb1..7e2f683f 100644 --- a/veilid-flutter/lib/veilid_state.dart +++ b/veilid-flutter/lib/veilid_state.dart @@ -215,7 +215,9 @@ sealed class VeilidUpdate with _$VeilidUpdate { const factory VeilidUpdate.attachment( {required AttachmentState state, required bool publicInternetReady, - required bool localNetworkReady}) = VeilidUpdateAttachment; + required bool localNetworkReady, + required TimestampDuration uptime, + required TimestampDuration? attachedUptime}) = VeilidUpdateAttachment; const factory VeilidUpdate.network( {required bool started, required BigInt bpsDown, @@ -247,7 +249,9 @@ class VeilidStateAttachment with _$VeilidStateAttachment { const factory VeilidStateAttachment( {required AttachmentState state, required bool publicInternetReady, - required bool localNetworkReady}) = _VeilidStateAttachment; + required bool localNetworkReady, + required TimestampDuration uptime, + required TimestampDuration? attachedUptime}) = _VeilidStateAttachment; factory VeilidStateAttachment.fromJson(dynamic json) => _$VeilidStateAttachmentFromJson(json as Map); diff --git a/veilid-flutter/lib/veilid_state.freezed.dart b/veilid-flutter/lib/veilid_state.freezed.dart index 0ccb7178..c1bcfbcb 100644 --- a/veilid-flutter/lib/veilid_state.freezed.dart +++ b/veilid-flutter/lib/veilid_state.freezed.dart @@ -2434,8 +2434,12 @@ mixin _$VeilidUpdate { Typed? sender, String? routeId) appCall, - required TResult Function(AttachmentState state, bool publicInternetReady, - bool localNetworkReady) + required TResult Function( + AttachmentState state, + bool publicInternetReady, + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime) attachment, required TResult Function(bool started, BigInt bpsDown, BigInt bpsUp, List peers) @@ -2463,8 +2467,12 @@ mixin _$VeilidUpdate { Typed? sender, String? routeId)? appCall, - TResult? Function(AttachmentState state, bool publicInternetReady, - bool localNetworkReady)? + TResult? Function( + AttachmentState state, + bool publicInternetReady, + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime)? attachment, TResult? Function(bool started, BigInt bpsDown, BigInt bpsUp, List peers)? @@ -2491,8 +2499,12 @@ mixin _$VeilidUpdate { Typed? sender, String? routeId)? appCall, - TResult Function(AttachmentState state, bool publicInternetReady, - bool localNetworkReady)? + TResult Function( + AttachmentState state, + bool publicInternetReady, + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime)? attachment, TResult Function(bool started, BigInt bpsDown, BigInt bpsUp, List peers)? @@ -2681,8 +2693,12 @@ class _$VeilidLogImpl implements VeilidLog { Typed? sender, String? routeId) appCall, - required TResult Function(AttachmentState state, bool publicInternetReady, - bool localNetworkReady) + required TResult Function( + AttachmentState state, + bool publicInternetReady, + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime) attachment, required TResult Function(bool started, BigInt bpsDown, BigInt bpsUp, List peers) @@ -2713,8 +2729,12 @@ class _$VeilidLogImpl implements VeilidLog { Typed? sender, String? routeId)? appCall, - TResult? Function(AttachmentState state, bool publicInternetReady, - bool localNetworkReady)? + TResult? Function( + AttachmentState state, + bool publicInternetReady, + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime)? attachment, TResult? Function(bool started, BigInt bpsDown, BigInt bpsUp, List peers)? @@ -2744,8 +2764,12 @@ class _$VeilidLogImpl implements VeilidLog { Typed? sender, String? routeId)? appCall, - TResult Function(AttachmentState state, bool publicInternetReady, - bool localNetworkReady)? + TResult Function( + AttachmentState state, + bool publicInternetReady, + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime)? attachment, TResult Function(bool started, BigInt bpsDown, BigInt bpsUp, List peers)? @@ -2957,8 +2981,12 @@ class _$VeilidAppMessageImpl implements VeilidAppMessage { Typed? sender, String? routeId) appCall, - required TResult Function(AttachmentState state, bool publicInternetReady, - bool localNetworkReady) + required TResult Function( + AttachmentState state, + bool publicInternetReady, + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime) attachment, required TResult Function(bool started, BigInt bpsDown, BigInt bpsUp, List peers) @@ -2989,8 +3017,12 @@ class _$VeilidAppMessageImpl implements VeilidAppMessage { Typed? sender, String? routeId)? appCall, - TResult? Function(AttachmentState state, bool publicInternetReady, - bool localNetworkReady)? + TResult? Function( + AttachmentState state, + bool publicInternetReady, + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime)? attachment, TResult? Function(bool started, BigInt bpsDown, BigInt bpsUp, List peers)? @@ -3020,8 +3052,12 @@ class _$VeilidAppMessageImpl implements VeilidAppMessage { Typed? sender, String? routeId)? appCall, - TResult Function(AttachmentState state, bool publicInternetReady, - bool localNetworkReady)? + TResult Function( + AttachmentState state, + bool publicInternetReady, + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime)? attachment, TResult Function(bool started, BigInt bpsDown, BigInt bpsUp, List peers)? @@ -3243,8 +3279,12 @@ class _$VeilidAppCallImpl implements VeilidAppCall { Typed? sender, String? routeId) appCall, - required TResult Function(AttachmentState state, bool publicInternetReady, - bool localNetworkReady) + required TResult Function( + AttachmentState state, + bool publicInternetReady, + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime) attachment, required TResult Function(bool started, BigInt bpsDown, BigInt bpsUp, List peers) @@ -3275,8 +3315,12 @@ class _$VeilidAppCallImpl implements VeilidAppCall { Typed? sender, String? routeId)? appCall, - TResult? Function(AttachmentState state, bool publicInternetReady, - bool localNetworkReady)? + TResult? Function( + AttachmentState state, + bool publicInternetReady, + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime)? attachment, TResult? Function(bool started, BigInt bpsDown, BigInt bpsUp, List peers)? @@ -3306,8 +3350,12 @@ class _$VeilidAppCallImpl implements VeilidAppCall { Typed? sender, String? routeId)? appCall, - TResult Function(AttachmentState state, bool publicInternetReady, - bool localNetworkReady)? + TResult Function( + AttachmentState state, + bool publicInternetReady, + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime)? attachment, TResult Function(bool started, BigInt bpsDown, BigInt bpsUp, List peers)? @@ -3416,7 +3464,9 @@ abstract class _$$VeilidUpdateAttachmentImplCopyWith<$Res> { $Res call( {AttachmentState state, bool publicInternetReady, - bool localNetworkReady}); + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime}); } /// @nodoc @@ -3436,6 +3486,8 @@ class __$$VeilidUpdateAttachmentImplCopyWithImpl<$Res> Object? state = null, Object? publicInternetReady = null, Object? localNetworkReady = null, + Object? uptime = null, + Object? attachedUptime = freezed, }) { return _then(_$VeilidUpdateAttachmentImpl( state: null == state @@ -3450,6 +3502,14 @@ class __$$VeilidUpdateAttachmentImplCopyWithImpl<$Res> ? _value.localNetworkReady : localNetworkReady // ignore: cast_nullable_to_non_nullable as bool, + uptime: null == uptime + ? _value.uptime + : uptime // ignore: cast_nullable_to_non_nullable + as TimestampDuration, + attachedUptime: freezed == attachedUptime + ? _value.attachedUptime + : attachedUptime // ignore: cast_nullable_to_non_nullable + as TimestampDuration?, )); } } @@ -3461,6 +3521,8 @@ class _$VeilidUpdateAttachmentImpl implements VeilidUpdateAttachment { {required this.state, required this.publicInternetReady, required this.localNetworkReady, + required this.uptime, + required this.attachedUptime, final String? $type}) : $type = $type ?? 'Attachment'; @@ -3473,13 +3535,17 @@ class _$VeilidUpdateAttachmentImpl implements VeilidUpdateAttachment { final bool publicInternetReady; @override final bool localNetworkReady; + @override + final TimestampDuration uptime; + @override + final TimestampDuration? attachedUptime; @JsonKey(name: 'kind') final String $type; @override String toString() { - return 'VeilidUpdate.attachment(state: $state, publicInternetReady: $publicInternetReady, localNetworkReady: $localNetworkReady)'; + return 'VeilidUpdate.attachment(state: $state, publicInternetReady: $publicInternetReady, localNetworkReady: $localNetworkReady, uptime: $uptime, attachedUptime: $attachedUptime)'; } @override @@ -3491,13 +3557,16 @@ class _$VeilidUpdateAttachmentImpl implements VeilidUpdateAttachment { (identical(other.publicInternetReady, publicInternetReady) || other.publicInternetReady == publicInternetReady) && (identical(other.localNetworkReady, localNetworkReady) || - other.localNetworkReady == localNetworkReady)); + other.localNetworkReady == localNetworkReady) && + (identical(other.uptime, uptime) || other.uptime == uptime) && + (identical(other.attachedUptime, attachedUptime) || + other.attachedUptime == attachedUptime)); } @JsonKey(includeFromJson: false, includeToJson: false) @override - int get hashCode => - Object.hash(runtimeType, state, publicInternetReady, localNetworkReady); + int get hashCode => Object.hash(runtimeType, state, publicInternetReady, + localNetworkReady, uptime, attachedUptime); /// Create a copy of VeilidUpdate /// with the given fields replaced by the non-null parameter values. @@ -3525,8 +3594,12 @@ class _$VeilidUpdateAttachmentImpl implements VeilidUpdateAttachment { Typed? sender, String? routeId) appCall, - required TResult Function(AttachmentState state, bool publicInternetReady, - bool localNetworkReady) + required TResult Function( + AttachmentState state, + bool publicInternetReady, + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime) attachment, required TResult Function(bool started, BigInt bpsDown, BigInt bpsUp, List peers) @@ -3539,7 +3612,8 @@ class _$VeilidUpdateAttachmentImpl implements VeilidUpdateAttachment { List subkeys, int count, ValueData? value) valueChange, }) { - return attachment(state, publicInternetReady, localNetworkReady); + return attachment( + state, publicInternetReady, localNetworkReady, uptime, attachedUptime); } @override @@ -3557,8 +3631,12 @@ class _$VeilidUpdateAttachmentImpl implements VeilidUpdateAttachment { Typed? sender, String? routeId)? appCall, - TResult? Function(AttachmentState state, bool publicInternetReady, - bool localNetworkReady)? + TResult? Function( + AttachmentState state, + bool publicInternetReady, + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime)? attachment, TResult? Function(bool started, BigInt bpsDown, BigInt bpsUp, List peers)? @@ -3570,7 +3648,8 @@ class _$VeilidUpdateAttachmentImpl implements VeilidUpdateAttachment { List subkeys, int count, ValueData? value)? valueChange, }) { - return attachment?.call(state, publicInternetReady, localNetworkReady); + return attachment?.call( + state, publicInternetReady, localNetworkReady, uptime, attachedUptime); } @override @@ -3588,8 +3667,12 @@ class _$VeilidUpdateAttachmentImpl implements VeilidUpdateAttachment { Typed? sender, String? routeId)? appCall, - TResult Function(AttachmentState state, bool publicInternetReady, - bool localNetworkReady)? + TResult Function( + AttachmentState state, + bool publicInternetReady, + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime)? attachment, TResult Function(bool started, BigInt bpsDown, BigInt bpsUp, List peers)? @@ -3603,7 +3686,8 @@ class _$VeilidUpdateAttachmentImpl implements VeilidUpdateAttachment { required TResult orElse(), }) { if (attachment != null) { - return attachment(state, publicInternetReady, localNetworkReady); + return attachment(state, publicInternetReady, localNetworkReady, uptime, + attachedUptime); } return orElse(); } @@ -3667,9 +3751,12 @@ class _$VeilidUpdateAttachmentImpl implements VeilidUpdateAttachment { abstract class VeilidUpdateAttachment implements VeilidUpdate { const factory VeilidUpdateAttachment( - {required final AttachmentState state, - required final bool publicInternetReady, - required final bool localNetworkReady}) = _$VeilidUpdateAttachmentImpl; + {required final AttachmentState state, + required final bool publicInternetReady, + required final bool localNetworkReady, + required final TimestampDuration uptime, + required final TimestampDuration? attachedUptime}) = + _$VeilidUpdateAttachmentImpl; factory VeilidUpdateAttachment.fromJson(Map json) = _$VeilidUpdateAttachmentImpl.fromJson; @@ -3677,6 +3764,8 @@ abstract class VeilidUpdateAttachment implements VeilidUpdate { AttachmentState get state; bool get publicInternetReady; bool get localNetworkReady; + TimestampDuration get uptime; + TimestampDuration? get attachedUptime; /// Create a copy of VeilidUpdate /// with the given fields replaced by the non-null parameter values. @@ -3813,8 +3902,12 @@ class _$VeilidUpdateNetworkImpl implements VeilidUpdateNetwork { Typed? sender, String? routeId) appCall, - required TResult Function(AttachmentState state, bool publicInternetReady, - bool localNetworkReady) + required TResult Function( + AttachmentState state, + bool publicInternetReady, + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime) attachment, required TResult Function(bool started, BigInt bpsDown, BigInt bpsUp, List peers) @@ -3845,8 +3938,12 @@ class _$VeilidUpdateNetworkImpl implements VeilidUpdateNetwork { Typed? sender, String? routeId)? appCall, - TResult? Function(AttachmentState state, bool publicInternetReady, - bool localNetworkReady)? + TResult? Function( + AttachmentState state, + bool publicInternetReady, + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime)? attachment, TResult? Function(bool started, BigInt bpsDown, BigInt bpsUp, List peers)? @@ -3876,8 +3973,12 @@ class _$VeilidUpdateNetworkImpl implements VeilidUpdateNetwork { Typed? sender, String? routeId)? appCall, - TResult Function(AttachmentState state, bool publicInternetReady, - bool localNetworkReady)? + TResult Function( + AttachmentState state, + bool publicInternetReady, + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime)? attachment, TResult Function(bool started, BigInt bpsDown, BigInt bpsUp, List peers)? @@ -4078,8 +4179,12 @@ class _$VeilidUpdateConfigImpl implements VeilidUpdateConfig { Typed? sender, String? routeId) appCall, - required TResult Function(AttachmentState state, bool publicInternetReady, - bool localNetworkReady) + required TResult Function( + AttachmentState state, + bool publicInternetReady, + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime) attachment, required TResult Function(bool started, BigInt bpsDown, BigInt bpsUp, List peers) @@ -4110,8 +4215,12 @@ class _$VeilidUpdateConfigImpl implements VeilidUpdateConfig { Typed? sender, String? routeId)? appCall, - TResult? Function(AttachmentState state, bool publicInternetReady, - bool localNetworkReady)? + TResult? Function( + AttachmentState state, + bool publicInternetReady, + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime)? attachment, TResult? Function(bool started, BigInt bpsDown, BigInt bpsUp, List peers)? @@ -4141,8 +4250,12 @@ class _$VeilidUpdateConfigImpl implements VeilidUpdateConfig { Typed? sender, String? routeId)? appCall, - TResult Function(AttachmentState state, bool publicInternetReady, - bool localNetworkReady)? + TResult Function( + AttachmentState state, + bool publicInternetReady, + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime)? attachment, TResult Function(bool started, BigInt bpsDown, BigInt bpsUp, List peers)? @@ -4357,8 +4470,12 @@ class _$VeilidUpdateRouteChangeImpl implements VeilidUpdateRouteChange { Typed? sender, String? routeId) appCall, - required TResult Function(AttachmentState state, bool publicInternetReady, - bool localNetworkReady) + required TResult Function( + AttachmentState state, + bool publicInternetReady, + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime) attachment, required TResult Function(bool started, BigInt bpsDown, BigInt bpsUp, List peers) @@ -4389,8 +4506,12 @@ class _$VeilidUpdateRouteChangeImpl implements VeilidUpdateRouteChange { Typed? sender, String? routeId)? appCall, - TResult? Function(AttachmentState state, bool publicInternetReady, - bool localNetworkReady)? + TResult? Function( + AttachmentState state, + bool publicInternetReady, + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime)? attachment, TResult? Function(bool started, BigInt bpsDown, BigInt bpsUp, List peers)? @@ -4420,8 +4541,12 @@ class _$VeilidUpdateRouteChangeImpl implements VeilidUpdateRouteChange { Typed? sender, String? routeId)? appCall, - TResult Function(AttachmentState state, bool publicInternetReady, - bool localNetworkReady)? + TResult Function( + AttachmentState state, + bool publicInternetReady, + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime)? attachment, TResult Function(bool started, BigInt bpsDown, BigInt bpsUp, List peers)? @@ -4666,8 +4791,12 @@ class _$VeilidUpdateValueChangeImpl implements VeilidUpdateValueChange { Typed? sender, String? routeId) appCall, - required TResult Function(AttachmentState state, bool publicInternetReady, - bool localNetworkReady) + required TResult Function( + AttachmentState state, + bool publicInternetReady, + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime) attachment, required TResult Function(bool started, BigInt bpsDown, BigInt bpsUp, List peers) @@ -4698,8 +4827,12 @@ class _$VeilidUpdateValueChangeImpl implements VeilidUpdateValueChange { Typed? sender, String? routeId)? appCall, - TResult? Function(AttachmentState state, bool publicInternetReady, - bool localNetworkReady)? + TResult? Function( + AttachmentState state, + bool publicInternetReady, + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime)? attachment, TResult? Function(bool started, BigInt bpsDown, BigInt bpsUp, List peers)? @@ -4729,8 +4862,12 @@ class _$VeilidUpdateValueChangeImpl implements VeilidUpdateValueChange { Typed? sender, String? routeId)? appCall, - TResult Function(AttachmentState state, bool publicInternetReady, - bool localNetworkReady)? + TResult Function( + AttachmentState state, + bool publicInternetReady, + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime)? attachment, TResult Function(bool started, BigInt bpsDown, BigInt bpsUp, List peers)? @@ -4838,6 +4975,8 @@ mixin _$VeilidStateAttachment { AttachmentState get state => throw _privateConstructorUsedError; bool get publicInternetReady => throw _privateConstructorUsedError; bool get localNetworkReady => throw _privateConstructorUsedError; + TimestampDuration get uptime => throw _privateConstructorUsedError; + TimestampDuration? get attachedUptime => throw _privateConstructorUsedError; /// Serializes this VeilidStateAttachment to a JSON map. Map toJson() => throw _privateConstructorUsedError; @@ -4858,7 +4997,9 @@ abstract class $VeilidStateAttachmentCopyWith<$Res> { $Res call( {AttachmentState state, bool publicInternetReady, - bool localNetworkReady}); + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime}); } /// @nodoc @@ -4880,6 +5021,8 @@ class _$VeilidStateAttachmentCopyWithImpl<$Res, Object? state = null, Object? publicInternetReady = null, Object? localNetworkReady = null, + Object? uptime = null, + Object? attachedUptime = freezed, }) { return _then(_value.copyWith( state: null == state @@ -4894,6 +5037,14 @@ class _$VeilidStateAttachmentCopyWithImpl<$Res, ? _value.localNetworkReady : localNetworkReady // ignore: cast_nullable_to_non_nullable as bool, + uptime: null == uptime + ? _value.uptime + : uptime // ignore: cast_nullable_to_non_nullable + as TimestampDuration, + attachedUptime: freezed == attachedUptime + ? _value.attachedUptime + : attachedUptime // ignore: cast_nullable_to_non_nullable + as TimestampDuration?, ) as $Val); } } @@ -4910,7 +5061,9 @@ abstract class _$$VeilidStateAttachmentImplCopyWith<$Res> $Res call( {AttachmentState state, bool publicInternetReady, - bool localNetworkReady}); + bool localNetworkReady, + TimestampDuration uptime, + TimestampDuration? attachedUptime}); } /// @nodoc @@ -4930,6 +5083,8 @@ class __$$VeilidStateAttachmentImplCopyWithImpl<$Res> Object? state = null, Object? publicInternetReady = null, Object? localNetworkReady = null, + Object? uptime = null, + Object? attachedUptime = freezed, }) { return _then(_$VeilidStateAttachmentImpl( state: null == state @@ -4944,6 +5099,14 @@ class __$$VeilidStateAttachmentImplCopyWithImpl<$Res> ? _value.localNetworkReady : localNetworkReady // ignore: cast_nullable_to_non_nullable as bool, + uptime: null == uptime + ? _value.uptime + : uptime // ignore: cast_nullable_to_non_nullable + as TimestampDuration, + attachedUptime: freezed == attachedUptime + ? _value.attachedUptime + : attachedUptime // ignore: cast_nullable_to_non_nullable + as TimestampDuration?, )); } } @@ -4954,7 +5117,9 @@ class _$VeilidStateAttachmentImpl implements _VeilidStateAttachment { const _$VeilidStateAttachmentImpl( {required this.state, required this.publicInternetReady, - required this.localNetworkReady}); + required this.localNetworkReady, + required this.uptime, + required this.attachedUptime}); factory _$VeilidStateAttachmentImpl.fromJson(Map json) => _$$VeilidStateAttachmentImplFromJson(json); @@ -4965,10 +5130,14 @@ class _$VeilidStateAttachmentImpl implements _VeilidStateAttachment { final bool publicInternetReady; @override final bool localNetworkReady; + @override + final TimestampDuration uptime; + @override + final TimestampDuration? attachedUptime; @override String toString() { - return 'VeilidStateAttachment(state: $state, publicInternetReady: $publicInternetReady, localNetworkReady: $localNetworkReady)'; + return 'VeilidStateAttachment(state: $state, publicInternetReady: $publicInternetReady, localNetworkReady: $localNetworkReady, uptime: $uptime, attachedUptime: $attachedUptime)'; } @override @@ -4980,13 +5149,16 @@ class _$VeilidStateAttachmentImpl implements _VeilidStateAttachment { (identical(other.publicInternetReady, publicInternetReady) || other.publicInternetReady == publicInternetReady) && (identical(other.localNetworkReady, localNetworkReady) || - other.localNetworkReady == localNetworkReady)); + other.localNetworkReady == localNetworkReady) && + (identical(other.uptime, uptime) || other.uptime == uptime) && + (identical(other.attachedUptime, attachedUptime) || + other.attachedUptime == attachedUptime)); } @JsonKey(includeFromJson: false, includeToJson: false) @override - int get hashCode => - Object.hash(runtimeType, state, publicInternetReady, localNetworkReady); + int get hashCode => Object.hash(runtimeType, state, publicInternetReady, + localNetworkReady, uptime, attachedUptime); /// Create a copy of VeilidStateAttachment /// with the given fields replaced by the non-null parameter values. @@ -5007,9 +5179,12 @@ class _$VeilidStateAttachmentImpl implements _VeilidStateAttachment { abstract class _VeilidStateAttachment implements VeilidStateAttachment { const factory _VeilidStateAttachment( - {required final AttachmentState state, - required final bool publicInternetReady, - required final bool localNetworkReady}) = _$VeilidStateAttachmentImpl; + {required final AttachmentState state, + required final bool publicInternetReady, + required final bool localNetworkReady, + required final TimestampDuration uptime, + required final TimestampDuration? attachedUptime}) = + _$VeilidStateAttachmentImpl; factory _VeilidStateAttachment.fromJson(Map json) = _$VeilidStateAttachmentImpl.fromJson; @@ -5020,6 +5195,10 @@ abstract class _VeilidStateAttachment implements VeilidStateAttachment { bool get publicInternetReady; @override bool get localNetworkReady; + @override + TimestampDuration get uptime; + @override + TimestampDuration? get attachedUptime; /// Create a copy of VeilidStateAttachment /// with the given fields replaced by the non-null parameter values. diff --git a/veilid-flutter/lib/veilid_state.g.dart b/veilid-flutter/lib/veilid_state.g.dart index 10a982ef..cf202e98 100644 --- a/veilid-flutter/lib/veilid_state.g.dart +++ b/veilid-flutter/lib/veilid_state.g.dart @@ -268,6 +268,10 @@ _$VeilidUpdateAttachmentImpl _$$VeilidUpdateAttachmentImplFromJson( state: AttachmentState.fromJson(json['state']), publicInternetReady: json['public_internet_ready'] as bool, localNetworkReady: json['local_network_ready'] as bool, + uptime: TimestampDuration.fromJson(json['uptime']), + attachedUptime: json['attached_uptime'] == null + ? null + : TimestampDuration.fromJson(json['attached_uptime']), $type: json['kind'] as String?, ); @@ -277,6 +281,8 @@ Map _$$VeilidUpdateAttachmentImplToJson( 'state': instance.state.toJson(), 'public_internet_ready': instance.publicInternetReady, 'local_network_ready': instance.localNetworkReady, + 'uptime': instance.uptime.toJson(), + 'attached_uptime': instance.attachedUptime?.toJson(), 'kind': instance.$type, }; @@ -363,6 +369,10 @@ _$VeilidStateAttachmentImpl _$$VeilidStateAttachmentImplFromJson( state: AttachmentState.fromJson(json['state']), publicInternetReady: json['public_internet_ready'] as bool, localNetworkReady: json['local_network_ready'] as bool, + uptime: TimestampDuration.fromJson(json['uptime']), + attachedUptime: json['attached_uptime'] == null + ? null + : TimestampDuration.fromJson(json['attached_uptime']), ); Map _$$VeilidStateAttachmentImplToJson( @@ -371,6 +381,8 @@ Map _$$VeilidStateAttachmentImplToJson( 'state': instance.state.toJson(), 'public_internet_ready': instance.publicInternetReady, 'local_network_ready': instance.localNetworkReady, + 'uptime': instance.uptime.toJson(), + 'attached_uptime': instance.attachedUptime?.toJson(), }; _$VeilidStateNetworkImpl _$$VeilidStateNetworkImplFromJson( diff --git a/veilid-python/veilid/schema/RecvMessage.json b/veilid-python/veilid/schema/RecvMessage.json index 45d6d3ce..b0a3d5d3 100644 --- a/veilid-python/veilid/schema/RecvMessage.json +++ b/veilid-python/veilid/schema/RecvMessage.json @@ -2588,9 +2588,17 @@ "kind", "local_network_ready", "public_internet_ready", - "state" + "state", + "uptime" ], "properties": { + "attached_uptime": { + "description": "Uptime since last attach, empty if the node is currently detached", + "type": [ + "string", + "null" + ] + }, "kind": { "type": "string", "enum": [ @@ -2598,11 +2606,11 @@ ] }, "local_network_ready": { - "description": "If attached and there are enough eachable nodes in the routing table to perform all the actions of the LocalNetwork RoutingDomain.", + "description": "If attached and there are enough reachable nodes in the routing table to perform all the actions of the LocalNetwork RoutingDomain.", "type": "boolean" }, "public_internet_ready": { - "description": "If attached and there are enough eachable nodes in the routing table to perform all the actions of the PublicInternet RoutingDomain, including things like private/safety route allocation and DHT operations.", + "description": "If attached and there are enough reachable nodes in the routing table to perform all the actions of the PublicInternet RoutingDomain, including things like private/safety route allocation and DHT operations.", "type": "boolean" }, "state": { @@ -2612,6 +2620,10 @@ "$ref": "#/definitions/AttachmentState" } ] + }, + "uptime": { + "description": "Node uptime", + "type": "string" } } }, @@ -4618,15 +4630,23 @@ "required": [ "local_network_ready", "public_internet_ready", - "state" + "state", + "uptime" ], "properties": { + "attached_uptime": { + "description": "Uptime since last attach, empty if the node is currently detached", + "type": [ + "string", + "null" + ] + }, "local_network_ready": { - "description": "If attached and there are enough eachable nodes in the routing table to perform all the actions of the LocalNetwork RoutingDomain.", + "description": "If attached and there are enough reachable nodes in the routing table to perform all the actions of the LocalNetwork RoutingDomain.", "type": "boolean" }, "public_internet_ready": { - "description": "If attached and there are enough eachable nodes in the routing table to perform all the actions of the PublicInternet RoutingDomain, including things like private/safety route allocation and DHT operations.", + "description": "If attached and there are enough reachable nodes in the routing table to perform all the actions of the PublicInternet RoutingDomain, including things like private/safety route allocation and DHT operations.", "type": "boolean" }, "state": { @@ -4636,6 +4656,10 @@ "$ref": "#/definitions/AttachmentState" } ] + }, + "uptime": { + "description": "Node uptime", + "type": "string" } } }, diff --git a/veilid-python/veilid/state.py b/veilid-python/veilid/state.py index d65c708b..4d28fa31 100644 --- a/veilid-python/veilid/state.py +++ b/veilid-python/veilid/state.py @@ -31,16 +31,22 @@ class VeilidStateAttachment: state: AttachmentState public_internet_ready: bool local_network_ready: bool + uptime: TimestampDuration + attached_uptime: Optional[TimestampDuration] def __init__( self, state: AttachmentState, public_internet_ready: bool, local_network_ready: bool, + uptime: TimestampDuration, + attached_uptime: Optional[TimestampDuration], ): self.state = state self.public_internet_ready = public_internet_ready self.local_network_ready = local_network_ready + self.uptime = uptime + self.attached_uptime = attached_uptime @classmethod def from_json(cls, j: dict) -> Self: @@ -49,6 +55,8 @@ class VeilidStateAttachment: AttachmentState(j["state"]), j["public_internet_ready"], j["local_network_ready"], + j["uptime"], + j["attached_uptime"], )