Skip to content

Skip Android cellular interface - #131

Merged
al8n merged 2 commits into
al8n:mainfrom
wkornewald:android-cellular
Aug 18, 2026
Merged

al8n merged 2 commits into
al8n:mainfrom
wkornewald:android-cellular

Conversation

@wkornewald

Copy link
Copy Markdown
Contributor

This is based on a battery drain fix in Syncthing: syncthing/syncthing#10504

Running mDNS on the cellular interface makes no sense and only drains battery.

This PR also deduplicates the existing interface filtering code and provides convenience helpers for retrieving the list of all interfaces for use with mDNS.

This is based on a battery drain fix in Syncthing: syncthing/syncthing#10504

Running mDNS on the cellular interface makes no sense and only drains battery.

This PR also deduplicates the existing interface filtering code and provides convenience helpers for retrieving the list of all interfaces for use with mDNS.
@codecov

codecov Bot commented Aug 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.37864% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.38%. Comparing base (38502f4) to head (b5bb50e).

Files with missing lines Patch % Lines
hick-udp/src/interfaces.rs 87.37% 13 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #131      +/-   ##
==========================================
- Coverage   92.49%   92.38%   -0.11%     
==========================================
  Files          94       95       +1     
  Lines       17412    17295     -117     
==========================================
- Hits        16105    15978     -127     
- Misses       1307     1317      +10     
Files with missing lines Coverage Δ
hick-compio/src/endpoint.rs 76.68% <ø> (-5.76%) ⬇️
hick-mio/src/socket.rs 90.51% <ø> (-0.58%) ⬇️
hick-reactor/src/endpoint.rs 73.85% <ø> (-8.53%) ⬇️
hick-udp/src/interfaces.rs 87.37% <87.37%> (ø)

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 38502f4...b5bb50e. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@al8n al8n left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this — the extraction is something we already wanted (it's #130's recommendation, filed before this PR arrived), and you've done the hard part well. Worth saying up front what I checked and found good:

  • the extracted rank_candidates preserves the relevance gate added in #128, so a candidate that cannot outrank the incumbent still isn't probed;
  • the tier scheme reproduces the original four effective tiers;
  • lib test count is unchanged at 582 across the four crates, despite removing 1064 lines — the consolidation kept coverage rather than deleting it;
  • clippy is clean;
  • index 0 is still refused, matching all three originals.

Two things need changing before merge, and one of them is unrelated to the feature you came to add.

Blocking: the extraction is not behaviour-preserving — it adds a RUNNING requirement

qualifies and fallback_qualifies both require Flags::RUNNING. None of the three predicates they replace did:

on main
hick-mio/src/socket.rs:2651 UP && MULTICAST && !LOOPBACK
hick-reactor/src/endpoint.rs:356 UP && MULTICAST && !LOOPBACK
hick-compio/src/endpoint.rs:441 UP && MULTICAST && !LOOPBACK
loopback fallback (all three) LOOPBACK && UP

Concretely: on Linux/Android an Ethernet interface that is UP|MULTICAST and still holds its static address, but has momentarily lost carrier, no longer has RUNNING. All three drivers previously ranked it a real link; now it is discarded and the default picker falls to loopback — or returns NotFound.

The part that makes it more than a hiccup is that the pick is a snapshot. When carrier returns, nothing migrates the endpoint: it stays on loopback for the process's life. And on Linux an IPv4 multicast join does not require carrier, so the old behaviour of joining anyway and becoming useful on carrier-up was doing real work.

This is an availability regression on all three drivers, and it has nothing to do with Android cellular. Please restore the UP-only requirement for parity. If rejecting non-running links is something you want, it's a reasonable idea — but it needs its own PR with a story for re-selection when the link comes back.

The Android rule: load-bearing, but it isn't a cellular classifier

I asked whether the POINTOPOINT check was doing real work given the module says VPN TUNs "do not support multicast anyway". Answer: it is load-bearing — raw-IP cellular drivers advertise MULTICAST, so the check placed before the multicast test is what catches them. That makes the VPN sentence the redundant half of the justification, not the operative one, and the module docs currently read the other way round.

But it misfires in both directions:

  • False positive. AOSP TUN and PPP devices initialise as POINTOPOINT|NOARP|MULTICAST. A configuration that preserves those flags and genuinely carries mDNS is now hidden from acceptable_mdns_interfaces and from every default picker. Ordinary VpnService TUNs usually clear MULTICAST, so this is narrower than it sounds — but it isn't empty.
  • False negative. qmi_wwan in Ethernet mode presents BROADCAST|MULTICAST with no POINTOPOINT. An addressed cellular link in that mode stays eligible and still wakes the radio — which is the battery drain the PR exists to prevent.

