From 8913f827ffeebf94ab3b37754c010fccc42e48bb Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Tue, 1 Aug 2023 00:40:11 -0400 Subject: [PATCH 01/15] doc --- veilid-flutter/example/pubspec.lock | 2 +- veilid-tools/src/eventual.rs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/veilid-flutter/example/pubspec.lock b/veilid-flutter/example/pubspec.lock index b121351f..da827445 100644 --- a/veilid-flutter/example/pubspec.lock +++ b/veilid-flutter/example/pubspec.lock @@ -403,7 +403,7 @@ packages: path: ".." relative: true source: path - version: "0.1.6" + version: "0.1.7" win32: dependency: transitive description: diff --git a/veilid-tools/src/eventual.rs b/veilid-tools/src/eventual.rs index 9ad0f6c0..a0a49a47 100644 --- a/veilid-tools/src/eventual.rs +++ b/veilid-tools/src/eventual.rs @@ -1,3 +1,10 @@ +/// Eventual is like Dart's "Completer" +/// It is a thread-safe concurrent data future that may eventually resolve to a value +/// Three variants exist +/// Eventual, which will complete each 'instance' future to that instance's value (can be different per instance) only when 'resolve' is called. +/// EventualValue, which will complete each 'instance' future when 'resolve' is called with an owned value, and one of those instances may 'take' the value. +/// EventualValueClone, which will complete each 'instance' future when 'resolve' is called with a Clone-able value, and any of those instances may get a clone of that value. +/// The future returned from an Eventual::resolve() can also be awaited on to wait until all instances have been completed use super::*; use eventual_base::*; From 01aa41149852f24eaa121d0fb4b1a4106e412f4b Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Tue, 1 Aug 2023 18:09:31 -0400 Subject: [PATCH 02/15] punishments --- veilid-core/src/veilid_api/debug.rs | 25 +++++++++++++++++++++++++ veilid-flutter/pubspec.yaml | 3 ++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/veilid-core/src/veilid_api/debug.rs b/veilid-core/src/veilid_api/debug.rs index 3dfa1b5f..4b93db45 100644 --- a/veilid-core/src/veilid_api/debug.rs +++ b/veilid-core/src/veilid_api/debug.rs @@ -1341,6 +1341,28 @@ impl VeilidAPI { } } + async fn debug_punish_list(&self, _args: Vec) -> VeilidAPIResult { + // + let network_manager = self.network_manager()?; + let address_filter = network_manager.address_filter(); + + let out = format!("Address Filter Punishments:\n{:#?}", address_filter); + return Ok(out); + } + + async fn debug_punish(&self, args: String) -> VeilidAPIResult { + let args: Vec = + shell_words::split(&args).map_err(|e| VeilidAPIError::parse_error(e, args))?; + + let command = get_debug_argument_at(&args, 0, "debug_punish", "command", get_string)?; + + if command == "list" { + self.debug_punish_list(args).await + } else { + Ok(">>> Unknown command\n".to_owned()) + } + } + pub async fn debug_help(&self, _args: String) -> VeilidAPIResult { Ok(r#"buckets [dead|reliable] dialinfo @@ -1358,6 +1380,7 @@ restart network contact [] ping relay [public|local] +punish list route allocate [ord|*ord] [rel] [] [in|out] release publish [full] @@ -1450,6 +1473,8 @@ record list self.debug_route(rest).await } else if arg == "record" { self.debug_record(rest).await + } else if arg == "punish" { + self.debug_punish(rest).await } else { Err(VeilidAPIError::generic("Unknown server debug command")) } diff --git a/veilid-flutter/pubspec.yaml b/veilid-flutter/pubspec.yaml index efe8114f..6aa84ed0 100644 --- a/veilid-flutter/pubspec.yaml +++ b/veilid-flutter/pubspec.yaml @@ -6,7 +6,8 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev environment: sdk: '>=3.0.0 <4.0.0' - + flutter: '>=3.10.6' + dependencies: change_case: ^1.0.1 charcode: ^1.3.1 From 79bf6fca6983c558e69fc68f9591370fbc497e1f Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Tue, 1 Aug 2023 18:14:53 -0400 Subject: [PATCH 03/15] fix bug --- veilid-core/src/network_manager/address_filter.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/veilid-core/src/network_manager/address_filter.rs b/veilid-core/src/network_manager/address_filter.rs index 5bb1ec4b..417ebd4e 100644 --- a/veilid-core/src/network_manager/address_filter.rs +++ b/veilid-core/src/network_manager/address_filter.rs @@ -361,7 +361,7 @@ impl AddressFilter { Entry::Occupied(mut o) => { let cnt = o.get_mut(); assert!(*cnt > 0); - if *cnt == 0 { + if *cnt == 1 { inner.conn_count_by_ip4.remove(&v4); } else { *cnt -= 1; @@ -377,7 +377,7 @@ impl AddressFilter { Entry::Occupied(mut o) => { let cnt = o.get_mut(); assert!(*cnt > 0); - if *cnt == 0 { + if *cnt == 1 { inner.conn_count_by_ip6_prefix.remove(&v6); } else { *cnt -= 1; From 559ac5f1622d7dfdd8b8d25bd5386f5109f29891 Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Wed, 2 Aug 2023 15:13:23 -0400 Subject: [PATCH 04/15] fix server port allocation --- .../network_manager/native/start_protocols.rs | 16 ++++++-------- veilid-server/src/settings.rs | 22 ++++++++++++------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/veilid-core/src/network_manager/native/start_protocols.rs b/veilid-core/src/network_manager/native/start_protocols.rs index 25286249..416225c4 100644 --- a/veilid-core/src/network_manager/native/start_protocols.rs +++ b/veilid-core/src/network_manager/native/start_protocols.rs @@ -164,9 +164,9 @@ impl Network { ///////////////////////////////////////////////////// - fn find_available_udp_port(&self) -> EyreResult { + fn find_available_udp_port(&self, start_port: u16) -> EyreResult { // If the address is empty, iterate ports until we find one we can use. - let mut udp_port = 5150u16; + let mut udp_port = start_port; loop { if BAD_PORTS.contains(&udp_port) { continue; @@ -182,9 +182,9 @@ impl Network { Ok(udp_port) } - fn find_available_tcp_port(&self) -> EyreResult { + fn find_available_tcp_port(&self, start_port: u16) -> EyreResult { // If the address is empty, iterate ports until we find one we can use. - let mut tcp_port = 5150u16; + let mut tcp_port = start_port; loop { if BAD_PORTS.contains(&tcp_port) { continue; @@ -203,7 +203,7 @@ impl Network { async fn allocate_udp_port(&self, listen_address: String) -> EyreResult<(u16, Vec)> { if listen_address.is_empty() { // If listen address is empty, find us a port iteratively - let port = self.find_available_udp_port()?; + let port = self.find_available_udp_port(5150)?; let ip_addrs = vec![ IpAddr::V4(Ipv4Addr::UNSPECIFIED), IpAddr::V6(Ipv6Addr::UNSPECIFIED), @@ -218,9 +218,7 @@ impl Network { bail!("No valid listen address: {}", listen_address); } let port = sockaddrs[0].port(); - if !self.bind_first_udp_port(port) { - bail!("Could not find free udp port to listen on"); - } + Ok((port, sockaddrs.iter().map(|s| s.ip()).collect())) } } @@ -228,7 +226,7 @@ impl Network { async fn allocate_tcp_port(&self, listen_address: String) -> EyreResult<(u16, Vec)> { if listen_address.is_empty() { // If listen address is empty, find us a port iteratively - let port = self.find_available_tcp_port()?; + let port = self.find_available_tcp_port(5150)?; let ip_addrs = vec![ IpAddr::V4(Ipv4Addr::UNSPECIFIED), IpAddr::V6(Ipv6Addr::UNSPECIFIED), diff --git a/veilid-server/src/settings.rs b/veilid-server/src/settings.rs index 3e41eac3..701e92d3 100644 --- a/veilid-server/src/settings.rs +++ b/veilid-server/src/settings.rs @@ -120,38 +120,38 @@ core: application: https: enabled: false - listen_address: ':5150' + listen_address: ':443' path: 'app' - # url: 'https://localhost:5150' + # url: 'https://localhost' http: enabled: false - listen_address: ':5150' + listen_address: ':80' path: 'app' - # url: 'http://localhost:5150' + # url: 'http://localhost' protocol: udp: enabled: true socket_pool_size: 0 - listen_address: ':5150' + listen_address: '' # public_address: '' tcp: connect: true listen: true max_connections: 32 - listen_address: ':5150' + listen_address: '' #'public_address: '' ws: connect: true listen: true max_connections: 16 - listen_address: ':5150' + listen_address: '' path: 'ws' # url: 'ws://localhost:5150/ws' wss: connect: true listen: false max_connections: 16 - listen_address: ':5150' + listen_address: '' path: 'ws' # url: '' "#, @@ -351,6 +351,12 @@ pub struct NamedSocketAddrs { impl FromStr for NamedSocketAddrs { type Err = std::io::Error; fn from_str(s: &str) -> Result { + if s.is_empty() { + return Ok(NamedSocketAddrs { + name: String::new(), + addrs: vec![], + }); + } let addr_iter = listen_address_to_socket_addrs(s) .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidInput, e))?; Ok(NamedSocketAddrs { From 7ba795132b3d330606595c6718b306d5d99613d4 Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Wed, 2 Aug 2023 21:09:47 -0400 Subject: [PATCH 05/15] crypto primitives --- veilid-flutter/example/pubspec.lock | 10 +- .../lib/routing_context.freezed.dart | 118 +++--- veilid-flutter/lib/routing_context.g.dart | 14 +- veilid-flutter/lib/veilid.dart | 9 +- veilid-flutter/lib/veilid_config.freezed.dart | 170 ++++---- veilid-flutter/lib/veilid_config.g.dart | 77 ++-- veilid-flutter/lib/veilid_crypto.dart | 46 +++ veilid-flutter/lib/veilid_state.freezed.dart | 383 +++++++++--------- veilid-flutter/lib/veilid_state.g.dart | 62 ++- veilid-flutter/pubspec.yaml | 1 + 10 files changed, 465 insertions(+), 425 deletions(-) diff --git a/veilid-flutter/example/pubspec.lock b/veilid-flutter/example/pubspec.lock index da827445..81b9dd42 100644 --- a/veilid-flutter/example/pubspec.lock +++ b/veilid-flutter/example/pubspec.lock @@ -113,6 +113,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.1" + fixnum: + dependency: transitive + description: + name: fixnum + sha256: "25517a4deb0c03aa0f32fd12db525856438902d9c16536311e76cdc57b31d7d1" + url: "https://pub.dev" + source: hosted + version: "1.1.0" flutter: dependency: "direct main" description: flutter @@ -430,4 +438,4 @@ packages: version: "3.5.0" sdks: dart: ">=3.0.0 <4.0.0" - flutter: ">=3.7.0" + flutter: ">=3.10.6" diff --git a/veilid-flutter/lib/routing_context.freezed.dart b/veilid-flutter/lib/routing_context.freezed.dart index 4bfc27c5..140c2214 100644 --- a/veilid-flutter/lib/routing_context.freezed.dart +++ b/veilid-flutter/lib/routing_context.freezed.dart @@ -600,8 +600,8 @@ DHTRecordDescriptor _$DHTRecordDescriptorFromJson(Map json) { mixin _$DHTRecordDescriptor { Typed get key => throw _privateConstructorUsedError; FixedEncodedString43 get owner => throw _privateConstructorUsedError; - FixedEncodedString43? get ownerSecret => throw _privateConstructorUsedError; DHTSchema get schema => throw _privateConstructorUsedError; + FixedEncodedString43? get ownerSecret => throw _privateConstructorUsedError; Map toJson() => throw _privateConstructorUsedError; @JsonKey(ignore: true) @@ -618,8 +618,8 @@ abstract class $DHTRecordDescriptorCopyWith<$Res> { $Res call( {Typed key, FixedEncodedString43 owner, - FixedEncodedString43? ownerSecret, - DHTSchema schema}); + DHTSchema schema, + FixedEncodedString43? ownerSecret}); $DHTSchemaCopyWith<$Res> get schema; } @@ -639,8 +639,8 @@ class _$DHTRecordDescriptorCopyWithImpl<$Res, $Val extends DHTRecordDescriptor> $Res call({ Object? key = null, Object? owner = null, - Object? ownerSecret = freezed, Object? schema = null, + Object? ownerSecret = freezed, }) { return _then(_value.copyWith( key: null == key @@ -651,14 +651,14 @@ class _$DHTRecordDescriptorCopyWithImpl<$Res, $Val extends DHTRecordDescriptor> ? _value.owner : owner // ignore: cast_nullable_to_non_nullable as FixedEncodedString43, - ownerSecret: freezed == ownerSecret - ? _value.ownerSecret - : ownerSecret // ignore: cast_nullable_to_non_nullable - as FixedEncodedString43?, schema: null == schema ? _value.schema : schema // ignore: cast_nullable_to_non_nullable as DHTSchema, + ownerSecret: freezed == ownerSecret + ? _value.ownerSecret + : ownerSecret // ignore: cast_nullable_to_non_nullable + as FixedEncodedString43?, ) as $Val); } @@ -682,8 +682,8 @@ abstract class _$$_DHTRecordDescriptorCopyWith<$Res> $Res call( {Typed key, FixedEncodedString43 owner, - FixedEncodedString43? ownerSecret, - DHTSchema schema}); + DHTSchema schema, + FixedEncodedString43? ownerSecret}); @override $DHTSchemaCopyWith<$Res> get schema; @@ -702,8 +702,8 @@ class __$$_DHTRecordDescriptorCopyWithImpl<$Res> $Res call({ Object? key = null, Object? owner = null, - Object? ownerSecret = freezed, Object? schema = null, + Object? ownerSecret = freezed, }) { return _then(_$_DHTRecordDescriptor( key: null == key @@ -714,14 +714,14 @@ class __$$_DHTRecordDescriptorCopyWithImpl<$Res> ? _value.owner : owner // ignore: cast_nullable_to_non_nullable as FixedEncodedString43, - ownerSecret: freezed == ownerSecret - ? _value.ownerSecret - : ownerSecret // ignore: cast_nullable_to_non_nullable - as FixedEncodedString43?, schema: null == schema ? _value.schema : schema // ignore: cast_nullable_to_non_nullable as DHTSchema, + ownerSecret: freezed == ownerSecret + ? _value.ownerSecret + : ownerSecret // ignore: cast_nullable_to_non_nullable + as FixedEncodedString43?, )); } } @@ -732,8 +732,8 @@ class _$_DHTRecordDescriptor implements _DHTRecordDescriptor { const _$_DHTRecordDescriptor( {required this.key, required this.owner, - this.ownerSecret, - required this.schema}); + required this.schema, + this.ownerSecret}); factory _$_DHTRecordDescriptor.fromJson(Map json) => _$$_DHTRecordDescriptorFromJson(json); @@ -743,13 +743,13 @@ class _$_DHTRecordDescriptor implements _DHTRecordDescriptor { @override final FixedEncodedString43 owner; @override - final FixedEncodedString43? ownerSecret; - @override final DHTSchema schema; + @override + final FixedEncodedString43? ownerSecret; @override String toString() { - return 'DHTRecordDescriptor(key: $key, owner: $owner, ownerSecret: $ownerSecret, schema: $schema)'; + return 'DHTRecordDescriptor(key: $key, owner: $owner, schema: $schema, ownerSecret: $ownerSecret)'; } @override @@ -759,14 +759,14 @@ class _$_DHTRecordDescriptor implements _DHTRecordDescriptor { other is _$_DHTRecordDescriptor && (identical(other.key, key) || other.key == key) && (identical(other.owner, owner) || other.owner == owner) && + (identical(other.schema, schema) || other.schema == schema) && (identical(other.ownerSecret, ownerSecret) || - other.ownerSecret == ownerSecret) && - (identical(other.schema, schema) || other.schema == schema)); + other.ownerSecret == ownerSecret)); } @JsonKey(ignore: true) @override - int get hashCode => Object.hash(runtimeType, key, owner, ownerSecret, schema); + int get hashCode => Object.hash(runtimeType, key, owner, schema, ownerSecret); @JsonKey(ignore: true) @override @@ -787,8 +787,8 @@ abstract class _DHTRecordDescriptor implements DHTRecordDescriptor { const factory _DHTRecordDescriptor( {required final Typed key, required final FixedEncodedString43 owner, - final FixedEncodedString43? ownerSecret, - required final DHTSchema schema}) = _$_DHTRecordDescriptor; + required final DHTSchema schema, + final FixedEncodedString43? ownerSecret}) = _$_DHTRecordDescriptor; factory _DHTRecordDescriptor.fromJson(Map json) = _$_DHTRecordDescriptor.fromJson; @@ -798,10 +798,10 @@ abstract class _DHTRecordDescriptor implements DHTRecordDescriptor { @override FixedEncodedString43 get owner; @override - FixedEncodedString43? get ownerSecret; - @override DHTSchema get schema; @override + FixedEncodedString43? get ownerSecret; + @override @JsonKey(ignore: true) _$$_DHTRecordDescriptorCopyWith<_$_DHTRecordDescriptor> get copyWith => throw _privateConstructorUsedError; @@ -1151,10 +1151,10 @@ SafetySpec _$SafetySpecFromJson(Map json) { /// @nodoc mixin _$SafetySpec { - String? get preferredRoute => throw _privateConstructorUsedError; int get hopCount => throw _privateConstructorUsedError; Stability get stability => throw _privateConstructorUsedError; Sequencing get sequencing => throw _privateConstructorUsedError; + String? get preferredRoute => throw _privateConstructorUsedError; Map toJson() => throw _privateConstructorUsedError; @JsonKey(ignore: true) @@ -1169,10 +1169,10 @@ abstract class $SafetySpecCopyWith<$Res> { _$SafetySpecCopyWithImpl<$Res, SafetySpec>; @useResult $Res call( - {String? preferredRoute, - int hopCount, + {int hopCount, Stability stability, - Sequencing sequencing}); + Sequencing sequencing, + String? preferredRoute}); } /// @nodoc @@ -1188,16 +1188,12 @@ class _$SafetySpecCopyWithImpl<$Res, $Val extends SafetySpec> @pragma('vm:prefer-inline') @override $Res call({ - Object? preferredRoute = freezed, Object? hopCount = null, Object? stability = null, Object? sequencing = null, + Object? preferredRoute = freezed, }) { return _then(_value.copyWith( - preferredRoute: freezed == preferredRoute - ? _value.preferredRoute - : preferredRoute // ignore: cast_nullable_to_non_nullable - as String?, hopCount: null == hopCount ? _value.hopCount : hopCount // ignore: cast_nullable_to_non_nullable @@ -1210,6 +1206,10 @@ class _$SafetySpecCopyWithImpl<$Res, $Val extends SafetySpec> ? _value.sequencing : sequencing // ignore: cast_nullable_to_non_nullable as Sequencing, + preferredRoute: freezed == preferredRoute + ? _value.preferredRoute + : preferredRoute // ignore: cast_nullable_to_non_nullable + as String?, ) as $Val); } } @@ -1223,10 +1223,10 @@ abstract class _$$_SafetySpecCopyWith<$Res> @override @useResult $Res call( - {String? preferredRoute, - int hopCount, + {int hopCount, Stability stability, - Sequencing sequencing}); + Sequencing sequencing, + String? preferredRoute}); } /// @nodoc @@ -1240,16 +1240,12 @@ class __$$_SafetySpecCopyWithImpl<$Res> @pragma('vm:prefer-inline') @override $Res call({ - Object? preferredRoute = freezed, Object? hopCount = null, Object? stability = null, Object? sequencing = null, + Object? preferredRoute = freezed, }) { return _then(_$_SafetySpec( - preferredRoute: freezed == preferredRoute - ? _value.preferredRoute - : preferredRoute // ignore: cast_nullable_to_non_nullable - as String?, hopCount: null == hopCount ? _value.hopCount : hopCount // ignore: cast_nullable_to_non_nullable @@ -1262,6 +1258,10 @@ class __$$_SafetySpecCopyWithImpl<$Res> ? _value.sequencing : sequencing // ignore: cast_nullable_to_non_nullable as Sequencing, + preferredRoute: freezed == preferredRoute + ? _value.preferredRoute + : preferredRoute // ignore: cast_nullable_to_non_nullable + as String?, )); } } @@ -1270,26 +1270,26 @@ class __$$_SafetySpecCopyWithImpl<$Res> @JsonSerializable() class _$_SafetySpec implements _SafetySpec { const _$_SafetySpec( - {this.preferredRoute, - required this.hopCount, + {required this.hopCount, required this.stability, - required this.sequencing}); + required this.sequencing, + this.preferredRoute}); factory _$_SafetySpec.fromJson(Map json) => _$$_SafetySpecFromJson(json); - @override - final String? preferredRoute; @override final int hopCount; @override final Stability stability; @override final Sequencing sequencing; + @override + final String? preferredRoute; @override String toString() { - return 'SafetySpec(preferredRoute: $preferredRoute, hopCount: $hopCount, stability: $stability, sequencing: $sequencing)'; + return 'SafetySpec(hopCount: $hopCount, stability: $stability, sequencing: $sequencing, preferredRoute: $preferredRoute)'; } @override @@ -1297,20 +1297,20 @@ class _$_SafetySpec implements _SafetySpec { return identical(this, other) || (other.runtimeType == runtimeType && other is _$_SafetySpec && - (identical(other.preferredRoute, preferredRoute) || - other.preferredRoute == preferredRoute) && (identical(other.hopCount, hopCount) || other.hopCount == hopCount) && (identical(other.stability, stability) || other.stability == stability) && (identical(other.sequencing, sequencing) || - other.sequencing == sequencing)); + other.sequencing == sequencing) && + (identical(other.preferredRoute, preferredRoute) || + other.preferredRoute == preferredRoute)); } @JsonKey(ignore: true) @override int get hashCode => - Object.hash(runtimeType, preferredRoute, hopCount, stability, sequencing); + Object.hash(runtimeType, hopCount, stability, sequencing, preferredRoute); @JsonKey(ignore: true) @override @@ -1328,16 +1328,14 @@ class _$_SafetySpec implements _SafetySpec { abstract class _SafetySpec implements SafetySpec { const factory _SafetySpec( - {final String? preferredRoute, - required final int hopCount, + {required final int hopCount, required final Stability stability, - required final Sequencing sequencing}) = _$_SafetySpec; + required final Sequencing sequencing, + final String? preferredRoute}) = _$_SafetySpec; factory _SafetySpec.fromJson(Map json) = _$_SafetySpec.fromJson; - @override - String? get preferredRoute; @override int get hopCount; @override @@ -1345,6 +1343,8 @@ abstract class _SafetySpec implements SafetySpec { @override Sequencing get sequencing; @override + String? get preferredRoute; + @override @JsonKey(ignore: true) _$$_SafetySpecCopyWith<_$_SafetySpec> get copyWith => throw _privateConstructorUsedError; diff --git a/veilid-flutter/lib/routing_context.g.dart b/veilid-flutter/lib/routing_context.g.dart index 7cb46bac..da5aa313 100644 --- a/veilid-flutter/lib/routing_context.g.dart +++ b/veilid-flutter/lib/routing_context.g.dart @@ -22,7 +22,7 @@ _$DHTSchemaSMPL _$$DHTSchemaSMPLFromJson(Map json) => _$DHTSchemaSMPL( oCnt: json['o_cnt'] as int, members: (json['members'] as List) - .map((e) => DHTSchemaMember.fromJson(e as Map)) + .map(DHTSchemaMember.fromJson) .toList(), $type: json['kind'] as String?, ); @@ -51,10 +51,10 @@ _$_DHTRecordDescriptor _$$_DHTRecordDescriptorFromJson( _$_DHTRecordDescriptor( key: Typed.fromJson(json['key']), owner: FixedEncodedString43.fromJson(json['owner']), + schema: DHTSchema.fromJson(json['schema']), ownerSecret: json['owner_secret'] == null ? null : FixedEncodedString43.fromJson(json['owner_secret']), - schema: DHTSchema.fromJson(json['schema'] as Map), ); Map _$$_DHTRecordDescriptorToJson( @@ -62,8 +62,8 @@ Map _$$_DHTRecordDescriptorToJson( { 'key': instance.key.toJson(), 'owner': instance.owner.toJson(), - 'owner_secret': instance.ownerSecret?.toJson(), 'schema': instance.schema.toJson(), + 'owner_secret': instance.ownerSecret?.toJson(), }; _$_ValueSubkeyRange _$$_ValueSubkeyRangeFromJson(Map json) => @@ -93,18 +93,18 @@ Map _$$_ValueDataToJson(_$_ValueData instance) => _$_SafetySpec _$$_SafetySpecFromJson(Map json) => _$_SafetySpec( - preferredRoute: json['preferred_route'] as String?, hopCount: json['hop_count'] as int, - stability: Stability.fromJson(json['stability'] as String), - sequencing: Sequencing.fromJson(json['sequencing'] as String), + stability: Stability.fromJson(json['stability']), + sequencing: Sequencing.fromJson(json['sequencing']), + preferredRoute: json['preferred_route'] as String?, ); Map _$$_SafetySpecToJson(_$_SafetySpec instance) => { - 'preferred_route': instance.preferredRoute, 'hop_count': instance.hopCount, 'stability': instance.stability.toJson(), 'sequencing': instance.sequencing.toJson(), + 'preferred_route': instance.preferredRoute, }; _$_RouteBlob _$$_RouteBlobFromJson(Map json) => _$_RouteBlob( diff --git a/veilid-flutter/lib/veilid.dart b/veilid-flutter/lib/veilid.dart index b65ac68d..378cc732 100644 --- a/veilid-flutter/lib/veilid.dart +++ b/veilid-flutter/lib/veilid.dart @@ -3,6 +3,7 @@ import 'dart:typed_data'; import 'package:equatable/equatable.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:fixnum/fixnum.dart'; ////////////////////////////////////////////////////////// @@ -61,6 +62,8 @@ class VeilidVersion extends Equatable { @immutable class Timestamp extends Equatable { const Timestamp({required this.value}); + factory Timestamp.fromInt64(Int64 i64) => + Timestamp(value: BigInt.parse(i64.toStringUnsigned())); factory Timestamp.fromString(String s) => Timestamp(value: BigInt.parse(s)); factory Timestamp.fromJson(dynamic json) => Timestamp.fromString(json as String); @@ -70,8 +73,8 @@ class Timestamp extends Equatable { @override String toString() => value.toString(); - String toJson() => toString(); + Int64 toInt64() => Int64.parseInt(value.toString()); TimestampDuration diff(Timestamp other) => TimestampDuration(value: value - other.value); @@ -83,6 +86,8 @@ class Timestamp extends Equatable { @immutable class TimestampDuration extends Equatable { const TimestampDuration({required this.value}); + factory TimestampDuration.fromInt64(Int64 i64) => + TimestampDuration(value: BigInt.parse(i64.toStringUnsigned())); factory TimestampDuration.fromString(String s) => TimestampDuration(value: BigInt.parse(s)); factory TimestampDuration.fromJson(dynamic json) => @@ -93,8 +98,8 @@ class TimestampDuration extends Equatable { @override String toString() => value.toString(); - String toJson() => toString(); + Int64 toInt64() => Int64.parseInt(value.toString()); int toMillis() => (value ~/ BigInt.from(1000)).toInt(); BigInt toMicros() => value; diff --git a/veilid-flutter/lib/veilid_config.freezed.dart b/veilid-flutter/lib/veilid_config.freezed.dart index 26554b99..779981c9 100644 --- a/veilid-flutter/lib/veilid_config.freezed.dart +++ b/veilid-flutter/lib/veilid_config.freezed.dart @@ -4377,11 +4377,11 @@ VeilidConfigRPC _$VeilidConfigRPCFromJson(Map json) { mixin _$VeilidConfigRPC { int get concurrency => throw _privateConstructorUsedError; int get queueSize => throw _privateConstructorUsedError; - int? get maxTimestampBehindMs => throw _privateConstructorUsedError; - int? get maxTimestampAheadMs => throw _privateConstructorUsedError; int get timeoutMs => throw _privateConstructorUsedError; int get maxRouteHopCount => throw _privateConstructorUsedError; int get defaultRouteHopCount => throw _privateConstructorUsedError; + int? get maxTimestampBehindMs => throw _privateConstructorUsedError; + int? get maxTimestampAheadMs => throw _privateConstructorUsedError; Map toJson() => throw _privateConstructorUsedError; @JsonKey(ignore: true) @@ -4398,11 +4398,11 @@ abstract class $VeilidConfigRPCCopyWith<$Res> { $Res call( {int concurrency, int queueSize, - int? maxTimestampBehindMs, - int? maxTimestampAheadMs, int timeoutMs, int maxRouteHopCount, - int defaultRouteHopCount}); + int defaultRouteHopCount, + int? maxTimestampBehindMs, + int? maxTimestampAheadMs}); } /// @nodoc @@ -4420,11 +4420,11 @@ class _$VeilidConfigRPCCopyWithImpl<$Res, $Val extends VeilidConfigRPC> $Res call({ Object? concurrency = null, Object? queueSize = null, - Object? maxTimestampBehindMs = freezed, - Object? maxTimestampAheadMs = freezed, Object? timeoutMs = null, Object? maxRouteHopCount = null, Object? defaultRouteHopCount = null, + Object? maxTimestampBehindMs = freezed, + Object? maxTimestampAheadMs = freezed, }) { return _then(_value.copyWith( concurrency: null == concurrency @@ -4435,14 +4435,6 @@ class _$VeilidConfigRPCCopyWithImpl<$Res, $Val extends VeilidConfigRPC> ? _value.queueSize : queueSize // ignore: cast_nullable_to_non_nullable as int, - maxTimestampBehindMs: freezed == maxTimestampBehindMs - ? _value.maxTimestampBehindMs - : maxTimestampBehindMs // ignore: cast_nullable_to_non_nullable - as int?, - maxTimestampAheadMs: freezed == maxTimestampAheadMs - ? _value.maxTimestampAheadMs - : maxTimestampAheadMs // ignore: cast_nullable_to_non_nullable - as int?, timeoutMs: null == timeoutMs ? _value.timeoutMs : timeoutMs // ignore: cast_nullable_to_non_nullable @@ -4455,6 +4447,14 @@ class _$VeilidConfigRPCCopyWithImpl<$Res, $Val extends VeilidConfigRPC> ? _value.defaultRouteHopCount : defaultRouteHopCount // ignore: cast_nullable_to_non_nullable as int, + maxTimestampBehindMs: freezed == maxTimestampBehindMs + ? _value.maxTimestampBehindMs + : maxTimestampBehindMs // ignore: cast_nullable_to_non_nullable + as int?, + maxTimestampAheadMs: freezed == maxTimestampAheadMs + ? _value.maxTimestampAheadMs + : maxTimestampAheadMs // ignore: cast_nullable_to_non_nullable + as int?, ) as $Val); } } @@ -4470,11 +4470,11 @@ abstract class _$$_VeilidConfigRPCCopyWith<$Res> $Res call( {int concurrency, int queueSize, - int? maxTimestampBehindMs, - int? maxTimestampAheadMs, int timeoutMs, int maxRouteHopCount, - int defaultRouteHopCount}); + int defaultRouteHopCount, + int? maxTimestampBehindMs, + int? maxTimestampAheadMs}); } /// @nodoc @@ -4490,11 +4490,11 @@ class __$$_VeilidConfigRPCCopyWithImpl<$Res> $Res call({ Object? concurrency = null, Object? queueSize = null, - Object? maxTimestampBehindMs = freezed, - Object? maxTimestampAheadMs = freezed, Object? timeoutMs = null, Object? maxRouteHopCount = null, Object? defaultRouteHopCount = null, + Object? maxTimestampBehindMs = freezed, + Object? maxTimestampAheadMs = freezed, }) { return _then(_$_VeilidConfigRPC( concurrency: null == concurrency @@ -4505,14 +4505,6 @@ class __$$_VeilidConfigRPCCopyWithImpl<$Res> ? _value.queueSize : queueSize // ignore: cast_nullable_to_non_nullable as int, - maxTimestampBehindMs: freezed == maxTimestampBehindMs - ? _value.maxTimestampBehindMs - : maxTimestampBehindMs // ignore: cast_nullable_to_non_nullable - as int?, - maxTimestampAheadMs: freezed == maxTimestampAheadMs - ? _value.maxTimestampAheadMs - : maxTimestampAheadMs // ignore: cast_nullable_to_non_nullable - as int?, timeoutMs: null == timeoutMs ? _value.timeoutMs : timeoutMs // ignore: cast_nullable_to_non_nullable @@ -4525,6 +4517,14 @@ class __$$_VeilidConfigRPCCopyWithImpl<$Res> ? _value.defaultRouteHopCount : defaultRouteHopCount // ignore: cast_nullable_to_non_nullable as int, + maxTimestampBehindMs: freezed == maxTimestampBehindMs + ? _value.maxTimestampBehindMs + : maxTimestampBehindMs // ignore: cast_nullable_to_non_nullable + as int?, + maxTimestampAheadMs: freezed == maxTimestampAheadMs + ? _value.maxTimestampAheadMs + : maxTimestampAheadMs // ignore: cast_nullable_to_non_nullable + as int?, )); } } @@ -4537,11 +4537,11 @@ class _$_VeilidConfigRPC const _$_VeilidConfigRPC( {required this.concurrency, required this.queueSize, - this.maxTimestampBehindMs, - this.maxTimestampAheadMs, required this.timeoutMs, required this.maxRouteHopCount, - required this.defaultRouteHopCount}); + required this.defaultRouteHopCount, + this.maxTimestampBehindMs, + this.maxTimestampAheadMs}); factory _$_VeilidConfigRPC.fromJson(Map json) => _$$_VeilidConfigRPCFromJson(json); @@ -4551,19 +4551,19 @@ class _$_VeilidConfigRPC @override final int queueSize; @override - final int? maxTimestampBehindMs; - @override - final int? maxTimestampAheadMs; - @override final int timeoutMs; @override final int maxRouteHopCount; @override final int defaultRouteHopCount; + @override + final int? maxTimestampBehindMs; + @override + final int? maxTimestampAheadMs; @override String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { - return 'VeilidConfigRPC(concurrency: $concurrency, queueSize: $queueSize, maxTimestampBehindMs: $maxTimestampBehindMs, maxTimestampAheadMs: $maxTimestampAheadMs, timeoutMs: $timeoutMs, maxRouteHopCount: $maxRouteHopCount, defaultRouteHopCount: $defaultRouteHopCount)'; + return 'VeilidConfigRPC(concurrency: $concurrency, queueSize: $queueSize, timeoutMs: $timeoutMs, maxRouteHopCount: $maxRouteHopCount, defaultRouteHopCount: $defaultRouteHopCount, maxTimestampBehindMs: $maxTimestampBehindMs, maxTimestampAheadMs: $maxTimestampAheadMs)'; } @override @@ -4573,11 +4573,11 @@ class _$_VeilidConfigRPC ..add(DiagnosticsProperty('type', 'VeilidConfigRPC')) ..add(DiagnosticsProperty('concurrency', concurrency)) ..add(DiagnosticsProperty('queueSize', queueSize)) - ..add(DiagnosticsProperty('maxTimestampBehindMs', maxTimestampBehindMs)) - ..add(DiagnosticsProperty('maxTimestampAheadMs', maxTimestampAheadMs)) ..add(DiagnosticsProperty('timeoutMs', timeoutMs)) ..add(DiagnosticsProperty('maxRouteHopCount', maxRouteHopCount)) - ..add(DiagnosticsProperty('defaultRouteHopCount', defaultRouteHopCount)); + ..add(DiagnosticsProperty('defaultRouteHopCount', defaultRouteHopCount)) + ..add(DiagnosticsProperty('maxTimestampBehindMs', maxTimestampBehindMs)) + ..add(DiagnosticsProperty('maxTimestampAheadMs', maxTimestampAheadMs)); } @override @@ -4589,16 +4589,16 @@ class _$_VeilidConfigRPC other.concurrency == concurrency) && (identical(other.queueSize, queueSize) || other.queueSize == queueSize) && - (identical(other.maxTimestampBehindMs, maxTimestampBehindMs) || - other.maxTimestampBehindMs == maxTimestampBehindMs) && - (identical(other.maxTimestampAheadMs, maxTimestampAheadMs) || - other.maxTimestampAheadMs == maxTimestampAheadMs) && (identical(other.timeoutMs, timeoutMs) || other.timeoutMs == timeoutMs) && (identical(other.maxRouteHopCount, maxRouteHopCount) || other.maxRouteHopCount == maxRouteHopCount) && (identical(other.defaultRouteHopCount, defaultRouteHopCount) || - other.defaultRouteHopCount == defaultRouteHopCount)); + other.defaultRouteHopCount == defaultRouteHopCount) && + (identical(other.maxTimestampBehindMs, maxTimestampBehindMs) || + other.maxTimestampBehindMs == maxTimestampBehindMs) && + (identical(other.maxTimestampAheadMs, maxTimestampAheadMs) || + other.maxTimestampAheadMs == maxTimestampAheadMs)); } @JsonKey(ignore: true) @@ -4607,11 +4607,11 @@ class _$_VeilidConfigRPC runtimeType, concurrency, queueSize, - maxTimestampBehindMs, - maxTimestampAheadMs, timeoutMs, maxRouteHopCount, - defaultRouteHopCount); + defaultRouteHopCount, + maxTimestampBehindMs, + maxTimestampAheadMs); @JsonKey(ignore: true) @override @@ -4631,11 +4631,11 @@ abstract class _VeilidConfigRPC implements VeilidConfigRPC { const factory _VeilidConfigRPC( {required final int concurrency, required final int queueSize, - final int? maxTimestampBehindMs, - final int? maxTimestampAheadMs, required final int timeoutMs, required final int maxRouteHopCount, - required final int defaultRouteHopCount}) = _$_VeilidConfigRPC; + required final int defaultRouteHopCount, + final int? maxTimestampBehindMs, + final int? maxTimestampAheadMs}) = _$_VeilidConfigRPC; factory _VeilidConfigRPC.fromJson(Map json) = _$_VeilidConfigRPC.fromJson; @@ -4645,16 +4645,16 @@ abstract class _VeilidConfigRPC implements VeilidConfigRPC { @override int get queueSize; @override - int? get maxTimestampBehindMs; - @override - int? get maxTimestampAheadMs; - @override int get timeoutMs; @override int get maxRouteHopCount; @override int get defaultRouteHopCount; @override + int? get maxTimestampBehindMs; + @override + int? get maxTimestampAheadMs; + @override @JsonKey(ignore: true) _$$_VeilidConfigRPCCopyWith<_$_VeilidConfigRPC> get copyWith => throw _privateConstructorUsedError; @@ -5016,7 +5016,6 @@ mixin _$VeilidConfigNetwork { int get clientWhitelistTimeoutMs => throw _privateConstructorUsedError; int get reverseConnectionReceiptTimeMs => throw _privateConstructorUsedError; int get holePunchReceiptTimeMs => throw _privateConstructorUsedError; - String? get networkKeyPassword => throw _privateConstructorUsedError; VeilidConfigRoutingTable get routingTable => throw _privateConstructorUsedError; VeilidConfigRPC get rpc => throw _privateConstructorUsedError; @@ -5027,6 +5026,7 @@ mixin _$VeilidConfigNetwork { VeilidConfigTLS get tls => throw _privateConstructorUsedError; VeilidConfigApplication get application => throw _privateConstructorUsedError; VeilidConfigProtocol get protocol => throw _privateConstructorUsedError; + String? get networkKeyPassword => throw _privateConstructorUsedError; Map toJson() => throw _privateConstructorUsedError; @JsonKey(ignore: true) @@ -5050,7 +5050,6 @@ abstract class $VeilidConfigNetworkCopyWith<$Res> { int clientWhitelistTimeoutMs, int reverseConnectionReceiptTimeMs, int holePunchReceiptTimeMs, - String? networkKeyPassword, VeilidConfigRoutingTable routingTable, VeilidConfigRPC rpc, VeilidConfigDHT dht, @@ -5059,7 +5058,8 @@ abstract class $VeilidConfigNetworkCopyWith<$Res> { int restrictedNatRetries, VeilidConfigTLS tls, VeilidConfigApplication application, - VeilidConfigProtocol protocol}); + VeilidConfigProtocol protocol, + String? networkKeyPassword}); $VeilidConfigRoutingTableCopyWith<$Res> get routingTable; $VeilidConfigRPCCopyWith<$Res> get rpc; @@ -5091,7 +5091,6 @@ class _$VeilidConfigNetworkCopyWithImpl<$Res, $Val extends VeilidConfigNetwork> Object? clientWhitelistTimeoutMs = null, Object? reverseConnectionReceiptTimeMs = null, Object? holePunchReceiptTimeMs = null, - Object? networkKeyPassword = freezed, Object? routingTable = null, Object? rpc = null, Object? dht = null, @@ -5101,6 +5100,7 @@ class _$VeilidConfigNetworkCopyWithImpl<$Res, $Val extends VeilidConfigNetwork> Object? tls = null, Object? application = null, Object? protocol = null, + Object? networkKeyPassword = freezed, }) { return _then(_value.copyWith( connectionInitialTimeoutMs: null == connectionInitialTimeoutMs @@ -5139,10 +5139,6 @@ class _$VeilidConfigNetworkCopyWithImpl<$Res, $Val extends VeilidConfigNetwork> ? _value.holePunchReceiptTimeMs : holePunchReceiptTimeMs // ignore: cast_nullable_to_non_nullable as int, - networkKeyPassword: freezed == networkKeyPassword - ? _value.networkKeyPassword - : networkKeyPassword // ignore: cast_nullable_to_non_nullable - as String?, routingTable: null == routingTable ? _value.routingTable : routingTable // ignore: cast_nullable_to_non_nullable @@ -5179,6 +5175,10 @@ class _$VeilidConfigNetworkCopyWithImpl<$Res, $Val extends VeilidConfigNetwork> ? _value.protocol : protocol // ignore: cast_nullable_to_non_nullable as VeilidConfigProtocol, + networkKeyPassword: freezed == networkKeyPassword + ? _value.networkKeyPassword + : networkKeyPassword // ignore: cast_nullable_to_non_nullable + as String?, ) as $Val); } @@ -5250,7 +5250,6 @@ abstract class _$$_VeilidConfigNetworkCopyWith<$Res> int clientWhitelistTimeoutMs, int reverseConnectionReceiptTimeMs, int holePunchReceiptTimeMs, - String? networkKeyPassword, VeilidConfigRoutingTable routingTable, VeilidConfigRPC rpc, VeilidConfigDHT dht, @@ -5259,7 +5258,8 @@ abstract class _$$_VeilidConfigNetworkCopyWith<$Res> int restrictedNatRetries, VeilidConfigTLS tls, VeilidConfigApplication application, - VeilidConfigProtocol protocol}); + VeilidConfigProtocol protocol, + String? networkKeyPassword}); @override $VeilidConfigRoutingTableCopyWith<$Res> get routingTable; @@ -5295,7 +5295,6 @@ class __$$_VeilidConfigNetworkCopyWithImpl<$Res> Object? clientWhitelistTimeoutMs = null, Object? reverseConnectionReceiptTimeMs = null, Object? holePunchReceiptTimeMs = null, - Object? networkKeyPassword = freezed, Object? routingTable = null, Object? rpc = null, Object? dht = null, @@ -5305,6 +5304,7 @@ class __$$_VeilidConfigNetworkCopyWithImpl<$Res> Object? tls = null, Object? application = null, Object? protocol = null, + Object? networkKeyPassword = freezed, }) { return _then(_$_VeilidConfigNetwork( connectionInitialTimeoutMs: null == connectionInitialTimeoutMs @@ -5343,10 +5343,6 @@ class __$$_VeilidConfigNetworkCopyWithImpl<$Res> ? _value.holePunchReceiptTimeMs : holePunchReceiptTimeMs // ignore: cast_nullable_to_non_nullable as int, - networkKeyPassword: freezed == networkKeyPassword - ? _value.networkKeyPassword - : networkKeyPassword // ignore: cast_nullable_to_non_nullable - as String?, routingTable: null == routingTable ? _value.routingTable : routingTable // ignore: cast_nullable_to_non_nullable @@ -5383,6 +5379,10 @@ class __$$_VeilidConfigNetworkCopyWithImpl<$Res> ? _value.protocol : protocol // ignore: cast_nullable_to_non_nullable as VeilidConfigProtocol, + networkKeyPassword: freezed == networkKeyPassword + ? _value.networkKeyPassword + : networkKeyPassword // ignore: cast_nullable_to_non_nullable + as String?, )); } } @@ -5402,7 +5402,6 @@ class _$_VeilidConfigNetwork required this.clientWhitelistTimeoutMs, required this.reverseConnectionReceiptTimeMs, required this.holePunchReceiptTimeMs, - this.networkKeyPassword, required this.routingTable, required this.rpc, required this.dht, @@ -5411,7 +5410,8 @@ class _$_VeilidConfigNetwork required this.restrictedNatRetries, required this.tls, required this.application, - required this.protocol}); + required this.protocol, + this.networkKeyPassword}); factory _$_VeilidConfigNetwork.fromJson(Map json) => _$$_VeilidConfigNetworkFromJson(json); @@ -5435,8 +5435,6 @@ class _$_VeilidConfigNetwork @override final int holePunchReceiptTimeMs; @override - final String? networkKeyPassword; - @override final VeilidConfigRoutingTable routingTable; @override final VeilidConfigRPC rpc; @@ -5454,10 +5452,12 @@ class _$_VeilidConfigNetwork final VeilidConfigApplication application; @override final VeilidConfigProtocol protocol; + @override + final String? networkKeyPassword; @override String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { - return 'VeilidConfigNetwork(connectionInitialTimeoutMs: $connectionInitialTimeoutMs, connectionInactivityTimeoutMs: $connectionInactivityTimeoutMs, maxConnectionsPerIp4: $maxConnectionsPerIp4, maxConnectionsPerIp6Prefix: $maxConnectionsPerIp6Prefix, maxConnectionsPerIp6PrefixSize: $maxConnectionsPerIp6PrefixSize, maxConnectionFrequencyPerMin: $maxConnectionFrequencyPerMin, clientWhitelistTimeoutMs: $clientWhitelistTimeoutMs, reverseConnectionReceiptTimeMs: $reverseConnectionReceiptTimeMs, holePunchReceiptTimeMs: $holePunchReceiptTimeMs, networkKeyPassword: $networkKeyPassword, routingTable: $routingTable, rpc: $rpc, dht: $dht, upnp: $upnp, detectAddressChanges: $detectAddressChanges, restrictedNatRetries: $restrictedNatRetries, tls: $tls, application: $application, protocol: $protocol)'; + return 'VeilidConfigNetwork(connectionInitialTimeoutMs: $connectionInitialTimeoutMs, connectionInactivityTimeoutMs: $connectionInactivityTimeoutMs, maxConnectionsPerIp4: $maxConnectionsPerIp4, maxConnectionsPerIp6Prefix: $maxConnectionsPerIp6Prefix, maxConnectionsPerIp6PrefixSize: $maxConnectionsPerIp6PrefixSize, maxConnectionFrequencyPerMin: $maxConnectionFrequencyPerMin, clientWhitelistTimeoutMs: $clientWhitelistTimeoutMs, reverseConnectionReceiptTimeMs: $reverseConnectionReceiptTimeMs, holePunchReceiptTimeMs: $holePunchReceiptTimeMs, routingTable: $routingTable, rpc: $rpc, dht: $dht, upnp: $upnp, detectAddressChanges: $detectAddressChanges, restrictedNatRetries: $restrictedNatRetries, tls: $tls, application: $application, protocol: $protocol, networkKeyPassword: $networkKeyPassword)'; } @override @@ -5482,7 +5482,6 @@ class _$_VeilidConfigNetwork 'reverseConnectionReceiptTimeMs', reverseConnectionReceiptTimeMs)) ..add( DiagnosticsProperty('holePunchReceiptTimeMs', holePunchReceiptTimeMs)) - ..add(DiagnosticsProperty('networkKeyPassword', networkKeyPassword)) ..add(DiagnosticsProperty('routingTable', routingTable)) ..add(DiagnosticsProperty('rpc', rpc)) ..add(DiagnosticsProperty('dht', dht)) @@ -5491,7 +5490,8 @@ class _$_VeilidConfigNetwork ..add(DiagnosticsProperty('restrictedNatRetries', restrictedNatRetries)) ..add(DiagnosticsProperty('tls', tls)) ..add(DiagnosticsProperty('application', application)) - ..add(DiagnosticsProperty('protocol', protocol)); + ..add(DiagnosticsProperty('protocol', protocol)) + ..add(DiagnosticsProperty('networkKeyPassword', networkKeyPassword)); } @override @@ -5524,8 +5524,6 @@ class _$_VeilidConfigNetwork reverseConnectionReceiptTimeMs) && (identical(other.holePunchReceiptTimeMs, holePunchReceiptTimeMs) || other.holePunchReceiptTimeMs == holePunchReceiptTimeMs) && - (identical(other.networkKeyPassword, networkKeyPassword) || - other.networkKeyPassword == networkKeyPassword) && (identical(other.routingTable, routingTable) || other.routingTable == routingTable) && (identical(other.rpc, rpc) || other.rpc == rpc) && @@ -5539,7 +5537,9 @@ class _$_VeilidConfigNetwork (identical(other.application, application) || other.application == application) && (identical(other.protocol, protocol) || - other.protocol == protocol)); + other.protocol == protocol) && + (identical(other.networkKeyPassword, networkKeyPassword) || + other.networkKeyPassword == networkKeyPassword)); } @JsonKey(ignore: true) @@ -5555,7 +5555,6 @@ class _$_VeilidConfigNetwork clientWhitelistTimeoutMs, reverseConnectionReceiptTimeMs, holePunchReceiptTimeMs, - networkKeyPassword, routingTable, rpc, dht, @@ -5564,7 +5563,8 @@ class _$_VeilidConfigNetwork restrictedNatRetries, tls, application, - protocol + protocol, + networkKeyPassword ]); @JsonKey(ignore: true) @@ -5593,7 +5593,6 @@ abstract class _VeilidConfigNetwork implements VeilidConfigNetwork { required final int clientWhitelistTimeoutMs, required final int reverseConnectionReceiptTimeMs, required final int holePunchReceiptTimeMs, - final String? networkKeyPassword, required final VeilidConfigRoutingTable routingTable, required final VeilidConfigRPC rpc, required final VeilidConfigDHT dht, @@ -5602,7 +5601,8 @@ abstract class _VeilidConfigNetwork implements VeilidConfigNetwork { required final int restrictedNatRetries, required final VeilidConfigTLS tls, required final VeilidConfigApplication application, - required final VeilidConfigProtocol protocol}) = _$_VeilidConfigNetwork; + required final VeilidConfigProtocol protocol, + final String? networkKeyPassword}) = _$_VeilidConfigNetwork; factory _VeilidConfigNetwork.fromJson(Map json) = _$_VeilidConfigNetwork.fromJson; @@ -5626,8 +5626,6 @@ abstract class _VeilidConfigNetwork implements VeilidConfigNetwork { @override int get holePunchReceiptTimeMs; @override - String? get networkKeyPassword; - @override VeilidConfigRoutingTable get routingTable; @override VeilidConfigRPC get rpc; @@ -5646,6 +5644,8 @@ abstract class _VeilidConfigNetwork implements VeilidConfigNetwork { @override VeilidConfigProtocol get protocol; @override + String? get networkKeyPassword; + @override @JsonKey(ignore: true) _$$_VeilidConfigNetworkCopyWith<_$_VeilidConfigNetwork> get copyWith => throw _privateConstructorUsedError; diff --git a/veilid-flutter/lib/veilid_config.g.dart b/veilid-flutter/lib/veilid_config.g.dart index fed9bae0..355367ee 100644 --- a/veilid-flutter/lib/veilid_config.g.dart +++ b/veilid-flutter/lib/veilid_config.g.dart @@ -55,12 +55,9 @@ Map _$$_VeilidFFIConfigLoggingApiToJson( _$_VeilidFFIConfigLogging _$$_VeilidFFIConfigLoggingFromJson( Map json) => _$_VeilidFFIConfigLogging( - terminal: VeilidFFIConfigLoggingTerminal.fromJson( - json['terminal'] as Map), - otlp: VeilidFFIConfigLoggingOtlp.fromJson( - json['otlp'] as Map), - api: VeilidFFIConfigLoggingApi.fromJson( - json['api'] as Map), + terminal: VeilidFFIConfigLoggingTerminal.fromJson(json['terminal']), + otlp: VeilidFFIConfigLoggingOtlp.fromJson(json['otlp']), + api: VeilidFFIConfigLoggingApi.fromJson(json['api']), ); Map _$$_VeilidFFIConfigLoggingToJson( @@ -73,8 +70,7 @@ Map _$$_VeilidFFIConfigLoggingToJson( _$_VeilidFFIConfig _$$_VeilidFFIConfigFromJson(Map json) => _$_VeilidFFIConfig( - logging: VeilidFFIConfigLogging.fromJson( - json['logging'] as Map), + logging: VeilidFFIConfigLogging.fromJson(json['logging']), ); Map _$$_VeilidFFIConfigToJson(_$_VeilidFFIConfig instance) => @@ -117,10 +113,9 @@ Map _$$_VeilidWASMConfigLoggingApiToJson( _$_VeilidWASMConfigLogging _$$_VeilidWASMConfigLoggingFromJson( Map json) => _$_VeilidWASMConfigLogging( - performance: VeilidWASMConfigLoggingPerformance.fromJson( - json['performance'] as Map), - api: VeilidWASMConfigLoggingApi.fromJson( - json['api'] as Map), + performance: + VeilidWASMConfigLoggingPerformance.fromJson(json['performance']), + api: VeilidWASMConfigLoggingApi.fromJson(json['api']), ); Map _$$_VeilidWASMConfigLoggingToJson( @@ -132,8 +127,7 @@ Map _$$_VeilidWASMConfigLoggingToJson( _$_VeilidWASMConfig _$$_VeilidWASMConfigFromJson(Map json) => _$_VeilidWASMConfig( - logging: VeilidWASMConfigLogging.fromJson( - json['logging'] as Map), + logging: VeilidWASMConfigLogging.fromJson(json['logging']), ); Map _$$_VeilidWASMConfigToJson(_$_VeilidWASMConfig instance) => @@ -177,8 +171,8 @@ Map _$$_VeilidConfigHTTPToJson(_$_VeilidConfigHTTP instance) => _$_VeilidConfigApplication _$$_VeilidConfigApplicationFromJson( Map json) => _$_VeilidConfigApplication( - https: VeilidConfigHTTPS.fromJson(json['https'] as Map), - http: VeilidConfigHTTP.fromJson(json['http'] as Map), + https: VeilidConfigHTTPS.fromJson(json['https']), + http: VeilidConfigHTTP.fromJson(json['http']), ); Map _$$_VeilidConfigApplicationToJson( @@ -265,10 +259,10 @@ Map _$$_VeilidConfigWSSToJson(_$_VeilidConfigWSS instance) => _$_VeilidConfigProtocol _$$_VeilidConfigProtocolFromJson( Map json) => _$_VeilidConfigProtocol( - udp: VeilidConfigUDP.fromJson(json['udp'] as Map), - tcp: VeilidConfigTCP.fromJson(json['tcp'] as Map), - ws: VeilidConfigWS.fromJson(json['ws'] as Map), - wss: VeilidConfigWSS.fromJson(json['wss'] as Map), + udp: VeilidConfigUDP.fromJson(json['udp']), + tcp: VeilidConfigTCP.fromJson(json['tcp']), + ws: VeilidConfigWS.fromJson(json['ws']), + wss: VeilidConfigWSS.fromJson(json['wss']), ); Map _$$_VeilidConfigProtocolToJson( @@ -349,22 +343,22 @@ _$_VeilidConfigRPC _$$_VeilidConfigRPCFromJson(Map json) => _$_VeilidConfigRPC( concurrency: json['concurrency'] as int, queueSize: json['queue_size'] as int, - maxTimestampBehindMs: json['max_timestamp_behind_ms'] as int?, - maxTimestampAheadMs: json['max_timestamp_ahead_ms'] as int?, timeoutMs: json['timeout_ms'] as int, maxRouteHopCount: json['max_route_hop_count'] as int, defaultRouteHopCount: json['default_route_hop_count'] as int, + maxTimestampBehindMs: json['max_timestamp_behind_ms'] as int?, + maxTimestampAheadMs: json['max_timestamp_ahead_ms'] as int?, ); Map _$$_VeilidConfigRPCToJson(_$_VeilidConfigRPC instance) => { 'concurrency': instance.concurrency, 'queue_size': instance.queueSize, - 'max_timestamp_behind_ms': instance.maxTimestampBehindMs, - 'max_timestamp_ahead_ms': instance.maxTimestampAheadMs, 'timeout_ms': instance.timeoutMs, 'max_route_hop_count': instance.maxRouteHopCount, 'default_route_hop_count': instance.defaultRouteHopCount, + 'max_timestamp_behind_ms': instance.maxTimestampBehindMs, + 'max_timestamp_ahead_ms': instance.maxTimestampAheadMs, }; _$_VeilidConfigRoutingTable _$$_VeilidConfigRoutingTableFromJson( @@ -414,19 +408,16 @@ _$_VeilidConfigNetwork _$$_VeilidConfigNetworkFromJson( reverseConnectionReceiptTimeMs: json['reverse_connection_receipt_time_ms'] as int, holePunchReceiptTimeMs: json['hole_punch_receipt_time_ms'] as int, - networkKeyPassword: json['network_key_password'] as String?, - routingTable: VeilidConfigRoutingTable.fromJson( - json['routing_table'] as Map), - rpc: VeilidConfigRPC.fromJson(json['rpc'] as Map), - dht: VeilidConfigDHT.fromJson(json['dht'] as Map), + routingTable: VeilidConfigRoutingTable.fromJson(json['routing_table']), + rpc: VeilidConfigRPC.fromJson(json['rpc']), + dht: VeilidConfigDHT.fromJson(json['dht']), upnp: json['upnp'] as bool, detectAddressChanges: json['detect_address_changes'] as bool, restrictedNatRetries: json['restricted_nat_retries'] as int, - tls: VeilidConfigTLS.fromJson(json['tls'] as Map), - application: VeilidConfigApplication.fromJson( - json['application'] as Map), - protocol: VeilidConfigProtocol.fromJson( - json['protocol'] as Map), + tls: VeilidConfigTLS.fromJson(json['tls']), + application: VeilidConfigApplication.fromJson(json['application']), + protocol: VeilidConfigProtocol.fromJson(json['protocol']), + networkKeyPassword: json['network_key_password'] as String?, ); Map _$$_VeilidConfigNetworkToJson( @@ -444,7 +435,6 @@ Map _$$_VeilidConfigNetworkToJson( 'reverse_connection_receipt_time_ms': instance.reverseConnectionReceiptTimeMs, 'hole_punch_receipt_time_ms': instance.holePunchReceiptTimeMs, - 'network_key_password': instance.networkKeyPassword, 'routing_table': instance.routingTable.toJson(), 'rpc': instance.rpc.toJson(), 'dht': instance.dht.toJson(), @@ -454,6 +444,7 @@ Map _$$_VeilidConfigNetworkToJson( 'tls': instance.tls.toJson(), 'application': instance.application.toJson(), 'protocol': instance.protocol.toJson(), + 'network_key_password': instance.networkKeyPassword, }; _$_VeilidConfigTableStore _$$_VeilidConfigTableStoreFromJson( @@ -526,16 +517,12 @@ _$_VeilidConfig _$$_VeilidConfigFromJson(Map json) => _$_VeilidConfig( programName: json['program_name'] as String, namespace: json['namespace'] as String, - capabilities: VeilidConfigCapabilities.fromJson( - json['capabilities'] as Map), - protectedStore: VeilidConfigProtectedStore.fromJson( - json['protected_store'] as Map), - tableStore: VeilidConfigTableStore.fromJson( - json['table_store'] as Map), - blockStore: VeilidConfigBlockStore.fromJson( - json['block_store'] as Map), - network: - VeilidConfigNetwork.fromJson(json['network'] as Map), + capabilities: VeilidConfigCapabilities.fromJson(json['capabilities']), + protectedStore: + VeilidConfigProtectedStore.fromJson(json['protected_store']), + tableStore: VeilidConfigTableStore.fromJson(json['table_store']), + blockStore: VeilidConfigBlockStore.fromJson(json['block_store']), + network: VeilidConfigNetwork.fromJson(json['network']), ); Map _$$_VeilidConfigToJson(_$_VeilidConfig instance) => diff --git a/veilid-flutter/lib/veilid_crypto.dart b/veilid-flutter/lib/veilid_crypto.dart index 97686ec7..21050517 100644 --- a/veilid-flutter/lib/veilid_crypto.dart +++ b/veilid-flutter/lib/veilid_crypto.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:convert'; import 'dart:typed_data'; import 'package:charcode/charcode.dart'; @@ -184,4 +185,49 @@ abstract class VeilidCryptoSystem { SharedSecret sharedSecret, Uint8List? associatedData); Future cryptNoAuth( Uint8List body, Nonce nonce, SharedSecret sharedSecret); + + Future encryptNoAuthWithNonce( + Uint8List body, SharedSecret secret) async { + // generate nonce + final nonce = await randomNonce(); + // crypt and append nonce + final b = BytesBuilder() + ..add(await cryptNoAuth(body, nonce, secret)) + ..add(nonce.decode()); + return b.toBytes(); + } + + Future decryptNoAuthWithNonce( + Uint8List body, SharedSecret secret) async { + if (body.length <= Nonce.decodedLength()) { + throw const FormatException('not enough data to decrypt'); + } + final nonce = + Nonce.fromBytes(body.sublist(body.length - Nonce.decodedLength())); + final encryptedData = body.sublist(0, body.length - Nonce.decodedLength()); + // decrypt + return cryptNoAuth(encryptedData, nonce, secret); + } + + Future encryptNoAuthWithPassword( + Uint8List body, String password) async { + final ekbytes = Uint8List.fromList(utf8.encode(password)); + final nonce = await randomNonce(); + final saltBytes = nonce.decode(); + final sharedSecret = await deriveSharedSecret(ekbytes, saltBytes); + return (await cryptNoAuth(body, nonce, sharedSecret))..addAll(saltBytes); + } + + Future decryptNoAuthWithPassword( + Uint8List body, String password) async { + if (body.length <= Nonce.decodedLength()) { + throw const FormatException('not enough data to decrypt'); + } + final ekbytes = Uint8List.fromList(utf8.encode(password)); + final bodyBytes = body.sublist(0, body.length - Nonce.decodedLength()); + final saltBytes = body.sublist(body.length - Nonce.decodedLength()); + final nonce = Nonce.fromBytes(saltBytes); + final sharedSecret = await deriveSharedSecret(ekbytes, saltBytes); + return cryptNoAuth(bodyBytes, nonce, sharedSecret); + } } diff --git a/veilid-flutter/lib/veilid_state.freezed.dart b/veilid-flutter/lib/veilid_state.freezed.dart index 6e7bf3f3..ca6d13af 100644 --- a/veilid-flutter/lib/veilid_state.freezed.dart +++ b/veilid-flutter/lib/veilid_state.freezed.dart @@ -866,8 +866,8 @@ PeerStats _$PeerStatsFromJson(Map json) { mixin _$PeerStats { Timestamp get timeAdded => throw _privateConstructorUsedError; RPCStats get rpcStats => throw _privateConstructorUsedError; - LatencyStats? get latency => throw _privateConstructorUsedError; TransferStatsDownUp get transfer => throw _privateConstructorUsedError; + LatencyStats? get latency => throw _privateConstructorUsedError; Map toJson() => throw _privateConstructorUsedError; @JsonKey(ignore: true) @@ -883,12 +883,12 @@ abstract class $PeerStatsCopyWith<$Res> { $Res call( {Timestamp timeAdded, RPCStats rpcStats, - LatencyStats? latency, - TransferStatsDownUp transfer}); + TransferStatsDownUp transfer, + LatencyStats? latency}); $RPCStatsCopyWith<$Res> get rpcStats; - $LatencyStatsCopyWith<$Res>? get latency; $TransferStatsDownUpCopyWith<$Res> get transfer; + $LatencyStatsCopyWith<$Res>? get latency; } /// @nodoc @@ -906,8 +906,8 @@ class _$PeerStatsCopyWithImpl<$Res, $Val extends PeerStats> $Res call({ Object? timeAdded = null, Object? rpcStats = null, - Object? latency = freezed, Object? transfer = null, + Object? latency = freezed, }) { return _then(_value.copyWith( timeAdded: null == timeAdded @@ -918,14 +918,14 @@ class _$PeerStatsCopyWithImpl<$Res, $Val extends PeerStats> ? _value.rpcStats : rpcStats // ignore: cast_nullable_to_non_nullable as RPCStats, - latency: freezed == latency - ? _value.latency - : latency // ignore: cast_nullable_to_non_nullable - as LatencyStats?, transfer: null == transfer ? _value.transfer : transfer // ignore: cast_nullable_to_non_nullable as TransferStatsDownUp, + latency: freezed == latency + ? _value.latency + : latency // ignore: cast_nullable_to_non_nullable + as LatencyStats?, ) as $Val); } @@ -937,6 +937,14 @@ class _$PeerStatsCopyWithImpl<$Res, $Val extends PeerStats> }); } + @override + @pragma('vm:prefer-inline') + $TransferStatsDownUpCopyWith<$Res> get transfer { + return $TransferStatsDownUpCopyWith<$Res>(_value.transfer, (value) { + return _then(_value.copyWith(transfer: value) as $Val); + }); + } + @override @pragma('vm:prefer-inline') $LatencyStatsCopyWith<$Res>? get latency { @@ -948,14 +956,6 @@ class _$PeerStatsCopyWithImpl<$Res, $Val extends PeerStats> return _then(_value.copyWith(latency: value) as $Val); }); } - - @override - @pragma('vm:prefer-inline') - $TransferStatsDownUpCopyWith<$Res> get transfer { - return $TransferStatsDownUpCopyWith<$Res>(_value.transfer, (value) { - return _then(_value.copyWith(transfer: value) as $Val); - }); - } } /// @nodoc @@ -968,15 +968,15 @@ abstract class _$$_PeerStatsCopyWith<$Res> implements $PeerStatsCopyWith<$Res> { $Res call( {Timestamp timeAdded, RPCStats rpcStats, - LatencyStats? latency, - TransferStatsDownUp transfer}); + TransferStatsDownUp transfer, + LatencyStats? latency}); @override $RPCStatsCopyWith<$Res> get rpcStats; @override - $LatencyStatsCopyWith<$Res>? get latency; - @override $TransferStatsDownUpCopyWith<$Res> get transfer; + @override + $LatencyStatsCopyWith<$Res>? get latency; } /// @nodoc @@ -992,8 +992,8 @@ class __$$_PeerStatsCopyWithImpl<$Res> $Res call({ Object? timeAdded = null, Object? rpcStats = null, - Object? latency = freezed, Object? transfer = null, + Object? latency = freezed, }) { return _then(_$_PeerStats( timeAdded: null == timeAdded @@ -1004,14 +1004,14 @@ class __$$_PeerStatsCopyWithImpl<$Res> ? _value.rpcStats : rpcStats // ignore: cast_nullable_to_non_nullable as RPCStats, - latency: freezed == latency - ? _value.latency - : latency // ignore: cast_nullable_to_non_nullable - as LatencyStats?, transfer: null == transfer ? _value.transfer : transfer // ignore: cast_nullable_to_non_nullable as TransferStatsDownUp, + latency: freezed == latency + ? _value.latency + : latency // ignore: cast_nullable_to_non_nullable + as LatencyStats?, )); } } @@ -1022,8 +1022,8 @@ class _$_PeerStats implements _PeerStats { const _$_PeerStats( {required this.timeAdded, required this.rpcStats, - this.latency, - required this.transfer}); + required this.transfer, + this.latency}); factory _$_PeerStats.fromJson(Map json) => _$$_PeerStatsFromJson(json); @@ -1033,13 +1033,13 @@ class _$_PeerStats implements _PeerStats { @override final RPCStats rpcStats; @override - final LatencyStats? latency; - @override final TransferStatsDownUp transfer; + @override + final LatencyStats? latency; @override String toString() { - return 'PeerStats(timeAdded: $timeAdded, rpcStats: $rpcStats, latency: $latency, transfer: $transfer)'; + return 'PeerStats(timeAdded: $timeAdded, rpcStats: $rpcStats, transfer: $transfer, latency: $latency)'; } @override @@ -1051,15 +1051,15 @@ class _$_PeerStats implements _PeerStats { other.timeAdded == timeAdded) && (identical(other.rpcStats, rpcStats) || other.rpcStats == rpcStats) && - (identical(other.latency, latency) || other.latency == latency) && (identical(other.transfer, transfer) || - other.transfer == transfer)); + other.transfer == transfer) && + (identical(other.latency, latency) || other.latency == latency)); } @JsonKey(ignore: true) @override int get hashCode => - Object.hash(runtimeType, timeAdded, rpcStats, latency, transfer); + Object.hash(runtimeType, timeAdded, rpcStats, transfer, latency); @JsonKey(ignore: true) @override @@ -1079,8 +1079,8 @@ abstract class _PeerStats implements PeerStats { const factory _PeerStats( {required final Timestamp timeAdded, required final RPCStats rpcStats, - final LatencyStats? latency, - required final TransferStatsDownUp transfer}) = _$_PeerStats; + required final TransferStatsDownUp transfer, + final LatencyStats? latency}) = _$_PeerStats; factory _PeerStats.fromJson(Map json) = _$_PeerStats.fromJson; @@ -1090,10 +1090,10 @@ abstract class _PeerStats implements PeerStats { @override RPCStats get rpcStats; @override - LatencyStats? get latency; - @override TransferStatsDownUp get transfer; @override + LatencyStats? get latency; + @override @JsonKey(ignore: true) _$$_PeerStatsCopyWith<_$_PeerStats> get copyWith => throw _privateConstructorUsedError; @@ -1335,11 +1335,11 @@ mixin _$VeilidUpdate { required TResult Function( VeilidLogLevel logLevel, String message, String? backtrace) log, - required TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message) + required TResult Function(@Uint8ListJsonConverter() Uint8List message, + Typed? sender) appMessage, - required TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message, String callId) + required TResult Function(@Uint8ListJsonConverter() Uint8List message, + String callId, Typed? sender) appCall, required TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady) @@ -1361,11 +1361,11 @@ mixin _$VeilidUpdate { TResult? Function( VeilidLogLevel logLevel, String message, String? backtrace)? log, - TResult? Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message)? + TResult? Function(@Uint8ListJsonConverter() Uint8List message, + Typed? sender)? appMessage, - TResult? Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message, String callId)? + TResult? Function(@Uint8ListJsonConverter() Uint8List message, + String callId, Typed? sender)? appCall, TResult? Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -1386,11 +1386,11 @@ mixin _$VeilidUpdate { TResult Function( VeilidLogLevel logLevel, String message, String? backtrace)? log, - TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message)? + TResult Function(@Uint8ListJsonConverter() Uint8List message, + Typed? sender)? appMessage, - TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message, String callId)? + TResult Function(@Uint8ListJsonConverter() Uint8List message, String callId, + Typed? sender)? appCall, TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -1562,11 +1562,11 @@ class _$VeilidLog implements VeilidLog { required TResult Function( VeilidLogLevel logLevel, String message, String? backtrace) log, - required TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message) + required TResult Function(@Uint8ListJsonConverter() Uint8List message, + Typed? sender) appMessage, - required TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message, String callId) + required TResult Function(@Uint8ListJsonConverter() Uint8List message, + String callId, Typed? sender) appCall, required TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady) @@ -1591,11 +1591,11 @@ class _$VeilidLog implements VeilidLog { TResult? Function( VeilidLogLevel logLevel, String message, String? backtrace)? log, - TResult? Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message)? + TResult? Function(@Uint8ListJsonConverter() Uint8List message, + Typed? sender)? appMessage, - TResult? Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message, String callId)? + TResult? Function(@Uint8ListJsonConverter() Uint8List message, + String callId, Typed? sender)? appCall, TResult? Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -1619,11 +1619,11 @@ class _$VeilidLog implements VeilidLog { TResult Function( VeilidLogLevel logLevel, String message, String? backtrace)? log, - TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message)? + TResult Function(@Uint8ListJsonConverter() Uint8List message, + Typed? sender)? appMessage, - TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message, String callId)? + TResult Function(@Uint8ListJsonConverter() Uint8List message, String callId, + Typed? sender)? appCall, TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -1725,8 +1725,8 @@ abstract class _$$VeilidAppMessageCopyWith<$Res> { __$$VeilidAppMessageCopyWithImpl<$Res>; @useResult $Res call( - {Typed? sender, - @Uint8ListJsonConverter() Uint8List message}); + {@Uint8ListJsonConverter() Uint8List message, + Typed? sender}); } /// @nodoc @@ -1740,18 +1740,18 @@ class __$$VeilidAppMessageCopyWithImpl<$Res> @pragma('vm:prefer-inline') @override $Res call({ - Object? sender = freezed, Object? message = null, + Object? sender = freezed, }) { return _then(_$VeilidAppMessage( - sender: freezed == sender - ? _value.sender - : sender // ignore: cast_nullable_to_non_nullable - as Typed?, message: null == message ? _value.message : message // ignore: cast_nullable_to_non_nullable as Uint8List, + sender: freezed == sender + ? _value.sender + : sender // ignore: cast_nullable_to_non_nullable + as Typed?, )); } } @@ -1760,26 +1760,26 @@ class __$$VeilidAppMessageCopyWithImpl<$Res> @JsonSerializable() class _$VeilidAppMessage implements VeilidAppMessage { const _$VeilidAppMessage( - {this.sender, - @Uint8ListJsonConverter() required this.message, + {@Uint8ListJsonConverter() required this.message, + this.sender, final String? $type}) : $type = $type ?? 'AppMessage'; factory _$VeilidAppMessage.fromJson(Map json) => _$$VeilidAppMessageFromJson(json); - @override - final Typed? sender; @override @Uint8ListJsonConverter() final Uint8List message; + @override + final Typed? sender; @JsonKey(name: 'kind') final String $type; @override String toString() { - return 'VeilidUpdate.appMessage(sender: $sender, message: $message)'; + return 'VeilidUpdate.appMessage(message: $message, sender: $sender)'; } @override @@ -1787,14 +1787,14 @@ class _$VeilidAppMessage implements VeilidAppMessage { return identical(this, other) || (other.runtimeType == runtimeType && other is _$VeilidAppMessage && - (identical(other.sender, sender) || other.sender == sender) && - const DeepCollectionEquality().equals(other.message, message)); + const DeepCollectionEquality().equals(other.message, message) && + (identical(other.sender, sender) || other.sender == sender)); } @JsonKey(ignore: true) @override int get hashCode => Object.hash( - runtimeType, sender, const DeepCollectionEquality().hash(message)); + runtimeType, const DeepCollectionEquality().hash(message), sender); @JsonKey(ignore: true) @override @@ -1808,11 +1808,11 @@ class _$VeilidAppMessage implements VeilidAppMessage { required TResult Function( VeilidLogLevel logLevel, String message, String? backtrace) log, - required TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message) + required TResult Function(@Uint8ListJsonConverter() Uint8List message, + Typed? sender) appMessage, - required TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message, String callId) + required TResult Function(@Uint8ListJsonConverter() Uint8List message, + String callId, Typed? sender) appCall, required TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady) @@ -1828,7 +1828,7 @@ class _$VeilidAppMessage implements VeilidAppMessage { List subkeys, int count, ValueData valueData) valueChange, }) { - return appMessage(sender, message); + return appMessage(message, sender); } @override @@ -1837,11 +1837,11 @@ class _$VeilidAppMessage implements VeilidAppMessage { TResult? Function( VeilidLogLevel logLevel, String message, String? backtrace)? log, - TResult? Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message)? + TResult? Function(@Uint8ListJsonConverter() Uint8List message, + Typed? sender)? appMessage, - TResult? Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message, String callId)? + TResult? Function(@Uint8ListJsonConverter() Uint8List message, + String callId, Typed? sender)? appCall, TResult? Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -1856,7 +1856,7 @@ class _$VeilidAppMessage implements VeilidAppMessage { List subkeys, int count, ValueData valueData)? valueChange, }) { - return appMessage?.call(sender, message); + return appMessage?.call(message, sender); } @override @@ -1865,11 +1865,11 @@ class _$VeilidAppMessage implements VeilidAppMessage { TResult Function( VeilidLogLevel logLevel, String message, String? backtrace)? log, - TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message)? + TResult Function(@Uint8ListJsonConverter() Uint8List message, + Typed? sender)? appMessage, - TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message, String callId)? + TResult Function(@Uint8ListJsonConverter() Uint8List message, String callId, + Typed? sender)? appCall, TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -1886,7 +1886,7 @@ class _$VeilidAppMessage implements VeilidAppMessage { required TResult orElse(), }) { if (appMessage != null) { - return appMessage(sender, message); + return appMessage(message, sender); } return orElse(); } @@ -1950,16 +1950,15 @@ class _$VeilidAppMessage implements VeilidAppMessage { abstract class VeilidAppMessage implements VeilidUpdate { const factory VeilidAppMessage( - {final Typed? sender, - @Uint8ListJsonConverter() required final Uint8List message}) = - _$VeilidAppMessage; + {@Uint8ListJsonConverter() required final Uint8List message, + final Typed? sender}) = _$VeilidAppMessage; factory VeilidAppMessage.fromJson(Map json) = _$VeilidAppMessage.fromJson; - Typed? get sender; @Uint8ListJsonConverter() Uint8List get message; + Typed? get sender; @JsonKey(ignore: true) _$$VeilidAppMessageCopyWith<_$VeilidAppMessage> get copyWith => throw _privateConstructorUsedError; @@ -1972,9 +1971,9 @@ abstract class _$$VeilidAppCallCopyWith<$Res> { __$$VeilidAppCallCopyWithImpl<$Res>; @useResult $Res call( - {Typed? sender, - @Uint8ListJsonConverter() Uint8List message, - String callId}); + {@Uint8ListJsonConverter() Uint8List message, + String callId, + Typed? sender}); } /// @nodoc @@ -1988,15 +1987,11 @@ class __$$VeilidAppCallCopyWithImpl<$Res> @pragma('vm:prefer-inline') @override $Res call({ - Object? sender = freezed, Object? message = null, Object? callId = null, + Object? sender = freezed, }) { return _then(_$VeilidAppCall( - sender: freezed == sender - ? _value.sender - : sender // ignore: cast_nullable_to_non_nullable - as Typed?, message: null == message ? _value.message : message // ignore: cast_nullable_to_non_nullable @@ -2005,6 +2000,10 @@ class __$$VeilidAppCallCopyWithImpl<$Res> ? _value.callId : callId // ignore: cast_nullable_to_non_nullable as String, + sender: freezed == sender + ? _value.sender + : sender // ignore: cast_nullable_to_non_nullable + as Typed?, )); } } @@ -2013,29 +2012,29 @@ class __$$VeilidAppCallCopyWithImpl<$Res> @JsonSerializable() class _$VeilidAppCall implements VeilidAppCall { const _$VeilidAppCall( - {this.sender, - @Uint8ListJsonConverter() required this.message, + {@Uint8ListJsonConverter() required this.message, required this.callId, + this.sender, final String? $type}) : $type = $type ?? 'AppCall'; factory _$VeilidAppCall.fromJson(Map json) => _$$VeilidAppCallFromJson(json); - @override - final Typed? sender; @override @Uint8ListJsonConverter() final Uint8List message; @override final String callId; + @override + final Typed? sender; @JsonKey(name: 'kind') final String $type; @override String toString() { - return 'VeilidUpdate.appCall(sender: $sender, message: $message, callId: $callId)'; + return 'VeilidUpdate.appCall(message: $message, callId: $callId, sender: $sender)'; } @override @@ -2043,15 +2042,15 @@ class _$VeilidAppCall implements VeilidAppCall { return identical(this, other) || (other.runtimeType == runtimeType && other is _$VeilidAppCall && - (identical(other.sender, sender) || other.sender == sender) && const DeepCollectionEquality().equals(other.message, message) && - (identical(other.callId, callId) || other.callId == callId)); + (identical(other.callId, callId) || other.callId == callId) && + (identical(other.sender, sender) || other.sender == sender)); } @JsonKey(ignore: true) @override - int get hashCode => Object.hash(runtimeType, sender, - const DeepCollectionEquality().hash(message), callId); + int get hashCode => Object.hash(runtimeType, + const DeepCollectionEquality().hash(message), callId, sender); @JsonKey(ignore: true) @override @@ -2065,11 +2064,11 @@ class _$VeilidAppCall implements VeilidAppCall { required TResult Function( VeilidLogLevel logLevel, String message, String? backtrace) log, - required TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message) + required TResult Function(@Uint8ListJsonConverter() Uint8List message, + Typed? sender) appMessage, - required TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message, String callId) + required TResult Function(@Uint8ListJsonConverter() Uint8List message, + String callId, Typed? sender) appCall, required TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady) @@ -2085,7 +2084,7 @@ class _$VeilidAppCall implements VeilidAppCall { List subkeys, int count, ValueData valueData) valueChange, }) { - return appCall(sender, message, callId); + return appCall(message, callId, sender); } @override @@ -2094,11 +2093,11 @@ class _$VeilidAppCall implements VeilidAppCall { TResult? Function( VeilidLogLevel logLevel, String message, String? backtrace)? log, - TResult? Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message)? + TResult? Function(@Uint8ListJsonConverter() Uint8List message, + Typed? sender)? appMessage, - TResult? Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message, String callId)? + TResult? Function(@Uint8ListJsonConverter() Uint8List message, + String callId, Typed? sender)? appCall, TResult? Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -2113,7 +2112,7 @@ class _$VeilidAppCall implements VeilidAppCall { List subkeys, int count, ValueData valueData)? valueChange, }) { - return appCall?.call(sender, message, callId); + return appCall?.call(message, callId, sender); } @override @@ -2122,11 +2121,11 @@ class _$VeilidAppCall implements VeilidAppCall { TResult Function( VeilidLogLevel logLevel, String message, String? backtrace)? log, - TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message)? + TResult Function(@Uint8ListJsonConverter() Uint8List message, + Typed? sender)? appMessage, - TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message, String callId)? + TResult Function(@Uint8ListJsonConverter() Uint8List message, String callId, + Typed? sender)? appCall, TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -2143,7 +2142,7 @@ class _$VeilidAppCall implements VeilidAppCall { required TResult orElse(), }) { if (appCall != null) { - return appCall(sender, message, callId); + return appCall(message, callId, sender); } return orElse(); } @@ -2207,17 +2206,17 @@ class _$VeilidAppCall implements VeilidAppCall { abstract class VeilidAppCall implements VeilidUpdate { const factory VeilidAppCall( - {final Typed? sender, - @Uint8ListJsonConverter() required final Uint8List message, - required final String callId}) = _$VeilidAppCall; + {@Uint8ListJsonConverter() required final Uint8List message, + required final String callId, + final Typed? sender}) = _$VeilidAppCall; factory VeilidAppCall.fromJson(Map json) = _$VeilidAppCall.fromJson; - Typed? get sender; @Uint8ListJsonConverter() Uint8List get message; String get callId; + Typed? get sender; @JsonKey(ignore: true) _$$VeilidAppCallCopyWith<_$VeilidAppCall> get copyWith => throw _privateConstructorUsedError; @@ -2325,11 +2324,11 @@ class _$VeilidUpdateAttachment implements VeilidUpdateAttachment { required TResult Function( VeilidLogLevel logLevel, String message, String? backtrace) log, - required TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message) + required TResult Function(@Uint8ListJsonConverter() Uint8List message, + Typed? sender) appMessage, - required TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message, String callId) + required TResult Function(@Uint8ListJsonConverter() Uint8List message, + String callId, Typed? sender) appCall, required TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady) @@ -2354,11 +2353,11 @@ class _$VeilidUpdateAttachment implements VeilidUpdateAttachment { TResult? Function( VeilidLogLevel logLevel, String message, String? backtrace)? log, - TResult? Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message)? + TResult? Function(@Uint8ListJsonConverter() Uint8List message, + Typed? sender)? appMessage, - TResult? Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message, String callId)? + TResult? Function(@Uint8ListJsonConverter() Uint8List message, + String callId, Typed? sender)? appCall, TResult? Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -2382,11 +2381,11 @@ class _$VeilidUpdateAttachment implements VeilidUpdateAttachment { TResult Function( VeilidLogLevel logLevel, String message, String? backtrace)? log, - TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message)? + TResult Function(@Uint8ListJsonConverter() Uint8List message, + Typed? sender)? appMessage, - TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message, String callId)? + TResult Function(@Uint8ListJsonConverter() Uint8List message, String callId, + Typed? sender)? appCall, TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -2595,11 +2594,11 @@ class _$VeilidUpdateNetwork implements VeilidUpdateNetwork { required TResult Function( VeilidLogLevel logLevel, String message, String? backtrace) log, - required TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message) + required TResult Function(@Uint8ListJsonConverter() Uint8List message, + Typed? sender) appMessage, - required TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message, String callId) + required TResult Function(@Uint8ListJsonConverter() Uint8List message, + String callId, Typed? sender) appCall, required TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady) @@ -2624,11 +2623,11 @@ class _$VeilidUpdateNetwork implements VeilidUpdateNetwork { TResult? Function( VeilidLogLevel logLevel, String message, String? backtrace)? log, - TResult? Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message)? + TResult? Function(@Uint8ListJsonConverter() Uint8List message, + Typed? sender)? appMessage, - TResult? Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message, String callId)? + TResult? Function(@Uint8ListJsonConverter() Uint8List message, + String callId, Typed? sender)? appCall, TResult? Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -2652,11 +2651,11 @@ class _$VeilidUpdateNetwork implements VeilidUpdateNetwork { TResult Function( VeilidLogLevel logLevel, String message, String? backtrace)? log, - TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message)? + TResult Function(@Uint8ListJsonConverter() Uint8List message, + Typed? sender)? appMessage, - TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message, String callId)? + TResult Function(@Uint8ListJsonConverter() Uint8List message, String callId, + Typed? sender)? appCall, TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -2840,11 +2839,11 @@ class _$VeilidUpdateConfig implements VeilidUpdateConfig { required TResult Function( VeilidLogLevel logLevel, String message, String? backtrace) log, - required TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message) + required TResult Function(@Uint8ListJsonConverter() Uint8List message, + Typed? sender) appMessage, - required TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message, String callId) + required TResult Function(@Uint8ListJsonConverter() Uint8List message, + String callId, Typed? sender) appCall, required TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady) @@ -2869,11 +2868,11 @@ class _$VeilidUpdateConfig implements VeilidUpdateConfig { TResult? Function( VeilidLogLevel logLevel, String message, String? backtrace)? log, - TResult? Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message)? + TResult? Function(@Uint8ListJsonConverter() Uint8List message, + Typed? sender)? appMessage, - TResult? Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message, String callId)? + TResult? Function(@Uint8ListJsonConverter() Uint8List message, + String callId, Typed? sender)? appCall, TResult? Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -2897,11 +2896,11 @@ class _$VeilidUpdateConfig implements VeilidUpdateConfig { TResult Function( VeilidLogLevel logLevel, String message, String? backtrace)? log, - TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message)? + TResult Function(@Uint8ListJsonConverter() Uint8List message, + Typed? sender)? appMessage, - TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message, String callId)? + TResult Function(@Uint8ListJsonConverter() Uint8List message, String callId, + Typed? sender)? appCall, TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -3099,11 +3098,11 @@ class _$VeilidUpdateRouteChange implements VeilidUpdateRouteChange { required TResult Function( VeilidLogLevel logLevel, String message, String? backtrace) log, - required TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message) + required TResult Function(@Uint8ListJsonConverter() Uint8List message, + Typed? sender) appMessage, - required TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message, String callId) + required TResult Function(@Uint8ListJsonConverter() Uint8List message, + String callId, Typed? sender) appCall, required TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady) @@ -3128,11 +3127,11 @@ class _$VeilidUpdateRouteChange implements VeilidUpdateRouteChange { TResult? Function( VeilidLogLevel logLevel, String message, String? backtrace)? log, - TResult? Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message)? + TResult? Function(@Uint8ListJsonConverter() Uint8List message, + Typed? sender)? appMessage, - TResult? Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message, String callId)? + TResult? Function(@Uint8ListJsonConverter() Uint8List message, + String callId, Typed? sender)? appCall, TResult? Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -3156,11 +3155,11 @@ class _$VeilidUpdateRouteChange implements VeilidUpdateRouteChange { TResult Function( VeilidLogLevel logLevel, String message, String? backtrace)? log, - TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message)? + TResult Function(@Uint8ListJsonConverter() Uint8List message, + Typed? sender)? appMessage, - TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message, String callId)? + TResult Function(@Uint8ListJsonConverter() Uint8List message, String callId, + Typed? sender)? appCall, TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -3383,11 +3382,11 @@ class _$VeilidUpdateValueChange implements VeilidUpdateValueChange { required TResult Function( VeilidLogLevel logLevel, String message, String? backtrace) log, - required TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message) + required TResult Function(@Uint8ListJsonConverter() Uint8List message, + Typed? sender) appMessage, - required TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message, String callId) + required TResult Function(@Uint8ListJsonConverter() Uint8List message, + String callId, Typed? sender) appCall, required TResult Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady) @@ -3412,11 +3411,11 @@ class _$VeilidUpdateValueChange implements VeilidUpdateValueChange { TResult? Function( VeilidLogLevel logLevel, String message, String? backtrace)? log, - TResult? Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message)? + TResult? Function(@Uint8ListJsonConverter() Uint8List message, + Typed? sender)? appMessage, - TResult? Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message, String callId)? + TResult? Function(@Uint8ListJsonConverter() Uint8List message, + String callId, Typed? sender)? appCall, TResult? Function(AttachmentState state, bool publicInternetReady, bool localNetworkReady)? @@ -3440,11 +3439,11 @@ class _$VeilidUpdateValueChange implements VeilidUpdateValueChange { TResult Function( VeilidLogLevel logLevel, String message, String? backtrace)? log, - TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message)? + TResult Function(@Uint8ListJsonConverter() Uint8List message, + Typed? sender)? appMessage, - TResult Function(Typed? sender, - @Uint8ListJsonConverter() Uint8List message, String callId)? + TResult Function(@Uint8ListJsonConverter() Uint8List message, String callId, + Typed? sender)? 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 9acc648d..d3797e28 100644 --- a/veilid-flutter/lib/veilid_state.g.dart +++ b/veilid-flutter/lib/veilid_state.g.dart @@ -39,8 +39,8 @@ Map _$$_TransferStatsToJson(_$_TransferStats instance) => _$_TransferStatsDownUp _$$_TransferStatsDownUpFromJson( Map json) => _$_TransferStatsDownUp( - down: TransferStats.fromJson(json['down'] as Map), - up: TransferStats.fromJson(json['up'] as Map), + down: TransferStats.fromJson(json['down']), + up: TransferStats.fromJson(json['up']), ); Map _$$_TransferStatsDownUpToJson( @@ -81,20 +81,19 @@ Map _$$_RPCStatsToJson(_$_RPCStats instance) => _$_PeerStats _$$_PeerStatsFromJson(Map json) => _$_PeerStats( timeAdded: Timestamp.fromJson(json['time_added']), - rpcStats: RPCStats.fromJson(json['rpc_stats'] as Map), + rpcStats: RPCStats.fromJson(json['rpc_stats']), + transfer: TransferStatsDownUp.fromJson(json['transfer']), latency: json['latency'] == null ? null - : LatencyStats.fromJson(json['latency'] as Map), - transfer: TransferStatsDownUp.fromJson( - json['transfer'] as Map), + : LatencyStats.fromJson(json['latency']), ); Map _$$_PeerStatsToJson(_$_PeerStats instance) => { 'time_added': instance.timeAdded.toJson(), 'rpc_stats': instance.rpcStats.toJson(), - 'latency': instance.latency?.toJson(), 'transfer': instance.transfer.toJson(), + 'latency': instance.latency?.toJson(), }; _$_PeerTableData _$$_PeerTableDataFromJson(Map json) => @@ -103,7 +102,7 @@ _$_PeerTableData _$$_PeerTableDataFromJson(Map json) => .map(Typed.fromJson) .toList(), peerAddress: json['peer_address'] as String, - peerStats: PeerStats.fromJson(json['peer_stats'] as Map), + peerStats: PeerStats.fromJson(json['peer_stats']), ); Map _$$_PeerTableDataToJson(_$_PeerTableData instance) => @@ -114,7 +113,7 @@ Map _$$_PeerTableDataToJson(_$_PeerTableData instance) => }; _$VeilidLog _$$VeilidLogFromJson(Map json) => _$VeilidLog( - logLevel: VeilidLogLevel.fromJson(json['log_level'] as String), + logLevel: VeilidLogLevel.fromJson(json['log_level']), message: json['message'] as String, backtrace: json['backtrace'] as String?, $type: json['kind'] as String?, @@ -130,44 +129,44 @@ Map _$$VeilidLogToJson(_$VeilidLog instance) => _$VeilidAppMessage _$$VeilidAppMessageFromJson(Map json) => _$VeilidAppMessage( + message: + const Uint8ListJsonConverter().fromJson(json['message'] as String), sender: json['sender'] == null ? null : Typed.fromJson(json['sender']), - message: - const Uint8ListJsonConverter().fromJson(json['message'] as String), $type: json['kind'] as String?, ); Map _$$VeilidAppMessageToJson(_$VeilidAppMessage instance) => { - 'sender': instance.sender?.toJson(), 'message': const Uint8ListJsonConverter().toJson(instance.message), + 'sender': instance.sender?.toJson(), 'kind': instance.$type, }; _$VeilidAppCall _$$VeilidAppCallFromJson(Map json) => _$VeilidAppCall( - sender: json['sender'] == null - ? null - : Typed.fromJson(json['sender']), message: const Uint8ListJsonConverter().fromJson(json['message'] as String), callId: json['call_id'] as String, + sender: json['sender'] == null + ? null + : Typed.fromJson(json['sender']), $type: json['kind'] as String?, ); Map _$$VeilidAppCallToJson(_$VeilidAppCall instance) => { - 'sender': instance.sender?.toJson(), 'message': const Uint8ListJsonConverter().toJson(instance.message), 'call_id': instance.callId, + 'sender': instance.sender?.toJson(), 'kind': instance.$type, }; _$VeilidUpdateAttachment _$$VeilidUpdateAttachmentFromJson( Map json) => _$VeilidUpdateAttachment( - state: AttachmentState.fromJson(json['state'] as String), + state: AttachmentState.fromJson(json['state']), publicInternetReady: json['public_internet_ready'] as bool, localNetworkReady: json['local_network_ready'] as bool, $type: json['kind'] as String?, @@ -188,9 +187,8 @@ _$VeilidUpdateNetwork _$$VeilidUpdateNetworkFromJson( started: json['started'] as bool, bpsDown: BigInt.parse(json['bps_down'] as String), bpsUp: BigInt.parse(json['bps_up'] as String), - peers: (json['peers'] as List) - .map((e) => PeerTableData.fromJson(e as Map)) - .toList(), + peers: + (json['peers'] as List).map(PeerTableData.fromJson).toList(), $type: json['kind'] as String?, ); @@ -206,7 +204,7 @@ Map _$$VeilidUpdateNetworkToJson( _$VeilidUpdateConfig _$$VeilidUpdateConfigFromJson(Map json) => _$VeilidUpdateConfig( - config: VeilidConfig.fromJson(json['config'] as Map), + config: VeilidConfig.fromJson(json['config']), $type: json['kind'] as String?, ); @@ -242,10 +240,10 @@ _$VeilidUpdateValueChange _$$VeilidUpdateValueChangeFromJson( _$VeilidUpdateValueChange( key: Typed.fromJson(json['key']), subkeys: (json['subkeys'] as List) - .map((e) => ValueSubkeyRange.fromJson(e as Map)) + .map(ValueSubkeyRange.fromJson) .toList(), count: json['count'] as int, - valueData: ValueData.fromJson(json['value_data'] as Map), + valueData: ValueData.fromJson(json['value_data']), $type: json['kind'] as String?, ); @@ -262,7 +260,7 @@ Map _$$VeilidUpdateValueChangeToJson( _$_VeilidStateAttachment _$$_VeilidStateAttachmentFromJson( Map json) => _$_VeilidStateAttachment( - state: AttachmentState.fromJson(json['state'] as String), + state: AttachmentState.fromJson(json['state']), publicInternetReady: json['public_internet_ready'] as bool, localNetworkReady: json['local_network_ready'] as bool, ); @@ -281,9 +279,8 @@ _$_VeilidStateNetwork _$$_VeilidStateNetworkFromJson( started: json['started'] as bool, bpsDown: BigInt.parse(json['bps_down'] as String), bpsUp: BigInt.parse(json['bps_up'] as String), - peers: (json['peers'] as List) - .map((e) => PeerTableData.fromJson(e as Map)) - .toList(), + peers: + (json['peers'] as List).map(PeerTableData.fromJson).toList(), ); Map _$$_VeilidStateNetworkToJson( @@ -297,7 +294,7 @@ Map _$$_VeilidStateNetworkToJson( _$_VeilidStateConfig _$$_VeilidStateConfigFromJson(Map json) => _$_VeilidStateConfig( - config: VeilidConfig.fromJson(json['config'] as Map), + config: VeilidConfig.fromJson(json['config']), ); Map _$$_VeilidStateConfigToJson( @@ -308,12 +305,9 @@ Map _$$_VeilidStateConfigToJson( _$_VeilidState _$$_VeilidStateFromJson(Map json) => _$_VeilidState( - attachment: VeilidStateAttachment.fromJson( - json['attachment'] as Map), - network: - VeilidStateNetwork.fromJson(json['network'] as Map), - config: - VeilidStateConfig.fromJson(json['config'] as Map), + attachment: VeilidStateAttachment.fromJson(json['attachment']), + network: VeilidStateNetwork.fromJson(json['network']), + config: VeilidStateConfig.fromJson(json['config']), ); Map _$$_VeilidStateToJson(_$_VeilidState instance) => diff --git a/veilid-flutter/pubspec.yaml b/veilid-flutter/pubspec.yaml index 6aa84ed0..d3dc3ab4 100644 --- a/veilid-flutter/pubspec.yaml +++ b/veilid-flutter/pubspec.yaml @@ -13,6 +13,7 @@ dependencies: charcode: ^1.3.1 equatable: ^2.0.5 ffi: ^2.0.0 + fixnum: ^1.1.0 flutter: sdk: flutter flutter_web_plugins: From 042b84005a52e004d22799a517517d9a34f2a687 Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Fri, 4 Aug 2023 01:00:23 -0400 Subject: [PATCH 06/15] fix bug --- veilid-flutter/lib/veilid_crypto.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/veilid-flutter/lib/veilid_crypto.dart b/veilid-flutter/lib/veilid_crypto.dart index 21050517..6b258c11 100644 --- a/veilid-flutter/lib/veilid_crypto.dart +++ b/veilid-flutter/lib/veilid_crypto.dart @@ -199,7 +199,7 @@ abstract class VeilidCryptoSystem { Future decryptNoAuthWithNonce( Uint8List body, SharedSecret secret) async { - if (body.length <= Nonce.decodedLength()) { + if (body.length < Nonce.decodedLength()) { throw const FormatException('not enough data to decrypt'); } final nonce = @@ -220,7 +220,7 @@ abstract class VeilidCryptoSystem { Future decryptNoAuthWithPassword( Uint8List body, String password) async { - if (body.length <= Nonce.decodedLength()) { + if (body.length < Nonce.decodedLength()) { throw const FormatException('not enough data to decrypt'); } final ekbytes = Uint8List.fromList(utf8.encode(password)); From ef327fb963f8975139d94907d6dfdae581b29554 Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Sat, 5 Aug 2023 10:49:42 -0400 Subject: [PATCH 07/15] crash fix --- veilid-core/src/storage_manager/mod.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/veilid-core/src/storage_manager/mod.rs b/veilid-core/src/storage_manager/mod.rs index 4b21abb7..a5b7e798 100644 --- a/veilid-core/src/storage_manager/mod.rs +++ b/veilid-core/src/storage_manager/mod.rs @@ -201,6 +201,17 @@ impl StorageManager { // Reopen inner to store value we just got let mut inner = self.lock().await?; + // Check again to see if we have a local record already or not + // because waiting for the outbound_get_value action could result in the key being opened + // via some parallel process + + if let Some(res) = inner + .open_existing_record(key, writer, safety_selection) + .await? + { + return Ok(res); + } + // Open the new record inner .open_new_record(key, writer, subkey, subkey_result, safety_selection) From 8e1ed1e3f1c41608ac866893bc06ed520acaca9a Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Sat, 5 Aug 2023 11:33:27 -0400 Subject: [PATCH 08/15] fix crash --- veilid-core/src/crypto/mod.rs | 7 ++++++ veilid-core/src/routing_table/find_peers.rs | 23 +++++++++++++++---- veilid-core/src/routing_table/mod.rs | 2 +- .../src/routing_table/routing_table_inner.rs | 8 ++++--- veilid-core/src/rpc_processor/fanout_call.rs | 11 ++++++--- veilid-core/src/veilid_api/api.rs | 4 ++++ veilid-core/src/veilid_api/routing_context.rs | 8 +++++++ veilid-flutter/lib/veilid_crypto.dart | 2 ++ 8 files changed, 54 insertions(+), 11 deletions(-) diff --git a/veilid-core/src/crypto/mod.rs b/veilid-core/src/crypto/mod.rs index 07c02a37..0b2c63ec 100644 --- a/veilid-core/src/crypto/mod.rs +++ b/veilid-core/src/crypto/mod.rs @@ -325,4 +325,11 @@ impl Crypto { }, ) } + + pub(crate) fn validate_crypto_kind(kind: CryptoKind) -> VeilidAPIResult<()> { + if !VALID_CRYPTO_KINDS.contains(&kind) { + apibail_generic!("invalid crypto kind"); + } + Ok(()) + } } diff --git a/veilid-core/src/routing_table/find_peers.rs b/veilid-core/src/routing_table/find_peers.rs index c60b3537..03b109b3 100644 --- a/veilid-core/src/routing_table/find_peers.rs +++ b/veilid-core/src/routing_table/find_peers.rs @@ -13,6 +13,9 @@ impl RoutingTable { "Not finding closest peers because our network class is still invalid", ); } + if Crypto::validate_crypto_kind(key.kind).is_err() { + return NetworkResult::invalid_message("invalid crypto kind"); + } // find N nodes closest to the target node in our routing table let own_peer_info = self.get_own_peer_info(RoutingDomain::PublicInternet); @@ -46,7 +49,7 @@ impl RoutingTable { }; let own_peer_info = self.get_own_peer_info(RoutingDomain::PublicInternet); - let closest_nodes = self.find_closest_nodes( + let closest_nodes = match self.find_closest_nodes( node_count, key, filters, @@ -54,7 +57,13 @@ impl RoutingTable { |rti, entry| { rti.transform_to_peer_info(RoutingDomain::PublicInternet, &own_peer_info, entry) }, - ); + ) { + Ok(v) => v, + Err(e) => { + error!("failed to find closest nodes for key {}: {}", key, e); + return NetworkResult::invalid_message("failed to find closest nodes for key"); + } + }; NetworkResult::value(closest_nodes) } @@ -117,7 +126,7 @@ impl RoutingTable { }; // - let closest_nodes = self.find_closest_nodes( + let closest_nodes = match self.find_closest_nodes( node_count, key, filters, @@ -127,7 +136,13 @@ impl RoutingTable { e.make_peer_info(RoutingDomain::PublicInternet).unwrap() }) }, - ); + ) { + Ok(v) => v, + Err(e) => { + error!("failed to find closest nodes for key {}: {}", key, e); + return NetworkResult::invalid_message("failed to find closest nodes for key"); + } + }; // Validate peers returned are, in fact, closer to the key than the node we sent this to // This same test is used on the other side so we vet things here diff --git a/veilid-core/src/routing_table/mod.rs b/veilid-core/src/routing_table/mod.rs index a1106d83..2f63df4a 100644 --- a/veilid-core/src/routing_table/mod.rs +++ b/veilid-core/src/routing_table/mod.rs @@ -1012,7 +1012,7 @@ impl RoutingTable { node_id: TypedKey, filters: VecDeque, transform: T, - ) -> Vec + ) -> VeilidAPIResult> where T: for<'r> FnMut(&'r RoutingTableInner, Option>) -> O + Send, { diff --git a/veilid-core/src/routing_table/routing_table_inner.rs b/veilid-core/src/routing_table/routing_table_inner.rs index e82f9f9d..029f5da8 100644 --- a/veilid-core/src/routing_table/routing_table_inner.rs +++ b/veilid-core/src/routing_table/routing_table_inner.rs @@ -1162,7 +1162,7 @@ impl RoutingTableInner { node_id: TypedKey, mut filters: VecDeque, transform: T, - ) -> Vec + ) -> VeilidAPIResult> where T: for<'r> FnMut(&'r RoutingTableInner, Option>) -> O, { @@ -1170,7 +1170,9 @@ impl RoutingTableInner { // Get the crypto kind let crypto_kind = node_id.kind; - let vcrypto = self.unlocked_inner.crypto().get(crypto_kind).unwrap(); + let Some(vcrypto) = self.unlocked_inner.crypto().get(crypto_kind) else { + apibail_generic!("invalid crypto kind"); + }; // Filter to ensure entries support the crypto kind in use let filter = Box::new( @@ -1236,7 +1238,7 @@ impl RoutingTableInner { let out = self.find_peers_with_sort_and_filter(node_count, cur_ts, filters, sort, transform); log_rtab!(">> find_closest_nodes: node count = {}", out.len()); - out + Ok(out) } pub fn sort_and_clean_closest_noderefs( diff --git a/veilid-core/src/rpc_processor/fanout_call.rs b/veilid-core/src/rpc_processor/fanout_call.rs index 215378aa..7d16b086 100644 --- a/veilid-core/src/rpc_processor/fanout_call.rs +++ b/veilid-core/src/rpc_processor/fanout_call.rs @@ -208,7 +208,7 @@ where } } - fn init_closest_nodes(self: Arc) { + fn init_closest_nodes(self: Arc) -> Result<(), RPCError> { // Get the 'node_count' closest nodes to the key out of our routing table let closest_nodes = { let routing_table = self.routing_table.clone(); @@ -247,11 +247,14 @@ where NodeRef::new(routing_table.clone(), v.unwrap().clone(), None) }; - routing_table.find_closest_nodes(self.node_count, self.node_id, filters, transform) + routing_table + .find_closest_nodes(self.node_count, self.node_id, filters, transform) + .map_err(RPCError::invalid_format)? }; let mut ctx = self.context.lock(); ctx.closest_nodes = closest_nodes; + Ok(()) } pub async fn run(self: Arc) -> TimeoutOr, RPCError>> { @@ -264,7 +267,9 @@ where }; // Initialize closest nodes list - self.clone().init_closest_nodes(); + if let Err(e) = self.clone().init_closest_nodes() { + return TimeoutOr::value(Err(e)); + } // Do a quick check to see if we're already done if self.clone().evaluate_done() { diff --git a/veilid-core/src/veilid_api/api.rs b/veilid-core/src/veilid_api/api.rs index 5953a251..6c943e61 100644 --- a/veilid-core/src/veilid_api/api.rs +++ b/veilid-core/src/veilid_api/api.rs @@ -188,6 +188,10 @@ impl VeilidAPI { stability: Stability, sequencing: Sequencing, ) -> VeilidAPIResult<(RouteId, Vec)> { + for kind in crypto_kinds { + Crypto::validate_crypto_kind(*kind)?; + } + let default_route_hop_count: usize = { let config = self.config()?; let c = config.get(); diff --git a/veilid-core/src/veilid_api/routing_context.rs b/veilid-core/src/veilid_api/routing_context.rs index 16afc60a..2aeebc17 100644 --- a/veilid-core/src/veilid_api/routing_context.rs +++ b/veilid-core/src/veilid_api/routing_context.rs @@ -199,6 +199,7 @@ impl RoutingContext { kind: Option, ) -> VeilidAPIResult { let kind = kind.unwrap_or(best_crypto_kind()); + Crypto::validate_crypto_kind(kind)?; let storage_manager = self.api.storage_manager()?; storage_manager .create_record(kind, schema, self.unlocked_inner.safety_selection) @@ -213,6 +214,7 @@ impl RoutingContext { key: TypedKey, writer: Option, ) -> VeilidAPIResult { + Crypto::validate_crypto_kind(key.kind)?; let storage_manager = self.api.storage_manager()?; storage_manager .open_record(key, writer, self.unlocked_inner.safety_selection) @@ -222,6 +224,7 @@ impl RoutingContext { /// Closes a DHT record at a specific key that was opened with create_dht_record or open_dht_record. /// Closing a record allows you to re-open it with a different routing context pub async fn close_dht_record(&self, key: TypedKey) -> VeilidAPIResult<()> { + Crypto::validate_crypto_kind(key.kind)?; let storage_manager = self.api.storage_manager()?; storage_manager.close_record(key).await } @@ -230,6 +233,7 @@ impl RoutingContext { /// Deleting a record does not delete it from the network, but will remove the storage of the record /// locally, and will prevent its value from being refreshed on the network by this node. pub async fn delete_dht_record(&self, key: TypedKey) -> VeilidAPIResult<()> { + Crypto::validate_crypto_kind(key.kind)?; let storage_manager = self.api.storage_manager()?; storage_manager.delete_record(key).await } @@ -244,6 +248,7 @@ impl RoutingContext { subkey: ValueSubkey, force_refresh: bool, ) -> VeilidAPIResult> { + Crypto::validate_crypto_kind(key.kind)?; let storage_manager = self.api.storage_manager()?; storage_manager.get_value(key, subkey, force_refresh).await } @@ -257,6 +262,7 @@ impl RoutingContext { subkey: ValueSubkey, data: Vec, ) -> VeilidAPIResult> { + Crypto::validate_crypto_kind(key.kind)?; let storage_manager = self.api.storage_manager()?; storage_manager.set_value(key, subkey, data).await } @@ -273,6 +279,7 @@ impl RoutingContext { expiration: Timestamp, count: u32, ) -> VeilidAPIResult { + Crypto::validate_crypto_kind(key.kind)?; let storage_manager = self.api.storage_manager()?; storage_manager .watch_values(key, subkeys, expiration, count) @@ -286,6 +293,7 @@ impl RoutingContext { key: TypedKey, subkeys: ValueSubkeyRangeSet, ) -> VeilidAPIResult { + Crypto::validate_crypto_kind(key.kind)?; let storage_manager = self.api.storage_manager()?; storage_manager.cancel_watch_values(key, subkeys).await } diff --git a/veilid-flutter/lib/veilid_crypto.dart b/veilid-flutter/lib/veilid_crypto.dart index 6b258c11..665942ca 100644 --- a/veilid-flutter/lib/veilid_crypto.dart +++ b/veilid-flutter/lib/veilid_crypto.dart @@ -23,6 +23,7 @@ String cryptoKindToString(CryptoKind kind) => const CryptoKind bestCryptoKind = cryptoKindVLD0; Uint8List cryptoKindToBytes(CryptoKind kind) { + assert(kind == cryptoKindVLD0, 'xxx'); final b = Uint8List(4); ByteData.sublistView(b).setUint32(0, kind); return b; @@ -34,6 +35,7 @@ CryptoKind cryptoKindFromString(String s) { } final kind = ByteData.sublistView(Uint8List.fromList(s.codeUnits)).getUint32(0); + assert(kind == cryptoKindVLD0, 'xxx'); return kind; } From 684f93e6a096a5761830d02313820d0b4f5ade9d Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Sat, 5 Aug 2023 13:50:16 -0400 Subject: [PATCH 09/15] fix endianness --- veilid-flutter/lib/veilid_crypto.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/veilid-flutter/lib/veilid_crypto.dart b/veilid-flutter/lib/veilid_crypto.dart index 665942ca..a1417cf3 100644 --- a/veilid-flutter/lib/veilid_crypto.dart +++ b/veilid-flutter/lib/veilid_crypto.dart @@ -13,9 +13,9 @@ import 'veilid.dart'; typedef CryptoKind = int; const CryptoKind cryptoKindVLD0 = - $V << 0 | $L << 8 | $D << 16 | $0 << 24; // "VLD0" + $V << 24 | $L << 16 | $D << 8 | $0 << 0; // "VLD0" const CryptoKind cryptoKindNONE = - $N << 0 | $O << 8 | $N << 16 | $E << 24; // "NONE" + $N << 24 | $O << 16 | $N << 8 | $E << 0; // "NONE" String cryptoKindToString(CryptoKind kind) => cryptoKindToBytes(kind).map(String.fromCharCode).join(); From 435469ce94d2a1984a5f4e862bfe2f31fa9ca546 Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Sun, 6 Aug 2023 12:31:20 -0400 Subject: [PATCH 10/15] offline subkey writes --- veilid-core/src/storage_manager/mod.rs | 38 +++++++++++- .../storage_manager/storage_manager_inner.rs | 8 ++- veilid-core/src/storage_manager/tasks/mod.rs | 35 ++++++++++- .../tasks/offline_subkey_writes.rs | 62 +++++++++++++++++++ 4 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 veilid-core/src/storage_manager/tasks/offline_subkey_writes.rs diff --git a/veilid-core/src/storage_manager/mod.rs b/veilid-core/src/storage_manager/mod.rs index a5b7e798..7d087436 100644 --- a/veilid-core/src/storage_manager/mod.rs +++ b/veilid-core/src/storage_manager/mod.rs @@ -18,6 +18,7 @@ use storage_manager_inner::*; pub use types::*; use super::*; +use network_manager::*; use routing_table::*; use rpc_processor::*; @@ -27,6 +28,8 @@ const MAX_SUBKEY_SIZE: usize = ValueData::MAX_LEN; const MAX_RECORD_DATA_SIZE: usize = 1_048_576; /// Frequency to flush record stores to disk const FLUSH_RECORD_STORES_INTERVAL_SECS: u32 = 1; +/// Frequency to check for offline subkeys writes to send to the network +const OFFLINE_SUBKEY_WRITES_INTERVAL_SECS: u32 = 1; struct StorageManagerUnlockedInner { config: VeilidConfig, @@ -37,6 +40,7 @@ struct StorageManagerUnlockedInner { // Background processes flush_record_stores_task: TickTask, + offline_subkey_writes_task: TickTask, } #[derive(Clone)] @@ -59,6 +63,7 @@ impl StorageManager { #[cfg(feature = "unstable-blockstore")] block_store, flush_record_stores_task: TickTask::new(FLUSH_RECORD_STORES_INTERVAL_SECS), + offline_subkey_writes_task: TickTask::new(OFFLINE_SUBKEY_WRITES_INTERVAL_SECS), } } fn new_inner(unlocked_inner: Arc) -> StorageManagerInner { @@ -127,6 +132,32 @@ impl StorageManager { Ok(inner) } + async fn network_is_ready(&self) -> EyreResult { + if let Some(rpc_processor) = { + let inner = self.lock().await?; + inner.rpc_processor.clone() + } { + if let Some(network_class) = rpc_processor + .routing_table() + .get_network_class(RoutingDomain::PublicInternet) + { + // If our PublicInternet network class is valid we're ready to talk + Ok(network_class != NetworkClass::Invalid) + } else { + // If we haven't gotten a network class yet we shouldnt try to use the DHT + Ok(false) + } + } else { + // If we aren't attached, we won't have an rpc processor + Ok(false) + } + } + + async fn has_offline_subkey_writes(&self) -> EyreResult { + let inner = self.lock().await?; + Ok(inner.offline_subkey_writes.len() != 0) + } + /// Create a local record from scratch with a new owner key, open it, and return the opened descriptor pub async fn create_record( &self, @@ -391,7 +422,12 @@ impl StorageManager { .await?; // Add to offline writes to flush - inner.offline_subkey_writes.entry(key).and_modify(|x| { x.insert(subkey); } ).or_insert(ValueSubkeyRangeSet::single(subkey)); + inner.offline_subkey_writes.entry(key) + .and_modify(|x| { x.subkeys.insert(subkey); } ) + .or_insert(OfflineSubkeyWrite{ + safety_selection, + subkeys: ValueSubkeyRangeSet::single(subkey) + }); return Ok(None) }; diff --git a/veilid-core/src/storage_manager/storage_manager_inner.rs b/veilid-core/src/storage_manager/storage_manager_inner.rs index 2d74c2b5..9a8815da 100644 --- a/veilid-core/src/storage_manager/storage_manager_inner.rs +++ b/veilid-core/src/storage_manager/storage_manager_inner.rs @@ -3,6 +3,12 @@ use super::*; const STORAGE_MANAGER_METADATA: &str = "storage_manager_metadata"; const OFFLINE_SUBKEY_WRITES: &[u8] = b"offline_subkey_writes"; +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub(super) struct OfflineSubkeyWrite { + pub safety_selection: SafetySelection, + pub subkeys: ValueSubkeyRangeSet, +} + /// Locked structure for storage manager pub(super) struct StorageManagerInner { unlocked_inner: Arc, @@ -15,7 +21,7 @@ pub(super) struct StorageManagerInner { /// Records that have been pushed to this node for distribution by other nodes, that we make an effort to republish pub remote_record_store: Option>, /// Record subkeys that have not been pushed to the network because they were written to offline - pub offline_subkey_writes: HashMap, + pub offline_subkey_writes: HashMap, /// Storage manager metadata that is persistent, including copy of offline subkey writes pub metadata_db: Option, /// RPC processor if it is available diff --git a/veilid-core/src/storage_manager/tasks/mod.rs b/veilid-core/src/storage_manager/tasks/mod.rs index cd90a82e..d9f49d7b 100644 --- a/veilid-core/src/storage_manager/tasks/mod.rs +++ b/veilid-core/src/storage_manager/tasks/mod.rs @@ -1,10 +1,11 @@ pub mod flush_record_stores; +pub mod offline_subkey_writes; use super::*; impl StorageManager { pub(crate) fn setup_tasks(&self) { - // Set rolling transfers tick task + // Set flush records tick task debug!("starting flush record stores task"); { let this = self.clone(); @@ -25,12 +26,40 @@ impl StorageManager { ) }); } + // Set offline subkey writes tick task + debug!("starting offline subkey writes task"); + { + let this = self.clone(); + self.unlocked_inner + .offline_subkey_writes_task + .set_routine(move |s, l, t| { + Box::pin( + this.clone() + .offline_subkey_writes_task_routine( + s, + Timestamp::new(l), + Timestamp::new(t), + ) + .instrument(trace_span!( + parent: None, + "StorageManager offline subkey writes task routine" + )), + ) + }); + } } pub async fn tick(&self) -> EyreResult<()> { // Run the rolling transfers task self.unlocked_inner.flush_record_stores_task.tick().await?; + // Run offline subkey writes task if there's work to be done + if self.network_is_ready().await? && self.has_offline_subkey_writes().await? { + self.unlocked_inner + .offline_subkey_writes_task + .tick() + .await?; + } Ok(()) } @@ -39,5 +68,9 @@ impl StorageManager { if let Err(e) = self.unlocked_inner.flush_record_stores_task.stop().await { warn!("flush_record_stores_task not stopped: {}", e); } + debug!("stopping offline subkey writes task"); + if let Err(e) = self.unlocked_inner.offline_subkey_writes_task.stop().await { + warn!("offline_subkey_writes_task not stopped: {}", e); + } } } diff --git a/veilid-core/src/storage_manager/tasks/offline_subkey_writes.rs b/veilid-core/src/storage_manager/tasks/offline_subkey_writes.rs new file mode 100644 index 00000000..81b1613a --- /dev/null +++ b/veilid-core/src/storage_manager/tasks/offline_subkey_writes.rs @@ -0,0 +1,62 @@ +use super::*; +use futures_util::*; + +impl StorageManager { + // Best-effort write subkeys to the network that were written offline + #[instrument(level = "trace", skip(self), err)] + pub(crate) async fn offline_subkey_writes_task_routine( + self, + stop_token: StopToken, + _last_ts: Timestamp, + _cur_ts: Timestamp, + ) -> EyreResult<()> { + let (rpc_processor, offline_subkey_writes) = { + let inner = self.lock().await?; + + let Some(rpc_processor) = inner.rpc_processor.clone() else { + return Ok(()); + }; + + (rpc_processor, inner.offline_subkey_writes.clone()) + }; + + // make a safety selection that is conservative + for (key, osw) in offline_subkey_writes { + if poll!(stop_token.clone()).is_ready() { + break; + } + for subkey in osw.subkeys.iter() { + let subkey_result = { + let mut inner = self.lock().await?; + inner.handle_get_local_value(key, subkey, true).await + }; + let Ok(subkey_result) = subkey_result else { + continue; + }; + let Some(value) = subkey_result.value else { + continue; + }; + let Some(descriptor) = subkey_result.descriptor else { + continue; + }; + if let Err(e) = self + .outbound_set_value( + rpc_processor.clone(), + key, + subkey, + osw.safety_selection, + value, + descriptor, + ) + .await + { + log_stor!(debug "failed to write offline subkey: {}", e); + } + } + let mut inner = self.lock().await?; + inner.offline_subkey_writes.remove(&key); + } + + Ok(()) + } +} From b2503ae7894cae04355fbd2ae39d441f37c79270 Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Sun, 6 Aug 2023 13:27:57 -0400 Subject: [PATCH 11/15] offline work --- veilid-core/src/storage_manager/mod.rs | 23 ++++++++++++++----- veilid-core/src/storage_manager/tasks/mod.rs | 2 +- .../tasks/offline_subkey_writes.rs | 20 +++++++++------- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/veilid-core/src/storage_manager/mod.rs b/veilid-core/src/storage_manager/mod.rs index 7d087436..c1b30978 100644 --- a/veilid-core/src/storage_manager/mod.rs +++ b/veilid-core/src/storage_manager/mod.rs @@ -132,9 +132,8 @@ impl StorageManager { Ok(inner) } - async fn network_is_ready(&self) -> EyreResult { + fn online_writes_ready_inner(inner: &StorageManagerInner) -> Option { if let Some(rpc_processor) = { - let inner = self.lock().await?; inner.rpc_processor.clone() } { if let Some(network_class) = rpc_processor @@ -142,17 +141,26 @@ impl StorageManager { .get_network_class(RoutingDomain::PublicInternet) { // If our PublicInternet network class is valid we're ready to talk - Ok(network_class != NetworkClass::Invalid) + if network_class != NetworkClass::Invalid { + Some(rpc_processor) + } else { + None + } } else { // If we haven't gotten a network class yet we shouldnt try to use the DHT - Ok(false) + None } } else { // If we aren't attached, we won't have an rpc processor - Ok(false) + None } } + async fn online_writes_ready(&self) -> EyreResult> { + let inner = self.lock().await?; + return Ok(Self::online_writes_ready_inner(&*inner)); + } + async fn has_offline_subkey_writes(&self) -> EyreResult { let inner = self.lock().await?; Ok(inner.offline_subkey_writes.len() != 0) @@ -415,12 +423,15 @@ impl StorageManager { )?; // Get rpc processor and drop mutex so we don't block while getting the value from the network - let Some(rpc_processor) = inner.rpc_processor.clone() else { + let Some(rpc_processor) = Self::online_writes_ready_inner(&inner) else { + log_stor!(debug "Writing subkey locally: {}:{} len={}", key, subkey, signed_value_data.value_data().data().len() ); + // Offline, just write it locally and return immediately inner .handle_set_local_value(key, subkey, signed_value_data.clone()) .await?; + log_stor!(debug "Writing subkey offline: {}:{} len={}", key, subkey, signed_value_data.value_data().data().len() ); // Add to offline writes to flush inner.offline_subkey_writes.entry(key) .and_modify(|x| { x.subkeys.insert(subkey); } ) diff --git a/veilid-core/src/storage_manager/tasks/mod.rs b/veilid-core/src/storage_manager/tasks/mod.rs index d9f49d7b..36171b80 100644 --- a/veilid-core/src/storage_manager/tasks/mod.rs +++ b/veilid-core/src/storage_manager/tasks/mod.rs @@ -54,7 +54,7 @@ impl StorageManager { self.unlocked_inner.flush_record_stores_task.tick().await?; // Run offline subkey writes task if there's work to be done - if self.network_is_ready().await? && self.has_offline_subkey_writes().await? { + if self.online_writes_ready().await?.is_some() && self.has_offline_subkey_writes().await? { self.unlocked_inner .offline_subkey_writes_task .tick() diff --git a/veilid-core/src/storage_manager/tasks/offline_subkey_writes.rs b/veilid-core/src/storage_manager/tasks/offline_subkey_writes.rs index 81b1613a..93a4d55e 100644 --- a/veilid-core/src/storage_manager/tasks/offline_subkey_writes.rs +++ b/veilid-core/src/storage_manager/tasks/offline_subkey_writes.rs @@ -10,35 +10,39 @@ impl StorageManager { _last_ts: Timestamp, _cur_ts: Timestamp, ) -> EyreResult<()> { - let (rpc_processor, offline_subkey_writes) = { + let offline_subkey_writes = { let inner = self.lock().await?; - - let Some(rpc_processor) = inner.rpc_processor.clone() else { - return Ok(()); - }; - - (rpc_processor, inner.offline_subkey_writes.clone()) + inner.offline_subkey_writes.clone() }; // make a safety selection that is conservative for (key, osw) in offline_subkey_writes { if poll!(stop_token.clone()).is_ready() { + log_stor!(debug "Offline subkey writes cancelled."); break; } + let Some(rpc_processor) = self.online_writes_ready().await? else { + log_stor!(debug "Offline subkey writes stopped for network."); + break; + }; for subkey in osw.subkeys.iter() { let subkey_result = { let mut inner = self.lock().await?; inner.handle_get_local_value(key, subkey, true).await }; let Ok(subkey_result) = subkey_result else { - continue; + log_stor!(debug "Offline subkey write had no subkey result: {}:{}", key, subkey); + continue; }; let Some(value) = subkey_result.value else { + log_stor!(debug "Offline subkey write had no subkey value: {}:{}", key, subkey); continue; }; let Some(descriptor) = subkey_result.descriptor else { + log_stor!(debug "Offline subkey write had no descriptor: {}:{}", key, subkey); continue; }; + log_stor!(debug "Offline subkey write: {}:{} len={}", key, subkey, value.value_data().data().len()); if let Err(e) = self .outbound_set_value( rpc_processor.clone(), From fcd9772e00824a3526cec53ff9113783a36a5b7b Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Mon, 7 Aug 2023 14:26:58 -0700 Subject: [PATCH 12/15] improve timestamp --- veilid-flutter/lib/veilid.dart | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/veilid-flutter/lib/veilid.dart b/veilid-flutter/lib/veilid.dart index 378cc732..84709a11 100644 --- a/veilid-flutter/lib/veilid.dart +++ b/veilid-flutter/lib/veilid.dart @@ -60,10 +60,11 @@ class VeilidVersion extends Equatable { ////////////////////////////////////// /// Timestamp @immutable -class Timestamp extends Equatable { +class Timestamp extends Equatable implements Comparable { const Timestamp({required this.value}); - factory Timestamp.fromInt64(Int64 i64) => - Timestamp(value: BigInt.parse(i64.toStringUnsigned())); + factory Timestamp.fromInt64(Int64 i64) => Timestamp( + value: (BigInt.from((i64 >> 32).toUnsigned(32).toInt()) << 32) | + BigInt.from(i64.toUnsigned(32).toInt())); factory Timestamp.fromString(String s) => Timestamp(value: BigInt.parse(s)); factory Timestamp.fromJson(dynamic json) => Timestamp.fromString(json as String); @@ -71,10 +72,14 @@ class Timestamp extends Equatable { @override List get props => [value]; + @override + int compareTo(Timestamp other) => value.compareTo(other.value); + @override String toString() => value.toString(); String toJson() => toString(); - Int64 toInt64() => Int64.parseInt(value.toString()); + Int64 toInt64() => Int64.fromInts( + (value >> 32).toUnsigned(32).toInt(), value.toUnsigned(32).toInt()); TimestampDuration diff(Timestamp other) => TimestampDuration(value: value - other.value); @@ -84,10 +89,12 @@ class Timestamp extends Equatable { } @immutable -class TimestampDuration extends Equatable { +class TimestampDuration extends Equatable + implements Comparable { const TimestampDuration({required this.value}); - factory TimestampDuration.fromInt64(Int64 i64) => - TimestampDuration(value: BigInt.parse(i64.toStringUnsigned())); + factory TimestampDuration.fromInt64(Int64 i64) => TimestampDuration( + value: (BigInt.from((i64 >> 32).toUnsigned(32).toInt()) << 32) | + BigInt.from(i64.toUnsigned(32).toInt())); factory TimestampDuration.fromString(String s) => TimestampDuration(value: BigInt.parse(s)); factory TimestampDuration.fromJson(dynamic json) => @@ -96,10 +103,14 @@ class TimestampDuration extends Equatable { @override List get props => [value]; + @override + int compareTo(TimestampDuration other) => value.compareTo(other.value); + @override String toString() => value.toString(); String toJson() => toString(); - Int64 toInt64() => Int64.parseInt(value.toString()); + Int64 toInt64() => Int64.fromInts( + (value >> 32).toUnsigned(32).toInt(), value.toUnsigned(32).toInt()); int toMillis() => (value ~/ BigInt.from(1000)).toInt(); BigInt toMicros() => value; From 2c779b225752959653d4aaf1ff30ecd5045d06b9 Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Tue, 8 Aug 2023 23:33:54 -0700 Subject: [PATCH 13/15] fanout debugging --- veilid-core/src/rpc_processor/fanout_call.rs | 6 ++- veilid-core/src/storage_manager/get_value.rs | 54 +++++++++++++------ veilid-core/src/storage_manager/set_value.rs | 57 +++++++++++++------- veilid-flutter/lib/default_config.dart | 12 ++--- 4 files changed, 89 insertions(+), 40 deletions(-) diff --git a/veilid-core/src/rpc_processor/fanout_call.rs b/veilid-core/src/rpc_processor/fanout_call.rs index 7d16b086..94dfda66 100644 --- a/veilid-core/src/rpc_processor/fanout_call.rs +++ b/veilid-core/src/rpc_processor/fanout_call.rs @@ -288,7 +288,11 @@ where } // Wait for them to complete timeout(timeout_ms, async { - while let Some(_) = unord.next().await {} + while let Some(_) = unord.next().await { + if self.clone().evaluate_done() { + break; + } + } }) .await .into_timeout_or() diff --git a/veilid-core/src/storage_manager/get_value.rs b/veilid-core/src/storage_manager/get_value.rs index 47998eff..2bb7d1c7 100644 --- a/veilid-core/src/storage_manager/get_value.rs +++ b/veilid-core/src/storage_manager/get_value.rs @@ -13,7 +13,6 @@ struct OutboundGetValueContext { } impl StorageManager { - /// Perform a 'get value' query on the network pub async fn outbound_get_value( &self, @@ -74,15 +73,14 @@ impl StorageManager { if let Some(descriptor) = gva.answer.descriptor { let mut ctx = context.lock(); if ctx.descriptor.is_none() && ctx.schema.is_none() { - ctx.schema = - Some(descriptor.schema().map_err(RPCError::invalid_format)?); + ctx.schema = Some(descriptor.schema().map_err(RPCError::invalid_format)?); ctx.descriptor = Some(descriptor); } } // Keep the value if we got one and it is newer and it passes schema validation if let Some(value) = gva.answer.value { - log_stor!(debug "Got value back: len={}", value.value_data().data().len()); + log_stor!(debug "Got value back: len={} seq={}", value.value_data().data().len(), value.value_data().seq()); let mut ctx = context.lock(); // Ensure we have a schema and descriptor @@ -126,8 +124,7 @@ impl StorageManager { } else { // If the sequence number is older, ignore it } - } - else { + } else { // If we have no prior value, keep it ctx.value = Some(value); // One node has shown us this value so far @@ -136,7 +133,7 @@ impl StorageManager { } // Return peers if we have some - #[cfg(feature="network-result-extra")] + #[cfg(feature = "network-result-extra")] log_stor!(debug "GetValue fanout call returned peers {}", gva.answer.peers.len()); Ok(Some(gva.answer.peers)) @@ -147,7 +144,8 @@ impl StorageManager { let check_done = |_closest_nodes: &[NodeRef]| { // If we have reached sufficient consensus, return done let ctx = context.lock(); - if ctx.value.is_some() && ctx.descriptor.is_some() && ctx.value_count >= consensus_count { + if ctx.value.is_some() && ctx.descriptor.is_some() && ctx.value_count >= consensus_count + { return Some(()); } None @@ -167,14 +165,31 @@ impl StorageManager { match fanout_call.run().await { // If we don't finish in the timeout (too much time passed checking for consensus) - TimeoutOr::Timeout | + TimeoutOr::Timeout => { + log_stor!(debug "GetValue Fanout Timeout"); + // Return the best answer we've got + let ctx = context.lock(); + Ok(SubkeyResult { + value: ctx.value.clone(), + descriptor: ctx.descriptor.clone(), + }) + } // If we finished with consensus (enough nodes returning the same value) - TimeoutOr::Value(Ok(Some(()))) | + TimeoutOr::Value(Ok(Some(()))) => { + log_stor!(debug "GetValue Fanout Consensus"); + // Return the best answer we've got + let ctx = context.lock(); + Ok(SubkeyResult { + value: ctx.value.clone(), + descriptor: ctx.descriptor.clone(), + }) + } // If we finished without consensus (ran out of nodes before getting consensus) TimeoutOr::Value(Ok(None)) => { // Return the best answer we've got let ctx = context.lock(); - Ok(SubkeyResult{ + log_stor!(debug "GetValue Fanout No Consensus: {}", ctx.value_count); + Ok(SubkeyResult { value: ctx.value.clone(), descriptor: ctx.descriptor.clone(), }) @@ -182,22 +197,31 @@ impl StorageManager { // Failed TimeoutOr::Value(Err(e)) => { // If we finished with an error, return that + log_stor!(debug "GetValue Fanout Error: {}", e); Err(e.into()) } } } /// Handle a recieved 'Get Value' query - pub async fn inbound_get_value(&self, key: TypedKey, subkey: ValueSubkey, want_descriptor: bool) -> VeilidAPIResult> { + pub async fn inbound_get_value( + &self, + key: TypedKey, + subkey: ValueSubkey, + want_descriptor: bool, + ) -> VeilidAPIResult> { let mut inner = self.lock().await?; - let res = match inner.handle_get_remote_value(key, subkey, want_descriptor).await { + let res = match inner + .handle_get_remote_value(key, subkey, want_descriptor) + .await + { Ok(res) => res, Err(VeilidAPIError::Internal { message }) => { apibail_internal!(message); - }, + } Err(e) => { return Ok(NetworkResult::invalid_message(e)); - }, + } }; Ok(NetworkResult::value(res)) } diff --git a/veilid-core/src/storage_manager/set_value.rs b/veilid-core/src/storage_manager/set_value.rs index 25a08170..09f655aa 100644 --- a/veilid-core/src/storage_manager/set_value.rs +++ b/veilid-core/src/storage_manager/set_value.rs @@ -11,7 +11,6 @@ struct OutboundSetValueContext { } impl StorageManager { - /// Perform a 'set value' query on the network pub async fn outbound_set_value( &self, @@ -49,7 +48,6 @@ impl StorageManager { let context = context.clone(); let descriptor = descriptor.clone(); async move { - let send_descriptor = true; // xxx check if next_node needs the descriptor or not // get most recent value to send @@ -81,6 +79,7 @@ impl StorageManager { // Keep the value if we got one and it is newer and it passes schema validation if let Some(value) = sva.answer.value { + log_stor!(debug "Got value back: len={} seq={}", value.value_data().data().len(), value.value_data().seq()); // Validate with schema if !ctx.schema.check_subkey_value_data( @@ -101,14 +100,12 @@ impl StorageManager { // One node has shown us this value so far ctx.value_count = 1; } else { - // If the sequence number is older, or an equal sequence number, + // If the sequence number is older, or an equal sequence number, // node should have not returned a value here. // Skip this node and it's closer list because it is misbehaving return Ok(None); } - } - else - { + } else { // It was set on this node and no newer value was found and returned, // so increase our consensus count ctx.value_count += 1; @@ -116,7 +113,7 @@ impl StorageManager { } // Return peers if we have some - #[cfg(feature="network-result-extra")] + #[cfg(feature = "network-result-extra")] log_stor!(debug "SetValue fanout call returned peers {}", sva.answer.peers.len()); Ok(Some(sva.answer.peers)) @@ -147,18 +144,30 @@ impl StorageManager { match fanout_call.run().await { // If we don't finish in the timeout (too much time passed checking for consensus) - TimeoutOr::Timeout | + TimeoutOr::Timeout => { + log_stor!(debug "SetValue Fanout Timeout"); + // Return the best answer we've got + let ctx = context.lock(); + Ok(ctx.value.clone()) + } // If we finished with consensus (enough nodes returning the same value) - TimeoutOr::Value(Ok(Some(()))) | + TimeoutOr::Value(Ok(Some(()))) => { + log_stor!(debug "SetValue Fanout Consensus"); + // Return the best answer we've got + let ctx = context.lock(); + Ok(ctx.value.clone()) + } // If we finished without consensus (ran out of nodes before getting consensus) TimeoutOr::Value(Ok(None)) => { // Return the best answer we've got let ctx = context.lock(); + log_stor!(debug "SetValue Fanout No Consensus: {}", ctx.value_count); Ok(ctx.value.clone()) } // Failed TimeoutOr::Value(Err(e)) => { // If we finished with an error, return that + log_stor!(debug "SetValue Fanout Error: {}", e); Err(e.into()) } } @@ -167,7 +176,13 @@ impl StorageManager { /// Handle a recieved 'Set Value' query /// Returns a None if the value passed in was set /// Returns a Some(current value) if the value was older and the current value was kept - pub async fn inbound_set_value(&self, key: TypedKey, subkey: ValueSubkey, value: SignedValueData, descriptor: Option) -> VeilidAPIResult>> { + pub async fn inbound_set_value( + &self, + key: TypedKey, + subkey: ValueSubkey, + value: SignedValueData, + descriptor: Option, + ) -> VeilidAPIResult>> { let mut inner = self.lock().await?; // See if this is a remote or local value @@ -198,19 +213,23 @@ impl StorageManager { if let Some(descriptor) = descriptor { // Descriptor must match last one if it is provided if descriptor.cmp_no_sig(&last_descriptor) != cmp::Ordering::Equal { - return Ok(NetworkResult::invalid_message("setvalue descriptor does not match last descriptor")); + return Ok(NetworkResult::invalid_message( + "setvalue descriptor does not match last descriptor", + )); } } else { // Descriptor was not provided always go with last descriptor } last_descriptor - } + } None => { if let Some(descriptor) = descriptor { descriptor } else { // No descriptor - return Ok(NetworkResult::invalid_message("descriptor must be provided")); + return Ok(NetworkResult::invalid_message( + "descriptor must be provided", + )); } } }; @@ -228,16 +247,18 @@ impl StorageManager { let res = if is_local { inner.handle_set_local_value(key, subkey, value).await } else { - inner.handle_set_remote_value(key, subkey, value, actual_descriptor).await + inner + .handle_set_remote_value(key, subkey, value, actual_descriptor) + .await }; - match res { - Ok(()) => {}, + match res { + Ok(()) => {} Err(VeilidAPIError::Internal { message }) => { apibail_internal!(message); - }, + } Err(e) => { return Ok(NetworkResult::invalid_message(e)); - }, + } } Ok(NetworkResult::value(None)) } diff --git a/veilid-flutter/lib/default_config.dart b/veilid-flutter/lib/default_config.dart index 9b877dbc..5ee45061 100644 --- a/veilid-flutter/lib/default_config.dart +++ b/veilid-flutter/lib/default_config.dart @@ -117,15 +117,15 @@ Future getDefaultVeilidConfig(String programName) async => ), dht: VeilidConfigDHT( resolveNodeTimeoutMs: 10000, - resolveNodeCount: 20, - resolveNodeFanout: 3, + resolveNodeCount: 1, + resolveNodeFanout: 4, maxFindNodeCount: 20, getValueTimeoutMs: 10000, - getValueCount: 20, - getValueFanout: 3, + getValueCount: 3, + getValueFanout: 4, setValueTimeoutMs: 10000, - setValueCount: 20, - setValueFanout: 5, + setValueCount: 4, + setValueFanout: 6, minPeerCount: 20, minPeerRefreshTimeMs: 60000, validateDialInfoReceiptTimeMs: 2000, From be45a1b3502b3e361a2bd6e69fc8116e5391d362 Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Fri, 18 Aug 2023 00:32:44 -0400 Subject: [PATCH 14/15] remove debugging code --- veilid-flutter/lib/veilid_crypto.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/veilid-flutter/lib/veilid_crypto.dart b/veilid-flutter/lib/veilid_crypto.dart index a1417cf3..6edb6358 100644 --- a/veilid-flutter/lib/veilid_crypto.dart +++ b/veilid-flutter/lib/veilid_crypto.dart @@ -23,7 +23,6 @@ String cryptoKindToString(CryptoKind kind) => const CryptoKind bestCryptoKind = cryptoKindVLD0; Uint8List cryptoKindToBytes(CryptoKind kind) { - assert(kind == cryptoKindVLD0, 'xxx'); final b = Uint8List(4); ByteData.sublistView(b).setUint32(0, kind); return b; @@ -35,7 +34,6 @@ CryptoKind cryptoKindFromString(String s) { } final kind = ByteData.sublistView(Uint8List.fromList(s.codeUnits)).getUint32(0); - assert(kind == cryptoKindVLD0, 'xxx'); return kind; } From 1a1820126024c812e29940f8960498dad603b4ba Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Fri, 18 Aug 2023 00:53:31 -0400 Subject: [PATCH 15/15] fix tests --- veilid-server/src/settings.rs | 39 +++++++++++------------------------ 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/veilid-server/src/settings.rs b/veilid-server/src/settings.rs index 701e92d3..4066e59e 100644 --- a/veilid-server/src/settings.rs +++ b/veilid-server/src/settings.rs @@ -1647,13 +1647,10 @@ mod tests { assert_eq!(s.core.network.tls.connection_initial_timeout_ms, 2_000u32); // assert_eq!(s.core.network.application.https.enabled, false); - assert_eq!( - s.core.network.application.https.listen_address.name, - ":5150" - ); + assert_eq!(s.core.network.application.https.listen_address.name, ":443"); assert_eq!( s.core.network.application.https.listen_address.addrs, - listen_address_to_socket_addrs(":5150").unwrap() + listen_address_to_socket_addrs(":443").unwrap() ); assert_eq!( s.core.network.application.https.path, @@ -1661,10 +1658,10 @@ mod tests { ); assert_eq!(s.core.network.application.https.url, None); assert_eq!(s.core.network.application.http.enabled, false); - assert_eq!(s.core.network.application.http.listen_address.name, ":5150"); + assert_eq!(s.core.network.application.http.listen_address.name, ":80"); assert_eq!( s.core.network.application.http.listen_address.addrs, - listen_address_to_socket_addrs(":5150").unwrap() + listen_address_to_socket_addrs(":80").unwrap() ); assert_eq!( s.core.network.application.http.path, @@ -1674,33 +1671,24 @@ mod tests { // assert_eq!(s.core.network.protocol.udp.enabled, true); assert_eq!(s.core.network.protocol.udp.socket_pool_size, 0); - assert_eq!(s.core.network.protocol.udp.listen_address.name, ":5150"); - assert_eq!( - s.core.network.protocol.udp.listen_address.addrs, - listen_address_to_socket_addrs(":5150").unwrap() - ); + assert_eq!(s.core.network.protocol.udp.listen_address.name, ""); + assert_eq!(s.core.network.protocol.udp.listen_address.addrs, vec![]); assert_eq!(s.core.network.protocol.udp.public_address, None); // assert_eq!(s.core.network.protocol.tcp.connect, true); assert_eq!(s.core.network.protocol.tcp.listen, true); assert_eq!(s.core.network.protocol.tcp.max_connections, 32); - assert_eq!(s.core.network.protocol.tcp.listen_address.name, ":5150"); - assert_eq!( - s.core.network.protocol.tcp.listen_address.addrs, - listen_address_to_socket_addrs(":5150").unwrap() - ); + assert_eq!(s.core.network.protocol.tcp.listen_address.name, ""); + assert_eq!(s.core.network.protocol.tcp.listen_address.addrs, vec![]); assert_eq!(s.core.network.protocol.tcp.public_address, None); // assert_eq!(s.core.network.protocol.ws.connect, true); assert_eq!(s.core.network.protocol.ws.listen, true); assert_eq!(s.core.network.protocol.ws.max_connections, 16); - assert_eq!(s.core.network.protocol.ws.listen_address.name, ":5150"); - assert_eq!( - s.core.network.protocol.ws.listen_address.addrs, - listen_address_to_socket_addrs(":5150").unwrap() - ); + assert_eq!(s.core.network.protocol.ws.listen_address.name, ""); + assert_eq!(s.core.network.protocol.ws.listen_address.addrs, vec![]); assert_eq!( s.core.network.protocol.ws.path, std::path::PathBuf::from("ws") @@ -1710,11 +1698,8 @@ mod tests { assert_eq!(s.core.network.protocol.wss.connect, true); assert_eq!(s.core.network.protocol.wss.listen, false); assert_eq!(s.core.network.protocol.wss.max_connections, 16); - assert_eq!(s.core.network.protocol.wss.listen_address.name, ":5150"); - assert_eq!( - s.core.network.protocol.wss.listen_address.addrs, - listen_address_to_socket_addrs(":5150").unwrap() - ); + assert_eq!(s.core.network.protocol.wss.listen_address.name, ""); + assert_eq!(s.core.network.protocol.wss.listen_address.addrs, vec![]); assert_eq!( s.core.network.protocol.wss.path, std::path::PathBuf::from("ws")