"""Built-in router jobs — standard periodic and one-shot tasks. Ported from various net.i2p.router.* job classes. Each job has a minimal ``run()`` / ``execute()`` that logs and delegates to the subsystem it wraps. The actual tunnel-building, NetDB searching, and peer-profiling logic lives in the respective subsystem modules. """ from __future__ import annotations import logging from typing import Any from i2p_router.job import Job, TimedJob log = logging.getLogger(__name__) class TunnelBuildJob(TimedJob): """Build new tunnels when tunnel pools are low. Runs every 60 seconds. Delegates to the TunnelManager on the context. """ def __init__(self, priority: int = 5) -> None: super().__init__( name="tunnel-build", priority=priority, interval_seconds=60.0, ) def run(self, context: Any) -> None: log.debug("TunnelBuildJob: checking tunnel pools") if hasattr(context, "tunnel_manager"): context.tunnel_manager.build_if_needed() class TunnelRefreshJob(TimedJob): """Remove expired tunnels and request rebuilds. Runs every 30 seconds. Delegates to the TunnelManager on the context. """ def __init__(self, priority: int = 4) -> None: super().__init__( name="tunnel-refresh", priority=priority, interval_seconds=30.0, ) def run(self, context: Any) -> None: log.debug("TunnelRefreshJob: expiring stale tunnels") if hasattr(context, "tunnel_manager"): context.tunnel_manager.expire_tunnels() class DatabaseSearchJob(Job): """One-shot iterative Kademlia search in the network database. This is a one-shot job (not a TimedJob) — it executes once and is removed from the queue. """ def __init__(self, priority: int = 3) -> None: super().__init__(name="database-search", priority=priority) def execute(self, context: Any) -> None: log.debug("DatabaseSearchJob: running iterative lookup") if hasattr(context, "netdb_handler"): context.netdb_handler.run_search() class PeerProfileUpdateJob(TimedJob): """Update peer statistics and prune dead peers. Runs every 120 seconds. """ def __init__(self, priority: int = 7) -> None: super().__init__( name="peer-profile-update", priority=priority, interval_seconds=120.0, ) def run(self, context: Any) -> None: log.debug("PeerProfileUpdateJob: updating peer profiles") if hasattr(context, "peer_manager"): context.peer_manager.update_profiles()