-fixed an update issue with actual group item

- simply didn't open grp file in "out" mode on update
-made update a bit more sturdy is group not found on update
  - prevent client can crash librs
  
- updated unit tests for grps and messages
- removed data base removal on db reset as cannot rekey db unfortunately (as passphrase (ssl) cannot be kept in the clear in mem)

 

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs_finale@6873 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2013-10-22 19:56:01 +00:00
parent d31a34bd95
commit a6f62caef4
12 changed files with 174 additions and 89 deletions

View File

@ -663,7 +663,7 @@ int RsDataService::updateGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
if(!validSize(grpPtr)) continue;
std::string grpFile = mServiceDir + "/" + grpPtr->grpId;
std::fstream ostrm(grpFile.c_str(), std::ios::binary | std::ios::trunc);
std::ofstream ostrm(grpFile.c_str(), std::ios::binary | std::ios::trunc);
uint32_t offset = 0; // get file offset
/*!
@ -1058,34 +1058,33 @@ int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaDat
}else
{
std::map<RsGxsGroupId, RsGxsGrpMetaData *>::iterator mit = grp.begin();
for(; mit != grp.end(); mit++)
{
const RsGxsGroupId& grpId = mit->first;
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpMetaColumns, "grpId='" + grpId + "'", "");
for(; mit != grp.end(); mit++)
{
const RsGxsGroupId& grpId = mit->first;
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpMetaColumns, "grpId='" + grpId + "'", "");
if(c)
{
bool valid = c->moveToFirst();
if(c)
{
bool valid = c->moveToFirst();
while(valid)
{
RsGxsGrpMetaData* g = locked_getGrpMeta(*c);
while(valid)
{
RsGxsGrpMetaData* g = locked_getGrpMeta(*c);
if(g)
{
grp[g->mGroupId] = g;
}
valid = c->moveToNext();
}
delete c;
}
if(g)
{
grp[g->mGroupId] = g;
}
valid = c->moveToNext();
}
delete c;
}
}
}
}
}
return 1;
@ -1104,21 +1103,21 @@ int RsDataService::resetDataStore()
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";
remove(file.c_str()); // remove group file
remove(msgFile.c_str()); // and remove messages file
delete mit->second;
}
{
RsStackMutex stack(mDbMutex);
mDb->closeDb();
}
remove(mDbName.c_str()); // remove db file
// remove all grp msgs files from service dir
for(; mit != grps.end(); mit++){
std::string file = mServiceDir + "/" + mit->first;
std::string msgFile = file + "-msgs";
remove(file.c_str()); // remove group file
remove(msgFile.c_str()); // and remove messages file
delete mit->second;
}
mDb->execSQL("DROP TABLE " + MSG_TABLE_NAME);
mDb->execSQL("DROP TABLE " + GRP_TABLE_NAME);
}
// recreate database
initialise();

View File

@ -1881,7 +1881,20 @@ void RsGenExchange::processGroupUpdatePublish()
{
GroupUpdatePublish& gup = *vit;
const RsGxsGroupId& groupId = gup.grpItem->meta.mGroupId;
RsGxsGrpMetaData* meta = grpMeta[groupId];
std::map<std::string, RsGxsGrpMetaData*>::iterator mit = grpMeta.find(groupId);
RsGxsGrpMetaData* meta = NULL;
if(mit == grpMeta.end())
{
std::cerr << "Error! could not find meta of old group to update!" << std::endl;
mDataAccess->updatePublicRequestStatus(gup.mToken, RsTokenService::GXS_REQUEST_V2_STATUS_FAILED);
delete gup.grpItem;
continue;
}else
{
meta = mit->second;
}
gup.grpItem->meta = *meta;
assignMetaUpdates(gup.grpItem->meta, gup.mUpdateMeta);
@ -1897,6 +1910,7 @@ void RsGenExchange::processGroupUpdatePublish()
ggps.mStartTS = time(NULL);
ggps.mLastAttemptTS = 0;
ggps.mIsUpdate = true;
ggps.mToken = gup.mToken;
mGrpsToPublish.push_back(ggps);
}else
{

View File

@ -46,6 +46,7 @@ public:
mGroupStatus = 0;
mCircleType = 0;
mAuthenFlags = 0;
mPublishTs = 0;
}

View File

@ -56,7 +56,9 @@ linux-* {
LIBS += ../../../lib/libretroshare.a
LIBS += ../../../../../libbitdht/src/lib/libbitdht.a
LIBS += ../../../../../openpgpsdk/src/lib/libops.a
LIBS += -lssl -lgpgme -lupnp -lixml -lgnome-keyring -lsqlite3 -lbz2
LIBS += -lssl -lgpgme -lupnp -lixml -lgnome-keyring -lbz2
# We need a explicit path here, to force using the home version of sqlite3 that really encrypts the database.
LIBS += /home/crispy/Development/retroshare/sqlcipher/sqlcipher/.libs/libsqlite3.a
LIBS *= -rdynamic -frtti
DEFINES *= HAVE_XSS # for idle time, libx screensaver extensions
DEFINES *= UBUNTU

View File

@ -108,7 +108,7 @@ bool GenExchangeTest::pollForMsgAcknowledgement(uint32_t token,
now = time(NULL);
}
return false;
}
}
GenExchangeTestService* GenExchangeTest::getTestService()
{
@ -155,12 +155,13 @@ void GenExchangeTest::setUp()
// would be useful for genexchange services
// to have a protected reset button
mTestService->start();
}
}
void GenExchangeTest::breakDown()
{
mTestService->join();
clearAllData();
mDataService->resetDataStore();
mTestService->join();
clearAllData();
}
bool msgDataSort(const RsDummyMsg* m1, const RsDummyMsg* m2)
@ -189,7 +190,7 @@ bool GenExchangeTest::compareMsgDataMaps()
}
return ok;
}
}
bool GenExchangeTest::compareMsgIdMaps()
@ -205,7 +206,7 @@ bool GenExchangeTest::compareMsgIdMaps()
ok &= Comparison<std::vector<RsGxsMessageId>, RsGxsMessageId>::comparison(v1, v2);
}
return ok;
}
}
bool GenExchangeTest::compareMsgMetaMaps()
@ -220,19 +221,19 @@ bool GenExchangeTest::compareMsgMetaMaps()
ok &= Comparison<std::vector<RsMsgMetaData>, RsMsgMetaData>::comparison(v1, v2);
}
return ok;
}
}
bool GenExchangeTest::compareMsgRelateIdsMap()
{
return false;
}
}
bool GenExchangeTest::compareMsgRelatedDataMap()
{
return false;
}
}
bool grpDataSort(const RsDummyGrp* g1, const RsDummyGrp* g2)
{
@ -247,7 +248,7 @@ bool GenExchangeTest::compareGrpData()
bool ok = Comparison<std::vector<RsDummyGrp*>, RsDummyGrp*>::comparison
(mGrpDataIn, mGrpDataOut);
return ok;
}
}
bool operator<(const RsGroupMetaData& l, const RsGroupMetaData& r)
{
@ -263,7 +264,7 @@ bool GenExchangeTest::compareGrpMeta()
bool ok = Comparison<std::list<RsGroupMetaData>, RsGroupMetaData>::comparison
(mGrpMetaDataIn, mGrpMetaDataOut);
return ok;
}
}
bool GenExchangeTest::compareGrpIds()
@ -289,7 +290,7 @@ void GenExchangeTest::createGrps(uint32_t nGrps,
pollForGrpAcknowledgement(token, grpId);
groupId.push_back(grpId);
}
}
}
void GenExchangeTest::init(RsMsgMetaData& msgMetaData) const
{
@ -334,7 +335,7 @@ void GenExchangeTest::init(RsDummyGrp& grpItem) const
{
randString(SHORT_STR, grpItem.grpData);
init(grpItem.meta);
}
}
void GenExchangeTest::init(RsDummyMsg& msgItem) const
@ -346,72 +347,72 @@ void GenExchangeTest::init(RsDummyMsg& msgItem) const
void GenExchangeTest::storeToMsgDataOutMaps(const DummyMsgMap& msgDataOut)
{
mMsgDataOut.insert(msgDataOut.begin(), msgDataOut.end());
}
}
void GenExchangeTest::storeToMsgIdsOutMaps(const GxsMsgIdResult& msgIdsOut)
{
mMsgIdsOut.insert(msgIdsOut.begin(), msgIdsOut.end());
}
}
void GenExchangeTest::storeToMsgMetaOutMaps(const GxsMsgMetaMap& msgMetaOut)
{
mMsgMetaDataOut.insert(msgMetaOut.begin(), msgMetaOut.end());
}
}
void GenExchangeTest::storeToMsgDataInMaps(const DummyMsgMap& msgDataIn)
{
mMsgDataIn.insert(msgDataIn.begin(), msgDataIn.end());
}
}
void GenExchangeTest::storeToMsgIdsInMaps(const GxsMsgIdResult& msgIdsIn)
{
mMsgIdsIn.insert(msgIdsIn.begin(), msgIdsIn.end());
}
}
void GenExchangeTest::storeToMsgMetaInMaps(const GxsMsgMetaMap& msgMetaIn)
{
mMsgMetaDataIn.insert(msgMetaIn.begin(), msgMetaIn.end());
}
}
void GenExchangeTest::storeToGrpIdsOutList(
const std::list<RsGxsGroupId>& grpIdOut)
{
mGrpIdsOut.insert(mGrpIdsOut.end(), grpIdOut.begin(), grpIdOut.end());
}
}
void GenExchangeTest::storeToGrpMetaOutList(
const std::list<RsGroupMetaData>& grpMetaOut)
{
mGrpMetaDataOut.insert(mGrpMetaDataOut.end(), grpMetaOut.begin(), grpMetaOut.end());
}
}
void GenExchangeTest::storeToGrpDataOutList(
const std::vector<RsDummyGrp*>& grpDataOut)
{
mGrpDataOut.insert(mGrpDataOut.end(), grpDataOut.begin(), grpDataOut.end());
}
}
void GenExchangeTest::storeToGrpIdsInList(
const std::list<RsGxsGroupId>& grpIdIn)
{
mGrpIdsIn.insert(mGrpIdsIn.end(), grpIdIn.begin(), grpIdIn.end());
}
}
void GenExchangeTest::storeToGrpMetaInList(
const std::list<RsGroupMetaData>& grpMetaIn)
{
mGrpMetaDataIn.insert(mGrpMetaDataIn.end(), grpMetaIn.begin(), grpMetaIn.end());
}
}
void GenExchangeTest::storeToGrpDataInList(
@ -437,14 +438,14 @@ void GenExchangeTest::clearAllData()
void GenExchangeTest::clearMsgDataInMap()
{
mMsgDataIn.clear();
}
}
void GenExchangeTest::clearMsgDataOutMap()
{
clearMsgDataMap(mMsgDataOut);
}
}
void GenExchangeTest::clearMsgDataMap(DummyMsgMap& msgDataMap) const
{
@ -459,31 +460,31 @@ void GenExchangeTest::clearMsgDataMap(DummyMsgMap& msgDataMap) const
void GenExchangeTest::clearMsgMetaInMap()
{
mMsgMetaDataIn.clear();
}
}
void GenExchangeTest::clearMsgMetaOutMap()
{
mMsgMetaDataOut.clear();
}
}
void GenExchangeTest::clearMsgIdInMap()
{
mMsgIdsIn.clear();
}
}
void GenExchangeTest::clearMsgIdOutMap()
{
mMsgIdsOut.clear();
}
}
void GenExchangeTest::clearMsgRelatedIdInMap()
{
mMsgRelatedIdsIn.clear();
}
}
void GenExchangeTest::clearGrpDataInList()
@ -494,38 +495,38 @@ void GenExchangeTest::clearGrpDataInList()
void GenExchangeTest::clearGrpDataList(std::vector<RsDummyGrp*>& grpData) const
{
deleteResVector<RsDummyGrp>(grpData);
}
}
void GenExchangeTest::clearGrpDataOutList()
{
clearGrpDataList(mGrpDataOut);
}
}
void GenExchangeTest::clearGrpMetaInList()
{
mGrpMetaDataIn.clear();
}
}
void GenExchangeTest::clearGrpMetaOutList()
{
mGrpMetaDataOut.clear();
}
}
void GenExchangeTest::clearGrpIdInList()
{
mGrpIdsIn.clear();
}
}
void GenExchangeTest::clearGrpIdOutList()
{
mGrpIdsOut.clear();
}
}
bool operator ==(const RsMsgMetaData& lMeta, const RsMsgMetaData& rMeta)
{
@ -584,5 +585,5 @@ bool operator ==(const RsDummyMsg& lMsg, const RsDummyMsg& rMsg)
bool operator ==(const RsGxsGrpItem& lGrp, const RsGxsGrpItem& rGrp)
{
return false;
}
}

View File

@ -258,7 +258,7 @@ private:
std::list<RsGroupMetaData> mGrpMetaDataOut, mGrpMetaDataIn;
std::list<RsGxsGroupId> mGrpIdsOut, mGrpIdsIn;
DummyMsgMap mMsgDataOut, mMsgDataIn;
std::map<RsGxsGroupId, std::vector<RsDummyMsg*> > mMsgDataOut, mMsgDataIn;
GxsMsgMetaMap mMsgMetaDataOut, mMsgMetaDataIn;
GxsMsgIdResult mMsgIdsOut, mMsgIdsIn;

View File

@ -17,6 +17,11 @@ void GenExchangeTestService::publishDummyGrp(uint32_t &token, RsDummyGrp *grp)
publishGroup(token, grp);
}
void GenExchangeTestService::updateDummyGrp(uint32_t &token, RsGxsGroupUpdateMeta &updateMeta, RsDummyGrp *group)
{
updateGroup(token, updateMeta, group);
}
void GenExchangeTestService::publishDummyMsg(uint32_t &token, RsDummyMsg *msg)
{
publishMsg(token, msg);

View File

@ -15,6 +15,7 @@ public:
void notifyChanges(std::vector<RsGxsNotify*>& changes);
void publishDummyGrp(uint32_t& token, RsDummyGrp* grp);
void updateDummyGrp(uint32_t &token, RsGxsGroupUpdateMeta& meta, RsDummyGrp *group);
void publishDummyMsg(uint32_t& token, RsDummyMsg* msg);
/*!

View File

@ -7,6 +7,7 @@
#include "gxspublishgrouptest.h"
#include "util/utest.h"
#include "support.h"
#define POLLING_TIME_OUT 5
@ -169,6 +170,65 @@ bool GxsPublishGroupTest::testGrpIdRetrieval()
return ok;
}
bool GxsPublishGroupTest::testUpdateGroup()
{
setUp();
GenExchangeTestService* testService = getTestService();
RsTokenService* tokenService = getTokenService();
// create some random grps to allow msg testing
RsDummyGrp* dgrp1 = new RsDummyGrp();
RsDummyGrp* dgrp2 = new RsDummyGrp();
RsDummyGrp* dgrp2_copy = new RsDummyGrp();
init(*dgrp1);
init(*dgrp2);
RsTokReqOptions opts;
opts.mReqType = 45000;
uint32_t token;
RsGxsGroupId grpId;
std::vector<RsDummyGrp*> groupsPublished;
std::list<RsGxsGroupId> grpIds;
std::string name = dgrp1->meta.mGroupName;
*dgrp2 = *dgrp1;
testService->publishDummyGrp(token, dgrp1);
bool ok = pollForGrpAcknowledgement(token, grpId);
grpIds.push_back(grpId);
RsGxsGroupUpdateMeta updateMeta(grpId);
updateMeta.setMetaUpdate(RsGxsGroupUpdateMeta::NAME, name);
randString(SHORT_STR, dgrp2->grpData);
dgrp2->meta.mGroupId = grpId;
*dgrp2_copy = *dgrp2;
dgrp2->grpData ="ojfosfjsofjsof";
testService->updateDummyGrp(token, updateMeta, dgrp2);
ok &= pollForGrpAcknowledgement(token, grpId);
groupsPublished.push_back(dgrp2_copy);
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
tokenService->requestGroupInfo(token, 0, opts, grpIds);
pollForToken(token, opts, true);
ok &= compareGrpData();
breakDown();
return ok;
}
bool GxsPublishGroupTest::testGrpMetaRetrieval()
{
@ -229,10 +289,11 @@ bool GxsPublishGroupTest::testGrpMetaRetrieval()
}
void GxsPublishGroupTest::runTests()
{
CHECK(testGrpSubmissionRetrieval());
CHECK(testGrpIdRetrieval());
CHECK(testGrpMetaRetrieval());
CHECK(testSpecificGrpRetrieval());
// CHECK(testGrpSubmissionRetrieval());
// CHECK(testGrpIdRetrieval());
// CHECK(testGrpMetaRetrieval());
// CHECK(testSpecificGrpRetrieval());
CHECK(testUpdateGroup());
}

View File

@ -26,6 +26,7 @@ private:
bool testSpecificGrpRetrieval();
bool testGrpIdRetrieval();
bool testGrpMetaRetrieval();
bool testUpdateGroup();
private:

View File

@ -49,10 +49,10 @@ bool GxsPublishMsgTest::testMsgSubmissionRetrieval()
msgOut->meta.mMsgId = msgId.second;
DummyMsgMap msgMap;
std::vector<RsDummyMsg*> msgV;
msgV.push_back(msgOut);
msgMap[msgOut->meta.mGroupId] = msgV;
storeToMsgDataOutMaps(msgMap);
std::vector<RsDummyMsg*> msgV;
msgV.push_back(msgOut);
msgMap[msgOut->meta.mGroupId] = msgV;
storeToMsgDataOutMaps(msgMap);
RsTokReqOptions opts;

View File

@ -30,16 +30,16 @@ INITTEST();
int main()
{
RsGeneralDataService* dataStore = new RsDataService("./", "testServiceDb", RS_SERVICE_TYPE_DUMMY, NULL);
RsGeneralDataService* dataStore = new RsDataService("./", "testServiceDb", RS_SERVICE_TYPE_DUMMY, NULL, "");
// we want to use default authentication which is NO authentication :)
GenExchangeTestService testService(dataStore, NULL, NULL);
//GxsPublishGroupTest testGrpPublishing(&testService, dataStore);
//testGrpPublishing.runTests();
GxsPublishGroupTest testGrpPublishing(&testService, dataStore);
testGrpPublishing.runTests();
GxsPublishMsgTest testMsgPublishing(&testService, dataStore);
testMsgPublishing.runTests();
//GxsPublishMsgTest testMsgPublishing(&testService, dataStore);
//testMsgPublishing.runTests();
FINALREPORT("RsGenExchangeTest");