import io.netty.util.concurrent.GenericFutureListener;
import java.io.IOException;
import java.net.SocketAddress;
-import org.apache.sshd.client.SshClient;
-import org.apache.sshd.client.channel.ClientChannel;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.sshd.ClientChannel;
+import org.apache.sshd.ClientSession;
+import org.apache.sshd.SshClient;
import org.apache.sshd.client.future.AuthFuture;
import org.apache.sshd.client.future.ConnectFuture;
import org.apache.sshd.client.future.OpenFuture;
-import org.apache.sshd.client.session.ClientSession;
-import org.apache.sshd.client.session.ClientSessionCreator;
import org.apache.sshd.common.future.CloseFuture;
import org.apache.sshd.common.future.SshFutureListener;
import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
public static final SshClient DEFAULT_CLIENT;
static {
+ final Map<String, String> props = new HashMap<>();
+ props.put(SshClient.AUTH_TIMEOUT, Long.toString(DEFAULT_TIMEOUT));
+ props.put(SshClient.IDLE_TIMEOUT, Long.toString(DEFAULT_TIMEOUT));
+
final SshClient c = SshClient.setUpDefaultClient();
- c.getProperties().put(SshClient.AUTH_TIMEOUT, Long.toString(DEFAULT_TIMEOUT));
- c.getProperties().put(SshClient.IDLE_TIMEOUT, Long.toString(DEFAULT_TIMEOUT));
+
+ c.setProperties(props);
// TODO make configurable, or somehow reuse netty threadpool
c.setNioWorkers(SSH_DEFAULT_NIO_WORKERS);
c.start();
}
private final AuthenticationHandler authenticationHandler;
- private final ClientSessionCreator sshClient;
+ private final SshClient sshClient;
private Future<?> negotiationFuture;
private AsyncSshHandlerReader sshReadAsyncListener;
private ChannelPromise connectPromise;
private GenericFutureListener negotiationFutureListener;
- public AsyncSshHandler(final AuthenticationHandler authenticationHandler, final ClientSessionCreator sshClient,
- final Future<?> negotiationFuture) {
+ public AsyncSshHandler(final AuthenticationHandler authenticationHandler, final SshClient sshClient,
+ final Future<?> negotiationFuture) throws IOException {
this(authenticationHandler, sshClient);
this.negotiationFuture = negotiationFuture;
}
*
* @param authenticationHandler
* @param sshClient started SshClient
+ * @throws IOException
*/
- public AsyncSshHandler(final AuthenticationHandler authenticationHandler, final ClientSessionCreator sshClient) {
+ public AsyncSshHandler(final AuthenticationHandler authenticationHandler, final SshClient sshClient) throws IOException {
this.authenticationHandler = Preconditions.checkNotNull(authenticationHandler);
this.sshClient = Preconditions.checkNotNull(sshClient);
}
- public static AsyncSshHandler createForNetconfSubsystem(final AuthenticationHandler authenticationHandler) {
+ public static AsyncSshHandler createForNetconfSubsystem(final AuthenticationHandler authenticationHandler) throws IOException {
return new AsyncSshHandler(authenticationHandler, DEFAULT_CLIENT);
}
/**
*
- * Create AsyncSshHandler for netconf subsystem. Negotiation future has to be set to success after successful
- * NETCONF negotiation.
+ * Create AsyncSshHandler for netconf subsystem. Negotiation future has to be set to success after successful netconf
+ * negotiation.
*
* @param authenticationHandler
* @param negotiationFuture
* @return
+ * @throws IOException
*/
public static AsyncSshHandler createForNetconfSubsystem(final AuthenticationHandler authenticationHandler,
- final Future<?> negotiationFuture) {
+ final Future<?> negotiationFuture) throws IOException {
return new AsyncSshHandler(authenticationHandler, DEFAULT_CLIENT, negotiationFuture);
}
- private void startSsh(final ChannelHandlerContext ctx, final SocketAddress address) throws IOException {
+ private void startSsh(final ChannelHandlerContext ctx, final SocketAddress address) {
LOG.debug("Starting SSH to {} on channel: {}", address, ctx.channel());
final ConnectFuture sshConnectionFuture = sshClient.connect(authenticationHandler.getUsername(), address);