From ce96234fdbe337fa3aa071a255363f487460e9a4 Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Sat, 21 Nov 2015 19:45:54 +0000
Subject: [PATCH] SSU ext. options:   - don't ask for intro if he is indirect  
 - ask for intro if our state is unknown   - debug logging   - change min to
 0.9.23 for testing

---
 .../transport/udp/EstablishmentManager.java   |  9 ++++---
 .../transport/udp/InboundEstablishState.java  |  2 ++
 .../router/transport/udp/PacketBuilder.java   |  5 +++-
 .../router/transport/udp/UDPTransport.java    | 25 +++++++++++++++++++
 4 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/router/java/src/net/i2p/router/transport/udp/EstablishmentManager.java b/router/java/src/net/i2p/router/transport/udp/EstablishmentManager.java
index 64c32cddff..77fdd78ba1 100644
--- a/router/java/src/net/i2p/router/transport/udp/EstablishmentManager.java
+++ b/router/java/src/net/i2p/router/transport/udp/EstablishmentManager.java
@@ -132,10 +132,11 @@ class EstablishmentManager {
      * but i2pd hasn't recognized it until this release.
      * No matter, the options weren't defined until this release anyway.
      *
-     * FIXME 0.9.22 for testing, change to 0.9.24 for release
+**********************************************************************************************************
+     * FIXME 0.9.23 for testing, change to 0.9.24 for release
      *
      */
-    private static final String VERSION_ALLOW_EXTENDED_OPTIONS = "0.9.22";
+    private static final String VERSION_ALLOW_EXTENDED_OPTIONS = "0.9.23";
     private static final String PROP_DISABLE_EXT_OPTS = "i2np.udp.disableExtendedOptions";
 
 
@@ -373,7 +374,9 @@ class EstablishmentManager {
                                                                           VERSION_ALLOW_EXTENDED_OPTIONS) >= 0
                                                    && !_context.getBooleanProperty(PROP_DISABLE_EXT_OPTS);
                     // w/o ext options, it's always 'requested', no need to set
-                    boolean requestIntroduction = allowExtendedOptions && _transport.introducersRequired();
+                    // don't ask if they are indirect
+                    boolean requestIntroduction = allowExtendedOptions && !isIndirect &&
+                                                  _transport.introducersMaybeRequired();
                     state = new OutboundEstablishState(_context, maybeTo, to,
                                                        toIdentity, allowExtendedOptions,
                                                        requestIntroduction,
diff --git a/router/java/src/net/i2p/router/transport/udp/InboundEstablishState.java b/router/java/src/net/i2p/router/transport/udp/InboundEstablishState.java
index 96d45c216b..332282c24d 100644
--- a/router/java/src/net/i2p/router/transport/udp/InboundEstablishState.java
+++ b/router/java/src/net/i2p/router/transport/udp/InboundEstablishState.java
@@ -155,6 +155,8 @@ class InboundEstablishState {
         byte[] ext = req.readExtendedOptions();
         if (ext != null && ext.length >= UDPPacket.SESS_REQ_MIN_EXT_OPTIONS_LENGTH) {
             _introductionRequested = (ext[1] & (byte) UDPPacket.SESS_REQ_EXT_FLAG_REQUEST_RELAY_TAG) != 0;
+            if (_log.shouldInfo())
+                _log.info("got sess req. w/ ext. options, need intro? " + _introductionRequested + ' ' + this);
         }
         if (_log.shouldLog(Log.DEBUG))
             _log.debug("Receive sessionRequest, BobIP = " + Addresses.toString(_bobIP));
diff --git a/router/java/src/net/i2p/router/transport/udp/PacketBuilder.java b/router/java/src/net/i2p/router/transport/udp/PacketBuilder.java
index 98cf82bb61..0f7e0ac804 100644
--- a/router/java/src/net/i2p/router/transport/udp/PacketBuilder.java
+++ b/router/java/src/net/i2p/router/transport/udp/PacketBuilder.java
@@ -788,8 +788,11 @@ class PacketBuilder {
         boolean ext = state.isExtendedOptionsAllowed();
         if (ext) {
             options = new byte[UDPPacket.SESS_REQ_MIN_EXT_OPTIONS_LENGTH];
-            if (state.needIntroduction())
+            boolean intro = state.needIntroduction();
+            if (intro)
                 options[1] = (byte) UDPPacket.SESS_REQ_EXT_FLAG_REQUEST_RELAY_TAG;
+            if (_log.shouldInfo())
+                _log.info("send sess req. w/ ext. options, need intro? " + intro + ' ' + state);
             off += UDPPacket.SESS_REQ_MIN_EXT_OPTIONS_LENGTH + 1;
         } else {
             options = null;
diff --git a/router/java/src/net/i2p/router/transport/udp/UDPTransport.java b/router/java/src/net/i2p/router/transport/udp/UDPTransport.java
index b68626ab50..f6a94d7fb8 100644
--- a/router/java/src/net/i2p/router/transport/udp/UDPTransport.java
+++ b/router/java/src/net/i2p/router/transport/udp/UDPTransport.java
@@ -2216,6 +2216,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
                 if (_log.shouldLog(Log.DEBUG))
                     _log.debug("Require introducers, because our status is " + status);
                 return true;
+
             default:
                 if (!allowDirectUDP()) {
                     if (_log.shouldLog(Log.DEBUG))
@@ -2226,6 +2227,30 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
         }
     }
     
+    /**
+     *  MIGHT we require introducers?
+     *  This is like introducersRequired, but if we aren't sure, this returns true.
+     *  Used only by EstablishmentManager.
+     *
+     *  @since 0.9.24
+     */
+    boolean introducersMaybeRequired() {
+        Status status = getReachabilityStatus();
+        switch (status) {
+            case REJECT_UNSOLICITED:
+            case DIFFERENT:
+            case IPV4_FIREWALLED_IPV6_OK:
+            case IPV4_FIREWALLED_IPV6_UNKNOWN:
+            case IPV4_UNKNOWN_IPV6_OK:
+            case IPV4_UNKNOWN_IPV6_FIREWALLED:
+            case UNKNOWN:
+                return true;
+
+            default:
+                return !allowDirectUDP();
+        }
+    }
+    
     /**
      *  For EstablishmentManager
      *  @since 0.9.3
-- 
GitLab