added a structure in GxsNetService to record who sends info about groups, so as to dynamically compute group popularity. The GUI needs to be improved to update regularly so as to reflect current values for popularity. For now only subscribing/unsubscribing and new messages trigger the update

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7587 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2014-10-07 21:42:44 +00:00
parent c527fa9375
commit 8c2ba8b980
6 changed files with 64 additions and 22 deletions

View File

@ -1147,8 +1147,14 @@ bool RsGenExchange::getGroupMeta(const uint32_t &token, std::list<RsGroupMetaDat
for(; lit != metaL.end(); lit++)
{
RsGxsGrpMetaData& gMeta = *(*lit);
m = gMeta;
groupInfo.push_back(m);
m = gMeta;
if(mNetService != NULL)
m.mPop = mNetService->getGroupPopularity((*lit)->mGroupId) ;
else
m.mPop= 0 ;
groupInfo.push_back(m);
delete (*lit);
}
@ -1245,7 +1251,12 @@ bool RsGenExchange::getGroupData(const uint32_t &token, std::vector<RsGxsGrpItem
RsGxsGrpItem* gItem = dynamic_cast<RsGxsGrpItem*>(item);
if (gItem)
{
gItem->meta = *((*lit)->metaData);
gItem->meta = *((*lit)->metaData);
if(mNetService != NULL)
gItem->meta.mPop = mNetService->getGroupPopularity(gItem->meta.mGroupId) ;
else
gItem->meta.mPop= 0 ;
grpItem.push_back(gItem);
}
else
@ -1428,10 +1439,10 @@ void RsGenExchange::notifyNewGroups(std::vector<RsNxsGrp *> &groups)
// TODO: move this to nxs layer to save bandwidth
if(received == mReceivedGrps.end())
{
#ifdef GEN_EXCH_DEBUG
//#ifdef GEN_EXCH_DEBUG
std::cerr << "RsGenExchange::notifyNewGroups() Received GrpId: " << grp->grpId;
std::cerr << std::endl;
#endif
//#endif
GxsPendingItem<RsNxsGrp*, RsGxsGroupId> gpsi(grp, grp->grpId);
mReceivedGrps.push_back(gpsi);

View File

@ -1216,6 +1216,18 @@ void RsGxsNetService::processTransactions(){
}
}
int RsGxsNetService::getGroupPopularity(const RsGxsGroupId& gid)
{
RsStackMutex stack(mNxsMutex);
std::map<RsGxsGroupId,std::set<RsPeerId> >::const_iterator it = mGroupSuppliers.find(gid) ;
if(it == mGroupSuppliers.end())
return 0 ;
else
return it->second.size();
}
void RsGxsNetService::processCompletedTransactions()
{
RsStackMutex stack(mNxsMutex);
@ -1283,7 +1295,8 @@ void RsGxsNetService::locked_processCompletedIncomingTrans(NxsTransaction* tr)
if(grp)
{
tr->mItems.pop_front();
grps.push_back(grp);
grps.push_back(grp);
}
else
{
@ -2170,7 +2183,6 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrp* item)
RsPeerId peer = item->PeerId();
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grp;
mDataStore->retrieveGxsGrpMetaData(grp);
@ -2507,6 +2519,10 @@ void RsGxsNetService::handleRecvSyncMessage(RsNxsSyncMsg* item)
{
RsStackMutex stack(mNxsMutex);
// We do that early, so as to get info about who sends data about which group,
// even when the group doesn't need update.
mGroupSuppliers[item->grpId].insert(item->PeerId()) ;
if(!locked_CanReceiveUpdate(item))
return;
@ -2523,7 +2539,7 @@ void RsGxsNetService::handleRecvSyncMessage(RsNxsSyncMsg* item)
if(grpMeta == NULL)
return;
req[item->grpId] = std::vector<RsGxsMessageId>();
req[item->grpId] = std::vector<RsGxsMessageId>();
mDataStore->retrieveGxsMsgMetaData(req, metaResult);
std::vector<RsGxsMsgMetaData*>& msgMetas = metaResult[item->grpId];

View File

@ -96,14 +96,14 @@ public:
* Use this to set how far back synchronisation of messages should take place
* @param age the max age a sync item can to be allowed in a synchronisation
*/
void setSyncAge(uint32_t age);
virtual void setSyncAge(uint32_t age);
/*!
* pauses synchronisation of subscribed groups and request for group id
* from peers
* @param enabled set to false to disable pause, and true otherwise
*/
void pauseSynchronisation(bool enabled);
virtual void pauseSynchronisation(bool enabled);
/*!
@ -112,7 +112,7 @@ public:
* @param msgId the messages to retrieve
* @return request token to be redeemed
*/
int requestMsg(const RsGxsGrpMsgIdPair& /* msgId */){ return 0;}
virtual int requestMsg(const RsGxsGrpMsgIdPair& /* msgId */){ return 0;}
/*!
* Request for this group is sent through to peers on your network
@ -120,13 +120,15 @@ public:
* @param enabled set to false to disable pause, and true otherwise
* @return request token to be redeemed
*/
int requestGrp(const std::list<RsGxsGroupId>& grpId, const RsPeerId& peerId);
virtual int requestGrp(const std::list<RsGxsGroupId>& grpId, const RsPeerId& peerId);
/*!
* share publish keys for the specified group with the peers in the specified list.
*/
int sharePublishKey(const RsGxsGroupId& grpId,const std::list<RsPeerId>& peers) ;
virtual int sharePublishKey(const RsGxsGroupId& grpId,const std::list<RsPeerId>& peers) ;
virtual int getGroupPopularity(const RsGxsGroupId& id) ;
/* p3Config methods */
public:
@ -476,8 +478,11 @@ private:
ServerMsgMap mServerMsgUpdateMap;
ClientGrpMap mClientGrpUpdateMap;
std::map<RsGxsGroupId,std::set<RsPeerId> > mGroupSuppliers ;
RsGxsServerGrpUpdateItem* mGrpServerUpdateItem;
RsServiceInfo mServiceInfo;
};
#endif // RSGXSNETSERVICE_H

View File

@ -118,6 +118,12 @@ public:
*/
virtual int sharePublishKey(const RsGxsGroupId& grpId,const std::list<RsPeerId>& peers)=0 ;
/*!
* Request the number of peers who sent info about this group, as an indicator
* of group popularity.
*/
virtual int getGroupPopularity(const RsGxsGroupId& id) = 0 ;
};
#endif // RSGNP_H

View File

@ -1335,6 +1335,8 @@ int RsServer::StartupRetroShare()
mGxsIdService, mGxsCircles,
pgpAuxUtils);
mPosted->setNetworkExchangeService(posted_ns) ;
/**** Wiki GXS service ****/
@ -1351,6 +1353,7 @@ int RsServer::StartupRetroShare()
mGxsIdService, mGxsCircles,
pgpAuxUtils);
mWiki->setNetworkExchangeService(wiki_ns) ;
/**** Forum GXS service ****/
@ -1367,6 +1370,7 @@ int RsServer::StartupRetroShare()
mGxsIdService, mGxsCircles,
pgpAuxUtils);
mGxsForums->setNetworkExchangeService(gxsforums_ns) ;
/**** Channel GXS service ****/

View File

@ -27,21 +27,21 @@ QIcon PopularityDefs::icon(int popularity)
{
if (popularity == 0) {
return QIcon(":/images/hot_0.png");
} else if (popularity <= 7) {
/* 1-7 */
} else if (popularity <= 1) {
/* 1-1 */
return QIcon(":/images/hot_1.png");
} else if (popularity <= 15) {
/* 8-15 */
} else if (popularity <= 2) {
/* 2-2 */
return QIcon(":/images/hot_2.png");
} else if (popularity <= 24) {
/* 16-24 */
} else if (popularity <= 5) {
/* 3-5 */
return QIcon(":/images/hot_3.png");
} else if (popularity <= 34) {
/* 25-34 */
} else if (popularity <= 10) {
/* 6-10 */
return QIcon(":/images/hot_4.png");
}
/* >34 */
/* >10 */
return QIcon(":/images/hot_5.png");
}