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