mina-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lgoldst...@apache.org
Subject [2/6] mina-sshd git commit: [SSHD-839] Provide remote address endpoint (when available) to PortForwardingEventListener callbacks
Date Sun, 26 Aug 2018 05:51:44 GMT
[SSHD-839] Provide remote address endpoint (when available) to PortForwardingEventListener
callbacks


Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/cb39ad88
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/cb39ad88
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/cb39ad88

Branch: refs/heads/master
Commit: cb39ad88e9a6006b4a8b6f6e1369e7f61782e206
Parents: 3495f72
Author: Goldstein Lyor <lyor@cb4.com>
Authored: Wed Aug 22 15:37:23 2018 +0300
Committer: Goldstein Lyor <lyor@cb4.com>
Committed: Sun Aug 26 08:50:42 2018 +0300

----------------------------------------------------------------------
 .../common/forward/DefaultForwardingFilter.java | 50 +++++++++++---------
 .../forward/PortForwardingEventListener.java    | 30 +++++++-----
 .../test/java/org/apache/sshd/ProxyTest.java    | 23 +++++----
 .../common/forward/PortForwardingLoadTest.java  | 15 +++---
 .../sshd/common/forward/PortForwardingTest.java | 23 ++++-----
 sshd-mina/pom.xml                               |  2 +-
 6 files changed, 80 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/cb39ad88/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultForwardingFilter.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultForwardingFilter.java
b/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultForwardingFilter.java
index 42fdce0..0bc1cf0 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultForwardingFilter.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultForwardingFilter.java
@@ -252,22 +252,24 @@ public class DefaultForwardingFilter
         unbindLocalForwarding(local, remote, bound);
     }
 
