Repository navigation
Conversation
aiortc advertises a max-message-size of 64 KiB. RFC 8841 forbids a larger message, but AiortcPeerConnections sent each frame as one message. aiortc does not refuse such a message, and its receiver needs quadratic time for it. Therefore a 100 MB message never arrived. AiortcPeerConnections now splits each frame into chunks of at most 64 KiB, and the peer joins the chunks again. A new test checks the size of each message that aiortc sends.
Each client keeps one WebSocket open to the server. The server relays offers and answers between two online clients by email. It tells a client when a watched peer comes online or goes offline. It gives each client short-lived TURN credentials from Cloudflare. Clients sign in with one shared access key, and the server keeps all state in memory. Run it with python -m syft.sync.connections.webrtc.signaling.server. The webrtc extra now includes websockets.
…ing code The signaling server reads and checks a client's hello in its own helper. The checks of the watch list and the offline error moved into helpers too. Each function name now says what the function does. The server uses the CloseCode of websockets in place of its own copy of 1008, and the docstrings follow the Google style.
…e online ServerSignaling signs in to the signaling server over one WebSocket and carries offers and answers through it. AiortcPeerConnections gets its ICE servers from the signaling. Its new watch() connects to a watched peer each time the peer comes online. Of two peers, the one whose email sorts first sends the offer.
A connection to the signaling server carries one signaling session or one peering request. Peering requests store and read peer requests, and the key bundles and peer info that a client shares with a peer. ServerPeeringConnection uses them and keeps the peer list on local disk. The server matches emails in lower case and reports each email as its owner spells it.
LocalOwnerStoreConnection keeps the event log, the checkpoints and the rolling state in a folder on local disk. It keeps the order and the replacement rules of the Drive store. A WebRTC user has no Drive, so it is the owner store for WebRTC mode.
login_do and login_ds, in syft and syft-rds, take webrtc=True or a WebRTCConfig. The client then logs in to no Google account. It sends messages over WebRTC, peers through the signaling server, and keeps the owner state on local disk. Datasets do not go over WebRTC yet. webrtc=True reads the server from SYFT_SIGNALING_URL and SYFT_SIGNALING_ACCESS_KEY. The DS sends the offers, and the DO answers only the peers it approved. A client signs in to the server only when it knows its peers.
A signaling session that ends makes the next set_peers raise, and the call after it signs in again. A cancelled caller no longer cancels the shared sign-in. Each new peer connection gets new ICE servers, because TURN credentials expire. Peer emails keep the spelling of the peer list, and a DO that accepts with add_peer accepts the DS at once. A refused offer goes back to the DS as a refuse message. Failed connects, refused offers and ended sessions raise at the next set_peers. syft-rds passes no dataset specs in WebRTC mode, and the config raises on any.
set_peers no longer raises old background failures, so an approval always completes and fires peer_approved. sync() raises them at the end of its pass, after the client has signed in again. A token_path with webrtc raises. One helper builds the connection router config for both login builders, and names, docstrings and a comment follow the guidelines.
WebRTC clients no longer use a signaling server of ours. Each org sets up a Firebase project from firebase/README.md: Firestore holds presence, an inbox of offers and answers for each client, peer requests, key bundles and peer info, under the rules in firebase/firestore.rules. A Cloud Function gives signed-in users short-lived Cloudflare TURN credentials. The client polls Firestore over REST with the user's Firebase ID token. webrtc=True reads SYFT_FIREBASE_PROJECT_ID and SYFT_FIREBASE_API_KEY, and the first login on a machine signs in with an emailed link. A refused session asks for a new link. The signaling server, its client and websockets go away. Tests run on the Firebase emulators, which need npx and Java 21.
…nsplit v3 task says WebRTC signaling and peering now use the Firebase Realtime Database in place of Firestore. Each client reads its own signal/ node as one stream of server-sent events, so nothing polls. A client says hello to each accepted peer with no open channel, and the lower email sends the offer. acl/ lets only accepted peers write signals, and each sender has one hello slot. TURN credentials last 4 hours, and the offering side opens a new peer connection before they expire. The ID token follows the wall clock, so it stays valid after the machine sleeps. The project ID and the web API key come only from SYFT_FIREBASE_PROJECT_ID and SYFT_FIREBASE_API_KEY. The Firestore code goes away.
…C mode Two new tests run on the Firebase emulators. In one, a DO exchanges frames with two DSs at once. In the other, an offer that waits in the inbox from before the sign-in gets no answer. A third test drops all ICE packets until both channels close. Then the next set_peers must connect the two peers again. sign_in_failed returns early instead of combining three checks, and prettier formats firebase/firebase.json.
…t v3 task says The rules, firebase.json, the TURN Cloud Function and the setup steps move from firebase/ to infra/firebase/. The docstrings and the tests use the new path.
… reply When the TURN Cloud Function refused a Firebase ID token, its 401 reply held the text of the exception. A ValueError from verify_id_token can describe the setup of the function, and CodeQL flagged it as py/stack-trace-exposure. Now the reply gives a fixed reason, and the function logs the exception.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
login,login_doorlogin_ds, it previously synced only over Google Drive, after a Google login. These functions are insyftand insyft-rds. Nowwebrtc=Truesyncs over WebRTC, with no Google login. Two settings name the Firebase project:SYFT_FIREBASE_PROJECT_IDandSYFT_FIREBASE_API_KEY. The owner of the project gives both values to its users. The owner is OpenMined, or an org. Neither value is in the source.webrtc=Truefor the first time on a machine, Firebase sends a sign-in link to the email. The user pastes the link into the notebook once. If Firebase later refuses the saved session, the next login sends a new link.webrtc=WebRTCConfig(...)selects a project, or the Firebase emulators.login,login_do,login_ds,SyftboxManagerConfig.for_colabandSyftboxManagerConfig.for_jupyterget a newwebrtcparameter.acl/, the key bundles and the peer info.acl/lists the peers that each user accepts. The rules ininfra/firebase/database.rules.jsoncontrol who reads and writes each path. Before, WebRTC worked only in test pairs, with peering and the state of the DO on a mock Drive. The peer list stays on local disk, with the version entry ofSYFT_peers.json.signal/node as one stream of server-sent events, so nothing polls. A client says hello to each peer that has no open channel to it. Then the peer with the lower email sends the WebRTC offer. Only an accepted peer can send signals, and each sender has one hello slot. Before, WebRTC peers found each other only throughLocalSignaling, in one process.add_peer,approve_peer_requestorload_peerschanges the peers, the WebRTC connection now gets the new list of peers. It connects to new peers, and it closes the channels to removed peers.sync()now raises the error at its end. The same happens when a connect, a hello or an answer fails in the background, or when a peer refuses an offer.NotImplementedError, because datasets do not go over WebRTC yet. Thereforesyft-rdsregisters no dataset collection specs for a WebRTC client.AiortcPeerConnectionssent a frame, it previously sent the whole frame as one data channel message. That message was larger than the 64 KiB limit of aiortc. The aiortc receiver needs quadratic time for such a message, so a message of 100 MB never arrived. NowAiortcPeerConnectionssplits each frame into chunks of 64 KiB or less, and the peer joins the chunks again.infra/firebase/folder, which the owner of a project deploys. It holds the database rules, theturn_credentialsCloud Function, and the setup steps ininfra/firebase/README.md. We run no server.Guidelines
High level
login_doandlogin_dssync over WebRTC through a Firebase project, with no Google login.Mid level
Low level
SyftboxManager._webrtc_connectionsimports aiortc inside the function. The reason is the optionalwebrtcextra, not a circular import: a top-level import would breakimport syftwithout that extra.Security
acl/can send signals to the receiver. Each type of signal has exactly its own fields. A hello can only replace the hello slot of its sender.Testing
tests/unit/webrtc/,tests/unit/test_login_webrtc.pyandpackages/syft-rds/tests/test_webrtc_config.py. They cover the signals in stream events, and how the stream handles an unreachable token refresh andauth_revoked. They also cover the ID token after the machine sleeps, the sign-in link and the session file. Other unit tests cover a failed sign-in, the ICE servers that the TURN function picks, and the login settings.tests/integration/webrtc/run on the Firebase emulators. They cover the database rules, the stream,DatabaseSignalingwith aiortc clients on localhost, andDatabasePeeringConnection. They also cover the login with the emailed link, and the job flow of a DO and a DS from end to end. Other tests cover a DO with two DSs at once, and an offer that waits in the inbox from before the sign-in. The client deletes that offer, and does not answer it. The tests passed three times in a row. They need npx and Java 21. The CI jobwebrtc-testsruns them.set_peers, the two clients connect again.Asana task