Skip to content

feat: add WebRTC p2p connection over a fake channel - #9607

Open
koenvanderveen wants to merge 2 commits into
devfrom
koen/webrtc-mock-connection
Open

koenvanderveen wants to merge 2 commits into
devfrom
koen/webrtc-mock-connection

Conversation

@koenvanderveen

@koenvanderveen koenvanderveen commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

First step of the local WebRTC connection (connsplit v2). Only the data channel is faked; the WebRTC core on top of it is real, the same idea as MockDriveService for Drive.

Changes

  • syft/sync/connections/webrtc/: WebRTCP2PConnection (the synchronous core), Channel (the pipe under it), FakeChannel (in-memory pipe, no threads) and MessageQueue (a folder per queue, one file per message).
    • send writes the outgoing file, sends the frame and returns QUEUED. The peer stores the message in its incoming file and sends a receipt; delivered() then reports it once.
    • A message that arrives twice is stored once. Unconfirmed messages are resent in order when the channel opens, before any new one. Both queues survive a restart.
  • pair_with_mock_drive_and_mock_webrtc_connection on SyftboxManager and SyftRDSClient: the mock Drive does peering, datasets and storage, WebRTC carries the messages.
  • Outbox compaction is skipped when the p2p connection keeps no sent messages (keeps_sent_messages, true only for Drive).

Not in this PR: chunking, the DeliveryTracker in-flight list (the DO still counts a QUEUED send as delivered, which is safe while FakeChannel returns the receipt inside send), the DO duplicate check, FakeChannel manual mode, the shared pair fixture and strict mode, thread safety, aiortc.

Tests (new folder tests/unit/webrtc/)

  • test_webrtc_p2p.py: the core over a FakeChannel without managers.
  • test_webrtc_end_to_end.py: a file round trip and a job round trip through the new factory, both checking that no message files appear in the Drive inbox, archive or outbox.
  • just test-unit-fast: 741 passed. Pre-commit passes.

The real WebRTC core (queue files, receipts, duplicate check, resend on connect) runs over a FakeChannel, an in-memory pipe in place of an aiortc data channel. pair_with_mock_drive_and_mock_webrtc_connection sends messages over it while the mock Drive does peering, datasets and storage. Outbox compaction is skipped for a p2p connection that keeps no sent messages.
…est pair factories

New messages wait until the channel has opened and older unconfirmed ones were resent. Each queue is a folder with one file per message, so adding or removing one never rewrites the others. The Drive and Drive+WebRTC pair factories are separate methods built from shared helpers.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant