changeset 319:776a220dbcc6 ganymed

add ecdsa key support everywhere
author Carl Byington <carl@five-ten-sg.com>
date Thu, 31 Jul 2014 08:20:47 -0700
parents 5351641c8a46
children 5afb8c1a54b9
files src/ch/ethz/ssh2/Connection.java src/ch/ethz/ssh2/transport/TransportManager.java
diffstat 2 files changed, 41 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/src/ch/ethz/ssh2/Connection.java	Wed Jul 30 17:46:06 2014 -0700
+++ b/src/ch/ethz/ssh2/Connection.java	Thu Jul 31 08:20:47 2014 -0700
@@ -670,27 +670,17 @@
      */
 
     public void close() {
+        Throwable t = new Throwable("Closed due to user request.");
+        close(t, false);
+    }
+
+    public void close(Throwable t, boolean hard) {
         if (cm != null) {
             cm.closeAllChannels();
         }
 
         if (tm != null) {
-            tm.close();
-            tm = null;
-        }
-
-        am = null;
-        cm = null;
-        authenticated = false;
-    }
-
-    public synchronized void close(IOException t) {
-        if (cm != null) {
-            cm.closeAllChannels();
-        }
-
-        if (tm != null) {
-            tm.close(t);
+            tm.close(t, hard == false);
             tm = null;
         }
 
@@ -827,7 +817,7 @@
                             }
 
                             state.timeoutSocketClosed = true;
-                            tm.close(new SocketTimeoutException("The connect timeout expired"));
+                            tm.close(new SocketTimeoutException("The connect timeout expired"), false);
                         }
                     }
                 };
--- a/src/ch/ethz/ssh2/transport/TransportManager.java	Wed Jul 30 17:46:06 2014 -0700
+++ b/src/ch/ethz/ssh2/transport/TransportManager.java	Thu Jul 31 08:20:47 2014 -0700
@@ -162,30 +162,47 @@
         return km.sessionId;
     }
 
-    public void close() {
-        // It is safe now to acquire the semaphore.
+    public void close(Throwable cause, boolean useDisconnectPacket) {
+        if (useDisconnectPacket == false) {
+            // OK, hard shutdown - do not acquire the semaphore,
+            // perhaps somebody is inside (and waits until
+            // the remote side is ready to accept new data).
+            try {
+                socket.close();
+            }
+            catch (IOException ignore) {
+            }
+            // OK, whoever tried to send data, should now agree that
+            // there is no point in further waiting =)
+            // It is safe now to acquire the semaphore.
+        }
+
         synchronized (connectionSemaphore) {
             if (!connectionClosed) {
-                try {
-                    tc.sendMessage(new PacketDisconnect(
-                                       PacketDisconnect.Reason.SSH_DISCONNECT_BY_APPLICATION, "").getPayload());
-                }
-                catch (IOException ignore) {
-                    //
-                }
+                if (useDisconnectPacket == true) {
+                    try {
+                        if (tc != null)
+                            tc.sendMessage(new PacketDisconnect(PacketDisconnect.Reason.SSH_DISCONNECT_BY_APPLICATION, "").getPayload());
+                    }
+                    catch (IOException ignore) {
+                    }
 
-                try {
-                    socket.close();
-                }
-                catch (IOException ignore) {
-                    //
-                }
+                    try {
+                        socket.close();
+                    }
+                    catch (IOException ignore) {
+                    }
 
-                connectionClosed = true;
+                    connectionClosed = true;
+                    reasonClosedCause = cause;
 
                 synchronized (this) {
                     for (ConnectionMonitor cmon : connectionMonitors) {
-                        cmon.connectionLost(reasonClosedCause);
+                        try {
+                            cmon.connectionLost(reasonClosedCause);
+                        }
+                        catch (Exception ignore) {
+                        }
                     }
                 }
             }
@@ -194,29 +211,6 @@
         }
     }
 
-    public void close(IOException cause) {
-        // Do not acquire the semaphore, perhaps somebody is inside (and waits until
-        // the remote side is ready to accept new data
-        try {
-            socket.close();
-        }
-        catch (IOException ignore) {
-        }
-
-        // It is safe now to acquire the semaphore.
-        synchronized (connectionSemaphore) {
-            connectionClosed = true;
-            reasonClosedCause = cause;
-            connectionSemaphore.notifyAll();
-        }
-
-        synchronized (this) {
-            for (ConnectionMonitor cmon : connectionMonitors) {
-                cmon.connectionLost(reasonClosedCause);
-            }
-        }
-    }
-
     protected void startReceiver() throws IOException {
         final Thread receiveThread = new Thread(new Runnable() {
             public void run() {