propagate from branch 'i2p.i2p' (head d289b6cafae6b23ce699dca11dbb3e993c8f827f)

to branch 'i2p.i2p.zzz.test' (head e2c6210696c78c54650ff345f18ad62b4543a18b)
This commit is contained in:
zzz
2012-01-02 14:39:17 +00:00
17 changed files with 323 additions and 175 deletions

View File

@@ -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;

View File

@@ -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();
@@ -235,14 +243,16 @@ public class Router implements RouterClock.ClockShiftListener {
_config.put("router.updateLastInstalled", now);
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,7 +382,14 @@ 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 {
@@ -1266,13 +1283,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 +1303,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.

View File

@@ -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);

View File

@@ -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;
}
}

View File

@@ -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);

View File

@@ -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 {

View File

@@ -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 &&

View File

@@ -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))) );
}
}

View File

@@ -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 {