updated rsnxsitem test and added appropriate fixes.

fixed undeclared virtual methods in rsdataservice, added test files
overloaded assignment op for Rstlvbindata 
 

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-new_cache_system@5187 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2012-05-24 22:38:59 +00:00
parent add4715da0
commit 768cf49da6
13 changed files with 220 additions and 302 deletions

View File

@ -18,10 +18,8 @@
// grp table columns // grp table columns
#define KEY_ADMIN_SIGN std::string("adminSign") #define KEY_ADMIN_SIGN std::string("adminSign")
#define KEY_PUB_PUBLISH_KEY std::string("pubPublishhKey") #define KEY_KEY_SET std::string("keySet")
#define KEY_PUB_ADMIN_KEY std::string("pubAdminKey")
#define KEY_PRIV_ADMIN_KEY std::string("privAdminKey")
#define KEY_PRIV_PUBLISH_KEY std::string("privPublishKey")
#define KEY_GRP_FILE std::string("grpFile") #define KEY_GRP_FILE std::string("grpFile")
@ -33,11 +31,7 @@
// grp col numbers // grp col numbers
#define COL_GRP_ID 1 #define COL_GRP_ID 1
#define COL_ADMIN_SIGN 2 #define COL_ADMIN_SIGN 2
#define COL_PUB_PUBLISH_KEY 10 #define COL_KEY_SET 10
#define COL_PUB_ADMIN_KEY 11
#define COL_PRIV_ADMIN_KEY 12
#define COL_PRIV_PUBLISH_KEY 13
// msg col numbers // msg col numbers
#define COL_MSG_ID 1 #define COL_MSG_ID 1
@ -72,10 +66,8 @@ RsDataService::RsDataService(const std::string &serviceDir, const std::string &d
// create table for grps // create table for grps
mDb->execSQL("CREATE TABLE " + GRP_TABLE_NAME + "(" + KEY_GRP_ID + mDb->execSQL("CREATE TABLE " + GRP_TABLE_NAME + "(" + KEY_GRP_ID +
" TEXT PRIMARY KEY ASC," + KEY_TIME_STAMP + " INT," + " TEXT PRIMARY KEY ASC," + KEY_TIME_STAMP + " INT," +
KEY_ADMIN_SIGN + " BLOB," + KEY_PUB_ADMIN_KEY + " BLOB," KEY_ADMIN_SIGN + " BLOB," + " BLOB," + KEY_NXS_FILE +
+ KEY_PUB_PUBLISH_KEY + " BLOB," + KEY_PRIV_ADMIN_KEY + " TEXT," + KEY_NXS_FILE_OFFSET + KEY_KEY_SET + " BLOB," + " INT," + KEY_NXS_LEN + " INT,"
" BLOB," + KEY_PRIV_PUBLISH_KEY + " BLOB," + KEY_NXS_FILE +
" TEXT," + KEY_NXS_FILE_OFFSET + " INT," + KEY_NXS_LEN + " INT,"
+ KEY_NXS_IDENTITY + " TEXT," + KEY_NXS_FLAGS + " INT," + KEY_IDENTITY_SIGN + " BLOB);"); + KEY_NXS_IDENTITY + " TEXT," + KEY_NXS_FLAGS + " INT," + KEY_IDENTITY_SIGN + " BLOB);");
@ -86,10 +78,13 @@ RsDataService::RsDataService(const std::string &serviceDir, const std::string &d
grpColumns.push_back(KEY_GRP_ID); grpColumns.push_back(KEY_ADMIN_SIGN); grpColumns.push_back(KEY_NXS_FILE); 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_LEN); grpColumns.push_back(KEY_TIME_STAMP); grpColumns.push_back(KEY_NXS_FILE_OFFSET); grpColumns.push_back(KEY_NXS_LEN); grpColumns.push_back(KEY_TIME_STAMP);
grpColumns.push_back(KEY_NXS_FLAGS); grpColumns.push_back(KEY_NXS_IDENTITY); grpColumns.push_back(KEY_IDENTITY_SIGN); grpColumns.push_back(KEY_NXS_FLAGS); grpColumns.push_back(KEY_NXS_IDENTITY); grpColumns.push_back(KEY_IDENTITY_SIGN);
grpColumns.push_back(KEY_PUB_PUBLISH_KEY); grpColumns.push_back(KEY_PUB_ADMIN_KEY); grpColumns.push_back(KEY_PRIV_ADMIN_KEY); grpColumns.push_back(KEY_KEY_SET); grpColumns.push_back(KEY_GRP_FILE);
grpColumns.push_back(KEY_PRIV_PUBLISH_KEY); grpColumns.push_back(KEY_GRP_FILE);
} }
RsDataService::~RsDataService(){
mDb->closeDb();
delete mDb;
}
RsNxsGrp* RsDataService::getGroup(RetroCursor &c){ RsNxsGrp* RsDataService::getGroup(RetroCursor &c){
@ -127,7 +122,7 @@ RsNxsGrp* RsDataService::getGroup(RetroCursor &c){
offset = 0; data = NULL; data_len = 0; offset = 0; data = NULL; data_len = 0;
data = c.getData(COL_PRIV_ADMIN_KEY, data_len); data = (char*)c.getData(COL_KEY_SET, data_len);
if(data){ if(data){
ok &= grp->keys.SetTlv(data, data_len, &offset); ok &= grp->keys.SetTlv(data, data_len, &offset);
} }
@ -185,28 +180,28 @@ RsNxsMsg* RsDataService::getMessage(RetroCursor &c){
offset = 0; data_len = 0; offset = 0; data_len = 0;
if(ok){ if(ok){
data = c.getData(COL_PUBLISH_SIGN, data_len); data = (char*)c.getData(COL_PUBLISH_SIGN, data_len);
if(data) if(data)
msg->publishSign.SetTlv(data, data_len, &offset); msg->publishSign.SetTlv(data, data_len, &offset);
} }
std::string grpFile; std::string msgFile;
c.getString(COL_NXS_FILE, grpFile); c.getString(COL_NXS_FILE, msgFile);
data_len = c.getInt32(COL_NXS_LEN); data_len = c.getInt32(COL_NXS_LEN);
ok &= !msgFile.empty(); ok &= !msgFile.empty();
/* now retrieve grp data from file */ /* now retrieve grp data from file */
if(ok){ if(ok){
offset = c.getInt32(COL_NXS_FILE_OFFSET); offset = c.getInt32(COL_NXS_FILE_OFFSET);
std::ifstream istrm(grpFile.c_str()); std::ifstream istrm(msgFile.c_str());
istrm.open(grpFile.c_str(), std::ios::binary); istrm.open(msgFile.c_str(), std::ios::binary);
istrm.seekg(offset, std::ios::beg); istrm.seekg(offset, std::ios::beg);
char grp_data[data_len]; char grp_data[data_len];
istrm.read(grp_data, data_len); istrm.read(grp_data, data_len);
istrm.close(); istrm.close();
offset = 0; offset = 0;
ok &= grp->grp.SetTlv(grp_data, data_len, &offset); ok &= msg->msg.SetTlv(grp_data, data_len, &offset);
} }
if(ok) if(ok)
@ -231,7 +226,7 @@ int RsDataService::storeMessage(std::set<RsNxsMsg *> &msg){
std::string msgFile = mServiceDir + "/" + msgPtr->grpId + "-msgs"; std::string msgFile = mServiceDir + "/" + msgPtr->grpId + "-msgs";
std::fstream ostrm(msgFile.c_str(), std::ios::binary | std::ios::app | std::ios::out); 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 ostrm.seekg(0, std::ios::end); // go to end to append
int32_t offset = ostrm.tellg(); // get fill offset uint32_t offset = ostrm.tellg(); // get fill offset
ContentValue cv; ContentValue cv;
cv.put(KEY_MSG_ID, msgPtr->msgId); cv.put(KEY_MSG_ID, msgPtr->msgId);
@ -249,11 +244,11 @@ int RsDataService::storeMessage(std::set<RsNxsMsg *> &msg){
cv.put(KEY_TIME_STAMP, (int32_t) msgPtr->timeStamp); cv.put(KEY_TIME_STAMP, (int32_t) msgPtr->timeStamp);
char msgData[msgPtr->msg.TlvSize()]; char msgData[msgPtr->msg.TlvSize()];
msgPtr->msg.SetTlv(msgData, msgPtr->msg.TlvSize(), offset); msgPtr->msg.SetTlv(msgData, msgPtr->msg.TlvSize(), &offset);
ostrm.write(msgData, msgPtr->msg.TlvSize()); ostrm.write(msgData, msgPtr->msg.TlvSize());
ostrm.close(); ostrm.close();
cv.put(KEY_NXS_FILE_OFFSET, offset); cv.put(KEY_NXS_FILE_OFFSET, (int32_t)offset);
mDb->sqlInsert(MSG_TABLE_NAME, "", cv); mDb->sqlInsert(MSG_TABLE_NAME, "", cv);
} }
@ -273,10 +268,10 @@ int RsDataService::storeGroup(std::set<RsNxsGrp *> &grp){
RsNxsGrp* grpPtr = *sit; RsNxsGrp* grpPtr = *sit;
std::string grpFile = mServiceDir + "/" + msgPtr->grpId; std::string grpFile = mServiceDir + "/" + grpPtr->grpId;
std::fstream ostrm(grpFile.c_str(), std::ios::binary | std::ios::app | std::ios::out); 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 ostrm.seekg(0, std::ios::end); // go to end to append
int32_t offset = ostrm.tellg(); // get fill offset uint32_t offset = ostrm.tellg(); // get fill offset
ContentValue cv; ContentValue cv;
cv.put(KEY_GRP_ID, grpPtr->grpId); cv.put(KEY_GRP_ID, grpPtr->grpId);
@ -286,20 +281,20 @@ int RsDataService::storeGroup(std::set<RsNxsGrp *> &grp){
if(! (grpPtr->identity.empty()) ){ if(! (grpPtr->identity.empty()) ){
cv.put(KEY_NXS_IDENTITY, grpPtr->identity); cv.put(KEY_NXS_IDENTITY, grpPtr->identity);
char idSignData[msgPtr->idSign.TlvSize()]; char idSignData[grpPtr->idSign.TlvSize()];
cv.put(KEY_IDENTITY_SIGN, grpPtr->idSign.TlvSize(), idSignData); cv.put(KEY_IDENTITY_SIGN, grpPtr->idSign.TlvSize(), idSignData);
} }
char adminSignData[grpPtr->adminSign.TlvSize()]; char adminSignData[grpPtr->adminSign.TlvSize()];
grpPtr->adminSign.SetTlv(adminSignData, grpPtr->adminSign.TlvSize(), offset); grpPtr->adminSign.SetTlv(adminSignData, grpPtr->adminSign.TlvSize(), &offset);
cv.put(KEY_ADMIN_SIGN, grpPtr->adminSign.TlvSize()); cv.put(KEY_ADMIN_SIGN, grpPtr->adminSign.TlvSize(), adminSignData);
char keySetData[grpPtr->keys.TlvSize()]; char keySetData[grpPtr->keys.TlvSize()];
grpPtr->keys.SetTlv(data, grpPtr->keys.TlvSize(), offset); grpPtr->keys.SetTlv(keySetData, grpPtr->keys.TlvSize(), &offset);
cv.put(KEY_KEY_SET, grpPtr->keys.TlvSize(), keySetData); cv.put(KEY_KEY_SET, grpPtr->keys.TlvSize(), keySetData);
char grpData[grpPtr->grp.TlvSize()]; char grpData[grpPtr->grp.TlvSize()];
msgPtr->msg.SetTlv(grpData, grpPtr->grp.TlvSize(), offset); grpPtr->grp.SetTlv(grpData, grpPtr->grp.TlvSize(), &offset);
ostrm.write(grpData, grpPtr->grp.TlvSize()); ostrm.write(grpData, grpPtr->grp.TlvSize());
ostrm.close(); ostrm.close();
} }
@ -325,12 +320,12 @@ int RsDataService::retrieveGrps(std::map<std::string, RsNxsGrp*> &grp, bool cach
if(grp[g->grpId]->timeStamp < g->timeStamp){ if(grp[g->grpId]->timeStamp < g->timeStamp){
delete grp[g->grpId]; delete grp[g->grpId];
grp.insert(g); grp[g->grpId] = g;
}else{ }else{
delete g; delete g;
} }
}else{ }else{
grp.insert(g); grp[g->grpId] = g;
} }
valid = c->moveToNext(); valid = c->moveToNext();
@ -343,7 +338,7 @@ int RsDataService::retrieveGrps(std::map<std::string, RsNxsGrp*> &grp, bool cach
} }
} }
int RsDataService::retrieveMsgs(const std::string &grpId, std::map<std::string, RsGxsMsg *> msg, bool cache){ int RsDataService::retrieveMsgs(const std::string &grpId, std::map<std::string, RsNxsMsg *> msg, bool cache){
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgColumns, KEY_GRP_ID+ "=" + grpId, ""); RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgColumns, KEY_GRP_ID+ "=" + grpId, "");
@ -354,10 +349,10 @@ int RsDataService::retrieveMsgs(const std::string &grpId, std::map<std::string,
RsNxsMsg* m = getMessage(*c); RsNxsMsg* m = getMessage(*c);
// only add the latest grp info // only add the latest grp info
bool exists = grp.find(g->grpId) != grp.end(); bool exists = msg.find(m->msgId) != msg.end();
if(exists){ if(exists){
if(grp[m->msgId]->timeStamp < m->timeStamp){ if(msg[m->msgId]->timeStamp < m->timeStamp){
delete msg[m->msgId]; delete msg[m->msgId];
msg[m->msgId] = m; msg[m->msgId] = m;
}else{ }else{
@ -377,8 +372,8 @@ int RsDataService::retrieveMsgs(const std::string &grpId, std::map<std::string,
} }
} }
int RsDataService::retrieveMsgVersions(const std::string &grpId, const std::string msgId, int RsDataService::retrieveMsgVersions(const std::string &grpId, const std::string& msgId,
std::set<RsNxsMsg *> msg, bool cache){ std::set<RsNxsMsg *>& msg, bool cache){
std::string selection = KEY_GRP_ID + "=" + grpId + "," + KEY_MSG_ID + "=" + msgId; std::string selection = KEY_GRP_ID + "=" + grpId + "," + KEY_MSG_ID + "=" + msgId;
@ -405,7 +400,7 @@ int RsDataService::retrieveMsgVersions(const std::string &grpId, const std::stri
} }
int RsDataService::retrieveGrpVersions(const std::string &grpId, std::set<RsGxsGroup *> &grp){ int RsDataService::retrieveGrpVersions(const std::string &grpId, std::set<RsNxsGrp *> &grp, bool cache){
std::string selection = KEY_GRP_ID + "=" + grpId; std::string selection = KEY_GRP_ID + "=" + grpId;
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, msgColumns, selection, ""); RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, msgColumns, selection, "");
@ -442,7 +437,8 @@ RsNxsGrp* RsDataService::retrieveGrpVersion(const RsGxsGrpId &grpId){
for(; sit != grps.end(); sit++){ for(; sit != grps.end(); sit++){
grp = *sit; grp = *sit;
if(grp->adminSign == grpId.adminSign){ if(!memcmp(grp->adminSign.signData.bin_data, grpId.adminSign.signData.bin_data,
grpId.adminSign.signData.bin_len)){
break; break;
} }
grp = NULL; grp = NULL;
@ -463,7 +459,7 @@ RsNxsGrp* RsDataService::retrieveGrpVersion(const RsGxsGrpId &grpId){
RsNxsMsg* RsDataService::retrieveMsgVersion(const RsGxsMsgId &msgId){ RsNxsMsg* RsDataService::retrieveMsgVersion(const RsGxsMsgId &msgId){
std::set<RsNxsMsg*> msgs; std::set<RsNxsMsg*> msgs;
retrieveMsgVersions(msgId.grpId, msgId.msgId, msgs); retrieveMsgVersions(msgId.grpId, msgId.msgId, msgs, false);
RsNxsMsg* msg = NULL; RsNxsMsg* msg = NULL;
if(!msgs.empty()){ if(!msgs.empty()){
@ -473,7 +469,8 @@ RsNxsMsg* RsDataService::retrieveMsgVersion(const RsGxsMsgId &msgId){
for(; sit != msgs.end(); sit++){ for(; sit != msgs.end(); sit++){
msg = *sit; msg = *sit;
if(msg->idSign == msgId.idSign) if(!memcmp(msg->idSign.signData.bin_data, msgId.idSign.signData.bin_data,
msg->idSign.signData.bin_len))
break; break;
msg = NULL; msg = NULL;

View File

@ -19,7 +19,7 @@ public:
* @param cache whether to store retrieval in memory for faster later retrieval * @param cache whether to store retrieval in memory for faster later retrieval
* @return error code * @return error code
*/ */
int retrieveMsgs(const std::string& grpId, std::map<std::string, RsGxsMsg*> msg, bool cache); int retrieveMsgs(const std::string& grpId, std::map<std::string, RsNxsMsg*> msg, bool cache);
/*! /*!
* Retrieves latest version of groups for a service * Retrieves latest version of groups for a service
@ -28,7 +28,7 @@ public:
* @param cache whether to store retrieval in mem for faster later retrieval * @param cache whether to store retrieval in mem for faster later retrieval
* @return error code * @return error code
*/ */
int retrieveGrps(std::set<std::string, RsGxsGroup*>& grp, bool cache); int retrieveGrps(std::map<std::string, RsNxsGrp*>& grp, bool cache);
/*! /*!
* Retrieves all the versions of a group * Retrieves all the versions of a group
@ -44,7 +44,7 @@ public:
* @param msgId the id of the message to get versions for * @param msgId the id of the message to get versions for
* @return errCode * @return errCode
*/ */
int retrieveMsgVersions(const std::string &grpId, const std::string msgId, std::set<RsNxsMsg *> grp, bool cache); int retrieveMsgVersions(const std::string &grpId, const std::string& msgId, std::set<RsNxsMsg *>& grp, bool cache);
/*! /*!
* @param msgId the id of the message to retrieve * @param msgId the id of the message to retrieve

View File

@ -83,21 +83,21 @@ public:
* @param cache whether to store retrieval in mem for faster later retrieval * @param cache whether to store retrieval in mem for faster later retrieval
* @return error code * @return error code
*/ */
virtual int retrieveGrps(std::set<std::string, RsNxsGrp*>& grp, bool cache) = 0; virtual int retrieveGrps(std::map<std::string, RsNxsGrp*>& grp, bool cache) = 0;
/*! /*!
* @param grpId the id of the group to get versions for * @param grpId the id of the group to get versions for
* @param cache whether to store the result in memory * @param cache whether to store the result in memory
* @param errCode * @param errCode
*/ */
virtual int retrieveGrpVersions(const std::string& grpId, std::set<RsNxsGrp*>& grp) = 0; virtual int retrieveGrpVersions(const std::string& grpId, std::set<RsNxsGrp*>& grp, bool cache) = 0;
/*! /*!
* @param msgId the id of the message to get versions for * @param msgId the id of the message to get versions for
* @param cache whether to store the result in memory * @param cache whether to store the result in memory
* @param errCode * @param errCode
*/ */
virtual int retrieveMsgVersions(const std::string& grpId, const std::string msgId, std::set<RsNxsMsg*> grp) = 0; virtual int retrieveMsgVersions(const std::string& grpId, const std::string& msgId, std::set<RsNxsMsg*>& grp, bool cache) = 0;
/*! /*!
* @param msgId the id of the message to retrieve * @param msgId the id of the message to retrieve

View File

@ -5,7 +5,7 @@
#include "rsgxs.h" #include "rsgxs.h"
class RsGenExchange : public RsGxsService class RsGenExchange // : public RsGxsService
{ {
public: public:
RsGenExchange(); RsGenExchange();

View File

@ -693,3 +693,4 @@ SOURCES += services/p3photoservice.cc \
# rsserver/p3photo.cc \ # rsserver/p3photo.cc \
} }

View File

@ -1,7 +1,7 @@
#include "rsnxsitems.h" #include "rsnxsitems.h"
#include "rsbaseserial.h" #include "rsbaseserial.h"
#define RSSERIAL_DEBUG
const uint8_t RsSyncGrpList::FLAG_REQUEST = 0x001; const uint8_t RsSyncGrpList::FLAG_REQUEST = 0x001;
const uint8_t RsSyncGrpList::FLAG_RESPONSE = 0x002; const uint8_t RsSyncGrpList::FLAG_RESPONSE = 0x002;
@ -166,27 +166,8 @@ bool RsNxsSerialiser::serialiseSynGrpMsgList(RsSyncGrpMsgList *item, void *data,
ok &= setRawUInt8(data, *size, &offset, item->flag); 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_GROUPID, item->grpId);
ok &= SetTlvString(data, *size, &offset, TLV_TYPE_STR_MSGID, item->msgId);
SyncList::iterator mit = ok &= item->idSign.SetTlv(data, *size, &offset);
item->msgs.begin();
for(; mit != item->msgs.end(); mit++){
// if not version contains then this
// entry is invalid
ok &= SetTlvString(data, *size, &offset, TLV_TYPE_STR_MSGID, mit->first);
uint32_t nVersions = mit->second.size();
ok &= setRawUInt32(data, *size, &offset, nVersions);
std::list<RsTlvKeySignature>::iterator lit = mit->second.begin();
for(; lit != mit->second.end(); lit++)
{
RsTlvKeySignature& b = *lit;
b.SetTlv(data, *size, &offset);
}
}
if(offset != tlvsize){ if(offset != tlvsize){
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
@ -295,6 +276,7 @@ bool RsNxsSerialiser::serialiseNxsGrp(RsNxsGrp *item, void *data, uint32_t *size
ok &= item->idSign.SetTlv(data, tlvsize, &offset); ok &= item->idSign.SetTlv(data, tlvsize, &offset);
ok &= item->adminSign.SetTlv(data, tlvsize, &offset); ok &= item->adminSign.SetTlv(data, tlvsize, &offset);
ok &= item->keys.SetTlv(data, tlvsize, &offset); ok &= item->keys.SetTlv(data, tlvsize, &offset);
ok &= item->grp.SetTlv(data, tlvsize, &offset);
if(offset != tlvsize){ if(offset != tlvsize){
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
@ -388,29 +370,9 @@ bool RsNxsSerialiser::serialiseSyncGrpList(RsSyncGrpList *item, void *data, uint
/* RsSyncGrpList */ /* RsSyncGrpList */
SyncList::iterator mit =
item->grps.begin();
ok &= setRawUInt8(data, *size, &offset, item->flag); ok &= setRawUInt8(data, *size, &offset, item->flag);
ok &= SetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
for(; mit != item->grps.end(); mit++){ ok &= item->adminSign.SetTlv(data, *size, &offset);
// if not version contains then this
// entry is invalid
ok &= SetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, mit->first);
uint32_t nVersions = mit->second.size();
ok &= setRawUInt32(data, *size, &offset, nVersions);
std::list<RsTlvKeySignature>::iterator lit = mit->second.begin();
for(; lit != mit->second.end(); lit++)
{
RsTlvKeySignature& b = *lit;
b.SetTlv(data, *size, &offset);
}
}
if(offset != tlvsize){ if(offset != tlvsize){
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
@ -493,7 +455,7 @@ bool RsNxsSerialiser::serialiseNxsExtended(RsNxsExtended *item, void *data, uint
RsNxsGrp* RsNxsSerialiser::deserialNxsGrp(void *data, uint32_t *size){ RsNxsGrp* RsNxsSerialiser::deserialNxsGrp(void *data, uint32_t *size){
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
std::cerr << "RsNxsSerialiser::deserialGrpResp()" << std::endl; std::cerr << "RsNxsSerialiser::deserialNxsGrp()" << std::endl;
#endif #endif
/* get the type and size */ /* get the type and size */
uint32_t rstype = getRsItemId(data); uint32_t rstype = getRsItemId(data);
@ -536,6 +498,7 @@ RsNxsGrp* RsNxsSerialiser::deserialNxsGrp(void *data, uint32_t *size){
ok &= item->idSign.GetTlv(data, *size, &offset); ok &= item->idSign.GetTlv(data, *size, &offset);
ok &= item->adminSign.GetTlv(data, *size, &offset); ok &= item->adminSign.GetTlv(data, *size, &offset);
ok &= item->keys.GetTlv(data, *size, &offset); ok &= item->keys.GetTlv(data, *size, &offset);
ok &= item->grp.GetTlv(data, *size, &offset);
if (offset != rssize) if (offset != rssize)
{ {
@ -738,24 +701,8 @@ RsSyncGrpList* RsNxsSerialiser::deserialSyncGrpList(void *data, uint32_t *size){
offset += 8; offset += 8;
ok &= getRawUInt8(data, *size, &offset, &(item->flag)); ok &= getRawUInt8(data, *size, &offset, &(item->flag));
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
while((offset < rssize) && ok) ok &= item->adminSign.GetTlv(data, *size, &offset);
{
std::string grpId;
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, grpId);
uint32_t nVersions;
ok &= getRawUInt32(data, *size, &offset, &nVersions);
uint32_t verCount = 0;
while((offset < rssize) && ok && (verCount < nVersions))
{
RsTlvKeySignature sign;
ok &= sign.GetTlv(data, *size, &offset);
item->grps[grpId].push_back(sign);
verCount++;
}
}
if (offset != rssize) if (offset != rssize)
{ {
@ -821,27 +768,8 @@ RsSyncGrpMsgList* RsNxsSerialiser::deserialSyncGrpMsgList(void *data, uint32_t *
ok &= getRawUInt8(data, *size, &offset, &(item->flag)); 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_GROUPID, item->grpId);
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_MSGID, item->msgId);
// now get number of msgs ok &= item->idSign.GetTlv(data, *size, &offset);
while((offset < rssize) && ok)
{
std::string msgId;
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_MSGID, msgId);
uint32_t nVersions;
ok &= getRawUInt32(data, *size, &offset, &nVersions);
uint32_t verCount = 0;
while((offset < rssize) && ok && (verCount < nVersions))
{
RsTlvKeySignature sign;
ok &= sign.GetTlv(data, *size, &offset);
item->msgs[msgId].push_back(sign);
verCount++;
}
}
if (offset != rssize) if (offset != rssize)
{ {
@ -1002,23 +930,9 @@ uint32_t RsNxsSerialiser::sizeSyncGrpList(RsSyncGrpList *item)
s += 1; // flag s += 1; // flag
std::map<std::string, std::list<RsTlvKeySignature> >::iterator mit s += GetTlvStringSize(item->grpId);
= item->grps.begin(); s += item->adminSign.TlvSize();
for(; mit != item->grps.end(); mit++){
s += 4; // number of versions
s += GetTlvStringSize(mit->first);
std::list<RsTlvKeySignature>& verL = mit->second;
std::list<RsTlvKeySignature>::iterator lit =
verL.begin();
for(; lit != verL.end(); lit++){
RsTlvKeySignature& sign = *lit; // version
s += sign.TlvSize();
}
}
return s; return s;
} }
@ -1043,23 +957,9 @@ uint32_t RsNxsSerialiser::sizeSyncGrpMsgList(RsSyncGrpMsgList *item)
s += 1; // flag s += 1; // flag
s += GetTlvStringSize(item->grpId); s += GetTlvStringSize(item->grpId);
std::map<std::string, std::list<RsTlvKeySignature> >::iterator mit s += GetTlvStringSize(item->msgId);
= item->msgs.begin(); s += item->idSign.TlvSize();
for(; mit != item->msgs.end(); mit++){
s += 4; // number of versions
s += GetTlvStringSize(mit->first);
std::list<RsTlvKeySignature>& verL = mit->second;
std::list<RsTlvKeySignature>::iterator lit =
verL.begin();
for(; lit != verL.end(); lit++){
RsTlvKeySignature& sign = *lit; // version
s += sign.TlvSize();
}
}
return s; return s;
} }
@ -1067,6 +967,11 @@ uint32_t RsNxsSerialiser::sizeNxsSearchReq(RsNxsSearchReq *item){
return 0; return 0;
} }
uint32_t RsNxsSerialiser::sizeNxsExtended(RsNxsExtended *item){
return 0;
}
/** print and clear functions **/ /** print and clear functions **/
@ -1112,13 +1017,16 @@ void RsSyncGrpMsg::clear()
void RsSyncGrpList::clear() void RsSyncGrpList::clear()
{ {
flag = 0; flag = 0;
grps.clear(); adminSign.TlvClear();
grpId.clear();
} }
void RsSyncGrpMsgList::clear() void RsSyncGrpMsgList::clear()
{ {
flag = 0; flag = 0;
msgs.clear(); msgId.clear();
idSign.TlvClear();
grpId.clear();
} }
std::ostream& RsSyncGrp::print(std::ostream &out, uint16_t indent) std::ostream& RsSyncGrp::print(std::ostream &out, uint16_t indent)
@ -1180,24 +1088,10 @@ std::ostream& RsSyncGrpList::print(std::ostream &out, uint16_t indent)
printIndent(out , int_Indent); printIndent(out , int_Indent);
out << "flag: " << flag << std::endl; out << "flag: " << flag << std::endl;
printIndent(out , int_Indent); printIndent(out , int_Indent);
out << "grpId: " << grpId << std::endl;
SyncList::iterator mit printIndent(out , int_Indent);
= grps.begin(); adminSign.print(out, indent);
printIndent(out , int_Indent);
for(; mit != grps.end(); mit++){
out << "grpId: " << mit->first;
printIndent(out , int_Indent);
std::list<RsTlvKeySignature>& verL = mit->second;
std::list<RsTlvKeySignature>::iterator lit =
verL.begin();
for(; lit != verL.end(); lit++){
RsTlvKeySignature& sign = *lit;
sign.print(out, indent);
}
}
printRsItemEnd(out , "RsSyncGrpList", indent); printRsItemEnd(out , "RsSyncGrpList", indent);
return out; return out;
@ -1214,24 +1108,11 @@ std::ostream& RsSyncGrpMsgList::print(std::ostream &out, uint16_t indent)
out << "flag: " << flag << std::endl; out << "flag: " << flag << std::endl;
printIndent(out , int_Indent); printIndent(out , int_Indent);
out << "grpId: " << grpId << std::endl; out << "grpId: " << grpId << std::endl;
printIndent(out , int_Indent);
SyncList::iterator mit out << "msgId: " << msgId << std::endl;
= msgs.begin(); printIndent(out , int_Indent);
idSign.print(out, indent);
for(; mit != msgs.end(); mit++){ printIndent(out , int_Indent);
out << "msgId: " << mit->first;
printIndent(out , int_Indent);
std::list<RsTlvKeySignature>& verL = mit->second;
std::list<RsTlvKeySignature>::iterator lit =
verL.begin();
for(; lit != verL.end(); lit++){
RsTlvKeySignature& sign = *lit;
sign.print(out, indent);
}
}
printRsItemEnd(out ,"RsSyncGrpMsgList", indent); printRsItemEnd(out ,"RsSyncGrpMsgList", indent);
return out; return out;

View File

@ -96,8 +96,6 @@ public:
}; };
typedef std::map<std::string, std::list<RsTlvKeySignature> > SyncList;
/*! /*!
* Use to send to peer list of grps * Use to send to peer list of grps
* held by server peer * held by server peer
@ -112,6 +110,7 @@ public:
static const uint8_t FLAG_USE_SYNC_HASH; static const uint8_t FLAG_USE_SYNC_HASH;
RsSyncGrpList(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_SYNC_GRP_LIST) { return ; } RsSyncGrpList(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_SYNC_GRP_LIST) { return ; }
virtual ~RsSyncGrpList() { return; }
virtual void clear(); virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent); virtual std::ostream &print(std::ostream &out, uint16_t indent);
@ -120,7 +119,8 @@ public:
uint8_t flag; // request or response uint8_t flag; // request or response
/// groups held by sending peer /// groups held by sending peer
SyncList grps; // grpId/ sign pair RsTlvKeySignature adminSign;
std::string grpId;
}; };
@ -192,7 +192,8 @@ public:
uint8_t flag; // response/req uint8_t flag; // response/req
std::string grpId; std::string grpId;
SyncList msgs; // msg/versions pairs std::string msgId;
RsTlvKeySignature idSign;
}; };

View File

@ -81,6 +81,11 @@ RsTlvBinaryData::~RsTlvBinaryData()
TlvClear(); TlvClear();
} }
void RsTlvBinaryData::operator =(const RsTlvBinaryData& b){
setBinData(b.bin_data, b.bin_len);
tlvtype = b.tlvtype;
}
/// used to allocate memory andinitialize binary data member /// used to allocate memory andinitialize binary data member
bool RsTlvBinaryData::setBinData(const void *data, uint32_t size) bool RsTlvBinaryData::setBinData(const void *data, uint32_t size)

View File

@ -65,6 +65,7 @@ class RsTlvBinaryData: public RsTlvItem
{ {
public: public:
RsTlvBinaryData(uint16_t t); RsTlvBinaryData(uint16_t t);
void operator=(const RsTlvBinaryData& b);
virtual ~RsTlvBinaryData(); virtual ~RsTlvBinaryData();
virtual uint32_t TlvSize(); virtual uint32_t TlvSize();
virtual void TlvClear(); /*! Initialize fields to empty legal values ( "0", "", etc) */ virtual void TlvClear(); /*! Initialize fields to empty legal values ( "0", "", etc) */

View File

@ -0,0 +1,32 @@
#include "support.h"
#include "rsdataservice_test.h"
#include "gxs/rsdataservice.h"
INITTEST();
int main()
{
std::cerr << "RsDataService Tests" << std::endl;
FINALREPORT("RsDataService Tests");
return TESTRESULT();
}
bool test_groupStoreAndRetrieve(){
RsNxsGrp* grp;
}

View File

@ -0,0 +1,29 @@
#ifndef RSDATASERVICE_TEST_H
#define RSDATASERVICE_TEST_H
#include "util/rsthreads.h"
bool test_messageStoresAndRetrieve();
bool test_messageVersionRetrieve();
bool test_groupStoreAndRetrieve();
bool test_groupVersionRetrieve();
bool test_storeAndDeleteGroup();
bool test_storeAndDeleteMessage();
bool test_searchMsg();
bool test_searchGrp();
bool test_multiThreaded();
class DataReadWrite : RsThread
{
};
bool test_cacheSize();
#endif // RSDATASERVICE_TEST_H

View File

@ -9,30 +9,43 @@ INITTEST();
#define NUM_SYNC_MSGS 8 #define NUM_SYNC_MSGS 8
#define NUM_SYNC_GRPS 5 #define NUM_SYNC_GRPS 5
RsSerialType* init_item(RsGrpResp& rgr) RsSerialType* init_item(RsNxsGrp& nxg)
{ {
rgr.clear(); randString(SHORT_STR, nxg.identity);
randString(SHORT_STR, nxg.grpId);
nxg.timeStamp = rand()%23;
nxg.grpFlag = rand()%242;
init_item(nxg.grp);
for(int i=0; i < 5; i++){ init_item(nxg.adminSign);
RsTlvBinaryData* b = new RsTlvBinaryData(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); init_item(nxg.idSign);
init_item(*b);
rgr.grps.push_back(b); 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;
} }
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
} }
RsSerialType* init_item(RsGrpMsgResp& rgmr) RsSerialType* init_item(RsNxsMsg& nxm)
{ {
rgmr.clear(); randString(SHORT_STR, nxm.msgId);
randString(SHORT_STR, nxm.grpId);
randString(SHORT_STR, nxm.identity);
for(int i=0; i < 5; i++){ init_item(nxm.publishSign);
RsTlvBinaryData* b = new RsTlvBinaryData(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); init_item(nxm.idSign);
init_item(*b); init_item(nxm.msg);
rgmr.msgs.push_back(b); nxm.msgFlag = rand()%4252;
} nxm.timeStamp = rand()%246;
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
} }
@ -65,20 +78,10 @@ RsSerialType* init_item(RsSyncGrpList& rsgl)
rsgl.clear(); rsgl.clear();
rsgl.flag = RsSyncGrpList::FLAG_RESPONSE; rsgl.flag = RsSyncGrpList::FLAG_RESPONSE;
randString(SHORT_STR, rsgl.grpId);
init_item(rsgl.adminSign);
for(int i=0; i < NUM_SYNC_GRPS; i++){
int nVers = rand()%8;
std::list<uint32_t> verL;
for(int j=0; j < nVers; j++){
verL.push_back(rand()%343);
}
std::string grpId;
randString(SHORT_STR, grpId);
std::pair<std::string, std::list<uint32_t> > p(grpId, verL);
rsgl.grps.insert(p);
}
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
} }
@ -88,50 +91,47 @@ RsSerialType* init_item(RsSyncGrpMsgList& rsgml)
rsgml.flag = RsSyncGrpList::FLAG_RESPONSE; rsgml.flag = RsSyncGrpList::FLAG_RESPONSE;
randString(SHORT_STR, rsgml.grpId); randString(SHORT_STR, rsgml.grpId);
randString(SHORT_STR, rsgml.msgId);
init_item(rsgml.idSign);
for(int i=0; i < NUM_SYNC_GRPS; i++){
int nVers = rand()%8;
std::list<uint32_t> verL;
for(int j=0; j < nVers; j++){
verL.push_back(rand()%343);
}
std::string msgId;
randString(SHORT_STR, msgId);
std::pair<std::string, std::list<uint32_t> > p(msgId, verL);
rsgml.msgs.insert(p);
}
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
} }
bool operator==(const RsGrpResp& l, const RsGrpResp& r){ bool operator==(const RsNxsGrp& l, const RsNxsGrp& r){
if(l.grps.size() != r.grps.size()) return false; 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;
std::list<RsTlvBinaryData*>::const_iterator lit std::map<std::string, RsTlvSecurityKey>::const_iterator mit =
= l.grps.begin(), rit = l.keys.keys.begin(), mit_end = l.keys.keys.end();
r.grps.begin();
for(; lit != l.grps.end(); lit++, rit++){ for(; mit != mit_end; mit++){
if(!(*(*lit) == *(*rit))) return false; 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; return true;
} }
bool operator==(const RsGrpMsgResp& l, const RsGrpMsgResp& r){ bool operator==(const RsNxsMsg& l, const RsNxsMsg& r){
if(l.msgs.size() != r.msgs.size()) return false; if(l.msgId != r.msgId) return false;
if(l.grpId != r.grpId) return false;
std::list<RsTlvBinaryData*>::const_iterator lit if(l.identity != r.identity) return false;
= l.msgs.begin(), rit = if(l.timeStamp != r.timeStamp) return false;
r.msgs.begin(); if(l.msgFlag != r.msgFlag) return false;
if(! (l.msg == r.msg) ) return false;
for(; lit != l.msgs.end(); lit++, rit++){ if(! (l.publishSign == r.publishSign) ) return false;
if(!(*(*lit) == *(*rit))) return false; if(! (l.idSign == r.idSign) ) return false;
}
return true; return true;
} }
@ -160,23 +160,9 @@ bool operator==(const RsSyncGrpMsg& l, const RsSyncGrpMsg& r)
bool operator==(const RsSyncGrpList& l, const RsSyncGrpList& r) bool operator==(const RsSyncGrpList& l, const RsSyncGrpList& r)
{ {
if(l.flag != r.flag) return false; if(l.flag != r.flag) return false;
if(! (l.adminSign == r.adminSign) ) return false;
if(l.grpId != r.grpId) return false;
SyncList::const_iterator lit = l.grps.begin(), rit= r.grps.begin();
for(; lit != l.grps.end(); lit++, rit++){
if(lit->first != rit->first) return false;
const std::list<uint32_t>& lList = lit->second, &rList
= rit->second;
std::list<uint32_t>::const_iterator lit2 = lList.begin(), rit2
= rList.begin();
for(; lit2 != lList.end(); lit2++, rit2++){
if(*lit2 != *rit2) return false;
}
}
return true; return true;
} }
@ -184,23 +170,8 @@ bool operator==(const RsSyncGrpMsgList& l, const RsSyncGrpMsgList& r)
{ {
if(l.flag != r.flag) return false; if(l.flag != r.flag) return false;
if(l.grpId != r.grpId) return false; if(l.grpId != r.grpId) return false;
if(l.msgId != r.msgId) return false;
SyncList::const_iterator lit = l.msgs.begin(), rit= r.msgs.begin(); if(! (l.idSign == r.idSign) ) return false;
for(; lit != l.msgs.end(); lit++, rit++){
if(lit->first != rit->first) return false;
const std::list<uint32_t>& lList = lit->second, &rList
= rit->second;
std::list<uint32_t>::const_iterator lit2 = lList.begin(), rit2
= rList.begin();
for(; lit2 != lList.end(); lit2++, rit2++){
if(*lit2 != *rit2) return false;
}
}
return true; return true;
} }
@ -209,8 +180,8 @@ int main()
{ {
std::cerr << "RsNxsItem Tests" << std::endl; std::cerr << "RsNxsItem Tests" << std::endl;
test_RsItem<RsGrpResp>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsGrpResp"); test_RsItem<RsNxsGrp>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsGrpResp");
test_RsItem<RsGrpMsgResp>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsGrpMsgResp"); test_RsItem<RsNxsMsg>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsGrpMsgResp");
test_RsItem<RsSyncGrp>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsSyncGrp"); test_RsItem<RsSyncGrp>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsSyncGrp");
test_RsItem<RsSyncGrpMsg>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsSyncGrpMsg"); test_RsItem<RsSyncGrpMsg>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsSyncGrpMsg");
test_RsItem<RsSyncGrpList>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsSyncGrpList"); test_RsItem<RsSyncGrpList>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsSyncGrpList");

View File

@ -4,15 +4,15 @@
#include "serialiser/rsnxsitems.h" #include "serialiser/rsnxsitems.h"
RsSerialType* init_item(RsGrpResp&); RsSerialType* init_item(RsNxsGrp&);
RsSerialType* init_item(RsGrpMsgResp&); RsSerialType* init_item(RsNxsMsg&);
RsSerialType* init_item(RsSyncGrp&); RsSerialType* init_item(RsSyncGrp&);
RsSerialType* init_item(RsSyncGrpMsg&); RsSerialType* init_item(RsSyncGrpMsg&);
RsSerialType* init_item(RsSyncGrpList&); RsSerialType* init_item(RsSyncGrpList&);
RsSerialType* init_item(RsSyncGrpMsgList&); RsSerialType* init_item(RsSyncGrpMsgList&);
bool operator==(const RsGrpResp&, const RsGrpResp&); bool operator==(const RsNxsGrp&, const RsNxsGrp&);
bool operator==(const RsGrpMsgResp&, const RsGrpMsgResp&); bool operator==(const RsNxsMsg&, const RsNxsMsg&);
bool operator==(const RsSyncGrp&, const RsSyncGrp&); bool operator==(const RsSyncGrp&, const RsSyncGrp&);
bool operator==(const RsSyncGrpMsg&, const RsSyncGrpMsg&); bool operator==(const RsSyncGrpMsg&, const RsSyncGrpMsg&);
bool operator==(const RsSyncGrpList&, const RsSyncGrpList&); bool operator==(const RsSyncGrpList&, const RsSyncGrpList&);