Fixed hidden nodes listening failure

In case of hidden node the listen address was not properly converted to
  ipv4 mapped format causing bind to fail
Use sockaddr_storage_copy instead of = as sockaddr_storage is not
  guaranted to be copyable
This commit is contained in:
Gioacchino Mazzurco 2018-04-07 12:48:01 +02:00
parent 73c6deebf4
commit cc091cc2c8
No known key found for this signature in database
GPG Key ID: A1FBCA3872E87051
2 changed files with 21 additions and 24 deletions

View File

@ -589,7 +589,10 @@ int pqissl::Initiate_Connection()
#endif
int err;
sockaddr_storage addr = remote_addr;
sockaddr_storage addr; sockaddr_storage_copy(remote_addr, addr);
std::cerr << __PRETTY_FUNCTION__ << " " << sockaddr_storage_tostring(addr)
<< std::endl;
if(waiting != WAITING_DELAY)
@ -638,13 +641,6 @@ int pqissl::Initiate_Connection()
return -1;
}
{
std::string out;
rs_sprintf(out, "pqissl::Initiate_Connection() Connecting To: %s via: ", PeerId().toStdString().c_str());
out += sockaddr_storage_tostring(addr);
rslog(RSL_WARNING, pqisslzone, out);
}
if (sockaddr_storage_isnull(addr))
{
rslog(RSL_WARNING, pqisslzone, "pqissl::Initiate_Connection() Invalid (0.0.0.0) Remote Address, Aborting Connect.");
@ -721,6 +717,11 @@ int pqissl::Initiate_Connection()
//std::cerr << "Setting Connect Timeout " << mConnectTimeout << " Seconds into Future " << std::endl;
sockaddr_storage_ipv4_to_ipv6(addr);
std::cerr << __PRETTY_FUNCTION__ << " Connecting To: "
<< PeerId().toStdString() <<" via: "
<< sockaddr_storage_tostring(addr) << std::endl;
if (0 != (err = unix_connect(osock, addr)))
{
switch (errno)

View File

@ -60,8 +60,10 @@ static struct RsLog::logInfo pqissllistenzoneInfo = {RsLog::Default, "p3peermgr"
pqissllistenbase::pqissllistenbase(const sockaddr_storage &addr, p3PeerMgr *pm)
: laddr(addr), mPeerMgr(pm), active(false)
: mPeerMgr(pm), active(false)
{
sockaddr_storage_copy(addr, laddr);
if (!(AuthSSL::getAuthSSL()-> active()))
{
pqioutput(PQL_ALERT, pqissllistenzone,
@ -208,26 +210,20 @@ int pqissllistenbase::setuplisten()
}
}
#ifdef OPEN_UNIVERSAL_PORT
struct sockaddr_storage tmpaddr = laddr;
if (!mPeerMgr->isHidden())
{
tmpaddr.ss_family = PF_INET6;
sockaddr_storage_zeroip(tmpaddr);
}
struct sockaddr_storage tmpaddr;
sockaddr_storage_copy(laddr, tmpaddr);
sockaddr_storage_ipv4_to_ipv6(tmpaddr);
if (!mPeerMgr->isHidden()) sockaddr_storage_zeroip(tmpaddr);
if (0 != (err = rs_bind(lsock, tmpaddr)))
#else
if (0 != (err = universal_bind(lsock, laddr)))
#endif
{
std::string out = "pqissllistenbase::setuplisten() Cannot Bind to Local Address!\n";
showSocketError(out);
pqioutput(PQL_ALERT, pqissllistenzone, out);
std::cerr << out << std::endl;
std::cerr << "laddr: " << sockaddr_storage_tostring(laddr) << std::endl;
#ifdef OPEN_UNIVERSAL_PORT
if (!mPeerMgr->isHidden()) std::cerr << "Zeroed tmpaddr: " << sockaddr_storage_tostring(tmpaddr) << std::endl;
#endif
std::cerr << out << std::endl
<< "tmpaddr: " << sockaddr_storage_tostring(tmpaddr)
<< std::endl;
print_stacktrace();
return -1;
}