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