Enable server heartbeats
[netconf.git] / netconf / mdsal-netconf-ssh / src / main / java / org / opendaylight / netconf / ssh / SshProxyServer.java
index cf9cdb817a98efa49f5440fb0f5d3c474aa95cca..8c099fa30cb8d27149eb09da9a95dd82d5bd5a4a 100644 (file)
@@ -33,8 +33,8 @@ import org.opendaylight.netconf.shaded.sshd.common.io.IoServiceFactoryFactory;
 import org.opendaylight.netconf.shaded.sshd.common.io.nio2.Nio2Acceptor;
 import org.opendaylight.netconf.shaded.sshd.common.io.nio2.Nio2Connector;
 import org.opendaylight.netconf.shaded.sshd.common.io.nio2.Nio2ServiceFactoryFactory;
+import org.opendaylight.netconf.shaded.sshd.common.session.SessionHeartbeatController.HeartbeatType;
 import org.opendaylight.netconf.shaded.sshd.common.util.closeable.AbstractCloseable;
-import org.opendaylight.netconf.shaded.sshd.server.ServerFactoryManager;
 import org.opendaylight.netconf.shaded.sshd.server.SshServer;
 
 /**
@@ -89,10 +89,19 @@ public class SshProxyServer implements AutoCloseable {
 
         sshServer.setIoServiceFactoryFactory(nioServiceWithPoolFactoryFactory);
         sshServer.setScheduledExecutorService(minaTimerExecutor);
-        sshServer.getProperties().put(ServerFactoryManager.IDLE_TIMEOUT,
-            String.valueOf(sshProxyServerConfiguration.getIdleTimeout()));
-        sshServer.getProperties().put(ServerFactoryManager.AUTH_TIMEOUT,
-            String.valueOf(sshProxyServerConfiguration.getIdleTimeout()));
+
+        final int idleTimeout = sshProxyServerConfiguration.getIdleTimeout();
+        sshServer.getProperties().put(FactoryManager.IDLE_TIMEOUT, String.valueOf(idleTimeout));
+        final String nioReadTimeout;
+        if (idleTimeout > 0) {
+            final long heartBeat = idleTimeout * 333333L;
+            sshServer.setSessionHeartbeat(HeartbeatType.IGNORE, TimeUnit.NANOSECONDS, heartBeat);
+            nioReadTimeout = String.valueOf(idleTimeout + TimeUnit.SECONDS.toMillis(15L));
+        } else {
+            nioReadTimeout = "0";
+        }
+        sshServer.getProperties().put(FactoryManager.NIO2_READ_TIMEOUT, nioReadTimeout);
+        sshServer.getProperties().put(FactoryManager.AUTH_TIMEOUT, String.valueOf(idleTimeout));
 
         final RemoteNetconfCommand.NetconfCommandFactory netconfCommandFactory =
                 new RemoteNetconfCommand.NetconfCommandFactory(clientGroup,