From: Robert Varga Date: Thu, 21 Sep 2023 02:53:52 +0000 (+0200) Subject: Bind SshClient/SshServer to NettyIoServiceFactoryFactory X-Git-Tag: v7.0.0~521 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=2a9984350c87c388b64115f66f563d5217122273;p=netconf.git Bind SshClient/SshServer to NettyIoServiceFactoryFactory 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 --- diff --git a/transport/transport-ssh/src/main/java/org/opendaylight/netconf/transport/ssh/SSHClient.java b/transport/transport-ssh/src/main/java/org/opendaylight/netconf/transport/ssh/SSHClient.java index 0172c85237..7bfc12a298 100644 --- a/transport/transport-ssh/src/main/java/org/opendaylight/netconf/transport/ssh/SSHClient.java +++ b/transport/transport-ssh/src/main/java/org/opendaylight/netconf/transport/ssh/SSHClient.java @@ -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()) diff --git a/transport/transport-ssh/src/main/java/org/opendaylight/netconf/transport/ssh/SSHServer.java b/transport/transport-ssh/src/main/java/org/opendaylight/netconf/transport/ssh/SSHServer.java index 3dc4361ac5..e1a7268e2b 100644 --- a/transport/transport-ssh/src/main/java/org/opendaylight/netconf/transport/ssh/SSHServer.java +++ b/transport/transport-ssh/src/main/java/org/opendaylight/netconf/transport/ssh/SSHServer.java @@ -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()); diff --git a/transport/transport-ssh/src/main/java/org/opendaylight/netconf/transport/ssh/SSHTransportStackFactory.java b/transport/transport-ssh/src/main/java/org/opendaylight/netconf/transport/ssh/SSHTransportStackFactory.java index d6a24cb3d1..907cd970fa 100644 --- a/transport/transport-ssh/src/main/java/org/opendaylight/netconf/transport/ssh/SSHTransportStackFactory.java +++ b/transport/transport-ssh/src/main/java/org/opendaylight/netconf/transport/ssh/SSHTransportStackFactory.java @@ -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 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 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 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); } diff --git a/transport/transport-ssh/src/main/java/org/opendaylight/netconf/transport/ssh/TransportSshClient.java b/transport/transport-ssh/src/main/java/org/opendaylight/netconf/transport/ssh/TransportSshClient.java index 9b680f8cb9..ce74da3cd7 100644 --- a/transport/transport-ssh/src/main/java/org/opendaylight/netconf/transport/ssh/TransportSshClient.java +++ b/transport/transport-ssh/src/main/java/org/opendaylight/netconf/transport/ssh/TransportSshClient.java @@ -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 { diff --git a/transport/transport-ssh/src/main/java/org/opendaylight/netconf/transport/ssh/TransportSshServer.java b/transport/transport-ssh/src/main/java/org/opendaylight/netconf/transport/ssh/TransportSshServer.java index 20378fd610..dfa6455c78 100644 --- a/transport/transport-ssh/src/main/java/org/opendaylight/netconf/transport/ssh/TransportSshServer.java +++ b/transport/transport-ssh/src/main/java/org/opendaylight/netconf/transport/ssh/TransportSshServer.java @@ -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) {