-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,7 +1058,6 @@ int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaDat
}else
{
std::map<RsGxsGroupId, RsGxsGrpMetaData *>::iterator mit = grp.begin();
for(; mit != grp.end(); mit++)
@ -1104,6 +1103,8 @@ int RsDataService::resetDataStore()
std::map<std::string, RsNxsGrp*>::iterator mit
= grps.begin();
{
RsStackMutex stack(mDbMutex);
// remove all grp msgs files from service dir
for(; mit != grps.end(); mit++){
@ -1113,12 +1114,10 @@ int RsDataService::resetDataStore()
remove(msgFile.c_str()); // and remove messages file
delete mit->second;
}
{
RsStackMutex stack(mDbMutex);
mDb->closeDb();
}
remove(mDbName.c_str()); // remove db file
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

@ -159,6 +159,7 @@ void GenExchangeTest::setUp()
void GenExchangeTest::breakDown()
{
mDataService->resetDataStore();
mTestService->join();
clearAllData();
}

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

@ -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");