an improvement on 'Internal SSH' support for 'ext' connection.
"Atsuhiko Yamanaka" <[email protected]> Mon, 27 Feb 2006 18:51:36 +0900
| Newsgroups | gmane.comp.java.netbeans.modules.javacvs.devel |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_625_15436405.1141033896523
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
Hi developers,
Here is a patch to improve the response time in using 'Internal SSH'
for 'ext' connection type.
In the current implementation, for each remote executions 'cvs server',
ssh connections have been established, and you know that the establishment =
of
ssh connection will take much of CPU time and memories for DH key exchangin=
g.
In the attached patch, an established ssh connection will be reused to save
computer resources. Please try it.
PS. Do you have a plan to support public-key authentication? If you have,
I'll write you a patch for it.
Sincerely,
--
Atsuhiko Yamanaka
JCraft,Inc.
14-20 HONCHO 1-CHOME AOBA-KU,
SENDAI, MIYAGI 980-0014 Japan.
Tel +81-22-723-2150
+1-415-578-3454
Fax +81-22-224-8773
Skype callto://jcraft/
------=_Part_625_15436405.1141033896523
Content-Type: text/plain; name=SSHConnection.java.1.7.patch;
charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Attachment-Id: f_ek6lw9lh
Content-Disposition: attachment; filename="SSHConnection.java.1.7.patch"
# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: C:\Documents and Settings\ymnk\nb_all\javacvs\cvsmodule\src\org\netbeans\modules\versioning\system\cvss
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: SSHConnection.java
*** C:\Documents and Settings\ymnk\nb_all\javacvs\cvsmodule\src\org\netbeans\modules\versioning\system\cvss\SSHConnection.java Base (1.7)
--- C:\Documents and Settings\ymnk\nb_all\javacvs\cvsmodule\src\org\netbeans\modules\versioning\system\cvss\SSHConnection.java Locally Modified (Based On 1.7)
***************
*** 44,50 ****
private final String username;
private final String password;
! private Session session;
private ChannelExec channel;
/**
--- 44,51 ----
private final String username;
private final String password;
! private JSch jsch;
! private static Hashtable session_pool=new Hashtable();
private ChannelExec channel;
/**
***************
*** 62,86 ****
this.port = port;
this.username = username != null ? username : System.getProperty("user.name"); // NOI18N
this.password = password;
}
public void open() throws AuthenticationException, CommandAbortedException {
- Properties props = new Properties();
- props.put("StrictHostKeyChecking", "no"); // NOI18N
-
- JSch jsch = new JSch();
try {
- session = jsch.getSession(username, host, port);
- session.setSocketFactory(new SocketFactoryBridge());
- session.setConfig(props);
- session.setUserInfo(new SSHUserInfo());
- session.connect();
- } catch (JSchException e) {
- throw new AuthenticationException(e, NbBundle.getMessage(SSHConnection.class, "BK3001"));
- }
-
- try {
channel = (ChannelExec) session.openChannel("exec"); // NOI18N
channel.setCommand(CVS_SERVER_COMMAND);
setInputStream(new LoggedDataInputStream(new SshChannelInputStream(channel)));
--- 63,78 ----
this.port = port;
this.username = username != null ? username : System.getProperty("user.name"); // NOI18N
this.password = password;
+ jsch = new JSch();
}
public void open() throws AuthenticationException, CommandAbortedException {
+ Session session=getSession();
try {
channel = (ChannelExec) session.openChannel("exec"); // NOI18N
channel.setCommand(CVS_SERVER_COMMAND);
***************
*** 122,128 ****
}
private void reset() {
- session = null;
channel = null;
setInputStream(null);
setOutputStream(null);
--- 111,116 ----
***************
*** 130,136 ****
public void close() throws IOException {
if (channel != null) channel.disconnect();
- if (session != null) session.disconnect();
reset();
}
--- 118,123 ----
***************
*** 228,234 ****
--- 215,249 ----
if (exitStatus == 0 || channel.isEOF()) throw new EOFException(NbBundle.getMessage(SSHConnection.class, "BK3007"));
}
}
+
+ private Session getSession() throws AuthenticationException{
+ String key=username+":"+host+":"+port;
+ Session session=null;
+ synchronized(session_pool){
+ session=(Session) session_pool.get(key);
+ if(session!=null && !session.isConnected()){
+ session_pool.remove(key);
+ session=null;
}
+ if(session==null){
+ Properties props = new Properties();
+ props.put("StrictHostKeyChecking", "no"); // NOI18N
+ try {
+ session = jsch.getSession(username, host, port);
+ session.setSocketFactory(new SocketFactoryBridge());
+ session.setConfig(props);
+ session.setUserInfo(new SSHUserInfo());
+ session.connect();
+ } catch (JSchException e) {
+ throw new AuthenticationException(e, NbBundle.getMessage(SSHConnection.class, "BK3001"));
+ }
+ }
+ session_pool.put(key, session);
+ }
+ return session;
+ }
+ }
------=_Part_625_15436405.1141033896523
Content-Type: text/plain; charset=us-ascii
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
------=_Part_625_15436405.1141033896523--