summaryrefslogtreecommitdiff
path: root/cpp/src/IceDiscovery/PluginI.cpp
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2017-03-01 19:42:52 +0100
committerBenoit Foucher <benoit@zeroc.com>2017-03-01 19:42:52 +0100
commit0a57f0b1841f51bc45ff2adc9ac19e114d695e43 (patch)
tree2ecab85164a70618fc0f861058f97194cb4e797e /cpp/src/IceDiscovery/PluginI.cpp
parentUWP build failure (diff)
downloadice-0a57f0b1841f51bc45ff2adc9ac19e114d695e43.tar.bz2
ice-0a57f0b1841f51bc45ff2adc9ac19e114d695e43.tar.xz
ice-0a57f0b1841f51bc45ff2adc9ac19e114d695e43.zip
Fixed ICE-7584 - discovery plugins now send multicast datagrams on all interfaces
Diffstat (limited to 'cpp/src/IceDiscovery/PluginI.cpp')
-rw-r--r--cpp/src/IceDiscovery/PluginI.cpp64
1 files changed, 24 insertions, 40 deletions
diff --git a/cpp/src/IceDiscovery/PluginI.cpp b/cpp/src/IceDiscovery/PluginI.cpp
index 2275459c04f..fa6e65bc5b2 100644
--- a/cpp/src/IceDiscovery/PluginI.cpp
+++ b/cpp/src/IceDiscovery/PluginI.cpp
@@ -9,6 +9,7 @@
#include <IceUtil/IceUtil.h>
#include <Ice/Ice.h>
+#include <Ice/Network.h> // For getInterfacesForMulticast
#include <IceDiscovery/PluginI.h>
#include <IceDiscovery/LocatorI.h>
@@ -87,16 +88,33 @@ PluginI::initialize()
}
properties->setProperty("IceDiscovery.Multicast.Endpoints", os.str());
}
- if(properties->getProperty("IceDiscovery.Reply.Endpoints").empty())
+
+ string lookupEndpoints = properties->getProperty("IceDiscovery.Lookup");
+ if(lookupEndpoints.empty())
{
- ostringstream os;
- os << "udp";
- if(!intf.empty())
+ //
+ // If no lookup endpoints are specified, we get all the network interfaces and create
+ // an endpoint for each of them. We'll send UDP multicast packages on each interface.
+ //
+ IceInternal::ProtocolSupport protocol = ipv4 && !preferIPv6 ? IceInternal::EnableIPv4 : IceInternal::EnableIPv6;
+ vector<string> interfaces = IceInternal::getInterfacesForMulticast(intf, protocol);
+ ostringstream lookup;
+ for(vector<string>::const_iterator p = interfaces.begin(); p != interfaces.end(); ++p)
{
- os << " -h \"" << intf << "\"";
+ if(p != interfaces.begin())
+ {
+ lookup << ":";
+ }
+ lookup << "udp -h \"" << address << "\" -p " << port << " --interface \"" << *p << "\"";
}
- properties->setProperty("IceDiscovery.Reply.Endpoints", os.str());
+ lookupEndpoints = lookup.str();
}
+
+ if(properties->getProperty("IceDiscovery.Reply.Endpoints").empty())
+ {
+ properties->setProperty("IceDiscovery.Reply.Endpoints", "udp -h " + (intf.empty() ? "*" : "\"" + intf + "\""));
+ }
+
if(properties->getProperty("IceDiscovery.Locator.Endpoints").empty())
{
properties->setProperty("IceDiscovery.Locator.AdapterId", Ice::generateUUID());
@@ -113,42 +131,8 @@ PluginI::initialize()
Ice::LocatorRegistryPrxPtr locatorRegistryPrx =
ICE_UNCHECKED_CAST(Ice::LocatorRegistryPrx, _locatorAdapter->addWithUUID(locatorRegistry));
- string lookupEndpoints = properties->getProperty("IceDiscovery.Lookup");
- if(lookupEndpoints.empty())
- {
- ostringstream os;
- os << "udp -h \"" << address << "\" -p " << port;
- if(!intf.empty())
- {
- os << " --interface \"" << intf << "\"";
- }
- lookupEndpoints = os.str();
- }
-
Ice::ObjectPrxPtr lookupPrx = _communicator->stringToProxy("IceDiscovery/Lookup -d:" + lookupEndpoints);
lookupPrx = lookupPrx->ice_collocationOptimized(false); // No collocation optimization for the multicast proxy!
- try
- {
- // Ensure we can establish a connection to the multicast proxy
- // but don't block.
-#ifdef ICE_CPP11_MAPPING
- lookupPrx->ice_getConnection();
-#else
- Ice::AsyncResultPtr result = lookupPrx->begin_ice_getConnection();
- if(result->sentSynchronously())
- {
- lookupPrx->end_ice_getConnection(result);
- }
-#endif
- }
- catch(const Ice::LocalException& ex)
- {
- ostringstream os;
- os << "IceDiscovery is unable to establish a multicast connection:\n";
- os << "proxy = " << lookupPrx << '\n';
- os << ex;
- throw Ice::PluginInitializationException(__FILE__, __LINE__, os.str());
- }
//
// Add lookup and lookup reply Ice objects