From c79ff0dc09522e1949ffbb0f0e6d3bae36cc59b3 Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Fri, 14 Feb 2014 17:02:14 +0000
Subject: [PATCH] minor cleanups

---
 .../i2p/router/tunnel/BuildMessageGenerator.java   | 10 +++++++---
 .../src/net/i2p/router/tunnel/HopProcessor.java    | 14 ++++++++------
 .../router/tunnel/InboundEndpointProcessor.java    |  4 ++--
 .../src/net/i2p/router/tunnel/InboundSender.java   |  4 ++--
 .../router/tunnel/OutboundGatewayProcessor.java    |  6 +++---
 .../src/net/i2p/router/tunnel/OutboundSender.java  |  4 ++--
 .../net/i2p/router/tunnel/pool/BuildRequestor.java |  4 +++-
 .../src/net/i2p/router/tunnel/pool/TunnelPool.java |  3 ++-
 8 files changed, 29 insertions(+), 20 deletions(-)

diff --git a/router/java/src/net/i2p/router/tunnel/BuildMessageGenerator.java b/router/java/src/net/i2p/router/tunnel/BuildMessageGenerator.java
index e956f4364b..42aae3ce38 100644
--- a/router/java/src/net/i2p/router/tunnel/BuildMessageGenerator.java
+++ b/router/java/src/net/i2p/router/tunnel/BuildMessageGenerator.java
@@ -55,7 +55,9 @@ public abstract class BuildMessageGenerator {
      *
      * @param msg out parameter
      */
-    public static void createRecord(int recordNum, int hop, TunnelBuildMessage msg, TunnelCreatorConfig cfg, Hash replyRouter, long replyTunnel, I2PAppContext ctx, PublicKey peerKey) {
+    public static void createRecord(int recordNum, int hop, TunnelBuildMessage msg,
+                                    TunnelCreatorConfig cfg, Hash replyRouter,
+                                    long replyTunnel, I2PAppContext ctx, PublicKey peerKey) {
         byte encrypted[] = new byte[TunnelBuildMessage.RECORD_SIZE];
         //Log log = ctx.logManager().getLog(BuildMessageGenerator.class);
         if (peerKey != null) {
@@ -79,7 +81,8 @@ public abstract class BuildMessageGenerator {
         msg.setRecord(recordNum, new ByteArray(encrypted));
     }
     
-    private static BuildRequestRecord createUnencryptedRecord(I2PAppContext ctx, TunnelCreatorConfig cfg, int hop, Hash replyRouter, long replyTunnel) {
+    private static BuildRequestRecord createUnencryptedRecord(I2PAppContext ctx, TunnelCreatorConfig cfg, int hop,
+                                                              Hash replyRouter, long replyTunnel) {
         //Log log = ctx.logManager().getLog(BuildMessageGenerator.class);
         if (hop < cfg.getLength()) {
             // ok, now lets fill in some data
@@ -143,7 +146,8 @@ public abstract class BuildMessageGenerator {
      * Encrypt the records so their hop ident is visible at the appropriate times
      * @param order list of hop #s as Integers.  For instance, if (order.get(1) is 4), it is peer cfg.getPeer(4)
      */
-    public static void layeredEncrypt(I2PAppContext ctx, TunnelBuildMessage msg, TunnelCreatorConfig cfg, List<Integer> order) {
+    public static void layeredEncrypt(I2PAppContext ctx, TunnelBuildMessage msg,
+                                      TunnelCreatorConfig cfg, List<Integer> order) {
         //Log log = ctx.logManager().getLog(BuildMessageGenerator.class);
         // encrypt the records so that the right elements will be visible at the right time
         for (int i = 0; i < msg.getRecordCount(); i++) {
diff --git a/router/java/src/net/i2p/router/tunnel/HopProcessor.java b/router/java/src/net/i2p/router/tunnel/HopProcessor.java
index b24ad0c5e2..fa2f5f3fa3 100644
--- a/router/java/src/net/i2p/router/tunnel/HopProcessor.java
+++ b/router/java/src/net/i2p/router/tunnel/HopProcessor.java
@@ -20,13 +20,15 @@ class HopProcessor {
     private final IVValidator _validator;
         
     /** helpful flag for debugging */
-    static final boolean USE_ENCRYPTION = true;
+    //static final boolean USE_ENCRYPTION = true;
     /**
-     * as of i2p 0.6, the tunnel crypto will change by encrypting the IV both before 
+     * as of i2p 0.6, the tunnel crypto changed  to encrypt the IV both before 
      * and after using it at each hop so as to prevent a certain type of replay/confirmation 
      * attack.
+     *
+     * See: http://osdir.com/ml/network.i2p/2005-07/msg00031.html
      */
-    static final boolean USE_DOUBLE_IV_ENCRYPTION = true;
+    //static final boolean USE_DOUBLE_IV_ENCRYPTION = true;
     static final int IV_LENGTH = 16;
     
     /** @deprecated unused */
@@ -83,12 +85,12 @@ class HopProcessor {
             //_log.debug("IV received: " + Base64.encode(iv));
             //_log.debug("Before:" + Base64.encode(orig, IV_LENGTH, orig.length - IV_LENGTH));
         }
-        if (USE_ENCRYPTION) {
-            if (USE_DOUBLE_IV_ENCRYPTION) 
+        //if (USE_ENCRYPTION) {
+            //if (USE_DOUBLE_IV_ENCRYPTION) 
                 updateIV(orig, offset);
             encrypt(orig, offset, length);
             updateIV(orig, offset);
-        }
+        //}
         //if (_log.shouldLog(Log.DEBUG)) {
             //_log.debug("Data after processing: " + Base64.encode(orig, IV_LENGTH, orig.length - IV_LENGTH));
             //_log.debug("IV sent: " + Base64.encode(orig, 0, IV_LENGTH));
diff --git a/router/java/src/net/i2p/router/tunnel/InboundEndpointProcessor.java b/router/java/src/net/i2p/router/tunnel/InboundEndpointProcessor.java
index cda394fa54..88aa6da71a 100644
--- a/router/java/src/net/i2p/router/tunnel/InboundEndpointProcessor.java
+++ b/router/java/src/net/i2p/router/tunnel/InboundEndpointProcessor.java
@@ -19,7 +19,7 @@ class InboundEndpointProcessor {
     private final TunnelCreatorConfig _config;
     private final IVValidator _validator;    
     
-    static final boolean USE_ENCRYPTION = HopProcessor.USE_ENCRYPTION;
+    //static final boolean USE_ENCRYPTION = HopProcessor.USE_ENCRYPTION;
     
     /** @deprecated unused */
     public InboundEndpointProcessor(RouterContext ctx, TunnelCreatorConfig cfg) {
@@ -67,7 +67,7 @@ class InboundEndpointProcessor {
         }
         
         // inbound endpoints and outbound gateways have to undo the crypto in the same way
-        if (USE_ENCRYPTION)
+        //if (USE_ENCRYPTION)
             decrypt(_context, _config, iv, orig, offset, length);
         
         SimpleByteCache.release(iv);
diff --git a/router/java/src/net/i2p/router/tunnel/InboundSender.java b/router/java/src/net/i2p/router/tunnel/InboundSender.java
index 9ab0a61d13..0e00b6b398 100644
--- a/router/java/src/net/i2p/router/tunnel/InboundSender.java
+++ b/router/java/src/net/i2p/router/tunnel/InboundSender.java
@@ -10,14 +10,14 @@ import net.i2p.I2PAppContext;
 class InboundSender implements TunnelGateway.Sender {
     private final InboundGatewayProcessor _processor;
     
-    static final boolean USE_ENCRYPTION = HopProcessor.USE_ENCRYPTION;
+    //static final boolean USE_ENCRYPTION = HopProcessor.USE_ENCRYPTION;
     
     public InboundSender(I2PAppContext ctx, HopConfig config) {
         _processor = new InboundGatewayProcessor(ctx, config);
     }
     
     public long sendPreprocessed(byte[] preprocessed, TunnelGateway.Receiver receiver) {
-        if (USE_ENCRYPTION)
+        //if (USE_ENCRYPTION)
             _processor.process(preprocessed, 0, preprocessed.length);
         return receiver.receiveEncrypted(preprocessed);
     }
diff --git a/router/java/src/net/i2p/router/tunnel/OutboundGatewayProcessor.java b/router/java/src/net/i2p/router/tunnel/OutboundGatewayProcessor.java
index 8acb0e5bbb..c6a08ccef0 100644
--- a/router/java/src/net/i2p/router/tunnel/OutboundGatewayProcessor.java
+++ b/router/java/src/net/i2p/router/tunnel/OutboundGatewayProcessor.java
@@ -16,7 +16,7 @@ class OutboundGatewayProcessor {
     private final Log _log;
     private final TunnelCreatorConfig _config;
         
-    static final boolean USE_ENCRYPTION = HopProcessor.USE_ENCRYPTION;
+    //static final boolean USE_ENCRYPTION = HopProcessor.USE_ENCRYPTION;
 
     public OutboundGatewayProcessor(I2PAppContext ctx, TunnelCreatorConfig cfg) {
         _context = ctx;
@@ -42,7 +42,7 @@ class OutboundGatewayProcessor {
             _log.debug("Orig random IV: " + Base64.encode(iv));
             //_log.debug("data:  " + Base64.encode(orig, iv.length, length - iv.length));
         }
-        if (USE_ENCRYPTION)
+        //if (USE_ENCRYPTION)
             decrypt(_context, _config, iv, orig, offset, length);
         if (_log.shouldLog(Log.DEBUG))
             _log.debug("finished processing the preprocessed data");
@@ -97,7 +97,7 @@ class OutboundGatewayProcessor {
             cur = xf;
         }
         
-        if (HopProcessor.USE_DOUBLE_IV_ENCRYPTION)
+        //if (HopProcessor.USE_DOUBLE_IV_ENCRYPTION)
             ctx.aes().decryptBlock(orig, offset, config.getIVKey(), orig, offset);
     }
 }
diff --git a/router/java/src/net/i2p/router/tunnel/OutboundSender.java b/router/java/src/net/i2p/router/tunnel/OutboundSender.java
index 3842f7a512..961c29031f 100644
--- a/router/java/src/net/i2p/router/tunnel/OutboundSender.java
+++ b/router/java/src/net/i2p/router/tunnel/OutboundSender.java
@@ -15,7 +15,7 @@ class OutboundSender implements TunnelGateway.Sender {
     private final TunnelCreatorConfig _config;
     private final OutboundGatewayProcessor _processor;
     
-    static final boolean USE_ENCRYPTION = HopProcessor.USE_ENCRYPTION;
+    //static final boolean USE_ENCRYPTION = HopProcessor.USE_ENCRYPTION;
     
     public OutboundSender(I2PAppContext ctx, TunnelCreatorConfig config) {
         _context = ctx;
@@ -27,7 +27,7 @@ class OutboundSender implements TunnelGateway.Sender {
     public long sendPreprocessed(byte[] preprocessed, TunnelGateway.Receiver receiver) {
         if (_log.shouldLog(Log.DEBUG))
             _log.debug("preprocessed data going out " + _config + ": " + Base64.encode(preprocessed));
-        if (USE_ENCRYPTION)
+        //if (USE_ENCRYPTION)
             _processor.process(preprocessed, 0, preprocessed.length);
         if (_log.shouldLog(Log.DEBUG))
             _log.debug("after wrapping up the preprocessed data on " + _config);
diff --git a/router/java/src/net/i2p/router/tunnel/pool/BuildRequestor.java b/router/java/src/net/i2p/router/tunnel/pool/BuildRequestor.java
index 65ae2be276..fbfca2bcc9 100644
--- a/router/java/src/net/i2p/router/tunnel/pool/BuildRequestor.java
+++ b/router/java/src/net/i2p/router/tunnel/pool/BuildRequestor.java
@@ -248,7 +248,9 @@ abstract class BuildRequestor {
      *  then use that, otherwise the old 8-entry version.
      *  @return null on error
      */
-    private static TunnelBuildMessage createTunnelBuildMessage(RouterContext ctx, TunnelPool pool, PooledTunnelCreatorConfig cfg, TunnelInfo pairedTunnel, BuildExecutor exec) {
+    private static TunnelBuildMessage createTunnelBuildMessage(RouterContext ctx, TunnelPool pool,
+                                                               PooledTunnelCreatorConfig cfg,
+                                                               TunnelInfo pairedTunnel, BuildExecutor exec) {
         Log log = ctx.logManager().getLog(BuildRequestor.class);
         long replyTunnel = 0;
         Hash replyRouter = null;
diff --git a/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java b/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java
index 38a7e1253a..e76058c8ef 100644
--- a/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java
+++ b/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java
@@ -1137,7 +1137,8 @@ public class TunnelPool {
             peers = Collections.singletonList(_context.routerHash());
         }
 
-        PooledTunnelCreatorConfig cfg = new PooledTunnelCreatorConfig(_context, peers.size(), settings.isInbound(), settings.getDestination());
+        PooledTunnelCreatorConfig cfg = new PooledTunnelCreatorConfig(_context, peers.size(),
+                                                settings.isInbound(), settings.getDestination());
         cfg.setTunnelPool(this);
         // peers list is ordered endpoint first, but cfg.getPeer() is ordered gateway first
         for (int i = 0; i < peers.size(); i++) {
-- 
GitLab