Hi Everyone,
I have a question regarding mina-core/sshd-core libraries and was hoping you guys could help me since i haven't found anything online that could help me solve my problem. I'll try to be as detailed as possible. So here is my system information:
OS
PRETTY_NAME="Ubuntu 20.04.3 LTS"

JAVA
openjdk 11.0.11 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)

Mina/Sshd dependencies
"mvn:org.apache.sshd:sshd-core:jar:1.7.0"
"mvn:org.apache.mina:mina-core:jar:2.0.16"

Now, the problem:
We have a service that upon startup, starts a tcp listener and other devices will connect to it at some point. we are using org.apache.mina.transport.socket.nio.NioSocketAcceptor class as follows:
serverAcceptor = new NioSocketAcceptor();
//set logger
serverAcceptor.getFilterChain().addLast("logger", new LoggingFilter());
//set message type
serverAcceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
//set IO Handler class
serverAcceptor.setHandler(new TcpMinaServerHandler()); //our class extending IoHandlerAdapter class
serverAcceptor.getSessionConfig().setReadBufferSize(READ_BUFFER_SIZE);
serverAcceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, IDLE_SECONDS_CHECK);
//start
serverAcceptor.bind(new InetSocketAddress(PORT));

We want to look for a way to use the session opened from a client connecting to this listener and somehow handing it over/parsing it on an instance of org.apache.sshd.client.SshClient. I havent been able to find anything online but i believe this could be possible by looking at SshClient code:

SshClient client;
//set up client
client = SshClient.setUpDefaultClient();
client.start();
client.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
//Interesting session factory method
client.getSessionFactory().sessionCreated(IoSession object here); // <--- looking at the implementation for this method, see below //Seems to be kind of what we are looking to achieve. Having an already open session and handing it over to the ssh client
 public void sessionCreated(IoSession ioSession) throws Exception {
ValidateUtils.checkNotNull(this.createSession(ioSession), "No session created for %s", ioSession);
 }

My problem is i havent been able to find any way to do this online. Does anyone have any ideas/tips?
Thank you very much for any help in advance!

Reply via email to