-    protected void unbindLocalForwarding(SshdSocketAddress local, SshdSocketAddress remote,
InetSocketAddress bound) throws IOException {
+    protected void unbindLocalForwarding(
+            SshdSocketAddress local, SshdSocketAddress remote, InetSocketAddress bound)
+                    throws IOException {
         if ((bound != null) && (acceptor != null)) {
             if (log.isDebugEnabled()) {
                 log.debug("unbindLocalForwarding(" + local + " => " + remote + ") unbind
" + bound);
             }
 
             SshdSocketAddress boundAddress = new SshdSocketAddress(bound);
-            signalTearingDownExplicitTunnel(boundAddress, true);
+            signalTearingDownExplicitTunnel(boundAddress, true, remote);
             try {
                 acceptor.unbind(bound);
             } catch (RuntimeException e) {
-                signalTornDownExplicitTunnel(boundAddress, true, e);
+                signalTornDownExplicitTunnel(boundAddress, true, remote, e);
                 throw e;
             }
 
-            signalTornDownExplicitTunnel(boundAddress, true, null);
+            signalTornDownExplicitTunnel(boundAddress, true, remote, null);
         } else {
             if (log.isDebugEnabled()) {
                 log.debug("unbindLocalForwarding(" + local + " => " + remote + ") no mapping/acceptor
for " + bound);
@@ -353,15 +355,15 @@ public class DefaultForwardingFilter
             buffer.putString(remoteHost);
             buffer.putInt(port);
 
-            signalTearingDownExplicitTunnel(bound, false);
+            signalTearingDownExplicitTunnel(bound, false, remote);
             try {
                 session.writePacket(buffer);
             } catch (IOException | RuntimeException e) {
-                signalTornDownExplicitTunnel(bound, false, e);
+                signalTornDownExplicitTunnel(bound, false, remote, e);
                 throw e;
             }
 
-            signalTornDownExplicitTunnel(bound, false, null);
+            signalTornDownExplicitTunnel(bound, false, remote, null);
         } else {
             if (log.isDebugEnabled()) {
                 log.debug("stopRemotePortForwarding(" + remote + ") no binding found");
@@ -369,10 +371,12 @@ public class DefaultForwardingFilter
         }
     }
 
-    protected void signalTearingDownExplicitTunnel(SshdSocketAddress boundAddress, boolean
localForwarding) throws IOException {
+    protected void signalTearingDownExplicitTunnel(
+            SshdSocketAddress boundAddress, boolean localForwarding, SshdSocketAddress remote)
+                throws IOException {
         try {
             invokePortEventListenerSignaller(l -> {
-                signalTearingDownExplicitTunnel(l, boundAddress, localForwarding);
+                signalTearingDownExplicitTunnel(l, boundAddress, localForwarding, remote);
                 return null;
             });
         } catch (Throwable t) {
@@ -391,19 +395,21 @@ public class DefaultForwardingFilter
     }
 
     protected void signalTearingDownExplicitTunnel(
-            PortForwardingEventListener listener, SshdSocketAddress boundAddress, boolean
localForwarding)
-                    throws IOException {
+            PortForwardingEventListener listener, SshdSocketAddress boundAddress, boolean
localForwarding, SshdSocketAddress remoteAddress)
+                throws IOException {
         if (listener == null) {
             return;
         }
 
-        listener.tearingDownExplicitTunnel(getSession(), boundAddress, localForwarding);
+        listener.tearingDownExplicitTunnel(getSession(), boundAddress, localForwarding, remoteAddress);
     }
 
-    protected void signalTornDownExplicitTunnel(SshdSocketAddress boundAddress, boolean localForwarding,
Throwable reason) throws IOException {
+    protected void signalTornDownExplicitTunnel(
+            SshdSocketAddress boundAddress, boolean localForwarding, SshdSocketAddress remoteAddress,
Throwable reason)
+                throws IOException {
         try {
             invokePortEventListenerSignaller(l -> {
-                signalTornDownExplicitTunnel(l, boundAddress, localForwarding, reason);
+                signalTornDownExplicitTunnel(l, boundAddress, localForwarding, remoteAddress,
reason);
                 return null;
             });
         } catch (Throwable t) {
@@ -422,13 +428,13 @@ public class DefaultForwardingFilter
     }
 
     protected void signalTornDownExplicitTunnel(
-            PortForwardingEventListener listener, SshdSocketAddress boundAddress, boolean
localForwarding, Throwable reason)
+            PortForwardingEventListener listener, SshdSocketAddress boundAddress, boolean
localForwarding, SshdSocketAddress remoteAddress, Throwable reason)
                     throws IOException {
         if (listener == null) {
             return;
         }
 
-        listener.tornDownExplicitTunnel(getSession(), boundAddress, localForwarding, reason);
+        listener.tornDownExplicitTunnel(getSession(), boundAddress, localForwarding, remoteAddress,
reason);
     }
 
     @Override
@@ -712,15 +718,15 @@ public class DefaultForwardingFilter
                 log.debug("localPortForwardingCancelled(" + local + ") unbind " + entry);
             }
 
-            signalTearingDownExplicitTunnel(entry, true);
+            signalTearingDownExplicitTunnel(entry, true, null);
             try {
                 acceptor.unbind(entry.toInetSocketAddress());
             } catch (RuntimeException e) {
-                signalTornDownExplicitTunnel(entry, true, e);
+                signalTornDownExplicitTunnel(entry, true, null, e);
                 throw e;
             }
 
-            signalTornDownExplicitTunnel(entry, true, null);
+            signalTornDownExplicitTunnel(entry, true, null, null);
         } else {
             if (log.isDebugEnabled()) {
                 log.debug("localPortForwardingCancelled(" + local + ") no match/acceptor:
" + entry);
@@ -751,9 +757,9 @@ public class DefaultForwardingFilter
         }
     }
 
-    protected void signalEstablishingExplicitTunnel(PortForwardingEventListener listener,
-            SshdSocketAddress local, SshdSocketAddress remote, boolean localForwarding)
-                    throws IOException {
+    protected void signalEstablishingExplicitTunnel(
+            PortForwardingEventListener listener, SshdSocketAddress local, SshdSocketAddress
remote, boolean localForwarding)
+                throws IOException {
         if (listener == null) {
             return;
         }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/cb39ad88/sshd-core/src/main/java/org/apache/sshd/common/forward/PortForwardingEventListener.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/forward/PortForwardingEventListener.java
b/sshd-core/src/main/java/org/apache/sshd/common/forward/PortForwardingEventListener.java
index fde2d6d..67abdfe 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/forward/PortForwardingEventListener.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/forward/PortForwardingEventListener.java
@@ -48,8 +48,8 @@ public interface PortForwardingEventListener extends SshdEventListener {
      */
     default void establishingExplicitTunnel(
             Session session, SshdSocketAddress local, SshdSocketAddress remote, boolean localForwarding)
-                    throws IOException {
-                        // ignored
+                throws IOException {
+        // ignored
     }
 
     /**
@@ -67,8 +67,8 @@ public interface PortForwardingEventListener extends SshdEventListener {
     default void establishedExplicitTunnel(
             Session session, SshdSocketAddress local, SshdSocketAddress remote, boolean localForwarding,
             SshdSocketAddress boundAddress, Throwable reason)
-                    throws IOException {
-                        // ignored
+                throws IOException {
+        // ignored
     }
 
     /**
@@ -77,12 +77,15 @@ public interface PortForwardingEventListener extends SshdEventListener
{
      * @param session The {@link Session} through which the request is made
      * @param address The (bound) address - local/remote according to the forwarding type
      * @param localForwarding Local/remote port forwarding indicator
+     * @param remoteAddress The specified peer address when tunnel was established - may
+     * be {@code null} for server-side local tunneling requests
      * @throws IOException If failed to handle the event - in which case
      * the request is aborted
      */
-    default void tearingDownExplicitTunnel(Session session, SshdSocketAddress address, boolean
localForwarding)
-            throws IOException {
-                // ignored
+    default void tearingDownExplicitTunnel(
+            Session session, SshdSocketAddress address, boolean localForwarding, SshdSocketAddress
remoteAddress)
+                    throws IOException {
+        // ignored
     }
 
     /**
@@ -91,14 +94,17 @@ public interface PortForwardingEventListener extends SshdEventListener
{
      * @param session The {@link Session} through which the request is made
      * @param address The (bound) address - local/remote according to the forwarding type
      * @param localForwarding Local/remote port forwarding indicator
+     * @param remoteAddress The specified peer address when tunnel was established - may
+     * be {@code null} for server-side local tunneling requests
      * @param reason Reason for failure - {@code null} if successful
      * @throws IOException If failed to handle the event - <B>Note:</B>
      * the exception is propagated, but the port forwarding may have
      * been torn down - no rollback
      */
-    default void tornDownExplicitTunnel(Session session, SshdSocketAddress address, boolean
localForwarding, Throwable reason)
-            throws IOException {
-                // ignored
+    default void tornDownExplicitTunnel(
+            Session session, SshdSocketAddress address, boolean localForwarding, SshdSocketAddress
remoteAddress, Throwable reason)
+                throws IOException {
+        // ignored
     }
 
     /**
@@ -125,8 +131,8 @@ public interface PortForwardingEventListener extends SshdEventListener
{
      */
     default void establishedDynamicTunnel(
             Session session, SshdSocketAddress local, SshdSocketAddress boundAddress, Throwable
reason)
-                    throws IOException {
-                        // ignored
+                throws IOException {
+        // ignored
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/cb39ad88/sshd-core/src/test/java/org/apache/sshd/ProxyTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/ProxyTest.java b/sshd-core/src/test/java/org/apache/sshd/ProxyTest.java
index 7a1fa72..5f14471 100644
--- a/sshd-core/src/test/java/org/apache/sshd/ProxyTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/ProxyTest.java
@@ -82,16 +82,19 @@ public class ProxyTest extends BaseTestSupport {
         }
 
         @Override
-        public void tearingDownExplicitTunnel(org.apache.sshd.common.session.Session session,
SshdSocketAddress address,
-                boolean localForwarding) throws IOException {
-            log.info("tearingDownExplicitTunnel(session={}, address={}, localForwarding={})",
session, address, localForwarding);
+        public void tearingDownExplicitTunnel(
+                org.apache.sshd.common.session.Session session, SshdSocketAddress address,
boolean localForwarding, SshdSocketAddress remoteAddress)
+                    throws IOException {
+            log.info("tearingDownExplicitTunnel(session={}, address={}, localForwarding={},
remote={})",
+                session, address, localForwarding, remoteAddress);
         }
 
         @Override
-        public void tornDownExplicitTunnel(org.apache.sshd.common.session.Session session,
SshdSocketAddress address,
-                boolean localForwarding, Throwable reason) throws IOException {
-            log.info("tornDownExplicitTunnel(session={}, address={}, localForwarding={},
reason={})",
-                     session, address, localForwarding, reason);
+        public void tornDownExplicitTunnel(
+                org.apache.sshd.common.session.Session session, SshdSocketAddress address,
boolean localForwarding, SshdSocketAddress remoteAddress, Throwable reason)
+                    throws IOException {
+            log.info("tornDownExplicitTunnel(session={}, address={}, localForwarding={},
remote={}, reason={})",
+                     session, address, localForwarding, remoteAddress, reason);
         }
 
         @Override
@@ -172,7 +175,7 @@ public class ProxyTest extends BaseTestSupport {
         PortForwardingEventListener listener = new PortForwardingEventListener() {
             @Override
             public void tornDownExplicitTunnel(
-                    org.apache.sshd.common.session.Session session, SshdSocketAddress address,
boolean localForwarding, Throwable reason)
+                    org.apache.sshd.common.session.Session session, SshdSocketAddress address,
boolean localForwarding, SshdSocketAddress remoteAddress, Throwable reason)
                             throws IOException {
                 throw new UnsupportedOperationException("Unexpected explicit tunnel torn
down indication: session=" + session + ", address=" + address);
             }
@@ -187,8 +190,8 @@ public class ProxyTest extends BaseTestSupport {
 
             @Override
             public void tearingDownExplicitTunnel(
-                    org.apache.sshd.common.session.Session session, SshdSocketAddress address,
boolean localForwarding)
-                            throws IOException {
+                    org.apache.sshd.common.session.Session session, SshdSocketAddress address,
boolean localForwarding, SshdSocketAddress remoteAddress)
+                        throws IOException {
                 throw new UnsupportedOperationException("Unexpected explicit tunnel tear
down indication: session=" + session + ", address=" + address);
             }
 

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/cb39ad88/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingLoadTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingLoadTest.java
b/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingLoadTest.java
index e37ff7b..3b6197e 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingLoadTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingLoadTest.java
@@ -95,17 +95,18 @@ public class PortForwardingLoadTest extends BaseTestSupport {
 
         @Override
         public void tearingDownExplicitTunnel(
-                org.apache.sshd.common.session.Session session, SshdSocketAddress address,
boolean localForwarding)
+                org.apache.sshd.common.session.Session session, SshdSocketAddress address,
boolean localForwarding, SshdSocketAddress remoteAddress)
                     throws IOException {
-            log.info("tearingDownExplicitTunnel(session={}, address={}, localForwarding={})",
session, address, localForwarding);
+            log.info("tearingDownExplicitTunnel(session={}, address={}, localForwarding={},
remote={})",
+                session, address, localForwarding, remoteAddress);
         }
 
         @Override
         public void tornDownExplicitTunnel(
-                org.apache.sshd.common.session.Session session, SshdSocketAddress address,
boolean localForwarding, Throwable reason)
+                org.apache.sshd.common.session.Session session, SshdSocketAddress address,
boolean localForwarding, SshdSocketAddress remoteAddress, Throwable reason)
                     throws IOException {
-            log.info("tornDownExplicitTunnel(session={}, address={}, localForwarding={},
reason={})",
-                 session, address, localForwarding, reason);
+            log.info("tornDownExplicitTunnel(session={}, address={}, localForwarding={},
remote={}, reason={})",
+                 session, address, localForwarding, remoteAddress, reason);
         }
 
         @Override
@@ -266,7 +267,7 @@ public class PortForwardingLoadTest extends BaseTestSupport {
                                     }
                                 }
                             }
-                            log.info("Finished iteration {}", i);
+                            log.info("Finished iteration {}/{}", i, numIterations);
                             iterationsSignal.release();
                         }
                         log.info("Done");
@@ -280,7 +281,7 @@ public class PortForwardingLoadTest extends BaseTestSupport {
 
             byte[] buf = new byte[8192];
             for (int i = 0; i < numIterations; i++) {
-                log.info("Iteration {} started", i);
+                log.info("Iteration {}/{} started", i, numIterations);
                 try (Socket s = new Socket(TEST_LOCALHOST, sinkPort);
                      OutputStream sockOut = s.getOutputStream()) {
 

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/cb39ad88/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingTest.java
b/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingTest.java
index 450184e..e933046 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingTest.java
@@ -101,17 +101,18 @@ public class PortForwardingTest extends BaseTestSupport {
 
         @Override
         public void tearingDownExplicitTunnel(
-                org.apache.sshd.common.session.Session session, SshdSocketAddress address,
boolean localForwarding)
+                org.apache.sshd.common.session.Session session, SshdSocketAddress address,
boolean localForwarding, SshdSocketAddress remoteAddress)
                     throws IOException {
-            log.info("tearingDownExplicitTunnel(session={}, address={}, localForwarding={})",
session, address, localForwarding);
+            log.info("tearingDownExplicitTunnel(session={}, address={}, localForwarding={},
remote={})",
+                session, address, localForwarding, remoteAddress);
         }
 
         @Override
         public void tornDownExplicitTunnel(
-                org.apache.sshd.common.session.Session session, SshdSocketAddress address,
boolean localForwarding, Throwable reason)
+                org.apache.sshd.common.session.Session session, SshdSocketAddress address,
boolean localForwarding, SshdSocketAddress remoteAddress, Throwable reason)
                     throws IOException {
-            log.info("tornDownExplicitTunnel(session={}, address={}, localForwarding={},
reason={})",
-                 session, address, localForwarding, reason);
+            log.info("tornDownExplicitTunnel(session={}, address={}, localForwarding={},
remote={}, reason={})",
+                 session, address, localForwarding, remoteAddress, reason);
         }
 
         @Override
@@ -363,8 +364,8 @@ public class PortForwardingTest extends BaseTestSupport {
         PortForwardingEventListener listener = new PortForwardingEventListener() {
             @Override
             public void tornDownExplicitTunnel(
-                    org.apache.sshd.common.session.Session session, SshdSocketAddress address,
boolean localForwarding, Throwable reason)
-                            throws IOException {
+                    org.apache.sshd.common.session.Session session, SshdSocketAddress address,
boolean localForwarding, SshdSocketAddress remoteAddress, Throwable reason)
+                        throws IOException {
                 assertFalse("Unexpected local tunnel has been torn down: address=" + address,
localForwarding);
                 assertEquals("Tear down indication not invoked", 1, tearDownSignal.get());
             }
@@ -377,8 +378,8 @@ public class PortForwardingTest extends BaseTestSupport {
 
             @Override
             public void tearingDownExplicitTunnel(
-                    org.apache.sshd.common.session.Session session, SshdSocketAddress address,
boolean localForwarding)
-                            throws IOException {
+                    org.apache.sshd.common.session.Session session, SshdSocketAddress address,
boolean localForwarding, SshdSocketAddress remoteAddress)
+                        throws IOException {
                 assertFalse("Unexpected local tunnel being torn down: address=" + address,
localForwarding);
                 assertEquals("Duplicate tear down signalling", 1, tearDownSignal.incrementAndGet());
             }
@@ -501,7 +502,7 @@ public class PortForwardingTest extends BaseTestSupport {
         PortForwardingEventListener listener = new PortForwardingEventListener() {
             @Override
             public void tornDownExplicitTunnel(
-                    org.apache.sshd.common.session.Session session, SshdSocketAddress address,
boolean localForwarding, Throwable reason)
+                    org.apache.sshd.common.session.Session session, SshdSocketAddress address,
boolean localForwarding, SshdSocketAddress remoteAddress, Throwable reason)
                         throws IOException {
                 assertTrue("Unexpected remote tunnel has been torn down: address=" + address,
localForwarding);
                 assertEquals("Tear down indication not invoked", 1, tearDownSignal.get());
@@ -516,7 +517,7 @@ public class PortForwardingTest extends BaseTestSupport {
 
             @Override
             public void tearingDownExplicitTunnel(
-                    org.apache.sshd.common.session.Session session, SshdSocketAddress address,
boolean localForwarding)
+                    org.apache.sshd.common.session.Session session, SshdSocketAddress address,
boolean localForwarding, SshdSocketAddress remoteAddress)
                         throws IOException {
                 assertTrue("Unexpected remote tunnel being torn down: address=" + address,
localForwarding);
                 assertEquals("Duplicate tear down signalling", 1, tearDownSignal.incrementAndGet());

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/cb39ad88/sshd-mina/pom.xml
----------------------------------------------------------------------
diff --git a/sshd-mina/pom.xml b/sshd-mina/pom.xml
index f231cab..ec900fe 100644
--- a/sshd-mina/pom.xml
+++ b/sshd-mina/pom.xml
@@ -168,7 +168,7 @@
                         <exclude>**/CipherTest.java</exclude>
                         <exclude>**/CompressionTest.java</exclude>
                         <exclude>**/NoServerNoClientTest.java</exclude>
-                        <exclude>**/PortForwardingTest.java</exclude>
+                        <!-- exclude>**/PortForwardingTest.java</exclude -->
                         <exclude>**/MacTest.java</exclude>
                         <exclude>**/SpringConfigTest.java</exclude>
                         <exclude>**/ConcurrentConnectionTest.java</exclude>


Mime
View raw message