Bind SshClient/SshServer to NettyIoServiceFactoryFactory 35/107935/3
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 21 Sep 2023 02:53:52 +0000 (04:53 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 21 Sep 2023 12:35:15 +0000 (14:35 +0200)
Our implementation are captives of SSHTransportStackFactory and
therefore should be bound to a particular EventLoopGroup and not delve
into DefaultIoServiceFactoryFactory's
getDefaultIoServiceFactoryFactoryInstance(), which works with
ServiceLoader.

Pass down NettyIoServiceFactoryFactory to make sure the configuration
does not stray from the path we have set for it.

JIRA: NETCONF-590
Change-Id: I32fc9115a28cb60cae1960293416a62a96529aec
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
transport/transport-ssh/src/main/java/org/opendaylight/netconf/transport/ssh/SSHClient.java
transport/transport-ssh/src/main/java/org/opendaylight/netconf/transport/ssh/SSHServer.java
transport/transport-ssh/src/main/java/org/opendaylight/netconf/transport/ssh/SSHTransportStackFactory.java
transport/transport-ssh/src/main/java/org/opendaylight/netconf/transport/ssh/TransportSshClient.java
transport/transport-ssh/src/main/java/org/opendaylight/netconf/transport/ssh/TransportSshServer.java

index 0172c8523716a425002d8a721674d503e08f1455..7bfc12a2989ffb39eb8af3e373ada72e658d659e 100644 (file)
@@ -18,6 +18,7 @@ import org.opendaylight.netconf.shaded.sshd.client.ClientFactoryManager;
 import org.opendaylight.netconf.shaded.sshd.client.session.ClientSessionImpl;
 import org.opendaylight.netconf.shaded.sshd.client.session.SessionFactory;
 import org.opendaylight.netconf.shaded.sshd.common.io.IoHandler;
+import org.opendaylight.netconf.shaded.sshd.netty.NettyIoServiceFactoryFactory;
 import org.opendaylight.netconf.transport.api.TransportChannelListener;
 import org.opendaylight.netconf.transport.api.TransportStack;
 import org.opendaylight.netconf.transport.api.UnsupportedConfigurationException;
@@ -51,12 +52,13 @@ public final class SSHClient extends SSHTransportStack {
                 sessionFactory);
     }
 
