java.lang.Object
net.i2p.router.networkdb.reseed.Reseeder.ReseedRunner
All Implemented Interfaces:
Runnable, EepGet.StatusListener
Enclosing class:
Reseeder

private class Reseeder.ReseedRunnerextends Object implements Runnable, EepGet.StatusListener
Runs one reseed download attempt.
  • Field Details

    • _isRunning

      private boolean _isRunning
      True while this attempt is running.
    • _proxyHost

      private final String _proxyHost
      Proxy host for HTTP fetches.
    • _sproxyHost

      private final String _sproxyHost
      Proxy host for HTTPS fetches.
    • _proxyPort

      private final int _proxyPort
      Proxy port for HTTP fetches.
    • _sproxyPort

      private final int _sproxyPort
      Proxy port for HTTPS fetches.
    • _shouldProxyHTTP

      private final boolean _shouldProxyHTTP
      True to route HTTP fetches through the proxy.
    • _shouldProxySSL

      private final boolean _shouldProxySSL
      True to route HTTPS fetches through the proxy.
    • _sproxyType

      private final SSLEepGet.ProxyType _sproxyType
      Proxy type used for HTTPS fetches.
    • _sslState

      private SSLEepGet.SSLState _sslState
      SSL result of the fetch, for the stats.
    • _gotDate

      private int _gotDate
      Nonzero once a reseed date was seen.
    • _attemptStarted

      private long _attemptStarted
      When the current attempt started.
    • _bandwidths

      private final List<Long> _bandwidths
      Bytes per second for each SU3 download.
    • MAX_DATE_SETS

      private static final int MAX_DATE_SETS
      Distinct reseed dates accepted per attempt.
      See Also:
    • _url

      private final URI _url
      The reseed URL being fetched.
  • Constructor Details

    • ReseedRunner

      public ReseedRunner()
      Start a reseed from the default URL list.
    • ReseedRunner

      public ReseedRunner(URI url) throws IllegalArgumentException
      Start a reseed from this URL only, or null for trying one or more from the default list.
      Parameters:
      url - if non-null, must be a zip or su3 URL, NOT a directory
      Throws:
      IllegalArgumentException - if it doesn't end with zip or su3
  • Method Details

    • validateUrl

      private void validateUrl(URI url)
      Rejects a reseed URL that is not HTTPS.
      Parameters:
      url - the URL to validate
    • isValidHostPort

      private boolean isValidHostPort(String host, int port)
      Checks the URL host and port are acceptable.
      Parameters:
      host - the URL host
      port - the URL port
      Returns:
      true if the URL may be fetched
    • run

      public void run()
      Run the reseed sequence.
      Specified by:
      run in interface Runnable
    • run2

      private void run2()
      Runs one reseed download and apply attempt.
    • processBandwidths

      private void processBandwidths()
      Record and log download bandwidth samples. @since 0.9.18.
    • attemptFailed

      public void attemptFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt, int numRetries, Exception cause)
      Log and report a failed reseed attempt. readURL() runs an EepGet with 0 retries, so errors arrive here with the failure cause (unlike transferFailed(String, long, long, int)).
      Specified by:
      attemptFailed in interface EepGet.StatusListener
      Parameters:
      url - the full URL that failed
      bytesTransferred - bytes transferred before failure
      bytesRemaining - bytes remaining when failed
      currentAttempt - attempt number, as EepGet counts it
      numRetries - retries remaining, always 0 because readURL() runs EepGet with none
      cause - the exception that caused the failure
      See Also:
    • bytesTransferred

      public void bytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url)
      Progress not tracked here. @see #attemptFailed.
      Specified by:
      bytesTransferred in interface EepGet.StatusListener
      Parameters:
      alreadyTransferred - total of all attempts, not including currentWrite If nonzero on the first call, a partial file of that length was found, _and_ the server supports resume. If zero on a subsequent call after some bytes are transferred (and presumably after an attemptFailed), the server does _not_ support resume and we had to start over. To track _actual_ transfer if the output file could already exist, the listener should keep its own counter, or subtract the initial alreadyTransferred value. And watch out for alreadyTransferred resetting if a resume failed...
      currentWrite - since last call to the listener
      bytesTransferred - includes headers, retries, redirects, discarded partial downloads, ...
      bytesRemaining - on this attempt only, currentWrite already subtracted - or -1 if chunked encoding or server does not return a length
      url - the URL being fetched
    • transferComplete

      public void transferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified)
      Completion handled in caller.
      Specified by:
      transferComplete in interface EepGet.StatusListener
      Parameters:
      alreadyTransferred - total bytes transferred
      bytesTransferred - total incl headers
      bytesRemaining - bytes still owed by the server, or -1 if chunked encoding or no Content-Length was returned
      url - the address the transfer was reading
      outputFile - null if unknown (output stream constructor)
      notModified - whether 304
      See Also:
    • transferFailed

      public void transferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt)
      Specified by:
      transferFailed in interface EepGet.StatusListener
      Parameters:
      url - the address whose transfer failed
      bytesTransferred - bytes received so far, counted across every attempt and including response headers
      bytesRemaining - bytes still owed, or -1 if unknown
      currentAttempt - zero-based index of the attempt that failed
      See Also:
    • headerReceived

      public void headerReceived(String url, int attemptNum, String key, String val)
      Use the Date header as a backup time source. May be called multiple times; the first call has lower stratum than subsequent refinements.
      Specified by:
      headerReceived in interface EepGet.StatusListener
      Parameters:
      url - the address the header arrived on
      attemptNum - zero-based index of the attempt the header arrived on
      key - header key
      val - header value
    • attempting

      public void attempting(String url)
      Record the attempt start time for RTT-based clock adjustment.
      Specified by:
      attempting in interface EepGet.StatusListener
      Parameters:
      url - the URL being attempted
    • reseed

      private int reseed(boolean echoStatus)
      Performs reseed operation using configured URLs or defaults.

      <p>Builds a list of URIs to use for reseeding based on current configuration and SSL settings, then delegates to the reseed method that accepts a URI list.

      Parameters:
      echoStatus - Whether to echo status messages (typically false)
      Returns:
      count of routerinfos successfully fetched, or -1 if no valid URLs
    • buildUrlList

      private List<URI> buildUrlList()
      Builds the list of URIs to use for reseed based on configured properties and defaults.

      <p>Handles default URLs, SSL enablement/disablement, shuffling, and filtering based on SNI support.

      Returns:
      list of URIs to attempt reseed from
    • parseUrlsWithTrailingSlash

      private List<URI> parseUrlsWithTrailingSlash(String urls)
      Parses a comma/space separated list of URLs into a list of URIs, ensuring each ends with a trailing slash.
      Parameters:
      urls - String containing the URLs to parse
      Returns:
      list of URIs, excluding invalid ones
    • safeUri

      private URI safeUri(String u)
      Safely converts a string to a URI, returning null if invalid.
      Parameters:
      u - URL string to convert
      Returns:
      corresponding URI, or null if syntax invalid
    • filterUrlsIfNoSNI

      private void filterUrlsIfNoSNI(List<URI> urlList)
      Removes specific URLs from the list if Server Name Indication (SNI) is not supported.
      Parameters:
      urlList - list of URIs to filter
    • reseed

      private int reseed(List<URI> urlList, boolean echoStatus)
      Attempts to fetch router information files from the specified list of URIs.

      <p>Tracks the number of routerinfos successfully fetched and stops when minimum targets are met or when shutdown in progress.

      Parameters:
      urlList - the list of URIs to fetch reseed data from
      echoStatus - Whether to echo status messages (typically false)
      Returns:
      count of routerinfos successfully fetched
    • reseedSU3

      public int reseedSU3(URI seedURL, boolean echoStatus)
      Fetch an su3 file containing routerInfo files. Updates status on the checker.
      Parameters:
      seedURL - the URL of the SU3 file
      echoStatus - if true, print debug dots per routerinfo
      Returns:
      count of routerinfos successfully fetched
    • reseedZip

      public int reseedZip(URI seedURL, boolean echoStatus)
      Fetch a zip file containing routerInfo files. Updates status on the checker.
      Parameters:
      seedURL - the URL of the zip file
      echoStatus - if true, print debug dots per routerinfo
      Returns:
      count of routerinfos successfully fetched
    • reseedSU3OrZip

      private int reseedSU3OrZip(URI seedURL, boolean isSU3, boolean echoStatus)
      Fetch an su3 or zip file containing routerInfo files. Updates status on the checker.
      Parameters:
      seedURL - the URL of the SU3 or zip file
      isSU3 - true for SU3, false for zip
      echoStatus - if true, print debug dots per routerinfo
      Returns:
      count of routerinfos successfully fetched
    • extractSU3

      public int[] extractSU3(File contentRaw) throws IOException
      Verify and extract router infos from a downloaded SU3 bundle.
      Parameters:
      contentRaw - the downloaded file holding the SU3 bundle
      Returns:
      2 ints: number successful and number of errors
      Throws:
      IOException - if the SU3 content type is not reseed, the file is too old, or reading or verifying it fails
    • extractZip

      public int[] extractZip(File zip) throws IOException
      Extract and validate router info files from a zip bundle.
      Parameters:
      zip - the downloaded file holding the zip bundle
      Returns:
      2 ints: number successful and number of errors
      Throws:
      IOException - if the zip cannot be read or unpacked
    • fetchURL

      private File fetchURL(URI url)
      Fetch a URL to a temporary file.
      Parameters:
      url - the URL to fetch
      Returns:
      temp file with content, or null on error
    • getProxyType

      private SSLEepGet.ProxyType getProxyType() throws IllegalArgumentException
      Resolve the SSL proxy type from configuration.
      Returns:
      non-null proxy type
      Throws:
      IllegalArgumentException - if unknown, default is HTTP
    • getDisplayString

      private String getDisplayString(URI url)
      Display string for what we're fetching. Untranslated, for logs only.
      Parameters:
      url - if null, returns ""
      Returns:
      the untranslated display string, or "" if url is null
    • getDisplayString

      private String getDisplayString(String url)
      Display string for what we're fetching. Untranslated, for logs only.
      Parameters:
      url - if null, returns ""
      Returns:
      the untranslated display string, or "" if url is null
    • getDisplayString

      private String getDisplayString(SSLEepGet.ProxyType type)
      Display string for what we're fetching. Untranslated, for logs only.
      Parameters:
      type - the proxy type being fetched
      Returns:
      the display string