qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From astitc...@apache.org
Subject svn commit: r1478398 - in /qpid/trunk/qpid/cpp/src/qpid: broker/Broker.cpp broker/Broker.h sys/SslPlugin.cpp sys/TCPIOPlugin.cpp
Date Thu, 02 May 2013 14:59:33 GMT
Author: astitcher
Date: Thu May  2 14:59:32 2013
New Revision: 1478398

URL: http://svn.apache.org/r1478398
Log:
QPID-4807: Add new broker option to disable listening on specific transport type

Modified:
    qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp
    qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h
    qpid/trunk/qpid/cpp/src/qpid/sys/SslPlugin.cpp
    qpid/trunk/qpid/cpp/src/qpid/sys/TCPIOPlugin.cpp

Modified: qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp?rev=1478398&r1=1478397&r2=1478398&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp Thu May  2 14:59:32 2013
@@ -162,6 +162,7 @@ Broker::Options::Options(const std::stri
         ("no-data-dir", optValue(noDataDir), "Don't use a data directory.  No persistent
configuration will be loaded or stored")
         ("port,p", optValue(port,"PORT"), "Tells the broker to listen on PORT")
         ("interface", optValue(listenInterfaces, "<interface name>|<interface address>"),
"Which network interfaces to use to listen for incoming connections")
+        ("listen-disable", optValue(listenDisabled, "<transport name>"), "Transports
to disable listening")
         ("worker-threads", optValue(workerThreads, "N"), "Sets the broker thread pool size")
         ("connection-backlog", optValue(connectionBacklog, "N"), "Sets the connection backlog
limit for the server socket")
         ("mgmt-enable,m", optValue(enableMgmt,"yes|no"), "Enable Management")
@@ -208,6 +209,7 @@ Broker::Broker(const Broker::Options& co
     managementAgent(conf.enableMgmt ? new ManagementAgent(conf.qmf1Support,
                                                           conf.qmf2Support)
                                     : 0),
+    disabledListeningTransports(config.listenDisabled.begin(), config.listenDisabled.end()),
     store(new NullMessageStore),
     acl(0),
     dataDir(conf.noDataDir ? std::string() : conf.dataDir),
@@ -1060,13 +1062,28 @@ uint16_t Broker::getPort(const std::stri
     }
 }
 
+bool Broker::shouldListen(std::string transport) {
+    return disabledListeningTransports.count(transport)==0;
+}
+
+void Broker::disableListening(std::string transport) {
+    disabledListeningTransports.insert(transport);
+}
+
 void Broker::registerTransport(const std::string& name, boost::shared_ptr<TransportAcceptor>
a, boost::shared_ptr<TransportConnector> c, uint16_t p) {
     transportMap[name] = TransportInfo(a, c, p);
 }
 
 void Broker::accept() {
+    unsigned accepting = 0;
     for (TransportMap::const_iterator i = transportMap.begin(); i != transportMap.end();
i++) {
-        if (i->second.acceptor) i->second.acceptor->accept(poller, factory.get());
+        if (i->second.acceptor) {
+            i->second.acceptor->accept(poller, factory.get());
+            ++accepting;
+        }
+    }
+    if ( accepting==0 ) {
+        throw Exception(QPID_MSG("Failed to start broker: No transports are listening for
incoming connections"));
     }
 }
 

Modified: qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h?rev=1478398&r1=1478397&r2=1478398&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h Thu May  2 14:59:32 2013
@@ -94,6 +94,7 @@ class Broker : public sys::Runnable, pub
         std::string dataDir;
         uint16_t port;
         std::vector<std::string> listenInterfaces;
+        std::vector<std::string> listenDisabled;
         int workerThreads;
         int connectionBacklog;
         bool enableMgmt;
@@ -168,6 +169,7 @@ class Broker : public sys::Runnable, pub
     std::auto_ptr<sys::Timer> timer;
     Options config;
     std::auto_ptr<management::ManagementAgent> managementAgent;
+    std::set<std::string> disabledListeningTransports;
     TransportMap transportMap;
     std::auto_ptr<MessageStore> store;
     AclModule* acl;
@@ -247,6 +249,12 @@ class Broker : public sys::Runnable, pub
     QPID_BROKER_EXTERN management::Manageable::status_t ManagementMethod(
         uint32_t methodId, management::Args& args, std::string& text);
 
+    // Should we listen using this protocol or not?
+    QPID_BROKER_EXTERN bool shouldListen(std::string transport);
+
+    // Turn off listening for a protocol
+    QPID_BROKER_EXTERN void disableListening(std::string transport);
+
     /** Add to the broker's protocolFactorys */
     QPID_BROKER_EXTERN void registerTransport(
         const std::string& name,

Modified: qpid/trunk/qpid/cpp/src/qpid/sys/SslPlugin.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/SslPlugin.cpp?rev=1478398&r1=1478397&r2=1478398&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/sys/SslPlugin.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/sys/SslPlugin.cpp Thu May  2 14:59:32 2013
@@ -43,12 +43,10 @@ struct SslServerOptions : ssl::SslOption
     uint16_t port;
     bool clientAuth;
     bool nodict;
-    bool multiplex;
 
     SslServerOptions() : port(5671),
                          clientAuth(false),
-                         nodict(false),
-                         multiplex(false)
+                         nodict(false)
     {
         addOptions()
             ("ssl-port", optValue(port, "PORT"), "Port on which to listen for SSL connections")
@@ -78,10 +76,11 @@ namespace {
 static struct SslPlugin : public Plugin {
     SslServerOptions options;
     bool nssInitialized;
+    bool multiplex;
 
     Options* getOptions() { return &options; }
 
-    SslPlugin() : nssInitialized(false) {}
+    SslPlugin() : nssInitialized(false), multiplex(false) {}
     ~SslPlugin() { if (nssInitialized) ssl::shutdownNSS(); }
 
     void earlyInitialize(Target& target) {
@@ -90,14 +89,11 @@ static struct SslPlugin : public Plugin 
             broker::Broker::Options& opts = broker->getOptions();
 
             if (opts.port == options.port && // AMQP & AMQPS ports are the same
-                opts.port != 0) {
-                // The presence of this option is used to signal to the TCP
-                // plugin not to start listening on the shared port. The actual
-                // value cannot be configured through the command line or config
-                // file (other than by setting the ports to the same value)
-                // because we are only adding it after option parsing.
-                options.multiplex = true;
-                options.addOptions()("ssl-multiplex", optValue(options.multiplex), "Allow
SSL and non-SSL connections on the same port");
+                opts.port != 0 &&
+                broker->shouldListen("tcp")&&
+                broker->shouldListen("ssl")) {
+                multiplex = true;
+                broker->disableListening("tcp");
             }
         }
     }
@@ -115,21 +111,23 @@ static struct SslPlugin : public Plugin 
                     nssInitialized = true;
 
                     const broker::Broker::Options& opts = broker->getOptions();
+                    uint16_t port = options.port;
                     TransportAcceptor::shared_ptr ta;
-                    SocketAcceptor* sa =
-                        new SocketAcceptor(opts.tcpNoDelay, options.nodict, opts.maxNegotiateTime,
broker->getTimer());
-                    uint16_t port = sa->listen(opts.listenInterfaces, boost::lexical_cast<std::string>(options.port),
opts.connectionBacklog,
-                                               options.multiplex ?
-                                                 boost::bind(&createServerSSLMuxSocket,
options) :
-                                                 boost::bind(&createServerSSLSocket,
options));
-                    if ( port!=0 ) {
-                        ta.reset(sa);
-                        QPID_LOG(notice, "Listening for " <<
-                                        (options.multiplex ? "SSL or TCP" : "SSL") <<
-                                        " connections on TCP/TCP6 port " <<
-                                        port);
+                    if (broker->shouldListen("ssl")) {
+                        SocketAcceptor* sa =
+                            new SocketAcceptor(opts.tcpNoDelay, options.nodict, opts.maxNegotiateTime,
broker->getTimer());
+                            port = sa->listen(opts.listenInterfaces, boost::lexical_cast<std::string>(options.port),
opts.connectionBacklog,
+                                                multiplex ?
+                                                    boost::bind(&createServerSSLMuxSocket,
options) :
+                                                    boost::bind(&createServerSSLSocket,
options));
+                        if ( port!=0 ) {
+                            ta.reset(sa);
+                            QPID_LOG(notice, "Listening for " <<
+                                            (multiplex ? "SSL or TCP" : "SSL") <<
+                                            " connections on TCP/TCP6 port " <<
+                                            port);
+                        }
                     }
-
                     TransportConnector::shared_ptr tc(
                         new SocketConnector(opts.tcpNoDelay, options.nodict, opts.maxNegotiateTime,
broker->getTimer(),
                                             &createClientSSLSocket));

Modified: qpid/trunk/qpid/cpp/src/qpid/sys/TCPIOPlugin.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/TCPIOPlugin.cpp?rev=1478398&r1=1478397&r2=1478398&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/sys/TCPIOPlugin.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/sys/TCPIOPlugin.cpp Thu May  2 14:59:32 2013
@@ -31,20 +31,6 @@
 namespace qpid {
 namespace sys {
 
-static bool sslMultiplexEnabled(void)
-{
-    Options o;
-    Plugin::addOptions(o);
-
-    if (o.find_nothrow("ssl-multiplex", false)) {
-        // This option is added by the SSL plugin when the SSL port
-        // is configured to be the same as the main port.
-        QPID_LOG(notice, "SSL multiplexing enabled");
-        return true;
-    }
-    return false;
-}
-
 // Static instance to initialise plugin
 static class TCPIOPlugin : public Plugin {
     void earlyInitialize(Target&) {
@@ -56,12 +42,9 @@ static class TCPIOPlugin : public Plugin
         if (broker) {
             const broker::Broker::Options& opts = broker->getOptions();
 
-            // Check for SSL on the same port
-            bool shouldListen = !sslMultiplexEnabled();
-
             uint16_t port = opts.port;
             TransportAcceptor::shared_ptr ta;
-            if (shouldListen) {
+            if (broker->shouldListen("tcp")) {
                 SocketAcceptor* aa = new SocketAcceptor(opts.tcpNoDelay, false, opts.maxNegotiateTime,
broker->getTimer());
                 ta.reset(aa);
                 port = aa->listen(opts.listenInterfaces, boost::lexical_cast<std::string>(opts.port),
opts.connectionBacklog, &createSocket);



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message