diff --git a/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/ISshSettings.java b/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/ISshSettings.java index 8c1b7805828..4c389be56df 100644 --- a/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/ISshSettings.java +++ b/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/ISshSettings.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,18 +8,71 @@ * Contributors: * Michael Scharf (Wind River) - initial API and implementation * Martin Oberhuber (Wind River) - fixed copyright headers and beautified + * Johnson Ma (Wind River) - [218880] Add UI setting for ssh keepalives *******************************************************************************/ package org.eclipse.tm.internal.terminal.ssh; import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore; public interface ISshSettings { + /** + * Get the host name or IP address of remote system to connect. + * @return host name or IP address of the remote system. + */ String getHost(); + + /** + * Get the login name for connecting to the remote system. + * @return remote login name + */ String getUser(); + + /** + * Get the password for connecting to the remote system. + * May be empty if connecting via SSH public key authentication + * (with or without passphrase). + * @return password to use + */ String getPassword(); + + /** + * Get the timeout (in seconds) after which the SSH connection is assumed dead. + * @return timeout (in seconds) for the SSH connection. + */ int getTimeout(); + + /** + * Get the keepalive interval (in seconds). + * After this time of inactivity, the SSH connector will send a message to the + * remote system in order to avoid timeouts on the remote. A maximum of 6 + * keepalive messages will be sent if enabled. When set to 0, the keepalive + * feature is disabled. + * @return interval (in seconds) for keepalive messages. + */ + int getKeepalive(); + + /** + * Get the TCP/IP port on the remote system to use. + * @return TCP/IP port on the remote system to use. + */ int getPort(); + + /** + * Return a human-readable String summarizing all relevant connection data. + * This String can be displayed in the Terminal caption, for instance. + * @return a human-readable String summarizing relevant connection data. + */ String getSummary(); + + /** + * Load connection data from a settings store. + * @param store the settings store to access. + */ void load(ISettingsStore store); + + /** + * Store connection data into a settings store. + * @param store the settings store to access. + */ void save(ISettingsStore store); } diff --git a/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshConnection.java b/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshConnection.java index 7f347fe98ff..04c27793f29 100644 --- a/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshConnection.java +++ b/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshConnection.java @@ -13,6 +13,7 @@ * Martin Oberhuber (Wind River) - [198790] make SSH createSession() protected * Mikhail Kalugin - [201864] Fix Terminal SSH keyboard interactive authentication * Martin Oberhuber (Wind River) - [155026] Add keepalives for SSH connection + * Johnson Ma (Wind River) - [218880] Add UI setting for ssh keepalives *******************************************************************************/ package org.eclipse.tm.internal.terminal.ssh; @@ -68,7 +69,6 @@ class SshConnection extends Thread { Session session = service.createSession(hostname, port, username); //session.setTimeout(getSshTimeoutInMillis()); session.setTimeout(0); //never time out on the session - session.setServerAliveInterval(300000); //5 minutes session.setServerAliveCountMax(6); //give up after 6 tries (remote will be dead after 30 min) if (password != null) session.setPassword(password); @@ -87,6 +87,7 @@ class SshConnection extends Thread { public void run() { try { int nTimeout = fConn.getTelnetSettings().getTimeout() * 1000; + int nKeepalive = fConn.getTelnetSettings().getKeepalive() * 1000; String host = fConn.getTelnetSettings().getHost(); String user = fConn.getTelnetSettings().getUser(); String password = fConn.getTelnetSettings().getPassword(); @@ -108,6 +109,9 @@ class SshConnection extends Thread { //config.put("StrictHostKeyChecking", "no"); //session.setConfig(config); //ui.aboutToConnect(); + if (nKeepalive > 0) { + session.setServerAliveInterval(nKeepalive); //default is 5 minutes + } session.connect(nTimeout); // making connection with timeout. ChannelShell channel=(ChannelShell) session.openChannel("shell"); //$NON-NLS-1$ diff --git a/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshMessages.java b/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshMessages.java index ca912590635..d24753a17bb 100644 --- a/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshMessages.java +++ b/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshMessages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * Michael Scharf (Wind River) - initial API and implementation * Martin Oberhuber (Wind River) - fixed copyright headers and beautified + * Johnson Ma (Wind River) - [218880] Add UI setting for ssh keepalives *******************************************************************************/ package org.eclipse.tm.internal.terminal.ssh; @@ -22,6 +23,8 @@ public class SshMessages extends NLS { public static String PORT; public static String PASSWORD; public static String TIMEOUT; + public static String KEEPALIVE; + public static String KEEPALIVE_Tooltip; public static String WARNING; public static String INFO; diff --git a/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshMessages.properties b/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshMessages.properties index b3e54267791..b2f0806a9a3 100644 --- a/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshMessages.properties +++ b/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshMessages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2006, 2007 Wind River Systems, Inc. and others. +# Copyright (c) 2006, 2008 Wind River Systems, Inc. and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -8,12 +8,15 @@ # Contributors: # Michael Scharf (Wind River) - initial API and implementation # Martin Oberhuber (Wind River) - fixed copyright headers and beautified +# Johnson Ma (Wind River) - [218880] Add UI setting for ssh keepalives ############################################################################### HOST = Host USER = User PORT = Port PASSWORD = Password TIMEOUT = Timeout (sec) +KEEPALIVE = KeepAlive (sec) +KEEPALIVE_Tooltip=Interval for sending keepalive messages in case of inactivity. Enter 0 to disable keepalives. WARNING = Warning INFO = Info diff --git a/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshSettings.java b/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshSettings.java index 45c469dff73..3aa99536803 100644 --- a/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshSettings.java +++ b/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshSettings.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * Michael Scharf (Wind River) - initial API and implementation * Martin Oberhuber (Wind River) - fixed copyright headers and beautified * Mikhail Kalugin - [201867] Improve Terminal SSH connection summary string + * Johnson Ma (Wind River) - [218880] Add UI setting for ssh keepalives *******************************************************************************/ package org.eclipse.tm.internal.terminal.ssh; @@ -20,6 +21,7 @@ public class SshSettings implements ISshSettings { protected String fPassword; protected String fPort; protected String fTimeout; + protected String fKeepalive; public String getHost() { return fHost; } @@ -41,6 +43,7 @@ public class SshSettings implements ISshSettings { fUser = store.get("User");//$NON-NLS-1$ fPort = store.get("Port");//$NON-NLS-1$ fTimeout = store.get("Timeout");//$NON-NLS-1$ + fKeepalive = store.get("Keepalive");//$NON-NLS-1$ } @@ -49,6 +52,7 @@ public class SshSettings implements ISshSettings { store.put("User", fUser);//$NON-NLS-1$ store.put("Port", fPort);//$NON-NLS-1$ store.put("Timeout", fTimeout);//$NON-NLS-1$ + store.put("Keepalive", fKeepalive);//$NON-NLS-1$ } @@ -66,6 +70,21 @@ public class SshSettings implements ISshSettings { public void setTimeout(String timeout) { fTimeout = timeout; } + + public int getKeepalive() { + try { + return Integer.parseInt(fKeepalive); + } catch (NumberFormatException numberFormatException) { + return 300; + } + } + public String getKeepaliveString() { + return fKeepalive; + } + + public void setKeepalive(String keepalive) { + fKeepalive = keepalive; + } public String getUser() { return fUser; diff --git a/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshSettingsPage.java b/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshSettingsPage.java index 5ae8292f4a1..35d6b800bb5 100644 --- a/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshSettingsPage.java +++ b/org.eclipse.tm.terminal.ssh/src/org/eclipse/tm/internal/terminal/ssh/SshSettingsPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * Michael Scharf (Wind River) - initial API and implementation * Martin Oberhuber (Wind River) - fixed copyright headers and beautified + * Johnson Ma (Wind River) - [218880] Add UI setting for ssh keepalives *******************************************************************************/ package org.eclipse.tm.internal.terminal.ssh; @@ -23,6 +24,7 @@ public class SshSettingsPage implements ISettingsPage { private Text fHostText; private Text fUser; private Text fTimeout; + private Text fKeepalive; private final SshSettings fTerminalSettings; private Text fPort; private Text fPassword; @@ -36,12 +38,14 @@ public class SshSettingsPage implements ISettingsPage { fTerminalSettings.setPassword(fPassword.getText()); fTerminalSettings.setPort(fPort.getText()); fTerminalSettings.setTimeout(fTimeout.getText()); + fTerminalSettings.setKeepalive(fKeepalive.getText()); } public void loadSettings() { if(fTerminalSettings!=null) { fHostText.setText(get(fTerminalSettings.getHost(),""));//$NON-NLS-1$ fTimeout.setText(get(fTerminalSettings.getTimeoutString(),"0"));//$NON-NLS-1$ + fKeepalive.setText(get(fTerminalSettings.getKeepaliveString(),"300"));//$NON-NLS-1$ fUser.setText(get(fTerminalSettings.getUser(),""));//$NON-NLS-1$ fPort.setText(get(fTerminalSettings.getPortString(),"22"));//$NON-NLS-1$ fPassword.setText(get(fTerminalSettings.getPassword(),""));//$NON-NLS-1$ @@ -67,6 +71,8 @@ public class SshSettingsPage implements ISettingsPage { fUser = createTextField(composite, SshMessages.USER); fPassword = createTextField(composite, SshMessages.PASSWORD,SWT.PASSWORD); fTimeout = createTextField(composite, SshMessages.TIMEOUT); + fKeepalive = createTextField(composite, SshMessages.KEEPALIVE); + fKeepalive.setToolTipText(SshMessages.KEEPALIVE_Tooltip); fPort = createTextField(composite, SshMessages.PORT); loadSettings(); }