-    static SSHClient of(final EventLoopGroup group, final TransportChannelListener listener,
-            final SshClientGrouping clientParams) throws UnsupportedConfigurationException {
+    static SSHClient of(final NettyIoServiceFactoryFactory ioServiceFactory, final EventLoopGroup group,
+            final TransportChannelListener listener, final SshClientGrouping clientParams)
+                throws UnsupportedConfigurationException {
         final var clientIdentity = clientParams.getClientIdentity();
         final var username = clientIdentity == null ? "" : clientIdentity.getUsername();
 
-        return new SSHClient(listener, new TransportSshClient.Builder(group)
+        return new SSHClient(listener, new TransportSshClient.Builder(ioServiceFactory, group)
             .transportParams(clientParams.getTransportParams())
             .keepAlives(clientParams.getKeepalives())
             .clientIdentity(clientParams.getClientIdentity())
index 3dc4361ac5691d24e1deb579134838def298bc18..e1a7268e2bebb51b7c045fb63475e0e435e5e145 100644 (file)
@@ -17,6 +17,7 @@ import io.netty.channel.group.DefaultChannelGroup;
 import io.netty.util.concurrent.GlobalEventExecutor;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.netconf.shaded.sshd.common.io.IoHandler;
+import org.opendaylight.netconf.shaded.sshd.netty.NettyIoServiceFactoryFactory;
 import org.opendaylight.netconf.shaded.sshd.server.ServerFactoryManager;
 import org.opendaylight.netconf.shaded.sshd.server.session.SessionFactory;
 import org.opendaylight.netconf.shaded.sshd.server.subsystem.SubsystemFactory;
@@ -46,10 +47,11 @@ public final class SSHServer extends SSHTransportStack {
                 serverSessionFactory);
     }
 
-    static SSHServer of(final EventLoopGroup group, final TransportChannelListener listener,
-            final SubsystemFactory subsystemFactory, final SshServerGrouping serverParams,
-            final ServerFactoryManagerConfigurator configurator) throws UnsupportedConfigurationException {
-        return new SSHServer(listener, new TransportSshServer.Builder(group, subsystemFactory)
+    static SSHServer of(final NettyIoServiceFactoryFactory ioServiceFactory, final EventLoopGroup group,
+            final TransportChannelListener listener, final SubsystemFactory subsystemFactory,
+            final SshServerGrouping serverParams, final ServerFactoryManagerConfigurator configurator)
+                throws UnsupportedConfigurationException {
+        return new SSHServer(listener, new TransportSshServer.Builder(ioServiceFactory, group, subsystemFactory)
             .serverParams(serverParams)
             .configurator(configurator)
             .buildChecked());
index d6a24cb3d1119816534dd2e7cec03bc9239820d0..907cd970fa02a9d19a731630426f4df1c4963ab6 100644 (file)
@@ -15,6 +15,7 @@ import io.netty.bootstrap.Bootstrap;
 import io.netty.bootstrap.ServerBootstrap;
 import io.netty.channel.EventLoopGroup;
 import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.netconf.shaded.sshd.netty.NettyIoServiceFactoryFactory;
 import org.opendaylight.netconf.shaded.sshd.server.subsystem.SubsystemFactory;
 import org.opendaylight.netconf.transport.api.TransportChannelListener;
 import org.opendaylight.netconf.transport.api.UnsupportedConfigurationException;
@@ -30,11 +31,12 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.tcp.server.
 public final class SSHTransportStackFactory implements AutoCloseable {
     private final EventLoopGroup group;
     private final EventLoopGroup parentGroup;
+    private final NettyIoServiceFactoryFactory ioServiceFactory;
 
     private SSHTransportStackFactory(final EventLoopGroup group, final EventLoopGroup parentGroup) {
         this.group = requireNonNull(group);
         this.parentGroup = parentGroup;
-        // FIXME: factoryFactory = new NettyIoServiceFactoryFactory(group);
+        ioServiceFactory = new NettyIoServiceFactoryFactory(group);
     }
 
     public SSHTransportStackFactory(final @NonNull String groupName, final int groupThreads) {
@@ -50,19 +52,19 @@ public final class SSHTransportStackFactory implements AutoCloseable {
     public @NonNull ListenableFuture<SSHClient> connectClient(final TransportChannelListener listener,
             final TcpClientGrouping connectParams, final SshClientGrouping clientParams)
                 throws UnsupportedConfigurationException {
-        return SSHClient.of(group, listener, clientParams).connect(newBootstrap(), connectParams);
+        return SSHClient.of(ioServiceFactory, group, listener, clientParams).connect(newBootstrap(), connectParams);
     }
 
     public @NonNull ListenableFuture<SSHClient> listenClient(final TransportChannelListener listener,
             final TcpServerGrouping listenParams, final SshClientGrouping clientParams)
                 throws UnsupportedConfigurationException {
-        return SSHClient.of(group, listener, clientParams).listen(newServerBootstrap(), listenParams);
+        return SSHClient.of(ioServiceFactory, group, listener, clientParams).listen(newServerBootstrap(), listenParams);
     }
 
     public @NonNull ListenableFuture<SSHServer> connectServer(final TransportChannelListener listener,
             final SubsystemFactory subsystemFactory, final TcpClientGrouping connectParams,
             final SshServerGrouping serverParams) throws UnsupportedConfigurationException {
-        return SSHServer.of(group, listener, subsystemFactory, requireNonNull(serverParams), null)
+        return SSHServer.of(ioServiceFactory, group, listener, subsystemFactory, requireNonNull(serverParams), null)
             .connect(newBootstrap(), connectParams);
     }
 
@@ -91,7 +93,7 @@ public final class SSHTransportStackFactory implements AutoCloseable {
                     throws UnsupportedConfigurationException {
         checkArgument(serverParams != null || configurator != null,
             "Neither server parameters nor factory configurator is defined");
-        return SSHServer.of(group, listener, subsystemFactory, serverParams, configurator)
+        return SSHServer.of(ioServiceFactory, group, listener, subsystemFactory, serverParams, configurator)
             .listen(newServerBootstrap(), listenParams);
     }
 
index 9b680f8cb9e52c2e67b681ab9d9a46676cf14276..ce74da3cd70f30dd22834df7406ea210ff3f53b6 100644 (file)
@@ -23,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;
@@ -68,12 +69,14 @@ 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 EventLoopGroup group) {
+        Builder(final NettyIoServiceFactoryFactory ioServiceFactory, final EventLoopGroup group) {
+            this.ioServiceFactory = requireNonNull(ioServiceFactory);
             this.group = requireNonNull(group);
         }
 
@@ -124,6 +127,7 @@ final class TransportSshClient extends SshClient {
             if (clientIdentity != null && clientIdentity.getNone() == null) {
                 setClientIdentity(ret, clientIdentity);
             }
+            ret.setIoServiceFactoryFactory(ioServiceFactory);
             ret.setScheduledExecutorService(group);
 
             try {
index 20378fd6105527182127ee6ed7712408a1504486..dfa6455c783baf4b3bef28645292ca8cb6f070f1 100644 (file)
@@ -16,6 +16,7 @@ import io.netty.channel.EventLoopGroup;
 import java.security.PublicKey;
 import java.util.List;
 import org.opendaylight.netconf.shaded.sshd.common.keyprovider.KeyPairProvider;
+import org.opendaylight.netconf.shaded.sshd.netty.NettyIoServiceFactoryFactory;
 import org.opendaylight.netconf.shaded.sshd.server.ServerBuilder;
 import org.opendaylight.netconf.shaded.sshd.server.SshServer;
 import org.opendaylight.netconf.shaded.sshd.server.auth.UserAuthFactory;
@@ -67,6 +68,7 @@ final class TransportSshServer extends SshServer {
      * {@code ietf-netconf-server.yang} configuration.
      */
     static final class Builder extends ServerBuilder {
+        private final NettyIoServiceFactoryFactory ioServiceFactory;
         private final EventLoopGroup group;
         private final SubsystemFactory subsystemFactory;
 
@@ -75,7 +77,9 @@ final class TransportSshServer extends SshServer {
         private ServerIdentity serverIdentity;
         private Keepalives keepAlives;
 
-        Builder(final EventLoopGroup group, final SubsystemFactory subsystemFactory) {
+        Builder(final NettyIoServiceFactoryFactory ioServiceFactory, final EventLoopGroup group,
+                final SubsystemFactory subsystemFactory) {
+            this.ioServiceFactory = requireNonNull(ioServiceFactory);
             this.group = requireNonNull(group);
             this.subsystemFactory = requireNonNull(subsystemFactory);
         }
@@ -141,9 +145,9 @@ final class TransportSshServer extends SshServer {
             }
 
             ret.setSubsystemFactories(List.of(subsystemFactory));
+            ret.setIoServiceFactoryFactory(ioServiceFactory);
             ret.setScheduledExecutorService(group);
 
-
             try {
                 ret.checkConfig();
             } catch (IllegalArgumentException e) {