Add ttl for peer data expiration (#655)

* Add ttl and last_identified to peerdata

* Add test for ttl

Signed-off-by: sukhman <sukhmansinghsaluja@gmail.com>

* Fix lint and add newsfragments

Signed-off-by: sukhman <sukhmansinghsaluja@gmail.com>

* Fix failing ci

Signed-off-by: sukhman <sukhmansinghsaluja@gmail.com>

* fix ttl time from 600 to 120

Signed-off-by: sukhman <sukhmansinghsaluja@gmail.com>

* fix test ttl timeout and lint errors

Signed-off-by: sukhman <sukhmansinghsaluja@gmail.com>

* Fix docstrings

Signed-off-by: sukhman <sukhmansinghsaluja@gmail.com>

* rebase main

* remove print statement

---------

Signed-off-by: sukhman <sukhmansinghsaluja@gmail.com>
Co-authored-by: pacrob <5199899+pacrob@users.noreply.github.com>
This commit is contained in:
Sukhman Singh
2025-06-10 00:12:59 +05:30
committed by GitHub
parent bdadec7519
commit 22d93b39ae
8 changed files with 158 additions and 16 deletions

View File

@ -1440,6 +1440,60 @@ class IPeerData(ABC):
"""
@abstractmethod
def update_last_identified(self) -> None:
"""
Updates timestamp to current time.
"""
@abstractmethod
def get_last_identified(self) -> int:
"""
Fetch the last identified timestamp
Returns
-------
last_identified_timestamp
The lastIdentified time of peer.
"""
@abstractmethod
def get_ttl(self) -> int:
"""
Get ttl value for the peer for validity check
Returns
-------
int
The ttl of the peer.
"""
@abstractmethod
def set_ttl(self, ttl: int) -> None:
"""
Set ttl value for the peer for validity check
Parameters
----------
ttl : int
The ttl for the peer.
"""
@abstractmethod
def is_expired(self) -> bool:
"""
Check if the peer is expired based on last_identified and ttl
Returns
-------
bool
True, if last_identified + ttl > current_time
"""
# ------------------ multiselect_communicator interface.py ------------------