WIP: feat(net): send the world's block table in the handshake ack #31

Draft
Serkyo wants to merge 19 commits from feat/block-table-handshake into feat/level-v7
Owner

What does this PR do?

This PR stacks on feat/level-v7, which has its own pull request. The diff is against that branch, so it should be reviewed after it. It targets dev once that pull request merges.

Chunk payloads carry raw BlockId handles and handles are bound per world, so the same block can hold different handles in two worlds. The client never loaded block data, so it could not tell which block a handle named. I made the server send the world's block table in the handshake acknowledgement and made the client bind its own registry against it.

  • HandshakeAck in crates/shared/src/protocol/control.rs gains block_ids: Vec<ContentId>, the world's block_ids in handle order. PROTOCOL_VERSION goes from 5 to 6.
  • The table is bounded on decode, since it arrives before the session is trusted: MAX_BLOCK_TABLE_LEN (2048 entries), MAX_BLOCK_TABLE_ID_LEN (128 bytes per id) and MAX_BLOCK_TABLE_BYTES (60 KiB counting each id with its wire length prefix). The decoder checks the declared count before reading entries and each id's length before building its string. check_block_table applies the same bounds and shares one size function with the decoder.
  • NetworkServer::spawn in crates/net/src/runtime.rs takes the table, and every session's acknowledgement carries it. check_ack_fits in crates/net/src/handshake.rs checks the table and the whole encoded acknowledgement against MAX_CONTROL_FRAME_LEN before any thread or socket exists, so a world that cannot be served fails once at startup. NetError gains BlockTable and AckTooLarge.
  • RegistryBuilder::bind_received and bind_received_blocks in crates/shared/src/registry.rs bind against a received table without appending. A block the client registers that the table lacks is a RegistryError, which means the packs differ. A table entry the client does not register is an orphan and resolves as air, as a chunk load does on the server. syn:air must be at index 0; the check moved into check_air_first, which level.dat binding now uses too.
  • scripting::load_data no longer skips data/ for a client VM, so the client loads the base game's blocks through load_base_game. No second registration path exists.
  • crates/client/src/blocks.rs (bind_world_blocks) loads the base game and binds it against the received table. App::accept_ack in crates/client/src/main.rs calls it when the handshake completes, hands the bound registry to bind_blocks in chunks.rs, and logs the table length and the registered count. A table the client cannot bind refuses the join and drops the link.
  • crates/server/src/main.rs passes metadata.block_ids() to the network server through a small spawn_network helper.
  • docs/networking.md describes the table, its bounds and the client binding. docs/scripting.md now says a client VM loads pack data too.

Chunk payloads and their tests are unchanged. Nothing renders differently yet.

Why is this change necessary?

A handle in a chunk payload only means something relative to the world's block table. Without the table the client cannot map a handle to a block, so it draws every face the same colour, and anything that needs to know what a block is (textures, client-side solidity for prediction) has nothing to build on. Sending the table once in the acknowledgement keeps chunk payloads as they are and lets the client resolve every handle the server uses.

Binding without appending matters here. Reusing the server-side bind would let a client silently extend its copy of the table, and nothing would look wrong until two clients disagreed on a handle.

Scope of Changes

client, server, networking, shared, scripting, workspace

Testing

Automated, run from the worktree on feat/block-table-handshake at ad2afa0:

  • cargo check -p shared -p net -p client -p server -p scripting: passed.
  • cargo test -p shared -p net -p client -p scripting -p server: passed (shared 384, net 55, client 83, scripting 26, server 111, no failures).
  • cargo clippy --all-targets --all-features -- -D warnings: passed.
  • cargo fmt --all -- --check: passed.

New tests cover the decode bounds (entry count, id length, the byte budget on both sides of the 127 and 128 byte boundaries, and agreement between the decoder and check_block_table), the server refusing a table or acknowledgement that cannot be sent, bind_received never appending, a client-only block refusing the bind, an orphan resolving as air, a table whose index 0 is not syn:air being refused, and a loopback handshake test in crates/net/src/tests/runtime.rs that compares the server's and the client's bound registries at every handle.

