ffdb8aed84b9a82514a638cf7fd1d70b7e6a9e74
[netconf.git] / transport / transport-ssh / src / main / java / org / opendaylight / netconf / transport / ssh / SSHServer.java
1 /*
2  * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.netconf.transport.ssh;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import io.netty.bootstrap.Bootstrap;
12 import io.netty.bootstrap.ServerBootstrap;
13 import io.netty.channel.EventLoopGroup;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.netconf.shaded.sshd.netty.NettyIoServiceFactoryFactory;
16 import org.opendaylight.netconf.shaded.sshd.server.subsystem.SubsystemFactory;
17 import org.opendaylight.netconf.transport.api.TransportChannelListener;
18 import org.opendaylight.netconf.transport.api.TransportStack;
19 import org.opendaylight.netconf.transport.api.UnsupportedConfigurationException;
20 import org.opendaylight.netconf.transport.tcp.TCPClient;
21 import org.opendaylight.netconf.transport.tcp.TCPServer;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ssh.server.rev230417.SshServerGrouping;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.tcp.client.rev230417.TcpClientGrouping;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.tcp.server.rev230417.TcpServerGrouping;
25
26 /**
27  * A {@link TransportStack} acting as an SSH server.
28  */
29 public final class SSHServer extends SSHTransportStack {
30     private SSHServer(final TransportChannelListener listener, final TransportSshServer sshServer) {
31         super(listener, sshServer, sshServer.getSessionFactory());
32     }
33
34     static SSHServer of(final NettyIoServiceFactoryFactory ioServiceFactory, final EventLoopGroup group,
35             final TransportChannelListener listener, final SubsystemFactory subsystemFactory,
36             final SshServerGrouping serverParams, final ServerFactoryManagerConfigurator configurator)
37                 throws UnsupportedConfigurationException {
38         return new SSHServer(listener, new TransportSshServer.Builder(ioServiceFactory, group, subsystemFactory)
39             .serverParams(serverParams)
40             .configurator(configurator)
41             .buildChecked());
42     }
43
44     @NonNull ListenableFuture<SSHServer> connect(final Bootstrap bootstrap, final TcpClientGrouping connectParams)
45             throws UnsupportedConfigurationException {
46         return transformUnderlay(this, TCPClient.connect(asListener(), bootstrap, connectParams));
47     }
48
49     @NonNull ListenableFuture<SSHServer> listen(final ServerBootstrap bootstrap, final TcpServerGrouping connectParams)
50             throws UnsupportedConfigurationException {
51         return transformUnderlay(this, TCPServer.listen(asListener(), bootstrap, connectParams));
52     }
53 }