mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-11 07:30:55 +00:00
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:
@ -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 ------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user