mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-27 15:57:08 -05:00
added last msg time in GxsTrans stats. Added mutex to protect non atomic mPreferredGroup
This commit is contained in:
parent
332feddb17
commit
51c7e18a3a
@ -40,7 +40,10 @@ p3GxsTrans::~p3GxsTrans()
|
|||||||
|
|
||||||
bool p3GxsTrans::getStatistics(GxsTransStatistics& stats)
|
bool p3GxsTrans::getStatistics(GxsTransStatistics& stats)
|
||||||
{
|
{
|
||||||
stats.prefered_group_id = mPreferredGroupId;
|
{
|
||||||
|
RS_STACK_MUTEX(mDataMutex);
|
||||||
|
stats.prefered_group_id = mPreferredGroupId;
|
||||||
|
}
|
||||||
stats.outgoing_records.clear();
|
stats.outgoing_records.clear();
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -143,6 +146,19 @@ void p3GxsTrans::handleResponse(uint32_t token, uint32_t req_type)
|
|||||||
std::vector<RsGxsGrpItem*> groups;
|
std::vector<RsGxsGrpItem*> groups;
|
||||||
getGroupData(token, groups);
|
getGroupData(token, groups);
|
||||||
|
|
||||||
|
// First recompute the prefered group Id.
|
||||||
|
|
||||||
|
{
|
||||||
|
RS_STACK_MUTEX(mDataMutex);
|
||||||
|
mPreferredGroupId.clear();
|
||||||
|
|
||||||
|
for( auto grp : groups )
|
||||||
|
locked_supersedePreferredGroup(grp->meta.mGroupId);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG_GXSTRANS
|
||||||
|
std::cerr << " computed preferred group id: " << mPreferredGroupId << std::endl;
|
||||||
|
#endif
|
||||||
for( auto grp : groups )
|
for( auto grp : groups )
|
||||||
{
|
{
|
||||||
/* For each group check if it is better candidate then
|
/* For each group check if it is better candidate then
|
||||||
@ -155,18 +171,24 @@ void p3GxsTrans::handleResponse(uint32_t token, uint32_t req_type)
|
|||||||
|
|
||||||
const RsGroupMetaData& meta = grp->meta;
|
const RsGroupMetaData& meta = grp->meta;
|
||||||
bool subscribed = IS_GROUP_SUBSCRIBED(meta.mSubscribeFlags);
|
bool subscribed = IS_GROUP_SUBSCRIBED(meta.mSubscribeFlags);
|
||||||
bool old = olderThen( meta.mLastPost,
|
bool old = olderThen( meta.mLastPost, UNUSED_GROUP_UNSUBSCRIBE_INTERVAL );
|
||||||
UNUSED_GROUP_UNSUBSCRIBE_INTERVAL );
|
|
||||||
bool supersede = supersedePreferredGroup(meta.mGroupId);
|
|
||||||
uint32_t token;
|
uint32_t token;
|
||||||
|
|
||||||
bool shoudlSubscribe = !subscribed && ( !old || supersede );
|
bool shouldSubscribe = false ;
|
||||||
bool shoudlUnSubscribe = subscribed && old
|
bool shouldUnSubscribe = false ;
|
||||||
&& meta.mGroupId != mPreferredGroupId;
|
{
|
||||||
|
RS_STACK_MUTEX(mDataMutex);
|
||||||
|
bool shouldSubscribe = !subscribed && ( !old || meta.mGroupId == mPreferredGroupId );
|
||||||
|
bool shouldUnSubscribe = subscribed && old && meta.mGroupId != mPreferredGroupId;
|
||||||
|
}
|
||||||
|
|
||||||
if(shoudlSubscribe)
|
#ifdef DEBUG_GXSTRANS
|
||||||
|
std::cout << " group " << grp->meta.mGroupId << ", subscribed: " << subscribed << " last post: " << meta.mLastPost << " should subscribe: "<< shouldSubscribe
|
||||||
|
<< ", should unsubscribe: " << shouldUnSubscribe << std::endl;
|
||||||
|
#endif
|
||||||
|
if(shouldSubscribe)
|
||||||
RsGenExchange::subscribeToGroup(token, meta.mGroupId, true);
|
RsGenExchange::subscribeToGroup(token, meta.mGroupId, true);
|
||||||
else if(shoudlUnSubscribe)
|
else if(shouldUnSubscribe)
|
||||||
RsGenExchange::subscribeToGroup(token, meta.mGroupId, false);
|
RsGenExchange::subscribeToGroup(token, meta.mGroupId, false);
|
||||||
|
|
||||||
#ifdef GXS_MAIL_GRP_DEBUG
|
#ifdef GXS_MAIL_GRP_DEBUG
|
||||||
@ -188,7 +210,14 @@ void p3GxsTrans::handleResponse(uint32_t token, uint32_t req_type)
|
|||||||
delete grp;
|
delete grp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mPreferredGroupId.isNull())
|
bool have_preferred_group = false ;
|
||||||
|
|
||||||
|
{
|
||||||
|
RS_STACK_MUTEX(mDataMutex);
|
||||||
|
have_preferred_group = !mPreferredGroupId.isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!have_preferred_group)
|
||||||
{
|
{
|
||||||
/* This is true only at first run when we haven't received mail
|
/* This is true only at first run when we haven't received mail
|
||||||
* distribuition groups from friends
|
* distribuition groups from friends
|
||||||
@ -214,7 +243,9 @@ void p3GxsTrans::handleResponse(uint32_t token, uint32_t req_type)
|
|||||||
#endif
|
#endif
|
||||||
RsGxsGroupId grpId;
|
RsGxsGroupId grpId;
|
||||||
acknowledgeTokenGrp(token, grpId);
|
acknowledgeTokenGrp(token, grpId);
|
||||||
supersedePreferredGroup(grpId);
|
|
||||||
|
RS_STACK_MUTEX(mDataMutex);
|
||||||
|
locked_supersedePreferredGroup(grpId);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MAILS_UPDATE:
|
case MAILS_UPDATE:
|
||||||
@ -346,6 +377,9 @@ void p3GxsTrans::GxsTransIntegrityCleanupThread::run()
|
|||||||
{
|
{
|
||||||
std::vector<RsNxsMsg*>& msgV = mit->second;
|
std::vector<RsNxsMsg*>& msgV = mit->second;
|
||||||
std::vector<RsNxsMsg*>::iterator vit = msgV.begin();
|
std::vector<RsNxsMsg*>::iterator vit = msgV.begin();
|
||||||
|
#ifdef DEBUG_GXSTRANS
|
||||||
|
std::cerr << "Group " << mit->first << ": " << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
for(; vit != msgV.end(); ++vit)
|
for(; vit != msgV.end(); ++vit)
|
||||||
{
|
{
|
||||||
@ -817,6 +851,8 @@ void p3GxsTrans::locked_processOutgoingRecord(OutgoingRecord& pr)
|
|||||||
}
|
}
|
||||||
case GxsTransSendStatus::PENDING_PREFERRED_GROUP:
|
case GxsTransSendStatus::PENDING_PREFERRED_GROUP:
|
||||||
{
|
{
|
||||||
|
RS_STACK_MUTEX(mDataMutex);
|
||||||
|
|
||||||
if(mPreferredGroupId.isNull())
|
if(mPreferredGroupId.isNull())
|
||||||
{
|
{
|
||||||
requestGroupsData();
|
requestGroupsData();
|
||||||
@ -841,7 +877,10 @@ void p3GxsTrans::locked_processOutgoingRecord(OutgoingRecord& pr)
|
|||||||
grsrz.resize(grsz);
|
grsrz.resize(grsz);
|
||||||
RsGxsTransSerializer().serialise(&grcpt, &grsrz[0], &grsz);
|
RsGxsTransSerializer().serialise(&grcpt, &grsrz[0], &grsz);
|
||||||
|
|
||||||
pr.presignedReceipt.grpId = mPreferredGroupId;
|
{
|
||||||
|
RS_STACK_MUTEX(mDataMutex);
|
||||||
|
pr.presignedReceipt.grpId = mPreferredGroupId;
|
||||||
|
}
|
||||||
pr.presignedReceipt.metaData = new RsGxsMsgMetaData();
|
pr.presignedReceipt.metaData = new RsGxsMsgMetaData();
|
||||||
*pr.presignedReceipt.metaData = grcpt.meta;
|
*pr.presignedReceipt.metaData = grcpt.meta;
|
||||||
pr.presignedReceipt.msg.setBinData(&grsrz[0], grsz);
|
pr.presignedReceipt.msg.setBinData(&grsrz[0], grsz);
|
||||||
|
@ -99,7 +99,8 @@ public:
|
|||||||
mServClientsMutex("p3GxsTrans client services map mutex"),
|
mServClientsMutex("p3GxsTrans client services map mutex"),
|
||||||
mOutgoingMutex("p3GxsTrans outgoing queue map mutex"),
|
mOutgoingMutex("p3GxsTrans outgoing queue map mutex"),
|
||||||
mIngoingMutex("p3GxsTrans ingoing queue map mutex"),
|
mIngoingMutex("p3GxsTrans ingoing queue map mutex"),
|
||||||
mPerUserStatsMutex("p3GxsTrans user stats mutex")
|
mPerUserStatsMutex("p3GxsTrans user stats mutex"),
|
||||||
|
mDataMutex("p3GxsTrans data mutex")
|
||||||
{
|
{
|
||||||
mLastMsgCleanup = time(NULL) - MAX_DELAY_BETWEEN_CLEANUPS + 30; // always check 30 secs after start
|
mLastMsgCleanup = time(NULL) - MAX_DELAY_BETWEEN_CLEANUPS + 30; // always check 30 secs after start
|
||||||
mCleanupThread = NULL ;
|
mCleanupThread = NULL ;
|
||||||
@ -253,7 +254,7 @@ private:
|
|||||||
* @return true if preferredGroupId has been supeseded by potentialGrId
|
* @return true if preferredGroupId has been supeseded by potentialGrId
|
||||||
* false otherwise.
|
* false otherwise.
|
||||||
*/
|
*/
|
||||||
bool inline supersedePreferredGroup(const RsGxsGroupId& potentialGrId)
|
bool inline locked_supersedePreferredGroup(const RsGxsGroupId& potentialGrId)
|
||||||
{
|
{
|
||||||
if(mPreferredGroupId < potentialGrId)
|
if(mPreferredGroupId < potentialGrId)
|
||||||
{
|
{
|
||||||
@ -320,5 +321,9 @@ private:
|
|||||||
|
|
||||||
RsMutex mPerUserStatsMutex;
|
RsMutex mPerUserStatsMutex;
|
||||||
std::map<RsGxsId,MsgSizeCount> per_user_statistics ;
|
std::map<RsGxsId,MsgSizeCount> per_user_statistics ;
|
||||||
|
|
||||||
|
// Mutex to protect local data
|
||||||
|
|
||||||
|
RsMutex mDataMutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -252,8 +252,10 @@ void GxsTransportStatistics::updateContent()
|
|||||||
groupTreeWidget->addTopLevelItem(item);
|
groupTreeWidget->addTopLevelItem(item);
|
||||||
groupTreeWidget->setItemExpanded(item,openned_groups.find(it->first) != openned_groups.end());
|
groupTreeWidget->setItemExpanded(item,openned_groups.find(it->first) != openned_groups.end());
|
||||||
|
|
||||||
|
QString msg_time_string = (stat.last_publish_TS>0)?QString(" (Last msg: %1)").arg(QDateTime::fromTime_t(stat.last_publish_TS).toString()):"" ;
|
||||||
|
|
||||||
|
item->setData(COL_GROUP_NUM_MSGS, Qt::DisplayRole, QString::number(stat.mNumMsgs) + msg_time_string) ;
|
||||||
item->setData(COL_GROUP_GRP_ID, Qt::DisplayRole, QString::fromStdString(stat.mGrpId.toStdString())) ;
|
item->setData(COL_GROUP_GRP_ID, Qt::DisplayRole, QString::fromStdString(stat.mGrpId.toStdString())) ;
|
||||||
item->setData(COL_GROUP_NUM_MSGS, Qt::DisplayRole, QString::number(stat.mNumMsgs)) ;
|
|
||||||
item->setData(COL_GROUP_SIZE_MSGS, Qt::DisplayRole, QString::number(stat.mTotalSizeOfMsgs)) ;
|
item->setData(COL_GROUP_SIZE_MSGS, Qt::DisplayRole, QString::number(stat.mTotalSizeOfMsgs)) ;
|
||||||
item->setData(COL_GROUP_SUBSCRIBED,Qt::DisplayRole, stat.subscribed?tr("Yes"):tr("No")) ;
|
item->setData(COL_GROUP_SUBSCRIBED,Qt::DisplayRole, stat.subscribed?tr("Yes"):tr("No")) ;
|
||||||
item->setData(COL_GROUP_POPULARITY,Qt::DisplayRole, QString::number(stat.popularity)) ;
|
item->setData(COL_GROUP_POPULARITY,Qt::DisplayRole, QString::number(stat.popularity)) ;
|
||||||
@ -429,6 +431,7 @@ void GxsTransportStatistics::loadMsgMeta(const uint32_t& token)
|
|||||||
return ;
|
return ;
|
||||||
|
|
||||||
for(GxsMsgMetaMap::const_iterator it(m.begin());it!=m.end();++it)
|
for(GxsMsgMetaMap::const_iterator it(m.begin());it!=m.end();++it)
|
||||||
mGroupStats[it->first].messages_metas = it->second ;
|
for(uint32_t i=0;i<it->second.size();++i)
|
||||||
|
mGroupStats[it->first].addMessageMeta(it->second[i]) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,11 +38,24 @@ class UIStateHelper;
|
|||||||
class RsGxsTransGroupStatistics: public GxsGroupStatistic
|
class RsGxsTransGroupStatistics: public GxsGroupStatistic
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsGxsTransGroupStatistics() {}
|
RsGxsTransGroupStatistics()
|
||||||
|
{
|
||||||
|
last_publish_TS = 0;
|
||||||
|
popularity = 0;
|
||||||
|
subscribed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void addMessageMeta(const RsMsgMetaData& meta)
|
||||||
|
{
|
||||||
|
messages_metas.push_back(meta) ;
|
||||||
|
last_publish_TS = std::max(last_publish_TS,meta.mPublishTs) ;
|
||||||
|
}
|
||||||
|
|
||||||
bool subscribed ;
|
bool subscribed ;
|
||||||
int popularity ;
|
int popularity ;
|
||||||
|
|
||||||
|
time_t last_publish_TS;
|
||||||
|
|
||||||
std::vector<RsMsgMetaData> messages_metas ;
|
std::vector<RsMsgMetaData> messages_metas ;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user