Skip to content

Commit 64bc388

Browse files
committed
added peer-store cleanup task in ping example
1 parent 09e151a commit 64bc388

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

examples/ping/ping.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ async def run(port: int, destination: str) -> None:
5959
host = new_host(listen_addrs=[listen_addr])
6060

6161
async with host.run(listen_addrs=[listen_addr]), trio.open_nursery() as nursery:
62+
# Start the peer-store cleanup task
63+
nursery.start_soon(host.get_peerstore().start_cleanup_task, 60)
64+
6265
if not destination:
6366
host.set_stream_handler(PING_PROTOCOL_ID, handle_ping)
6467

libp2p/abc.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,10 @@ def peer_ids(self) -> list[ID]:
13271327
def clear_peerdata(self, peer_id: ID) -> None:
13281328
"""clear_peerdata"""
13291329

1330+
@abstractmethod
1331+
async def start_cleanup_task(self, cleanup_interval: int = 3600) -> None:
1332+
"""Start periodic cleanup of expired peer records and addresses."""
1333+
13301334

13311335
# -------------------------- listener interface.py --------------------------
13321336

0 commit comments

Comments
 (0)