p2pfl.communication.protocols.protobuff.neighbors moduleΒΆ
Protocol agnostic neighbor management.
- class p2pfl.communication.protocols.protobuff.neighbors.Neighbors(build_client_fn)[source]ΒΆ
Bases:
NodeComponent
Neighbor management class for agnostic communication protocol.
- Parameters:
build_client_fn (
Callable
[...
,ProtobuffClient
])
- add(addr, non_direct=False, handshake=True)[source]ΒΆ
Add a neighbor to the neighbors list.
- Parameters:
addr (
str
) β Address of the neighbor to add.non_direct (
bool
) β Flag to add a non-direct neighbor.handshake (
bool
) β Flag to perform a handshake.
- Return type:
bool
- Returns:
True if the neighbor was added, False otherwise.
- exists(addr, only_direct=False)[source]ΒΆ
Check if a neighbor exists in the neighbors list.
- Parameters:
addr (
str
) β Address of the neighbor to check.only_direct (
bool
) β Flag to check only direct neighbors.
- Return type:
bool
- get(addr)[source]ΒΆ
Get a neighbor from the neighbors list.
- Parameters:
addr (
str
) β Address of the neighbor to get.- Return type:
- Returns:
The neighbor.
- 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
,tuple
[ProtobuffClient
,float
]]
- 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, disconnect_msg=True)[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.disconnect_msg (
bool
) β If a disconnect message is needed.
- Return type:
None