net.i2p.router.transport.udp deadwood code cleanup.

documented rare NPE in InboundEstablishState.java.
This commit is contained in:
sponge
2009-11-29 15:02:50 +00:00
parent 0642fa8093
commit 278b917494
18 changed files with 44 additions and 49 deletions

View File

@ -1,4 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/1">
<file>file:/usblv/NetBeansProjects/i2p.i2p/apps/BOB/src/net/i2p/BOB/TCPio.java</file>
</open-files>
</project-private>

View File

@ -1,3 +1,7 @@
2009-11-29 sponge
* net.i2p.router.transport.udp deadwood code cleanup.
* documented rare NPE in InboundEstablishState.java.
2009-11-28 sponge
* Improvement to BOB's TCPio to hopefully lower load average. It seems
to be helping a little when stress-tested with Robert.

View File

@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */
public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 22;
public final static long BUILD = 23;
/** for example "-test" */
public final static String EXTRA = "";
public final static String FULL_VERSION = VERSION + "-" + BUILD + EXTRA;

View File

@ -46,7 +46,7 @@ public class InboundEstablishState {
// general status
private long _establishBegin;
private long _lastReceive;
private long _lastSend;
// private long _lastSend;
private long _nextSend;
private RemoteHostId _remoteHostId;
private int _currentState;
@ -129,6 +129,7 @@ public class InboundEstablishState {
public synchronized byte[] getSentY() {
if (_sentY == null)
// Rare NPE seen here...
_sentY = _keyBuilder.getMyPublicValueBytes();
return _sentY;
}
@ -198,7 +199,7 @@ public class InboundEstablishState {
/** note that we just sent a SessionCreated packet */
public synchronized void createdPacketSent() {
_lastSend = _context.clock().now();
// _lastSend = _context.clock().now();
if ( (_currentState == STATE_UNKNOWN) || (_currentState == STATE_REQUEST_RECEIVED) )
_currentState = STATE_CREATED_SENT;
}
@ -210,8 +211,7 @@ public class InboundEstablishState {
public synchronized void setNextSendTime(long when) { _nextSend = when; }
/** RemoteHostId, uniquely identifies an attempt */
// FIXME Exporting non-public type through public API FIXME
public RemoteHostId getRemoteHostId() { return _remoteHostId; }
RemoteHostId getRemoteHostId() { return _remoteHostId; }
public synchronized void receiveSessionConfirmed(UDPPacketReader.SessionConfirmedReader conf) {
if (_receivedIdentity == null)

View File

@ -157,8 +157,7 @@ public class IntroductionManager {
return found;
}
/* FIXME Exporting non-public type through public API FIXME */
public void receiveRelayIntro(RemoteHostId bob, UDPPacketReader reader) {
void receiveRelayIntro(RemoteHostId bob, UDPPacketReader reader) {
if (_context.router().isHidden())
return;
if (_log.shouldLog(Log.INFO))
@ -167,8 +166,7 @@ public class IntroductionManager {
_transport.send(_builder.buildHolePunch(reader));
}
/* FIXME Exporting non-public type through public API FIXME */
public void receiveRelayRequest(RemoteHostId alice, UDPPacketReader reader) {
void receiveRelayRequest(RemoteHostId alice, UDPPacketReader reader) {
if (_context.router().isHidden())
return;
long tag = reader.getRelayRequestReader().readTag();

View File

@ -413,8 +413,7 @@ public class OutboundEstablishState {
}
/** uniquely identifies an attempt */
/* FIXME Exporting non-public type through public API FIXME */
public RemoteHostId getRemoteHostId() { return _remoteHostId; }
RemoteHostId getRemoteHostId() { return _remoteHostId; }
/** we have received a real data packet, so we're done establishing */
public synchronized void dataReceived() {

View File

@ -26,7 +26,7 @@ public class OutboundMessageFragments {
private RouterContext _context;
private Log _log;
private UDPTransport _transport;
private ActiveThrottle _throttle; // LINT not used ??
// private ActiveThrottle _throttle; // LINT not used ??
/** peers we are actively sending messages to */
private final List _activePeers;
private boolean _alive;
@ -34,8 +34,8 @@ public class OutboundMessageFragments {
private int _nextPeer;
private PacketBuilder _builder;
/** if we can handle more messages explicitly, set this to true */
private boolean _allowExcess; // LINT not used??
private volatile long _packetsRetransmitted; // LINT not used??
// private boolean _allowExcess; // LINT not used??
// private volatile long _packetsRetransmitted; // LINT not used??
// private static final int MAX_ACTIVE = 64; // not used.
// don't send a packet more than 10 times
@ -45,12 +45,12 @@ public class OutboundMessageFragments {
_context = ctx;
_log = ctx.logManager().getLog(OutboundMessageFragments.class);
_transport = transport;
_throttle = throttle;
// _throttle = throttle;
_activePeers = new ArrayList(256);
_nextPeer = 0;
_builder = new PacketBuilder(ctx, transport);
_alive = true;
_allowExcess = false;
// _allowExcess = false;
_context.statManager().createRateStat("udp.sendVolleyTime", "Long it takes to send a full volley", "udp", UDPTransport.RATES);
_context.statManager().createRateStat("udp.sendConfirmTime", "How long it takes to send a message and get the ACK", "udp", UDPTransport.RATES);
_context.statManager().createRateStat("udp.sendConfirmFragments", "How many fragments are included in a fully ACKed message", "udp", UDPTransport.RATES);
@ -376,7 +376,7 @@ public class OutboundMessageFragments {
if (state.getPushCount() > 1) {
int toSend = fragments-sparseCount;
peer.messageRetransmitted(toSend);
_packetsRetransmitted += toSend; // lifetime for the transport
// _packetsRetransmitted += toSend; // lifetime for the transport
_context.statManager().addRateData("udp.peerPacketsRetransmitted", peer.getPacketsRetransmitted(), peer.getPacketsTransmitted());
_context.statManager().addRateData("udp.packetsRetransmitted", state.getLifetime(), peer.getPacketsTransmitted());
if (_log.shouldLog(Log.INFO))

View File

@ -32,7 +32,7 @@ public class OutboundMessageState {
private long _nextSendTime;
private int _pushCount;
private short _maxSends;
private int _nextSendFragment;
// private int _nextSendFragment;
public static final int MAX_MSG_SIZE = 32 * 1024;
/** is this enough for a high-bandwidth router? */
@ -45,7 +45,7 @@ public class OutboundMessageState {
_log = _context.logManager().getLog(OutboundMessageState.class);
_pushCount = 0;
_maxSends = 0;
_nextSendFragment = 0;
// _nextSendFragment = 0;
}
public boolean initialize(OutNetMessage msg) {

View File

@ -16,14 +16,14 @@ public class OutboundRefiller implements Runnable {
private OutboundMessageFragments _fragments;
private MessageQueue _messages;
private boolean _alive;
private Object _refillLock;
// private Object _refillLock;
public OutboundRefiller(RouterContext ctx, OutboundMessageFragments fragments, MessageQueue messages) {
_context = ctx;
_log = ctx.logManager().getLog(OutboundRefiller.class);
_fragments = fragments;
_messages = messages;
_refillLock = this;
// _refillLock = this;
_context.statManager().createRateStat("udp.timeToActive", "Message lifetime until it reaches the outbound fragment queue", "udp", UDPTransport.RATES);
}

View File

@ -879,8 +879,7 @@ public class PacketBuilder {
*/
private static final byte PEER_RELAY_INTRO_FLAG_BYTE = (UDPPacket.PAYLOAD_TYPE_RELAY_INTRO << 4);
/* FIXME Exporting non-public type through public API FIXME */
public UDPPacket buildRelayIntro(RemoteHostId alice, PeerState charlie, UDPPacketReader.RelayRequestReader request) {
UDPPacket buildRelayIntro(RemoteHostId alice, PeerState charlie, UDPPacketReader.RelayRequestReader request) {
UDPPacket packet = UDPPacket.acquire(_context, false);
byte data[] = packet.getPacket().getData();
Arrays.fill(data, 0, data.length, (byte)0x0);
@ -930,8 +929,7 @@ public class PacketBuilder {
*/
private static final byte PEER_RELAY_RESPONSE_FLAG_BYTE = (UDPPacket.PAYLOAD_TYPE_RELAY_RESPONSE << 4);
/* FIXME Exporting non-public type through public API FIXME */
public UDPPacket buildRelayResponse(RemoteHostId alice, PeerState charlie, long nonce, SessionKey aliceIntroKey) {
UDPPacket buildRelayResponse(RemoteHostId alice, PeerState charlie, long nonce, SessionKey aliceIntroKey) {
InetAddress aliceAddr = null;
try {
aliceAddr = InetAddress.getByAddress(alice.getIP());

View File

@ -36,8 +36,7 @@ public class PacketHandler {
/** let packets be up to 30s slow */
private static final long GRACE_PERIOD = Router.CLOCK_FUDGE_FACTOR + 30*1000;
/* FIXME Exporting non-public type through public API FIXME */
public PacketHandler(RouterContext ctx, UDPTransport transport, UDPEndpoint endpoint, EstablishmentManager establisher, InboundMessageFragments inbound, PeerTestManager testManager, IntroductionManager introManager) {// LINT -- Exporting non-public type through public API
PacketHandler(RouterContext ctx, UDPTransport transport, UDPEndpoint endpoint, EstablishmentManager establisher, InboundMessageFragments inbound, PeerTestManager testManager, IntroductionManager introManager) {// LINT -- Exporting non-public type through public API
_context = ctx;
_log = ctx.logManager().getLog(PacketHandler.class);
_transport = transport;

View File

@ -10,14 +10,14 @@ import net.i2p.util.Log;
*
*/
public class PacketPusher implements Runnable {
private RouterContext _context;
// private RouterContext _context;
private Log _log;
private OutboundMessageFragments _fragments;
private UDPSender _sender;
private boolean _alive;
public PacketPusher(RouterContext ctx, OutboundMessageFragments fragments, UDPSender sender) {
_context = ctx;
// _context = ctx;
_log = ctx.logManager().getLog(PacketPusher.class);
_fragments = fragments;
_sender = sender;

View File

@ -72,7 +72,7 @@ public class PeerState {
/** how many consecutive messages have we sent and not received an ACK to */
private int _consecutiveFailedSends;
/** when did we last have a failed send (beginning of period) */
private long _lastFailedSendPeriod;
// private long _lastFailedSendPeriod;
/** list of messageIds (Long) that we have received but not yet sent */
private final List _currentACKs;
/**
@ -805,7 +805,7 @@ public class PeerState {
_concurrentMessagesActive = 0;
_consecutiveFailedSends = 0;
_lastFailedSendPeriod = -1;
// _lastFailedSendPeriod = -1;
if (numSends < 2) {
if (_context.random().nextInt(_concurrentMessagesAllowed) <= 0)
_concurrentMessagesAllowed++;
@ -1003,8 +1003,7 @@ public class PeerState {
return MAX_RTO;
}
/* FIXME Exporting non-public type through public API FIXME */
public RemoteHostId getRemoteHostId() { return _remoteHostId; }
RemoteHostId getRemoteHostId() { return _remoteHostId; }
public int add(OutboundMessageState state) {
if (_dead) {

View File

@ -4,7 +4,6 @@ import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import net.i2p.router.CommSystemFacade;
import net.i2p.router.RouterContext;
import net.i2p.util.Log;

View File

@ -9,14 +9,14 @@ import net.i2p.data.i2np.I2NPMessage;
import net.i2p.router.OutNetMessage;
import net.i2p.router.RouterContext;
import net.i2p.util.I2PThread;
import net.i2p.util.Log;
// import net.i2p.util.Log;
/**
*
*/
class UDPFlooder implements Runnable {
private RouterContext _context;
private Log _log;
// private Log _log;
private UDPTransport _transport;
private final List _peers;
private boolean _alive;
@ -24,7 +24,7 @@ class UDPFlooder implements Runnable {
public UDPFlooder(RouterContext ctx, UDPTransport transport) {
_context = ctx;
_log = ctx.logManager().getLog(UDPFlooder.class);
// _log = ctx.logManager().getLog(UDPFlooder.class);
_transport = transport;
_peers = new ArrayList(4);
ctx.random().nextBytes(_floodData);

View File

@ -38,7 +38,7 @@ public class UDPPacket {
private long _beforeReceiveFragments;
private long _afterHandlingTime;
private int _validateCount;
private boolean _isInbound;
// private boolean _isInbound;
private static final List _packetCache;
static {
@ -83,13 +83,14 @@ public class UDPPacket {
_ivBuf = new byte[IV_SIZE];
init(ctx, inbound);
}
// FIXME optimization, remove the inbound parameter, as it is unused. FIXME
private void init(I2PAppContext ctx, boolean inbound) {
_context = ctx;
//_dataBuf = _dataCache.acquire();
Arrays.fill(_data, (byte)0);
//_packet = new DatagramPacket(_data, MAX_PACKET_SIZE);
_packet.setData(_data);
_isInbound = inbound;
// _isInbound = inbound;
_initializeTime = _context.clock().now();
_markedType = -1;
_validateCount = 0;
@ -125,8 +126,7 @@ public class UDPPacket {
int getFragmentCount() { return _fragmentCount; }
void setFragmentCount(int count) { _fragmentCount = count; }
// FIXME Exporting non-public type through public API FIXME
public RemoteHostId getRemoteHost() {
RemoteHostId getRemoteHost() {
if (_remoteHost == null) {
long before = System.currentTimeMillis();
InetAddress addr = _packet.getAddress();

View File

@ -28,7 +28,7 @@ public class UDPReceiver {
private boolean _keepRunning;
private Runner _runner;
private UDPTransport _transport;
private static int __id;
// private static int __id;
private int _id;
public UDPReceiver(RouterContext ctx, UDPTransport transport, DatagramSocket socket, String name) {

View File

@ -3,7 +3,6 @@ package net.i2p.router.transport.udp;
import java.io.IOException;
import java.io.Writer;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.text.DecimalFormat;
import java.util.ArrayList;
@ -545,8 +544,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
* get the state for the peer at the given remote host/port, or null
* if no state exists
*/
/* FIXME Exporting non-public type through public API FIXME */
public PeerState getPeerState(RemoteHostId hostInfo) {
PeerState getPeerState(RemoteHostId hostInfo) {
synchronized (_peersByRemoteHost) {
return (PeerState)_peersByRemoteHost.get(hostInfo);
}
@ -783,8 +781,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
}
}
/* FIXME Exporting non-public type through public API FIXME */
public boolean isInDropList(RemoteHostId peer) { synchronized (_dropList) { return _dropList.contains(peer); } }
boolean isInDropList(RemoteHostId peer) { synchronized (_dropList) { return _dropList.contains(peer); } }
void dropPeer(Hash peer, boolean shouldShitlist, String why) {
PeerState state = getPeerState(peer);
@ -2235,8 +2232,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
_testEvent.runTest();
}
/* FIXME Exporting non-public type through public API FIXME */
public PeerState pickTestPeer(RemoteHostId dontInclude) {
PeerState pickTestPeer(RemoteHostId dontInclude) {
List peers = null;
synchronized (_peersByIdent) {
peers = new ArrayList(_peersByIdent.values());