Fix of ovsdb conneciton listener 46/15346/2
authorHsin-Yi Shen <syshen66@gmail.com>
Mon, 16 Feb 2015 02:39:35 +0000 (18:39 -0800)
committerSam Hague <shague@redhat.com>
Wed, 18 Feb 2015 14:24:07 +0000 (14:24 +0000)
For ssl connection, the notification of connected event to listeners should happen after ssl handshake is complete.

Signed-off-by: Hsin-Yi Shen <syshen66@gmail.com>
library/src/main/java/org/opendaylight/ovsdb/lib/impl/OvsdbConnectionService.java

index fe279abba8bfdcbd0bdede2d509d5bf09233dc8b..17df805dabf1c908f8c334e181c29be9182f09ec 100644 (file)
@@ -277,6 +277,30 @@ public class OvsdbConnectionService implements OvsdbConnection {
             @Override
             public void run() {
                 OvsdbClient client = getChannelClient(channel, ConnectionType.PASSIVE, Executors.newFixedThreadPool(NUM_THREADS));
+
+                SslHandler sslHandler = (SslHandler) channel.pipeline().get("ssl");
+                if (sslHandler != null) {
+                    //Wait until ssl handshake is complete
+                    int count = 0;
+                    logger.debug("Check if ssl handshake is done");
+                    while (sslHandler.engine().getSession().getCipherSuite()
+                                            .equals("SSL_NULL_WITH_NULL_NULL")
+                                            && count < 10) {
+                        try {
+                            Thread.sleep(100);
+                        } catch (InterruptedException e) {
+                            logger.error("Exception : {}", e.toString());
+                            e.printStackTrace();
+                        }
+                        count++;
+                    }
+                    if (sslHandler.engine().getSession().getCipherSuite()
+                                           .equals("SSL_NULL_WITH_NULL_NULL")) {
+                        logger.debug("Ssl hanshake is not compelete yet");
+                        return;
+                    }
+                }
+                logger.debug("Notify listener");
                 for (OvsdbConnectionListener listener : connectionListeners) {
                     listener.connected(client);
                 }