Skip to content

fix(ws): disambiguate Meshtastic feeder WebSocket for shared API keys#384

Merged
pskillen merged 6 commits into
mainfrom
api-383/paddy/mt-ws-feeder-disambiguation
Jun 2, 2026
Merged

fix(ws): disambiguate Meshtastic feeder WebSocket for shared API keys#384
pskillen merged 6 commits into
mainfrom
api-383/paddy/mt-ws-feeder-disambiguation

Conversation

@pskillen

@pskillen pskillen commented Jun 2, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add resolve_meshtastic_feeder() so Meshtastic feeders on a shared NodeAPIKey are identified by feeder_node_id or feeder_node_id_str (parity with MeshCore feeder_pubkey_prefix and MT HTTP ingest).
  • Refactor NodeConsumer to reject ambiguous shared-key WebSocket connects instead of silently using auths[0].
  • Fix mixed MC+MT shared-key case where a Meshtastic bot could be assigned the MeshCore feeder.
  • Update docs/API_KEYS.md, openapi.yaml, and docs/REDIS.md.

Closes #383

Companion bot PR: pskillen/meshflow-bot#123

Backward compatibility

This change is backward compatible for the normal volunteer setup: one Meshtastic bot (or one feeder) per API key. No new query parameters are required when only one ManagedNode is linked to the key.

Scenario WebSocket behaviour
One MT feeder per key (typical production) Unchanged — connect with ?api_key=… only
One MC feeder per key Unchanged
Bot sends feeder_node_id on a single-feeder key Harmless — API resolves the same node
HTTP packet ingest (/api/packets/{node_id}/ingest/) Unchanged

When this is a breaking change

WebSocket connect is rejected (instead of silently joining the wrong Channels group) only when the key is ambiguous:

  1. Multiple Meshtastic feeders on one key and the bot omits feeder_node_id / feeder_node_id_str. This matches pre-prod / integration-test setups; production volunteers almost always use one bot per key.
  2. One MeshCore + one Meshtastic feeder on the same key and neither disambiguator is sent (fixes incorrect routing to the MC node).
  3. Multiple MeshCore feeders on one key without feeder_pubkey_prefix — already rejected before this PR; behaviour unchanged.

After API deploy, case (1) stays broken for WS until the bot PR ships (feeder_node_id on the URL). Packet ingest for multi-feeder keys was already correct and remains so.

Deploy

  1. Merge and deploy this API PR first.
  2. Merge and deploy bot PR feat(messages): add packet_id and sender_node_id filter #123 immediately after (Meshtastic bots must send feeder_node_id).
  3. Pre-prod smoke test if you run two MT bots on one key: distinct group=node_* in API logs; traceroute reaches only the intended feeder.

Testing performed

  • python -m pytest Meshflow/ws/tests/ Meshflow/common/tests/test_meshtastic_feeder_auth.py -v (21 passed)
  • black, isort, flake8 on changed Python files

Mirror MeshCore feeder resolution so WebSocket and other callers can
pick the correct Meshtastic ManagedNode by nodenum when one key links
multiple feeders.
Accept feeder_node_id and feeder_node_id_str query params, reject
ambiguous shared-key connects, and stop assigning the MC feeder when
one MC and one MT share a key without disambiguators.
Describe feeder_node_id and feeder_node_id_str for shared Meshtastic
keys; update OpenAPI and Redis docs for ws/nodes disambiguation.
…ility

Add _channel_redis_host() with configurable socket timeouts (default 30s)
so channels_redis BZPOPMIN can outlive busy Redis on DB 1. Set
CELERY_RESULT_EXPIRES default to 3600s to limit result-key churn.
Stop writing celery-task-meta-* keys for high-frequency scheduled tasks
that do not use return values, reducing load on Redis DB 1.
@pskillen pskillen merged commit 3d99a6e into main Jun 2, 2026
2 checks passed
@pskillen pskillen deleted the api-383/paddy/mt-ws-feeder-disambiguation branch June 2, 2026 10:14
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.

Meshtastic: disambiguate feeder WebSocket when multiple ManagedNodes share one API key

2 participants