forked from I2P_Developers/i2p.i2p
more final and cleanups
This commit is contained in:
@ -21,10 +21,10 @@ import net.i2p.util.Log;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class IntroductionManager {
|
class IntroductionManager {
|
||||||
private RouterContext _context;
|
private final RouterContext _context;
|
||||||
private Log _log;
|
private final Log _log;
|
||||||
private UDPTransport _transport;
|
private final UDPTransport _transport;
|
||||||
private PacketBuilder _builder;
|
private final PacketBuilder _builder;
|
||||||
/** map of relay tag to PeerState that should receive the introduction */
|
/** map of relay tag to PeerState that should receive the introduction */
|
||||||
private final Map<Long, PeerState> _outbound;
|
private final Map<Long, PeerState> _outbound;
|
||||||
/** list of peers (PeerState) who have given us introduction tags */
|
/** list of peers (PeerState) who have given us introduction tags */
|
||||||
|
@ -20,9 +20,9 @@ import net.i2p.util.Log;
|
|||||||
* {@link net.i2p.router.InNetMessagePool} by way of the {@link UDPTransport}.
|
* {@link net.i2p.router.InNetMessagePool} by way of the {@link UDPTransport}.
|
||||||
*/
|
*/
|
||||||
class MessageReceiver {
|
class MessageReceiver {
|
||||||
private RouterContext _context;
|
private final RouterContext _context;
|
||||||
private Log _log;
|
private final Log _log;
|
||||||
private UDPTransport _transport;
|
private final UDPTransport _transport;
|
||||||
/** list of messages (InboundMessageState) fully received but not interpreted yet */
|
/** list of messages (InboundMessageState) fully received but not interpreted yet */
|
||||||
private final BlockingQueue<InboundMessageState> _completeMessages;
|
private final BlockingQueue<InboundMessageState> _completeMessages;
|
||||||
private boolean _alive;
|
private boolean _alive;
|
||||||
|
@ -50,7 +50,7 @@ class OutboundEstablishState {
|
|||||||
private long _nextSend;
|
private long _nextSend;
|
||||||
private RemoteHostId _remoteHostId;
|
private RemoteHostId _remoteHostId;
|
||||||
private final RouterIdentity _remotePeer;
|
private final RouterIdentity _remotePeer;
|
||||||
private SessionKey _introKey;
|
private final SessionKey _introKey;
|
||||||
private final Queue<OutNetMessage> _queuedMessages;
|
private final Queue<OutNetMessage> _queuedMessages;
|
||||||
private int _currentState;
|
private int _currentState;
|
||||||
private long _introductionNonce;
|
private long _introductionNonce;
|
||||||
|
@ -95,9 +95,9 @@ around briefly, to address packet loss and reordering.</p>
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class PacketBuilder {
|
class PacketBuilder {
|
||||||
private I2PAppContext _context;
|
private final I2PAppContext _context;
|
||||||
private Log _log;
|
private final Log _log;
|
||||||
private UDPTransport _transport;
|
private final UDPTransport _transport;
|
||||||
|
|
||||||
private static final ByteCache _ivCache = ByteCache.getInstance(64, UDPPacket.IV_SIZE);
|
private static final ByteCache _ivCache = ByteCache.getInstance(64, UDPPacket.IV_SIZE);
|
||||||
private static final ByteCache _hmacCache = ByteCache.getInstance(64, Hash.HASH_LENGTH);
|
private static final ByteCache _hmacCache = ByteCache.getInstance(64, Hash.HASH_LENGTH);
|
||||||
|
@ -91,17 +91,17 @@ with either Bob or Charlie, but it is not required.</p>
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
class PeerTestManager {
|
class PeerTestManager {
|
||||||
private RouterContext _context;
|
private final RouterContext _context;
|
||||||
private Log _log;
|
private final Log _log;
|
||||||
private UDPTransport _transport;
|
private final UDPTransport _transport;
|
||||||
private PacketBuilder _packetBuilder;
|
private final PacketBuilder _packetBuilder;
|
||||||
/** map of Long(nonce) to PeerTestState for tests currently in progress (as Bob/Charlie) */
|
/** map of Long(nonce) to PeerTestState for tests currently in progress (as Bob/Charlie) */
|
||||||
private final Map<Long, PeerTestState> _activeTests;
|
private final Map<Long, PeerTestState> _activeTests;
|
||||||
/** current test we are running (as Alice), or null */
|
/** current test we are running (as Alice), or null */
|
||||||
private PeerTestState _currentTest;
|
private PeerTestState _currentTest;
|
||||||
private boolean _currentTestComplete;
|
private boolean _currentTestComplete;
|
||||||
/** as Alice */
|
/** as Alice */
|
||||||
private Queue<Long> _recentTests;
|
private final Queue<Long> _recentTests;
|
||||||
|
|
||||||
/** longest we will keep track of a Charlie nonce for */
|
/** longest we will keep track of a Charlie nonce for */
|
||||||
private static final int MAX_CHARLIE_LIFETIME = 10*1000;
|
private static final int MAX_CHARLIE_LIFETIME = 10*1000;
|
||||||
|
@ -19,13 +19,13 @@ import net.i2p.util.Log;
|
|||||||
class UDPPacket {
|
class UDPPacket {
|
||||||
private I2PAppContext _context;
|
private I2PAppContext _context;
|
||||||
private static Log _log;
|
private static Log _log;
|
||||||
private volatile DatagramPacket _packet;
|
private final DatagramPacket _packet;
|
||||||
private volatile short _priority;
|
private volatile short _priority;
|
||||||
private volatile long _initializeTime;
|
private volatile long _initializeTime;
|
||||||
private volatile long _expiration;
|
private volatile long _expiration;
|
||||||
private byte[] _data;
|
private final byte[] _data;
|
||||||
private byte[] _validateBuf;
|
private final byte[] _validateBuf;
|
||||||
private byte[] _ivBuf;
|
private final byte[] _ivBuf;
|
||||||
private volatile int _markedType;
|
private volatile int _markedType;
|
||||||
private volatile RemoteHostId _remoteHost;
|
private volatile RemoteHostId _remoteHost;
|
||||||
private volatile boolean _released;
|
private volatile boolean _released;
|
||||||
@ -81,22 +81,22 @@ class UDPPacket {
|
|||||||
|
|
||||||
private static final int MAX_VALIDATE_SIZE = MAX_PACKET_SIZE;
|
private static final int MAX_VALIDATE_SIZE = MAX_PACKET_SIZE;
|
||||||
|
|
||||||
private UDPPacket(I2PAppContext ctx, boolean inbound) {
|
private UDPPacket(I2PAppContext ctx) {
|
||||||
ctx.statManager().createRateStat("udp.fetchRemoteSlow", "How long it takes to grab the remote ip info", "udp", UDPTransport.RATES);
|
ctx.statManager().createRateStat("udp.fetchRemoteSlow", "How long it takes to grab the remote ip info", "udp", UDPTransport.RATES);
|
||||||
// the data buffer is clobbered on init(..), but we need it to bootstrap
|
// the data buffer is clobbered on init(..), but we need it to bootstrap
|
||||||
_data = new byte[MAX_PACKET_SIZE];
|
_data = new byte[MAX_PACKET_SIZE];
|
||||||
_packet = new DatagramPacket(_data, MAX_PACKET_SIZE);
|
_packet = new DatagramPacket(_data, MAX_PACKET_SIZE);
|
||||||
_validateBuf = new byte[MAX_VALIDATE_SIZE];
|
_validateBuf = new byte[MAX_VALIDATE_SIZE];
|
||||||
_ivBuf = new byte[IV_SIZE];
|
_ivBuf = new byte[IV_SIZE];
|
||||||
init(ctx, inbound);
|
init(ctx);
|
||||||
}
|
}
|
||||||
// FIXME optimization, remove the inbound parameter, as it is unused. FIXME
|
|
||||||
private void init(I2PAppContext ctx, boolean inbound) {
|
private void init(I2PAppContext ctx) {
|
||||||
_context = ctx;
|
_context = ctx;
|
||||||
//_dataBuf = _dataCache.acquire();
|
//_dataBuf = _dataCache.acquire();
|
||||||
Arrays.fill(_data, (byte)0);
|
Arrays.fill(_data, (byte)0);
|
||||||
//_packet = new DatagramPacket(_data, MAX_PACKET_SIZE);
|
//_packet = new DatagramPacket(_data, MAX_PACKET_SIZE);
|
||||||
_packet.setData(_data);
|
//_packet.setData(_data);
|
||||||
// _isInbound = inbound;
|
// _isInbound = inbound;
|
||||||
_initializeTime = _context.clock().now();
|
_initializeTime = _context.clock().now();
|
||||||
_markedType = -1;
|
_markedType = -1;
|
||||||
@ -262,15 +262,18 @@ class UDPPacket {
|
|||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param inbound unused
|
||||||
|
*/
|
||||||
public static UDPPacket acquire(I2PAppContext ctx, boolean inbound) {
|
public static UDPPacket acquire(I2PAppContext ctx, boolean inbound) {
|
||||||
UDPPacket rv = null;
|
UDPPacket rv = null;
|
||||||
if (CACHE) {
|
if (CACHE) {
|
||||||
rv = _packetCache.poll();
|
rv = _packetCache.poll();
|
||||||
if (rv != null)
|
if (rv != null)
|
||||||
rv.init(ctx, inbound);
|
rv.init(ctx);
|
||||||
}
|
}
|
||||||
if (rv == null)
|
if (rv == null)
|
||||||
rv = new UDPPacket(ctx, inbound);
|
rv = new UDPPacket(ctx);
|
||||||
//if (rv._acquiredBy != null) {
|
//if (rv._acquiredBy != null) {
|
||||||
// _log.log(Log.CRIT, "Already acquired! current stack trace is:", new Exception());
|
// _log.log(Log.CRIT, "Already acquired! current stack trace is:", new Exception());
|
||||||
// _log.log(Log.CRIT, "Earlier acquired:", rv._acquiredBy);
|
// _log.log(Log.CRIT, "Earlier acquired:", rv._acquiredBy);
|
||||||
|
@ -16,19 +16,19 @@ import net.i2p.util.Log;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class UDPPacketReader {
|
class UDPPacketReader {
|
||||||
private I2PAppContext _context;
|
private final I2PAppContext _context;
|
||||||
private Log _log;
|
private final Log _log;
|
||||||
private byte _message[];
|
private byte _message[];
|
||||||
private int _payloadBeginOffset;
|
private int _payloadBeginOffset;
|
||||||
private int _payloadLength;
|
private int _payloadLength;
|
||||||
private SessionRequestReader _sessionRequestReader;
|
private final SessionRequestReader _sessionRequestReader;
|
||||||
private SessionCreatedReader _sessionCreatedReader;
|
private final SessionCreatedReader _sessionCreatedReader;
|
||||||
private SessionConfirmedReader _sessionConfirmedReader;
|
private final SessionConfirmedReader _sessionConfirmedReader;
|
||||||
private DataReader _dataReader;
|
private final DataReader _dataReader;
|
||||||
private PeerTestReader _peerTestReader;
|
private final PeerTestReader _peerTestReader;
|
||||||
private RelayRequestReader _relayRequestReader;
|
private final RelayRequestReader _relayRequestReader;
|
||||||
private RelayIntroReader _relayIntroReader;
|
private final RelayIntroReader _relayIntroReader;
|
||||||
private RelayResponseReader _relayResponseReader;
|
private final RelayResponseReader _relayResponseReader;
|
||||||
|
|
||||||
private static final int KEYING_MATERIAL_LENGTH = 64;
|
private static final int KEYING_MATERIAL_LENGTH = 64;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user