mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 06:06:10 -04:00
Reworked ranking process flow
added ranking retrieval in gui removed locks from TokenQueue refactored gxs p3 pointers in p3face header file and gxs services now shutdown correctly using join(led to bad segfaults on shutdown) git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5972 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
f8c83779af
commit
3eaf844ec8
13 changed files with 297 additions and 92 deletions
|
@ -44,8 +44,8 @@
|
|||
|
||||
#define PUB_GRP_OFFSET 0
|
||||
#define RESTR_GRP_OFFSET 8
|
||||
#define PRIV_GRP_OFFSET 16
|
||||
#define GRP_OPTIONS_OFFSET 24
|
||||
#define PRIV_GRP_OFFSET 9
|
||||
#define GRP_OPTIONS_OFFSET 7
|
||||
|
||||
#define GXS_MASK "GXS_MASK_HACK"
|
||||
|
||||
|
|
|
@ -64,13 +64,14 @@ class RsPostedGroup
|
|||
class RsPostedPost;
|
||||
class RsPostedComment;
|
||||
class RsPostedVote;
|
||||
class RsPostedPostRanking;
|
||||
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsPostedPost> > PostedPostResult;
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsPostedComment> > PostedCommentResult;
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsPostedVote> > PostedVoteResult;
|
||||
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsPostedComment> > PostedRelatedCommentResult;
|
||||
typedef std::pair<RsGxsGroupId, int32_t> GroupRank;
|
||||
typedef std::map<RsGxsMessageId, uint32_t> PostedRanking;
|
||||
typedef std::map<uint32_t, RsGxsMessageId> PostedRanking;
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const RsPostedGroup &group);
|
||||
std::ostream &operator<<(std::ostream &out, const RsPostedPost &post);
|
||||
|
@ -100,7 +101,7 @@ virtual ~RsPosted() { return; }
|
|||
virtual bool getPost(const uint32_t &token, PostedPostResult &post) = 0;
|
||||
virtual bool getComment(const uint32_t &token, PostedCommentResult &comment) = 0;
|
||||
virtual bool getRelatedComment(const uint32_t& token, PostedRelatedCommentResult& comments) = 0;
|
||||
virtual bool getRanking(const uint32_t& token, PostedRanking& ranking) = 0;
|
||||
virtual bool getPostRanking(const uint32_t& token, RsPostedPostRanking& ranking) = 0;
|
||||
|
||||
virtual bool submitGroup(uint32_t &token, RsPostedGroup &group) = 0;
|
||||
virtual bool submitPost(uint32_t &token, RsPostedPost &post) = 0;
|
||||
|
@ -116,7 +117,7 @@ virtual ~RsPosted() { return; }
|
|||
* @param rType
|
||||
* @param groupId
|
||||
*/
|
||||
virtual bool requestMessageRankings(uint32_t &token, const RankType& rType, const RsGxsGroupId& groupId) = 0;
|
||||
virtual bool requestPostRankings(uint32_t &token, const RankType& rType, const RsGxsGroupId& groupId) = 0;
|
||||
|
||||
/*!
|
||||
* Makes request for ranking of comments for a post
|
||||
|
@ -175,4 +176,12 @@ class RsPostedComment
|
|||
RsMsgMetaData mMeta;
|
||||
};
|
||||
|
||||
class RsPostedPostRanking
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsGroupId grpId;
|
||||
PostedRanking ranking;
|
||||
RsPosted::RankType rType;
|
||||
};
|
||||
#endif // RSPOSTED_H
|
||||
|
|
|
@ -186,9 +186,21 @@ void RsServer::rsGlobalShutDown()
|
|||
mPluginsManager->stopPlugins();
|
||||
|
||||
// stop the p3distrib threads
|
||||
|
||||
mForums->join();
|
||||
mChannels->join();
|
||||
|
||||
if(mGxsCircles) mGxsCircles->join();
|
||||
if(mGxsForums) mGxsForums->join();
|
||||
if(mGxsIdService) mGxsIdService->join();
|
||||
if(mPosted) mPosted->join();
|
||||
if(mPhoto) mPhoto->join();
|
||||
if(mWiki) mWiki->join();
|
||||
if(mWire) mWire->join();
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef RS_USE_BLOGS
|
||||
mBlogs->join();
|
||||
#endif
|
||||
|
|
|
@ -76,6 +76,15 @@ RsServer::RsServer(RsIface &i, NotifyBase &callback)
|
|||
/* Config */
|
||||
mConfigMgr = NULL;
|
||||
mGeneralConfig = NULL;
|
||||
|
||||
/* GXS */
|
||||
mPhoto = NULL;
|
||||
mWiki = NULL;
|
||||
mPosted = NULL;
|
||||
mGxsCircles = NULL;
|
||||
mGxsIdService = NULL;
|
||||
mGxsForums = NULL;
|
||||
mWire = NULL;
|
||||
}
|
||||
|
||||
RsServer::~RsServer()
|
||||
|
|
|
@ -45,6 +45,15 @@
|
|||
#include "services/p3channels.h"
|
||||
#include "services/p3forums.h"
|
||||
|
||||
#include "services/p3idservice.h"
|
||||
#include "services/p3gxscircles.h"
|
||||
#include "services/p3wiki.h"
|
||||
#include "services/p3posted.h"
|
||||
#include "services/p3photoservice.h"
|
||||
#include "services/p3gxsforums.h"
|
||||
#include "services/p3wire.h"
|
||||
|
||||
|
||||
class p3PeerMgrIMPL;
|
||||
class p3LinkMgrIMPL;
|
||||
class p3NetMgrIMPL;
|
||||
|
@ -175,6 +184,16 @@ class RsServer: public RsControl, public RsThread
|
|||
p3Forums *mForums;
|
||||
/* caches (that need ticking) */
|
||||
|
||||
/* GXS */
|
||||
|
||||
p3Wiki *mWiki;
|
||||
p3Posted *mPosted;
|
||||
p3PhotoService *mPhoto;
|
||||
p3GxsCircles *mGxsCircles;
|
||||
p3IdService *mGxsIdService;
|
||||
p3GxsForums *mGxsForums;
|
||||
p3Wire *mWire;
|
||||
|
||||
/* Config */
|
||||
p3ConfigMgr *mConfigMgr;
|
||||
p3GeneralConfig *mGeneralConfig;
|
||||
|
|
|
@ -1823,15 +1823,6 @@ RsTurtle *rsTurtle = NULL ;
|
|||
#include "gxs/rsgxsflags.h"
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_GXS_SERVICES
|
||||
#include "services/p3idservice.h"
|
||||
#include "services/p3gxscircles.h"
|
||||
#include "services/p3wiki.h"
|
||||
#include "services/p3posted.h"
|
||||
#include "services/p3photoservice.h"
|
||||
#include "services/p3gxsforums.h"
|
||||
#include "services/p3wire.h"
|
||||
#endif
|
||||
|
||||
#ifndef PQI_DISABLE_TUNNEL
|
||||
#include "services/p3tunnel.h"
|
||||
|
@ -2302,8 +2293,6 @@ int RsServer::StartupRetroShare()
|
|||
|
||||
/**** Identity service ****/
|
||||
|
||||
p3IdService *mGxsIdService = NULL;
|
||||
|
||||
RsGeneralDataService* gxsid_ds = new RsDataService(currGxsDir + "/", "gxsid_db",
|
||||
RS_SERVICE_GXSV1_TYPE_GXSID, NULL);
|
||||
|
||||
|
@ -2318,7 +2307,6 @@ int RsServer::StartupRetroShare()
|
|||
|
||||
/**** GxsCircle service ****/
|
||||
|
||||
p3GxsCircles *mGxsCircles = NULL;
|
||||
|
||||
RsGeneralDataService* gxscircles_ds = new RsDataService(currGxsDir + "/", "gxscircles_db",
|
||||
RS_SERVICE_GXSV1_TYPE_GXSCIRCLE, NULL);
|
||||
|
@ -2354,8 +2342,6 @@ int RsServer::StartupRetroShare()
|
|||
RsGenExchange::setAuthenPolicyFlag(flag, photoAuthenPolicy,
|
||||
RsGenExchange::GRP_OPTION_BITS);
|
||||
|
||||
p3PhotoService *mPhoto = NULL;
|
||||
|
||||
|
||||
RsGeneralDataService* photo_ds = new RsDataService(currGxsDir + "/", "photoV2_db",
|
||||
RS_SERVICE_GXSV1_TYPE_PHOTO, NULL);
|
||||
|
@ -2372,7 +2358,7 @@ int RsServer::StartupRetroShare()
|
|||
|
||||
/**** Posted GXS service ****/
|
||||
|
||||
p3Posted *mPosted = NULL;
|
||||
|
||||
|
||||
RsGeneralDataService* posted_ds = new RsDataService(currGxsDir + "/", "posted_db",
|
||||
RS_SERVICE_GXSV1_TYPE_POSTED);
|
||||
|
@ -2388,7 +2374,7 @@ int RsServer::StartupRetroShare()
|
|||
|
||||
/**** Wiki GXS service ****/
|
||||
|
||||
p3Wiki *mWiki = NULL;
|
||||
|
||||
|
||||
RsGeneralDataService* wiki_ds = new RsDataService(currGxsDir + "/", "wiki_db",
|
||||
RS_SERVICE_GXSV1_TYPE_WIKI);
|
||||
|
@ -2404,7 +2390,6 @@ int RsServer::StartupRetroShare()
|
|||
|
||||
/**** Wire GXS service ****/
|
||||
|
||||
p3Wire *mWire = NULL;
|
||||
|
||||
RsGeneralDataService* wire_ds = new RsDataService(currGxsDir + "/", "wire_db",
|
||||
RS_SERVICE_GXSV1_TYPE_WIRE);
|
||||
|
@ -2420,8 +2405,6 @@ int RsServer::StartupRetroShare()
|
|||
|
||||
/**** Forum GXS service ****/
|
||||
|
||||
p3GxsForums *mGxsForums = NULL;
|
||||
|
||||
RsGeneralDataService* gxsforums_ds = new RsDataService(currGxsDir + "/", "gxsforums_db",
|
||||
RS_SERVICE_GXSV1_TYPE_FORUMS);
|
||||
|
||||
|
|
|
@ -15,12 +15,12 @@
|
|||
#define UPDATE_PHASE_COMMENT_COUNT 5
|
||||
#define UPDATE_PHASE_COMPLETE 6
|
||||
|
||||
#define NUM_TOPICS_TO_GENERATE 1
|
||||
#define NUM_POSTS_TO_GENERATE 1
|
||||
#define NUM_VOTES_TO_GENERATE 23
|
||||
#define NUM_COMMENTS_TO_GENERATE 23
|
||||
#define NUM_TOPICS_TO_GENERATE 7
|
||||
#define NUM_POSTS_TO_GENERATE 7
|
||||
#define NUM_VOTES_TO_GENERATE 11
|
||||
#define NUM_COMMENTS_TO_GENERATE 4
|
||||
|
||||
#define VOTE_UPDATE_PERIOD 30 // 20 seconds
|
||||
#define VOTE_UPDATE_PERIOD 5 // 20 seconds
|
||||
|
||||
const uint32_t RsPosted::FLAG_MSGTYPE_COMMENT = 0x0001;
|
||||
const uint32_t RsPosted::FLAG_MSGTYPE_POST = 0x0002;
|
||||
|
@ -77,6 +77,8 @@ void p3Posted::service_tick()
|
|||
}
|
||||
|
||||
updateVotes();
|
||||
|
||||
processRankings();
|
||||
}
|
||||
|
||||
void p3Posted::generateVotesAndComments()
|
||||
|
@ -157,6 +159,7 @@ void p3Posted::generateVotesAndComments()
|
|||
c.mComment = "Comment " + ostrm.str();
|
||||
c.mMeta.mParentId = msgId;
|
||||
c.mMeta.mGroupId = grpId;
|
||||
c.mMeta.mThreadId = msgId;
|
||||
|
||||
submitComment(token, c);
|
||||
mTokens.push_back(token);
|
||||
|
@ -490,7 +493,7 @@ bool p3Posted::requestCommentRankings(uint32_t &token, const RankType &rType, co
|
|||
return true;
|
||||
}
|
||||
|
||||
bool p3Posted::requestMessageRankings(uint32_t &token, const RankType &rType, const RsGxsGroupId &groupId)
|
||||
bool p3Posted::requestPostRankings(uint32_t &token, const RankType &rType, const RsGxsGroupId &groupId)
|
||||
{
|
||||
token = RsGenExchange::generatePublicToken();
|
||||
|
||||
|
@ -499,64 +502,111 @@ bool p3Posted::requestMessageRankings(uint32_t &token, const RankType &rType, co
|
|||
gp->grpId = groupId;
|
||||
gp->rType = rType;
|
||||
gp->pubToken = token;
|
||||
gp->rankingResult.rType = gp->rType;
|
||||
gp->grpId = gp->grpId;
|
||||
|
||||
mPendingPostRanks.insert(std::make_pair(token, gp));
|
||||
mPendingPostRanks.push_back(gp);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3Posted::getRanking(const uint32_t &token, PostedRanking &ranking)
|
||||
bool p3Posted::getPostRanking(const uint32_t &token, RsPostedPostRanking &ranking)
|
||||
{
|
||||
RsStackMutex stack(mPostedMutex);
|
||||
|
||||
if( mCompletePostRanks.find(token) == mCompletePostRanks.end()) return false;
|
||||
|
||||
ranking = mCompletePostRanks[token];
|
||||
mCompletePostRanks.erase(token);
|
||||
|
||||
// put this in service tick as it's blocking
|
||||
// and likely costly
|
||||
disposeOfPublicToken(token);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void p3Posted::processRankings()
|
||||
{
|
||||
processMessageRanks();
|
||||
// processPostRanks();
|
||||
|
||||
processCommentRanks();
|
||||
//processCommentRanks();
|
||||
}
|
||||
|
||||
void p3Posted::processMessageRanks()
|
||||
void p3Posted::processPostRanks()
|
||||
{
|
||||
|
||||
RsStackMutex stack(mPostedMutex);
|
||||
std::map<uint32_t, GxsPostedPostRanking*>::iterator mit =mPendingPostRanks.begin();
|
||||
|
||||
std::vector<GxsPostedPostRanking*>::iterator vit = mPendingPostRanks.begin();
|
||||
|
||||
// go through all pending posts
|
||||
for(; mit !=mPendingPostRanks.begin(); mit++)
|
||||
for(; vit !=mPendingPostRanks.begin(); )
|
||||
{
|
||||
GxsPostedPostRanking* gp = *vit;
|
||||
uint32_t token;
|
||||
std::list<RsGxsGroupId> grpL;
|
||||
grpL.push_back(mit->second->grpId);
|
||||
grpL.push_back(gp->grpId);
|
||||
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_MSG_META;
|
||||
opts.mMsgFlagFilter = RsPosted::FLAG_MSGTYPE_POST;
|
||||
opts.mMsgFlagMask = RsPosted::FLAG_MSGTYPE_MASK;
|
||||
opts.mOptions = RS_TOKREQOPT_MSG_LATEST | RS_TOKREQOPT_MSG_THREAD;
|
||||
|
||||
RsGenExchange::getTokenService()->requestMsgInfo(token, GXS_REQUEST_TYPE_GROUP_DATA, opts, grpL);
|
||||
GxsPostedPostRanking* gp = mit->second;
|
||||
|
||||
|
||||
gp->reqToken = token;
|
||||
|
||||
while(true)
|
||||
{
|
||||
uint32_t status = mTokenService->requestStatus(token);
|
||||
|
||||
if(RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE
|
||||
== status)
|
||||
{
|
||||
completePostedPostCalc(gp);
|
||||
break;
|
||||
}
|
||||
else if(RsTokenService::GXS_REQUEST_V2_STATUS_FAILED
|
||||
== status)
|
||||
{
|
||||
discardCalc(token);
|
||||
break;
|
||||
}
|
||||
}
|
||||
vit = mPendingPostRanks.erase(vit);
|
||||
mCompletionPostRanks.push_back(gp);
|
||||
}
|
||||
|
||||
mPendingPostRanks.clear();
|
||||
|
||||
vit = mCompletionPostRanks.begin();
|
||||
|
||||
for(; vit != mCompletionPostRanks.end(); )
|
||||
{
|
||||
bool ok = false;
|
||||
GxsPostedPostRanking *gp = *vit;
|
||||
uint32_t status = mTokenService->requestStatus(gp->reqToken);
|
||||
|
||||
if(RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE
|
||||
== status)
|
||||
{
|
||||
ok = completePostedPostCalc(gp);
|
||||
|
||||
if(ok)
|
||||
{
|
||||
mCompletePostRanks.insert(
|
||||
std::make_pair(gp->pubToken, gp->rankingResult));
|
||||
}
|
||||
}
|
||||
else if(RsTokenService::GXS_REQUEST_V2_STATUS_FAILED
|
||||
== status)
|
||||
{
|
||||
discardCalc(gp->reqToken);
|
||||
ok = false;
|
||||
}else
|
||||
{
|
||||
vit++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(ok)
|
||||
{
|
||||
updatePublicRequestStatus(gp->pubToken, RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE);
|
||||
}
|
||||
else
|
||||
{
|
||||
updatePublicRequestStatus(gp->pubToken, RsTokenService::GXS_REQUEST_V2_STATUS_FAILED);
|
||||
}
|
||||
|
||||
vit = mCompletionPostRanks.erase(vit);
|
||||
delete gp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -617,25 +667,27 @@ bool PostedBestScoreComp(const PostedScore& i, const PostedScore& j)
|
|||
return i_score < j_score;
|
||||
}
|
||||
|
||||
void p3Posted::completePostedPostCalc(GxsPostedPostRanking *gpp)
|
||||
bool p3Posted::completePostedPostCalc(GxsPostedPostRanking *gpp)
|
||||
{
|
||||
GxsMsgMetaMap msgMetas;
|
||||
|
||||
if(getMsgMeta(gpp->reqToken, msgMetas))
|
||||
{
|
||||
std::vector<RsMsgMetaData> msgMetaV = msgMetas[gpp->grpId];
|
||||
std::vector<RsMsgMetaData>& msgMetaV = msgMetas[gpp->grpId];
|
||||
switch(gpp->rType)
|
||||
{
|
||||
case NewRankType:
|
||||
calcPostedPostRank(msgMetaV, gpp->rankingResult, PostedNewScoreComp);
|
||||
calcPostedPostRank(msgMetaV, gpp->rankingResult.ranking, PostedNewScoreComp);
|
||||
break;
|
||||
case TopRankType:
|
||||
calcPostedPostRank(msgMetaV, gpp->rankingResult, PostedTopScoreComp);
|
||||
calcPostedPostRank(msgMetaV, gpp->rankingResult.ranking, PostedTopScoreComp);
|
||||
break;
|
||||
default:
|
||||
std::cerr << "Unknown ranking tpye: " << gpp->rType << std::endl;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -667,7 +719,7 @@ void p3Posted::calcPostedPostRank(const std::vector<RsMsgMetaData > msgMeta, Pos
|
|||
for(; vit != scores.end(); vit++)
|
||||
{
|
||||
const PostedScore& p = *vit;
|
||||
ranking.insert(std::make_pair(p.msgId, i++));
|
||||
ranking.insert(std::make_pair(i++, p.msgId));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -713,7 +765,7 @@ void p3Posted::calcPostedCommentsRank(const std::map<RsGxsMessageId, std::vector
|
|||
for(; cvit != scores.end(); cvit)
|
||||
{
|
||||
const PostedScore& p = *cvit;
|
||||
ranking.insert(std::make_pair(p.msgId, i++));
|
||||
ranking.insert(std::make_pair(i++, p.msgId));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ public:
|
|||
uint32_t reqToken;
|
||||
RsPosted::RankType rType;
|
||||
RsGxsGroupId grpId;
|
||||
PostedRanking rankingResult;
|
||||
RsPostedPostRanking rankingResult;
|
||||
};
|
||||
|
||||
class GxsPostedCommentRanking
|
||||
|
@ -82,14 +82,14 @@ public:
|
|||
bool getPost(const uint32_t &token, PostedPostResult& posts) ;
|
||||
bool getComment(const uint32_t &token, PostedCommentResult& comments) ;
|
||||
bool getRelatedComment(const uint32_t& token, PostedRelatedCommentResult &comments);
|
||||
bool getRanking(const uint32_t &token, PostedRanking &ranking);
|
||||
bool getPostRanking(const uint32_t &token, RsPostedPostRanking &ranking);
|
||||
|
||||
bool submitGroup(uint32_t &token, RsPostedGroup &group);
|
||||
bool submitPost(uint32_t &token, RsPostedPost &post);
|
||||
bool submitVote(uint32_t &token, RsPostedVote &vote);
|
||||
bool submitComment(uint32_t &token, RsPostedComment &comment) ;
|
||||
// Special Ranking Request.
|
||||
bool requestMessageRankings(uint32_t &token, const RankType &rType, const RsGxsGroupId &groupId);
|
||||
bool requestPostRankings(uint32_t &token, const RankType &rType, const RsGxsGroupId &groupId);
|
||||
bool requestCommentRankings(uint32_t &token, const RankType &rType, const RsGxsGrpMsgIdPair &msgId);
|
||||
|
||||
bool retrieveScores(const std::string& serviceString, uint32_t& upVotes, uint32_t& downVotes, uint32_t& nComments) const;
|
||||
|
@ -99,10 +99,10 @@ private:
|
|||
/* Functions for processing rankings */
|
||||
|
||||
void processRankings();
|
||||
void processMessageRanks();
|
||||
void processPostRanks();
|
||||
void processCommentRanks();
|
||||
void discardCalc(const uint32_t& token);
|
||||
void completePostedPostCalc(GxsPostedPostRanking* gpp);
|
||||
bool completePostedPostCalc(GxsPostedPostRanking* gpp);
|
||||
void completePostedCommentRanking(GxsPostedCommentRanking* gpc);
|
||||
|
||||
bool storeScores(std::string& serviceString, uint32_t& upVotes, uint32_t downVotes, uint32_t nComments) const;
|
||||
|
@ -142,8 +142,9 @@ private:
|
|||
private:
|
||||
|
||||
// for calculating ranks
|
||||
std::map<uint32_t, GxsPostedPostRanking*> mPendingPostRanks;
|
||||
std::map<uint32_t, GxsPostedPostRanking*> mPendingCalculationPostRanks;
|
||||
std::vector<GxsPostedPostRanking*> mPendingPostRanks;
|
||||
std::vector<GxsPostedPostRanking*> mCompletionPostRanks;
|
||||
std::map<uint32_t, RsPostedPostRanking> mCompletePostRanks;
|
||||
std::map<uint32_t, GxsPostedCommentRanking*> mPendingCommentRanks;
|
||||
std::map<uint32_t, GxsPostedCommentRanking*> mPendingCalculationCommentRanks;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue