diff --git a/veilid-core/src/rpc_processor/mod.rs b/veilid-core/src/rpc_processor/mod.rs index 4d3dee31..b4a06628 100644 --- a/veilid-core/src/rpc_processor/mod.rs +++ b/veilid-core/src/rpc_processor/mod.rs @@ -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 diff --git a/veilid-flutter/example/pubspec.lock b/veilid-flutter/example/pubspec.lock index f3b8af02..b121351f 100644 --- a/veilid-flutter/example/pubspec.lock +++ b/veilid-flutter/example/pubspec.lock @@ -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: diff --git a/veilid-flutter/lib/default_config.dart b/veilid-flutter/lib/default_config.dart index 3917842f..815c0793 100644 --- a/veilid-flutter/lib/default_config.dart +++ b/veilid-flutter/lib/default_config.dart @@ -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 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 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 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, diff --git a/veilid-flutter/pubspec.yaml b/veilid-flutter/pubspec.yaml index 1adadf0e..d4638878 100644 --- a/veilid-flutter/pubspec.yaml +++ b/veilid-flutter/pubspec.yaml @@ -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