nvflare.fuel.f3.communicator module

class Communicator(local_endpoint: Endpoint)[source]

Bases: object

FCI (Flare Communication Interface) main communication API

add_connector(url: str, mode: Mode, secure: bool = False) str[source]

Load a connector. The driver is selected based on the URL

Parameters:
  • url – The url to listen on or connect to, like “https://0:443”. Use 0 for empty host

  • mode – Active for connecting, Passive for listening

  • secure – True if SSL is required.

Returns:

A handle that can be used to delete connector

Raises:

CommError – If any errors

add_connector_advanced(driver: Driver, mode: Mode, params: dict, secure: bool, start: bool = False) str[source]

Add a connector using a specific driver instance.

Parameters:
  • driver – A transport driver instance

  • mode – Active or passive

  • params – Driver parameters

  • secure – SSL is required if true

  • start – Start the connector if true

Returns:

A handle that can be used to delete the connector

Raises:

CommError – If any errors

find_endpoint(name: str) Endpoint | None[source]

Find endpoint by name

Parameters:

name – Endpoint name

Returns:

The endpoint if found. None if not found

register_message_receiver(app_id: int, receiver: MessageReceiver)[source]

Register a receiver to process FCI message for the app

Parameters:
  • app_id – Application ID

  • receiver – The receiver to process the message

Raises:

CommError – If duplicate endpoint/app or receiver is of wrong type

register_monitor(monitor: EndpointMonitor)[source]

Register a monitor for endpoint lifecycle changes

This monitor is notified for any state changes of all the endpoints. Multiple monitors can be registered.

Parameters:

monitor – The class that receives the endpoint state change notification

Raises:

CommError – If any error happens while sending the request

remove_connector(handle: str)[source]

Remove the connector

Parameters:

handle – The connector handle

Raises:

CommError – If any errors

remove_endpoint(name: str)[source]

Remove endpoint and close all the connections associated with it

Parameters:

name – Endpoint name

send(endpoint: Endpoint, app_id: int, message: Message)[source]

Send a message to endpoint for app_id, no response is expected

Parameters:
  • endpoint – An endpoint to send the request to

  • app_id – Application ID

  • message – Message to send

Raises:

CommError – If any error happens while sending the data

start()[source]

Start the communicator and establishing all the connections

Raises:

CommError – If any error encountered while starting up

start_listener(scheme: str, resources: dict) -> (<class 'str'>, <class 'str'>)[source]

Add and start a connector in passive mode on an address selected by the driver.

Parameters:
  • scheme – Connection scheme, e.g. http, https

  • resources – User specified resources like host and port ranges

Returns:

A tuple with connector handle and connect url

Raises:

CommError – If any errors like invalid host or port not available

stop()[source]

Stop the communicator and shutdown all the connections

Raises:

CommError – If any error encountered while shutting down

load_comm_drivers()[source]