Major commit of progress on new GxsServices (Channels and Posted). These are not complete yet!

- Reorganisation of p3posted, stripped out lots of previous stuff.
 - Converted p3posted to use GxsComment system.
 - Disabled much of the DummyData - switch it on manually when testing.
 - Added Basics of ChannelPost processing for AutoDownload. (incomplete).
 - Added GxsCommon backend for RsGxsImage and RsGxsFile.
 - Completed Serialiser for GxsChannels.




git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6207 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2013-03-11 20:40:28 +00:00
parent 4b9087b60d
commit 123d4a630b
16 changed files with 1927 additions and 2179 deletions

View file

@ -44,7 +44,12 @@
RsGxsChannels *rsGxsChannels = NULL;
#define CHANNEL_TESTEVENT_DUMMYDATA 0x0001
#define GXSCHANNELS_SUBSCRIBED_META 1
#define GXSCHANNELS_UNPROCESSED_SPECIFIC 2
#define GXSCHANNELS_UNPROCESSED_GENERIC 3
#define CHANNEL_PROCESS 0x0001
#define CHANNEL_TESTEVENT_DUMMYDATA 0x0002
#define DUMMYDATA_PERIOD 60 // long enough for some RsIdentities to be generated.
/********************************************************************************/
@ -52,17 +57,16 @@ RsGxsChannels *rsGxsChannels = NULL;
/********************************************************************************/
p3GxsChannels::p3GxsChannels(RsGeneralDataService *gds, RsNetworkExchangeService *nes, RsGixs* gixs)
: RsGenExchange(gds, nes, new RsGxsChannelSerialiser(), RS_SERVICE_GXSV1_TYPE_CHANNELS, gixs, channelsAuthenPolicy()), RsGxsChannels(this)
: RsGenExchange(gds, nes, new RsGxsChannelSerialiser(), RS_SERVICE_GXSV1_TYPE_CHANNELS, gixs, channelsAuthenPolicy()), RsGxsChannels(this), GxsTokenQueue(this)
{
// For Dummy Msgs.
mGenActive = false;
mCommentService = new p3GxsCommentService(this, RS_SERVICE_GXSV1_TYPE_CHANNELS);
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
RsTickEvent::schedule_in(CHANNEL_PROCESS, 0);
RsTickEvent::schedule_in(CHANNEL_TESTEVENT_DUMMYDATA, DUMMYDATA_PERIOD);
#endif
// Test Data disabled in repo.
//RsTickEvent::schedule_in(CHANNEL_TESTEVENT_DUMMYDATA, DUMMYDATA_PERIOD);
}
@ -86,6 +90,44 @@ uint32_t p3GxsChannels::channelsAuthenPolicy()
void p3GxsChannels::notifyChanges(std::vector<RsGxsNotify *> &changes)
{
std::cerr << "p3GxsChannels::notifyChanges()";
std::cerr << std::endl;
/* iterate through and grab any new messages */
std::list<RsGxsGroupId> unprocessedGroups;
std::vector<RsGxsNotify *>::iterator it;
for(it = changes.begin(); it != changes.end(); it++)
{
RsGxsMsgChange *msgChange = dynamic_cast<RsGxsMsgChange *>(*it);
if (msgChange)
{
std::cerr << "p3GxsChannels::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 << "p3GxsChannels::notifyChanges() Msgs for Group: " << mit->first;
std::cerr << std::endl;
if (autoDownloadEnabled(mit->first))
{
std::cerr << "p3GxsChannels::notifyChanges() AutoDownload for Group: " << mit->first;
std::cerr << std::endl;
/* problem is most of these will be comments and votes,
* should make it occasional - every 5mins / 10minutes TODO */
unprocessedGroups.push_back(mit->first);
}
}
}
}
request_SpecificSubscribedGroups(unprocessedGroups);
RsGxsIfaceHelper::receiveChanges(changes);
}
@ -98,6 +140,9 @@ void p3GxsChannels::service_tick()
bool p3GxsChannels::getGroupData(const uint32_t &token, std::vector<RsGxsChannelGroup> &groups)
{
std::cerr << "p3GxsChannels::getGroupData()";
std::cerr << std::endl;
std::vector<RsGxsGrpItem*> grpData;
bool ok = RsGenExchange::getGroupData(token, grpData);
@ -108,13 +153,26 @@ bool p3GxsChannels::getGroupData(const uint32_t &token, std::vector<RsGxsChannel
for(; vit != grpData.end(); vit++)
{
RsGxsChannelGroupItem* item = dynamic_cast<RsGxsChannelGroupItem*>(*vit);
RsGxsChannelGroup grp = item->mGroup;
item->mGroup.mMeta = item->meta;
grp.mMeta = item->mGroup.mMeta;
delete item;
groups.push_back(grp);
if (item)
{
RsGxsChannelGroup grp;
item->toChannelGroup(grp, true);
delete item;
groups.push_back(grp);
}
else
{
std::cerr << "p3GxsChannels::getGroupData() ERROR in decode";
std::cerr << std::endl;
}
}
}
else
{
std::cerr << "p3GxsChannels::getGroupData() ERROR in request";
std::cerr << std::endl;
}
return ok;
}
@ -125,6 +183,9 @@ bool p3GxsChannels::getGroupData(const uint32_t &token, std::vector<RsGxsChannel
bool p3GxsChannels::getPostData(const uint32_t &token, std::vector<RsGxsChannelPost> &msgs)
{
std::cerr << "p3GxsChannels::getPostData()";
std::cerr << std::endl;
GxsMsgDataMap msgData;
bool ok = RsGenExchange::getMsgData(token, msgData);
@ -144,8 +205,8 @@ bool p3GxsChannels::getPostData(const uint32_t &token, std::vector<RsGxsChannelP
if(item)
{
RsGxsChannelPost msg = item->mMsg;
msg.mMeta = item->meta;
RsGxsChannelPost msg;
item->toChannelPost(msg, true);
msgs.push_back(msg);
delete item;
}
@ -157,6 +218,11 @@ bool p3GxsChannels::getPostData(const uint32_t &token, std::vector<RsGxsChannelP
}
}
}
else
{
std::cerr << "p3GxsChannels::getPostData() ERROR in request";
std::cerr << std::endl;
}
return ok;
}
@ -164,6 +230,9 @@ bool p3GxsChannels::getPostData(const uint32_t &token, std::vector<RsGxsChannelP
bool p3GxsChannels::getRelatedPosts(const uint32_t &token, std::vector<RsGxsChannelPost> &msgs)
{
std::cerr << "p3GxsChannels::getRelatedPosts()";
std::cerr << std::endl;
GxsMsgRelatedDataMap msgData;
bool ok = RsGenExchange::getMsgRelatedData(token, msgData);
@ -182,8 +251,8 @@ bool p3GxsChannels::getRelatedPosts(const uint32_t &token, std::vector<RsGxsChan
if(item)
{
RsGxsChannelPost msg = item->mMsg;
msg.mMeta = item->meta;
RsGxsChannelPost msg;
item->toChannelPost(msg, true);
msgs.push_back(msg);
delete item;
}
@ -195,11 +264,424 @@ bool p3GxsChannels::getRelatedPosts(const uint32_t &token, std::vector<RsGxsChan
}
}
}
else
{
std::cerr << "p3GxsChannels::getRelatedPosts() ERROR in request";
std::cerr << std::endl;
}
return ok;
}
/********************************************************************************************/
/********************************************************************************************/
void p3GxsChannels::setChannelAutoDownload(uint32_t&, const RsGxsGroupId&, bool)
{
std::cerr << "p3GxsChannels::setChannelAutoDownload() TODO";
std::cerr << std::endl;
return;
}
void p3GxsChannels::request_AllSubscribedGroups()
{
#ifdef GXSCHANNELS_DEBUG
std::cerr << "p3GxsChannels::request_SubscribedGroups()";
std::cerr << std::endl;
#endif // GXSCHANNELS_DEBUG
uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY;
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
uint32_t token = 0;
RsGenExchange::getTokenService()->requestGroupInfo(token, ansType, opts);
GxsTokenQueue::queueRequest(token, GXSCHANNELS_SUBSCRIBED_META);
}
void p3GxsChannels::request_SpecificSubscribedGroups(const std::list<RsGxsGroupId> &groups)
{
#ifdef GXSCHANNELS_DEBUG
std::cerr << "p3GxsChannels::request_SpecificSubscribedGroups()";
std::cerr << std::endl;
#endif // GXSCHANNELS_DEBUG
uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY;
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
uint32_t token = 0;
RsGenExchange::getTokenService()->requestGroupInfo(token, ansType, opts, groups);
GxsTokenQueue::queueRequest(token, GXSCHANNELS_SUBSCRIBED_META);
}
void p3GxsChannels::load_SubscribedGroups(const uint32_t &token)
{
#ifdef GXSCHANNELS_DEBUG
std::cerr << "p3GxsChannels::load_SubscribedGroups()";
std::cerr << std::endl;
#endif // GXSCHANNELS_DEBUG
std::list<RsGroupMetaData> groups;
std::list<RsGxsGroupId> groupList;
getGroupMeta(token, groups);
std::list<RsGroupMetaData>::iterator it;
for(it = groups.begin(); it != groups.end(); it++)
{
if (it->mSubscribeFlags &
(GXS_SERV::GROUP_SUBSCRIBE_ADMIN |
GXS_SERV::GROUP_SUBSCRIBE_PUBLISH |
GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED ))
{
std::cerr << "p3GxsChannels::load_SubscribedGroups() updating Subscribed Group: " << it->mGroupId;
std::cerr << std::endl;
updateSubscribedGroup(*it);
if (autoDownloadEnabled(it->mGroupId))
{
std::cerr << "p3GxsChannels::load_SubscribedGroups() remembering AutoDownload Group: " << it->mGroupId;
std::cerr << std::endl;
groupList.push_back(it->mGroupId);
}
}
else
{
std::cerr << "p3GxsChannels::load_SubscribedGroups() clearing unsubscribed Group: " << it->mGroupId;
std::cerr << std::endl;
clearUnsubscribedGroup(it->mGroupId);
}
}
/* Query for UNPROCESSED POSTS from checkGroupList */
request_GroupUnprocessedPosts(groupList);
}
void p3GxsChannels::updateSubscribedGroup(const RsGroupMetaData &group)
{
std::cerr << "p3GxsChannels::updateSubscribedGroup() id: " << group.mGroupId;
std::cerr << std::endl;
mSubscribedGroups[group.mGroupId] = group;
}
void p3GxsChannels::clearUnsubscribedGroup(const RsGxsGroupId &id)
{
std::cerr << "p3GxsChannels::clearUnsubscribedGroup() id: " << id;
std::cerr << std::endl;
//std::map<RsGxsGroupId, RsGrpMetaData> mSubscribedGroups;
std::map<RsGxsGroupId, RsGroupMetaData>::iterator it;
it = mSubscribedGroups.find(id);
if (it != mSubscribedGroups.end())
{
mSubscribedGroups.erase(it);
}
}
void p3GxsChannels::subscribeToGroup(const RsGxsGroupId &groupId, bool subscribe)
{
std::cerr << "p3GxsChannels::subscribedToGroup() id: " << groupId << " subscribe: " << subscribe;
std::cerr << std::endl;
std::list<RsGxsGroupId> groups;
groups.push_back(groupId);
// Call down to do the real work.
uint32_t token;
RsGenExchange::subscribeToGroup(token, groupId, subscribe);
// reload Group afterwards.
request_SpecificSubscribedGroups(groups);
}
void p3GxsChannels::request_SpecificUnprocessedPosts(std::list<std::pair<RsGxsGroupId, RsGxsMessageId> > &ids)
{
#ifdef GXSCHANNELS_DEBUG
std::cerr << "p3GxsChannels::request_SpecificUnprocessedPosts()";
std::cerr << std::endl;
#endif // GXSCHANNELS_DEBUG
uint32_t ansType = RS_TOKREQ_ANSTYPE_DATA;
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
uint32_t token = 0;
RsGenExchange::getTokenService()->requestGroupInfo(token, ansType, opts);
GxsTokenQueue::queueRequest(token, GXSCHANNELS_UNPROCESSED_SPECIFIC);
}
void p3GxsChannels::request_GroupUnprocessedPosts(const std::list<RsGxsGroupId> &grouplist)
{
#ifdef GXSCHANNELS_DEBUG
std::cerr << "p3GxsChannels::request_GroupUnprocessedPosts()";
std::cerr << std::endl;
#endif // GXSCHANNELS_DEBUG
uint32_t ansType = RS_TOKREQ_ANSTYPE_DATA;
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
uint32_t token = 0;
RsGenExchange::getTokenService()->requestGroupInfo(token, ansType, opts);
GxsTokenQueue::queueRequest(token, GXSCHANNELS_UNPROCESSED_GENERIC);
}
void p3GxsChannels::load_SpecificUnprocessedPosts(const uint32_t &token)
{
std::vector<RsGxsChannelPost> posts;
if (!getRelatedPosts(token, posts))
{
std::cerr << "p3GxsChannels::load_GroupUnprocessedPosts ERROR";
return;
}
std::vector<RsGxsChannelPost>::iterator it;
for(it = posts.begin(); it != posts.end(); it++)
{
/* autodownload the files */
handleUnprocessedPost(*it);
}
}
void p3GxsChannels::load_GroupUnprocessedPosts(const uint32_t &token)
{
std::vector<RsGxsChannelPost> posts;
if (!getPostData(token, posts))
{
std::cerr << "p3GxsChannels::load_GroupUnprocessedPosts ERROR";
return;
}
std::vector<RsGxsChannelPost>::iterator it;
for(it = posts.begin(); it != posts.end(); it++)
{
handleUnprocessedPost(*it);
}
}
void p3GxsChannels::handleUnprocessedPost(const RsGxsChannelPost &msg)
{
std::cerr << "p3GxsChannels::handleUnprocessedPost() GroupId: " << msg.mMeta.mGroupId << " MsgId: " << msg.mMeta.mMsgId;
std::cerr << std::endl;
/* check that autodownload is set */
if (autoDownloadEnabled(msg.mMeta.mGroupId))
{
std::cerr << "p3GxsChannels::handleUnprocessedPost() AutoDownload Enabled ... handling";
std::cerr << std::endl;
/* check the date is not too old */
/* start download */
std::cerr << "p3GxsChannels::handleUnprocessedPost() START DOWNLOAD (TODO)";
std::cerr << std::endl;
/* mark as processed */
uint32_t token;
RsGxsGrpMsgIdPair msgId(msg.mMeta.mGroupId, msg.mMeta.mMsgId);
setMessageProcessedStatus(token, msgId, true);
}
else
{
std::cerr << "p3GxsChannels::handleUnprocessedPost() AutoDownload Disabled ... skipping";
std::cerr << std::endl;
}
}
// Overloaded from GxsTokenQueue for Request callbacks.
void p3GxsChannels::handleResponse(uint32_t token, uint32_t req_type)
{
#ifdef GXSCHANNELS_DEBUG
std::cerr << "p3GxsChannels::handleResponse(" << token << "," << req_type << ")";
std::cerr << std::endl;
#endif // GXSCHANNELS_DEBUG
// stuff.
switch(req_type)
{
case GXSCHANNELS_SUBSCRIBED_META:
load_SubscribedGroups(token);
break;
case GXSCHANNELS_UNPROCESSED_SPECIFIC:
load_SpecificUnprocessedPosts(token);
break;
case GXSCHANNELS_UNPROCESSED_GENERIC:
load_SpecificUnprocessedPosts(token);
break;
default:
/* error */
std::cerr << "p3GxsService::handleResponse() Unknown Request Type: " << req_type;
std::cerr << std::endl;
break;
}
}
/********************************************************************************************/
/********************************************************************************************/
bool p3GxsChannels::autoDownloadEnabled(const RsGxsGroupId &id)
{
std::cerr << "p3GxsChannels::autoDownloadEnabled(" << id << ")";
std::cerr << std::endl;
std::map<RsGxsGroupId, RsGroupMetaData>::iterator it;
it = mSubscribedGroups.find(id);
if (it != mSubscribedGroups.end())
{
std::cerr << "p3GxsChannels::autoDownloadEnabled() No Entry";
std::cerr << std::endl;
return false;
}
/* extract from ServiceString */
SSGxsChannelGroup ss;
ss.load(it->second.mServiceString);
return ss.mAutoDownload;
}
#define RSGXSCHANNEL_MAX_SERVICE_STRING 128
bool SSGxsChannelGroup::load(const std::string &input)
{
char line[RSGXSCHANNEL_MAX_SERVICE_STRING];
int download_val;
mAutoDownload = false;
if (1 == sscanf(input.c_str(), "D:%d", &download_val))
{
if (download_val == 1)
{
mAutoDownload = true;
}
}
return true;
}
std::string SSGxsChannelGroup::save() const
{
std::string output;
if (mAutoDownload)
{
output += "D:1";
}
else
{
output += "D:0";
}
return output;
}
bool p3GxsChannels::setAutoDownload(const RsGxsGroupId &groupId, bool enabled)
{
std::cerr << "p3GxsChannels::setAutoDownload() id: " << groupId << " enabled: " << enabled;
std::cerr << std::endl;
std::map<RsGxsGroupId, RsGroupMetaData>::iterator it;
it = mSubscribedGroups.find(groupId);
if (it != mSubscribedGroups.end())
{
std::cerr << "p3GxsChannels::setAutoDownload() Missing Group";
std::cerr << std::endl;
return false;
}
/* extract from ServiceString */
SSGxsChannelGroup ss;
ss.load(it->second.mServiceString);
if (enabled == ss.mAutoDownload)
{
/* it should be okay! */
std::cerr << "p3GxsChannels::setAutoDownload() WARNING setting looks okay already";
std::cerr << std::endl;
}
/* we are just going to set it anyway. */
ss.mAutoDownload = enabled;
std::string serviceString = ss.save();
uint32_t token;
RsGenExchange::setGroupServiceString(token, groupId, serviceString);
/* now reload it */
std::list<RsGxsGroupId> groups;
groups.push_back(groupId);
request_SpecificSubscribedGroups(groups);
return true;
}
/********************************************************************************************/
/********************************************************************************************/
void p3GxsChannels::setMessageProcessedStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool processed)
{
std::cerr << "p3GxsChannels::setMessageProcessedStatus()";
std::cerr << std::endl;
uint32_t mask = GXS_SERV::GXS_MSG_STATUS_UNPROCESSED;
uint32_t status = GXS_SERV::GXS_MSG_STATUS_UNPROCESSED;
if (processed)
{
status = 0;
}
setMsgStatusFlags(token, msgId, status, mask);
}
void p3GxsChannels::setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read)
{
std::cerr << "p3GxsChannels::setMessageReadStatus()";
std::cerr << std::endl;
uint32_t mask = GXS_SERV::GXS_MSG_STATUS_UNREAD;
uint32_t status = GXS_SERV::GXS_MSG_STATUS_UNREAD;
if (read)
{
status = 0;
}
setMsgStatusFlags(token, msgId, status, mask);
}
/********************************************************************************************/
/********************************************************************************************/
bool p3GxsChannels::createGroup(uint32_t &token, RsGxsChannelGroup &group)
@ -207,8 +689,7 @@ bool p3GxsChannels::createGroup(uint32_t &token, RsGxsChannelGroup &group)
std::cerr << "p3GxsChannels::createGroup()" << std::endl;
RsGxsChannelGroupItem* grpItem = new RsGxsChannelGroupItem();
grpItem->mGroup = group;
grpItem->meta = group.mMeta;
grpItem->fromChannelGroup(group, true);
RsGenExchange::publishGroup(token, grpItem);
return true;
@ -221,30 +702,13 @@ bool p3GxsChannels::createPost(uint32_t &token, RsGxsChannelPost &msg)
std::cerr << std::endl;
RsGxsChannelPostItem* msgItem = new RsGxsChannelPostItem();
msgItem->mMsg = msg;
msgItem->meta = msg.mMeta;
msgItem->fromChannelPost(msg, true);
RsGenExchange::publishMsg(token, msgItem);
return true;
}
/********************************************************************************************/
/********************************************************************************************/
void p3GxsChannels::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);
}
/********************************************************************************************/
/********************************************************************************************/
@ -451,7 +915,7 @@ bool p3GxsChannels::generateComment(uint32_t &token, const RsGxsGroupId &grpId,
rsIdentity->getOwnIds(ownIds);
uint32_t idx = (uint32_t) (ownIds.size() * RSRandom::random_f32());
int i = 0;
uint32_t i = 0;
for(it = ownIds.begin(); (it != ownIds.end()) && (i < idx); it++, i++);
if (it != ownIds.end())
@ -497,6 +961,9 @@ void p3GxsChannels::handle_event(uint32_t event_type, const std::string &elabel)
generateDummyData();
break;
case CHANNEL_PROCESS:
request_AllSubscribedGroups();
default:
/* error */
std::cerr << "p3GxsChannels::handle_event() Unknown Event Type: " << event_type;

View file

@ -30,6 +30,7 @@
#include "retroshare/rsgxschannels.h"
#include "services/p3gxscommon.h"
#include "gxs/rsgenexchange.h"
#include "gxs/gxstokenqueue.h"
#include "util/rstickevent.h"
@ -40,7 +41,20 @@
*
*/
class SSGxsChannelGroup
{
public:
bool load(const std::string &input);
std::string save() const;
bool mAutoDownload;
};
class p3GxsChannels: public RsGenExchange, public RsGxsChannels,
public GxsTokenQueue,
public RsTickEvent /* only needed for testing - remove after */
{
public:
@ -65,7 +79,6 @@ virtual bool getPostData(const uint32_t &token, std::vector<RsGxsChannelPost> &p
virtual bool getRelatedPosts(const uint32_t &token, std::vector<RsGxsChannelPost> &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);
@ -76,7 +89,7 @@ virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgI
virtual bool createGroup(uint32_t &token, RsGxsChannelGroup &group);
virtual bool createPost(uint32_t &token, RsGxsChannelPost &post);
virtual void setChannelAutoDownload(uint32_t&, const RsGxsGroupId&, bool);
/* Comment service - Provide RsGxsCommentService - redirect to p3GxsCommentService */
virtual bool getCommentData(const uint32_t &token, std::vector<RsGxsComment> &msgs)
@ -104,10 +117,46 @@ virtual bool acknowledgeComment(const uint32_t& token, std::pair<RsGxsGroupId, R
return acknowledgeMsg(token, msgId);
}
// Overloaded from RsGxsIface.
virtual void subscribeToGroup(const RsGxsGroupId &groupId, bool subscribe);
// Set Statuses.
virtual void setMessageProcessedStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool processed);
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read);
protected:
// Overloaded from GxsTokenQueue for Request callbacks.
virtual void handleResponse(uint32_t token, uint32_t req_type);
private:
static uint32_t channelsAuthenPolicy();
// Handle Processing.
void request_AllSubscribedGroups();
void request_SpecificSubscribedGroups(const std::list<RsGxsGroupId> &groups);
void load_SubscribedGroups(const uint32_t &token);
void request_SpecificUnprocessedPosts(std::list<std::pair<RsGxsGroupId, RsGxsMessageId> > &ids);
void load_SpecificUnprocessedPosts(const uint32_t &token);
void request_GroupUnprocessedPosts(const std::list<RsGxsGroupId> &grouplist);
void load_GroupUnprocessedPosts(const uint32_t &token);
void handleUnprocessedPost(const RsGxsChannelPost &msg);
// Local Cache of Subscribed Groups. and AutoDownload Flag.
void updateSubscribedGroup(const RsGroupMetaData &group);
void clearUnsubscribedGroup(const RsGxsGroupId &id);
bool autoDownloadEnabled(const RsGxsGroupId &id);
bool setAutoDownload(const RsGxsGroupId &groupId, bool enabled);
std::map<RsGxsGroupId, RsGroupMetaData> mSubscribedGroups;
// DUMMY DATA,
virtual bool generateDummyData();

View file

@ -28,6 +28,7 @@
#include "serialiser/rsgxscommentitems.h"
#include <stdio.h>
#include <stdlib.h>
RsGxsComment::RsGxsComment()
@ -37,6 +38,8 @@ RsGxsComment::RsGxsComment()
score = 0;
}
/********************************************************************************/
RsGxsImage::RsGxsImage()
{
mData = NULL;
@ -44,6 +47,64 @@ RsGxsImage::RsGxsImage()
}
RsGxsImage::~RsGxsImage()
{
clear();
}
void RsGxsImage::take(uint8_t *data, uint32_t size)
{
// Copies Pointer.
clear();
mData = data;
mSize = size;
}
// NB Must make sure that we always use malloc/free for this data.
uint8_t *RsGxsImage::allocate(uint32_t size)
{
return (uint8_t *) malloc(size);
}
void RsGxsImage::release(void *data)
{
free(data);
}
void RsGxsImage::copy(uint8_t *data, uint32_t size)
{
// Allocates and Copies.
clear();
if (data && size)
{
mData = allocate(size);
memcpy(mData, data, size);
mSize = size;
}
}
void RsGxsImage::clear()
{
// Frees.
if (mData)
{
release(mData);
}
mData = NULL;
mSize = 0;
}
void RsGxsImage::shallowClear()
{
// Clears Pointer.
mData = NULL;
mSize = 0;
}
/********************************************************************************/
RsGxsFile::RsGxsFile()
{
mSize = 0;

View file

@ -22,6 +22,8 @@
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#ifndef P3_GXSCOMMON_SERVICE_HEADER
#define P3_GXSCOMMON_SERVICE_HEADER
#include "retroshare/rsgxscommon.h"
#include "gxs/rsgenexchange.h"
@ -56,4 +58,5 @@ class p3GxsCommentService
};
#endif

