p2pfl.communication.protocols.grpc.grpc_client moduleΒΆ

GRPC client.

class p2pfl.communication.protocols.grpc.grpc_client.GrpcClient(self_addr, neighbors)[source]ΒΆ

Bases: Client

Implementation of the client side (i.e. who initiates the communication) of the GRPC communication protocol.

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

  • neighbors (GrpcNeighbors) – Neighbors of the node.

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

Broadcast a message to all the neighbors.

Parameters:
  • msg (RootMessage) – 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 RootMessage 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:

RootMessage

Returns:

RootMessage to send.

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

Build a RootMessage with a Weights payload 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 (number of samples).

Return type:

RootMessage

Returns:

RootMessage to send.

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