Merge branch 'veilidchat-work' into 'main'
This commit is contained in:
commit
91fab6ce5a
@ -395,10 +395,16 @@ impl NetworkInterfaces {
|
||||
continue;
|
||||
}
|
||||
if let Some(pipv4) = intf.primary_ipv4() {
|
||||
intf_addrs.push(pipv4);
|
||||
// Skip temporary addresses because they're going to change
|
||||
if !pipv4.is_temporary() {
|
||||
intf_addrs.push(pipv4);
|
||||
}
|
||||
}
|
||||
if let Some(pipv6) = intf.primary_ipv6() {
|
||||
intf_addrs.push(pipv6);
|
||||
// Skip temporary addresses because they're going to change
|
||||
if !pipv6.is_temporary() {
|
||||
intf_addrs.push(pipv6);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1678,7 +1678,10 @@ impl RPCProcessor {
|
||||
|
||||
let send_channel = {
|
||||
let inner = self.inner.lock();
|
||||
inner.send_channel.as_ref().unwrap().clone()
|
||||
let Some(send_channel) = inner.send_channel.as_ref().cloned() else {
|
||||
bail!("send channel is closed");
|
||||
};
|
||||
send_channel
|
||||
};
|
||||
let span_id = Span::current().id();
|
||||
send_channel
|
||||
@ -1714,7 +1717,10 @@ impl RPCProcessor {
|
||||
};
|
||||
let send_channel = {
|
||||
let inner = self.inner.lock();
|
||||
inner.send_channel.as_ref().unwrap().clone()
|
||||
let Some(send_channel) = inner.send_channel.as_ref().cloned() else {
|
||||
bail!("send channel is closed");
|
||||
};
|
||||
send_channel
|
||||
};
|
||||
let span_id = Span::current().id();
|
||||
send_channel
|
||||
@ -1753,7 +1759,10 @@ impl RPCProcessor {
|
||||
|
||||
let send_channel = {
|
||||
let inner = self.inner.lock();
|
||||
inner.send_channel.as_ref().unwrap().clone()
|
||||
let Some(send_channel) = inner.send_channel.as_ref().cloned() else {
|
||||
bail!("send channel is closed");
|
||||
};
|
||||
send_channel
|
||||
};
|
||||
let span_id = Span::current().id();
|
||||
send_channel
|
||||
|
@ -380,7 +380,7 @@ impl StorageManager {
|
||||
|
||||
// Add to offline writes to flush
|
||||
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
|
||||
@ -393,7 +393,7 @@ impl StorageManager {
|
||||
key,
|
||||
subkey,
|
||||
safety_selection,
|
||||
signed_value_data,
|
||||
signed_value_data.clone(),
|
||||
descriptor,
|
||||
)
|
||||
.await?;
|
||||
@ -404,7 +404,13 @@ impl StorageManager {
|
||||
.handle_set_local_value(key, subkey, final_signed_value_data.clone())
|
||||
.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(
|
||||
|
@ -357,6 +357,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.2"
|
||||
system_info_plus:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: system_info_plus
|
||||
sha256: b915c811c6605b802f3988859bc2bb79c95f735762a75b5451741f7a2b949d1b
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.0.5"
|
||||
term_glyph:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -395,7 +403,7 @@ packages:
|
||||
path: ".."
|
||||
relative: true
|
||||
source: path
|
||||
version: "0.1.1"
|
||||
version: "0.1.6"
|
||||
win32:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -1,7 +1,10 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart' show kIsWeb;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:system_info2/system_info2.dart' as sysinfo;
|
||||
import 'package:system_info_plus/system_info_plus.dart';
|
||||
import 'veilid.dart';
|
||||
|
||||
const int megaByte = 1024 * 1024;
|
||||
@ -13,10 +16,13 @@ int getLocalSubkeyCacheSize() {
|
||||
return 1024;
|
||||
}
|
||||
|
||||
int getLocalMaxSubkeyCacheMemoryMb() {
|
||||
Future<int> getLocalMaxSubkeyCacheMemoryMb() async {
|
||||
if (kIsWeb) {
|
||||
return 256;
|
||||
}
|
||||
if (Platform.isIOS || Platform.isAndroid) {
|
||||
return (await SystemInfoPlus.physicalMemory ?? 2048) ~/ 32;
|
||||
}
|
||||
return sysinfo.SysInfo.getTotalPhysicalMemory() ~/ 32 ~/ megaByte;
|
||||
}
|
||||
|
||||
@ -34,10 +40,13 @@ int getRemoteMaxRecords() {
|
||||
return 128;
|
||||
}
|
||||
|
||||
int getRemoteMaxSubkeyCacheMemoryMb() {
|
||||
Future<int> getRemoteMaxSubkeyCacheMemoryMb() async {
|
||||
if (kIsWeb) {
|
||||
return 256;
|
||||
}
|
||||
if (Platform.isIOS || Platform.isAndroid) {
|
||||
return (await SystemInfoPlus.physicalMemory ?? 2048) ~/ 32;
|
||||
}
|
||||
return sysinfo.SysInfo.getTotalPhysicalMemory() ~/ 32 ~/ megaByte;
|
||||
}
|
||||
|
||||
@ -121,10 +130,10 @@ Future<VeilidConfig> getDefaultVeilidConfig(String programName) async {
|
||||
minPeerRefreshTimeMs: 60000,
|
||||
validateDialInfoReceiptTimeMs: 2000,
|
||||
localSubkeyCacheSize: getLocalSubkeyCacheSize(),
|
||||
localMaxSubkeyCacheMemoryMb: getLocalMaxSubkeyCacheMemoryMb(),
|
||||
localMaxSubkeyCacheMemoryMb: await getLocalMaxSubkeyCacheMemoryMb(),
|
||||
remoteSubkeyCacheSize: getRemoteSubkeyCacheSize(),
|
||||
remoteMaxRecords: getRemoteMaxRecords(),
|
||||
remoteMaxSubkeyCacheMemoryMb: getRemoteMaxSubkeyCacheMemoryMb(),
|
||||
remoteMaxSubkeyCacheMemoryMb: await getRemoteMaxSubkeyCacheMemoryMb(),
|
||||
remoteMaxStorageSpaceMb: getRemoteMaxStorageSpaceMb()),
|
||||
upnp: true,
|
||||
detectAddressChanges: true,
|
||||
|
@ -5,7 +5,6 @@ import 'package:change_case/change_case.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
import 'veilid_encoding.dart';
|
||||
import 'veilid.dart';
|
||||
|
||||
part 'routing_context.freezed.dart';
|
||||
@ -51,8 +50,8 @@ sealed class DHTSchema with _$DHTSchema {
|
||||
{required int oCnt,
|
||||
required List<DHTSchemaMember> members}) = DHTSchemaSMPL;
|
||||
|
||||
factory DHTSchema.fromJson(Map<String, dynamic> json) =>
|
||||
_$DHTSchemaFromJson(json);
|
||||
factory DHTSchema.fromJson(dynamic json) =>
|
||||
_$DHTSchemaFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
const DHTSchema defaultDHTSchema = DHTSchema.dflt(oCnt: 1);
|
||||
@ -65,8 +64,8 @@ class DHTSchemaMember with _$DHTSchemaMember {
|
||||
required int mCnt,
|
||||
}) = _DHTSchemaMember;
|
||||
|
||||
factory DHTSchemaMember.fromJson(Map<String, dynamic> json) =>
|
||||
_$DHTSchemaMemberFromJson(json);
|
||||
factory DHTSchemaMember.fromJson(dynamic json) =>
|
||||
_$DHTSchemaMemberFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
@ -80,8 +79,8 @@ class DHTRecordDescriptor with _$DHTRecordDescriptor {
|
||||
PublicKey? ownerSecret,
|
||||
required DHTSchema schema,
|
||||
}) = _DHTRecordDescriptor;
|
||||
factory DHTRecordDescriptor.fromJson(Map<String, dynamic> json) =>
|
||||
_$DHTRecordDescriptorFromJson(json);
|
||||
factory DHTRecordDescriptor.fromJson(dynamic json) =>
|
||||
_$DHTRecordDescriptorFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
extension DHTRecordDescriptorExt on DHTRecordDescriptor {
|
||||
@ -112,8 +111,8 @@ class ValueSubkeyRange with _$ValueSubkeyRange {
|
||||
required int high,
|
||||
}) = _ValueSubkeyRange;
|
||||
|
||||
factory ValueSubkeyRange.fromJson(Map<String, dynamic> json) =>
|
||||
_$ValueSubkeyRangeFromJson(json);
|
||||
factory ValueSubkeyRange.fromJson(dynamic json) =>
|
||||
_$ValueSubkeyRangeFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
@ -128,8 +127,8 @@ class ValueData with _$ValueData {
|
||||
required PublicKey writer,
|
||||
}) = _ValueData;
|
||||
|
||||
factory ValueData.fromJson(Map<String, dynamic> json) =>
|
||||
_$ValueDataFromJson(json);
|
||||
factory ValueData.fromJson(dynamic json) =>
|
||||
_$ValueDataFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
@ -140,8 +139,8 @@ enum Stability {
|
||||
reliable;
|
||||
|
||||
String toJson() => name.toPascalCase();
|
||||
factory Stability.fromJson(String j) =>
|
||||
Stability.values.byName(j.toCamelCase());
|
||||
factory Stability.fromJson(dynamic j) =>
|
||||
Stability.values.byName((j as String).toCamelCase());
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
@ -153,8 +152,8 @@ enum Sequencing {
|
||||
ensureOrdered;
|
||||
|
||||
String toJson() => name.toPascalCase();
|
||||
factory Sequencing.fromJson(String j) =>
|
||||
Sequencing.values.byName(j.toCamelCase());
|
||||
factory Sequencing.fromJson(dynamic j) =>
|
||||
Sequencing.values.byName((j as String).toCamelCase());
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
@ -162,7 +161,8 @@ enum Sequencing {
|
||||
|
||||
@immutable
|
||||
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")) {
|
||||
return SafetySelectionUnsafe(
|
||||
sequencing: Sequencing.fromJson(json["Unsafe"]));
|
||||
@ -223,8 +223,8 @@ class SafetySpec with _$SafetySpec {
|
||||
required Sequencing sequencing,
|
||||
}) = _SafetySpec;
|
||||
|
||||
factory SafetySpec.fromJson(Map<String, dynamic> json) =>
|
||||
_$SafetySpecFromJson(json);
|
||||
factory SafetySpec.fromJson(dynamic json) =>
|
||||
_$SafetySpecFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
@ -234,8 +234,8 @@ class RouteBlob with _$RouteBlob {
|
||||
const factory RouteBlob(
|
||||
{required String routeId,
|
||||
@Uint8ListJsonConverter() required Uint8List blob}) = _RouteBlob;
|
||||
factory RouteBlob.fromJson(Map<String, dynamic> json) =>
|
||||
_$RouteBlobFromJson(json);
|
||||
factory RouteBlob.fromJson(dynamic json) =>
|
||||
_$RouteBlobFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
@ -156,7 +156,7 @@ abstract class Veilid {
|
||||
Future<void> releasePrivateRoute(String key);
|
||||
|
||||
// App calls
|
||||
Future<void> appCallReply(String id, Uint8List message);
|
||||
Future<void> appCallReply(String callId, Uint8List message);
|
||||
|
||||
// TableStore
|
||||
Future<VeilidTableDB> openTableDB(String name, int columnCount);
|
||||
|
@ -17,8 +17,8 @@ class VeilidFFIConfigLoggingTerminal with _$VeilidFFIConfigLoggingTerminal {
|
||||
required VeilidConfigLogLevel level,
|
||||
}) = _VeilidFFIConfigLoggingTerminal;
|
||||
|
||||
factory VeilidFFIConfigLoggingTerminal.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidFFIConfigLoggingTerminalFromJson(json);
|
||||
factory VeilidFFIConfigLoggingTerminal.fromJson(dynamic json) =>
|
||||
_$VeilidFFIConfigLoggingTerminalFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
@freezed
|
||||
@ -30,8 +30,8 @@ class VeilidFFIConfigLoggingOtlp with _$VeilidFFIConfigLoggingOtlp {
|
||||
required String serviceName,
|
||||
}) = _VeilidFFIConfigLoggingOtlp;
|
||||
|
||||
factory VeilidFFIConfigLoggingOtlp.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidFFIConfigLoggingOtlpFromJson(json);
|
||||
factory VeilidFFIConfigLoggingOtlp.fromJson(dynamic json) =>
|
||||
_$VeilidFFIConfigLoggingOtlpFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
@freezed
|
||||
@ -41,8 +41,8 @@ class VeilidFFIConfigLoggingApi with _$VeilidFFIConfigLoggingApi {
|
||||
required VeilidConfigLogLevel level,
|
||||
}) = _VeilidFFIConfigLoggingApi;
|
||||
|
||||
factory VeilidFFIConfigLoggingApi.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidFFIConfigLoggingApiFromJson(json);
|
||||
factory VeilidFFIConfigLoggingApi.fromJson(dynamic json) =>
|
||||
_$VeilidFFIConfigLoggingApiFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
@freezed
|
||||
@ -52,8 +52,8 @@ class VeilidFFIConfigLogging with _$VeilidFFIConfigLogging {
|
||||
required VeilidFFIConfigLoggingOtlp otlp,
|
||||
required VeilidFFIConfigLoggingApi api}) = _VeilidFFIConfigLogging;
|
||||
|
||||
factory VeilidFFIConfigLogging.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidFFIConfigLoggingFromJson(json);
|
||||
factory VeilidFFIConfigLogging.fromJson(dynamic json) =>
|
||||
_$VeilidFFIConfigLoggingFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
@freezed
|
||||
@ -62,8 +62,8 @@ class VeilidFFIConfig with _$VeilidFFIConfig {
|
||||
required VeilidFFIConfigLogging logging,
|
||||
}) = _VeilidFFIConfig;
|
||||
|
||||
factory VeilidFFIConfig.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidFFIConfigFromJson(json);
|
||||
factory VeilidFFIConfig.fromJson(dynamic json) =>
|
||||
_$VeilidFFIConfigFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
@ -79,9 +79,9 @@ class VeilidWASMConfigLoggingPerformance
|
||||
required bool logsInConsole,
|
||||
}) = _VeilidWASMConfigLoggingPerformance;
|
||||
|
||||
factory VeilidWASMConfigLoggingPerformance.fromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
_$VeilidWASMConfigLoggingPerformanceFromJson(json);
|
||||
factory VeilidWASMConfigLoggingPerformance.fromJson(dynamic json) =>
|
||||
_$VeilidWASMConfigLoggingPerformanceFromJson(
|
||||
json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
@freezed
|
||||
@ -91,8 +91,8 @@ class VeilidWASMConfigLoggingApi with _$VeilidWASMConfigLoggingApi {
|
||||
required VeilidConfigLogLevel level,
|
||||
}) = _VeilidWASMConfigLoggingApi;
|
||||
|
||||
factory VeilidWASMConfigLoggingApi.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidWASMConfigLoggingApiFromJson(json);
|
||||
factory VeilidWASMConfigLoggingApi.fromJson(dynamic json) =>
|
||||
_$VeilidWASMConfigLoggingApiFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
@freezed
|
||||
@ -101,8 +101,8 @@ class VeilidWASMConfigLogging with _$VeilidWASMConfigLogging {
|
||||
{required VeilidWASMConfigLoggingPerformance performance,
|
||||
required VeilidWASMConfigLoggingApi api}) = _VeilidWASMConfigLogging;
|
||||
|
||||
factory VeilidWASMConfigLogging.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidWASMConfigLoggingFromJson(json);
|
||||
factory VeilidWASMConfigLogging.fromJson(dynamic json) =>
|
||||
_$VeilidWASMConfigLoggingFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
@freezed
|
||||
@ -111,8 +111,8 @@ class VeilidWASMConfig with _$VeilidWASMConfig {
|
||||
required VeilidWASMConfigLogging logging,
|
||||
}) = _VeilidWASMConfig;
|
||||
|
||||
factory VeilidWASMConfig.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidWASMConfigFromJson(json);
|
||||
factory VeilidWASMConfig.fromJson(dynamic json) =>
|
||||
_$VeilidWASMConfigFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
@ -147,8 +147,8 @@ class VeilidConfigHTTPS with _$VeilidConfigHTTPS {
|
||||
String? url,
|
||||
}) = _VeilidConfigHTTPS;
|
||||
|
||||
factory VeilidConfigHTTPS.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidConfigHTTPSFromJson(json);
|
||||
factory VeilidConfigHTTPS.fromJson(dynamic json) =>
|
||||
_$VeilidConfigHTTPSFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
////////////
|
||||
@ -162,8 +162,8 @@ class VeilidConfigHTTP with _$VeilidConfigHTTP {
|
||||
String? url,
|
||||
}) = _VeilidConfigHTTP;
|
||||
|
||||
factory VeilidConfigHTTP.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidConfigHTTPFromJson(json);
|
||||
factory VeilidConfigHTTP.fromJson(dynamic json) =>
|
||||
_$VeilidConfigHTTPFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
////////////
|
||||
@ -175,8 +175,8 @@ class VeilidConfigApplication with _$VeilidConfigApplication {
|
||||
required VeilidConfigHTTP http,
|
||||
}) = _VeilidConfigApplication;
|
||||
|
||||
factory VeilidConfigApplication.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidConfigApplicationFromJson(json);
|
||||
factory VeilidConfigApplication.fromJson(dynamic json) =>
|
||||
_$VeilidConfigApplicationFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
////////////
|
||||
@ -188,8 +188,8 @@ class VeilidConfigUDP with _$VeilidConfigUDP {
|
||||
required String listenAddress,
|
||||
String? publicAddress}) = _VeilidConfigUDP;
|
||||
|
||||
factory VeilidConfigUDP.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidConfigUDPFromJson(json);
|
||||
factory VeilidConfigUDP.fromJson(dynamic json) =>
|
||||
_$VeilidConfigUDPFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
////////////
|
||||
@ -202,8 +202,8 @@ class VeilidConfigTCP with _$VeilidConfigTCP {
|
||||
required String listenAddress,
|
||||
String? publicAddress}) = _VeilidConfigTCP;
|
||||
|
||||
factory VeilidConfigTCP.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidConfigTCPFromJson(json);
|
||||
factory VeilidConfigTCP.fromJson(dynamic json) =>
|
||||
_$VeilidConfigTCPFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
////////////
|
||||
@ -217,8 +217,8 @@ class VeilidConfigWS with _$VeilidConfigWS {
|
||||
required String path,
|
||||
String? url}) = _VeilidConfigWS;
|
||||
|
||||
factory VeilidConfigWS.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidConfigWSFromJson(json);
|
||||
factory VeilidConfigWS.fromJson(dynamic json) =>
|
||||
_$VeilidConfigWSFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
////////////
|
||||
@ -232,8 +232,8 @@ class VeilidConfigWSS with _$VeilidConfigWSS {
|
||||
required String path,
|
||||
String? url}) = _VeilidConfigWSS;
|
||||
|
||||
factory VeilidConfigWSS.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidConfigWSSFromJson(json);
|
||||
factory VeilidConfigWSS.fromJson(dynamic json) =>
|
||||
_$VeilidConfigWSSFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
////////////
|
||||
@ -247,8 +247,8 @@ class VeilidConfigProtocol with _$VeilidConfigProtocol {
|
||||
required VeilidConfigWSS wss,
|
||||
}) = _VeilidConfigProtocol;
|
||||
|
||||
factory VeilidConfigProtocol.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidConfigProtocolFromJson(json);
|
||||
factory VeilidConfigProtocol.fromJson(dynamic json) =>
|
||||
_$VeilidConfigProtocolFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
////////////
|
||||
@ -261,8 +261,8 @@ class VeilidConfigTLS with _$VeilidConfigTLS {
|
||||
required int connectionInitialTimeoutMs,
|
||||
}) = _VeilidConfigTLS;
|
||||
|
||||
factory VeilidConfigTLS.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidConfigTLSFromJson(json);
|
||||
factory VeilidConfigTLS.fromJson(dynamic json) =>
|
||||
_$VeilidConfigTLSFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
////////////
|
||||
@ -289,8 +289,8 @@ class VeilidConfigDHT with _$VeilidConfigDHT {
|
||||
required int remoteMaxSubkeyCacheMemoryMb,
|
||||
required int remoteMaxStorageSpaceMb}) = _VeilidConfigDHT;
|
||||
|
||||
factory VeilidConfigDHT.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidConfigDHTFromJson(json);
|
||||
factory VeilidConfigDHT.fromJson(dynamic json) =>
|
||||
_$VeilidConfigDHTFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
////////////
|
||||
@ -306,8 +306,8 @@ class VeilidConfigRPC with _$VeilidConfigRPC {
|
||||
required int maxRouteHopCount,
|
||||
required int defaultRouteHopCount}) = _VeilidConfigRPC;
|
||||
|
||||
factory VeilidConfigRPC.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidConfigRPCFromJson(json);
|
||||
factory VeilidConfigRPC.fromJson(dynamic json) =>
|
||||
_$VeilidConfigRPCFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
////////////
|
||||
@ -325,8 +325,8 @@ class VeilidConfigRoutingTable with _$VeilidConfigRoutingTable {
|
||||
required int limitAttachedWeak,
|
||||
}) = _VeilidConfigRoutingTable;
|
||||
|
||||
factory VeilidConfigRoutingTable.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidConfigRoutingTableFromJson(json);
|
||||
factory VeilidConfigRoutingTable.fromJson(dynamic json) =>
|
||||
_$VeilidConfigRoutingTableFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
////////////
|
||||
@ -355,8 +355,8 @@ class VeilidConfigNetwork with _$VeilidConfigNetwork {
|
||||
required VeilidConfigProtocol protocol,
|
||||
}) = _VeilidConfigNetwork;
|
||||
|
||||
factory VeilidConfigNetwork.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidConfigNetworkFromJson(json);
|
||||
factory VeilidConfigNetwork.fromJson(dynamic json) =>
|
||||
_$VeilidConfigNetworkFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
////////////
|
||||
@ -368,8 +368,8 @@ class VeilidConfigTableStore with _$VeilidConfigTableStore {
|
||||
required bool delete,
|
||||
}) = _VeilidConfigTableStore;
|
||||
|
||||
factory VeilidConfigTableStore.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidConfigTableStoreFromJson(json);
|
||||
factory VeilidConfigTableStore.fromJson(dynamic json) =>
|
||||
_$VeilidConfigTableStoreFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
////////////
|
||||
@ -381,8 +381,8 @@ class VeilidConfigBlockStore with _$VeilidConfigBlockStore {
|
||||
required bool delete,
|
||||
}) = _VeilidConfigBlockStore;
|
||||
|
||||
factory VeilidConfigBlockStore.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidConfigBlockStoreFromJson(json);
|
||||
factory VeilidConfigBlockStore.fromJson(dynamic json) =>
|
||||
_$VeilidConfigBlockStoreFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
////////////
|
||||
@ -397,8 +397,8 @@ class VeilidConfigProtectedStore with _$VeilidConfigProtectedStore {
|
||||
required String deviceEncryptionKeyPassword,
|
||||
String? newDeviceEncryptionKeyPassword}) = _VeilidConfigProtectedStore;
|
||||
|
||||
factory VeilidConfigProtectedStore.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidConfigProtectedStoreFromJson(json);
|
||||
factory VeilidConfigProtectedStore.fromJson(dynamic json) =>
|
||||
_$VeilidConfigProtectedStoreFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
////////////
|
||||
@ -409,8 +409,8 @@ class VeilidConfigCapabilities with _$VeilidConfigCapabilities {
|
||||
required List<String> disable,
|
||||
}) = _VeilidConfigCapabilities;
|
||||
|
||||
factory VeilidConfigCapabilities.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidConfigCapabilitiesFromJson(json);
|
||||
factory VeilidConfigCapabilities.fromJson(dynamic json) =>
|
||||
_$VeilidConfigCapabilitiesFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
////////////
|
||||
@ -427,6 +427,6 @@ class VeilidConfig with _$VeilidConfig {
|
||||
required VeilidConfigNetwork network,
|
||||
}) = _VeilidConfig;
|
||||
|
||||
factory VeilidConfig.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidConfigFromJson(json);
|
||||
factory VeilidConfig.fromJson(dynamic json) =>
|
||||
_$VeilidConfigFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
@ -18,17 +18,14 @@ const CryptoKind cryptoKindNONE =
|
||||
$N << 0 | $O << 8 | $N << 16 | $E << 24; // "NONE"
|
||||
|
||||
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;
|
||||
|
||||
Uint8List cryptoKindToBytes(CryptoKind kind) {
|
||||
var b = Uint8List(4);
|
||||
b[0] = kind & 0xFF;
|
||||
b[1] = (kind >> 8) & 0xFF;
|
||||
b[2] = (kind >> 16) & 0xFF;
|
||||
b[3] = (kind >> 24) & 0xFF;
|
||||
ByteData.sublistView(b).setUint32(0, kind, Endian.big);
|
||||
return b;
|
||||
}
|
||||
|
||||
@ -36,10 +33,8 @@ CryptoKind cryptoKindFromString(String s) {
|
||||
if (s.codeUnits.length != 4) {
|
||||
throw const FormatException("malformed string");
|
||||
}
|
||||
CryptoKind kind = s.codeUnits[0] |
|
||||
s.codeUnits[1] << 8 |
|
||||
s.codeUnits[2] << 16 |
|
||||
s.codeUnits[3] << 24;
|
||||
CryptoKind kind = ByteData.sublistView(Uint8List.fromList(s.codeUnits))
|
||||
.getUint32(0, Endian.big);
|
||||
return kind;
|
||||
}
|
||||
|
||||
@ -71,9 +66,10 @@ class Typed<V extends EncodedString> extends Equatable {
|
||||
}
|
||||
|
||||
Uint8List decode() {
|
||||
var b = cryptoKindToBytes(kind);
|
||||
b.addAll(value.decode());
|
||||
return b;
|
||||
var b = BytesBuilder();
|
||||
b.add(cryptoKindToBytes(kind));
|
||||
b.add(value.decode());
|
||||
return b.toBytes();
|
||||
}
|
||||
|
||||
String toJson() => toString();
|
||||
|
@ -27,7 +27,7 @@ class Uint8ListJsonConverter implements JsonConverter<Uint8List, String> {
|
||||
const Uint8ListJsonConverter();
|
||||
|
||||
@override
|
||||
Uint8List fromJson(String json) => base64UrlNoPadDecode(json);
|
||||
Uint8List fromJson(dynamic json) => base64UrlNoPadDecode(json as String);
|
||||
@override
|
||||
String toJson(Uint8List data) => base64UrlNoPadEncode(data);
|
||||
}
|
||||
|
@ -368,7 +368,7 @@ Future<T> processFuturePlain<T>(Future<dynamic> future) {
|
||||
}
|
||||
|
||||
Future<T> processFutureJson<T>(
|
||||
T Function(Map<String, dynamic>) jsonConstructor, Future<dynamic> future) {
|
||||
T Function(dynamic) jsonConstructor, Future<dynamic> future) {
|
||||
return future.then((value) {
|
||||
final list = value as List<dynamic>;
|
||||
switch (list[0] as int) {
|
||||
@ -541,7 +541,7 @@ Future<Stream<T>> processFutureStream<T>(
|
||||
}
|
||||
|
||||
Stream<T> processStreamJson<T>(
|
||||
T Function(Map<String, dynamic>) jsonConstructor, ReceivePort port) async* {
|
||||
T Function(dynamic) jsonConstructor, ReceivePort port) async* {
|
||||
try {
|
||||
await for (var value in port) {
|
||||
final list = value as List<dynamic>;
|
||||
@ -688,7 +688,7 @@ class VeilidRoutingContextFFI extends VeilidRoutingContext {
|
||||
_ctx.ensureValid();
|
||||
final nativeKey = jsonEncode(key).toNativeUtf8();
|
||||
final nativeWriter =
|
||||
writer != null ? jsonEncode(key).toNativeUtf8() : nullptr;
|
||||
writer != null ? jsonEncode(writer).toNativeUtf8() : nullptr;
|
||||
final recvPort = ReceivePort("routing_context_open_dht_record");
|
||||
final sendPort = recvPort.sendPort;
|
||||
_ctx.ffi._routingContextOpenDHTRecord(
|
||||
@ -729,7 +729,7 @@ class VeilidRoutingContextFFI extends VeilidRoutingContext {
|
||||
final sendPort = recvPort.sendPort;
|
||||
_ctx.ffi._routingContextGetDHTValue(
|
||||
sendPort.nativePort, _ctx.id!, nativeKey, subkey, forceRefresh);
|
||||
final valueData = await processFutureJson(
|
||||
final valueData = await processFutureOptJson(
|
||||
optFromJson(ValueData.fromJson), recvPort.first);
|
||||
return valueData;
|
||||
}
|
||||
@ -745,7 +745,7 @@ class VeilidRoutingContextFFI extends VeilidRoutingContext {
|
||||
final sendPort = recvPort.sendPort;
|
||||
_ctx.ffi._routingContextSetDHTValue(
|
||||
sendPort.nativePort, _ctx.id!, nativeKey, subkey, nativeData);
|
||||
final valueData = await processFutureJson(
|
||||
final valueData = await processFutureOptJson(
|
||||
optFromJson(ValueData.fromJson), recvPort.first);
|
||||
return valueData;
|
||||
}
|
||||
@ -1651,8 +1651,8 @@ class VeilidFFI extends Veilid {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> appCallReply(String call_id, Uint8List message) {
|
||||
final nativeCallId = call_id.toNativeUtf8();
|
||||
Future<void> appCallReply(String callId, Uint8List message) {
|
||||
final nativeCallId = callId.toNativeUtf8();
|
||||
final nativeEncodedMessage = base64UrlNoPadEncode(message).toNativeUtf8();
|
||||
final recvPort = ReceivePort("app_call_reply");
|
||||
final sendPort = recvPort.sendPort;
|
||||
@ -1681,15 +1681,15 @@ class VeilidFFI extends Veilid {
|
||||
@override
|
||||
List<CryptoKind> validCryptoKinds() {
|
||||
final vckString = _validCryptoKinds();
|
||||
final vck = jsonDecode(vckString.toDartString());
|
||||
final vck = jsonDecode(vckString.toDartString()) as List<dynamic>;
|
||||
_freeString(vckString);
|
||||
return vck;
|
||||
return vck.map((v) => v as CryptoKind).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<VeilidCryptoSystem> getCryptoSystem(CryptoKind kind) async {
|
||||
if (!validCryptoKinds().contains(kind)) {
|
||||
throw VeilidAPIExceptionGeneric("unsupported cryptosystem");
|
||||
throw const VeilidAPIExceptionGeneric("unsupported cryptosystem");
|
||||
}
|
||||
return VeilidCryptoSystemFFI._(this, kind);
|
||||
}
|
||||
|
@ -571,13 +571,15 @@ class VeilidJS extends Veilid {
|
||||
|
||||
@override
|
||||
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
|
||||
Future<VeilidCryptoSystem> getCryptoSystem(CryptoKind kind) async {
|
||||
if (!validCryptoKinds().contains(kind)) {
|
||||
throw VeilidAPIExceptionGeneric("unsupported cryptosystem");
|
||||
throw const VeilidAPIExceptionGeneric("unsupported cryptosystem");
|
||||
}
|
||||
return VeilidCryptoSystemJS._(this, kind);
|
||||
}
|
||||
|
@ -22,8 +22,8 @@ enum AttachmentState {
|
||||
detaching;
|
||||
|
||||
String toJson() => name.toPascalCase();
|
||||
factory AttachmentState.fromJson(String j) =>
|
||||
AttachmentState.values.byName(j.toCamelCase());
|
||||
factory AttachmentState.fromJson(dynamic j) =>
|
||||
AttachmentState.values.byName((j as String).toCamelCase());
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
@ -37,8 +37,8 @@ enum VeilidLogLevel {
|
||||
trace;
|
||||
|
||||
String toJson() => name.toPascalCase();
|
||||
factory VeilidLogLevel.fromJson(String j) =>
|
||||
VeilidLogLevel.values.byName(j.toCamelCase());
|
||||
factory VeilidLogLevel.fromJson(dynamic j) =>
|
||||
VeilidLogLevel.values.byName((j as String).toCamelCase());
|
||||
}
|
||||
|
||||
////////////
|
||||
@ -51,8 +51,8 @@ class LatencyStats with _$LatencyStats {
|
||||
required TimestampDuration slowest,
|
||||
}) = _LatencyStats;
|
||||
|
||||
factory LatencyStats.fromJson(Map<String, dynamic> json) =>
|
||||
_$LatencyStatsFromJson(json);
|
||||
factory LatencyStats.fromJson(dynamic json) =>
|
||||
_$LatencyStatsFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
////////////
|
||||
@ -66,8 +66,8 @@ class TransferStats with _$TransferStats {
|
||||
required BigInt minimum,
|
||||
}) = _TransferStats;
|
||||
|
||||
factory TransferStats.fromJson(Map<String, dynamic> json) =>
|
||||
_$TransferStatsFromJson(json);
|
||||
factory TransferStats.fromJson(dynamic json) =>
|
||||
_$TransferStatsFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
////////////
|
||||
@ -79,8 +79,8 @@ class TransferStatsDownUp with _$TransferStatsDownUp {
|
||||
required TransferStats up,
|
||||
}) = _TransferStatsDownUp;
|
||||
|
||||
factory TransferStatsDownUp.fromJson(Map<String, dynamic> json) =>
|
||||
_$TransferStatsDownUpFromJson(json);
|
||||
factory TransferStatsDownUp.fromJson(dynamic json) =>
|
||||
_$TransferStatsDownUpFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
////////////
|
||||
@ -98,8 +98,8 @@ class RPCStats with _$RPCStats {
|
||||
required int failedToSend,
|
||||
}) = _RPCStats;
|
||||
|
||||
factory RPCStats.fromJson(Map<String, dynamic> json) =>
|
||||
_$RPCStatsFromJson(json);
|
||||
factory RPCStats.fromJson(dynamic json) =>
|
||||
_$RPCStatsFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
////////////
|
||||
@ -113,8 +113,8 @@ class PeerStats with _$PeerStats {
|
||||
required TransferStatsDownUp transfer,
|
||||
}) = _PeerStats;
|
||||
|
||||
factory PeerStats.fromJson(Map<String, dynamic> json) =>
|
||||
_$PeerStatsFromJson(json);
|
||||
factory PeerStats.fromJson(dynamic json) =>
|
||||
_$PeerStatsFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
////////////
|
||||
@ -127,8 +127,8 @@ class PeerTableData with _$PeerTableData {
|
||||
required PeerStats peerStats,
|
||||
}) = _PeerTableData;
|
||||
|
||||
factory PeerTableData.fromJson(Map<String, dynamic> json) =>
|
||||
_$PeerTableDataFromJson(json);
|
||||
factory PeerTableData.fromJson(dynamic json) =>
|
||||
_$PeerTableDataFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
@ -173,8 +173,8 @@ sealed class VeilidUpdate with _$VeilidUpdate {
|
||||
required ValueData valueData,
|
||||
}) = VeilidUpdateValueChange;
|
||||
|
||||
factory VeilidUpdate.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidUpdateFromJson(json);
|
||||
factory VeilidUpdate.fromJson(dynamic json) =>
|
||||
_$VeilidUpdateFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
@ -187,8 +187,8 @@ class VeilidStateAttachment with _$VeilidStateAttachment {
|
||||
required bool publicInternetReady,
|
||||
required bool localNetworkReady}) = _VeilidStateAttachment;
|
||||
|
||||
factory VeilidStateAttachment.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidStateAttachmentFromJson(json);
|
||||
factory VeilidStateAttachment.fromJson(dynamic json) =>
|
||||
_$VeilidStateAttachmentFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
@ -202,8 +202,8 @@ class VeilidStateNetwork with _$VeilidStateNetwork {
|
||||
required BigInt bpsUp,
|
||||
required List<PeerTableData> peers}) = _VeilidStateNetwork;
|
||||
|
||||
factory VeilidStateNetwork.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidStateNetworkFromJson(json);
|
||||
factory VeilidStateNetwork.fromJson(dynamic json) =>
|
||||
_$VeilidStateNetworkFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
@ -215,8 +215,8 @@ class VeilidStateConfig with _$VeilidStateConfig {
|
||||
required VeilidConfig config,
|
||||
}) = _VeilidStateConfig;
|
||||
|
||||
factory VeilidStateConfig.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidStateConfigFromJson(json);
|
||||
factory VeilidStateConfig.fromJson(dynamic json) =>
|
||||
_$VeilidStateConfigFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
@ -230,6 +230,6 @@ class VeilidState with _$VeilidState {
|
||||
required VeilidStateConfig config,
|
||||
}) = _VeilidState;
|
||||
|
||||
factory VeilidState.fromJson(Map<String, dynamic> json) =>
|
||||
_$VeilidStateFromJson(json);
|
||||
factory VeilidState.fromJson(dynamic json) =>
|
||||
_$VeilidStateFromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ dependencies:
|
||||
path_provider: ^2.0.9
|
||||
path: ^1.8.0
|
||||
system_info2: ^3.0.2
|
||||
system_info_plus: ^0.0.5
|
||||
charcode: ^1.3.1
|
||||
freezed_annotation: ^2.2.0
|
||||
json_annotation: ^4.8.1
|
||||
|
@ -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 rc = ROUTING_CONTEXTS.lock();
|
||||
while rc.contains_key(&next_id) {
|
||||
next_id += 1;
|
||||
}
|
||||
@ -382,7 +381,8 @@ pub extern "C" fn routing_context(port: i64) {
|
||||
DartIsolateWrapper::new(port).spawn_result(async move {
|
||||
let veilid_api = get_veilid_api().await?;
|
||||
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)
|
||||
});
|
||||
}
|
||||
@ -398,14 +398,14 @@ pub extern "C" fn release_routing_context(id: u32) -> i32 {
|
||||
|
||||
#[no_mangle]
|
||||
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 {
|
||||
return 0;
|
||||
};
|
||||
let Ok(routing_context) = routing_context.clone().with_privacy() else {
|
||||
return 0;
|
||||
};
|
||||
let new_id = add_routing_context(routing_context);
|
||||
let new_id = add_routing_context(&mut rc, routing_context);
|
||||
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 =
|
||||
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 {
|
||||
return 0;
|
||||
};
|
||||
let Ok(routing_context) = routing_context.clone().with_custom_privacy(safety_selection) else {
|
||||
return 0;
|
||||
};
|
||||
let new_id = add_routing_context(routing_context);
|
||||
let new_id = add_routing_context(&mut rc, routing_context);
|
||||
new_id
|
||||
}
|
||||
|
||||
@ -430,12 +430,12 @@ pub extern "C" fn routing_context_with_sequencing(id: u32, sequencing: FfiStr) -
|
||||
let sequencing: veilid_core::Sequencing =
|
||||
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 {
|
||||
return 0;
|
||||
};
|
||||
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
|
||||
}
|
||||
|
||||
@ -569,7 +569,7 @@ pub extern "C" fn routing_context_delete_dht_record(port: i64, id: u32, key: Ffi
|
||||
#[no_mangle]
|
||||
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();
|
||||
DartIsolateWrapper::new(port).spawn_result_opt_json(async move {
|
||||
DartIsolateWrapper::new(port).spawn_result_json(async move {
|
||||
let routing_context = {
|
||||
let rc = ROUTING_CONTEXTS.lock();
|
||||
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();
|
||||
|
||||
DartIsolateWrapper::new(port).spawn_result_opt_json(async move {
|
||||
DartIsolateWrapper::new(port).spawn_result_json(async move {
|
||||
let routing_context = {
|
||||
let rc = ROUTING_CONTEXTS.lock();
|
||||
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());
|
||||
|
||||
DartIsolateWrapper::new(port).spawn_result_json(async move {
|
||||
DartIsolateWrapper::new(port).spawn_result(async move {
|
||||
let veilid_api = get_veilid_api().await?;
|
||||
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()))?;
|
||||
@ -1412,6 +1412,7 @@ pub extern "C" fn crypto_decrypt_aead(port: i64, kind: u32, body: FfiStr, nonce:
|
||||
Some(ad) => Some(ad.as_slice()),
|
||||
None => None
|
||||
})?;
|
||||
let out = data_encoding::BASE64URL_NOPAD.encode(&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());
|
||||
|
||||
DartIsolateWrapper::new(port).spawn_result_json(async move {
|
||||
DartIsolateWrapper::new(port).spawn_result(async move {
|
||||
let veilid_api = get_veilid_api().await?;
|
||||
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()))?;
|
||||
@ -1444,6 +1445,7 @@ pub extern "C" fn crypto_encrypt_aead(port: i64, kind: u32, body: FfiStr, nonce:
|
||||
Some(ad) => Some(ad.as_slice()),
|
||||
None => None
|
||||
})?;
|
||||
let out = data_encoding::BASE64URL_NOPAD.encode(&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 =
|
||||
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 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()))?;
|
||||
csv.crypt_in_place_no_auth(&mut body, &nonce, &shared_secret);
|
||||
let body = data_encoding::BASE64URL_NOPAD.encode(&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 {
|
||||
match result {
|
||||
Ok(v) => self.ok(v),
|
||||
@ -78,16 +67,6 @@ impl DartIsolateWrapper {
|
||||
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 {
|
||||
self.isolate
|
||||
.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 {
|
||||
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
|
||||
where
|
||||
@ -120,14 +114,6 @@ where
|
||||
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
|
||||
where
|
||||
F: Future<Output = APIResult<T>> + 'static,
|
||||
@ -507,7 +493,7 @@ pub fn routing_context_get_dht_value(
|
||||
force_refresh: bool,
|
||||
) -> Promise {
|
||||
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 rc = (*ROUTING_CONTEXTS).borrow();
|
||||
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())
|
||||
.unwrap();
|
||||
|
||||
wrap_api_future_opt_json(async move {
|
||||
wrap_api_future_json(async move {
|
||||
let routing_context = {
|
||||
let rc = (*ROUTING_CONTEXTS).borrow();
|
||||
let Some(routing_context) = rc.get(&id) else {
|
||||
@ -1361,7 +1347,7 @@ pub fn crypto_decrypt_aead(
|
||||
.unwrap()
|
||||
});
|
||||
|
||||
wrap_api_future_json(async move {
|
||||
wrap_api_future(async move {
|
||||
let veilid_api = get_veilid_api()?;
|
||||
let crypto = veilid_api.crypto()?;
|
||||
let csv = crypto.get(kind).ok_or_else(|| {
|
||||
@ -1380,6 +1366,7 @@ pub fn crypto_decrypt_aead(
|
||||
None => None,
|
||||
},
|
||||
)?;
|
||||
let out = data_encoding::BASE64URL_NOPAD.encode(&out);
|
||||
APIResult::Ok(out)
|
||||
})
|
||||
}
|
||||
@ -1409,7 +1396,7 @@ pub fn crypto_encrypt_aead(
|
||||
.unwrap()
|
||||
});
|
||||
|
||||
wrap_api_future_json(async move {
|
||||
wrap_api_future(async move {
|
||||
let veilid_api = get_veilid_api()?;
|
||||
let crypto = veilid_api.crypto()?;
|
||||
let csv = crypto.get(kind).ok_or_else(|| {
|
||||
@ -1428,6 +1415,7 @@ pub fn crypto_encrypt_aead(
|
||||
None => None,
|
||||
},
|
||||
)?;
|
||||
let out = data_encoding::BASE64URL_NOPAD.encode(&out);
|
||||
APIResult::Ok(out)
|
||||
})
|
||||
}
|
||||
@ -1450,7 +1438,7 @@ pub fn crypto_crypt_no_auth(
|
||||
let shared_secret: veilid_core::SharedSecret =
|
||||
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 crypto = veilid_api.crypto()?;
|
||||
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);
|
||||
let out = data_encoding::BASE64URL_NOPAD.encode(&out);
|
||||
APIResult::Ok(body)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user