fixed costly polling in RsGenExchange

This commit is contained in:
csoler 2018-04-07 00:56:07 +02:00
parent 2b9139bf85
commit c0570ffef6
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C

View File

@ -64,7 +64,7 @@ static const uint32_t INDEX_AUTHEN_ADMIN = 0x00000040; // admin key
#define GXS_MASK "GXS_MASK_HACK" #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 MSG_CLEANUP_PERIOD = 60*59; // 59 minutes
static const uint32_t INTEGRITY_CHECK_PERIOD = 60*31; // 31 minutes static const uint32_t INTEGRITY_CHECK_PERIOD = 60*31; // 31 minutes
@ -2860,8 +2860,10 @@ void RsGenExchange::processRecvdMessages()
time_t now = time(NULL); time_t now = time(NULL);
if(mMsgPendingValidate.empty())
return ;
#ifdef GEN_EXCH_DEBUG #ifdef GEN_EXCH_DEBUG
if(!mMsgPendingValidate.empty()) else
std::cerr << "processing received messages" << std::endl; std::cerr << "processing received messages" << std::endl;
#endif #endif
// 1 - First, make sure items metadata is deserialised, clean old failed items, and collect the groups Ids we have to check // 1 - First, make sure items metadata is deserialised, clean old failed items, and collect the groups Ids we have to check
@ -2904,8 +2906,10 @@ 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
if(!grpMetas.empty())
mDataStore->retrieveGxsGrpMetaData(grpMetas); mDataStore->retrieveGxsGrpMetaData(grpMetas);
GxsMsgReq msgIds; GxsMsgReq msgIds;
@ -2934,7 +2938,7 @@ void RsGenExchange::processRecvdMessages()
// } // }
#ifdef GEN_EXCH_DEBUG #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 #endif
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grpMetas.find(msg->grpId); std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grpMetas.find(msg->grpId);
@ -2977,8 +2981,8 @@ void RsGenExchange::processRecvdMessages()
msg->metaData->recvTS = time(NULL); msg->metaData->recvTS = time(NULL);
#ifdef GEN_EXCH_DEBUG #ifdef GEN_EXCH_DEBUG
std::cerr << " new status flags: " << meta->mMsgStatus << std::endl; std::cerr << " new status flags: " << msg->metaData->mMsgStatus << std::endl;
std::cerr << " computed hash: " << meta->mHash << 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; std::cerr << "Message received. Identity=" << msg->metaData->mAuthorId << ", from peer " << msg->PeerId() << std::endl;
#endif #endif
@ -3062,9 +3066,6 @@ void RsGenExchange::processRecvdGroups()
GxsPendingItem<RsNxsGrp*, RsGxsGroupId>& gpsi = vit->second; GxsPendingItem<RsNxsGrp*, RsGxsGroupId>& gpsi = vit->second;
RsNxsGrp* grp = gpsi.mItem; 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) if(grp->metaData == NULL)
{ {
RsGxsGrpMetaData* meta = new RsGxsGrpMetaData(); RsGxsGrpMetaData* meta = new RsGxsGrpMetaData();
@ -3074,6 +3075,9 @@ void RsGenExchange::processRecvdGroups()
else else
delete meta ; 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 // 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()) if(!grp->metaData->mAuthorId.isNull())
{ {
#ifdef GEN_EXCH_DEBUG #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 #endif
mRoutingClues[grp->metaData->mAuthorId].insert(grp->PeerId()) ; mRoutingClues[grp->metaData->mAuthorId].insert(grp->PeerId()) ;
} }
@ -3349,7 +3353,7 @@ void RsGenExchange::removeDeleteExistingMessages( std::list<RsNxsMsg*>& msgs, Gx
const RsGxsMessageId::std_vector& msgIds = msgIdReq[(*cit2)->metaData->mGroupId]; const RsGxsMessageId::std_vector& msgIds = msgIdReq[(*cit2)->metaData->mGroupId];
#ifdef GEN_EXCH_DEBUG #ifdef GEN_EXCH_DEBUG
std::cerr << " grpid=" << cit2->second->mGroupId << ", msgid=" << cit2->second->mMsgId ; std::cerr << " grpid=" << (*cit2)->grpId << ", msgid=" << (*cit2)->msgId ;
#endif #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) // 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<RsNxsMsg*>& msgs, Gx
} }
} }
#ifdef GEN_EXCH_DEBUG #ifdef GEN_EXCH_DEBUG
std::cerr << " discarding " << cit2->second->mMsgId << std::endl; std::cerr << " discarding " << (*cit2)->msgId << std::endl;
#endif #endif
delete *cit2; delete *cit2;