Commit c2651edf authored by Luciano Orsini's avatar Luciano Orsini
Browse files

references #256: use of DNS with retry

parent a8b6ecab
......@@ -24,7 +24,7 @@ pt::vpi::ConnectionRequest::ConnectionRequest(pt::PeerTransport * pt, std::share
pt::vpi::ConnectionRequest::~ConnectionRequest()
{
pt::vpi::PeerTransport * pt = dynamic_cast<pt::vpi::PeerTransport*>(pt_);
//pt::vpi::PeerTransport * pt = dynamic_cast<pt::vpi::PeerTransport*>(pt_);
}
......
......@@ -58,6 +58,9 @@
#include "toolbox/TimeInterval.h"
#include "toolbox/TimeVal.h"
#include "toolbox/mem/MemoryPoolFactory.h"
#include "toolbox/net/DNS.h"
#include "toolbox/exception/Timeout.h"
#include "toolbox/net/exception/UnresolvedAddress.h"
static std::string getIPv4(const std::string & ifname)
......@@ -1467,35 +1470,57 @@ void pt::vpi::PeerTransport::connect(pt::Address::Reference from, pt::Address::
std::string lport = laddress.getPort();
std::string lhostname = laddress.getHost();
std::string localIPNumber = inet_ntoa(toolbox::net::getSocketAddressByName(lhostname, (uint16_t)(toolbox::toUnsignedLong(lport))).sin_addr);
std::string remoteIPNumber = inet_ntoa(toolbox::net::getSocketAddressByName(rhostname, (uint16_t)(toolbox::toUnsignedLong(rport))).sin_addr);
if (app->allowLocalPipeSupport_ && ( localIPNumber == remoteIPNumber))
try
{
LOG4CPLUS_INFO(this->getOwnerApplication()->getApplicationLogger(), "Connection request for network (as local):" << network << " Local IP " << localIPNumber << " Remote IP " << remoteIPNumber);
std::thread lc(&pt::vpi::PeerTransport::localconnect, this, app->sendQueuePairSize_, app->completionQueueSize_, network, listener, user_context);
lc.detach();
std::string lip = toolbox::net::DNS::waitAndRetry(lhostname,3,1).front().hostAddress();
std::string rip = toolbox::net::DNS::waitAndRetry(rhostname,3,1).front().hostAddress();
if (app->allowLocalPipeSupport_ && (lip == rip))
{
LOG4CPLUS_INFO(this->getOwnerApplication()->getApplicationLogger(), "Connection request for network (as local):" << network << " Local IP " << lip << " Remote IP " << rip);
std::thread lc(&pt::vpi::PeerTransport::localconnect, this, app->sendQueuePairSize_, app->completionQueueSize_, network, listener, user_context);
lc.detach();
}
else
{
LOG4CPLUS_INFO(this->getOwnerApplication()->getApplicationLogger(), "Connection request for network (as remote):" << network << " IP was " << lip);
nlohmann::json cookie;
cookie["mtu"] = (xdata::UnsignedIntegerT)app->deviceMTU_;
cookie["ibport"] = laddress.getIBPort();
cookie["sgid_index"] = laddress.getSGIDIndex();
cookie["path"] = laddress.getIBPath();
cookie["is_global"] = laddress.getIsGlobal();
cookie["sl"] = laddress.getSL();
cookie["traffic_class"] = laddress.getTrafficClass();
cookie["network"] = laddress.getNetwork();
cookie["sendwithtimeout"] = (xdata::BooleanT)app->sendWithTimeout_;
cookie["remoteip"] = rip; // to be used in ROutput for qpinfo
std::thread rc(&pt::vpi::PeerTransport::remoteconnect, this, cookie, rhostname, rportnum, network, listener, user_context);
rc.detach();
}
}
else
catch (toolbox::net::exception::UnresolvedAddress & e )
{
LOG4CPLUS_INFO(this->getOwnerApplication()->getApplicationLogger(), "Connection request for network (as remote):" << network << " IP was " << localIPNumber);
nlohmann::json cookie;
cookie["mtu"] = (xdata::UnsignedIntegerT)app->deviceMTU_;
cookie["ibport"] = laddress.getIBPort();
cookie["sgid_index"] = laddress.getSGIDIndex();
cookie["path"] = laddress.getIBPath();
cookie["is_global"] = laddress.getIsGlobal();
cookie["sl"] = laddress.getSL();
cookie["traffic_class"] = laddress.getTrafficClass();
cookie["network"] = laddress.getNetwork();
cookie["sendwithtimeout"] = (xdata::BooleanT)app->sendWithTimeout_;
cookie["remoteip"] = remoteIPNumber; // to be used in ROutput for qpinfo
std::stringstream ss;
ss << "fail to DNS reolution, with error " << e.what() << std::endl;
XCEPT_DECLARE_NESTED(pt::vpi::exception::Exception, ex, ss.str(), e);
std::shared_ptr<pt::pipe::ConnectionError> pce = std::make_shared<pt::pipe::ConnectionError>(user_context, ex);
std::thread rc(&pt::vpi::PeerTransport::remoteconnect, this, cookie, rhostname, rportnum, network, listener, user_context);
rc.detach();
std::thread([](pt::pipe::ServiceListener * listener,std::shared_ptr<pt::pipe::ConnectionError> pce){ listener->actionPerformed(pce);},listener,pce).detach();
}
catch (toolbox::net::exception::Exception& e )
{
std::stringstream ss;
ss << "fail to DNS reolution, with error " << e.what() << std::endl;
XCEPT_DECLARE_NESTED(pt::vpi::exception::Exception, ex, ss.str(), e);
std::shared_ptr<pt::pipe::ConnectionError> pce = std::make_shared<pt::pipe::ConnectionError>(user_context, ex);
std::thread([](pt::pipe::ServiceListener * listener,std::shared_ptr<pt::pipe::ConnectionError> pce){ listener->actionPerformed(pce);},listener,pce).detach();
}
}
......
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