From 9373d26be0ec0c7d4474a668adec2c640e95a98c Mon Sep 17 00:00:00 2001 From: drbob Date: Thu, 15 Nov 2012 23:50:54 +0000 Subject: [PATCH] * Added Dummy Forums and Messages to GxsForums. * Extra GxsForums::getRelatedMessages() fn + HACKs to cover up GXS bugs. * more debugging in rsgenexchange. * fixed up some of wikis text. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5828 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/gxs/rsgenexchange.cc | 29 +- libretroshare/src/retroshare/rsgxsforums.h | 2 + .../src/serialiser/rsgxsforumitems.cc | 2 +- libretroshare/src/services/p3gxsforums.cc | 434 ++++++++++-------- libretroshare/src/services/p3gxsforums.h | 27 +- libretroshare/src/services/p3wiki.cc | 8 +- 6 files changed, 293 insertions(+), 209 deletions(-) diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index dbf6e5600..5712bf4f6 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -47,6 +47,8 @@ #define PRIV_GRP_OFFSET 16 #define GRP_OPTIONS_OFFSET 24 +#define GEN_EXCH_DEBUG 1 + RsGenExchange::RsGenExchange(RsGeneralDataService *gds, RsNetworkExchangeService *ns, RsSerialType *serviceSerialiser, uint16_t servType, RsGixs* gixs, uint32_t authenPolicy) : mGenMtx("GenExchange"), mDataStore(gds), mNetService(ns), mSerialiser(serviceSerialiser), @@ -952,17 +954,27 @@ void RsGenExchange::publishGroup(uint32_t& token, RsGxsGrpItem *grpItem) { RsStackMutex stack(mGenMtx); - token = mDataAccess->generatePublicToken(); mGrpsToPublish.insert(std::make_pair(token, grpItem)); + +#ifdef GEN_EXCH_DEBUG + std::cerr << "RsGenExchange::publishGroup() token: " << token; + std::cerr << std::endl; +#endif + } void RsGenExchange::publishMsg(uint32_t& token, RsGxsMsgItem *msgItem) { RsStackMutex stack(mGenMtx); - token = mDataAccess->generatePublicToken(); mMsgsToPublish.insert(std::make_pair(token, msgItem)); + +#ifdef GEN_EXCH_DEBUG + std::cerr << "RsGenExchange::publishMsg() token: " << token; + std::cerr << std::endl; +#endif + } void RsGenExchange::setGroupSubscribeFlags(uint32_t& token, const RsGxsGroupId& grpId, const uint32_t& flag, const uint32_t& mask) @@ -1125,6 +1137,13 @@ void RsGenExchange::publishMsgs() req.insert(std::make_pair(msg->grpId, msgV)); mDataStore->retrieveGxsMsgMetaData(req, res); msgDoesnExist = res[grpId].empty(); + +#ifdef GEN_EXCH_DEBUG + if (!msgDoesnExist) + { + std::cerr << "RsGenExchange::publishMsgs() msg exists already :( " << std::endl; + } +#endif } if(createOk && msgDoesnExist) @@ -1167,6 +1186,12 @@ void RsGenExchange::publishMsgs() #endif } } + else + { +#ifdef GEN_EXCH_DEBUG + std::cerr << "RsGenExchange::publishMsgs() failed to serialise msg " << std::endl; +#endif + } delete[] mData; delete msgItem; diff --git a/libretroshare/src/retroshare/rsgxsforums.h b/libretroshare/src/retroshare/rsgxsforums.h index 34d57b89d..8c18509e5 100644 --- a/libretroshare/src/retroshare/rsgxsforums.h +++ b/libretroshare/src/retroshare/rsgxsforums.h @@ -75,6 +75,7 @@ virtual ~RsGxsForums() { return; } /* Specific Service Data */ virtual bool getGroupData(const uint32_t &token, std::vector &groups) = 0; virtual bool getMsgData(const uint32_t &token, std::vector &msgs) = 0; +virtual bool getRelatedMessages(const uint32_t &token, std::vector &msgs) = 0; ////////////////////////////////////////////////////////////////////////////// virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read) = 0; @@ -88,6 +89,7 @@ virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgI virtual bool createGroup(uint32_t &token, RsGxsForumGroup &group) = 0; virtual bool createMsg(uint32_t &token, RsGxsForumMsg &msg) = 0; +virtual bool generateDummyData() = 0; }; diff --git a/libretroshare/src/serialiser/rsgxsforumitems.cc b/libretroshare/src/serialiser/rsgxsforumitems.cc index 2d0f90430..9423ce058 100644 --- a/libretroshare/src/serialiser/rsgxsforumitems.cc +++ b/libretroshare/src/serialiser/rsgxsforumitems.cc @@ -279,7 +279,7 @@ uint32_t RsGxsForumSerialiser::sizeGxsForumMsgItem(RsGxsForumMsgItem *item) const RsGxsForumMsg& msg = item->mMsg; uint32_t s = 8; // header - s += 4; // mMsg. + s += GetTlvStringSize(msg.mMsg); // mMsg. return s; } diff --git a/libretroshare/src/services/p3gxsforums.cc b/libretroshare/src/services/p3gxsforums.cc index 6d0bd2985..6c539cd97 100644 --- a/libretroshare/src/services/p3gxsforums.cc +++ b/libretroshare/src/services/p3gxsforums.cc @@ -26,10 +26,14 @@ #include "services/p3gxsforums.h" #include "serialiser/rsgxsforumitems.h" -#include "util/rsrandom.h" + #include "gxs/rsgxsflags.h" #include +// For Dummy Msgs. +#include "util/rsrandom.h" +#include "util/rsstring.h" + /**** * #define GXSFORUM_DEBUG 1 ****/ @@ -45,6 +49,8 @@ RsGxsForums *rsGxsForums = NULL; p3GxsForums::p3GxsForums(RsGeneralDataService *gds, RsNetworkExchangeService *nes) : RsGenExchange(gds, nes, new RsGxsForumSerialiser(), RS_SERVICE_GXSV1_TYPE_FORUMS), RsGxsForums(this) { + // For Dummy Msgs. + mGenActive = false; } void p3GxsForums::notifyChanges(std::vector &changes) @@ -54,6 +60,7 @@ void p3GxsForums::notifyChanges(std::vector &changes) void p3GxsForums::service_tick() { + dummy_tick(); return; } @@ -122,6 +129,65 @@ bool p3GxsForums::getMsgData(const uint32_t &token, std::vector & return ok; } + +bool p3GxsForums::getRelatedMessages(const uint32_t &token, std::vector &msgs) +{ + GxsMsgRelatedDataMap msgData; + bool ok = RsGenExchange::getMsgRelatedData(token, msgData); + + if(ok) + { + GxsMsgRelatedDataMap::iterator mit = msgData.begin(); + + for(; mit != msgData.end(); mit++) + { + std::vector& msgItems = mit->second; + std::vector::iterator vit = msgItems.begin(); + + for(; vit != msgItems.end(); vit++) + { + RsGxsForumMsgItem* item = dynamic_cast(*vit); + + if(item) + { + /* HACK UNTIL CHRIS FIXES RELATED MSGS in GXS */ + if (item->meta.mMsgId == (mit->first).second) + { + std::cerr << "p3GxsForums::getRelatedMessages()"; + std::cerr << " ERROR Found Original - discarding"; + std::cerr << " Id: " << item->meta.mMsgId; + std::cerr << std::endl; + delete item; + continue; + } + + if (item->meta.mParentId != (mit->first).second) + { + std::cerr << "p3GxsForums::getRelatedMessages()"; + std::cerr << " ERROR Found !CHILD - discarding"; + std::cerr << " Id: " << item->meta.mMsgId; + std::cerr << std::endl; + delete item; + continue; + } + + RsGxsForumMsg msg = item->mMsg; + msg.mMeta = item->meta; + msgs.push_back(msg); + delete item; + } + else + { + std::cerr << "Not a GxsForumMsgItem, deleting!" << std::endl; + delete *vit; + } + } + } + } + + return ok; +} + /********************************************************************************************/ bool p3GxsForums::createGroup(uint32_t &token, RsGxsForumGroup &group) @@ -170,218 +236,184 @@ void p3GxsForums::setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& /********************************************************************************************/ /********************************************************************************************/ +/* so we need the same tick idea as wiki for generating dummy forums + */ + +#define MAX_GEN_GROUPS 5 +#define MAX_GEN_MESSAGES 100 std::string p3GxsForums::genRandomId() { - std::string randomId; - for(int i = 0; i < 20; i++) - { - randomId += (char) ('a' + (RSRandom::random_u32() % 26)); - } - - return randomId; + std::string randomId; + for(int i = 0; i < 20; i++) + { + randomId += (char) ('a' + (RSRandom::random_u32() % 26)); + } + + return randomId; } bool p3GxsForums::generateDummyData() { - return false; -} + mGenCount = 0; + mGenRefs.resize(MAX_GEN_MESSAGES); + std::string groupName; + rs_sprintf(groupName, "TestForum_%d", mGenCount); -#if 0 + std::cerr << "p3GxsForums::generateDummyData() Starting off with Group: " << groupName; + std::cerr << std::endl; -bool p3GxsForums::generateDummyData() -{ - /* so we want to generate 100's of forums */ -#define MAX_FORUMS 10 //100 -#define MAX_THREADS 10 //1000 -#define MAX_MSGS 100 //10000 + /* create a new group */ + generateGroup(mGenToken, groupName); - std::list mGroups; - std::list::iterator git; - - std::list mMsgs; - std::list::iterator mit; - -#define DUMMY_NAME_MAX_LEN 10000 - char name[DUMMY_NAME_MAX_LEN]; - int i, j; - time_t now = time(NULL); - - for(i = 0; i < MAX_FORUMS; i++) - { - /* generate a new forum */ - RsForumV2Group forum; - - /* generate a temp id */ - forum.mMeta.mGroupId = genRandomId(); - - snprintf(name, DUMMY_NAME_MAX_LEN, "TestForum_%d", i+1); - - forum.mMeta.mGroupId = genRandomId(); - forum.mMeta.mGroupName = name; - - forum.mMeta.mPublishTs = now - (RSRandom::random_f32() * 100000); - /* key fields to fill in: - * GroupId. - * Name. - * Flags. - * Pop. - */ - - - - /* use probability to decide which are subscribed / own / popularity. - */ - - float rnd = RSRandom::random_f32(); - if (rnd < 0.1) - { - forum.mMeta.mSubscribeFlags = RSGXS_GROUP_SUBSCRIBE_ADMIN; - - } - else if (rnd < 0.3) - { - forum.mMeta.mSubscribeFlags = RSGXS_GROUP_SUBSCRIBE_SUBSCRIBED; - } - else - { - forum.mMeta.mSubscribeFlags = 0; - } - - forum.mMeta.mPop = (int) (RSRandom::random_f32() * 10.0); - - mGroups.push_back(forum); - - - //std::cerr << "p3GxsForums::generateDummyData() Generated Forum: " << forum.mMeta; - //std::cerr << std::endl; - } - - - for(i = 0; i < MAX_THREADS; i++) - { - /* generate a base thread */ - - /* rotate the Forum Groups Around, then pick one. - */ - - int rnd = (int) (RSRandom::random_f32() * 10.0); - - for(j = 0; j < rnd; j++) - { - RsForumV2Group head = mGroups.front(); - mGroups.pop_front(); - mGroups.push_back(head); - } - - RsForumV2Group forum = mGroups.front(); - - /* now create a new thread */ - - RsForumV2Msg msg; - - /* fill in key data - * GroupId - * MsgId - * OrigMsgId - * ThreadId - * ParentId - * PublishTS (take Forum TS + a bit ). - * - * ChildTS ???? - */ - snprintf(name, DUMMY_NAME_MAX_LEN, "%s => ThreadMsg_%d", forum.mMeta.mGroupName.c_str(), i+1); - msg.mMeta.mMsgName = name; - - msg.mMeta.mGroupId = forum.mMeta.mGroupId; - msg.mMeta.mMsgId = genRandomId(); - msg.mMeta.mOrigMsgId = msg.mMeta.mMsgId; - msg.mMeta.mThreadId = msg.mMeta.mMsgId; - msg.mMeta.mParentId = ""; - - msg.mMeta.mPublishTs = forum.mMeta.mPublishTs + (RSRandom::random_f32() * 10000); - if (msg.mMeta.mPublishTs > now) - msg.mMeta.mPublishTs = now - 1; - - mMsgs.push_back(msg); - - //std::cerr << "p3GxsForums::generateDummyData() Generated Thread: " << msg.mMeta; - //std::cerr << std::endl; - - } - - for(i = 0; i < MAX_MSGS; i++) - { - /* generate a base thread */ - - /* rotate the Forum Groups Around, then pick one. - */ - - int rnd = (int) (RSRandom::random_f32() * 10.0); - - for(j = 0; j < rnd; j++) - { - RsForumV2Msg head = mMsgs.front(); - mMsgs.pop_front(); - mMsgs.push_back(head); - } - - RsForumV2Msg parent = mMsgs.front(); - - /* now create a new child msg */ - - RsForumV2Msg msg; - - /* fill in key data - * GroupId - * MsgId - * OrigMsgId - * ThreadId - * ParentId - * PublishTS (take Forum TS + a bit ). - * - * ChildTS ???? - */ - snprintf(name, DUMMY_NAME_MAX_LEN, "%s => Msg_%d", parent.mMeta.mMsgName.c_str(), i+1); - msg.mMeta.mMsgName = name; - msg.mMsg = name; - - msg.mMeta.mGroupId = parent.mMeta.mGroupId; - msg.mMeta.mMsgId = genRandomId(); - msg.mMeta.mOrigMsgId = msg.mMeta.mMsgId; - msg.mMeta.mThreadId = parent.mMeta.mThreadId; - msg.mMeta.mParentId = parent.mMeta.mOrigMsgId; - - msg.mMeta.mPublishTs = parent.mMeta.mPublishTs + (RSRandom::random_f32() * 10000); - if (msg.mMeta.mPublishTs > now) - msg.mMeta.mPublishTs = now - 1; - - mMsgs.push_back(msg); - - //std::cerr << "p3GxsForums::generateDummyData() Generated Child Msg: " << msg.mMeta; - //std::cerr << std::endl; - - } - - - mUpdated = true; - - /* Then - at the end, we push them all into the Proxy */ - for(git = mGroups.begin(); git != mGroups.end(); git++) - { - /* pushback */ - mForumProxy->addForumGroup(*git); - - } - - for(mit = mMsgs.begin(); mit != mMsgs.end(); mit++) - { - /* pushback */ - mForumProxy->addForumMsg(*mit); - } + mGenActive = true; + + return true; +} + + +void p3GxsForums::dummy_tick() +{ + /* check for a new callback */ + + if (mGenActive) + { + std::cerr << "p3Wiki::dummyTick() AboutActive"; + std::cerr << std::endl; + + uint32_t status = RsGenExchange::getTokenService()->requestStatus(mGenToken); + if (status != RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE) + { + std::cerr << "p3GxsForums::dummy_tick() Status: " << status; + std::cerr << std::endl; + + if (status == RsTokenService::GXS_REQUEST_V2_STATUS_FAILED) + { + std::cerr << "p3GxsForums::dummy_tick() generateDummyMsgs() FAILED"; + std::cerr << std::endl; + mGenActive = false; + } + return; + } + + if (mGenCount < MAX_GEN_GROUPS) + { + /* get the group Id */ + RsGxsGroupId groupId; + RsGxsMessageId emptyId; + if (!acknowledgeTokenGrp(mGenToken, groupId)) + { + std::cerr << " ERROR "; + std::cerr << std::endl; + mGenActive = false; + return; + } + + std::cerr << "p3GxsForums::dummy_tick() Acknowledged GroupId: " << groupId; + std::cerr << std::endl; + + ForumDummyRef ref(groupId, emptyId, emptyId); + mGenRefs[mGenCount] = ref; + } + else if (mGenCount < MAX_GEN_MESSAGES) + { + /* get the msg Id, and generate next snapshot */ + RsGxsGrpMsgIdPair msgId; + if (!acknowledgeTokenMsg(mGenToken, msgId)) + { + std::cerr << " ERROR "; + std::cerr << std::endl; + mGenActive = false; + return; + } + + std::cerr << "p3GxsForums::dummy_tick() Acknowledged "; + std::cerr << std::endl; + + /* store results for later selection */ + + ForumDummyRef ref(msgId.first, mGenThreadId, msgId.second); + mGenRefs[mGenCount] = ref; + } + else + { + std::cerr << "p3GxsForums::dummy_tick() Finished"; + std::cerr << std::endl; + + /* done */ + mGenActive = false; + return; + } + + mGenCount++; + + if (mGenCount < MAX_GEN_GROUPS) + { + std::string groupName; + rs_sprintf(groupName, "TestForum_%d", mGenCount); + + std::cerr << "p3GxsForums::dummy_tick() Generating Group: " << groupName; + std::cerr << std::endl; + + /* create a new group */ + generateGroup(mGenToken, groupName); + } + else + { + /* create a new message */ + uint32_t idx = (uint32_t) (mGenCount * RSRandom::random_f32()); + ForumDummyRef &ref = mGenRefs[idx]; + + RsGxsGroupId grpId = ref.mGroupId; + RsGxsMessageId parentId = ref.mMsgId; + mGenThreadId = ref.mThreadId; + if (mGenThreadId.empty()) + { + mGenThreadId = parentId; + } + + std::cerr << "p3GxsForums::dummy_tick() Generating Msg ... "; + std::cerr << " GroupId: " << grpId; + std::cerr << " ThreadId: " << mGenThreadId; + std::cerr << " ParentId: " << parentId; + std::cerr << std::endl; + + generateMessage(mGenToken, grpId, parentId, mGenThreadId); + } + } +} + + +bool p3GxsForums::generateMessage(uint32_t &token, const RsGxsGroupId &grpId, const RsGxsMessageId &parentId, const RsGxsMessageId &threadId) +{ + RsGxsForumMsg msg; + + std::string rndId = genRandomId(); + + rs_sprintf(msg.mMsg, "Forum Msg: GroupId: %s, ThreadId: %s, ParentId: %s + some randomness: %s", + grpId.c_str(), threadId.c_str(), parentId.c_str(), rndId.c_str()); + + msg.mMeta.mMsgName = msg.mMsg; + + msg.mMeta.mGroupId = grpId; + msg.mMeta.mThreadId = threadId; + msg.mMeta.mParentId = parentId; + + createMsg(token, msg); + + return true; +} + + +bool p3GxsForums::generateGroup(uint32_t &token, std::string groupName) +{ + /* generate a new forum */ + RsGxsForumGroup forum; + forum.mMeta.mGroupName = groupName; + + createGroup(token, forum); return true; } -#endif diff --git a/libretroshare/src/services/p3gxsforums.h b/libretroshare/src/services/p3gxsforums.h index 8ed77ab80..a8a45358f 100644 --- a/libretroshare/src/services/p3gxsforums.h +++ b/libretroshare/src/services/p3gxsforums.h @@ -52,6 +52,7 @@ virtual void service_tick(); virtual bool getGroupData(const uint32_t &token, std::vector &groups); virtual bool getMsgData(const uint32_t &token, std::vector &msgs); +virtual bool getRelatedMessages(const uint32_t &token, std::vector &msgs); ////////////////////////////////////////////////////////////////////////////// virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read); @@ -65,11 +66,35 @@ virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgI virtual bool createGroup(uint32_t &token, RsGxsForumGroup &group); virtual bool createMsg(uint32_t &token, RsGxsForumMsg &msg); +virtual bool generateDummyData(); private: std::string genRandomId(); -bool generateDummyData(); +void dummy_tick(); + +bool generateMessage(uint32_t &token, const RsGxsGroupId &grpId, + const RsGxsMessageId &parentId, const RsGxsMessageId &threadId); +bool generateGroup(uint32_t &token, std::string groupName); + + class ForumDummyRef + { + public: + ForumDummyRef() { return; } + ForumDummyRef(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 mGenRefs; + RsGxsMessageId mGenThreadId; + }; #endif diff --git a/libretroshare/src/services/p3wiki.cc b/libretroshare/src/services/p3wiki.cc index 508f5fed9..29cc0200e 100644 --- a/libretroshare/src/services/p3wiki.cc +++ b/libretroshare/src/services/p3wiki.cc @@ -330,13 +330,13 @@ const std::string improvements_txt[] = " - Diffs, lots of edits will lead to complex merges - a robust merge tool is essential\n", " - Read Mode... hide all the Edits, and only show the most recently published versions\n", " - Easy Duplication - to take over an Abandoned or badly moderated Wiki. Copies All base versions to a new group\n", - " - WikiLinks. A generic Wiki Cross Linking system. This should be combined with Easy Duplication option,\n", - " to allow easy replacement of groups if necessary... A good design here is critical to a successful Wiki ecosystem", - " the republished page becomes a new version of the Root Page, allowing more edits to be done\n", + " - WikiLinks. A generic Wiki Cross Linking system. This should be combined with Easy Duplication option,", + " to allow easy replacement of groups if necessary... A good design here is critical to a successful Wiki ecosystem\n", " - work out how to include media (photos, audio, video, etc) without embedding in pages", " this would leverage the turtle transfer system somehow - maybe like channels.\n", " - Comments, reviews etc can be incorporated - ideas here are welcome.\n", - " - Any other suggestion???" + " - Any other suggestion???", + " - Come on more ideas!" };