You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2012/11/16 15:27:34 UTC

svn commit: r1410366 - in /qpid/trunk/qpid/cpp/src/qpid: broker/windows/SslProtocolFactory.cpp sys/windows/SystemInfo.cpp

Author: astitcher
Date: Fri Nov 16 14:27:34 2012
New Revision: 1410366

URL: http://svn.apache.org/viewvc?rev=1410366&view=rev
Log:
QPID-3351: Provide ability to specify the network interfaces
Made this work on windows too:
- Caveat is that you can't specify interface name currently
  only interface address

Modified:
    qpid/trunk/qpid/cpp/src/qpid/broker/windows/SslProtocolFactory.cpp
    qpid/trunk/qpid/cpp/src/qpid/sys/windows/SystemInfo.cpp

Modified: qpid/trunk/qpid/cpp/src/qpid/broker/windows/SslProtocolFactory.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/windows/SslProtocolFactory.cpp?rev=1410366&r1=1410365&r2=1410366&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/windows/SslProtocolFactory.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/windows/SslProtocolFactory.cpp Fri Nov 16 14:27:34 2012
@@ -93,9 +93,7 @@ class SslProtocolFactory : public qpid::
     CredHandle credHandle;
 
   public:
-    SslProtocolFactory(const SslServerOptions&, const std::string& host, const std::string& port,
-                       int backlog, bool nodelay,
-                       Timer& timer, uint32_t maxTime);
+    SslProtocolFactory(const qpid::broker::Broker::Options& opts, const SslServerOptions&, Timer& timer);
     ~SslProtocolFactory();
     void accept(sys::Poller::shared_ptr, sys::ConnectionCodec::Factory*);
     void connect(sys::Poller::shared_ptr, const std::string& host, const std::string& port,
@@ -129,10 +127,7 @@ static struct SslPlugin : public Plugin 
         if (broker) {
             try {
                 const broker::Broker::Options& opts = broker->getOptions();
-                ProtocolFactory::shared_ptr protocol(new SslProtocolFactory(options,
-                                                                            "", boost::lexical_cast<std::string>(options.port),
-                                                                            opts.connectionBacklog, opts.tcpNoDelay,
-                                                                            broker->getTimer(), opts.maxNegotiateTime));
+                ProtocolFactory::shared_ptr protocol(new SslProtocolFactory(opts, options, broker->getTimer()));
                 QPID_LOG(notice, "Listening for SSL connections on TCP port " << protocol->getPort());
                 broker->registerProtocolFactory("ssl", protocol);
             } catch (const std::exception& e) {
@@ -142,13 +137,36 @@ static struct SslPlugin : public Plugin 
     }
 } sslPlugin;
 
-SslProtocolFactory::SslProtocolFactory(const SslServerOptions& options,
-                                       const std::string& host, const std::string& port,
-                                       int backlog, bool nodelay,
-                                       Timer& timer, uint32_t maxTime)
+namespace {
+    // Expand list of Interfaces and addresses to a list of addresses
+    std::vector<std::string> expandInterfaces(const std::vector<std::string>& interfaces) {
+        std::vector<std::string> addresses;
+        // If there are no specific interfaces listed use a single "" to listen on every interface
+        if (interfaces.empty()) {
+            addresses.push_back("");
+            return addresses;
+        }
+        for (unsigned i = 0; i < interfaces.size(); ++i) {
+            const std::string& interface = interfaces[i];
+            if (!(SystemInfo::getInterfaceAddresses(interface, addresses))) {
+                // We don't have an interface of that name -
+                // Check for IPv6 ('[' ']') brackets and remove them
+                // then pass to be looked up directly
+                if (interface[0]=='[' && interface[interface.size()-1]==']') {
+                    addresses.push_back(interface.substr(1, interface.size()-2));
+                } else {
+                    addresses.push_back(interface);
+                }
+            }
+        }
+        return addresses;
+    }
+}
+
+SslProtocolFactory::SslProtocolFactory(const qpid::broker::Broker::Options& opts, const SslServerOptions& options, Timer& timer)
     : brokerTimer(timer),
-      maxNegotiateTime(maxTime),
-      tcpNoDelay(nodelay),
+      maxNegotiateTime(opts.maxNegotiateTime),
+      tcpNoDelay(opts.tcpNoDelay),
       clientAuthSelected(options.clientAuth) {
 
     // Make sure that certificate store is good before listening to sockets
@@ -212,21 +230,31 @@ SslProtocolFactory::SslProtocolFactory(c
     ::CertFreeCertificateContext(certContext);
     ::CertCloseStore(certStoreHandle, 0);
 
-    // Listen to socket(s)
-    SocketAddress sa(host, port);
+    std::vector<std::string> addresses = expandInterfaces(opts.listenInterfaces);
+    if (addresses.empty()) {
+        // We specified some interfaces, but couldn't find addresses for them
+        QPID_LOG(warning, "TCP/TCP6: No specified network interfaces found: Not Listening");
+        listeningPort = 0;
+    }
+
+    for (unsigned i = 0; i<addresses.size(); ++i) {
+        QPID_LOG(debug, "Using interface: " << addresses[i]);
+        SocketAddress sa(addresses[i], boost::lexical_cast<std::string>(options.port));
 
-    // We must have at least one resolved address
-    QPID_LOG(info, "SSL Listening to: " << sa.asString())
-    Socket* s = createSocket();
-    listeningPort = s->listen(sa, backlog);
-    listeners.push_back(s);
 
-    // Try any other resolved addresses
-    while (sa.nextAddress()) {
+        // We must have at least one resolved address
         QPID_LOG(info, "SSL Listening to: " << sa.asString())
         Socket* s = createSocket();
-        s->listen(sa, backlog);
+        listeningPort = s->listen(sa, opts.connectionBacklog);
         listeners.push_back(s);
+
+        // Try any other resolved addresses
+        while (sa.nextAddress()) {
+            QPID_LOG(info, "SSL Listening to: " << sa.asString())
+            Socket* s = createSocket();
+            s->listen(sa, opts.connectionBacklog);
+            listeners.push_back(s);
+        }
     }
 }
 

Modified: qpid/trunk/qpid/cpp/src/qpid/sys/windows/SystemInfo.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/windows/SystemInfo.cpp?rev=1410366&r1=1410365&r2=1410366&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/sys/windows/SystemInfo.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/sys/windows/SystemInfo.cpp Fri Nov 16 14:27:34 2012
@@ -96,10 +96,10 @@ void SystemInfo::getLocalIpAddresses (ui
     }
 }
 
-bool SystemInfo::isLocalHost(const std::string& candidateHost) {
-    // FIXME aconway 2012-05-03: not implemented.
-    assert(0);
-    throw Exception("Not implemented: isLocalHost");
+// Null function which always fails to find an network interface name
+bool SystemInfo::getInterfaceAddresses(const std::string&, std::vector<std::string>&)
+{
+    return false;
 }
 
 void SystemInfo::getSystemId (std::string &osName,



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