2005-01-05 jrandom

* Handle unexpected network read errors more carefully (thanks parg!)
    * Added more methods to partially compare (DataHelper) and display
      arrays (Base64.encode).
    * Exposed the AES encryptBlock/decryptBlock on the context.aes()
    * Be more generous on the throttle when just starting up the router
    * Fix a missing scheduled event in the streaming lib (caused after reset)
    * Add a new DisconnectListener on the I2PSocketManager to allow
      notification of session destruction.
    * Make sure our own router identity is valid, and if it isn't, build a new
      one and restart the router.  Alternately, you can run the Router with
      the single command line argument "rebuild" and it will do the same.
This commit is contained in:
jrandom
2005-01-06 00:17:53 +00:00
committed by zzz
parent 3dd2f67ff3
commit 4838564460
21 changed files with 235 additions and 27 deletions

View File

@ -138,6 +138,11 @@ public class I2NPMessageReader {
_log.warn("IO Error handling message", ioe);
_listener.disconnected(I2NPMessageReader.this);
cancelRunner();
} catch (Exception e) {
_log.log(Log.CRIT, "wtf, error reading", e);
_listener.readError(I2NPMessageReader.this, e);
_listener.disconnected(I2NPMessageReader.this);
cancelRunner();
}
}
if (!_doRun) {

View File

@ -50,7 +50,10 @@ public abstract class NetworkDatabaseFacade implements Service {
* @throws IllegalArgumentException if the data is not valid
*/
public abstract RouterInfo store(Hash key, RouterInfo routerInfo) throws IllegalArgumentException;
public abstract void publish(RouterInfo localRouterInfo);
/**
* @throws IllegalArgumentException if the local router is not valid
*/
public abstract void publish(RouterInfo localRouterInfo) throws IllegalArgumentException;
public abstract void publish(LeaseSet localLeaseSet);
public abstract void unpublish(LeaseSet localLeaseSet);
public abstract void fail(Hash dbEntry);

View File

@ -261,11 +261,49 @@ public class Router {
}
ri.sign(key);
setRouterInfo(ri);
_context.netDb().publish(ri);
try {
_context.netDb().publish(ri);
} catch (IllegalArgumentException iae) {
_log.log(Log.CRIT, "Local router info is invalid? rebuilding a new identity", iae);
rebuildNewIdentity();
}
} catch (DataFormatException dfe) {
_log.log(Log.CRIT, "Internal error - unable to sign our own address?!", dfe);
}
}
/**
* Ugly list of files that we need to kill if we are building a new identity
*
*/
private static final String _rebuildFiles[] = new String[] { "router.info",
"router.keys",
"connectionTag.keys",
"keyBackup/privateEncryption.key",
"keyBackup/privateSigning.key",
"keyBackup/publicEncryption.key",
"keyBackup/publicSigning.key",
"sessionKeys.dat" };
/**
* Rebuild a new identity the hard way - delete all of our old identity
* files, then reboot the router.
*
*/
public void rebuildNewIdentity() {
for (int i = 0; i < _rebuildFiles.length; i++) {
File f = new File(_rebuildFiles[i]);
if (f.exists()) {
boolean removed = f.delete();
if (removed)
System.out.println("INFO: Removing old identity file: " + _rebuildFiles[i]);
else
System.out.println("ERROR: Could not remove old identity file: " + _rebuildFiles[i]);
}
}
System.out.println("INFO: Restarting the router after removing any old identity files");
// hard and ugly
System.exit(EXIT_GRACEFUL_RESTART);
}
/**
* coalesce the stats framework every minute
@ -813,7 +851,11 @@ public class Router {
installUpdates();
verifyWrapperConfig();
Router r = new Router();
r.runRouter();
if ( (args != null) && (args.length == 1) && ("rebuild".equals(args[0])) ) {
r.rebuildNewIdentity();
} else {
r.runRouter();
}
}
private static final String UPDATE_FILE = "i2pupdate.zip";

View File

@ -50,7 +50,7 @@ class RouterThrottleImpl implements RouterThrottle {
public boolean acceptNetworkMessage() {
long lag = _context.jobQueue().getMaxLag();
if (lag > JOB_LAG_LIMIT) {
if ( (lag > JOB_LAG_LIMIT) && (_context.router().getUptime() > 60*1000) ) {
if (_log.shouldLog(Log.DEBUG))
_log.debug("Throttling network reader, as the job lag is " + lag);
_context.statManager().addRateData("router.throttleNetworkCause", lag, lag);

View File

@ -15,9 +15,9 @@ import net.i2p.CoreVersion;
*
*/
public class RouterVersion {
public final static String ID = "$Revision: 1.128 $ $Date: 2004/12/31 12:18:05 $";
public final static String ID = "$Revision: 1.129 $ $Date: 2004/12/31 19:57:01 $";
public final static String VERSION = "0.4.2.5";
public final static long BUILD = 6;
public final static long BUILD = 7;
public static void main(String args[]) {
System.out.println("I2P Router version: " + VERSION);
System.out.println("Router ID: " + RouterVersion.ID);

View File

@ -54,7 +54,12 @@ public class PublishLocalRouterInfoJob extends JobImpl {
_log.info("Newly updated routerInfo is published with " + stats.size()
+ "/" + ri.getOptions().size() + " options on "
+ new Date(ri.getPublished()));
getContext().netDb().publish(ri);
try {
getContext().netDb().publish(ri);
} catch (IllegalArgumentException iae) {
_log.log(Log.CRIT, "Error publishing our identity - corrupt?", iae);
getContext().router().rebuildNewIdentity();
}
} catch (DataFormatException dfe) {
_log.error("Error signing the updated local router info!", dfe);
}

View File

@ -487,18 +487,17 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
}
}
public void publish(RouterInfo localRouterInfo) {
/**
* @throws IllegalArgumentException if the local router info is invalid
*/
public void publish(RouterInfo localRouterInfo) throws IllegalArgumentException {
if (!_initialized) return;
Hash h = localRouterInfo.getIdentity().getHash();
try {
store(h, localRouterInfo);
synchronized (_explicitSendKeys) {
_explicitSendKeys.add(h);
}
writeMyInfo(localRouterInfo);
} catch (IllegalArgumentException iae) {
_log.error("Local routerInfo was invalid? "+ iae.getMessage(), iae);
store(h, localRouterInfo);
synchronized (_explicitSendKeys) {
_explicitSendKeys.add(h);
}
writeMyInfo(localRouterInfo);
}
/**