Skip to content

fix(hub): reject a second register from an already registered agent - #161

Merged
jamofer merged 1 commit into
mainfrom
fix/hub1-reject-duplicate-register
Jul 27, 2026
Merged

fix(hub): reject a second register from an already registered agent#161
jamofer merged 1 commit into
mainfrom
fix/hub1-reject-duplicate-register

Conversation

@jamofer

@jamofer jamofer commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

What

Reject a second REGISTER from an agent peer that is already registered.

Why

InterfaceRegistry_RegisterAgent restarted agent_channel at 0 on every call and never checked the peer, so a second REGISTER on a live connection created duplicate (peer_id, channel) keys. FindByAgentChannel always resolved to the stale entry, and the agent's ChannelMap had already been reassigned by the second ACK. Audit finding HUB-1 (HIGH).

Path Effect before
hub -> agent writes hub and agent disagree on the channel meaning: frames injected on the wrong CAN bus
agent -> hub frames routed to the old interface_id; wrong fan-out, wrong counters and shaper entry
LIST / admin advertise interfaces that never carry traffic
identity HubPeer_SetAgentName overwrites the peer name while the registry keeps the old one
resource one agent fills all 256 registry slots in 16 messages

How

Guard in the registry domain (the "one registration per peer_id" invariant belongs there), before the collision check: reject with REGISTER_STATUS_REJECTED. No broker change — the existing !registered path already sends the ack and disconnects, and the early return keeps the peer name in sync. Reusing status 1 means no wire or protocol.md change. Both disconnect paths clear the registry, so a reconnecting agent is never blocked; ghost displacement (#146/#149) is unaffected because it always involves a different peer_id.

Testing

  • make test green (405 tests)
  • Removed the guard locally to confirm the 3 new tests fail without it

Notes

No wire-format impact. The reference agent sends REGISTER once per connection, so no legitimate flow is affected.

@jamofer
jamofer merged commit dd59e5e into main Jul 27, 2026
6 checks passed
@jamofer
jamofer deleted the fix/hub1-reject-duplicate-register branch July 27, 2026 12:02
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.

1 participant