One run of the server tests failed a_block_the_base_game_does_not_register_stays_an_orphan while the five crates ran together. It passed in isolation and on three further runs. The test and the code it covers are not in this branch's diff.

Manual verification: TODO for the maintainer. Start the server and the client, join, and confirm the client log reports a bound block table of the same length as the server's block_ids. I have not done this.

Additional Context

Stacks on #30 (feat/level-v7); review that one first.

  • Breaking network protocol: PROTOCOL_VERSION goes from 5 to 6, so a version 5 client or server is refused at the handshake.
  • The table is held to 60 KiB of the 64 KiB control frame, which leaves 4 KiB for the other acknowledgement fields and the build string. The server also checks the whole encoded acknowledgement against the frame cap at startup, since the build string is the open-ended part.
  • The client reads its block data from assets/ relative to the working directory, as the server does.
  • Modlist matching is still a TODO in build_ack. Until it lands, a client whose packs differ from the server's finds out when the bind fails, and the join is refused with a local error.

None.

Checklist

  • I have branched from dev (or a feature branch off dev) and my PR targets dev. (This branch is stacked on feat/level-v7, so the pull request targets dev after that pull request merges.)
  • I have kept my changes focused to a single concept.
  • I have added or updated documentation (/// doc comments for Rust) where necessary.
  • I have tested my changes and described any relevant automated or manual testing above. (The manual join check is still to do.)
### What does this PR do? This PR stacks on `feat/level-v7`, which has its own pull request. The diff is against that branch, so it should be reviewed after it. It targets `dev` once that pull request merges. Chunk payloads carry raw `BlockId` handles and handles are bound per world, so the same block can hold different handles in two worlds. The client never loaded block data, so it could not tell which block a handle named. I made the server send the world's block table in the handshake acknowledgement and made the client bind its own registry against it. - `HandshakeAck` in `crates/shared/src/protocol/control.rs` gains `block_ids: Vec<ContentId>`, the world's `block_ids` in handle order. `PROTOCOL_VERSION` goes from 5 to 6. - The table is bounded on decode, since it arrives before the session is trusted: `MAX_BLOCK_TABLE_LEN` (2048 entries), `MAX_BLOCK_TABLE_ID_LEN` (128 bytes per id) and `MAX_BLOCK_TABLE_BYTES` (60 KiB counting each id with its wire length prefix). The decoder checks the declared count before reading entries and each id's length before building its string. `check_block_table` applies the same bounds and shares one size function with the decoder. - `NetworkServer::spawn` in `crates/net/src/runtime.rs` takes the table, and every session's acknowledgement carries it. `check_ack_fits` in `crates/net/src/handshake.rs` checks the table and the whole encoded acknowledgement against `MAX_CONTROL_FRAME_LEN` before any thread or socket exists, so a world that cannot be served fails once at startup. `NetError` gains `BlockTable` and `AckTooLarge`. - `RegistryBuilder::bind_received` and `bind_received_blocks` in `crates/shared/src/registry.rs` bind against a received table without appending. A block the client registers that the table lacks is a `RegistryError`, which means the packs differ. A table entry the client does not register is an orphan and resolves as air, as a chunk load does on the server. `syn:air` must be at index 0; the check moved into `check_air_first`, which `level.dat` binding now uses too. - `scripting::load_data` no longer skips `data/` for a client VM, so the client loads the base game's blocks through `load_base_game`. No second registration path exists. - `crates/client/src/blocks.rs` (`bind_world_blocks`) loads the base game and binds it against the received table. `App::accept_ack` in `crates/client/src/main.rs` calls it when the handshake completes, hands the bound registry to `bind_blocks` in `chunks.rs`, and logs the table length and the registered count. A table the client cannot bind refuses the join and drops the link. - `crates/server/src/main.rs` passes `metadata.block_ids()` to the network server through a small `spawn_network` helper. - `docs/networking.md` describes the table, its bounds and the client binding. `docs/scripting.md` now says a client VM loads pack data too. Chunk payloads and their tests are unchanged. Nothing renders differently yet. ### Why is this change necessary? A handle in a chunk payload only means something relative to the world's block table. Without the table the client cannot map a handle to a block, so it draws every face the same colour, and anything that needs to know what a block is (textures, client-side solidity for prediction) has nothing to build on. Sending the table once in the acknowledgement keeps chunk payloads as they are and lets the client resolve every handle the server uses. Binding without appending matters here. Reusing the server-side `bind` would let a client silently extend its copy of the table, and nothing would look wrong until two clients disagreed on a handle. ### Scope of Changes client, server, networking, shared, scripting, workspace ### Testing Automated, run from the worktree on `feat/block-table-handshake` at `ad2afa0`: - `cargo check -p shared -p net -p client -p server -p scripting`: passed. - `cargo test -p shared -p net -p client -p scripting -p server`: passed (shared 384, net 55, client 83, scripting 26, server 111, no failures). - `cargo clippy --all-targets --all-features -- -D warnings`: passed. - `cargo fmt --all -- --check`: passed. New tests cover the decode bounds (entry count, id length, the byte budget on both sides of the 127 and 128 byte boundaries, and agreement between the decoder and `check_block_table`), the server refusing a table or acknowledgement that cannot be sent, `bind_received` never appending, a client-only block refusing the bind, an orphan resolving as air, a table whose index 0 is not `syn:air` being refused, and a loopback handshake test in `crates/net/src/tests/runtime.rs` that compares the server's and the client's bound registries at every handle. One run of the server tests failed `a_block_the_base_game_does_not_register_stays_an_orphan` while the five crates ran together. It passed in isolation and on three further runs. The test and the code it covers are not in this branch's diff. Manual verification: TODO for the maintainer. Start the server and the client, join, and confirm the client log reports a bound block table of the same length as the server's `block_ids`. I have not done this. ### Additional Context Stacks on #30 (feat/level-v7); review that one first. - Breaking network protocol: `PROTOCOL_VERSION` goes from 5 to 6, so a version 5 client or server is refused at the handshake. - The table is held to 60 KiB of the 64 KiB control frame, which leaves 4 KiB for the other acknowledgement fields and the build string. The server also checks the whole encoded acknowledgement against the frame cap at startup, since the build string is the open-ended part. - The client reads its block data from `assets/` relative to the working directory, as the server does. - Modlist matching is still a TODO in `build_ack`. Until it lands, a client whose packs differ from the server's finds out when the bind fails, and the join is refused with a local error. ### Related Issues None. ### Checklist - [x] I have branched from `dev` (or a feature branch off `dev`) and my PR targets `dev`. (This branch is stacked on `feat/level-v7`, so the pull request targets `dev` after that pull request merges.) - [x] I have kept my changes focused to a single concept. - [x] I have added or updated documentation (`///` doc comments for Rust) where necessary. - [ ] I have tested my changes and described any relevant automated or manual testing above. (The manual join check is still to do.)
docs(workspace): tidy the handshake acknowledgement wording
All checks were successful
Auto Labeler / label-scope (pull_request_target) Successful in 2s
CLA Signed All authors have signed the CLA.
CLA Check / cla-check (pull_request_target) Successful in 2s
ad2afa0f8a
All checks were successful
Auto Labeler / label-scope (pull_request_target) Successful in 2s
CLA Signed All authors have signed the CLA.
CLA Check / cla-check (pull_request_target) Successful in 2s
This pull request is marked as a work in progress.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feat/block-table-handshake:feat/block-table-handshake
git switch feat/block-table-handshake

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch feat/level-v7
git merge --no-ff feat/block-table-handshake
git switch feat/block-table-handshake
git rebase feat/level-v7
git switch feat/level-v7
git merge --ff-only feat/block-table-handshake
git switch feat/block-table-handshake
git rebase feat/level-v7
git switch feat/level-v7
git merge --no-ff feat/block-table-handshake
git switch feat/level-v7
git merge --squash feat/block-table-handshake
git switch feat/level-v7
git merge --ff-only feat/block-table-handshake
git switch feat/level-v7
git merge feat/block-table-handshake
git push origin feat/level-v7
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
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
Synvael/synvael!31
No description provided.