directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r326637 - in /directory/network/trunk/src/java/org/apache/mina/filter: SSLFilter.java support/SSLHandler.java
Date Wed, 19 Oct 2005 18:37:31 GMT
Author: trustin
Date: Wed Oct 19 11:37:28 2005
New Revision: 326637

URL: http://svn.apache.org/viewcvs?rev=326637&view=rev
Log:
Related issue: DIRMINA-106 - Add TLS closure support to SSLFilter
* Implemented filterClose() so that close_notify is sent before closing the connection.
* TODO: Provide a way to exchange close_notify in the middle of connection.

Modified:
    directory/network/trunk/src/java/org/apache/mina/filter/SSLFilter.java
    directory/network/trunk/src/java/org/apache/mina/filter/support/SSLHandler.java

Modified: directory/network/trunk/src/java/org/apache/mina/filter/SSLFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/filter/SSLFilter.java?rev=326637&r1=326636&r2=326637&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/SSLFilter.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/filter/SSLFilter.java Wed Oct 19 11:37:28
2005
@@ -26,8 +26,10 @@
 
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.ByteBufferProxy;
+import org.apache.mina.common.CloseFuture;
 import org.apache.mina.common.IoFilterAdapter;
 import org.apache.mina.common.IoSession;
+import org.apache.mina.common.WriteFuture;
 import org.apache.mina.filter.support.SSLHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -241,24 +243,17 @@
         {
             synchronized( sslHandler )
             {
-               // Start SSL shutdown process
-               try
-               {
-                  // shut down
-                  sslHandler.shutdown();
-                  
-                  // there might be data to write out here?
-                  sslHandler.writeNetBuffer( nextFilter, session );
-               }
-               finally
-               {
-                  // notify closed session
-                  nextFilter.sessionClosed( session );
-                  
-                  // release buffers
-                  sslHandler.release();
-                  removeSSLSessionHandler( session );
-               }
+                // release resources
+                removeSSLSessionHandler( session );
+                try
+                {
+                    sslHandler.release();
+                }
+                finally
+                {
+                   // notify closed session
+                   nextFilter.sessionClosed( session );
+                }
             }
         }
     }
@@ -403,6 +398,52 @@
             }
         }
     }
+    
+    public void filterClose( NextFilter nextFilter, IoSession session, CloseFuture closeFuture
) throws SSLException
+    {
+        try
+        {
+            initiateClosure( nextFilter, session );
+        }
+        finally
+        {
+            nextFilter.filterClose( session, closeFuture );
+        }
+    }
+    
+    private void initiateClosure( NextFilter nextFilter, IoSession session ) throws SSLException
+    {
+        SSLHandler handler = getSSLSessionHandler( session );
+        if( handler == null )
+        {
+            return;
+        }
+        
+        WriteFuture future;
+        try
+        {
+            synchronized( handler )
+            {
+                // shut down
+                handler.shutdown();
+                
+                // there might be data to write out here?
+                future = handler.writeNetBuffer( nextFilter, session );
+                
+                // release buffers
+                handler.release();
+            }
+            
+            if( future != null )
+            {
+                future.join();
+            }
+        }
+        finally
+        {
+            removeSSLSessionHandler( session );
+        }
+    }
 
     // Utiliities
 
@@ -481,9 +522,9 @@
         return ( SSLHandler ) session.getAttribute( SSL_HANDLER );
     }
 
-    private void removeSSLSessionHandler( IoSession session )
+    private SSLHandler removeSSLSessionHandler( IoSession session )
     {
-        session.removeAttribute( SSL_HANDLER );
+        return ( SSLHandler ) session.removeAttribute( SSL_HANDLER );
     }
 
     private static class EncryptedBuffer extends ByteBufferProxy

Modified: directory/network/trunk/src/java/org/apache/mina/filter/support/SSLHandler.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/filter/support/SSLHandler.java?rev=326637&r1=326636&r2=326637&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/support/SSLHandler.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/filter/support/SSLHandler.java Wed Oct
19 11:37:28 2005
@@ -28,6 +28,7 @@
 import javax.net.ssl.SSLSession;
 
 import org.apache.mina.common.IoSession;
+import org.apache.mina.common.WriteFuture;
 import org.apache.mina.common.IoFilter.NextFilter;
 import org.apache.mina.common.IoFilter.WriteRequest;
 import org.apache.mina.filter.SSLFilter;
@@ -487,19 +488,21 @@
         }
     }
 
-    public void writeNetBuffer( NextFilter nextFilter, IoSession session ) throws SSLException
+    public WriteFuture writeNetBuffer( NextFilter nextFilter, IoSession session ) throws
SSLException
     {
         // Check if any net data needed to be writen
         if( !getOutNetBuffer().hasRemaining() )
         {
             // no; bail out
-            return;
+            return null;
         }
         
+        WriteFuture writeFuture = null;
+        
         // write net data
         
         // set flag that we are writing encrypted data
-        // (used in filterWrite() above)
+        // (used in SSLFilter.filterWrite())
         synchronized( this )
         {
             setWritingEncryptedData( true );
@@ -518,8 +521,9 @@
             }
             //debug("outNetBuffer (after copy): {0}", sslHandler.getOutNetBuffer());
             
-            parent.filterWrite( nextFilter, session, new WriteRequest( writeBuffer, null
) );
-        
+            writeFuture = new WriteFuture();
+            parent.filterWrite( nextFilter, session, new WriteRequest( writeBuffer, writeFuture
) );
+
             // loop while more writes required to complete handshake
             while( needToCompleteInitialHandshake() )
             {
@@ -541,7 +545,8 @@
                         log.debug( session + " write outNetBuffer2: " + getOutNetBuffer()
);
                     }
                     org.apache.mina.common.ByteBuffer writeBuffer2 = copy( getOutNetBuffer()
);
-                    session.write( writeBuffer2 );
+                    writeFuture = new WriteFuture();
+                    parent.filterWrite( nextFilter, session, new WriteRequest( writeBuffer2,
writeFuture ) );
                 }
             }
         }
@@ -552,6 +557,8 @@
                 setWritingEncryptedData( false );
             }
         }
+        
+        return writeFuture;
     }
     
     



Mime
View raw message