Commit 19603037 authored by Raphael Defosseux's avatar Raphael Defosseux

Merge branch 'giving-resolution-multiple-tries' into 'develop'

feat(fqdn): giving some time for FQDN resolution

See merge request oai/cn5g/oai-cn5g-amf!151
parents d4c04b9a 3550b210
...@@ -137,7 +137,6 @@ check_supported_distribution() { ...@@ -137,7 +137,6 @@ check_supported_distribution() {
"rhel8.5") return 0 ;; "rhel8.5") return 0 ;;
"rhel8.6") return 0 ;; "rhel8.6") return 0 ;;
"rhel8.7") return 0 ;; "rhel8.7") return 0 ;;
#"centos7") return 0 ;;
esac esac
return 1 return 1
} }
...@@ -297,7 +296,10 @@ check_enable_epel_repos() { ...@@ -297,7 +296,10 @@ check_enable_epel_repos() {
echo "EPEL repos already present. Good." echo "EPEL repos already present. Good."
else else
echo "EPEL repos not present. Installing them." echo "EPEL repos not present. Installing them."
$SUDO $INSTALLER install $OPTION https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm wget --tries=4 --retry-connrefused --wait=8 \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
$SUDO $INSTALLER install $OPTION epel-release-latest-7.noarch.rpm
rm -f epel-release-latest-7.noarch.rpm
fi fi
fi fi
} }
......
...@@ -51,6 +51,7 @@ RUN rm -f /etc/rhsm-host && \ ...@@ -51,6 +51,7 @@ RUN rm -f /etc/rhsm-host && \
boost-devel \ boost-devel \
openssl-devel \ openssl-devel \
openssl \ openssl \
wget \
libasan && \ libasan && \
echo "/usr/local/lib" > /etc/ld.so.conf.d/local-lib.conf && \ echo "/usr/local/lib" > /etc/ld.so.conf.d/local-lib.conf && \
echo "/usr/local/lib64" >> /etc/ld.so.conf.d/local-lib.conf echo "/usr/local/lib64" >> /etc/ld.so.conf.d/local-lib.conf
......
...@@ -20,18 +20,24 @@ ...@@ -20,18 +20,24 @@
*/ */
#include "fqdn.hpp" #include "fqdn.hpp"
#include "logger.hpp"
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include <iostream> #include <iostream>
#include <chrono>
#include <thread>
#include "logger.hpp" #define MAX_NB_RESOLVE_TRIES 4
#define TIME_BETWEEN_TRIES 2
bool fqdn::resolve( bool fqdn::resolve(
const std::string& host_name, std::string& address, uint32_t& port, const std::string& host_name, std::string& address, uint32_t& port,
uint8_t& addr_type, const std::string& protocol) { uint8_t& addr_type, const std::string& protocol) {
int tries = 0;
Logger::amf_app().debug("Resolving a DNS (name %s)", host_name.c_str());
while (tries < MAX_NB_RESOLVE_TRIES) {
try { try {
Logger::amf_app().debug("Resolving DNS:- %s", host_name.c_str());
boost::asio::io_context io_context = {}; boost::asio::io_context io_context = {};
Logger::amf_app().debug("Resolving DNS Try #%u", tries);
boost::asio::ip::tcp::resolver resolver{io_context}; boost::asio::ip::tcp::resolver resolver{io_context};
boost::asio::ip::tcp::resolver::results_type endpoints = boost::asio::ip::tcp::resolver::results_type endpoints =
...@@ -44,7 +50,7 @@ bool fqdn::resolve( ...@@ -44,7 +50,7 @@ bool fqdn::resolve(
address = endpoint.address().to_string(); address = endpoint.address().to_string();
port = endpoint.port(); port = endpoint.port();
Logger::amf_app().debug( Logger::amf_app().debug(
"Resolve a DNS (name %s, protocol %s): Ip Addr %s, port %u", "Resolved a DNS (name %s, protocol %s): Ip Addr %s, port %u",
host_name.c_str(), protocol.c_str(), address.c_str(), port); host_name.c_str(), protocol.c_str(), address.c_str(), port);
if (endpoint.address().is_v4()) if (endpoint.address().is_v4())
addr_type = 0; addr_type = 0;
...@@ -53,11 +59,16 @@ bool fqdn::resolve( ...@@ -53,11 +59,16 @@ bool fqdn::resolve(
return true; return true;
} }
} catch (std::exception& e) { } catch (std::exception& e) {
// TODO: Remove this line so that AMF can re-try several times tries++;
if (tries == MAX_NB_RESOLVE_TRIES) {
throw std::runtime_error( throw std::runtime_error(
"Cannot resolve a DNS name " + std::string(e.what())); "Cannot resolve a DNS name " + std::string(e.what()) + " after " +
std::to_string(tries) + " tries");
return false; return false;
} }
std::this_thread::sleep_for(std::chrono::seconds(TIME_BETWEEN_TRIES));
}
}
return false; return false;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment