* started reducing the temporary buffers created within various crypto methods , as we've
got some pretty heavy GC churn when under load. rough estimate is we allocate 5-8x as much data as we need, copying it all over the place before forwarding it (or processing it). this should cut down a few of those copies, but not enough yet. it'd be great to get that down to 2x. * lots of logging
This commit is contained in:
@ -89,7 +89,7 @@ public class TunnelMessage extends I2NPMessageImpl {
|
||||
if ( (_tunnelId == null) || (_data == null) || (_data.length <= 0) )
|
||||
throw new I2NPMessageException("Not enough data to write out");
|
||||
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream(4096);
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream(64+_data.length);
|
||||
try {
|
||||
_tunnelId.writeBytes(os);
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
|
@ -60,6 +60,13 @@ public class InNetMessagePool {
|
||||
I2NPMessage messageBody = msg.getMessage();
|
||||
msg.processingComplete();
|
||||
Date exp = messageBody.getMessageExpiration();
|
||||
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Received inbound "
|
||||
+ " with id " + messageBody.getUniqueId()
|
||||
+ " expiring on " + exp
|
||||
+ " of type " + messageBody.getClass().getName());
|
||||
|
||||
boolean valid = _context.messageValidator().validateMessage(messageBody.getUniqueId(), exp.getTime());
|
||||
if (!valid) {
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
|
@ -41,6 +41,13 @@ public class OutNetMessagePool {
|
||||
*
|
||||
*/
|
||||
public void add(OutNetMessage msg) {
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Adding outbound message to "
|
||||
+ msg.getTarget().getIdentity().getHash().toBase64().substring(0,6)
|
||||
+ " with id " + msg.getMessage().getUniqueId()
|
||||
+ " expiring on " + msg.getMessage().getMessageExpiration()
|
||||
+ " of type " + msg.getMessageType());
|
||||
|
||||
boolean valid = validate(msg);
|
||||
if (!valid) return;
|
||||
MessageSelector selector = msg.getReplySelector();
|
||||
|
@ -415,7 +415,7 @@ public class HandleTunnelMessageJob extends JobImpl {
|
||||
byte iv[] = new byte[16];
|
||||
Hash h = getContext().sha().calculateHash(key.getData());
|
||||
System.arraycopy(h.getData(), 0, iv, 0, iv.length);
|
||||
byte decrypted[] = getContext().AESEngine().safeDecrypt(encryptedMessage, key, iv);
|
||||
byte decrypted[] = getContext().aes().safeDecrypt(encryptedMessage, key, iv);
|
||||
if (decrypted == null) {
|
||||
if (_log.shouldLog(Log.ERROR))
|
||||
_log.error("Error decrypting the message", getAddedBy());
|
||||
@ -429,7 +429,7 @@ public class HandleTunnelMessageJob extends JobImpl {
|
||||
byte iv[] = new byte[16];
|
||||
Hash h = getContext().sha().calculateHash(key.getData());
|
||||
System.arraycopy(h.getData(), 0, iv, 0, iv.length);
|
||||
byte decrypted[] = getContext().AESEngine().safeDecrypt(encryptedInstructions, key, iv);
|
||||
byte decrypted[] = getContext().aes().safeDecrypt(encryptedInstructions, key, iv);
|
||||
if (decrypted == null) {
|
||||
if (_log.shouldLog(Log.ERROR))
|
||||
_log.error("Error decrypting the instructions", getAddedBy());
|
||||
|
@ -396,7 +396,7 @@ public class SendTunnelMessageJob extends JobImpl {
|
||||
byte iv[] = new byte[16];
|
||||
Hash h = getContext().sha().calculateHash(key.getData());
|
||||
System.arraycopy(h.getData(), 0, iv, 0, iv.length);
|
||||
return getContext().AESEngine().safeEncrypt(baos.toByteArray(), key, iv, paddedSize);
|
||||
return getContext().aes().safeEncrypt(baos.toByteArray(), key, iv, paddedSize);
|
||||
} catch (IOException ioe) {
|
||||
if (_log.shouldLog(Log.ERROR))
|
||||
_log.error("Error writing out data to encrypt", ioe);
|
||||
|
@ -307,8 +307,8 @@ public class ConnectionBuilder {
|
||||
byte pre[] = new byte[48];
|
||||
System.arraycopy(_nonce.getData(), 0, pre, 0, 4);
|
||||
System.arraycopy(_connectionTag.getData(), 0, pre, 4, 32);
|
||||
byte encr[] = _context.AESEngine().encrypt(pre, _key, _iv);
|
||||
Hash h = _context.sha().calculateHash(encr);
|
||||
_context.aes().encrypt(pre, 0, pre, 0, _key, _iv, pre.length);
|
||||
Hash h = _context.sha().calculateHash(pre);
|
||||
_nextConnectionTag = new ByteArray(h.getData());
|
||||
}
|
||||
|
||||
@ -638,7 +638,9 @@ public class ConnectionBuilder {
|
||||
private void establishComplete() {
|
||||
_connectionIn = new BandwidthLimitedInputStream(_context, _rawIn, _actualPeer.getIdentity());
|
||||
OutputStream blos = new BandwidthLimitedOutputStream(_context, _rawOut, _actualPeer.getIdentity());
|
||||
_connectionOut = blos;
|
||||
_connectionOut = blos;
|
||||
//_connectionIn = _rawIn;
|
||||
//_connectionOut = _rawOut;
|
||||
|
||||
Hash peer = _actualPeer.getIdentity().getHash();
|
||||
_context.netDb().store(peer, _actualPeer);
|
||||
|
@ -328,8 +328,8 @@ public class ConnectionHandler {
|
||||
byte pre[] = new byte[48];
|
||||
System.arraycopy(_nonce.getData(), 0, pre, 0, 4);
|
||||
System.arraycopy(_connectionTag.getData(), 0, pre, 4, 32);
|
||||
byte encr[] = _context.AESEngine().encrypt(pre, _key, _iv);
|
||||
Hash h = _context.sha().calculateHash(encr);
|
||||
_context.aes().encrypt(pre, 0, pre, 0, _key, _iv, pre.length);
|
||||
Hash h = _context.sha().calculateHash(pre);
|
||||
_nextConnectionTag = new ByteArray(h.getData());
|
||||
}
|
||||
|
||||
@ -804,6 +804,8 @@ public class ConnectionHandler {
|
||||
_connectionIn = new BandwidthLimitedInputStream(_context, _rawIn, _actualPeer.getIdentity());
|
||||
OutputStream blos = new BandwidthLimitedOutputStream(_context, _rawOut, _actualPeer.getIdentity());
|
||||
_connectionOut = blos;
|
||||
//_connectionIn = _rawIn;
|
||||
//_connectionOut = _rawOut;
|
||||
|
||||
Hash peer = _actualPeer.getIdentity().getHash();
|
||||
_context.netDb().store(peer, _actualPeer);
|
||||
|
@ -74,6 +74,11 @@ class ConnectionRunner implements Runnable {
|
||||
out.flush();
|
||||
after = _context.clock().now();
|
||||
}
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Just sent message " + msg.getMessageId() + " to "
|
||||
+ msg.getTarget().getIdentity().getHash().toBase64().substring(0,6)
|
||||
+ " writeTime = " + (after-before) +"ms"
|
||||
+ " lifetime = " + msg.getLifetime() + "ms");
|
||||
|
||||
ok = true;
|
||||
} catch (IOException ioe) {
|
||||
|
@ -4,12 +4,14 @@ import net.i2p.data.Hash;
|
||||
import net.i2p.data.RouterIdentity;
|
||||
import net.i2p.data.i2np.I2NPMessageReader;
|
||||
import net.i2p.data.i2np.I2NPMessage;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
* Receive messages from a message reader and bounce them off to the transport
|
||||
* for further enqueueing.
|
||||
*/
|
||||
public class MessageHandler implements I2NPMessageReader.I2NPMessageEventListener {
|
||||
private Log _log;
|
||||
private TCPTransport _transport;
|
||||
private TCPConnection _con;
|
||||
private RouterIdentity _ident;
|
||||
@ -20,6 +22,7 @@ public class MessageHandler implements I2NPMessageReader.I2NPMessageEventListene
|
||||
_con = con;
|
||||
_ident = con.getRemoteRouterIdentity();
|
||||
_identHash = _ident.calculateHash();
|
||||
_log = con.getRouterContext().logManager().getLog(MessageHandler.class);
|
||||
}
|
||||
|
||||
public void disconnected(I2NPMessageReader reader) {
|
||||
@ -27,6 +30,10 @@ public class MessageHandler implements I2NPMessageReader.I2NPMessageEventListene
|
||||
}
|
||||
|
||||
public void messageReceived(I2NPMessageReader reader, I2NPMessage message, long msToRead) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Just received message " + message.getUniqueId() + " from "
|
||||
+ _identHash.toBase64().substring(0,6)
|
||||
+ " readTime = " + msToRead + "ms type = " + message.getClass().getName());
|
||||
_transport.messageReceived(message, _ident, _identHash, msToRead, message.getSize());
|
||||
}
|
||||
|
||||
|
@ -202,6 +202,7 @@ public class TCPConnection {
|
||||
|
||||
/** Have we been closed already? */
|
||||
boolean getIsClosed() { return _closed; }
|
||||
RouterContext getRouterContext() { return _context; }
|
||||
|
||||
/**
|
||||
* The message was sent.
|
||||
|
Reference in New Issue
Block a user