2005-11-27 jrandom

* Inlined the Syndie CSS to reduce the number of HTTP requests (and
      because firefox [and others?] delay rendering until they fetch the css).
    * Make sure we fire the shutdown tasks when regenerating a new identity
      (thanks picsou!)
    * Cleaned up some of the things I b0rked in the 'dynamic keys' mode
    * Don't drop SSU sessions if they're still transmitting data successfully,
      even if there are transmission failures
    * Adjusted the time summarization to display hours after 119m, not 90m
    * Further EepGet cleanup (grr)
This commit is contained in:
jrandom
2005-11-28 16:02:38 +00:00
committed by zzz
parent cdf94295f3
commit 686742a67b
12 changed files with 97 additions and 81 deletions

View File

@ -38,8 +38,6 @@ import net.i2p.data.i2np.GarlicMessage;
import net.i2p.router.message.GarlicMessageHandler;
//import net.i2p.router.message.TunnelMessageHandler;
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
import net.i2p.router.transport.udp.UDPTransport;
import net.i2p.router.transport.udp.UDPAddress;
import net.i2p.router.startup.StartupJob;
import net.i2p.stat.Rate;
import net.i2p.stat.RateStat;
@ -218,51 +216,6 @@ public class Router {
_context.jobQueue().addJob(new PersistRouterInfoJob());
}
/**
* Called when our RouterInfo is loaded by LoadRouterInfoJob
* to store our most recently known address to determine if
* it has changed while we were down.
*/
public boolean updateExternalAddress(Collection addrs, boolean reboot) {
if ("false".equalsIgnoreCase(_context.getProperty(Router.PROP_DYNAMIC_KEYS, "false")))
return false; // no one cares. pretend it didn't change
boolean ret = false;
for (Iterator i = addrs.iterator(); i.hasNext(); ) {
RouterAddress addr = (RouterAddress)i.next();
if (UDPTransport.STYLE.equalsIgnoreCase(addr.getTransportStyle()))
ret = updateExternalAddress(addr, reboot);
}
return ret;
}
/**
* Called by TransportImpl.replaceAddress to notify the router of an
* address change. It is the caller's responsibility to make sure this
* really is a substantial change.
*
*/
public boolean updateExternalAddress(RouterAddress addr, boolean rebootRouter) {
String newExternal = null;
// TCP is often incorrectly initialized to 83.246.74.28 for some
// reason. Numerous hosts in the netdb report this address for TCP.
// It is also easier to lie over the TCP transport. So only trust UDP.
if (!UDPTransport.STYLE.equalsIgnoreCase(addr.getTransportStyle()))
return false;
if ("false".equalsIgnoreCase(_context.getProperty(Router.PROP_DYNAMIC_KEYS, "false")))
return false; // no one cares. pretend it didn't change
if (_log.shouldLog(Log.WARN))
_log.warn("Rekeying and restarting due to " + addr.getTransportStyle()
+ " address update. new address: " + addr);
if (rebootRouter) {
_context.router().rebuildNewIdentity();
} else {
_context.router().killKeys();
}
return true;
}
/**
* True if the router has tried to communicate with another router who is running a higher
* incompatible protocol version.
@ -459,6 +412,14 @@ public class Router {
*/
public void rebuildNewIdentity() {
killKeys();
try {
for (Iterator iter = _shutdownTasks.iterator(); iter.hasNext(); ) {
Runnable task = (Runnable)iter.next();
task.run();
}
} catch (Throwable t) {
_log.log(Log.CRIT, "Error running shutdown task", t);
}
// hard and ugly
finalShutdown(EXIT_HARD_RESTART);
}
@ -870,6 +831,9 @@ public class Router {
public void finalShutdown(int exitCode) {
_log.log(Log.CRIT, "Shutdown(" + exitCode + ") complete", new Exception("Shutdown"));
try { _context.logManager().shutdown(); } catch (Throwable t) { }
if ("true".equalsIgnoreCase(_context.getProperty(PROP_DYNAMIC_KEYS, "false")))
killKeys();
File f = new File(getPingFile());
f.delete();
if (_killVMOnEnd) {

View File

@ -15,9 +15,9 @@ import net.i2p.CoreVersion;
*
*/
public class RouterVersion {
public final static String ID = "$Revision: 1.301 $ $Date: 2005/11/26 11:51:19 $";
public final static String ID = "$Revision: 1.302 $ $Date: 2005/11/26 13:26:23 $";
public final static String VERSION = "0.6.1.6";
public final static long BUILD = 0;
public final static long BUILD = 1;
public static void main(String args[]) {
System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
System.out.println("Router ID: " + RouterVersion.ID);

View File

@ -11,8 +11,6 @@ package net.i2p.router.startup;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Collection;
import java.util.Set;
import net.i2p.data.DataFormatException;
import net.i2p.data.PrivateKey;
@ -78,7 +76,6 @@ public class LoadRouterInfoJob extends JobImpl {
fis1 = new FileInputStream(rif);
info = new RouterInfo();
info.readBytes(fis1);
getContext().router().updateExternalAddress(info.getAddresses(), false);
_log.debug("Reading in routerInfo from " + rif.getAbsolutePath() + " and it has " + info.getAddresses().size() + " addresses");
}

View File

@ -763,7 +763,8 @@ public class EstablishmentManager {
Hash peer = outboundState.getRemoteIdentity().calculateHash();
_context.shitlist().shitlistRouter(peer, err);
_context.profileManager().commErrorOccurred(peer);
_transport.dropPeer(peer);
//_context.profileManager().commErrorOccurred(peer);
} else {
while (true) {
OutNetMessage msg = outboundState.getNextQueuedMessage();

View File

@ -418,6 +418,11 @@ public class PeerState {
}
return _consecutiveFailedSends;
}
public long getInactivityTime() {
long now = _context.clock().now();
long lastActivity = Math.max(_lastReceiveTime, _lastSendFullyTime);
return now - lastActivity;
}
/** how fast we are sending *ack* packets */
public int getSendACKBps() { return _sendACKBps; }

View File

@ -23,6 +23,7 @@ import net.i2p.data.i2np.DatabaseStoreMessage;
import net.i2p.router.CommSystemFacade;
import net.i2p.router.OutNetMessage;
import net.i2p.router.RouterContext;
import net.i2p.router.Router;
import net.i2p.router.transport.Transport;
import net.i2p.router.transport.TransportImpl;
import net.i2p.router.transport.TransportBid;
@ -526,8 +527,10 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
return super.getCurrentAddress();
}
private void dropPeer(PeerState peer) {
dropPeer(peer, true);
void dropPeer(Hash peer) {
PeerState state = getPeerState(peer);
if (state != null)
dropPeer(state, false);
}
private void dropPeer(PeerState peer, boolean shouldShitlist) {
if (_log.shouldLog(Log.INFO)) {
@ -827,15 +830,26 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
protected void replaceAddress(RouterAddress address, RouterAddress oldAddress) {
replaceAddress(address);
if (oldAddress != null) {
// fire a router.updateExternalAddress only if the address /really/ changed.
// updating the introducers doesn't require a real change, only updating the
// IP or port does.
UDPAddress old = new UDPAddress(oldAddress);
InetAddress oldHost = old.getHostAddress();
UDPAddress newAddr = new UDPAddress(address);
InetAddress newHost = newAddr.getHostAddress();
if ( (old.getPort() != newAddr.getPort()) || (!oldHost.equals(newHost)) )
_context.router().updateExternalAddress(address, true);
if ( (old.getPort() > 0) && (oldHost != null) && (isValid(oldHost.getAddress())) &&
(newAddr.getPort() > 0) && (newHost != null) && (isValid(newHost.getAddress())) ) {
if ( (old.getPort() != newAddr.getPort()) || (!oldHost.equals(newHost)) ) {
// substantial data has changed, so if we are in 'dynamic keys' mode, restart the
// router hard and regenerate a new identity
if ("true".equalsIgnoreCase(_context.getProperty(Router.PROP_DYNAMIC_KEYS, "false"))) {
if (_log.shouldLog(Log.ERROR))
_log.error("SSU address updated. new address: "
+ newAddr.getHostAddress() + ":" + newAddr.getPort() + ", old address: "
+ old.getHostAddress() + ":" + old.getPort());
// shutdown itself checks the DYNAMIC_KEYS flag, and if its set to true, deletes
// the keys
_context.router().shutdown(Router.EXIT_HARD_RESTART);
}
}
}
}
}
@ -859,6 +873,8 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
else
return "";
}
private static final int DROP_INACTIVITY_TIME = 10*1000;
public void failed(OutboundMessageState msg) {
if (msg == null) return;
@ -875,7 +891,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
consecutive = msg.getPeer().incrementConsecutiveFailedSends();
if (_log.shouldLog(Log.WARN))
_log.warn("Consecutive failure #" + consecutive + " sending to " + msg.getPeer());
if (consecutive > MAX_CONSECUTIVE_FAILED)
if ( (consecutive > MAX_CONSECUTIVE_FAILED) && (msg.getPeer().getInactivityTime() > DROP_INACTIVITY_TIME))
dropPeer(msg.getPeer(), false);
}
failed(msg.getMessage());