Move send controls into Routing and split retry limits
Direct and flood attempts are separate settings, available with auto route rotation off. Saved single retry limits migrate to that split, and reset restores the whole Routing section. Co-authored-by: zjs81 <zjs81@users.noreply.github.com>
This commit is contained in:
69 files changed
+2199
-784
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import 'custom_theme.dart';
|
||||
import 'image_codec_support.dart';
|
||||
import 'send_attempt_plan.dart';
|
||||
import 'translation_support.dart';
|
||||
|
||||
enum UnitSystem { metric, imperial }
|
||||
@@ -103,7 +104,9 @@ class AppSettings {
|
||||
static const double defaultInitialRouteWeight = 3.0;
|
||||
static const double defaultRouteWeightSuccessIncrement = 0.5;
|
||||
static const double defaultRouteWeightFailureDecrement = 0.2;
|
||||
static const int defaultMaxMessageRetries = 5;
|
||||
static const int defaultDirectRetries = SendAttemptPlan.defaultDirectRetries;
|
||||
static const int defaultFloodRetries = SendAttemptPlan.defaultFloodRetries;
|
||||
static const int defaultLoginAttempts = SendAttemptPlan.defaultLoginAttempts;
|
||||
|
||||
final bool clearPathOnMaxRetry;
|
||||
final bool mapShowRepeaters;
|
||||
@@ -137,7 +140,11 @@ class AppSettings {
|
||||
final double initialRouteWeight;
|
||||
final double routeWeightSuccessIncrement;
|
||||
final double routeWeightFailureDecrement;
|
||||
final int maxMessageRetries;
|
||||
final int directRetries;
|
||||
final int floodRetries;
|
||||
|
||||
/// How many times a repeater or room-server login is sent before giving up.
|
||||
final int loginAttempts;
|
||||
final bool channelMinHopsEnabled;
|
||||
final int channelMinHops;
|
||||
final int channelMinHopsRetries;
|
||||
@@ -236,6 +243,16 @@ class AppSettings {
|
||||
downloadedModels: imageCodecDownloadedModels,
|
||||
);
|
||||
|
||||
/// Attempts for one direct message. [rotating] is auto route rotation with
|
||||
/// no manual path. [floodPath] is the contact's fixed path.
|
||||
int sendAttemptLimit({required bool rotating, required bool floodPath}) {
|
||||
return SendAttemptPlan(
|
||||
directRetries: directRetries,
|
||||
floodRetries: floodRetries,
|
||||
rotateRoutes: rotating,
|
||||
).attemptLimit(floodPath: floodPath);
|
||||
}
|
||||
|
||||
String get effectiveMapTileApiKey {
|
||||
final apiKey = mapTileApiKey?.trim();
|
||||
if (apiKey == null || apiKey.isEmpty) {
|
||||
@@ -291,7 +308,9 @@ class AppSettings {
|
||||
this.initialRouteWeight = defaultInitialRouteWeight,
|
||||
this.routeWeightSuccessIncrement = defaultRouteWeightSuccessIncrement,
|
||||
this.routeWeightFailureDecrement = defaultRouteWeightFailureDecrement,
|
||||
this.maxMessageRetries = defaultMaxMessageRetries,
|
||||
this.directRetries = defaultDirectRetries,
|
||||
this.floodRetries = defaultFloodRetries,
|
||||
this.loginAttempts = defaultLoginAttempts,
|
||||
this.channelMinHopsEnabled = false,
|
||||
this.channelMinHops = 2,
|
||||
this.channelMinHopsRetries = 1,
|
||||
@@ -389,7 +408,9 @@ class AppSettings {
|
||||
'initial_route_weight': initialRouteWeight,
|
||||
'route_weight_success_increment': routeWeightSuccessIncrement,
|
||||
'route_weight_failure_decrement': routeWeightFailureDecrement,
|
||||
'max_message_retries': maxMessageRetries,
|
||||
'max_direct_retries': directRetries,
|
||||
'max_flood_retries': floodRetries,
|
||||
'login_attempts': loginAttempts,
|
||||
'channel_min_hops_enabled': channelMinHopsEnabled,
|
||||
'channel_min_hops': channelMinHops,
|
||||
'channel_min_hops_retries': channelMinHopsRetries,
|
||||
@@ -539,8 +560,11 @@ class AppSettings {
|
||||
routeWeightFailureDecrement:
|
||||
(json['route_weight_failure_decrement'] as num?)?.toDouble() ??
|
||||
defaultRouteWeightFailureDecrement,
|
||||
maxMessageRetries:
|
||||
json['max_message_retries'] as int? ?? defaultMaxMessageRetries,
|
||||
directRetries: SendAttemptPlan.retriesFromJson(json).direct,
|
||||
floodRetries: SendAttemptPlan.retriesFromJson(json).flood,
|
||||
loginAttempts: SendAttemptPlan.clampLogin(
|
||||
(json['login_attempts'] as num?)?.toInt() ?? defaultLoginAttempts,
|
||||
),
|
||||
channelMinHopsEnabled: json['channel_min_hops_enabled'] as bool? ?? false,
|
||||
channelMinHops: json['channel_min_hops'] as int? ?? 2,
|
||||
channelMinHopsRetries: json['channel_min_hops_retries'] as int? ?? 1,
|
||||
@@ -698,7 +722,9 @@ class AppSettings {
|
||||
double? initialRouteWeight,
|
||||
double? routeWeightSuccessIncrement,
|
||||
double? routeWeightFailureDecrement,
|
||||
int? maxMessageRetries,
|
||||
int? directRetries,
|
||||
int? floodRetries,
|
||||
int? loginAttempts,
|
||||
bool? channelMinHopsEnabled,
|
||||
int? channelMinHops,
|
||||
int? channelMinHopsRetries,
|
||||
@@ -791,7 +817,9 @@ class AppSettings {
|
||||
routeWeightSuccessIncrement ?? this.routeWeightSuccessIncrement,
|
||||
routeWeightFailureDecrement:
|
||||
routeWeightFailureDecrement ?? this.routeWeightFailureDecrement,
|
||||
maxMessageRetries: maxMessageRetries ?? this.maxMessageRetries,
|
||||
directRetries: directRetries ?? this.directRetries,
|
||||
floodRetries: floodRetries ?? this.floodRetries,
|
||||
loginAttempts: loginAttempts ?? this.loginAttempts,
|
||||
channelMinHopsEnabled:
|
||||
channelMinHopsEnabled ?? this.channelMinHopsEnabled,
|
||||
channelMinHops: channelMinHops ?? this.channelMinHops,
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
/// How many times a direct message is sent, split by route kind.
|
||||
///
|
||||
/// Direct attempts use a known route. Flood attempts ask the mesh to flood.
|
||||
/// With [rotateRoutes] on (and no manual path), the direct attempts run first
|
||||
/// and the flood attempts follow. With it off, every attempt stays on the
|
||||
/// contact's current path and only that path's limit applies.
|
||||
class SendAttemptPlan {
|
||||
static const int minDirectRetries = 0;
|
||||
static const int maxDirectRetries = 15;
|
||||
static const int defaultDirectRetries = 4;
|
||||
|
||||
static const int minFloodRetries = 0;
|
||||
static const int maxFloodRetries = 10;
|
||||
|
||||
/// One flood, matching the previous single limit of 5 whose last attempt
|
||||
/// flooded when auto route rotation was on (4 direct + 1 flood).
|
||||
static const int defaultFloodRetries = 1;
|
||||
|
||||
static const int minLoginAttempts = 1;
|
||||
static const int maxLoginAttempts = 10;
|
||||
static const int defaultLoginAttempts = 5;
|
||||
|
||||
final int directRetries;
|
||||
final int floodRetries;
|
||||
|
||||
/// When true, direct attempts may change route and are followed by floods.
|
||||
final bool rotateRoutes;
|
||||
|
||||
const SendAttemptPlan({
|
||||
required this.directRetries,
|
||||
required this.floodRetries,
|
||||
required this.rotateRoutes,
|
||||
});
|
||||
|
||||
static int clampDirect(int value) =>
|
||||
value.clamp(minDirectRetries, maxDirectRetries);
|
||||
|
||||
static int clampFlood(int value) =>
|
||||
value.clamp(minFloodRetries, maxFloodRetries);
|
||||
|
||||
static int clampLogin(int value) =>
|
||||
value.clamp(minLoginAttempts, maxLoginAttempts);
|
||||
|
||||
/// Reads the split limits, or derives them from the old single
|
||||
/// `max_message_retries` value. That value was a total: every attempt but
|
||||
/// the last used a route, then one attempt flooded.
|
||||
static ({int direct, int flood}) retriesFromJson(Map<String, dynamic> json) {
|
||||
final direct = json['max_direct_retries'];
|
||||
final flood = json['max_flood_retries'];
|
||||
if (direct is num || flood is num) {
|
||||
return (
|
||||
direct: clampDirect(
|
||||
direct is num ? direct.toInt() : defaultDirectRetries,
|
||||
),
|
||||
flood: clampFlood(flood is num ? flood.toInt() : defaultFloodRetries),
|
||||
);
|
||||
}
|
||||
final legacy = json['max_message_retries'];
|
||||
if (legacy is num) {
|
||||
return (
|
||||
direct: clampDirect(legacy.toInt() - 1),
|
||||
flood: defaultFloodRetries,
|
||||
);
|
||||
}
|
||||
return (direct: defaultDirectRetries, flood: defaultFloodRetries);
|
||||
}
|
||||
|
||||
/// How many times to send before giving up.
|
||||
///
|
||||
/// [floodPath] is the contact's fixed path. It is ignored while rotating,
|
||||
/// because those sends spend [directRetries] then [floodRetries]. A plan
|
||||
/// with both limits at 0 still sends once, on the current path.
|
||||
int attemptLimit({required bool floodPath}) {
|
||||
if (rotateRoutes) {
|
||||
final total = directRetries + floodRetries;
|
||||
return total < 1 ? 1 : total;
|
||||
}
|
||||
final count = floodPath ? floodRetries : directRetries;
|
||||
return count < 1 ? 1 : count;
|
||||
}
|
||||
|
||||
/// First attempt index that should flood, or null when this plan never
|
||||
/// switches onto a flood (rotation off, or no flood attempts configured).
|
||||
int? get floodFromAttempt {
|
||||
if (!rotateRoutes || floodRetries < 1) return null;
|
||||
return directRetries;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user