mina-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lgoldst...@apache.org
Subject [1/4] mina-sshd git commit: Added some more log messages and validations to TCP/IP forwarders
Date Mon, 08 Feb 2016 08:21:19 GMT
Repository: mina-sshd
Updated Branches:
  refs/heads/master f275a5217 -> a3d058b09


Added some more log messages and validations to TCP/IP forwarders


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

Branch: refs/heads/master
Commit: a00c397d9392b149b427fe126c6067134dd17609
Parents: f275a52
Author: Lyor Goldstein <lgoldstein@vmware.com>
Authored: Mon Feb 8 07:47:36 2016 +0200
Committer: Lyor Goldstein <lgoldstein@vmware.com>
Committed: Mon Feb 8 07:47:36 2016 +0200

----------------------------------------------------------------------
 .../common/forward/DefaultTcpipForwarder.java   | 41 +++++++++++++++++---
 .../global/CancelTcpipForwardHandler.java       |  6 +--
 .../sshd/server/global/TcpipForwardHandler.java |  3 +-
 3 files changed, 40 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/a00c397d/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java
b/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java
index facf9bd..30c9b37 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java
@@ -22,6 +22,8 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.net.InetSocketAddress;
 import java.net.SocketAddress;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -78,6 +80,9 @@ public class DefaultTcpipForwarder
      */
     public static final long DEFAULT_FORWARD_REQUEST_TIMEOUT = TimeUnit.SECONDS.toMillis(15L);
 
+    public static final Set<ClientChannel.ClientChannelEvent> STATIC_IO_MSG_RECEIVED_EVENTS
=
+            Collections.unmodifiableSet(EnumSet.of(ClientChannel.ClientChannelEvent.OPENED,
ClientChannel.ClientChannelEvent.CLOSED));
+
     private final ConnectionService service;
     private final IoHandlerFactory socksProxyIoHandlerFactory = new IoHandlerFactory() {
         @Override
@@ -371,7 +376,7 @@ public class DefaultTcpipForwarder
         if (acceptor == null) {
             Session session = getSession();
             FactoryManager manager = ValidateUtils.checkNotNull(session.getFactoryManager(),
"No factory manager");
-            IoServiceFactory factory = manager.getIoServiceFactory();
+            IoServiceFactory factory = ValidateUtils.checkNotNull(manager.getIoServiceFactory(),
"No I/O service factory");
             IoHandler handler = handlerFactory.create();
             acceptor = factory.createAcceptor(handler);
         }
@@ -417,12 +422,16 @@ public class DefaultTcpipForwarder
             super();
         }
 
-        @SuppressWarnings("synthetic-access")
         @Override
+        @SuppressWarnings("synthetic-access")
         public void sessionCreated(final IoSession session) throws Exception {
             InetSocketAddress local = (InetSocketAddress) session.getLocalAddress();
             int localPort = local.getPort();
             SshdSocketAddress remote = localToRemote.get(localPort);
+            if (log.isDebugEnabled()) {
+                log.debug("sessionCreated({}) remote={}", session, remote);
+            }
+
             final TcpipClientChannel channel;
             if (remote != null) {
                 channel = new TcpipClientChannel(TcpipClientChannel.Type.Direct, session,
remote);
@@ -430,12 +439,18 @@ public class DefaultTcpipForwarder
                 channel = new TcpipClientChannel(TcpipClientChannel.Type.Forwarded, session,
null);
             }
             session.setAttribute(TcpipClientChannel.class, channel);
+
             service.registerChannel(channel);
             channel.open().addListener(new SshFutureListener<OpenFuture>() {
                 @Override
                 public void operationComplete(OpenFuture future) {
                     Throwable t = future.getException();
                     if (t != null) {
+                        log.warn("Failed ({}) to open channel for session={}: {}",
+                                 t.getClass().getSimpleName(), session, t.getMessage());
+                        if (log.isDebugEnabled()) {
+                            log.debug("sessionCreated(" + session + ") channel=" + channel
+ " open failure details", t);
+                        }
                         DefaultTcpipForwarder.this.service.unregisterChannel(channel);
                         channel.close(false);
                     }
@@ -443,22 +458,30 @@ public class DefaultTcpipForwarder
             });
         }
 
-        @SuppressWarnings("synthetic-access")
         @Override
+        @SuppressWarnings("synthetic-access")
         public void sessionClosed(IoSession session) throws Exception {
             TcpipClientChannel channel = (TcpipClientChannel) session.getAttribute(TcpipClientChannel.class);
             if (channel != null) {
-                log.debug("IoSession {} closed, will now close the channel", session);
+                if (log.isDebugEnabled()) {
+                    log.debug("sessionClosed({}) closing channel={}", session, channel);
+                }
                 channel.close(false);
             }
         }
 
         @Override
+        @SuppressWarnings("synthetic-access")
         public void messageReceived(IoSession session, Readable message) throws Exception
{
             TcpipClientChannel channel = (TcpipClientChannel) session.getAttribute(TcpipClientChannel.class);
             Buffer buffer = new ByteArrayBuffer(message.available() + Long.SIZE, false);
             buffer.putBuffer(message);
-            channel.waitFor(EnumSet.of(ClientChannel.ClientChannelEvent.OPENED, ClientChannel.ClientChannelEvent.CLOSED),
Long.MAX_VALUE);
+
+            Collection<ClientChannel.ClientChannelEvent> result = channel.waitFor(STATIC_IO_MSG_RECEIVED_EVENTS,
Long.MAX_VALUE);
+            if (log.isTraceEnabled()) {
+                log.trace("messageReceived({}) channel={}, len={} wait result: {}",
+                          session, channel, result, buffer.array());
+            }
 
             OutputStream outputStream = channel.getInvertedIn();
             outputStream.write(buffer.array(), buffer.rpos(), buffer.available());
@@ -466,8 +489,14 @@ public class DefaultTcpipForwarder
         }
 
         @Override
+        @SuppressWarnings("synthetic-access")
         public void exceptionCaught(IoSession session, Throwable cause) throws Exception
{
-            cause.printStackTrace();
+            if (log.isDebugEnabled()) {
+                log.debug("exceptionCaught({}) {}: {}", session, cause.getClass().getSimpleName(),
cause.getMessage());
+            }
+            if (log.isTraceEnabled()) {
+                log.trace("exceptionCaught(" + session + ") caught exception details", cause);
+            }
             session.close(false);
         }
     }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/a00c397d/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java
