From b2a137c5bc95bd86cc5b5bc862ac93bfaa5d2a12 Mon Sep 17 00:00:00 2001 From: zzz Date: Wed, 30 Dec 2009 22:33:26 +0000 Subject: [PATCH] make BuildResponseRecord static --- .../i2p/data/i2np/BuildResponseRecord.java | 22 +++++++++++++------ .../i2p/router/tunnel/pool/BuildHandler.java | 21 ++++++++++++------ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/router/java/src/net/i2p/data/i2np/BuildResponseRecord.java b/router/java/src/net/i2p/data/i2np/BuildResponseRecord.java index 562f082ba..3b17e01b3 100644 --- a/router/java/src/net/i2p/data/i2np/BuildResponseRecord.java +++ b/router/java/src/net/i2p/data/i2np/BuildResponseRecord.java @@ -5,28 +5,36 @@ import net.i2p.data.Base64; import net.i2p.data.DataHelper; import net.i2p.data.Hash; import net.i2p.data.SessionKey; -import net.i2p.util.Log; +//import net.i2p.util.Log; /** * Read and write the reply to a tunnel build message record. * + * The reply record is the same size as the request record (528 bytes). + * Bytes 0-526 contain random data. + * Byte 527 contains the reply. */ public class BuildResponseRecord { + /** * Create a new encrypted response + * + * @param status the response + * @param responseMessageID unused except for debugging + * @param a 528-byte response record */ - public byte[] create(I2PAppContext ctx, int status, SessionKey replyKey, byte replyIV[], long responseMessageId) { - Log log = ctx.logManager().getLog(BuildResponseRecord.class); + public static byte[] create(I2PAppContext ctx, int status, SessionKey replyKey, byte replyIV[], long responseMessageId) { + //Log log = ctx.logManager().getLog(BuildResponseRecord.class); byte rv[] = new byte[TunnelBuildReplyMessage.RECORD_SIZE]; ctx.random().nextBytes(rv); DataHelper.toLong(rv, TunnelBuildMessage.RECORD_SIZE-1, 1, status); // rv = AES(SHA256(padding+status) + padding + status, replyKey, replyIV) ctx.sha().calculateHash(rv, Hash.HASH_LENGTH, rv.length - Hash.HASH_LENGTH, rv, 0); - if (log.shouldLog(Log.DEBUG)) - log.debug(responseMessageId + ": before encrypt: " + Base64.encode(rv, 0, 128) + " with " + replyKey.toBase64() + "/" + Base64.encode(replyIV)); + //if (log.shouldLog(Log.DEBUG)) + // log.debug(responseMessageId + ": before encrypt: " + Base64.encode(rv, 0, 128) + " with " + replyKey.toBase64() + "/" + Base64.encode(replyIV)); ctx.aes().encrypt(rv, 0, rv, 0, replyKey, replyIV, rv.length); - if (log.shouldLog(Log.DEBUG)) - log.debug(responseMessageId + ": after encrypt: " + Base64.encode(rv, 0, 128)); + //if (log.shouldLog(Log.DEBUG)) + // log.debug(responseMessageId + ": after encrypt: " + Base64.encode(rv, 0, 128)); return rv; } } diff --git a/router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java b/router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java index 8a48b5186..971b20a54 100644 --- a/router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java +++ b/router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java @@ -113,10 +113,10 @@ class BuildHandler { if (toHandle > MAX_HANDLE_AT_ONCE) toHandle = MAX_HANDLE_AT_ONCE; handled = new ArrayList(toHandle); - if (false) { - for (int i = 0; i < toHandle; i++) // LIFO for lower response time (should we RED it for DoS?) - handled.add(_inboundBuildMessages.remove(_inboundBuildMessages.size()-1)); - } else { + //if (false) { + // for (int i = 0; i < toHandle; i++) // LIFO for lower response time (should we RED it for DoS?) + // handled.add(_inboundBuildMessages.remove(_inboundBuildMessages.size()-1)); + //} else { // drop any expired messages long dropBefore = System.currentTimeMillis() - (BuildRequestor.REQUEST_TIMEOUT/4); do { @@ -140,7 +140,7 @@ class BuildHandler { // when adding) for (int i = 0; i < toHandle && _inboundBuildMessages.size() > 0; i++) handled.add(_inboundBuildMessages.remove(0)); - } + //} } remaining = _inboundBuildMessages.size(); } @@ -482,6 +482,14 @@ class BuildHandler { return 0; } + /** + * Actually process the request and send the reply. + * + * Todo: Replies are not subject to RED for bandwidth reasons, + * and the bandwidth is not credited to any tunnel. + * If we did credit the reply to the tunnel, it would + * prevent the classification of the tunnel as 'inactive' on tunnels.jsp. + */ @SuppressWarnings("static-access") private void handleReq(RouterInfo nextPeerInfo, BuildMessageState state, BuildRequestRecord req, Hash nextPeer) { long ourId = req.readReceiveTunnelId(); @@ -604,8 +612,7 @@ class BuildHandler { return; } - BuildResponseRecord resp = new BuildResponseRecord(); - byte reply[] = resp.create(_context, response, req.readReplyKey(), req.readReplyIV(), state.msg.getUniqueId()); + byte reply[] = BuildResponseRecord.create(_context, response, req.readReplyKey(), req.readReplyIV(), state.msg.getUniqueId()); for (int j = 0; j < TunnelBuildMessage.RECORD_COUNT; j++) { if (state.msg.getRecord(j) == null) { ourSlot = j;