Nxs items now do not support the concept of version

timestamp has been added to grp sync item 
updated data service and grps to deal with this
added msg and grp meta types which serves to hold meta data of grp and msg 
removed observer temporarily 

updated nxs item tests, need to update data service tests

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-new_cache_system@5256 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2012-06-26 19:52:01 +00:00
parent 03e2ee72e0
commit d533a2e580
15 changed files with 965 additions and 729 deletions

View File

@ -15,38 +15,76 @@
#define KEY_IDENTITY_SIGN std::string("idSign")
#define KEY_TIME_STAMP std::string("timeStamp")
#define KEY_NXS_FLAGS std::string("flags")
#define KEY_NXS_META std::string("meta")
// grp table columns
#define KEY_ADMIN_SIGN std::string("adminSign")
#define KEY_KEY_SET std::string("keySet")
#define KEY_GRP_NAME std::string("grpName")
// grp local
#define KEY_GRP_SUBCR_FLAG std::string("subscribeFlag")
#define KEY_GRP_POP std::string("popularity")
#define KEY_MSG_COUNT std::string("msgCount")
#define KEY_GRP_STATUS std::string("grpStatus")
#define KEY_GRP_LAST_POST std::string("lastPost")
// msg table columns
#define KEY_PUBLISH_SIGN std::string("publishSign")
#define KEY_MSG_ID std::string("msgId")
#define KEY_ORIG_MSG_ID std::string("origMsgId")
#define KEY_MSG_PARENT_ID std::string("parentId")
#define KEY_MSG_THREAD_ID std::string("threadId")
#define KEY_MSG_NAME std::string("msgName")
// msg local
#define KEY_MSG_STATUS std::string("msgStatus")
#define KEY_CHILD_TS std::string("childTs")
/*** actual data col numbers ***/
// generic
#define COL_ACT_GROUP_ID 0
#define COL_NXS_FILE 1
#define COL_NXS_FILE_OFFSET 2
#define COL_NXS_FILE_LEN 3
#define COL_META_DATA 4
#define COL_ACT_MSG_ID 5
/*** meta column numbers ***/
// grp col numbers
#define COL_GRP_ID 0
#define COL_ADMIN_SIGN 1
#define COL_KEY_SET 9
#define COL_ADMIN_SIGN 5
#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 11
#define COL_GRP_NAME 12
#define COL_GRP_LAST_POST 13
// msg col numbers
#define COL_PUBLISH_SIGN 1
#define COL_MSG_ID 9
#define COL_ORIG_MSG_ID 10
// generic col numbers
#define COL_NXS_FILE 2
#define COL_NXS_FILE_OFFSET 3
#define COL_NXS_FILE_LEN 4
#define COL_TIME_STAMP 5
#define COL_NXS_FLAGS 6
#define COL_IDENTITY_SIGN 7
#define COL_IDENTITY 8
#define COL_PUBLISH_SIGN 5
#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
// generic meta shared col numbers
#define COL_GRP_ID 0
#define COL_TIME_STAMP 1
#define COL_NXS_FLAGS 2
#define COL_IDENTITY_SIGN 3
#define COL_IDENTITY 4
#define RS_DATA_SERVICE_DEBUG
@ -56,15 +94,27 @@ RsDataService::RsDataService(const std::string &serviceDir, const std::string &d
initialise();
msgColumns.push_back(KEY_GRP_ID); msgColumns.push_back(KEY_PUBLISH_SIGN); msgColumns.push_back(KEY_NXS_FILE);
msgColumns.push_back(KEY_NXS_FILE_OFFSET); msgColumns.push_back(KEY_NXS_FILE_LEN); msgColumns.push_back(KEY_TIME_STAMP);
msgColumns.push_back(KEY_NXS_FLAGS); msgColumns.push_back(KEY_IDENTITY_SIGN); msgColumns.push_back(KEY_NXS_IDENTITY);
msgColumns.push_back(KEY_MSG_ID); msgColumns.push_back(KEY_ORIG_MSG_ID);
// 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_IDENTITY_SIGN); msgMetaColumns.push_back(KEY_NXS_IDENTITY); msgMetaColumns.push_back(KEY_PUBLISH_SIGN);
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);
grpColumns.push_back(KEY_GRP_ID); grpColumns.push_back(KEY_ADMIN_SIGN); grpColumns.push_back(KEY_NXS_FILE);
grpColumns.push_back(KEY_NXS_FILE_OFFSET); grpColumns.push_back(KEY_NXS_FILE_LEN); grpColumns.push_back(KEY_TIME_STAMP);
grpColumns.push_back(KEY_NXS_FLAGS); grpColumns.push_back(KEY_IDENTITY_SIGN);
grpColumns.push_back(KEY_NXS_IDENTITY); grpColumns.push_back(KEY_KEY_SET);
// for retrieving actual data
msgColumns.push_back(KEY_GRP_ID); msgColumns.push_back(KEY_NXS_FILE); msgColumns.push_back(KEY_NXS_FILE_OFFSET);
msgColumns.push_back(KEY_NXS_FILE_LEN); msgColumns.push_back(KEY_NXS_META); msgColumns.push_back(KEY_MSG_ID);
// 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_IDENTITY_SIGN); grpMetaColumns.push_back(KEY_NXS_IDENTITY); grpMetaColumns.push_back(KEY_ADMIN_SIGN);
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);
// for retrieving actual grp data
grpColumns.push_back(KEY_GRP_ID); grpColumns.push_back(KEY_NXS_FILE); grpColumns.push_back(KEY_NXS_FILE_OFFSET);
grpColumns.push_back(KEY_NXS_FILE_LEN); grpColumns.push_back(KEY_NXS_META);
}
RsDataService::~RsDataService(){
@ -77,23 +127,89 @@ void RsDataService::initialise(){
// initialise database
mDb = new RetroDb(mDbName, RetroDb::OPEN_READWRITE_CREATE);
// create table for msgs
// create table for msg data
mDb->execSQL("CREATE TABLE " + MSG_TABLE_NAME + "(" + KEY_MSG_ID
+ " TEXT," + KEY_GRP_ID + " TEXT," + KEY_NXS_FLAGS + " INT," + KEY_ORIG_MSG_ID + " TEXT,"
+ KEY_TIME_STAMP + " INT," + KEY_PUBLISH_SIGN + " BLOB," + KEY_NXS_IDENTITY + " TEXT,"
+ KEY_IDENTITY_SIGN + " BLOB," + KEY_NXS_FILE + " TEXT,"+ KEY_NXS_FILE_OFFSET + " INT,"
+ KEY_MSG_STATUS + " INT," + KEY_CHILD_TS + " INT,"+ KEY_NXS_META + " BLOB,"
+ KEY_MSG_THREAD_ID + " TEXT," + KEY_MSG_PARENT_ID + " TEXT,"+ KEY_MSG_NAME + " TEXT,"
+ KEY_NXS_FILE_LEN+ " INT);");
// create table for grps
// create table for grp data
mDb->execSQL("CREATE TABLE " + GRP_TABLE_NAME + "(" + KEY_GRP_ID +
" TEXT," + KEY_TIME_STAMP + " INT," +
KEY_ADMIN_SIGN + " BLOB," + " BLOB," + KEY_NXS_FILE +
" TEXT," + KEY_NXS_FILE_OFFSET + " INT," + KEY_KEY_SET + " BLOB," + KEY_NXS_FILE_LEN + " INT,"
+ KEY_NXS_META + " BLOB," + KEY_GRP_NAME + " TEXT," + KEY_GRP_LAST_POST + " INT,"
+ KEY_GRP_LAST_POST + " INT," + KEY_GRP_POP + " INT," + KEY_MSG_COUNT + " INT,"
+ KEY_GRP_SUBCR_FLAG + " INT," + KEY_GRP_STATUS + " INT,"
+ KEY_NXS_IDENTITY + " TEXT," + KEY_NXS_FLAGS + " INT," + KEY_IDENTITY_SIGN + " BLOB);");
}
RsNxsGrp* RsDataService::getGroup(RetroCursor &c){
RsGxsGrpMetaData* RsDataService::getGrpMeta(RetroCursor &c)
{
RsGxsGrpMetaData* grpMeta = new RsGxsGrpMetaData();
bool ok = true;
// for manipulating raw data
uint32_t offset = 0;
char* data = NULL;
uint32_t data_len = 0;
// grpId
c.getString(COL_GRP_ID, grpMeta->mGroupId);
// required definition of a group
ok &= !grpMeta->mGroupId.empty();
// identity if any
c.getString(COL_IDENTITY, grpMeta->mAuthorId);
c.getString(COL_GRP_NAME, grpMeta->mGroupName);
grpMeta->mPublishTs = c.getInt32(COL_TIME_STAMP);
grpMeta->mGroupFlags = c.getInt32(COL_NXS_FLAGS);
if(!grpMeta->mAuthorId.empty() && ok){
offset = 0;
data = (char*)c.getData(COL_IDENTITY_SIGN, data_len);
if(data)
grpMeta->idSign.GetTlv(data, data_len, &offset);
}
offset = 0;
data = (char*)c.getData(COL_ADMIN_SIGN, data_len);
if(data)
grpMeta->adminSign.GetTlv(data, data_len, &offset);
offset = 0; data = NULL; data_len = 0;
data = (char*)c.getData(COL_KEY_SET, data_len);
if(data)
ok &= grpMeta->keys.GetTlv(data, data_len, &offset);
// local meta
grpMeta->mSubscribeFlags = c.getInt32(COL_GRP_SUBCR_FLAG);
grpMeta->mPop = c.getInt32(COL_GRP_POP);
grpMeta->mMsgCount = c.getInt32(COL_MSG_COUNT);
grpMeta->mLastPost = c.getInt32(COL_GRP_LAST_POST);
grpMeta->mGroupStatus = c.getInt32(COL_GRP_STATUS);
if(ok)
return grpMeta;
else
delete grpMeta;
return NULL;
}
RsNxsGrp* RsDataService::getGroup(RetroCursor &c)
{
/*!
* grpId, pub admin and pub publish key
@ -109,43 +225,21 @@ RsNxsGrp* RsDataService::getGroup(RetroCursor &c){
uint32_t data_len = 0;
// grpId
c.getString(COL_GRP_ID, grp->grpId);
c.getString(COL_ACT_GROUP_ID, grp->grpId);
ok &= !grp->grpId.empty();
// identity if any
c.getString(COL_IDENTITY, grp->identity);
grp->timeStamp = c.getInt32(COL_TIME_STAMP);
offset = 0; data_len = 0;
if(ok){
if(!( grp->identity.empty() ) && ok){
offset = 0;
data = (char*)c.getData(COL_IDENTITY_SIGN, data_len);
if(data){
grp->idSign.GetTlv(data, data_len, &offset);
}
}
offset = 0;
data = (char*)c.getData(COL_ADMIN_SIGN, data_len);
if(data){
grp->adminSign.GetTlv(data, data_len, &offset);
}
grp->grpFlag = c.getInt32(COL_NXS_FLAGS);
offset = 0; data = NULL; data_len = 0;
data = (char*)c.getData(COL_KEY_SET, data_len);
if(data){
ok &= grp->keys.GetTlv(data, data_len, &offset);
data = (char*)c.getData(COL_META_DATA, data_len);
if(data)
grp->meta.GetTlv(data, data_len, &offset);
}
/* now retrieve grp data from file */
std::string grpFile;
c.getString(COL_NXS_FILE, grpFile);
ok &= !grpFile.empty();
/* now retrieve grp data from file */
if(ok){
@ -170,8 +264,65 @@ RsNxsGrp* RsDataService::getGroup(RetroCursor &c){
return NULL;
}
RsGxsMsgMetaData* RsDataService::getMsgMeta(RetroCursor &c)
{
RsNxsMsg* RsDataService::getMessage(RetroCursor &c){
RsGxsMsgMetaData* msgMeta = new RsGxsMsgMetaData();
bool ok = true;
uint32_t data_len = 0,
offset = 0;
char* data = NULL;
c.getString(COL_GRP_ID, msgMeta->mGroupId);
c.getString(COL_MSG_ID, msgMeta->mMsgId);
// without these, a msg is meaningless
ok &= (!msgMeta->mGroupId.empty()) && (!msgMeta->mMsgId.empty());
c.getString(COL_ORIG_MSG_ID, msgMeta->mOrigMsgId);
c.getString(COL_IDENTITY, msgMeta->mAuthorId);
c.getString(COL_MSG_NAME, msgMeta->mMsgName);
if(!msgMeta->mAuthorId.empty()){
offset = 0;
data = (char*)c.getData(COL_IDENTITY_SIGN, data_len);
msgMeta->idSign.GetTlv(data, data_len, &offset);
}
msgMeta->mMsgFlags = c.getInt32(COL_NXS_FLAGS);
msgMeta->mPublishTs = c.getInt32(COL_TIME_STAMP);
offset = 0; data_len = 0;
if(ok){
data = (char*)c.getData(COL_PUBLISH_SIGN, data_len);
if(data)
msgMeta->pubSign.GetTlv(data, data_len, &offset);
}
// thread and parent id
c.getString(COL_THREAD_ID, msgMeta->mThreadId);
c.getString(COL_PARENT_ID, msgMeta->mParentId);
// local meta
msgMeta->mMsgStatus = c.getInt32(COL_MSG_STATUS);
msgMeta->mChildTs = c.getInt32(COL_CHILD_TS);
if(ok)
return msgMeta;
else
delete msgMeta;
return NULL;
}
RsNxsMsg* RsDataService::getMessage(RetroCursor &c)
{
RsNxsMsg* msg = new RsNxsMsg(mServType);
@ -179,37 +330,25 @@ RsNxsMsg* RsDataService::getMessage(RetroCursor &c){
uint32_t data_len = 0,
offset = 0;
char* data = NULL;
c.getString(COL_GRP_ID, msg->grpId);
c.getString(COL_MSG_ID, msg->msgId);
c.getString(COL_ACT_GROUP_ID, msg->grpId);
c.getString(COL_ACT_MSG_ID, msg->msgId);
ok &= (!msg->grpId.empty()) && (!msg->msgId.empty());
c.getString(COL_IDENTITY, msg->identity);
if(!msg->identity.empty()){
offset = 0;
data = (char*)c.getData(COL_IDENTITY_SIGN, data_len);
msg->idSign.GetTlv(data, data_len, &offset);
}
msg->msgFlag = c.getInt32(COL_NXS_FLAGS);
msg->timeStamp = c.getInt32(COL_TIME_STAMP);
offset = 0; data_len = 0;
if(ok){
data = (char*)c.getData(COL_PUBLISH_SIGN, data_len);
data = (char*)c.getData(COL_META_DATA, data_len);
if(data)
msg->publishSign.GetTlv(data, data_len, &offset);
msg->meta.GetTlv(data, data_len, &offset);
}
/* now retrieve grp data from file */
std::string msgFile;
c.getString(COL_NXS_FILE, msgFile);
offset = c.getInt32(COL_NXS_FILE_OFFSET);
data_len = c.getInt32(COL_NXS_FILE_LEN);
ok &= !msgFile.empty();
/* now retrieve grp data from file */
if(ok){
@ -231,44 +370,60 @@ RsNxsMsg* RsDataService::getMessage(RetroCursor &c){
return NULL;
}
int RsDataService::storeMessage(std::set<RsNxsMsg *> &msg){
std::set<RsNxsMsg*>::iterator sit = msg.begin();
int RsDataService::storeMessage(std::map<RsNxsMsg *, RsGxsMsgMetaData *> &msg)
{
std::map<RsNxsMsg*, RsGxsMsgMetaData* >::iterator mit = msg.begin();
// start a transaction
mDb->execSQL("BEGIN;");
for(; mit != msg.end(); mit++){
for(; sit != msg.end(); sit++){
RsNxsMsg* msgPtr = mit->first;
RsGxsMsgMetaData* msgMetaPtr = mit->second;
RsNxsMsg* msgPtr = *sit;
// create or access file in binary
std::string msgFile = mServiceDir + "/" + msgPtr->grpId + "-msgs";
std::fstream ostrm(msgFile.c_str(), std::ios::binary | std::ios::app | std::ios::out);
ostrm.seekg(0, std::ios::end); // go to end to append
uint32_t offset = ostrm.tellg(); // get fill offset
ContentValue cv;
cv.put(KEY_NXS_FILE_OFFSET, (int32_t)offset);
cv.put(KEY_NXS_FILE, msgFile);
cv.put(KEY_NXS_FILE_LEN, (int32_t)msgPtr->msg.TlvSize());
cv.put(KEY_MSG_ID, msgPtr->msgId);
cv.put(KEY_GRP_ID, msgPtr->grpId);
char pubSignData[msgPtr->publishSign.TlvSize()];
cv.put(KEY_MSG_ID, msgMetaPtr->mMsgId);
cv.put(KEY_GRP_ID, msgMetaPtr->mGroupId);
char pubSignData[msgMetaPtr->pubSign.TlvSize()];
offset = 0;
msgPtr->publishSign.SetTlv(pubSignData, msgPtr->publishSign.TlvSize(), &offset);
cv.put(KEY_PUBLISH_SIGN, msgPtr->publishSign.TlvSize(), pubSignData);
msgMetaPtr->pubSign.SetTlv(pubSignData, msgMetaPtr->pubSign.TlvSize(), &offset);
cv.put(KEY_PUBLISH_SIGN, msgMetaPtr->pubSign.TlvSize(), pubSignData);
if(! (msgPtr->identity.empty()) ){
char idSignData[msgPtr->idSign.TlvSize()];
if(! (msgMetaPtr->mAuthorId.empty()) ){
char idSignData[msgMetaPtr->idSign.TlvSize()];
offset = 0;
msgPtr->idSign.SetTlv(idSignData, msgPtr->idSign.TlvSize(), &offset);
cv.put(KEY_IDENTITY_SIGN, msgPtr->idSign.TlvSize(), idSignData);
cv.put(KEY_NXS_IDENTITY, msgPtr->identity);
msgMetaPtr->idSign.SetTlv(idSignData, msgMetaPtr->idSign.TlvSize(), &offset);
cv.put(KEY_IDENTITY_SIGN, msgMetaPtr->idSign.TlvSize(), idSignData);
cv.put(KEY_NXS_IDENTITY, msgMetaPtr->mAuthorId);
}
cv.put(KEY_NXS_FLAGS, (int32_t) msgPtr->msgFlag);
cv.put(KEY_TIME_STAMP, (int32_t) msgPtr->timeStamp);
cv.put(KEY_NXS_FLAGS, (int32_t) msgMetaPtr->mMsgFlags);
cv.put(KEY_TIME_STAMP, (int32_t) msgMetaPtr->mPublishTs);
offset = 0;
char metaData[msgPtr->meta.TlvSize()];
msgPtr->meta.SetTlv(metaData, msgPtr->meta.TlvSize(), &offset);
cv.put(KEY_NXS_META, msgPtr->meta.TlvSize(), metaData);
cv.put(KEY_MSG_PARENT_ID, msgMetaPtr->mParentId);
cv.put(KEY_MSG_THREAD_ID, msgMetaPtr->mThreadId);
cv.put(KEY_MSG_NAME, msgMetaPtr->mMsgName);
// now local meta
cv.put(KEY_MSG_STATUS, (int32_t)msgMetaPtr->mMsgStatus);
cv.put(KEY_CHILD_TS, (int32_t)msgMetaPtr->mChildTs);
offset = 0;
char msgData[msgPtr->msg.TlvSize()];
@ -276,58 +431,77 @@ int RsDataService::storeMessage(std::set<RsNxsMsg *> &msg){
ostrm.write(msgData, msgPtr->msg.TlvSize());
ostrm.close();
mDb->sqlInsert(MSG_TABLE_NAME, "", cv);
}
// finish transaction
return mDb->execSQL("COMMIT;");;
}
int RsDataService::storeGroup(std::set<RsNxsGrp *> &grp){
std::set<RsNxsGrp*>::iterator sit = grp.begin();
int RsDataService::storeGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
{
std::map<RsNxsGrp*, RsGxsGrpMetaData* >::iterator sit = grp.begin();
// begin transaction
mDb->execSQL("BEGIN;");
for(; sit != grp.end(); sit++){
RsNxsGrp* grpPtr = *sit;
RsNxsGrp* grpPtr = sit->first;
RsGxsGrpMetaData* grpMetaPtr = sit->second;
std::string grpFile = mServiceDir + "/" + grpPtr->grpId;
std::fstream ostrm(grpFile.c_str(), std::ios::binary | std::ios::app | std::ios::out);
ostrm.seekg(0, std::ios::end); // go to end to append
uint32_t offset = ostrm.tellg(); // get fill offset
/*!
* STORE file offset, file length, file name,
* grpId, flags, publish time stamp, identity,
* id signature, admin signatue, key set, last posting ts
* and meta data
**/
ContentValue cv;
cv.put(KEY_NXS_FILE_OFFSET, (int32_t)offset);
cv.put(KEY_NXS_FILE_LEN, (int32_t)grpPtr->grp.TlvSize());
cv.put(KEY_NXS_FILE, grpFile);
cv.put(KEY_GRP_ID, grpPtr->grpId);
cv.put(KEY_NXS_FLAGS, (int32_t)grpPtr->grpFlag);
cv.put(KEY_TIME_STAMP, (int32_t)grpPtr->timeStamp);
cv.put(KEY_GRP_ID, grpMetaPtr->mGroupId);
cv.put(KEY_NXS_FLAGS, (int32_t)grpMetaPtr->mGroupFlags);
cv.put(KEY_TIME_STAMP, (int32_t)grpMetaPtr->mPublishTs);
if(! (grpPtr->identity.empty()) ){
cv.put(KEY_NXS_IDENTITY, grpPtr->identity);
if(! (grpMetaPtr->mAuthorId.empty()) ){
cv.put(KEY_NXS_IDENTITY, grpMetaPtr->mAuthorId);
char idSignData[grpPtr->idSign.TlvSize()];
char idSignData[grpMetaPtr->idSign.TlvSize()];
offset = 0;
grpPtr->idSign.SetTlv(idSignData, grpPtr->idSign.TlvSize(), &offset);
cv.put(KEY_IDENTITY_SIGN, grpPtr->idSign.TlvSize(), idSignData);
std::string wat(idSignData, grpPtr->idSign.TlvSize());
grpMetaPtr->idSign.SetTlv(idSignData, grpMetaPtr->idSign.TlvSize(), &offset);
cv.put(KEY_IDENTITY_SIGN, grpMetaPtr->idSign.TlvSize(), idSignData);
std::string wat(idSignData, grpMetaPtr->idSign.TlvSize());
std::cerr << wat << std::endl;
}
char adminSignData[grpPtr->adminSign.TlvSize()];
char adminSignData[grpMetaPtr->adminSign.TlvSize()];
offset = 0;
grpPtr->adminSign.SetTlv(adminSignData, grpPtr->adminSign.TlvSize(), &offset);
cv.put(KEY_ADMIN_SIGN, grpPtr->adminSign.TlvSize(), adminSignData);
grpMetaPtr->adminSign.SetTlv(adminSignData, grpMetaPtr->adminSign.TlvSize(), &offset);
cv.put(KEY_ADMIN_SIGN, grpMetaPtr->adminSign.TlvSize(), adminSignData);
offset = 0;
char keySetData[grpPtr->keys.TlvSize()];
grpPtr->keys.SetTlv(keySetData, grpPtr->keys.TlvSize(), &offset);
cv.put(KEY_KEY_SET, grpPtr->keys.TlvSize(), keySetData);
char keySetData[grpMetaPtr->keys.TlvSize()];
grpMetaPtr->keys.SetTlv(keySetData, grpMetaPtr->keys.TlvSize(), &offset);
cv.put(KEY_KEY_SET, grpMetaPtr->keys.TlvSize(), keySetData);
offset = 0;
char metaData[grpPtr->meta.TlvSize()];
grpPtr->meta.SetTlv(metaData, grpPtr->meta.TlvSize(), &offset);
cv.put(KEY_NXS_META, grpPtr->meta.TlvSize(), metaData);
// local meta data
cv.put(KEY_GRP_SUBCR_FLAG, (int32_t)grpMetaPtr->mSubscribeFlags);
cv.put(KEY_GRP_POP, (int32_t)grpMetaPtr->mPop);
cv.put(KEY_MSG_COUNT, (int32_t)grpMetaPtr->mMsgCount);
cv.put(KEY_GRP_STATUS, (int32_t)grpMetaPtr->mGroupStatus);
cv.put(KEY_GRP_LAST_POST, (int32_t)grpMetaPtr->mLastPost);
offset = 0;
char grpData[grpPtr->grp.TlvSize()];
@ -337,11 +511,11 @@ int RsDataService::storeGroup(std::set<RsNxsGrp *> &grp){
mDb->sqlInsert(GRP_TABLE_NAME, "", cv);
}
// finish transaction
return mDb->execSQL("COMMIT;");
}
int RsDataService::retrieveGrps(std::map<std::string, RsNxsGrp*> &grp, bool cache){
int RsDataService::retrieveNxsGrps(std::map<std::string, RsNxsGrp *> &grp, bool cache){
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpColumns, "", "");
@ -353,19 +527,9 @@ int RsDataService::retrieveGrps(std::map<std::string, RsNxsGrp*> &grp, bool cach
RsNxsGrp* g = getGroup(*c);
// only add the latest grp info
if(g){
bool exists = grp.find(g->grpId) != grp.end();
if(exists){
if(grp[g->grpId]->timeStamp < g->timeStamp){
delete grp[g->grpId];
grp[g->grpId] = g;
}else{
delete g;
}
}else{
grp[g->grpId] = g;
}
if(g)
{
grp[g->grpId] = g;
}
valid = c->moveToNext();
}
@ -377,111 +541,128 @@ int RsDataService::retrieveGrps(std::map<std::string, RsNxsGrp*> &grp, bool cach
}
}
int RsDataService::retrieveMsgs(const std::string &grpId, std::map<std::string, RsNxsMsg *>& msg, bool cache){
int RsDataService::retrieveNxsMsgs(const GxsMsgReq &reqIds, GxsMsgResult &msg, bool cache)
{
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgColumns, KEY_GRP_ID+ "='" + grpId + "'", "");
GxsMsgReq::const_iterator mit = reqIds.begin();
if(c){
for(; mit != reqIds.end(); mit++)
{
bool valid = c->moveToFirst();
while(valid){
RsNxsMsg* m = getMessage(*c);
const std::string& grpId = mit->first;
if(m){
// only add the latest grp info
bool exists = msg.find(m->msgId) != msg.end();
if(exists){
// if vector empty then request all messages
const std::set<std::string>& msgIdSet = mit->second;
std::vector<RsNxsMsg*> msgSet;
if(msg[m->msgId]->timeStamp < m->timeStamp){
delete msg[m->msgId];
msg[m->msgId] = m;
}else{
delete m;
}
}else{
msg[m->msgId] = m;
}
if(msgIdSet.empty()){
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgColumns, KEY_GRP_ID+ "='" + grpId + "'", "");
if(c)
retrieveMessages(c, msgSet);
}else{
// request each grp
std::set<std::string>::const_iterator sit = msgIdSet.begin();
for(; sit!=msgIdSet.end();sit++){
const std::string& msgId = *sit;
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgColumns, KEY_GRP_ID+ "='" + grpId + "','" + msgId + "'", "");
retrieveMessages(c, msgSet);
}
valid = c->moveToNext();
}
delete c;
return 1;
}else{
return 0;
msg[grpId] = msgSet;
}
}
int RsDataService::retrieveGrpVersions(const std::string &grpId, std::set<RsNxsGrp *> &grp, bool cache){
void RsDataService::retrieveMessages(RetroCursor *c, std::vector<RsNxsMsg *> &msgs)
{
bool valid = c->moveToFirst();
while(valid){
RsNxsMsg* m = getMessage(*c);
std::string selection = KEY_GRP_ID + "='" + grpId + "'";
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpColumns, selection, "");
if(m){
msgs.push_back(m);;
}else{
delete m;
}
if(c){
valid = c->moveToNext();
}
return;
}
int RsDataService::retrieveGxsMsgMetaData(const std::vector<std::string> &grpIds, GxsMsgMetaResult &msgMeta)
{
std::vector<std::string>::const_iterator vit = grpIds.begin();
for(; vit != grpIds.end(); vit++)
{
const std::string& grpId = *vit;
std::vector<RsGxsMsgMetaData*> meta;
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgMetaColumns, "", KEY_GRP_ID+ "='" + grpId + "'");
if(c)
{
bool valid = c->moveToFirst();
while(valid){
RsGxsMsgMetaData* m = getMsgMeta(*c);
if(m){
meta.push_back(m);
}else{
delete m;
}
valid = c->moveToNext();
}
msgMeta[grpId] = meta;
}
}
return 1;
}
int RsDataService::retrieveGxsGrpMetaData(std::map<std::string, RsGxsGrpMetaData *>& grp)
{
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpMetaColumns, "", "");
if(c)
{
bool valid = c->moveToFirst();
while(valid){
RsNxsGrp* g = getGroup(*c);
while(valid)
{
RsGxsGrpMetaData* g = getGrpMeta(*c);
if(g)
grp.insert(g);
{
grp[g->mGroupId] = g;
}
valid = c->moveToNext();
}
delete c;
return 1;
}else{
return 0;
}
}
RsNxsGrp* RsDataService::retrieveGrpVersion(const RsGxsGrpId &grpId){
std::set<RsNxsGrp*> grps;
retrieveGrpVersions(grpId.grpId, grps, false);
RsNxsGrp* grp = NULL;
if(!grps.empty()){
// find grp with comparable sign
std::set<RsNxsGrp*>::iterator sit = grps.begin();
for(; sit != grps.end(); sit++){
grp = *sit;
if(!memcmp(grp->adminSign.signData.bin_data, grpId.adminSign.signData.bin_data,
grpId.adminSign.signData.bin_len)){
break;
}
grp = NULL;
}
if(grp){
grps.erase(grp);
// release memory for non matching grps
for(sit = grps.begin(); sit != grps.end(); sit++)
delete *sit;
}
}
return grp;
return 1;
}
int RsDataService::resetDataStore(){
int RsDataService::resetDataStore()
{
#ifdef RS_DATA_SERVICE_DEBUG
std::cerr << "resetDataStore() " << std::endl;
#endif
std::map<std::string, RsNxsGrp*> grps;
retrieveGrps(grps, false);
retrieveNxsGrps(grps, false);
std::map<std::string, RsNxsGrp*>::iterator mit
= grps.begin();
// remove all grp msgs files from service dir
for(; mit != grps.end(); mit++){
std::string file = mServiceDir + "/" + mit->first;
std::string msgFile = file + "-msgs";
@ -490,19 +671,33 @@ int RsDataService::resetDataStore(){
}
mDb->closeDb();
remove(mDbName.c_str());
remove(mDbName.c_str()); // remove db file
// recreate database
initialise();
return 1;
}
int RsDataService::removeGroups(const std::list<RsGxsGrpId> &grpIds){
int RsDataService::removeGroups(const std::vector<std::string> &grpIds)
{
return 0;
}
int RsDataService::removeMsgs(const std::list<RsGxsMsgId> &msgIds){
int RsDataService::updateGroupMetaData(GrpLocMetaData *meta)
{
return 0;
}
int RsDataService::updateMessageMetaData(MsgLocMetaData *metaData)
{
return 0;
}
int RsDataService::removeMsgs(const std::string grpId, const std::vector<std::string> &msgIds)
{
return 0;
}
@ -510,15 +705,8 @@ uint32_t RsDataService::cacheSize() const {
return 0;
}
int RsDataService::setCacheSize(uint32_t size) {
int RsDataService::setCacheSize(uint32_t size)
{
return 0;
}
int RsDataService::searchGrps(RsGxsSearch *search, std::list<RsGxsSrchResGrpCtx *> &result) {
return 0;
}
int RsDataService::searchMsgs(RsGxsSearch *search, std::list<RsGxsSrchResMsgCtx *> &result) {
return 0;
}

View File

@ -13,67 +13,52 @@ public:
virtual ~RsDataService();
/*!
* Retrieves latest version of msgs for a service
* @param msgIds ids of messagesto retrieve
* Retrieves all msgs
* @param reqIds requested msg ids (grpId,msgId), leave msg list empty to get all msgs for the grp
* @param msg result of msg retrieval
* @param cache whether to store retrieval in memory for faster later retrieval
* @param cache whether to store results of this retrieval in memory for faster later retrieval
* @return error code
*/
int retrieveMsgs(const std::string& grpId, std::map<std::string, RsNxsMsg*>& msg, bool cache);
int retrieveNxsMsgs(const GxsMsgReq& reqIds, GxsMsgResult& msg, bool cache);
/*!
* Retrieves latest version of groups for a service
* @param grpId the Id of the groups to retrieve
* @param grp results of retrieval
* Retrieves all groups stored (most current versions only)
* @param grp retrieved groups
* @param cache whether to store retrieval in mem for faster later retrieval
* @return error code
*/
int retrieveGrps(std::map<std::string, RsNxsGrp*>& grp, bool cache);
int retrieveNxsGrps(std::map<std::string, RsNxsGrp*>& grp, bool cache);
/*!
* Retrieves all the versions of a group
* @param grpId the id of the group to get versions for
* @param cache whether to store the result in memory
* @return errCode
* Retrieves meta data of all groups stored (most current versions only)
* @param cache whether to store retrieval in mem for faster later retrieval
* @return error code
*/
int retrieveGrpVersions(const std::string &grpId, std::set<RsNxsGrp *> &grp, bool cache);
int retrieveGxsGrpMetaData(std::map<std::string, RsGxsGrpMetaData*>& grp);
/*!
* @param grpId the id of the group to retrieve
* @return NULL if group does not exist or pointer to grp if found
* Retrieves meta data of all groups stored (most current versions only)
* @param grpIds grpIds for which to retrieve meta data
* @param msgMeta meta data result as map of grpIds to array of metadata for that grpId
* @param cache whether to store retrieval in mem for faster later retrieval
* @return error code
*/
RsNxsGrp* retrieveGrpVersion(const RsGxsGrpId& grpId);
int retrieveGxsMsgMetaData(const std::vector<std::string>& grpIds, GxsMsgMetaResult& msgMeta);
/*!
* remove msgs in data store listed in msgIds param
* remove msgs in data store
* @param grpId group Id of message to be removed
* @param msgIds ids of messages to be removed
* @return error code
*/
int removeMsgs(const std::list<RsGxsMsgId>& msgIds);
int removeMsgs(const std::string grpId, const std::vector<std::string>& msgIds);
/*!
* remove groups in data store listed in grpIds param
* @param grpIds ids of groups to be removed
* @return error code
*/
int removeGroups(const std::list<RsGxsGrpId>& grpIds);
/*!
* allows for more complex queries specific to the service
* @param search generally stores parameters needed for query
* @param msgId is set with msg ids which satisfy the gxs search
* @return error code
*/
int searchMsgs(RsGxsSearch* search, std::list<RsGxsSrchResMsgCtx*>& result);
/*!
* allows for more complex queries specific to the associated service
* @param search generally stores parameters needed for query
* @param msgId is set with msg ids which satisfy the gxs search
* @return error code
*/
int searchGrps(RsGxsSearch* search, std::list<RsGxsSrchResGrpCtx*>& result);
int removeGroups(const std::vector<std::string>& grpIds);
/*!
* @return the cache size set for this RsGeneralDataService in bytes
@ -83,43 +68,92 @@ public:
/*!
* @param size size of cache to set in bytes
*/
virtual int setCacheSize(uint32_t size);
int setCacheSize(uint32_t size);
/*!
* Stores a list signed messages into data store
* @param msg list of signed messages to store
* Stores a list of signed messages into data store
* @param msg map of message and decoded meta data information
* @return error code
*/
int storeMessage(std::set<RsNxsMsg*>& msg);
int storeMessage(std::map<RsNxsMsg*, RsGxsMsgMetaData*>& msg);
/*!
* Stores a list of groups in data store
* @param msg list of messages
* @param grp map of group and decoded meta data
* @return error code
*/
int storeGroup(std::set<RsNxsGrp*>& grp);
int storeGroup(std::map<RsNxsGrp*, RsGxsGrpMetaData*>& grp);
/*!
* @param metaData The meta data item to update
* @return error code
*/
int updateMessageMetaData(MsgLocMetaData* metaData);
/*!
* @param metaData The meta data item to update
* @return error code
*/
int updateGroupMetaData(GrpLocMetaData* meta);
/*!
* Completely clear out data stored in
* this data store and returns this to a state
* and returns this to a state
* as it was when first constructed
* This also clears any data store items created in service directory
* @return error code
*/
int resetDataStore();
private:
/*!
* Retrieves all the msg results from a cursor
* @param c cursor to result set
* @param msgs messages retrieved from cursor are stored here
*/
void retrieveMessages(RetroCursor* c, std::vector<RsNxsMsg*>& msgs);
/*!
* extracts a msg meta item from a cursor at its
* current position
*/
RsGxsMsgMetaData* getMsgMeta(RetroCursor& c);
/*!
* extracts a grp meta item from a cursor at its
* current position
*/
RsGxsGrpMetaData* getGrpMeta(RetroCursor& c);
/*!
* extracts a msg item from a cursor at its
* current position
*/
RsNxsMsg* getMessage(RetroCursor& c);
/*!
* extracts a grp item from a cursor at its
* current position
*/
RsNxsGrp* getGroup(RetroCursor& c);
/*!
* Creates an sql database and its associated file
* also creates the message and groups table
*/
void initialise();
private:
RetroDb* mDb;
std::list<std::string> msgColumns;
std::list<std::string> msgMetaColumns;
std::list<std::string> grpColumns;
std::list<std::string> grpMetaColumns;
std::string mServiceDir, mDbName;
uint16_t mServType;

View File

@ -34,6 +34,7 @@
#include "serialiser/rsgxsitems.h"
#include "serialiser/rsnxsitems.h"
#include "gxs/rsgxsdata.h"
class RsGxsSearchModule {
@ -47,6 +48,17 @@ public:
};
class MsgLocMetaData {
};
class GrpLocMetaData {
};
typedef std::map<std::string, std::set<std::string> > GxsMsgReq; // <grpId, msgIds>
typedef std::map<std::string, std::vector<RsNxsMsg*> > GxsMsgResult; // <grpId, msgs>
typedef std::map<std::string, std::vector<RsGxsMsgMetaData*> > GxsMsgMetaResult; // <grpId, msg metadatas>
/*!
* The main role of GDS is the preparation and handing out of messages requested from
@ -74,67 +86,54 @@ class RsGeneralDataService
public:
virtual ~RsGeneralDataService(){return;};
/*!
* Retrieves signed message
* @param grpId
* @param msg result of msg retrieval
* @param cache whether to store retrieval in memory for faster later retrieval
* @return error code
*/
virtual int retrieveMsgs(const std::string& grpId, std::map<std::string, RsNxsMsg*>& msg, bool cache) = 0;
virtual ~RsGeneralDataService(){return;}
/*!
* Retrieves a group item by grpId
* @param grpId the Id of the groups to retrieve
* @param grp results of retrieval
* Retrieves all msgs
* @param reqIds requested msg ids (grpId,msgId), leave msg list empty to get all msgs for the grp
* @param msg result of msg retrieval
* @param cache whether to store results of this retrieval in memory for faster later retrieval
* @return error code
*/
virtual int retrieveNxsMsgs(const GxsMsgReq& reqIds, GxsMsgResult& msg, bool cache) = 0;
/*!
* Retrieves all groups stored
* @param grp retrieved groups
* @param cache whether to store retrieval in mem for faster later retrieval
* @return error code
*/
virtual int retrieveGrps(std::map<std::string, RsNxsGrp*>& grp, bool cache) = 0;
virtual int retrieveNxsGrps(std::map<std::string, RsNxsGrp*>& grp, bool cache) = 0;
/*!
* @param grpId the id of the group to get versions for
* @param cache whether to store the result in memory
* @param errCode
*/
virtual int retrieveGrpVersions(const std::string& grpId, std::set<RsNxsGrp*>& grp, bool cache) = 0;
/*!
* @param grpId the id of the group to retrieve
* @return NULL if group does not exist or pointer to grp if found
*/
virtual RsNxsGrp* retrieveGrpVersion(const RsGxsGrpId& grpId) = 0;
/*!
* allows for more complex queries specific to the service
* @param search generally stores parameters needed for query
* @param msgId is set with msg ids which satisfy the gxs search
* Retrieves meta data of all groups stored (most current versions only)
* @param cache whether to store retrieval in mem for faster later retrieval
* @return error code
*/
virtual int searchMsgs(RsGxsSearch* search, std::list<RsGxsSrchResMsgCtx*>& result) = 0;
virtual int retrieveGxsGrpMetaData(std::map<std::string, RsGxsGrpMetaData*>& grp) = 0;
/*!
* allows for more complex queries specific to the associated service
* @param search generally stores parameters needed for query
* @param msgId is set with msg ids which satisfy the gxs search
* Retrieves meta data of all groups stored (most current versions only)
* @param grpIds grpIds for which to retrieve meta data
* @param msgMeta meta data result as map of grpIds to array of metadata for that grpId
* @param cache whether to store retrieval in mem for faster later retrieval
* @return error code
*/
virtual int searchGrps(RsGxsSearch* search, std::list<RsGxsSrchResGrpCtx*>& result) = 0;
virtual int retrieveGxsMsgMetaData(const std::vector<std::string>& grpIds, GxsMsgMetaResult& msgMeta) = 0;
/*!
* remove msgs in data store listed in msgIds param
* @param msgIds ids of messages to be removed
* @return error code
*/
virtual int removeMsgs(const std::list<RsGxsMsgId>& msgIds) = 0;
virtual int removeMsgs(const std::string grpId, const std::vector<std::string>& msgIds) = 0;
/*!
* remove groups in data store listed in grpIds param
* @param grpIds ids of groups to be removed
* @return error code
*/
virtual int removeGroups(const std::list<RsGxsGrpId>& grpIds) = 0;
virtual int removeGroups(const std::vector<std::string>& grpIds) = 0;
/*!
* @return the cache size set for this RsGeneralDataService in bytes
@ -147,18 +146,29 @@ public:
virtual int setCacheSize(uint32_t size) = 0;
/*!
* Stores a list signed messages into data store
* @param msg list of signed messages to store
* Stores a list of signed messages into data store
* @param msg map of message and decoded meta data information
* @return error code
*/
virtual int storeMessage(std::set<RsNxsMsg*>& msg) = 0;
virtual int storeMessage(std::map<RsNxsMsg*, RsGxsMsgMetaData*>& msg);
/*!
* Stores a list of groups in data store
* @param msg list of messages
* @param grp map of group and decoded meta data
* @return error code
*/
virtual int storeGroup(std::set<RsNxsGrp*>& grp) = 0;
virtual int storeGroup(std::map<RsNxsGrp*, RsGxsGrpMetaData*>& grp);
/*!
* @param metaData
*/
virtual int updateMessageMetaData(MsgLocMetaData* metaData) = 0;
/*!
* @param metaData
*/
virtual int updateGroupMetaData(GrpLocMetaData* meta) = 0;
/*!

View File

@ -50,6 +50,17 @@
typedef uint64_t RsGroupId ;
class RsTokReqOptions
{
public:
RsTokReqOptions() { mOptions = 0; mBefore = 0; mAfter = 0; }
uint32_t mOptions;
time_t mBefore;
time_t mAfter;
};
/*!
@ -97,75 +108,37 @@ public:
virtual uint16_t getServiceType() const = 0;
/*!
* Request group, not intialising version member of RsGxsGrpId
* results in the latest version of groups being returned
* @return token for request
* Request group information
* @param token this initialised with a token that can be redeemed for this request
* @param ansType type of group result wanted, summary
* @param opts token options
* @param groupIds list of group ids wanted, leaving this empty will result in a request for only list of group ids for the service
* @return false if request failed, true otherwise
* @see receiveGrp()
*/
int requestGrps();
bool requestGroupInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &groupIds);
/*!
* Request group, not intialising version member of RsGxsGrpId
* results in the latest version of group being returned
* @return token for request
* @see receiveGrpList()
* Request message information for a list of groups
* @param token this initialised with a token that can be redeemed for this request
* @param ansType type of msg info result
* @param opts token options
* @param groupIds groups ids for which message info will be requested
* @return false if request failed, true otherwise
* @see receiveGrp()
*/
int requestSubscribedGrps();
virtual bool requestMsgInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &groupIds);
/*!
* Request all versions of a group
* @param grpId group id to request version for
* @return token for request
* Request message information for a list of groups
* @param token this initialised with a token that can be redeemed for this request
* @param ansType type of msg info result
* @param opts token options
* @param groupIds groups ids for which message info will be requested
* @return false if request failed, true otherwise
* @see receiveGrp()
*/
int requestAllGrpVersions(const std::string& grpId);
/*!
* Event call back from Gxs runner
* after requested Grp(s) have been retrieved
* @param token the token to be redeemed
* @param errCode error code, can be exchanged for error string
* @param grps list of groups associated to request token
*/
virtual void receiveGrp(int token, int errCode, std::set<RsGxsGroup*>& grps) = 0;
/*************** Start: Msg request receive API ********************/
/* Messages a level below grps on the hiearchy hence group requests */
/* are intrinsically linked to their grp Id */
/*!
* request latest version of messages for groups
* listed
* @param grpIds list of grpIds to get msgs for
* @return token for request
* @see receiveMsg()
*/
int requestGrpMsgs(const std::list<std::string>& grpIds);
/*!
* request latest version of messages for group
* @param grpIds list of grpIds to get msgs for
* @return token for request
* @see receiveMsg()
*/
int requestAllMsgVersions(const std::list<RsGxsMsgId>& msgIds);
/*!
*
*
*/
int requestMsgVersion(const RsGxsMsgId& msgId);
/*!
* Event call back from GxsRunner
* after request msg(s) have been received
* @param token token to be redeemed
*/
virtual void receiveMsg(int token, int errCode, std::set<RsGxsMsg*>& msgs) = 0;
/*************** End: Msg request receive API ********************/
bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &msgIds);
/*********** Start: publication *****************/
@ -207,27 +180,6 @@ public:
/*********** End: publication *****************/
/*************************************************************************/
// The main idea here is each RsGroup needs permission set for each RsGxsGroup
// Thus a
// This is a configuration thing.
/*************************************************************************/
/*********** Start: groups *****************/
/*!
* This says listed group can are only ones that can
* share grp/msgs between themselves for grpId
* Default behaviour on group sharing is share with between all peers
* @param rsGrpId list of group id sharing will be allowed
* @param grpId groupId that share behaviour is being set
* @return status token to be redeemed
*/
int setShareGroup(const std::list<RsGroupId>& rsGrpId, const std::string grpId);
/*********** End: Identity control and groups *****************/
/****************************************************************************************************/
// Interface for Message Read Status
// At the moment this is overloaded to handle autodownload flags too.
@ -241,7 +193,7 @@ public:
* @param GrpMsgMap flags this msg,version pair as read
* @param read set to true for read and false for unread
*/
int flagMsgRead(const RsGxsMsgId& msgId, bool read) ;
int flagMsgRead(const std::string& msgId, bool read) ;
/*!
@ -266,32 +218,7 @@ public:
* and not circulated. Entry will later be removed
* once discard age is reached
*/
int requestDeleteGrp(const RsGxsGroup& grp);
/******************* Start: Configuration *************************/
/*!
* How long to keep subscribed groups
* @param length how long to keep group in seconds
*/
int setSubscribedGroupDiscardAge(uint32_t length);
/*!
* How long to keep unsubscribed groups
* @param length how long to keep groups in seconds
* @return status token to be redeemed
* @see statusMsg()
*/
int setUnsubscribedGrpDiscardAge(uint32_t length);
/*!
* How long to keep messages, group discard age supercedes this \n
* discard age
* @param length how long to keep messages in seconds
*/
int setMsgDiscardAge(uint32_t length);
bool requestDeleteGrp(uint32_t& token, const RsGxsGroup& grp);
/*!
@ -300,7 +227,7 @@ public:
* @param subscribe set to false to unsubscribe and true otherwise
* @return token to redeem
*/
int requestSubscribeToGrp(const std::string& grpId, bool subscribe);
bool requestSubscribeToGrp(uint32_t token, const std::string& grpId, bool subscribe);
public:
@ -310,7 +237,7 @@ public:
* @param errCode error code, can be exchanged for error string
* @param gxsStatus the status of subscription request
*/
virtual void receiveSubscribeToGrp(int token, int errCode) = 0;
virtual void receiveSubscribeToGrp(int token, int errCode);
/*!
*
@ -328,7 +255,7 @@ public:
* have been updated or newly arrived
* @param grpId ids of groups that have changed or newly arrived
*/
virtual void notifyGroupChanged(std::list<std::string> grpIds) = 0;
virtual void notifyGroupChanged(std::list<std::string> grpIds);
/*!
@ -336,108 +263,27 @@ public:
* have been updated or newly arrived
* @param msgId ids of msgs that have changed or newly arrived
*/
virtual void notifyMsgChanged(std::list<RsGxsMsgId> msgId) = 0;
virtual void notifyMsgChanged(std::list<std::string> msgId);
/****************** End: Notifications from event runner ***************/
/****************** Start: Search from event runner ***************/
// Users can either search groups or messages
/*!
* Users
* Some standard search terms are supported
* @param term this allows users to search their local storage defined terms
* @return token to redeem search
*/
int requestLocalSearch(RsGxsSearch* term);
/*!
*
* @param token
* @param errCode error code, can be exchanged for error string
* @param grpIds list of grp ids
*/
virtual void receiveLocalSearchGrps(int token, int errCode, std::list<RsGxsGroup*>& grps);
/*!
*
* @param token the request token to be redeemed
* @param errCode error code, can be exchanged for error string
* @param msgIds the message ids that contain contain search term
*/
virtual void receiveLocalSearchMsgs(int token, int errCode, std::list<RsGxsMsg*> &msgs) = 0;
/*!
*
* @param token request token to be redeemed
* @param errCode error code, can be exchanged for error string
* @param grps
*/
virtual void receiveRemoteSearchGrps(int token, int errCode, std::list<RsGxsGroup*>& grps) = 0;
/*!
*
* @param token the request token to be redeemed
* @param errCode error code, can be exchanged for error string
* @param msgIds
*/
virtual void recieveRemoteSearchMsgs(int token, int errCode, std::list<RsGxsMsg*>& msgs) = 0;
/* the following are protected to prevent RsGxsNetService calling below
* and causing infinite recursion
*/
// Remote Search...(2 hops ?)
/*!
*
* @param term This contains the search term
* @param hops how many hops from your immediate peer on the network for search
* @param delay lenght of time search should persist (if you are online search will be saved \n
* delay seconds, max is 2 days
* @return token to redeem search
*/
int requestRemoteSearchGrps(RsGxsSearch* term, uint32_t hops, uint32_t delay, bool immediate);
// Remote Search...(2 hops ?)
/*!
*
* @param term This contains the search term
* @param hops how many hops from your immediate peer on the network for search
* @param delay lenght of time search should persist (if you are online search will be saved \n
* delay seconds, max is 2 days
* @return token to redeem search
*/
int requestRemoteSearchMsgs(RsGxsSearch* term, uint32_t hops, uint32_t delay, bool immediate);
/* Generic Lists */
bool getGroupList(const uint32_t &token, std::list<std::string> &groupIds);
bool getMsgList(const uint32_t &token, std::list<std::string> &msgIds);
/*!
* Note if parent group is not present this will be requested \n
* by the event runner
* @param msgIds the ids of the remote messages being requested
* @return token to be redeemed
* @see receiveMsg()
*/
int requestRemoteMsg(std::list<RsGxsMsgId>& msgIds);
/*!
* @param grpIds the ids of the group being requested
* @return token to be redeemed
* @see receiveGrp()
*/
int requestRemoteGrp(std::list<RsGxsGrpId>& grpIds);
/* Poll */
uint32_t requestStatus(const uint32_t token);
/****************** End: Search from event runner ***************/
/* Cancel Request */
bool cancelRequest(const uint32_t &token);
/*!
* @param msgIds ids of messages to be deleted
* @return token to be redeemed
*/
virtual int deleteRemoteMsg(std::list<RsGxsMsgId>& msgIds);
virtual int deleteRemoteGrp(std::list<RsGxsGrpId>& grpIds);
bool groupShareKeys(const std::string &groupId, std::list<std::string>& peers);
};
#endif // RSGXS_H

View File

@ -0,0 +1,176 @@
#include "rsgxsdata.h"
#include "serialiser/rsbaseserial.h"
RsGxsGrpMetaData::RsGxsGrpMetaData()
{
}
uint32_t RsGxsGrpMetaData::serial_size()
{
uint32_t s = 8; // header size
s += GetTlvStringSize(mGroupId);
s += GetTlvStringSize(mOrigGrpId);
s += GetTlvStringSize(mGroupName);
s += 4;
s += 4;
s += GetTlvStringSize(mAuthorId);
s += adminSign.TlvSize();
s += keys.TlvSize();
s += idSign.TlvSize();
return s;
}
bool RsGxsGrpMetaData::serialise(void *data, uint32_t &pktsize)
{
uint32_t tlvsize = serial_size() ;
uint32_t offset = 0;
if (pktsize < tlvsize)
return false; /* not enough space */
pktsize = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, 0, tlvsize);
#ifdef GXS_DEBUG
std::cerr << "RsGxsGrpMetaData serialise()" << std::endl;
std::cerr << "RsGxsGrpMetaData serialise(): Header: " << ok << std::endl;
std::cerr << "RsGxsGrpMetaData serialise(): Size: " << tlvsize << std::endl;
#endif
/* skip header */
offset += 8;
ok &= SetTlvString(data, tlvsize, &offset, 0, mGroupId);
ok &= SetTlvString(data, tlvsize, &offset, 0, mOrigGrpId);
ok &= SetTlvString(data, tlvsize, &offset, 0, mGroupName);
ok &= setRawUInt32(data, tlvsize, &offset, mGroupFlags);
ok &= setRawUInt32(data, tlvsize, &offset, mPublishTs);
ok &= SetTlvString(data, tlvsize, &offset, 0, mAuthorId);
ok &= adminSign.SetTlv(data, tlvsize, &offset);
ok &= keys.SetTlv(data, tlvsize, &offset);
ok &= idSign.SetTlv(data, tlvsize, &offset);
return ok;
}
bool RsGxsGrpMetaData::deserialise(void *data, uint32_t &pktsize)
{
uint32_t offset = 8; // skip the header
uint32_t rssize = getRsItemSize(data);
bool ok = true ;
ok &= rssize != pktsize;
if(!ok) return false;
ok &= GetTlvString(data, pktsize, &offset, 0, mGroupId);
ok &= GetTlvString(data, pktsize, &offset, 0, mOrigGrpId);
ok &= GetTlvString(data, pktsize, &offset, 0, mOrigGrpId);
ok &= getRawUInt32(data, pktsize, &offset, &mGroupFlags);
ok &= getRawUInt32(data, pktsize, &offset, &mPublishTs);
ok &= GetTlvString(data, pktsize, &offset, 0, mAuthorId);
ok &= adminSign.GetTlv(data, pktsize, &offset);
ok &= keys.SetTlv(data, pktsize, &offset);
ok &= idSign.SetTlv(data, pktsize, &offset);
return ok;
}
uint32_t RsGxsMsgMetaData::serial_size()
{
uint32_t s = 8; // header size
s += GetTlvStringSize(mGroupId);
s += GetTlvStringSize(mMsgId);
s += GetTlvStringSize(mThreadId);
s += GetTlvStringSize(mParentId);
s += GetTlvStringSize(mOrigMsgId);
s += pubSign.TlvSize();
s += idSign.TlvSize();
s += GetTlvStringSize(mMsgName);
s += 4;
s += 4;
return s;
}
bool RsGxsMsgMetaData::serialise(void *data, uint32_t *size)
{
uint32_t tlvsize = serial_size() ;
uint32_t offset = 0;
if (*size < tlvsize)
return false; /* not enough space */
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, 0, tlvsize);
#ifdef GXS_DEBUG
std::cerr << "RsGxsGrpMetaData serialise()" << std::endl;
std::cerr << "RsGxsGrpMetaData serialise(): Header: " << ok << std::endl;
std::cerr << "RsGxsGrpMetaData serialise(): Size: " << tlvsize << std::endl;
#endif
/* skip header */
offset += 8;
ok &= SetTlvString(data, *size, &offset, 0, mGroupId);
ok &= SetTlvString(data, *size, &offset, 0, mMsgId);
ok &= SetTlvString(data, *size, &offset, 0, mThreadId);
ok &= SetTlvString(data, *size, &offset, 0, mParentId);
ok &= SetTlvString(data, *size, &offset, 0, mOrigMsgId);
ok &= pubSign.SetTlv(data, *size, &offset);
ok &= idSign.SetTlv(data, *size, &offset);
ok &= SetTlvString(data, *size, &offset, 0, mMsgName);
ok &= setRawUInt32(data, *size, &offset, mPublishTs);
ok &= setRawUInt32(data, *size, &offset, mMsgFlags);
return ok;
}
bool RsGxsMsgMetaData::deserialise(void *data, uint32_t *size)
{
uint32_t offset = 8; // skip the header
uint32_t rssize = getRsItemSize(data);
bool ok = true ;
ok &= rssize != *size;
if(!ok) return false;
ok &= GetTlvString(data, *size, &offset, 0, mGroupId);
ok &= GetTlvString(data, *size, &offset, 0, mMsgId);
ok &= GetTlvString(data, *size, &offset, 0, mThreadId);
ok &= GetTlvString(data, *size, &offset, 0, mParentId);
ok &= GetTlvString(data, *size, &offset, 0, mOrigMsgId);
ok &= pubSign.GetTlv(data, *size, &offset);
ok &= idSign.GetTlv(data, *size, &offset);
ok &= GetTlvString(data, *size, &offset, 0, mMsgName);
uint32_t t;
ok &= getRawUInt32(data, *size, &offset, &t);
mPublishTs = t;
ok &= getRawUInt32(data, *size, &offset, &mMsgFlags);
return ok;
}

View File

@ -0,0 +1,85 @@
#ifndef RSGXSMETA_H
#define RSGXSMETA_H
#include <string>
#include "serialiser/rsserial.h"
#include "serialiser/rstlvbase.h"
#include "serialiser/rstlvtypes.h"
#include "serialiser/rstlvkeys.h"
class RsGxsGrpMetaData
{
public:
RsGxsGrpMetaData();
bool deserialise(void *data, uint32_t &pktsize);
bool serialise(void* data, uint32_t &pktsize);
uint32_t serial_size();
std::string mGroupId;
std::string mOrigGrpId;
std::string mGroupName;
uint32_t mGroupFlags;
uint32_t mPublishTs;
std::string mAuthorId;
RsTlvKeySignature adminSign;
RsTlvSecurityKeySet keys;
RsTlvKeySignature idSign;
// BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG.
uint32_t mSubscribeFlags;
uint32_t mPop; // HOW DO WE DO THIS NOW.
uint32_t mMsgCount; // ???
time_t mLastPost; // ???
uint32_t mGroupStatus;
};
class RsGxsMsgMetaData
{
public:
RsGxsMsgMetaData();
bool deserialise(void *data, uint32_t *size);
bool serialise(void* data, uint32_t *size);
uint32_t serial_size();
std::string mGroupId;
std::string mMsgId;
std::string mThreadId;
std::string mParentId;
std::string mOrigMsgId;
std::string mAuthorId;
RsTlvKeySignature pubSign;
RsTlvKeySignature idSign;
std::string mMsgName;
time_t mPublishTs;
uint32_t mMsgFlags; // Whats this for?
// BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG.
// normally READ / UNREAD flags. LOCAL Data.
uint32_t mMsgStatus;
time_t mChildTs;
};
#endif // RSGXSMETA_H

View File

@ -415,6 +415,7 @@ void RsGxsNetService::genReqMsgTransaction(NxsTransaction* tr)
std::list<RsNxsItem*>::iterator lit = tr->mItems.begin();
// first get item list sent from transaction
for(; lit != tr->mItems.end(); lit++)
{
RsNxsSyncMsgItem* item = dynamic_cast<RsNxsSyncMsgItem*>(*lit);
@ -424,7 +425,7 @@ void RsGxsNetService::genReqMsgTransaction(NxsTransaction* tr)
}else
{
#ifdef NXS_NET_DEBUG
std::cerr << "RsGxsNetService::genReqMsgTransaction(): item failed to caste to RsNxsSyncMsgItem* "
std::cerr << "RsGxsNetService::genReqMsgTransaction(): item failed cast to RsNxsSyncMsgItem* "
<< std::endl;
#endif
delete item;
@ -432,22 +433,36 @@ void RsGxsNetService::genReqMsgTransaction(NxsTransaction* tr)
}
}
RsNxsSyncMsgItem* item = msgItemL.front();
const std::string& grpId = item->grpId;
std::map<std::string, RsNxsMsg*> msgMap;
mDataStore->retrieveMsgs(grpId, msgMap, false);
// now do compare and add loop
std::list<RsNxsSyncMsgItem*>::iterator llit = msgItemL.begin();
std::list<RsNxsItem*> reqList;
// get grp id for this transaction
RsNxsSyncMsgItem* item = msgItemL.front();
const std::string& grpId = item->grpId;
std::vector<std::string> grpIdV;
grpIdV.push_back(grpId);
GxsMsgMetaResult result;
mDataStore->retrieveGxsMsgMetaData(grpIdV, result);
std::vector<RsGxsMsgMetaData*> &msgMetaV = result[grpId];
std::vector<RsGxsMsgMetaData*>::const_iterator vit = msgMetaV.begin();
std::set<std::string> msgIdSet;
// put ids in set for each searching
for(; vit != msgMetaV.end(); vit++)
msgIdSet.insert((*vit)->mMsgId);
// get unique id for this transaction
uint32_t transN = getTransactionId();
// now do compare and add loop
std::list<RsNxsSyncMsgItem*>::iterator llit = msgItemL.begin();
std::list<RsNxsItem*> reqList;
for(; llit != msgItemL.end(); llit++)
{
const std::string& msgId = (*llit)->msgId;
if(msgMap.find(msgId) == msgMap.end()){
if(msgIdSet.find(msgId) == msgIdSet.end()){
RsNxsSyncMsgItem* msgItem = new RsNxsSyncMsgItem(mServType);
msgItem->grpId = grpId;
msgItem->msgId = msgId;
@ -506,8 +521,8 @@ void RsGxsNetService::genReqGrpTransaction(NxsTransaction* tr)
RsNxsSyncGrpItem* item = grpItemL.front();
const std::string& grpId = item->grpId;
std::map<std::string, RsNxsGrp*> grpMap;
mDataStore->retrieveGrps(grpMap, false);
std::map<std::string, RsGxsGrpMetaData*> grpMetaMap;
mDataStore->retrieveGxsGrpMetaData(grpMetaMap);
// now do compare and add loop
std::list<RsNxsSyncGrpItem*>::iterator llit = grpItemL.begin();
@ -519,7 +534,7 @@ void RsGxsNetService::genReqGrpTransaction(NxsTransaction* tr)
{
const std::string& grpId = (*llit)->grpId;
if(grpMap.find(grpId) == grpMap.end()){
if(grpMetaMap.find(grpId) == grpMetaMap.end()){
RsNxsSyncGrpItem* grpItem = new RsNxsSyncGrpItem(mServType);
grpItem->grpId = grpId;

View File

@ -111,7 +111,7 @@ public:
* @param peerId Id of peer
* @param grpId id of group to request messages for
*/
void requestMessagesOfPeer(const std::string& peerId, const RsGxsGrpId& grpId){ return; }
void requestMessagesOfPeer(const std::string& peerId, const std::string& grpId){ return; }
/*!
* Initiates a search through the network
@ -154,7 +154,7 @@ public:
* @param enabled set to false to disable pause, and true otherwise
* @return request token to be redeemed
*/
int requestGrp(const std::list<RsGxsGrpId>& grpId, uint8_t hops){ return 0;}
int requestGrp(const std::list<std::string>& grpId, uint8_t hops){ return 0;}

View File

@ -81,7 +81,7 @@ public:
* @param peerId Id of peer
* @param grpId id of group to request messages for
*/
virtual void requestMessagesOfPeer(const std::string& peerId, const RsGxsGrpId& grpId) = 0;
virtual void requestMessagesOfPeer(const std::string& peerId, const std::string& grpId) = 0;
/*!
* Initiates a search through the network
@ -124,7 +124,7 @@ public:
* @param enabled set to false to disable pause, and true otherwise
* @return request token to be redeemed
*/
virtual int requestGrp(const std::list<RsGxsGrpId>& grpId, uint8_t hops) = 0;
virtual int requestGrp(const std::list<std::string>& grpId, uint8_t hops) = 0;
};

View File

@ -157,11 +157,9 @@ PUBLIC_HEADERS = retroshare/rsblogs.h \
retroshare/rsconfig.h
HEADERS += plugins/pluginmanager.h \
plugins/dlfcn_win32.h \
serialiser/rspluginitems.h \
gxs/rsdataservice.h \
gxs/rsgxsflags.h \
gxs/rsgenexchange.h
plugins/dlfcn_win32.h \
serialiser/rspluginitems.h \
gxs/rsgxsdata.h
HEADERS += $$PUBLIC_HEADERS
@ -666,8 +664,12 @@ newcache {
HEADERS += serialiser/rsnxsitems.h \
gxs/rsgds.h \
gxs/rsgxs.h \
gxs/rsdataservice/h \
gxs/rsgxsnetservice.h
gxs/rsdataservice.h \
gxs/rsgxsnetservice.h \
gxs/rsgxsflags.h \
gxs/rsgenexchange.h \
gxs/rsgenexchange.h \
gxs/rsnxsobserver.h
SOURCES += serialiser/rsnxsitems.cc \
gxs/rsdataservice.cc \
@ -703,4 +705,9 @@ SOURCES += services/p3photoservice.cc \
# rsserver/p3photo.cc \
}
SOURCES += \
SOURCES +=
SOURCES += \
gxs/rsgxsdata.cc

View File

@ -34,6 +34,7 @@
#include "serialiser/rstlvbase.h"
#include "serialiser/rstlvtypes.h"
#include "serialiser/rstlvkeys.h"
#include "gxs/rsgxsdata.h"
@ -50,26 +51,8 @@ public:
RsGxsMsg() : RsItem(0) {}
virtual ~RsGxsMsg(){ return; }
/***** Don not serialise or set these members *****/
std::string grpId; /// group id
std::string msgId; /// message id
uint32_t timeStamp; /// UTC time when created
std::string identity; /// identity associated with (no id means no signed)
/*!
* The purpose of the flag is to note
* If this message is an edit (note that edits only applies to
* signed msgs)
*/
uint32_t msgFlag;
/***** Don not serialise or set these members *****/
};
/*!
* Base class used by client API
* for groups.
@ -82,8 +65,6 @@ class RsGxsGroup : public RsItem
public:
/*** type of msgs ***/
RsGxsGroup(uint16_t servtype, uint8_t subtype)
@ -91,13 +72,6 @@ public:
virtual ~RsGxsGroup() { return; }
std::string grpId; /// group id
std::string identity; /// identity associated with group
uint32_t timeStamp; /// UTC time
bool subscribed;
bool read;
/*!
* Three thing flag represents:
* Is it signed by identity?

View File

@ -232,14 +232,9 @@ bool RsNxsSerialiser::serialiseNxsMsg(RsNxsMsg *item, void *data, uint32_t *size
ok &= setRawUInt32(data, *size, &offset, item->transactionNumber);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSGID, item->msgId);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSGID, item->originalMsgId);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, item->identity);
ok &= setRawUInt32(data, tlvsize, &offset, item->timeStamp);
ok &= setRawUInt32(data, tlvsize, &offset, item->msgFlag);
ok &= item->idSign.SetTlv(data, tlvsize, &offset);
ok &= item->publishSign.SetTlv(data, tlvsize, &offset);
ok &= item->msg.SetTlv(data, tlvsize, &offset);
ok &= item->meta.SetTlv(data, *size, &offset);
if(offset != tlvsize){
@ -288,13 +283,8 @@ bool RsNxsSerialiser::serialiseNxsGrp(RsNxsGrp *item, void *data, uint32_t *size
// grp id
ok &= setRawUInt32(data, *size, &offset, item->transactionNumber);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, item->identity);
ok &= setRawUInt32(data, tlvsize, &offset, item->grpFlag);
ok &= setRawUInt32(data, tlvsize, &offset, item->timeStamp);
ok &= item->idSign.SetTlv(data, tlvsize, &offset);
ok &= item->adminSign.SetTlv(data, tlvsize, &offset);
ok &= item->keys.SetTlv(data, tlvsize, &offset);
ok &= item->grp.SetTlv(data, tlvsize, &offset);
ok &= item->meta.SetTlv(data, *size, &offset);
if(offset != tlvsize){
#ifdef RSSERIAL_DEBUG
@ -422,7 +412,7 @@ bool RsNxsSerialiser::serialiseNxsSyncGrpItem(RsNxsSyncGrpItem *item, void *data
if(*size < tlvsize){
#ifdef RSSERIAL_DEBUG
std::cerr << "RsNxsSerialiser::serialiseNxsSyncGrpItem() size do not match" << std::endl;
std::cerr << "RsNxsSerialiser::serialiseNxsSyncm() size do not match" << std::endl;
#endif
return false;
}
@ -436,16 +426,16 @@ bool RsNxsSerialiser::serialiseNxsSyncGrpItem(RsNxsSyncGrpItem *item, void *data
/* skip the header */
offset += 8;
/* RsNxsSyncGrpItem */
/* RsNxsSyncm */
ok &= setRawUInt32(data, *size, &offset, item->transactionNumber);
ok &= setRawUInt8(data, *size, &offset, item->flag);
ok &= SetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
ok &= item->adminSign.SetTlv(data, *size, &offset);
ok &= setRawUInt32(data, *size, &offset, item->publishTs);
if(offset != tlvsize){
#ifdef RSSERIAL_DEBUG
std::cerr << "RsNxsSerialiser::serialiseNxsSyncGrpItem( FAIL Size Error! " << std::endl;
std::cerr << "RsNxsSerialiser::serialiseNxsSyncm( FAIL Size Error! " << std::endl;
#endif
ok = false;
}
@ -453,7 +443,7 @@ bool RsNxsSerialiser::serialiseNxsSyncGrpItem(RsNxsSyncGrpItem *item, void *data
#ifdef RSSERIAL_DEBUG
if (!ok)
{
std::cerr << "RsNxsSerialiser::serialiseNxsSyncGrpItem() NOK" << std::endl;
std::cerr << "RsNxsSerialiser::serialiseNxsSyncm() NOK" << std::endl;
}
#endif
@ -558,13 +548,8 @@ RsNxsGrp* RsNxsSerialiser::deserialNxsGrp(void *data, uint32_t *size){
ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber));
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_NAME, item->identity);
ok &= getRawUInt32(data, *size, &offset, &(item->grpFlag));
ok &= getRawUInt32(data, *size, &offset, &(item->timeStamp));
ok &= item->idSign.GetTlv(data, *size, &offset);
ok &= item->adminSign.GetTlv(data, *size, &offset);
ok &= item->keys.GetTlv(data, *size, &offset);
ok &= item->grp.GetTlv(data, *size, &offset);
ok &= item->meta.GetTlv(data, *size, &offset);
if (offset != rssize)
{
@ -631,14 +616,9 @@ RsNxsMsg* RsNxsSerialiser::deserialNxsMsg(void *data, uint32_t *size){
ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber));
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_MSGID, item->msgId);
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_MSGID, item->originalMsgId);
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_NAME, item->identity);
ok &= getRawUInt32(data, *size, &offset, &(item->timeStamp));
ok &= getRawUInt32(data, *size, &offset, &(item->msgFlag));
ok &= item->idSign.GetTlv(data, *size, &offset);
ok &= item->publishSign.GetTlv(data, *size, &offset);
ok &= item->msg.GetTlv(data, *size, &offset);;
ok &= item->msg.GetTlv(data, *size, &offset);
ok &= item->meta.GetTlv(data, *size, &offset);
if (offset != rssize)
{
@ -772,7 +752,7 @@ RsNxsSyncGrpItem* RsNxsSerialiser::deserialNxsSyncGrpItem(void *data, uint32_t *
ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber));
ok &= getRawUInt8(data, *size, &offset, &(item->flag));
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
ok &= item->adminSign.GetTlv(data, *size, &offset);
ok &= getRawUInt32(data, *size, &offset, &(item->publishTs));
if (offset != rssize)
{
@ -1020,13 +1000,8 @@ uint32_t RsNxsSerialiser::sizeNxsMsg(RsNxsMsg *item)
s += 4; // transaction number
s += GetTlvStringSize(item->grpId);
s += GetTlvStringSize(item->msgId);
s += GetTlvStringSize(item->identity);
s += GetTlvStringSize(item->originalMsgId);
s += 4; // msgFlag
s += 4; // timeStamp
s += item->publishSign.TlvSize();
s += item->idSign.TlvSize();
s += item->msg.TlvSize();
s += item->meta.TlvSize();
return s;
}
@ -1037,13 +1012,8 @@ uint32_t RsNxsSerialiser::sizeNxsGrp(RsNxsGrp *item)
s += 4; // transaction number
s += GetTlvStringSize(item->grpId);
s += GetTlvStringSize(item->identity);
s += 4; // grpFlag
s += 4; // timestamp
s += item->adminSign.TlvSize();
s += item->idSign.TlvSize();
s += item->keys.TlvSize();
s += item->grp.TlvSize();
s += item->meta.TlvSize();
return s;
}
@ -1067,9 +1037,9 @@ uint32_t RsNxsSerialiser::sizeNxsSyncGrpItem(RsNxsSyncGrpItem *item)
uint32_t s = 8; // header size
s += 4; // transaction number
s += 4; // publishTs
s += 1; // flag
s += GetTlvStringSize(item->grpId);
s += item->adminSign.TlvSize();
return s;
}
@ -1124,27 +1094,16 @@ uint32_t RsNxsSerialiser::sizeNxsExtended(RsNxsExtended *item){
void RsNxsMsg::clear()
{
msg.TlvClear();
grpId.clear();
msgId.clear();
msgFlag = 0;
timeStamp = 0;
publishSign.TlvClear();
idSign.TlvClear();
identity.clear();
originalMsgId.clear();
meta.TlvClear();
}
void RsNxsGrp::clear()
{
grpId.clear();
timeStamp = 0;
grp.TlvClear();
adminSign.TlvClear();
keys.TlvClear();
identity.clear();
grpFlag = 0;
idSign.TlvClear();
meta.TlvClear();
}
void RsNxsSyncGrp::clear()
@ -1165,7 +1124,7 @@ void RsNxsSyncMsg::clear()
void RsNxsSyncGrpItem::clear()
{
flag = 0;
adminSign.TlvClear();
publishTs = 0;
grpId.clear();
}
@ -1209,7 +1168,7 @@ std::ostream& RsNxsExtended::print(std::ostream &out, uint16_t indent){
printIndent(out , int_Indent);
out << "type: " << type << std::endl;
printIndent(out , int_Indent);
extData.print(out, indent);
extData.print(out, int_Indent);
printRsItemEnd(out ,"RsNxsExtended", indent);
@ -1244,8 +1203,7 @@ std::ostream& RsNxsSyncGrpItem::print(std::ostream &out, uint16_t indent)
printIndent(out , int_Indent);
out << "grpId: " << grpId << std::endl;
printIndent(out , int_Indent);
adminSign.print(out, indent);
printIndent(out , int_Indent);
out << "publishTs: " << publishTs << std::endl;
printRsItemEnd(out , "RsNxsSyncGrpItem", indent);
return out;
@ -1277,17 +1235,10 @@ std::ostream& RsNxsGrp::print(std::ostream &out, uint16_t indent){
out << "grpId: " << grpId << std::endl;
printIndent(out , int_Indent);
out << "timeStamp: " << timeStamp << std::endl;
printIndent(out , int_Indent);
out << "identity: " << identity << std::endl;
printIndent(out , int_Indent);
out << "grpFlag: " << grpFlag << std::endl;
out << "adminSign: " << std::endl;
adminSign.print(out, indent);
out << "idSign: " << std::endl;
idSign.print(out, indent);
out << "keys: " << std::endl;
keys.print(out, indent);
out << "grp: " << std::endl;
grp.print(out, int_Indent);
out << "meta: " << std::endl;
meta.print(out, int_Indent);
printRsItemEnd(out, "RsNxsGrp", indent);
return out;
@ -1302,16 +1253,10 @@ std::ostream& RsNxsMsg::print(std::ostream &out, uint16_t indent){
printIndent(out , int_Indent);
out << "grpId: " << grpId << std::endl;
printIndent(out , int_Indent);
out << "msgFlag: " << msgFlag << std::endl;
printIndent(out , int_Indent);
out << "identity: " << identity << std::endl;
printIndent(out , int_Indent);
out << "timeStamp: " << timeStamp << std::endl;
printIndent(out , int_Indent);
out << "pub sign: " << std::endl;
publishSign.print(out, indent);
out << "id sign: " << std::endl;
idSign.print(out, indent);
out << "msg: " << std::endl;
msg.print(out, indent);
out << "meta: " << std::endl;
meta.print(out, int_Indent);
printRsItemEnd(out ,"RsNxsMsg", indent);
return out;

View File

@ -111,8 +111,8 @@ class RsNxsTransac : public RsNxsItem {
public:
static const uint16_t FLAG_TRANS_MASK = 0xf;
static const uint16_t FLAG_TYPE_MASK = 0xff;
static const uint16_t FLAG_TRANS_MASK = 0xf;
static const uint16_t FLAG_TYPE_MASK = 0xff;
/** transaction **/
static const uint16_t FLAG_BEGIN_P1;
@ -165,8 +165,9 @@ public:
uint8_t flag; // request or response
/// groups held by sending peer
RsTlvKeySignature adminSign;
uint32_t publishTs; // to compare to Ts of receiving peer's grp of same id
/// grpId of grp held by sending peer
std::string grpId;
};
@ -181,20 +182,22 @@ class RsNxsGrp : public RsNxsItem
public:
RsNxsGrp(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_GRP), grp(servtype) { clear(); return; }
RsNxsGrp(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_GRP), grp(servtype), meta(servtype) { clear(); return; }
virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent);
std::string grpId; /// group Id, needed to complete version Id (ncvi)
uint32_t timeStamp; /// UTC time, ncvi
RsTlvBinaryData grp; /// actual group data
RsTlvKeySignature adminSign; /// signature of admin (needed to complete version Id
RsTlvSecurityKeySet keys;
std::string identity;
RsTlvKeySignature idSign; /// identity sign if applicable
uint32_t grpFlag;
/*!
* This should contains all the data
* which is not specific to the Gxs service data
*/
RsTlvBinaryData meta;
};
/*!
@ -251,21 +254,25 @@ class RsNxsMsg : public RsNxsItem
{
public:
RsNxsMsg(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_MSG), msg(servtype) { clear(); return; }
RsNxsMsg(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_MSG), msg(servtype), meta(servtype) { clear(); return; }
virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent);
std::string grpId; /// group id, forms part of version id
std::string msgId; /// msg id
std::string originalMsgId;
uint32_t msgFlag;
uint32_t timeStamp; /// UTC time create,
/*!
* This should contains all the data
* which is not specific to the Gxs service data
*/
RsTlvBinaryData meta;
/*!
* This contains Gxs specific data
* only client of API knows who to decode this
*/
RsTlvBinaryData msg;
RsTlvKeySignature publishSign; /// publish signature
RsTlvKeySignature idSign; /// identity signature
std::string identity;
};
@ -445,24 +452,4 @@ private:
};
class RsGxsMsgId {
public:
std::string grpId;
std::string msgId;
RsTlvKeySignature idSign;
};
class RsGxsGrpId {
public:
std::string grpId;
RsTlvKeySignature adminSign;
};
#endif // RSNXSITEMS_H

View File

@ -11,26 +11,12 @@ INITTEST();
RsSerialType* init_item(RsNxsGrp& nxg)
{
nxg.clear();
randString(SHORT_STR, nxg.identity);
randString(SHORT_STR, nxg.grpId);
nxg.timeStamp = rand()%23;
nxg.transactionNumber = rand()%23;
nxg.grpFlag = rand()%242;
init_item(nxg.grp);
init_item(nxg.adminSign);
init_item(nxg.idSign);
int nKey = rand()%12;
for(int i=0; i < nKey; i++){
nxg.keys.groupId = nxg.grpId;
std::string s;
RsTlvSecurityKey k;
init_item(k);
nxg.keys.keys[k.keyId] = k;
}
init_item(nxg.meta);
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
}
@ -38,15 +24,12 @@ RsSerialType* init_item(RsNxsGrp& nxg)
RsSerialType* init_item(RsNxsMsg& nxm)
{
nxm.clear();
randString(SHORT_STR, nxm.msgId);
randString(SHORT_STR, nxm.grpId);
randString(SHORT_STR, nxm.identity);
init_item(nxm.publishSign);
init_item(nxm.idSign);
init_item(nxm.msg);
nxm.msgFlag = rand()%4252;
nxm.timeStamp = rand()%246;
init_item(nxm.meta);
nxm.transactionNumber = rand()%23;
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
@ -55,7 +38,6 @@ RsSerialType* init_item(RsNxsMsg& nxm)
RsSerialType* init_item(RsNxsSyncGrp& rsg)
{
rsg.clear();
rsg.flag = RsNxsSyncGrp::FLAG_USE_SYNC_HASH;
rsg.syncAge = rand()%2423;
randString(3124,rsg.syncHash);
@ -82,9 +64,8 @@ RsSerialType* init_item(RsNxsSyncGrpItem& rsgl)
rsgl.flag = RsNxsSyncGrpItem::FLAG_RESPONSE;
rsgl.transactionNumber = rand()%23;
rsgl.publishTs = rand()%23;
randString(SHORT_STR, rsgl.grpId);
init_item(rsgl.adminSign);
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
}
@ -115,26 +96,11 @@ RsSerialType* init_item(RsNxsTransac& rstx){
bool operator==(const RsNxsGrp& l, const RsNxsGrp& r){
if(!(l.adminSign == r.adminSign)) return false;
if(!(l.idSign == r.idSign)) return false;
if(l.timeStamp != r.timeStamp) return false;
if(l.grpFlag != r.grpFlag) return false;
if(l.identity != r.identity) return false;
if(l.grpId != r.grpId) return false;
if(l.keys.groupId != r.keys.groupId) return false;
if(!(l.grp == r.grp) ) return false;
if(!(l.meta == r.meta) ) return false;
if(l.transactionNumber != r.transactionNumber) return false;
std::map<std::string, RsTlvSecurityKey>::const_iterator mit =
l.keys.keys.begin(), mit_end = l.keys.keys.end();
for(; mit != mit_end; mit++){
const RsTlvSecurityKey& lk = l.keys.keys.find(mit->first)->second;
const RsTlvSecurityKey& rk = r.keys.keys.find(mit->first)->second;
if(! ( lk == rk) ) return false;
}
return true;
}
@ -142,12 +108,8 @@ bool operator==(const RsNxsMsg& l, const RsNxsMsg& r){
if(l.msgId != r.msgId) return false;
if(l.grpId != r.grpId) return false;
if(l.identity != r.identity) return false;
if(l.timeStamp != r.timeStamp) return false;
if(l.msgFlag != r.msgFlag) return false;
if(! (l.msg == r.msg) ) return false;
if(! (l.publishSign == r.publishSign) ) return false;
if(! (l.idSign == r.idSign) ) return false;
if(! (l.meta == r.meta) ) return false;
if(l.transactionNumber != r.transactionNumber) return false;
return true;
@ -179,7 +141,7 @@ bool operator==(const RsNxsSyncMsg& l, const RsNxsSyncMsg& r)
bool operator==(const RsNxsSyncGrpItem& l, const RsNxsSyncGrpItem& r)
{
if(l.flag != r.flag) return false;
if(! (l.adminSign == r.adminSign) ) return false;
if(l.publishTs != r.publishTs) return false;
if(l.grpId != r.grpId) return false;
if(l.transactionNumber != r.transactionNumber) return false;

View File

@ -724,7 +724,8 @@ ContentValue::ContentValue(){
}
ContentValue::~ContentValue(){
// release resources held in data
clearData();
}
ContentValue::ContentValue(ContentValue &from){
@ -861,46 +862,51 @@ void ContentValue::put(const std::string &key, uint32_t len, const char* value){
bool ContentValue::getAsBool(const std::string &key, bool& value) const{
if(mKvBool.find(key) == mKvBool.end())
std::map<std::string, bool>::const_iterator it;
if((it = mKvBool.find(key)) == mKvBool.end())
return false;
value = mKvBool.at(key);
value = it->second;
return true;
}
bool ContentValue::getAsInt32(const std::string &key, int32_t& value) const{
if(mKvInt32.find(key) == mKvInt32.end())
std::map<std::string, int32_t>::const_iterator it;
if((it = mKvInt32.find(key)) == mKvInt32.end())
return false;
value = mKvInt32.at(key);
value = it->second;
return true;
}
bool ContentValue::getAsInt64(const std::string &key, int64_t& value) const{
if(mKvInt64.find(key) == mKvInt64.end())
std::map<std::string, int64_t>::const_iterator it;
if((it = mKvInt64.find(key)) == mKvInt64.end())
return false;
value = mKvInt64.at(key);
value = it->second;
return true;
}
bool ContentValue::getAsString(const std::string &key, std::string &value) const{
if(mKvString.find(key) == mKvString.end())
std::map<std::string, std::string>::const_iterator it;
if((it = mKvString.find(key)) == mKvString.end())
return false;
value = mKvString.at(key);
value = it->second;
return true;
}
bool ContentValue::getAsData(const std::string& key, uint32_t &len, char*& value) const{
if(mKvData.find(key) == mKvData.end())
std::map<std::string, std::pair<uint32_t, char*> >::const_iterator it;
if((it = mKvData.find(key)) == mKvData.end())
return false;
const std::pair<uint32_t, char*> &kvRef = mKvData.at(key);
const std::pair<uint32_t, char*> &kvRef = it->second;
len = kvRef.first;
value = kvRef.second;
@ -909,10 +915,11 @@ bool ContentValue::getAsData(const std::string& key, uint32_t &len, char*& value
bool ContentValue::getAsDouble(const std::string &key, double& value) const{
if(mKvDouble.find(key) == mKvDouble.end())
std::map<std::string, double>::const_iterator it;
if((it = mKvDouble.find(key)) == mKvDouble.end())
return false;
value = mKvDouble.at(key);
value = it->second;
return true;
}