From 946d33ced634509d4b4a9f432872ea3075987e2a Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Fri, 8 Mar 2024 00:17:38 -0500 Subject: [PATCH] fixes for privacy issues, closes #357 --- .../coders/operations/operation.rs | 1 + veilid-core/src/rpc_processor/mod.rs | 14 ++ veilid-core/src/rpc_processor/rpc_app_call.rs | 20 +- .../src/rpc_processor/rpc_app_message.rs | 20 +- .../src/veilid_api/tests/test_types.rs | 7 +- .../src/veilid_api/types/app_message_call.rs | 37 ++- veilid-flutter/lib/veilid.dart | 2 +- veilid-flutter/lib/veilid_ffi.dart | 6 +- veilid-flutter/lib/veilid_js.dart | 4 +- veilid-flutter/lib/veilid_state.dart | 2 + veilid-flutter/lib/veilid_state.freezed.dart | 211 +++++++++++------- veilid-flutter/lib/veilid_state.g.dart | 4 + veilid-python/tests/test_routing_context.py | 3 + veilid-python/veilid/schema/RecvMessage.json | 16 +- veilid-python/veilid/state.py | 10 +- 15 files changed, 261 insertions(+), 96 deletions(-) diff --git a/veilid-core/src/rpc_processor/coders/operations/operation.rs b/veilid-core/src/rpc_processor/coders/operations/operation.rs index b15841ca..9e070ef1 100644 --- a/veilid-core/src/rpc_processor/coders/operations/operation.rs +++ b/veilid-core/src/rpc_processor/coders/operations/operation.rs @@ -106,6 +106,7 @@ impl RPCOperation { .validate(validate_context.crypto.clone()) .map_err(RPCError::protocol)?; } + // Validate operation kind self.kind.validate(validate_context) } diff --git a/veilid-core/src/rpc_processor/mod.rs b/veilid-core/src/rpc_processor/mod.rs index b2c74e0c..e51e431a 100644 --- a/veilid-core/src/rpc_processor/mod.rs +++ b/veilid-core/src/rpc_processor/mod.rs @@ -615,6 +615,20 @@ impl RPCProcessor { // Reply received let recv_ts = get_aligned_timestamp(); + // Ensure the reply comes over the private route that was requested + if let Some(reply_private_route) = waitable_reply.reply_private_route { + match &rpcreader.header.detail { + RPCMessageHeaderDetail::Direct(_) | RPCMessageHeaderDetail::SafetyRouted(_) => { + return Err(RPCError::protocol("should have received reply over private route")); + } + RPCMessageHeaderDetail::PrivateRouted(pr) => { + if pr.private_route != reply_private_route { + return Err(RPCError::protocol("received reply over the wrong private route")); + } + } + }; + } + // Record answer received self.record_answer_received( waitable_reply.send_ts, diff --git a/veilid-core/src/rpc_processor/rpc_app_call.rs b/veilid-core/src/rpc_processor/rpc_app_call.rs index d358b4a1..1a26bbf9 100644 --- a/veilid-core/src/rpc_processor/rpc_app_call.rs +++ b/veilid-core/src/rpc_processor/rpc_app_call.rs @@ -73,6 +73,24 @@ impl RPCProcessor { )); } + // Get the private route this came over + let opt_pr_pubkey = match &msg.header.detail { + RPCMessageHeaderDetail::Direct(_) | RPCMessageHeaderDetail::SafetyRouted(_) => None, + RPCMessageHeaderDetail::PrivateRouted(pr) => Some(pr.private_route), + }; + let route_id = if let Some(pr_pubkey) = opt_pr_pubkey { + let rss = routing_table.route_spec_store(); + let Some(route_id) = rss.get_route_id_for_key(&pr_pubkey) else { + return Ok(NetworkResult::invalid_message(format!( + "private route does not exist for key: {}", + pr_pubkey + ))); + }; + Some(route_id) + } else { + None + }; + // Get the question let (op_id, _, _, kind) = msg.operation.clone().destructure(); let app_call_q = match kind { @@ -101,7 +119,7 @@ impl RPCProcessor { // Pass the call up through the update callback let message_q = app_call_q.destructure(); (self.unlocked_inner.update_callback)(VeilidUpdate::AppCall(Box::new(VeilidAppCall::new( - sender, message_q, op_id, + sender, route_id, message_q, op_id, )))); // Wait for an app call answer to come back from the app diff --git a/veilid-core/src/rpc_processor/rpc_app_message.rs b/veilid-core/src/rpc_processor/rpc_app_message.rs index b77fda93..5c397883 100644 --- a/veilid-core/src/rpc_processor/rpc_app_message.rs +++ b/veilid-core/src/rpc_processor/rpc_app_message.rs @@ -36,6 +36,24 @@ impl RPCProcessor { )); } + // Get the private route this came over + let opt_pr_pubkey = match &msg.header.detail { + RPCMessageHeaderDetail::Direct(_) | RPCMessageHeaderDetail::SafetyRouted(_) => None, + RPCMessageHeaderDetail::PrivateRouted(pr) => Some(pr.private_route), + }; + let route_id = if let Some(pr_pubkey) = opt_pr_pubkey { + let rss = routing_table.route_spec_store(); + let Some(route_id) = rss.get_route_id_for_key(&pr_pubkey) else { + return Ok(NetworkResult::invalid_message(format!( + "private route does not exist for key: {}", + pr_pubkey + ))); + }; + Some(route_id) + } else { + None + }; + // Get the statement let (_, _, _, kind) = msg.operation.destructure(); let app_message = match kind { @@ -58,7 +76,7 @@ impl RPCProcessor { // Pass the message up through the update callback let message = app_message.destructure(); (self.unlocked_inner.update_callback)(VeilidUpdate::AppMessage(Box::new( - VeilidAppMessage::new(sender, message), + VeilidAppMessage::new(sender, route_id, message), ))); Ok(NetworkResult::value(())) diff --git a/veilid-core/src/veilid_api/tests/test_types.rs b/veilid-core/src/veilid_api/tests/test_types.rs index 3a9b38bf..73617bff 100644 --- a/veilid-core/src/veilid_api/tests/test_types.rs +++ b/veilid-core/src/veilid_api/tests/test_types.rs @@ -13,7 +13,11 @@ pub async fn test_alignedu64() { // app_messsage_call pub async fn test_veilidappmessage() { - let orig = VeilidAppMessage::new(Some(fix_typedkey()), b"Hi there!".to_vec()); + let orig = VeilidAppMessage::new( + Some(fix_typedkey()), + Some(fix_cryptokey()), + b"Hi there!".to_vec(), + ); let copy = deserialize_json(&serialize_json(&orig)).unwrap(); assert_eq!(orig, copy); @@ -22,6 +26,7 @@ pub async fn test_veilidappmessage() { pub async fn test_veilidappcall() { let orig = VeilidAppCall::new( Some(fix_typedkey()), + Some(fix_cryptokey()), b"Well, hello!".to_vec(), AlignedU64::from(123), ); diff --git a/veilid-core/src/veilid_api/types/app_message_call.rs b/veilid-core/src/veilid_api/types/app_message_call.rs index ff117e5e..388ace53 100644 --- a/veilid-core/src/veilid_api/types/app_message_call.rs +++ b/veilid-core/src/veilid_api/types/app_message_call.rs @@ -9,6 +9,11 @@ pub struct VeilidAppMessage { #[cfg_attr(target_arch = "wasm32", tsify(optional, type = "string"))] sender: Option, + #[serde(with = "as_human_opt_string")] + #[schemars(with = "Option")] + #[cfg_attr(target_arch = "wasm32", tsify(optional, type = "string"))] + route_id: Option, + #[cfg_attr(not(target_arch = "wasm32"), serde(with = "as_human_base64"))] #[schemars(with = "String")] #[cfg_attr( @@ -20,8 +25,12 @@ pub struct VeilidAppMessage { } impl VeilidAppMessage { - pub fn new(sender: Option, message: Vec) -> Self { - Self { sender, message } + pub fn new(sender: Option, route_id: Option, message: Vec) -> Self { + Self { + sender, + route_id, + message, + } } /// Some(sender) if the message was sent directly, None if received via a private/safety route @@ -29,6 +38,11 @@ impl VeilidAppMessage { self.sender.as_ref() } + /// Some(route_id) if the message was received over a private route, None if received only a safety route or directly + pub fn route_id(&self) -> Option<&RouteId> { + self.route_id.as_ref() + } + /// The content of the message to deliver to the application pub fn message(&self) -> &[u8] { &self.message @@ -44,6 +58,11 @@ pub struct VeilidAppCall { #[cfg_attr(target_arch = "wasm32", tsify(optional))] sender: Option, + #[serde(with = "as_human_opt_string")] + #[schemars(with = "Option")] + #[cfg_attr(target_arch = "wasm32", tsify(optional, type = "string"))] + route_id: Option, + #[cfg_attr(not(target_arch = "wasm32"), serde(with = "as_human_base64"))] #[schemars(with = "String")] #[cfg_attr( @@ -59,9 +78,15 @@ pub struct VeilidAppCall { } impl VeilidAppCall { - pub fn new(sender: Option, message: Vec, call_id: OperationId) -> Self { + pub fn new( + sender: Option, + route_id: Option, + message: Vec, + call_id: OperationId, + ) -> Self { Self { sender, + route_id, message, call_id, } @@ -71,6 +96,12 @@ impl VeilidAppCall { pub fn sender(&self) -> Option<&TypedKey> { self.sender.as_ref() } + + /// Some(route_id) if the request was received over a private route, None if received only a safety route or directly + pub fn route_id(&self) -> Option<&RouteId> { + self.route_id.as_ref() + } + /// The content of the request to deliver to the application pub fn message(&self) -> &[u8] { &self.message diff --git a/veilid-flutter/lib/veilid.dart b/veilid-flutter/lib/veilid.dart index c66364f4..d31c0a44 100644 --- a/veilid-flutter/lib/veilid.dart +++ b/veilid-flutter/lib/veilid.dart @@ -150,7 +150,7 @@ abstract class Veilid { Future newCustomPrivateRoute( Stability stability, Sequencing sequencing); Future importRemotePrivateRoute(Uint8List blob); - Future releasePrivateRoute(String key); + Future releasePrivateRoute(String routeId); // App calls Future appCallReply(String callId, Uint8List message); diff --git a/veilid-flutter/lib/veilid_ffi.dart b/veilid-flutter/lib/veilid_ffi.dart index d4f5abb9..c16122f0 100644 --- a/veilid-flutter/lib/veilid_ffi.dart +++ b/veilid-flutter/lib/veilid_ffi.dart @@ -1613,12 +1613,12 @@ class VeilidFFI extends Veilid { } @override - Future releasePrivateRoute(String key) async { - final nativeEncodedKey = key.toNativeUtf8(); + Future releasePrivateRoute(String routeId) async { + final nativeEncodedRouteId = routeId.toNativeUtf8(); final recvPort = ReceivePort('release_private_route'); final sendPort = recvPort.sendPort; - _releasePrivateRoute(sendPort.nativePort, nativeEncodedKey); + _releasePrivateRoute(sendPort.nativePort, nativeEncodedRouteId); return processFutureVoid(recvPort.first); } diff --git a/veilid-flutter/lib/veilid_js.dart b/veilid-flutter/lib/veilid_js.dart index 96f624a7..f189c163 100644 --- a/veilid-flutter/lib/veilid_js.dart +++ b/veilid-flutter/lib/veilid_js.dart @@ -672,8 +672,8 @@ class VeilidJS extends Veilid { } @override - Future releasePrivateRoute(String key) => - _wrapApiPromise(js_util.callMethod(wasm, 'release_private_route', [key])); + Future releasePrivateRoute(String routeId) => _wrapApiPromise( + js_util.callMethod(wasm, 'release_private_route', [routeId])); @override Future appCallReply(String callId, Uint8List message) { diff --git a/veilid-flutter/lib/veilid_state.dart b/veilid-flutter/lib/veilid_state.dart index 6286c6fc..d5d2f366 100644 --- a/veilid-flutter/lib/veilid_state.dart +++ b/veilid-flutter/lib/veilid_state.dart @@ -146,11 +146,13 @@ sealed class VeilidUpdate with _$VeilidUpdate { const factory VeilidUpdate.appMessage({ @Uint8ListJsonConverter() required Uint8List message, TypedKey? sender, + String? routeId, }) = VeilidAppMessage; const factory VeilidUpdate.appCall({ @Uint8ListJsonConverter() required Uint8List message, required String callId, TypedKey? sender, + String? routeId, }) = VeilidAppCall; const factory VeilidUpdate.attachment( {required AttachmentState state, diff --git a/veilid-flutter/lib/veilid_state.freezed.dart b/veilid-flutter/lib/veilid_state.freezed.dart index 2a4e4eac..5759ae7b 100644 --- a/veilid-flutter/lib/veilid_state.freezed.dart +++ b/veilid-flutter/lib/veilid_state.freezed.dart @@ -1339,10 +1339,10 @@ mixin _$VeilidUpdate { VeilidLogLevel logLevel, String message, String? backtrace) log, required TResult Function(@Uint8ListJsonConverter() Uint8List message, - Typed? sender) + Typed? sender, String? routeId) appMessage, required TResult Function(@Uint8ListJsonConverter() Uint8List message, - String callId, Typed? sender) + String callId, Typed? sender, String? routeId) appCall, required TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady) @@ -1365,10 +1365,13 @@ mixin _$VeilidUpdate { VeilidLogLevel logLevel, String message, String? backtrace)? log, TResult? Function(@Uint8ListJsonConverter() Uint8List message, - Typed? sender)? + Typed? sender, String? routeId)? appMessage, - TResult? Function(@Uint8ListJsonConverter() Uint8List message, - String callId, Typed? sender)? + TResult? Function( + @Uint8ListJsonConverter() Uint8List message, + String callId, + Typed? sender, + String? routeId)? appCall, TResult? Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -1390,10 +1393,10 @@ mixin _$VeilidUpdate { VeilidLogLevel logLevel, String message, String? backtrace)? log, TResult Function(@Uint8ListJsonConverter() Uint8List message, - Typed? sender)? + Typed? sender, String? routeId)? appMessage, TResult Function(@Uint8ListJsonConverter() Uint8List message, String callId, - Typed? sender)? + Typed? sender, String? routeId)? appCall, TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -1566,10 +1569,10 @@ class _$VeilidLogImpl implements VeilidLog { VeilidLogLevel logLevel, String message, String? backtrace) log, required TResult Function(@Uint8ListJsonConverter() Uint8List message, - Typed? sender) + Typed? sender, String? routeId) appMessage, required TResult Function(@Uint8ListJsonConverter() Uint8List message, - String callId, Typed? sender) + String callId, Typed? sender, String? routeId) appCall, required TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady) @@ -1595,10 +1598,13 @@ class _$VeilidLogImpl implements VeilidLog { VeilidLogLevel logLevel, String message, String? backtrace)? log, TResult? Function(@Uint8ListJsonConverter() Uint8List message, - Typed? sender)? + Typed? sender, String? routeId)? appMessage, - TResult? Function(@Uint8ListJsonConverter() Uint8List message, - String callId, Typed? sender)? + TResult? Function( + @Uint8ListJsonConverter() Uint8List message, + String callId, + Typed? sender, + String? routeId)? appCall, TResult? Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -1623,10 +1629,10 @@ class _$VeilidLogImpl implements VeilidLog { VeilidLogLevel logLevel, String message, String? backtrace)? log, TResult Function(@Uint8ListJsonConverter() Uint8List message, - Typed? sender)? + Typed? sender, String? routeId)? appMessage, TResult Function(@Uint8ListJsonConverter() Uint8List message, String callId, - Typed? sender)? + Typed? sender, String? routeId)? appCall, TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -1730,7 +1736,8 @@ abstract class _$$VeilidAppMessageImplCopyWith<$Res> { @useResult $Res call( {@Uint8ListJsonConverter() Uint8List message, - Typed? sender}); + Typed? sender, + String? routeId}); } /// @nodoc @@ -1746,6 +1753,7 @@ class __$$VeilidAppMessageImplCopyWithImpl<$Res> $Res call({ Object? message = null, Object? sender = freezed, + Object? routeId = freezed, }) { return _then(_$VeilidAppMessageImpl( message: null == message @@ -1756,6 +1764,10 @@ class __$$VeilidAppMessageImplCopyWithImpl<$Res> ? _value.sender : sender // ignore: cast_nullable_to_non_nullable as Typed?, + routeId: freezed == routeId + ? _value.routeId + : routeId // ignore: cast_nullable_to_non_nullable + as String?, )); } } @@ -1766,6 +1778,7 @@ class _$VeilidAppMessageImpl implements VeilidAppMessage { const _$VeilidAppMessageImpl( {@Uint8ListJsonConverter() required this.message, this.sender, + this.routeId, final String? $type}) : $type = $type ?? 'AppMessage'; @@ -1777,13 +1790,15 @@ class _$VeilidAppMessageImpl implements VeilidAppMessage { final Uint8List message; @override final Typed? sender; + @override + final String? routeId; @JsonKey(name: 'kind') final String $type; @override String toString() { - return 'VeilidUpdate.appMessage(message: $message, sender: $sender)'; + return 'VeilidUpdate.appMessage(message: $message, sender: $sender, routeId: $routeId)'; } @override @@ -1792,13 +1807,14 @@ class _$VeilidAppMessageImpl implements VeilidAppMessage { (other.runtimeType == runtimeType && other is _$VeilidAppMessageImpl && const DeepCollectionEquality().equals(other.message, message) && - (identical(other.sender, sender) || other.sender == sender)); + (identical(other.sender, sender) || other.sender == sender) && + (identical(other.routeId, routeId) || other.routeId == routeId)); } @JsonKey(ignore: true) @override - int get hashCode => Object.hash( - runtimeType, const DeepCollectionEquality().hash(message), sender); + int get hashCode => Object.hash(runtimeType, + const DeepCollectionEquality().hash(message), sender, routeId); @JsonKey(ignore: true) @override @@ -1814,10 +1830,10 @@ class _$VeilidAppMessageImpl implements VeilidAppMessage { VeilidLogLevel logLevel, String message, String? backtrace) log, required TResult Function(@Uint8ListJsonConverter() Uint8List message, - Typed? sender) + Typed? sender, String? routeId) appMessage, required TResult Function(@Uint8ListJsonConverter() Uint8List message, - String callId, Typed? sender) + String callId, Typed? sender, String? routeId) appCall, required TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady) @@ -1833,7 +1849,7 @@ class _$VeilidAppMessageImpl implements VeilidAppMessage { List subkeys, int count, ValueData value) valueChange, }) { - return appMessage(message, sender); + return appMessage(message, sender, routeId); } @override @@ -1843,10 +1859,13 @@ class _$VeilidAppMessageImpl implements VeilidAppMessage { VeilidLogLevel logLevel, String message, String? backtrace)? log, TResult? Function(@Uint8ListJsonConverter() Uint8List message, - Typed? sender)? + Typed? sender, String? routeId)? appMessage, - TResult? Function(@Uint8ListJsonConverter() Uint8List message, - String callId, Typed? sender)? + TResult? Function( + @Uint8ListJsonConverter() Uint8List message, + String callId, + Typed? sender, + String? routeId)? appCall, TResult? Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -1861,7 +1880,7 @@ class _$VeilidAppMessageImpl implements VeilidAppMessage { List subkeys, int count, ValueData value)? valueChange, }) { - return appMessage?.call(message, sender); + return appMessage?.call(message, sender, routeId); } @override @@ -1871,10 +1890,10 @@ class _$VeilidAppMessageImpl implements VeilidAppMessage { VeilidLogLevel logLevel, String message, String? backtrace)? log, TResult Function(@Uint8ListJsonConverter() Uint8List message, - Typed? sender)? + Typed? sender, String? routeId)? appMessage, TResult Function(@Uint8ListJsonConverter() Uint8List message, String callId, - Typed? sender)? + Typed? sender, String? routeId)? appCall, TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -1891,7 +1910,7 @@ class _$VeilidAppMessageImpl implements VeilidAppMessage { required TResult orElse(), }) { if (appMessage != null) { - return appMessage(message, sender); + return appMessage(message, sender, routeId); } return orElse(); } @@ -1956,7 +1975,8 @@ class _$VeilidAppMessageImpl implements VeilidAppMessage { abstract class VeilidAppMessage implements VeilidUpdate { const factory VeilidAppMessage( {@Uint8ListJsonConverter() required final Uint8List message, - final Typed? sender}) = _$VeilidAppMessageImpl; + final Typed? sender, + final String? routeId}) = _$VeilidAppMessageImpl; factory VeilidAppMessage.fromJson(Map json) = _$VeilidAppMessageImpl.fromJson; @@ -1964,6 +1984,7 @@ abstract class VeilidAppMessage implements VeilidUpdate { @Uint8ListJsonConverter() Uint8List get message; Typed? get sender; + String? get routeId; @JsonKey(ignore: true) _$$VeilidAppMessageImplCopyWith<_$VeilidAppMessageImpl> get copyWith => throw _privateConstructorUsedError; @@ -1978,7 +1999,8 @@ abstract class _$$VeilidAppCallImplCopyWith<$Res> { $Res call( {@Uint8ListJsonConverter() Uint8List message, String callId, - Typed? sender}); + Typed? sender, + String? routeId}); } /// @nodoc @@ -1995,6 +2017,7 @@ class __$$VeilidAppCallImplCopyWithImpl<$Res> Object? message = null, Object? callId = null, Object? sender = freezed, + Object? routeId = freezed, }) { return _then(_$VeilidAppCallImpl( message: null == message @@ -2009,6 +2032,10 @@ class __$$VeilidAppCallImplCopyWithImpl<$Res> ? _value.sender : sender // ignore: cast_nullable_to_non_nullable as Typed?, + routeId: freezed == routeId + ? _value.routeId + : routeId // ignore: cast_nullable_to_non_nullable + as String?, )); } } @@ -2020,6 +2047,7 @@ class _$VeilidAppCallImpl implements VeilidAppCall { {@Uint8ListJsonConverter() required this.message, required this.callId, this.sender, + this.routeId, final String? $type}) : $type = $type ?? 'AppCall'; @@ -2033,13 +2061,15 @@ class _$VeilidAppCallImpl implements VeilidAppCall { final String callId; @override final Typed? sender; + @override + final String? routeId; @JsonKey(name: 'kind') final String $type; @override String toString() { - return 'VeilidUpdate.appCall(message: $message, callId: $callId, sender: $sender)'; + return 'VeilidUpdate.appCall(message: $message, callId: $callId, sender: $sender, routeId: $routeId)'; } @override @@ -2049,13 +2079,14 @@ class _$VeilidAppCallImpl implements VeilidAppCall { other is _$VeilidAppCallImpl && const DeepCollectionEquality().equals(other.message, message) && (identical(other.callId, callId) || other.callId == callId) && - (identical(other.sender, sender) || other.sender == sender)); + (identical(other.sender, sender) || other.sender == sender) && + (identical(other.routeId, routeId) || other.routeId == routeId)); } @JsonKey(ignore: true) @override int get hashCode => Object.hash(runtimeType, - const DeepCollectionEquality().hash(message), callId, sender); + const DeepCollectionEquality().hash(message), callId, sender, routeId); @JsonKey(ignore: true) @override @@ -2070,10 +2101,10 @@ class _$VeilidAppCallImpl implements VeilidAppCall { VeilidLogLevel logLevel, String message, String? backtrace) log, required TResult Function(@Uint8ListJsonConverter() Uint8List message, - Typed? sender) + Typed? sender, String? routeId) appMessage, required TResult Function(@Uint8ListJsonConverter() Uint8List message, - String callId, Typed? sender) + String callId, Typed? sender, String? routeId) appCall, required TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady) @@ -2089,7 +2120,7 @@ class _$VeilidAppCallImpl implements VeilidAppCall { List subkeys, int count, ValueData value) valueChange, }) { - return appCall(message, callId, sender); + return appCall(message, callId, sender, routeId); } @override @@ -2099,10 +2130,13 @@ class _$VeilidAppCallImpl implements VeilidAppCall { VeilidLogLevel logLevel, String message, String? backtrace)? log, TResult? Function(@Uint8ListJsonConverter() Uint8List message, - Typed? sender)? + Typed? sender, String? routeId)? appMessage, - TResult? Function(@Uint8ListJsonConverter() Uint8List message, - String callId, Typed? sender)? + TResult? Function( + @Uint8ListJsonConverter() Uint8List message, + String callId, + Typed? sender, + String? routeId)? appCall, TResult? Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -2117,7 +2151,7 @@ class _$VeilidAppCallImpl implements VeilidAppCall { List subkeys, int count, ValueData value)? valueChange, }) { - return appCall?.call(message, callId, sender); + return appCall?.call(message, callId, sender, routeId); } @override @@ -2127,10 +2161,10 @@ class _$VeilidAppCallImpl implements VeilidAppCall { VeilidLogLevel logLevel, String message, String? backtrace)? log, TResult Function(@Uint8ListJsonConverter() Uint8List message, - Typed? sender)? + Typed? sender, String? routeId)? appMessage, TResult Function(@Uint8ListJsonConverter() Uint8List message, String callId, - Typed? sender)? + Typed? sender, String? routeId)? appCall, TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -2147,7 +2181,7 @@ class _$VeilidAppCallImpl implements VeilidAppCall { required TResult orElse(), }) { if (appCall != null) { - return appCall(message, callId, sender); + return appCall(message, callId, sender, routeId); } return orElse(); } @@ -2213,7 +2247,8 @@ abstract class VeilidAppCall implements VeilidUpdate { const factory VeilidAppCall( {@Uint8ListJsonConverter() required final Uint8List message, required final String callId, - final Typed? sender}) = _$VeilidAppCallImpl; + final Typed? sender, + final String? routeId}) = _$VeilidAppCallImpl; factory VeilidAppCall.fromJson(Map json) = _$VeilidAppCallImpl.fromJson; @@ -2222,6 +2257,7 @@ abstract class VeilidAppCall implements VeilidUpdate { Uint8List get message; String get callId; Typed? get sender; + String? get routeId; @JsonKey(ignore: true) _$$VeilidAppCallImplCopyWith<_$VeilidAppCallImpl> get copyWith => throw _privateConstructorUsedError; @@ -2332,10 +2368,10 @@ class _$VeilidUpdateAttachmentImpl implements VeilidUpdateAttachment { VeilidLogLevel logLevel, String message, String? backtrace) log, required TResult Function(@Uint8ListJsonConverter() Uint8List message, - Typed? sender) + Typed? sender, String? routeId) appMessage, required TResult Function(@Uint8ListJsonConverter() Uint8List message, - String callId, Typed? sender) + String callId, Typed? sender, String? routeId) appCall, required TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady) @@ -2361,10 +2397,13 @@ class _$VeilidUpdateAttachmentImpl implements VeilidUpdateAttachment { VeilidLogLevel logLevel, String message, String? backtrace)? log, TResult? Function(@Uint8ListJsonConverter() Uint8List message, - Typed? sender)? + Typed? sender, String? routeId)? appMessage, - TResult? Function(@Uint8ListJsonConverter() Uint8List message, - String callId, Typed? sender)? + TResult? Function( + @Uint8ListJsonConverter() Uint8List message, + String callId, + Typed? sender, + String? routeId)? appCall, TResult? Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -2389,10 +2428,10 @@ class _$VeilidUpdateAttachmentImpl implements VeilidUpdateAttachment { VeilidLogLevel logLevel, String message, String? backtrace)? log, TResult Function(@Uint8ListJsonConverter() Uint8List message, - Typed? sender)? + Typed? sender, String? routeId)? appMessage, TResult Function(@Uint8ListJsonConverter() Uint8List message, String callId, - Typed? sender)? + Typed? sender, String? routeId)? appCall, TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -2602,10 +2641,10 @@ class _$VeilidUpdateNetworkImpl implements VeilidUpdateNetwork { VeilidLogLevel logLevel, String message, String? backtrace) log, required TResult Function(@Uint8ListJsonConverter() Uint8List message, - Typed? sender) + Typed? sender, String? routeId) appMessage, required TResult Function(@Uint8ListJsonConverter() Uint8List message, - String callId, Typed? sender) + String callId, Typed? sender, String? routeId) appCall, required TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady) @@ -2631,10 +2670,13 @@ class _$VeilidUpdateNetworkImpl implements VeilidUpdateNetwork { VeilidLogLevel logLevel, String message, String? backtrace)? log, TResult? Function(@Uint8ListJsonConverter() Uint8List message, - Typed? sender)? + Typed? sender, String? routeId)? appMessage, - TResult? Function(@Uint8ListJsonConverter() Uint8List message, - String callId, Typed? sender)? + TResult? Function( + @Uint8ListJsonConverter() Uint8List message, + String callId, + Typed? sender, + String? routeId)? appCall, TResult? Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -2659,10 +2701,10 @@ class _$VeilidUpdateNetworkImpl implements VeilidUpdateNetwork { VeilidLogLevel logLevel, String message, String? backtrace)? log, TResult Function(@Uint8ListJsonConverter() Uint8List message, - Typed? sender)? + Typed? sender, String? routeId)? appMessage, TResult Function(@Uint8ListJsonConverter() Uint8List message, String callId, - Typed? sender)? + Typed? sender, String? routeId)? appCall, TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -2847,10 +2889,10 @@ class _$VeilidUpdateConfigImpl implements VeilidUpdateConfig { VeilidLogLevel logLevel, String message, String? backtrace) log, required TResult Function(@Uint8ListJsonConverter() Uint8List message, - Typed? sender) + Typed? sender, String? routeId) appMessage, required TResult Function(@Uint8ListJsonConverter() Uint8List message, - String callId, Typed? sender) + String callId, Typed? sender, String? routeId) appCall, required TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady) @@ -2876,10 +2918,13 @@ class _$VeilidUpdateConfigImpl implements VeilidUpdateConfig { VeilidLogLevel logLevel, String message, String? backtrace)? log, TResult? Function(@Uint8ListJsonConverter() Uint8List message, - Typed? sender)? + Typed? sender, String? routeId)? appMessage, - TResult? Function(@Uint8ListJsonConverter() Uint8List message, - String callId, Typed? sender)? + TResult? Function( + @Uint8ListJsonConverter() Uint8List message, + String callId, + Typed? sender, + String? routeId)? appCall, TResult? Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -2904,10 +2949,10 @@ class _$VeilidUpdateConfigImpl implements VeilidUpdateConfig { VeilidLogLevel logLevel, String message, String? backtrace)? log, TResult Function(@Uint8ListJsonConverter() Uint8List message, - Typed? sender)? + Typed? sender, String? routeId)? appMessage, TResult Function(@Uint8ListJsonConverter() Uint8List message, String callId, - Typed? sender)? + Typed? sender, String? routeId)? appCall, TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -3108,10 +3153,10 @@ class _$VeilidUpdateRouteChangeImpl implements VeilidUpdateRouteChange { VeilidLogLevel logLevel, String message, String? backtrace) log, required TResult Function(@Uint8ListJsonConverter() Uint8List message, - Typed? sender) + Typed? sender, String? routeId) appMessage, required TResult Function(@Uint8ListJsonConverter() Uint8List message, - String callId, Typed? sender) + String callId, Typed? sender, String? routeId) appCall, required TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady) @@ -3137,10 +3182,13 @@ class _$VeilidUpdateRouteChangeImpl implements VeilidUpdateRouteChange { VeilidLogLevel logLevel, String message, String? backtrace)? log, TResult? Function(@Uint8ListJsonConverter() Uint8List message, - Typed? sender)? + Typed? sender, String? routeId)? appMessage, - TResult? Function(@Uint8ListJsonConverter() Uint8List message, - String callId, Typed? sender)? + TResult? Function( + @Uint8ListJsonConverter() Uint8List message, + String callId, + Typed? sender, + String? routeId)? appCall, TResult? Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -3165,10 +3213,10 @@ class _$VeilidUpdateRouteChangeImpl implements VeilidUpdateRouteChange { VeilidLogLevel logLevel, String message, String? backtrace)? log, TResult Function(@Uint8ListJsonConverter() Uint8List message, - Typed? sender)? + Typed? sender, String? routeId)? appMessage, TResult Function(@Uint8ListJsonConverter() Uint8List message, String callId, - Typed? sender)? + Typed? sender, String? routeId)? appCall, TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -3393,10 +3441,10 @@ class _$VeilidUpdateValueChangeImpl implements VeilidUpdateValueChange { VeilidLogLevel logLevel, String message, String? backtrace) log, required TResult Function(@Uint8ListJsonConverter() Uint8List message, - Typed? sender) + Typed? sender, String? routeId) appMessage, required TResult Function(@Uint8ListJsonConverter() Uint8List message, - String callId, Typed? sender) + String callId, Typed? sender, String? routeId) appCall, required TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady) @@ -3422,10 +3470,13 @@ class _$VeilidUpdateValueChangeImpl implements VeilidUpdateValueChange { VeilidLogLevel logLevel, String message, String? backtrace)? log, TResult? Function(@Uint8ListJsonConverter() Uint8List message, - Typed? sender)? + Typed? sender, String? routeId)? appMessage, - TResult? Function(@Uint8ListJsonConverter() Uint8List message, - String callId, Typed? sender)? + TResult? Function( + @Uint8ListJsonConverter() Uint8List message, + String callId, + Typed? sender, + String? routeId)? appCall, TResult? Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -3450,10 +3501,10 @@ class _$VeilidUpdateValueChangeImpl implements VeilidUpdateValueChange { VeilidLogLevel logLevel, String message, String? backtrace)? log, TResult Function(@Uint8ListJsonConverter() Uint8List message, - Typed? sender)? + Typed? sender, String? routeId)? appMessage, TResult Function(@Uint8ListJsonConverter() Uint8List message, String callId, - Typed? sender)? + Typed? sender, String? routeId)? appCall, TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? diff --git a/veilid-flutter/lib/veilid_state.g.dart b/veilid-flutter/lib/veilid_state.g.dart index 88733fbc..b23f7504 100644 --- a/veilid-flutter/lib/veilid_state.g.dart +++ b/veilid-flutter/lib/veilid_state.g.dart @@ -137,6 +137,7 @@ _$VeilidAppMessageImpl _$$VeilidAppMessageImplFromJson( sender: json['sender'] == null ? null : Typed.fromJson(json['sender']), + routeId: json['route_id'] as String?, $type: json['kind'] as String?, ); @@ -145,6 +146,7 @@ Map _$$VeilidAppMessageImplToJson( { 'message': const Uint8ListJsonConverter().toJson(instance.message), 'sender': instance.sender?.toJson(), + 'route_id': instance.routeId, 'kind': instance.$type, }; @@ -155,6 +157,7 @@ _$VeilidAppCallImpl _$$VeilidAppCallImplFromJson(Map json) => sender: json['sender'] == null ? null : Typed.fromJson(json['sender']), + routeId: json['route_id'] as String?, $type: json['kind'] as String?, ); @@ -163,6 +166,7 @@ Map _$$VeilidAppCallImplToJson(_$VeilidAppCallImpl instance) => 'message': const Uint8ListJsonConverter().toJson(instance.message), 'call_id': instance.callId, 'sender': instance.sender?.toJson(), + 'route_id': instance.routeId, 'kind': instance.$type, }; diff --git a/veilid-python/tests/test_routing_context.py b/veilid-python/tests/test_routing_context.py index 0357ad20..0b3e9bcd 100644 --- a/veilid-python/tests/test_routing_context.py +++ b/veilid-python/tests/test_routing_context.py @@ -84,6 +84,8 @@ async def test_routing_context_app_message_loopback(): assert isinstance(update.detail, veilid.VeilidAppMessage) assert update.detail.message == message + assert update.detail.route_id is not None + finally: # release imported private route await api.release_private_route(prr) @@ -130,6 +132,7 @@ async def test_routing_context_app_call_loopback(): assert isinstance(appcall, veilid.VeilidAppCall) assert appcall.message == request + assert appcall.route_id is not None # now we reply to the request reply = b"qwer5678" diff --git a/veilid-python/veilid/schema/RecvMessage.json b/veilid-python/veilid/schema/RecvMessage.json index d8e110e4..49deabce 100644 --- a/veilid-python/veilid/schema/RecvMessage.json +++ b/veilid-python/veilid/schema/RecvMessage.json @@ -2437,6 +2437,12 @@ "message": { "type": "string" }, + "route_id": { + "type": [ + "string", + "null" + ] + }, "sender": { "type": [ "string", @@ -2466,6 +2472,12 @@ "message": { "type": "string" }, + "route_id": { + "type": [ + "string", + "null" + ] + }, "sender": { "type": [ "string", @@ -3982,7 +3994,7 @@ } }, "VeilidConfigWS": { - "description": "Enable and configure Web Sockets\n\n```yaml ws: connect: true listen: true max_connections: 16 listen_address: ':5150' path: 'ws' url: 'ws://localhost:5150/ws'", + "description": "Enable and configure Web Sockets\n\n```yaml ws: connect: true listen: true max_connections: 32 listen_address: ':5150' path: 'ws' url: 'ws://localhost:5150/ws'", "type": "object", "required": [ "connect", @@ -4018,7 +4030,7 @@ } }, "VeilidConfigWSS": { - "description": "Enable and configure Secure Web Sockets\n\n```yaml wss: connect: true listen: false max_connections: 16 listen_address: ':5150' path: 'ws' url: ''", + "description": "Enable and configure Secure Web Sockets\n\n```yaml wss: connect: true listen: false max_connections: 32 listen_address: ':5150' path: 'ws' url: ''", "type": "object", "required": [ "connect", diff --git a/veilid-python/veilid/state.py b/veilid-python/veilid/state.py index 6aab549d..373052e3 100644 --- a/veilid-python/veilid/state.py +++ b/veilid-python/veilid/state.py @@ -296,10 +296,12 @@ class VeilidLog: class VeilidAppMessage: sender: Optional[TypedKey] + route_id: Optional[RouteId] message: bytes - def __init__(self, sender: Optional[TypedKey], message: bytes): + def __init__(self, sender: Optional[TypedKey], route_id: Optional[RouteId], message: bytes): self.sender = sender + self.route_id = route_id self.message = message @classmethod @@ -307,17 +309,20 @@ class VeilidAppMessage: """JSON object hook""" return cls( None if j["sender"] is None else TypedKey(j["sender"]), + None if j["route_id"] is None else RouteId(j["route_id"]), urlsafe_b64decode_no_pad(j["message"]), ) class VeilidAppCall: sender: Optional[TypedKey] + route_id: Optional[RouteId] message: bytes call_id: OperationId - def __init__(self, sender: Optional[TypedKey], message: bytes, call_id: OperationId): + def __init__(self, sender: Optional[TypedKey], route_id: Optional[TypedKey], message: bytes, call_id: OperationId): self.sender = sender + self.route_id = route_id self.message = message self.call_id = call_id @@ -326,6 +331,7 @@ class VeilidAppCall: """JSON object hook""" return cls( None if j["sender"] is None else TypedKey(j["sender"]), + None if j["route_id"] is None else RouteId(j["route_id"]), urlsafe_b64decode_no_pad(j["message"]), OperationId(j["call_id"]), )