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

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