p2pfl.communication.protocols.memory.memory_client moduleΒΆ

In-memory client.

class p2pfl.communication.protocols.memory.memory_client.InMemoryClient(self_addr, neighbors)[source]ΒΆ

Bases: Client

Implementation of the client side of an in-memory communication protocol.

Parameters:
  • self_addr (str) – Address of the node.

  • neighbors (InMemoryNeighbors) – Neighbors of the node.

broadcast(msg, node_list=None)[source]ΒΆ

Broadcast a message to all the neighbors.

Parameters:
  • msg (Dict[str, Union[str, int, bytes, List[str]]]) – Message to send.

  • node_list (Optional[List[str]]) – List of neighbors to send the message. If None, send to all the neighbors.

Return type:

None

build_message(cmd, args=None, round=None)[source]ΒΆ

Build a message to send to the neighbors.

Parameters:
  • cmd (str) – Command of the message.

  • args (Optional[List[str]]) – Arguments of the message.

  • round (Optional[int]) – Round of the message.

Return type:

Dict[str, Union[str, int, List[str]]]

Returns:

Message to send.

build_weights(cmd, round, serialized_model, contributors=None, weight=1)[source]ΒΆ

Build a weight message to send to the neighbors.

Parameters:
  • cmd (str) – Command of the message.

  • round (int) – Round of the message.

  • serialized_model (bytes) – Serialized model to send.

  • contributors (Optional[List[str]]) – List of contributors.

  • weight (int) – Weight of the message.

Return type:

Dict[str, Union[str, int, bytes, List[str]]]

send(nei, msg, create_connection=False, raise_error=False, remove_on_error=True)[source]ΒΆ

Send a message to a neighbor.

Parameters:
  • nei (string) – Neighbor address.

  • msg (node_pb2.Message or node_pb2.Weights) – Message to send.

  • create_connection (bool) – Create a connection if not exists.

  • raise_error (bool) – Raise error if an error occurs.

  • remove_on_error (bool) – Remove neighbor if an error occurs.

Return type:

None