View file

@ -56,11 +56,8 @@ p3GxsForums::p3GxsForums(RsGeneralDataService *gds, RsNetworkExchangeService *ne
// For Dummy Msgs.
mGenActive = false;
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
RsTickEvent::schedule_in(FORUM_TESTEVENT_DUMMYDATA, DUMMYDATA_PERIOD);
#endif
// Test Data disabled in Repo.
//RsTickEvent::schedule_in(FORUM_TESTEVENT_DUMMYDATA, DUMMYDATA_PERIOD);
}

File diff suppressed because it is too large Load diff

View file

@ -1,175 +1,153 @@
#ifndef P3POSTED_H
#define P3POSTED_H
#include <map>
#include "retroshare/rsposted.h"
#include "gxs/rsgenexchange.h"
class GxsPostedPostRanking
{
public:
uint32_t pubToken;
uint32_t reqToken;
RsPosted::RankType rType;
RsGxsGroupId grpId;
RsPostedPostRanking rankingResult;
};
class GxsPostedCommentRanking
{
public:
uint32_t pubToken;
uint32_t reqToken;
RsPosted::RankType rType;
RsGxsGrpMsgIdPair msgId;
PostedRanking result;
};
class PostedScore {
public:
PostedScore() : upVotes(0), downVotes(0), commentCount(0), date(0) {}
uint32_t upVotes, downVotes;
uint32_t commentCount;
time_t date;
RsGxsMessageId msgId;
};
class p3Posted : public RsGenExchange, public RsPosted
{
public:
p3Posted(RsGeneralDataService* gds, RsNetworkExchangeService* nes);
protected:
/*!
* This confirms this class as an abstract one that \n
* should not be instantiated \n
* The deriving class should implement this function \n
* as it is called by the backend GXS system to \n
* update client of changes which should \n
* instigate client to retrieve new content from the system
* @param changes the changes that have occured to data held by this service
*/
void notifyChanges(std::vector<RsGxsNotify*>& changes) ;
void service_tick();
public:
void generateTopics();
/*!
* Exists solely for testing
*/
void generatePosts();
/*!
* Exists solely for testing
* Generates random votes to existing posts
* in the system
*/
void generateVotesAndComments();
public:
bool getGroup(const uint32_t &token, std::vector<RsPostedGroup> &group);
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 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 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;
private:
/* Functions for processing rankings */
void processRankings();
void processPostRanks();
void processCommentRanks();
void discardCalc(const uint32_t& token);
bool completePostedPostCalc(GxsPostedPostRanking* gpp);
void completePostedCommentRanking(GxsPostedCommentRanking* gpc);
bool storeScores(std::string& serviceString, uint32_t& upVotes, uint32_t downVotes, uint32_t nComments) const;
// for posts
void calcPostedPostRank(const std::vector<RsMsgMetaData>, PostedRanking& ranking, bool com(const PostedScore& i, const PostedScore &j)) const;
// for comments
void calcPostedCommentsRank(const std::map<RsGxsMessageId, std::vector<RsGxsMessageId> >& msgBranches, std::map<RsGxsMessageId, RsMsgMetaData>& msgMetas,
PostedRanking& ranking, bool com(const PostedScore& i, const PostedScore &j)) const;
/* Functions for maintaing vote counts in meta data */
/*!
* Update votes should only be called when a vote comes in
* Several phases to calculating votes.
* First get all messages for groups which you are subscribed
* Then for these messages get all the votes accorded to them
* Then do the calculation and update messages
* Also stores updates for messages which have new scores
*/
void updateVotes();
bool updateRequestGroups();
bool updateRequestMessages();
bool updateRequestVotesComments();
bool updateCompleteVotes();
bool updateCompleteComments();
/*!
* The aim of this is create notifications
* for the UI of changes to a post if their vote
* or comment count has changed
*/
bool updateComplete();
private:
// for calculating ranks
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;
// for maintaining vote counts in msg meta
uint32_t mUpdateRequestGroup, mUpdateRequestMessages, mUpdateRequestComments, mUpdateRequestVotes;
bool mPostUpdate;
uint32_t mUpdatePhase;
std::vector<RsGxsGrpMsgIdPair> mMsgsPendingUpdate;
time_t mLastUpdate;
GxsMsgMetaMap mMsgMetaUpdate;
std::map<RsGxsGrpMsgIdPair, PostedScore > mMsgCounts;
std::vector<uint32_t> mChangeTokens;
RsTokenService* mTokenService;
RsMutex mPostedMutex;
// for data generation
bool mGeneratingPosts, mGeneratingTopics,
mRequestPhase1, mRequestPhase2, mRequestPhase3, mGenerateVotesAndComments;
std::vector<uint32_t> mTokens;
uint32_t mToken;
std::list<RsGxsGroupId> mGrpIds;
};
#endif // P3POSTED_H
/*
* libretroshare/src/services: p3posted.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_POSTED_SERVICE_HEADER
#define P3_POSTED_SERVICE_HEADER
#include "retroshare/rsposted.h"
#include "services/p3gxscommon.h"
#include "gxs/rsgenexchange.h"
#include "util/rstickevent.h"
#include <map>
#include <string>
/*
*
*/
class p3Posted: public RsGenExchange, public RsPosted,
public RsTickEvent /* only needed for testing - remove after */
{
public:
p3Posted(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs* gixs);
virtual void service_tick();
protected:
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes);
// Overloaded from RsTickEvent.
virtual void handle_event(uint32_t event_type, const std::string &elabel);
public:
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);
//////////////////////////////////////////////////////////////////////////////
// SPECIAL REQUEST.
virtual bool requestPostRankings(uint32_t &token, const RankType &rType, uint32_t count, uint32_t page_no, const RsGxsGroupId &groupId);
virtual bool getPostRanking(const uint32_t &token, std::vector<RsPostedPost> &msgs);
//////////////////////////////////////////////////////////////////////////////
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);
/* Comment service - Provide RsGxsCommentService - redirect to p3GxsCommentService */
virtual bool getCommentData(const uint32_t &token, std::vector<RsGxsComment> &msgs)
{
return mCommentService->getGxsCommentData(token, msgs);
}
virtual bool getRelatedComments(const uint32_t &token, std::vector<RsGxsComment> &msgs)
{
return mCommentService->getGxsRelatedComments(token, msgs);
}
virtual bool createComment(uint32_t &token, RsGxsComment &msg)
{
return mCommentService->createGxsComment(token, msg);
}
virtual bool createVote(uint32_t &token, RsGxsVote &msg)
{
return mCommentService->createGxsVote(token, msg);
}
virtual bool acknowledgeComment(const uint32_t& token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId)
{
return acknowledgeMsg(token, msgId);
}
private:
static uint32_t postedAuthenPolicy();
// 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

View file

@ -35,11 +35,6 @@
RsWiki *rsWiki = NULL;
/**
* #define WIKI_GEN_DUMMY_DATA 1
**/
#define WIKI_GEN_DUMMY_DATA 1
#define WIKI_EVENT_DUMMYTICK 0x0001
#define WIKI_EVENT_DUMMYSTART 0x0002
@ -56,11 +51,8 @@ p3Wiki::p3Wiki(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs
mImprovActive = false;
mMarkdownActive = false;
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
#ifdef WIKI_GEN_DUMMY_DATA
RsTickEvent::schedule_in(WIKI_EVENT_DUMMYSTART, DUMMYSTART_PERIOD);
#endif
#endif
// TestData disabled in Repo.
//RsTickEvent::schedule_in(WIKI_EVENT_DUMMYSTART, DUMMYSTART_PERIOD);
}