java.lang.Object
net.i2p.router.networkdb.reseed.Reseeder.ReseedRunner
- All Implemented Interfaces:
Runnable, EepGet.StatusListener
- Enclosing class:
Reseeder
Runs one reseed download attempt.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate longWhen the current attempt started.Bytes per second for each SU3 download.private intNonzero once a reseed date was seen.private booleanTrue while this attempt is running.private final StringProxy host for HTTP fetches.private final intProxy port for HTTP fetches.private final booleanTrue to route HTTP fetches through the proxy.private final booleanTrue to route HTTPS fetches through the proxy.private final StringProxy host for HTTPS fetches.private final intProxy port for HTTPS fetches.private final SSLEepGet.ProxyTypeProxy type used for HTTPS fetches.private SSLEepGet.SSLStateSSL result of the fetch, for the stats.private final URIThe reseed URL being fetched.private static final intDistinct reseed dates accepted per attempt.Constructor Summary
ConstructorsConstructorDescriptionStart a reseed from the default URL list.ReseedRunner(URI url) Start a reseed from this URL only, or null for trying one or more from the default list.Method Summary
Modifier and TypeMethodDescriptionvoidattemptFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt, int numRetries, Exception cause) Log and report a failed reseed attempt.voidattempting(String url) Record the attempt start time for RTT-based clock adjustment.Builds the list of URIs to use for reseed based on configured properties and defaults.voidbytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url) Progress not tracked here.int[]extractSU3(File contentRaw) Verify and extract router infos from a downloaded SU3 bundle.int[]extractZip(File zip) Extract and validate router info files from a zip bundle.private FileFetch a URL to a temporary file.private voidfilterUrlsIfNoSNI(List<URI> urlList) Removes specific URLs from the list if Server Name Indication (SNI) is not supported.private StringgetDisplayString(String url) Display string for what we're fetching.private StringgetDisplayString(URI url) Display string for what we're fetching.private StringDisplay string for what we're fetching.private SSLEepGet.ProxyTypeResolve the SSL proxy type from configuration.voidheaderReceived(String url, int attemptNum, String key, String val) Use the Date header as a backup time source.private booleanisValidHostPort(String host, int port) Checks the URL host and port are acceptable.Parses a comma/space separated list of URLs into a list of URIs, ensuring each ends with a trailing slash.private voidRecord and log download bandwidth samples.private intreseed(boolean echoStatus) Performs reseed operation using configured URLs or defaults.private intAttempts to fetch router information files from the specified list of URIs.intFetch an su3 file containing routerInfo files.private intreseedSU3OrZip(URI seedURL, boolean isSU3, boolean echoStatus) Fetch an su3 or zip file containing routerInfo files.intFetch a zip file containing routerInfo files.voidrun()Run the reseed sequence.private voidrun2()Runs one reseed download and apply attempt.private URISafely converts a string to a URI, returning null if invalid.voidtransferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified) Completion handled in caller.voidtransferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt) Failure handled inattemptFailed(String, long, long, int, int, Exception).private voidvalidateUrl(URI url) Rejects a reseed URL that is not HTTPS.
Field Details
_isRunning
private boolean _isRunningTrue while this attempt is running._proxyHost
Proxy host for HTTP fetches._sproxyHost
Proxy host for HTTPS fetches._proxyPort
private final int _proxyPortProxy port for HTTP fetches._sproxyPort
private final int _sproxyPortProxy port for HTTPS fetches._shouldProxyHTTP
private final boolean _shouldProxyHTTPTrue to route HTTP fetches through the proxy._shouldProxySSL
private final boolean _shouldProxySSLTrue to route HTTPS fetches through the proxy._sproxyType
Proxy type used for HTTPS fetches._sslState
SSL result of the fetch, for the stats._gotDate
private int _gotDateNonzero once a reseed date was seen._attemptStarted
private long _attemptStartedWhen the current attempt started._bandwidths
MAX_DATE_SETS
private static final int MAX_DATE_SETSDistinct reseed dates accepted per attempt.- See Also:
_url
The reseed URL being fetched.
Constructor Details
ReseedRunner
public ReseedRunner()Start a reseed from the default URL list.ReseedRunner
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
Rejects a reseed URL that is not HTTPS.- Parameters:
url- the URL to validate
isValidHostPort
Checks the URL host and port are acceptable.- Parameters:
host- the URL hostport- the URL port- Returns:
- true if the URL may be fetched
run
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 (unliketransferFailed(String, long, long, int)).- Specified by:
attemptFailedin interfaceEepGet.StatusListener- Parameters:
url- the full URL that failedbytesTransferred- bytes transferred before failurebytesRemaining- bytes remaining when failedcurrentAttempt- attempt number, as EepGet counts itnumRetries- retries remaining, always 0 because readURL() runs EepGet with nonecause- 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:
bytesTransferredin interfaceEepGet.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 listenerbytesTransferred- 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 lengthurl- 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:
transferCompletein interfaceEepGet.StatusListener- Parameters:
alreadyTransferred- total bytes transferredbytesTransferred- total incl headersbytesRemaining- bytes still owed by the server, or -1 if chunked encoding or no Content-Length was returnedurl- the address the transfer was readingoutputFile- null if unknown (output stream constructor)notModified- whether 304- See Also:
transferFailed
public void transferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt) Failure handled inattemptFailed(String, long, long, int, int, Exception).- Specified by:
transferFailedin interfaceEepGet.StatusListener- Parameters:
url- the address whose transfer failedbytesTransferred- bytes received so far, counted across every attempt and including response headersbytesRemaining- bytes still owed, or -1 if unknowncurrentAttempt- zero-based index of the attempt that failed- See Also:
headerReceived
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:
headerReceivedin interfaceEepGet.StatusListener- Parameters:
url- the address the header arrived onattemptNum- zero-based index of the attempt the header arrived onkey- header keyval- header value
attempting
Record the attempt start time for RTT-based clock adjustment.- Specified by:
attemptingin interfaceEepGet.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
parseUrlsWithTrailingSlash
safeUri
filterUrlsIfNoSNI
reseed
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 fromechoStatus- Whether to echo status messages (typically false)- Returns:
- count of routerinfos successfully fetched
reseedSU3
Fetch an su3 file containing routerInfo files. Updates status on the checker.- Parameters:
seedURL- the URL of the SU3 fileechoStatus- if true, print debug dots per routerinfo- Returns:
- count of routerinfos successfully fetched
reseedZip
Fetch a zip file containing routerInfo files. Updates status on the checker.- Parameters:
seedURL- the URL of the zip fileechoStatus- if true, print debug dots per routerinfo- Returns:
- count of routerinfos successfully fetched
reseedSU3OrZip
Fetch an su3 or zip file containing routerInfo files. Updates status on the checker.- Parameters:
seedURL- the URL of the SU3 or zip fileisSU3- true for SU3, false for zipechoStatus- if true, print debug dots per routerinfo- Returns:
- count of routerinfos successfully fetched
extractSU3
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
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
getProxyType
Resolve the SSL proxy type from configuration.- Returns:
- non-null proxy type
- Throws:
IllegalArgumentException- if unknown, default is HTTP
getDisplayString
getDisplayString
getDisplayString
Display string for what we're fetching. Untranslated, for logs only.- Parameters:
type- the proxy type being fetched- Returns:
- the display string