mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
- Split majority of p3posted into p3postbase.cc - so that it can be reused by other services.
- Fixed iterator overflow into rsgxsupdateitems.cc - Fixed Mutex deadlock in pqiperson.cc - Removed old code. - Fixed lots of compile warnings - mainly wrong variable ordering in constructors. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-initdev@7044 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
46518ebf51
commit
ae5942733e
@ -436,11 +436,13 @@ private:
|
||||
private:
|
||||
|
||||
RsGeneralDataService* mDataStore;
|
||||
|
||||
RsMutex mDataMutex; /* protecting below */
|
||||
|
||||
uint32_t mNextToken;
|
||||
std::map<uint32_t, uint32_t> mPublicToken;
|
||||
std::map<uint32_t, GxsRequest*> mRequests;
|
||||
|
||||
RsMutex mDataMutex;
|
||||
|
||||
|
||||
};
|
||||
|
@ -1646,10 +1646,13 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
|
||||
RsNxsSyncGrpItem*& grpSyncItem = *llit;
|
||||
const std::string& grpId = grpSyncItem->grpId;
|
||||
metaIter = grpMetaMap.find(grpId);
|
||||
bool haveItem = metaIter != grpMetaMap.end();
|
||||
bool haveItem = false;
|
||||
bool latestVersion = false;
|
||||
|
||||
if (metaIter != grpMetaMap.end())
|
||||
{
|
||||
haveItem = true;
|
||||
latestVersion = grpSyncItem->publishTs > metaIter->second->mPublishTs;
|
||||
}
|
||||
|
||||
if(!haveItem || (haveItem && latestVersion) ){
|
||||
|
||||
|
@ -143,7 +143,7 @@ class GroupUpdatePublish
|
||||
{
|
||||
public:
|
||||
GroupUpdatePublish(RsGxsGrpItem* item, RsGxsGroupUpdateMeta updateMeta, uint32_t token)
|
||||
: grpItem(item), mToken(token), mUpdateMeta(updateMeta) {}
|
||||
: grpItem(item), mUpdateMeta(updateMeta), mToken(token) {}
|
||||
RsGxsGrpItem* grpItem;
|
||||
RsGxsGroupUpdateMeta mUpdateMeta;
|
||||
uint32_t mToken;
|
||||
|
@ -711,11 +711,13 @@ gxs {
|
||||
serialiser/rswireitems.cc \
|
||||
|
||||
# Posted Service
|
||||
HEADERS += services/p3posted.h \
|
||||
HEADERS += services/p3postbase.h \
|
||||
services/p3posted.h \
|
||||
retroshare/rsposted.h \
|
||||
serialiser/rsposteditems.h
|
||||
|
||||
SOURCES += services/p3posted.cc \
|
||||
SOURCES += services/p3postbase.cc \
|
||||
services/p3posted.cc \
|
||||
serialiser/rsposteditems.cc
|
||||
|
||||
#Photo Service
|
||||
|
@ -151,7 +151,7 @@ int pqiperson::tick()
|
||||
out += " No Heartbeat & No Packets -> assume dead. calling pqissl::reset()";
|
||||
pqioutput(PQL_WARNING, pqipersonzone, out);
|
||||
|
||||
this->reset();
|
||||
this->reset_locked();
|
||||
}
|
||||
|
||||
}
|
||||
@ -384,6 +384,11 @@ int pqiperson::reset()
|
||||
{
|
||||
RsStackMutex stack(mPersonMtx); /**** LOCK MUTEX ****/
|
||||
|
||||
return reset_locked();
|
||||
}
|
||||
|
||||
int pqiperson::reset_locked()
|
||||
{
|
||||
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::reset() resetting all pqiconnect for Id: " + PeerId());
|
||||
|
||||
std::map<uint32_t, pqiconnect *>::iterator it;
|
||||
|
@ -179,6 +179,8 @@ int handleNotifyEvent_locked(NetInterface *ni, int event, const struct socka
|
||||
|
||||
RsMutex mPersonMtx; /**** LOCKS below ****/
|
||||
|
||||
int reset_locked();
|
||||
|
||||
void setRateCap_locked(float val_in, float val_out);
|
||||
|
||||
std::map<uint32_t, pqiconnect *> kids;
|
||||
|
@ -93,16 +93,15 @@ static const int PQISSL_SSL_CONNECT_TIMEOUT = 30;
|
||||
|
||||
pqissl::pqissl(pqissllistener *l, PQInterface *parent, p3LinkMgr *lm)
|
||||
:NetBinInterface(parent, parent->PeerId()),
|
||||
mLinkMgr(lm), pqil(l),
|
||||
mSslMtx("pqissl"),
|
||||
waiting(WAITING_NOT), active(false), certvalid(false),
|
||||
active(false), certvalid(false), waiting(WAITING_NOT),
|
||||
sslmode(PQISSL_ACTIVE), ssl_connection(NULL), sockfd(-1),
|
||||
pqil(l), // no init for remote_addr.
|
||||
readpkt(NULL), pktlen(0),
|
||||
readpkt(NULL), pktlen(0), total_len(0),
|
||||
attempt_ts(0),
|
||||
sameLAN(false), n_read_zero(0), mReadZeroTS(0),
|
||||
mConnectDelay(0), mConnectTS(0),
|
||||
mConnectTimeout(0), mTimeoutTS(0), mLinkMgr(lm)
|
||||
|
||||
mConnectTimeout(0), mTimeoutTS(0)
|
||||
{
|
||||
RsStackMutex stack(mSslMtx); /**** LOCKED MUTEX ****/
|
||||
|
||||
|
@ -32,7 +32,7 @@
|
||||
#define DEFAULT_STREAMER_IDLE_SLEEP 1000000 // 1 sec
|
||||
|
||||
pqithreadstreamer::pqithreadstreamer(PQInterface *parent, RsSerialiser *rss, std::string id, BinInterface *bio_in, int bio_flags_in)
|
||||
:pqistreamer(rss, id, bio_in, bio_flags_in), mThreadMutex("pqithreadstreamer"), mParent(parent), mTimeout(0)
|
||||
:pqistreamer(rss, id, bio_in, bio_flags_in), mParent(parent), mThreadMutex("pqithreadstreamer"), mTimeout(0)
|
||||
{
|
||||
mTimeout = DEFAULT_STREAMER_TIMEOUT;
|
||||
mSleepPeriod = DEFAULT_STREAMER_SLEEP;
|
||||
|
@ -82,7 +82,6 @@ class RsPosted : public RsGxsIfaceHelper, public RsGxsCommentService
|
||||
virtual ~RsPosted() { return; }
|
||||
|
||||
/* Specific Service Data */
|
||||
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsPostedGroup> &groups) = 0;
|
||||
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts) = 0;
|
||||
virtual bool getRelatedPosts(const uint32_t &token, std::vector<RsPostedPost> &posts) = 0;
|
||||
|
@ -51,7 +51,7 @@ void RsGxsMsgUpdateItem::clear()
|
||||
|
||||
std::ostream& RsGxsMsgUpdateItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
@ -64,7 +64,7 @@ void RsGxsServerMsgUpdateItem::clear()
|
||||
|
||||
std::ostream& RsGxsServerMsgUpdateItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
@ -75,7 +75,7 @@ void RsGxsServerGrpUpdateItem::clear()
|
||||
|
||||
std::ostream& RsGxsServerGrpUpdateItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1165,7 +1165,7 @@ bool p3GxsChannels::generateVote(uint32_t &token, const RsGxsGroupId &grpId, con
|
||||
|
||||
uint32_t idx = (uint32_t) (ownIds.size() * RSRandom::random_f32());
|
||||
uint32_t i = 0;
|
||||
for(it = ownIds.begin(); (it != ownIds.end()) && (i < idx); it++, i++);
|
||||
for(it = ownIds.begin(); (it != ownIds.end()) && (i < idx); it++, i++) ;
|
||||
|
||||
if (it != ownIds.end())
|
||||
{
|
||||
|
@ -1511,7 +1511,7 @@ void p3GxsCircles::generateDummyCircle()
|
||||
|
||||
int selection = (RSRandom::random_u32() % npgps);
|
||||
std::list<RsGxsId>::iterator it = mDummyPgpLinkedIds.begin();
|
||||
for(int j = 0; (it != mDummyPgpLinkedIds.end()) && (j < selection); j++, it++);
|
||||
for(int j = 0; (it != mDummyPgpLinkedIds.end()) && (j < selection); j++, it++) ;
|
||||
if (it != mDummyPgpLinkedIds.end())
|
||||
{
|
||||
idset.insert(*it);
|
||||
@ -1525,7 +1525,7 @@ void p3GxsCircles::generateDummyCircle()
|
||||
int selection = (RSRandom::random_u32() % mDummyOwnIds.size());
|
||||
std::list<RsGxsId>::iterator it = mDummyOwnIds.begin();
|
||||
mDummyOwnIds.push_back(*it);
|
||||
for(int j = 0; (it != mDummyOwnIds.end()) && (j < selection); j++, it++);
|
||||
for(int j = 0; (it != mDummyOwnIds.end()) && (j < selection); j++, it++) ;
|
||||
if (it != mDummyOwnIds.end())
|
||||
{
|
||||
idset.insert(*it);
|
||||
|
@ -438,7 +438,7 @@ bool p3GxsForums::generateMessage(uint32_t &token, const RsGxsGroupId &grpId, co
|
||||
|
||||
uint32_t idx = (uint32_t) (ownIds.size() * RSRandom::random_f32());
|
||||
int i = 0;
|
||||
for(it = ownIds.begin(); (it != ownIds.end()) && (i < idx); it++, i++);
|
||||
for(it = ownIds.begin(); (it != ownIds.end()) && (i < idx); it++, i++) ;
|
||||
|
||||
if (it != ownIds.end())
|
||||
{
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,191 +0,0 @@
|
||||
/*
|
||||
* libretroshare/src/services p3gxsservice.h
|
||||
*
|
||||
* Generic Service Support Class for RetroShare.
|
||||
*
|
||||
* Copyright 2012 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef P3_GXS_SERVICE_HEADER
|
||||
#define P3_GXS_SERVICE_HEADER
|
||||
|
||||
#include "services/p3service.h"
|
||||
#include "retroshare/rsidentityVEG.h"
|
||||
|
||||
/*
|
||||
* This class provides useful generic support for GXS style services.
|
||||
* I expect much of this will be incorporated into the base GXS.
|
||||
*
|
||||
*/
|
||||
|
||||
#define GXS_REQUEST_STATUS_FAILED 0
|
||||
#define GXS_REQUEST_STATUS_PENDING 1
|
||||
#define GXS_REQUEST_STATUS_PARTIAL 2
|
||||
#define GXS_REQUEST_STATUS_FINISHED_INCOMPLETE 3
|
||||
#define GXS_REQUEST_STATUS_COMPLETE 4
|
||||
#define GXS_REQUEST_STATUS_DONE 5 // ONCE ALL DATA RETRIEVED.
|
||||
|
||||
#define GXS_REQUEST_TYPE_GROUPS 0x00010000
|
||||
#define GXS_REQUEST_TYPE_MSGS 0x00020000
|
||||
#define GXS_REQUEST_TYPE_MSGRELATED 0x00040000
|
||||
|
||||
class gxsRequest
|
||||
{
|
||||
public:
|
||||
uint32_t token;
|
||||
uint32_t reqTime;
|
||||
|
||||
uint32_t ansType;
|
||||
uint32_t reqType;
|
||||
RsTokReqOptionsVEG Options;
|
||||
|
||||
uint32_t status;
|
||||
|
||||
std::list<std::string> inList;
|
||||
std::list<std::string> outList;
|
||||
//std::map<std::string, void *> readyData;
|
||||
};
|
||||
|
||||
|
||||
class p3GxsServiceVEG: public p3Service
|
||||
{
|
||||
protected:
|
||||
|
||||
p3GxsServiceVEG(uint16_t type);
|
||||
|
||||
public:
|
||||
|
||||
//virtual ~p3Service() { p3Service::~p3Service(); return; }
|
||||
|
||||
bool generateToken(uint32_t &token);
|
||||
bool storeRequest(const uint32_t &token, const uint32_t &ansType, const RsTokReqOptionsVEG &opts, const uint32_t &type, const std::list<std::string> &ids);
|
||||
bool clearRequest(const uint32_t &token);
|
||||
|
||||
bool updateRequestStatus(const uint32_t &token, const uint32_t &status);
|
||||
bool updateRequestInList(const uint32_t &token, std::list<std::string> ids);
|
||||
bool updateRequestOutList(const uint32_t &token, std::list<std::string> ids);
|
||||
//bool updateRequestData(const uint32_t &token, std::map<std::string, void *> data);
|
||||
bool checkRequestStatus(const uint32_t &token, uint32_t &status, uint32_t &reqtype, uint32_t &anstype, time_t &ts);
|
||||
|
||||
// special ones for testing (not in final design)
|
||||
bool tokenList(std::list<uint32_t> &tokens);
|
||||
bool popRequestInList(const uint32_t &token, std::string &id);
|
||||
bool popRequestOutList(const uint32_t &token, std::string &id);
|
||||
bool loadRequestOutList(const uint32_t &token, std::list<std::string> &ids);
|
||||
|
||||
virtual bool fakeprocessrequests();
|
||||
|
||||
protected:
|
||||
|
||||
RsMutex mReqMtx;
|
||||
|
||||
uint32_t mNextToken;
|
||||
|
||||
std::map<uint32_t, gxsRequest> mRequests;
|
||||
|
||||
};
|
||||
|
||||
|
||||
class GxsDataProxyVEG
|
||||
{
|
||||
public:
|
||||
|
||||
GxsDataProxyVEG();
|
||||
|
||||
virtual bool getGroupList( uint32_t &token, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds, std::list<std::string> &outGroupIds);
|
||||
virtual bool getMsgList( uint32_t &token, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds, std::list<std::string> &outMsgIds);
|
||||
virtual bool getMsgRelatedList(uint32_t &token, const RsTokReqOptionsVEG &opts, const std::list<std::string> &msgIds, std::list<std::string> &outMsgIds);
|
||||
|
||||
|
||||
/* This functions return a token - which can be used to retrieve the RsGroupMetaData, later
|
||||
* This is required, as signatures and keys might have to be generated in the background
|
||||
* Though at the moment: for this test system it won't change anything? FIXME.
|
||||
*/
|
||||
virtual bool createGroup(void *groupData);
|
||||
virtual bool createMsg(void *msgData);
|
||||
|
||||
/* These Functions must be overloaded to complete the service */
|
||||
virtual bool convertGroupToMetaData(void *groupData, RsGroupMetaData &meta);
|
||||
virtual bool convertMsgToMetaData(void *groupData, RsMsgMetaData &meta);
|
||||
|
||||
/* extract Data */
|
||||
bool getGroupSummary(const std::list<std::string> &groupIds, std::list<RsGroupMetaData> &groupSummary);
|
||||
bool getMsgSummary(const std::list<std::string> &msgIds, std::list<RsMsgMetaData> &msgSummary);
|
||||
|
||||
bool getGroupSummary(const std::string &groupId, RsGroupMetaData &groupSummary);
|
||||
bool getMsgSummary(const std::string &msgId, RsMsgMetaData &msgSummary);
|
||||
|
||||
//bool getGroupData(const std::list<std::string> &groupIds, std::list<void *> &groupData);
|
||||
//bool getMsgData(const std::list<std::string> &msgIds, std::list<void *> &msgData);
|
||||
bool getGroupData(const std::string &groupId, void * &groupData);
|
||||
bool getMsgData(const std::string &msgId, void * &msgData);
|
||||
|
||||
bool isUniqueGroup(const std::string &groupId);
|
||||
bool isUniqueMsg(const std::string &msgId);
|
||||
|
||||
|
||||
/* Handle Status & Subscribe Modes */
|
||||
// This is removed as redundant - use getGroupList - with OptFlags to find these.
|
||||
//virtual bool requestGroupsChanged(uint32_t &token); //std::list<std::string> &groupIds);
|
||||
|
||||
// Get Message Status - is retrived via MessageSummary.
|
||||
// These operations could have a token, but for the moment we are going to assume
|
||||
// they are async and always succeed - (or fail silently).
|
||||
virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask);
|
||||
virtual bool setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask);
|
||||
virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask);
|
||||
|
||||
virtual bool setMessageServiceString(const std::string &msgId, const std::string &str);
|
||||
virtual bool setGroupServiceString(const std::string &grpId, const std::string &str);
|
||||
|
||||
protected:
|
||||
|
||||
bool filterGroupList(const RsTokReqOptionsVEG &opts, std::list<std::string> &groupIds);
|
||||
bool filterMsgList(const RsTokReqOptionsVEG &opts, std::list<std::string> &msgIds);
|
||||
|
||||
|
||||
RsMutex mDataMtx;
|
||||
|
||||
std::map<std::string, void *> mGroupData;
|
||||
std::map<std::string, void *> mMsgData;
|
||||
|
||||
std::map<std::string, RsGroupMetaData> mGroupMetaData;
|
||||
std::map<std::string, RsMsgMetaData> mMsgMetaData;
|
||||
|
||||
};
|
||||
|
||||
|
||||
class p3GxsDataServiceVEG: public p3GxsServiceVEG
|
||||
{
|
||||
public:
|
||||
|
||||
p3GxsDataServiceVEG(uint16_t type, GxsDataProxyVEG *proxy);
|
||||
virtual bool fakeprocessrequests();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
GxsDataProxyVEG *mProxy;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // P3_GXS_SERVICE_HEADER
|
||||
|
@ -139,9 +139,10 @@ RsIdentity *rsIdentity = NULL;
|
||||
|
||||
p3IdService::p3IdService(RsGeneralDataService *gds, RsNetworkExchangeService *nes)
|
||||
: RsGxsIdExchange(gds, nes, new RsGxsIdSerialiser(), RS_SERVICE_GXSV2_TYPE_GXSID, idAuthenPolicy()),
|
||||
RsIdentity(this), GxsTokenQueue(this), RsTickEvent(), mIdMtx("p3IdService"),
|
||||
RsIdentity(this), GxsTokenQueue(this), RsTickEvent(),
|
||||
mPublicKeyCache(DEFAULT_MEM_CACHE_SIZE, "GxsIdPublicKeyCache"),
|
||||
mPrivateKeyCache(DEFAULT_MEM_CACHE_SIZE, "GxsIdPrivateKeyCache"), mNes(nes)
|
||||
mPrivateKeyCache(DEFAULT_MEM_CACHE_SIZE, "GxsIdPrivateKeyCache"),
|
||||
mIdMtx("p3IdService"), mNes(nes)
|
||||
{
|
||||
mBgSchedule_Mode = 0;
|
||||
mBgSchedule_Active = false;
|
||||
@ -2884,7 +2885,7 @@ void p3IdService::generateDummy_FriendPGP()
|
||||
|
||||
int idx = RSRandom::random_f32() * (gpgids.size() - 1);
|
||||
it = gpgids.begin();
|
||||
for(int j = 0; j < idx; j++, it++);
|
||||
for(int j = 0; j < idx; j++, it++) ;
|
||||
|
||||
// HACK FOR DUMMY GENERATION.
|
||||
id.mMeta.mAuthorId = *it;
|
||||
|
@ -91,9 +91,9 @@ virtual std::string save() const;
|
||||
bool tagsPending() const; // should we reprocess?
|
||||
bool tagValid(int i) const;
|
||||
|
||||
uint32_t tagFlags;
|
||||
time_t publishTs;
|
||||
time_t lastCheckTs;
|
||||
uint32_t tagFlags;
|
||||
};
|
||||
|
||||
|
||||
|
723
libretroshare/src/services/p3postbase.cc
Normal file
723
libretroshare/src/services/p3postbase.cc
Normal file
@ -0,0 +1,723 @@
|
||||
/*
|
||||
* libretroshare/src/services p3posted.cc
|
||||
*
|
||||
* Posted interface for RetroShare.
|
||||
*
|
||||
* Copyright 2012-2012 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2.1 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <retroshare/rsidentity.h>
|
||||
|
||||
#include "retroshare/rsgxsflags.h"
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "services/p3postbase.h"
|
||||
#include "serialiser/rsgxscommentitems.h"
|
||||
|
||||
// For Dummy Msgs.
|
||||
#include "util/rsrandom.h"
|
||||
#include "util/rsstring.h"
|
||||
|
||||
/****
|
||||
* #define POSTBASE_DEBUG 1
|
||||
****/
|
||||
|
||||
#define POSTBASE_BACKGROUND_PROCESSING 0x0002
|
||||
#define PROCESSING_START_PERIOD 30
|
||||
#define PROCESSING_INC_PERIOD 15
|
||||
|
||||
#define POSTBASE_ALL_GROUPS 0x0011
|
||||
#define POSTBASE_UNPROCESSED_MSGS 0x0012
|
||||
#define POSTBASE_ALL_MSGS 0x0013
|
||||
#define POSTBASE_BG_POST_META 0x0014
|
||||
/********************************************************************************/
|
||||
/******************* Startup / Tick ******************************************/
|
||||
/********************************************************************************/
|
||||
|
||||
p3PostBase::p3PostBase(RsGeneralDataService *gds, RsNetworkExchangeService *nes, RsGixs* gixs,
|
||||
RsSerialType* serviceSerialiser, uint16_t serviceType)
|
||||
: RsGenExchange(gds, nes, serviceSerialiser, serviceType, gixs, postBaseAuthenPolicy()), GxsTokenQueue(this), RsTickEvent(), mPostBaseMtx("PostBaseMtx")
|
||||
{
|
||||
mBgProcessing = false;
|
||||
|
||||
mCommentService = new p3GxsCommentService(this, serviceType);
|
||||
RsTickEvent::schedule_in(POSTBASE_BACKGROUND_PROCESSING, PROCESSING_START_PERIOD);
|
||||
}
|
||||
|
||||
|
||||
uint32_t p3PostBase::postBaseAuthenPolicy()
|
||||
{
|
||||
uint32_t policy = 0;
|
||||
uint32_t flag = 0;
|
||||
|
||||
flag = GXS_SERV::MSG_AUTHEN_ROOT_AUTHOR_SIGN | GXS_SERV::MSG_AUTHEN_CHILD_AUTHOR_SIGN;
|
||||
RsGenExchange::setAuthenPolicyFlag(flag, policy, RsGenExchange::PUBLIC_GRP_BITS);
|
||||
|
||||
flag |= GXS_SERV::MSG_AUTHEN_ROOT_PUBLISH_SIGN | GXS_SERV::MSG_AUTHEN_CHILD_PUBLISH_SIGN;
|
||||
RsGenExchange::setAuthenPolicyFlag(flag, policy, RsGenExchange::RESTRICTED_GRP_BITS);
|
||||
RsGenExchange::setAuthenPolicyFlag(flag, policy, RsGenExchange::PRIVATE_GRP_BITS);
|
||||
|
||||
flag = 0;
|
||||
RsGenExchange::setAuthenPolicyFlag(flag, policy, RsGenExchange::GRP_OPTION_BITS);
|
||||
|
||||
return policy;
|
||||
}
|
||||
|
||||
void p3PostBase::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
||||
{
|
||||
std::cerr << "p3PostBase::notifyChanges()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::vector<RsGxsNotify *> changesForGUI;
|
||||
std::vector<RsGxsNotify *>::iterator it;
|
||||
|
||||
for(it = changes.begin(); it != changes.end(); it++)
|
||||
{
|
||||
RsGxsGroupChange *groupChange = dynamic_cast<RsGxsGroupChange *>(*it);
|
||||
RsGxsMsgChange *msgChange = dynamic_cast<RsGxsMsgChange *>(*it);
|
||||
if (msgChange)
|
||||
{
|
||||
std::cerr << "p3PostBase::notifyChanges() Found Message Change Notification";
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgChangeMap = msgChange->msgChangeMap;
|
||||
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::iterator mit;
|
||||
for(mit = msgChangeMap.begin(); mit != msgChangeMap.end(); mit++)
|
||||
{
|
||||
std::cerr << "p3PostBase::notifyChanges() Msgs for Group: " << mit->first;
|
||||
std::cerr << std::endl;
|
||||
// To start with we are just going to trigger updates on these groups.
|
||||
// FUTURE OPTIMISATION.
|
||||
// It could be taken a step further and directly request these msgs for an update.
|
||||
addGroupForProcessing(mit->first);
|
||||
}
|
||||
delete msgChange;
|
||||
}
|
||||
|
||||
/* pass on Group Changes to GUI */
|
||||
if (groupChange)
|
||||
{
|
||||
std::cerr << "p3PostBase::notifyChanges() Found Group Change Notification";
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::list<RsGxsGroupId> &groupList = groupChange->mGrpIdList;
|
||||
std::list<RsGxsGroupId>::iterator git;
|
||||
for(git = groupList.begin(); git != groupList.end(); git++)
|
||||
{
|
||||
std::cerr << "p3PostBase::notifyChanges() Incoming Group: " << *git;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
changesForGUI.push_back(groupChange);
|
||||
}
|
||||
}
|
||||
changes.clear();
|
||||
receiveHelperChanges(changesForGUI);
|
||||
|
||||
std::cerr << "p3PostBase::notifyChanges() -> receiveChanges()";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
void p3PostBase::service_tick()
|
||||
{
|
||||
RsTickEvent::tick_events();
|
||||
GxsTokenQueue::checkRequests();
|
||||
|
||||
mCommentService->comment_tick();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/********************************************************************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
void p3PostBase::setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read)
|
||||
{
|
||||
uint32_t mask = GXS_SERV::GXS_MSG_STATUS_UNREAD | GXS_SERV::GXS_MSG_STATUS_UNPROCESSED;
|
||||
uint32_t status = GXS_SERV::GXS_MSG_STATUS_UNREAD;
|
||||
if (read)
|
||||
{
|
||||
status = 0;
|
||||
}
|
||||
|
||||
setMsgStatusFlags(token, msgId, status, mask);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Overloaded from RsTickEvent for Event callbacks.
|
||||
void p3PostBase::handle_event(uint32_t event_type, const std::string & /* elabel */)
|
||||
{
|
||||
std::cerr << "p3PostBase::handle_event(" << event_type << ")";
|
||||
std::cerr << std::endl;
|
||||
|
||||
// stuff.
|
||||
switch(event_type)
|
||||
{
|
||||
case POSTBASE_BACKGROUND_PROCESSING:
|
||||
background_tick();
|
||||
break;
|
||||
|
||||
default:
|
||||
/* error */
|
||||
std::cerr << "p3PostBase::handle_event() Unknown Event Type: " << event_type;
|
||||
std::cerr << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************************
|
||||
* Background Calculations.
|
||||
*
|
||||
* Get list of change groups from Notify....
|
||||
* this doesn't imclude your own submissions (at this point).
|
||||
* So they will not be processed until someone else changes something.
|
||||
* TODO FIX: Must push for that change.
|
||||
*
|
||||
* Eventually, we should just be able to get the new messages from Notify,
|
||||
* and only process them!
|
||||
*/
|
||||
|
||||
void p3PostBase::background_tick()
|
||||
{
|
||||
|
||||
#if 0
|
||||
{
|
||||
RsStackMutex stack(mPostBaseMtx); /********** STACK LOCKED MTX ******/
|
||||
if (mBgGroupList.empty())
|
||||
{
|
||||
background_requestAllGroups();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
background_requestUnprocessedGroup();
|
||||
|
||||
RsTickEvent::schedule_in(POSTBASE_BACKGROUND_PROCESSING, PROCESSING_INC_PERIOD);
|
||||
|
||||
}
|
||||
|
||||
bool p3PostBase::background_requestAllGroups()
|
||||
{
|
||||
std::cerr << "p3PostBase::background_requestAllGroups()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
uint32_t ansType = RS_TOKREQ_ANSTYPE_LIST;
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_IDS;
|
||||
|
||||
uint32_t token = 0;
|
||||
RsGenExchange::getTokenService()->requestGroupInfo(token, ansType, opts);
|
||||
GxsTokenQueue::queueRequest(token, POSTBASE_ALL_GROUPS);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void p3PostBase::background_loadGroups(const uint32_t &token)
|
||||
{
|
||||
/* get messages */
|
||||
std::cerr << "p3PostBase::background_loadGroups()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::list<RsGxsGroupId> groupList;
|
||||
bool ok = RsGenExchange::getGroupList(token, groupList);
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::list<RsGxsGroupId>::iterator it;
|
||||
for(it = groupList.begin(); it != groupList.end(); it++)
|
||||
{
|
||||
addGroupForProcessing(*it);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void p3PostBase::addGroupForProcessing(RsGxsGroupId grpId)
|
||||
{
|
||||
#ifdef POSTBASE_DEBUG
|
||||
std::cerr << "p3PostBase::addGroupForProcessing(" << grpId << ")";
|
||||
std::cerr << std::endl;
|
||||
#endif // POSTBASE_DEBUG
|
||||
|
||||
{
|
||||
RsStackMutex stack(mPostBaseMtx); /********** STACK LOCKED MTX ******/
|
||||
// no point having multiple lookups queued.
|
||||
if (mBgGroupList.end() == std::find(mBgGroupList.begin(),
|
||||
mBgGroupList.end(), grpId))
|
||||
{
|
||||
mBgGroupList.push_back(grpId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void p3PostBase::background_requestUnprocessedGroup()
|
||||
{
|
||||
#ifdef POSTBASE_DEBUG
|
||||
std::cerr << "p3PostBase::background_requestUnprocessedGroup()";
|
||||
std::cerr << std::endl;
|
||||
#endif // POSTBASE_DEBUG
|
||||
|
||||
|
||||
RsGxsGroupId grpId;
|
||||
{
|
||||
RsStackMutex stack(mPostBaseMtx); /********** STACK LOCKED MTX ******/
|
||||
if (mBgProcessing)
|
||||
{
|
||||
std::cerr << "p3PostBase::background_requestUnprocessedGroup() Already Active";
|
||||
std::cerr << std::endl;
|
||||
return;
|
||||
}
|
||||
if (mBgGroupList.empty())
|
||||
{
|
||||
std::cerr << "p3PostBase::background_requestUnprocessedGroup() No Groups to Process";
|
||||
std::cerr << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
grpId = mBgGroupList.front();
|
||||
mBgGroupList.pop_front();
|
||||
mBgProcessing = true;
|
||||
}
|
||||
|
||||
background_requestGroupMsgs(grpId, true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void p3PostBase::background_requestGroupMsgs(const RsGxsGroupId &grpId, bool unprocessedOnly)
|
||||
{
|
||||
std::cerr << "p3PostBase::background_requestGroupMsgs() id: " << grpId;
|
||||
std::cerr << std::endl;
|
||||
|
||||
uint32_t ansType = RS_TOKREQ_ANSTYPE_DATA;
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
|
||||
|
||||
if (unprocessedOnly)
|
||||
{
|
||||
opts.mStatusFilter = GXS_SERV::GXS_MSG_STATUS_UNPROCESSED;
|
||||
opts.mStatusMask = GXS_SERV::GXS_MSG_STATUS_UNPROCESSED;
|
||||
}
|
||||
|
||||
std::list<RsGxsGroupId> grouplist;
|
||||
grouplist.push_back(grpId);
|
||||
|
||||
uint32_t token = 0;
|
||||
|
||||
RsGenExchange::getTokenService()->requestMsgInfo(token, ansType, opts, grouplist);
|
||||
|
||||
if (unprocessedOnly)
|
||||
{
|
||||
GxsTokenQueue::queueRequest(token, POSTBASE_UNPROCESSED_MSGS);
|
||||
}
|
||||
else
|
||||
{
|
||||
GxsTokenQueue::queueRequest(token, POSTBASE_ALL_MSGS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void p3PostBase::background_loadUnprocessedMsgs(const uint32_t &token)
|
||||
{
|
||||
background_loadMsgs(token, true);
|
||||
}
|
||||
|
||||
|
||||
void p3PostBase::background_loadAllMsgs(const uint32_t &token)
|
||||
{
|
||||
background_loadMsgs(token, false);
|
||||
}
|
||||
|
||||
|
||||
/* This function is generalised to support any collection of messages, across multiple groups */
|
||||
|
||||
void p3PostBase::background_loadMsgs(const uint32_t &token, bool unprocessed)
|
||||
{
|
||||
/* get messages */
|
||||
std::cerr << "p3PostBase::background_loadMsgs()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::map<RsGxsGroupId, std::vector<RsGxsMsgItem*> > msgData;
|
||||
bool ok = RsGenExchange::getMsgData(token, msgData);
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "p3PostBase::background_loadMsgs() Failed to getMsgData()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
/* cleanup */
|
||||
background_cleanup();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
RsStackMutex stack(mPostBaseMtx); /********** STACK LOCKED MTX ******/
|
||||
mBgStatsMap.clear();
|
||||
mBgIncremental = unprocessed;
|
||||
}
|
||||
|
||||
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > postMap;
|
||||
|
||||
// generate vector of changes to push to the GUI.
|
||||
std::vector<RsGxsNotify *> changes;
|
||||
RsGxsMsgChange *msgChanges = new RsGxsMsgChange(RsGxsNotify::TYPE_PROCESSED);
|
||||
|
||||
|
||||
RsGxsGroupId groupId;
|
||||
std::map<RsGxsGroupId, std::vector<RsGxsMsgItem*> >::iterator mit;
|
||||
std::vector<RsGxsMsgItem*>::iterator vit;
|
||||
for (mit = msgData.begin(); mit != msgData.end(); mit++)
|
||||
{
|
||||
groupId = mit->first;
|
||||
for (vit = mit->second.begin(); vit != mit->second.end(); vit++)
|
||||
{
|
||||
RsGxsMessageId parentId = (*vit)->meta.mParentId;
|
||||
RsGxsMessageId threadId = (*vit)->meta.mThreadId;
|
||||
|
||||
|
||||
bool inc_counters = false;
|
||||
uint32_t vote_up_inc = 0;
|
||||
uint32_t vote_down_inc = 0;
|
||||
uint32_t comment_inc = 0;
|
||||
|
||||
bool add_voter = false;
|
||||
RsGxsId voterId;
|
||||
RsGxsCommentItem *commentItem;
|
||||
RsGxsVoteItem *voteItem;
|
||||
|
||||
/* THIS Should be handled by UNPROCESSED Filter - but isn't */
|
||||
if (!IS_MSG_UNPROCESSED((*vit)->meta.mMsgStatus))
|
||||
{
|
||||
RsStackMutex stack(mPostBaseMtx); /********** STACK LOCKED MTX ******/
|
||||
if (mBgIncremental)
|
||||
{
|
||||
std::cerr << "p3PostBase::background_loadMsgs() Msg already Processed - Skipping";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "p3PostBase::background_loadMsgs() ERROR This should not happen";
|
||||
std::cerr << std::endl;
|
||||
delete(*vit);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* 3 types expected: PostedPost, Comment and Vote */
|
||||
if (parentId.empty())
|
||||
{
|
||||
/* we don't care about top-level (Posts) */
|
||||
std::cerr << "\tIgnoring TopLevel Item";
|
||||
std::cerr << std::endl;
|
||||
|
||||
/* but we need to notify GUI about them */
|
||||
msgChanges->msgChangeMap[mit->first].push_back((*vit)->meta.mMsgId);
|
||||
}
|
||||
else if (NULL != (commentItem = dynamic_cast<RsGxsCommentItem *>(*vit)))
|
||||
{
|
||||
/* comment - want all */
|
||||
/* Comments are counted by Thread Id */
|
||||
std::cerr << "\tProcessing Comment: " << commentItem;
|
||||
std::cerr << std::endl;
|
||||
|
||||
inc_counters = true;
|
||||
comment_inc = 1;
|
||||
}
|
||||
else if (NULL != (voteItem = dynamic_cast<RsGxsVoteItem *>(*vit)))
|
||||
{
|
||||
/* vote - only care about direct children */
|
||||
if (parentId == threadId)
|
||||
{
|
||||
/* Votes are organised by Parent Id,
|
||||
* ie. you can vote for both Posts and Comments
|
||||
*/
|
||||
std::cerr << "\tProcessing Vote: " << voteItem;
|
||||
std::cerr << std::endl;
|
||||
|
||||
inc_counters = true;
|
||||
add_voter = true;
|
||||
voterId = voteItem->meta.mAuthorId;
|
||||
|
||||
if (voteItem->mMsg.mVoteType == GXS_VOTE_UP)
|
||||
{
|
||||
vote_up_inc = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
vote_down_inc = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* unknown! */
|
||||
std::cerr << "p3PostBase::background_processNewMessages() ERROR Strange NEW Message:";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "\t" << (*vit)->meta;
|
||||
std::cerr << std::endl;
|
||||
|
||||
}
|
||||
|
||||
if (inc_counters)
|
||||
{
|
||||
RsStackMutex stack(mPostBaseMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::map<RsGxsMessageId, PostStats>::iterator sit = mBgStatsMap.find(threadId);
|
||||
if (sit == mBgStatsMap.end())
|
||||
{
|
||||
// add to map of ones to update.
|
||||
postMap[groupId].push_back(threadId);
|
||||
|
||||
mBgStatsMap[threadId] = PostStats(0,0,0);
|
||||
sit = mBgStatsMap.find(threadId);
|
||||
}
|
||||
|
||||
sit->second.comments += comment_inc;
|
||||
sit->second.up_votes += vote_up_inc;
|
||||
sit->second.down_votes += vote_down_inc;
|
||||
|
||||
|
||||
if (add_voter)
|
||||
{
|
||||
sit->second.voters.push_back(voterId);
|
||||
}
|
||||
|
||||
std::cerr << "\tThreadId: " << threadId;
|
||||
std::cerr << " Comment Total: " << sit->second.comments;
|
||||
std::cerr << " UpVote Total: " << sit->second.up_votes;
|
||||
std::cerr << " DownVote Total: " << sit->second.down_votes;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
/* flag all messages as processed */
|
||||
if ((*vit)->meta.mMsgStatus & GXS_SERV::GXS_MSG_STATUS_UNPROCESSED)
|
||||
{
|
||||
uint32_t token_a;
|
||||
RsGxsGrpMsgIdPair msgId = std::make_pair(groupId, (*vit)->meta.mMsgId);
|
||||
RsGenExchange::setMsgStatusFlags(token_a, msgId, 0, GXS_SERV::GXS_MSG_STATUS_UNPROCESSED);
|
||||
}
|
||||
delete(*vit);
|
||||
}
|
||||
}
|
||||
|
||||
/* push updates of new Posts */
|
||||
if (msgChanges->msgChangeMap.size() > 0)
|
||||
{
|
||||
std::cerr << "p3PostBase::background_processNewMessages() -> receiveChanges()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
changes.push_back(msgChanges);
|
||||
receiveHelperChanges(changes);
|
||||
}
|
||||
|
||||
/* request the summary info from the parents */
|
||||
uint32_t token_b;
|
||||
uint32_t anstype = RS_TOKREQ_ANSTYPE_SUMMARY;
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_MSG_META;
|
||||
RsGenExchange::getTokenService()->requestMsgInfo(token_b, anstype, opts, postMap);
|
||||
|
||||
GxsTokenQueue::queueRequest(token_b, POSTBASE_BG_POST_META);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
#define RSGXS_MAX_SERVICE_STRING 1024
|
||||
bool encodePostCache(std::string &str, const PostStats &s)
|
||||
{
|
||||
char line[RSGXS_MAX_SERVICE_STRING];
|
||||
|
||||
snprintf(line, RSGXS_MAX_SERVICE_STRING, "%d %d %d", s.comments, s.up_votes, s.down_votes);
|
||||
|
||||
str = line;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool extractPostCache(const std::string &str, PostStats &s)
|
||||
{
|
||||
|
||||
uint32_t iupvotes, idownvotes, icomments;
|
||||
if (3 == sscanf(str.c_str(), "%d %d %d", &icomments, &iupvotes, &idownvotes))
|
||||
{
|
||||
s.comments = icomments;
|
||||
s.up_votes = iupvotes;
|
||||
s.down_votes = idownvotes;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void p3PostBase::background_updateVoteCounts(const uint32_t &token)
|
||||
{
|
||||
std::cerr << "p3PostBase::background_updateVoteCounts()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
GxsMsgMetaMap parentMsgList;
|
||||
GxsMsgMetaMap::iterator mit;
|
||||
std::vector<RsMsgMetaData>::iterator vit;
|
||||
|
||||
bool ok = RsGenExchange::getMsgMeta(token, parentMsgList);
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "p3PostBase::background_updateVoteCounts() ERROR";
|
||||
std::cerr << std::endl;
|
||||
background_cleanup();
|
||||
return;
|
||||
}
|
||||
|
||||
// generate vector of changes to push to the GUI.
|
||||
std::vector<RsGxsNotify *> changes;
|
||||
RsGxsMsgChange *msgChanges = new RsGxsMsgChange(RsGxsNotify::TYPE_PROCESSED);
|
||||
|
||||
for(mit = parentMsgList.begin(); mit != parentMsgList.end(); mit++)
|
||||
{
|
||||
for(vit = mit->second.begin(); vit != mit->second.end(); vit++)
|
||||
{
|
||||
std::cerr << "p3PostBase::background_updateVoteCounts() Processing Msg(" << mit->first;
|
||||
std::cerr << ", " << vit->mMsgId << ")";
|
||||
std::cerr << std::endl;
|
||||
|
||||
RsStackMutex stack(mPostBaseMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
/* extract current vote count */
|
||||
PostStats stats;
|
||||
if (mBgIncremental)
|
||||
{
|
||||
if (!extractPostCache(vit->mServiceString, stats))
|
||||
{
|
||||
if (!(vit->mServiceString.empty()))
|
||||
{
|
||||
std::cerr << "p3PostBase::background_updateVoteCounts() Failed to extract Votes";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "\tFrom String: " << vit->mServiceString;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* get increment */
|
||||
std::map<RsGxsMessageId, PostStats>::iterator it;
|
||||
it = mBgStatsMap.find(vit->mMsgId);
|
||||
|
||||
if (it != mBgStatsMap.end())
|
||||
{
|
||||
std::cerr << "p3PostBase::background_updateVoteCounts() Adding to msgChangeMap: ";
|
||||
std::cerr << mit->first << " MsgId: " << vit->mMsgId;
|
||||
std::cerr << std::endl;
|
||||
|
||||
stats.increment(it->second);
|
||||
msgChanges->msgChangeMap[mit->first].push_back(vit->mMsgId);
|
||||
}
|
||||
else
|
||||
{
|
||||
// warning.
|
||||
std::cerr << "p3PostBase::background_updateVoteCounts() Warning No New Votes found.";
|
||||
std::cerr << " For MsgId: " << vit->mMsgId;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
std::string str;
|
||||
if (!encodePostCache(str, stats))
|
||||
{
|
||||
std::cerr << "p3PostBase::background_updateVoteCounts() Failed to encode Votes";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "p3PostBase::background_updateVoteCounts() Encoded String: " << str;
|
||||
std::cerr << std::endl;
|
||||
/* store new result */
|
||||
uint32_t token_c;
|
||||
RsGxsGrpMsgIdPair msgId = std::make_pair(vit->mGroupId, vit->mMsgId);
|
||||
RsGenExchange::setMsgServiceString(token_c, msgId, str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (msgChanges->msgChangeMap.size() > 0)
|
||||
{
|
||||
std::cerr << "p3PostBase::background_updateVoteCounts() -> receiveChanges()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
changes.push_back(msgChanges);
|
||||
receiveHelperChanges(changes);
|
||||
}
|
||||
|
||||
// DONE!.
|
||||
background_cleanup();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool p3PostBase::background_cleanup()
|
||||
{
|
||||
std::cerr << "p3PostBase::background_cleanup()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
RsStackMutex stack(mPostBaseMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
// Cleanup.
|
||||
mBgStatsMap.clear();
|
||||
mBgProcessing = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Overloaded from GxsTokenQueue for Request callbacks.
|
||||
void p3PostBase::handleResponse(uint32_t token, uint32_t req_type)
|
||||
{
|
||||
std::cerr << "p3PostBase::handleResponse(" << token << "," << req_type << ")";
|
||||
std::cerr << std::endl;
|
||||
|
||||
// stuff.
|
||||
switch(req_type)
|
||||
{
|
||||
case POSTBASE_ALL_GROUPS:
|
||||
background_loadGroups(token);
|
||||
break;
|
||||
case POSTBASE_UNPROCESSED_MSGS:
|
||||
background_loadUnprocessedMsgs(token);
|
||||
break;
|
||||
case POSTBASE_ALL_MSGS:
|
||||
background_loadAllMsgs(token);
|
||||
break;
|
||||
case POSTBASE_BG_POST_META:
|
||||
background_updateVoteCounts(token);
|
||||
break;
|
||||
default:
|
||||
/* error */
|
||||
std::cerr << "p3PostBase::handleResponse() Unknown Request Type: " << req_type;
|
||||
std::cerr << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
135
libretroshare/src/services/p3postbase.h
Normal file
135
libretroshare/src/services/p3postbase.h
Normal file
@ -0,0 +1,135 @@
|
||||
/*
|
||||
* libretroshare/src/services: p3postbase.h
|
||||
*
|
||||
* GxsChannel interface for RetroShare.
|
||||
*
|
||||
* Copyright 2012-2013 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2.1 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef P3_POSTBASE_SERVICE_HEADER
|
||||
#define P3_POSTBASE_SERVICE_HEADER
|
||||
|
||||
|
||||
#include "services/p3gxscommon.h"
|
||||
#include "gxs/rsgenexchange.h"
|
||||
|
||||
#include "util/rstickevent.h"
|
||||
|
||||
#include <retroshare/rsidentity.h>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class PostStats
|
||||
{
|
||||
public:
|
||||
PostStats() :up_votes(0), down_votes(0), comments(0) { return; }
|
||||
PostStats(int up, int down, int c) :up_votes(up), down_votes(down), comments(c) { return; }
|
||||
|
||||
void increment(const PostStats &s)
|
||||
{
|
||||
up_votes += s.up_votes;
|
||||
down_votes += s.down_votes;
|
||||
comments += s.comments;
|
||||
return;
|
||||
}
|
||||
|
||||
int up_votes;
|
||||
int down_votes;
|
||||
int comments;
|
||||
std::list<RsGxsId> voters;
|
||||
};
|
||||
|
||||
bool encodePostCache(std::string &str, const PostStats &s);
|
||||
bool extractPostCache(const std::string &str, PostStats &s);
|
||||
|
||||
|
||||
class p3PostBase: public RsGenExchange, public GxsTokenQueue, public RsTickEvent
|
||||
{
|
||||
public:
|
||||
|
||||
p3PostBase(RsGeneralDataService *gds, RsNetworkExchangeService *nes, RsGixs* gixs,
|
||||
RsSerialType* serviceSerialiser, uint16_t serviceType);
|
||||
|
||||
virtual void service_tick();
|
||||
|
||||
// This should be overloaded to call RsGxsIfaceHelper::receiveChanges().
|
||||
virtual void receiveHelperChanges(std::vector<RsGxsNotify*>& changes) = 0;
|
||||
|
||||
protected:
|
||||
|
||||
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes);
|
||||
|
||||
// Overloaded from GxsTokenQueue for Request callbacks.
|
||||
virtual void handleResponse(uint32_t token, uint32_t req_type);
|
||||
|
||||
// Overloaded from RsTickEvent.
|
||||
virtual void handle_event(uint32_t event_type, const std::string &elabel);
|
||||
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
p3GxsCommentService *mCommentService;
|
||||
|
||||
private:
|
||||
|
||||
static uint32_t postBaseAuthenPolicy();
|
||||
|
||||
// Background processing.
|
||||
void background_tick();
|
||||
|
||||
bool background_requestAllGroups();
|
||||
void background_loadGroups(const uint32_t &token);
|
||||
|
||||
void addGroupForProcessing(RsGxsGroupId grpId);
|
||||
void background_requestUnprocessedGroup();
|
||||
|
||||
void background_requestGroupMsgs(const RsGxsGroupId &grpId, bool unprocessedOnly);
|
||||
void background_loadUnprocessedMsgs(const uint32_t &token);
|
||||
void background_loadAllMsgs(const uint32_t &token);
|
||||
void background_loadMsgs(const uint32_t &token, bool unprocessed);
|
||||
|
||||
|
||||
void background_updateVoteCounts(const uint32_t &token);
|
||||
bool background_cleanup();
|
||||
|
||||
|
||||
RsMutex mPostBaseMtx;
|
||||
|
||||
bool mBgProcessing;
|
||||
bool mBgIncremental;
|
||||
std::list<RsGxsGroupId> mBgGroupList;
|
||||
std::map<RsGxsMessageId, PostStats> mBgStatsMap;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
@ -28,10 +28,7 @@
|
||||
|
||||
|
||||
#include "retroshare/rsposted.h"
|
||||
#include "services/p3gxscommon.h"
|
||||
#include "gxs/rsgenexchange.h"
|
||||
|
||||
#include "util/rstickevent.h"
|
||||
#include "services/p3postbase.h"
|
||||
|
||||
#include <retroshare/rsidentity.h>
|
||||
|
||||
@ -43,72 +40,41 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class PostStats
|
||||
{
|
||||
public:
|
||||
PostStats() :up_votes(0), down_votes(0), comments(0) { return; }
|
||||
PostStats(int up, int down, int c) :up_votes(up), down_votes(down), comments(c) { return; }
|
||||
|
||||
void increment(const PostStats &s)
|
||||
{
|
||||
up_votes += s.up_votes;
|
||||
down_votes += s.down_votes;
|
||||
comments += s.comments;
|
||||
return;
|
||||
}
|
||||
|
||||
int up_votes;
|
||||
int down_votes;
|
||||
int comments;
|
||||
std::list<RsGxsId> voters;
|
||||
};
|
||||
|
||||
bool encodePostedCache(std::string &str, const PostStats &s);
|
||||
bool extractPostedCache(const std::string &str, PostStats &s);
|
||||
|
||||
|
||||
class p3Posted: public RsGenExchange, public RsPosted,
|
||||
public GxsTokenQueue,
|
||||
public RsTickEvent /* only needed for testing - remove after */
|
||||
class p3Posted: public p3PostBase, public RsPosted
|
||||
{
|
||||
public:
|
||||
|
||||
p3Posted(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs* gixs);
|
||||
|
||||
virtual void service_tick();
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes);
|
||||
|
||||
// Overloaded from GxsTokenQueue for Request callbacks.
|
||||
virtual void handleResponse(uint32_t token, uint32_t req_type);
|
||||
|
||||
// Overloaded from RsTickEvent.
|
||||
virtual void handle_event(uint32_t event_type, const std::string &elabel);
|
||||
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes)
|
||||
{
|
||||
return p3PostBase::notifyChanges(changes);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
virtual void receiveHelperChanges(std::vector<RsGxsNotify*>& changes)
|
||||
{
|
||||
return RsGxsIfaceHelper::receiveChanges(changes);
|
||||
}
|
||||
|
||||
// Posted Specific DataTypes.
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsPostedGroup> &groups);
|
||||
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts);
|
||||
|
||||
virtual bool getRelatedPosts(const uint32_t &token, std::vector<RsPostedPost> &posts);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read);
|
||||
|
||||
//virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask);
|
||||
//virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask);
|
||||
|
||||
//virtual bool groupRestoreKeys(const std::string &groupId);
|
||||
//virtual bool groupShareKeys(const std::string &groupId, std::list<std::string>& peers);
|
||||
|
||||
virtual bool createGroup(uint32_t &token, RsPostedGroup &group);
|
||||
virtual bool createPost(uint32_t &token, RsPostedPost &post);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// WRAPPERS due to the separate Interface.
|
||||
|
||||
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read)
|
||||
{
|
||||
return p3PostBase::setMessageReadStatus(token, msgId, read);
|
||||
}
|
||||
|
||||
|
||||
/* Comment service - Provide RsGxsCommentService - redirect to p3GxsCommentService */
|
||||
@ -145,82 +111,6 @@ virtual bool acknowledgeVote(const uint32_t& token, std::pair<RsGxsGroupId, RsGx
|
||||
}
|
||||
return acknowledgeMsg(token, msgId);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
static uint32_t postedAuthenPolicy();
|
||||
|
||||
bool calculateScores(RsPostedPost &post, time_t ref_time);
|
||||
|
||||
// Background processing.
|
||||
void background_tick();
|
||||
|
||||
bool background_requestAllGroups();
|
||||
void background_loadGroups(const uint32_t &token);
|
||||
|
||||
void addGroupForProcessing(RsGxsGroupId grpId);
|
||||
void background_requestUnprocessedGroup();
|
||||
|
||||
void background_requestGroupMsgs(const RsGxsGroupId &grpId, bool unprocessedOnly);
|
||||
void background_loadUnprocessedMsgs(const uint32_t &token);
|
||||
void background_loadAllMsgs(const uint32_t &token);
|
||||
void background_loadMsgs(const uint32_t &token, bool unprocessed);
|
||||
|
||||
|
||||
void background_updateVoteCounts(const uint32_t &token);
|
||||
bool background_cleanup();
|
||||
|
||||
|
||||
RsMutex mPostedMtx;
|
||||
|
||||
bool mBgProcessing;
|
||||
bool mBgIncremental;
|
||||
std::list<RsGxsGroupId> mBgGroupList;
|
||||
std::map<RsGxsMessageId, PostStats> mBgStatsMap;
|
||||
|
||||
|
||||
|
||||
|
||||
// DUMMY DATA,
|
||||
virtual bool generateDummyData();
|
||||
|
||||
std::string genRandomId();
|
||||
|
||||
void dummy_tick();
|
||||
|
||||
bool generatePost(uint32_t &token, const RsGxsGroupId &grpId);
|
||||
bool generateComment(uint32_t &token, const RsGxsGroupId &grpId,
|
||||
const RsGxsMessageId &parentId, const RsGxsMessageId &threadId);
|
||||
bool generateGroup(uint32_t &token, std::string groupName);
|
||||
|
||||
class PostedDummyRef
|
||||
{
|
||||
public:
|
||||
PostedDummyRef() { return; }
|
||||
PostedDummyRef(const RsGxsGroupId &grpId, const RsGxsMessageId &threadId, const RsGxsMessageId &msgId)
|
||||
:mGroupId(grpId), mThreadId(threadId), mMsgId(msgId) { return; }
|
||||
|
||||
RsGxsGroupId mGroupId;
|
||||
RsGxsMessageId mThreadId;
|
||||
RsGxsMessageId mMsgId;
|
||||
};
|
||||
|
||||
uint32_t mGenToken;
|
||||
bool mGenActive;
|
||||
int mGenCount;
|
||||
std::vector<PostedDummyRef> mGenRefs;
|
||||
RsGxsMessageId mGenThreadId;
|
||||
|
||||
p3GxsCommentService *mCommentService;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,190 +0,0 @@
|
||||
/*
|
||||
* libretroshare/src/services: p3posted.h
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2012-2012 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef P3_POSTED_SERVICE_VEG_HEADER
|
||||
#define P3_POSTED_SERVICE_VEG_HEADER
|
||||
|
||||
#include "services/p3gxsserviceVEG.h"
|
||||
#include "retroshare/rspostedVEG.h"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
/*
|
||||
* Posted Service
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class PostedDataProxy: public GxsDataProxyVEG
|
||||
{
|
||||
public:
|
||||
|
||||
bool addGroup(const RsPostedGroup &group);
|
||||
bool addPost(const RsPostedPost &post);
|
||||
bool addVote(const RsPostedVote &vote);
|
||||
bool addComment(const RsPostedComment &comment);
|
||||
|
||||
bool getGroup(const std::string &id, RsPostedGroup &group);
|
||||
bool getPost(const std::string &id, RsPostedPost &post);
|
||||
bool getVote(const std::string &id, RsPostedVote &vote);
|
||||
bool getComment(const std::string &id, RsPostedComment &comment);
|
||||
|
||||
/* These Functions must be overloaded to complete the service */
|
||||
virtual bool convertGroupToMetaData(void *groupData, RsGroupMetaData &meta);
|
||||
virtual bool convertMsgToMetaData(void *groupData, RsMsgMetaData &meta);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
class p3PostedServiceVEG: public p3GxsDataServiceVEG, public RsPostedVEG
|
||||
{
|
||||
public:
|
||||
|
||||
p3PostedServiceVEG(uint16_t type);
|
||||
|
||||
virtual int tick();
|
||||
|
||||
public:
|
||||
|
||||
// NEW INTERFACE.
|
||||
/************* Extern Interface *******/
|
||||
|
||||
virtual bool updated();
|
||||
|
||||
/* Data Requests */
|
||||
virtual bool requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds);
|
||||
virtual bool requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds);
|
||||
virtual bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &msgIds);
|
||||
|
||||
/* Generic Lists */
|
||||
virtual bool getGroupList( const uint32_t &token, std::list<std::string> &groupIds);
|
||||
virtual bool getMsgList( const uint32_t &token, std::list<std::string> &msgIds);
|
||||
|
||||
/* Generic Summary */
|
||||
virtual bool getGroupSummary( const uint32_t &token, std::list<RsGroupMetaData> &groupInfo);
|
||||
virtual bool getMsgSummary( const uint32_t &token, std::list<RsMsgMetaData> &msgInfo);
|
||||
|
||||
/* Actual Data -> specific to Interface */
|
||||
/* Specific Service Data */
|
||||
virtual bool getGroup(const uint32_t &token, RsPostedGroup &group);
|
||||
virtual bool getPost(const uint32_t &token, RsPostedPost &post);
|
||||
virtual bool getComment(const uint32_t &token, RsPostedComment &comment);
|
||||
|
||||
|
||||
/* Poll */
|
||||
virtual uint32_t requestStatus(const uint32_t token);
|
||||
|
||||
/* Cancel Request */
|
||||
virtual bool cancelRequest(const uint32_t &token);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask);
|
||||
virtual bool setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask);
|
||||
virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask);
|
||||
virtual bool setMessageServiceString(const std::string &msgId, const std::string &str);
|
||||
virtual bool setGroupServiceString(const std::string &grpId, const std::string &str);
|
||||
|
||||
virtual bool groupRestoreKeys(const std::string &groupId);
|
||||
virtual bool groupShareKeys(const std::string &groupId, std::list<std::string>& peers);
|
||||
|
||||
virtual bool submitGroup(uint32_t &token, RsPostedGroup &group, bool isNew);
|
||||
virtual bool submitPost(uint32_t &token, RsPostedPost &post, bool isNew);
|
||||
virtual bool submitVote(uint32_t &token, RsPostedVote &vote, bool isNew);
|
||||
virtual bool submitComment(uint32_t &token, RsPostedComment &comment, bool isNew);
|
||||
|
||||
// Extended Interface for Collated Data View.
|
||||
virtual bool setViewMode(uint32_t mode);
|
||||
virtual bool setViewPeriod(uint32_t period);
|
||||
virtual bool setViewRange(uint32_t first, uint32_t count);
|
||||
|
||||
virtual bool requestRanking(uint32_t &token, std::string groupId);
|
||||
virtual bool getRankedPost(const uint32_t &token, RsPostedPost &post);
|
||||
|
||||
|
||||
// These are exposed for GUI usage.
|
||||
virtual bool encodePostedCache(std::string &str, uint32_t votes, uint32_t comments);
|
||||
virtual bool extractPostedCache(const std::string &str, uint32_t &votes, uint32_t &comments);
|
||||
virtual float calcPostScore(const RsMsgMetaData &meta);
|
||||
|
||||
private:
|
||||
|
||||
//
|
||||
bool checkRankingRequest();
|
||||
bool processPosts();
|
||||
|
||||
// background processing of Votes.
|
||||
// NB: These should probably be handled by a background thread.
|
||||
// At the moment they are run from the tick() thread.
|
||||
|
||||
bool background_checkTokenRequest();
|
||||
bool background_requestGroups();
|
||||
bool background_requestNewMessages();
|
||||
bool background_processNewMessages();
|
||||
|
||||
bool background_updateVoteCounts();
|
||||
bool background_cleanup();
|
||||
|
||||
|
||||
|
||||
std::string genRandomId();
|
||||
bool generateDummyData();
|
||||
bool addExtraDummyData();
|
||||
|
||||
PostedDataProxy *mPostedProxy;
|
||||
|
||||
RsMutex mPostedMtx;
|
||||
bool mUpdated;
|
||||
|
||||
// Ranking view mode, stored here.
|
||||
uint32_t mViewMode;
|
||||
uint32_t mViewPeriod;
|
||||
uint32_t mViewStart;
|
||||
uint32_t mViewCount;
|
||||
|
||||
// Processing Ranking stuff.
|
||||
bool mProcessingRanking;
|
||||
uint32_t mRankingState;
|
||||
uint32_t mRankingExternalToken;
|
||||
uint32_t mRankingInternalToken;
|
||||
|
||||
// background processing - Mutex protected.
|
||||
time_t mLastBgCheck;
|
||||
bool mBgProcessing;
|
||||
uint32_t mBgPhase;
|
||||
uint32_t mBgToken;
|
||||
|
||||
std::map<std::string, uint32_t> mBgVoteMap; // ParentId -> Vote Count.
|
||||
std::map<std::string, uint32_t> mBgCommentMap; // ThreadId -> Comment Count.
|
||||
|
||||
// extra dummy data.
|
||||
std::list<RsPostedVote> mDummyLaterVotes;
|
||||
std::list<RsPostedComment> mDummyLaterComments;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
@ -504,7 +504,7 @@ std::string chooseRandomAuthorId()
|
||||
|
||||
uint32_t idx = (uint32_t) (ownIds.size() * RSRandom::random_f32());
|
||||
int i = 0;
|
||||
for(it = ownIds.begin(); (it != ownIds.end()) && (i < idx); it++, i++);
|
||||
for(it = ownIds.begin(); (it != ownIds.end()) && (i < idx); it++, i++) ;
|
||||
|
||||
std::string answer;
|
||||
if (it != ownIds.end())
|
||||
|
Loading…
Reference in New Issue
Block a user