p2pfl.communication.protocols.neighbors moduleΒΆ

Protocol agnostic neighbor management.

class p2pfl.communication.protocols.neighbors.Neighbors(self_addr)[source]ΒΆ

Bases: object

Neighbor management class for agnostic communication protocol.

Parameters:

self_addr – Address of the node.

add(addr, *args, **kargs)[source]ΒΆ

Add a neighbor to the neighbors list.

Parameters:
  • addr (str) – Address of the neighbor to add.

  • args – Additional arguments for the connect method (focused reimplementation).

  • kargs – Additional keyword arguments for the connect method (focused reimplementation).

Return type:

bool

clear_neighbors()[source]ΒΆ

Clear all neighbors.

Return type:

None

connect(addr)[source]ΒΆ

Connect to a neighbor.

Parameters:

addr (str) – Address of the neighbor to connect.

Return type:

Any

disconnect(addr)[source]ΒΆ

Disconnect from a neighbor.

Parameters:

addr (str) – Address of the neighbor to disconnect.

Return type:

None

exists(addr)[source]ΒΆ

Check if a neighbor exists in the neighbors list.

Parameters:

addr (str) – Address of the neighbor to check.

Return type:

bool

get(addr)[source]ΒΆ

Get a neighbor from the neighbors list.

Parameters:

addr (str) – Address of the neighbor to get.

Return type:

Any

get_all(only_direct=False)[source]ΒΆ

Get all neighbors from the neighbors list.

Parameters:

only_direct (bool) – Flag to get only direct neighbors.

Return type:

Dict[str, Any]

refresh_or_add(addr, time)[source]ΒΆ

Refresh or add a neighbor.

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

  • time (float) – Time of the last heartbeat.

Return type:

None

remove(addr, *args, **kargs)[source]ΒΆ

Remove a neighbor from the neighbors list.

Be careful, this method does not close the connection, is agnostic to the connection state.

Parameters:
  • addr (str) – Address of the neighbor to remove.

  • args – Additional arguments for the disconnect method (focused reimplementation).

  • kargs – Additional keyword arguments for the disconnect method (focused reimplementation).

Return type:

None