2005-09-13 jrandom

* More careful error handling with introductions (thanks dust!)
    * Fix the forceIntroducers checkbox on config.jsp (thanks Complication!)
    * Hide the shitlist on the summary so it doesn't confuse new users.
This commit is contained in:
jrandom
2005-09-13 23:02:35 +00:00
committed by zzz
parent 4293a18726
commit 5694206b35
10 changed files with 80 additions and 35 deletions

View File

@ -5,6 +5,7 @@ import net.i2p.router.RouterContext;
import net.i2p.router.CommSystemFacade;
import net.i2p.data.RouterAddress;
import net.i2p.router.transport.udp.UDPAddress;
import net.i2p.router.transport.udp.UDPTransport;
public class ConfigNetHelper {
private RouterContext _context;
@ -66,11 +67,15 @@ public class ConfigNetHelper {
short status = _context.commSystem().getReachabilityStatus();
switch (status) {
case CommSystemFacade.STATUS_OK:
if ("true".equalsIgnoreCase(_context.getProperty(UDPTransport.PROP_FORCE_INTRODUCERS, "false")))
return "checked=\"true\"";
return "";
case CommSystemFacade.STATUS_DIFFERENT:
case CommSystemFacade.STATUS_REJECT_UNSOLICITED:
return "checked=\"true\"";
case CommSystemFacade.STATUS_UNKNOWN:
if ("true".equalsIgnoreCase(_context.getProperty(UDPTransport.PROP_FORCE_INTRODUCERS, "false")))
return "checked=\"true\"";
return "";
default:
return "checked=\"true\"";

View File

@ -40,7 +40,7 @@
<b>High capacity:</b> <jsp:getProperty name="helper" property="highCapacityPeers" /><br />
<b>Well integrated:</b> <jsp:getProperty name="helper" property="wellIntegratedPeers" /><br />
<b>Failing:</b> <jsp:getProperty name="helper" property="failingPeers" /><br />
<b>Shitlisted:</b> <jsp:getProperty name="helper" property="shitlistedPeers" /><br />
<!-- <b>Shitlisted:</b> <jsp:getProperty name="helper" property="shitlistedPeers" /><br /> -->
<b>Known:</b> <jsp:getProperty name="helper" property="allPeers" /><br /><%
if (helper.getActivePeers() <= 0) {
%><b><a href="config.jsp">check your NAT/firewall</a></b><br /><%

View File

@ -1,4 +1,9 @@
$Id: history.txt,v 1.247 2005/09/12 22:32:30 jrandom Exp $
$Id: history.txt,v 1.248 2005/09/13 04:06:07 comwiz Exp $
2005-09-13 jrandom
* More careful error handling with introductions (thanks dust!)
* Fix the forceIntroducers checkbox on config.jsp (thanks Complication!)
* Hide the shitlist on the summary so it doesn't confuse new users.
2005-09-12 comwiz
* Migrated the router tests to junit

View File

@ -15,9 +15,9 @@ import net.i2p.CoreVersion;
*
*/
public class RouterVersion {
public final static String ID = "$Revision: 1.233 $ $Date: 2005/09/12 20:12:43 $";
public final static String ID = "$Revision: 1.234 $ $Date: 2005/09/12 22:32:30 $";
public final static String VERSION = "0.6.0.5";
public final static long BUILD = 8;
public final static long BUILD = 9;
public static void main(String args[]) {
System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
System.out.println("Router ID: " + RouterVersion.ID);

View File

@ -764,36 +764,46 @@ public class EstablishmentManager {
private class Establisher implements Runnable {
public void run() {
while (_alive) {
_activity = 0;
long now = _context.clock().now();
long nextSendTime = -1;
long nextSendInbound = handleInbound();
long nextSendOutbound = handleOutbound();
if (nextSendInbound > 0)
nextSendTime = nextSendInbound;
if ( (nextSendTime < 0) || (nextSendOutbound < nextSendTime) )
nextSendTime = nextSendOutbound;
long delay = nextSendTime - now;
if ( (nextSendTime == -1) || (delay > 0) ) {
boolean interrupted = false;
try {
synchronized (_activityLock) {
if (_activity > 0)
continue;
if (nextSendTime == -1)
_activityLock.wait();
else
_activityLock.wait(delay);
}
} catch (InterruptedException ie) {
interrupted = true;
}
if (_log.shouldLog(Log.DEBUG))
_log.debug("After waiting w/ nextSend=" + nextSendTime
+ " and delay=" + delay + " and interrupted=" + interrupted);
try {
doPass();
} catch (OutOfMemoryError oom) {
throw oom;
} catch (RuntimeException re) {
_log.log(Log.CRIT, "Error in the establisher", re);
}
}
}
}
private void doPass() {
_activity = 0;
long now = _context.clock().now();
long nextSendTime = -1;
long nextSendInbound = handleInbound();
long nextSendOutbound = handleOutbound();
if (nextSendInbound > 0)
nextSendTime = nextSendInbound;
if ( (nextSendTime < 0) || (nextSendOutbound < nextSendTime) )
nextSendTime = nextSendOutbound;
long delay = nextSendTime - now;
if ( (nextSendTime == -1) || (delay > 0) ) {
boolean interrupted = false;
try {
synchronized (_activityLock) {
if (_activity > 0)
return;
if (nextSendTime == -1)
_activityLock.wait();
else
_activityLock.wait(delay);
}
} catch (InterruptedException ie) {
interrupted = true;
}
if (_log.shouldLog(Log.DEBUG))
_log.debug("After waiting w/ nextSend=" + nextSendTime
+ " and delay=" + delay + " and interrupted=" + interrupted);
}
}
}

View File

@ -641,11 +641,20 @@ public class PacketBuilder {
public UDPPacket buildRelayRequest(OutboundEstablishState state, SessionKey ourIntroKey) {
UDPAddress addr = state.getRemoteAddress();
int index = _context.random().nextInt(UDPAddress.MAX_INTRODUCERS) % addr.getIntroducerCount();
int count = addr.getIntroducerCount();
if (count <= 0)
return null;
int index = _context.random().nextInt(count);
InetAddress iaddr = addr.getIntroducerHost(index);
int iport = addr.getIntroducerPort(index);
byte ikey[] = addr.getIntroducerKey(index);
long tag = addr.getIntroducerTag(index);
if ( (ikey == null) || (iport <= 0) || (iaddr == null) || (tag <= 0) ) {
if (_log.shouldLog(_log.ERROR))
_log.error("Cannot build a relay request to " + state.getRemoteIdentity().calculateHash().toBase64()
+ ", as their UDP address is invalid: addr=" + addr + " index=" + index);
return null;
}
return buildRelayRequest(iaddr, iport, ikey, tag, ourIntroKey, state.getIntroNonce(), true);
}

View File

@ -422,7 +422,7 @@ class PeerTestManager {
aliceIP = InetAddress.getByAddress(from.getIP());
aliceIntroKey = new SessionKey(new byte[SessionKey.KEYSIZE_BYTES]);
testInfo.readIntroKey(aliceIntroKey.getData(), 0);
UDPAddress addr = new UDPAddress(charlieInfo.getTargetAddress(UDPTransport.STYLE));
SessionKey charlieIntroKey = new SessionKey(addr.getIntroKey());

View File

@ -61,6 +61,7 @@ public class UDPAddress {
}
private void parse(RouterAddress addr) {
if (addr == null) return;
Properties opts = addr.getOptions();
_host = opts.getProperty(PROP_HOST);
if (_host != null) _host = _host.trim();

View File

@ -1173,7 +1173,12 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
PeerState peer = (PeerState)peers.get(i);
if ( (dontInclude != null) && (dontInclude.equals(peer.getRemoteHostId())) )
continue;
return peer;
RouterInfo peerInfo = _context.netDb().lookupRouterInfoLocally(peer.getRemotePeer());
if (peerInfo == null)
continue;
RouterAddress addr = peerInfo.getTargetAddress(STYLE);
if (addr != null)
return peer;
}
return null;
}

View File

@ -90,6 +90,8 @@ public class FragmentHandler {
}
offset = off;
}
} catch (ArrayIndexOutOfBoundsException aioobe) {
_context.statManager().addRateData("tunnel.corruptMessage", 1, 1);
} catch (RuntimeException e) {
if (_log.shouldLog(Log.ERROR))
_log.error("Corrupt fragment received: offset = " + offset, e);
@ -216,17 +218,23 @@ public class FragmentHandler {
long messageId = -1;
if (type == TYPE_TUNNEL) {
if (offset + 4 >= preprocessed.length)
return -1;
long id = DataHelper.fromLong(preprocessed, offset, 4);
tunnelId = new TunnelId(id);
offset += 4;
}
if ( (type == TYPE_ROUTER) || (type == TYPE_TUNNEL) ) {
byte h[] = new byte[Hash.HASH_LENGTH];
if (offset + Hash.HASH_LENGTH >= preprocessed.length)
return -1;
System.arraycopy(preprocessed, offset, h, 0, Hash.HASH_LENGTH);
router = new Hash(h);
offset += Hash.HASH_LENGTH;
}
if (fragmented) {
if (offset + 4 >= preprocessed.length)
return -1;
messageId = DataHelper.fromLong(preprocessed, offset, 4);
if (_log.shouldLog(Log.DEBUG))
_log.debug("reading messageId " + messageId + " at offset "+ offset
@ -241,6 +249,8 @@ public class FragmentHandler {
offset += extendedSize; // we don't interpret these yet, but skip them for now
}
if (offset + 2 >= preprocessed.length)
return -1;
int size = (int)DataHelper.fromLong(preprocessed, offset, 2);
offset += 2;