fixes for privacy issues, closes #357

This commit is contained in:
Christien Rioux 2024-03-08 00:17:38 -05:00
parent ab419f03ef
commit 946d33ced6
15 changed files with 261 additions and 96 deletions

View File

@ -106,6 +106,7 @@ impl RPCOperation {
.validate(validate_context.crypto.clone())
.map_err(RPCError::protocol)?;
}
// Validate operation kind
self.kind.validate(validate_context)
}

View File

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

View File

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

View File

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

View File

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

View File

@ -9,6 +9,11 @@ pub struct VeilidAppMessage {
#[cfg_attr(target_arch = "wasm32", tsify(optional, type = "string"))]
sender: Option<TypedKey>,
#[serde(with = "as_human_opt_string")]
#[schemars(with = "Option<String>")]
#[cfg_attr(target_arch = "wasm32", tsify(optional, type = "string"))]
route_id: Option<RouteId>,
#[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<TypedKey>, message: Vec<u8>) -> Self {
Self { sender, message }
pub fn new(sender: Option<TypedKey>, route_id: Option<RouteId>, message: Vec<u8>) -> 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<TypedKey>,
#[serde(with = "as_human_opt_string")]
#[schemars(with = "Option<String>")]
#[cfg_attr(target_arch = "wasm32", tsify(optional, type = "string"))]
route_id: Option<RouteId>,
#[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<TypedKey>, message: Vec<u8>, call_id: OperationId) -> Self {
pub fn new(
sender: Option<TypedKey>,
route_id: Option<RouteId>,
message: Vec<u8>,
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

View File

@ -150,7 +150,7 @@ abstract class Veilid {
Future<RouteBlob> newCustomPrivateRoute(
Stability stability, Sequencing sequencing);
Future<String> importRemotePrivateRoute(Uint8List blob);
Future<void> releasePrivateRoute(String key);
Future<void> releasePrivateRoute(String routeId);
// App calls
Future<void> appCallReply(String callId, Uint8List message);

View File

@ -1613,12 +1613,12 @@ class VeilidFFI extends Veilid {
}
@override
Future<void> releasePrivateRoute(String key) async {
final nativeEncodedKey = key.toNativeUtf8();
Future<void> 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);
}

View File

@ -672,8 +672,8 @@ class VeilidJS extends Veilid {
}
@override
Future<void> releasePrivateRoute(String key) =>
_wrapApiPromise(js_util.callMethod(wasm, 'release_private_route', [key]));
Future<void> releasePrivateRoute(String routeId) => _wrapApiPromise(
js_util.callMethod(wasm, 'release_private_route', [routeId]));
@override
Future<void> appCallReply(String callId, Uint8List message) {

View File

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

View File

@ -1339,10 +1339,10 @@ mixin _$VeilidUpdate {
VeilidLogLevel logLevel, String message, String? backtrace)
log,
required TResult Function(@Uint8ListJsonConverter() Uint8List message,
Typed<FixedEncodedString43>? sender)
Typed<FixedEncodedString43>? sender, String? routeId)
appMessage,
required TResult Function(@Uint8ListJsonConverter() Uint8List message,
String callId, Typed<FixedEncodedString43>? sender)
String callId, Typed<FixedEncodedString43>? 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<FixedEncodedString43>? sender)?
Typed<FixedEncodedString43>? sender, String? routeId)?
appMessage,
TResult? Function(@Uint8ListJsonConverter() Uint8List message,
String callId, Typed<FixedEncodedString43>? sender)?
TResult? Function(
@Uint8ListJsonConverter() Uint8List message,
String callId,
Typed<FixedEncodedString43>? 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<FixedEncodedString43>? sender)?
Typed<FixedEncodedString43>? sender, String? routeId)?
appMessage,
TResult Function(@Uint8ListJsonConverter() Uint8List message, String callId,
Typed<FixedEncodedString43>? sender)?
Typed<FixedEncodedString43>? 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<FixedEncodedString43>? sender)
Typed<FixedEncodedString43>? sender, String? routeId)
appMessage,
required TResult Function(@Uint8ListJsonConverter() Uint8List message,
String callId, Typed<FixedEncodedString43>? sender)
String callId, Typed<FixedEncodedString43>? 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<FixedEncodedString43>? sender)?
Typed<FixedEncodedString43>? sender, String? routeId)?
appMessage,
TResult? Function(@Uint8ListJsonConverter() Uint8List message,
String callId, Typed<FixedEncodedString43>? sender)?
TResult? Function(
@Uint8ListJsonConverter() Uint8List message,
String callId,
Typed<FixedEncodedString43>? 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<FixedEncodedString43>? sender)?
Typed<FixedEncodedString43>? sender, String? routeId)?
appMessage,
TResult Function(@Uint8ListJsonConverter() Uint8List message, String callId,
Typed<FixedEncodedString43>? sender)?
Typed<FixedEncodedString43>? 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<FixedEncodedString43>? sender});
Typed<FixedEncodedString43>? 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<FixedEncodedString43>?,
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<FixedEncodedString43>? 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<FixedEncodedString43>? sender)
Typed<FixedEncodedString43>? sender, String? routeId)
appMessage,
required TResult Function(@Uint8ListJsonConverter() Uint8List message,
String callId, Typed<FixedEncodedString43>? sender)
String callId, Typed<FixedEncodedString43>? sender, String? routeId)
appCall,
required TResult Function(AttachmentState state, bool publicInternetReady,
bool localNetworkReady)
@ -1833,7 +1849,7 @@ class _$VeilidAppMessageImpl implements VeilidAppMessage {
List<ValueSubkeyRange> 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<FixedEncodedString43>? sender)?
Typed<FixedEncodedString43>? sender, String? routeId)?
appMessage,
TResult? Function(@Uint8ListJsonConverter() Uint8List message,
String callId, Typed<FixedEncodedString43>? sender)?
TResult? Function(
@Uint8ListJsonConverter() Uint8List message,
String callId,
Typed<FixedEncodedString43>? sender,
String? routeId)?
appCall,
TResult? Function(AttachmentState state, bool publicInternetReady,
bool localNetworkReady)?
@ -1861,7 +1880,7 @@ class _$VeilidAppMessageImpl implements VeilidAppMessage {
List<ValueSubkeyRange> 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<FixedEncodedString43>? sender)?
Typed<FixedEncodedString43>? sender, String? routeId)?
appMessage,
TResult Function(@Uint8ListJsonConverter() Uint8List message, String callId,
Typed<FixedEncodedString43>? sender)?
Typed<FixedEncodedString43>? 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<FixedEncodedString43>? sender}) = _$VeilidAppMessageImpl;
final Typed<FixedEncodedString43>? sender,
final String? routeId}) = _$VeilidAppMessageImpl;
factory VeilidAppMessage.fromJson(Map<String, dynamic> json) =
_$VeilidAppMessageImpl.fromJson;
@ -1964,6 +1984,7 @@ abstract class VeilidAppMessage implements VeilidUpdate {
@Uint8ListJsonConverter()
Uint8List get message;
Typed<FixedEncodedString43>? 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<FixedEncodedString43>? sender});
Typed<FixedEncodedString43>? 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<FixedEncodedString43>?,
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<FixedEncodedString43>? 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<FixedEncodedString43>? sender)
Typed<FixedEncodedString43>? sender, String? routeId)
appMessage,
required TResult Function(@Uint8ListJsonConverter() Uint8List message,
String callId, Typed<FixedEncodedString43>? sender)
String callId, Typed<FixedEncodedString43>? sender, String? routeId)
appCall,
required TResult Function(AttachmentState state, bool publicInternetReady,
bool localNetworkReady)
@ -2089,7 +2120,7 @@ class _$VeilidAppCallImpl implements VeilidAppCall {
List<ValueSubkeyRange> 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<FixedEncodedString43>? sender)?
Typed<FixedEncodedString43>? sender, String? routeId)?
appMessage,
TResult? Function(@Uint8ListJsonConverter() Uint8List message,
String callId, Typed<FixedEncodedString43>? sender)?
TResult? Function(
@Uint8ListJsonConverter() Uint8List message,
String callId,
Typed<FixedEncodedString43>? sender,
String? routeId)?
appCall,
TResult? Function(AttachmentState state, bool publicInternetReady,
bool localNetworkReady)?
@ -2117,7 +2151,7 @@ class _$VeilidAppCallImpl implements VeilidAppCall {
List<ValueSubkeyRange> 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<FixedEncodedString43>? sender)?
Typed<FixedEncodedString43>? sender, String? routeId)?
appMessage,
TResult Function(@Uint8ListJsonConverter() Uint8List message, String callId,
Typed<FixedEncodedString43>? sender)?
Typed<FixedEncodedString43>? 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<FixedEncodedString43>? sender}) = _$VeilidAppCallImpl;
final Typed<FixedEncodedString43>? sender,
final String? routeId}) = _$VeilidAppCallImpl;
factory VeilidAppCall.fromJson(Map<String, dynamic> json) =
_$VeilidAppCallImpl.fromJson;
@ -2222,6 +2257,7 @@ abstract class VeilidAppCall implements VeilidUpdate {
Uint8List get message;
String get callId;
Typed<FixedEncodedString43>? 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<FixedEncodedString43>? sender)
Typed<FixedEncodedString43>? sender, String? routeId)
appMessage,
required TResult Function(@Uint8ListJsonConverter() Uint8List message,
String callId, Typed<FixedEncodedString43>? sender)
String callId, Typed<FixedEncodedString43>? 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<FixedEncodedString43>? sender)?
Typed<FixedEncodedString43>? sender, String? routeId)?
appMessage,
TResult? Function(@Uint8ListJsonConverter() Uint8List message,
String callId, Typed<FixedEncodedString43>? sender)?
TResult? Function(
@Uint8ListJsonConverter() Uint8List message,
String callId,
Typed<FixedEncodedString43>? 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<FixedEncodedString43>? sender)?
Typed<FixedEncodedString43>? sender, String? routeId)?
appMessage,
TResult Function(@Uint8ListJsonConverter() Uint8List message, String callId,
Typed<FixedEncodedString43>? sender)?
Typed<FixedEncodedString43>? 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<FixedEncodedString43>? sender)
Typed<FixedEncodedString43>? sender, String? routeId)
appMessage,
required TResult Function(@Uint8ListJsonConverter() Uint8List message,
String callId, Typed<FixedEncodedString43>? sender)
String callId, Typed<FixedEncodedString43>? 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<FixedEncodedString43>? sender)?
Typed<FixedEncodedString43>? sender, String? routeId)?
appMessage,
TResult? Function(@Uint8ListJsonConverter() Uint8List message,
String callId, Typed<FixedEncodedString43>? sender)?
TResult? Function(
@Uint8ListJsonConverter() Uint8List message,
String callId,
Typed<FixedEncodedString43>? 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<FixedEncodedString43>? sender)?
Typed<FixedEncodedString43>? sender, String? routeId)?
appMessage,
TResult Function(@Uint8ListJsonConverter() Uint8List message, String callId,
Typed<FixedEncodedString43>? sender)?
Typed<FixedEncodedString43>? 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<FixedEncodedString43>? sender)
Typed<FixedEncodedString43>? sender, String? routeId)
appMessage,
required TResult Function(@Uint8ListJsonConverter() Uint8List message,
String callId, Typed<FixedEncodedString43>? sender)
String callId, Typed<FixedEncodedString43>? 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<FixedEncodedString43>? sender)?
Typed<FixedEncodedString43>? sender, String? routeId)?
appMessage,
TResult? Function(@Uint8ListJsonConverter() Uint8List message,
String callId, Typed<FixedEncodedString43>? sender)?
TResult? Function(
@Uint8ListJsonConverter() Uint8List message,
String callId,
Typed<FixedEncodedString43>? 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<FixedEncodedString43>? sender)?
Typed<FixedEncodedString43>? sender, String? routeId)?
appMessage,
TResult Function(@Uint8ListJsonConverter() Uint8List message, String callId,
Typed<FixedEncodedString43>? sender)?
Typed<FixedEncodedString43>? 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<FixedEncodedString43>? sender)
Typed<FixedEncodedString43>? sender, String? routeId)
appMessage,
required TResult Function(@Uint8ListJsonConverter() Uint8List message,
String callId, Typed<FixedEncodedString43>? sender)
String callId, Typed<FixedEncodedString43>? 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<FixedEncodedString43>? sender)?
Typed<FixedEncodedString43>? sender, String? routeId)?
appMessage,
TResult? Function(@Uint8ListJsonConverter() Uint8List message,
String callId, Typed<FixedEncodedString43>? sender)?
TResult? Function(
@Uint8ListJsonConverter() Uint8List message,
String callId,
Typed<FixedEncodedString43>? 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<FixedEncodedString43>? sender)?
Typed<FixedEncodedString43>? sender, String? routeId)?
appMessage,
TResult Function(@Uint8ListJsonConverter() Uint8List message, String callId,
Typed<FixedEncodedString43>? sender)?
Typed<FixedEncodedString43>? 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<FixedEncodedString43>? sender)
Typed<FixedEncodedString43>? sender, String? routeId)
appMessage,
required TResult Function(@Uint8ListJsonConverter() Uint8List message,
String callId, Typed<FixedEncodedString43>? sender)
String callId, Typed<FixedEncodedString43>? 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<FixedEncodedString43>? sender)?
Typed<FixedEncodedString43>? sender, String? routeId)?
appMessage,
TResult? Function(@Uint8ListJsonConverter() Uint8List message,
String callId, Typed<FixedEncodedString43>? sender)?
TResult? Function(
@Uint8ListJsonConverter() Uint8List message,
String callId,
Typed<FixedEncodedString43>? 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<FixedEncodedString43>? sender)?
Typed<FixedEncodedString43>? sender, String? routeId)?
appMessage,
TResult Function(@Uint8ListJsonConverter() Uint8List message, String callId,
Typed<FixedEncodedString43>? sender)?
Typed<FixedEncodedString43>? sender, String? routeId)?
appCall,
TResult Function(AttachmentState state, bool publicInternetReady,
bool localNetworkReady)?

