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

GRPC server.

class p2pfl.communication.protocols.grpc.grpc_server.GrpcServer(addr, gossiper, neighbors, commands=None)[source]ΒΆ

Bases: NodeServicesServicer

Implementation of the server side of a GRPC communication protocol.

Parameters:
  • addr (str) – Address of the server.

  • gossiper (Gossiper) – Gossiper instance.

  • neighbors (GrpcNeighbors) – Neighbors instance.

  • commands (Optional[List[Command]]) – List of commands to be executed by the server.

add_command(cmds)[source]ΒΆ

Add a command.

Parameters:

cmds (Union[Command, List[Command]]) – Command or list of commands to be added.

Return type:

None

disconnect(request, _)[source]ΒΆ

GRPC service. It is called when a node disconnects from another.

Parameters:
  • request (HandShakeRequest) – Request message.

  • _ – Context.

Return type:

Empty

handshake(request, _)[source]ΒΆ

GRPC service. It is called when a node connects to another.

Parameters:
  • request (HandShakeRequest) – Request message.

  • _ – Context.

Return type:

ResponseMessage

is_running()[source]ΒΆ

Check if the server is running.

Return type:

bool

Returns:

True if the server is running, False otherwise.

send(request, _)[source]ΒΆ

GRPC service. Handles both regular messages and model weights.

Parameters:
  • request (RootMessage) – The RootMessage containing either a Message or Weights payload.

  • _ – Context.

Return type:

ResponseMessage

start(wait=False)[source]ΒΆ

Start the GRPC server.

Parameters:

wait (bool) – If True, wait for termination.

Return type:

None

stop()[source]ΒΆ

Stop the GRPC server.

Return type:

None

wait_for_termination()[source]ΒΆ

Wait for termination.

Return type:

None