X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fnetconf-netty-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fnettyutil%2Fhandler%2Fssh%2Fclient%2FAsyncSshHandler.java;h=0d2f6e1aa5aa42868fb6bcec746a87ee168139a9;hb=22755ee880d798830f42cc0d60e84c8602fe3794;hp=96e5a975f92497f1f609566651e6771753a6d9b2;hpb=7461000dc0c8263ae58f3f95e1e3081daf9f69fa;p=netconf.git diff --git a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandler.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandler.java index 96e5a975f9..0d2f6e1aa5 100644 --- a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandler.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandler.java @@ -14,18 +14,18 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelOutboundHandlerAdapter; import io.netty.channel.ChannelPromise; import io.netty.util.concurrent.Future; -import io.netty.util.concurrent.GenericFutureListener; +import io.netty.util.concurrent.FutureListener; import java.io.IOException; import java.net.SocketAddress; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import org.eclipse.jdt.annotation.Nullable; import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler; -import org.opendaylight.netconf.shaded.sshd.client.SshClient; import org.opendaylight.netconf.shaded.sshd.client.channel.ClientChannel; import org.opendaylight.netconf.shaded.sshd.client.future.AuthFuture; import org.opendaylight.netconf.shaded.sshd.client.future.ConnectFuture; import org.opendaylight.netconf.shaded.sshd.client.session.ClientSession; +import org.opendaylight.netconf.shaded.sshd.core.CoreModuleProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,15 +38,16 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter { public static final String SUBSYSTEM = "netconf"; public static final int SSH_DEFAULT_NIO_WORKERS = 8; - // Disable default timeouts from mina sshd - private static final long DEFAULT_TIMEOUT = -1L; public static final NetconfSshClient DEFAULT_CLIENT; static { final NetconfSshClient c = new NetconfClientBuilder().build(); - c.getProperties().put(SshClient.AUTH_TIMEOUT, Long.toString(DEFAULT_TIMEOUT)); - c.getProperties().put(SshClient.IDLE_TIMEOUT, Long.toString(DEFAULT_TIMEOUT)); + // Disable default timeouts from mina sshd + c.getProperties().put(CoreModuleProperties.AUTH_TIMEOUT.getName(), "0"); + c.getProperties().put(CoreModuleProperties.IDLE_TIMEOUT.getName(), "0"); + c.getProperties().put(CoreModuleProperties.NIO2_READ_TIMEOUT.getName(), "0"); + c.getProperties().put(CoreModuleProperties.TCP_NODELAY.getName(), true); // TODO make configurable, or somehow reuse netty threadpool c.setNioWorkers(SSH_DEFAULT_NIO_WORKERS); @@ -64,7 +65,7 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter { private NettyAwareChannelSubsystem channel; private ClientSession session; private ChannelPromise connectPromise; - private GenericFutureListener negotiationFutureListener; + private FutureListener negotiationFutureListener; public AsyncSshHandler(final AuthenticationHandler authenticationHandler, final NetconfSshClient sshClient, final Future negotiationFuture) { @@ -139,10 +140,10 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter { private synchronized void handleSshAuthenticated(final NettyAwareClientSession newSession, final ChannelHandlerContext ctx) { - try { - LOG.debug("SSH session authenticated on channel: {}, server version: {}", ctx.channel(), - newSession.getServerVersion()); + LOG.debug("SSH session authenticated on channel: {}, server version: {}", ctx.channel(), + newSession.getServerVersion()); + try { channel = newSession.createSubsystemChannel(SUBSYSTEM, ctx); channel.setStreaming(ClientChannel.Streaming.Async); channel.open().addListener(future -> { @@ -152,8 +153,6 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter { handleSshSetupFailure(ctx, future.getException()); } }); - - } catch (final IOException e) { handleSshSetupFailure(ctx, e); } @@ -190,8 +189,8 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter { @Override public synchronized void connect(final ChannelHandlerContext ctx, final SocketAddress remoteAddress, final SocketAddress localAddress, final ChannelPromise promise) throws Exception { - LOG.debug("SSH session connecting on channel {}. promise: {} ", ctx.channel(), connectPromise); - this.connectPromise = promise; + LOG.debug("SSH session connecting on channel {}. promise: {}", ctx.channel(), promise); + connectPromise = requireNonNull(promise); if (negotiationFuture != null) { negotiationFutureListener = future -> {