bugfixes
This commit is contained in:
parent
a6666d3a6c
commit
00aad2c728
@ -380,7 +380,7 @@ impl StorageManager {
|
|||||||
|
|
||||||
// Add to offline writes to flush
|
// 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.insert(subkey); } ).or_insert(ValueSubkeyRangeSet::single(subkey));
|
||||||
return Ok(Some(signed_value_data.into_value_data()))
|
return Ok(None)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Drop the lock for network access
|
// Drop the lock for network access
|
||||||
@ -393,7 +393,7 @@ impl StorageManager {
|
|||||||
key,
|
key,
|
||||||
subkey,
|
subkey,
|
||||||
safety_selection,
|
safety_selection,
|
||||||
signed_value_data,
|
signed_value_data.clone(),
|
||||||
descriptor,
|
descriptor,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@ -404,7 +404,13 @@ impl StorageManager {
|
|||||||
.handle_set_local_value(key, subkey, final_signed_value_data.clone())
|
.handle_set_local_value(key, subkey, final_signed_value_data.clone())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(Some(final_signed_value_data.into_value_data()))
|
// Return the new value if it differs from what was asked to set
|
||||||
|
if final_signed_value_data.value_data() != signed_value_data.value_data() {
|
||||||
|
return Ok(Some(final_signed_value_data.into_value_data()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the original value was set, return None
|
||||||
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn watch_values(
|
pub async fn watch_values(
|
||||||
|
@ -5,7 +5,6 @@ import 'package:change_case/change_case.dart';
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||||
|
|
||||||
import 'veilid_encoding.dart';
|
|
||||||
import 'veilid.dart';
|
import 'veilid.dart';
|
||||||
|
|
||||||
part 'routing_context.freezed.dart';
|
part 'routing_context.freezed.dart';
|
||||||
@ -51,8 +50,8 @@ sealed class DHTSchema with _$DHTSchema {
|
|||||||
{required int oCnt,
|
{required int oCnt,
|
||||||
required List<DHTSchemaMember> members}) = DHTSchemaSMPL;
|
required List<DHTSchemaMember> members}) = DHTSchemaSMPL;
|
||||||
|
|
||||||
factory DHTSchema.fromJson(Map<String, dynamic> json) =>
|
factory DHTSchema.fromJson(dynamic json) =>
|
||||||
_$DHTSchemaFromJson(json);
|
_$DHTSchemaFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
const DHTSchema defaultDHTSchema = DHTSchema.dflt(oCnt: 1);
|
const DHTSchema defaultDHTSchema = DHTSchema.dflt(oCnt: 1);
|
||||||
@ -65,8 +64,8 @@ class DHTSchemaMember with _$DHTSchemaMember {
|
|||||||
required int mCnt,
|
required int mCnt,
|
||||||
}) = _DHTSchemaMember;
|
}) = _DHTSchemaMember;
|
||||||
|
|
||||||
factory DHTSchemaMember.fromJson(Map<String, dynamic> json) =>
|
factory DHTSchemaMember.fromJson(dynamic json) =>
|
||||||
_$DHTSchemaMemberFromJson(json);
|
_$DHTSchemaMemberFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
@ -80,8 +79,8 @@ class DHTRecordDescriptor with _$DHTRecordDescriptor {
|
|||||||
PublicKey? ownerSecret,
|
PublicKey? ownerSecret,
|
||||||
required DHTSchema schema,
|
required DHTSchema schema,
|
||||||
}) = _DHTRecordDescriptor;
|
}) = _DHTRecordDescriptor;
|
||||||
factory DHTRecordDescriptor.fromJson(Map<String, dynamic> json) =>
|
factory DHTRecordDescriptor.fromJson(dynamic json) =>
|
||||||
_$DHTRecordDescriptorFromJson(json);
|
_$DHTRecordDescriptorFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
extension DHTRecordDescriptorExt on DHTRecordDescriptor {
|
extension DHTRecordDescriptorExt on DHTRecordDescriptor {
|
||||||
@ -112,8 +111,8 @@ class ValueSubkeyRange with _$ValueSubkeyRange {
|
|||||||
required int high,
|
required int high,
|
||||||
}) = _ValueSubkeyRange;
|
}) = _ValueSubkeyRange;
|
||||||
|
|
||||||
factory ValueSubkeyRange.fromJson(Map<String, dynamic> json) =>
|
factory ValueSubkeyRange.fromJson(dynamic json) =>
|
||||||
_$ValueSubkeyRangeFromJson(json);
|
_$ValueSubkeyRangeFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
@ -128,8 +127,8 @@ class ValueData with _$ValueData {
|
|||||||
required PublicKey writer,
|
required PublicKey writer,
|
||||||
}) = _ValueData;
|
}) = _ValueData;
|
||||||
|
|
||||||
factory ValueData.fromJson(Map<String, dynamic> json) =>
|
factory ValueData.fromJson(dynamic json) =>
|
||||||
_$ValueDataFromJson(json);
|
_$ValueDataFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
@ -140,8 +139,8 @@ enum Stability {
|
|||||||
reliable;
|
reliable;
|
||||||
|
|
||||||
String toJson() => name.toPascalCase();
|
String toJson() => name.toPascalCase();
|
||||||
factory Stability.fromJson(String j) =>
|
factory Stability.fromJson(dynamic j) =>
|
||||||
Stability.values.byName(j.toCamelCase());
|
Stability.values.byName((j as String).toCamelCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
@ -153,8 +152,8 @@ enum Sequencing {
|
|||||||
ensureOrdered;
|
ensureOrdered;
|
||||||
|
|
||||||
String toJson() => name.toPascalCase();
|
String toJson() => name.toPascalCase();
|
||||||
factory Sequencing.fromJson(String j) =>
|
factory Sequencing.fromJson(dynamic j) =>
|
||||||
Sequencing.values.byName(j.toCamelCase());
|
Sequencing.values.byName((j as String).toCamelCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
@ -162,7 +161,8 @@ enum Sequencing {
|
|||||||
|
|
||||||
@immutable
|
@immutable
|
||||||
abstract class SafetySelection extends Equatable {
|
abstract class SafetySelection extends Equatable {
|
||||||
factory SafetySelection.fromJson(Map<String, dynamic> json) {
|
factory SafetySelection.fromJson(dynamic jsond) {
|
||||||
|
final json = jsond as Map<String, dynamic>;
|
||||||
if (json.containsKey("Unsafe")) {
|
if (json.containsKey("Unsafe")) {
|
||||||
return SafetySelectionUnsafe(
|
return SafetySelectionUnsafe(
|
||||||
sequencing: Sequencing.fromJson(json["Unsafe"]));
|
sequencing: Sequencing.fromJson(json["Unsafe"]));
|
||||||
@ -223,8 +223,8 @@ class SafetySpec with _$SafetySpec {
|
|||||||
required Sequencing sequencing,
|
required Sequencing sequencing,
|
||||||
}) = _SafetySpec;
|
}) = _SafetySpec;
|
||||||
|
|
||||||
factory SafetySpec.fromJson(Map<String, dynamic> json) =>
|
factory SafetySpec.fromJson(dynamic json) =>
|
||||||
_$SafetySpecFromJson(json);
|
_$SafetySpecFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
@ -234,8 +234,8 @@ class RouteBlob with _$RouteBlob {
|
|||||||
const factory RouteBlob(
|
const factory RouteBlob(
|
||||||
{required String routeId,
|
{required String routeId,
|
||||||
@Uint8ListJsonConverter() required Uint8List blob}) = _RouteBlob;
|
@Uint8ListJsonConverter() required Uint8List blob}) = _RouteBlob;
|
||||||
factory RouteBlob.fromJson(Map<String, dynamic> json) =>
|
factory RouteBlob.fromJson(dynamic json) =>
|
||||||
_$RouteBlobFromJson(json);
|
_$RouteBlobFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
|
@ -156,7 +156,7 @@ abstract class Veilid {
|
|||||||
Future<void> releasePrivateRoute(String key);
|
Future<void> releasePrivateRoute(String key);
|
||||||
|
|
||||||
// App calls
|
// App calls
|
||||||
Future<void> appCallReply(String id, Uint8List message);
|
Future<void> appCallReply(String callId, Uint8List message);
|
||||||
|
|
||||||
// TableStore
|
// TableStore
|
||||||
Future<VeilidTableDB> openTableDB(String name, int columnCount);
|
Future<VeilidTableDB> openTableDB(String name, int columnCount);
|
||||||
|
@ -17,8 +17,8 @@ class VeilidFFIConfigLoggingTerminal with _$VeilidFFIConfigLoggingTerminal {
|
|||||||
required VeilidConfigLogLevel level,
|
required VeilidConfigLogLevel level,
|
||||||
}) = _VeilidFFIConfigLoggingTerminal;
|
}) = _VeilidFFIConfigLoggingTerminal;
|
||||||
|
|
||||||
factory VeilidFFIConfigLoggingTerminal.fromJson(Map<String, dynamic> json) =>
|
factory VeilidFFIConfigLoggingTerminal.fromJson(dynamic json) =>
|
||||||
_$VeilidFFIConfigLoggingTerminalFromJson(json);
|
_$VeilidFFIConfigLoggingTerminalFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
@freezed
|
@freezed
|
||||||
@ -30,8 +30,8 @@ class VeilidFFIConfigLoggingOtlp with _$VeilidFFIConfigLoggingOtlp {
|
|||||||
required String serviceName,
|
required String serviceName,
|
||||||
}) = _VeilidFFIConfigLoggingOtlp;
|
}) = _VeilidFFIConfigLoggingOtlp;
|
||||||
|
|
||||||
factory VeilidFFIConfigLoggingOtlp.fromJson(Map<String, dynamic> json) =>
|
factory VeilidFFIConfigLoggingOtlp.fromJson(dynamic json) =>
|
||||||
_$VeilidFFIConfigLoggingOtlpFromJson(json);
|
_$VeilidFFIConfigLoggingOtlpFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
@freezed
|
@freezed
|
||||||
@ -41,8 +41,8 @@ class VeilidFFIConfigLoggingApi with _$VeilidFFIConfigLoggingApi {
|
|||||||
required VeilidConfigLogLevel level,
|
required VeilidConfigLogLevel level,
|
||||||
}) = _VeilidFFIConfigLoggingApi;
|
}) = _VeilidFFIConfigLoggingApi;
|
||||||
|
|
||||||
factory VeilidFFIConfigLoggingApi.fromJson(Map<String, dynamic> json) =>
|
factory VeilidFFIConfigLoggingApi.fromJson(dynamic json) =>
|
||||||
_$VeilidFFIConfigLoggingApiFromJson(json);
|
_$VeilidFFIConfigLoggingApiFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
@freezed
|
@freezed
|
||||||
@ -52,8 +52,8 @@ class VeilidFFIConfigLogging with _$VeilidFFIConfigLogging {
|
|||||||
required VeilidFFIConfigLoggingOtlp otlp,
|
required VeilidFFIConfigLoggingOtlp otlp,
|
||||||
required VeilidFFIConfigLoggingApi api}) = _VeilidFFIConfigLogging;
|
required VeilidFFIConfigLoggingApi api}) = _VeilidFFIConfigLogging;
|
||||||
|
|
||||||
factory VeilidFFIConfigLogging.fromJson(Map<String, dynamic> json) =>
|
factory VeilidFFIConfigLogging.fromJson(dynamic json) =>
|
||||||
_$VeilidFFIConfigLoggingFromJson(json);
|
_$VeilidFFIConfigLoggingFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
@freezed
|
@freezed
|
||||||
@ -62,8 +62,8 @@ class VeilidFFIConfig with _$VeilidFFIConfig {
|
|||||||
required VeilidFFIConfigLogging logging,
|
required VeilidFFIConfigLogging logging,
|
||||||
}) = _VeilidFFIConfig;
|
}) = _VeilidFFIConfig;
|
||||||
|
|
||||||
factory VeilidFFIConfig.fromJson(Map<String, dynamic> json) =>
|
factory VeilidFFIConfig.fromJson(dynamic json) =>
|
||||||
_$VeilidFFIConfigFromJson(json);
|
_$VeilidFFIConfigFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////
|
||||||
@ -79,9 +79,9 @@ class VeilidWASMConfigLoggingPerformance
|
|||||||
required bool logsInConsole,
|
required bool logsInConsole,
|
||||||
}) = _VeilidWASMConfigLoggingPerformance;
|
}) = _VeilidWASMConfigLoggingPerformance;
|
||||||
|
|
||||||
factory VeilidWASMConfigLoggingPerformance.fromJson(
|
factory VeilidWASMConfigLoggingPerformance.fromJson(dynamic json) =>
|
||||||
Map<String, dynamic> json) =>
|
_$VeilidWASMConfigLoggingPerformanceFromJson(
|
||||||
_$VeilidWASMConfigLoggingPerformanceFromJson(json);
|
json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
@freezed
|
@freezed
|
||||||
@ -91,8 +91,8 @@ class VeilidWASMConfigLoggingApi with _$VeilidWASMConfigLoggingApi {
|
|||||||
required VeilidConfigLogLevel level,
|
required VeilidConfigLogLevel level,
|
||||||
}) = _VeilidWASMConfigLoggingApi;
|
}) = _VeilidWASMConfigLoggingApi;
|
||||||
|
|
||||||
factory VeilidWASMConfigLoggingApi.fromJson(Map<String, dynamic> json) =>
|
factory VeilidWASMConfigLoggingApi.fromJson(dynamic json) =>
|
||||||
_$VeilidWASMConfigLoggingApiFromJson(json);
|
_$VeilidWASMConfigLoggingApiFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
@freezed
|
@freezed
|
||||||
@ -101,8 +101,8 @@ class VeilidWASMConfigLogging with _$VeilidWASMConfigLogging {
|
|||||||
{required VeilidWASMConfigLoggingPerformance performance,
|
{required VeilidWASMConfigLoggingPerformance performance,
|
||||||
required VeilidWASMConfigLoggingApi api}) = _VeilidWASMConfigLogging;
|
required VeilidWASMConfigLoggingApi api}) = _VeilidWASMConfigLogging;
|
||||||
|
|
||||||
factory VeilidWASMConfigLogging.fromJson(Map<String, dynamic> json) =>
|
factory VeilidWASMConfigLogging.fromJson(dynamic json) =>
|
||||||
_$VeilidWASMConfigLoggingFromJson(json);
|
_$VeilidWASMConfigLoggingFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
@freezed
|
@freezed
|
||||||
@ -111,8 +111,8 @@ class VeilidWASMConfig with _$VeilidWASMConfig {
|
|||||||
required VeilidWASMConfigLogging logging,
|
required VeilidWASMConfigLogging logging,
|
||||||
}) = _VeilidWASMConfig;
|
}) = _VeilidWASMConfig;
|
||||||
|
|
||||||
factory VeilidWASMConfig.fromJson(Map<String, dynamic> json) =>
|
factory VeilidWASMConfig.fromJson(dynamic json) =>
|
||||||
_$VeilidWASMConfigFromJson(json);
|
_$VeilidWASMConfigFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
@ -147,8 +147,8 @@ class VeilidConfigHTTPS with _$VeilidConfigHTTPS {
|
|||||||
String? url,
|
String? url,
|
||||||
}) = _VeilidConfigHTTPS;
|
}) = _VeilidConfigHTTPS;
|
||||||
|
|
||||||
factory VeilidConfigHTTPS.fromJson(Map<String, dynamic> json) =>
|
factory VeilidConfigHTTPS.fromJson(dynamic json) =>
|
||||||
_$VeilidConfigHTTPSFromJson(json);
|
_$VeilidConfigHTTPSFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
@ -162,8 +162,8 @@ class VeilidConfigHTTP with _$VeilidConfigHTTP {
|
|||||||
String? url,
|
String? url,
|
||||||
}) = _VeilidConfigHTTP;
|
}) = _VeilidConfigHTTP;
|
||||||
|
|
||||||
factory VeilidConfigHTTP.fromJson(Map<String, dynamic> json) =>
|
factory VeilidConfigHTTP.fromJson(dynamic json) =>
|
||||||
_$VeilidConfigHTTPFromJson(json);
|
_$VeilidConfigHTTPFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
@ -175,8 +175,8 @@ class VeilidConfigApplication with _$VeilidConfigApplication {
|
|||||||
required VeilidConfigHTTP http,
|
required VeilidConfigHTTP http,
|
||||||
}) = _VeilidConfigApplication;
|
}) = _VeilidConfigApplication;
|
||||||
|
|
||||||
factory VeilidConfigApplication.fromJson(Map<String, dynamic> json) =>
|
factory VeilidConfigApplication.fromJson(dynamic json) =>
|
||||||
_$VeilidConfigApplicationFromJson(json);
|
_$VeilidConfigApplicationFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
@ -188,8 +188,8 @@ class VeilidConfigUDP with _$VeilidConfigUDP {
|
|||||||
required String listenAddress,
|
required String listenAddress,
|
||||||
String? publicAddress}) = _VeilidConfigUDP;
|
String? publicAddress}) = _VeilidConfigUDP;
|
||||||
|
|
||||||
factory VeilidConfigUDP.fromJson(Map<String, dynamic> json) =>
|
factory VeilidConfigUDP.fromJson(dynamic json) =>
|
||||||
_$VeilidConfigUDPFromJson(json);
|
_$VeilidConfigUDPFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
@ -202,8 +202,8 @@ class VeilidConfigTCP with _$VeilidConfigTCP {
|
|||||||
required String listenAddress,
|
required String listenAddress,
|
||||||
String? publicAddress}) = _VeilidConfigTCP;
|
String? publicAddress}) = _VeilidConfigTCP;
|
||||||
|
|
||||||
factory VeilidConfigTCP.fromJson(Map<String, dynamic> json) =>
|
factory VeilidConfigTCP.fromJson(dynamic json) =>
|
||||||
_$VeilidConfigTCPFromJson(json);
|
_$VeilidConfigTCPFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
@ -217,8 +217,8 @@ class VeilidConfigWS with _$VeilidConfigWS {
|
|||||||
required String path,
|
required String path,
|
||||||
String? url}) = _VeilidConfigWS;
|
String? url}) = _VeilidConfigWS;
|
||||||
|
|
||||||
factory VeilidConfigWS.fromJson(Map<String, dynamic> json) =>
|
factory VeilidConfigWS.fromJson(dynamic json) =>
|
||||||
_$VeilidConfigWSFromJson(json);
|
_$VeilidConfigWSFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
@ -232,8 +232,8 @@ class VeilidConfigWSS with _$VeilidConfigWSS {
|
|||||||
required String path,
|
required String path,
|
||||||
String? url}) = _VeilidConfigWSS;
|
String? url}) = _VeilidConfigWSS;
|
||||||
|
|
||||||
factory VeilidConfigWSS.fromJson(Map<String, dynamic> json) =>
|
factory VeilidConfigWSS.fromJson(dynamic json) =>
|
||||||
_$VeilidConfigWSSFromJson(json);
|
_$VeilidConfigWSSFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
@ -247,8 +247,8 @@ class VeilidConfigProtocol with _$VeilidConfigProtocol {
|
|||||||
required VeilidConfigWSS wss,
|
required VeilidConfigWSS wss,
|
||||||
}) = _VeilidConfigProtocol;
|
}) = _VeilidConfigProtocol;
|
||||||
|
|
||||||
factory VeilidConfigProtocol.fromJson(Map<String, dynamic> json) =>
|
factory VeilidConfigProtocol.fromJson(dynamic json) =>
|
||||||
_$VeilidConfigProtocolFromJson(json);
|
_$VeilidConfigProtocolFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
@ -261,8 +261,8 @@ class VeilidConfigTLS with _$VeilidConfigTLS {
|
|||||||
required int connectionInitialTimeoutMs,
|
required int connectionInitialTimeoutMs,
|
||||||
}) = _VeilidConfigTLS;
|
}) = _VeilidConfigTLS;
|
||||||
|
|
||||||
factory VeilidConfigTLS.fromJson(Map<String, dynamic> json) =>
|
factory VeilidConfigTLS.fromJson(dynamic json) =>
|
||||||
_$VeilidConfigTLSFromJson(json);
|
_$VeilidConfigTLSFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
@ -289,8 +289,8 @@ class VeilidConfigDHT with _$VeilidConfigDHT {
|
|||||||
required int remoteMaxSubkeyCacheMemoryMb,
|
required int remoteMaxSubkeyCacheMemoryMb,
|
||||||
required int remoteMaxStorageSpaceMb}) = _VeilidConfigDHT;
|
required int remoteMaxStorageSpaceMb}) = _VeilidConfigDHT;
|
||||||
|
|
||||||
factory VeilidConfigDHT.fromJson(Map<String, dynamic> json) =>
|
factory VeilidConfigDHT.fromJson(dynamic json) =>
|
||||||
_$VeilidConfigDHTFromJson(json);
|
_$VeilidConfigDHTFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
@ -306,8 +306,8 @@ class VeilidConfigRPC with _$VeilidConfigRPC {
|
|||||||
required int maxRouteHopCount,
|
required int maxRouteHopCount,
|
||||||
required int defaultRouteHopCount}) = _VeilidConfigRPC;
|
required int defaultRouteHopCount}) = _VeilidConfigRPC;
|
||||||
|
|
||||||
factory VeilidConfigRPC.fromJson(Map<String, dynamic> json) =>
|
factory VeilidConfigRPC.fromJson(dynamic json) =>
|
||||||
_$VeilidConfigRPCFromJson(json);
|
_$VeilidConfigRPCFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
@ -325,8 +325,8 @@ class VeilidConfigRoutingTable with _$VeilidConfigRoutingTable {
|
|||||||
required int limitAttachedWeak,
|
required int limitAttachedWeak,
|
||||||
}) = _VeilidConfigRoutingTable;
|
}) = _VeilidConfigRoutingTable;
|
||||||
|
|
||||||
factory VeilidConfigRoutingTable.fromJson(Map<String, dynamic> json) =>
|
factory VeilidConfigRoutingTable.fromJson(dynamic json) =>
|
||||||
_$VeilidConfigRoutingTableFromJson(json);
|
_$VeilidConfigRoutingTableFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
@ -355,8 +355,8 @@ class VeilidConfigNetwork with _$VeilidConfigNetwork {
|
|||||||
required VeilidConfigProtocol protocol,
|
required VeilidConfigProtocol protocol,
|
||||||
}) = _VeilidConfigNetwork;
|
}) = _VeilidConfigNetwork;
|
||||||
|
|
||||||
factory VeilidConfigNetwork.fromJson(Map<String, dynamic> json) =>
|
factory VeilidConfigNetwork.fromJson(dynamic json) =>
|
||||||
_$VeilidConfigNetworkFromJson(json);
|
_$VeilidConfigNetworkFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
@ -368,8 +368,8 @@ class VeilidConfigTableStore with _$VeilidConfigTableStore {
|
|||||||
required bool delete,
|
required bool delete,
|
||||||
}) = _VeilidConfigTableStore;
|
}) = _VeilidConfigTableStore;
|
||||||
|
|
||||||
factory VeilidConfigTableStore.fromJson(Map<String, dynamic> json) =>
|
factory VeilidConfigTableStore.fromJson(dynamic json) =>
|
||||||
_$VeilidConfigTableStoreFromJson(json);
|
_$VeilidConfigTableStoreFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
@ -381,8 +381,8 @@ class VeilidConfigBlockStore with _$VeilidConfigBlockStore {
|
|||||||
required bool delete,
|
required bool delete,
|
||||||
}) = _VeilidConfigBlockStore;
|
}) = _VeilidConfigBlockStore;
|
||||||
|
|
||||||
factory VeilidConfigBlockStore.fromJson(Map<String, dynamic> json) =>
|
factory VeilidConfigBlockStore.fromJson(dynamic json) =>
|
||||||
_$VeilidConfigBlockStoreFromJson(json);
|
_$VeilidConfigBlockStoreFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
@ -397,8 +397,8 @@ class VeilidConfigProtectedStore with _$VeilidConfigProtectedStore {
|
|||||||
required String deviceEncryptionKeyPassword,
|
required String deviceEncryptionKeyPassword,
|
||||||
String? newDeviceEncryptionKeyPassword}) = _VeilidConfigProtectedStore;
|
String? newDeviceEncryptionKeyPassword}) = _VeilidConfigProtectedStore;
|
||||||
|
|
||||||
factory VeilidConfigProtectedStore.fromJson(Map<String, dynamic> json) =>
|
factory VeilidConfigProtectedStore.fromJson(dynamic json) =>
|
||||||
_$VeilidConfigProtectedStoreFromJson(json);
|
_$VeilidConfigProtectedStoreFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
@ -409,8 +409,8 @@ class VeilidConfigCapabilities with _$VeilidConfigCapabilities {
|
|||||||
required List<String> disable,
|
required List<String> disable,
|
||||||
}) = _VeilidConfigCapabilities;
|
}) = _VeilidConfigCapabilities;
|
||||||
|
|
||||||
factory VeilidConfigCapabilities.fromJson(Map<String, dynamic> json) =>
|
factory VeilidConfigCapabilities.fromJson(dynamic json) =>
|
||||||
_$VeilidConfigCapabilitiesFromJson(json);
|
_$VeilidConfigCapabilitiesFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
@ -427,6 +427,6 @@ class VeilidConfig with _$VeilidConfig {
|
|||||||
required VeilidConfigNetwork network,
|
required VeilidConfigNetwork network,
|
||||||
}) = _VeilidConfig;
|
}) = _VeilidConfig;
|
||||||
|
|
||||||
factory VeilidConfig.fromJson(Map<String, dynamic> json) =>
|
factory VeilidConfig.fromJson(dynamic json) =>
|
||||||
_$VeilidConfigFromJson(json);
|
_$VeilidConfigFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
@ -18,17 +18,14 @@ const CryptoKind cryptoKindNONE =
|
|||||||
$N << 0 | $O << 8 | $N << 16 | $E << 24; // "NONE"
|
$N << 0 | $O << 8 | $N << 16 | $E << 24; // "NONE"
|
||||||
|
|
||||||
String cryptoKindToString(CryptoKind kind) {
|
String cryptoKindToString(CryptoKind kind) {
|
||||||
return "${String.fromCharCode(kind & 0xFF)}${String.fromCharCode((kind >> 8) & 0xFF)}${String.fromCharCode((kind >> 16) & 0xFF)}${String.fromCharCode((kind >> 24) & 0xFF)}";
|
return cryptoKindToBytes(kind).map((c) => String.fromCharCode(c)).join();
|
||||||
}
|
}
|
||||||
|
|
||||||
const CryptoKind bestCryptoKind = cryptoKindVLD0;
|
const CryptoKind bestCryptoKind = cryptoKindVLD0;
|
||||||
|
|
||||||
Uint8List cryptoKindToBytes(CryptoKind kind) {
|
Uint8List cryptoKindToBytes(CryptoKind kind) {
|
||||||
var b = Uint8List(4);
|
var b = Uint8List(4);
|
||||||
b[0] = kind & 0xFF;
|
ByteData.sublistView(b).setUint32(0, kind, Endian.big);
|
||||||
b[1] = (kind >> 8) & 0xFF;
|
|
||||||
b[2] = (kind >> 16) & 0xFF;
|
|
||||||
b[3] = (kind >> 24) & 0xFF;
|
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,10 +33,8 @@ CryptoKind cryptoKindFromString(String s) {
|
|||||||
if (s.codeUnits.length != 4) {
|
if (s.codeUnits.length != 4) {
|
||||||
throw const FormatException("malformed string");
|
throw const FormatException("malformed string");
|
||||||
}
|
}
|
||||||
CryptoKind kind = s.codeUnits[0] |
|
CryptoKind kind = ByteData.sublistView(Uint8List.fromList(s.codeUnits))
|
||||||
s.codeUnits[1] << 8 |
|
.getUint32(0, Endian.big);
|
||||||
s.codeUnits[2] << 16 |
|
|
||||||
s.codeUnits[3] << 24;
|
|
||||||
return kind;
|
return kind;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,9 +66,10 @@ class Typed<V extends EncodedString> extends Equatable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Uint8List decode() {
|
Uint8List decode() {
|
||||||
var b = cryptoKindToBytes(kind);
|
var b = BytesBuilder();
|
||||||
b.addAll(value.decode());
|
b.add(cryptoKindToBytes(kind));
|
||||||
return b;
|
b.add(value.decode());
|
||||||
|
return b.toBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
String toJson() => toString();
|
String toJson() => toString();
|
||||||
|
@ -27,7 +27,7 @@ class Uint8ListJsonConverter implements JsonConverter<Uint8List, String> {
|
|||||||
const Uint8ListJsonConverter();
|
const Uint8ListJsonConverter();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Uint8List fromJson(String json) => base64UrlNoPadDecode(json);
|
Uint8List fromJson(dynamic json) => base64UrlNoPadDecode(json as String);
|
||||||
@override
|
@override
|
||||||
String toJson(Uint8List data) => base64UrlNoPadEncode(data);
|
String toJson(Uint8List data) => base64UrlNoPadEncode(data);
|
||||||
}
|
}
|
||||||
|
@ -368,7 +368,7 @@ Future<T> processFuturePlain<T>(Future<dynamic> future) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<T> processFutureJson<T>(
|
Future<T> processFutureJson<T>(
|
||||||
T Function(Map<String, dynamic>) jsonConstructor, Future<dynamic> future) {
|
T Function(dynamic) jsonConstructor, Future<dynamic> future) {
|
||||||
return future.then((value) {
|
return future.then((value) {
|
||||||
final list = value as List<dynamic>;
|
final list = value as List<dynamic>;
|
||||||
switch (list[0] as int) {
|
switch (list[0] as int) {
|
||||||
@ -541,7 +541,7 @@ Future<Stream<T>> processFutureStream<T>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
Stream<T> processStreamJson<T>(
|
Stream<T> processStreamJson<T>(
|
||||||
T Function(Map<String, dynamic>) jsonConstructor, ReceivePort port) async* {
|
T Function(dynamic) jsonConstructor, ReceivePort port) async* {
|
||||||
try {
|
try {
|
||||||
await for (var value in port) {
|
await for (var value in port) {
|
||||||
final list = value as List<dynamic>;
|
final list = value as List<dynamic>;
|
||||||
@ -729,7 +729,7 @@ class VeilidRoutingContextFFI extends VeilidRoutingContext {
|
|||||||
final sendPort = recvPort.sendPort;
|
final sendPort = recvPort.sendPort;
|
||||||
_ctx.ffi._routingContextGetDHTValue(
|
_ctx.ffi._routingContextGetDHTValue(
|
||||||
sendPort.nativePort, _ctx.id!, nativeKey, subkey, forceRefresh);
|
sendPort.nativePort, _ctx.id!, nativeKey, subkey, forceRefresh);
|
||||||
final valueData = await processFutureJson(
|
final valueData = await processFutureOptJson(
|
||||||
optFromJson(ValueData.fromJson), recvPort.first);
|
optFromJson(ValueData.fromJson), recvPort.first);
|
||||||
return valueData;
|
return valueData;
|
||||||
}
|
}
|
||||||
@ -745,7 +745,7 @@ class VeilidRoutingContextFFI extends VeilidRoutingContext {
|
|||||||
final sendPort = recvPort.sendPort;
|
final sendPort = recvPort.sendPort;
|
||||||
_ctx.ffi._routingContextSetDHTValue(
|
_ctx.ffi._routingContextSetDHTValue(
|
||||||
sendPort.nativePort, _ctx.id!, nativeKey, subkey, nativeData);
|
sendPort.nativePort, _ctx.id!, nativeKey, subkey, nativeData);
|
||||||
final valueData = await processFutureJson(
|
final valueData = await processFutureOptJson(
|
||||||
optFromJson(ValueData.fromJson), recvPort.first);
|
optFromJson(ValueData.fromJson), recvPort.first);
|
||||||
return valueData;
|
return valueData;
|
||||||
}
|
}
|
||||||
@ -1651,8 +1651,8 @@ class VeilidFFI extends Veilid {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> appCallReply(String call_id, Uint8List message) {
|
Future<void> appCallReply(String callId, Uint8List message) {
|
||||||
final nativeCallId = call_id.toNativeUtf8();
|
final nativeCallId = callId.toNativeUtf8();
|
||||||
final nativeEncodedMessage = base64UrlNoPadEncode(message).toNativeUtf8();
|
final nativeEncodedMessage = base64UrlNoPadEncode(message).toNativeUtf8();
|
||||||
final recvPort = ReceivePort("app_call_reply");
|
final recvPort = ReceivePort("app_call_reply");
|
||||||
final sendPort = recvPort.sendPort;
|
final sendPort = recvPort.sendPort;
|
||||||
@ -1681,15 +1681,15 @@ class VeilidFFI extends Veilid {
|
|||||||
@override
|
@override
|
||||||
List<CryptoKind> validCryptoKinds() {
|
List<CryptoKind> validCryptoKinds() {
|
||||||
final vckString = _validCryptoKinds();
|
final vckString = _validCryptoKinds();
|
||||||
final vck = jsonDecode(vckString.toDartString());
|
final vck = jsonDecode(vckString.toDartString()) as List<dynamic>;
|
||||||
_freeString(vckString);
|
_freeString(vckString);
|
||||||
return vck;
|
return vck.map((v) => v as CryptoKind).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<VeilidCryptoSystem> getCryptoSystem(CryptoKind kind) async {
|
Future<VeilidCryptoSystem> getCryptoSystem(CryptoKind kind) async {
|
||||||
if (!validCryptoKinds().contains(kind)) {
|
if (!validCryptoKinds().contains(kind)) {
|
||||||
throw VeilidAPIExceptionGeneric("unsupported cryptosystem");
|
throw const VeilidAPIExceptionGeneric("unsupported cryptosystem");
|
||||||
}
|
}
|
||||||
return VeilidCryptoSystemFFI._(this, kind);
|
return VeilidCryptoSystemFFI._(this, kind);
|
||||||
}
|
}
|
||||||
|
@ -571,13 +571,15 @@ class VeilidJS extends Veilid {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
List<CryptoKind> validCryptoKinds() {
|
List<CryptoKind> validCryptoKinds() {
|
||||||
return jsonDecode(js_util.callMethod(wasm, "valid_crypto_kinds", []));
|
final vck = jsonDecode(js_util.callMethod(wasm, "valid_crypto_kinds", []))
|
||||||
|
as List<dynamic>;
|
||||||
|
return vck.map((v) => v as CryptoKind).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<VeilidCryptoSystem> getCryptoSystem(CryptoKind kind) async {
|
Future<VeilidCryptoSystem> getCryptoSystem(CryptoKind kind) async {
|
||||||
if (!validCryptoKinds().contains(kind)) {
|
if (!validCryptoKinds().contains(kind)) {
|
||||||
throw VeilidAPIExceptionGeneric("unsupported cryptosystem");
|
throw const VeilidAPIExceptionGeneric("unsupported cryptosystem");
|
||||||
}
|
}
|
||||||
return VeilidCryptoSystemJS._(this, kind);
|
return VeilidCryptoSystemJS._(this, kind);
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,8 @@ enum AttachmentState {
|
|||||||
detaching;
|
detaching;
|
||||||
|
|
||||||
String toJson() => name.toPascalCase();
|
String toJson() => name.toPascalCase();
|
||||||
factory AttachmentState.fromJson(String j) =>
|
factory AttachmentState.fromJson(dynamic j) =>
|
||||||
AttachmentState.values.byName(j.toCamelCase());
|
AttachmentState.values.byName((j as String).toCamelCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
@ -37,8 +37,8 @@ enum VeilidLogLevel {
|
|||||||
trace;
|
trace;
|
||||||
|
|
||||||
String toJson() => name.toPascalCase();
|
String toJson() => name.toPascalCase();
|
||||||
factory VeilidLogLevel.fromJson(String j) =>
|
factory VeilidLogLevel.fromJson(dynamic j) =>
|
||||||
VeilidLogLevel.values.byName(j.toCamelCase());
|
VeilidLogLevel.values.byName((j as String).toCamelCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
@ -51,8 +51,8 @@ class LatencyStats with _$LatencyStats {
|
|||||||
required TimestampDuration slowest,
|
required TimestampDuration slowest,
|
||||||
}) = _LatencyStats;
|
}) = _LatencyStats;
|
||||||
|
|
||||||
factory LatencyStats.fromJson(Map<String, dynamic> json) =>
|
factory LatencyStats.fromJson(dynamic json) =>
|
||||||
_$LatencyStatsFromJson(json);
|
_$LatencyStatsFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
@ -66,8 +66,8 @@ class TransferStats with _$TransferStats {
|
|||||||
required BigInt minimum,
|
required BigInt minimum,
|
||||||
}) = _TransferStats;
|
}) = _TransferStats;
|
||||||
|
|
||||||
factory TransferStats.fromJson(Map<String, dynamic> json) =>
|
factory TransferStats.fromJson(dynamic json) =>
|
||||||
_$TransferStatsFromJson(json);
|
_$TransferStatsFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
@ -79,8 +79,8 @@ class TransferStatsDownUp with _$TransferStatsDownUp {
|
|||||||
required TransferStats up,
|
required TransferStats up,
|
||||||
}) = _TransferStatsDownUp;
|
}) = _TransferStatsDownUp;
|
||||||
|
|
||||||
factory TransferStatsDownUp.fromJson(Map<String, dynamic> json) =>
|
factory TransferStatsDownUp.fromJson(dynamic json) =>
|
||||||
_$TransferStatsDownUpFromJson(json);
|
_$TransferStatsDownUpFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
@ -98,8 +98,8 @@ class RPCStats with _$RPCStats {
|
|||||||
required int failedToSend,
|
required int failedToSend,
|
||||||
}) = _RPCStats;
|
}) = _RPCStats;
|
||||||
|
|
||||||
factory RPCStats.fromJson(Map<String, dynamic> json) =>
|
factory RPCStats.fromJson(dynamic json) =>
|
||||||
_$RPCStatsFromJson(json);
|
_$RPCStatsFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
@ -113,8 +113,8 @@ class PeerStats with _$PeerStats {
|
|||||||
required TransferStatsDownUp transfer,
|
required TransferStatsDownUp transfer,
|
||||||
}) = _PeerStats;
|
}) = _PeerStats;
|
||||||
|
|
||||||
factory PeerStats.fromJson(Map<String, dynamic> json) =>
|
factory PeerStats.fromJson(dynamic json) =>
|
||||||
_$PeerStatsFromJson(json);
|
_$PeerStatsFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
@ -127,8 +127,8 @@ class PeerTableData with _$PeerTableData {
|
|||||||
required PeerStats peerStats,
|
required PeerStats peerStats,
|
||||||
}) = _PeerTableData;
|
}) = _PeerTableData;
|
||||||
|
|
||||||
factory PeerTableData.fromJson(Map<String, dynamic> json) =>
|
factory PeerTableData.fromJson(dynamic json) =>
|
||||||
_$PeerTableDataFromJson(json);
|
_$PeerTableDataFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
@ -173,8 +173,8 @@ sealed class VeilidUpdate with _$VeilidUpdate {
|
|||||||
required ValueData valueData,
|
required ValueData valueData,
|
||||||
}) = VeilidUpdateValueChange;
|
}) = VeilidUpdateValueChange;
|
||||||
|
|
||||||
factory VeilidUpdate.fromJson(Map<String, dynamic> json) =>
|
factory VeilidUpdate.fromJson(dynamic json) =>
|
||||||
_$VeilidUpdateFromJson(json);
|
_$VeilidUpdateFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
@ -187,8 +187,8 @@ class VeilidStateAttachment with _$VeilidStateAttachment {
|
|||||||
required bool publicInternetReady,
|
required bool publicInternetReady,
|
||||||
required bool localNetworkReady}) = _VeilidStateAttachment;
|
required bool localNetworkReady}) = _VeilidStateAttachment;
|
||||||
|
|
||||||
factory VeilidStateAttachment.fromJson(Map<String, dynamic> json) =>
|
factory VeilidStateAttachment.fromJson(dynamic json) =>
|
||||||
_$VeilidStateAttachmentFromJson(json);
|
_$VeilidStateAttachmentFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
@ -202,8 +202,8 @@ class VeilidStateNetwork with _$VeilidStateNetwork {
|
|||||||
required BigInt bpsUp,
|
required BigInt bpsUp,
|
||||||
required List<PeerTableData> peers}) = _VeilidStateNetwork;
|
required List<PeerTableData> peers}) = _VeilidStateNetwork;
|
||||||
|
|
||||||
factory VeilidStateNetwork.fromJson(Map<String, dynamic> json) =>
|
factory VeilidStateNetwork.fromJson(dynamic json) =>
|
||||||
_$VeilidStateNetworkFromJson(json);
|
_$VeilidStateNetworkFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
@ -215,8 +215,8 @@ class VeilidStateConfig with _$VeilidStateConfig {
|
|||||||
required VeilidConfig config,
|
required VeilidConfig config,
|
||||||
}) = _VeilidStateConfig;
|
}) = _VeilidStateConfig;
|
||||||
|
|
||||||
factory VeilidStateConfig.fromJson(Map<String, dynamic> json) =>
|
factory VeilidStateConfig.fromJson(dynamic json) =>
|
||||||
_$VeilidStateConfigFromJson(json);
|
_$VeilidStateConfigFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
@ -230,6 +230,6 @@ class VeilidState with _$VeilidState {
|
|||||||
required VeilidStateConfig config,
|
required VeilidStateConfig config,
|
||||||
}) = _VeilidState;
|
}) = _VeilidState;
|
||||||
|
|
||||||
factory VeilidState.fromJson(Map<String, dynamic> json) =>
|
factory VeilidState.fromJson(dynamic json) =>
|
||||||
_$VeilidStateFromJson(json);
|
_$VeilidStateFromJson(json as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
@ -367,9 +367,8 @@ pub extern "C" fn shutdown_veilid_core(port: i64) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_routing_context(routing_context: veilid_core::RoutingContext) -> u32 {
|
fn add_routing_context(rc: &mut BTreeMap<u32, veilid_core::RoutingContext>, routing_context: veilid_core::RoutingContext) -> u32 {
|
||||||
let mut next_id: u32 = 1;
|
let mut next_id: u32 = 1;
|
||||||
let mut rc = ROUTING_CONTEXTS.lock();
|
|
||||||
while rc.contains_key(&next_id) {
|
while rc.contains_key(&next_id) {
|
||||||
next_id += 1;
|
next_id += 1;
|
||||||
}
|
}
|
||||||
@ -382,7 +381,8 @@ pub extern "C" fn routing_context(port: i64) {
|
|||||||
DartIsolateWrapper::new(port).spawn_result(async move {
|
DartIsolateWrapper::new(port).spawn_result(async move {
|
||||||
let veilid_api = get_veilid_api().await?;
|
let veilid_api = get_veilid_api().await?;
|
||||||
let routing_context = veilid_api.routing_context();
|
let routing_context = veilid_api.routing_context();
|
||||||
let new_id = add_routing_context(routing_context);
|
let mut rc = ROUTING_CONTEXTS.lock();
|
||||||
|
let new_id = add_routing_context(&mut *rc, routing_context);
|
||||||
APIResult::Ok(new_id)
|
APIResult::Ok(new_id)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -398,14 +398,14 @@ pub extern "C" fn release_routing_context(id: u32) -> i32 {
|
|||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn routing_context_with_privacy(id: u32) -> u32 {
|
pub extern "C" fn routing_context_with_privacy(id: u32) -> u32 {
|
||||||
let rc = ROUTING_CONTEXTS.lock();
|
let mut rc = ROUTING_CONTEXTS.lock();
|
||||||
let Some(routing_context) = rc.get(&id) else {
|
let Some(routing_context) = rc.get(&id) else {
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
let Ok(routing_context) = routing_context.clone().with_privacy() else {
|
let Ok(routing_context) = routing_context.clone().with_privacy() else {
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
let new_id = add_routing_context(routing_context);
|
let new_id = add_routing_context(&mut rc, routing_context);
|
||||||
new_id
|
new_id
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -414,14 +414,14 @@ pub extern "C" fn routing_context_with_custom_privacy(id: u32, safety_selection:
|
|||||||
let safety_selection: veilid_core::SafetySelection =
|
let safety_selection: veilid_core::SafetySelection =
|
||||||
veilid_core::deserialize_opt_json(safety_selection.into_opt_string()).unwrap();
|
veilid_core::deserialize_opt_json(safety_selection.into_opt_string()).unwrap();
|
||||||
|
|
||||||
let rc = ROUTING_CONTEXTS.lock();
|
let mut rc = ROUTING_CONTEXTS.lock();
|
||||||
let Some(routing_context) = rc.get(&id) else {
|
let Some(routing_context) = rc.get(&id) else {
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
let Ok(routing_context) = routing_context.clone().with_custom_privacy(safety_selection) else {
|
let Ok(routing_context) = routing_context.clone().with_custom_privacy(safety_selection) else {
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
let new_id = add_routing_context(routing_context);
|
let new_id = add_routing_context(&mut rc, routing_context);
|
||||||
new_id
|
new_id
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -430,12 +430,12 @@ pub extern "C" fn routing_context_with_sequencing(id: u32, sequencing: FfiStr) -
|
|||||||
let sequencing: veilid_core::Sequencing =
|
let sequencing: veilid_core::Sequencing =
|
||||||
veilid_core::deserialize_opt_json(sequencing.into_opt_string()).unwrap();
|
veilid_core::deserialize_opt_json(sequencing.into_opt_string()).unwrap();
|
||||||
|
|
||||||
let rc = ROUTING_CONTEXTS.lock();
|
let mut rc = ROUTING_CONTEXTS.lock();
|
||||||
let Some(routing_context) = rc.get(&id) else {
|
let Some(routing_context) = rc.get(&id) else {
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
let routing_context = routing_context.clone().with_sequencing(sequencing);
|
let routing_context = routing_context.clone().with_sequencing(sequencing);
|
||||||
let new_id = add_routing_context(routing_context);
|
let new_id = add_routing_context(&mut rc, routing_context);
|
||||||
new_id
|
new_id
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -569,7 +569,7 @@ pub extern "C" fn routing_context_delete_dht_record(port: i64, id: u32, key: Ffi
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn routing_context_get_dht_value(port: i64, id: u32, key: FfiStr, subkey: u32, force_refresh: bool) {
|
pub extern "C" fn routing_context_get_dht_value(port: i64, id: u32, key: FfiStr, subkey: u32, force_refresh: bool) {
|
||||||
let key: veilid_core::TypedKey = veilid_core::deserialize_opt_json(key.into_opt_string()).unwrap();
|
let key: veilid_core::TypedKey = veilid_core::deserialize_opt_json(key.into_opt_string()).unwrap();
|
||||||
DartIsolateWrapper::new(port).spawn_result_opt_json(async move {
|
DartIsolateWrapper::new(port).spawn_result_json(async move {
|
||||||
let routing_context = {
|
let routing_context = {
|
||||||
let rc = ROUTING_CONTEXTS.lock();
|
let rc = ROUTING_CONTEXTS.lock();
|
||||||
let Some(routing_context) = rc.get(&id) else {
|
let Some(routing_context) = rc.get(&id) else {
|
||||||
@ -594,7 +594,7 @@ pub extern "C" fn routing_context_set_dht_value(port: i64, id: u32, key: FfiStr,
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
DartIsolateWrapper::new(port).spawn_result_opt_json(async move {
|
DartIsolateWrapper::new(port).spawn_result_json(async move {
|
||||||
let routing_context = {
|
let routing_context = {
|
||||||
let rc = ROUTING_CONTEXTS.lock();
|
let rc = ROUTING_CONTEXTS.lock();
|
||||||
let Some(routing_context) = rc.get(&id) else {
|
let Some(routing_context) = rc.get(&id) else {
|
||||||
@ -1404,7 +1404,7 @@ pub extern "C" fn crypto_decrypt_aead(port: i64, kind: u32, body: FfiStr, nonce:
|
|||||||
|
|
||||||
let associated_data: Option<Vec<u8>> = associated_data.into_opt_string().map(|s| data_encoding::BASE64URL_NOPAD.decode(s.as_bytes()).unwrap());
|
let associated_data: Option<Vec<u8>> = associated_data.into_opt_string().map(|s| data_encoding::BASE64URL_NOPAD.decode(s.as_bytes()).unwrap());
|
||||||
|
|
||||||
DartIsolateWrapper::new(port).spawn_result_json(async move {
|
DartIsolateWrapper::new(port).spawn_result(async move {
|
||||||
let veilid_api = get_veilid_api().await?;
|
let veilid_api = get_veilid_api().await?;
|
||||||
let crypto = veilid_api.crypto()?;
|
let crypto = veilid_api.crypto()?;
|
||||||
let csv = crypto.get(kind).ok_or_else(|| veilid_core::VeilidAPIError::invalid_argument("crypto_decrypt_aead", "kind", kind.to_string()))?;
|
let csv = crypto.get(kind).ok_or_else(|| veilid_core::VeilidAPIError::invalid_argument("crypto_decrypt_aead", "kind", kind.to_string()))?;
|
||||||
@ -1412,6 +1412,7 @@ pub extern "C" fn crypto_decrypt_aead(port: i64, kind: u32, body: FfiStr, nonce:
|
|||||||
Some(ad) => Some(ad.as_slice()),
|
Some(ad) => Some(ad.as_slice()),
|
||||||
None => None
|
None => None
|
||||||
})?;
|
})?;
|
||||||
|
let out = data_encoding::BASE64URL_NOPAD.encode(&out);
|
||||||
APIResult::Ok(out)
|
APIResult::Ok(out)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1436,7 +1437,7 @@ pub extern "C" fn crypto_encrypt_aead(port: i64, kind: u32, body: FfiStr, nonce:
|
|||||||
|
|
||||||
let associated_data: Option<Vec<u8>> = associated_data.into_opt_string().map(|s| data_encoding::BASE64URL_NOPAD.decode(s.as_bytes()).unwrap());
|
let associated_data: Option<Vec<u8>> = associated_data.into_opt_string().map(|s| data_encoding::BASE64URL_NOPAD.decode(s.as_bytes()).unwrap());
|
||||||
|
|
||||||
DartIsolateWrapper::new(port).spawn_result_json(async move {
|
DartIsolateWrapper::new(port).spawn_result(async move {
|
||||||
let veilid_api = get_veilid_api().await?;
|
let veilid_api = get_veilid_api().await?;
|
||||||
let crypto = veilid_api.crypto()?;
|
let crypto = veilid_api.crypto()?;
|
||||||
let csv = crypto.get(kind).ok_or_else(|| veilid_core::VeilidAPIError::invalid_argument("crypto_encrypt_aead", "kind", kind.to_string()))?;
|
let csv = crypto.get(kind).ok_or_else(|| veilid_core::VeilidAPIError::invalid_argument("crypto_encrypt_aead", "kind", kind.to_string()))?;
|
||||||
@ -1444,6 +1445,7 @@ pub extern "C" fn crypto_encrypt_aead(port: i64, kind: u32, body: FfiStr, nonce:
|
|||||||
Some(ad) => Some(ad.as_slice()),
|
Some(ad) => Some(ad.as_slice()),
|
||||||
None => None
|
None => None
|
||||||
})?;
|
})?;
|
||||||
|
let out = data_encoding::BASE64URL_NOPAD.encode(&out);
|
||||||
APIResult::Ok(out)
|
APIResult::Ok(out)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1468,11 +1470,12 @@ pub extern "C" fn crypto_crypt_no_auth(port: i64, kind: u32, body: FfiStr, nonce
|
|||||||
let shared_secret: veilid_core::SharedSecret =
|
let shared_secret: veilid_core::SharedSecret =
|
||||||
veilid_core::deserialize_opt_json(shared_secret.into_opt_string()).unwrap();
|
veilid_core::deserialize_opt_json(shared_secret.into_opt_string()).unwrap();
|
||||||
|
|
||||||
DartIsolateWrapper::new(port).spawn_result_json(async move {
|
DartIsolateWrapper::new(port).spawn_result(async move {
|
||||||
let veilid_api = get_veilid_api().await?;
|
let veilid_api = get_veilid_api().await?;
|
||||||
let crypto = veilid_api.crypto()?;
|
let crypto = veilid_api.crypto()?;
|
||||||
let csv = crypto.get(kind).ok_or_else(|| veilid_core::VeilidAPIError::invalid_argument("crypto_crypt_no_auth", "kind", kind.to_string()))?;
|
let csv = crypto.get(kind).ok_or_else(|| veilid_core::VeilidAPIError::invalid_argument("crypto_crypt_no_auth", "kind", kind.to_string()))?;
|
||||||
csv.crypt_in_place_no_auth(&mut body, &nonce, &shared_secret);
|
csv.crypt_in_place_no_auth(&mut body, &nonce, &shared_secret);
|
||||||
|
let body = data_encoding::BASE64URL_NOPAD.encode(&body);
|
||||||
APIResult::Ok(body)
|
APIResult::Ok(body)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -52,17 +52,6 @@ impl DartIsolateWrapper {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn spawn_result_opt_json<F, T, E>(self, future: F)
|
|
||||||
where
|
|
||||||
F: Future<Output = Result<Option<T>, E>> + Send + 'static,
|
|
||||||
T: Serialize + Debug,
|
|
||||||
E: Serialize + Debug,
|
|
||||||
{
|
|
||||||
spawn(async move {
|
|
||||||
self.result_opt_json(future.await);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn result<T: IntoDart + Debug, E: Serialize + Debug>(self, result: Result<T, E>) -> bool {
|
pub fn result<T: IntoDart + Debug, E: Serialize + Debug>(self, result: Result<T, E>) -> bool {
|
||||||
match result {
|
match result {
|
||||||
Ok(v) => self.ok(v),
|
Ok(v) => self.ok(v),
|
||||||
@ -78,16 +67,6 @@ impl DartIsolateWrapper {
|
|||||||
Err(e) => self.err_json(e),
|
Err(e) => self.err_json(e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn result_opt_json<T: Serialize + Debug, E: Serialize + Debug>(
|
|
||||||
self,
|
|
||||||
result: Result<Option<T>, E>,
|
|
||||||
) -> bool {
|
|
||||||
match result {
|
|
||||||
Ok(Some(v)) => self.ok_json(v),
|
|
||||||
Ok(None) => self.ok(()),
|
|
||||||
Err(e) => self.err_json(e),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn ok<T: IntoDart>(self, value: T) -> bool {
|
pub fn ok<T: IntoDart>(self, value: T) -> bool {
|
||||||
self.isolate
|
self.isolate
|
||||||
.post(vec![MESSAGE_OK.into_dart(), value.into_dart()])
|
.post(vec![MESSAGE_OK.into_dart(), value.into_dart()])
|
||||||
|
@ -60,12 +60,6 @@ fn take_veilid_api() -> Result<veilid_core::VeilidAPI, veilid_core::VeilidAPIErr
|
|||||||
pub fn to_json<T: Serialize + Debug>(val: T) -> JsValue {
|
pub fn to_json<T: Serialize + Debug>(val: T) -> JsValue {
|
||||||
JsValue::from_str(&serialize_json(val))
|
JsValue::from_str(&serialize_json(val))
|
||||||
}
|
}
|
||||||
pub fn to_opt_json<T: Serialize + Debug>(val: Option<T>) -> JsValue {
|
|
||||||
match val {
|
|
||||||
Some(v) => JsValue::from_str(&serialize_json(v)),
|
|
||||||
None => JsValue::UNDEFINED,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_jsvalue<T>(val: T) -> JsValue
|
pub fn to_jsvalue<T>(val: T) -> JsValue
|
||||||
where
|
where
|
||||||
@ -120,14 +114,6 @@ where
|
|||||||
future_to_promise(future.map(|res| res.map(|v| to_json(v)).map_err(|e| to_json(e))))
|
future_to_promise(future.map(|res| res.map(|v| to_json(v)).map_err(|e| to_json(e))))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn wrap_api_future_opt_json<F, T>(future: F) -> Promise
|
|
||||||
where
|
|
||||||
F: Future<Output = APIResult<Option<T>>> + 'static,
|
|
||||||
T: Serialize + Debug + 'static,
|
|
||||||
{
|
|
||||||
future_to_promise(future.map(|res| res.map(|v| to_opt_json(v)).map_err(|e| to_json(e))))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn wrap_api_future_plain<F, T>(future: F) -> Promise
|
pub fn wrap_api_future_plain<F, T>(future: F) -> Promise
|
||||||
where
|
where
|
||||||
F: Future<Output = APIResult<T>> + 'static,
|
F: Future<Output = APIResult<T>> + 'static,
|
||||||
@ -507,7 +493,7 @@ pub fn routing_context_get_dht_value(
|
|||||||
force_refresh: bool,
|
force_refresh: bool,
|
||||||
) -> Promise {
|
) -> Promise {
|
||||||
let key: veilid_core::TypedKey = veilid_core::deserialize_json(&key).unwrap();
|
let key: veilid_core::TypedKey = veilid_core::deserialize_json(&key).unwrap();
|
||||||
wrap_api_future_opt_json(async move {
|
wrap_api_future_json(async move {
|
||||||
let routing_context = {
|
let routing_context = {
|
||||||
let rc = (*ROUTING_CONTEXTS).borrow();
|
let rc = (*ROUTING_CONTEXTS).borrow();
|
||||||
let Some(routing_context) = rc.get(&id) else {
|
let Some(routing_context) = rc.get(&id) else {
|
||||||
@ -529,7 +515,7 @@ pub fn routing_context_set_dht_value(id: u32, key: String, subkey: u32, data: St
|
|||||||
.decode(&data.as_bytes())
|
.decode(&data.as_bytes())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
wrap_api_future_opt_json(async move {
|
wrap_api_future_json(async move {
|
||||||
let routing_context = {
|
let routing_context = {
|
||||||
let rc = (*ROUTING_CONTEXTS).borrow();
|
let rc = (*ROUTING_CONTEXTS).borrow();
|
||||||
let Some(routing_context) = rc.get(&id) else {
|
let Some(routing_context) = rc.get(&id) else {
|
||||||
@ -1361,7 +1347,7 @@ pub fn crypto_decrypt_aead(
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
});
|
});
|
||||||
|
|
||||||
wrap_api_future_json(async move {
|
wrap_api_future(async move {
|
||||||
let veilid_api = get_veilid_api()?;
|
let veilid_api = get_veilid_api()?;
|
||||||
let crypto = veilid_api.crypto()?;
|
let crypto = veilid_api.crypto()?;
|
||||||
let csv = crypto.get(kind).ok_or_else(|| {
|
let csv = crypto.get(kind).ok_or_else(|| {
|
||||||
@ -1380,6 +1366,7 @@ pub fn crypto_decrypt_aead(
|
|||||||
None => None,
|
None => None,
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
|
let out = data_encoding::BASE64URL_NOPAD.encode(&out);
|
||||||
APIResult::Ok(out)
|
APIResult::Ok(out)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -1409,7 +1396,7 @@ pub fn crypto_encrypt_aead(
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
});
|
});
|
||||||
|
|
||||||
wrap_api_future_json(async move {
|
wrap_api_future(async move {
|
||||||
let veilid_api = get_veilid_api()?;
|
let veilid_api = get_veilid_api()?;
|
||||||
let crypto = veilid_api.crypto()?;
|
let crypto = veilid_api.crypto()?;
|
||||||
let csv = crypto.get(kind).ok_or_else(|| {
|
let csv = crypto.get(kind).ok_or_else(|| {
|
||||||
@ -1428,6 +1415,7 @@ pub fn crypto_encrypt_aead(
|
|||||||
None => None,
|
None => None,
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
|
let out = data_encoding::BASE64URL_NOPAD.encode(&out);
|
||||||
APIResult::Ok(out)
|
APIResult::Ok(out)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -1450,7 +1438,7 @@ pub fn crypto_crypt_no_auth(
|
|||||||
let shared_secret: veilid_core::SharedSecret =
|
let shared_secret: veilid_core::SharedSecret =
|
||||||
veilid_core::deserialize_json(&shared_secret).unwrap();
|
veilid_core::deserialize_json(&shared_secret).unwrap();
|
||||||
|
|
||||||
wrap_api_future_json(async move {
|
wrap_api_future(async move {
|
||||||
let veilid_api = get_veilid_api()?;
|
let veilid_api = get_veilid_api()?;
|
||||||
let crypto = veilid_api.crypto()?;
|
let crypto = veilid_api.crypto()?;
|
||||||
let csv = crypto.get(kind).ok_or_else(|| {
|
let csv = crypto.get(kind).ok_or_else(|| {
|
||||||
@ -1461,6 +1449,7 @@ pub fn crypto_crypt_no_auth(
|
|||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
csv.crypt_in_place_no_auth(&mut body, &nonce, &shared_secret);
|
csv.crypt_in_place_no_auth(&mut body, &nonce, &shared_secret);
|
||||||
|
let out = data_encoding::BASE64URL_NOPAD.encode(&out);
|
||||||
APIResult::Ok(body)
|
APIResult::Ok(body)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user