Bind SshClient/SshServer to NettyIoServiceFactoryFactory
[netconf.git] / transport / transport-ssh / src / main / java / org / opendaylight / netconf / transport / ssh / TransportSshClient.java
index 1175eb8f96acc6de5ed8d840b9d4ed14291dfd2e..ce74da3cd70f30dd22834df7406ea210ff3f53b6 100644 (file)
@@ -7,8 +7,11 @@
  */
 package org.opendaylight.netconf.transport.ssh;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.collect.ImmutableList;
 import com.google.errorprone.annotations.DoNotCall;
+import io.netty.channel.EventLoopGroup;
 import java.security.cert.Certificate;
 import org.opendaylight.netconf.shaded.sshd.client.ClientBuilder;
 import org.opendaylight.netconf.shaded.sshd.client.SshClient;
@@ -20,6 +23,7 @@ import org.opendaylight.netconf.shaded.sshd.client.auth.password.UserAuthPasswor
 import org.opendaylight.netconf.shaded.sshd.client.auth.pubkey.UserAuthPublicKeyFactory;
 import org.opendaylight.netconf.shaded.sshd.client.keyverifier.ServerKeyVerifier;
 import org.opendaylight.netconf.shaded.sshd.common.keyprovider.KeyIdentityProvider;
+import org.opendaylight.netconf.shaded.sshd.netty.NettyIoServiceFactoryFactory;
 import org.opendaylight.netconf.transport.api.UnsupportedConfigurationException;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.crypto.types.rev230417.password.grouping.password.type.CleartextPassword;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ssh.client.rev230417.ssh.client.grouping.ClientIdentity;
@@ -65,9 +69,17 @@ final class TransportSshClient extends SshClient {
      * {@code ietf-netconf-client.yang} configuration.
      */
     static final class Builder extends ClientBuilder {
+        private final NettyIoServiceFactoryFactory ioServiceFactory;
+        private final EventLoopGroup group;
+
         private Keepalives keepAlives;
         private ClientIdentity clientIdentity;
 
+        Builder(final NettyIoServiceFactoryFactory ioServiceFactory, final EventLoopGroup group) {
+            this.ioServiceFactory = requireNonNull(ioServiceFactory);
+            this.group = requireNonNull(group);
+        }
+
         Builder transportParams(final TransportParamsGrouping params) throws UnsupportedConfigurationException {
             ConfigUtils.setTransportParams(this, params, TransportUtils::getClientKexFactories);
             return this;
@@ -115,9 +127,8 @@ final class TransportSshClient extends SshClient {
             if (clientIdentity != null && clientIdentity.getNone() == null) {
                 setClientIdentity(ret, clientIdentity);
             }
-
-            // FIXME: this is the default added by checkConfig(), but we really want to use an EventLoopGroup for this
-            // ret.setScheduledExecutorService(group);
+            ret.setIoServiceFactoryFactory(ioServiceFactory);
+            ret.setScheduledExecutorService(group);
 
             try {
                 ret.checkConfig();