fix(#550): poll CoreScope with backoff, not once at T+0

Observer counts accrue over time (the packet must propagate the mesh and be
reported before CoreScope has any record), so an instant query at send+0.2s
always missed it. Now polls at ~10/30/60/120s, keeping the highest count as
observers report in; bails on disconnect. Part of #524.

Agent: QuietSnow (session 31eaba02)
pull/556/head
Strycher 2 months ago
parent da322d79d9
commit dd6d46bff9

@ -4754,6 +4754,17 @@ class MeshCoreConnector extends ChangeNotifier {
/// After sending a channel message, fetch its firmware hash then CoreScope's /// After sending a channel message, fetch its firmware hash then CoreScope's
/// observer count and stamp both on the message. Best-effort and gated; any /// observer count and stamp both on the message. Best-effort and gated; any
/// failure leaves the message showing radio-only. /// failure leaves the message showing radio-only.
/// Backoff schedule for polling CoreScope after a send. Observer counts
/// accrue over time: the packet must propagate the mesh and be reported by
/// observers before CoreScope has any record, then the count keeps climbing
/// for a few seconds. Cumulative wall-clock: ~10s, 30s, 60s, 120s.
static const List<Duration> _coreScopePollSchedule = [
Duration(seconds: 10),
Duration(seconds: 20),
Duration(seconds: 30),
Duration(seconds: 60),
];
Future<void> _fetchAndStoreCoreScopeCount( Future<void> _fetchAndStoreCoreScopeCount(
int channelIndex, int channelIndex,
int ts, int ts,
@ -4774,15 +4785,23 @@ class MeshCoreConnector extends ChangeNotifier {
messageId, messageId,
(m) => m.copyWith(onAirHash: pkt.hashHex), (m) => m.copyWith(onAirHash: pkt.hashHex),
); );
final count = await _coreScopeService.fetchObserverCount(pkt.hashHex); // Poll with backoff, keeping the highest count as observers report in.
if (count == null) return; var best = 0;
_updateChannelMessageById( for (final delay in _coreScopePollSchedule) {
channelIndex, await Future<void>.delayed(delay);
messageId, if (!isConnected) return;
(m) => m.copyWith(coreScopeObserverCount: count), final count = await _coreScopeService.fetchObserverCount(pkt.hashHex);
); if (count != null && count > best) {
appLogger.info('stored observer count=$count', tag: 'CoreScope'); best = count;
notifyListeners(); _updateChannelMessageById(
channelIndex,
messageId,
(m) => m.copyWith(coreScopeObserverCount: count),
);
appLogger.info('observer count=$count', tag: 'CoreScope');
notifyListeners();
}
}
} catch (e) { } catch (e) {
appLogger.warn( appLogger.warn(
'CoreScope observer-count fetch failed: $e', 'CoreScope observer-count fetch failed: $e',

Loading…
Cancel
Save

Powered by TurnKey Linux.