Skip to content
Snippets Groups Projects
Commit 83c85787 authored by Reiner Hauser's avatar Reiner Hauser
Browse files

change default name server; add two more lookup functions for retrieving the...

change default name server; add two more lookup functions for retrieving the name of the application as well as the endpoint
parent 7077a90b
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include <map>
#include <tuple> #include <tuple>
#include <cstdint> #include <cstdint>
#include "boost/asio.hpp" #include "boost/asio.hpp"
...@@ -48,11 +49,12 @@ namespace daq { ...@@ -48,11 +49,12 @@ namespace daq {
/** /**
* \param[in] partition The IPC partition object. * \param[in] partition The IPC partition object.
* \param[in] data_networks A list of networks in the format network/netmask. Both IP 4 and 6 are accepted. * \param[in] data_networks A list of networks in the format network/netmask. Both IP 4 and 6 are accepted.
* \param[in] is_server The IS server to publish the information to. * \param[in] is_server The IS server to publish the information to. If the DF_CONFIG_IS_SERVER environment variable
is set, it takes precedence.
*/ */
NameService(IPCPartition partition , NameService(IPCPartition partition ,
const std::vector<std::string>& data_networks, const std::vector<std::string>& data_networks,
const std::string& is_server = "DF") noexcept; const std::string& is_server = "DFConfig") noexcept;
~NameService() noexcept; ~NameService() noexcept;
/** \brief Publish IS object with all valid local interfaces and port number. /** \brief Publish IS object with all valid local interfaces and port number.
...@@ -74,6 +76,26 @@ namespace daq { ...@@ -74,6 +76,26 @@ namespace daq {
*/ */
std::vector<boost::asio::ip::tcp::endpoint> lookup(const std::string& prefix) const; std::vector<boost::asio::ip::tcp::endpoint> lookup(const std::string& prefix) const;
/** \brief Look up all applications starting with the given 'prefix' and return a map of names and endpoints.
*
* \param[in] prefix The search criteria in IS will be 'prefix.*'.
*
* \returns A map of application names and boost ASIO TCP endpoints, exactly one for each remote application.
*
* \throws IS exceptions
*/
std::map<std::string,boost::asio::ip::tcp::endpoint> lookup_names(const std::string& prefix) const;
/** \brief Look up all applications starting with the given 'prefix' and return a map of names and all endpoints.
*
* \param[in] prefix The search criteria in IS will be 'prefix.*'.
*
* \returns A map of application names and a list of all boost ASIO TCP endpoints that would be available.
*
* \throws IS exceptions
*/
std::map<std::string,std::vector<boost::asio::ip::tcp::endpoint>> lookup_all(const std::string& prefix) const;
/** \brief Resolve a single specific application. /** \brief Resolve a single specific application.
* *
* \param[in] Resolves exactly one specific remote applications. * \param[in] Resolves exactly one specific remote applications.
......
...@@ -15,6 +15,12 @@ namespace daq { ...@@ -15,6 +15,12 @@ namespace daq {
: m_partition(partition), : m_partition(partition),
m_is_server(is_server) m_is_server(is_server)
{ {
if(const char *server = getenv("DF_CONFIG_IS_SERVER")) {
// override user argument
m_is_server = server;
}
for(const auto & network : data_networks) { for(const auto & network : data_networks) {
m_data_networks.push_back(parse_address_network(network)); m_data_networks.push_back(parse_address_network(network));
} }
...@@ -173,6 +179,66 @@ namespace daq { ...@@ -173,6 +179,66 @@ namespace daq {
return results; return results;
} }
// Look up all applications of given 'type' and return a map of names and endpoints
std::map<std::string,boost::asio::ip::tcp::endpoint>
NameService::lookup_names(const std::string& prefix) const
{
std::map<std::string,boost::asio::ip::tcp::endpoint> results;
ISInfoIterator it(m_partition, m_is_server, ISCriteria("MSG_" + prefix + ".*", MsgInfo::type()));
while(it++) {
std::string name(it.name());
MsgInfo info;
it.value(info);
// match my local interfaces against the list
for(auto& addr_netmask : info.Addresses) {
boost::asio::ip::address addr, mask;
std::tie(addr, mask) = parse_address_network(addr_netmask);
if(matches(addr, mask)) {
results[name.substr(4)] = boost::asio::ip::tcp::endpoint(addr, info.Port);
break;
}
}
}
return results;
}
// Look up all applications of given 'type' and return a map of all names and endpoints that match
std::map<std::string, std::vector<boost::asio::ip::tcp::endpoint>>
NameService::lookup_all(const std::string& prefix) const
{
std::map<std::string,std::vector<boost::asio::ip::tcp::endpoint>> results;
ISInfoIterator it(m_partition, m_is_server, ISCriteria("MSG_" + prefix + ".*", MsgInfo::type()));
while(it++) {
std::string name(it.name());
MsgInfo info;
it.value(info);
// match my local interfaces against the list
for(auto& addr_netmask : info.Addresses) {
boost::asio::ip::address addr, mask;
std::tie(addr, mask) = parse_address_network(addr_netmask);
if(matches(addr, mask)) {
results[name.substr(4)].push_back(boost::asio::ip::tcp::endpoint(addr, info.Port));
break;
}
}
}
return results;
}
boost::asio::ip::tcp::endpoint boost::asio::ip::tcp::endpoint
NameService::resolve(const std::string& name) const NameService::resolve(const std::string& name) const
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment