From 64bc388b330d4a5d69be9d50f451a19164418d9b Mon Sep 17 00:00:00 2001 From: lla-dane Date: Sat, 19 Jul 2025 23:06:15 +0530 Subject: [PATCH] added peer-store cleanup task in ping example --- examples/ping/ping.py | 3 +++ libp2p/abc.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/examples/ping/ping.py b/examples/ping/ping.py index 647a607b..d1a5daae 100644 --- a/examples/ping/ping.py +++ b/examples/ping/ping.py @@ -59,6 +59,9 @@ async def run(port: int, destination: str) -> None: host = new_host(listen_addrs=[listen_addr]) async with host.run(listen_addrs=[listen_addr]), trio.open_nursery() as nursery: + # Start the peer-store cleanup task + nursery.start_soon(host.get_peerstore().start_cleanup_task, 60) + if not destination: host.set_stream_handler(PING_PROTOCOL_ID, handle_ping) diff --git a/libp2p/abc.py b/libp2p/abc.py index ecd71528..d3df0a8c 100644 --- a/libp2p/abc.py +++ b/libp2p/abc.py @@ -1327,6 +1327,10 @@ class IPeerStore( def clear_peerdata(self, peer_id: ID) -> None: """clear_peerdata""" + @abstractmethod + async def start_cleanup_task(self, cleanup_interval: int = 3600) -> None: + """Start periodic cleanup of expired peer records and addresses.""" + # -------------------------- listener interface.py --------------------------