mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
-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:
parent
d31a34bd95
commit
a6f62caef4
@ -663,7 +663,7 @@ int RsDataService::updateGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
|
|||||||
if(!validSize(grpPtr)) continue;
|
if(!validSize(grpPtr)) continue;
|
||||||
|
|
||||||
std::string grpFile = mServiceDir + "/" + grpPtr->grpId;
|
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
|
uint32_t offset = 0; // get file offset
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -1058,7 +1058,6 @@ int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaDat
|
|||||||
|
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
|
|
||||||
std::map<RsGxsGroupId, RsGxsGrpMetaData *>::iterator mit = grp.begin();
|
std::map<RsGxsGroupId, RsGxsGrpMetaData *>::iterator mit = grp.begin();
|
||||||
|
|
||||||
for(; mit != grp.end(); mit++)
|
for(; mit != grp.end(); mit++)
|
||||||
@ -1104,6 +1103,8 @@ int RsDataService::resetDataStore()
|
|||||||
std::map<std::string, RsNxsGrp*>::iterator mit
|
std::map<std::string, RsNxsGrp*>::iterator mit
|
||||||
= grps.begin();
|
= grps.begin();
|
||||||
|
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mDbMutex);
|
||||||
|
|
||||||
// remove all grp msgs files from service dir
|
// remove all grp msgs files from service dir
|
||||||
for(; mit != grps.end(); mit++){
|
for(; mit != grps.end(); mit++){
|
||||||
@ -1113,12 +1114,10 @@ int RsDataService::resetDataStore()
|
|||||||
remove(msgFile.c_str()); // and remove messages file
|
remove(msgFile.c_str()); // and remove messages file
|
||||||
delete mit->second;
|
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
|
// recreate database
|
||||||
initialise();
|
initialise();
|
||||||
|
@ -1881,7 +1881,20 @@ void RsGenExchange::processGroupUpdatePublish()
|
|||||||
{
|
{
|
||||||
GroupUpdatePublish& gup = *vit;
|
GroupUpdatePublish& gup = *vit;
|
||||||
const RsGxsGroupId& groupId = gup.grpItem->meta.mGroupId;
|
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;
|
gup.grpItem->meta = *meta;
|
||||||
assignMetaUpdates(gup.grpItem->meta, gup.mUpdateMeta);
|
assignMetaUpdates(gup.grpItem->meta, gup.mUpdateMeta);
|
||||||
@ -1897,6 +1910,7 @@ void RsGenExchange::processGroupUpdatePublish()
|
|||||||
ggps.mStartTS = time(NULL);
|
ggps.mStartTS = time(NULL);
|
||||||
ggps.mLastAttemptTS = 0;
|
ggps.mLastAttemptTS = 0;
|
||||||
ggps.mIsUpdate = true;
|
ggps.mIsUpdate = true;
|
||||||
|
ggps.mToken = gup.mToken;
|
||||||
mGrpsToPublish.push_back(ggps);
|
mGrpsToPublish.push_back(ggps);
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
|
@ -46,6 +46,7 @@ public:
|
|||||||
|
|
||||||
mGroupStatus = 0;
|
mGroupStatus = 0;
|
||||||
mCircleType = 0;
|
mCircleType = 0;
|
||||||
|
mAuthenFlags = 0;
|
||||||
|
|
||||||
mPublishTs = 0;
|
mPublishTs = 0;
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,9 @@ linux-* {
|
|||||||
LIBS += ../../../lib/libretroshare.a
|
LIBS += ../../../lib/libretroshare.a
|
||||||
LIBS += ../../../../../libbitdht/src/lib/libbitdht.a
|
LIBS += ../../../../../libbitdht/src/lib/libbitdht.a
|
||||||
LIBS += ../../../../../openpgpsdk/src/lib/libops.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
|
LIBS *= -rdynamic -frtti
|
||||||
DEFINES *= HAVE_XSS # for idle time, libx screensaver extensions
|
DEFINES *= HAVE_XSS # for idle time, libx screensaver extensions
|
||||||
DEFINES *= UBUNTU
|
DEFINES *= UBUNTU
|
||||||
|
@ -159,6 +159,7 @@ void GenExchangeTest::setUp()
|
|||||||
|
|
||||||
void GenExchangeTest::breakDown()
|
void GenExchangeTest::breakDown()
|
||||||
{
|
{
|
||||||
|
mDataService->resetDataStore();
|
||||||
mTestService->join();
|
mTestService->join();
|
||||||
clearAllData();
|
clearAllData();
|
||||||
}
|
}
|
||||||
|
@ -258,7 +258,7 @@ private:
|
|||||||
std::list<RsGroupMetaData> mGrpMetaDataOut, mGrpMetaDataIn;
|
std::list<RsGroupMetaData> mGrpMetaDataOut, mGrpMetaDataIn;
|
||||||
std::list<RsGxsGroupId> mGrpIdsOut, mGrpIdsIn;
|
std::list<RsGxsGroupId> mGrpIdsOut, mGrpIdsIn;
|
||||||
|
|
||||||
DummyMsgMap mMsgDataOut, mMsgDataIn;
|
std::map<RsGxsGroupId, std::vector<RsDummyMsg*> > mMsgDataOut, mMsgDataIn;
|
||||||
GxsMsgMetaMap mMsgMetaDataOut, mMsgMetaDataIn;
|
GxsMsgMetaMap mMsgMetaDataOut, mMsgMetaDataIn;
|
||||||
GxsMsgIdResult mMsgIdsOut, mMsgIdsIn;
|
GxsMsgIdResult mMsgIdsOut, mMsgIdsIn;
|
||||||
|
|
||||||
|
@ -17,6 +17,11 @@ void GenExchangeTestService::publishDummyGrp(uint32_t &token, RsDummyGrp *grp)
|
|||||||
publishGroup(token, 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)
|
void GenExchangeTestService::publishDummyMsg(uint32_t &token, RsDummyMsg *msg)
|
||||||
{
|
{
|
||||||
publishMsg(token, msg);
|
publishMsg(token, msg);
|
||||||
|
@ -15,6 +15,7 @@ public:
|
|||||||
void notifyChanges(std::vector<RsGxsNotify*>& changes);
|
void notifyChanges(std::vector<RsGxsNotify*>& changes);
|
||||||
|
|
||||||
void publishDummyGrp(uint32_t& token, RsDummyGrp* grp);
|
void publishDummyGrp(uint32_t& token, RsDummyGrp* grp);
|
||||||
|
void updateDummyGrp(uint32_t &token, RsGxsGroupUpdateMeta& meta, RsDummyGrp *group);
|
||||||
void publishDummyMsg(uint32_t& token, RsDummyMsg* msg);
|
void publishDummyMsg(uint32_t& token, RsDummyMsg* msg);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include "gxspublishgrouptest.h"
|
#include "gxspublishgrouptest.h"
|
||||||
#include "util/utest.h"
|
#include "util/utest.h"
|
||||||
|
#include "support.h"
|
||||||
|
|
||||||
#define POLLING_TIME_OUT 5
|
#define POLLING_TIME_OUT 5
|
||||||
|
|
||||||
@ -169,6 +170,65 @@ bool GxsPublishGroupTest::testGrpIdRetrieval()
|
|||||||
|
|
||||||
return ok;
|
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()
|
bool GxsPublishGroupTest::testGrpMetaRetrieval()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -229,10 +289,11 @@ bool GxsPublishGroupTest::testGrpMetaRetrieval()
|
|||||||
}
|
}
|
||||||
void GxsPublishGroupTest::runTests()
|
void GxsPublishGroupTest::runTests()
|
||||||
{
|
{
|
||||||
CHECK(testGrpSubmissionRetrieval());
|
// CHECK(testGrpSubmissionRetrieval());
|
||||||
CHECK(testGrpIdRetrieval());
|
// CHECK(testGrpIdRetrieval());
|
||||||
CHECK(testGrpMetaRetrieval());
|
// CHECK(testGrpMetaRetrieval());
|
||||||
CHECK(testSpecificGrpRetrieval());
|
// CHECK(testSpecificGrpRetrieval());
|
||||||
|
CHECK(testUpdateGroup());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ private:
|
|||||||
bool testSpecificGrpRetrieval();
|
bool testSpecificGrpRetrieval();
|
||||||
bool testGrpIdRetrieval();
|
bool testGrpIdRetrieval();
|
||||||
bool testGrpMetaRetrieval();
|
bool testGrpMetaRetrieval();
|
||||||
|
bool testUpdateGroup();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -30,16 +30,16 @@ INITTEST();
|
|||||||
int main()
|
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 :)
|
// we want to use default authentication which is NO authentication :)
|
||||||
GenExchangeTestService testService(dataStore, NULL, NULL);
|
GenExchangeTestService testService(dataStore, NULL, NULL);
|
||||||
|
|
||||||
//GxsPublishGroupTest testGrpPublishing(&testService, dataStore);
|
GxsPublishGroupTest testGrpPublishing(&testService, dataStore);
|
||||||
//testGrpPublishing.runTests();
|
testGrpPublishing.runTests();
|
||||||
|
|
||||||
GxsPublishMsgTest testMsgPublishing(&testService, dataStore);
|
//GxsPublishMsgTest testMsgPublishing(&testService, dataStore);
|
||||||
testMsgPublishing.runTests();
|
//testMsgPublishing.runTests();
|
||||||
|
|
||||||
FINALREPORT("RsGenExchangeTest");
|
FINALREPORT("RsGenExchangeTest");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user