mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 16:10:57 +00:00
added peer-store cleanup task in ping example
This commit is contained in:
@ -59,6 +59,9 @@ async def run(port: int, destination: str) -> None:
|
|||||||
host = new_host(listen_addrs=[listen_addr])
|
host = new_host(listen_addrs=[listen_addr])
|
||||||
|
|
||||||
async with host.run(listen_addrs=[listen_addr]), trio.open_nursery() as nursery:
|
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:
|
if not destination:
|
||||||
host.set_stream_handler(PING_PROTOCOL_ID, handle_ping)
|
host.set_stream_handler(PING_PROTOCOL_ID, handle_ping)
|
||||||
|
|
||||||
|
|||||||
@ -1327,6 +1327,10 @@ class IPeerStore(
|
|||||||
def clear_peerdata(self, peer_id: ID) -> None:
|
def clear_peerdata(self, peer_id: ID) -> None:
|
||||||
"""clear_peerdata"""
|
"""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 --------------------------
|
# -------------------------- listener interface.py --------------------------
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user