From 831b5607800cadf53852a1dba69ff9e95eee7d3a Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 4 Jun 2017 18:37:38 +0200 Subject: [PATCH] moved deletion of msgs in GxsTransport inside the service thread --- libretroshare/src/gxstrans/p3gxstrans.cc | 28 ++++++++++++++++++++++-- libretroshare/src/gxstrans/p3gxstrans.h | 10 ++++++--- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/libretroshare/src/gxstrans/p3gxstrans.cc b/libretroshare/src/gxstrans/p3gxstrans.cc index 7997363ed..0a67bb879 100644 --- a/libretroshare/src/gxstrans/p3gxstrans.cc +++ b/libretroshare/src/gxstrans/p3gxstrans.cc @@ -255,6 +255,14 @@ void p3GxsTrans::handleResponse(uint32_t token, uint32_t req_type) } } +void p3GxsTrans::GxsTransIntegrityCleanupThread::getMessagesToDelete(GxsMsgReq& m) +{ + RS_STACK_MUTEX(mMtx) ; + + m = mMsgToDel ; + mMsgToDel.clear(); +} + void p3GxsTrans::GxsTransIntegrityCleanupThread::run() { // first take out all the groups @@ -304,7 +312,7 @@ void p3GxsTrans::GxsTransIntegrityCleanupThread::run() std::cerr << " Unrecocognised item type!" << std::endl; else if(NULL != (mitem = dynamic_cast(item))) { - 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; + std::cerr << " " << msg->metaData->mMsgId << ": Mail data with ID " << std::hex << std::setfill('0') << std::setw(16) << 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) ; } @@ -337,7 +345,8 @@ void p3GxsTrans::GxsTransIntegrityCleanupThread::run() } } - mDs->removeMsgs(msgsToDel); + RS_STACK_MUTEX(mMtx) ; + mMsgToDel = msgsToDel ; } void p3GxsTrans::service_tick() @@ -362,6 +371,21 @@ void p3GxsTrans::service_tick() } } + // now grab collected messages to delete + + if(mCleanupThread != NULL && !mCleanupThread->isRunning()) + { + GxsMsgReq msgToDel ; + + mCleanupThread->getMessagesToDelete(msgToDel) ; + + if(!msgToDel.empty()) + { + std::cerr << "p3GxsTrans::service_tick(): deleting messages." << std::endl; + getDataStore()->removeMsgs(msgToDel); + } + } + { RS_STACK_MUTEX(mOutgoingMutex); for ( auto it = mOutgoingQueue.begin(); it != mOutgoingQueue.end(); ) diff --git a/libretroshare/src/gxstrans/p3gxstrans.h b/libretroshare/src/gxstrans/p3gxstrans.h index 0ae5d9989..14fa0f66f 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 = 1203; // every 20 mins. Could be less. + static const uint32_t MAX_DELAY_BETWEEN_CLEANUPS = 120; // every 20 mins. Could be less. time_t mLastMsgCleanup ; @@ -282,16 +282,20 @@ private: enum CheckState { CheckStart, CheckChecking }; public: - GxsTransIntegrityCleanupThread(RsGeneralDataService *const dataService): mDs(dataService) {} + GxsTransIntegrityCleanupThread(RsGeneralDataService *const dataService): mDs(dataService),mMtx("GxsTransIntegrityCheck") {} bool isDone(); void run(); void getDeletedIds(std::list& grpIds, std::map >& msgIds); - private: + void getMessagesToDelete(GxsMsgReq& req) ; + private: RsGeneralDataService* const mDs; + RsMutex mMtx ; + + GxsMsgReq mMsgToDel ; }; GxsTransIntegrityCleanupThread *mCleanupThread ;