hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1544821 - in /httpcomponents/httpcore/trunk: RELEASE_NOTES.txt httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
Date Sat, 23 Nov 2013 15:54:00 GMT
Author: olegk
Date: Sat Nov 23 15:54:00 2013
New Revision: 1544821

URL: http://svn.apache.org/r1544821
Log:
HTTPCORE-357: Avoid DNS lookups in SSLIOSessions in server mode.
Contributed by Isaac Cruz Ballesteros <icruzbal at gmail.com>

Modified:
    httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java

Modified: httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt?rev=1544821&r1=1544820&r2=1544821&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Sat Nov 23 15:54:00 2013
@@ -1,6 +1,9 @@
 Changes since 4.3
 -------------------
 
+* [HTTPCORE-357] Avoid DNS lookups in SSLIOSessions in server mode.
+  Contributed by Isaac Cruz Ballesteros <icruzbal at gmail.com>
+
 * [HTTPCORE-362] Purge pool per route map after closing out expired or idle connections with

   #closeExpired and #closeIdle methods. 
   Contributed by Oleg Kalnichevski <olegk at apache.org>

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java?rev=1544821&r1=1544820&r2=1544821&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
Sat Nov 23 15:54:00 2013
@@ -78,7 +78,6 @@ public class SSLIOSession implements IOS
     public static final String SESSION_KEY = "http.session.ssl";
 
     private final IOSession session;
-    private final SSLMode defaultMode;
     private final SSLEngine sslEngine;
     private final ByteBuffer inEncrypted;
     private final ByteBuffer outEncrypted;
@@ -91,6 +90,7 @@ public class SSLIOSession implements IOS
     private SessionBufferStatus appBufferStatus;
 
     private boolean endOfStream;
+    private volatile SSLMode sslMode;
     private volatile int status;
     private volatile boolean initialized;
 
@@ -98,20 +98,20 @@ public class SSLIOSession implements IOS
      * Creates new instance of <tt>SSLIOSession</tt> class.
      *
      * @param session I/O session to be decorated with the TLS/SSL capabilities.
-     * @param defaultMode default mode (client or server)
+     * @param sslMode SSL mode (client or server)
      * @param sslContext SSL context to use for this I/O session.
      * @param handler optional SSL setup handler. May be <code>null</code>.
      */
     public SSLIOSession(
             final IOSession session,
-            final SSLMode defaultMode,
+            final SSLMode sslMode,
             final SSLContext sslContext,
             final SSLSetupHandler handler) {
         super();
         Args.notNull(session, "IO session");
         Args.notNull(sslContext, "SSL context");
         this.session = session;
-        this.defaultMode = defaultMode;
+        this.sslMode = sslMode;
         this.appEventMask = session.getEventMask();
         this.channel = new InternalByteChannel();
         this.handler = handler;
@@ -120,10 +120,15 @@ public class SSLIOSession implements IOS
         this.session.setBufferStatus(this);
 
         final SocketAddress address = session.getRemoteAddress();
-        if (address instanceof InetSocketAddress) {
-            final String hostname = ((InetSocketAddress) address).getHostName();
-            final int port = ((InetSocketAddress) address).getPort();
-            this.sslEngine = sslContext.createSSLEngine(hostname, port);
+
+        if (this.sslMode == SSLMode.CLIENT) {
+            if (address instanceof InetSocketAddress) {
+                final String hostname = ((InetSocketAddress) address).getHostName();
+                final int port = ((InetSocketAddress) address).getPort();
+                this.sslEngine = sslContext.createSSLEngine(hostname, port);
+            } else {
+                this.sslEngine = sslContext.createSSLEngine();
+            }
         } else {
             this.sslEngine = sslContext.createSSLEngine();
         }
@@ -157,16 +162,28 @@ public class SSLIOSession implements IOS
      * if an instance of {@link SSLSetupHandler} was specified at
      * the construction time.
      *
-     * @param mode mode of operation (client or server).
+     * @deprecated (4.3) SSL mode must be set at construction time.
+     */
+    @Deprecated
+    public synchronized void initialize(final SSLMode sslMode) throws SSLException {
+        this.sslMode = sslMode;
+        initialize();
+    }
+
+    /**
+     * Initializes the session. This method invokes the {@link
+     * SSLSetupHandler#initalize(SSLEngine)} callback if an instance of
+     * {@link SSLSetupHandler} was specified at the construction time.
+     *
      * @throws SSLException in case of a SSL protocol exception.
      * @throws IllegalStateException if the session has already been initialized.
      */
-    public synchronized void initialize(final SSLMode mode) throws SSLException {
+    public synchronized void initialize() throws SSLException {
         Asserts.check(!this.initialized, "SSL I/O session already initialized");
         if (this.status >= IOSession.CLOSING) {
             return;
         }
-        switch (mode) {
+        switch (this.sslMode) {
         case CLIENT:
             this.sslEngine.setUseClientMode(true);
             break;
@@ -182,19 +199,6 @@ public class SSLIOSession implements IOS
         doHandshake();
     }
 
-    /**
-     * Initializes the session in the default operation mode. This method
-     * invokes the {@link SSLSetupHandler#initalize(SSLEngine)} callback
-     * if an instance of {@link SSLSetupHandler} was specified at
-     * the construction time.
-     *
-     * @throws SSLException in case of a SSL protocol exception.
-     * @throws IllegalStateException if the session has already been initialized.
-     */
-    public void initialize() throws SSLException {
-        initialize(this.defaultMode);
-    }
-
     public synchronized SSLSession getSSLSession() {
         return this.sslEngine.getSession();
     }



Mime
View raw message