mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-27 07:47:03 -05:00
merging gxs_phase2 branch
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6401 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
1150366913
commit
325fa4f222
@ -47,6 +47,7 @@
|
||||
#define KEY_NXS_FLAGS std::string("flags")
|
||||
#define KEY_NXS_META std::string("meta")
|
||||
#define KEY_NXS_SERV_STRING std::string("serv_str")
|
||||
#define KEY_NXS_HASH std::string("hash")
|
||||
|
||||
|
||||
// grp table columns
|
||||
@ -57,6 +58,7 @@
|
||||
#define KEY_GRP_CIRCLE_TYPE std::string("circleType")
|
||||
#define KEY_GRP_INTERNAL_CIRCLE std::string("internalCircle")
|
||||
#define KEY_GRP_ORIGINATOR std::string("originator")
|
||||
#define KEY_GRP_AUTHEN_FLAGS std::string("authenFlags")
|
||||
|
||||
// grp local
|
||||
#define KEY_GRP_SUBCR_FLAG std::string("subscribeFlag")
|
||||
@ -94,31 +96,32 @@
|
||||
|
||||
// grp col numbers
|
||||
|
||||
#define COL_KEY_SET 5
|
||||
#define COL_GRP_SUBCR_FLAG 6
|
||||
#define COL_GRP_POP 7
|
||||
#define COL_MSG_COUNT 8
|
||||
#define COL_GRP_STATUS 9
|
||||
#define COL_GRP_NAME 10
|
||||
#define COL_GRP_LAST_POST 11
|
||||
#define COL_ORIG_GRP_ID 12
|
||||
#define COL_GRP_SERV_STRING 13
|
||||
#define COL_GRP_SIGN_FLAGS 14
|
||||
#define COL_GRP_CIRCLE_ID 15
|
||||
#define COL_GRP_CIRCL_TYPE 16
|
||||
#define COL_GRP_INTERN_CIRCLE 17
|
||||
#define COL_GRP_ORIGINATOR 18
|
||||
#define COL_KEY_SET 6
|
||||
#define COL_GRP_SUBCR_FLAG 7
|
||||
#define COL_GRP_POP 8
|
||||
#define COL_MSG_COUNT 9
|
||||
#define COL_GRP_STATUS 10
|
||||
#define COL_GRP_NAME 11
|
||||
#define COL_GRP_LAST_POST 12
|
||||
#define COL_ORIG_GRP_ID 13
|
||||
#define COL_GRP_SERV_STRING 14
|
||||
#define COL_GRP_SIGN_FLAGS 15
|
||||
#define COL_GRP_CIRCLE_ID 16
|
||||
#define COL_GRP_CIRCL_TYPE 17
|
||||
#define COL_GRP_INTERN_CIRCLE 18
|
||||
#define COL_GRP_ORIGINATOR 19
|
||||
#define COL_GRP_AUTHEN_FLAGS 20
|
||||
|
||||
|
||||
// msg col numbers
|
||||
#define COL_MSG_ID 5
|
||||
#define COL_ORIG_MSG_ID 6
|
||||
#define COL_MSG_STATUS 7
|
||||
#define COL_CHILD_TS 8
|
||||
#define COL_PARENT_ID 9
|
||||
#define COL_THREAD_ID 10
|
||||
#define COL_MSG_NAME 11
|
||||
#define COL_MSG_SERV_STRING 12
|
||||
#define COL_MSG_ID 6
|
||||
#define COL_ORIG_MSG_ID 7
|
||||
#define COL_MSG_STATUS 8
|
||||
#define COL_CHILD_TS 9
|
||||
#define COL_PARENT_ID 10
|
||||
#define COL_THREAD_ID 11
|
||||
#define COL_MSG_NAME 12
|
||||
#define COL_MSG_SERV_STRING 13
|
||||
|
||||
// generic meta shared col numbers
|
||||
#define COL_GRP_ID 0
|
||||
@ -126,6 +129,7 @@
|
||||
#define COL_NXS_FLAGS 2
|
||||
#define COL_SIGN_SET 3
|
||||
#define COL_IDENTITY 4
|
||||
#define COL_HASH 5
|
||||
|
||||
#define RS_DATA_SERVICE_DEBUG
|
||||
|
||||
@ -139,15 +143,15 @@ const std::string RsGeneralDataService::MSG_META_STATUS = KEY_MSG_STATUS;
|
||||
const uint32_t RsGeneralDataService::GXS_MAX_ITEM_SIZE = 1572864; // 1.5 Mbytes
|
||||
|
||||
RsDataService::RsDataService(const std::string &serviceDir, const std::string &dbName, uint16_t serviceType,
|
||||
RsGxsSearchModule *mod)
|
||||
RsGxsSearchModule *mod, const std::string& key)
|
||||
: RsGeneralDataService(), mServiceDir(serviceDir), mDbName(mServiceDir + "/" + dbName), mServType(serviceType),
|
||||
mDbMutex("RsDataService"){
|
||||
mDbMutex("RsDataService"), mDb( new RetroDb(mDbName, RetroDb::OPEN_READWRITE_CREATE, key)) {
|
||||
|
||||
initialise();
|
||||
|
||||
// for retrieving msg meta
|
||||
msgMetaColumns.push_back(KEY_GRP_ID); msgMetaColumns.push_back(KEY_TIME_STAMP); msgMetaColumns.push_back(KEY_NXS_FLAGS);
|
||||
msgMetaColumns.push_back(KEY_SIGN_SET); msgMetaColumns.push_back(KEY_NXS_IDENTITY);
|
||||
msgMetaColumns.push_back(KEY_SIGN_SET); msgMetaColumns.push_back(KEY_NXS_IDENTITY); msgMetaColumns.push_back(KEY_NXS_HASH);
|
||||
msgMetaColumns.push_back(KEY_MSG_ID); msgMetaColumns.push_back(KEY_ORIG_MSG_ID); msgMetaColumns.push_back(KEY_MSG_STATUS);
|
||||
msgMetaColumns.push_back(KEY_CHILD_TS); msgMetaColumns.push_back(KEY_MSG_PARENT_ID); msgMetaColumns.push_back(KEY_MSG_THREAD_ID);
|
||||
msgMetaColumns.push_back(KEY_MSG_NAME); msgMetaColumns.push_back(KEY_NXS_SERV_STRING);
|
||||
@ -158,12 +162,13 @@ RsDataService::RsDataService(const std::string &serviceDir, const std::string &d
|
||||
|
||||
// for retrieving grp meta data
|
||||
grpMetaColumns.push_back(KEY_GRP_ID); grpMetaColumns.push_back(KEY_TIME_STAMP); grpMetaColumns.push_back(KEY_NXS_FLAGS);
|
||||
grpMetaColumns.push_back(KEY_SIGN_SET); grpMetaColumns.push_back(KEY_NXS_IDENTITY);
|
||||
grpMetaColumns.push_back(KEY_SIGN_SET); grpMetaColumns.push_back(KEY_NXS_IDENTITY); grpMetaColumns.push_back(KEY_NXS_HASH);
|
||||
grpMetaColumns.push_back(KEY_KEY_SET); grpMetaColumns.push_back(KEY_GRP_SUBCR_FLAG); grpMetaColumns.push_back(KEY_GRP_POP);
|
||||
grpMetaColumns.push_back(KEY_MSG_COUNT); grpMetaColumns.push_back(KEY_GRP_STATUS); grpMetaColumns.push_back(KEY_GRP_NAME);
|
||||
grpMetaColumns.push_back(KEY_GRP_LAST_POST); grpMetaColumns.push_back(KEY_ORIG_GRP_ID); grpMetaColumns.push_back(KEY_NXS_SERV_STRING);
|
||||
grpMetaColumns.push_back(KEY_GRP_SIGN_FLAGS); grpMetaColumns.push_back(KEY_GRP_CIRCLE_ID); grpMetaColumns.push_back(KEY_GRP_CIRCLE_TYPE);
|
||||
grpMetaColumns.push_back(KEY_GRP_INTERNAL_CIRCLE); grpMetaColumns.push_back(KEY_GRP_ORIGINATOR);
|
||||
grpMetaColumns.push_back(KEY_GRP_AUTHEN_FLAGS);
|
||||
|
||||
// for retrieving actual grp data
|
||||
grpColumns.push_back(KEY_GRP_ID); grpColumns.push_back(KEY_NXS_FILE); grpColumns.push_back(KEY_NXS_FILE_OFFSET);
|
||||
@ -184,7 +189,7 @@ void RsDataService::initialise(){
|
||||
RsStackMutex stack(mDbMutex);
|
||||
|
||||
// initialise database
|
||||
mDb = new RetroDb(mDbName, RetroDb::OPEN_READWRITE_CREATE);
|
||||
|
||||
|
||||
// create table for msg data
|
||||
mDb->execSQL("CREATE TABLE " + MSG_TABLE_NAME + "(" +
|
||||
@ -204,6 +209,7 @@ void RsDataService::initialise(){
|
||||
KEY_MSG_PARENT_ID + " TEXT,"+
|
||||
KEY_MSG_NAME + " TEXT," +
|
||||
KEY_NXS_SERV_STRING + " TEXT," +
|
||||
KEY_NXS_HASH + " TEXT," +
|
||||
KEY_NXS_FILE_LEN + " INT);");
|
||||
|
||||
// create table for grp data
|
||||
@ -225,11 +231,13 @@ void RsDataService::initialise(){
|
||||
KEY_ORIG_GRP_ID + " TEXT," +
|
||||
KEY_NXS_SERV_STRING + " TEXT," +
|
||||
KEY_NXS_FLAGS + " INT," +
|
||||
KEY_GRP_AUTHEN_FLAGS + " INT," +
|
||||
KEY_GRP_SIGN_FLAGS + " INT," +
|
||||
KEY_GRP_CIRCLE_ID + " TEXT," +
|
||||
KEY_GRP_CIRCLE_TYPE + " INT," +
|
||||
KEY_GRP_INTERNAL_CIRCLE + " TEXT," +
|
||||
KEY_GRP_ORIGINATOR + " TEXT," +
|
||||
KEY_NXS_HASH + " TEXT," +
|
||||
KEY_SIGN_SET + " BLOB);");
|
||||
|
||||
}
|
||||
@ -256,6 +264,7 @@ RsGxsGrpMetaData* RsDataService::locked_getGrpMeta(RetroCursor &c)
|
||||
c.getString(COL_GRP_NAME, grpMeta->mGroupName);
|
||||
c.getString(COL_ORIG_GRP_ID, grpMeta->mOrigGrpId);
|
||||
c.getString(COL_GRP_SERV_STRING, grpMeta->mServiceString);
|
||||
c.getString(COL_HASH, grpMeta->mHash);
|
||||
grpMeta->mSignFlags = c.getInt32(COL_GRP_SIGN_FLAGS);
|
||||
|
||||
grpMeta->mPublishTs = c.getInt32(COL_TIME_STAMP);
|
||||
@ -281,6 +290,7 @@ RsGxsGrpMetaData* RsDataService::locked_getGrpMeta(RetroCursor &c)
|
||||
grpMeta->mCircleType = c.getInt32(COL_GRP_CIRCL_TYPE);
|
||||
c.getString(COL_GRP_INTERN_CIRCLE, grpMeta->mInternalCircle);
|
||||
c.getString(COL_GRP_ORIGINATOR, grpMeta->mOriginator);
|
||||
grpMeta->mAuthenFlags = c.getInt32(COL_GRP_AUTHEN_FLAGS);
|
||||
|
||||
|
||||
if(ok)
|
||||
@ -366,6 +376,7 @@ RsGxsMsgMetaData* RsDataService::locked_getMsgMeta(RetroCursor &c)
|
||||
c.getString(COL_IDENTITY, msgMeta->mAuthorId);
|
||||
c.getString(COL_MSG_NAME, msgMeta->mMsgName);
|
||||
c.getString(COL_MSG_SERV_STRING, msgMeta->mServiceString);
|
||||
c.getString(COL_HASH, msgMeta->mHash);
|
||||
|
||||
offset = 0;
|
||||
data = (char*)c.getData(COL_SIGN_SET, data_len);
|
||||
@ -477,6 +488,7 @@ int RsDataService::storeMessage(std::map<RsNxsMsg *, RsGxsMsgMetaData *> &msg)
|
||||
cv.put(KEY_MSG_ID, msgMetaPtr->mMsgId);
|
||||
cv.put(KEY_GRP_ID, msgMetaPtr->mGroupId);
|
||||
cv.put(KEY_NXS_SERV_STRING, msgMetaPtr->mServiceString);
|
||||
cv.put(KEY_NXS_HASH, msgMetaPtr->mHash);
|
||||
|
||||
|
||||
char signSetData[msgMetaPtr->signSet.TlvSize()];
|
||||
@ -582,6 +594,8 @@ int RsDataService::storeGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
|
||||
cv.put(KEY_GRP_CIRCLE_TYPE, (int32_t)grpMetaPtr->mCircleType);
|
||||
cv.put(KEY_GRP_INTERNAL_CIRCLE, grpMetaPtr->mInternalCircle);
|
||||
cv.put(KEY_GRP_ORIGINATOR, grpMetaPtr->mOriginator);
|
||||
cv.put(KEY_GRP_AUTHEN_FLAGS, (int32_t)grpMetaPtr->mAuthenFlags);
|
||||
cv.put(KEY_NXS_HASH, grpMetaPtr->mHash);
|
||||
|
||||
if(! (grpMetaPtr->mAuthorId.empty()) ){
|
||||
cv.put(KEY_NXS_IDENTITY, grpMetaPtr->mAuthorId);
|
||||
@ -1018,12 +1032,6 @@ int RsDataService::resetDataStore()
|
||||
return 1;
|
||||
}
|
||||
|
||||
int RsDataService::removeGroups(const std::vector<std::string> &grpIds)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int RsDataService::updateGroupMetaData(GrpLocMetaData &meta)
|
||||
{
|
||||
RsStackMutex stack(mDbMutex);
|
||||
@ -1055,7 +1063,7 @@ int RsDataService::removeMsgs(const GxsMsgReq& msgIds)
|
||||
// get for all msgs their offsets and lengths
|
||||
// for message not contained in msg id vector
|
||||
// store their data file segments in buffer
|
||||
// then recalculate the retained messages
|
||||
// then recalculate the retained messages'
|
||||
// new offsets, update db with new offsets
|
||||
// replace old msg file with new file
|
||||
// remove messages that were not retained from
|
||||
@ -1113,7 +1121,7 @@ int RsDataService::removeMsgs(const GxsMsgReq& msgIds)
|
||||
up.msgId = m.msgId;
|
||||
up.cv.put(KEY_NXS_FILE_OFFSET, (int32_t)newOffset);
|
||||
|
||||
newBuffer.insert(dataBuff.end(), dataBuff.begin()+m.msgOffset,
|
||||
newBuffer.insert(newBuffer.end(), dataBuff.begin()+m.msgOffset,
|
||||
dataBuff.begin()+m.msgOffset+m.msgLen);
|
||||
|
||||
newOffset += msgLen;
|
||||
@ -1148,6 +1156,26 @@ int RsDataService::removeMsgs(const GxsMsgReq& msgIds)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int RsDataService::removeGroups(const std::vector<std::string> &grpIds)
|
||||
{
|
||||
|
||||
RsStackMutex stack(mDbMutex);
|
||||
|
||||
// the grp id is the group file name
|
||||
// first remove file then remove group
|
||||
// from db
|
||||
|
||||
std::vector<std::string>::const_iterator vit = grpIds.begin();
|
||||
for(; vit != grpIds.end(); vit++)
|
||||
{
|
||||
const std::string grpFileName = mServiceDir + "/" + *vit;
|
||||
remove(grpFileName.c_str());
|
||||
}
|
||||
|
||||
locked_removeGroupEntries(grpIds);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
bool RsDataService::locked_updateMessageEntries(const MsgUpdates& updates)
|
||||
@ -1203,6 +1231,24 @@ bool RsDataService::locked_removeMessageEntries(const GxsMsgReq& msgIds)
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool RsDataService::locked_removeGroupEntries(const std::vector<std::string>& grpIds)
|
||||
{
|
||||
// start a transaction
|
||||
bool ret = mDb->execSQL("BEGIN;");
|
||||
|
||||
std::vector<std::string>::const_iterator vit = grpIds.begin();
|
||||
|
||||
for(; vit != grpIds.end(); vit++)
|
||||
{
|
||||
|
||||
const RsGxsGroupId& grpId = *vit;
|
||||
mDb->sqlDelete(GRP_TABLE_NAME, KEY_GRP_ID+ "='" + grpId + "'", "");
|
||||
}
|
||||
|
||||
ret &= mDb->execSQL("COMMIT;");
|
||||
|
||||
return ret;
|
||||
}
|
||||
void RsDataService::locked_getMessageOffsets(const RsGxsGroupId& grpId, std::vector<MsgOffset>& offsets)
|
||||
{
|
||||
|
||||
|
@ -52,7 +52,8 @@ class RsDataService : public RsGeneralDataService
|
||||
{
|
||||
public:
|
||||
|
||||
RsDataService(const std::string& serviceDir, const std::string& dbName, uint16_t serviceType, RsGxsSearchModule* mod = NULL);
|
||||
RsDataService(const std::string& serviceDir, const std::string& dbName, uint16_t serviceType,
|
||||
RsGxsSearchModule* mod = NULL, const std::string& key = "");
|
||||
virtual ~RsDataService();
|
||||
|
||||
/*!
|
||||
@ -211,6 +212,7 @@ private:
|
||||
* @param msgIds
|
||||
*/
|
||||
bool locked_removeMessageEntries(const GxsMsgReq& msgIds);
|
||||
bool locked_removeGroupEntries(const std::vector<std::string>& grpIds);
|
||||
|
||||
typedef std::map<RsGxsGroupId, std::vector<MsgUpdate> > MsgUpdates;
|
||||
|
||||
@ -228,9 +230,6 @@ private:
|
||||
|
||||
private:
|
||||
|
||||
|
||||
RetroDb* mDb;
|
||||
|
||||
RsMutex mDbMutex;
|
||||
|
||||
std::list<std::string> msgColumns;
|
||||
@ -242,6 +241,8 @@ private:
|
||||
|
||||
std::string mServiceDir, mDbName;
|
||||
uint16_t mServType;
|
||||
|
||||
RetroDb* mDb;
|
||||
};
|
||||
|
||||
#endif // RSDATASERVICE_H
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "gxssecurity.h"
|
||||
#include "util/contentvalue.h"
|
||||
#include "retroshare/rsgxsflags.h"
|
||||
#include "retroshare/rsgxscircles.h"
|
||||
#include "rsgixs.h"
|
||||
#include "rsgxsutil.h"
|
||||
|
||||
@ -55,6 +56,7 @@
|
||||
#define GEN_EXCH_DEBUG 1
|
||||
|
||||
#define MSG_CLEANUP_PERIOD 60*5 // 5 minutes
|
||||
#define INTEGRITY_CHECK_PERIOD 60*30 // 30 minutes
|
||||
|
||||
RsGenExchange::RsGenExchange(RsGeneralDataService *gds, RsNetworkExchangeService *ns,
|
||||
RsSerialType *serviceSerialiser, uint16_t servType, RsGixs* gixs,
|
||||
@ -64,7 +66,8 @@ RsGenExchange::RsGenExchange(RsGeneralDataService *gds, RsNetworkExchangeService
|
||||
CREATE_FAIL(0), CREATE_SUCCESS(1), CREATE_FAIL_TRY_LATER(2), SIGN_MAX_ATTEMPTS(5),
|
||||
SIGN_FAIL(0), SIGN_SUCCESS(1), SIGN_FAIL_TRY_LATER(2),
|
||||
VALIDATE_FAIL(0), VALIDATE_SUCCESS(1), VALIDATE_FAIL_TRY_LATER(2), VALIDATE_MAX_ATTEMPTS(5),
|
||||
mCleaning(false), mLastClean(time(NULL)), mMsgCleanUp(NULL)
|
||||
mCleaning(false), mLastClean(time(NULL)), mMsgCleanUp(NULL), mChecking(false), mIntegrityCheck(NULL),
|
||||
mLastCheck(time(NULL))
|
||||
{
|
||||
|
||||
mDataAccess = new RsGxsDataAccess(gds);
|
||||
@ -146,6 +149,28 @@ void RsGenExchange::tick()
|
||||
mCleaning = true;
|
||||
}
|
||||
}
|
||||
|
||||
now = time(NULL);
|
||||
if(mChecking || (mLastCheck + INTEGRITY_CHECK_PERIOD < now))
|
||||
{
|
||||
if(mIntegrityCheck)
|
||||
{
|
||||
if(mIntegrityCheck->isDone())
|
||||
{
|
||||
mIntegrityCheck->join();
|
||||
delete mIntegrityCheck;
|
||||
mIntegrityCheck = NULL;
|
||||
mLastCheck = time(NULL);
|
||||
mChecking = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mIntegrityCheck = new RsGxsIntegrityCheck(mDataStore);
|
||||
mIntegrityCheck->start();
|
||||
mChecking = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool RsGenExchange::acknowledgeTokenMsg(const uint32_t& token,
|
||||
@ -1585,6 +1610,7 @@ void RsGenExchange::publishMsgs()
|
||||
mMsgsToPublish.insert(std::make_pair(sign_it->first, item.mItem));
|
||||
}
|
||||
|
||||
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > msgChangeMap;
|
||||
std::map<uint32_t, RsGxsMsgItem*>::iterator mit = mMsgsToPublish.begin();
|
||||
|
||||
for(; mit != mMsgsToPublish.end(); mit++)
|
||||
@ -1700,13 +1726,16 @@ void RsGenExchange::publishMsgs()
|
||||
msg->metaData->mMsgStatus = GXS_SERV::GXS_MSG_STATUS_UNPROCESSED | GXS_SERV::GXS_MSG_STATUS_UNREAD;
|
||||
msgId = msg->msgId;
|
||||
grpId = msg->grpId;
|
||||
computeHash(msg->msg, msg->metaData->mHash);
|
||||
mDataAccess->addMsgData(msg);
|
||||
msgChangeMap[grpId].push_back(msgId);
|
||||
|
||||
delete[] metaDataBuff;
|
||||
|
||||
// add to published to allow acknowledgement
|
||||
mMsgNotify.insert(std::make_pair(mit->first, std::make_pair(grpId, msgId)));
|
||||
mDataAccess->updatePublicRequestStatus(mit->first, RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1738,6 +1767,14 @@ void RsGenExchange::publishMsgs()
|
||||
// clear msg item map as we're done publishing them and all
|
||||
// entries are invalid
|
||||
mMsgsToPublish.clear();
|
||||
|
||||
if(!msgChangeMap.empty())
|
||||
{
|
||||
RsGxsMsgChange* ch = new RsGxsMsgChange(RsGxsNotify::TYPE_PUBLISH);
|
||||
ch->msgChangeMap = msgChangeMap;
|
||||
mNotifications.push_back(ch);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
RsGenExchange::ServiceCreate_Return RsGenExchange::service_CreateGroup(RsGxsGrpItem* /* grpItem */,
|
||||
@ -1873,6 +1910,7 @@ void RsGenExchange::publishGrps()
|
||||
if(mDataStore->validSize(grp) && serialOk)
|
||||
{
|
||||
grpId = grp->grpId;
|
||||
computeHash(grp->grp, grp->metaData->mHash);
|
||||
mDataAccess->addGroupData(grp);
|
||||
}
|
||||
else
|
||||
@ -1932,6 +1970,7 @@ void RsGenExchange::publishGrps()
|
||||
|
||||
std::map<uint32_t, GrpNote>::iterator mit = toNotify.begin();
|
||||
|
||||
std::list<RsGxsGroupId> grpChanged;
|
||||
for(; mit != toNotify.end(); mit++)
|
||||
{
|
||||
GrpNote& note = mit->second;
|
||||
@ -1940,6 +1979,16 @@ void RsGenExchange::publishGrps()
|
||||
|
||||
mGrpNotify.insert(std::make_pair(mit->first, note.second));
|
||||
mDataAccess->updatePublicRequestStatus(mit->first, status);
|
||||
|
||||
if(note.first)
|
||||
grpChanged.push_back(note.second);
|
||||
}
|
||||
|
||||
if(!grpChanged.empty())
|
||||
{
|
||||
RsGxsGroupChange* gc = new RsGxsGroupChange(RsGxsNotify::TYPE_PUBLISH);
|
||||
gc->mGrpIdList = grpChanged;
|
||||
mNotifications.push_back(gc);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1997,6 +2046,12 @@ void RsGenExchange::processRecvdData()
|
||||
}
|
||||
|
||||
|
||||
void RsGenExchange::computeHash(const RsTlvBinaryData& data, std::string& hash)
|
||||
{
|
||||
pqihash pHash;
|
||||
pHash.addData(data.bin_data, data.bin_len);
|
||||
pHash.Complete(hash);
|
||||
}
|
||||
|
||||
void RsGenExchange::processRecvdMessages()
|
||||
{
|
||||
@ -2070,6 +2125,8 @@ void RsGenExchange::processRecvdMessages()
|
||||
getMsgIdPair(*msg));
|
||||
|
||||
if(validated_entry != mMsgPendingValidate.end()) mMsgPendingValidate.erase(validated_entry);
|
||||
|
||||
computeHash(msg->msg, meta->mHash);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -2128,7 +2185,7 @@ void RsGenExchange::processRecvdMessages()
|
||||
if(!msgIds.empty())
|
||||
{
|
||||
mDataStore->storeMessage(msgs);
|
||||
RsGxsMsgChange* c = new RsGxsMsgChange();
|
||||
RsGxsMsgChange* c = new RsGxsMsgChange(RsGxsNotify::TYPE_RECEIVE);
|
||||
c->msgChangeMap = msgIds;
|
||||
mNotifications.push_back(c);
|
||||
}
|
||||
@ -2167,6 +2224,11 @@ void RsGenExchange::processRecvdGroups()
|
||||
{
|
||||
meta->mGroupStatus = GXS_SERV::GXS_GRP_STATUS_UNPROCESSED | GXS_SERV::GXS_GRP_STATUS_UNREAD;
|
||||
meta->mSubscribeFlags = GXS_SERV::GROUP_SUBSCRIBE_NOT_SUBSCRIBED;
|
||||
|
||||
if(meta->mCircleType == GXS_CIRCLE_TYPE_YOUREYESONLY)
|
||||
meta->mOriginator = grp->PeerId();
|
||||
|
||||
computeHash(grp->grp, meta->mHash);
|
||||
grps.insert(std::make_pair(grp, meta));
|
||||
grpIds.push_back(grp->grpId);
|
||||
|
||||
@ -2215,7 +2277,7 @@ void RsGenExchange::processRecvdGroups()
|
||||
|
||||
if(!grpIds.empty())
|
||||
{
|
||||
RsGxsGroupChange* c = new RsGxsGroupChange();
|
||||
RsGxsGroupChange* c = new RsGxsGroupChange(RsGxsNotify::TYPE_RECEIVE);
|
||||
c->mGrpIdList = grpIds;
|
||||
mNotifications.push_back(c);
|
||||
mDataStore->storeGroup(grps);
|
||||
|
@ -307,7 +307,37 @@ protected:
|
||||
*/
|
||||
bool getGroupData(const uint32_t &token, std::vector<RsGxsGrpItem*>& grpItem);
|
||||
|
||||
template<class GrpType>
|
||||
bool getGroupDataT(const uint32_t &token, std::vector<GrpType*>& grpItem)
|
||||
{
|
||||
std::vector<RsGxsGrpItem*> items;
|
||||
bool ok = getGroupData(token, items);
|
||||
std::vector<RsGxsGrpItem*>::iterator vit = items.begin();
|
||||
|
||||
for(; vit != items.end(); vit++)
|
||||
{
|
||||
RsGxsGrpItem* gi = *vit;
|
||||
|
||||
GrpType* item = dynamic_cast<GrpType*>(gi);
|
||||
|
||||
if(item)
|
||||
{
|
||||
grpItem.push_back(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GXS_DEBUG
|
||||
std::cerr << "\nRsGenExchange::getGroupDataT(): Wrong type!\n";
|
||||
#endif
|
||||
delete gi;
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/*!
|
||||
* retrieves message data associated to a request token
|
||||
* @param token token to be redeemed for message item retrieval
|
||||
@ -315,6 +345,40 @@ public:
|
||||
*/
|
||||
bool getMsgData(const uint32_t &token, GxsMsgDataMap& msgItems);
|
||||
|
||||
template <class MsgType>
|
||||
bool getMsgDataT(const uint32_t &token, std::map<RsGxsGroupId,
|
||||
std::vector<MsgType*> >& msgItems)
|
||||
{
|
||||
GxsMsgDataMap msgData;
|
||||
bool ok = getMsgData(token, msgData);
|
||||
|
||||
GxsMsgDataMap::iterator mit = msgData.begin();
|
||||
|
||||
for(; mit != msgData.end(); mit++)
|
||||
{
|
||||
const RsGxsGroupId& grpId = mit->first;
|
||||
std::vector<RsGxsMsgItem*>& mv = mit->second;
|
||||
std::vector<RsGxsMsgItem*>::iterator vit = mv.begin();
|
||||
for(; vit != mv.end(); vit++)
|
||||
{
|
||||
RsGxsMsgItem* mi = *vit;
|
||||
MsgType* mt = dynamic_cast<MsgType*>(mi);
|
||||
|
||||
if(mt != NULL)
|
||||
{
|
||||
msgItems[grpId].push_back(mt);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "RsGenExchange::getMsgDataT(): bad cast to msg type" << std::endl;
|
||||
delete mi;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
/*!
|
||||
* retrieves message related data associated to a request token
|
||||
* @param token token to be redeemed for message item retrieval
|
||||
@ -670,6 +734,8 @@ private:
|
||||
|
||||
void groupShareKeys(std::list<std::string> peers);
|
||||
|
||||
static void computeHash(const RsTlvBinaryData& data, std::string& hash);
|
||||
|
||||
private:
|
||||
|
||||
RsMutex mGenMtx;
|
||||
@ -718,6 +784,11 @@ private:
|
||||
time_t mLastClean;
|
||||
RsGxsMessageCleanUp* mMsgCleanUp;
|
||||
|
||||
|
||||
bool mChecking, mCheckStarted;
|
||||
time_t mLastCheck;
|
||||
RsGxsIntegrityCheck* mIntegrityCheck;
|
||||
|
||||
private:
|
||||
|
||||
std::vector<RsGxsNotify*> mChanges;
|
||||
|
@ -165,6 +165,7 @@ public:
|
||||
class GixsReputation
|
||||
{
|
||||
public:
|
||||
GixsReputation() : score(0) {}
|
||||
RsGxsId id;
|
||||
int score;
|
||||
};
|
||||
@ -174,7 +175,9 @@ class RsGixsReputation
|
||||
{
|
||||
public:
|
||||
// get Reputation.
|
||||
virtual bool getReputation(const RsGxsId &id, const GixsReputation &rep) = 0;
|
||||
virtual bool haveReputation(const RsGxsId &id) = 0;
|
||||
virtual bool loadReputation(const RsGxsId &id) = 0;
|
||||
virtual bool getReputation(const RsGxsId &id, GixsReputation &rep) = 0;
|
||||
};
|
||||
|
||||
|
||||
@ -206,6 +209,7 @@ class RsGcxs
|
||||
virtual bool loadCircle(const RsGxsCircleId &circleId) = 0;
|
||||
|
||||
virtual int canSend(const RsGxsCircleId &circleId, const RsPgpId &id) = 0;
|
||||
virtual int canReceive(const RsGxsCircleId &circleId, const RsPgpId &id) = 0;
|
||||
virtual bool recipients(const RsGxsCircleId &circleId, std::list<RsPgpId> &friendlist) = 0;
|
||||
};
|
||||
|
||||
|
@ -48,6 +48,7 @@ uint32_t RsGxsGrpMetaData::serial_size()
|
||||
s += keys.TlvSize();
|
||||
s += 4; // for mCircleType
|
||||
s += GetTlvStringSize(mCircleId);
|
||||
s += 4; // mAuthenFlag
|
||||
|
||||
return s;
|
||||
}
|
||||
@ -72,6 +73,7 @@ void RsGxsGrpMetaData::clear(){
|
||||
mInternalCircle.clear();
|
||||
mOriginator.clear();
|
||||
mCircleType = 0;
|
||||
mAuthenFlags = 0;
|
||||
|
||||
}
|
||||
|
||||
@ -105,9 +107,11 @@ bool RsGxsGrpMetaData::serialise(void *data, uint32_t &pktsize)
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mGroupFlags);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mPublishTs);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mCircleType);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mAuthenFlags);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 0, mAuthorId);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 0, mServiceString);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 0, mCircleId);
|
||||
|
||||
ok &= signSet.SetTlv(data, tlvsize, &offset);
|
||||
ok &= keys.SetTlv(data, tlvsize, &offset);
|
||||
|
||||
@ -133,6 +137,7 @@ bool RsGxsGrpMetaData::deserialise(void *data, uint32_t &pktsize)
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &mGroupFlags);
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &mPublishTs);
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &mCircleType);
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &mAuthenFlags);
|
||||
ok &= GetTlvString(data, pktsize, &offset, 0, mAuthorId);
|
||||
ok &= GetTlvString(data, pktsize, &offset, 0, mServiceString);
|
||||
ok &= GetTlvString(data, pktsize, &offset, 0, mCircleId);
|
||||
@ -278,6 +283,7 @@ void RsGxsGrpMetaData::operator =(const RsGroupMetaData& rMeta)
|
||||
this->mCircleType = rMeta.mCircleType;
|
||||
this->mInternalCircle = rMeta.mInternalCircle;
|
||||
this->mOriginator = rMeta.mOriginator;
|
||||
this->mAuthenFlags = rMeta.mAuthenFlags;
|
||||
}
|
||||
|
||||
void RsGxsMsgMetaData::operator =(const RsMsgMetaData& rMeta)
|
||||
|
@ -65,6 +65,7 @@ public:
|
||||
RsTlvSecurityKeySet keys;
|
||||
|
||||
std::string mServiceString;
|
||||
uint32_t mAuthenFlags;
|
||||
|
||||
// BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG.
|
||||
|
||||
@ -77,6 +78,7 @@ public:
|
||||
uint32_t mGroupStatus;
|
||||
std::string mOriginator;
|
||||
std::string mInternalCircle;
|
||||
std::string mHash;
|
||||
};
|
||||
|
||||
|
||||
@ -115,6 +117,7 @@ public:
|
||||
|
||||
uint32_t mMsgStatus;
|
||||
time_t mChildTs;
|
||||
std::string mHash;
|
||||
bool validated;
|
||||
|
||||
};
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-2012 by Robert Fernie, Christopher Evi-Parker
|
||||
* Copyright 2012-2013 by Robert Fernie, Christopher Evi-Parker
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
|
@ -29,9 +29,11 @@
|
||||
|
||||
#include "rsgxsnetservice.h"
|
||||
#include "retroshare/rsgxsflags.h"
|
||||
#include "retroshare/rsgxscircles.h"
|
||||
#include "retroshare/rspeers.h"
|
||||
|
||||
#define NXS_NET_DEBUG 1
|
||||
|
||||
#define GIXS_CUT_OFF 0
|
||||
|
||||
#define SYNC_PERIOD 12 // in microseconds every 10 seconds (1 second for testing)
|
||||
#define TRANSAC_TIMEOUT 5 // 5 seconds
|
||||
@ -39,10 +41,11 @@
|
||||
const uint32_t RsGxsNetService::FRAGMENT_SIZE = 150000;
|
||||
|
||||
RsGxsNetService::RsGxsNetService(uint16_t servType, RsGeneralDataService *gds,
|
||||
RsNxsNetMgr *netMgr, RsNxsObserver *nxsObs)
|
||||
RsNxsNetMgr *netMgr, RsNxsObserver *nxsObs, RsGixsReputation* reputations, RsGcxs* circles)
|
||||
: p3Config(servType), p3ThreadedService(servType),
|
||||
mTransactionTimeOut(TRANSAC_TIMEOUT), mServType(servType), mDataStore(gds), mTransactionN(0),
|
||||
mObserver(nxsObs), mNxsMutex("RsGxsNetService"), mNetMgr(netMgr), mSYNC_PERIOD(SYNC_PERIOD), mSyncTs(0)
|
||||
mObserver(nxsObs), mNxsMutex("RsGxsNetService"), mNetMgr(netMgr), mSYNC_PERIOD(SYNC_PERIOD),
|
||||
mSyncTs(0), mReputations(reputations), mCircles(circles)
|
||||
|
||||
{
|
||||
addSerialType(new RsNxsSerialiser(mServType));
|
||||
@ -279,6 +282,150 @@ struct GrpFragCollate
|
||||
bool operator()(RsNxsGrp* grp) { return grp->grpId == mGrpId;}
|
||||
};
|
||||
|
||||
void RsGxsNetService::locked_createTransactionFromPending(
|
||||
MsgRespPending* msgPend)
|
||||
{
|
||||
MsgAuthorV::const_iterator cit = msgPend->mMsgAuthV.begin();
|
||||
std::list<RsNxsItem*> reqList;
|
||||
uint32_t transN = locked_getTransactionId();
|
||||
for(; cit != msgPend->mMsgAuthV.end(); cit++)
|
||||
{
|
||||
const MsgAuthEntry& entry = *cit;
|
||||
|
||||
if(entry.mPassedVetting)
|
||||
{
|
||||
RsNxsSyncMsgItem* msgItem = new RsNxsSyncMsgItem(mServType);
|
||||
msgItem->grpId = entry.mGrpId;
|
||||
msgItem->msgId = entry.mMsgId;
|
||||
msgItem->authorId = entry.mAuthorId;
|
||||
msgItem->flag = RsNxsSyncMsgItem::FLAG_REQUEST;
|
||||
msgItem->transactionNumber = transN;
|
||||
msgItem->PeerId(msgPend->mPeerId);
|
||||
reqList.push_back(msgItem);
|
||||
}
|
||||
}
|
||||
|
||||
if(!reqList.empty())
|
||||
locked_pushMsgTransactionFromList(reqList, msgPend->mPeerId, transN);
|
||||
}
|
||||
|
||||
void RsGxsNetService::locked_createTransactionFromPending(
|
||||
GrpRespPending* grpPend)
|
||||
{
|
||||
GrpAuthorV::const_iterator cit = grpPend->mGrpAuthV.begin();
|
||||
std::list<RsNxsItem*> reqList;
|
||||
uint32_t transN = locked_getTransactionId();
|
||||
for(; cit != grpPend->mGrpAuthV.end(); cit++)
|
||||
{
|
||||
const GrpAuthEntry& entry = *cit;
|
||||
|
||||
if(entry.mPassedVetting)
|
||||
{
|
||||
RsNxsSyncGrpItem* msgItem = new RsNxsSyncGrpItem(mServType);
|
||||
msgItem->grpId = entry.mGrpId;
|
||||
msgItem->authorId = entry.mAuthorId;
|
||||
msgItem->flag = RsNxsSyncMsgItem::FLAG_REQUEST;
|
||||
msgItem->transactionNumber = transN;
|
||||
msgItem->PeerId(grpPend->mPeerId);
|
||||
reqList.push_back(msgItem);
|
||||
}
|
||||
}
|
||||
|
||||
if(!reqList.empty())
|
||||
locked_pushGrpTransactionFromList(reqList, grpPend->mPeerId, transN);
|
||||
}
|
||||
|
||||
|
||||
void RsGxsNetService::locked_createTransactionFromPending(GrpCircleIdRequestVetting* grpPend)
|
||||
{
|
||||
std::vector<GrpIdCircleVet>::iterator cit = grpPend->mGrpCircleV.begin();
|
||||
uint32_t transN = locked_getTransactionId();
|
||||
std::list<RsNxsItem*> itemL;
|
||||
for(; cit != grpPend->mGrpCircleV.end(); cit++)
|
||||
{
|
||||
const GrpIdCircleVet& entry = *cit;
|
||||
|
||||
if(entry.mCleared)
|
||||
{
|
||||
RsNxsSyncGrpItem* gItem = new
|
||||
RsNxsSyncGrpItem(mServType);
|
||||
gItem->flag = RsNxsSyncGrpItem::FLAG_RESPONSE;
|
||||
gItem->grpId = entry.mGroupId;
|
||||
gItem->publishTs = 0;
|
||||
gItem->PeerId(grpPend->mPeerId);
|
||||
gItem->transactionNumber = transN;
|
||||
itemL.push_back(gItem);
|
||||
}
|
||||
}
|
||||
|
||||
if(!itemL.empty())
|
||||
locked_pushGrpRespFromList(itemL, grpPend->mPeerId, transN);
|
||||
}
|
||||
|
||||
void RsGxsNetService::locked_createTransactionFromPending(MsgCircleIdsRequestVetting* msgPend)
|
||||
{
|
||||
std::vector<MsgIdCircleVet>::iterator vit = msgPend->mMsgs.begin();
|
||||
std::list<RsNxsItem*> itemL;
|
||||
|
||||
uint32_t transN = locked_getTransactionId();
|
||||
|
||||
for(; vit != msgPend->mMsgs.end(); vit++)
|
||||
{
|
||||
MsgIdCircleVet& mic = *vit;
|
||||
RsNxsSyncMsgItem* mItem = new
|
||||
RsNxsSyncMsgItem(mServType);
|
||||
mItem->flag = RsNxsSyncGrpItem::FLAG_RESPONSE;
|
||||
mItem->grpId = msgPend->mGrpId;
|
||||
mItem->msgId = mic.mMsgId;
|
||||
mItem->authorId = mic.mAuthorId;
|
||||
mItem->PeerId(msgPend->mPeerId);
|
||||
mItem->transactionNumber = transN;
|
||||
itemL.push_back(mItem);
|
||||
}
|
||||
|
||||
if(!itemL.empty())
|
||||
locked_pushMsgRespFromList(itemL, msgPend->mPeerId, transN);
|
||||
}
|
||||
|
||||
bool RsGxsNetService::locked_canReceive(const RsGxsGrpMetaData * const grpMeta,
|
||||
const std::string& peerId)
|
||||
{
|
||||
|
||||
double timeDelta = 0.2;
|
||||
|
||||
if(grpMeta->mCircleType == GXS_CIRCLE_TYPE_EXTERNAL)
|
||||
{
|
||||
int i=0;
|
||||
mCircles->loadCircle(grpMeta->mCircleId);
|
||||
|
||||
// check 5 times at most
|
||||
// spin for 1 second at most
|
||||
while(i < 5)
|
||||
{
|
||||
#ifndef WINDOWS_SYS
|
||||
usleep((int) (timeDelta * 1000000));
|
||||
#else
|
||||
Sleep((int) (timeDelta * 1000));
|
||||
#endif
|
||||
|
||||
if(mCircles->isLoaded(grpMeta->mCircleId))
|
||||
{
|
||||
const RsPgpId& pgpId = rsPeers->getGPGId(peerId);
|
||||
return mCircles->canSend(grpMeta->mCircleId, pgpId);
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
}else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void RsGxsNetService::collateGrpFragments(GrpFragments fragments,
|
||||
std::map<RsGxsGroupId, GrpFragments>& partFragments) const
|
||||
{
|
||||
@ -611,6 +758,9 @@ void RsGxsNetService::run(){
|
||||
// process completed transactions
|
||||
processCompletedTransactions();
|
||||
|
||||
// vetting of id and circle info
|
||||
runVetting();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -881,14 +1031,12 @@ void RsGxsNetService::locked_processCompletedIncomingTrans(NxsTransaction* tr)
|
||||
<< std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// notify listener of grps
|
||||
mObserver->notifyNewGroups(grps);
|
||||
|
||||
|
||||
|
||||
}else if(flag & RsNxsTransac::FLAG_TYPE_MSGS)
|
||||
{
|
||||
|
||||
@ -1002,6 +1150,31 @@ void RsGxsNetService::locked_processCompletedOutgoingTrans(NxsTransaction* tr)
|
||||
}
|
||||
|
||||
|
||||
void RsGxsNetService::locked_pushMsgTransactionFromList(
|
||||
std::list<RsNxsItem*>& reqList, const std::string& peerId, const uint32_t& transN)
|
||||
{
|
||||
RsNxsTransac* transac = new RsNxsTransac(mServType);
|
||||
transac->transactFlag = RsNxsTransac::FLAG_TYPE_MSG_LIST_REQ
|
||||
| RsNxsTransac::FLAG_BEGIN_P1;
|
||||
transac->timestamp = 0;
|
||||
transac->nItems = reqList.size();
|
||||
transac->PeerId(peerId);
|
||||
transac->transactionNumber = transN;
|
||||
NxsTransaction* newTrans = new NxsTransaction();
|
||||
newTrans->mItems = reqList;
|
||||
newTrans->mFlag = NxsTransaction::FLAG_STATE_WAITING_CONFIRM;
|
||||
newTrans->mTimeOut = time(NULL) + mTransactionTimeOut;
|
||||
// create transaction copy with your id to indicate
|
||||
// its an outgoing transaction
|
||||
newTrans->mTransaction = new RsNxsTransac(*transac);
|
||||
newTrans->mTransaction->PeerId(mOwnId);
|
||||
sendItem(transac);
|
||||
{
|
||||
if (!locked_addTransaction(newTrans))
|
||||
delete newTrans;
|
||||
}
|
||||
}
|
||||
|
||||
void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
|
||||
{
|
||||
|
||||
@ -1031,12 +1204,38 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
|
||||
}
|
||||
}
|
||||
|
||||
if(msgItemL.empty())
|
||||
return;
|
||||
if(msgItemL.empty())
|
||||
return;
|
||||
|
||||
|
||||
|
||||
// get grp id for this transaction
|
||||
RsNxsSyncMsgItem* item = msgItemL.front();
|
||||
const std::string& grpId = item->grpId;
|
||||
|
||||
std::map<std::string, RsGxsGrpMetaData*> grpMetaMap;
|
||||
grpMetaMap[grpId] = NULL;
|
||||
mDataStore->retrieveGxsGrpMetaData(grpMetaMap);
|
||||
RsGxsGrpMetaData* grpMeta = grpMetaMap[grpId];
|
||||
|
||||
// you want to find out if you can receive it
|
||||
// number polls essentially represent multiple
|
||||
// of sleep interval
|
||||
if(grpMeta)
|
||||
{
|
||||
bool can = locked_canReceive(grpMeta, tr->mTransaction->PeerId());
|
||||
|
||||
delete grpMeta;
|
||||
|
||||
if(!can)
|
||||
return;
|
||||
|
||||
}else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
GxsMsgReq reqIds;
|
||||
reqIds[grpId] = std::vector<RsGxsMessageId>();
|
||||
GxsMsgMetaResult result;
|
||||
@ -1060,49 +1259,87 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
|
||||
|
||||
const std::string peerFrom = tr->mTransaction->PeerId();
|
||||
|
||||
MsgAuthorV toVet;
|
||||
|
||||
for(; llit != msgItemL.end(); llit++)
|
||||
{
|
||||
const std::string& msgId = (*llit)->msgId;
|
||||
RsNxsSyncMsgItem*& syncItem = *llit;
|
||||
const std::string& msgId = syncItem->msgId;
|
||||
|
||||
if(msgIdSet.find(msgId) == msgIdSet.end()){
|
||||
RsNxsSyncMsgItem* msgItem = new RsNxsSyncMsgItem(mServType);
|
||||
msgItem->grpId = grpId;
|
||||
msgItem->msgId = msgId;
|
||||
msgItem->flag = RsNxsSyncMsgItem::FLAG_REQUEST;
|
||||
msgItem->transactionNumber = transN;
|
||||
msgItem->PeerId(peerFrom);
|
||||
reqList.push_back(msgItem);
|
||||
|
||||
|
||||
if(mReputations->haveReputation(syncItem->authorId) || syncItem->authorId.empty())
|
||||
{
|
||||
GixsReputation rep;
|
||||
mReputations->getReputation(syncItem->authorId, rep);
|
||||
|
||||
if(rep.score > GIXS_CUT_OFF)
|
||||
{
|
||||
RsNxsSyncMsgItem* msgItem = new RsNxsSyncMsgItem(mServType);
|
||||
msgItem->grpId = grpId;
|
||||
msgItem->msgId = msgId;
|
||||
msgItem->flag = RsNxsSyncMsgItem::FLAG_REQUEST;
|
||||
msgItem->transactionNumber = transN;
|
||||
msgItem->PeerId(peerFrom);
|
||||
reqList.push_back(msgItem);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// preload for speed
|
||||
mReputations->loadReputation(syncItem->authorId);
|
||||
MsgAuthEntry entry;
|
||||
entry.mAuthorId = syncItem->authorId;
|
||||
entry.mGrpId = syncItem->grpId;
|
||||
entry.mMsgId = syncItem->msgId;
|
||||
toVet.push_back(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!reqList.empty())
|
||||
{
|
||||
if(!toVet.empty())
|
||||
{
|
||||
MsgRespPending* mrp = new MsgRespPending(mReputations, tr->mTransaction->PeerId(), toVet);
|
||||
mPendingResp.push_back(mrp);
|
||||
}
|
||||
|
||||
RsNxsTransac* transac = new RsNxsTransac(mServType);
|
||||
transac->transactFlag = RsNxsTransac::FLAG_TYPE_MSG_LIST_REQ
|
||||
| RsNxsTransac::FLAG_BEGIN_P1;
|
||||
transac->timestamp = 0;
|
||||
transac->nItems = reqList.size();
|
||||
transac->PeerId(tr->mTransaction->PeerId());
|
||||
transac->transactionNumber = transN;
|
||||
if(!reqList.empty())
|
||||
{
|
||||
locked_pushMsgTransactionFromList(reqList, tr->mTransaction->PeerId(), transN);
|
||||
}
|
||||
}
|
||||
|
||||
NxsTransaction* newTrans = new NxsTransaction();
|
||||
newTrans->mItems = reqList;
|
||||
newTrans->mFlag = NxsTransaction::FLAG_STATE_WAITING_CONFIRM;
|
||||
newTrans->mTimeOut = time(NULL) + mTransactionTimeOut;
|
||||
|
||||
// create transaction copy with your id to indicate
|
||||
// its an outgoing transaction
|
||||
newTrans->mTransaction = new RsNxsTransac(*transac);
|
||||
newTrans->mTransaction->PeerId(mOwnId);
|
||||
|
||||
sendItem(transac);
|
||||
|
||||
{
|
||||
if(!locked_addTransaction(newTrans))
|
||||
delete newTrans;
|
||||
}
|
||||
}
|
||||
void RsGxsNetService::locked_pushGrpTransactionFromList(
|
||||
std::list<RsNxsItem*>& reqList, const std::string& peerId, const uint32_t& transN)
|
||||
{
|
||||
RsNxsTransac* transac = new RsNxsTransac(mServType);
|
||||
transac->transactFlag = RsNxsTransac::FLAG_TYPE_GRP_LIST_REQ
|
||||
| RsNxsTransac::FLAG_BEGIN_P1;
|
||||
transac->timestamp = 0;
|
||||
transac->nItems = reqList.size();
|
||||
transac->PeerId(peerId);
|
||||
transac->transactionNumber = transN;
|
||||
NxsTransaction* newTrans = new NxsTransaction();
|
||||
newTrans->mItems = reqList;
|
||||
newTrans->mFlag = NxsTransaction::FLAG_STATE_WAITING_CONFIRM;
|
||||
newTrans->mTimeOut = time(NULL) + mTransactionTimeOut;
|
||||
newTrans->mTransaction = new RsNxsTransac(*transac);
|
||||
newTrans->mTransaction->PeerId(mOwnId);
|
||||
sendItem(transac);
|
||||
if (!locked_addTransaction(newTrans))
|
||||
delete newTrans;
|
||||
}
|
||||
void RsGxsNetService::addGroupItemToList(NxsTransaction*& tr,
|
||||
const std::string& grpId, uint32_t& transN,
|
||||
std::list<RsNxsItem*>& reqList)
|
||||
{
|
||||
RsNxsSyncGrpItem* grpItem = new RsNxsSyncGrpItem(mServType);
|
||||
grpItem->PeerId(tr->mTransaction->PeerId());
|
||||
grpItem->grpId = grpId;
|
||||
grpItem->flag = RsNxsSyncMsgItem::FLAG_REQUEST;
|
||||
grpItem->transactionNumber = transN;
|
||||
reqList.push_back(grpItem);
|
||||
}
|
||||
|
||||
void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
|
||||
@ -1125,7 +1362,7 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
|
||||
}else
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG
|
||||
std::cerr << "RsGxsNetService::genReqMsgTransaction(): item failed to caste to RsNxsSyncMsgItem* "
|
||||
std::cerr << "RsGxsNetService::genReqGrpTransaction(): item failed to caste to RsNxsSyncMsgItem* "
|
||||
<< std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
@ -1142,43 +1379,60 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
|
||||
|
||||
uint32_t transN = locked_getTransactionId();
|
||||
|
||||
GrpAuthorV toVet;
|
||||
|
||||
for(; llit != grpItemL.end(); llit++)
|
||||
{
|
||||
const std::string& grpId = (*llit)->grpId;
|
||||
RsNxsSyncGrpItem*& grpSyncItem = *llit;
|
||||
const std::string& grpId = grpSyncItem->grpId;
|
||||
|
||||
if(grpMetaMap.find(grpId) == grpMetaMap.end()){
|
||||
RsNxsSyncGrpItem* grpItem = new RsNxsSyncGrpItem(mServType);
|
||||
grpItem->PeerId(tr->mTransaction->PeerId());
|
||||
grpItem->grpId = grpId;
|
||||
grpItem->flag = RsNxsSyncMsgItem::FLAG_REQUEST;
|
||||
grpItem->transactionNumber = transN;
|
||||
reqList.push_back(grpItem);
|
||||
|
||||
// determine if you need to check reputation
|
||||
bool checkRep = !grpSyncItem->authorId.empty();
|
||||
|
||||
// check if you have reputation, if you don't then
|
||||
// place in holding pen
|
||||
if(checkRep)
|
||||
{
|
||||
if(mReputations->haveReputation(grpSyncItem->authorId))
|
||||
{
|
||||
GixsReputation rep;
|
||||
mReputations->getReputation(grpSyncItem->authorId, rep);
|
||||
|
||||
if(rep.score > GIXS_CUT_OFF)
|
||||
{
|
||||
addGroupItemToList(tr, grpId, transN, reqList);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// preload reputation for later
|
||||
mReputations->loadReputation(grpSyncItem->authorId);
|
||||
GrpAuthEntry entry;
|
||||
entry.mAuthorId = grpSyncItem->authorId;
|
||||
entry.mGrpId = grpSyncItem->grpId;
|
||||
toVet.push_back(entry);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
addGroupItemToList(tr, grpId, transN, reqList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!toVet.empty())
|
||||
{
|
||||
std::string peerId = tr->mTransaction->PeerId();
|
||||
GrpRespPending* grp = new GrpRespPending(mReputations, peerId, toVet);
|
||||
mPendingResp.push_back(grp);
|
||||
}
|
||||
|
||||
|
||||
if(!reqList.empty())
|
||||
{
|
||||
|
||||
RsNxsTransac* transac = new RsNxsTransac(mServType);
|
||||
transac->transactFlag = RsNxsTransac::FLAG_TYPE_GRP_LIST_REQ
|
||||
| RsNxsTransac::FLAG_BEGIN_P1;
|
||||
transac->timestamp = 0;
|
||||
transac->nItems = reqList.size();
|
||||
transac->PeerId(tr->mTransaction->PeerId());
|
||||
transac->transactionNumber = transN;
|
||||
|
||||
NxsTransaction* newTrans = new NxsTransaction();
|
||||
newTrans->mItems = reqList;
|
||||
newTrans->mFlag = NxsTransaction::FLAG_STATE_WAITING_CONFIRM;
|
||||
newTrans->mTimeOut = time(NULL) + mTransactionTimeOut;
|
||||
newTrans->mTransaction = new RsNxsTransac(*transac);
|
||||
newTrans->mTransaction->PeerId(mOwnId);
|
||||
|
||||
sendItem(transac);
|
||||
|
||||
if(!locked_addTransaction(newTrans))
|
||||
delete newTrans;
|
||||
locked_pushGrpTransactionFromList(reqList, tr->mTransaction->PeerId(), transN);
|
||||
|
||||
}
|
||||
|
||||
@ -1258,6 +1512,86 @@ void RsGxsNetService::locked_genSendGrpsTransaction(NxsTransaction* tr)
|
||||
return;
|
||||
}
|
||||
|
||||
void RsGxsNetService::runVetting()
|
||||
{
|
||||
RsStackMutex stack(mNxsMutex);
|
||||
|
||||
std::vector<AuthorPending*>::iterator vit = mPendingResp.begin();
|
||||
|
||||
for(; vit != mPendingResp.end(); )
|
||||
{
|
||||
AuthorPending* ap = *vit;
|
||||
|
||||
if(ap->accepted() || ap->expired())
|
||||
{
|
||||
// add to transactions
|
||||
if(AuthorPending::MSG_PEND == ap->getType())
|
||||
{
|
||||
MsgRespPending* mrp = static_cast<MsgRespPending*>(ap);
|
||||
locked_createTransactionFromPending(mrp);
|
||||
}
|
||||
else if(AuthorPending::GRP_PEND == ap->getType())
|
||||
{
|
||||
GrpRespPending* grp = static_cast<GrpRespPending*>(ap);
|
||||
locked_createTransactionFromPending(grp);
|
||||
}else
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG
|
||||
std::cerr << "RsGxsNetService::runVetting(): Unknown pending type! Type: " << ap->getType()
|
||||
<< std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
delete ap;
|
||||
vit = mPendingResp.erase(vit);
|
||||
}
|
||||
else
|
||||
{
|
||||
vit++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// now lets do circle vetting
|
||||
std::vector<GrpCircleVetting*>::iterator vit2 = mPendingCircleVets.begin();
|
||||
for(; vit2 != mPendingCircleVets.end(); )
|
||||
{
|
||||
GrpCircleVetting*& gcv = *vit2;
|
||||
if(gcv->cleared() || gcv->expired())
|
||||
{
|
||||
if(gcv->getType() == GrpCircleVetting::GRP_ID_PEND)
|
||||
{
|
||||
GrpCircleIdRequestVetting* gcirv =
|
||||
static_cast<GrpCircleIdRequestVetting*>(gcv);
|
||||
|
||||
locked_createTransactionFromPending(gcirv);
|
||||
}
|
||||
else if(gcv->getType() == GrpCircleVetting::MSG_ID_SEND_PEND)
|
||||
{
|
||||
MsgCircleIdsRequestVetting* mcirv =
|
||||
static_cast<MsgCircleIdsRequestVetting*>(gcv);
|
||||
|
||||
locked_createTransactionFromPending(mcirv);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG
|
||||
std::cerr << "RsGxsNetService::runVetting(): Unknown Circle pending type! Type: " << gcv->getType()
|
||||
<< std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
delete gcv;
|
||||
vit2 = mPendingCircleVets.erase(vit2);
|
||||
}
|
||||
else
|
||||
{
|
||||
vit2++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RsGxsNetService::locked_genSendMsgsTransaction(NxsTransaction* tr)
|
||||
{
|
||||
|
||||
@ -1386,6 +1720,29 @@ void RsGxsNetService::cleanTransactionItems(NxsTransaction* tr) const
|
||||
tr->mItems.clear();
|
||||
}
|
||||
|
||||
void RsGxsNetService::locked_pushGrpRespFromList(std::list<RsNxsItem*>& respList,
|
||||
const std::string& peer, const uint32_t& transN)
|
||||
{
|
||||
NxsTransaction* tr = new NxsTransaction();
|
||||
tr->mItems = respList;
|
||||
|
||||
tr->mFlag = NxsTransaction::FLAG_STATE_WAITING_CONFIRM;
|
||||
RsNxsTransac* trItem = new RsNxsTransac(mServType);
|
||||
trItem->transactFlag = RsNxsTransac::FLAG_BEGIN_P1
|
||||
| RsNxsTransac::FLAG_TYPE_GRP_LIST_RESP;
|
||||
trItem->nItems = respList.size();
|
||||
trItem->timestamp = 0;
|
||||
trItem->PeerId(peer);
|
||||
trItem->transactionNumber = transN;
|
||||
// also make a copy for the resident transaction
|
||||
tr->mTransaction = new RsNxsTransac(*trItem);
|
||||
tr->mTransaction->PeerId(mOwnId);
|
||||
tr->mTimeOut = time(NULL) + mTransactionTimeOut;
|
||||
// signal peer to prepare for transaction
|
||||
sendItem(trItem);
|
||||
locked_addTransaction(tr);
|
||||
}
|
||||
|
||||
void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrp* item)
|
||||
{
|
||||
|
||||
@ -1402,11 +1759,12 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrp* item)
|
||||
std::map<std::string, RsGxsGrpMetaData*>::iterator mit =
|
||||
grp.begin();
|
||||
|
||||
NxsTransaction* tr = new NxsTransaction();
|
||||
std::list<RsNxsItem*>& itemL = tr->mItems;
|
||||
std::list<RsNxsItem*> itemL;
|
||||
|
||||
uint32_t transN = locked_getTransactionId();
|
||||
|
||||
std::vector<GrpIdCircleVet> toVet;
|
||||
|
||||
for(; mit != grp.end(); mit++)
|
||||
{
|
||||
RsGxsGrpMetaData* grpMeta = mit->second;
|
||||
@ -1414,42 +1772,92 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrp* item)
|
||||
if(grpMeta->mSubscribeFlags &
|
||||
GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED)
|
||||
{
|
||||
RsNxsSyncGrpItem* gItem = new
|
||||
RsNxsSyncGrpItem(mServType);
|
||||
gItem->flag = RsNxsSyncGrpItem::FLAG_RESPONSE;
|
||||
gItem->grpId = mit->first;
|
||||
gItem->publishTs = mit->second->mPublishTs;
|
||||
gItem->PeerId(peer);
|
||||
gItem->transactionNumber = transN;
|
||||
itemL.push_back(gItem);
|
||||
|
||||
// check if you can send this id to peer
|
||||
// or if you need to add to the holding
|
||||
// pen for peer to be vetted
|
||||
if(canSendGrpId(peer, *grpMeta, toVet))
|
||||
{
|
||||
RsNxsSyncGrpItem* gItem = new
|
||||
RsNxsSyncGrpItem(mServType);
|
||||
gItem->flag = RsNxsSyncGrpItem::FLAG_RESPONSE;
|
||||
gItem->grpId = mit->first;
|
||||
gItem->publishTs = mit->second->mPublishTs;
|
||||
gItem->authorId = grpMeta->mAuthorId;
|
||||
gItem->PeerId(peer);
|
||||
gItem->transactionNumber = transN;
|
||||
itemL.push_back(gItem);
|
||||
}
|
||||
}
|
||||
|
||||
delete grpMeta; // release resource
|
||||
}
|
||||
|
||||
tr->mFlag = NxsTransaction::FLAG_STATE_WAITING_CONFIRM;
|
||||
RsNxsTransac* trItem = new RsNxsTransac(mServType);
|
||||
trItem->transactFlag = RsNxsTransac::FLAG_BEGIN_P1
|
||||
| RsNxsTransac::FLAG_TYPE_GRP_LIST_RESP;
|
||||
trItem->nItems = itemL.size();
|
||||
if(!toVet.empty())
|
||||
{
|
||||
mPendingCircleVets.push_back(new GrpCircleIdRequestVetting(mCircles, toVet, peer));
|
||||
}
|
||||
|
||||
trItem->timestamp = 0;
|
||||
trItem->PeerId(peer);
|
||||
trItem->transactionNumber = transN;
|
||||
|
||||
// also make a copy for the resident transaction
|
||||
tr->mTransaction = new RsNxsTransac(*trItem);
|
||||
tr->mTransaction->PeerId(mOwnId);
|
||||
tr->mTimeOut = time(NULL) + mTransactionTimeOut;
|
||||
|
||||
// signal peer to prepare for transaction
|
||||
sendItem(trItem);
|
||||
|
||||
locked_addTransaction(tr);
|
||||
locked_pushGrpRespFromList(itemL, peer, transN);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool RsGxsNetService::canSendGrpId(const std::string& sslId, RsGxsGrpMetaData& grpMeta, std::vector<GrpIdCircleVet>& toVet)
|
||||
{
|
||||
// first do the simple checks
|
||||
uint8_t circleType = grpMeta.mCircleType;
|
||||
|
||||
if(circleType == GXS_CIRCLE_TYPE_LOCAL)
|
||||
return false;
|
||||
|
||||
if(circleType == GXS_CIRCLE_TYPE_PUBLIC)
|
||||
return true;
|
||||
|
||||
const RsGxsCircleId& circleId = grpMeta.mCircleId;
|
||||
|
||||
if(circleType == GXS_CIRCLE_TYPE_EXTERNAL)
|
||||
{
|
||||
if(mCircles->isLoaded(circleId))
|
||||
{
|
||||
const RsPgpId& pgpId = rsPeers->getGPGId(sslId);
|
||||
return mCircles->canSend(circleId, pgpId);
|
||||
}
|
||||
|
||||
toVet.push_back(GrpIdCircleVet(grpMeta.mGroupId, circleId));
|
||||
return false;
|
||||
}
|
||||
|
||||
if(circleType == GXS_CIRCLE_TYPE_YOUREYESONLY)
|
||||
{
|
||||
// a non empty internal circle id means this
|
||||
// is the personal circle owner
|
||||
if(!grpMeta.mInternalCircle.empty())
|
||||
{
|
||||
const RsGxsCircleId& internalCircleId = grpMeta.mCircleId;
|
||||
if(mCircles->isLoaded(internalCircleId))
|
||||
{
|
||||
const RsPgpId& pgpId = rsPeers->getGPGId(sslId);
|
||||
return mCircles->canSend(internalCircleId, pgpId);
|
||||
}
|
||||
|
||||
toVet.push_back(GrpIdCircleVet(grpMeta.mGroupId, internalCircleId));
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// an empty internal circle id means this peer can only
|
||||
// send circle related info from peer he received it
|
||||
if(grpMeta.mOriginator == sslId)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RsGxsNetService::handleRecvSyncMessage(RsNxsSyncMsg* item)
|
||||
{
|
||||
RsStackMutex stack(mNxsMutex);
|
||||
@ -1458,35 +1866,65 @@ void RsGxsNetService::handleRecvSyncMessage(RsNxsSyncMsg* item)
|
||||
|
||||
GxsMsgMetaResult metaResult;
|
||||
GxsMsgReq req;
|
||||
|
||||
std::map<std::string, RsGxsGrpMetaData*> grpMetas;
|
||||
grpMetas[item->grpId] = NULL;
|
||||
mDataStore->retrieveGxsGrpMetaData(grpMetas);
|
||||
RsGxsGrpMetaData* grpMeta = grpMetas[item->grpId];
|
||||
|
||||
if(grpMeta == NULL)
|
||||
return;
|
||||
|
||||
req[item->grpId] = std::vector<std::string>();
|
||||
mDataStore->retrieveGxsMsgMetaData(req, metaResult);
|
||||
std::vector<RsGxsMsgMetaData*>& msgMetas = metaResult[item->grpId];
|
||||
|
||||
std::vector<RsGxsMsgMetaData*>& msgMeta = metaResult[item->grpId];
|
||||
|
||||
if(req.empty()){
|
||||
if(req.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<RsGxsMsgMetaData*>::iterator vit = msgMeta.begin();
|
||||
|
||||
NxsTransaction* tr = new NxsTransaction();
|
||||
std::list<RsNxsItem*>& itemL = tr->mItems;
|
||||
std::list<RsNxsItem*> itemL;
|
||||
|
||||
uint32_t transN = locked_getTransactionId();
|
||||
|
||||
for(; vit != msgMeta.end(); vit++)
|
||||
if(/*canSendMsgIds(msgMetas, *grpMeta, peer)*/ true)
|
||||
{
|
||||
RsGxsMsgMetaData* m = *vit;
|
||||
RsNxsSyncMsgItem* mItem = new
|
||||
RsNxsSyncMsgItem(mServType);
|
||||
mItem->flag = RsNxsSyncGrpItem::FLAG_RESPONSE;
|
||||
mItem->grpId = m->mGroupId;
|
||||
mItem->msgId = m->mMsgId;
|
||||
mItem->PeerId(peer);
|
||||
mItem->transactionNumber = transN;
|
||||
itemL.push_back(mItem);
|
||||
std::vector<RsGxsMsgMetaData*>::iterator vit = msgMetas.begin();
|
||||
|
||||
for(; vit != msgMetas.end(); vit++)
|
||||
{
|
||||
RsGxsMsgMetaData* m = *vit;
|
||||
|
||||
RsNxsSyncMsgItem* mItem = new
|
||||
RsNxsSyncMsgItem(mServType);
|
||||
mItem->flag = RsNxsSyncGrpItem::FLAG_RESPONSE;
|
||||
mItem->grpId = m->mGroupId;
|
||||
mItem->msgId = m->mMsgId;
|
||||
mItem->authorId = m->mAuthorId;
|
||||
mItem->PeerId(peer);
|
||||
mItem->transactionNumber = transN;
|
||||
itemL.push_back(mItem);
|
||||
|
||||
}
|
||||
|
||||
if(!itemL.empty())
|
||||
locked_pushMsgRespFromList(itemL, peer, transN);
|
||||
}
|
||||
|
||||
std::vector<RsGxsMsgMetaData*>::iterator vit = msgMetas.begin();
|
||||
// release meta resource
|
||||
for(vit = msgMetas.begin(); vit != msgMetas.end(); vit++)
|
||||
delete *vit;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void RsGxsNetService::locked_pushMsgRespFromList(std::list<RsNxsItem*>& itemL, const std::string& sslId,
|
||||
const uint32_t& transN)
|
||||
{
|
||||
NxsTransaction* tr = new NxsTransaction();
|
||||
tr->mItems = itemL;
|
||||
tr->mFlag = NxsTransaction::FLAG_STATE_WAITING_CONFIRM;
|
||||
RsNxsTransac* trItem = new RsNxsTransac(mServType);
|
||||
trItem->transactFlag = RsNxsTransac::FLAG_BEGIN_P1
|
||||
@ -1495,7 +1933,7 @@ void RsGxsNetService::handleRecvSyncMessage(RsNxsSyncMsg* item)
|
||||
trItem->nItems = itemL.size();
|
||||
|
||||
trItem->timestamp = 0;
|
||||
trItem->PeerId(peer);
|
||||
trItem->PeerId(sslId);
|
||||
trItem->transactionNumber = transN;
|
||||
|
||||
// also make a copy for the resident transaction
|
||||
@ -1507,10 +1945,91 @@ void RsGxsNetService::handleRecvSyncMessage(RsNxsSyncMsg* item)
|
||||
sendItem(trItem);
|
||||
|
||||
locked_addTransaction(tr);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool RsGxsNetService::canSendMsgIds(const std::vector<RsGxsMsgMetaData*>& msgMetas,
|
||||
const RsGxsGrpMetaData& grpMeta, const std::string& sslId)
|
||||
{
|
||||
// first do the simple checks
|
||||
uint8_t circleType = grpMeta.mCircleType;
|
||||
|
||||
if(circleType == GXS_CIRCLE_TYPE_LOCAL)
|
||||
return false;
|
||||
|
||||
if(circleType == GXS_CIRCLE_TYPE_PUBLIC)
|
||||
return true;
|
||||
|
||||
const RsGxsCircleId& circleId = grpMeta.mCircleId;
|
||||
|
||||
if(circleType == GXS_CIRCLE_TYPE_EXTERNAL)
|
||||
{
|
||||
if(mCircles->isLoaded(circleId))
|
||||
{
|
||||
const RsPgpId& pgpId = rsPeers->getGPGId(sslId);
|
||||
return mCircles->canSend(circleId, pgpId);
|
||||
}
|
||||
|
||||
std::vector<MsgIdCircleVet> toVet;
|
||||
std::vector<RsGxsMsgMetaData*>::const_iterator vit = msgMetas.begin();
|
||||
|
||||
for(; vit != msgMetas.end(); vit++)
|
||||
{
|
||||
const RsGxsMsgMetaData* const& meta = *vit;
|
||||
|
||||
MsgIdCircleVet mic(meta->mMsgId, meta->mAuthorId);
|
||||
toVet.push_back(mic);
|
||||
}
|
||||
|
||||
if(!toVet.empty())
|
||||
mPendingCircleVets.push_back(new MsgCircleIdsRequestVetting(mCircles, toVet, grpMeta.mGroupId,
|
||||
sslId, grpMeta.mCircleId));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if(circleType == GXS_CIRCLE_TYPE_YOUREYESONLY)
|
||||
{
|
||||
// a non empty internal circle id means this
|
||||
// is the personal circle owner
|
||||
if(!grpMeta.mInternalCircle.empty())
|
||||
{
|
||||
const RsGxsCircleId& internalCircleId = grpMeta.mCircleId;
|
||||
if(mCircles->isLoaded(internalCircleId))
|
||||
{
|
||||
const RsPgpId& pgpId = rsPeers->getGPGId(sslId);
|
||||
return mCircles->canSend(internalCircleId, pgpId);
|
||||
}
|
||||
|
||||
std::vector<MsgIdCircleVet> toVet;
|
||||
std::vector<RsGxsMsgMetaData*>::const_iterator vit = msgMetas.begin();
|
||||
|
||||
for(; vit != msgMetas.end(); vit++)
|
||||
{
|
||||
const RsGxsMsgMetaData* const& meta = *vit;
|
||||
|
||||
MsgIdCircleVet mic(meta->mMsgId, meta->mAuthorId);
|
||||
toVet.push_back(mic);
|
||||
}
|
||||
|
||||
if(!toVet.empty())
|
||||
mPendingCircleVets.push_back(new MsgCircleIdsRequestVetting(mCircles, toVet, grpMeta.mGroupId,
|
||||
sslId, grpMeta.mCircleId));
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// an empty internal circle id means this peer can only
|
||||
// send circle related info from peer he received it
|
||||
if(grpMeta.mOriginator == sslId)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** inherited methods **/
|
||||
|
||||
@ -1524,68 +2043,3 @@ void RsGxsNetService::setSyncAge(uint32_t age)
|
||||
|
||||
}
|
||||
|
||||
/** NxsTransaction definition **/
|
||||
|
||||
const uint8_t NxsTransaction::FLAG_STATE_STARTING = 0x0001; // when
|
||||
const uint8_t NxsTransaction::FLAG_STATE_RECEIVING = 0x0002; // begin receiving items for incoming trans
|
||||
const uint8_t NxsTransaction::FLAG_STATE_SENDING = 0x0004; // begin sending items for outgoing trans
|
||||
const uint8_t NxsTransaction::FLAG_STATE_COMPLETED = 0x008;
|
||||
const uint8_t NxsTransaction::FLAG_STATE_FAILED = 0x0010;
|
||||
const uint8_t NxsTransaction::FLAG_STATE_WAITING_CONFIRM = 0x0020;
|
||||
|
||||
|
||||
NxsTransaction::NxsTransaction()
|
||||
: mFlag(0), mTimeOut(0), mTransaction(NULL) {
|
||||
|
||||
}
|
||||
|
||||
NxsTransaction::~NxsTransaction(){
|
||||
|
||||
std::list<RsNxsItem*>::iterator lit = mItems.begin();
|
||||
|
||||
for(; lit != mItems.end(); lit++)
|
||||
{
|
||||
delete *lit;
|
||||
*lit = NULL;
|
||||
}
|
||||
|
||||
delete mTransaction;
|
||||
mTransaction = NULL;
|
||||
}
|
||||
|
||||
|
||||
/* Net Manager */
|
||||
|
||||
RsNxsNetMgrImpl::RsNxsNetMgrImpl(p3LinkMgr *lMgr)
|
||||
: mLinkMgr(lMgr), mNxsNetMgrMtx("RsNxsNetMgrImpl")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::string RsNxsNetMgrImpl::getOwnId()
|
||||
{
|
||||
RsStackMutex stack(mNxsNetMgrMtx);
|
||||
return mLinkMgr->getOwnId();
|
||||
}
|
||||
|
||||
void RsNxsNetMgrImpl::getOnlineList(std::set<std::string> &ssl_peers)
|
||||
{
|
||||
ssl_peers.clear();
|
||||
|
||||
std::list<std::string> pList;
|
||||
{
|
||||
RsStackMutex stack(mNxsNetMgrMtx);
|
||||
mLinkMgr->getOnlineList(pList);
|
||||
}
|
||||
|
||||
std::list<std::string>::const_iterator lit = pList.begin();
|
||||
|
||||
for(; lit != pList.end(); lit++)
|
||||
ssl_peers.insert(*lit);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -34,79 +34,9 @@
|
||||
#include "rsnxsobserver.h"
|
||||
#include "pqi/p3linkmgr.h"
|
||||
#include "serialiser/rsnxsitems.h"
|
||||
|
||||
#include "rsgxsnetutils.h"
|
||||
#include "pqi/p3cfgmgr.h"
|
||||
|
||||
|
||||
/*!
|
||||
* This represents a transaction made
|
||||
* with the NxsNetService in all states
|
||||
* of operation until completion
|
||||
*
|
||||
*/
|
||||
class NxsTransaction
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
static const uint8_t FLAG_STATE_STARTING; // when
|
||||
static const uint8_t FLAG_STATE_RECEIVING; // begin receiving items for incoming trans
|
||||
static const uint8_t FLAG_STATE_SENDING; // begin sending items for outgoing trans
|
||||
static const uint8_t FLAG_STATE_COMPLETED;
|
||||
static const uint8_t FLAG_STATE_FAILED;
|
||||
static const uint8_t FLAG_STATE_WAITING_CONFIRM;
|
||||
|
||||
NxsTransaction();
|
||||
~NxsTransaction();
|
||||
|
||||
uint32_t mFlag; // current state of transaction
|
||||
uint32_t mTimeOut;
|
||||
|
||||
/*!
|
||||
* this contains who we
|
||||
* c what peer this transaction involves.
|
||||
* c The type of transaction
|
||||
* c transaction id
|
||||
* c timeout set for this transaction
|
||||
* c and itemCount
|
||||
*/
|
||||
RsNxsTransac* mTransaction;
|
||||
std::list<RsNxsItem*> mItems; // items received or sent
|
||||
};
|
||||
|
||||
/*!
|
||||
* An abstraction of the net manager
|
||||
* for retrieving Rs peers whom you will be synchronising
|
||||
* and also you own Id
|
||||
* Useful for testing also (abstracts away Rs's p3NetMgr)
|
||||
*/
|
||||
class RsNxsNetMgr
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
virtual std::string getOwnId() = 0;
|
||||
virtual void getOnlineList(std::set<std::string>& ssl_peers) = 0;
|
||||
|
||||
};
|
||||
|
||||
class RsNxsNetMgrImpl : public RsNxsNetMgr
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
RsNxsNetMgrImpl(p3LinkMgr* lMgr);
|
||||
|
||||
std::string getOwnId();
|
||||
void getOnlineList(std::set<std::string>& ssl_peers);
|
||||
|
||||
private:
|
||||
|
||||
p3LinkMgr* mLinkMgr;
|
||||
RsMutex mNxsNetMgrMtx;
|
||||
|
||||
};
|
||||
|
||||
#include "rsgixs.h"
|
||||
|
||||
/// keep track of transaction number
|
||||
typedef std::map<uint32_t, NxsTransaction*> TransactionIdMap;
|
||||
@ -139,9 +69,11 @@ public:
|
||||
* @param servType service type
|
||||
* @param gds The data service which allows read access to a service/store
|
||||
* @param nxsObs observer will be notified whenever new messages/grps
|
||||
* @param nxsObs observer will be notified whenever new messages/grps
|
||||
* arrive
|
||||
*/
|
||||
RsGxsNetService(uint16_t servType, RsGeneralDataService* gds, RsNxsNetMgr* netMgr, RsNxsObserver* nxsObs = NULL);
|
||||
RsGxsNetService(uint16_t servType, RsGeneralDataService* gds, RsNxsNetMgr* netMgr,
|
||||
RsNxsObserver* nxsObs = NULL, RsGixsReputation* repuations = NULL, RsGcxs* circles = NULL);
|
||||
|
||||
virtual ~RsGxsNetService();
|
||||
|
||||
@ -361,7 +293,34 @@ private:
|
||||
/** E: item handlers **/
|
||||
|
||||
|
||||
void runVetting();
|
||||
|
||||
/*!
|
||||
* @param peerId The peer to vet to see if they can receive this groupid
|
||||
* @param grpMeta this is the meta item to determine if it can be sent to given peer
|
||||
* @param toVet groupid/peer to vet are stored here if their circle id is not cached
|
||||
* @return false, if you cannot send to this peer, true otherwise
|
||||
*/
|
||||
bool canSendGrpId(const std::string& sslId, RsGxsGrpMetaData& grpMeta, std::vector<GrpIdCircleVet>& toVet);
|
||||
|
||||
|
||||
bool canSendMsgIds(const std::vector<RsGxsMsgMetaData*>& msgMetas, const RsGxsGrpMetaData&, const std::string& sslId);
|
||||
|
||||
void locked_createTransactionFromPending(MsgRespPending* grpPend);
|
||||
void locked_createTransactionFromPending(GrpRespPending* msgPend);
|
||||
void locked_createTransactionFromPending(GrpCircleIdRequestVetting* grpPend);
|
||||
void locked_createTransactionFromPending(MsgCircleIdsRequestVetting* grpPend);
|
||||
|
||||
void locked_pushMsgTransactionFromList(std::list<RsNxsItem*>& reqList, const std::string& peerId, const uint32_t& transN);
|
||||
void locked_pushGrpTransactionFromList(std::list<RsNxsItem*>& reqList, const std::string& peerId, const uint32_t& transN);
|
||||
void locked_pushGrpRespFromList(std::list<RsNxsItem*>& respList, const std::string& peer, const uint32_t& transN);
|
||||
void locked_pushMsgRespFromList(std::list<RsNxsItem*>& itemL, const std::string& sslId, const uint32_t& transN);
|
||||
void syncWithPeers();
|
||||
void addGroupItemToList(NxsTransaction*& tr,
|
||||
const std::string& grpId, uint32_t& transN,
|
||||
std::list<RsNxsItem*>& reqList);
|
||||
|
||||
bool locked_canReceive(const RsGxsGrpMetaData * const grpMeta, const std::string& peerId);
|
||||
|
||||
private:
|
||||
|
||||
@ -457,6 +416,12 @@ private:
|
||||
|
||||
const uint32_t mSYNC_PERIOD;
|
||||
|
||||
RsGcxs* mCircles;
|
||||
RsGixsReputation* mReputations;
|
||||
|
||||
// need to be verfied
|
||||
std::vector<AuthorPending*> mPendingResp;
|
||||
std::vector<GrpCircleVetting*> mPendingCircleVets;
|
||||
};
|
||||
|
||||
#endif // RSGXSNETSERVICE_H
|
||||
|
302
libretroshare/src/gxs/rsgxsnetutils.cc
Normal file
302
libretroshare/src/gxs/rsgxsnetutils.cc
Normal file
@ -0,0 +1,302 @@
|
||||
/*
|
||||
* libretroshare/src/gxs: rsgxnetutils.cc
|
||||
*
|
||||
* Helper objects for the operation rsgxsnetservice
|
||||
*
|
||||
* Copyright 2012-2013 by Christopher Evi-Parker
|
||||
*
|
||||
* 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".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "rsgxsnetutils.h"
|
||||
#include "retroshare/rspeers.h"
|
||||
|
||||
|
||||
const time_t AuthorPending::EXPIRY_PERIOD_OFFSET = 30; // 30 seconds
|
||||
const int AuthorPending::MSG_PEND = 1;
|
||||
const int AuthorPending::GRP_PEND = 2;
|
||||
|
||||
|
||||
AuthorPending::AuthorPending(RsGixsReputation* rep, time_t timeStamp)
|
||||
: mRep(rep), mTimeStamp(timeStamp) {
|
||||
}
|
||||
|
||||
AuthorPending::~AuthorPending()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool AuthorPending::expired() const
|
||||
{
|
||||
return time(NULL) > (mTimeStamp + EXPIRY_PERIOD_OFFSET);
|
||||
}
|
||||
|
||||
bool AuthorPending::getAuthorRep(GixsReputation& rep,
|
||||
const std::string& authorId)
|
||||
{
|
||||
if(mRep->haveReputation(authorId))
|
||||
{
|
||||
return mRep->getReputation(authorId, rep);
|
||||
}
|
||||
|
||||
mRep->loadReputation(authorId);
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
MsgAuthEntry::MsgAuthEntry()
|
||||
: mPassedVetting(false) {}
|
||||
|
||||
|
||||
GrpAuthEntry::GrpAuthEntry()
|
||||
: mPassedVetting(false) {}
|
||||
|
||||
|
||||
|
||||
MsgRespPending::MsgRespPending(RsGixsReputation* rep, const std::string& peerId, const MsgAuthorV& msgAuthV, int cutOff)
|
||||
: AuthorPending(rep, time(NULL)), mPeerId(peerId), mMsgAuthV(msgAuthV), mCutOff(cutOff)
|
||||
{
|
||||
}
|
||||
|
||||
GrpRespPending::GrpRespPending(RsGixsReputation* rep, const std::string& peerId, const GrpAuthorV& grpAuthV, int cutOff)
|
||||
: AuthorPending(rep, time(NULL)), mPeerId(peerId), mGrpAuthV(grpAuthV), mCutOff(cutOff)
|
||||
{
|
||||
}
|
||||
|
||||
int MsgRespPending::getType() const
|
||||
{
|
||||
return MSG_PEND;
|
||||
}
|
||||
|
||||
bool MsgRespPending::accepted()
|
||||
{
|
||||
MsgAuthorV::iterator cit = mMsgAuthV.begin();
|
||||
MsgAuthorV::size_type count = 0;
|
||||
for(; cit != mMsgAuthV.end(); cit++)
|
||||
{
|
||||
MsgAuthEntry& entry = *cit;
|
||||
|
||||
if(!entry.mPassedVetting)
|
||||
{
|
||||
GixsReputation rep;
|
||||
if(getAuthorRep(rep, entry.mAuthorId))
|
||||
{
|
||||
if(rep.score > mCutOff)
|
||||
{
|
||||
entry.mPassedVetting = true;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
}else
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return count == mMsgAuthV.size();
|
||||
}
|
||||
|
||||
int GrpRespPending::getType() const
|
||||
{
|
||||
return GRP_PEND;
|
||||
}
|
||||
|
||||
bool GrpRespPending::accepted()
|
||||
{
|
||||
GrpAuthorV::iterator cit = mGrpAuthV.begin();
|
||||
GrpAuthorV::size_type count = 0;
|
||||
for(; cit != mGrpAuthV.end(); cit++)
|
||||
{
|
||||
GrpAuthEntry& entry = *cit;
|
||||
|
||||
if(!entry.mPassedVetting)
|
||||
{
|
||||
GixsReputation rep;
|
||||
|
||||
if(getAuthorRep(rep, entry.mAuthorId))
|
||||
{
|
||||
if(rep.score > mCutOff)
|
||||
{
|
||||
entry.mPassedVetting = true;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
}else
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return count == mGrpAuthV.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** NxsTransaction definition **/
|
||||
|
||||
const uint8_t NxsTransaction::FLAG_STATE_STARTING = 0x0001; // when
|
||||
const uint8_t NxsTransaction::FLAG_STATE_RECEIVING = 0x0002; // begin receiving items for incoming trans
|
||||
const uint8_t NxsTransaction::FLAG_STATE_SENDING = 0x0004; // begin sending items for outgoing trans
|
||||
const uint8_t NxsTransaction::FLAG_STATE_COMPLETED = 0x008;
|
||||
const uint8_t NxsTransaction::FLAG_STATE_FAILED = 0x0010;
|
||||
const uint8_t NxsTransaction::FLAG_STATE_WAITING_CONFIRM = 0x0020;
|
||||
|
||||
|
||||
NxsTransaction::NxsTransaction()
|
||||
: mFlag(0), mTimeOut(0), mTransaction(NULL) {
|
||||
|
||||
}
|
||||
|
||||
NxsTransaction::~NxsTransaction(){
|
||||
|
||||
std::list<RsNxsItem*>::iterator lit = mItems.begin();
|
||||
|
||||
for(; lit != mItems.end(); lit++)
|
||||
{
|
||||
delete *lit;
|
||||
*lit = NULL;
|
||||
}
|
||||
|
||||
if(mTransaction)
|
||||
delete mTransaction;
|
||||
|
||||
mTransaction = NULL;
|
||||
}
|
||||
|
||||
|
||||
/* Net Manager */
|
||||
|
||||
RsNxsNetMgrImpl::RsNxsNetMgrImpl(p3LinkMgr *lMgr)
|
||||
: mLinkMgr(lMgr), mNxsNetMgrMtx("RsNxsNetMgrImpl")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::string RsNxsNetMgrImpl::getOwnId()
|
||||
{
|
||||
RsStackMutex stack(mNxsNetMgrMtx);
|
||||
return mLinkMgr->getOwnId();
|
||||
}
|
||||
|
||||
void RsNxsNetMgrImpl::getOnlineList(std::set<std::string> &ssl_peers)
|
||||
{
|
||||
ssl_peers.clear();
|
||||
|
||||
std::list<std::string> pList;
|
||||
{
|
||||
RsStackMutex stack(mNxsNetMgrMtx);
|
||||
mLinkMgr->getOnlineList(pList);
|
||||
}
|
||||
|
||||
std::list<std::string>::const_iterator lit = pList.begin();
|
||||
|
||||
for(; lit != pList.end(); lit++)
|
||||
ssl_peers.insert(*lit);
|
||||
}
|
||||
|
||||
const time_t GrpCircleVetting::EXPIRY_PERIOD_OFFSET = 5; // 10 seconds
|
||||
const int GrpCircleVetting::GRP_ID_PEND = 1;
|
||||
const int GrpCircleVetting::GRP_ITEM_PEND = 2;
|
||||
const int GrpCircleVetting::MSG_ID_SEND_PEND = 3;
|
||||
const int GrpCircleVetting::MSG_ID_RECV_PEND = 3;
|
||||
|
||||
|
||||
GrpIdCircleVet::GrpIdCircleVet(const RsGxsGroupId& grpId, const RsGxsCircleId& circleId)
|
||||
: mGroupId(grpId), mCircleId(circleId), mCleared(false) {}
|
||||
|
||||
GrpCircleVetting::GrpCircleVetting(RsGcxs* const circles)
|
||||
: mCircles(circles) {}
|
||||
|
||||
GrpCircleVetting::~GrpCircleVetting() {}
|
||||
|
||||
bool GrpCircleVetting::expired()
|
||||
{
|
||||
return time(NULL) > (mTimeStamp + EXPIRY_PERIOD_OFFSET);
|
||||
}
|
||||
bool GrpCircleVetting::canSend(const RsPgpId& peerId, const RsGxsCircleId& circleId)
|
||||
{
|
||||
if(mCircles->isLoaded(circleId))
|
||||
{
|
||||
const RsPgpId& pgpId = rsPeers->getGPGId(peerId);
|
||||
return mCircles->canSend(circleId, pgpId);
|
||||
}
|
||||
|
||||
mCircles->loadCircle(circleId);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
GrpCircleIdRequestVetting::GrpCircleIdRequestVetting(
|
||||
RsGcxs* const circles, std::vector<GrpIdCircleVet> grpCircleV, const std::string& peerId)
|
||||
: GrpCircleVetting(circles), mGrpCircleV(grpCircleV), mPeerId(peerId) {}
|
||||
|
||||
bool GrpCircleIdRequestVetting::cleared()
|
||||
{
|
||||
std::vector<GrpIdCircleVet>::size_type i, count;
|
||||
for(i = 0; i < mGrpCircleV.size(); i++)
|
||||
{
|
||||
GrpIdCircleVet& gic = mGrpCircleV[i];
|
||||
|
||||
if(!gic.mCleared)
|
||||
{
|
||||
if(canSend(mPeerId, gic.mCircleId))
|
||||
{
|
||||
gic.mCleared = true;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
count++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return count == mGrpCircleV.size();
|
||||
}
|
||||
|
||||
int GrpCircleIdRequestVetting::getType() const
|
||||
{
|
||||
return GRP_ID_PEND;
|
||||
}
|
||||
|
||||
MsgIdCircleVet::MsgIdCircleVet(const RsGxsMessageId& msgId,
|
||||
const std::string& authorId)
|
||||
: mMsgId(msgId), mAuthorId(authorId) {
|
||||
}
|
||||
|
||||
MsgCircleIdsRequestVetting::MsgCircleIdsRequestVetting(RsGcxs* const circles,
|
||||
std::vector<MsgIdCircleVet> msgs, const RsGxsGroupId& grpId,
|
||||
const std::string& peerId, const RsGxsCircleId& circleId)
|
||||
: GrpCircleVetting(circles), mMsgs(msgs), mGrpId(grpId), mPeerId(peerId), mCircleId(circleId) {}
|
||||
|
||||
bool MsgCircleIdsRequestVetting::cleared()
|
||||
{
|
||||
|
||||
return canSend(mPeerId, mCircleId);
|
||||
|
||||
}
|
||||
|
||||
int MsgCircleIdsRequestVetting::getType() const
|
||||
{
|
||||
return MSG_ID_SEND_PEND;
|
||||
}
|
||||
|
285
libretroshare/src/gxs/rsgxsnetutils.h
Normal file
285
libretroshare/src/gxs/rsgxsnetutils.h
Normal file
@ -0,0 +1,285 @@
|
||||
/*
|
||||
* libretroshare/src/gxs: rsgxnetutils.h
|
||||
*
|
||||
* Helper objects for the operation rsgxsnetservice
|
||||
*
|
||||
* Copyright 2012-2013 by Christopher Evi-Parker
|
||||
*
|
||||
* 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 RSGXSNETUTILS_H_
|
||||
#define RSGXSNETUTILS_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "retroshare/rsgxsifacetypes.h"
|
||||
#include "pqi/p3linkmgr.h"
|
||||
#include "serialiser/rsnxsitems.h"
|
||||
#include "rsgixs.h"
|
||||
|
||||
|
||||
/*!
|
||||
* This represents a transaction made
|
||||
* with the NxsNetService in all states
|
||||
* of operation until completion
|
||||
*
|
||||
*/
|
||||
class NxsTransaction
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
static const uint8_t FLAG_STATE_STARTING; // when
|
||||
static const uint8_t FLAG_STATE_RECEIVING; // begin receiving items for incoming trans
|
||||
static const uint8_t FLAG_STATE_SENDING; // begin sending items for outgoing trans
|
||||
static const uint8_t FLAG_STATE_COMPLETED;
|
||||
static const uint8_t FLAG_STATE_FAILED;
|
||||
static const uint8_t FLAG_STATE_WAITING_CONFIRM;
|
||||
|
||||
NxsTransaction();
|
||||
~NxsTransaction();
|
||||
|
||||
uint32_t mFlag; // current state of transaction
|
||||
uint32_t mTimeOut;
|
||||
|
||||
/*!
|
||||
* this contains who we
|
||||
* c what peer this transaction involves.
|
||||
* c The type of transaction
|
||||
* c transaction id
|
||||
* c timeout set for this transaction
|
||||
* c and itemCount
|
||||
*/
|
||||
RsNxsTransac* mTransaction;
|
||||
std::list<RsNxsItem*> mItems; // items received or sent
|
||||
};
|
||||
|
||||
/*!
|
||||
* An abstraction of the net manager
|
||||
* for retrieving Rs peers whom you will be synchronising
|
||||
* and also you own Id
|
||||
* Useful for testing also (abstracts away Rs's p3NetMgr)
|
||||
*/
|
||||
class RsNxsNetMgr
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
virtual ~RsNxsNetMgr(){};
|
||||
virtual std::string getOwnId() = 0;
|
||||
virtual void getOnlineList(std::set<std::string>& ssl_peers) = 0;
|
||||
|
||||
};
|
||||
|
||||
class RsNxsNetMgrImpl : public RsNxsNetMgr
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
RsNxsNetMgrImpl(p3LinkMgr* lMgr);
|
||||
virtual ~RsNxsNetMgrImpl(){};
|
||||
|
||||
std::string getOwnId();
|
||||
void getOnlineList(std::set<std::string>& ssl_peers);
|
||||
|
||||
private:
|
||||
|
||||
p3LinkMgr* mLinkMgr;
|
||||
RsMutex mNxsNetMgrMtx;
|
||||
|
||||
};
|
||||
|
||||
/*!
|
||||
* Partial abstract class
|
||||
* which represents
|
||||
* items waiting to be vetted
|
||||
* on account of their author Id
|
||||
*/
|
||||
class AuthorPending
|
||||
{
|
||||
public:
|
||||
|
||||
static const int MSG_PEND;
|
||||
static const int GRP_PEND;
|
||||
static const time_t EXPIRY_PERIOD_OFFSET;
|
||||
|
||||
AuthorPending(RsGixsReputation* rep, time_t timeStamp);
|
||||
virtual ~AuthorPending();
|
||||
virtual int getType() const = 0 ;
|
||||
|
||||
/*!
|
||||
* @return true if all authors pass vetting and their messages
|
||||
* should be requested
|
||||
*/
|
||||
virtual bool accepted() = 0;
|
||||
|
||||
/*!
|
||||
* @return true if message is past set expiry date
|
||||
*/
|
||||
bool expired() const;
|
||||
|
||||
protected:
|
||||
|
||||
/*!
|
||||
* Convenience function to get author reputation
|
||||
* @param rep reputation of author
|
||||
* @param authorId reputation to get
|
||||
* @return true if successfully retrieve repution
|
||||
*/
|
||||
bool getAuthorRep(GixsReputation& rep, const std::string& authorId);
|
||||
|
||||
private:
|
||||
|
||||
RsGixsReputation* mRep;
|
||||
time_t mTimeStamp;
|
||||
};
|
||||
|
||||
class MsgAuthEntry
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
MsgAuthEntry();
|
||||
|
||||
RsGxsMessageId mMsgId;
|
||||
RsGxsGroupId mGrpId;
|
||||
std::string mAuthorId;
|
||||
bool mPassedVetting;
|
||||
|
||||
};
|
||||
|
||||
class GrpAuthEntry
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
GrpAuthEntry();
|
||||
|
||||
RsGxsGroupId mGrpId;
|
||||
std::string mAuthorId;
|
||||
bool mPassedVetting;
|
||||
};
|
||||
|
||||
typedef std::vector<MsgAuthEntry> MsgAuthorV;
|
||||
typedef std::vector<GrpAuthEntry> GrpAuthorV;
|
||||
|
||||
class MsgRespPending : public AuthorPending
|
||||
{
|
||||
public:
|
||||
|
||||
MsgRespPending(RsGixsReputation* rep, const std::string& peerId, const MsgAuthorV& msgAuthV, int cutOff = 0);
|
||||
|
||||
int getType() const;
|
||||
bool accepted();
|
||||
std::string mPeerId;
|
||||
MsgAuthorV mMsgAuthV;
|
||||
int mCutOff;
|
||||
};
|
||||
|
||||
class GrpRespPending : public AuthorPending
|
||||
{
|
||||
public:
|
||||
|
||||
GrpRespPending(RsGixsReputation* rep, const std::string& peerId, const GrpAuthorV& grpAuthV, int cutOff = 0);
|
||||
int getType() const;
|
||||
bool accepted();
|
||||
std::string mPeerId;
|
||||
GrpAuthorV mGrpAuthV;
|
||||
int mCutOff;
|
||||
};
|
||||
|
||||
|
||||
///////////////
|
||||
|
||||
class GrpIdCircleVet
|
||||
{
|
||||
public:
|
||||
GrpIdCircleVet(const RsGxsGroupId& grpId, const RsGxsCircleId& circleId);
|
||||
RsGxsGroupId mGroupId;
|
||||
RsGxsCircleId mCircleId;
|
||||
bool mCleared;
|
||||
};
|
||||
|
||||
class MsgIdCircleVet
|
||||
{
|
||||
public:
|
||||
MsgIdCircleVet(const RsGxsMessageId& grpId, const std::string& authorId);
|
||||
|
||||
RsGxsMessageId mMsgId;
|
||||
std::string mAuthorId;
|
||||
};
|
||||
|
||||
class GrpItemCircleVet
|
||||
{
|
||||
public:
|
||||
RsNxsGrp* grpItem;
|
||||
RsGxsCircleId mCircleId;
|
||||
bool mCleared;
|
||||
};
|
||||
|
||||
class GrpCircleVetting
|
||||
{
|
||||
public:
|
||||
|
||||
static const time_t EXPIRY_PERIOD_OFFSET;
|
||||
static const int GRP_ID_PEND;
|
||||
static const int GRP_ITEM_PEND;
|
||||
static const int MSG_ID_SEND_PEND;
|
||||
static const int MSG_ID_RECV_PEND;
|
||||
|
||||
|
||||
GrpCircleVetting(RsGcxs* const circles);
|
||||
virtual ~GrpCircleVetting();
|
||||
bool expired();
|
||||
virtual int getType() const = 0;
|
||||
virtual bool cleared() = 0;
|
||||
|
||||
protected:
|
||||
bool canSend(const RsPgpId& peerId, const RsGxsCircleId& circleId);
|
||||
|
||||
private:
|
||||
|
||||
RsGcxs* const mCircles;
|
||||
time_t mTimeStamp;
|
||||
};
|
||||
|
||||
class GrpCircleIdRequestVetting : public GrpCircleVetting
|
||||
{
|
||||
public:
|
||||
GrpCircleIdRequestVetting(RsGcxs* const circles, std::vector<GrpIdCircleVet> mGrpCircleV, const std::string& peerId);
|
||||
bool cleared();
|
||||
int getType() const;
|
||||
std::vector<GrpIdCircleVet> mGrpCircleV;
|
||||
std::string mPeerId;
|
||||
};
|
||||
|
||||
class MsgCircleIdsRequestVetting : public GrpCircleVetting
|
||||
{
|
||||
public:
|
||||
MsgCircleIdsRequestVetting(RsGcxs* const circles, std::vector<MsgIdCircleVet> msgs, const RsGxsGroupId& grpId,
|
||||
const std::string& peerId, const RsGxsCircleId& circleId);
|
||||
bool cleared();
|
||||
int getType() const;
|
||||
std::vector<MsgIdCircleVet> mMsgs;
|
||||
RsGxsGroupId mGrpId;
|
||||
std::string mPeerId;
|
||||
RsGxsCircleId mCircleId;
|
||||
};
|
||||
|
||||
|
||||
#endif /* RSGXSNETUTILS_H_ */
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include "rsgxsutil.h"
|
||||
#include "retroshare/rsgxsflags.h"
|
||||
#include "pqi/pqihash.h"
|
||||
|
||||
|
||||
RsGxsMessageCleanUp::RsGxsMessageCleanUp(RsGeneralDataService* const dataService, uint32_t messageStorePeriod, uint32_t chunkSize)
|
||||
@ -102,3 +103,79 @@ bool RsGxsMessageCleanUp::clean()
|
||||
|
||||
return mGrpMeta.empty();
|
||||
}
|
||||
|
||||
RsGxsIntegrityCheck::RsGxsIntegrityCheck(
|
||||
RsGeneralDataService* const dataService) :
|
||||
mDs(dataService), mDone(false), mIntegrityMutex("integrity")
|
||||
{ }
|
||||
|
||||
void RsGxsIntegrityCheck::run()
|
||||
{
|
||||
check();
|
||||
}
|
||||
|
||||
bool RsGxsIntegrityCheck::check()
|
||||
{
|
||||
|
||||
// first take out all the groups
|
||||
std::map<RsGxsGroupId, RsNxsGrp*> grp;
|
||||
mDs->retrieveNxsGrps(grp, true, true);
|
||||
std::vector<RsGxsGroupId> grpsToDel;
|
||||
|
||||
// compute hash and compare to stored value, if it fails then simply add it
|
||||
// to list
|
||||
std::map<RsGxsGroupId, RsNxsGrp*>::iterator git = grp.begin();
|
||||
for(; git != grp.end(); git++)
|
||||
{
|
||||
RsNxsGrp* grp = git->second;
|
||||
std::string currHash;
|
||||
pqihash pHash;
|
||||
pHash.addData(grp->grp.bin_data, grp->grp.bin_len);
|
||||
pHash.Complete(currHash);
|
||||
|
||||
if(currHash != grp->metaData->mHash) grpsToDel.push_back(grp->grpId);
|
||||
delete grp;
|
||||
}
|
||||
|
||||
mDs->removeGroups(grpsToDel);
|
||||
|
||||
// now messages
|
||||
GxsMsgReq msgsToDel;
|
||||
GxsMsgResult msgs;
|
||||
|
||||
mDs->retrieveNxsMsgs(msgsToDel, msgs, false, true);
|
||||
|
||||
GxsMsgResult::iterator mit = msgs.begin();
|
||||
|
||||
for(; mit != msgs.begin(); mit++)
|
||||
{
|
||||
std::vector<RsNxsMsg*>& msgV = mit->second;
|
||||
std::vector<RsNxsMsg*>::iterator vit = msgV.begin();
|
||||
|
||||
for(; vit != msgV.end(); vit++)
|
||||
{
|
||||
RsNxsMsg* msg = *vit;
|
||||
std::string currHash;
|
||||
pqihash pHash;
|
||||
pHash.addData(msg->msg.bin_data, msg->msg.bin_len);
|
||||
pHash.Complete(currHash);
|
||||
|
||||
if(currHash != msg->metaData->mHash) msgsToDel[msg->grpId].push_back(msg->msgId);
|
||||
delete msg;
|
||||
}
|
||||
}
|
||||
|
||||
mDs->removeMsgs(msgsToDel);
|
||||
|
||||
RsStackMutex stack(mIntegrityMutex);
|
||||
mDone = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RsGxsIntegrityCheck::isDone()
|
||||
{
|
||||
RsStackMutex stack(mIntegrityMutex);
|
||||
return mDone;
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ public:
|
||||
bool clean();
|
||||
|
||||
/*!
|
||||
* TODO: Rather manual progressions consider running through a thread
|
||||
* TODO: Rather than manual progressions consider running through a thread
|
||||
*/
|
||||
void run(){}
|
||||
|
||||
@ -93,5 +93,40 @@ private:
|
||||
std::vector<RsGxsGrpMetaData*> mGrpMeta;
|
||||
};
|
||||
|
||||
/*!
|
||||
* Checks the integrity message and groups
|
||||
* in rsDataService using computed hash
|
||||
*/
|
||||
class RsGxsIntegrityCheck : public RsThread
|
||||
{
|
||||
|
||||
enum CheckState { CheckStart, CheckChecking };
|
||||
|
||||
public:
|
||||
|
||||
|
||||
/*!
|
||||
*
|
||||
* @param dataService
|
||||
* @param mGroupTS
|
||||
* @param chunkSize
|
||||
* @param sleepPeriod
|
||||
*/
|
||||
RsGxsIntegrityCheck(RsGeneralDataService* const dataService);
|
||||
|
||||
|
||||
bool check();
|
||||
bool isDone();
|
||||
|
||||
void run();
|
||||
|
||||
private:
|
||||
|
||||
RsGeneralDataService* const mDs;
|
||||
std::vector<RsNxsItem*> mItems;
|
||||
bool mDone;
|
||||
RsMutex mIntegrityMutex;
|
||||
|
||||
};
|
||||
|
||||
#endif /* GXSUTIL_H_ */
|
||||
|
@ -7,7 +7,7 @@ CONFIG += test_voip
|
||||
|
||||
#GXS Stuff.
|
||||
# This should be disabled for releases until further notice.
|
||||
#CONFIG += gxs debug
|
||||
CONFIG += gxs debug
|
||||
|
||||
# Beware: All data of the stripped services are lost
|
||||
DEFINES *= PQI_DISABLE_TUNNEL
|
||||
@ -198,46 +198,47 @@ win32-x-g++ {
|
||||
################################# Windows ##########################################
|
||||
|
||||
|
||||
|
||||
win32 {
|
||||
QMAKE_CC = g++
|
||||
OBJECTS_DIR = temp/obj
|
||||
MOC_DIR = temp/moc
|
||||
DEFINES *= WINDOWS_SYS WIN32 STATICLIB MINGW
|
||||
DEFINES *= MINIUPNPC_VERSION=13
|
||||
DESTDIR = lib
|
||||
QMAKE_CC = g++
|
||||
OBJECTS_DIR = temp/obj
|
||||
MOC_DIR = temp/moc
|
||||
DEFINES *= WINDOWS_SYS WIN32 STATICLIB MINGW
|
||||
DEFINES *= MINIUPNPC_VERSION=13
|
||||
DESTDIR = lib
|
||||
|
||||
# Switch on extra warnings
|
||||
QMAKE_CFLAGS += -Wextra
|
||||
QMAKE_CXXFLAGS += -Wextra
|
||||
# Switch on extra warnings
|
||||
QMAKE_CFLAGS += -Wextra
|
||||
QMAKE_CXXFLAGS += -Wextra
|
||||
|
||||
# Switch off optimization for release version
|
||||
QMAKE_CXXFLAGS_RELEASE -= -O2
|
||||
QMAKE_CXXFLAGS_RELEASE += -O0
|
||||
QMAKE_CFLAGS_RELEASE -= -O2
|
||||
QMAKE_CFLAGS_RELEASE += -O0
|
||||
# Switch off optimization for release version
|
||||
QMAKE_CXXFLAGS_RELEASE -= -O2
|
||||
QMAKE_CXXFLAGS_RELEASE += -O0
|
||||
QMAKE_CFLAGS_RELEASE -= -O2
|
||||
QMAKE_CFLAGS_RELEASE += -O0
|
||||
|
||||
# Switch on optimization for debug version
|
||||
#QMAKE_CXXFLAGS_DEBUG += -O2
|
||||
#QMAKE_CFLAGS_DEBUG += -O2
|
||||
# Switch on optimization for debug version
|
||||
#QMAKE_CXXFLAGS_DEBUG += -O2
|
||||
#QMAKE_CFLAGS_DEBUG += -O2
|
||||
|
||||
DEFINES += USE_CMD_ARGS
|
||||
DEFINES += USE_CMD_ARGS
|
||||
|
||||
CONFIG += upnp_miniupnpc
|
||||
CONFIG += upnp_miniupnpc
|
||||
|
||||
UPNPC_DIR = ../../../miniupnpc-1.3
|
||||
UPNPC_DIR = ../../../lib/miniupnpc-1.3
|
||||
PTHREADS_DIR = ../../../lib/pthreads-w32-2-8-0-release
|
||||
ZLIB_DIR = ../../../lib/zlib-1.2.3
|
||||
SSL_DIR = ../../../OpenSSL
|
||||
OPENPGPSDK_DIR = ../../openpgpsdk/src
|
||||
|
||||
PTHREADS_DIR = ../../../pthreads-w32-2-8-0-release
|
||||
ZLIB_DIR = ../../../zlib-1.2.3
|
||||
SSL_DIR = ../../../openssl-1.0.1c
|
||||
OPENPGPSDK_DIR = ../../openpgpsdk/src
|
||||
INCLUDEPATH += . $${SSL_DIR}/include $${UPNPC_DIR} $${PTHREADS_DIR} $${ZLIB_DIR} $${OPENPGPSDK_DIR}
|
||||
|
||||
INCLUDEPATH += . $${SSL_DIR}/include $${UPNPC_DIR} $${PTHREADS_DIR} $${ZLIB_DIR} $${OPENPGPSDK_DIR}
|
||||
|
||||
# SQLite include path is required to compile GXS.
|
||||
gxs {
|
||||
SQLITE_DIR = ../../../sqlite-autoconf-3070900
|
||||
INCLUDEPATH += $${SQLITE_DIR}
|
||||
}
|
||||
# SQLite include path is required to compile GXS.
|
||||
gxs {
|
||||
SQLITE_DIR = ../../../../Libraries/sqlite/sqlite-autoconf-3070900
|
||||
INCLUDEPATH += . \
|
||||
$${SQLITE_DIR}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -614,8 +615,8 @@ SOURCES += zeroconf/p3zcnatassist.cc \
|
||||
gxs {
|
||||
DEFINES *= RS_ENABLE_GXS
|
||||
|
||||
# DEFINES *= GXS_DEV_TESTNET
|
||||
# DEFINES *= GXS_ENABLE_SYNC_MSGS
|
||||
DEFINES *= GXS_DEV_TESTNET
|
||||
DEFINES *= GXS_ENABLE_SYNC_MSGS
|
||||
|
||||
HEADERS += serialiser/rsnxsitems.h \
|
||||
gxs/rsgds.h \
|
||||
@ -638,6 +639,7 @@ gxs {
|
||||
gxs/gxssecurity.h \
|
||||
gxs/rsgxsifacehelper.h \
|
||||
gxs/gxstokenqueue.h \
|
||||
gxs/rsgxsnetutils.h \
|
||||
gxs/rsgxsiface.h
|
||||
|
||||
|
||||
@ -653,6 +655,7 @@ gxs {
|
||||
util/rsdbbind.cc \
|
||||
gxs/gxssecurity.cc \
|
||||
gxs/gxstokenqueue.cc \
|
||||
gxs/rsgxsnetutils.cc \
|
||||
gxs/rsgxsutil.cc
|
||||
|
||||
|
||||
|
@ -52,7 +52,7 @@ class pqihash
|
||||
}
|
||||
|
||||
|
||||
void addData(void *data, uint32_t len)
|
||||
void addData(const void *data, uint32_t len)
|
||||
{
|
||||
if (doHash)
|
||||
{
|
||||
|
@ -50,6 +50,10 @@ typedef std::string RsCircleInternalId;
|
||||
#define GXS_CIRCLE_TYPE_PUBLIC 0x0001
|
||||
#define GXS_CIRCLE_TYPE_EXTERNAL 0x0002
|
||||
#define GXS_CIRCLE_TYPE_YOUREYESONLY 0x0003
|
||||
#define GXS_CIRCLE_TYPE_LOCAL 0x0004
|
||||
|
||||
// A special one - used only by Circles themselves - meaning Circle ID == Group ID.
|
||||
#define GXS_CIRCLE_TYPE_EXT_SELF 0x0005
|
||||
|
||||
/* Permissions is part of GroupMetaData
|
||||
*/
|
||||
@ -71,6 +75,7 @@ class RsGxsCircleGroup
|
||||
public:
|
||||
RsGroupMetaData mMeta; // includes GxsPermissions, for control of group distribution.
|
||||
|
||||
std::list<RsPgpId> mLocalFriends;
|
||||
std::list<RsGxsId> mInvitedMembers;
|
||||
std::list<RsGxsCircleId> mSubCircles;
|
||||
|
||||
@ -94,6 +99,10 @@ class RsGxsCircleDetails
|
||||
public:
|
||||
RsGxsCircleId mCircleId;
|
||||
std::string mCircleName;
|
||||
|
||||
uint32_t mCircleType;
|
||||
bool mIsExternal;
|
||||
|
||||
std::set<RsGxsId> mUnknownPeers;
|
||||
std::map<RsPgpId, std::list<RsGxsId> > mAllowedPeers;
|
||||
};
|
||||
@ -112,7 +121,8 @@ virtual ~RsGxsCircles() { return; }
|
||||
|
||||
/* External Interface (Cached stuff) */
|
||||
virtual bool getCircleDetails(const RsGxsCircleId &id, RsGxsCircleDetails &details) = 0;
|
||||
virtual bool getCircleIdList(std::list<RsGxsCircleId> &circleIds) = 0;
|
||||
virtual bool getCircleExternalIdList(std::list<RsGxsCircleId> &circleIds) = 0;
|
||||
virtual bool getCirclePersonalIdList(std::list<RsGxsCircleId> &circleIds) = 0;
|
||||
|
||||
/* standard load */
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsCircleGroup> &groups) = 0;
|
||||
|
@ -69,6 +69,21 @@ static void release(void *data);
|
||||
#define GXS_VOTE_DOWN 0x0001
|
||||
#define GXS_VOTE_UP 0x0002
|
||||
|
||||
|
||||
// Status Flags to indicate Voting....
|
||||
// All Services that use the Comment service must not Use This space.
|
||||
namespace GXS_SERV {
|
||||
/* Msg Vote Status */
|
||||
static const uint32_t GXS_MSG_STATUS_GXSCOMMENT_MASK = 0x000f0000;
|
||||
static const uint32_t GXS_MSG_STATUS_VOTE_MASK = 0x00030000;
|
||||
|
||||
static const uint32_t GXS_MSG_STATUS_VOTE_UP = 0x00010000;
|
||||
static const uint32_t GXS_MSG_STATUS_VOTE_DOWN = 0x00020000;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
class RsGxsVote
|
||||
{
|
||||
public:
|
||||
|
@ -89,15 +89,23 @@ namespace GXS_SERV {
|
||||
|
||||
/** START GXS Msg status flags **/
|
||||
|
||||
static const uint32_t GXS_MSG_STATUS_UNPROCESSED = 0x0000001;
|
||||
/*!
|
||||
* Two lower bytes are reserved for Generic STATUS Flags listed here.
|
||||
* Services are free to use the two upper bytes. (16 flags).
|
||||
*
|
||||
* NOTE: RsGxsCommentService uses 0x000f0000.
|
||||
*/
|
||||
static const uint32_t GXS_MSG_STATUS_GEN_MASK = 0x0000ffff;
|
||||
|
||||
static const uint32_t GXS_MSG_STATUS_UNREAD = 0x000002;
|
||||
static const uint32_t GXS_MSG_STATUS_UNPROCESSED = 0x00000001;
|
||||
|
||||
static const uint32_t GXS_MSG_STATUS_READ = 0x000004;
|
||||
static const uint32_t GXS_MSG_STATUS_UNREAD = 0x00000002;
|
||||
|
||||
static const uint32_t GXS_MSG_STATUS_KEEP = 0x000008;
|
||||
static const uint32_t GXS_MSG_STATUS_READ = 0x00000004;
|
||||
|
||||
static const uint32_t GXS_MSG_STATUS_DELETE = 0x0000020;
|
||||
static const uint32_t GXS_MSG_STATUS_KEEP = 0x00000008;
|
||||
|
||||
static const uint32_t GXS_MSG_STATUS_DELETE = 0x000000020;
|
||||
|
||||
/** END GXS Msg status flags **/
|
||||
|
||||
|
@ -93,7 +93,7 @@ public:
|
||||
|
||||
/*!
|
||||
* The msg changed. \n
|
||||
* class can reimplement to use to tailor
|
||||
* class can be reimplemented to use to tailor
|
||||
* the msg actually set for ui notification.
|
||||
* If receivedChanges is not passed RsGxsNotify changes
|
||||
* this function does nothing
|
||||
|
@ -10,6 +10,9 @@
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <inttypes.h>
|
||||
|
||||
|
||||
typedef std::string RsGxsGroupId;
|
||||
typedef std::string RsGxsMessageId;
|
||||
@ -60,6 +63,7 @@ public:
|
||||
// for circles
|
||||
std::string mCircleId;
|
||||
uint32_t mCircleType;
|
||||
uint32_t mAuthenFlags;
|
||||
|
||||
// BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG.
|
||||
|
||||
|
@ -18,8 +18,11 @@ typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsMsgMetaData> > GxsMsgRelatedMe
|
||||
class RsGxsNotify
|
||||
{
|
||||
public:
|
||||
RsGxsNotify(){ return; }
|
||||
|
||||
enum NotifyType { TYPE_PUBLISH, TYPE_RECEIVE, TYPE_PROCESSED };
|
||||
|
||||
virtual ~RsGxsNotify() {return; }
|
||||
virtual NotifyType getType() = 0;
|
||||
|
||||
};
|
||||
|
||||
@ -30,7 +33,11 @@ public:
|
||||
class RsGxsGroupChange : public RsGxsNotify
|
||||
{
|
||||
public:
|
||||
RsGxsGroupChange(NotifyType type) : NOTIFY_TYPE(type) {}
|
||||
std::list<RsGxsGroupId> mGrpIdList;
|
||||
NotifyType getType(){ return NOTIFY_TYPE;}
|
||||
private:
|
||||
const NotifyType NOTIFY_TYPE;
|
||||
};
|
||||
|
||||
/*!
|
||||
@ -40,7 +47,11 @@ public:
|
||||
class RsGxsMsgChange : public RsGxsNotify
|
||||
{
|
||||
public:
|
||||
RsGxsMsgChange(NotifyType type) : NOTIFY_TYPE(type) {}
|
||||
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > msgChangeMap;
|
||||
NotifyType getType(){ return NOTIFY_TYPE;}
|
||||
private:
|
||||
const NotifyType NOTIFY_TYPE;
|
||||
};
|
||||
|
||||
|
||||
|
@ -100,14 +100,20 @@ class RsGxsIdOpinion
|
||||
//std::string mPeerId; (mAuthorId) ???
|
||||
|
||||
uint32_t mOpinion;
|
||||
std::string mComment;
|
||||
uint32_t mReputation;
|
||||
|
||||
|
||||
/* these convert To/From uint32 to expected scale. */
|
||||
int getOpinion();
|
||||
int getReputation();
|
||||
|
||||
int setOpinion(int op);
|
||||
int setReputation(int rep);
|
||||
|
||||
// NOT SERIALISED YET!
|
||||
|
||||
double mReputation;
|
||||
//int mRating;
|
||||
//int mPeersRating;
|
||||
//std::string mComment;
|
||||
};
|
||||
|
||||
|
||||
@ -230,6 +236,7 @@ virtual bool createIdentity(uint32_t& token, RsIdentityParameters ¶ms) = 0;
|
||||
*/
|
||||
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups) = 0;
|
||||
virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
@ -75,8 +75,8 @@ class RsPosted : public RsGxsIfaceHelper, public RsGxsCommentService
|
||||
|
||||
enum RankType {TopRankType, HotRankType, NewRankType };
|
||||
|
||||
static const uint32_t FLAG_MSGTYPE_POST;
|
||||
static const uint32_t FLAG_MSGTYPE_MASK;
|
||||
//static const uint32_t FLAG_MSGTYPE_POST;
|
||||
//static const uint32_t FLAG_MSGTYPE_MASK;
|
||||
|
||||
RsPosted(RsGxsIface* gxs) : RsGxsIfaceHelper(gxs) { return; }
|
||||
virtual ~RsPosted() { return; }
|
||||
@ -87,15 +87,6 @@ virtual bool getGroupData(const uint32_t &token, std::vector<RsPostedGroup> &gro
|
||||
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts) = 0;
|
||||
virtual bool getRelatedPosts(const uint32_t &token, std::vector<RsPostedPost> &posts) = 0;
|
||||
|
||||
|
||||
// SPECIAL RANKING FNS.
|
||||
virtual bool requestPostRankings(uint32_t &token, const RankType &rType, uint32_t count, uint32_t page_no, const RsGxsGroupId &groupId) = 0;
|
||||
|
||||
virtual bool getPostRanking(const uint32_t &token, std::vector<RsPostedPost> &msgs) = 0;
|
||||
|
||||
|
||||
//virtual bool getPostRanking(const uint32_t& token, std::vector<RsPostedPost> &ranking) = 0;
|
||||
|
||||
/* From RsGxsCommentService */
|
||||
//virtual bool getCommentData(const uint32_t &token, std::vector<RsGxsComment> &comments) = 0;
|
||||
//virtual bool getRelatedComments(const uint32_t &token, std::vector<RsGxsComment> &comments) = 0;
|
||||
@ -108,25 +99,6 @@ virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgI
|
||||
virtual bool createGroup(uint32_t &token, RsPostedGroup &group) = 0;
|
||||
virtual bool createPost(uint32_t &token, RsPostedPost &post) = 0;
|
||||
|
||||
//virtual bool retrieveScores(const std::string& serviceString, uint32_t& upVotes, uint32_t& downVotes, uint32_t& nComments) const = 0;
|
||||
|
||||
// Special Ranking Request.
|
||||
/*!
|
||||
* Makes request for posts of a topic
|
||||
* @param token
|
||||
* @param rType
|
||||
* @param groupId
|
||||
*/
|
||||
//virtual bool requestPostRankings(uint32_t &token, const RankType& rType, const RsGxsGroupId& groupId) = 0;
|
||||
|
||||
/*!
|
||||
* Makes request for ranking of comments for a post
|
||||
* @param token
|
||||
* @param rType type of ranking to collect
|
||||
* @param msgId message id of post as groupid-messageid pair
|
||||
*/
|
||||
//virtual bool requestCommentRankings(uint32_t &token, const RankType& rType, const RsGxsGrpMsgIdPair& msgId) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -136,22 +108,28 @@ class RsPostedPost
|
||||
public:
|
||||
RsPostedPost()
|
||||
{
|
||||
mMeta.mMsgFlags = RsPosted::FLAG_MSGTYPE_POST;
|
||||
//mMeta.mMsgFlags = RsPosted::FLAG_MSGTYPE_POST;
|
||||
mUpVotes = 0;
|
||||
mDownVotes = 0;
|
||||
mComments = 0;
|
||||
mHaveVoted = false;
|
||||
return;
|
||||
}
|
||||
|
||||
bool calculateScores(time_t ref_time);
|
||||
|
||||
RsMsgMetaData mMeta;
|
||||
std::string mLink;
|
||||
std::string mNotes;
|
||||
|
||||
bool mHaveVoted;
|
||||
|
||||
// Calculated.
|
||||
uint32_t mUpVotes;
|
||||
uint32_t mDownVotes;
|
||||
uint32_t mComments;
|
||||
|
||||
|
||||
// and Calculated Scores:???
|
||||
double mHotScore;
|
||||
double mTopScore;
|
||||
|
@ -2270,7 +2270,7 @@ int RsServer::StartupRetroShare()
|
||||
// the given ssl user id then this directory is cleaned
|
||||
// and deleted
|
||||
std::string priorGxsDir = "./" + mLinkMgr->getOwnId() + "/";
|
||||
std::string currGxsDir = RsInitConfig::configDir + "/GXS_phase1";
|
||||
std::string currGxsDir = RsInitConfig::configDir + "/GXS_phase2";
|
||||
|
||||
#ifdef GXS_DEV_TESTNET // Different Directory for testing.
|
||||
currGxsDir += "_TESTNET3";
|
||||
@ -2297,7 +2297,7 @@ int RsServer::StartupRetroShare()
|
||||
/**** Identity service ****/
|
||||
|
||||
RsGeneralDataService* gxsid_ds = new RsDataService(currGxsDir + "/", "gxsid_db",
|
||||
RS_SERVICE_GXSV1_TYPE_GXSID, NULL);
|
||||
RS_SERVICE_GXSV2_TYPE_GXSID, NULL, RsInitConfig::passwd);
|
||||
|
||||
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
|
||||
gxsid_ds->resetDataStore();
|
||||
@ -2306,15 +2306,20 @@ int RsServer::StartupRetroShare()
|
||||
// init gxs services
|
||||
mGxsIdService = new p3IdService(gxsid_ds, NULL);
|
||||
|
||||
RsGeneralDataService* gxscircles_ds = new RsDataService(currGxsDir + "/", "gxscircles_db",
|
||||
RS_SERVICE_GXSV2_TYPE_GXSCIRCLE, NULL, RsInitConfig::passwd);
|
||||
|
||||
mGxsCircles = new p3GxsCircles(gxscircles_ds, NULL, mGxsIdService);
|
||||
|
||||
// create GXS photo service
|
||||
RsGxsNetService* gxsid_ns = new RsGxsNetService(
|
||||
RS_SERVICE_GXSV1_TYPE_GXSID, gxsid_ds, nxsMgr, mGxsIdService);
|
||||
RS_SERVICE_GXSV2_TYPE_GXSID, gxsid_ds, nxsMgr,
|
||||
mGxsIdService, mGxsIdService, mGxsCircles);
|
||||
|
||||
/**** GxsCircle service ****/
|
||||
|
||||
|
||||
RsGeneralDataService* gxscircles_ds = new RsDataService(currGxsDir + "/", "gxscircles_db",
|
||||
RS_SERVICE_GXSV1_TYPE_GXSCIRCLE, NULL);
|
||||
|
||||
|
||||
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
|
||||
gxscircles_ds->resetDataStore();
|
||||
@ -2325,12 +2330,13 @@ int RsServer::StartupRetroShare()
|
||||
|
||||
// create GXS Circle service
|
||||
RsGxsNetService* gxscircles_ns = new RsGxsNetService(
|
||||
RS_SERVICE_GXSV1_TYPE_GXSCIRCLE, gxscircles_ds, nxsMgr, mGxsCircles);
|
||||
RS_SERVICE_GXSV2_TYPE_GXSCIRCLE, gxscircles_ds, nxsMgr,
|
||||
mGxsCircles, mGxsIdService, mGxsCircles);
|
||||
|
||||
|
||||
/**** Photo service ****/
|
||||
RsGeneralDataService* photo_ds = new RsDataService(currGxsDir + "/", "photoV2_db",
|
||||
RS_SERVICE_GXSV1_TYPE_PHOTO, NULL);
|
||||
RS_SERVICE_GXSV2_TYPE_PHOTO, NULL, RsInitConfig::passwd);
|
||||
|
||||
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
|
||||
photo_ds->resetDataStore(); //TODO: remove, new service data per RS session, for testing
|
||||
@ -2341,14 +2347,14 @@ int RsServer::StartupRetroShare()
|
||||
|
||||
// create GXS photo service
|
||||
RsGxsNetService* photo_ns = new RsGxsNetService(
|
||||
RS_SERVICE_GXSV1_TYPE_PHOTO, photo_ds, nxsMgr, mPhoto);
|
||||
RS_SERVICE_GXSV2_TYPE_PHOTO, photo_ds, nxsMgr, mPhoto, mGxsIdService, mGxsCircles);
|
||||
|
||||
/**** Posted GXS service ****/
|
||||
|
||||
|
||||
|
||||
RsGeneralDataService* posted_ds = new RsDataService(currGxsDir + "/", "posted_db",
|
||||
RS_SERVICE_GXSV1_TYPE_POSTED);
|
||||
RS_SERVICE_GXSV2_TYPE_POSTED, NULL, RsInitConfig::passwd);
|
||||
|
||||
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
|
||||
posted_ds->resetDataStore(); //TODO: remove, new service data per RS session, for testing
|
||||
@ -2358,7 +2364,7 @@ int RsServer::StartupRetroShare()
|
||||
|
||||
// create GXS photo service
|
||||
RsGxsNetService* posted_ns = new RsGxsNetService(
|
||||
RS_SERVICE_GXSV1_TYPE_POSTED, posted_ds, nxsMgr, mPosted);
|
||||
RS_SERVICE_GXSV2_TYPE_POSTED, posted_ds, nxsMgr, mPosted, mGxsIdService, mGxsCircles);
|
||||
|
||||
|
||||
/**** Wiki GXS service ****/
|
||||
@ -2366,7 +2372,8 @@ int RsServer::StartupRetroShare()
|
||||
|
||||
|
||||
RsGeneralDataService* wiki_ds = new RsDataService(currGxsDir + "/", "wiki_db",
|
||||
RS_SERVICE_GXSV1_TYPE_WIKI);
|
||||
RS_SERVICE_GXSV2_TYPE_WIKI,
|
||||
NULL, RsInitConfig::passwd);
|
||||
|
||||
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
|
||||
wiki_ds->resetDataStore(); //TODO: remove, new service data per RS session, for testing
|
||||
@ -2376,14 +2383,14 @@ int RsServer::StartupRetroShare()
|
||||
|
||||
// create GXS photo service
|
||||
RsGxsNetService* wiki_ns = new RsGxsNetService(
|
||||
RS_SERVICE_GXSV1_TYPE_WIKI, wiki_ds, nxsMgr, mWiki);
|
||||
RS_SERVICE_GXSV2_TYPE_WIKI, wiki_ds, nxsMgr, mWiki, mGxsIdService, mGxsCircles);
|
||||
|
||||
|
||||
/**** Wire GXS service ****/
|
||||
|
||||
|
||||
RsGeneralDataService* wire_ds = new RsDataService(currGxsDir + "/", "wire_db",
|
||||
RS_SERVICE_GXSV1_TYPE_WIRE);
|
||||
RS_SERVICE_GXSV2_TYPE_WIRE, NULL, RsInitConfig::passwd);
|
||||
|
||||
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
|
||||
wire_ds->resetDataStore(); //TODO: remove, new service data per RS session, for testing
|
||||
@ -2393,13 +2400,13 @@ int RsServer::StartupRetroShare()
|
||||
|
||||
// create GXS photo service
|
||||
RsGxsNetService* wire_ns = new RsGxsNetService(
|
||||
RS_SERVICE_GXSV1_TYPE_WIRE, wire_ds, nxsMgr, mWire);
|
||||
RS_SERVICE_GXSV2_TYPE_WIRE, wire_ds, nxsMgr, mWire, mGxsIdService, mGxsCircles);
|
||||
|
||||
|
||||
/**** Forum GXS service ****/
|
||||
|
||||
RsGeneralDataService* gxsforums_ds = new RsDataService(currGxsDir + "/", "gxsforums_db",
|
||||
RS_SERVICE_GXSV1_TYPE_FORUMS);
|
||||
RS_SERVICE_GXSV2_TYPE_FORUMS, NULL, RsInitConfig::passwd);
|
||||
|
||||
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
|
||||
gxsforums_ds->resetDataStore(); //TODO: remove, new service data per RS session, for testing
|
||||
@ -2409,13 +2416,14 @@ int RsServer::StartupRetroShare()
|
||||
|
||||
// create GXS photo service
|
||||
RsGxsNetService* gxsforums_ns = new RsGxsNetService(
|
||||
RS_SERVICE_GXSV1_TYPE_FORUMS, gxsforums_ds, nxsMgr, mGxsForums);
|
||||
RS_SERVICE_GXSV2_TYPE_FORUMS, gxsforums_ds, nxsMgr,
|
||||
mGxsForums, mGxsIdService, mGxsCircles);
|
||||
|
||||
|
||||
/**** Channel GXS service ****/
|
||||
|
||||
RsGeneralDataService* gxschannels_ds = new RsDataService(currGxsDir + "/", "gxschannels_db",
|
||||
RS_SERVICE_GXSV1_TYPE_CHANNELS);
|
||||
RS_SERVICE_GXSV2_TYPE_CHANNELS, NULL, RsInitConfig::passwd);
|
||||
|
||||
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
|
||||
gxschannels_ds->resetDataStore(); //TODO: remove, new service data per RS session, for testing
|
||||
@ -2425,12 +2433,13 @@ int RsServer::StartupRetroShare()
|
||||
|
||||
// create GXS photo service
|
||||
RsGxsNetService* gxschannels_ns = new RsGxsNetService(
|
||||
RS_SERVICE_GXSV1_TYPE_CHANNELS, gxschannels_ds, nxsMgr, mGxsChannels);
|
||||
RS_SERVICE_GXSV2_TYPE_CHANNELS, gxschannels_ds, nxsMgr,
|
||||
mGxsChannels, mGxsIdService, mGxsCircles);
|
||||
|
||||
// now add to p3service
|
||||
pqih->addService(gxsid_ns);
|
||||
//pqih->addService(gxscircles_ns);
|
||||
//pqih->addService(photo_ns);
|
||||
pqih->addService(gxscircles_ns);
|
||||
pqih->addService(photo_ns);
|
||||
pqih->addService(posted_ns);
|
||||
pqih->addService(wiki_ns);
|
||||
pqih->addService(gxsforums_ns);
|
||||
@ -2670,7 +2679,7 @@ int RsServer::StartupRetroShare()
|
||||
/*** start up GXS core runner ***/
|
||||
createThread(*mGxsIdService);
|
||||
createThread(*mGxsCircles);
|
||||
//createThread(*mPhoto);
|
||||
createThread(*mPhoto);
|
||||
createThread(*mPosted);
|
||||
createThread(*mWiki);
|
||||
createThread(*mWire);
|
||||
|
@ -89,7 +89,7 @@ RsItem* RsGxsChannelSerialiser::deserialise(void* data, uint32_t* size)
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_CHANNELS != getRsItemService(rstype)))
|
||||
(RS_SERVICE_GXSV2_TYPE_CHANNELS != getRsItemService(rstype)))
|
||||
{
|
||||
#ifdef GXSCHANNEL_DEBUG
|
||||
std::cerr << "RsGxsChannelSerialiser::deserialise() ERROR Wrong Type" << std::endl;
|
||||
@ -255,7 +255,7 @@ RsGxsChannelGroupItem* RsGxsChannelSerialiser::deserialiseGxsChannelGroupItem(vo
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_CHANNELS != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_CHANNELS != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSCHANNEL_GROUP_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSCHANNEL_DEBUG
|
||||
@ -478,7 +478,7 @@ RsGxsChannelPostItem* RsGxsChannelSerialiser::deserialiseGxsChannelPostItem(void
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_CHANNELS != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_CHANNELS != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSCHANNEL_POST_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSCHANNEL_DEBUG
|
||||
|
@ -47,7 +47,7 @@ class RsGxsChannelGroupItem : public RsGxsGrpItem
|
||||
|
||||
public:
|
||||
|
||||
RsGxsChannelGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_CHANNELS,
|
||||
RsGxsChannelGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV2_TYPE_CHANNELS,
|
||||
RS_PKT_SUBTYPE_GXSCHANNEL_GROUP_ITEM) { return;}
|
||||
virtual ~RsGxsChannelGroupItem() { return;}
|
||||
|
||||
@ -66,7 +66,7 @@ class RsGxsChannelPostItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsChannelPostItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_CHANNELS,
|
||||
RsGxsChannelPostItem(): RsGxsMsgItem(RS_SERVICE_GXSV2_TYPE_CHANNELS,
|
||||
RS_PKT_SUBTYPE_GXSCHANNEL_POST_ITEM) {return; }
|
||||
virtual ~RsGxsChannelPostItem() { return;}
|
||||
void clear();
|
||||
@ -88,7 +88,7 @@ class RsGxsChannelSerialiser : public RsGxsCommentSerialiser
|
||||
public:
|
||||
|
||||
RsGxsChannelSerialiser()
|
||||
:RsGxsCommentSerialiser(RS_SERVICE_GXSV1_TYPE_CHANNELS)
|
||||
:RsGxsCommentSerialiser(RS_SERVICE_GXSV2_TYPE_CHANNELS)
|
||||
{ return; }
|
||||
virtual ~RsGxsChannelSerialiser() { return; }
|
||||
|
||||
|
@ -74,7 +74,7 @@ RsItem* RsGxsCircleSerialiser::deserialise(void* data, uint32_t* size)
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_GXSCIRCLE != getRsItemService(rstype)))
|
||||
(RS_SERVICE_GXSV2_TYPE_GXSCIRCLE != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
@ -107,6 +107,7 @@ RsItem* RsGxsCircleSerialiser::deserialise(void* data, uint32_t* size)
|
||||
|
||||
void RsGxsCircleGroupItem::clear()
|
||||
{
|
||||
pgpIdSet.TlvClear();
|
||||
gxsIdSet.TlvClear();
|
||||
subCircleSet.TlvClear();
|
||||
}
|
||||
@ -116,7 +117,16 @@ bool RsGxsCircleGroupItem::convertFrom(const RsGxsCircleGroup &group)
|
||||
clear();
|
||||
|
||||
meta = group.mMeta;
|
||||
gxsIdSet.ids = group.mInvitedMembers;
|
||||
|
||||
// Enforce the local rules.
|
||||
if (meta.mCircleType == GXS_CIRCLE_TYPE_LOCAL)
|
||||
{
|
||||
pgpIdSet.ids = group.mLocalFriends;
|
||||
}
|
||||
else
|
||||
{
|
||||
gxsIdSet.ids = group.mInvitedMembers;
|
||||
}
|
||||
subCircleSet.ids = group.mSubCircles;
|
||||
return true;
|
||||
}
|
||||
@ -124,7 +134,18 @@ bool RsGxsCircleGroupItem::convertFrom(const RsGxsCircleGroup &group)
|
||||
bool RsGxsCircleGroupItem::convertTo(RsGxsCircleGroup &group) const
|
||||
{
|
||||
group.mMeta = meta;
|
||||
group.mInvitedMembers = gxsIdSet.ids;
|
||||
|
||||
// Enforce the local rules.
|
||||
if (meta.mCircleType == GXS_CIRCLE_TYPE_LOCAL)
|
||||
{
|
||||
group.mLocalFriends = pgpIdSet.ids;
|
||||
group.mInvitedMembers.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
group.mLocalFriends.clear();
|
||||
group.mInvitedMembers = gxsIdSet.ids;
|
||||
}
|
||||
group.mSubCircles = subCircleSet.ids;
|
||||
return true;
|
||||
}
|
||||
@ -135,9 +156,22 @@ std::ostream& RsGxsCircleGroupItem::print(std::ostream& out, uint16_t indent)
|
||||
printRsItemBase(out, "RsGxsCircleGroupItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
gxsIdSet.print(out, int_Indent);
|
||||
if (meta.mCircleType == GXS_CIRCLE_TYPE_LOCAL)
|
||||
{
|
||||
printRsItemBase(out, "Local Circle: PGP Ids:", indent);
|
||||
pgpIdSet.print(out, int_Indent);
|
||||
printRsItemBase(out, "GXS Ids (should be empty):", indent);
|
||||
gxsIdSet.print(out, int_Indent);
|
||||
}
|
||||
else
|
||||
{
|
||||
printRsItemBase(out, "External Circle: GXS Ids", indent);
|
||||
gxsIdSet.print(out, int_Indent);
|
||||
printRsItemBase(out, "PGP Ids (should be empty):", indent);
|
||||
pgpIdSet.print(out, int_Indent);
|
||||
}
|
||||
|
||||
subCircleSet.print(out, int_Indent);
|
||||
|
||||
printRsItemEnd(out ,"RsGxsCircleGroupItem", indent);
|
||||
return out;
|
||||
}
|
||||
@ -147,6 +181,7 @@ uint32_t RsGxsCircleSerialiser::sizeGxsCircleGroupItem(RsGxsCircleGroupItem *ite
|
||||
{
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += item->pgpIdSet.TlvSize();
|
||||
s += item->gxsIdSet.TlvSize();
|
||||
s += item->subCircleSet.TlvSize();
|
||||
|
||||
@ -181,6 +216,7 @@ bool RsGxsCircleSerialiser::serialiseGxsCircleGroupItem(RsGxsCircleGroupItem *it
|
||||
offset += 8;
|
||||
|
||||
/* GxsCircleGroupItem */
|
||||
ok &= item->pgpIdSet.SetTlv(data, tlvsize, &offset);
|
||||
ok &= item->gxsIdSet.SetTlv(data, tlvsize, &offset);
|
||||
ok &= item->subCircleSet.SetTlv(data, tlvsize, &offset);
|
||||
|
||||
@ -216,7 +252,7 @@ RsGxsCircleGroupItem* RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem(void
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_GXSCIRCLE != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_GXSCIRCLE != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
@ -242,6 +278,7 @@ RsGxsCircleGroupItem* RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem(void
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= item->pgpIdSet.GetTlv(data, rssize, &offset);
|
||||
ok &= item->gxsIdSet.GetTlv(data, rssize, &offset);
|
||||
ok &= item->subCircleSet.GetTlv(data, rssize, &offset);
|
||||
|
||||
@ -365,7 +402,7 @@ RsGxsCircleMsgItem* RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem(void *dat
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_GXSCIRCLE != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_GXSCIRCLE != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
|
@ -38,16 +38,18 @@
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM = 0x03;
|
||||
|
||||
const uint16_t GXSCIRCLE_GXSIDSET = 0x0001;
|
||||
const uint16_t GXSCIRCLE_SUBCIRCLESET = 0x0002;
|
||||
const uint16_t GXSCIRCLE_PGPIDSET = 0x0001;
|
||||
const uint16_t GXSCIRCLE_GXSIDSET = 0x0002;
|
||||
const uint16_t GXSCIRCLE_SUBCIRCLESET = 0x0003;
|
||||
|
||||
class RsGxsCircleGroupItem : public RsGxsGrpItem
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
RsGxsCircleGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_GXSCIRCLE,
|
||||
RsGxsCircleGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV2_TYPE_GXSCIRCLE,
|
||||
RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM),
|
||||
pgpIdSet(GXSCIRCLE_PGPIDSET),
|
||||
gxsIdSet(GXSCIRCLE_GXSIDSET),
|
||||
subCircleSet(GXSCIRCLE_SUBCIRCLESET) { return;}
|
||||
virtual ~RsGxsCircleGroupItem() { return;}
|
||||
@ -59,7 +61,8 @@ public:
|
||||
bool convertTo(RsGxsCircleGroup &group) const;
|
||||
|
||||
// DIFFERENT FROM OTHER ONES, as stupid serialisation otherwise.
|
||||
RsTlvStringSet gxsIdSet;
|
||||
RsTlvStringSet pgpIdSet; // For Local Groups.
|
||||
RsTlvStringSet gxsIdSet; // For External Groups.
|
||||
RsTlvStringSet subCircleSet;
|
||||
};
|
||||
|
||||
@ -67,7 +70,7 @@ class RsGxsCircleMsgItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsCircleMsgItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_GXSCIRCLE,
|
||||
RsGxsCircleMsgItem(): RsGxsMsgItem(RS_SERVICE_GXSV2_TYPE_GXSCIRCLE,
|
||||
RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM) {return; }
|
||||
virtual ~RsGxsCircleMsgItem() { return;}
|
||||
void clear();
|
||||
@ -80,7 +83,7 @@ class RsGxsCircleSerialiser : public RsSerialType
|
||||
public:
|
||||
|
||||
RsGxsCircleSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_GXSCIRCLE)
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV2_TYPE_GXSCIRCLE)
|
||||
{ return; }
|
||||
virtual ~RsGxsCircleSerialiser() { return; }
|
||||
|
||||
|
@ -76,7 +76,7 @@ RsItem* RsGxsForumSerialiser::deserialise(void* data, uint32_t* size)
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_FORUMS != getRsItemService(rstype)))
|
||||
(RS_SERVICE_GXSV2_TYPE_FORUMS != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
@ -198,7 +198,7 @@ RsGxsForumGroupItem* RsGxsForumSerialiser::deserialiseGxsForumGroupItem(void *da
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_FORUMS != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_FORUMS != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSFORUM_DEBUG
|
||||
@ -346,7 +346,7 @@ RsGxsForumMsgItem* RsGxsForumSerialiser::deserialiseGxsForumMsgItem(void *data,
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_FORUMS != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_FORUMS != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSFORUM_MESSAGE_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSFORUM_DEBUG
|
||||
|
@ -43,7 +43,7 @@ class RsGxsForumGroupItem : public RsGxsGrpItem
|
||||
|
||||
public:
|
||||
|
||||
RsGxsForumGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_FORUMS,
|
||||
RsGxsForumGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV2_TYPE_FORUMS,
|
||||
RS_PKT_SUBTYPE_GXSFORUM_GROUP_ITEM) { return;}
|
||||
virtual ~RsGxsForumGroupItem() { return;}
|
||||
|
||||
@ -58,7 +58,7 @@ class RsGxsForumMsgItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsForumMsgItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_FORUMS,
|
||||
RsGxsForumMsgItem(): RsGxsMsgItem(RS_SERVICE_GXSV2_TYPE_FORUMS,
|
||||
RS_PKT_SUBTYPE_GXSFORUM_MESSAGE_ITEM) {return; }
|
||||
virtual ~RsGxsForumMsgItem() { return;}
|
||||
void clear();
|
||||
@ -72,7 +72,7 @@ class RsGxsForumSerialiser : public RsSerialType
|
||||
public:
|
||||
|
||||
RsGxsForumSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_FORUMS)
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV2_TYPE_FORUMS)
|
||||
{ return; }
|
||||
virtual ~RsGxsForumSerialiser() { return; }
|
||||
|
||||
|
@ -83,7 +83,7 @@ RsItem* RsGxsIdSerialiser::deserialise(void* data, uint32_t* size)
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_GXSID != getRsItemService(rstype)))
|
||||
(RS_SERVICE_GXSV2_TYPE_GXSID != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
@ -210,7 +210,7 @@ RsGxsIdGroupItem* RsGxsIdSerialiser::deserialiseGxsIdGroupItem(void *data, uint3
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_GXSID != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_GXSID != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSID_GROUP_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
@ -271,9 +271,8 @@ RsGxsIdGroupItem* RsGxsIdSerialiser::deserialiseGxsIdGroupItem(void *data, uint3
|
||||
void RsGxsIdOpinionItem::clear()
|
||||
{
|
||||
opinion.mOpinion = 0;
|
||||
|
||||
// Others that aren't serialised. - but should be cleared anyway
|
||||
opinion.mReputation = 0;
|
||||
opinion.mComment = "";
|
||||
}
|
||||
|
||||
std::ostream& RsGxsIdOpinionItem::print(std::ostream& out, uint16_t indent)
|
||||
@ -283,6 +282,10 @@ std::ostream& RsGxsIdOpinionItem::print(std::ostream& out, uint16_t indent)
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Opinion: " << opinion.mOpinion << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "Reputation: " << opinion.mReputation << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "Comment: " << opinion.mComment << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsGxsIdOpinionItem", indent);
|
||||
return out;
|
||||
@ -296,6 +299,8 @@ uint32_t RsGxsIdSerialiser::sizeGxsIdOpinionItem(RsGxsIdOpinionItem *item)
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += 4; // mOpinion.
|
||||
s += 4; // mReputation.
|
||||
s += GetTlvStringSize(opinion.mComment);
|
||||
|
||||
return s;
|
||||
}
|
||||
@ -326,6 +331,8 @@ bool RsGxsIdSerialiser::serialiseGxsIdOpinionItem(RsGxsIdOpinionItem *item, void
|
||||
|
||||
/* GxsIdOpinionItem */
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->opinion.mOpinion);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->opinion.mReputation);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->opinion.mComment);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
@ -356,7 +363,7 @@ RsGxsIdOpinionItem* RsGxsIdSerialiser::deserialiseGxsIdOpinionItem(void *data, u
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_GXSID != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_GXSID != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSID_OPINION_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
@ -383,6 +390,8 @@ RsGxsIdOpinionItem* RsGxsIdSerialiser::deserialiseGxsIdOpinionItem(void *data, u
|
||||
offset += 8;
|
||||
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->opinion.mOpinion));
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->opinion.mReputation));
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->opinion.mComment);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
@ -496,7 +505,7 @@ RsGxsIdCommentItem* RsGxsIdSerialiser::deserialiseGxsIdCommentItem(void *data, u
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_GXSID != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_GXSID != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
|
@ -44,7 +44,7 @@ class RsGxsIdGroupItem : public RsGxsGrpItem
|
||||
|
||||
public:
|
||||
|
||||
RsGxsIdGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_GXSID,
|
||||
RsGxsIdGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV2_TYPE_GXSID,
|
||||
RS_PKT_SUBTYPE_GXSID_GROUP_ITEM) { return;}
|
||||
virtual ~RsGxsIdGroupItem() { return;}
|
||||
|
||||
@ -59,7 +59,7 @@ class RsGxsIdOpinionItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsIdOpinionItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_GXSID,
|
||||
RsGxsIdOpinionItem(): RsGxsMsgItem(RS_SERVICE_GXSV2_TYPE_GXSID,
|
||||
RS_PKT_SUBTYPE_GXSID_OPINION_ITEM) {return; }
|
||||
virtual ~RsGxsIdOpinionItem() { return;}
|
||||
void clear();
|
||||
@ -71,7 +71,7 @@ class RsGxsIdCommentItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsIdCommentItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_GXSID,
|
||||
RsGxsIdCommentItem(): RsGxsMsgItem(RS_SERVICE_GXSV2_TYPE_GXSID,
|
||||
RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM) { return; }
|
||||
virtual ~RsGxsIdCommentItem() { return; }
|
||||
void clear();
|
||||
@ -85,7 +85,7 @@ class RsGxsIdSerialiser : public RsSerialType
|
||||
public:
|
||||
|
||||
RsGxsIdSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_GXSID)
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV2_TYPE_GXSID)
|
||||
{ return; }
|
||||
virtual ~RsGxsIdSerialiser() { return; }
|
||||
|
||||
|
@ -46,6 +46,7 @@
|
||||
this->mCircleType = rGxsMeta.mCircleType;
|
||||
this->mInternalCircle = rGxsMeta.mInternalCircle;
|
||||
this->mOriginator = rGxsMeta.mOriginator;
|
||||
this->mAuthenFlags = rGxsMeta.mAuthenFlags;
|
||||
}
|
||||
|
||||
|
||||
|
@ -205,6 +205,7 @@ bool RsNxsSerialiser::serialiseNxsSynMsgItem(RsNxsSyncMsgItem *item, void *data,
|
||||
ok &= setRawUInt8(data, *size, &offset, item->flag);
|
||||
ok &= SetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
|
||||
ok &= SetTlvString(data, *size, &offset, TLV_TYPE_STR_MSGID, item->msgId);
|
||||
ok &= SetTlvString(data, *size, &offset, TLV_TYPE_STR_NAME, item->authorId);
|
||||
|
||||
if(offset != tlvsize){
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
@ -454,6 +455,7 @@ bool RsNxsSerialiser::serialiseNxsSyncGrpItem(RsNxsSyncGrpItem *item, void *data
|
||||
ok &= setRawUInt8(data, *size, &offset, item->flag);
|
||||
ok &= SetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
|
||||
ok &= setRawUInt32(data, *size, &offset, item->publishTs);
|
||||
ok &= SetTlvString(data, *size, &offset, TLV_TYPE_STR_NAME, item->authorId);
|
||||
|
||||
if(offset != tlvsize){
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
@ -777,6 +779,7 @@ RsNxsSyncGrpItem* RsNxsSerialiser::deserialNxsSyncGrpItem(void *data, uint32_t *
|
||||
ok &= getRawUInt8(data, *size, &offset, &(item->flag));
|
||||
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
|
||||
ok &= getRawUInt32(data, *size, &offset, &(item->publishTs));
|
||||
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_NAME, item->authorId);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
@ -912,6 +915,7 @@ RsNxsSyncMsgItem* RsNxsSerialiser::deserialNxsSyncMsgItem(void *data, uint32_t *
|
||||
ok &= getRawUInt8(data, *size, &offset, &(item->flag));
|
||||
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
|
||||
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_MSGID, item->msgId);
|
||||
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_NAME, item->authorId);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
@ -1066,6 +1070,7 @@ uint32_t RsNxsSerialiser::sizeNxsSyncGrpItem(RsNxsSyncGrpItem *item)
|
||||
s += 4; // publishTs
|
||||
s += 1; // flag
|
||||
s += GetTlvStringSize(item->grpId);
|
||||
s += GetTlvStringSize(item->authorId);
|
||||
|
||||
return s;
|
||||
}
|
||||
@ -1094,6 +1099,7 @@ uint32_t RsNxsSerialiser::sizeNxsSyncMsgItem(RsNxsSyncMsgItem *item)
|
||||
s += 1; // flag
|
||||
s += GetTlvStringSize(item->grpId);
|
||||
s += GetTlvStringSize(item->msgId);
|
||||
s += GetTlvStringSize(item->authorId);
|
||||
|
||||
return s;
|
||||
}
|
||||
@ -1152,6 +1158,7 @@ void RsNxsSyncGrpItem::clear()
|
||||
flag = 0;
|
||||
publishTs = 0;
|
||||
grpId.clear();
|
||||
authorId.clear();
|
||||
}
|
||||
|
||||
void RsNxsSyncMsgItem::clear()
|
||||
@ -1159,6 +1166,7 @@ void RsNxsSyncMsgItem::clear()
|
||||
flag = 0;
|
||||
msgId.clear();
|
||||
grpId.clear();
|
||||
authorId.clear();
|
||||
}
|
||||
|
||||
void RsNxsTransac::clear(){
|
||||
@ -1230,6 +1238,8 @@ std::ostream& RsNxsSyncGrpItem::print(std::ostream &out, uint16_t indent)
|
||||
out << "grpId: " << grpId << std::endl;
|
||||
printIndent(out , int_Indent);
|
||||
out << "publishTs: " << publishTs << std::endl;
|
||||
printIndent(out , int_Indent);
|
||||
out << "authorId: " << authorId << std::endl;
|
||||
|
||||
printRsItemEnd(out , "RsNxsSyncGrpItem", indent);
|
||||
return out;
|
||||
@ -1249,6 +1259,8 @@ std::ostream& RsNxsSyncMsgItem::print(std::ostream &out, uint16_t indent)
|
||||
printIndent(out , int_Indent);
|
||||
out << "msgId: " << msgId << std::endl;
|
||||
printIndent(out , int_Indent);
|
||||
out << "authorId: " << authorId << std::endl;
|
||||
printIndent(out , int_Indent);
|
||||
|
||||
printRsItemEnd(out ,"RsNxsSyncMsgItem", indent);
|
||||
return out;
|
||||
|
@ -175,6 +175,7 @@ public:
|
||||
|
||||
/// grpId of grp held by sending peer
|
||||
std::string grpId;
|
||||
std::string authorId;
|
||||
|
||||
};
|
||||
|
||||
@ -257,6 +258,7 @@ public:
|
||||
uint8_t flag; // response/req
|
||||
std::string grpId;
|
||||
std::string msgId;
|
||||
std::string authorId;
|
||||
|
||||
};
|
||||
|
||||
|
@ -98,7 +98,7 @@ RsItem* RsGxsPhotoSerialiser::deserialise(void* data, uint32_t* size)
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_PHOTO != getRsItemService(rstype)))
|
||||
(RS_SERVICE_GXSV2_TYPE_PHOTO != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
@ -200,7 +200,7 @@ bool RsGxsPhotoSerialiser::serialiseGxsPhotoAlbumItem(RsGxsPhotoAlbumItem* item,
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mWhen);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mWhere);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->album.mThumbnail.type);
|
||||
RsTlvBinaryData b(RS_SERVICE_GXSV1_TYPE_PHOTO); // TODO, need something more persisitent
|
||||
RsTlvBinaryData b(RS_SERVICE_GXSV2_TYPE_PHOTO); // TODO, need something more persisitent
|
||||
b.setBinData(item->album.mThumbnail.data, item->album.mThumbnail.size);
|
||||
ok &= b.SetTlv(data, tlvsize, &offset);
|
||||
|
||||
@ -238,7 +238,7 @@ RsGxsPhotoAlbumItem* RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem(void* da
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_PHOTO != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_PHOTO != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_PHOTO_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
@ -276,7 +276,7 @@ RsGxsPhotoAlbumItem* RsGxsPhotoSerialiser::deserialiseGxsPhotoAlbumItem(void* da
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mWhere);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->album.mThumbnail.type);
|
||||
|
||||
RsTlvBinaryData b(RS_SERVICE_GXSV1_TYPE_PHOTO); // TODO, need something more persisitent
|
||||
RsTlvBinaryData b(RS_SERVICE_GXSV2_TYPE_PHOTO); // TODO, need something more persisitent
|
||||
ok &= b.GetTlv(data, rssize, &offset);
|
||||
item->album.mThumbnail.data = (uint8_t*)b.bin_data;
|
||||
item->album.mThumbnail.size = b.bin_len;
|
||||
@ -366,7 +366,7 @@ bool RsGxsPhotoSerialiser::serialiseGxsPhotoPhotoItem(RsGxsPhotoPhotoItem* item,
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mWhen);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mWhere);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->photo.mThumbnail.type);
|
||||
RsTlvBinaryData b(RS_SERVICE_GXSV1_TYPE_PHOTO); // TODO, need something more persisitent
|
||||
RsTlvBinaryData b(RS_SERVICE_GXSV2_TYPE_PHOTO); // TODO, need something more persisitent
|
||||
b.setBinData(item->photo.mThumbnail.data, item->photo.mThumbnail.size);
|
||||
ok &= b.SetTlv(data, tlvsize, &offset);
|
||||
|
||||
@ -404,7 +404,7 @@ RsGxsPhotoPhotoItem* RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem(void* da
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_PHOTO != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_PHOTO != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
@ -440,7 +440,7 @@ RsGxsPhotoPhotoItem* RsGxsPhotoSerialiser::deserialiseGxsPhotoPhotoItem(void* da
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mWhere);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->photo.mThumbnail.type);
|
||||
|
||||
RsTlvBinaryData b(RS_SERVICE_GXSV1_TYPE_PHOTO); // TODO, need something more persisitent
|
||||
RsTlvBinaryData b(RS_SERVICE_GXSV2_TYPE_PHOTO); // TODO, need something more persisitent
|
||||
ok &= b.GetTlv(data, rssize, &offset);
|
||||
item->photo.mThumbnail.data = (uint8_t*)(b.bin_data);
|
||||
item->photo.mThumbnail.size = b.bin_len;
|
||||
@ -535,7 +535,7 @@ RsGxsPhotoCommentItem * RsGxsPhotoSerialiser::deserialiseGxsPhotoCommentItem(
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_PHOTO != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_PHOTO != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXS_PHOTO_SERIAL_DEBUG
|
||||
|
@ -44,7 +44,7 @@ class RsGxsPhotoAlbumItem : public RsGxsGrpItem
|
||||
|
||||
public:
|
||||
|
||||
RsGxsPhotoAlbumItem(): RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_PHOTO,
|
||||
RsGxsPhotoAlbumItem(): RsGxsGrpItem(RS_SERVICE_GXSV2_TYPE_PHOTO,
|
||||
RS_PKT_SUBTYPE_PHOTO_ITEM) { return;}
|
||||
virtual ~RsGxsPhotoAlbumItem() { return;}
|
||||
|
||||
@ -59,7 +59,7 @@ class RsGxsPhotoPhotoItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsPhotoPhotoItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_PHOTO,
|
||||
RsGxsPhotoPhotoItem(): RsGxsMsgItem(RS_SERVICE_GXSV2_TYPE_PHOTO,
|
||||
RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM) {return; }
|
||||
virtual ~RsGxsPhotoPhotoItem() { return;}
|
||||
void clear();
|
||||
@ -71,7 +71,7 @@ class RsGxsPhotoCommentItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsPhotoCommentItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_PHOTO,
|
||||
RsGxsPhotoCommentItem(): RsGxsMsgItem(RS_SERVICE_GXSV2_TYPE_PHOTO,
|
||||
RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM) { return; }
|
||||
virtual ~RsGxsPhotoCommentItem() { return; }
|
||||
void clear();
|
||||
@ -86,7 +86,7 @@ class RsGxsPhotoSerialiser : public RsSerialType
|
||||
public:
|
||||
|
||||
RsGxsPhotoSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_PHOTO)
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV2_TYPE_PHOTO)
|
||||
{ return; }
|
||||
virtual ~RsGxsPhotoSerialiser() { return; }
|
||||
|
||||
|
@ -87,7 +87,7 @@ RsItem* RsGxsPostedSerialiser::deserialise(void *data, uint32_t *size)
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)))
|
||||
(RS_SERVICE_GXSV2_TYPE_POSTED != getRsItemService(rstype)))
|
||||
{
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialise() ERROR Wrong Type";
|
||||
std::cerr << std::endl;
|
||||
@ -207,7 +207,7 @@ RsGxsPostedPostItem* RsGxsPostedSerialiser::deserialiseGxsPostedPostItem(void *d
|
||||
uint32_t offset = 0;
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_POSTED != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_POSTED_POST_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() FAIL wrong type" << std::endl;
|
||||
@ -347,7 +347,7 @@ RsGxsPostedGroupItem* RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem(void
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_POSTED != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_POSTED_GRP_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() FAIL wrong type" << std::endl;
|
||||
|
@ -16,7 +16,7 @@ const uint8_t RS_PKT_SUBTYPE_POSTED_POST_ITEM = 0x03;
|
||||
class RsGxsPostedGroupItem : public RsGxsGrpItem
|
||||
{
|
||||
public:
|
||||
RsGxsPostedGroupItem() : RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_POSTED,
|
||||
RsGxsPostedGroupItem() : RsGxsGrpItem(RS_SERVICE_GXSV2_TYPE_POSTED,
|
||||
RS_PKT_SUBTYPE_POSTED_GRP_ITEM) { return; }
|
||||
virtual ~RsGxsPostedGroupItem() { return; }
|
||||
|
||||
@ -29,7 +29,7 @@ public:
|
||||
class RsGxsPostedPostItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
RsGxsPostedPostItem() : RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_POSTED,
|
||||
RsGxsPostedPostItem() : RsGxsMsgItem(RS_SERVICE_GXSV2_TYPE_POSTED,
|
||||
RS_PKT_SUBTYPE_POSTED_POST_ITEM) {return ; }
|
||||
virtual ~RsGxsPostedPostItem() { return; }
|
||||
|
||||
@ -45,7 +45,7 @@ class RsGxsPostedSerialiser : public RsGxsCommentSerialiser
|
||||
public:
|
||||
|
||||
RsGxsPostedSerialiser()
|
||||
:RsGxsCommentSerialiser(RS_SERVICE_GXSV1_TYPE_POSTED)
|
||||
:RsGxsCommentSerialiser(RS_SERVICE_GXSV2_TYPE_POSTED)
|
||||
{ return; }
|
||||
|
||||
virtual ~RsGxsPostedSerialiser() { return; }
|
||||
|
@ -131,15 +131,6 @@ const uint16_t RS_SERVICE_TYPE_GAME_POKER = 0xf214;
|
||||
/* Rs Network Exchange Service */
|
||||
const uint16_t RS_SERVICE_TYPE_NXS = 0xf300;
|
||||
|
||||
const uint16_t RS_SERVICE_GXSV1_TYPE_GXSID = 0xf301;
|
||||
const uint16_t RS_SERVICE_GXSV1_TYPE_PHOTO = 0xf302;
|
||||
const uint16_t RS_SERVICE_GXSV1_TYPE_WIKI = 0xf303;
|
||||
const uint16_t RS_SERVICE_GXSV1_TYPE_WIRE = 0xf304;
|
||||
const uint16_t RS_SERVICE_GXSV1_TYPE_FORUMS = 0xf305;
|
||||
const uint16_t RS_SERVICE_GXSV1_TYPE_POSTED = 0xf306;
|
||||
const uint16_t RS_SERVICE_GXSV1_TYPE_CHANNELS = 0xf307;
|
||||
const uint16_t RS_SERVICE_GXSV1_TYPE_GXSCIRCLE = 0xf308;
|
||||
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_GXSID = 0xf311;
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_GXSCIRCLE = 0xf312;
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_PHOTO = 0xf313;
|
||||
@ -149,13 +140,14 @@ const uint16_t RS_SERVICE_GXSV2_TYPE_FORUMS = 0xf316;
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_POSTED = 0xf317;
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_CHANNELS = 0xf318;
|
||||
|
||||
/* Example Versions (VEG) of New Cache Services */
|
||||
const uint16_t RS_SERVICE_VEG_TYPE_IDENTITY = 0xf320;
|
||||
const uint16_t RS_SERVICE_VEG_TYPE_PHOTO = 0xf321;
|
||||
const uint16_t RS_SERVICE_VEG_TYPE_WIKI = 0xf322;
|
||||
const uint16_t RS_SERVICE_VEG_TYPE_WIRE = 0xf323;
|
||||
const uint16_t RS_SERVICE_VEG_TYPE_FORUMS = 0xf324;
|
||||
const uint16_t RS_SERVICE_VEG_TYPE_POSTED = 0xf325;
|
||||
const uint16_t RS_SERVICE_GXSV3_TYPE_GXSID = 0xf321;
|
||||
const uint16_t RS_SERVICE_GXSV3_TYPE_PHOTO = 0xf322;
|
||||
const uint16_t RS_SERVICE_GXSV3_TYPE_WIKI = 0xf323;
|
||||
const uint16_t RS_SERVICE_GXSV3_TYPE_WIRE = 0xf324;
|
||||
const uint16_t RS_SERVICE_GXSV3_TYPE_FORUMS = 0xf325;
|
||||
const uint16_t RS_SERVICE_GXSV3_TYPE_POSTED = 0xf326;
|
||||
const uint16_t RS_SERVICE_GXSV3_TYPE_CHANNELS = 0xf327;
|
||||
const uint16_t RS_SERVICE_GXSV3_TYPE_GXSCIRCLE = 0xf328;
|
||||
|
||||
/***************** IDS ALLOCATED FOR PLUGINS ******************/
|
||||
|
||||
|
@ -84,7 +84,7 @@ RsItem* RsGxsWikiSerialiser::deserialise(void* data, uint32_t* size)
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_WIKI != getRsItemService(rstype)))
|
||||
(RS_SERVICE_GXSV2_TYPE_WIKI != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
@ -219,7 +219,7 @@ RsGxsWikiCollectionItem* RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem(v
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_WIKI != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_WIKI != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
@ -375,7 +375,7 @@ RsGxsWikiSnapshotItem* RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem(void
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_WIKI != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_WIKI != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
@ -523,7 +523,7 @@ RsGxsWikiCommentItem* RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem(void *d
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_WIKI != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_WIKI != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXSID_DEBUG
|
||||
|
@ -44,7 +44,7 @@ class RsGxsWikiCollectionItem : public RsGxsGrpItem
|
||||
|
||||
public:
|
||||
|
||||
RsGxsWikiCollectionItem(): RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_WIKI,
|
||||
RsGxsWikiCollectionItem(): RsGxsGrpItem(RS_SERVICE_GXSV2_TYPE_WIKI,
|
||||
RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM) { return;}
|
||||
virtual ~RsGxsWikiCollectionItem() { return;}
|
||||
|
||||
@ -59,7 +59,7 @@ class RsGxsWikiSnapshotItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsWikiSnapshotItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_WIKI,
|
||||
RsGxsWikiSnapshotItem(): RsGxsMsgItem(RS_SERVICE_GXSV2_TYPE_WIKI,
|
||||
RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM) {return; }
|
||||
virtual ~RsGxsWikiSnapshotItem() { return;}
|
||||
void clear();
|
||||
@ -71,7 +71,7 @@ class RsGxsWikiCommentItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsWikiCommentItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_WIKI,
|
||||
RsGxsWikiCommentItem(): RsGxsMsgItem(RS_SERVICE_GXSV2_TYPE_WIKI,
|
||||
RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM) { return; }
|
||||
virtual ~RsGxsWikiCommentItem() { return; }
|
||||
void clear();
|
||||
@ -85,7 +85,7 @@ class RsGxsWikiSerialiser : public RsSerialType
|
||||
public:
|
||||
|
||||
RsGxsWikiSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_WIKI)
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV2_TYPE_WIKI)
|
||||
{ return; }
|
||||
virtual ~RsGxsWikiSerialiser() { return; }
|
||||
|
||||
|
@ -74,7 +74,7 @@ RsItem* RsGxsWireSerialiser::deserialise(void* data, uint32_t* size)
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_WIRE != getRsItemService(rstype)))
|
||||
(RS_SERVICE_GXSV2_TYPE_WIRE != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
@ -196,7 +196,7 @@ RsGxsWireGroupItem* RsGxsWireSerialiser::deserialiseGxsWireGroupItem(void *data,
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_WIRE != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_WIRE != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_WIRE_GROUP_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
@ -350,7 +350,7 @@ RsGxsWirePulseItem* RsGxsWireSerialiser::deserialiseGxsWirePulseItem(void *data,
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_WIRE != getRsItemService(rstype)) ||
|
||||
(RS_SERVICE_GXSV2_TYPE_WIRE != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_WIRE_PULSE_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef WIRE_DEBUG
|
||||
|
@ -43,7 +43,7 @@ class RsGxsWireGroupItem : public RsGxsGrpItem
|
||||
|
||||
public:
|
||||
|
||||
RsGxsWireGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_WIRE,
|
||||
RsGxsWireGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV2_TYPE_WIRE,
|
||||
RS_PKT_SUBTYPE_WIRE_GROUP_ITEM) { return;}
|
||||
virtual ~RsGxsWireGroupItem() { return;}
|
||||
|
||||
@ -58,7 +58,7 @@ class RsGxsWirePulseItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsWirePulseItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_WIRE,
|
||||
RsGxsWirePulseItem(): RsGxsMsgItem(RS_SERVICE_GXSV2_TYPE_WIRE,
|
||||
RS_PKT_SUBTYPE_WIRE_PULSE_ITEM) {return; }
|
||||
virtual ~RsGxsWirePulseItem() { return;}
|
||||
void clear();
|
||||
@ -71,7 +71,7 @@ class RsGxsWireSerialiser : public RsSerialType
|
||||
public:
|
||||
|
||||
RsGxsWireSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_WIRE)
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV2_TYPE_WIRE)
|
||||
{ return; }
|
||||
virtual ~RsGxsWireSerialiser() { return; }
|
||||
|
||||
|
@ -65,11 +65,11 @@ 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), GxsTokenQueue(this)
|
||||
: RsGenExchange(gds, nes, new RsGxsChannelSerialiser(), RS_SERVICE_GXSV2_TYPE_CHANNELS, gixs, channelsAuthenPolicy()), RsGxsChannels(this), GxsTokenQueue(this)
|
||||
{
|
||||
// For Dummy Msgs.
|
||||
mGenActive = false;
|
||||
mCommentService = new p3GxsCommentService(this, RS_SERVICE_GXSV1_TYPE_CHANNELS);
|
||||
mCommentService = new p3GxsCommentService(this, RS_SERVICE_GXSV2_TYPE_CHANNELS);
|
||||
|
||||
RsTickEvent::schedule_in(CHANNEL_PROCESS, 0);
|
||||
|
||||
@ -473,6 +473,10 @@ void p3GxsChannels::request_SpecificUnprocessedPosts(std::list<std::pair<RsGxsGr
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
|
||||
|
||||
// Only Fetch UNPROCESSED messages.
|
||||
opts.mStatusFilter = GXS_SERV::GXS_MSG_STATUS_UNPROCESSED;
|
||||
opts.mStatusMask = GXS_SERV::GXS_MSG_STATUS_UNPROCESSED;
|
||||
|
||||
uint32_t token = 0;
|
||||
|
||||
/* organise Ids how they want them */
|
||||
@ -500,6 +504,9 @@ void p3GxsChannels::request_GroupUnprocessedPosts(const std::list<RsGxsGroupId>
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
|
||||
|
||||
// Only Fetch UNPROCESSED messages.
|
||||
opts.mStatusFilter = GXS_SERV::GXS_MSG_STATUS_UNPROCESSED;
|
||||
opts.mStatusMask = GXS_SERV::GXS_MSG_STATUS_UNPROCESSED;
|
||||
|
||||
uint32_t token = 0;
|
||||
|
||||
@ -561,6 +568,8 @@ void p3GxsChannels::handleUnprocessedPost(const RsGxsChannelPost &msg)
|
||||
{
|
||||
std::cerr << "p3GxsChannels::handleUnprocessedPost() Msg already Processed";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "p3GxsChannels::handleUnprocessedPost() ERROR - this should not happen";
|
||||
std::cerr << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,8 @@
|
||||
* #define DEBUG_CIRCLES 1
|
||||
****/
|
||||
|
||||
#define DEBUG_CIRCLES 1
|
||||
|
||||
RsGxsCircles *rsGxsCircles = NULL;
|
||||
|
||||
/******
|
||||
@ -106,7 +108,7 @@ RsGxsCircles *rsGxsCircles = NULL;
|
||||
|
||||
p3GxsCircles::p3GxsCircles(RsGeneralDataService *gds, RsNetworkExchangeService *nes, p3IdService *identities)
|
||||
: RsGxsCircleExchange(gds, nes, new RsGxsCircleSerialiser(),
|
||||
RS_SERVICE_GXSV1_TYPE_GXSCIRCLE, identities, circleAuthenPolicy()),
|
||||
RS_SERVICE_GXSV2_TYPE_GXSCIRCLE, identities, circleAuthenPolicy()),
|
||||
RsGxsCircles(this), GxsTokenQueue(this), RsTickEvent(), mIdentities(identities),
|
||||
mCircleMtx("p3GxsCircles"),
|
||||
mCircleCache(DEFAULT_MEM_CACHE_SIZE, "GxsCircleCache")
|
||||
@ -163,16 +165,46 @@ void p3GxsCircles::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
||||
std::cerr << "p3GxsCircles::notifyChanges()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
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 << "p3GxsCircles::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 << "p3GxsCircles::notifyChanges() Msgs for Group: " << mit->first;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
/* add groups to ExternalIdList (Might get Personal Circles here until NetChecks in place) */
|
||||
if (groupChange)
|
||||
{
|
||||
std::cerr << "p3GxsCircles::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 << "p3GxsCircles::notifyChanges() Incoming Group: " << *git;
|
||||
std::cerr << std::endl;
|
||||
|
||||
// for new circles we need to add them to the list.
|
||||
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
|
||||
mCircleExternalIdList.push_back(*git);
|
||||
}
|
||||
}
|
||||
}
|
||||
RsGxsIfaceHelper::receiveChanges(changes);
|
||||
|
||||
// for new circles we need to add them to the list.
|
||||
// TODO.
|
||||
#if 0
|
||||
{
|
||||
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
|
||||
mCircleIdList.push_back(grpItem->meta.mGroupId);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@ -180,40 +212,6 @@ void p3GxsCircles::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
||||
/******************* RsCircles Interface ***************************************/
|
||||
/********************************************************************************/
|
||||
|
||||
void p3GxsCircles::createLocalCircle()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void p3GxsCircles::addToLocalCircle()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void p3GxsCircles::removeFromLocalCircle()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void p3GxsCircles::getLocalCirclePeers()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void p3GxsCircles::getListOfLocalCircles()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
bool p3GxsCircles:: getNickname(const RsGxsId &id, std::string &nickname)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
bool p3GxsCircles:: getCircleDetails(const RsGxsCircleId &id, RsGxsCircleDetails &details)
|
||||
{
|
||||
|
||||
@ -231,6 +229,10 @@ bool p3GxsCircles:: getCircleDetails(const RsGxsCircleId &id, RsGxsCircleDetails
|
||||
// should also have meta data....
|
||||
details.mCircleId = id;
|
||||
details.mCircleName = data.mCircleName;
|
||||
|
||||
details.mCircleType = data.mCircleType;
|
||||
details.mIsExternal = data.mIsExternal;
|
||||
|
||||
details.mUnknownPeers = data.mUnknownPeers;
|
||||
details.mAllowedPeers = data.mAllowedPeers;
|
||||
return true;
|
||||
@ -244,7 +246,7 @@ bool p3GxsCircles:: getCircleDetails(const RsGxsCircleId &id, RsGxsCircleDetails
|
||||
}
|
||||
|
||||
|
||||
bool p3GxsCircles:: getCircleIdList(std::list<RsGxsCircleId> &circleIds)
|
||||
bool p3GxsCircles:: getCirclePersonalIdList(std::list<RsGxsCircleId> &circleIds)
|
||||
{
|
||||
#ifdef DEBUG_CIRCLES
|
||||
std::cerr << "p3GxsCircles::getCircleIdList()";
|
||||
@ -252,14 +254,50 @@ bool p3GxsCircles:: getCircleIdList(std::list<RsGxsCircleId> &circleIds)
|
||||
#endif // DEBUG_CIRCLES
|
||||
|
||||
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
|
||||
circleIds = mCircleIdList;
|
||||
if (circleIds.empty())
|
||||
{
|
||||
circleIds = mCirclePersonalIdList;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::list<RsGxsCircleId>::const_iterator it;
|
||||
for(it = mCirclePersonalIdList.begin(); it != mCirclePersonalIdList.begin(); it++)
|
||||
{
|
||||
circleIds.push_back(*it);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool p3GxsCircles:: getCircleExternalIdList(std::list<RsGxsCircleId> &circleIds)
|
||||
{
|
||||
#ifdef DEBUG_CIRCLES
|
||||
std::cerr << "p3GxsCircles::getCircleIdList()";
|
||||
std::cerr << std::endl;
|
||||
#endif // DEBUG_CIRCLES
|
||||
|
||||
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
|
||||
if (circleIds.empty())
|
||||
{
|
||||
circleIds = mCircleExternalIdList;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::list<RsGxsCircleId>::const_iterator it;
|
||||
for(it = mCircleExternalIdList.begin(); it != mCircleExternalIdList.begin(); it++)
|
||||
{
|
||||
circleIds.push_back(*it);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************************/
|
||||
/******************* RsGixs Interface ***************************************/
|
||||
/******************* RsGcxs Interface ***************************************/
|
||||
/********************************************************************************/
|
||||
|
||||
bool p3GxsCircles::isLoaded(const RsGxsCircleId &circleId)
|
||||
@ -273,7 +311,22 @@ bool p3GxsCircles::loadCircle(const RsGxsCircleId &circleId)
|
||||
return cache_request_load(circleId);
|
||||
}
|
||||
|
||||
int p3GxsCircles::canSend(const RsGxsCircleId &circleId, const RsPgpId &id)
|
||||
int p3GxsCircles::canSend(const RsGxsCircleId &circleId, const std::string &id)
|
||||
{
|
||||
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
|
||||
if (mCircleCache.is_cached(circleId))
|
||||
{
|
||||
RsGxsCircleCache &data = mCircleCache.ref(circleId);
|
||||
if (data.isAllowedPeer(id))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int p3GxsCircles::canReceive(const RsGxsCircleId &circleId, const RsPgpId &id)
|
||||
{
|
||||
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
|
||||
if (mCircleCache.is_cached(circleId))
|
||||
@ -361,18 +414,24 @@ RsGenExchange::ServiceCreate_Return p3GxsCircles::service_CreateGroup(RsGxsGrpIt
|
||||
}
|
||||
|
||||
// Now copy the GroupId into the mCircleId, and set the mode.
|
||||
// TODO.
|
||||
#ifdef HAVE_CIRCLE_META_DATA
|
||||
grpItem->meta.mCircleType = EXTERNAL;
|
||||
grpItem->meta.mCircleId = grpItem->meta.mGroupId;
|
||||
if (item->meta.mCircleType == GXS_CIRCLE_TYPE_EXT_SELF)
|
||||
{
|
||||
item->meta.mCircleType = GXS_CIRCLE_TYPE_EXTERNAL;
|
||||
item->meta.mCircleId = item->meta.mGroupId;
|
||||
}
|
||||
|
||||
grpItem->group.mMeta.mCircleType = grpItem->meta.mCircleType;
|
||||
grpItem->group.mMeta.mCircleId = grpItem->meta.mCircleId;
|
||||
#endif
|
||||
|
||||
{
|
||||
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
|
||||
mCircleIdList.push_back(grpItem->meta.mGroupId);
|
||||
|
||||
if (item->meta.mCircleType == GXS_CIRCLE_TYPE_LOCAL)
|
||||
{
|
||||
mCirclePersonalIdList.push_back(item->meta.mGroupId);
|
||||
}
|
||||
else
|
||||
{
|
||||
mCircleExternalIdList.push_back(item->meta.mGroupId);
|
||||
}
|
||||
}
|
||||
|
||||
return SERVICE_CREATE_SUCCESS;
|
||||
@ -390,6 +449,11 @@ RsGenExchange::ServiceCreate_Return p3GxsCircles::service_CreateGroup(RsGxsGrpIt
|
||||
|
||||
RsGxsCircleCache::RsGxsCircleCache()
|
||||
{
|
||||
mCircleType = GXS_CIRCLE_TYPE_EXTERNAL;
|
||||
mIsExternal = true;
|
||||
mUpdateTime = 0;
|
||||
mGroupStatus = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -402,6 +466,10 @@ bool RsGxsCircleCache::loadBaseCircle(const RsGxsCircleGroup &circle)
|
||||
mUpdateTime = time(NULL);
|
||||
mProcessedCircles.insert(mCircleId);
|
||||
|
||||
mCircleType = circle.mMeta.mCircleType;
|
||||
mIsExternal = (mCircleType != GXS_CIRCLE_TYPE_LOCAL);
|
||||
mGroupStatus = circle.mMeta.mGroupStatus;
|
||||
|
||||
#ifdef DEBUG_CIRCLES
|
||||
std::cerr << "RsGxsCircleCache::loadBaseCircle(" << mCircleId << ")";
|
||||
std::cerr << std::endl;
|
||||
@ -416,9 +484,10 @@ bool RsGxsCircleCache::loadSubCircle(const RsGxsCircleCache &subcircle)
|
||||
|
||||
/* should not be any unprocessed circles or peers */
|
||||
#ifdef DEBUG_CIRCLES
|
||||
#endif // DEBUG_CIRCLES
|
||||
|
||||
std::cerr << "RsGxsCircleCache::loadSubCircle(" << subcircle.mCircleId << ") TODO";
|
||||
std::cerr << std::endl;
|
||||
#endif // DEBUG_CIRCLES
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -452,6 +521,13 @@ bool RsGxsCircleCache::addAllowedPeer(const RsPgpId &pgpId, const RsGxsId &gxsId
|
||||
}
|
||||
|
||||
|
||||
bool RsGxsCircleCache::addLocalFriend(const RsPgpId &pgpId)
|
||||
{
|
||||
/* empty list as no GxsID associated */
|
||||
std::list<RsGxsId> &gxsList = mAllowedPeers[pgpId];
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************************/
|
||||
/************************************************************************************/
|
||||
@ -465,9 +541,9 @@ bool p3GxsCircles::request_CircleIdList()
|
||||
std::cerr << std::endl;
|
||||
#endif // DEBUG_CIRCLES
|
||||
|
||||
uint32_t ansType = RS_TOKREQ_ANSTYPE_LIST;
|
||||
uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY;
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_IDS;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
|
||||
|
||||
uint32_t token = 0;
|
||||
|
||||
@ -484,20 +560,28 @@ bool p3GxsCircles::load_CircleIdList(uint32_t token)
|
||||
std::cerr << std::endl;
|
||||
#endif // DEBUG_CIRCLES
|
||||
|
||||
std::list<RsGxsGroupId> groupIds;
|
||||
bool ok = RsGenExchange::getGroupList(token, groupIds);
|
||||
std::list<RsGroupMetaData> groups;
|
||||
bool ok = RsGenExchange::getGroupMeta(token, groups);
|
||||
|
||||
if(ok)
|
||||
{
|
||||
// Save List
|
||||
std::list<RsGxsGroupId>::iterator vit;
|
||||
std::list<RsGroupMetaData>::iterator it;
|
||||
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
mCircleIdList.clear();
|
||||
mCirclePersonalIdList.clear();
|
||||
mCircleExternalIdList.clear();
|
||||
|
||||
for(vit = groupIds.begin(); vit != groupIds.end(); vit++)
|
||||
for(it = groups.begin(); it != groups.end(); it++)
|
||||
{
|
||||
mCircleIdList.push_back(*vit);
|
||||
if (it->mCircleType == GXS_CIRCLE_TYPE_LOCAL)
|
||||
{
|
||||
mCirclePersonalIdList.push_back(it->mGroupId);
|
||||
}
|
||||
else
|
||||
{
|
||||
mCircleExternalIdList.push_back(it->mGroupId);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -751,10 +835,10 @@ bool p3GxsCircles::cache_load_for_token(uint32_t token)
|
||||
item->convertTo(group);
|
||||
|
||||
#ifdef DEBUG_CIRCLES
|
||||
#endif // DEBUG_CIRCLES
|
||||
std::cerr << "p3GxsCircles::cache_load_for_token() Loaded Id with Meta: ";
|
||||
std::cerr << item->meta;
|
||||
std::cerr << std::endl;
|
||||
#endif // DEBUG_CIRCLES
|
||||
|
||||
|
||||
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
|
||||
@ -765,6 +849,9 @@ bool p3GxsCircles::cache_load_for_token(uint32_t token)
|
||||
it = mLoadingCache.find(id);
|
||||
if (it == mLoadingCache.end())
|
||||
{
|
||||
std::cerr << "p3GxsCircles::cache_load_for_token() Load ERROR: ";
|
||||
std::cerr << item->meta;
|
||||
std::cerr << std::endl;
|
||||
// ERROR.
|
||||
continue;
|
||||
}
|
||||
@ -773,84 +860,132 @@ bool p3GxsCircles::cache_load_for_token(uint32_t token)
|
||||
cache.loadBaseCircle(group);
|
||||
delete item;
|
||||
|
||||
|
||||
bool isComplete = true;
|
||||
bool isUnprocessedPeers = false;
|
||||
|
||||
std::list<RsGxsId> &peers = group.mInvitedMembers;
|
||||
std::list<RsGxsId>::const_iterator pit;
|
||||
|
||||
// need to trigger the searches.
|
||||
for(pit = peers.begin(); pit != peers.end(); pit++)
|
||||
if (cache.mIsExternal)
|
||||
{
|
||||
/* check cache */
|
||||
if (mIdentities->haveKey(*pit))
|
||||
std::cerr << "p3GxsCircles::cache_load_for_token() Loading External Circle";
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::list<RsGxsId> &peers = group.mInvitedMembers;
|
||||
std::list<RsGxsId>::const_iterator pit;
|
||||
|
||||
// need to trigger the searches.
|
||||
for(pit = peers.begin(); pit != peers.end(); pit++)
|
||||
{
|
||||
/* we can process now! */
|
||||
RsIdentityDetails details;
|
||||
if (mIdentities->getIdDetails(*pit, details))
|
||||
std::cerr << "p3GxsCircles::cache_load_for_token() Invited Member: " << *pit;
|
||||
std::cerr << std::endl;
|
||||
|
||||
/* check cache */
|
||||
if (mIdentities->haveKey(*pit))
|
||||
{
|
||||
if (details.mPgpLinked && details.mPgpKnown)
|
||||
/* we can process now! */
|
||||
RsIdentityDetails details;
|
||||
if (mIdentities->getIdDetails(*pit, details))
|
||||
{
|
||||
cache.addAllowedPeer(details.mPgpId, *pit);
|
||||
if (details.mPgpLinked && details.mPgpKnown)
|
||||
{
|
||||
std::cerr << "p3GxsCircles::cache_load_for_token() Is Known -> AllowedPeer: " << *pit;
|
||||
std::cerr << std::endl;
|
||||
cache.addAllowedPeer(details.mPgpId, *pit);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "p3GxsCircles::cache_load_for_token() Is Unknown -> UnknownPeer: " << *pit;
|
||||
std::cerr << std::endl;
|
||||
cache.mUnknownPeers.insert(*pit);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cache.mUnknownPeers.insert(*pit);
|
||||
std::cerr << "p3GxsCircles::cache_load_for_token() Error no details: " << *pit;
|
||||
std::cerr << std::endl;
|
||||
// ERROR.
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// ERROR.
|
||||
|
||||
std::cerr << "p3GxsCircles::cache_load_for_token() Requesting UnprocessedPeer: " << *pit;
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::list<PeerId> peers;
|
||||
mIdentities->requestKey(*pit, peers);
|
||||
|
||||
/* store in to_process queue. */
|
||||
cache.mUnprocessedPeers.insert(*pit);
|
||||
|
||||
isComplete = false;
|
||||
isUnprocessedPeers = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* store in to_process queue. */
|
||||
cache.mUnprocessedPeers.insert(*pit);
|
||||
|
||||
isComplete = false;
|
||||
isUnprocessedPeers = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef HANDLE_SUBCIRCLES
|
||||
#if 0
|
||||
std::list<RsGxsCircleId> &circles = group.mSubCircles;
|
||||
std::list<RsGxsCircleId>::const_iterator cit;
|
||||
for(cit = circles.begin(); cit != circles.end(); cit++)
|
||||
{
|
||||
/* if its cached already -> then its complete. */
|
||||
if (mCircleCache.is_loaded(*cit))
|
||||
std::list<RsGxsCircleId> &circles = group.mSubCircles;
|
||||
std::list<RsGxsCircleId>::const_iterator cit;
|
||||
for(cit = circles.begin(); cit != circles.end(); cit++)
|
||||
{
|
||||
RsGxsCircleCache cachedCircle;
|
||||
if (mCircleCache.fetch(&cit, cachedCircle))
|
||||
/* if its cached already -> then its complete. */
|
||||
if (mCircleCache.is_loaded(*cit))
|
||||
{
|
||||
/* copy cached circle into circle */
|
||||
cache.loadSubCircle(cachedCircle);
|
||||
RsGxsCircleCache cachedCircle;
|
||||
if (mCircleCache.fetch(&cit, cachedCircle))
|
||||
{
|
||||
/* copy cached circle into circle */
|
||||
cache.loadSubCircle(cachedCircle);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* error */
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* error */
|
||||
continue;
|
||||
/* push into secondary processing queues */
|
||||
std::list<RsGxsCircleId> &proc_circles = mCacheLoad_SubCircle[*cit];
|
||||
proc_circles.push_back(id);
|
||||
|
||||
subCirclesToLoad.push_back(*cit);
|
||||
|
||||
isComplete = false;
|
||||
isUnprocessedCircles = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* push into secondary processing queues */
|
||||
std::list<RsGxsCircleId> &proc_circles = mCacheLoad_SubCircle[*cit];
|
||||
proc_circles.push_back(id);
|
||||
|
||||
subCirclesToLoad.push_back(*cit);
|
||||
|
||||
isComplete = false;
|
||||
isUnprocessedCircles = true;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
else
|
||||
{
|
||||
std::cerr << "p3GxsCircles::cache_load_for_token() Loading Personal Circle";
|
||||
std::cerr << std::endl;
|
||||
|
||||
// LOCAL Load.
|
||||
std::list<RsPgpId> &peers = group.mLocalFriends;
|
||||
std::list<RsPgpId>::const_iterator pit;
|
||||
|
||||
// need to trigger the searches.
|
||||
for(pit = peers.begin(); pit != peers.end(); pit++)
|
||||
{
|
||||
std::cerr << "p3GxsCircles::cache_load_for_token() Local Friend: " << *pit;
|
||||
std::cerr << std::endl;
|
||||
|
||||
cache.addLocalFriend(*pit);
|
||||
}
|
||||
isComplete = true;
|
||||
isUnprocessedPeers = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (isComplete)
|
||||
{
|
||||
checkCircleCacheForAutoSubscribe(cache);
|
||||
|
||||
/* move straight into the cache */
|
||||
mCircleCache.store(id, cache);
|
||||
mCircleCache.resize();
|
||||
@ -974,6 +1109,8 @@ bool p3GxsCircles::cache_reloadids(const std::string &circleId)
|
||||
std::cerr << std::endl;
|
||||
#endif // DEBUG_CIRCLES
|
||||
|
||||
checkCircleCacheForAutoSubscribe(cache);
|
||||
|
||||
// Push to Cache.
|
||||
mCircleCache.store(circleId, cache);
|
||||
mCircleCache.resize();
|
||||
@ -992,6 +1129,69 @@ bool p3GxsCircles::cache_reloadids(const std::string &circleId)
|
||||
}
|
||||
|
||||
|
||||
/* We need to AutoSubscribe if the Circle is relevent to us */
|
||||
bool p3GxsCircles::checkCircleCacheForAutoSubscribe(RsGxsCircleCache &cache)
|
||||
{
|
||||
std::cerr << "p3GxsCircles::checkCircleCacheForAutoSubscribe() : ";
|
||||
std::cerr << cache.mCircleId;
|
||||
std::cerr << std::endl;
|
||||
|
||||
/* if processed already - ignore */
|
||||
if (!(cache.mGroupStatus & GXS_SERV::GXS_GRP_STATUS_UNPROCESSED))
|
||||
{
|
||||
std::cerr << "p3GxsCircles::checkCircleCacheForAutoSubscribe() : Already Processed";
|
||||
std::cerr << std::endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* if personal - we created ... is subscribed already */
|
||||
if (!cache.mIsExternal)
|
||||
{
|
||||
std::cerr << "p3GxsCircles::checkCircleCacheForAutoSubscribe() : Personal Circle";
|
||||
std::cerr << std::endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* if we appear in the group - then autosubscribe, and mark as processed */
|
||||
std::string ownId = AuthGPG::getAuthGPG()->getGPGOwnId();
|
||||
std::map<RsPgpId, std::list<RsGxsId> >::iterator it = cache.mAllowedPeers.find(ownId);
|
||||
if (it != cache.mAllowedPeers.end())
|
||||
{
|
||||
/* we are part of this group - subscribe, clear unprocessed flag */
|
||||
std::cerr << "p3GxsCircles::checkCircleCacheForAutoSubscribe() Found OwnId -> AutoSubscribe!";
|
||||
std::cerr << std::endl;
|
||||
|
||||
|
||||
uint32_t token, token2;
|
||||
RsGenExchange::subscribeToGroup(token, cache.mCircleId, true);
|
||||
RsGenExchange::setGroupStatusFlags(token2, cache.mCircleId, 0, GXS_SERV::GXS_GRP_STATUS_UNPROCESSED);
|
||||
cache.mGroupStatus ^= GXS_SERV::GXS_GRP_STATUS_UNPROCESSED;
|
||||
return true;
|
||||
}
|
||||
else if (cache.mUnknownPeers.empty())
|
||||
{
|
||||
std::cerr << "p3GxsCircles::checkCircleCacheForAutoSubscribe() Know All Peers -> Processed";
|
||||
std::cerr << std::endl;
|
||||
|
||||
/* we know all the peers - we are not part - we can flag as PROCESSED. */
|
||||
uint32_t token;
|
||||
RsGenExchange::setGroupStatusFlags(token, cache.mCircleId, 0, GXS_SERV::GXS_GRP_STATUS_UNPROCESSED);
|
||||
cache.mGroupStatus ^= GXS_SERV::GXS_GRP_STATUS_UNPROCESSED;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "p3GxsCircles::checkCircleCacheForAutoSubscribe() Leaving Unprocessed";
|
||||
std::cerr << std::endl;
|
||||
|
||||
// Don't clear UNPROCESSED - as we might not know all the peers.
|
||||
// TODO - work out when we flag as PROCESSED.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef HANDLE_SUBCIRCLES
|
||||
#if 0
|
||||
|
@ -106,10 +106,16 @@ class RsGxsCircleCache
|
||||
bool getAllowedPeersList(std::list<RsPgpId> &friendlist);
|
||||
bool isAllowedPeer(const RsPgpId &id);
|
||||
bool addAllowedPeer(const RsPgpId &pgpid, const RsGxsId &gxsId);
|
||||
bool addLocalFriend(const RsPgpId &pgpid);
|
||||
|
||||
RsGxsCircleId mCircleId;
|
||||
std::string mCircleName;
|
||||
|
||||
uint32_t mCircleType;
|
||||
bool mIsExternal;
|
||||
|
||||
uint32_t mGroupStatus;
|
||||
|
||||
time_t mUpdateTime;
|
||||
std::set<RsGxsCircleId> mUnprocessedCircles;
|
||||
std::set<RsGxsId> mUnprocessedPeers;
|
||||
@ -121,22 +127,6 @@ class RsGxsCircleCache
|
||||
|
||||
|
||||
|
||||
class RsCircles
|
||||
{
|
||||
/* Functions to handle Local / Internal Circles == Same as for file permissions. */
|
||||
public:
|
||||
virtual void createLocalCircle() = 0;
|
||||
virtual void addToLocalCircle() = 0;
|
||||
virtual void removeFromLocalCircle() = 0;
|
||||
virtual void getLocalCirclePeers() = 0;
|
||||
virtual void getListOfLocalCircles() = 0;
|
||||
|
||||
/* similar functions for External Groups */
|
||||
virtual bool createGroup(uint32_t& token, RsGxsCircleGroup &group) = 0;
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsCircleGroup> &groups) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
class p3GxsCircles: public RsGxsCircleExchange, public RsGxsCircles,
|
||||
public GxsTokenQueue, public RsTickEvent
|
||||
@ -148,27 +138,21 @@ class p3GxsCircles: public RsGxsCircleExchange, public RsGxsCircles,
|
||||
/*********** External Interface ***************/
|
||||
|
||||
virtual bool getCircleDetails(const RsGxsCircleId &id, RsGxsCircleDetails &details);
|
||||
virtual bool getCircleIdList(std::list<RsGxsCircleId> &circleIds);
|
||||
virtual bool getCircleExternalIdList(std::list<RsGxsCircleId> &circleIds);
|
||||
virtual bool getCirclePersonalIdList(std::list<RsGxsCircleId> &circleIds);
|
||||
|
||||
virtual bool isLoaded(const RsGxsCircleId &circleId);
|
||||
virtual bool loadCircle(const RsGxsCircleId &circleId);
|
||||
|
||||
virtual int canSend(const RsGxsCircleId &circleId, const RsPgpId &id);
|
||||
virtual int canReceive(const RsGxsCircleId &circleId, const RsPgpId &id);
|
||||
virtual bool recipients(const RsGxsCircleId &circleId, std::list<RsPgpId> &friendlist);
|
||||
|
||||
/*******/
|
||||
|
||||
virtual void createLocalCircle();
|
||||
virtual void addToLocalCircle();
|
||||
virtual void removeFromLocalCircle();
|
||||
virtual void getLocalCirclePeers();
|
||||
virtual void getListOfLocalCircles();
|
||||
|
||||
/*******/
|
||||
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsCircleGroup> &groups);
|
||||
virtual bool createGroup(uint32_t& token, RsGxsCircleGroup &group);
|
||||
|
||||
|
||||
/**********************************************/
|
||||
|
||||
// needed for background processing.
|
||||
@ -206,12 +190,15 @@ class p3GxsCircles: public RsGxsCircleExchange, public RsGxsCircles,
|
||||
bool cache_load_for_token(uint32_t token);
|
||||
bool cache_reloadids(const std::string &circleId);
|
||||
|
||||
bool checkCircleCacheForAutoSubscribe(RsGxsCircleCache &cache);
|
||||
|
||||
|
||||
p3IdService *mIdentities; // Needed for constructing Circle Info,
|
||||
|
||||
RsMutex mCircleMtx; /* Locked Below Here */
|
||||
|
||||
std::list<RsGxsCircleId> mCircleIdList;
|
||||
std::list<RsGxsCircleId> mCircleExternalIdList;
|
||||
std::list<RsGxsCircleId> mCirclePersonalIdList;
|
||||
|
||||
/***** Caching Circle Info, *****/
|
||||
// initial load queue
|
||||
|
@ -72,6 +72,7 @@ RsGxsImage::~RsGxsImage()
|
||||
RsGxsImage &RsGxsImage::operator=(const RsGxsImage &a)
|
||||
{
|
||||
copy(a.mData, a.mSize);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@ -146,31 +147,6 @@ RsGxsVote::RsGxsVote()
|
||||
mVoteType = 0;
|
||||
}
|
||||
|
||||
/********************************************************************************/
|
||||
|
||||
#define RSGXSCOMMENT_MAX_SERVICE_STRING 16
|
||||
|
||||
bool SSGxsComment::load(const std::string &input)
|
||||
{
|
||||
//char line[RSGXSCOMMENT_MAX_SERVICE_STRING];
|
||||
int val;
|
||||
mVoteValue = 0;
|
||||
if (1 == sscanf(input.c_str(), "V:%d", &val))
|
||||
{
|
||||
mVoteValue = val;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
std::string SSGxsComment::save() const
|
||||
{
|
||||
std::string output;
|
||||
rs_sprintf(output, "V:%d", mVoteValue);
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************************/
|
||||
/******************* Startup / Tick ******************************************/
|
||||
/********************************************************************************/
|
||||
@ -255,10 +231,22 @@ bool p3GxsCommentService::getGxsCommentData(const uint32_t &token, std::vector<R
|
||||
}
|
||||
cit->mScore = calculateBestScore(cit->mUpVotes, cit->mDownVotes);
|
||||
|
||||
/* convert serviceString -> mHaveVoted */
|
||||
SSGxsComment ss;
|
||||
ss.load(cit->mMeta.mServiceString);
|
||||
cit->mOwnVote = ss.mVoteValue;
|
||||
/* convert Status -> mHaveVoted */
|
||||
if (cit->mMeta.mMsgStatus & GXS_SERV::GXS_MSG_STATUS_VOTE_MASK)
|
||||
{
|
||||
if (cit->mMeta.mMsgStatus & GXS_SERV::GXS_MSG_STATUS_VOTE_UP)
|
||||
{
|
||||
cit->mOwnVote = GXS_VOTE_UP;
|
||||
}
|
||||
else
|
||||
{
|
||||
cit->mOwnVote = GXS_VOTE_DOWN;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cit->mOwnVote = GXS_VOTE_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
std::cerr << "p3GxsCommentService::getGxsCommentData() Found " << comments.size() << " Comments";
|
||||
@ -345,10 +333,22 @@ bool p3GxsCommentService::getGxsRelatedComments(const uint32_t &token, std::vect
|
||||
}
|
||||
cit->mScore = calculateBestScore(cit->mUpVotes, cit->mDownVotes);
|
||||
|
||||
/* convert serviceString -> mHaveVoted */
|
||||
SSGxsComment ss;
|
||||
ss.load(cit->mMeta.mServiceString);
|
||||
cit->mOwnVote = ss.mVoteValue;
|
||||
/* convert Status -> mHaveVoted */
|
||||
if (cit->mMeta.mMsgStatus & GXS_SERV::GXS_MSG_STATUS_VOTE_MASK)
|
||||
{
|
||||
if (cit->mMeta.mMsgStatus & GXS_SERV::GXS_MSG_STATUS_VOTE_UP)
|
||||
{
|
||||
cit->mOwnVote = GXS_VOTE_UP;
|
||||
}
|
||||
else
|
||||
{
|
||||
cit->mOwnVote = GXS_VOTE_DOWN;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cit->mOwnVote = GXS_VOTE_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
std::cerr << "p3GxsCommentService::getGxsRelatedComments() Found " << comments.size() << " Comments";
|
||||
@ -392,7 +392,7 @@ double p3GxsCommentService::calculateBestScore(int upVotes, int downVotes)
|
||||
|
||||
bool p3GxsCommentService::createGxsComment(uint32_t &token, RsGxsComment &msg)
|
||||
{
|
||||
std::cerr << "p3GxsChannels::createGxsComment() GroupId: " << msg.mMeta.mGroupId;
|
||||
std::cerr << "p3GxsCommentService::createGxsComment() GroupId: " << msg.mMeta.mGroupId;
|
||||
std::cerr << std::endl;
|
||||
|
||||
RsGxsCommentItem* msgItem = new RsGxsCommentItem(mServiceType);
|
||||
@ -410,34 +410,34 @@ bool p3GxsCommentService::createGxsVote(uint32_t &token, RsGxsVote &vote)
|
||||
// NOTE Because we cannot do this operation immediately, we create a token,
|
||||
// and monitor acknowledgeTokenMsg ... to return correct answer.
|
||||
|
||||
std::cerr << "p3GxsChannels::createGxsVote() GroupId: " << vote.mMeta.mGroupId;
|
||||
std::cerr << "p3GxsCommentService::createGxsVote() GroupId: " << vote.mMeta.mGroupId;
|
||||
std::cerr << std::endl;
|
||||
|
||||
/* vote must be associated with another item */
|
||||
if (vote.mMeta.mThreadId.empty())
|
||||
{
|
||||
std::cerr << "p3GxsChannels::createGxsVote() ERROR Missing Required ThreadId";
|
||||
std::cerr << "p3GxsCommentService::createGxsVote() ERROR Missing Required ThreadId";
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (vote.mMeta.mParentId.empty())
|
||||
{
|
||||
std::cerr << "p3GxsChannels::createGxsVote() ERROR Missing Required ParentId";
|
||||
std::cerr << "p3GxsCommentService::createGxsVote() ERROR Missing Required ParentId";
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (vote.mMeta.mGroupId.empty())
|
||||
{
|
||||
std::cerr << "p3GxsChannels::createGxsVote() ERROR Missing Required GroupId";
|
||||
std::cerr << "p3GxsCommentService::createGxsVote() ERROR Missing Required GroupId";
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (vote.mMeta.mAuthorId.empty())
|
||||
{
|
||||
std::cerr << "p3GxsChannels::createGxsVote() ERROR Missing Required AuthorId";
|
||||
std::cerr << "p3GxsCommentService::createGxsVote() ERROR Missing Required AuthorId";
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
@ -451,7 +451,7 @@ bool p3GxsCommentService::createGxsVote(uint32_t &token, RsGxsVote &vote)
|
||||
it = mPendingVotes.find(parentId);
|
||||
if (it != mPendingVotes.end())
|
||||
{
|
||||
std::cerr << "p3GxsChannels::createGxsVote() ERROR Already a pending vote!";
|
||||
std::cerr << "p3GxsCommentService::createGxsVote() ERROR Already a pending vote!";
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
@ -519,13 +519,8 @@ void p3GxsCommentService::load_PendingVoteParent(const uint32_t &token)
|
||||
continue;
|
||||
}
|
||||
|
||||
/* check Vote serviceString */
|
||||
SSGxsComment ss;
|
||||
ss.load(meta.mServiceString);
|
||||
|
||||
RsGxsVote vote = pit->second.mVote;
|
||||
|
||||
if (ss.mVoteValue)
|
||||
if (meta.mMsgStatus & GXS_SERV::GXS_MSG_STATUS_VOTE_MASK)
|
||||
{
|
||||
std::cerr << "p3GxsCommentService::load_PendingVoteParent() ERROR Already Voted";
|
||||
std::cerr << std::endl;
|
||||
@ -543,11 +538,17 @@ void p3GxsCommentService::load_PendingVoteParent(const uint32_t &token)
|
||||
std::cerr << "p3GxsCommentService::load_PendingVoteParent() submitting Vote";
|
||||
std::cerr << std::endl;
|
||||
|
||||
ss.mVoteValue = vote.mVoteType;
|
||||
std::string servString = ss.save();
|
||||
|
||||
uint32_t ss_token;
|
||||
mExchange->setMsgServiceString(ss_token, parentId, servString);
|
||||
uint32_t status_token;
|
||||
if (vote.mVoteType == GXS_VOTE_UP)
|
||||
{
|
||||
mExchange->setMsgStatusFlags(status_token, parentId,
|
||||
GXS_SERV::GXS_MSG_STATUS_VOTE_UP, GXS_SERV::GXS_MSG_STATUS_VOTE_MASK);
|
||||
}
|
||||
else
|
||||
{
|
||||
mExchange->setMsgStatusFlags(status_token, parentId,
|
||||
GXS_SERV::GXS_MSG_STATUS_VOTE_DOWN, GXS_SERV::GXS_MSG_STATUS_VOTE_MASK);
|
||||
}
|
||||
|
||||
uint32_t vote_token;
|
||||
castVote(vote_token, vote);
|
||||
@ -563,7 +564,7 @@ void p3GxsCommentService::load_PendingVoteParent(const uint32_t &token)
|
||||
|
||||
void p3GxsCommentService::completeInternalVote(uint32_t &token)
|
||||
{
|
||||
std::cerr << "p3GxsChannels::completeInternalVote() token: " << token;
|
||||
std::cerr << "p3GxsCommentService::completeInternalVote() token: " << token;
|
||||
std::cerr << std::endl;
|
||||
std::map<RsGxsGrpMsgIdPair, VoteHolder>::iterator it;
|
||||
for (it = mPendingVotes.begin(); it != mPendingVotes.end(); it++)
|
||||
@ -574,7 +575,7 @@ void p3GxsCommentService::completeInternalVote(uint32_t &token)
|
||||
uint32_t status = mExchange->getTokenService()->requestStatus(token);
|
||||
mExchange->updatePublicRequestStatus(it->second.mReqToken, status);
|
||||
|
||||
std::cerr << "p3GxsChannels::completeInternalVote() Matched to PendingVote. status: " << status;
|
||||
std::cerr << "p3GxsCommentService::completeInternalVote() Matched to PendingVote. status: " << status;
|
||||
std::cerr << std::endl;
|
||||
|
||||
it->second.mStatus = VoteHolder::VOTE_READY;
|
||||
@ -582,7 +583,7 @@ void p3GxsCommentService::completeInternalVote(uint32_t &token)
|
||||
}
|
||||
}
|
||||
|
||||
std::cerr << "p3GxsChannels::completeInternalVote() ERROR Failed to match PendingVote";
|
||||
std::cerr << "p3GxsCommentService::completeInternalVote() ERROR Failed to match PendingVote";
|
||||
std::cerr << std::endl;
|
||||
|
||||
return;
|
||||
@ -591,7 +592,7 @@ void p3GxsCommentService::completeInternalVote(uint32_t &token)
|
||||
|
||||
bool p3GxsCommentService::acknowledgeVote(const uint32_t& token, RsGxsGrpMsgIdPair& msgId)
|
||||
{
|
||||
std::cerr << "p3GxsChannels::acknowledgeVote() token: " << token;
|
||||
std::cerr << "p3GxsCommentService::acknowledgeVote() token: " << token;
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::map<RsGxsGrpMsgIdPair, VoteHolder>::iterator it;
|
||||
@ -599,13 +600,13 @@ bool p3GxsCommentService::acknowledgeVote(const uint32_t& token, RsGxsGrpMsgIdPa
|
||||
{
|
||||
if (it->second.mReqToken == token)
|
||||
{
|
||||
std::cerr << "p3GxsChannels::acknowledgeVote() Matched to PendingVote";
|
||||
std::cerr << "p3GxsCommentService::acknowledgeVote() Matched to PendingVote";
|
||||
std::cerr << std::endl;
|
||||
|
||||
bool ans = false;
|
||||
if (it->second.mStatus == VoteHolder::VOTE_READY)
|
||||
{
|
||||
std::cerr << "p3GxsChannels::acknowledgeVote() PendingVote = READY";
|
||||
std::cerr << "p3GxsCommentService::acknowledgeVote() PendingVote = READY";
|
||||
std::cerr << std::endl;
|
||||
|
||||
// Finally finish this Vote off.
|
||||
@ -613,16 +614,16 @@ bool p3GxsCommentService::acknowledgeVote(const uint32_t& token, RsGxsGrpMsgIdPa
|
||||
}
|
||||
else if (it->second.mStatus == VoteHolder::VOTE_ERROR)
|
||||
{
|
||||
std::cerr << "p3GxsChannels::acknowledgeVote() PendingVote = ERROR ???";
|
||||
std::cerr << "p3GxsCommentService::acknowledgeVote() PendingVote = ERROR ???";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "p3GxsChannels::acknowledgeVote() PendingVote = OTHER STATUS";
|
||||
std::cerr << "p3GxsCommentService::acknowledgeVote() PendingVote = OTHER STATUS";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
std::cerr << "p3GxsChannels::acknowledgeVote() cleanup token & PendingVote";
|
||||
std::cerr << "p3GxsCommentService::acknowledgeVote() cleanup token & PendingVote";
|
||||
std::cerr << std::endl;
|
||||
mExchange->disposeOfPublicToken(it->second.mReqToken);
|
||||
mPendingVotes.erase(it);
|
||||
@ -631,7 +632,7 @@ bool p3GxsCommentService::acknowledgeVote(const uint32_t& token, RsGxsGrpMsgIdPa
|
||||
}
|
||||
}
|
||||
|
||||
std::cerr << "p3GxsChannels::acknowledgeVote() Failed to match PendingVote";
|
||||
std::cerr << "p3GxsCommentService::acknowledgeVote() Failed to match PendingVote";
|
||||
std::cerr << std::endl;
|
||||
|
||||
return false;
|
||||
@ -669,7 +670,7 @@ void p3GxsCommentService::handleResponse(uint32_t token, uint32_t req_type)
|
||||
|
||||
bool p3GxsCommentService::castVote(uint32_t &token, RsGxsVote &msg)
|
||||
{
|
||||
std::cerr << "p3GxsChannels::castVote() GroupId: " << msg.mMeta.mGroupId;
|
||||
std::cerr << "p3GxsCommentService::castVote() GroupId: " << msg.mMeta.mGroupId;
|
||||
std::cerr << std::endl;
|
||||
|
||||
RsGxsVoteItem* msgItem = new RsGxsVoteItem(mServiceType);
|
||||
|
@ -57,23 +57,6 @@ class VoteHolder
|
||||
uint32_t mStatus;
|
||||
};
|
||||
|
||||
// NOTE this ServiceString class must be compatible with other classes
|
||||
// that use ServiceString... i.e. it should scan to string for {V:%d }
|
||||
// and remember the rest of the string - so it can maintain other settings.
|
||||
// TODO.
|
||||
|
||||
class SSGxsComment
|
||||
{
|
||||
public:
|
||||
SSGxsComment(): mVoteValue(0) { return; }
|
||||
bool load(const std::string &input);
|
||||
std::string save() const;
|
||||
|
||||
std::string mPreString;
|
||||
std::string mPostString;
|
||||
uint32_t mVoteValue;
|
||||
};
|
||||
|
||||
|
||||
class p3GxsCommentService: public GxsTokenQueue
|
||||
{
|
||||
|
@ -51,7 +51,7 @@ RsGxsForums *rsGxsForums = NULL;
|
||||
/********************************************************************************/
|
||||
|
||||
p3GxsForums::p3GxsForums(RsGeneralDataService *gds, RsNetworkExchangeService *nes, RsGixs* gixs)
|
||||
: RsGenExchange(gds, nes, new RsGxsForumSerialiser(), RS_SERVICE_GXSV1_TYPE_FORUMS, gixs, forumsAuthenPolicy()), RsGxsForums(this)
|
||||
: RsGenExchange(gds, nes, new RsGxsForumSerialiser(), RS_SERVICE_GXSV2_TYPE_FORUMS, gixs, forumsAuthenPolicy()), RsGxsForums(this)
|
||||
{
|
||||
// For Dummy Msgs.
|
||||
mGenActive = false;
|
||||
|
@ -124,7 +124,7 @@ RsIdentity *rsIdentity = NULL;
|
||||
/********************************************************************************/
|
||||
|
||||
p3IdService::p3IdService(RsGeneralDataService *gds, RsNetworkExchangeService *nes)
|
||||
: RsGxsIdExchange(gds, nes, new RsGxsIdSerialiser(), RS_SERVICE_GXSV1_TYPE_GXSID, idAuthenPolicy()),
|
||||
: RsGxsIdExchange(gds, nes, new RsGxsIdSerialiser(), RS_SERVICE_GXSV2_TYPE_GXSID, idAuthenPolicy()),
|
||||
RsIdentity(this), GxsTokenQueue(this), RsTickEvent(), mIdMtx("p3IdService"),
|
||||
mPublicKeyCache(DEFAULT_MEM_CACHE_SIZE, "GxsIdPublicKeyCache"),
|
||||
mPrivateKeyCache(DEFAULT_MEM_CACHE_SIZE, "GxsIdPrivateKeyCache")
|
||||
@ -205,7 +205,7 @@ void p3IdService::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
||||
/* shouldn't need to worry about groups - as they need to be subscribed to */
|
||||
if (groupChange)
|
||||
{
|
||||
std::cerr << "p3IdService::notifyChanges() Found Message Change Notification";
|
||||
std::cerr << "p3IdService::notifyChanges() Found Group Change Notification";
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::list<RsGxsGroupId> &groupList = groupChange->mGrpIdList;
|
||||
@ -360,8 +360,33 @@ int p3IdService::getPrivateKey(const RsGxsId &id, RsTlvSecurityKey &key)
|
||||
/******************* RsGixsReputation ***************************************/
|
||||
/********************************************************************************/
|
||||
|
||||
bool p3IdService::getReputation(const RsGxsId &id, const GixsReputation &rep)
|
||||
bool p3IdService::haveReputation(const RsGxsId &id)
|
||||
{
|
||||
return haveKey(id);
|
||||
}
|
||||
|
||||
bool p3IdService::loadReputation(const RsGxsId &id)
|
||||
{
|
||||
if (haveKey(id))
|
||||
return true;
|
||||
return cache_request_load(id);
|
||||
}
|
||||
|
||||
bool p3IdService::getReputation(const RsGxsId &id, GixsReputation &rep)
|
||||
{
|
||||
/* this is the key part for accepting messages */
|
||||
|
||||
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
|
||||
RsGxsIdCache data;
|
||||
if (mPublicKeyCache.fetch(id, data))
|
||||
{
|
||||
rep.id = id;
|
||||
// Score > 0 is okay.
|
||||
// Will extract score from Cache Info.
|
||||
// For the moment just return positive number.
|
||||
rep.score = 10;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2107,12 +2132,9 @@ std::string rsIdTypeToString(uint32_t idtype)
|
||||
* that we don't block at all. This should be in a background thread.
|
||||
* Perhaps a generic method to handle this will be advisable.... but we do that later.
|
||||
*
|
||||
* To start with we will work from the Posted service.
|
||||
*
|
||||
*
|
||||
*
|
||||
* So Reputation....
|
||||
* Three components:
|
||||
* 4 components:
|
||||
* 1) Your Opinion: Should override everything else.
|
||||
* 2) Implicit Factors: Know the associated GPG Key.
|
||||
* 3) Your Friends Opinions:
|
||||
@ -2157,6 +2179,56 @@ std::string rsIdTypeToString(uint32_t idtype)
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/************************************************************************************/
|
||||
/*
|
||||
* Scoring system.
|
||||
* -100 to 100 is expected range.
|
||||
*
|
||||
*
|
||||
* Each Lobby has a publish threshold.
|
||||
* - As part of Lobby definition. ???
|
||||
* - Locally Set.
|
||||
*
|
||||
* Threshold:
|
||||
* 50 VIP List.
|
||||
* 20 Dress Code
|
||||
* 10 Limit Riffraff.
|
||||
* 0 Accept All.
|
||||
*
|
||||
* Implicit Scores:
|
||||
* +50 for known PGP
|
||||
* +10 for unknown PGP (want to encourage usage).
|
||||
* +5 for Anon ID.
|
||||
*
|
||||
* Own Scores:
|
||||
* +1000 Accepted
|
||||
* +50 Friend
|
||||
* +10 Interesting
|
||||
* 0 Mostly Harmless
|
||||
* -10 Annoying.
|
||||
* -50 Troll
|
||||
* -1000 Total Banned
|
||||
*
|
||||
*
|
||||
*
|
||||
|
||||
|
||||
|
||||
Processing Algorithm:
|
||||
* - Grab all Groups which have received messages.
|
||||
* (opt 1)-> grab latest msgs for each of these and process => score.
|
||||
* (opt 2)-> try incremental system (people probably won't change opinions often -> just set them once)
|
||||
* --> if not possible, fallback to full calculation.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool p3IdService::reputation_start()
|
||||
{
|
||||
if (!CacheArbitration(BG_REPUTATION))
|
||||
@ -2891,3 +2963,65 @@ void p3IdService::handle_event(uint32_t event_type, const std::string &elabel)
|
||||
|
||||
|
||||
|
||||
|
||||
/***** Conversion fns for RsGxsIdOpinion ****************/
|
||||
|
||||
#define REP_OFFSET 10000
|
||||
#define REP_RANGE 1000
|
||||
|
||||
int limitRep(int ans)
|
||||
{
|
||||
if (ans < -REP_RANGE)
|
||||
{
|
||||
ans = -REP_RANGE;
|
||||
}
|
||||
if (ans > REP_RANGE)
|
||||
{
|
||||
ans = REP_RANGE;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
|
||||
int convertRepToInt(uint32_t rep)
|
||||
{
|
||||
if (rep == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return limitRep(rep - REP_OFFSET);
|
||||
}
|
||||
|
||||
|
||||
uint32_t convertRepToUint32(int rep)
|
||||
{
|
||||
return limitRep(rep) + REP_OFFSET;
|
||||
}
|
||||
|
||||
|
||||
int RsGxsIdOpinion::getOpinion()
|
||||
{
|
||||
return convertRepToInt(mOpinion);
|
||||
}
|
||||
|
||||
|
||||
int RsGxsIdOpinion::setOpinion(int op)
|
||||
{
|
||||
mOpinion = convertRepToUint32(op);
|
||||
return op;
|
||||
}
|
||||
|
||||
int RsGxsIdOpinion::getReputation()
|
||||
{
|
||||
return convertRepToInt(mReputation);
|
||||
}
|
||||
|
||||
|
||||
int RsGxsIdOpinion::setReputation(int op)
|
||||
{
|
||||
mReputation = convertRepToUint32(op);
|
||||
return op;
|
||||
}
|
||||
|
||||
|
||||
|
@ -171,9 +171,9 @@ static uint32_t idAuthenPolicy();
|
||||
|
||||
// These are exposed via RsIdentity.
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups);
|
||||
virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions);
|
||||
|
||||
// These are local - and not exposed via RsIdentity.
|
||||
virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions);
|
||||
virtual bool createGroup(uint32_t& token, RsGxsIdGroup &group);
|
||||
virtual bool createMsg(uint32_t& token, RsGxsIdOpinion &opinion);
|
||||
|
||||
@ -218,7 +218,9 @@ virtual int getPrivateKey(const RsGxsId &id, RsTlvSecurityKey &key);
|
||||
*/
|
||||
|
||||
// get Reputation.
|
||||
virtual bool getReputation(const RsGxsId &id, const GixsReputation &rep);
|
||||
virtual bool haveReputation(const RsGxsId &id);
|
||||
virtual bool loadReputation(const RsGxsId &id);
|
||||
virtual bool getReputation(const RsGxsId &id, GixsReputation &rep);
|
||||
|
||||
|
||||
protected:
|
||||
|
@ -87,7 +87,7 @@ std::ostream &operator<<(std::ostream &out, const RsPhotoAlbum &album)
|
||||
}
|
||||
|
||||
p3PhotoService::p3PhotoService(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs* gixs)
|
||||
: RsGenExchange(gds, nes, new RsGxsPhotoSerialiser(), RS_SERVICE_GXSV1_TYPE_PHOTO, gixs, photoAuthenPolicy()),
|
||||
: RsGenExchange(gds, nes, new RsGxsPhotoSerialiser(), RS_SERVICE_GXSV2_TYPE_PHOTO, gixs, photoAuthenPolicy()),
|
||||
mPhotoMutex(std::string("Photo Mutex"))
|
||||
{
|
||||
}
|
||||
|
@ -31,6 +31,7 @@
|
||||
|
||||
#include "retroshare/rsgxsflags.h"
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
// For Dummy Msgs.
|
||||
#include "util/rsrandom.h"
|
||||
@ -43,26 +44,38 @@
|
||||
|
||||
RsPosted *rsPosted = NULL;
|
||||
|
||||
const uint32_t RsPosted::FLAG_MSGTYPE_POST = 0x0001;
|
||||
const uint32_t RsPosted::FLAG_MSGTYPE_MASK = 0x000f;
|
||||
//const uint32_t RsPosted::FLAG_MSGTYPE_POST = 0x0001;
|
||||
//const uint32_t RsPosted::FLAG_MSGTYPE_MASK = 0x000f;
|
||||
|
||||
|
||||
#define POSTED_TESTEVENT_DUMMYDATA 0x0001
|
||||
#define DUMMYDATA_PERIOD 60 // long enough for some RsIdentities to be generated.
|
||||
|
||||
#define POSTED_BACKGROUND_PROCESSING 0x0002
|
||||
#define PROCESSING_START_PERIOD 30
|
||||
#define PROCESSING_INC_PERIOD 15
|
||||
|
||||
#define POSTED_ALL_GROUPS 0x0011
|
||||
#define POSTED_UNPROCESSED_MSGS 0x0012
|
||||
#define POSTED_ALL_MSGS 0x0013
|
||||
#define POSTED_BG_POST_META 0x0014
|
||||
/********************************************************************************/
|
||||
/******************* Startup / Tick ******************************************/
|
||||
/********************************************************************************/
|
||||
|
||||
p3Posted::p3Posted(RsGeneralDataService *gds, RsNetworkExchangeService *nes, RsGixs* gixs)
|
||||
: RsGenExchange(gds, nes, new RsGxsPostedSerialiser(), RS_SERVICE_GXSV1_TYPE_POSTED, gixs, postedAuthenPolicy()), RsPosted(this)
|
||||
: RsGenExchange(gds, nes, new RsGxsPostedSerialiser(), RS_SERVICE_GXSV2_TYPE_POSTED, gixs, postedAuthenPolicy()), RsPosted(this), GxsTokenQueue(this), RsTickEvent(), mPostedMtx("PostedMtx")
|
||||
{
|
||||
mBgProcessing = false;
|
||||
|
||||
// For Dummy Msgs.
|
||||
mGenActive = false;
|
||||
mCommentService = new p3GxsCommentService(this, RS_SERVICE_GXSV1_TYPE_POSTED);
|
||||
mCommentService = new p3GxsCommentService(this, RS_SERVICE_GXSV2_TYPE_POSTED);
|
||||
|
||||
// Test Data disabled in repo.
|
||||
//RsTickEvent::schedule_in(POSTED_TESTEVENT_DUMMYDATA, DUMMYDATA_PERIOD);
|
||||
|
||||
RsTickEvent::schedule_in(POSTED_BACKGROUND_PROCESSING, PROCESSING_START_PERIOD);
|
||||
}
|
||||
|
||||
|
||||
@ -91,13 +104,63 @@ uint32_t p3Posted::postedAuthenPolicy()
|
||||
|
||||
void p3Posted::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
||||
{
|
||||
RsGxsIfaceHelper::receiveChanges(changes);
|
||||
std::cerr << "p3Posted::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 << "p3Posted::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 << "p3Posted::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 << "p3Posted::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 << "p3Posted::notifyChanges() Incoming Group: " << *git;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
changesForGUI.push_back(groupChange);
|
||||
}
|
||||
}
|
||||
changes.clear();
|
||||
RsGxsIfaceHelper::receiveChanges(changesForGUI);
|
||||
|
||||
std::cerr << "p3Posted::notifyChanges() -> receiveChanges()";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
void p3Posted::service_tick()
|
||||
{
|
||||
dummy_tick();
|
||||
RsTickEvent::tick_events();
|
||||
GxsTokenQueue::checkRequests();
|
||||
|
||||
mCommentService->comment_tick();
|
||||
|
||||
@ -130,6 +193,7 @@ bool p3Posted::getPostData(const uint32_t &token, std::vector<RsPostedPost> &msg
|
||||
{
|
||||
GxsMsgDataMap msgData;
|
||||
bool ok = RsGenExchange::getMsgData(token, msgData);
|
||||
time_t now = time(NULL);
|
||||
|
||||
if(ok)
|
||||
{
|
||||
@ -149,6 +213,8 @@ bool p3Posted::getPostData(const uint32_t &token, std::vector<RsPostedPost> &msg
|
||||
{
|
||||
RsPostedPost msg = item->mPost;
|
||||
msg.mMeta = item->meta;
|
||||
msg.calculateScores(now);
|
||||
|
||||
msgs.push_back(msg);
|
||||
delete item;
|
||||
}
|
||||
@ -169,6 +235,7 @@ bool p3Posted::getRelatedPosts(const uint32_t &token, std::vector<RsPostedPost>
|
||||
{
|
||||
GxsMsgRelatedDataMap msgData;
|
||||
bool ok = RsGenExchange::getMsgRelatedData(token, msgData);
|
||||
time_t now = time(NULL);
|
||||
|
||||
if(ok)
|
||||
{
|
||||
@ -187,6 +254,8 @@ bool p3Posted::getRelatedPosts(const uint32_t &token, std::vector<RsPostedPost>
|
||||
{
|
||||
RsPostedPost msg = item->mPost;
|
||||
msg.mMeta = item->meta;
|
||||
msg.calculateScores(now);
|
||||
|
||||
msgs.push_back(msg);
|
||||
delete item;
|
||||
}
|
||||
@ -207,50 +276,47 @@ bool p3Posted::getRelatedPosts(const uint32_t &token, std::vector<RsPostedPost>
|
||||
/********************************************************************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
bool p3Posted::requestPostRankings(uint32_t &token, const RankType &rType, uint32_t count, uint32_t page_no, const RsGxsGroupId &groupId)
|
||||
/* Switched from having explicit Ranking calculations to calculating the set of scores
|
||||
* on each RsPostedPost item.
|
||||
*
|
||||
* TODO: move this function to be part of RsPostedPost - then the GUI
|
||||
* can reuse is as necessary.
|
||||
*
|
||||
*/
|
||||
|
||||
bool RsPostedPost::calculateScores(time_t ref_time)
|
||||
{
|
||||
std::cerr << "p3Posted::requestPostRankings() doing boring call for now";
|
||||
std::cerr << std::endl;
|
||||
/* so we want to calculate all the scores for this Post. */
|
||||
|
||||
/* turn it into a boring Post Request for the moment */
|
||||
std::list<RsGxsGroupId> groups;
|
||||
groups.push_back(groupId);
|
||||
PostStats stats;
|
||||
extractPostedCache(mMeta.mServiceString, stats);
|
||||
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
|
||||
opts.mMsgFlagFilter = RsPosted::FLAG_MSGTYPE_POST;
|
||||
opts.mMsgFlagMask = RsPosted::FLAG_MSGTYPE_MASK;
|
||||
opts.mOptions = RS_TOKREQOPT_MSG_LATEST | RS_TOKREQOPT_MSG_THREAD;
|
||||
mUpVotes = stats.up_votes;
|
||||
mDownVotes = stats.down_votes;
|
||||
mComments = stats.comments;
|
||||
mHaveVoted = (mMeta.mMsgStatus & GXS_SERV::GXS_MSG_STATUS_VOTE_MASK);
|
||||
|
||||
RsGenExchange::getTokenService()->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, groups);
|
||||
time_t age_secs = ref_time - mMeta.mPublishTs;
|
||||
#define POSTED_AGESHIFT (2.0)
|
||||
#define POSTED_AGEFACTOR (3600.0)
|
||||
|
||||
mTopScore = ((int) mUpVotes - (int) mDownVotes);
|
||||
if (mTopScore > 0)
|
||||
{
|
||||
// score drops with time.
|
||||
mHotScore = mTopScore / pow(POSTED_AGESHIFT + age_secs / POSTED_AGEFACTOR, 1.5);
|
||||
}
|
||||
else
|
||||
{
|
||||
// gets more negative with time.
|
||||
mHotScore = mTopScore * pow(POSTED_AGESHIFT + age_secs / POSTED_AGEFACTOR, 1.5);
|
||||
}
|
||||
mNewScore = -age_secs;
|
||||
|
||||
/* what this should be doing ...
|
||||
* - Grab Public Token.
|
||||
* Trigger search for Post MetaData.
|
||||
* Score & Sort MetaData.
|
||||
* get Final list.
|
||||
* retrieve PostData.
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool p3Posted::getPostRanking(const uint32_t &token, std::vector<RsPostedPost> &msgs)
|
||||
{
|
||||
std::cerr << "p3Posted::getPostRanking() doing boring call for now";
|
||||
std::cerr << std::endl;
|
||||
|
||||
/* for the moment - this just returns the posts */
|
||||
return getPostData(token, msgs);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/********************************************************************************************/
|
||||
/********************************************************************************************/
|
||||
/********************************************************************************************/
|
||||
@ -298,6 +364,10 @@ void p3Posted::setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& ms
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/********************************************************************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
@ -481,7 +551,7 @@ bool p3Posted::generatePost(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())
|
||||
@ -526,7 +596,7 @@ bool p3Posted::generateComment(uint32_t &token, const RsGxsGroupId &grpId, const
|
||||
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())
|
||||
@ -560,7 +630,7 @@ bool p3Posted::generateGroup(uint32_t &token, std::string groupName)
|
||||
|
||||
|
||||
// Overloaded from RsTickEvent for Event callbacks.
|
||||
void p3Posted::handle_event(uint32_t event_type, const std::string &elabel)
|
||||
void p3Posted::handle_event(uint32_t event_type, const std::string & /* elabel */)
|
||||
{
|
||||
std::cerr << "p3Posted::handle_event(" << event_type << ")";
|
||||
std::cerr << std::endl;
|
||||
@ -572,6 +642,10 @@ void p3Posted::handle_event(uint32_t event_type, const std::string &elabel)
|
||||
generateDummyData();
|
||||
break;
|
||||
|
||||
case POSTED_BACKGROUND_PROCESSING:
|
||||
background_tick();
|
||||
break;
|
||||
|
||||
default:
|
||||
/* error */
|
||||
std::cerr << "p3Posted::handle_event() Unknown Event Type: " << event_type;
|
||||
@ -580,3 +654,539 @@ void p3Posted::handle_event(uint32_t event_type, const std::string &elabel)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************************
|
||||
* 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 p3Posted::background_tick()
|
||||
{
|
||||
|
||||
#if 0
|
||||
{
|
||||
RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/
|
||||
if (mBgGroupList.empty())
|
||||
{
|
||||
background_requestAllGroups();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
background_requestUnprocessedGroup();
|
||||
|
||||
RsTickEvent::schedule_in(POSTED_BACKGROUND_PROCESSING, PROCESSING_INC_PERIOD);
|
||||
|
||||
}
|
||||
|
||||
bool p3Posted::background_requestAllGroups()
|
||||
{
|
||||
std::cerr << "p3Posted::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, POSTED_ALL_GROUPS);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void p3Posted::background_loadGroups(const uint32_t &token)
|
||||
{
|
||||
/* get messages */
|
||||
std::cerr << "p3Posted::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 p3Posted::addGroupForProcessing(RsGxsGroupId grpId)
|
||||
{
|
||||
#ifdef POSTED_DEBUG
|
||||
std::cerr << "p3Posted::addGroupForProcessing(" << grpId << ")";
|
||||
std::cerr << std::endl;
|
||||
#endif // POSTED_DEBUG
|
||||
|
||||
{
|
||||
RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/
|
||||
// no point having multiple lookups queued.
|
||||
if (mBgGroupList.end() == std::find(mBgGroupList.begin(),
|
||||
mBgGroupList.end(), grpId))
|
||||
{
|
||||
mBgGroupList.push_back(grpId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void p3Posted::background_requestUnprocessedGroup()
|
||||
{
|
||||
#ifdef POSTED_DEBUG
|
||||
std::cerr << "p3Posted::background_requestUnprocessedGroup()";
|
||||
std::cerr << std::endl;
|
||||
#endif // POSTED_DEBUG
|
||||
|
||||
|
||||
RsGxsGroupId grpId;
|
||||
{
|
||||
RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/
|
||||
if (mBgProcessing)
|
||||
{
|
||||
std::cerr << "p3Posted::background_requestUnprocessedGroup() Already Active";
|
||||
std::cerr << std::endl;
|
||||
return;
|
||||
}
|
||||
if (mBgGroupList.empty())
|
||||
{
|
||||
std::cerr << "p3Posted::background_requestUnprocessedGroup() No Groups to Process";
|
||||
std::cerr << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
grpId = mBgGroupList.front();
|
||||
mBgGroupList.pop_front();
|
||||
mBgProcessing = true;
|
||||
}
|
||||
|
||||
background_requestGroupMsgs(grpId, true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void p3Posted::background_requestGroupMsgs(const RsGxsGroupId &grpId, bool unprocessedOnly)
|
||||
{
|
||||
std::cerr << "p3Posted::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, POSTED_UNPROCESSED_MSGS);
|
||||
}
|
||||
else
|
||||
{
|
||||
GxsTokenQueue::queueRequest(token, POSTED_ALL_MSGS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void p3Posted::background_loadUnprocessedMsgs(const uint32_t &token)
|
||||
{
|
||||
background_loadMsgs(token, true);
|
||||
}
|
||||
|
||||
|
||||
void p3Posted::background_loadAllMsgs(const uint32_t &token)
|
||||
{
|
||||
background_loadMsgs(token, false);
|
||||
}
|
||||
|
||||
|
||||
/* This function is generalised to support any collection of messages, across multiple groups */
|
||||
|
||||
void p3Posted::background_loadMsgs(const uint32_t &token, bool unprocessed)
|
||||
{
|
||||
/* get messages */
|
||||
std::cerr << "p3Posted::background_loadMsgs()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::map<RsGxsGroupId, std::vector<RsGxsMsgItem*> > msgData;
|
||||
bool ok = RsGenExchange::getMsgData(token, msgData);
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "p3Posted::background_loadMsgs() Failed to getMsgData()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
/* cleanup */
|
||||
background_cleanup();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
RsStackMutex stack(mPostedMtx); /********** 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(mPostedMtx); /********** STACK LOCKED MTX ******/
|
||||
if (mBgIncremental)
|
||||
{
|
||||
std::cerr << "p3Posted::background_loadMsgs() Msg already Processed - Skipping";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "p3Posted::background_loadMsgs() ERROR This should not happen";
|
||||
std::cerr << std::endl;
|
||||
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 << "p3Posted::background_processNewMessages() ERROR Strange NEW Message:";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "\t" << (*vit)->meta;
|
||||
std::cerr << std::endl;
|
||||
|
||||
}
|
||||
|
||||
if (inc_counters)
|
||||
{
|
||||
RsStackMutex stack(mPostedMtx); /********** 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* push updates of new Posts */
|
||||
if (msgChanges->msgChangeMap.size() > 0)
|
||||
{
|
||||
std::cerr << "p3Posted::background_processNewMessages() -> receiveChanges()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
changes.push_back(msgChanges);
|
||||
RsGxsIfaceHelper::receiveChanges(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, POSTED_BG_POST_META);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
#define RSGXS_MAX_SERVICE_STRING 1024
|
||||
bool encodePostedCache(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 extractPostedCache(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 p3Posted::background_updateVoteCounts(const uint32_t &token)
|
||||
{
|
||||
std::cerr << "p3Posted::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 << "p3Posted::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 << "p3Posted::background_updateVoteCounts() Processing Msg(" << mit->first;
|
||||
std::cerr << ", " << vit->mMsgId << ")";
|
||||
std::cerr << std::endl;
|
||||
|
||||
RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
/* extract current vote count */
|
||||
PostStats stats;
|
||||
if (mBgIncremental)
|
||||
{
|
||||
if (!extractPostedCache(vit->mServiceString, stats))
|
||||
{
|
||||
if (!(vit->mServiceString.empty()))
|
||||
{
|
||||
std::cerr << "p3Posted::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 << "p3Posted::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 << "p3Posted::background_updateVoteCounts() Warning No New Votes found.";
|
||||
std::cerr << " For MsgId: " << vit->mMsgId;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
std::string str;
|
||||
if (!encodePostedCache(str, stats))
|
||||
{
|
||||
std::cerr << "p3Posted::background_updateVoteCounts() Failed to encode Votes";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "p3Posted::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 << "p3Posted::background_updateVoteCounts() -> receiveChanges()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
changes.push_back(msgChanges);
|
||||
RsGxsIfaceHelper::receiveChanges(changes);
|
||||
}
|
||||
|
||||
// DONE!.
|
||||
background_cleanup();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool p3Posted::background_cleanup()
|
||||
{
|
||||
std::cerr << "p3Posted::background_cleanup()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
// Cleanup.
|
||||
mBgStatsMap.clear();
|
||||
mBgProcessing = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Overloaded from GxsTokenQueue for Request callbacks.
|
||||
void p3Posted::handleResponse(uint32_t token, uint32_t req_type)
|
||||
{
|
||||
std::cerr << "p3Posted::handleResponse(" << token << "," << req_type << ")";
|
||||
std::cerr << std::endl;
|
||||
|
||||
// stuff.
|
||||
switch(req_type)
|
||||
{
|
||||
case POSTED_ALL_GROUPS:
|
||||
background_loadGroups(token);
|
||||
break;
|
||||
case POSTED_UNPROCESSED_MSGS:
|
||||
background_loadUnprocessedMsgs(token);
|
||||
break;
|
||||
case POSTED_ALL_MSGS:
|
||||
background_loadAllMsgs(token);
|
||||
break;
|
||||
case POSTED_BG_POST_META:
|
||||
background_updateVoteCounts(token);
|
||||
break;
|
||||
default:
|
||||
/* error */
|
||||
std::cerr << "p3Posted::handleResponse() Unknown Request Type: " << req_type;
|
||||
std::cerr << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,14 +33,43 @@
|
||||
|
||||
#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 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 */
|
||||
{
|
||||
public:
|
||||
@ -54,6 +83,9 @@ virtual void service_tick();
|
||||
|
||||
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);
|
||||
|
||||
@ -66,13 +98,6 @@ virtual bool getRelatedPosts(const uint32_t &token, std::vector<RsPostedPost> &p
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// 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);
|
||||
@ -126,6 +151,36 @@ virtual bool acknowledgeVote(const uint32_t& token, std::pair<RsGxsGroupId, RsGx
|
||||
|
||||
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();
|
||||
@ -160,4 +215,12 @@ bool generateGroup(uint32_t &token, std::string groupName);
|
||||
p3GxsCommentService *mCommentService;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -43,7 +43,7 @@ RsWiki *rsWiki = NULL;
|
||||
#define DUMMYTICK_PERIOD 3
|
||||
|
||||
p3Wiki::p3Wiki(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs *gixs)
|
||||
:RsGenExchange(gds, nes, new RsGxsWikiSerialiser(), RS_SERVICE_GXSV1_TYPE_WIKI, gixs, wikiAuthenPolicy()),
|
||||
:RsGenExchange(gds, nes, new RsGxsWikiSerialiser(), RS_SERVICE_GXSV2_TYPE_WIKI, gixs, wikiAuthenPolicy()),
|
||||
RsWiki(this)
|
||||
{
|
||||
// Setup of dummy Pages.
|
||||
|
@ -36,7 +36,7 @@ RsWire *rsWire = NULL;
|
||||
|
||||
|
||||
p3Wire::p3Wire(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs *gixs)
|
||||
:RsGenExchange(gds, nes, new RsGxsWireSerialiser(), RS_SERVICE_GXSV1_TYPE_WIRE, gixs, wireAuthenPolicy()),
|
||||
:RsGenExchange(gds, nes, new RsGxsWireSerialiser(), RS_SERVICE_GXSV2_TYPE_WIRE, gixs, wireAuthenPolicy()),
|
||||
RsWire(this), mWireMtx("WireMtx")
|
||||
{
|
||||
|
||||
|
178
libretroshare/src/tests/gxs/gen_exchange/genexchange_test.pro
Normal file
178
libretroshare/src/tests/gxs/gen_exchange/genexchange_test.pro
Normal file
@ -0,0 +1,178 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2012-05-06T09:19:26
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
|
||||
#
|
||||
QT += core network
|
||||
|
||||
QT -= gui
|
||||
|
||||
CONFIG += gen_exchange_target
|
||||
|
||||
|
||||
CONFIG += bitdht
|
||||
|
||||
|
||||
|
||||
TARGET = gen_exchange_test
|
||||
|
||||
CONFIG += console
|
||||
CONFIG -= app_bundle
|
||||
|
||||
TEMPLATE = app
|
||||
|
||||
CONFIG += debug
|
||||
|
||||
debug {
|
||||
# DEFINES *= DEBUG
|
||||
# DEFINES *= OPENDHT_DEBUG DHT_DEBUG CONN_DEBUG DEBUG_UDP_SORTER P3DISC_DEBUG DEBUG_UDP_LAYER FT_DEBUG EXTADDRSEARCH_DEBUG
|
||||
# DEFINES *= CONTROL_DEBUG FT_DEBUG DEBUG_FTCHUNK P3TURTLE_DEBUG
|
||||
# DEFINES *= P3TURTLE_DEBUG
|
||||
# DEFINES *= NET_DEBUG
|
||||
# DEFINES *= DISTRIB_DEBUG
|
||||
# DEFINES *= P3TURTLE_DEBUG FT_DEBUG DEBUG_FTCHUNK MPLEX_DEBUG
|
||||
# DEFINES *= STATUS_DEBUG SERV_DEBUG RSSERIAL_DEBUG #CONN_DEBUG
|
||||
|
||||
QMAKE_CXXFLAGS -= -O2 -fomit-frame-pointer
|
||||
QMAKE_CXXFLAGS *= -g -fno-omit-frame-pointer
|
||||
}
|
||||
################################# Linux ##########################################
|
||||
# Put lib dir in QMAKE_LFLAGS so it appears before -L/usr/lib
|
||||
linux-* {
|
||||
#CONFIG += version_detail_bash_script
|
||||
QMAKE_CXXFLAGS *= -D_FILE_OFFSET_BITS=64
|
||||
|
||||
system(which gpgme-config >/dev/null 2>&1) {
|
||||
INCLUDEPATH += $$system(gpgme-config --cflags | sed -e "s/-I//g")
|
||||
} else {
|
||||
message(Could not find gpgme-config on your system, assuming gpgme.h is in /usr/include)
|
||||
}
|
||||
|
||||
PRE_TARGETDEPS *= ../../../lib/libretroshare.a
|
||||
|
||||
LIBS += ../../../lib/libretroshare.a
|
||||
LIBS += ../../../../../libbitdht/src/lib/libbitdht.a
|
||||
LIBS += ../../../../../openpgpsdk/src/lib/libops.a
|
||||
LIBS += -lssl -lgpgme -lupnp -lixml -lgnome-keyring -lsqlite3 -lbz2
|
||||
LIBS *= -rdynamic -frtti
|
||||
DEFINES *= HAVE_XSS # for idle time, libx screensaver extensions
|
||||
DEFINES *= UBUNTU
|
||||
}
|
||||
|
||||
linux-g++ {
|
||||
OBJECTS_DIR = temp/linux-g++/obj
|
||||
}
|
||||
|
||||
linux-g++-64 {
|
||||
OBJECTS_DIR = temp/linux-g++-64/obj
|
||||
}
|
||||
|
||||
#################################### Windows #####################################
|
||||
|
||||
win32 {
|
||||
|
||||
DEFINES *= WINDOWS_SYS \
|
||||
WIN32 \
|
||||
STATICLIB \
|
||||
MINGW
|
||||
# Switch on extra warnings
|
||||
QMAKE_CFLAGS += -Wextra
|
||||
QMAKE_CXXFLAGS += -Wextra
|
||||
|
||||
# Switch off optimization for release version
|
||||
QMAKE_CXXFLAGS_RELEASE -= -O2
|
||||
QMAKE_CXXFLAGS_RELEASE += -O0
|
||||
QMAKE_CFLAGS_RELEASE -= -O2
|
||||
QMAKE_CFLAGS_RELEASE += -O0
|
||||
|
||||
# Switch on optimization for debug version
|
||||
#QMAKE_CXXFLAGS_DEBUG += -O2
|
||||
#QMAKE_CFLAGS_DEBUG += -O2
|
||||
|
||||
# PRE_TARGETDEPS += ../../libretroshare/src/lib/libretroshare.a
|
||||
PRE_TARGETDEPS += ../../../../../libretroshare/libretroshare-build-desktop/lib/libretroshare.a
|
||||
|
||||
LIBS += ../../../../../libretroshare/libretroshare-build-desktop/lib/libretroshare.a
|
||||
LIBS += C:\Development\Rs\v0.5-gxs-b1\openpgpsdk\openpgpsdk-build-desktop\lib\libops.a
|
||||
LIBS += C:\Development\Libraries\sqlite\sqlite-autoconf-3070900\lib\libsqlite3.a
|
||||
LIBS += -L"../../../../../lib"
|
||||
LIBS += -lssl -lcrypto -lgpgme -lpthreadGC2d -lminiupnpc -lz -lbz2
|
||||
# added after bitdht
|
||||
# LIBS += -lws2_32
|
||||
LIBS += -luuid -lole32 -liphlpapi -lcrypt32-cygwin -lgdi32
|
||||
LIBS += -lole32 -lwinmm
|
||||
|
||||
# export symbols for the plugins
|
||||
#LIBS += -Wl,--export-all-symbols,--out-implib,lib/libretroshare-gui.a
|
||||
|
||||
GPG_ERROR_DIR = ../../../../libgpg-error-1.7
|
||||
GPGME_DIR = ../../../../gpgme-1.1.8
|
||||
GPG_ERROR_DIR = ../../../../lib/libgpg-error-1.7
|
||||
GPGME_DIR = ../../../../lib/gpgme-1.1.8
|
||||
SSL_DIR = ../../../../../OpenSSL
|
||||
OPENPGPSDK_DIR = ../../../../openpgpsdk/src
|
||||
INCLUDEPATH += . $${SSL_DIR}/include $${GPGME_DIR}/src $${GPG_ERROR_DIR}/src \
|
||||
$${OPENPGPSDK_DIR}
|
||||
|
||||
SQLITE_DIR = ../../../../../../Libraries/sqlite/sqlite-autoconf-3070900
|
||||
INCLUDEPATH += . \
|
||||
$${SQLITE_DIR}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
bitdht {
|
||||
|
||||
# Chris version.
|
||||
#LIBS += ../../libbitdht/libbitdht-build-desktop/lib/libbitdht.a
|
||||
#PRE_TARGETDEPS *= ../../libbitdht/libbitdht-build-desktop/lib/libbitdht.a
|
||||
}
|
||||
|
||||
win32 {
|
||||
# must be added after bitdht
|
||||
LIBS += -lws2_32
|
||||
}
|
||||
|
||||
version_detail_bash_script {
|
||||
DEFINES += ADD_LIBRETROSHARE_VERSION_INFO
|
||||
QMAKE_EXTRA_TARGETS += write_version_detail
|
||||
PRE_TARGETDEPS = write_version_detail
|
||||
write_version_detail.commands = ./version_detail.sh
|
||||
}
|
||||
|
||||
install_rs {
|
||||
INSTALLS += binary_rs
|
||||
binary_rs.path = $$(PREFIX)/usr/bin
|
||||
binary_rs.files = ./RetroShare
|
||||
}
|
||||
|
||||
|
||||
gen_exchange_target {
|
||||
|
||||
SOURCES += \
|
||||
../common/support.cc \
|
||||
genexchangetester.cpp \
|
||||
genexchangetestservice.cpp \
|
||||
rsdummyservices.cc \
|
||||
gxspublishgrouptest.cc \
|
||||
gxspublishmsgtest.cc \
|
||||
rsgenexchange_test.cc
|
||||
|
||||
HEADERS += ../common/support.h \
|
||||
../data_service/rsdataservice_test.h \
|
||||
gxspublishgrouptest.h \
|
||||
gxspublishmsgtest.h \
|
||||
rsdummyservices.h \
|
||||
../common/data_support.h \
|
||||
../common/support.h
|
||||
|
||||
}
|
||||
|
||||
|
||||
INCLUDEPATH += ../../../
|
||||
INCLUDEPATH += ../common
|
588
libretroshare/src/tests/gxs/gen_exchange/genexchangetester.cpp
Normal file
588
libretroshare/src/tests/gxs/gen_exchange/genexchangetester.cpp
Normal file
@ -0,0 +1,588 @@
|
||||
#include "genexchangetester.h"
|
||||
#include "support.h"
|
||||
#include "gxs/rsdataservice.h"
|
||||
#include "retroshare/rsgxsflags.h"
|
||||
|
||||
|
||||
GenExchangeTest::GenExchangeTest(GenExchangeTestService* const mTestService, RsGeneralDataService* dataService, int pollingTO)
|
||||
: mDataService(dataService), mTestService(mTestService), mTokenService(mTestService->getTokenService()),
|
||||
mPollingTO(pollingTO)
|
||||
{
|
||||
}
|
||||
|
||||
GenExchangeTest::~GenExchangeTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::pollForToken(uint32_t token, const RsTokReqOptions &opts, bool fill)
|
||||
{
|
||||
double timeDelta = 0.2;
|
||||
time_t now = time(NULL);
|
||||
time_t stopw = now + mPollingTO;
|
||||
|
||||
while(now < stopw)
|
||||
{
|
||||
#ifndef WINDOWS_SYS
|
||||
usleep((int) (timeDelta * 1000000));
|
||||
#else
|
||||
Sleep((int) (timeDelta * 1000));
|
||||
#endif
|
||||
|
||||
if((RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE == mTokenService->requestStatus(token)))
|
||||
{
|
||||
switch(opts.mReqType)
|
||||
{
|
||||
case GXS_REQUEST_TYPE_GROUP_DATA:
|
||||
if(fill)
|
||||
mTestService->getGroupDataTS(token, mGrpDataIn);
|
||||
break;
|
||||
case GXS_REQUEST_TYPE_GROUP_META:
|
||||
if(fill)
|
||||
mTestService->getGroupMetaTS(token, mGrpMetaDataIn);
|
||||
break;
|
||||
case GXS_REQUEST_TYPE_GROUP_IDS:
|
||||
if(fill)
|
||||
mTestService->getGroupListTS(token, mGrpIdsIn);
|
||||
break;
|
||||
case GXS_REQUEST_TYPE_MSG_DATA:
|
||||
if(fill)
|
||||
mTestService->getMsgDataTS(token, mMsgDataIn);
|
||||
break;
|
||||
case GXS_REQUEST_TYPE_MSG_META:
|
||||
if(fill)
|
||||
mTestService->getMsgMetaTS(token, mMsgMetaDataIn);
|
||||
break;
|
||||
case GXS_REQUEST_TYPE_MSG_IDS:
|
||||
if(fill)
|
||||
mTestService->getMsgListTS(token, mMsgIdsIn);
|
||||
break;
|
||||
case GXS_REQUEST_TYPE_MSG_RELATED_IDS:
|
||||
if(fill)
|
||||
mTestService->getMsgRelatedListTS(token, mMsgRelatedIdsIn);
|
||||
break;
|
||||
case GXS_REQUEST_TYPE_MSG_RELATED_DATA:
|
||||
if(fill)
|
||||
mTestService->getMsgRelatedDataTS(token, mMsgRelatedDataMapIn);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if(RsTokenService::GXS_REQUEST_V2_STATUS_FAILED == mTokenService->requestStatus(token))
|
||||
{
|
||||
mTokenService->cancelRequest(token);
|
||||
break;
|
||||
}
|
||||
now = time(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool GenExchangeTest::pollForMsgAcknowledgement(uint32_t token,
|
||||
RsGxsGrpMsgIdPair& msgId)
|
||||
{
|
||||
double timeDelta = 0.2;
|
||||
|
||||
time_t now = time(NULL);
|
||||
time_t stopw = now + mPollingTO;
|
||||
|
||||
while(now < stopw)
|
||||
{
|
||||
#ifndef WINDOWS_SYS
|
||||
usleep((int) (timeDelta * 1000000));
|
||||
#else
|
||||
Sleep((int) (timeDelta * 1000));
|
||||
#endif
|
||||
|
||||
if((RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE == mTokenService->requestStatus(token)))
|
||||
{
|
||||
mTestService->acknowledgeTokenMsg(token, msgId);
|
||||
return true;
|
||||
}
|
||||
else if(RsTokenService::GXS_REQUEST_V2_STATUS_FAILED == mTokenService->requestStatus(token))
|
||||
{
|
||||
mTokenService->cancelRequest(token);
|
||||
return false;
|
||||
}
|
||||
now = time(NULL);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
GenExchangeTestService* GenExchangeTest::getTestService()
|
||||
{
|
||||
return mTestService;
|
||||
}
|
||||
|
||||
RsTokenService* GenExchangeTest::getTokenService()
|
||||
{
|
||||
return mTokenService;
|
||||
}
|
||||
bool GenExchangeTest::pollForGrpAcknowledgement(uint32_t token,
|
||||
RsGxsGroupId& grpId)
|
||||
{
|
||||
double timeDelta = 0.2;
|
||||
time_t now = time(NULL);
|
||||
time_t stopw = now + mPollingTO;
|
||||
while(now < stopw)
|
||||
{
|
||||
#ifndef WINDOWS_SYS
|
||||
usleep((int) (timeDelta * 1000000));
|
||||
#else
|
||||
Sleep((int) (timeDelta * 1000));
|
||||
#endif
|
||||
|
||||
if((RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE == mTokenService->requestStatus(token)))
|
||||
{
|
||||
mTestService->acknowledgeTokenGrp(token, grpId);
|
||||
return true;
|
||||
}
|
||||
else if(RsTokenService::GXS_REQUEST_V2_STATUS_FAILED == mTokenService->requestStatus(token))
|
||||
{
|
||||
mTokenService->cancelRequest(token);
|
||||
return false;
|
||||
}
|
||||
now = time(NULL);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void GenExchangeTest::setUp()
|
||||
{
|
||||
mDataService->resetDataStore();
|
||||
|
||||
// would be useful for genexchange services
|
||||
// to have a protected reset button
|
||||
mTestService->start();
|
||||
}
|
||||
|
||||
void GenExchangeTest::breakDown()
|
||||
{
|
||||
mTestService->join();
|
||||
clearAllData();
|
||||
}
|
||||
|
||||
bool msgDataSort(const RsDummyMsg* m1, const RsDummyMsg* m2)
|
||||
{
|
||||
return m1->meta.mMsgId < m2->meta.mMsgId;
|
||||
}
|
||||
|
||||
bool GenExchangeTest::compareMsgDataMaps()
|
||||
{
|
||||
DummyMsgMap::iterator mit = mMsgDataOut.begin();
|
||||
|
||||
bool ok = true;
|
||||
for(; mit != mMsgDataOut.end(); mit++)
|
||||
{
|
||||
const RsGxsGroupId& grpId = mit->first;
|
||||
std::vector<RsDummyMsg*>& v1 = mit->second,
|
||||
&v2 = mMsgDataIn[grpId];
|
||||
|
||||
if(v1.size() != v2.size())
|
||||
return false;
|
||||
|
||||
std::sort(v1.begin(), v1.end(), msgDataSort);
|
||||
std::sort(v2.begin(), v2.end(), msgDataSort);
|
||||
|
||||
ok &= Comparison<std::vector<RsDummyMsg*>, RsDummyMsg*>::comparison(v1, v2);
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
bool GenExchangeTest::compareMsgIdMaps()
|
||||
{
|
||||
GxsMsgIdResult::const_iterator mit = mMsgIdsOut.begin();
|
||||
bool ok = true;
|
||||
for(; mit != mMsgIdsOut.end(); mit++)
|
||||
{
|
||||
const RsGxsGroupId& grpId = mit->first;
|
||||
const std::vector<RsGxsMessageId>& v1 = mit->second,
|
||||
&v2 = mMsgIdsIn[grpId];
|
||||
|
||||
ok &= Comparison<std::vector<RsGxsMessageId>, RsGxsMessageId>::comparison(v1, v2);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
bool GenExchangeTest::compareMsgMetaMaps()
|
||||
{
|
||||
GxsMsgMetaMap::iterator mit = mMsgMetaDataOut.begin();
|
||||
bool ok = true;
|
||||
for(; mit != mMsgMetaDataOut.end(); mit++)
|
||||
{
|
||||
const RsGxsGroupId& grpId = mit->first;
|
||||
const std::vector<RsMsgMetaData>& v1 = mit->second,
|
||||
&v2 = mMsgMetaDataOut[grpId];
|
||||
ok &= Comparison<std::vector<RsMsgMetaData>, RsMsgMetaData>::comparison(v1, v2);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
bool GenExchangeTest::compareMsgRelateIdsMap()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool GenExchangeTest::compareMsgRelatedDataMap()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool grpDataSort(const RsDummyGrp* g1, const RsDummyGrp* g2)
|
||||
{
|
||||
return g1->meta.mGroupId < g2->meta.mGroupId;
|
||||
}
|
||||
|
||||
bool GenExchangeTest::compareGrpData()
|
||||
{
|
||||
|
||||
std::sort(mGrpDataIn.begin(), mGrpDataIn.end(), grpDataSort);
|
||||
std::sort(mGrpDataOut.begin(), mGrpDataOut.end(), grpDataSort);
|
||||
bool ok = Comparison<std::vector<RsDummyGrp*>, RsDummyGrp*>::comparison
|
||||
(mGrpDataIn, mGrpDataOut);
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool operator<(const RsGroupMetaData& l, const RsGroupMetaData& r)
|
||||
{
|
||||
return l.mGroupId < r.mGroupId;
|
||||
}
|
||||
|
||||
bool GenExchangeTest::compareGrpMeta()
|
||||
{
|
||||
|
||||
mGrpMetaDataIn.sort();
|
||||
mGrpMetaDataOut.sort();
|
||||
|
||||
bool ok = Comparison<std::list<RsGroupMetaData>, RsGroupMetaData>::comparison
|
||||
(mGrpMetaDataIn, mGrpMetaDataOut);
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
bool GenExchangeTest::compareGrpIds()
|
||||
{
|
||||
mGrpIdsIn.sort();
|
||||
mGrpIdsOut.sort();
|
||||
bool ok = Comparison<std::list<RsGxsGroupId>, RsGxsGroupId>::comparison
|
||||
(mGrpIdsIn, mGrpIdsOut);
|
||||
return ok;
|
||||
}
|
||||
|
||||
void GenExchangeTest::createGrps(uint32_t nGrps,
|
||||
std::list<RsGxsGroupId>& groupId)
|
||||
{
|
||||
// create n groups and publish all nGrps and collect id information
|
||||
for(uint32_t i=0; i < nGrps; i++)
|
||||
{
|
||||
RsDummyGrp* grp = new RsDummyGrp();
|
||||
init(*grp);
|
||||
uint32_t token;
|
||||
mTestService->publishDummyGrp(token, grp);
|
||||
RsGxsGroupId grpId;
|
||||
pollForGrpAcknowledgement(token, grpId);
|
||||
groupId.push_back(grpId);
|
||||
}
|
||||
}
|
||||
|
||||
void GenExchangeTest::init(RsMsgMetaData& msgMetaData) const
|
||||
{
|
||||
//randString(SHORT_STR, msgMeta.mAuthorId);
|
||||
randString(SHORT_STR, msgMetaData.mMsgName);
|
||||
randString(SHORT_STR, msgMetaData.mServiceString);
|
||||
randString(SHORT_STR, msgMetaData.mOrigMsgId);
|
||||
randString(SHORT_STR, msgMetaData.mParentId);
|
||||
randString(SHORT_STR, msgMetaData.mThreadId);
|
||||
randString(SHORT_STR, msgMetaData.mGroupId);
|
||||
|
||||
msgMetaData.mChildTs = randNum();
|
||||
msgMetaData.mMsgStatus = randNum();
|
||||
msgMetaData.mMsgFlags = randNum();
|
||||
msgMetaData.mPublishTs = randNum();
|
||||
}
|
||||
|
||||
uint32_t GenExchangeTest::randNum() const
|
||||
{
|
||||
return rand()%23562424;
|
||||
}
|
||||
|
||||
void GenExchangeTest::init(RsGroupMetaData& grpMetaData) const
|
||||
{
|
||||
randString(SHORT_STR, grpMetaData.mGroupId);
|
||||
//randString(SHORT_STR, grpMetaData.mAuthorId);
|
||||
randString(SHORT_STR, grpMetaData.mGroupName);
|
||||
randString(SHORT_STR, grpMetaData.mServiceString);
|
||||
|
||||
|
||||
grpMetaData.mGroupFlags = randNum();
|
||||
grpMetaData.mLastPost = randNum();
|
||||
grpMetaData.mGroupStatus = randNum();
|
||||
grpMetaData.mMsgCount = randNum();
|
||||
grpMetaData.mPop = randNum();
|
||||
grpMetaData.mSignFlags = randNum();
|
||||
grpMetaData.mPublishTs = randNum();
|
||||
grpMetaData.mSubscribeFlags = GXS_SERV::GROUP_SUBSCRIBE_ADMIN;
|
||||
}
|
||||
|
||||
void GenExchangeTest::init(RsDummyGrp& grpItem) const
|
||||
{
|
||||
randString(SHORT_STR, grpItem.grpData);
|
||||
init(grpItem.meta);
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::init(RsDummyMsg& msgItem) const
|
||||
{
|
||||
randString(SHORT_STR, msgItem.msgData);
|
||||
init(msgItem.meta);
|
||||
}
|
||||
|
||||
void GenExchangeTest::storeToMsgDataOutMaps(const DummyMsgMap& msgDataOut)
|
||||
{
|
||||
mMsgDataOut.insert(msgDataOut.begin(), msgDataOut.end());
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::storeToMsgIdsOutMaps(const GxsMsgIdResult& msgIdsOut)
|
||||
{
|
||||
mMsgIdsOut.insert(msgIdsOut.begin(), msgIdsOut.end());
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::storeToMsgMetaOutMaps(const GxsMsgMetaMap& msgMetaOut)
|
||||
{
|
||||
mMsgMetaDataOut.insert(msgMetaOut.begin(), msgMetaOut.end());
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::storeToMsgDataInMaps(const DummyMsgMap& msgDataIn)
|
||||
{
|
||||
mMsgDataIn.insert(msgDataIn.begin(), msgDataIn.end());
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::storeToMsgIdsInMaps(const GxsMsgIdResult& msgIdsIn)
|
||||
{
|
||||
mMsgIdsIn.insert(msgIdsIn.begin(), msgIdsIn.end());
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::storeToMsgMetaInMaps(const GxsMsgMetaMap& msgMetaIn)
|
||||
{
|
||||
mMsgMetaDataIn.insert(msgMetaIn.begin(), msgMetaIn.end());
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::storeToGrpIdsOutList(
|
||||
const std::list<RsGxsGroupId>& grpIdOut)
|
||||
{
|
||||
mGrpIdsOut.insert(mGrpIdsOut.end(), grpIdOut.begin(), grpIdOut.end());
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::storeToGrpMetaOutList(
|
||||
const std::list<RsGroupMetaData>& grpMetaOut)
|
||||
{
|
||||
mGrpMetaDataOut.insert(mGrpMetaDataOut.end(), grpMetaOut.begin(), grpMetaOut.end());
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::storeToGrpDataOutList(
|
||||
const std::vector<RsDummyGrp*>& grpDataOut)
|
||||
{
|
||||
mGrpDataOut.insert(mGrpDataOut.end(), grpDataOut.begin(), grpDataOut.end());
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::storeToGrpIdsInList(
|
||||
const std::list<RsGxsGroupId>& grpIdIn)
|
||||
{
|
||||
mGrpIdsIn.insert(mGrpIdsIn.end(), grpIdIn.begin(), grpIdIn.end());
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::storeToGrpMetaInList(
|
||||
const std::list<RsGroupMetaData>& grpMetaIn)
|
||||
{
|
||||
mGrpMetaDataIn.insert(mGrpMetaDataIn.end(), grpMetaIn.begin(), grpMetaIn.end());
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::storeToGrpDataInList(
|
||||
const std::vector<RsDummyGrp*>& grpDataIn)
|
||||
{
|
||||
mGrpDataIn.insert(mGrpDataIn.begin(), grpDataIn.begin(), grpDataIn.end());
|
||||
}
|
||||
void GenExchangeTest::clearAllData()
|
||||
{
|
||||
clearMsgDataInMap();
|
||||
clearMsgDataOutMap();
|
||||
clearMsgIdInMap();
|
||||
clearMsgIdOutMap();
|
||||
clearMsgMetaInMap();
|
||||
clearMsgMetaOutMap();
|
||||
clearGrpDataInList();
|
||||
clearGrpDataOutList();
|
||||
clearGrpMetaInList();
|
||||
clearGrpMetaOutList();
|
||||
clearGrpIdInList();
|
||||
clearGrpIdOutList();
|
||||
}
|
||||
void GenExchangeTest::clearMsgDataInMap()
|
||||
{
|
||||
mMsgDataIn.clear();
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::clearMsgDataOutMap()
|
||||
{
|
||||
|
||||
clearMsgDataMap(mMsgDataOut);
|
||||
}
|
||||
|
||||
void GenExchangeTest::clearMsgDataMap(DummyMsgMap& msgDataMap) const
|
||||
{
|
||||
DummyMsgMap::iterator it = msgDataMap.begin();
|
||||
|
||||
for(; it != msgDataMap.end(); it++)
|
||||
{
|
||||
deleteResVector<RsDummyMsg>(it->second);
|
||||
}
|
||||
}
|
||||
|
||||
void GenExchangeTest::clearMsgMetaInMap()
|
||||
{
|
||||
mMsgMetaDataIn.clear();
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::clearMsgMetaOutMap()
|
||||
{
|
||||
mMsgMetaDataOut.clear();
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::clearMsgIdInMap()
|
||||
{
|
||||
mMsgIdsIn.clear();
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::clearMsgIdOutMap()
|
||||
{
|
||||
mMsgIdsOut.clear();
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::clearMsgRelatedIdInMap()
|
||||
{
|
||||
mMsgRelatedIdsIn.clear();
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::clearGrpDataInList()
|
||||
{
|
||||
clearGrpDataList(mGrpDataIn);
|
||||
}
|
||||
|
||||
void GenExchangeTest::clearGrpDataList(std::vector<RsDummyGrp*>& grpData) const
|
||||
{
|
||||
deleteResVector<RsDummyGrp>(grpData);
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::clearGrpDataOutList()
|
||||
{
|
||||
clearGrpDataList(mGrpDataOut);
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::clearGrpMetaInList()
|
||||
{
|
||||
mGrpMetaDataIn.clear();
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::clearGrpMetaOutList()
|
||||
{
|
||||
mGrpMetaDataOut.clear();
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::clearGrpIdInList()
|
||||
{
|
||||
mGrpIdsIn.clear();
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::clearGrpIdOutList()
|
||||
{
|
||||
mGrpIdsOut.clear();
|
||||
}
|
||||
|
||||
|
||||
bool operator ==(const RsMsgMetaData& lMeta, const RsMsgMetaData& rMeta)
|
||||
{
|
||||
|
||||
if(lMeta.mAuthorId != rMeta.mAuthorId) return false;
|
||||
if(lMeta.mChildTs != rMeta.mChildTs) return false;
|
||||
if(lMeta.mGroupId != rMeta.mGroupId) return false;
|
||||
if(lMeta.mMsgFlags != rMeta.mMsgFlags) return false;
|
||||
if(lMeta.mMsgId != rMeta.mMsgId) return false;
|
||||
if(lMeta.mMsgName != rMeta.mMsgName) return false;
|
||||
//if(lMeta.mMsgStatus != rMeta.mMsgStatus) return false;
|
||||
if(lMeta.mOrigMsgId != rMeta.mOrigMsgId) return false;
|
||||
if(lMeta.mParentId != rMeta.mParentId) return false;
|
||||
//if(lMeta.mPublishTs != rMeta.mPublishTs) return false; // don't compare this as internally set in gxs
|
||||
if(lMeta.mThreadId != rMeta.mThreadId) return false;
|
||||
if(lMeta.mServiceString != rMeta.mServiceString) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator ==(const RsGroupMetaData& lMeta, const RsGroupMetaData& rMeta)
|
||||
{
|
||||
if(lMeta.mAuthorId != rMeta.mAuthorId) return false;
|
||||
if(lMeta.mGroupFlags != rMeta.mGroupFlags) return false;
|
||||
if(lMeta.mGroupId != rMeta.mGroupId) return false;
|
||||
if(lMeta.mGroupName != rMeta.mGroupName) return false;
|
||||
if(lMeta.mGroupStatus != rMeta.mGroupStatus) return false;
|
||||
if(lMeta.mLastPost != rMeta.mLastPost) return false;
|
||||
if(lMeta.mMsgCount != rMeta.mMsgCount) return false;
|
||||
if(lMeta.mPop != rMeta.mPop) return false;
|
||||
// if(lMeta.mPublishTs != rMeta.mPublishTs) return false; set in gxs
|
||||
if(lMeta.mServiceString != rMeta.mServiceString) return false;
|
||||
if(lMeta.mSignFlags != rMeta.mSignFlags) return false;
|
||||
// if(lMeta.mSubscribeFlags != rMeta.mSubscribeFlags) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator ==(const RsDummyGrp& lGrp, const RsDummyGrp& rGrp)
|
||||
{
|
||||
|
||||
if(lGrp.grpData != rGrp.grpData) return false;
|
||||
if(! (lGrp.meta == rGrp.meta)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator ==(const RsDummyMsg& lMsg, const RsDummyMsg& rMsg)
|
||||
{
|
||||
if(lMsg.msgData != rMsg.msgData) return false;
|
||||
if(!(lMsg.meta == rMsg.meta)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator ==(const RsGxsGrpItem& lGrp, const RsGxsGrpItem& rGrp)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
278
libretroshare/src/tests/gxs/gen_exchange/genexchangetester.h
Normal file
278
libretroshare/src/tests/gxs/gen_exchange/genexchangetester.h
Normal file
@ -0,0 +1,278 @@
|
||||
#ifndef GENEXCHANGETESTER_H
|
||||
#define GENEXCHANGETESTER_H
|
||||
|
||||
#include "genexchangetestservice.h"
|
||||
#include "gxs/rsgds.h"
|
||||
#include "gxs/rsnxs.h"
|
||||
|
||||
bool operator ==(const RsMsgMetaData& lMeta, const RsMsgMetaData& rMeta);
|
||||
bool operator ==(const RsDummyMsg& lMsg, const RsDummyMsg& rMsg);
|
||||
bool operator ==(const RsGxsGrpItem& lMsg, const RsGxsGrpItem& rMsg);
|
||||
|
||||
bool operator ==(const RsGroupMetaData& lMeta, const RsGroupMetaData& rMeta);
|
||||
bool operator ==(const RsDummyGrp& lMsg, const RsDummyGrp& rMsg);
|
||||
bool operator ==(const RsGxsMsgItem& lMsg, const RsGxsMsgItem& rMsg);
|
||||
|
||||
/*!
|
||||
* The idea of GenExchangeTest is to simplify test
|
||||
* of the RsGenExchange via the RsGxsDummyService
|
||||
* One can test all publish/request/meta-modify
|
||||
* capabilities of RsGenExchange
|
||||
* Simplifications comes from: \n
|
||||
*
|
||||
* - ability to store in and out data for comparison (in data are
|
||||
* usually from requests, out data are from publications,
|
||||
* but generally what you want to compare) \n
|
||||
* - convenience function to poll tokens \n
|
||||
* - also allows filling in-data automatically from polls \n
|
||||
* - convenience interface for running tests
|
||||
*/
|
||||
class GenExchangeTest
|
||||
{
|
||||
public:
|
||||
|
||||
/*!
|
||||
* Constructs the GenExchangeTest with a tokenService
|
||||
* @param tokenService This is needed. If not an instance of token service,
|
||||
* behaviour of GenExchangeTest is undefined
|
||||
*/
|
||||
GenExchangeTest(GenExchangeTestService* const mTestService, RsGeneralDataService* dataService, int pollingTO = 5 /* 5 secs default */);
|
||||
|
||||
virtual ~GenExchangeTest();
|
||||
|
||||
/*!
|
||||
* This should be called in the main
|
||||
* routines to execute all tests
|
||||
* When implementing ensure units test header
|
||||
* is in same file scope as implementation
|
||||
* (you chould be using the CHECK functions
|
||||
* to assert tests has passed)
|
||||
*/
|
||||
virtual void runTests() = 0;
|
||||
|
||||
protected:
|
||||
|
||||
/*!
|
||||
* After each request and publish operation this should
|
||||
* be called to ensure the operation has completed
|
||||
* Requests will result in in data maps being filled
|
||||
* @param
|
||||
* @param opts
|
||||
* @param fill if set to true, the received that is
|
||||
* routed to IN data structures
|
||||
*/
|
||||
void pollForToken(uint32_t token, const RsTokReqOptions& opts, bool fill = false);
|
||||
|
||||
/*!
|
||||
* Allows to poll for token, and receive the message id
|
||||
* as acknowledgement. This function blocks for as long the
|
||||
* timeout value set on construction of tester
|
||||
* @param token
|
||||
* @param msgId
|
||||
*/
|
||||
bool pollForMsgAcknowledgement(uint32_t token, RsGxsGrpMsgIdPair& msgId);
|
||||
|
||||
/*!
|
||||
* Allows to poll for token, and receive the group id
|
||||
* as acknowledgement. This function blocks for as long the
|
||||
* timeout value set on construction of tester
|
||||
* @param token
|
||||
* @param msgId
|
||||
*/
|
||||
bool pollForGrpAcknowledgement(uint32_t token, RsGxsGroupId& msgId);
|
||||
|
||||
GenExchangeTestService* getTestService();
|
||||
RsTokenService* getTokenService();
|
||||
// bool testGrpMetaModRequest();
|
||||
// bool testMsgMetaModRequest();
|
||||
|
||||
// convenience functions for clearing IN and OUT data structures
|
||||
void clearMsgDataInMap();
|
||||
void clearMsgDataOutMap();
|
||||
void clearMsgMetaInMap();
|
||||
void clearMsgMetaOutMap();
|
||||
void clearMsgIdInMap();
|
||||
void clearMsgIdOutMap();
|
||||
void clearMsgRelatedIdInMap();
|
||||
void clearGrpDataInList();
|
||||
void clearGrpDataOutList();
|
||||
void clearGrpMetaInList();
|
||||
void clearGrpMetaOutList();
|
||||
void clearGrpIdInList();
|
||||
void clearGrpIdOutList();
|
||||
|
||||
/*!
|
||||
* clears up all internal
|
||||
* IN and OUT data structure for
|
||||
* both msgs and groups
|
||||
* frees resources in relation to allocated data
|
||||
*/
|
||||
void clearAllData();
|
||||
|
||||
template <class Item>
|
||||
void deleteResVector(std::vector<Item*>& v) const
|
||||
{
|
||||
typename std::vector<Item*>::iterator vit = v.begin();
|
||||
for(; vit != v.end(); vit++)
|
||||
delete *vit;
|
||||
v.clear();
|
||||
}
|
||||
|
||||
// using class to enable partial
|
||||
// function specialisation, bit of a hack in a
|
||||
// way
|
||||
template <class Cont, class Item>
|
||||
class Comparison
|
||||
{
|
||||
public:
|
||||
|
||||
static bool comparison(const Cont& l, const Cont& r)
|
||||
{
|
||||
if(l.size() != r.size()) return false;
|
||||
|
||||
typename Cont::const_iterator vit1 = l.begin(), vit2 = r.begin();
|
||||
|
||||
while(vit1 != l.end())
|
||||
{
|
||||
const Item& item1 = (*vit1);
|
||||
const Item& item2 = (*vit2);
|
||||
if(!(item1 == item2)) return false;
|
||||
|
||||
vit1++;
|
||||
vit2++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class Cont, class Item>
|
||||
class Comparison<Cont, Item*>
|
||||
{
|
||||
public:
|
||||
|
||||
static bool comparison(const Cont& l, const Cont& r)
|
||||
{
|
||||
if(l.size() != r.size())
|
||||
return false;
|
||||
|
||||
typename Cont::const_iterator vit1 = l.begin(), vit2 = r.begin();
|
||||
|
||||
while(vit1 != l.end())
|
||||
{
|
||||
const Item* item1 = (*vit1);
|
||||
const Item* item2 = (*vit2);
|
||||
if(!(*item1 == *item2))
|
||||
return false;
|
||||
|
||||
vit1++;
|
||||
vit2++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// convenience function for comparing IN and OUT data structures
|
||||
bool compareMsgDataMaps() ;
|
||||
bool compareMsgIdMaps() ;
|
||||
bool compareMsgMetaMaps() ;
|
||||
bool compareMsgRelateIdsMap() ;
|
||||
bool compareMsgRelatedDataMap() ;
|
||||
bool compareGrpData() ;
|
||||
bool compareGrpMeta() ;
|
||||
bool compareGrpIds() ;
|
||||
|
||||
void storeToMsgDataOutMaps(const DummyMsgMap& msgDataOut);
|
||||
void storeToMsgIdsOutMaps(const GxsMsgIdResult& msgIdsOut);
|
||||
void storeToMsgMetaOutMaps(const GxsMsgMetaMap& msgMetaOut);
|
||||
|
||||
void storeToMsgDataInMaps(const DummyMsgMap& msgDataOut);
|
||||
void storeToMsgIdsInMaps(const GxsMsgIdResult& msgIdsOut);
|
||||
void storeToMsgMetaInMaps(const GxsMsgMetaMap& msgMetaOut);
|
||||
|
||||
void storeToGrpIdsOutList(const std::list<RsGxsGroupId>& grpIdOut);
|
||||
void storeToGrpMetaOutList(const std::list<RsGroupMetaData>& grpMetaOut);
|
||||
void storeToGrpDataOutList(const std::vector<RsDummyGrp*>& grpDataOut);
|
||||
|
||||
void storeToGrpIdsInList(const std::list<RsGxsGroupId>& grpIdIn);
|
||||
void storeToGrpMetaInList(const std::list<RsGroupMetaData>& grpMetaOut);
|
||||
void storeToGrpDataInList(const std::vector<RsDummyGrp*>& grpDataOut);
|
||||
|
||||
/*!
|
||||
* This sets up any resources required to operate a test
|
||||
*/
|
||||
void setUp();
|
||||
|
||||
/*!
|
||||
* Call at end of test to ensure resources
|
||||
* used in tests are released
|
||||
* This can invalidate other test runs if not called
|
||||
*/
|
||||
void breakDown();
|
||||
|
||||
/*!
|
||||
* initialises item to random data
|
||||
* @param grpItem item to initialise
|
||||
*/
|
||||
void init(RsDummyGrp& grpItem) const;
|
||||
|
||||
/*!
|
||||
* Initialises meta data to random data
|
||||
* @param grpMetaData
|
||||
*/
|
||||
void init(RsGroupMetaData& grpMetaData) const;
|
||||
|
||||
/*!
|
||||
* Initialises msg item to random data
|
||||
* @param msgItem
|
||||
*/
|
||||
void init(RsDummyMsg& msgItem) const;
|
||||
|
||||
/*!
|
||||
* Initialises meta data to random data
|
||||
* @param msgMetaData
|
||||
*/
|
||||
void init(RsMsgMetaData& msgMetaData) const;
|
||||
|
||||
|
||||
void clearMsgDataMap(DummyMsgMap& msgDataMap) const;
|
||||
void clearGrpDataList(std::vector<RsDummyGrp*>& grpData) const;
|
||||
|
||||
/*!
|
||||
* Helper function which sets up groups
|
||||
* data in to be used for publication
|
||||
* group data
|
||||
* @param nGrps number of groups to publish
|
||||
* @param groupId the ids for the created groups
|
||||
*/
|
||||
void createGrps(uint32_t nGrps, std::list<RsGxsGroupId>& groupId);
|
||||
|
||||
/*!
|
||||
* @return random number
|
||||
*/
|
||||
uint32_t randNum() const;
|
||||
|
||||
private:
|
||||
|
||||
std::vector<RsDummyGrp*> mGrpDataOut, mGrpDataIn;
|
||||
std::list<RsGroupMetaData> mGrpMetaDataOut, mGrpMetaDataIn;
|
||||
std::list<RsGxsGroupId> mGrpIdsOut, mGrpIdsIn;
|
||||
|
||||
DummyMsgMap mMsgDataOut, mMsgDataIn;
|
||||
GxsMsgMetaMap mMsgMetaDataOut, mMsgMetaDataIn;
|
||||
GxsMsgIdResult mMsgIdsOut, mMsgIdsIn;
|
||||
|
||||
MsgRelatedIdResult mMsgRelatedIdsOut, mMsgRelatedIdsIn;
|
||||
GxsMsgRelatedDataMap mMsgRelatedDataMapOut, mMsgRelatedDataMapIn;
|
||||
|
||||
std::vector<RsGxsGroupId> mRandGrpIds; // ids that exist to help group testing
|
||||
|
||||
private:
|
||||
|
||||
RsGeneralDataService* mDataService;
|
||||
GenExchangeTestService* mTestService;
|
||||
RsTokenService* mTokenService;
|
||||
int mPollingTO;
|
||||
};
|
||||
|
||||
#endif // GENEXCHANGETESTER_H
|
@ -1,8 +1,8 @@
|
||||
#include "genexchangetestservice.h"
|
||||
|
||||
GenExchangeTestService::GenExchangeTestService(RsGeneralDataService *dataServ, RsNetworkExchangeService * netService,
|
||||
RsGixs* gixs, uint32_t authenPolicy)
|
||||
: RsGenExchange(dataServ, netService, new RsDummySerialiser(), RS_SERVICE_TYPE_DUMMY, gixs, authenPolicy)
|
||||
RsGixs* gixs)
|
||||
: RsGenExchange(dataServ, netService, new RsDummySerialiser(), RS_SERVICE_TYPE_DUMMY, gixs, 0)
|
||||
{
|
||||
|
||||
}
|
||||
@ -32,14 +32,14 @@ bool GenExchangeTestService::getGroupMetaTS(const uint32_t &token, std::list<RsG
|
||||
return getGroupMeta(token, groupInfo);
|
||||
}
|
||||
|
||||
bool GenExchangeTestService::getGroupDataTS(const uint32_t &token, std::vector<RsGxsGrpItem *> &grpItem)
|
||||
bool GenExchangeTestService::getGroupDataTS(const uint32_t &token, std::vector<RsDummyGrp *>& grpItem)
|
||||
{
|
||||
return getGroupData(token, grpItem);
|
||||
return getGroupDataT<RsDummyGrp>(token, grpItem);
|
||||
}
|
||||
|
||||
bool GenExchangeTestService::getMsgDataTS(const uint32_t &token, GxsMsgDataMap &msgItems)
|
||||
bool GenExchangeTestService::getMsgDataTS(const uint32_t &token, DummyMsgMap &msgItems)
|
||||
{
|
||||
return getMsgData(token, msgItems);
|
||||
return getMsgDataT<RsDummyMsg>(token, msgItems);
|
||||
}
|
||||
|
||||
bool GenExchangeTestService::getMsgRelatedDataTS(const uint32_t &token, GxsMsgRelatedDataMap &msgItems)
|
@ -5,17 +5,18 @@
|
||||
#include "retroshare/rsgxsifacehelper.h"
|
||||
#include "rsdummyservices.h"
|
||||
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsDummyMsg*> > DummyMsgMap;
|
||||
|
||||
class GenExchangeTestService : public RsGenExchange
|
||||
{
|
||||
public:
|
||||
GenExchangeTestService(RsGeneralDataService* dataServ, RsNetworkExchangeService*, RsGixs* gixs, uint32_t authenPolicy);
|
||||
GenExchangeTestService(RsGeneralDataService* dataServ, RsNetworkExchangeService* nxs, RsGixs* gixs);
|
||||
|
||||
void notifyChanges(std::vector<RsGxsNotify*>& changes);
|
||||
|
||||
void publishDummyGrp(uint32_t& token, RsDummyGrp* grp);
|
||||
void publishDummyMsg(uint32_t& token, RsDummyMsg* msg);
|
||||
|
||||
|
||||
/*!
|
||||
* Retrieve group list for a given token
|
||||
* @param token
|
||||
@ -51,14 +52,16 @@ public:
|
||||
* @param token token to be redeemed for grpitem retrieval
|
||||
* @param grpItem the items to be retrieved for token are stored here
|
||||
*/
|
||||
bool getGroupDataTS(const uint32_t &token, std::vector<RsGxsGrpItem*>& grpItem);
|
||||
bool getGroupDataTS(const uint32_t &token, std::vector<RsDummyGrp*>& grpItem);
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
* retrieves message data associated to a request token
|
||||
* @param token token to be redeemed for message item retrieval
|
||||
* @param msgItems
|
||||
*/
|
||||
bool getMsgDataTS(const uint32_t &token, GxsMsgDataMap& msgItems);
|
||||
bool getMsgDataTS(const uint32_t &token, DummyMsgMap& msgItems);
|
||||
|
||||
/*!
|
||||
* Retrieve msg related list for a given token sectioned by group Ids
|
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* gxsmsgrelatedtest.cpp
|
||||
*
|
||||
* Created on: 27 Apr 2013
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#include "gxsmsgrelatedtest.h"
|
||||
|
||||
GxsMsgRelatedTest::GxsMsgRelatedTest() {
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
}
|
||||
|
||||
GxsMsgRelatedTest::~GxsMsgRelatedTest() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
25
libretroshare/src/tests/gxs/gen_exchange/gxsmsgrelatedtest.h
Normal file
25
libretroshare/src/tests/gxs/gen_exchange/gxsmsgrelatedtest.h
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* gxsmsgrelatedtest.h
|
||||
*
|
||||
* Created on: 27 Apr 2013
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#ifndef GXSMSGRELATEDTEST_H_
|
||||
#define GXSMSGRELATEDTEST_H_
|
||||
|
||||
#include "genexchangetester.h"
|
||||
|
||||
class GxsMsgRelatedTest: public GenExchangeTest {
|
||||
public:
|
||||
GxsMsgRelatedTest();
|
||||
virtual ~GxsMsgRelatedTest();
|
||||
|
||||
// request msg related tests
|
||||
bool testMsgRelatedChildIdRetrieval();
|
||||
bool testMsgRelatedChildDataRetrieval();
|
||||
bool testMsgRelatedChildDataRetrieval_Multi();
|
||||
bool testMsgAllVersions();
|
||||
};
|
||||
|
||||
#endif /* GXSMSGRELATEDTEST_H_ */
|
240
libretroshare/src/tests/gxs/gen_exchange/gxspublishgrouptest.cc
Normal file
240
libretroshare/src/tests/gxs/gen_exchange/gxspublishgrouptest.cc
Normal file
@ -0,0 +1,240 @@
|
||||
/*
|
||||
* gxspublishgrouptest.cc
|
||||
*
|
||||
* Created on: 27 Apr 2013
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#include "gxspublishgrouptest.h"
|
||||
#include "util/utest.h"
|
||||
|
||||
#define POLLING_TIME_OUT 5
|
||||
|
||||
GxsPublishGroupTest::GxsPublishGroupTest(GenExchangeTestService* const testService,
|
||||
RsGeneralDataService* dataService)
|
||||
: GenExchangeTest(testService, dataService, POLLING_TIME_OUT)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
GxsPublishGroupTest::~GxsPublishGroupTest()
|
||||
{
|
||||
}
|
||||
|
||||
bool GxsPublishGroupTest::testGrpSubmissionRetrieval()
|
||||
{
|
||||
|
||||
setUp();
|
||||
|
||||
GenExchangeTestService* testService = getTestService();
|
||||
RsTokenService* tokenService = getTokenService();
|
||||
|
||||
// create some random grps to allow msg testing
|
||||
|
||||
RsDummyGrp* dgrp1 = new RsDummyGrp();
|
||||
RsDummyGrp* dgrp2 = new RsDummyGrp();
|
||||
RsDummyGrp* dgrp3 = new RsDummyGrp();
|
||||
|
||||
RsDummyGrp* dgrp1_copy = new RsDummyGrp();
|
||||
RsDummyGrp* dgrp2_copy = new RsDummyGrp();
|
||||
RsDummyGrp* dgrp3_copy = new RsDummyGrp();
|
||||
|
||||
init(*dgrp1);
|
||||
init(*dgrp2);
|
||||
init(*dgrp3);
|
||||
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = 45000;
|
||||
uint32_t token;
|
||||
RsGxsGroupId grpId;
|
||||
|
||||
std::vector<RsDummyGrp*> groupsPublished;
|
||||
|
||||
*dgrp1_copy = *dgrp1;
|
||||
testService->publishDummyGrp(token, dgrp1);
|
||||
pollForGrpAcknowledgement(token, grpId);
|
||||
dgrp1_copy->meta.mGroupId = grpId;
|
||||
groupsPublished.push_back(dgrp1_copy);
|
||||
|
||||
*dgrp2_copy = *dgrp2;
|
||||
testService->publishDummyGrp(token, dgrp2);
|
||||
pollForGrpAcknowledgement(token, grpId);
|
||||
dgrp2_copy->meta.mGroupId = grpId;
|
||||
groupsPublished.push_back(dgrp2_copy);
|
||||
|
||||
*dgrp3_copy = *dgrp3;
|
||||
testService->publishDummyGrp(token, dgrp3);
|
||||
pollForGrpAcknowledgement(token, grpId);
|
||||
dgrp3_copy->meta.mGroupId = grpId;
|
||||
groupsPublished.push_back(dgrp3_copy);
|
||||
|
||||
|
||||
storeToGrpDataOutList(groupsPublished);
|
||||
|
||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
|
||||
std::list<RsGxsGroupId> grpIds;
|
||||
tokenService->requestGroupInfo(token, 0, opts);
|
||||
|
||||
pollForToken(token, opts, true);
|
||||
|
||||
|
||||
bool ok = compareGrpData();
|
||||
|
||||
breakDown();
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool GxsPublishGroupTest::testSpecificGrpRetrieval()
|
||||
{
|
||||
setUp();
|
||||
|
||||
GenExchangeTestService* testService = getTestService();
|
||||
RsTokenService* tokenService = getTokenService();
|
||||
|
||||
// create some random grps to allow msg testing
|
||||
|
||||
RsDummyGrp* dgrp1 = new RsDummyGrp();
|
||||
RsDummyGrp* dgrp2 = new RsDummyGrp();
|
||||
RsDummyGrp* dgrp3 = new RsDummyGrp();
|
||||
|
||||
RsDummyGrp* dgrp1_copy = new RsDummyGrp();
|
||||
RsDummyGrp* dgrp2_copy = new RsDummyGrp();
|
||||
|
||||
init(*dgrp1);
|
||||
init(*dgrp2);
|
||||
init(*dgrp3);
|
||||
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = 45000;
|
||||
uint32_t token;
|
||||
RsGxsGroupId grpId;
|
||||
|
||||
std::vector<RsDummyGrp*> groupsPublished;
|
||||
std::list<RsGxsGroupId> grpIds;
|
||||
|
||||
*dgrp1_copy = *dgrp1;
|
||||
testService->publishDummyGrp(token, dgrp1);
|
||||
pollForGrpAcknowledgement(token, grpId);
|
||||
dgrp1_copy->meta.mGroupId = grpId;
|
||||
groupsPublished.push_back(dgrp1_copy);
|
||||
grpIds.push_back(grpId);
|
||||
|
||||
*dgrp2_copy = *dgrp2;
|
||||
testService->publishDummyGrp(token, dgrp2);
|
||||
pollForGrpAcknowledgement(token, grpId);
|
||||
dgrp2_copy->meta.mGroupId = grpId;
|
||||
groupsPublished.push_back(dgrp2_copy);
|
||||
grpIds.push_back(grpId);
|
||||
|
||||
|
||||
testService->publishDummyGrp(token, dgrp3);
|
||||
pollForGrpAcknowledgement(token, grpId);
|
||||
|
||||
|
||||
storeToGrpDataOutList(groupsPublished);
|
||||
|
||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
|
||||
|
||||
tokenService->requestGroupInfo(token, 0, opts, grpIds);
|
||||
|
||||
pollForToken(token, opts, true);
|
||||
|
||||
|
||||
bool ok = compareGrpData();
|
||||
|
||||
breakDown();
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool GxsPublishGroupTest::testGrpIdRetrieval()
|
||||
{
|
||||
setUp();
|
||||
|
||||
std::list<RsGxsGroupId> grpIds;
|
||||
createGrps(5, grpIds);
|
||||
storeToGrpIdsOutList(grpIds);
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_IDS;
|
||||
uint32_t token;
|
||||
|
||||
getTokenService()->requestGroupInfo(token, 0, opts);
|
||||
|
||||
pollForToken(token, opts, true);
|
||||
|
||||
bool ok = compareGrpIds();
|
||||
|
||||
breakDown();
|
||||
|
||||
return ok;
|
||||
}
|
||||
bool GxsPublishGroupTest::testGrpMetaRetrieval()
|
||||
{
|
||||
|
||||
setUp();
|
||||
|
||||
GenExchangeTestService* testService = getTestService();
|
||||
|
||||
// create some random grps to allow msg testing
|
||||
|
||||
RsDummyGrp* dgrp1 = new RsDummyGrp();
|
||||
RsDummyGrp* dgrp2 = new RsDummyGrp();
|
||||
RsDummyGrp* dgrp3 = new RsDummyGrp();
|
||||
|
||||
init(*dgrp1);
|
||||
init(*dgrp2);
|
||||
init(*dgrp3);
|
||||
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = 45000;
|
||||
uint32_t token;
|
||||
RsGxsGroupId grpId;
|
||||
|
||||
RsGroupMetaData meta1(dgrp1->meta);
|
||||
RsGroupMetaData meta2(dgrp2->meta);
|
||||
RsGroupMetaData meta3(dgrp3->meta);
|
||||
|
||||
std::list<RsGroupMetaData> groupsMetaPublished;
|
||||
|
||||
testService->publishDummyGrp(token, dgrp1);
|
||||
pollForGrpAcknowledgement(token, grpId);
|
||||
meta1.mGroupId = grpId;
|
||||
groupsMetaPublished.push_back(meta1);
|
||||
|
||||
testService->publishDummyGrp(token, dgrp2);
|
||||
pollForGrpAcknowledgement(token, grpId);
|
||||
meta2.mGroupId = grpId;
|
||||
groupsMetaPublished.push_back(meta2);
|
||||
|
||||
testService->publishDummyGrp(token, dgrp3);
|
||||
pollForGrpAcknowledgement(token, grpId);
|
||||
meta3.mGroupId = grpId;
|
||||
groupsMetaPublished.push_back(meta3);
|
||||
|
||||
storeToGrpMetaOutList(groupsMetaPublished);
|
||||
|
||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
|
||||
std::list<RsGxsGroupId> grpIds;
|
||||
|
||||
getTokenService()->requestGroupInfo(token, 0, opts);
|
||||
|
||||
pollForToken(token, opts, true);
|
||||
|
||||
bool ok = compareGrpMeta();
|
||||
|
||||
breakDown();
|
||||
|
||||
return ok;
|
||||
}
|
||||
void GxsPublishGroupTest::runTests()
|
||||
{
|
||||
CHECK(testGrpSubmissionRetrieval());
|
||||
CHECK(testGrpIdRetrieval());
|
||||
CHECK(testGrpMetaRetrieval());
|
||||
CHECK(testSpecificGrpRetrieval());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* gxspublishgrouptest.h
|
||||
*
|
||||
* Created on: 27 Apr 2013
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#ifndef GXSPUBLISHGROUPTEST_H_
|
||||
#define GXSPUBLISHGROUPTEST_H_
|
||||
|
||||
#include "genexchangetester.h"
|
||||
|
||||
class GxsPublishGroupTest : public GenExchangeTest {
|
||||
public:
|
||||
|
||||
GxsPublishGroupTest(GenExchangeTestService* const testService,
|
||||
RsGeneralDataService* dataService);
|
||||
virtual ~GxsPublishGroupTest();
|
||||
|
||||
void runTests();
|
||||
|
||||
private:
|
||||
|
||||
// group tests
|
||||
bool testGrpSubmissionRetrieval();
|
||||
bool testSpecificGrpRetrieval();
|
||||
bool testGrpIdRetrieval();
|
||||
bool testGrpMetaRetrieval();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif /* GXSPUBLISHGROUPTEST_H_ */
|
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* gxspublishmsgtest.cpp
|
||||
*
|
||||
* Created on: 27 Apr 2013
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#include "gxspublishmsgtest.h"
|
||||
#include "util/utest.h"
|
||||
|
||||
#define POLLING_TIME_OUT 5
|
||||
|
||||
GxsPublishMsgTest::GxsPublishMsgTest(GenExchangeTestService* const testService,
|
||||
RsGeneralDataService* dataService)
|
||||
: GenExchangeTest(testService, dataService, POLLING_TIME_OUT)
|
||||
{
|
||||
}
|
||||
|
||||
GxsPublishMsgTest::~GxsPublishMsgTest()
|
||||
{
|
||||
}
|
||||
|
||||
void GxsPublishMsgTest::runTests()
|
||||
{
|
||||
CHECK(testMsgSubmissionRetrieval());
|
||||
}
|
||||
|
||||
bool GxsPublishMsgTest::testMsgSubmissionRetrieval()
|
||||
{
|
||||
// start up
|
||||
setUp();
|
||||
std::list<RsGxsGroupId> grpIds;
|
||||
createGrps(4, grpIds);
|
||||
|
||||
/********************/
|
||||
|
||||
RsDummyMsg* msg = new RsDummyMsg();
|
||||
init(*msg);
|
||||
|
||||
msg->meta.mGroupId = grpIds.front();
|
||||
uint32_t token;
|
||||
RsDummyMsg* msgOut = new RsDummyMsg();
|
||||
*msgOut = *msg;
|
||||
getTestService()->publishDummyMsg(token, msg);
|
||||
|
||||
|
||||
RsGxsGrpMsgIdPair msgId;
|
||||
pollForMsgAcknowledgement(token, msgId);
|
||||
msgOut->meta.mMsgId = msgId.second;
|
||||
|
||||
DummyMsgMap msgMap;
|
||||
std::vector<RsDummyMsg*> msgV;
|
||||
msgV.push_back(msgOut);
|
||||
msgMap[msgOut->meta.mGroupId] = msgV;
|
||||
storeToMsgDataOutMaps(msgMap);
|
||||
|
||||
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
|
||||
|
||||
getTokenService()->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, grpIds);
|
||||
|
||||
// poll again
|
||||
pollForToken(token, opts, true);
|
||||
|
||||
bool ok = compareMsgDataMaps();
|
||||
|
||||
// complete
|
||||
breakDown();
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
|
32
libretroshare/src/tests/gxs/gen_exchange/gxspublishmsgtest.h
Normal file
32
libretroshare/src/tests/gxs/gen_exchange/gxspublishmsgtest.h
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* gxspublishmsgtest.h
|
||||
*
|
||||
* Created on: 27 Apr 2013
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#ifndef GXSPUBLISHMSGTEST_H_
|
||||
#define GXSPUBLISHMSGTEST_H_
|
||||
|
||||
#include "genexchangetester.h"
|
||||
|
||||
class GxsPublishMsgTest: public GenExchangeTest {
|
||||
public:
|
||||
GxsPublishMsgTest(GenExchangeTestService* const testService,
|
||||
RsGeneralDataService* dataService);
|
||||
virtual ~GxsPublishMsgTest();
|
||||
|
||||
void runTests();
|
||||
|
||||
// message tests
|
||||
bool testMsgSubmissionRetrieval();
|
||||
// bool testMsgIdRetrieval();
|
||||
// bool testMsgIdRetrieval_OptParents();
|
||||
// bool testMsgIdRetrieval_OptOrigMsgId();
|
||||
// bool testMsgIdRetrieval_OptLatest();
|
||||
// bool testSpecificMsgMetaRetrieval();
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif /* GXSPUBLISHMSGTEST_H_ */
|
@ -13,6 +13,7 @@ class RsDummyNetService: public RsNetworkExchangeService
|
||||
public:
|
||||
|
||||
RsDummyNetService(){ return;}
|
||||
virtual ~RsDummyNetService() { }
|
||||
|
||||
void setSyncAge(uint32_t age){}
|
||||
|
||||
@ -55,7 +56,6 @@ public:
|
||||
virtual ~RsDummyGrp() { return; }
|
||||
|
||||
|
||||
|
||||
std::string grpData;
|
||||
void clear() { grpData.clear(); }
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0){ return out; }
|
||||
@ -109,6 +109,8 @@ public:
|
||||
*/
|
||||
RsGixsDummy(const RsGxsId& incomingId, const RsGxsId& outgoingId){}
|
||||
|
||||
virtual ~RsGixsDummy(){}
|
||||
|
||||
/*!
|
||||
*
|
||||
* @return id used for signing incoming data (should have both public and private components)
|
@ -0,0 +1,47 @@
|
||||
|
||||
|
||||
#include "genexchangetester.h"
|
||||
#include "gxspublishgrouptest.h"
|
||||
#include "gxspublishmsgtest.h"
|
||||
#include "util/utest.h"
|
||||
#include "gxs/rsdataservice.h"
|
||||
#include "rsdummyservices.h"
|
||||
|
||||
|
||||
/*!
|
||||
* It always hard to say exactly what coverage of a test would
|
||||
* be ahead of time. Partly because its difficult to create the
|
||||
* actual conditions of a test or the permutations of different request
|
||||
* options to a module is extremely large (and there are probably ways to deal with this)
|
||||
* In so far as the genexchange test is concerned we are primarily interested that it
|
||||
* retrieves and stores data correctly
|
||||
* The auxillary (and important) requirement is authentication and ensuring the authentication
|
||||
* rules are respected. This auxillary requirement is of the "hard" situation to create as
|
||||
* genexchange depends on an external module (rsidentity) for satisfying a significant sum
|
||||
* of its authentication. This difficulty is solved with a dummy identity service.
|
||||
* Which passes all authentications (In this respect authentication) is reserved for "online"
|
||||
* testing and is relatively straight forward.
|
||||
*
|
||||
*/
|
||||
|
||||
INITTEST();
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
RsGeneralDataService* dataStore = new RsDataService("./", "testServiceDb", RS_SERVICE_TYPE_DUMMY, NULL);
|
||||
|
||||
// we want to use default authentication which is NO authentication :)
|
||||
GenExchangeTestService testService(dataStore, NULL, NULL);
|
||||
|
||||
//GxsPublishGroupTest testGrpPublishing(&testService, dataStore);
|
||||
//testGrpPublishing.runTests();
|
||||
|
||||
GxsPublishMsgTest testMsgPublishing(&testService, dataStore);
|
||||
testMsgPublishing.runTests();
|
||||
|
||||
FINALREPORT("RsGenExchangeTest");
|
||||
|
||||
return 0;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,122 +0,0 @@
|
||||
#ifndef GENEXCHANGETESTER_H
|
||||
#define GENEXCHANGETESTER_H
|
||||
|
||||
#include "genexchangetestservice.h"
|
||||
#include "gxs/rsgds.h"
|
||||
#include "gxs/rsnxs.h"
|
||||
|
||||
bool operator ==(const RsMsgMetaData& lMeta, const RsMsgMetaData& rMeta);
|
||||
bool operator ==(const RsDummyMsg& lMsg, const RsDummyMsg& rMsg);
|
||||
|
||||
bool operator ==(const RsGroupMetaData& lMeta, const RsGroupMetaData& rMeta);
|
||||
bool operator ==(const RsDummyGrp& lMsg, const RsDummyGrp& rMsg);
|
||||
|
||||
/*!
|
||||
* The job of the service tester is to send dummy msg items to the GenExchange service
|
||||
* and then retrieve them (ignoring ackowledge message)
|
||||
* Also it modifies local meta items and check if it worked out
|
||||
*/
|
||||
class GenExchangeTester
|
||||
{
|
||||
public:
|
||||
|
||||
void pollForToken(uint32_t, const RsTokReqOptions& opts);
|
||||
|
||||
GenExchangeTester();
|
||||
|
||||
// message tests
|
||||
bool testMsgSubmissionRetrieval();
|
||||
bool testMsgIdRetrieval();
|
||||
bool testMsgIdRetrieval_OptParents();
|
||||
bool testMsgIdRetrieval_OptOrigMsgId();
|
||||
bool testMsgIdRetrieval_OptLatest();
|
||||
bool testSpecificMsgMetaRetrieval();
|
||||
|
||||
// request msg related tests
|
||||
bool testMsgRelatedChildIdRetrieval();
|
||||
bool testMsgRelatedChildDataRetrieval();
|
||||
bool testMsgRelatedChildDataRetrieval_Multi();
|
||||
bool testMsgAllVersions();
|
||||
|
||||
|
||||
// group tests
|
||||
bool testGrpSubmissionRetrieval();
|
||||
bool testSpecificGrpRetrieval();
|
||||
bool testGrpIdRetrieval();
|
||||
bool testGrpMetaRetrieval();
|
||||
|
||||
bool testGrpMetaModRequest();
|
||||
bool testMsgMetaModRequest();
|
||||
|
||||
|
||||
// testing verification (publish).
|
||||
// Strategy is
|
||||
// inject a group which you only have the public signature for
|
||||
// The injection can be done via
|
||||
|
||||
private:
|
||||
|
||||
// to be called at start
|
||||
void setUp();
|
||||
|
||||
// and at end of test routines, resets db and clears out maps
|
||||
void breakDown();
|
||||
|
||||
|
||||
void setUpGrps(uint32_t grpFlag=0); // to be called at start of msg tests
|
||||
|
||||
/*!
|
||||
* Can be called at start grpId or grpMeta test
|
||||
* to help out
|
||||
* ids are store is mGrpIdsOut
|
||||
*/
|
||||
void setUpLargeGrps(uint32_t nGrps);
|
||||
|
||||
void storeMsgData(GxsMsgDataMap& msgData);
|
||||
void storeMsgMeta(GxsMsgMetaMap& msgMetaData);
|
||||
void storeMsgIds(GxsMsgIdResult& msgIds);
|
||||
|
||||
void storeGrpData(std::vector<RsGxsGrpItem*>& grpData);
|
||||
void storeGrpMeta(std::list<RsGroupMetaData>& grpMetaData);
|
||||
void storeGrpId(std::list<RsGxsGroupId>& grpIds);
|
||||
|
||||
void init(RsDummyGrp* grpItem) const;
|
||||
void init(RsGroupMetaData&) const;
|
||||
void init(RsDummyMsg* msgItem) const;
|
||||
void init(RsMsgMetaData&) const;
|
||||
|
||||
uint32_t randNum() const;
|
||||
private:
|
||||
|
||||
void createMsgs(std::vector<RsDummyMsg*>& msgs, int nMsgs) const;
|
||||
|
||||
private:
|
||||
|
||||
|
||||
RsMutex mGenTestMutex;
|
||||
|
||||
std::vector<RsGxsGrpItem*> mGrpDataOut, mGrpDataIn;
|
||||
std::list<RsGroupMetaData> mGrpMetaDataOut, mGrpMetaDataIn;
|
||||
std::list<RsGxsGroupId> mGrpIdsOut, mGrpIdsIn;
|
||||
|
||||
GxsMsgDataMap mMsgDataOut, mMsgDataIn;
|
||||
GxsMsgMetaMap mMsgMetaDataOut, mMsgMetaDataIn;
|
||||
GxsMsgIdResult mMsgIdsOut, mMsgIdsIn;
|
||||
|
||||
MsgRelatedIdResult mMsgRelatedIdsOut, mMsgRelatedIdsIn;
|
||||
GxsMsgRelatedDataMap mMsgRelatedDataMapOut, mMsgRelatedDataMapIn;
|
||||
|
||||
std::vector<RsGxsGroupId> mRandGrpIds; // ids that exist to help group testing
|
||||
|
||||
private:
|
||||
|
||||
GenExchangeTestService* mTestService;
|
||||
RsTokenService* mTokenService;
|
||||
|
||||
RsNetworkExchangeService* mNxs;
|
||||
RsGeneralDataService* mDataStore;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // GENEXCHANGETESTER_H
|
203
libretroshare/src/tests/gxs/nxs_test/nxs_tests.pro
Normal file
203
libretroshare/src/tests/gxs/nxs_test/nxs_tests.pro
Normal file
@ -0,0 +1,203 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2012-05-06T09:19:26
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
|
||||
#
|
||||
QT += core network
|
||||
|
||||
QT -= gui
|
||||
|
||||
#CONFIG += gen_exchange_target
|
||||
CONFIG += nxs_net_test
|
||||
#CONFIG += dstore_target
|
||||
#CONFIG += gxsdata_target
|
||||
|
||||
CONFIG += bitdht
|
||||
|
||||
|
||||
|
||||
#gen_exchange_target {
|
||||
|
||||
#TARGET = gen_exchange_test
|
||||
|
||||
#}
|
||||
|
||||
#nxs_net_test {
|
||||
|
||||
TARGET = nxs_net_test
|
||||
|
||||
#}
|
||||
|
||||
#gxsdata_target {
|
||||
|
||||
#TARGET = gxsdata_test
|
||||
#}
|
||||
|
||||
CONFIG += console
|
||||
CONFIG -= app_bundle
|
||||
|
||||
TEMPLATE = app
|
||||
|
||||
CONFIG += debug
|
||||
|
||||
debug {
|
||||
# DEFINES *= DEBUG
|
||||
# DEFINES *= OPENDHT_DEBUG DHT_DEBUG CONN_DEBUG DEBUG_UDP_SORTER P3DISC_DEBUG DEBUG_UDP_LAYER FT_DEBUG EXTADDRSEARCH_DEBUG
|
||||
# DEFINES *= CONTROL_DEBUG FT_DEBUG DEBUG_FTCHUNK P3TURTLE_DEBUG
|
||||
# DEFINES *= P3TURTLE_DEBUG
|
||||
# DEFINES *= NET_DEBUG
|
||||
# DEFINES *= DISTRIB_DEBUG
|
||||
# DEFINES *= P3TURTLE_DEBUG FT_DEBUG DEBUG_FTCHUNK MPLEX_DEBUG
|
||||
# DEFINES *= STATUS_DEBUG SERV_DEBUG RSSERIAL_DEBUG #CONN_DEBUG
|
||||
|
||||
QMAKE_CXXFLAGS -= -O2 -fomit-frame-pointer
|
||||
QMAKE_CXXFLAGS *= -g -fno-omit-frame-pointer
|
||||
}
|
||||
################################# Linux ##########################################
|
||||
# Put lib dir in QMAKE_LFLAGS so it appears before -L/usr/lib
|
||||
linux-* {
|
||||
#CONFIG += version_detail_bash_script
|
||||
QMAKE_CXXFLAGS *= -D_FILE_OFFSET_BITS=64
|
||||
|
||||
system(which gpgme-config >/dev/null 2>&1) {
|
||||
INCLUDEPATH += $$system(gpgme-config --cflags | sed -e "s/-I//g")
|
||||
} else {
|
||||
message(Could not find gpgme-config on your system, assuming gpgme.h is in /usr/include)
|
||||
}
|
||||
|
||||
PRE_TARGETDEPS *= ../../lib/libretroshare.a
|
||||
|
||||
LIBS += ../../lib/libretroshare.a
|
||||
LIBS += ../../../../libbitdht/src/lib/libbitdht.a
|
||||
LIBS += ../../../../openpgpsdk/src/lib/libops.a
|
||||
LIBS += -lssl -lgpgme -lupnp -lixml -lgnome-keyring -lsqlite3 -lbz2
|
||||
LIBS *= -rdynamic -frtti
|
||||
DEFINES *= HAVE_XSS # for idle time, libx screensaver extensions
|
||||
DEFINES *= UBUNTU
|
||||
}
|
||||
|
||||
linux-g++ {
|
||||
OBJECTS_DIR = temp/linux-g++/obj
|
||||
}
|
||||
|
||||
linux-g++-64 {
|
||||
OBJECTS_DIR = temp/linux-g++-64/obj
|
||||
}
|
||||
|
||||
#################################### Windows #####################################
|
||||
|
||||
win32 {
|
||||
|
||||
DEFINES *= WINDOWS_SYS \
|
||||
WIN32 \
|
||||
STATICLIB \
|
||||
MINGW
|
||||
# Switch on extra warnings
|
||||
QMAKE_CFLAGS += -Wextra
|
||||
QMAKE_CXXFLAGS += -Wextra
|
||||
|
||||
# Switch off optimization for release version
|
||||
QMAKE_CXXFLAGS_RELEASE -= -O2
|
||||
QMAKE_CXXFLAGS_RELEASE += -O0
|
||||
QMAKE_CFLAGS_RELEASE -= -O2
|
||||
QMAKE_CFLAGS_RELEASE += -O0
|
||||
|
||||
# Switch on optimization for debug version
|
||||
#QMAKE_CXXFLAGS_DEBUG += -O2
|
||||
#QMAKE_CFLAGS_DEBUG += -O2
|
||||
|
||||
# PRE_TARGETDEPS += ../../libretroshare/src/lib/libretroshare.a
|
||||
PRE_TARGETDEPS += ../../../../libretroshare/libretroshare-build-desktop/lib/libretroshare.a
|
||||
|
||||
LIBS += ../../../../libretroshare/libretroshare-build-desktop/lib/libretroshare.a
|
||||
LIBS += C:\Development\Rs\v0.5-gxs-b1\openpgpsdk\openpgpsdk-build-desktop\lib\libops.a
|
||||
LIBS += C:\Development\Libraries\sqlite\sqlite-autoconf-3070900\lib\libsqlite3.a
|
||||
LIBS += -L"../../../../../lib"
|
||||
LIBS += -lssl -lcrypto -lgpgme -lpthreadGC2d -lminiupnpc -lz -lbz2
|
||||
# added after bitdht
|
||||
# LIBS += -lws2_32
|
||||
LIBS += -luuid -lole32 -liphlpapi -lcrypt32-cygwin -lgdi32
|
||||
LIBS += -lole32 -lwinmm
|
||||
|
||||
# export symbols for the plugins
|
||||
#LIBS += -Wl,--export-all-symbols,--out-implib,lib/libretroshare-gui.a
|
||||
|
||||
GPG_ERROR_DIR = ../../../../libgpg-error-1.7
|
||||
GPGME_DIR = ../../../../gpgme-1.1.8
|
||||
GPG_ERROR_DIR = ../../../../lib/libgpg-error-1.7
|
||||
GPGME_DIR = ../../../../lib/gpgme-1.1.8
|
||||
SSL_DIR = ../../../../../OpenSSL
|
||||
OPENPGPSDK_DIR = ../../../../openpgpsdk/src
|
||||
INCLUDEPATH += . $${SSL_DIR}/include $${GPGME_DIR}/src $${GPG_ERROR_DIR}/src \
|
||||
$${OPENPGPSDK_DIR}
|
||||
|
||||
SQLITE_DIR = ../../../../../../Libraries/sqlite/sqlite-autoconf-3070900
|
||||
INCLUDEPATH += . \
|
||||
$${SQLITE_DIR}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
bitdht {
|
||||
|
||||
# Chris version.
|
||||
#LIBS += ../../libbitdht/libbitdht-build-desktop/lib/libbitdht.a
|
||||
#PRE_TARGETDEPS *= ../../libbitdht/libbitdht-build-desktop/lib/libbitdht.a
|
||||
}
|
||||
|
||||
win32 {
|
||||
# must be added after bitdht
|
||||
LIBS += -lws2_32
|
||||
}
|
||||
|
||||
version_detail_bash_script {
|
||||
DEFINES += ADD_LIBRETROSHARE_VERSION_INFO
|
||||
QMAKE_EXTRA_TARGETS += write_version_detail
|
||||
PRE_TARGETDEPS = write_version_detail
|
||||
write_version_detail.commands = ./version_detail.sh
|
||||
}
|
||||
|
||||
install_rs {
|
||||
INSTALLS += binary_rs
|
||||
binary_rs.path = $$(PREFIX)/usr/bin
|
||||
binary_rs.files = ./RetroShare
|
||||
}
|
||||
|
||||
|
||||
#gen_exchange_target {
|
||||
|
||||
# SOURCES += \
|
||||
# support.cc \
|
||||
# genexchangetester.cpp \
|
||||
# genexchangetestservice.cpp \
|
||||
# rsdummyservices.cc \
|
||||
# rsgenexchange_test.cc
|
||||
|
||||
# HEADERS += support.h \
|
||||
# rsdataservice_test.h \
|
||||
# rsdummyservices.h \
|
||||
# data_support.h
|
||||
#}
|
||||
|
||||
nxs_net_test {
|
||||
|
||||
SOURCES += \
|
||||
support.cc \
|
||||
data_support.cc \
|
||||
nxstesthub.cc \
|
||||
nxstestscenario.cc \
|
||||
rsgxsnetservice_test.cc
|
||||
|
||||
HEADERS += support.h \
|
||||
nxstestscenario.h \
|
||||
nxstesthub.h \
|
||||
data_support.h
|
||||
|
||||
}
|
||||
|
||||
INCLUDEPATH += ../../
|
@ -1,92 +0,0 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2012-05-06T09:19:26
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core network
|
||||
|
||||
QT -= gui
|
||||
|
||||
TARGET = rs_test
|
||||
CONFIG += console
|
||||
CONFIG -= app_bundle
|
||||
|
||||
TEMPLATE = app
|
||||
|
||||
CONFIG += debug
|
||||
|
||||
debug {
|
||||
# DEFINES *= DEBUG
|
||||
# DEFINES *= OPENDHT_DEBUG DHT_DEBUG CONN_DEBUG DEBUG_UDP_SORTER P3DISC_DEBUG DEBUG_UDP_LAYER FT_DEBUG EXTADDRSEARCH_DEBUG
|
||||
# DEFINES *= CONTROL_DEBUG FT_DEBUG DEBUG_FTCHUNK P3TURTLE_DEBUG
|
||||
# DEFINES *= P3TURTLE_DEBUG
|
||||
# DEFINES *= NET_DEBUG
|
||||
# DEFINES *= DISTRIB_DEBUG
|
||||
# DEFINES *= P3TURTLE_DEBUG FT_DEBUG DEBUG_FTCHUNK MPLEX_DEBUG
|
||||
# DEFINES *= STATUS_DEBUG SERV_DEBUG RSSERIAL_DEBUG #CONN_DEBUG
|
||||
|
||||
QMAKE_CXXFLAGS -= -O2 -fomit-frame-pointer
|
||||
QMAKE_CXXFLAGS *= -g -fno-omit-frame-pointer
|
||||
}
|
||||
################################# Linux ##########################################
|
||||
# Put lib dir in QMAKE_LFLAGS so it appears before -L/usr/lib
|
||||
linux-* {
|
||||
#CONFIG += version_detail_bash_script
|
||||
QMAKE_CXXFLAGS *= -D_FILE_OFFSET_BITS=64
|
||||
|
||||
system(which gpgme-config >/dev/null 2>&1) {
|
||||
INCLUDEPATH += $$system(gpgme-config --cflags | sed -e "s/-I//g")
|
||||
} else {
|
||||
message(Could not find gpgme-config on your system, assuming gpgme.h is in /usr/include)
|
||||
}
|
||||
|
||||
PRE_TARGETDEPS *= /home/crispy/workspace/v0.5-gxs-b1/libretroshare/src/lib/libretroshare.a
|
||||
|
||||
LIBS += /home/crispy/workspace/v0.5-gxs-b1/libretroshare/src/lib/libretroshare.a
|
||||
LIBS += /home/crispy/workspace/v0.5-gxs-b1/libbitdht/src/lib/libbitdht.a
|
||||
LIBS += /home/crispy/workspace/v0.5-gxs-b1/openpgpsdk/src/lib/libops.a
|
||||
LIBS += -lssl -lgpgme -lupnp -lixml -lgnome-keyring -lsqlite3 -lbz2
|
||||
LIBS *= -rdynamic -frtti
|
||||
DEFINES *= HAVE_XSS # for idle time, libx screensaver extensions
|
||||
DEFINES *= UBUNTU
|
||||
}
|
||||
|
||||
linux-g++ {
|
||||
OBJECTS_DIR = temp/linux-g++/obj
|
||||
}
|
||||
|
||||
linux-g++-64 {
|
||||
OBJECTS_DIR = temp/linux-g++-64/obj
|
||||
}
|
||||
|
||||
version_detail_bash_script {
|
||||
DEFINES += ADD_LIBRETROSHARE_VERSION_INFO
|
||||
QMAKE_EXTRA_TARGETS += write_version_detail
|
||||
PRE_TARGETDEPS = write_version_detail
|
||||
write_version_detail.commands = ./version_detail.sh
|
||||
}
|
||||
|
||||
install_rs {
|
||||
INSTALLS += binary_rs
|
||||
binary_rs.path = $$(PREFIX)/usr/bin
|
||||
binary_rs.files = ./RetroShare
|
||||
}
|
||||
|
||||
|
||||
SOURCES += \
|
||||
/home/crispy/workspace/v0.5-gxs-b1/libretroshare/src/tests/gxs/data_support.cc \
|
||||
/home/crispy/workspace/v0.5-gxs-b1/libretroshare/src/tests/gxs/nxstesthub.cc \
|
||||
/home/crispy/workspace/v0.5-gxs-b1/libretroshare/src/tests/gxs/nxstestscenario.cc \
|
||||
/home/crispy/workspace/v0.5-gxs-b1/libretroshare/src/tests/gxs/rsgxsnetservice_test.cc \
|
||||
/home/crispy/workspace/v0.5-gxs-b1/libretroshare/src/tests/gxs/support.cc
|
||||
|
||||
|
||||
HEADERS += \
|
||||
/home/crispy/workspace/v0.5-gxs-b1/libretroshare/src/tests/gxs/data_support.h \
|
||||
/home/crispy/workspace/v0.5-gxs-b1/libretroshare/src/tests/gxs/nxstesthub.h \
|
||||
/home/crispy/workspace/v0.5-gxs-b1/libretroshare/src/tests/gxs/nxstestscenario.h \
|
||||
/home/crispy/workspace/v0.5-gxs-b1/libretroshare/src/tests/gxs/support.h
|
||||
|
||||
INCLUDEPATH += /home/crispy/workspace/v0.5-gxs-b1/libretroshare/src
|
||||
|
@ -1,73 +0,0 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2012-05-06T09:19:26
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core network
|
||||
|
||||
QT -= gui
|
||||
|
||||
TARGET = rs_test
|
||||
CONFIG += console
|
||||
CONFIG -= app_bundle
|
||||
|
||||
TEMPLATE = app
|
||||
|
||||
win32 {
|
||||
# Switch on extra warnings
|
||||
QMAKE_CFLAGS += -Wextra
|
||||
QMAKE_CXXFLAGS += -Wextra
|
||||
|
||||
# Switch off optimization for release version
|
||||
QMAKE_CXXFLAGS_RELEASE -= -O2
|
||||
QMAKE_CXXFLAGS_RELEASE += -O0
|
||||
QMAKE_CFLAGS_RELEASE -= -O2
|
||||
QMAKE_CFLAGS_RELEASE += -O0
|
||||
|
||||
# Switch on optimization for debug version
|
||||
#QMAKE_CXXFLAGS_DEBUG += -O2
|
||||
#QMAKE_CFLAGS_DEBUG += -O2
|
||||
DEFINES *= WINDOWS_SYS
|
||||
PRE_TARGETDEPS += C:\Development\Rs\v0.5-new_cache_system\libretroshare\libretroshare-build-desktop\lib\libretroshare.a
|
||||
LIBS += C:\Development\Rs\v0.5-new_cache_system\libretroshare\libretroshare-build-desktop\lib\libretroshare.a
|
||||
LIBS += -L"../lib"
|
||||
LIBS += -lssl -lcrypto -lgpgme -lpthreadGC2d -lminiupnpc -lz
|
||||
# added after bitdht
|
||||
# LIBS += -lws2_32
|
||||
LIBS += -luuid -lole32 -liphlpapi -lcrypt32-cygwin -lgdi32
|
||||
LIBS += -lole32 -lwinmm
|
||||
|
||||
# export symbols for the plugins
|
||||
#LIBS += -Wl,--export-all-symbols,--out-implib,lib/libretroshare-gui.a
|
||||
|
||||
GPG_ERROR_DIR = ../../../../libgpg-error-1.7
|
||||
GPGME_DIR = ../../../../gpgme-1.1.8
|
||||
GPG_ERROR_DIR = ../../../../lib/libgpg-error-1.7
|
||||
GPGME_DIR = ../../../../lib/gpgme-1.1.8
|
||||
INCLUDEPATH += . $${GPGME_DIR}/src $${GPG_ERROR_DIR}/src ../../Libraries/sqlite/sqlite-autoconf-3070900
|
||||
LIBS += C:\Development\Libraries\sqlite\sqlite-autoconf-3070900\.libs\libsqlite3.a
|
||||
}
|
||||
|
||||
win32 {
|
||||
# must be added after bitdht
|
||||
LIBS += -lws2_32
|
||||
}
|
||||
|
||||
SOURCES += \
|
||||
support.cc \
|
||||
#rsnxsitems_test.cc
|
||||
rsdataservice_test.cc \
|
||||
data_support.cc
|
||||
#rsnxsservice_test.cc \
|
||||
#nxstesthub.cc
|
||||
#rsgxsdata_test.cc
|
||||
|
||||
HEADERS += support.h \
|
||||
#rsnxsitems_test.h
|
||||
rsdataservice_test.h \
|
||||
data_support.h
|
||||
#rsnxsservice_test.h \
|
||||
#nxstesthub.h
|
||||
|
||||
INCLUDEPATH += C:\Development\Rs\v0.5-new_cache_system\libretroshare\src
|
@ -1,36 +0,0 @@
|
||||
|
||||
|
||||
#include "genexchangetester.h"
|
||||
#include "genexchangetestservice.h"
|
||||
#include "util/utest.h"
|
||||
#include "gxs/gxscoreserver.h"
|
||||
#include "gxs/rsdataservice.h"
|
||||
#include "rsdummyservices.h"
|
||||
|
||||
INITTEST();
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
GenExchangeTester tester;
|
||||
|
||||
CHECK(tester.testMsgSubmissionRetrieval()); REPORT("testMsgSubmissionRetrieval()");
|
||||
CHECK(tester.testSpecificMsgMetaRetrieval()); REPORT("testSpecificMsgMetaRetrieval()");
|
||||
CHECK(tester.testMsgIdRetrieval()); REPORT("tester.testMsgIdRetrieval()");
|
||||
CHECK(tester.testMsgIdRetrieval_OptParents()); REPORT("tester.testRelatedMsgIdRetrieval_Parents()");
|
||||
CHECK(tester.testMsgIdRetrieval_OptOrigMsgId()); REPORT("tester.testRelatedMsgIdRetrieval_OrigMsgId()");
|
||||
CHECK(tester.testMsgIdRetrieval_OptLatest()); REPORT("tester.testRelatedMsgIdRetrieval_Latest()");
|
||||
CHECK(tester.testMsgMetaModRequest()); REPORT("tester.testMsgMetaModRequest()");
|
||||
CHECK(tester.testMsgRelatedChildDataRetrieval()); REPORT("tester.testMsgRelatedChildDataRetrieval()");
|
||||
CHECK(tester.testMsgRelatedChildDataRetrieval_Multi()); REPORT("tester.testMsgRelatedChildDataRetrieval_Multi()");
|
||||
CHECK(tester.testMsgAllVersions()); REPORT("tester.testMsgAllVersions()");
|
||||
|
||||
CHECK(tester.testGrpSubmissionRetrieval()); REPORT("tester.testGrpSubmissionRetrieval()");
|
||||
CHECK(tester.testGrpMetaRetrieval()); REPORT("tester.testGrpMetaRetrieval()");
|
||||
CHECK(tester.testGrpIdRetrieval()); REPORT("tester.testGrpIdRetrieval()");
|
||||
CHECK(tester.testGrpMetaModRequest()); REPORT("tester.testGrpMetaModRequest()");
|
||||
|
||||
FINALREPORT("RsGenExchangeTest");
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
|
||||
TEMPLATE = app
|
||||
TARGET = rsgenexcahnge_test
|
||||
CONFIG += debug
|
||||
|
||||
win32 {
|
||||
|
||||
DEFINES *= WINDOWS_SYS \
|
||||
WIN32 \
|
||||
STATICLIB \
|
||||
MINGW
|
||||
|
||||
# Switch on extra warnings
|
||||
QMAKE_CFLAGS += -Wextra
|
||||
QMAKE_CXXFLAGS += -Wextra
|
||||
|
||||
# Switch off optimization for release version
|
||||
QMAKE_CXXFLAGS_RELEASE -= -O2
|
||||
QMAKE_CXXFLAGS_RELEASE += -O0
|
||||
QMAKE_CFLAGS_RELEASE -= -O2
|
||||
QMAKE_CFLAGS_RELEASE += -O0
|
||||
|
||||
# Switch on optimization for debug version
|
||||
#QMAKE_CXXFLAGS_DEBUG += -O2
|
||||
#QMAKE_CFLAGS_DEBUG += -O2
|
||||
|
||||
# PRE_TARGETDEPS += ../../libretroshare/src/lib/libretroshare.a
|
||||
PRE_TARGETDEPS += C:\Development\Rs\v0.5-gxs-b1/libretroshare/libretroshare-build-desktop/lib/libretroshare.a
|
||||
|
||||
LIBS += C:\Development\Rs\v0.5-gxs-b1/libretroshare/libretroshare-build-desktop/lib/libretroshare.a
|
||||
LIBS += C:\Development\Rs\v0.5-gxs-b1\openpgpsdk\openpgpsdk-build-desktop\lib\libops.a
|
||||
LIBS += C:\Development\Libraries\sqlite\sqlite-autoconf-3070900\lib\libsqlite3.a
|
||||
LIBS += -L"../lib"
|
||||
LIBS += -lssl -lcrypto -lgpgme -lpthreadGC2d -lminiupnpc -lz -lbz2
|
||||
# added after bitdht
|
||||
# LIBS += -lws2_32
|
||||
LIBS += -luuid -lole32 -liphlpapi -lcrypt32-cygwin -lgdi32
|
||||
LIBS += -lole32 -lwinmm
|
||||
|
||||
# export symbols for the plugins
|
||||
#LIBS += -Wl,--export-all-symbols,--out-implib,lib/libretroshare-gui.a
|
||||
|
||||
GPG_ERROR_DIR = ../../../../libgpg-error-1.7
|
||||
GPGME_DIR = ../../../../gpgme-1.1.8
|
||||
GPG_ERROR_DIR = ../../../../lib/libgpg-error-1.7
|
||||
GPGME_DIR = ../../../../lib/gpgme-1.1.8
|
||||
INCLUDEPATH += . $${GPGME_DIR}/src $${GPG_ERROR_DIR}/src
|
||||
SQLITE_DIR = ../../Libraries/sqlite/sqlite-autoconf-3070900
|
||||
INCLUDEPATH += . \
|
||||
$${SQLITE_DIR}
|
||||
|
||||
LIBS += -lws2_32
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
INCLUDEPATH += C:\Development\Rs\v0.5-gxs-b1\libretroshare\src
|
||||
|
||||
HEADERS += \
|
||||
genexchangetestservice.h \
|
||||
genexchangetester.h \
|
||||
rsdummyservices.h \
|
||||
support.h
|
||||
|
||||
SOURCES += \
|
||||
genexchangetestservice.cpp \
|
||||
genexchangetester.cpp \
|
||||
rsgenexchange_test.cc \
|
||||
support.cc \
|
||||
rsdummyservices.cc
|
@ -29,7 +29,6 @@
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "retrodb.h"
|
||||
#include "radix64.h"
|
||||
#include "rsdbbind.h"
|
||||
|
||||
//#define RETRODB_DEBUG
|
||||
@ -39,7 +38,7 @@ const int RetroDb::OPEN_READONLY = SQLITE_OPEN_READONLY;
|
||||
const int RetroDb::OPEN_READWRITE = SQLITE_OPEN_READWRITE;
|
||||
const int RetroDb::OPEN_READWRITE_CREATE = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
|
||||
|
||||
RetroDb::RetroDb(const std::string &dbPath, int flags) : mDb(NULL) {
|
||||
RetroDb::RetroDb(const std::string &dbPath, int flags, const std::string& key) : mDb(NULL), mKey(key) {
|
||||
|
||||
int rc = sqlite3_open_v2(dbPath.c_str(), &mDb, flags, NULL);
|
||||
|
||||
@ -48,6 +47,17 @@ RetroDb::RetroDb(const std::string &dbPath, int flags) : mDb(NULL) {
|
||||
<< std::endl;
|
||||
sqlite3_close(mDb);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_ENCRYPTED_DB
|
||||
rc = sqlite3_key(mDb, mKey.c_str(), mKey.size());
|
||||
#endif
|
||||
|
||||
if(rc){
|
||||
std::cerr << "Can't key database: " << sqlite3_errmsg(mDb)
|
||||
<< std::endl;
|
||||
|
||||
sqlite3_close(mDb);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -229,6 +239,11 @@ bool RetroDb::sqlInsert(const std::string &table, const std::string& /* nullColu
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string RetroDb::getKey() const
|
||||
{
|
||||
return mKey;
|
||||
}
|
||||
|
||||
bool RetroDb::execSQL_bind(const std::string &query, std::list<RetroBind*> ¶mBindings){
|
||||
|
||||
// prepare statement
|
||||
|
@ -52,13 +52,18 @@ public:
|
||||
* @param dbPath path to data base file
|
||||
* @param flags determine where to open read only or read/write
|
||||
*/
|
||||
RetroDb(const std::string& dbPath, int flags);
|
||||
RetroDb(const std::string& dbPath, int flags, const std::string& key = "");
|
||||
|
||||
/*!
|
||||
* closes db if it is not already closed
|
||||
*/
|
||||
~RetroDb();
|
||||
|
||||
/*!
|
||||
* @return key used to encrypt database
|
||||
*/
|
||||
std::string getKey() const;
|
||||
|
||||
/*!
|
||||
* opens sqlite data base
|
||||
* @param dbPath
|
||||
@ -173,7 +178,7 @@ private:
|
||||
private:
|
||||
|
||||
sqlite3* mDb;
|
||||
|
||||
const std::string mKey;
|
||||
};
|
||||
|
||||
/*!
|
||||
|
@ -50,7 +50,9 @@ CirclesDialog::CirclesDialog(QWidget *parent)
|
||||
ui.setupUi(this);
|
||||
|
||||
connect( ui.pushButton_refresh, SIGNAL(clicked()), this, SLOT(reloadAll()));
|
||||
connect( ui.pushButton_circle, SIGNAL(clicked()), this, SLOT(create()));
|
||||
connect( ui.pushButton_extCircle, SIGNAL(clicked()), this, SLOT(createExternalCircle()));
|
||||
connect( ui.pushButton_localCircle, SIGNAL(clicked()), this, SLOT(createPersonalCircle()));
|
||||
connect( ui.pushButton_editCircle, SIGNAL(clicked()), this, SLOT(editExistingCircle()));
|
||||
|
||||
QTimer *timer = new QTimer(this);
|
||||
timer->connect(timer, SIGNAL(timeout()), this, SLOT(checkUpdate()));
|
||||
@ -86,10 +88,31 @@ void CirclesDialog::checkUpdate()
|
||||
#define CIRCLEGROUP_FRIEND_COL_NAME 0
|
||||
#define CIRCLEGROUP_FRIEND_COL_ID 1
|
||||
|
||||
void CirclesDialog::create()
|
||||
void CirclesDialog::createExternalCircle()
|
||||
{
|
||||
CreateCircleDialog *createDialog = new CreateCircleDialog();
|
||||
createDialog->editNewId(true);
|
||||
createDialog->show();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void CirclesDialog::createPersonalCircle()
|
||||
{
|
||||
CreateCircleDialog *createDialog = new CreateCircleDialog();
|
||||
createDialog->editNewId(false);
|
||||
createDialog->show();
|
||||
}
|
||||
|
||||
|
||||
void CirclesDialog::editExistingCircle()
|
||||
{
|
||||
#if 0
|
||||
std::string id;
|
||||
CreateCircleDialog *createDialog = new CreateCircleDialog();
|
||||
createDialog->editExistingId(id);
|
||||
createDialog->show();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -586,9 +609,21 @@ void CirclesDialog::loadGroupMeta(const uint32_t &token)
|
||||
}
|
||||
|
||||
/* add the top level item */
|
||||
QTreeWidgetItem *circlesItem = new QTreeWidgetItem();
|
||||
circlesItem->setText(0, "Circles");
|
||||
ui.treeWidget_membership->addTopLevelItem(circlesItem);
|
||||
QTreeWidgetItem *personalCirclesItem = new QTreeWidgetItem();
|
||||
personalCirclesItem->setText(0, "Personal Circles");
|
||||
ui.treeWidget_membership->addTopLevelItem(personalCirclesItem);
|
||||
|
||||
QTreeWidgetItem *externalAdminCirclesItem = new QTreeWidgetItem();
|
||||
externalAdminCirclesItem->setText(0, "External Circles (Admin)");
|
||||
ui.treeWidget_membership->addTopLevelItem(externalAdminCirclesItem);
|
||||
|
||||
QTreeWidgetItem *externalSubCirclesItem = new QTreeWidgetItem();
|
||||
externalSubCirclesItem->setText(0, "External Circles (Subscribed)");
|
||||
ui.treeWidget_membership->addTopLevelItem(externalSubCirclesItem);
|
||||
|
||||
QTreeWidgetItem *externalOtherCirclesItem = new QTreeWidgetItem();
|
||||
externalOtherCirclesItem->setText(0, "External Circles (Other)");
|
||||
ui.treeWidget_membership->addTopLevelItem(externalOtherCirclesItem);
|
||||
|
||||
for(vit = groupInfo.begin(); vit != groupInfo.end(); vit++)
|
||||
{
|
||||
@ -600,7 +635,26 @@ void CirclesDialog::loadGroupMeta(const uint32_t &token)
|
||||
QTreeWidgetItem *groupItem = new QTreeWidgetItem();
|
||||
groupItem->setText(CIRCLEGROUP_CIRCLE_COL_GROUPNAME, QString::fromStdString(vit->mGroupName));
|
||||
groupItem->setText(CIRCLEGROUP_CIRCLE_COL_GROUPID, QString::fromStdString(vit->mGroupId));
|
||||
circlesItem->addChild(groupItem);
|
||||
|
||||
if (vit->mCircleType == GXS_CIRCLE_TYPE_LOCAL)
|
||||
{
|
||||
personalCirclesItem->addChild(groupItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (vit->mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN)
|
||||
{
|
||||
externalAdminCirclesItem->addChild(groupItem);
|
||||
}
|
||||
else if (vit->mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED)
|
||||
{
|
||||
externalSubCirclesItem->addChild(groupItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
externalOtherCirclesItem->addChild(groupItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,9 @@ void loadRequest(const TokenQueue *queue, const TokenRequest &req);
|
||||
|
||||
private slots:
|
||||
|
||||
void create();
|
||||
void createExternalCircle();
|
||||
void createPersonalCircle();
|
||||
void editExistingCircle();
|
||||
|
||||
void checkUpdate();
|
||||
|
||||
|
@ -17,16 +17,23 @@
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_localgroup">
|
||||
<widget class="QPushButton" name="pushButton_localCircle">
|
||||
<property name="text">
|
||||
<string>Create Personal Group</string>
|
||||
<string>Create Personal Circle</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_circle">
|
||||
<widget class="QPushButton" name="pushButton_extCircle">
|
||||
<property name="text">
|
||||
<string>Create Circle</string>
|
||||
<string>Create External Circle</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_editCircle">
|
||||
<property name="text">
|
||||
<string>Edit Circle</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -157,6 +164,9 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_3">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Permissions</string>
|
||||
</property>
|
||||
|
@ -78,6 +78,9 @@ CreateCircleDialog::CreateCircleDialog()
|
||||
connect(ui.addButton, SIGNAL(clicked()), this, SLOT(addMember()));
|
||||
connect(ui.removeButton, SIGNAL(clicked()), this, SLOT(removeMember()));
|
||||
|
||||
connect(ui.pushButton_create, SIGNAL(clicked()), this, SLOT(createCircle()));
|
||||
connect(ui.pushButton_cancel, SIGNAL(clicked()), this, SLOT(cancelDialog()));
|
||||
|
||||
//connect(ui.emoticonButton, SIGNAL(clicked()), this, SLOT(smileyWidgetForums()));
|
||||
//connect(ui.attachFileButton, SIGNAL(clicked()), this, SLOT(addFile()));
|
||||
//connect(ui.pastersButton, SIGNAL(clicked()), this, SLOT(pasteLink()));
|
||||
@ -87,8 +90,13 @@ CreateCircleDialog::CreateCircleDialog()
|
||||
|
||||
ui.removeButton->setEnabled(false);
|
||||
ui.addButton->setEnabled(false);
|
||||
ui.radioButton_ListAll->setChecked(true);
|
||||
requestIdentities();
|
||||
ui.radioButton_ListKnownPGP->setChecked(true);
|
||||
|
||||
mIsExistingCircle = false;
|
||||
mIsExternalCircle = true;
|
||||
|
||||
ui.idChooser->loadIds(0,"");
|
||||
ui.circleComboBox->loadCircles(GXS_CIRCLE_CHOOSER_EXTERNAL);
|
||||
}
|
||||
|
||||
|
||||
@ -99,6 +107,83 @@ CreateCircleDialog::~CreateCircleDialog()
|
||||
delete(mIdQueue);
|
||||
}
|
||||
|
||||
void CreateCircleDialog::editExistingId(std::string circleId)
|
||||
{
|
||||
/* load this circle */
|
||||
mIsExistingCircle = true;
|
||||
|
||||
/* setup personal or external circle */
|
||||
|
||||
bool isExternal = false;
|
||||
if (isExternal)
|
||||
{
|
||||
setupForExternalCircle();
|
||||
}
|
||||
else
|
||||
{
|
||||
setupForPersonalCircle();
|
||||
}
|
||||
|
||||
/* lock stuff they cannot edit */
|
||||
|
||||
|
||||
}
|
||||
|
||||
void CreateCircleDialog::editNewId(bool isExternal)
|
||||
{
|
||||
/* load this circle */
|
||||
mIsExistingCircle = false;
|
||||
|
||||
/* setup personal or external circle */
|
||||
if (isExternal)
|
||||
{
|
||||
setupForExternalCircle();
|
||||
}
|
||||
else
|
||||
{
|
||||
setupForPersonalCircle();
|
||||
}
|
||||
|
||||
/* enable stuff that might be locked */
|
||||
}
|
||||
|
||||
void CreateCircleDialog::setupForPersonalCircle()
|
||||
{
|
||||
mIsExternalCircle = false;
|
||||
|
||||
/* hide distribution line */
|
||||
ui.groupBox_title->setTitle(tr("Personal Circle Details"));
|
||||
ui.frame_PgpTypes->hide();
|
||||
ui.frame_Distribution->hide();
|
||||
ui.idChooserLabel->hide();
|
||||
ui.idChooser->hide();
|
||||
|
||||
getPgpIdentities();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CreateCircleDialog::setupForExternalCircle()
|
||||
{
|
||||
mIsExternalCircle = true;
|
||||
|
||||
/* show distribution line */
|
||||
ui.groupBox_title->setTitle(tr("External Circle Details"));
|
||||
ui.frame_PgpTypes->show();
|
||||
ui.frame_Distribution->show();
|
||||
ui.idChooserLabel->show();
|
||||
ui.idChooser->show();
|
||||
|
||||
requestGxsIdentities();
|
||||
}
|
||||
|
||||
|
||||
void CreateCircleDialog::cancelDialog()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CreateCircleDialog::selectedId(QTreeWidgetItem *current, QTreeWidgetItem *previous)
|
||||
{
|
||||
@ -532,13 +617,29 @@ void CreateCircleDialog::addMember()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* check that its not there already */
|
||||
QString keyId = item->text(RSCIRCLEID_COL_KEYID);
|
||||
QTreeWidget *tree = ui.treeWidget_membership;
|
||||
|
||||
int count = tree->topLevelItemCount();
|
||||
for(int i = 0; i < count; i++)
|
||||
{
|
||||
QTreeWidgetItem *item = tree->topLevelItem(i);
|
||||
if (keyId == item->text(RSCIRCLEID_COL_KEYID))
|
||||
{
|
||||
std::cerr << "CreateCircleDialog::addMember() Already is a Member: " << keyId.toStdString();
|
||||
std::cerr << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QTreeWidgetItem *member = new QTreeWidgetItem();
|
||||
member->setText(RSCIRCLEID_COL_NICKNAME, item->text(RSCIRCLEID_COL_NICKNAME));
|
||||
member->setText(RSCIRCLEID_COL_KEYID, item->text(RSCIRCLEID_COL_KEYID));
|
||||
member->setText(RSCIRCLEID_COL_IDTYPE, item->text(RSCIRCLEID_COL_IDTYPE));
|
||||
|
||||
ui.treeWidget_membership->addTopLevelItem(member);
|
||||
|
||||
tree->addTopLevelItem(member);
|
||||
}
|
||||
|
||||
|
||||
@ -558,6 +659,9 @@ void CreateCircleDialog::removeMember()
|
||||
|
||||
void CreateCircleDialog::createCircle()
|
||||
{
|
||||
std::cerr << "CreateCircleDialog::createCircle()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
QString name = ui.circleName->text();
|
||||
QString desc;
|
||||
|
||||
@ -588,8 +692,106 @@ void CreateCircleDialog::createCircle()
|
||||
|
||||
|
||||
/* copy Ids from GUI */
|
||||
QTreeWidget *tree = ui.treeWidget_membership;
|
||||
int count = tree->topLevelItemCount();
|
||||
for(int i = 0; i < count; i++)
|
||||
{
|
||||
QTreeWidgetItem *item = tree->topLevelItem(i);
|
||||
QString keyId = item->text(RSCIRCLEID_COL_KEYID);
|
||||
|
||||
/* insert into circle */
|
||||
if (mIsExternalCircle)
|
||||
{
|
||||
circle.mInvitedMembers.push_back(keyId.toStdString());
|
||||
std::cerr << "CreateCircleDialog::createCircle() Inserting Member: " << keyId.toStdString();
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
circle.mLocalFriends.push_back(keyId.toStdString());
|
||||
std::cerr << "CreateCircleDialog::createCircle() Inserting Friend: " << keyId.toStdString();
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (mIsExistingCircle)
|
||||
{
|
||||
std::cerr << "CreateCircleDialog::createCircle() Existing Circle TODO";
|
||||
std::cerr << std::endl;
|
||||
|
||||
// cannot edit these yet.
|
||||
QMessageBox::warning(this, tr("RetroShare"),tr("Cannot Edit Existing Circles Yet"),
|
||||
QMessageBox::Ok, QMessageBox::Ok);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mIsExternalCircle)
|
||||
{
|
||||
std::cerr << "CreateCircleDialog::createCircle() External Circle";
|
||||
std::cerr << std::endl;
|
||||
|
||||
// set distribution from GUI.
|
||||
circle.mMeta.mCircleId = "";
|
||||
if (ui.radioButton_Public->isChecked())
|
||||
{
|
||||
std::cerr << "CreateCircleDialog::createCircle() Public Circle";
|
||||
std::cerr << std::endl;
|
||||
|
||||
circle.mMeta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC;
|
||||
}
|
||||
else if (ui.radioButton_Self->isChecked())
|
||||
{
|
||||
std::cerr << "CreateCircleDialog::createCircle() ExtSelfRef Circle";
|
||||
std::cerr << std::endl;
|
||||
|
||||
circle.mMeta.mCircleType = GXS_CIRCLE_TYPE_EXT_SELF;
|
||||
}
|
||||
else if (ui.radioButton_Restricted->isChecked())
|
||||
{
|
||||
std::cerr << "CreateCircleDialog::createCircle() External (Other) Circle";
|
||||
std::cerr << std::endl;
|
||||
|
||||
circle.mMeta.mCircleType = GXS_CIRCLE_TYPE_EXTERNAL;
|
||||
|
||||
/* grab circle ID from chooser */
|
||||
RsGxsCircleId chosenId;
|
||||
if (ui.circleComboBox->getChosenCircle(chosenId))
|
||||
{
|
||||
std::cerr << "CreateCircleDialog::createCircle() ChosenId: " << chosenId;
|
||||
std::cerr << std::endl;
|
||||
|
||||
circle.mMeta.mCircleId = chosenId;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "CreateCircleDialog::createCircle() Error no Id Chosen";
|
||||
std::cerr << std::endl;
|
||||
|
||||
QMessageBox::warning(this, tr("RetroShare"),tr("No Restriction Circle Selected"),
|
||||
QMessageBox::Ok, QMessageBox::Ok);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::warning(this, tr("RetroShare"),tr("No Circle Limitations Selected"),
|
||||
QMessageBox::Ok, QMessageBox::Ok);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "CreateCircleDialog::createCircle() Personal Circle";
|
||||
std::cerr << std::endl;
|
||||
|
||||
// set personal distribution
|
||||
circle.mMeta.mCircleId = "";
|
||||
circle.mMeta.mCircleType = GXS_CIRCLE_TYPE_LOCAL;
|
||||
}
|
||||
|
||||
std::cerr << "CreateCircleDialog::createCircle() Checks and Balances Okay - calling service proper..";
|
||||
std::cerr << std::endl;
|
||||
|
||||
uint32_t token;
|
||||
rsGxsCircles->createGroup(token, circle);
|
||||
@ -648,7 +850,37 @@ void CreateCircleDialog::loadCircle(uint32_t token)
|
||||
}
|
||||
|
||||
|
||||
void CreateCircleDialog::requestIdentities()
|
||||
void CreateCircleDialog::getPgpIdentities()
|
||||
{
|
||||
std::cerr << "CreateCircleDialog::getPgpIdentities()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
QTreeWidget *tree = ui.treeWidget_IdList;
|
||||
|
||||
tree->clear();
|
||||
|
||||
std::list<std::string> ids;
|
||||
std::list<std::string>::iterator it;
|
||||
|
||||
|
||||
rsPeers->getGPGAcceptedList(ids);
|
||||
for(it = ids.begin(); it != ids.end(); it++)
|
||||
{
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem();
|
||||
RsPeerDetails details;
|
||||
|
||||
rsPeers->getGPGDetails(*it, details);
|
||||
|
||||
item->setText(RSCIRCLEID_COL_IDTYPE, "PGP Identity");
|
||||
item->setText(RSCIRCLEID_COL_NICKNAME, QString::fromStdString(details.name));
|
||||
item->setText(RSCIRCLEID_COL_KEYID, QString::fromStdString(details.gpg_id));
|
||||
|
||||
tree->addTopLevelItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CreateCircleDialog::requestGxsIdentities()
|
||||
{
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
|
||||
@ -676,7 +908,6 @@ void CreateCircleDialog::loadIdentities(uint32_t token)
|
||||
std::list<std::string> ids;
|
||||
std::list<std::string>::iterator it;
|
||||
|
||||
bool acceptAll = ui.radioButton_ListAll->isChecked();
|
||||
bool acceptAllPGP = ui.radioButton_ListAllPGP->isChecked();
|
||||
bool acceptKnownPGP = ui.radioButton_ListKnownPGP->isChecked();
|
||||
|
||||
@ -696,11 +927,7 @@ void CreateCircleDialog::loadIdentities(uint32_t token)
|
||||
|
||||
/* do filtering */
|
||||
bool ok = false;
|
||||
if (acceptAll)
|
||||
{
|
||||
ok = true;
|
||||
}
|
||||
else if (data.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID)
|
||||
if (data.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID)
|
||||
{
|
||||
if (acceptAllPGP)
|
||||
{
|
||||
|
@ -39,6 +39,9 @@ public:
|
||||
CreateCircleDialog();
|
||||
~CreateCircleDialog();
|
||||
|
||||
void editNewId(bool isExternal);
|
||||
void editExistingId(std::string circleId);
|
||||
|
||||
#if 0
|
||||
void newMsg(); /* cleanup */
|
||||
#endif
|
||||
@ -53,6 +56,9 @@ private slots:
|
||||
void selectedId(QTreeWidgetItem*, QTreeWidgetItem*);
|
||||
void selectedMember(QTreeWidgetItem*, QTreeWidgetItem*);
|
||||
|
||||
void createCircle();
|
||||
void cancelDialog();
|
||||
|
||||
#if 0
|
||||
/** Create the context popup menu and it's submenus */
|
||||
void forumMessageCostumPopupMenu( QPoint point );
|
||||
@ -94,13 +100,18 @@ private:
|
||||
RsGroupMetaData mForumMeta;
|
||||
#endif
|
||||
|
||||
void createCircle();
|
||||
void setupForPersonalCircle();
|
||||
void setupForExternalCircle();
|
||||
|
||||
bool mIsExistingCircle;
|
||||
bool mIsExternalCircle;
|
||||
|
||||
void loadCircle(uint32_t token);
|
||||
void loadIdentities(uint32_t token);
|
||||
|
||||
void requestCircle(const RsGxsGroupId &groupId);
|
||||
void requestIdentities();
|
||||
void requestGxsIdentities();
|
||||
void getPgpIdentities();
|
||||
|
||||
TokenQueue *mCircleQueue;
|
||||
TokenQueue *mIdQueue;
|
||||
|
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>746</width>
|
||||
<height>568</height>
|
||||
<width>681</width>
|
||||
<height>544</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -15,7 +15,7 @@
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0" colspan="3">
|
||||
<widget class="QGroupBox" name="groupBox_5">
|
||||
<widget class="QGroupBox" name="groupBox_title">
|
||||
<property name="title">
|
||||
<string>Circle Details</string>
|
||||
</property>
|
||||
@ -39,7 +39,7 @@
|
||||
<widget class="QLineEdit" name="circleName"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<widget class="QLabel" name="idChooserLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
@ -57,58 +57,72 @@
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Distribution</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioButton_Public">
|
||||
<property name="text">
|
||||
<string>Public</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioButton_Self">
|
||||
<property name="text">
|
||||
<string>Self-Restricted</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioButton_Restricted">
|
||||
<property name="text">
|
||||
<string>Restricted to:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="GxsCircleChooser" name="circleComboBox"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
<widget class="QFrame" name="frame_Distribution">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Distribution</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioButton_Public">
|
||||
<property name="text">
|
||||
<string>Public</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioButton_Self">
|
||||
<property name="text">
|
||||
<string>Self-Restricted</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioButton_Restricted">
|
||||
<property name="text">
|
||||
<string>Restricted to:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="GxsCircleChooser" name="circleComboBox"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>147</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
@ -187,29 +201,36 @@
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioButton_ListAll">
|
||||
<property name="text">
|
||||
<string>All IDs</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioButton_ListAllPGP">
|
||||
<property name="text">
|
||||
<string>All PGP IDs</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioButton_ListKnownPGP">
|
||||
<property name="text">
|
||||
<string>Known PGP IDs</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<widget class="QFrame" name="frame_PgpTypes">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioButton_ListAllPGP">
|
||||
<property name="text">
|
||||
<string>All PGP IDs</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioButton_ListKnownPGP">
|
||||
<property name="text">
|
||||
<string>Known PGP IDs</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
@ -263,14 +284,14 @@
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_publicgroup_2">
|
||||
<widget class="QPushButton" name="pushButton_cancel">
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_publicgroup">
|
||||
<widget class="QPushButton" name="pushButton_create">
|
||||
<property name="text">
|
||||
<string>Create Group</string>
|
||||
</property>
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user