p2pfl.communication.protocols.gossiper moduleΒΆ
Protocol agnostic gossiper.
- class p2pfl.communication.protocols.gossiper.Gossiper(self_addr, client, period=None, messages_per_period=None)[source]ΒΆ
Bases:
Thread
Gossiper for agnostic communication protocol.
- Parameters:
self_addr β Address of the node.
client (
Client
) β Client to send messages.period (
Optional
[float
]) β Period of gossip.messages_per_period (
Optional
[int
]) β Amount of messages to send per period.
- add_message(msg, pending_neis)[source]ΒΆ
Add message to pending.
- Parameters:
msg (
Any
) β Message to send.pending_neis (
List
[str
]) β Neighbors to send the message.
- Return type:
None
- check_and_set_processed(msg_hash)[source]ΒΆ
Check if message was already processed and set it as processed.
- Parameters:
msg_hash (
int
) β Hash of the message to check.- Return type:
bool
- gossip_weights(early_stopping_fn, get_candidates_fn, status_fn, model_fn, period, create_connection)[source]ΒΆ
Gossip model weights. This is a synchronous gossip. End when there are no more neighbors to gossip.
- Parameters:
early_stopping_fn (
Callable
[[],bool
]) β Function to check if the gossip should stop.get_candidates_fn (
Callable
[[],List
[str
]]) β Function to get the neighbors to gossip.status_fn (
Callable
[[],Any
]) β Function to get the status of the node.model_fn (
Callable
[[str
],Any
]) β Function to get the model of a neighbor.period (
float
) β Period of gossip.create_connection (
bool
) β Flag to create a connection.
- Return type:
None