From 832ba69b692ec1a45d016d8dae6a25bdc45ee74b Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 30 May 2017 21:38:59 +0200 Subject: [PATCH] fixed up cleanup for GxsTransport --- libretroshare/src/gxstrans/p3gxstrans.cc | 33 +++++++++++++++++++----- libretroshare/src/gxstrans/p3gxstrans.h | 8 ++---- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/libretroshare/src/gxstrans/p3gxstrans.cc b/libretroshare/src/gxstrans/p3gxstrans.cc index 12933eff4..7997363ed 100644 --- a/libretroshare/src/gxstrans/p3gxstrans.cc +++ b/libretroshare/src/gxstrans/p3gxstrans.cc @@ -278,9 +278,11 @@ void p3GxsTrans::GxsTransIntegrityCleanupThread::run() } // now messages - GxsMsgReq msgsToDel; - GxsMsgResult msgs; + std::map > stored_msgs ; + std::list received_msgs ; + + GxsMsgResult msgs; mDs->retrieveNxsMsgs(grps, msgs, false, true); for(GxsMsgResult::iterator mit = msgs.begin();mit != msgs.end(); ++mit) @@ -302,11 +304,15 @@ void p3GxsTrans::GxsTransIntegrityCleanupThread::run() std::cerr << " Unrecocognised item type!" << std::endl; else if(NULL != (mitem = dynamic_cast(item))) { - std::cerr << " Mail data with ID " << std::hex << mitem->mailId << std::dec << " from " << msg->metaData->mAuthorId << std::endl; + std::cerr << " " << msg->metaData->mMsgId << ": Mail data with ID " << std::hex << mitem->mailId << std::dec << " from " << msg->metaData->mAuthorId << " size: " << msg->msg.bin_len << std::endl; + + stored_msgs[mitem->mailId] = std::make_pair(msg->metaData->mGroupId,msg->metaData->mMsgId) ; } else if(NULL != (pitem = dynamic_cast(item))) { - std::cerr << " Signed rcpt of ID " << std::hex << pitem->mailId << std::dec << " from " << msg->metaData->mAuthorId << std::endl; + std::cerr << " " << msg->metaData->mMsgId << ": Signed rcpt of ID " << std::hex << pitem->mailId << std::dec << " from " << msg->metaData->mAuthorId << " size: " << msg->msg.bin_len << std::endl; + + received_msgs.push_back(pitem->mailId) ; } else std::cerr << " Unknown item type!" << std::endl; @@ -314,11 +320,24 @@ void p3GxsTrans::GxsTransIntegrityCleanupThread::run() delete msg; } } - RS_STACK_MUTEX(mIntegrityMutex); - //mDs->removeMsgs(msgsToDel); + GxsMsgReq msgsToDel ; - mDone = true; + std::cerr << "Msg removal report:" << std::endl; + + for(std::list::const_iterator it(received_msgs.begin());it!=received_msgs.end();++it) + { + std::map >::const_iterator it2 = stored_msgs.find(*it) ; + + if(stored_msgs.end() != it2) + { + msgsToDel[it2->second.first].push_back(it2->second.second); + + std::cerr << " scheduling msg " << std::hex << it2->second.first << "," << it2->second.second << " for deletion." << std::endl; + } + } + + mDs->removeMsgs(msgsToDel); } void p3GxsTrans::service_tick() diff --git a/libretroshare/src/gxstrans/p3gxstrans.h b/libretroshare/src/gxstrans/p3gxstrans.h index 809a5541f..0ae5d9989 100644 --- a/libretroshare/src/gxstrans/p3gxstrans.h +++ b/libretroshare/src/gxstrans/p3gxstrans.h @@ -159,7 +159,7 @@ private: * Two weeks seems fair ATM. */ static const uint32_t GXS_STORAGE_PERIOD = 0x127500; - static const uint32_t MAX_DELAY_BETWEEN_CLEANUPS = 120; // should be 3600 + static const uint32_t MAX_DELAY_BETWEEN_CLEANUPS = 1203; // every 20 mins. Could be less. time_t mLastMsgCleanup ; @@ -282,7 +282,7 @@ private: enum CheckState { CheckStart, CheckChecking }; public: - GxsTransIntegrityCleanupThread(RsGeneralDataService *const dataService): mDs(dataService),mIntegrityMutex("GxsTransIntegrityCheck") {} + GxsTransIntegrityCleanupThread(RsGeneralDataService *const dataService): mDs(dataService) {} bool isDone(); void run(); @@ -292,10 +292,6 @@ private: private: RsGeneralDataService* const mDs; - bool mDone; - RsMutex mIntegrityMutex; - std::list mDeletedGrps; - std::map > mDeletedMsgs; }; GxsTransIntegrityCleanupThread *mCleanupThread ;