b/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java
index bbf7b34..36d8bf2 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/global/CancelTcpipForwardHandler.java
@@ -24,6 +24,7 @@ import org.apache.sshd.common.session.AbstractConnectionServiceRequestHandler;
 import org.apache.sshd.common.session.ConnectionService;
 import org.apache.sshd.common.session.Session;
 import org.apache.sshd.common.util.Int2IntFunction;
+import org.apache.sshd.common.util.ValidateUtils;
 import org.apache.sshd.common.util.buffer.Buffer;
 import org.apache.sshd.common.util.net.SshdSocketAddress;
 
@@ -55,11 +56,10 @@ public class CancelTcpipForwardHandler extends AbstractConnectionServiceRequestH
         int port = buffer.getInt();
         SshdSocketAddress socketAddress = new SshdSocketAddress(address, port);
         if (log.isDebugEnabled()) {
-            log.debug("process({})[{}] {} reply=" + wantReply,
-                      connectionService, request, socketAddress, wantReply);
+            log.debug("process({})[{}] {} reply={}", connectionService, request, socketAddress,
wantReply);
         }
 
-        TcpipForwarder forwarder = connectionService.getTcpipForwarder();
+        TcpipForwarder forwarder = ValidateUtils.checkNotNull(connectionService.getTcpipForwarder(),
"No TCP/IP forwarder");
         forwarder.localPortForwardingCancelled(socketAddress);
 
         if (wantReply) {

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/a00c397d/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java
b/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java
index 95e6ad9..a0e19af 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/global/TcpipForwardHandler.java
@@ -24,6 +24,7 @@ import org.apache.sshd.common.session.AbstractConnectionServiceRequestHandler;
 import org.apache.sshd.common.session.ConnectionService;
 import org.apache.sshd.common.session.Session;
 import org.apache.sshd.common.util.Int2IntFunction;
+import org.apache.sshd.common.util.ValidateUtils;
 import org.apache.sshd.common.util.buffer.Buffer;
 import org.apache.sshd.common.util.net.SshdSocketAddress;
 
@@ -55,7 +56,7 @@ public class TcpipForwardHandler extends AbstractConnectionServiceRequestHandler
         String address = buffer.getString();
         int port = buffer.getInt();
         SshdSocketAddress socketAddress = new SshdSocketAddress(address, port);
-        TcpipForwarder forwarder = connectionService.getTcpipForwarder();
+        TcpipForwarder forwarder = ValidateUtils.checkNotNull(connectionService.getTcpipForwarder(),
"No TCP/IP forwader");
         SshdSocketAddress bound = forwarder.localPortForwardingRequested(socketAddress);
         if (log.isDebugEnabled()) {
             log.debug("process({})[{}][want-reply-{}] {} => {}",


Mime
View raw message