java.lang.Object
net.i2p.router.JobImpl
net.i2p.router.tasks.PersistRouterInfoJob
All Implemented Interfaces:
Job

public class PersistRouterInfoJobextends JobImpl
Router information persistence and synchronization job.

This job is responsible for persisting the router's RouterInfo to disk whenever it changes. The RouterInfo contains critical router identity, capabilities, addresses, and statistics that must be preserved across restarts and shared with the network.

RouterInfo Contents:

  • Router identity (public keys, certificates)
  • Network addresses and transport endpoints
  • Router capabilities and supported versions
  • Performance statistics and bandwidth limits
  • Current router status and options

Persistence Process:

  • Retrieves current RouterInfo from router
  • Writes to router.info file in router directory
  • Uses synchronized access to prevent corruption
  • Employs atomic file writing for safety
  • Handles errors gracefully with detailed logging

File Safety:

  • Uses SecureFileOutputStream for atomic writes
  • Synchronized on routerInfoFileLock for thread safety
  • Prevents partial writes and corruption
  • Ensures consistent state across restarts

This job is triggered automatically whenever RouterInfo is updated due to address changes, capability changes, or periodic refreshes. The persisted file is used for router startup and network database publication.

  • Constructor Details

    • PersistRouterInfoJob

      public PersistRouterInfoJob(RouterContext ctx)
      Create a new router info persistence job.
      Parameters:
      ctx - router context for accessing router services
  • Method Details

    • getName

      public String getName()
      Name of this job.
      Returns:
      job name for logging and identification
    • runJob

      public void runJob()
      Save the current router information to disk.

      This job writes the router's RouterInfo to the router.info file in the router directory. It uses a synchronized block to ensure thread-safe access to the router info file.

      The file is written using SecureFileOutputStream to ensure atomic writes and prevent corruption. Any errors during the write process are logged but do not prevent the job from completing.