forked from I2P_Developers/i2p.i2p
propagate from branch 'i2p.i2p' (head b7ee04ecc7a594239e977b25a52ebdabadce558e)
to branch 'i2p.i2p.zzz.jetty6' (head 2cd4a4dae8b87b9ed2128d83aff1b39e3a818556)
This commit is contained in:
@@ -488,9 +488,7 @@ public class Blocklist {
|
||||
for (int j = 0; j < paddr.size(); j++) {
|
||||
RouterAddress pa = (RouterAddress) pladdr.get(j);
|
||||
if (pa == null) continue;
|
||||
Properties pprops = pa.getOptions();
|
||||
if (pprops == null) continue;
|
||||
String phost = pprops.getProperty("host");
|
||||
String phost = pa.getOption("host");
|
||||
if (phost == null) continue;
|
||||
if (oldphost != null && oldphost.equals(phost)) continue;
|
||||
oldphost = phost;
|
||||
|
@@ -12,6 +12,7 @@ package net.i2p.router;
|
||||
* Defines the criteria for selecting a set of peers for use when searching the
|
||||
* PeerManager
|
||||
*
|
||||
* Only used by PeerTestJob, which may not have a point.
|
||||
*/
|
||||
public class PeerSelectionCriteria {
|
||||
/** The peers will be used in a tunnel */
|
||||
|
@@ -60,7 +60,7 @@ import net.i2p.util.SimpleScheduler;
|
||||
*
|
||||
*/
|
||||
public class Router implements RouterClock.ClockShiftListener {
|
||||
private final Log _log;
|
||||
private Log _log;
|
||||
private final RouterContext _context;
|
||||
private final Map<String, String> _config;
|
||||
/** full path */
|
||||
@@ -77,9 +77,9 @@ public class Router implements RouterClock.ClockShiftListener {
|
||||
private ShutdownHook _shutdownHook;
|
||||
/** non-cancellable shutdown has begun */
|
||||
private volatile boolean _shutdownInProgress;
|
||||
private final I2PThread _gracefulShutdownDetector;
|
||||
private final RouterWatchdog _watchdog;
|
||||
private final Thread _watchdogThread;
|
||||
private I2PThread _gracefulShutdownDetector;
|
||||
private RouterWatchdog _watchdog;
|
||||
private Thread _watchdogThread;
|
||||
|
||||
public final static String PROP_CONFIG_FILE = "router.configLocation";
|
||||
|
||||
@@ -128,9 +128,17 @@ public class Router implements RouterClock.ClockShiftListener {
|
||||
System.setProperty("Dorg.mortbay.util.FileResource.checkAliases", "true");
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiation only. Starts no threads. Does not install updates.
|
||||
* RouterContext is created but not initialized.
|
||||
* You must call runRouter() after any constructor to start things up.
|
||||
*/
|
||||
public Router() { this(null, null); }
|
||||
|
||||
public Router(Properties envProps) { this(null, envProps); }
|
||||
|
||||
public Router(String configFilename) { this(configFilename, null); }
|
||||
|
||||
public Router(String configFilename, Properties envProps) {
|
||||
_gracefulExitCode = -1;
|
||||
_config = new ConcurrentHashMap();
|
||||
@@ -233,16 +241,20 @@ public class Router implements RouterClock.ClockShiftListener {
|
||||
String now = Long.toString(System.currentTimeMillis());
|
||||
_config.put("router.firstInstalled", now);
|
||||
_config.put("router.updateLastInstalled", now);
|
||||
// only compatible with new i2prouter script
|
||||
_config.put("router.gracefulHUP", "true");
|
||||
saveConfig();
|
||||
}
|
||||
// ********* Start no threads before here ********* //
|
||||
}
|
||||
|
||||
// This is here so that we can get the directory location from the context
|
||||
// for the zip file and the base location to unzip to.
|
||||
// If it does an update, it never returns.
|
||||
// I guess it's better to have the other-router check above this, we don't want to
|
||||
// overwrite an existing running router's jar files. Other than ours.
|
||||
installUpdates();
|
||||
|
||||
/**
|
||||
* Initializes the RouterContext.
|
||||
* Starts some threads. Does not install updates.
|
||||
* All this was in the constructor.
|
||||
* @since 0.8.12
|
||||
*/
|
||||
private void startupStuff() {
|
||||
// ********* Start no threads before here ********* //
|
||||
//
|
||||
// NOW we can start the ping file thread.
|
||||
@@ -372,11 +384,18 @@ public class Router implements RouterClock.ClockShiftListener {
|
||||
|
||||
public RouterContext getContext() { return _context; }
|
||||
|
||||
/**
|
||||
* Initializes the RouterContext.
|
||||
* Starts the threads. Does not install updates.
|
||||
*/
|
||||
void runRouter() {
|
||||
if (_isAlive)
|
||||
throw new IllegalStateException();
|
||||
startupStuff();
|
||||
_isAlive = true;
|
||||
_started = _context.clock().now();
|
||||
try {
|
||||
Runtime.getRuntime().removeShutdownHook(_shutdownHook);
|
||||
Runtime.getRuntime().addShutdownHook(_shutdownHook);
|
||||
} catch (IllegalStateException ise) {}
|
||||
I2PThread.addOOMEventListener(_oomListener);
|
||||
|
||||
@@ -987,9 +1006,12 @@ public class Router implements RouterClock.ClockShiftListener {
|
||||
|
||||
/**
|
||||
* Cancel the JVM runtime hook before calling this.
|
||||
* Called by the ShutdownHook.
|
||||
* NOT to be called by others, use shutdown().
|
||||
*/
|
||||
public void shutdown2(int exitCode) {
|
||||
_shutdownInProgress = true;
|
||||
_log.log(Log.CRIT, "Starting final shutdown(" + exitCode + ')');
|
||||
// So we can get all the way to the end
|
||||
// No, you can't do Thread.currentThread.setDaemon(false)
|
||||
if (_killVMOnEnd) {
|
||||
@@ -1004,6 +1026,7 @@ public class Router implements RouterClock.ClockShiftListener {
|
||||
// Run the shutdown hooks first in case they want to send some goodbye messages
|
||||
// Maybe we need a delay after this too?
|
||||
for (Runnable task : _context.getShutdownTasks()) {
|
||||
//System.err.println("Running shutdown task " + task.getClass());
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Running shutdown task " + task.getClass());
|
||||
try {
|
||||
@@ -1098,7 +1121,7 @@ public class Router implements RouterClock.ClockShiftListener {
|
||||
//Runtime.getRuntime().halt(exitCode);
|
||||
// allow the Runtime shutdown hooks to execute
|
||||
Runtime.getRuntime().exit(exitCode);
|
||||
} else {
|
||||
} else if (System.getProperty("java.vendor").contains("Android")) {
|
||||
Runtime.getRuntime().gc();
|
||||
}
|
||||
}
|
||||
@@ -1266,13 +1289,18 @@ public class Router implements RouterClock.ClockShiftListener {
|
||||
|
||||
public static void main(String args[]) {
|
||||
System.out.println("Starting I2P " + RouterVersion.FULL_VERSION);
|
||||
// installUpdates() moved to constructor so we can get file locations from the context
|
||||
// installUpdates();
|
||||
//verifyWrapperConfig();
|
||||
Router r = new Router();
|
||||
if ( (args != null) && (args.length == 1) && ("rebuild".equals(args[0])) ) {
|
||||
r.rebuildNewIdentity();
|
||||
} else {
|
||||
// This is here so that we can get the directory location from the context
|
||||
// for the zip file and the base location to unzip to.
|
||||
// If it does an update, it never returns.
|
||||
// I guess it's better to have the other-router check above this, we don't want to
|
||||
// overwrite an existing running router's jar files. Other than ours.
|
||||
r.installUpdates();
|
||||
// ********* Start no threads before here ********* //
|
||||
r.runRouter();
|
||||
}
|
||||
}
|
||||
@@ -1281,6 +1309,7 @@ public class Router implements RouterClock.ClockShiftListener {
|
||||
private static final String DELETE_FILE = "deletelist.txt";
|
||||
|
||||
/**
|
||||
* Context must be available.
|
||||
* Unzip update file found in the router dir OR base dir, to the base dir
|
||||
*
|
||||
* If we can't write to the base dir, complain.
|
||||
|
@@ -18,10 +18,10 @@ public class RouterVersion {
|
||||
/** deprecated */
|
||||
public final static String ID = "Monotone";
|
||||
public final static String VERSION = CoreVersion.VERSION;
|
||||
public final static long BUILD = 24;
|
||||
public final static long BUILD = 1;
|
||||
|
||||
/** for example "-test" */
|
||||
public final static String EXTRA = "-rc";
|
||||
public final static String EXTRA = "";
|
||||
public final static String FULL_VERSION = VERSION + "-" + BUILD + EXTRA;
|
||||
public static void main(String args[]) {
|
||||
System.out.println("I2P Router version: " + FULL_VERSION);
|
||||
|
@@ -41,7 +41,7 @@ public class PublishLocalRouterInfoJob extends JobImpl {
|
||||
RouterInfo ri = new RouterInfo(getContext().router().getRouterInfo());
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Old routerInfo contains " + ri.getAddresses().size()
|
||||
+ " addresses and " + ri.getOptions().size() + " options");
|
||||
+ " addresses and " + ri.getOptionsMap().size() + " options");
|
||||
Properties stats = getContext().statPublisher().publishStatistics();
|
||||
stats.setProperty(RouterInfo.PROP_NETWORK_ID, ""+Router.NETWORK_ID);
|
||||
try {
|
||||
@@ -60,7 +60,7 @@ public class PublishLocalRouterInfoJob extends JobImpl {
|
||||
getContext().router().setRouterInfo(ri);
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Newly updated routerInfo is published with " + stats.size()
|
||||
+ "/" + ri.getOptions().size() + " options on "
|
||||
+ "/" + ri.getOptionsMap().size() + " options on "
|
||||
+ new Date(ri.getPublished()));
|
||||
try {
|
||||
getContext().netDb().publish(ri);
|
||||
|
@@ -133,8 +133,7 @@ class FloodfillMonitorJob extends JobImpl {
|
||||
if (ra == null)
|
||||
happy = false;
|
||||
else {
|
||||
Properties props = ra.getOptions();
|
||||
if (props == null || props.getProperty("ihost0") != null)
|
||||
if (ra.getOption("ihost0") != null)
|
||||
happy = false;
|
||||
}
|
||||
}
|
||||
|
@@ -786,8 +786,7 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
|
||||
RouterAddress ra = routerInfo.getTargetAddress("SSU");
|
||||
if (ra != null) {
|
||||
// Introducers change often, introducee will ping introducer for 2 hours
|
||||
Properties props = ra.getOptions();
|
||||
if (props != null && props.getProperty("ihost0") != null)
|
||||
if (ra.getOption("ihost0") != null)
|
||||
return "Peer " + key.toBase64() + " published > 75m ago with SSU Introducers";
|
||||
if (routerInfo.getTargetAddress("NTCP") == null)
|
||||
return "Peer " + key.toBase64() + " published > 75m ago, SSU only without introducers";
|
||||
@@ -822,10 +821,10 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
|
||||
if (err != null)
|
||||
throw new IllegalArgumentException("Invalid store attempt - " + err);
|
||||
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("RouterInfo " + key.toBase64() + " is stored with "
|
||||
+ routerInfo.getOptions().size() + " options on "
|
||||
+ new Date(routerInfo.getPublished()));
|
||||
//if (_log.shouldLog(Log.DEBUG))
|
||||
// _log.debug("RouterInfo " + key.toBase64() + " is stored with "
|
||||
// + routerInfo.getOptionsMap().size() + " options on "
|
||||
// + new Date(routerInfo.getPublished()));
|
||||
|
||||
_context.peerManager().setCapabilities(key, routerInfo.getCapabilities());
|
||||
_ds.put(key, routerInfo, persist);
|
||||
|
@@ -25,6 +25,7 @@ import net.i2p.util.Log;
|
||||
* selection to the peer manager and tests the peer by sending it a useless
|
||||
* database store message
|
||||
*
|
||||
* TODO - What's the point? Disable this? See also notes in PeerManager.selectPeers()
|
||||
*/
|
||||
public class PeerTestJob extends JobImpl {
|
||||
private final Log _log;
|
||||
@@ -65,7 +66,8 @@ public class PeerTestJob extends JobImpl {
|
||||
_log.info("Stop testing peers");
|
||||
}
|
||||
|
||||
public String getName() { return "Initiate some peer tests"; }
|
||||
public String getName() { return "Peer test start"; }
|
||||
|
||||
public void runJob() {
|
||||
if (!_keepTesting) return;
|
||||
Set peers = selectPeersToTest();
|
||||
|
@@ -701,8 +701,7 @@ public class ProfileOrganizer {
|
||||
continue;
|
||||
}
|
||||
// This is the quick way of doing UDPAddress.getIntroducerCount() > 0
|
||||
Properties props = ra.getOptions();
|
||||
if (props != null && props.getProperty("ihost0") != null)
|
||||
if (ra.getOption("ihost0") != null)
|
||||
l.add(peer);
|
||||
}
|
||||
}
|
||||
@@ -1263,9 +1262,7 @@ public class ProfileOrganizer {
|
||||
if (paddr == null)
|
||||
return rv;
|
||||
for (RouterAddress pa : paddr) {
|
||||
Properties pprops = pa.getOptions();
|
||||
if (pprops == null) continue;
|
||||
String phost = pprops.getProperty("host");
|
||||
String phost = pa.getOption("host");
|
||||
if (phost == null) continue;
|
||||
InetAddress pi;
|
||||
try {
|
||||
|
@@ -12,6 +12,7 @@ import net.i2p.router.Job;
|
||||
import net.i2p.router.JobImpl;
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.router.RouterClock;
|
||||
import net.i2p.router.tasks.ReadConfigJob;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/** This actually boots almost everything */
|
||||
|
@@ -1,4 +1,4 @@
|
||||
package net.i2p.router.startup;
|
||||
package net.i2p.router.tasks;
|
||||
/*
|
||||
* free (adj.): unencumbered; not under the control of others
|
||||
* Written by jrandom in 2003 and released into the public domain
|
@@ -32,6 +32,10 @@ public class ShutdownHook extends Thread {
|
||||
setName("Router " + _id + " shutdown");
|
||||
Log l = _context.logManager().getLog(Router.class);
|
||||
l.log(Log.CRIT, "Shutting down the router...");
|
||||
// Needed to make the wrapper happy, otherwise it gets confused
|
||||
// and thinks we haven't shut down, possibly because it
|
||||
// prevents other shutdown hooks from running
|
||||
_context.router().setKillVMOnEnd(false);
|
||||
_context.router().shutdown2(Router.EXIT_HARD);
|
||||
}
|
||||
}
|
||||
|
@@ -266,24 +266,17 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
|
||||
NTCPTransport t = (NTCPTransport) _manager.getTransport(NTCPTransport.STYLE);
|
||||
if (t == null)
|
||||
return;
|
||||
Properties UDPProps = UDPAddr.getOptions();
|
||||
if (UDPProps == null)
|
||||
return;
|
||||
Properties newProps;
|
||||
RouterAddress oldAddr = t.getCurrentAddress();
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Changing NTCP Address? was " + oldAddr);
|
||||
RouterAddress newAddr = oldAddr;
|
||||
if (newAddr == null) {
|
||||
newAddr = new RouterAddress();
|
||||
RouterAddress newAddr = new RouterAddress();
|
||||
newAddr.setTransportStyle(NTCPTransport.STYLE);
|
||||
Properties newProps = new Properties();
|
||||
if (oldAddr == null) {
|
||||
newAddr.setCost(NTCPAddress.DEFAULT_COST);
|
||||
newAddr.setExpiration(null);
|
||||
newAddr.setTransportStyle(NTCPTransport.STYLE);
|
||||
newProps = new Properties();
|
||||
} else {
|
||||
newProps = newAddr.getOptions();
|
||||
if (newProps == null)
|
||||
newProps = new Properties();
|
||||
newAddr.setCost(oldAddr.getCost());
|
||||
newProps.putAll(oldAddr.getOptionsMap());
|
||||
}
|
||||
|
||||
boolean changed = false;
|
||||
@@ -297,7 +290,7 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
|
||||
if (cport != null && cport.length() > 0) {
|
||||
nport = cport;
|
||||
} else if (_context.getBooleanPropertyDefaultTrue(PROP_I2NP_NTCP_AUTO_PORT)) {
|
||||
nport = UDPProps.getProperty(UDPAddress.PROP_PORT);
|
||||
nport = UDPAddr.getOption(UDPAddress.PROP_PORT);
|
||||
}
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("old: " + oport + " config: " + cport + " new: " + nport);
|
||||
@@ -330,7 +323,7 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
|
||||
_log.info("old: " + ohost + " config: " + name + " auto: " + enabled + " status: " + status);
|
||||
if (enabled.equals("always") ||
|
||||
(Boolean.valueOf(enabled).booleanValue() && status == STATUS_OK)) {
|
||||
String nhost = UDPProps.getProperty(UDPAddress.PROP_HOST);
|
||||
String nhost = UDPAddr.getOption(UDPAddress.PROP_HOST);
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("old: " + ohost + " config: " + name + " new: " + nhost);
|
||||
if (nhost == null || nhost.length() <= 0)
|
||||
@@ -483,10 +476,7 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
|
||||
RouterAddress ra = ri.getTargetAddress("SSU");
|
||||
if (ra == null)
|
||||
return null;
|
||||
Properties props = ra.getOptions();
|
||||
if (props == null)
|
||||
return null;
|
||||
return props.getProperty("host");
|
||||
return ra.getOption("host");
|
||||
}
|
||||
|
||||
/** full name for a country code, or the code if we don't know the name */
|
||||
|
@@ -343,15 +343,12 @@ public class TransportManager implements TransportEventListener {
|
||||
for (Transport t : _transports.values()) {
|
||||
int port = t.getRequestedPort();
|
||||
if (t.getCurrentAddress() != null) {
|
||||
Properties opts = t.getCurrentAddress().getOptions();
|
||||
if (opts != null) {
|
||||
String s = opts.getProperty("port");
|
||||
String s = t.getCurrentAddress().getOption("port");
|
||||
if (s != null) {
|
||||
try {
|
||||
port = Integer.parseInt(s);
|
||||
} catch (NumberFormatException nfe) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Use UDP port for NTCP too - see comment in NTCPTransport.getRequestedPort() for why this is here
|
||||
if (t.getStyle().equals(NTCPTransport.STYLE) && port <= 0 &&
|
||||
|
@@ -57,13 +57,13 @@ public class NTCPAddress {
|
||||
_port = -1;
|
||||
return;
|
||||
}
|
||||
String host = addr.getOptions().getProperty(PROP_HOST);
|
||||
String host = addr.getOption(PROP_HOST);
|
||||
if (host == null) {
|
||||
_host = null;
|
||||
_port = -1;
|
||||
} else {
|
||||
_host = host.trim();
|
||||
String port = addr.getOptions().getProperty(PROP_PORT);
|
||||
String port = addr.getOption(PROP_PORT);
|
||||
if ( (port != null) && (port.trim().length() > 0) && !("null".equals(port)) ) {
|
||||
try {
|
||||
_port = Integer.parseInt(port.trim());
|
||||
@@ -156,9 +156,7 @@ public class NTCPAddress {
|
||||
|
||||
public boolean equals(RouterAddress addr) {
|
||||
if (addr == null) return false;
|
||||
Properties opts = addr.getOptions();
|
||||
if (opts == null) return false;
|
||||
return ( (_host.equals(opts.getProperty(PROP_HOST))) &&
|
||||
(Integer.toString(_port).equals(opts.getProperty(PROP_PORT))) );
|
||||
return ( (_host.equals(addr.getOption(PROP_HOST))) &&
|
||||
(Integer.toString(_port).equals(addr.getOption(PROP_PORT))) );
|
||||
}
|
||||
}
|
||||
|
@@ -64,31 +64,30 @@ public class UDPAddress {
|
||||
|
||||
private void parse(RouterAddress addr) {
|
||||
if (addr == null) return;
|
||||
Properties opts = addr.getOptions();
|
||||
_host = opts.getProperty(PROP_HOST);
|
||||
_host = addr.getOption(PROP_HOST);
|
||||
if (_host != null) _host = _host.trim();
|
||||
try {
|
||||
String port = opts.getProperty(PROP_PORT);
|
||||
String port = addr.getOption(PROP_PORT);
|
||||
if (port != null)
|
||||
_port = Integer.parseInt(port);
|
||||
} catch (NumberFormatException nfe) {
|
||||
_port = -1;
|
||||
}
|
||||
String key = opts.getProperty(PROP_INTRO_KEY);
|
||||
String key = addr.getOption(PROP_INTRO_KEY);
|
||||
if (key != null)
|
||||
_introKey = Base64.decode(key.trim());
|
||||
|
||||
for (int i = MAX_INTRODUCERS; i >= 0; i--) {
|
||||
String host = opts.getProperty(PROP_INTRO_HOST_PREFIX + i);
|
||||
String host = addr.getOption(PROP_INTRO_HOST_PREFIX + i);
|
||||
if (host == null) continue;
|
||||
String port = opts.getProperty(PROP_INTRO_PORT_PREFIX + i);
|
||||
String port = addr.getOption(PROP_INTRO_PORT_PREFIX + i);
|
||||
if (port == null) continue;
|
||||
String k = opts.getProperty(PROP_INTRO_KEY_PREFIX + i);
|
||||
String k = addr.getOption(PROP_INTRO_KEY_PREFIX + i);
|
||||
if (k == null) continue;
|
||||
byte ikey[] = Base64.decode(k);
|
||||
if ( (ikey == null) || (ikey.length != SessionKey.KEYSIZE_BYTES) )
|
||||
continue;
|
||||
String t = opts.getProperty(PROP_INTRO_TAG_PREFIX + i);
|
||||
String t = addr.getOption(PROP_INTRO_TAG_PREFIX + i);
|
||||
if (t == null) continue;
|
||||
int p = -1;
|
||||
try {
|
||||
|
Reference in New Issue
Block a user