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
#define KEY_ADMIN_SIGN std::string("adminSign")
#define KEY_PUB_PUBLISH_KEY std::string("pubPublishhKey")
#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_KEY_SET std::string("keySet")
#define KEY_GRP_FILE std::string("grpFile")
@ -33,11 +31,7 @@
// grp col numbers
#define COL_GRP_ID 1
#define COL_ADMIN_SIGN 2
#define COL_PUB_PUBLISH_KEY 10
#define COL_PUB_ADMIN_KEY 11
#define COL_PRIV_ADMIN_KEY 12
#define COL_PRIV_PUBLISH_KEY 13
#define COL_KEY_SET 10
// msg col numbers
#define COL_MSG_ID 1
@ -72,10 +66,8 @@ RsDataService::RsDataService(const std::string &serviceDir, const std::string &d
// create table for grps
mDb->execSQL("CREATE TABLE " + GRP_TABLE_NAME + "(" + KEY_GRP_ID +
" TEXT PRIMARY KEY ASC," + KEY_TIME_STAMP + " INT," +
KEY_ADMIN_SIGN + " BLOB," + KEY_PUB_ADMIN_KEY + " BLOB,"
+ KEY_PUB_PUBLISH_KEY + " BLOB," + KEY_PRIV_ADMIN_KEY +
" BLOB," + KEY_PRIV_PUBLISH_KEY + " BLOB," + KEY_NXS_FILE +
" TEXT," + KEY_NXS_FILE_OFFSET + " INT," + KEY_NXS_LEN + " INT,"
KEY_ADMIN_SIGN + " BLOB," + " BLOB," + KEY_NXS_FILE +
" TEXT," + KEY_NXS_FILE_OFFSET + KEY_KEY_SET + " BLOB," + " INT," + KEY_NXS_LEN + " INT,"
+ 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_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_PUB_PUBLISH_KEY); grpColumns.push_back(KEY_PUB_ADMIN_KEY); grpColumns.push_back(KEY_PRIV_ADMIN_KEY);
grpColumns.push_back(KEY_PRIV_PUBLISH_KEY); grpColumns.push_back(KEY_GRP_FILE);
grpColumns.push_back(KEY_KEY_SET); grpColumns.push_back(KEY_GRP_FILE);
}
RsDataService::~RsDataService(){
mDb->closeDb();
delete mDb;
}
RsNxsGrp* RsDataService::getGroup(RetroCursor &c){
@ -127,7 +122,7 @@ RsNxsGrp* RsDataService::getGroup(RetroCursor &c){
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){
ok &= grp->keys.SetTlv(data, data_len, &offset);
}
@ -185,28 +180,28 @@ RsNxsMsg* RsDataService::getMessage(RetroCursor &c){
offset = 0; data_len = 0;
if(ok){
data = c.getData(COL_PUBLISH_SIGN, data_len);
data = (char*)c.getData(COL_PUBLISH_SIGN, data_len);
if(data)
msg->publishSign.SetTlv(data, data_len, &offset);
}
std::string grpFile;
c.getString(COL_NXS_FILE, grpFile);
std::string msgFile;
c.getString(COL_NXS_FILE, msgFile);
data_len = c.getInt32(COL_NXS_LEN);
ok &= !msgFile.empty();
/* now retrieve grp data from file */
if(ok){
offset = c.getInt32(COL_NXS_FILE_OFFSET);
std::ifstream istrm(grpFile.c_str());
istrm.open(grpFile.c_str(), std::ios::binary);
std::ifstream istrm(msgFile.c_str());
istrm.open(msgFile.c_str(), std::ios::binary);
istrm.seekg(offset, std::ios::beg);
char grp_data[data_len];
istrm.read(grp_data, data_len);
istrm.close();
offset = 0;
ok &= grp->grp.SetTlv(grp_data, data_len, &offset);
ok &= msg->msg.SetTlv(grp_data, data_len, &offset);
}
if(ok)
@ -231,7 +226,7 @@ int RsDataService::storeMessage(std::set<RsNxsMsg *> &msg){
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
int32_t offset = ostrm.tellg(); // get fill offset
uint32_t offset = ostrm.tellg(); // get fill offset
ContentValue cv;
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);
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.close();
cv.put(KEY_NXS_FILE_OFFSET, offset);
cv.put(KEY_NXS_FILE_OFFSET, (int32_t)offset);
mDb->sqlInsert(MSG_TABLE_NAME, "", cv);
}
@ -273,10 +268,10 @@ int RsDataService::storeGroup(std::set<RsNxsGrp *> &grp){
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);
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;
cv.put(KEY_GRP_ID, grpPtr->grpId);
@ -286,20 +281,20 @@ int RsDataService::storeGroup(std::set<RsNxsGrp *> &grp){
if(! (grpPtr->identity.empty()) ){
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);
}
char adminSignData[grpPtr->adminSign.TlvSize()];
grpPtr->adminSign.SetTlv(adminSignData, grpPtr->adminSign.TlvSize(), offset);
cv.put(KEY_ADMIN_SIGN, grpPtr->adminSign.TlvSize());
grpPtr->adminSign.SetTlv(adminSignData, grpPtr->adminSign.TlvSize(), &offset);
cv.put(KEY_ADMIN_SIGN, grpPtr->adminSign.TlvSize(), adminSignData);
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);
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.close();
}
@ -325,12 +320,12 @@ int RsDataService::retrieveGrps(std::map<std::string, RsNxsGrp*> &grp, bool cach
if(grp[g->grpId]->timeStamp < g->timeStamp){
delete grp[g->grpId];
grp.insert(g);
grp[g->grpId] = g;
}else{
delete g;
}
}else{
grp.insert(g);
grp[g->grpId] = g;
}
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, "");
@ -354,10 +349,10 @@ int RsDataService::retrieveMsgs(const std::string &grpId, std::map<std::string,
RsNxsMsg* m = getMessage(*c);
// 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(grp[m->msgId]->timeStamp < m->timeStamp){
if(msg[m->msgId]->timeStamp < m->timeStamp){
delete msg[m->msgId];
msg[m->msgId] = m;
}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,
std::set<RsNxsMsg *> msg, bool cache){
int RsDataService::retrieveMsgVersions(const std::string &grpId, const std::string& msgId,
std::set<RsNxsMsg *>& msg, bool cache){
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;
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, msgColumns, selection, "");
@ -442,7 +437,8 @@ RsNxsGrp* RsDataService::retrieveGrpVersion(const RsGxsGrpId &grpId){
for(; sit != grps.end(); 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;
}
grp = NULL;
@ -463,7 +459,7 @@ RsNxsGrp* RsDataService::retrieveGrpVersion(const RsGxsGrpId &grpId){
RsNxsMsg* RsDataService::retrieveMsgVersion(const RsGxsMsgId &msgId){
std::set<RsNxsMsg*> msgs;
retrieveMsgVersions(msgId.grpId, msgId.msgId, msgs);
retrieveMsgVersions(msgId.grpId, msgId.msgId, msgs, false);
RsNxsMsg* msg = NULL;
if(!msgs.empty()){
@ -473,7 +469,8 @@ RsNxsMsg* RsDataService::retrieveMsgVersion(const RsGxsMsgId &msgId){
for(; sit != msgs.end(); 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;
msg = NULL;

View File

@ -19,7 +19,7 @@ public:
* @param cache whether to store retrieval in memory for faster later retrieval
* @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
@ -28,7 +28,7 @@ public:
* @param cache whether to store retrieval in mem for faster later retrieval
* @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
@ -44,7 +44,7 @@ public:
* @param msgId the id of the message to get versions for
* @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

View File

@ -83,21 +83,21 @@ public:
* @param cache whether to store retrieval in mem for faster later retrieval
* @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 cache whether to store the result in memory
* @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 cache whether to store the result in memory
* @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

View File

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

View File

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

View File

@ -1,7 +1,7 @@
#include "rsnxsitems.h"
#include "rsbaseserial.h"
#define RSSERIAL_DEBUG
const uint8_t RsSyncGrpList::FLAG_REQUEST = 0x001;
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 &= SetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
SyncList::iterator mit =
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);
}
}
ok &= SetTlvString(data, *size, &offset, TLV_TYPE_STR_MSGID, item->msgId);
ok &= item->idSign.SetTlv(data, *size, &offset);
if(offset != tlvsize){
#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->adminSign.SetTlv(data, tlvsize, &offset);
ok &= item->keys.SetTlv(data, tlvsize, &offset);
ok &= item->grp.SetTlv(data, tlvsize, &offset);
if(offset != tlvsize){
#ifdef RSSERIAL_DEBUG
@ -388,29 +370,9 @@ bool RsNxsSerialiser::serialiseSyncGrpList(RsSyncGrpList *item, void *data, uint
/* RsSyncGrpList */
SyncList::iterator mit =
item->grps.begin();
ok &= setRawUInt8(data, *size, &offset, item->flag);
for(; mit != item->grps.end(); mit++){
// 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);
}
}
ok &= SetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
ok &= item->adminSign.SetTlv(data, *size, &offset);
if(offset != tlvsize){
#ifdef RSSERIAL_DEBUG
@ -493,7 +455,7 @@ bool RsNxsSerialiser::serialiseNxsExtended(RsNxsExtended *item, void *data, uint
RsNxsGrp* RsNxsSerialiser::deserialNxsGrp(void *data, uint32_t *size){
#ifdef RSSERIAL_DEBUG
std::cerr << "RsNxsSerialiser::deserialGrpResp()" << std::endl;
std::cerr << "RsNxsSerialiser::deserialNxsGrp()" << std::endl;
#endif
/* get the type and size */
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->adminSign.GetTlv(data, *size, &offset);
ok &= item->keys.GetTlv(data, *size, &offset);
ok &= item->grp.GetTlv(data, *size, &offset);
if (offset != rssize)
{
@ -738,24 +701,8 @@ RsSyncGrpList* RsNxsSerialiser::deserialSyncGrpList(void *data, uint32_t *size){
offset += 8;
ok &= getRawUInt8(data, *size, &offset, &(item->flag));
while((offset < rssize) && ok)
{
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++;
}
}
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
ok &= item->adminSign.GetTlv(data, *size, &offset);
if (offset != rssize)
{
@ -821,27 +768,8 @@ RsSyncGrpMsgList* RsNxsSerialiser::deserialSyncGrpMsgList(void *data, uint32_t *
ok &= getRawUInt8(data, *size, &offset, &(item->flag));
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
// now get number of msgs
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++;
}
}
ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_MSGID, item->msgId);
ok &= item->idSign.GetTlv(data, *size, &offset);
if (offset != rssize)
{
@ -1002,23 +930,9 @@ uint32_t RsNxsSerialiser::sizeSyncGrpList(RsSyncGrpList *item)
s += 1; // flag
std::map<std::string, std::list<RsTlvKeySignature> >::iterator mit
= item->grps.begin();
s += GetTlvStringSize(item->grpId);
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;
}
@ -1043,23 +957,9 @@ uint32_t RsNxsSerialiser::sizeSyncGrpMsgList(RsSyncGrpMsgList *item)
s += 1; // flag
s += GetTlvStringSize(item->grpId);
std::map<std::string, std::list<RsTlvKeySignature> >::iterator mit
= item->msgs.begin();
s += GetTlvStringSize(item->msgId);
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;
}
@ -1067,6 +967,11 @@ uint32_t RsNxsSerialiser::sizeNxsSearchReq(RsNxsSearchReq *item){
return 0;
}
uint32_t RsNxsSerialiser::sizeNxsExtended(RsNxsExtended *item){
return 0;
}
/** print and clear functions **/
@ -1112,13 +1017,16 @@ void RsSyncGrpMsg::clear()
void RsSyncGrpList::clear()
{
flag = 0;
grps.clear();
adminSign.TlvClear();
grpId.clear();
}
void RsSyncGrpMsgList::clear()
{
flag = 0;
msgs.clear();
msgId.clear();
idSign.TlvClear();
grpId.clear();
}
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);
out << "flag: " << flag << std::endl;
printIndent(out , int_Indent);
SyncList::iterator mit
= grps.begin();
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);
}
}
out << "grpId: " << grpId << std::endl;
printIndent(out , int_Indent);
adminSign.print(out, indent);
printIndent(out , int_Indent);
printRsItemEnd(out , "RsSyncGrpList", indent);
return out;
@ -1214,24 +1108,11 @@ std::ostream& RsSyncGrpMsgList::print(std::ostream &out, uint16_t indent)
out << "flag: " << flag << std::endl;
printIndent(out , int_Indent);
out << "grpId: " << grpId << std::endl;
SyncList::iterator mit
= msgs.begin();
for(; mit != msgs.end(); mit++){
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);
}
}
printIndent(out , int_Indent);
out << "msgId: " << msgId << std::endl;
printIndent(out , int_Indent);
idSign.print(out, indent);
printIndent(out , int_Indent);
printRsItemEnd(out ,"RsSyncGrpMsgList", indent);
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
* held by server peer
@ -112,6 +110,7 @@ public:
static const uint8_t FLAG_USE_SYNC_HASH;
RsSyncGrpList(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_SYNC_GRP_LIST) { return ; }
virtual ~RsSyncGrpList() { return; }
virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent);
@ -120,7 +119,8 @@ public:
uint8_t flag; // request or response
/// 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
std::string grpId;
SyncList msgs; // msg/versions pairs
std::string msgId;
RsTlvKeySignature idSign;
};