View File

@ -137,6 +137,7 @@ _$VeilidAppMessageImpl _$$VeilidAppMessageImplFromJson(
sender: json['sender'] == null
? null
: Typed<FixedEncodedString43>.fromJson(json['sender']),
routeId: json['route_id'] as String?,
$type: json['kind'] as String?,
);
@ -145,6 +146,7 @@ Map<String, dynamic> _$$VeilidAppMessageImplToJson(
<String, dynamic>{
'message': const Uint8ListJsonConverter().toJson(instance.message),
'sender': instance.sender?.toJson(),
'route_id': instance.routeId,
'kind': instance.$type,
};
@ -155,6 +157,7 @@ _$VeilidAppCallImpl _$$VeilidAppCallImplFromJson(Map<String, dynamic> json) =>
sender: json['sender'] == null
? null
: Typed<FixedEncodedString43>.fromJson(json['sender']),
routeId: json['route_id'] as String?,
$type: json['kind'] as String?,
);
@ -163,6 +166,7 @@ Map<String, dynamic> _$$VeilidAppCallImplToJson(_$VeilidAppCallImpl instance) =>
'message': const Uint8ListJsonConverter().toJson(instance.message),
'call_id': instance.callId,
'sender': instance.sender?.toJson(),
'route_id': instance.routeId,
'kind': instance.$type,
};

View File

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

View File

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

View File

@ -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"]),
)