firmware icon indicating copy to clipboard operation
firmware copied to clipboard

[Feature Request]: CLIENT_BASE Improvements

Open tylerpieper opened this issue 1 month ago • 8 comments

Platform

Cross-Platform

Description

The CLIENT_BASE role introduced in #7863 works well for private Direct Messages (DMs) to and from favorited indoor companion nodes (CLIENT_MUTE or CLIENT). Because the base station checks isFromOrToFavoritedNode(*p), it prioritizes and guarantees retransmission for those specific packets.

However, public/broadcast channel messages (e.g. LongFast) have to = 0xFFFFFFFF, so a rooftop/attic CLIENT_BASE node cannot distinguish whether an incoming broadcast was intended for an indoor companion node in an RF shadow. As a result:

  1. The base station receives an incoming broadcast from the outdoor mesh.
  2. A nearby outdoor node also rebroadcasts it.
  3. The base station hears the duplicate and cancels its own rebroadcast via FloodingRouter::perhapsCancelDupe().
  4. The indoor node in the RF shadow never hears the outdoor neighbor and misses the broadcast entirely.

This limitation has been raised in several previous discussions and feature requests (#8820, #9195, #8366, #10704). A frequent concern from maintainers is that having a base station unconditionally rebroadcast all channel messages risks recreating ROUTER behavior in an attic, increasing channel utilization and noise on the wider mesh.


Proposed Solution: "CLIENT_BASE+"

Instead of outright canceling a broadcast when an outdoor duplicate is heard, the base station falls back to a dead-zone fill-in transmission:

  1. Compete as normal first: The node initially enqueues the broadcast in the standard contention window like a normal client.
  2. Contention fallback: If an outdoor node rebroadcasts first and triggers duplicate cancellation, do not drop the packet. Instead:
    • Clamp the packet into the late rebroadcast window (clampToLateRebroadcastWindow()).
    • Mutate the packet's remaining hops to hop_limit = 0 (ensuring terminal delivery; no downstream nodes will ever rebroadcast it).
    • Adjust hop_start so receiving indoor nodes compute the true hop distance accurately.
  3. Optional RF containment (power reduction): Because the fill-in broadcast only needs to penetrate nearby interior walls/windows, transmit this late zero-hop frame at reduced RF power (e.g., -3 dBm or -6 dBm relative to nominal tx_power).

Proposal Variants

1. CLIENT_BASE+ (Nominal TX Power, 0-hop late fill-in)

  • Behavior: When cancelled, moves the packet to the late window, sets hop_limit = 0, updates hop_start, and transmits at normal configured power.
  • Pros: Maximum penetration through heavy construction (concrete, metal siding, multiple floors).
  • Cons: Overheard by nearby outdoor neighbors (who will drop it via wasSeenRecently(), but still spend receive airtime decoding the packet).

2. CLIENT_BASE+(-3) (0-hop late fill-in at -3 dBm reduction / 50% power)

  • Behavior: Same as above, but drops output power by 3 dBm (half the RF wattage) for the fallback frame.
  • Pros: Noticeable reduction in outdoor spillover; 50% RF power reduction; maintains strong indoor SNR.
  • Cons: Requires a temporary radio power register write before transmission and restoration afterward.

3. CLIENT_BASE+(-6) (0-hop late fill-in at -6 dBm reduction / 25% power)

  • Behavior: Same as above, but drops output power by 6 dBm (one-quarter of nominal wattage).
  • Pros: Highly contained RF microcell. Effectively confines the fill-in frame to the immediate building footprint, causing near-zero interference to the outdoor mesh.
  • Cons: Same as above.

(Alternatively, this could be implemented as a single CLIENT_BASE configuration flag: client_base_broadcast_fillin = true with a configurable power backoff setting: 0 dB, -3 dB, or -6 dB.). Other power levels could be considered as well.


Firmware Code Integration Points

This mechanism hooks directly into existing primitives in meshtastic/firmware:

  1. Duplicate Cancellation Intercept (src/mesh/FloodingRouter.cpp)

    • In FloodingRouter::perhapsCancelDupe(const meshtastic_MeshPacket *p): Currently, when roleAllowsCancelingDupe(p) is true, the node calls Router::cancelSending(p->from, p->id).
      • Hook: For CLIENT_BASE+, instead of deleting the pending packet from the TX queue, mutate the queued packet:
        • Set tosend->hop_limit = 0;
        • Update tosend->hop_start = (p->hop_start - p->hop_limit) + 1; (see hop math below).
        • Mark a flag/tag on the queued packet indicating reduced TX power (if applicable).
        • Call iface->clampToLateRebroadcastWindow(getFrom(p), p->id);.
  2. Accurate Hop Calculation (NodeDB::getHopsAway())

    • Receiving nodes compute distance as: hops_away = hop_start - hop_limit.
    • Since hop_limit is forced to 0, the receiver computes hops_away = hop_start - 0 = hop_start.
    • Formula: To reflect the exact number of hops taken to reach the indoor node:
      outgoing.hop_start = (incoming.hop_start - incoming.hop_limit) + 1;
      outgoing.hop_limit = 0;
      
    • Safety check: Ensure outgoing.hop_start is never set to 0, preserving compatibility with modern bitfield distance tracking.
  3. Terminal Rebroadcast Guarantee (src/mesh/NextHopRouter.cpp)

    • In NextHopRouter::perhapsRebroadcast(const meshtastic_MeshPacket *p): Nodes gate rebroadcast on p->hop_limit > 0. Because the fill-in frame transmits with hop_limit == 0, every device that receives it processes and displays it locally, but zero nodes will ever relay it.
  4. Dynamic Transmit Power Control (src/mesh/RadioLibInterface.cpp)

    • In RadioLibInterface::startSend(meshtastic_MeshPacket *txp): Before calling iface->startTransmit(), inspect whether txp is marked for fallback attenuation:
      if (txp->is_fallback_fillin) {
          iface->setOutputPower(clamped_reduced_power);
      }
      
    • In RadioLibInterface::completeSending() / handleTransmitInterrupt(): Restore nominal transmit power (power = config.lora.tx_power) so future regular packets are unaffected.

Pros & Cons Summary

Metric Current CLIENT_BASE CLIENT_BASE+ (Full Power) CLIENT_BASE+(-3 / -6 dBm)
Indoor Broadcast Delivery ❌ Could miss broadcasts if outdoor neighbor rebroadcasts ✅ Guaranteed delivery via late window ✅ Guaranteed delivery via late window
Outdoor Contention Interference ✅ None (cancels) ⚠️ Minimal (waits for late window, but full power) ✅ Negligible (waits for late window + confined RF footprint)
Airtime Utilization Lowest Moderate (1 local frame per overheard broadcast) Moderate airtime, but low RF energy
Implementation Complexity Baseline Low (uses existing clampToLateRebroadcastWindow) Moderate (adds dynamic power swap & restore)

Prior Art & Related Issues

  • #7863 – Feature Request: CLIENT_BASE mode: ROUTER for favorites, CLIENT otherwise
  • #8820 – Feature Request: Retransmit messages received in public channel to favorite nodes from CLIENT_BASE node
  • #8366 – Feature Request: CLIENT_BASE should not decrement hop count for favorites
  • #10704 – Feature Request: Ask roof node for missing broadcast messages (S&F with 0-hop answer)

tylerpieper avatar Oct 13 '26 19:10 tylerpieper

Traffic can be further reduced to only text messages. That way only messages that the client_base can decrypt will have a forwarding guarantee. People handle dropped packets differently than machines.

luivicur avatar Oct 14 '26 01:10 luivicur

A frequent concern from maintainers is that having a base station unconditionally rebroadcast all channel messages risks recreating ROUTER behavior in an attic, increasing channel utilization and noise on the wider mesh.

ROUTER behavior? I always thought, for favorited nodes and isFrom, it has been ROUTER_LATE instead of ROUTER behavior since end of 2025. So, late rebroadcast window instead of early. Good so surrounding CLIENTs have a chance to rebroadcast first.

That was done in https://github.com/meshtastic/firmware/issues/8844, merged MR https://github.com/meshtastic/firmware/pull/8567

shalberd avatar Oct 14 '26 05:10 shalberd

Traffic can be further reduced to only text messages. That way only messages that the client_base can decrypt will have a forwarding guarantee. People handle dropped packets differently than machines.

I do like this and would be in support of this. There is the downside that it would not support any text messages on a channel not known to the client_base, but I think it is somewhat safe to assume that the client base would share most/all of the private channels with the nodes it is supporting. But that might not be the case for all use cases so it will need to be considered.

ROUTER behavior? I always thought, for favorited nodes and isFrom, it has been ROUTER_LATE instead of ROUTER behavior since end of 2025. So, late rebroadcast window instead of early. Good so surrounding CLIENTs have a chance to rebroadcast first.

Yeah Client_Base will router_late traffic to or from a favorited node if it hears another node go first (instead of cancelling). But it does not rebroadcast channel/broadcast messages reliably if there are other nodes nearby that could cause the client_base to cancel its rebroadcast. My proposal adds that in as a 0 hops remaining gap filler.

tylerpieper avatar Oct 14 '26 06:10 tylerpieper

We have already tested similar firmware patches on our network, and the results are very satisfactory. Only with a patch like this clients around client_base can participate in public chats.

And a note regarding zeroing the hop limit: if other nodes have already seen this packet, it makes absolutely no difference to them what the hop limit of this particular duplicate is; conversely, if they have NOT seen it, resetting the limit would effectively bury the packet—preventing it from being forwarded to someone who hasn't received it yet.

sibrat avatar Oct 16 '26 01:10 sibrat

Some field data for this issue, plus an alternative variant of the fix.

Setup

  • Base: Heltec V3, fw 2.7.26, USB powered, at the rural edge of a ~65-node city mesh (RU 869 MHz, MEDIUM_FAST, channel utilization 5-10%).
  • Companion: nRF52 ProMicro DIY, fw 2.7.16, role CLIENT, weak antenna. Its only reliable direct neighbor is the base (SNR +10.75). Every other neighbor is at about -9.5 dB or below and is heard rarely.
  • The problem got much worse after the local mesh moved from MEDIUM_SLOW to MEDIUM_FAST. We lose about 2.5 dB of link budget, and the companion lost its marginal direct links to the outdoor mesh. As a result it now depends entirely on the base.

Measurements (LocalStats)

Base as CLIENT_BASE (3.7 h) Base as ROUTER_LATE (~1 h)
Unique packets heard by base ~139/h ~192/h
Base rebroadcasts 19/h 183/h
Base numTxRelayCanceled 114/h 0
Share of heard packets relayed by base ~14% ~95%
Base airUtilTx 0.10% 1.16%
Channel utilization at base 5.5% 5.2%
Unique packets received by companion ~26/h (~19% of base) ~169/h (~88% of base)

The companion's NodeDB also filled up much faster after the switch: 44 → 65 nodes. Before the switch, new nodes appeared on it very slowly after a NodeDB reset, because NodeInfo broadcasts are subject to the same cancellation.

Caveat: the ROUTER_LATE window is short and starts right after a reboot, so airUtilTx is probably somewhat inflated. A longer measurement is running.

So the mechanism in the issue description is confirmed. About 85% of the base's rebroadcasts were cancelled because an outdoor node relayed first. The companion never hears that outdoor node.

Alternative variant: cancel only if a favorite already has the packet

In perhapsCancelDupe(), for CLIENT_BASE with at least one favorited node:

  • If the duplicate's relay_node matches the last byte of a favorited node, the favorite already has the packet. Cancel, as today.
  • Otherwise, don't cancel. Instead call clampToLateRebroadcastWindow(), the same as for favorited from/to packets today.
  • With no favorites, behavior is unchanged.

PacketHistory already tracks relayed_by[], so the same check can also cover a favorite that relayed before the base queued its copy.

This can be combined with the 0-hop fill-in from the proposal: skip if a favorite already relayed it, otherwise send a late copy, with hop_limit = 0 if preferred. I agree with @sibrat that zeroing hop_limit buys little, though.

Limitations, to be upfront:

  • With a deaf companion like ours, it saves no airtime compared to ROUTER_LATE, because the companion can never relay first. The savings come where the companion sometimes hears the outdoor mesh directly, which is typical for indoor/apartment setups.
  • It needs the favorite to be a rebroadcaster. A CLIENT_MUTE favorite never relays, so the base would fill in everything.
  • relay_node is one byte, so occasional false cancels are possible (~1/256 per neighbor).

I'm preparing a patch and will test it on the same pair of nodes (base back to CLIENT_BASE, companion favorited), comparing against the ROUTER_LATE numbers above. I'll open a PR referencing this issue if it holds up.

curlysasha avatar Oct 16 '26 11:10 curlysasha

Follow-up: the patch is up as #12180 (queued for 2.8.3). A few corrections to my comment above, so it matches what the PR actually does:

  • relayed_by[] is not used. I wrote that PacketHistory relayed_by[] could also cover a favorite that relayed before the base queued its copy. That doesn't hold: it only records nodes that relayed the base's own copy, so it can't tell whether the favorite already had the packet. The PR only checks the relay_node of the duplicate the base hears while its copy is still queued.
  • Relay byte collisions. Instead of matching the last byte directly, the PR resolves it with NodeDB::resolveUniqueLastByte(). If the byte is ambiguous, the base doesn't cancel and fills in instead, so a collision can no longer cause a false cancel.
  • Only direct favorites count. The check applies to favorites at hops_away == 0. A favorite the base can't hear directly doesn't affect cancellation.
  • Airtime saving was better than I expected. I said a deaf companion would save nothing compared to ROUTER_LATE. In the field test, the companion's own relay proved it already had the packet for about half of the broadcasts, so the base skipped those. Numbers are in the PR.

curlysasha avatar Oct 17 '26 16:10 curlysasha

@curlysasha I think the whole favorite handling is extra work that isn't necessary. I imagine most users will have more than one node under a client_base (and in the base's favorites) so that would always cause a rebroadcast.

I already don't like have client_base favorites both do the router_late handling as well as zero-hop routing so adding another behavior for favorites on client_base is meh for me.

tylerpieper avatar Oct 17 '26 16:10 tylerpieper

I would also not look at hops_away in the nodedb because a favorite node could be mostly quiet (client_mute) and recently arrived at the client_base, and the base would not be aware of its presence. The client_base should just always assume there's a node under it that needs the fill-in.

tylerpieper avatar Oct 17 '26 16:10 tylerpieper