Add netplay state-message types to reliable channel protocol #1

Closed
opened 2026-08-25 06:03:44 +02:00 by pbwraith · 1 comment
Owner

Repo: gopher64-netplay (fork of https://github.com/gopher64/gopher64)
Context: Full scope doc at upstream analysis — see commit history. Netplay uses GGRS over WebRTC (matchbox_socket), reliable channel carries NetplayMessage { name, data } in 16KB chunks. Savestates serialize full Device via postcard + compress.

Goal: Extend the reliable channel protocol with new message types for state transfer.

Background:

  • src/netplay.rs has send_save/receive_save sending NetplayMessage { name, data } in 16KB chunks (lines 72-111)
  • Sessions already exchange: player_number, rtc, rng, eep/sra/fla/mpk/img/rom saves
  • Need message names for: full session state, resync state, ready-ack

Acceptance:

  • Add message-name constants: "netplay_state", "netplay_state_ready", "resync_state", "resync_ready"
  • Add send_netplay_state(netplay, data) / receive_netplay_state(netplay) -> Vec<u8> that reuse the existing chunked send_message/process_reliable_messages machinery (no new transport code)
  • Add ack helpers: send_ready(netplay, name) / wait_for_ready(netplay, name) with 10s timeout like receive_message
  • Large payloads (>1MB) must round-trip correctly — the current chunking accumulates into incoming_message until a full postcard message parses
  • Unit tests: serialize/deserialize a 5MB payload through the message codec; ack send/receive within timeout; missing ack times out with the existing panic message pattern

Verification: cargo test passes with new tests. All existing netplay tests stay green.

**Repo:** gopher64-netplay (fork of https://github.com/gopher64/gopher64) **Context:** Full scope doc at upstream analysis — see commit history. Netplay uses GGRS over WebRTC (matchbox_socket), reliable channel carries `NetplayMessage { name, data }` in 16KB chunks. Savestates serialize full Device via postcard + compress. **Goal:** Extend the reliable channel protocol with new message types for state transfer. **Background:** - `src/netplay.rs` has `send_save`/`receive_save` sending `NetplayMessage { name, data }` in 16KB chunks (lines 72-111) - Sessions already exchange: player_number, rtc, rng, eep/sra/fla/mpk/img/rom saves - Need message names for: full session state, resync state, ready-ack **Acceptance:** - Add message-name constants: `"netplay_state"`, `"netplay_state_ready"`, `"resync_state"`, `"resync_ready"` - Add `send_netplay_state(netplay, data)` / `receive_netplay_state(netplay) -> Vec<u8>` that reuse the existing chunked `send_message`/`process_reliable_messages` machinery (no new transport code) - Add ack helpers: `send_ready(netplay, name)` / `wait_for_ready(netplay, name)` with 10s timeout like `receive_message` - Large payloads (>1MB) must round-trip correctly — the current chunking accumulates into `incoming_message` until a full postcard message parses - Unit tests: serialize/deserialize a 5MB payload through the message codec; ack send/receive within timeout; missing ack times out with the existing panic message pattern **Verification:** `cargo test` passes with new tests. All existing netplay tests stay green.
pbwraith added the
netplay
p1
rust
labels 2026-08-25 06:04:33 +02:00
pbwraith added the
in-review
label 2026-08-25 09:44:02 +02:00
Author
Owner

Implementing lane 4 — PR ready for manual review.

PR: #14 — #14 (base main, head issue-1, state open, mergeable)

Commit: 891d12c — "netplay: add state-message types to reliable channel protocol (#1)" (258+/34-, 1 file: src/netplay.rs)

What changed:

  • Message-name constants: NETPLAY_STATE_MESSAGE ("netplay_state"), NETPLAY_STATE_READY_MESSAGE ("netplay_state_ready"), RESYNC_STATE_MESSAGE ("resync_state"), RESYNC_READY_MESSAGE ("resync_ready").
  • Chunked codec helpers encode_message_chunks / decode_message / decode_packets (16 KiB chunks, accumulate into incoming_message until a full postcard message parses) — existing transport reused, no new transport code.
  • send_netplay_state / receive_netplay_state, plus ack helpers send_ready / wait_for_ready (10 s timeout, same pattern as receive_message, extracted to wait_for_message; input-delay/disconnect side effects preserved).
  • Large (>1 MB) payloads round-trip through the chunked codec.

Tests (cargo test --lib, local worktree build): 4 passed / 0 failed

  • state_message_constants_match_protocol
  • large_payload_round_trips_through_chunked_codec (5 MB)
  • ready_ack_send_receive_within_timeout
  • missing_ack_times_out_with_standard_panic

git diff --check clean. (Note: this WSL box needs local-only build tweaks in build.rs/.cargo to compile; those are intentionally NOT part of this PR.)

Implementing lane 4 — PR ready for manual review. **PR:** #14 — https://gitea.185.214.135.234.nip.io/pbwraith/gopher64-netplay/pulls/14 (base `main`, head `issue-1`, state open, mergeable) **Commit:** `891d12c` — "netplay: add state-message types to reliable channel protocol (#1)" (258+/34-, 1 file: src/netplay.rs) **What changed:** - Message-name constants: `NETPLAY_STATE_MESSAGE` ("netplay_state"), `NETPLAY_STATE_READY_MESSAGE` ("netplay_state_ready"), `RESYNC_STATE_MESSAGE` ("resync_state"), `RESYNC_READY_MESSAGE` ("resync_ready"). - Chunked codec helpers `encode_message_chunks` / `decode_message` / `decode_packets` (16 KiB chunks, accumulate into `incoming_message` until a full postcard message parses) — existing transport reused, no new transport code. - `send_netplay_state` / `receive_netplay_state`, plus ack helpers `send_ready` / `wait_for_ready` (10 s timeout, same pattern as `receive_message`, extracted to `wait_for_message`; input-delay/disconnect side effects preserved). - Large (>1 MB) payloads round-trip through the chunked codec. **Tests** (`cargo test --lib`, local worktree build): 4 passed / 0 failed - `state_message_constants_match_protocol` - `large_payload_round_trips_through_chunked_codec` (5 MB) - `ready_ack_send_receive_within_timeout` - `missing_ack_times_out_with_standard_panic` `git diff --check` clean. (Note: this WSL box needs local-only build tweaks in build.rs/.cargo to compile; those are intentionally NOT part of this PR.)
This repo is archived. You cannot comment on issues.
No Milestone
No project
No Assignees
1 Participants
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: pbwraith/gopher64-netplay#1
No description provided.