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

run()[source]ΒΆ

Run the gossiper thread.

Return type:

None

start()[source]ΒΆ

Start the gossiper thread.

Return type:

None

stop()[source]ΒΆ

Stop the gossiper thread.

Return type:

None