Syft-Flwr supports multiple transport mechanisms for federated learning communication. The transport layer handles how FL messages are sent between the aggregator (server) and datasites (clients).
When transport=None, Syft-Flwr automatically selects the appropriate transport:
# bootstrap.py:119-126if transport is None: if _is_colab(): transport = "p2p" logger.info("Detected Colab environment, using 'p2p' transport") else: transport = "syftbox" logger.info("Using default 'syftbox' transport")
Both transports implement the SyftFlwrRpc protocol:
# rpc/protocol.pyclass SyftFlwrRpc(ABC): """Protocol for syft-flwr RPC implementations. This abstraction allows syft-flwr to work with different transport mechanisms for sending FL messages: - syft_core: syft_rpc (using SyftBox Go Client) with futures database - syft_client: P2P File-based RPC via Google Drive sync """ @abstractmethod def send( self, to_email: str, app_name: str, endpoint: str, body: bytes, encrypt: bool = False, ) -> str: """Send a message to a recipient.""" ... @abstractmethod def get_response(self, future_id: str) -> Optional[bytes]: """Get response for a future ID.""" ... @abstractmethod def delete_future(self, future_id: str) -> None: """Delete a future after processing its response.""" ...
For SyftBox transport, encryption keys are automatically generated:
# run_simulation.py:68-130def _bootstrap_encryption_keys( do_clients: list[RDSClient], ds_client: RDSClient) -> None: """Bootstrap the encryption keys for all clients if encryption is enabled.""" encryption_enabled = ( os.environ.get(SYFT_FLWR_ENCRYPTION_ENABLED, "true").lower() != "false" ) if not encryption_enabled: logger.warning("⚠️ Encryption disabled - skipping key bootstrap") return logger.info("🔐 Bootstrapping encryption keys for all participants...") # Bootstrap server server_client = ds_client._syftbox_client ensure_bootstrap(server_client) # Bootstrap each client for do_client in do_clients: client = do_client._syftbox_client ensure_bootstrap(client) # Verify all DID documents are accessible logger.info("🔐 All participants bootstrapped for E2E encryption ✅✅✅")
# Each participant has:# - Private key: ~/.syftbox/{email}_private_key.pem# - DID document: ~/datasites/{email}/did.json## DID document contains public key for encryption
# Same API, different behavior based on transport configclient, encryption_enabled, app_path = setup_client( app_name="my-fl-app", project_dir="./my-project")# For P2P transport:# - client: SyftP2PClient instance# - encryption_enabled: False# - app_path: "flwr/my-fl-app"