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.future.OpenFuture;
import org.opendaylight.netconf.shaded.sshd.client.session.ClientSession;
import org.opendaylight.netconf.shaded.sshd.core.CoreModuleProperties;
import org.slf4j.Logger;
negotiationFuture);
}
- private synchronized void handleSshAuthenticated(final NettyAwareClientSession newSession,
- final ChannelHandlerContext ctx) {
- 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 -> {
- if (future.isOpened()) {
- handleSshChanelOpened(ctx);
- } else {
- handleSshSetupFailure(ctx, future.getException());
- }
- });
- } catch (final IOException e) {
- handleSshSetupFailure(ctx, e);
- }
- }
-
private synchronized void handleSshChanelOpened(final ChannelHandlerContext ctx) {
LOG.trace("SSH subsystem channel opened successfully on channel: {}", ctx.channel());
return;
}
- handleSshAuthenticated(clientSession, ctx);
+ onAuthComplete(clientSession, ctx);
+ }
+
+ private synchronized void onAuthComplete(final NettyAwareClientSession clientSession,
+ final ChannelHandlerContext ctx) {
+ LOG.debug("SSH session authenticated on channel: {}, server version: {}", ctx.channel(),
+ clientSession.getServerVersion());
+
+ final OpenFuture openFuture;
+ try {
+ channel = clientSession.createSubsystemChannel(SUBSYSTEM, ctx);
+ channel.setStreaming(ClientChannel.Streaming.Async);
+ openFuture = channel.open();
+ } catch (final IOException e) {
+ handleSshSetupFailure(ctx, e);
+ return;
+ }
+
+ openFuture.addListener(future -> onOpenComplete(future, ctx));
+ }
+
+ private void onOpenComplete(final OpenFuture future, final ChannelHandlerContext ctx) {
+ final var cause = future.getException();
+ if (cause != null) {
+ handleSshSetupFailure(ctx, cause);
+ return;
+ }
+
+ handleSshChanelOpened(ctx);
}
@Override
}
private static OpenFuture getSuccessOpenFuture() {
- final OpenFuture failedOpenFuture = mock(OpenFuture.class);
- doReturn(true).when(failedOpenFuture).isOpened();
- return failedOpenFuture;
+ final OpenFuture openFuture = mock(OpenFuture.class);
+ doReturn(null).when(openFuture).getException();
+ return openFuture;
}
private static AuthFuture getSuccessAuthFuture() {
}
private static OpenFuture getFailedOpenFuture() {
- final OpenFuture authFuture = mock(OpenFuture.class);
- doReturn(false).when(authFuture).isOpened();
- doReturn(new IllegalStateException()).when(authFuture).getException();
- return authFuture;
+ final OpenFuture openFuture = mock(OpenFuture.class);
+ doReturn(new IllegalStateException()).when(openFuture).getException();
+ return openFuture;
}
@Test