From bf4fc5c25ec31566b0fc1ee2e5e8bc15e5512893 Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Fri, 14 Mar 2014 00:34:50 +0100 Subject: [PATCH] Add support for NIO2 IoSession Starting from version 0.9.0 Apache SSHD project added support for NIO2 IoSession. To use the new NIO2 session the `backend` option must be set to `NIO2`. By default, `NIO2`. Change-Id: I06cf92b02e80ecf9e8bfbd9f6d6d623dfe3ccff3 --- src/main/distrib/data/gitblit.properties | 5 +++++ .../com/gitblit/transport/ssh/SshDaemon.java | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/main/distrib/data/gitblit.properties b/src/main/distrib/data/gitblit.properties index 2338cc5b..64a52f5c 100644 --- a/src/main/distrib/data/gitblit.properties +++ b/src/main/distrib/data/gitblit.properties @@ -124,6 +124,11 @@ git.sshKeysManager = com.gitblit.transport.ssh.FileKeyManager # SINCE 1.5.0 git.sshKeysFolder= ${baseFolder}/ssh +# SSH backend NIO2|MINA. +# +# SINCE 1.5.0 +git.sshBackend = NIO2 + # Allow push/pull over http/https with JGit servlet. # If you do NOT want to allow Git clients to clone/push to Gitblit set this # to false. You might want to do this if you are only using ssh:// or git://. diff --git a/src/main/java/com/gitblit/transport/ssh/SshDaemon.java b/src/main/java/com/gitblit/transport/ssh/SshDaemon.java index 5bd397d7..f0429a7c 100644 --- a/src/main/java/com/gitblit/transport/ssh/SshDaemon.java +++ b/src/main/java/com/gitblit/transport/ssh/SshDaemon.java @@ -24,6 +24,12 @@ import java.util.concurrent.atomic.AtomicBoolean; import javax.inject.Singleton; import org.apache.sshd.SshServer; +import org.apache.sshd.common.io.IoServiceFactory; +import org.apache.sshd.common.io.IoServiceFactoryFactory; +import org.apache.sshd.common.io.mina.MinaServiceFactory; +import org.apache.sshd.common.io.mina.MinaServiceFactoryFactory; +import org.apache.sshd.common.io.nio2.Nio2ServiceFactory; +import org.apache.sshd.common.io.nio2.Nio2ServiceFactoryFactory; import org.apache.sshd.server.keyprovider.PEMGeneratorHostKeyProvider; import org.eclipse.jgit.internal.JGitText; import org.slf4j.Logger; @@ -59,6 +65,10 @@ public class SshDaemon { private final Logger log = LoggerFactory.getLogger(SshDaemon.class); + public static enum SshSessionBackend { + MINA, NIO2 + } + /** * 22: IANA assigned port number for ssh. Note that this is a distinct * concept from gitblit's default conf for ssh port -- this "default" is @@ -90,6 +100,14 @@ public class SshDaemon { "localhost"); IKeyManager keyManager = getKeyManager(); + + String sshBackendStr = settings.getString(Keys.git.sshBackend, + SshSessionBackend.NIO2.name()); + SshSessionBackend backend = SshSessionBackend.valueOf(sshBackendStr); + System.setProperty(IoServiceFactoryFactory.class.getName(), + backend == SshSessionBackend.MINA + ? MinaServiceFactoryFactory.class.getName() + : Nio2ServiceFactoryFactory.class.getName()); InetSocketAddress addr; if (StringUtils.isEmpty(bindInterface)) { -- 2.39.5