Skip to content

Consolidate internal duplication#150

Merged
gafferongames merged 2 commits into
mainfrom
dedup
Jul 9, 2026
Merged

Consolidate internal duplication#150
gafferongames merged 2 commits into
mainfrom
dedup

Conversation

@gafferongames

Copy link
Copy Markdown
Contributor

Summary

Removes the internal duplication flagged in CLAUDE.md — no public header change, no wire change, net −116 lines:

  1. netcode_server_process_packet delegates to netcode_server_read_and_process_packet instead of duplicating its ~45-line body (the pair where a fix to one had to be remembered in the other).
  2. Client receive loops feed netcode_client_process_packet — the public entry point — instead of inlining the allowed-packets table + netcode_read_packet call in two more places.
  3. netcode_address_to_sockaddr / netcode_sockaddr_to_address replace the IPv4/IPv6 conversions repeated across socket create (bind + getsockname), send, and receive.
  4. netcode_send_packet_to_address unifies the simulator/override/socket dispatch shared by the client send path and both server send paths.
  5. netcode_server_reset_client_slot shares queue drain + slot reset between normal and loopback disconnect.

Only observable behavior difference: the client samples time(NULL) per packet instead of per receive batch (whole-second token-expiry timestamp — no functional change).

Verification

  • 42/42 tests in Release, Debug, ASan+UBSan
  • Fuzz corpus (300 fresh random + saved adversarial + past crash inputs) replays clean under ASan on all three harnesses
  • client_server example end-to-end over real sockets
  • 45s ASan soak: 5,913 client connections churned through the refactored packet/send/reset paths, zero findings
  • CI green on all 9 jobs

🤖 Generated with Claude Code

gafferongames and others added 2 commits July 9, 2026 10:48
No public header change, no wire change, net -116 lines:

- netcode_server_process_packet builds the allowed packets table and
  timestamp, then delegates to netcode_server_read_and_process_packet
  instead of duplicating its ~45 line body. This was the pair where a fix
  applied to one had to be remembered in the other.

- The client receive loops (socket and network simulator) feed packets
  through netcode_client_process_packet instead of inlining the same
  allowed packets table and netcode_read_packet call twice more.

- netcode_address_to_sockaddr / netcode_sockaddr_to_address replace the
  IPv4/IPv6 sockaddr conversions repeated across socket create (bind and
  getsockname), send and receive.

- netcode_send_packet_to_address unifies the simulator/override/socket
  dispatch repeated in the client send path and both server send paths.

- netcode_server_reset_client_slot shares the packet queue drain and slot
  reset between normal and loopback client disconnect.

Verified: 42/42 tests in Release, Debug, and ASan+UBSan; fuzz corpus and
adversarial inputs replay clean under ASan; client_server example runs
end to end over real sockets; 45 second ASan soak run churned 5,913
client connections through the refactored paths with zero findings.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Games that care about allocation churn are expected to supply an
allocator whose alloc and free are cheap and don't call out to the OS.
That is how shipped games use this library: yojimbo provides its own
allocator through these hooks. The library defines where allocations
happen; the application decides how fast they are.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@gafferongames gafferongames merged commit b289266 into main Jul 9, 2026
@gafferongames gafferongames deleted the dedup branch July 9, 2026 16:00
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