2009-04-17 sponge

* Catch NPE in NTCP.
      This possibly augments fix 2009-04-11 welterde below.
    * Various LINT on NTCP sources, and removal of space-wasting
      spaces at end of lines in sources touched.
This commit is contained in:
sponge
2009-04-17 13:11:16 +00:00
parent 834fdfe9b3
commit d0376f82a5
6 changed files with 233 additions and 215 deletions

View File

@ -1,3 +1,9 @@
2009-04-17 sponge
* Catch NPE in NTCP.
This possibly augments fix 2009-04-11 welterde below.
* Various LINT on NTCP sources, and removal of space-wasting
spaces at end of lines in sources touched.
2009-04-13 Mathiasdm
* Bugfix on tray icon updating
* Some more work on the general configuration menu

View File

@ -17,7 +17,7 @@ import net.i2p.CoreVersion;
public class RouterVersion {
public final static String ID = "$Revision: 1.548 $ $Date: 2008-06-07 23:00:00 $";
public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 18;
public final static long BUILD = 19;
public static void main(String args[]) {
System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
System.out.println("Router ID: " + RouterVersion.ID);

View File

@ -14,7 +14,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -46,10 +45,10 @@ public abstract class TransportImpl implements Transport {
private Log _log;
private TransportEventListener _listener;
private RouterAddress _currentAddress;
private List _sendPool;
private final List _sendPool;
protected RouterContext _context;
/** map from routerIdentHash to timestamp (Long) that the peer was last unreachable */
private Map<Hash, Long> _unreachableEntries;
private final Map<Hash, Long> _unreachableEntries;
private Set<Hash> _wasUnreachableEntries;
/** global router ident -> IP */
private static Map<Hash, byte[]> _IPMap = new ConcurrentHashMap(128);
@ -506,7 +505,7 @@ public abstract class TransportImpl implements Transport {
_log.warn(this.getStyle() + " setting wasUnreachable to " + yes + " for " + peer);
}
public static void setIP(Hash peer, byte[] ip) {
public /* static */ void setIP(Hash peer, byte[] ip) {
_IPMap.put(peer, ip);
}

View File

@ -519,7 +519,7 @@ public class EstablishState {
try {
RouterIdentity alice = new RouterIdentity();
int sz = (int)DataHelper.fromLong(b, 0, 2);
int sz = (int)DataHelper.fromLong(b, 0, 2); // TO-DO: Hey zzz... Throws an NPE for me... see below, for my "quick fix", need to find out the real reason
if ( (sz <= 0) || (sz > b.length-2-4-Signature.SIGNATURE_BYTES) ) {
_context.statManager().addRateData("ntcp.invalidInboundSize", sz, 0);
fail("size is invalid", new Exception("size is " + sz));
@ -597,6 +597,8 @@ public class EstablishState {
} catch (DataFormatException dfe) {
_context.statManager().addRateData("ntcp.invalidInboundDFE", 1, 0);
fail("Error verifying peer", dfe);
} catch(NullPointerException npe) {
fail("Error verifying peer", npe); // TO-DO: zzz This is that quick-fix. -- Sponge
}
}
@ -658,6 +660,7 @@ public class EstablishState {
public Exception getException() { return _e; }
private String prefix() { return toString(); }
@Override
public String toString() {
StringBuffer buf = new StringBuffer(64);
buf.append("est").append(System.identityHashCode(this));

View File

@ -36,7 +36,7 @@ public class NTCPTransport extends TransportImpl {
private SharedBid _fastBid;
private SharedBid _slowBid;
private SharedBid _transientFail;
private Object _conLock;
private final Object _conLock;
private Map _conByIdent;
private NTCPAddress _myAddress;
private EventPumper _pumper;
@ -46,7 +46,7 @@ public class NTCPTransport extends TransportImpl {
* list of NTCPConnection of connections not yet established that we
* want to remove on establishment or close on timeout
*/
private List _establishing;
private final List _establishing;
private List _sent;
private NTCPSendFinisher _finisher;
@ -238,6 +238,7 @@ public class NTCPTransport extends TransportImpl {
}
}
@Override
public void afterSend(OutNetMessage msg, boolean sendSuccessful, boolean allowRequeue, long msToSend) {
super.afterSend(msg, sendSuccessful, allowRequeue, msToSend);
}
@ -313,6 +314,7 @@ public class NTCPTransport extends TransportImpl {
return countActivePeers() < getMaxConnections();
}
@Override
public boolean haveCapacity() {
return countActivePeers() < getMaxConnections() * 4 / 5;
}
@ -324,6 +326,7 @@ public class NTCPTransport extends TransportImpl {
return isEstablished(peer.calculateHash());
}
@Override
public boolean isEstablished(Hash dest) {
synchronized (_conLock) {
NTCPConnection con = (NTCPConnection)_conByIdent.get(dest);
@ -331,6 +334,7 @@ public class NTCPTransport extends TransportImpl {
}
}
@Override
public boolean isBacklogged(Hash dest) {
synchronized (_conLock) {
NTCPConnection con = (NTCPConnection)_conByIdent.get(dest);
@ -357,10 +361,12 @@ public class NTCPTransport extends TransportImpl {
* How many peers can we talk to right now?
*
*/
@Override
public int countActivePeers() { synchronized (_conLock) { return _conByIdent.size(); } }
/**
* How many peers are we actively sending messages to (this minute)
*/
@Override
public int countActiveSendPeers() {
int active = 0;
synchronized (_conLock) {
@ -377,6 +383,7 @@ public class NTCPTransport extends TransportImpl {
* Return our peer clock skews on this transport.
* Vector composed of Long, each element representing a peer skew in seconds.
*/
@Override
public Vector getClockSkews() {
Vector peers = new Vector();
@ -555,6 +562,7 @@ public class NTCPTransport extends TransportImpl {
public static final String STYLE = "NTCP";
public void renderStatusHTML(java.io.Writer out, int sortFlags) throws IOException {}
@Override
public void renderStatusHTML(java.io.Writer out, String urlBase, int sortFlags) throws IOException {
TreeSet peers = new TreeSet(getComparator(sortFlags));
synchronized (_conLock) {
@ -674,7 +682,7 @@ public class NTCPTransport extends TransportImpl {
buf.setLength(0);
}
private static NumberFormat _rateFmt = new DecimalFormat("#,#0.00");
private static final NumberFormat _rateFmt = new DecimalFormat("#,#0.00");
private static String formatRate(float rate) {
synchronized (_rateFmt) { return _rateFmt.format(rate); }
}
@ -717,7 +725,9 @@ public class NTCPTransport extends TransportImpl {
*/
private class SharedBid extends TransportBid {
public SharedBid(int ms) { super(); setLatencyMs(ms); }
@Override
public Transport getTransport() { return NTCPTransport.this; }
@Override
public String toString() { return "NTCP bid @ " + getLatencyMs(); }
}
}

View File

@ -26,18 +26,18 @@ public class OutboundMessageFragments {
private RouterContext _context;
private Log _log;
private UDPTransport _transport;
private ActiveThrottle _throttle;
private ActiveThrottle _throttle; // LINT not used ??
/** peers we are actively sending messages to */
private List _activePeers;
private final List _activePeers;
private boolean _alive;
/** which peer should we build the next packet out of? */
private int _nextPeer;
private PacketBuilder _builder;
/** if we can handle more messages explicitly, set this to true */
private boolean _allowExcess;
private volatile long _packetsRetransmitted;
private boolean _allowExcess; // LINT not used??
private volatile long _packetsRetransmitted; // LINT not used??
private static final int MAX_ACTIVE = 64;
// private static final int MAX_ACTIVE = 64; // not used.
// don't send a packet more than 10 times
static final int MAX_VOLLEYS = 10;