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;
|
||||
|
||||
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();
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -46,6 +46,7 @@ public:
|
||||
|
||||
mGroupStatus = 0;
|
||||
mCircleType = 0;
|
||||
mAuthenFlags = 0;
|
||||
|
||||
mPublishTs = 0;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -159,8 +159,9 @@ void GenExchangeTest::setUp()
|
||||
|
||||
void GenExchangeTest::breakDown()
|
||||
{
|
||||
mTestService->join();
|
||||
clearAllData();
|
||||
mDataService->resetDataStore();
|
||||
mTestService->join();
|
||||
clearAllData();
|
||||
}
|
||||
|
||||
bool msgDataSort(const RsDummyMsg* m1, const RsDummyMsg* m2)
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
/*!
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,6 +26,7 @@ private:
|
||||
bool testSpecificGrpRetrieval();
|
||||
bool testGrpIdRetrieval();
|
||||
bool testGrpMetaRetrieval();
|
||||
bool testUpdateGroup();
|
||||
|
||||
|
||||
private:
|
||||
|
@ -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;
|
||||
|
@ -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");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user