View File

@ -81,6 +81,11 @@ RsTlvBinaryData::~RsTlvBinaryData()
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
bool RsTlvBinaryData::setBinData(const void *data, uint32_t size)

View File

@ -65,6 +65,7 @@ class RsTlvBinaryData: public RsTlvItem
{
public:
RsTlvBinaryData(uint16_t t);
void operator=(const RsTlvBinaryData& b);
virtual ~RsTlvBinaryData();
virtual uint32_t TlvSize();
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_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++){
RsTlvBinaryData* b = new RsTlvBinaryData(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
init_item(*b);
rgr.grps.push_back(b);
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;
}
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++){
RsTlvBinaryData* b = new RsTlvBinaryData(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
init_item(*b);
rgmr.msgs.push_back(b);
}
init_item(nxm.publishSign);
init_item(nxm.idSign);
init_item(nxm.msg);
nxm.msgFlag = rand()%4252;
nxm.timeStamp = rand()%246;
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
}
@ -65,20 +78,10 @@ RsSerialType* init_item(RsSyncGrpList& rsgl)
rsgl.clear();
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);
}
@ -88,50 +91,47 @@ RsSerialType* init_item(RsSyncGrpMsgList& rsgml)
rsgml.flag = RsSyncGrpList::FLAG_RESPONSE;
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);
}
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
= l.grps.begin(), rit =
r.grps.begin();
std::map<std::string, RsTlvSecurityKey>::const_iterator mit =
l.keys.keys.begin(), mit_end = l.keys.keys.end();
for(; lit != l.grps.end(); lit++, rit++){
if(!(*(*lit) == *(*rit))) return false;
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;
}
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;
std::list<RsTlvBinaryData*>::const_iterator lit
= l.msgs.begin(), rit =
r.msgs.begin();
for(; lit != l.msgs.end(); lit++, rit++){
if(!(*(*lit) == *(*rit))) return false;
}
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;
return true;
}
@ -160,23 +160,9 @@ bool operator==(const RsSyncGrpMsg& l, const RsSyncGrpMsg& r)
bool operator==(const RsSyncGrpList& l, const RsSyncGrpList& r)
{
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;
}
@ -184,23 +170,8 @@ bool operator==(const RsSyncGrpMsgList& l, const RsSyncGrpMsgList& r)
{
if(l.flag != r.flag) return false;
if(l.grpId != r.grpId) return false;
SyncList::const_iterator lit = l.msgs.begin(), rit= r.msgs.begin();
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;
}
}
if(l.msgId != r.msgId) return false;
if(! (l.idSign == r.idSign) ) return false;
return true;
}
@ -209,8 +180,8 @@ int main()
{
std::cerr << "RsNxsItem Tests" << std::endl;
test_RsItem<RsGrpResp>(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<RsNxsGrp>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsGrpResp");
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<RsSyncGrpMsg>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsSyncGrpMsg");
test_RsItem<RsSyncGrpList>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsSyncGrpList");

View File

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