I'm not asking you to solve cellular detection properly; that needs platform network capabilities, which this crate can't reach. What I'd like is for the code and docs to stop claiming more than the heuristic delivers: describe it as "skip point-to-point on Android, which catches most cellular", note both gaps, and give callers an explicit override so a legitimate P2P multicast link can be used.

Public API, worth getting right before the release boundary

interface_tier cannot reproduce the ranking it promises. It returns the flags-derived base (Some(0) / Some(2)), but rank_candidates later adjusts to 1 or 3 when a requested family has no address. So: interface A has IPv4 only and comes first, B has both. interface_tier returns Some(0) for both, while pick_default_interface_index(true, true) ranks A as 1 and B as 0 and picks B. The doc says an app's own ranking "can never disagree" with the pick — as written, it can. Either make it private, or rename to interface_base_tier and drop the promise; a family-aware ranking API with a semantic type would be better than raw u8 tiers if you want to expose this at all.

ForcedEnumerationError is reachable from a normal feature. It's a public fieldless type, so it's auto-Send, and its Drop clears only the current thread's TLS — move the guard across threads and the creating thread stays injected forever. It also stores no previous value, so force(V4); force(V6); drop(inner) clears the still-live outer injection. Please give it private state holding the prior value, restore that on drop, and make it non-Send — or don't expose it through an ordinary public feature at all.

Minor

cargo fmt fails.


To be clear about the shape of this: the extraction is welcome and I'd like it to land. The blocking item is the RUNNING gate, which I think slipped in unintentionally while consolidating three predicates into one — that one is a two-line revert.

If any of the rest is more than you want to take on, say which parts and I'll pick them up — the API narrowing and the test-guard fix are both fine for us to do on top. The extraction itself is the valuable part and I'd rather it land than stall on the trimmings.

@wkornewald

wkornewald commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Regarding RUNNING: This was added explicitly in the linked PR, too. Otherwise you'll only get errors on a non-RUNNING interface. The bigger problem is that Hick doesn't have a mechanism to use mDNS on all acceptable interfaces in parallel. One has to build the interface change monitoring separately on top of this library (like I've done in my Iroh mDNS lookup). And for that I think you really want to respect RUNNING, too. Maybe only for the default interface helper it would be OK to ignore RUNNING. Should I really change that? (I've already pushed the change in my latest commit)

In general, Hick's default interface binding makes no sense. It would be better to provide an on_interfaces_changed() hook that can be triggered via external logic (e.g. on Android you need to interact with Android APIs to observe changes) and change Hick to support binding to all acceptable interfaces in parallel and allow optionally filtering the acceptable list (the underlying building block should still be per-interface binding of course). But a "default interface" - what use-case is that? Devices with only a single multicast interface (e.g. only WiFi, no LAN)? My MacBook is connected via LAN most of the time and sometimes via WiFi. Hick's default behavior wouldn't handle that correctly. My phone switches between WiFi and cellular all the time. Again, Hick's default behavior wouldn't handle that correctly. By offering the current half-working default, Hick nudges people into writing buggy software.

Regarding "Android rule":

The false positive claim seems to be an LLM hallucination because in practice TUN is only usable with VpnService and we never want to send mDNS/multicast packets across TUN devices.

The false negative claim also seems to be an LLM hallucination. In the source https://github.com/torvalds/linux/blob/master/drivers/net/usb/qmi_wwan.c you'll find that the interface is set up with:

dev->flags           = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST;

The other issue like cargo fmt should be fixed now.

@al8n al8n left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on b5bb50e: the RUNNING split (strict enumeration keeps it, lenient picker drops it) is a better answer than either of our starting positions, interface_tier is out of the public surface, and the test guard now stores prev, restores on Drop, and is non-Send. fmt and clippy clean, lib tests 582 → 586.

Thanks also for the architectural point — you were right, and it is now #133, credited to your comment. Worth reading before anyone acts on it: I recorded a hazard the "one endpoint per interface" advice walks into on a multi-homed host, where two links on one broadcast domain announce the same name with different addresses and the host conflicts with itself under §9.

One doc line to fix after merge, which I will take rather than send you another round: the module says VPN TUN interfaces "do not support multicast anyway". tun_net_initialize sets IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST, so they do — the rule is right, the stated reason is not. (Same check on qmi_wwan: qmi_wwan_netdev_setup has two branches, and the ether_setup one has no POINTOPOINT, so 802.3 mode escapes the test. Narrow in practice, since raw-IP is the Android norm.)

Approving.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants