Merge pull request #869 from csoler/v0.6-GxsTransport

V0.6 gxs transport
This commit is contained in:
csoler 2017-06-04 18:44:26 +02:00 committed by GitHub
commit 458e180622
2 changed files with 32 additions and 4 deletions

View File

@ -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() void p3GxsTrans::GxsTransIntegrityCleanupThread::run()
{ {
// first take out all the groups // first take out all the groups
@ -304,7 +312,7 @@ void p3GxsTrans::GxsTransIntegrityCleanupThread::run()
std::cerr << " Unrecocognised item type!" << std::endl; std::cerr << " Unrecocognised item type!" << std::endl;
else if(NULL != (mitem = dynamic_cast<RsGxsTransMailItem*>(item))) else if(NULL != (mitem = dynamic_cast<RsGxsTransMailItem*>(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) ; 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() 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); RS_STACK_MUTEX(mOutgoingMutex);
for ( auto it = mOutgoingQueue.begin(); it != mOutgoingQueue.end(); ) for ( auto it = mOutgoingQueue.begin(); it != mOutgoingQueue.end(); )

View File

@ -282,16 +282,20 @@ private:
enum CheckState { CheckStart, CheckChecking }; enum CheckState { CheckStart, CheckChecking };
public: public:
GxsTransIntegrityCleanupThread(RsGeneralDataService *const dataService): mDs(dataService) {} GxsTransIntegrityCleanupThread(RsGeneralDataService *const dataService): mDs(dataService),mMtx("GxsTransIntegrityCheck") {}
bool isDone(); bool isDone();
void run(); void run();
void getDeletedIds(std::list<RsGxsGroupId>& grpIds, std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >& msgIds); void getDeletedIds(std::list<RsGxsGroupId>& grpIds, std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >& msgIds);
private: void getMessagesToDelete(GxsMsgReq& req) ;
private:
RsGeneralDataService* const mDs; RsGeneralDataService* const mDs;
RsMutex mMtx ;
GxsMsgReq mMsgToDel ;
}; };
GxsTransIntegrityCleanupThread *mCleanupThread ; GxsTransIntegrityCleanupThread *mCleanupThread ;