From cc091cc2c8872c555c09d30b3c741390f699713d Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Sat, 7 Apr 2018 12:48:01 +0200 Subject: [PATCH 1/4] 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 --- libretroshare/src/pqi/pqissl.cc | 17 ++++++++------- libretroshare/src/pqi/pqissllistener.cc | 28 +++++++++++-------------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/libretroshare/src/pqi/pqissl.cc b/libretroshare/src/pqi/pqissl.cc index 48186b755..58c7fc856 100644 --- a/libretroshare/src/pqi/pqissl.cc +++ b/libretroshare/src/pqi/pqissl.cc @@ -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) diff --git a/libretroshare/src/pqi/pqissllistener.cc b/libretroshare/src/pqi/pqissllistener.cc index 15c754888..b93eb1e97 100644 --- a/libretroshare/src/pqi/pqissllistener.cc +++ b/libretroshare/src/pqi/pqissllistener.cc @@ -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; } From e2b0e27205e75d2e0065a654249a49e09572c174 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 7 Apr 2018 00:56:07 +0200 Subject: [PATCH 2/4] fixed costly polling in RsGenExchange --- libretroshare/src/gxs/rsgenexchange.cc | 30 +++++++++++++++----------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index 14a2471e1..11137f8b0 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -64,7 +64,7 @@ static const uint32_t INDEX_AUTHEN_ADMIN = 0x00000040; // admin key #define GXS_MASK "GXS_MASK_HACK" -//#define GEN_EXCH_DEBUG 1 +#define GEN_EXCH_DEBUG 1 static const uint32_t MSG_CLEANUP_PERIOD = 60*59; // 59 minutes static const uint32_t INTEGRITY_CHECK_PERIOD = 60*31; // 31 minutes @@ -2860,8 +2860,10 @@ void RsGenExchange::processRecvdMessages() time_t now = time(NULL); + if(mMsgPendingValidate.empty()) + return ; #ifdef GEN_EXCH_DEBUG - if(!mMsgPendingValidate.empty()) + else std::cerr << "processing received messages" << std::endl; #endif // 1 - First, make sure items metadata is deserialised, clean old failed items, and collect the groups Ids we have to check @@ -2904,9 +2906,11 @@ void RsGenExchange::processRecvdMessages() } } - // 2 - Retrieve the metadata for the associated groups. + // 2 - Retrieve the metadata for the associated groups. The test is here to avoid the default behavior to + // retrieve all groups when the list is empty - mDataStore->retrieveGxsGrpMetaData(grpMetas); + if(!grpMetas.empty()) + mDataStore->retrieveGxsGrpMetaData(grpMetas); GxsMsgReq msgIds; RsNxsMsgDataTemporaryList msgs_to_store; @@ -2934,7 +2938,7 @@ void RsGenExchange::processRecvdMessages() // } #ifdef GEN_EXCH_DEBUG - std::cerr << " deserialised info: grp id=" << meta->mGroupId << ", msg id=" << meta->mMsgId ; + std::cerr << " deserialised info: grp id=" << msg->grpId << ", msg id=" << msg->msgId ; #endif std::map::iterator mit = grpMetas.find(msg->grpId); @@ -2977,8 +2981,8 @@ void RsGenExchange::processRecvdMessages() msg->metaData->recvTS = time(NULL); #ifdef GEN_EXCH_DEBUG - std::cerr << " new status flags: " << meta->mMsgStatus << std::endl; - std::cerr << " computed hash: " << meta->mHash << std::endl; + std::cerr << " new status flags: " << msg->metaData->mMsgStatus << std::endl; + std::cerr << " computed hash: " << msg->metaData->mHash << std::endl; std::cerr << "Message received. Identity=" << msg->metaData->mAuthorId << ", from peer " << msg->PeerId() << std::endl; #endif @@ -3062,9 +3066,6 @@ void RsGenExchange::processRecvdGroups() GxsPendingItem& gpsi = vit->second; RsNxsGrp* grp = gpsi.mItem; -#ifdef GEN_EXCH_DEBUG - std::cerr << " processing validation for group " << meta->mGroupId << ", original attempt time: " << time(NULL) - gpsi.mFirstTryTS << " seconds ago" << std::endl; -#endif if(grp->metaData == NULL) { RsGxsGrpMetaData* meta = new RsGxsGrpMetaData(); @@ -3074,6 +3075,9 @@ void RsGenExchange::processRecvdGroups() else delete meta ; } +#ifdef GEN_EXCH_DEBUG + std::cerr << " processing validation for group " << grp->metaData->mGroupId << ", original attempt time: " << time(NULL) - gpsi.mFirstTryTS << " seconds ago" << std::endl; +#endif // early deletion of group from the pending list if it's malformed, not accepted, or has been tried unsuccessfully for too long @@ -3102,7 +3106,7 @@ void RsGenExchange::processRecvdGroups() if(!grp->metaData->mAuthorId.isNull()) { #ifdef GEN_EXCH_DEBUG - std::cerr << "Group routage info: Identity=" << meta->mAuthorId << " from " << grp->PeerId() << std::endl; + std::cerr << "Group routage info: Identity=" << grp->metaData->mAuthorId << " from " << grp->PeerId() << std::endl; #endif mRoutingClues[grp->metaData->mAuthorId].insert(grp->PeerId()) ; } @@ -3349,7 +3353,7 @@ void RsGenExchange::removeDeleteExistingMessages( std::list& msgs, Gx const RsGxsMessageId::std_vector& msgIds = msgIdReq[(*cit2)->metaData->mGroupId]; #ifdef GEN_EXCH_DEBUG - std::cerr << " grpid=" << cit2->second->mGroupId << ", msgid=" << cit2->second->mMsgId ; + std::cerr << " grpid=" << (*cit2)->grpId << ", msgid=" << (*cit2)->msgId ; #endif // Avoid storing messages that are already in the database, as well as messages that are too old (or generally do not pass the database storage test) @@ -3369,7 +3373,7 @@ void RsGenExchange::removeDeleteExistingMessages( std::list& msgs, Gx } } #ifdef GEN_EXCH_DEBUG - std::cerr << " discarding " << cit2->second->mMsgId << std::endl; + std::cerr << " discarding " << (*cit2)->msgId << std::endl; #endif delete *cit2; From 27824943ffd582ed713b7c2bf05f646a0ad26661 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 7 Apr 2018 14:29:23 +0200 Subject: [PATCH 3/4] removed debug info --- libretroshare/src/gxs/rsgenexchange.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index 11137f8b0..15d0aa9e9 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -64,7 +64,7 @@ static const uint32_t INDEX_AUTHEN_ADMIN = 0x00000040; // admin key #define GXS_MASK "GXS_MASK_HACK" -#define GEN_EXCH_DEBUG 1 +//#define GEN_EXCH_DEBUG 1 static const uint32_t MSG_CLEANUP_PERIOD = 60*59; // 59 minutes static const uint32_t INTEGRITY_CHECK_PERIOD = 60*31; // 31 minutes From c19919962d1f2173da79d5f81f539412c9a69c97 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Sun, 8 Apr 2018 12:37:41 +0200 Subject: [PATCH 4/4] pqissl silence extra debug message --- libretroshare/src/pqi/pqissl.cc | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/libretroshare/src/pqi/pqissl.cc b/libretroshare/src/pqi/pqissl.cc index 58c7fc856..57b4f5e18 100644 --- a/libretroshare/src/pqi/pqissl.cc +++ b/libretroshare/src/pqi/pqissl.cc @@ -585,16 +585,13 @@ int pqissl::Delay_Connection() int pqissl::Initiate_Connection() { #ifdef PQISSL_DEBUG - std::cout << __PRETTY_FUNCTION__ << std::endl; + std::cerr << __PRETTY_FUNCTION__ << " " + << sockaddr_storage_tostring(remote_addr) << std::endl; #endif int err; sockaddr_storage addr; sockaddr_storage_copy(remote_addr, addr); - std::cerr << __PRETTY_FUNCTION__ << " " << sockaddr_storage_tostring(addr) - << std::endl; - - if(waiting != WAITING_DELAY) { std::cerr << __PRETTY_FUNCTION__ << " Already Attempt in Progress!"