From 21564494860dafe39e88ee31d6250dd46df36092 Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Fri, 16 Feb 2024 09:19:26 -0700 Subject: [PATCH] fix missing address range for local --- .../src/network_manager/types/address.rs | 1 + veilid-flutter/lib/veilid_state.dart | 10 +- veilid-flutter/lib/veilid_state.freezed.dart | 218 ++++++++++++++++-- veilid-flutter/lib/veilid_state.g.dart | 147 ++++++++++++ 4 files changed, 349 insertions(+), 27 deletions(-) diff --git a/veilid-core/src/network_manager/types/address.rs b/veilid-core/src/network_manager/types/address.rs index abd1702f..df660960 100644 --- a/veilid-core/src/network_manager/types/address.rs +++ b/veilid-core/src/network_manager/types/address.rs @@ -50,6 +50,7 @@ impl Address { Address::IPV4(v4) => { ipv4addr_is_private(v4) || ipv4addr_is_link_local(v4) + || ipv4addr_is_shared(v4) || ipv4addr_is_ietf_protocol_assignment(v4) } Address::IPV6(v6) => { diff --git a/veilid-flutter/lib/veilid_state.dart b/veilid-flutter/lib/veilid_state.dart index aff63714..9ed85a5d 100644 --- a/veilid-flutter/lib/veilid_state.dart +++ b/veilid-flutter/lib/veilid_state.dart @@ -175,14 +175,8 @@ sealed class VeilidUpdate with _$VeilidUpdate { required ValueData valueData, }) = VeilidUpdateValueChange; - factory VeilidUpdate.fromJson(dynamic json) { - try { - return _$VeilidUpdateFromJson(json as Map); - } catch (e) { - print('VeilidUpdateFromJson failed: $e'); - rethrow; - } - } + factory VeilidUpdate.fromJson(dynamic json) => + _$VeilidUpdateFromJson(json as Map); } ////////////////////////////////////// diff --git a/veilid-flutter/lib/veilid_state.freezed.dart b/veilid-flutter/lib/veilid_state.freezed.dart index 3cccb2b0..4e6e76e3 100644 --- a/veilid-flutter/lib/veilid_state.freezed.dart +++ b/veilid-flutter/lib/veilid_state.freezed.dart @@ -1306,6 +1306,31 @@ abstract class _PeerTableData implements PeerTableData { throw _privateConstructorUsedError; } +VeilidUpdate _$VeilidUpdateFromJson(Map json) { + switch (json['kind']) { + case 'Log': + return VeilidLog.fromJson(json); + case 'AppMessage': + return VeilidAppMessage.fromJson(json); + case 'AppCall': + return VeilidAppCall.fromJson(json); + case 'Attachment': + return VeilidUpdateAttachment.fromJson(json); + case 'Network': + return VeilidUpdateNetwork.fromJson(json); + case 'Config': + return VeilidUpdateConfig.fromJson(json); + case 'RouteChange': + return VeilidUpdateRouteChange.fromJson(json); + case 'ValueChange': + return VeilidUpdateValueChange.fromJson(json); + + default: + throw CheckedFromJsonException(json, 'kind', 'VeilidUpdate', + 'Invalid union type "${json['kind']}"!'); + } +} + /// @nodoc mixin _$VeilidUpdate { @optionalTypeArgs @@ -1422,6 +1447,7 @@ mixin _$VeilidUpdate { required TResult orElse(), }) => throw _privateConstructorUsedError; + Map toJson() => throw _privateConstructorUsedError; } /// @nodoc @@ -1484,10 +1510,17 @@ class __$$VeilidLogImplCopyWithImpl<$Res> } /// @nodoc - +@JsonSerializable() class _$VeilidLogImpl implements VeilidLog { const _$VeilidLogImpl( - {required this.logLevel, required this.message, this.backtrace}); + {required this.logLevel, + required this.message, + this.backtrace, + final String? $type}) + : $type = $type ?? 'Log'; + + factory _$VeilidLogImpl.fromJson(Map json) => + _$$VeilidLogImplFromJson(json); @override final VeilidLogLevel logLevel; @@ -1496,6 +1529,9 @@ class _$VeilidLogImpl implements VeilidLog { @override final String? backtrace; + @JsonKey(name: 'kind') + final String $type; + @override String toString() { return 'VeilidUpdate.log(logLevel: $logLevel, message: $message, backtrace: $backtrace)'; @@ -1513,6 +1549,7 @@ class _$VeilidLogImpl implements VeilidLog { other.backtrace == backtrace)); } + @JsonKey(ignore: true) @override int get hashCode => Object.hash(runtimeType, logLevel, message, backtrace); @@ -1659,6 +1696,13 @@ class _$VeilidLogImpl implements VeilidLog { } return orElse(); } + + @override + Map toJson() { + return _$$VeilidLogImplToJson( + this, + ); + } } abstract class VeilidLog implements VeilidUpdate { @@ -1667,6 +1711,9 @@ abstract class VeilidLog implements VeilidUpdate { required final String message, final String? backtrace}) = _$VeilidLogImpl; + factory VeilidLog.fromJson(Map json) = + _$VeilidLogImpl.fromJson; + VeilidLogLevel get logLevel; String get message; String? get backtrace; @@ -1714,10 +1761,16 @@ class __$$VeilidAppMessageImplCopyWithImpl<$Res> } /// @nodoc - +@JsonSerializable() class _$VeilidAppMessageImpl implements VeilidAppMessage { const _$VeilidAppMessageImpl( - {@Uint8ListJsonConverter() required this.message, this.sender}); + {@Uint8ListJsonConverter() required this.message, + this.sender, + final String? $type}) + : $type = $type ?? 'AppMessage'; + + factory _$VeilidAppMessageImpl.fromJson(Map json) => + _$$VeilidAppMessageImplFromJson(json); @override @Uint8ListJsonConverter() @@ -1725,6 +1778,9 @@ class _$VeilidAppMessageImpl implements VeilidAppMessage { @override final Typed? sender; + @JsonKey(name: 'kind') + final String $type; + @override String toString() { return 'VeilidUpdate.appMessage(message: $message, sender: $sender)'; @@ -1739,6 +1795,7 @@ class _$VeilidAppMessageImpl implements VeilidAppMessage { (identical(other.sender, sender) || other.sender == sender)); } + @JsonKey(ignore: true) @override int get hashCode => Object.hash( runtimeType, const DeepCollectionEquality().hash(message), sender); @@ -1887,6 +1944,13 @@ class _$VeilidAppMessageImpl implements VeilidAppMessage { } return orElse(); } + + @override + Map toJson() { + return _$$VeilidAppMessageImplToJson( + this, + ); + } } abstract class VeilidAppMessage implements VeilidUpdate { @@ -1894,6 +1958,9 @@ abstract class VeilidAppMessage implements VeilidUpdate { {@Uint8ListJsonConverter() required final Uint8List message, final Typed? sender}) = _$VeilidAppMessageImpl; + factory VeilidAppMessage.fromJson(Map json) = + _$VeilidAppMessageImpl.fromJson; + @Uint8ListJsonConverter() Uint8List get message; Typed? get sender; @@ -1947,12 +2014,17 @@ class __$$VeilidAppCallImplCopyWithImpl<$Res> } /// @nodoc - +@JsonSerializable() class _$VeilidAppCallImpl implements VeilidAppCall { const _$VeilidAppCallImpl( {@Uint8ListJsonConverter() required this.message, required this.callId, - this.sender}); + this.sender, + final String? $type}) + : $type = $type ?? 'AppCall'; + + factory _$VeilidAppCallImpl.fromJson(Map json) => + _$$VeilidAppCallImplFromJson(json); @override @Uint8ListJsonConverter() @@ -1962,6 +2034,9 @@ class _$VeilidAppCallImpl implements VeilidAppCall { @override final Typed? sender; + @JsonKey(name: 'kind') + final String $type; + @override String toString() { return 'VeilidUpdate.appCall(message: $message, callId: $callId, sender: $sender)'; @@ -1977,6 +2052,7 @@ class _$VeilidAppCallImpl implements VeilidAppCall { (identical(other.sender, sender) || other.sender == sender)); } + @JsonKey(ignore: true) @override int get hashCode => Object.hash(runtimeType, const DeepCollectionEquality().hash(message), callId, sender); @@ -2124,6 +2200,13 @@ class _$VeilidAppCallImpl implements VeilidAppCall { } return orElse(); } + + @override + Map toJson() { + return _$$VeilidAppCallImplToJson( + this, + ); + } } abstract class VeilidAppCall implements VeilidUpdate { @@ -2132,6 +2215,9 @@ abstract class VeilidAppCall implements VeilidUpdate { required final String callId, final Typed? sender}) = _$VeilidAppCallImpl; + factory VeilidAppCall.fromJson(Map json) = + _$VeilidAppCallImpl.fromJson; + @Uint8ListJsonConverter() Uint8List get message; String get callId; @@ -2188,12 +2274,17 @@ class __$$VeilidUpdateAttachmentImplCopyWithImpl<$Res> } /// @nodoc - +@JsonSerializable() class _$VeilidUpdateAttachmentImpl implements VeilidUpdateAttachment { const _$VeilidUpdateAttachmentImpl( {required this.state, required this.publicInternetReady, - required this.localNetworkReady}); + required this.localNetworkReady, + final String? $type}) + : $type = $type ?? 'Attachment'; + + factory _$VeilidUpdateAttachmentImpl.fromJson(Map json) => + _$$VeilidUpdateAttachmentImplFromJson(json); @override final AttachmentState state; @@ -2202,6 +2293,9 @@ class _$VeilidUpdateAttachmentImpl implements VeilidUpdateAttachment { @override final bool localNetworkReady; + @JsonKey(name: 'kind') + final String $type; + @override String toString() { return 'VeilidUpdate.attachment(state: $state, publicInternetReady: $publicInternetReady, localNetworkReady: $localNetworkReady)'; @@ -2219,6 +2313,7 @@ class _$VeilidUpdateAttachmentImpl implements VeilidUpdateAttachment { other.localNetworkReady == localNetworkReady)); } + @JsonKey(ignore: true) @override int get hashCode => Object.hash(runtimeType, state, publicInternetReady, localNetworkReady); @@ -2367,6 +2462,13 @@ class _$VeilidUpdateAttachmentImpl implements VeilidUpdateAttachment { } return orElse(); } + + @override + Map toJson() { + return _$$VeilidUpdateAttachmentImplToJson( + this, + ); + } } abstract class VeilidUpdateAttachment implements VeilidUpdate { @@ -2375,6 +2477,9 @@ abstract class VeilidUpdateAttachment implements VeilidUpdate { required final bool publicInternetReady, required final bool localNetworkReady}) = _$VeilidUpdateAttachmentImpl; + factory VeilidUpdateAttachment.fromJson(Map json) = + _$VeilidUpdateAttachmentImpl.fromJson; + AttachmentState get state; bool get publicInternetReady; bool get localNetworkReady; @@ -2431,14 +2536,19 @@ class __$$VeilidUpdateNetworkImplCopyWithImpl<$Res> } /// @nodoc - +@JsonSerializable() class _$VeilidUpdateNetworkImpl implements VeilidUpdateNetwork { const _$VeilidUpdateNetworkImpl( {required this.started, required this.bpsDown, required this.bpsUp, - required final List peers}) - : _peers = peers; + required final List peers, + final String? $type}) + : _peers = peers, + $type = $type ?? 'Network'; + + factory _$VeilidUpdateNetworkImpl.fromJson(Map json) => + _$$VeilidUpdateNetworkImplFromJson(json); @override final bool started; @@ -2454,6 +2564,9 @@ class _$VeilidUpdateNetworkImpl implements VeilidUpdateNetwork { return EqualUnmodifiableListView(_peers); } + @JsonKey(name: 'kind') + final String $type; + @override String toString() { return 'VeilidUpdate.network(started: $started, bpsDown: $bpsDown, bpsUp: $bpsUp, peers: $peers)'; @@ -2470,6 +2583,7 @@ class _$VeilidUpdateNetworkImpl implements VeilidUpdateNetwork { const DeepCollectionEquality().equals(other._peers, _peers)); } + @JsonKey(ignore: true) @override int get hashCode => Object.hash(runtimeType, started, bpsDown, bpsUp, const DeepCollectionEquality().hash(_peers)); @@ -2618,6 +2732,13 @@ class _$VeilidUpdateNetworkImpl implements VeilidUpdateNetwork { } return orElse(); } + + @override + Map toJson() { + return _$$VeilidUpdateNetworkImplToJson( + this, + ); + } } abstract class VeilidUpdateNetwork implements VeilidUpdate { @@ -2627,6 +2748,9 @@ abstract class VeilidUpdateNetwork implements VeilidUpdate { required final BigInt bpsUp, required final List peers}) = _$VeilidUpdateNetworkImpl; + factory VeilidUpdateNetwork.fromJson(Map json) = + _$VeilidUpdateNetworkImpl.fromJson; + bool get started; BigInt get bpsDown; BigInt get bpsUp; @@ -2678,13 +2802,20 @@ class __$$VeilidUpdateConfigImplCopyWithImpl<$Res> } /// @nodoc - +@JsonSerializable() class _$VeilidUpdateConfigImpl implements VeilidUpdateConfig { - const _$VeilidUpdateConfigImpl({required this.config}); + const _$VeilidUpdateConfigImpl({required this.config, final String? $type}) + : $type = $type ?? 'Config'; + + factory _$VeilidUpdateConfigImpl.fromJson(Map json) => + _$$VeilidUpdateConfigImplFromJson(json); @override final VeilidConfig config; + @JsonKey(name: 'kind') + final String $type; + @override String toString() { return 'VeilidUpdate.config(config: $config)'; @@ -2698,6 +2829,7 @@ class _$VeilidUpdateConfigImpl implements VeilidUpdateConfig { (identical(other.config, config) || other.config == config)); } + @JsonKey(ignore: true) @override int get hashCode => Object.hash(runtimeType, config); @@ -2845,12 +2977,22 @@ class _$VeilidUpdateConfigImpl implements VeilidUpdateConfig { } return orElse(); } + + @override + Map toJson() { + return _$$VeilidUpdateConfigImplToJson( + this, + ); + } } abstract class VeilidUpdateConfig implements VeilidUpdate { const factory VeilidUpdateConfig({required final VeilidConfig config}) = _$VeilidUpdateConfigImpl; + factory VeilidUpdateConfig.fromJson(Map json) = + _$VeilidUpdateConfigImpl.fromJson; + VeilidConfig get config; @JsonKey(ignore: true) _$$VeilidUpdateConfigImplCopyWith<_$VeilidUpdateConfigImpl> get copyWith => @@ -2896,13 +3038,18 @@ class __$$VeilidUpdateRouteChangeImplCopyWithImpl<$Res> } /// @nodoc - +@JsonSerializable() class _$VeilidUpdateRouteChangeImpl implements VeilidUpdateRouteChange { const _$VeilidUpdateRouteChangeImpl( {required final List deadRoutes, - required final List deadRemoteRoutes}) + required final List deadRemoteRoutes, + final String? $type}) : _deadRoutes = deadRoutes, - _deadRemoteRoutes = deadRemoteRoutes; + _deadRemoteRoutes = deadRemoteRoutes, + $type = $type ?? 'RouteChange'; + + factory _$VeilidUpdateRouteChangeImpl.fromJson(Map json) => + _$$VeilidUpdateRouteChangeImplFromJson(json); final List _deadRoutes; @override @@ -2921,6 +3068,9 @@ class _$VeilidUpdateRouteChangeImpl implements VeilidUpdateRouteChange { return EqualUnmodifiableListView(_deadRemoteRoutes); } + @JsonKey(name: 'kind') + final String $type; + @override String toString() { return 'VeilidUpdate.routeChange(deadRoutes: $deadRoutes, deadRemoteRoutes: $deadRemoteRoutes)'; @@ -2937,6 +3087,7 @@ class _$VeilidUpdateRouteChangeImpl implements VeilidUpdateRouteChange { .equals(other._deadRemoteRoutes, _deadRemoteRoutes)); } + @JsonKey(ignore: true) @override int get hashCode => Object.hash( runtimeType, @@ -3087,6 +3238,13 @@ class _$VeilidUpdateRouteChangeImpl implements VeilidUpdateRouteChange { } return orElse(); } + + @override + Map toJson() { + return _$$VeilidUpdateRouteChangeImplToJson( + this, + ); + } } abstract class VeilidUpdateRouteChange implements VeilidUpdate { @@ -3095,6 +3253,9 @@ abstract class VeilidUpdateRouteChange implements VeilidUpdate { required final List deadRemoteRoutes}) = _$VeilidUpdateRouteChangeImpl; + factory VeilidUpdateRouteChange.fromJson(Map json) = + _$VeilidUpdateRouteChangeImpl.fromJson; + List get deadRoutes; List get deadRemoteRoutes; @JsonKey(ignore: true) @@ -3165,14 +3326,19 @@ class __$$VeilidUpdateValueChangeImplCopyWithImpl<$Res> } /// @nodoc - +@JsonSerializable() class _$VeilidUpdateValueChangeImpl implements VeilidUpdateValueChange { const _$VeilidUpdateValueChangeImpl( {required this.key, required final List subkeys, required this.count, - required this.valueData}) - : _subkeys = subkeys; + required this.valueData, + final String? $type}) + : _subkeys = subkeys, + $type = $type ?? 'ValueChange'; + + factory _$VeilidUpdateValueChangeImpl.fromJson(Map json) => + _$$VeilidUpdateValueChangeImplFromJson(json); @override final Typed key; @@ -3189,6 +3355,9 @@ class _$VeilidUpdateValueChangeImpl implements VeilidUpdateValueChange { @override final ValueData valueData; + @JsonKey(name: 'kind') + final String $type; + @override String toString() { return 'VeilidUpdate.valueChange(key: $key, subkeys: $subkeys, count: $count, valueData: $valueData)'; @@ -3206,6 +3375,7 @@ class _$VeilidUpdateValueChangeImpl implements VeilidUpdateValueChange { other.valueData == valueData)); } + @JsonKey(ignore: true) @override int get hashCode => Object.hash(runtimeType, key, const DeepCollectionEquality().hash(_subkeys), count, valueData); @@ -3354,6 +3524,13 @@ class _$VeilidUpdateValueChangeImpl implements VeilidUpdateValueChange { } return orElse(); } + + @override + Map toJson() { + return _$$VeilidUpdateValueChangeImplToJson( + this, + ); + } } abstract class VeilidUpdateValueChange implements VeilidUpdate { @@ -3363,6 +3540,9 @@ abstract class VeilidUpdateValueChange implements VeilidUpdate { required final int count, required final ValueData valueData}) = _$VeilidUpdateValueChangeImpl; + factory VeilidUpdateValueChange.fromJson(Map json) = + _$VeilidUpdateValueChangeImpl.fromJson; + Typed get key; List get subkeys; int get count; diff --git a/veilid-flutter/lib/veilid_state.g.dart b/veilid-flutter/lib/veilid_state.g.dart index 02fcd499..6cc9fcfb 100644 --- a/veilid-flutter/lib/veilid_state.g.dart +++ b/veilid-flutter/lib/veilid_state.g.dart @@ -114,6 +114,153 @@ Map _$$PeerTableDataImplToJson(_$PeerTableDataImpl instance) => 'peer_stats': instance.peerStats.toJson(), }; +_$VeilidLogImpl _$$VeilidLogImplFromJson(Map json) => + _$VeilidLogImpl( + logLevel: VeilidLogLevel.fromJson(json['log_level']), + message: json['message'] as String, + backtrace: json['backtrace'] as String?, + $type: json['kind'] as String?, + ); + +Map _$$VeilidLogImplToJson(_$VeilidLogImpl instance) => + { + 'log_level': instance.logLevel.toJson(), + 'message': instance.message, + 'backtrace': instance.backtrace, + 'kind': instance.$type, + }; + +_$VeilidAppMessageImpl _$$VeilidAppMessageImplFromJson( + Map json) => + _$VeilidAppMessageImpl( + message: const Uint8ListJsonConverter().fromJson(json['message']), + sender: json['sender'] == null + ? null + : Typed.fromJson(json['sender']), + $type: json['kind'] as String?, + ); + +Map _$$VeilidAppMessageImplToJson( + _$VeilidAppMessageImpl instance) => + { + 'message': const Uint8ListJsonConverter().toJson(instance.message), + 'sender': instance.sender?.toJson(), + 'kind': instance.$type, + }; + +_$VeilidAppCallImpl _$$VeilidAppCallImplFromJson(Map json) => + _$VeilidAppCallImpl( + message: const Uint8ListJsonConverter().fromJson(json['message']), + callId: json['call_id'] as String, + sender: json['sender'] == null + ? null + : Typed.fromJson(json['sender']), + $type: json['kind'] as String?, + ); + +Map _$$VeilidAppCallImplToJson(_$VeilidAppCallImpl instance) => + { + 'message': const Uint8ListJsonConverter().toJson(instance.message), + 'call_id': instance.callId, + 'sender': instance.sender?.toJson(), + 'kind': instance.$type, + }; + +_$VeilidUpdateAttachmentImpl _$$VeilidUpdateAttachmentImplFromJson( + Map json) => + _$VeilidUpdateAttachmentImpl( + state: AttachmentState.fromJson(json['state']), + publicInternetReady: json['public_internet_ready'] as bool, + localNetworkReady: json['local_network_ready'] as bool, + $type: json['kind'] as String?, + ); + +Map _$$VeilidUpdateAttachmentImplToJson( + _$VeilidUpdateAttachmentImpl instance) => + { + 'state': instance.state.toJson(), + 'public_internet_ready': instance.publicInternetReady, + 'local_network_ready': instance.localNetworkReady, + 'kind': instance.$type, + }; + +_$VeilidUpdateNetworkImpl _$$VeilidUpdateNetworkImplFromJson( + Map json) => + _$VeilidUpdateNetworkImpl( + 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(PeerTableData.fromJson).toList(), + $type: json['kind'] as String?, + ); + +Map _$$VeilidUpdateNetworkImplToJson( + _$VeilidUpdateNetworkImpl instance) => + { + 'started': instance.started, + 'bps_down': instance.bpsDown.toString(), + 'bps_up': instance.bpsUp.toString(), + 'peers': instance.peers.map((e) => e.toJson()).toList(), + 'kind': instance.$type, + }; + +_$VeilidUpdateConfigImpl _$$VeilidUpdateConfigImplFromJson( + Map json) => + _$VeilidUpdateConfigImpl( + config: VeilidConfig.fromJson(json['config']), + $type: json['kind'] as String?, + ); + +Map _$$VeilidUpdateConfigImplToJson( + _$VeilidUpdateConfigImpl instance) => + { + 'config': instance.config.toJson(), + 'kind': instance.$type, + }; + +_$VeilidUpdateRouteChangeImpl _$$VeilidUpdateRouteChangeImplFromJson( + Map json) => + _$VeilidUpdateRouteChangeImpl( + deadRoutes: (json['dead_routes'] as List) + .map((e) => e as String) + .toList(), + deadRemoteRoutes: (json['dead_remote_routes'] as List) + .map((e) => e as String) + .toList(), + $type: json['kind'] as String?, + ); + +Map _$$VeilidUpdateRouteChangeImplToJson( + _$VeilidUpdateRouteChangeImpl instance) => + { + 'dead_routes': instance.deadRoutes, + 'dead_remote_routes': instance.deadRemoteRoutes, + 'kind': instance.$type, + }; + +_$VeilidUpdateValueChangeImpl _$$VeilidUpdateValueChangeImplFromJson( + Map json) => + _$VeilidUpdateValueChangeImpl( + key: Typed.fromJson(json['key']), + subkeys: (json['subkeys'] as List) + .map(ValueSubkeyRange.fromJson) + .toList(), + count: json['count'] as int, + valueData: ValueData.fromJson(json['value_data']), + $type: json['kind'] as String?, + ); + +Map _$$VeilidUpdateValueChangeImplToJson( + _$VeilidUpdateValueChangeImpl instance) => + { + 'key': instance.key.toJson(), + 'subkeys': instance.subkeys.map((e) => e.toJson()).toList(), + 'count': instance.count, + 'value_data': instance.valueData.toJson(), + 'kind': instance.$type, + }; + _$VeilidStateAttachmentImpl _$$VeilidStateAttachmentImplFromJson( Map json) => _$VeilidStateAttachmentImpl(