diff --git a/router/java/src/net/i2p/router/CommandLine.java b/router/java/src/net/i2p/router/CommandLine.java index 65c789e4123f7b451f31ab167d23b060d756bf9c..0d955338edfa67ef2c8b29fbec100512a79733ff 100644 --- a/router/java/src/net/i2p/router/CommandLine.java +++ b/router/java/src/net/i2p/router/CommandLine.java @@ -23,6 +23,7 @@ public class CommandLine extends net.i2p.util.CommandLine { "net.i2p.router.RouterVersion", "net.i2p.router.crypto.FamilyKeyCrypto", "net.i2p.router.naming.BlockfileNamingService", + "net.i2p.router.networkdb.reseed.Reseeder", "net.i2p.router.peermanager.ProfileOrganizer", "net.i2p.router.tasks.CryptoChecker", "net.i2p.router.time.NtpClient", diff --git a/router/java/src/net/i2p/router/networkdb/reseed/Reseeder.java b/router/java/src/net/i2p/router/networkdb/reseed/Reseeder.java index 6cbdaa59a3b21433e38ad89a84956294e65ec415..b1bb9172210322db2eb581ab909a29afcb4cfacc 100644 --- a/router/java/src/net/i2p/router/networkdb/reseed/Reseeder.java +++ b/router/java/src/net/i2p/router/networkdb/reseed/Reseeder.java @@ -1219,15 +1219,83 @@ public class Reseeder { return Translate.getString(n, s, p, _context, BUNDLE_NAME); } -/****** - public static void main(String args[]) { - if ( (args != null) && (args.length == 1) && (!Boolean.parseBoolean(args[0])) ) { - System.out.println("Not reseeding, as requested"); - return; // not reseeding on request + /** + * @since 0.9.58 + */ + public static void main(String args[]) throws Exception { + File f = new File("certificates"); + if (!f.exists()) { + System.out.println("Must be run from $I2P or have symlink to $I2P/certificates in this directory"); + System.exit(1); + } + String[] urls = (args.length > 0) ? args : DataHelper.split(DEFAULT_SSL_SEED_URL, ","); + int pass = 0, fail = 0; + SSLEepGet.SSLState sslState = null; + I2PAppContext ctx = I2PAppContext.getGlobalContext(); + for (String url : urls) { + url += SU3_FILENAME + NETID_PARAM + '2'; + URI uri = new URI(url); + String host = uri.getHost(); + System.out.println("Testing " + host); + File su3 = new File(host + ".su3"); + try { + SSLEepGet get; + if (sslState == null) { + get = new SSLEepGet(ctx, su3.getPath(), url); + sslState = get.getSSLState(); + } else { + get = new SSLEepGet(ctx, su3.getPath(), url, sslState); + } + if (get.fetch()) { + int rc = get.getStatusCode(); + if (rc == 200) { + SU3File su3f = new SU3File(su3); + File zip = new File(host + ".zip"); + su3f.verifyAndMigrate(zip); + SU3File.main(new String[] {"showversion", su3.getPath()}); + String version = su3f.getVersionString(); + try { + Long ver = Long.parseLong(version.trim()); + ver *= 1000; + if (ver < System.currentTimeMillis() - MAX_FILE_AGE / 4) + throw new IOException("su3 file too old"); + } catch (NumberFormatException nfe) {} + java.util.zip.ZipFile zipf = new java.util.zip.ZipFile(zip); + java.util.Enumeration<? extends java.util.zip.ZipEntry> entries = zipf.entries(); + int ri = 0; + while (entries.hasMoreElements()) { + entries.nextElement(); + ri++; + } + zipf.close(); + System.out.println("Test passed for " + host + ", returned " + ri + " router infos"); + pass++; + } else { + System.out.println("Test failed for " + host + " return code: " + rc); + su3.delete(); + fail++; + } + } else { + int rc = get.getStatusCode(); + System.out.println("Test failed for " + host + " return code: " + rc); + su3.delete(); + fail++; + } + } catch (IOException ioe) { + System.out.println("Test failed for " + host + ": " + ioe); + ioe.printStackTrace(); + if (su3.exists()) { + try { + SU3File.main(new String[] {"showversion", su3.getPath()}); + } catch (Exception e) {} + su3.delete(); + } + fail++; + } + System.out.println(); } - System.out.println("Reseeding"); - Reseeder reseedHandler = new Reseeder(); - reseedHandler.requestReseed(); + System.out.println("Passed: " + pass + "; Failed: " + fail); + if (fail > 0) + System.exit(1); } -******/ }