Skip to content

Replace bach’s UDP simulation backend with a first-pass turmoil-net adapter - #113

Draft
camshaft with Copilot wants to merge 3 commits into
mainfrom
copilot/replace-bachs-network-with-turmoil-net
Draft

Replace bach’s UDP simulation backend with a first-pass turmoil-net adapter#113
camshaft with Copilot wants to merge 3 commits into
mainfrom
copilot/replace-bachs-network-with-turmoil-net

Conversation

Copilot AI commented May 14, 2026

Copy link
Copy Markdown
Contributor

This PR swaps bach’s internal network backend over to turmoil-net as a first pass, with the goal of preserving the existing bach::net surface and surfacing the remaining compatibility gaps early. The current pass keeps existing UDP-centric behavior working while leaving a few advanced backend hooks intentionally stubbed or unsupported.

  • Backend swap

    • Replaces the custom UDP socket backend with a turmoil-net-backed adapter under the existing bach::net API.
    • Keeps UdpSocket::{bind, connect, send, send_to, recv, recv_from} semantics intact for current callers.
    • Routes per-group execution through a shared turmoil_net::Net topology.
  • Compatibility layer

    • Preserves bach hostname/group resolution so existing tests and call sites continue to use names like "server:8080".
    • Adapts turmoil-net packets into bach’s monitor packet shape so net-monitor callbacks continue to observe send/receive traffic.
    • Emulates GSO-style segmented sends by splitting payloads on SendOptions.segment_len.
  • Runtime / scope hardening

    • Fixes scope restoration so thread-local runtime state is unwound correctly across panic paths.
    • Avoids aborts during monitor-triggered panics by ensuring cleanup does not re-enter torn-down TLS state.
  • Intentional first-pass gaps

    • with_pcap_dir remains as a compatibility no-op for now.
    • Custom net queue allocators remain API-compatible but are not wired into the new backend yet.
    • Some advanced socket options remain unsupported by the adapter.
    • Adding new groups after the turmoil topology is initialized is not supported in this pass.

Example of the preserved public API shape:

use bach::net::UdpSocket;

async {
    let socket = UdpSocket::bind("0.0.0.0:0").await.unwrap();
    socket.send_to(b"ping", "server:8080").await.unwrap();

    let mut buf = [0; 4];
    let (len, addr) = socket.recv_from(&mut buf).await.unwrap();
    assert_eq!((&buf[..len], addr.port()), (b"pong", 8080));
};

Copilot AI and others added 3 commits May 14, 2026 10:19
Agent-Logs-Url: https://github.com/camshaft/bach/sessions/0fe5944e-8451-4d54-ad6a-dac452aff1be

Co-authored-by: camshaft <799311+camshaft@users.noreply.github.com>
Agent-Logs-Url: https://github.com/camshaft/bach/sessions/0fe5944e-8451-4d54-ad6a-dac452aff1be

Co-authored-by: camshaft <799311+camshaft@users.noreply.github.com>
Agent-Logs-Url: https://github.com/camshaft/bach/sessions/0fe5944e-8451-4d54-ad6a-dac452aff1be

Co-authored-by: camshaft <799311+camshaft@users.noreply.github.com>
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