mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-12-20 10:55:28 -05:00
added more extensive test for rsdataservice and subsequent bug fixes.
added test for RsNxsTransac item. applied rule of three to RsTlvBinaryData (destructor, assign op, copy constructor implemented) git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-new_cache_system@5196 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
36103b29a1
commit
822e395f93
17 changed files with 1107 additions and 73 deletions
|
|
@ -46,27 +46,13 @@
|
|||
#define COL_IDENTITY 8
|
||||
|
||||
|
||||
#define RS_DATA_SERVICE_DEBUG
|
||||
|
||||
RsDataService::RsDataService(const std::string &serviceDir, const std::string &dbName, uint16_t serviceType,
|
||||
RsGxsSearchModule *mod)
|
||||
: mServiceDir(serviceDir), mDbName(dbName), mServType(serviceType){
|
||||
: mServiceDir(serviceDir), mDbName(mServiceDir + "/" + dbName), mServType(serviceType){
|
||||
|
||||
|
||||
// initialise database
|
||||
mDb = new RetroDb(dbName, RetroDb::OPEN_READWRITE_CREATE);
|
||||
|
||||
// create table for msgs
|
||||
mDb->execSQL("CREATE TABLE " + MSG_TABLE_NAME + "(" + KEY_MSG_ID
|
||||
+ " TEXT," + KEY_GRP_ID + " TEXT," + KEY_NXS_FLAGS + " INT,"
|
||||
+ KEY_TIME_STAMP + " INT," + KEY_PUBLISH_SIGN + " BLOB," + KEY_NXS_IDENTITY + " TEXT,"
|
||||
+ KEY_IDENTITY_SIGN + " BLOB," + KEY_NXS_FILE + " TEXT,"+ KEY_NXS_FILE_OFFSET + " INT,"
|
||||
+ KEY_NXS_FILE_LEN+ " INT);");
|
||||
|
||||
// create table for grps
|
||||
mDb->execSQL("CREATE TABLE " + GRP_TABLE_NAME + "(" + KEY_GRP_ID +
|
||||
" TEXT," + KEY_TIME_STAMP + " INT," +
|
||||
KEY_ADMIN_SIGN + " BLOB," + " BLOB," + KEY_NXS_FILE +
|
||||
" TEXT," + KEY_NXS_FILE_OFFSET + " INT," + KEY_KEY_SET + " BLOB," + KEY_NXS_FILE_LEN + " INT,"
|
||||
+ KEY_NXS_IDENTITY + " TEXT," + KEY_NXS_FLAGS + " INT," + KEY_IDENTITY_SIGN + " BLOB);");
|
||||
initialise();
|
||||
|
||||
msgColumns.push_back(KEY_GRP_ID); msgColumns.push_back(KEY_PUBLISH_SIGN); msgColumns.push_back(KEY_NXS_FILE);
|
||||
msgColumns.push_back(KEY_NXS_FILE_OFFSET); msgColumns.push_back(KEY_NXS_FILE_LEN); msgColumns.push_back(KEY_TIME_STAMP);
|
||||
|
|
@ -84,6 +70,27 @@ RsDataService::~RsDataService(){
|
|||
delete mDb;
|
||||
}
|
||||
|
||||
void RsDataService::initialise(){
|
||||
|
||||
// initialise database
|
||||
mDb = new RetroDb(mDbName, RetroDb::OPEN_READWRITE_CREATE);
|
||||
|
||||
// create table for msgs
|
||||
mDb->execSQL("CREATE TABLE " + MSG_TABLE_NAME + "(" + KEY_MSG_ID
|
||||
+ " TEXT," + KEY_GRP_ID + " TEXT," + KEY_NXS_FLAGS + " INT,"
|
||||
+ KEY_TIME_STAMP + " INT," + KEY_PUBLISH_SIGN + " BLOB," + KEY_NXS_IDENTITY + " TEXT,"
|
||||
+ KEY_IDENTITY_SIGN + " BLOB," + KEY_NXS_FILE + " TEXT,"+ KEY_NXS_FILE_OFFSET + " INT,"
|
||||
+ KEY_NXS_FILE_LEN+ " INT);");
|
||||
|
||||
// create table for grps
|
||||
mDb->execSQL("CREATE TABLE " + GRP_TABLE_NAME + "(" + KEY_GRP_ID +
|
||||
" TEXT," + KEY_TIME_STAMP + " INT," +
|
||||
KEY_ADMIN_SIGN + " BLOB," + " BLOB," + KEY_NXS_FILE +
|
||||
" TEXT," + KEY_NXS_FILE_OFFSET + " INT," + KEY_KEY_SET + " BLOB," + KEY_NXS_FILE_LEN + " INT,"
|
||||
+ KEY_NXS_IDENTITY + " TEXT," + KEY_NXS_FLAGS + " INT," + KEY_IDENTITY_SIGN + " BLOB);");
|
||||
|
||||
}
|
||||
|
||||
RsNxsGrp* RsDataService::getGroup(RetroCursor &c){
|
||||
|
||||
/*!
|
||||
|
|
@ -409,7 +416,7 @@ int RsDataService::retrieveMsgVersions(const std::string &grpId, const std::stri
|
|||
std::set<RsNxsMsg *>& msg, bool cache){
|
||||
|
||||
|
||||
std::string selection = KEY_GRP_ID + "=" + grpId + "," + KEY_MSG_ID + "=" + msgId;
|
||||
std::string selection = KEY_GRP_ID + "='" + grpId + "' and " + KEY_MSG_ID + "='" + msgId + "'";
|
||||
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgColumns, selection, "");
|
||||
|
||||
|
||||
|
|
@ -435,8 +442,8 @@ int RsDataService::retrieveMsgVersions(const std::string &grpId, const std::stri
|
|||
|
||||
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, "");
|
||||
std::string selection = KEY_GRP_ID + "='" + grpId + "'";
|
||||
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpColumns, selection, "");
|
||||
|
||||
if(c){
|
||||
|
||||
|
|
@ -502,7 +509,7 @@ RsNxsMsg* RsDataService::retrieveMsgVersion(const RsGxsMsgId &msgId){
|
|||
for(; sit != msgs.end(); sit++){
|
||||
|
||||
msg = *sit;
|
||||
if(!memcmp(msg->idSign.signData.bin_data, msgId.idSign.signData.bin_data,
|
||||
if(0 == memcmp(msg->idSign.signData.bin_data, msgId.idSign.signData.bin_data,
|
||||
msg->idSign.signData.bin_len))
|
||||
break;
|
||||
|
||||
|
|
@ -523,6 +530,28 @@ RsNxsMsg* RsDataService::retrieveMsgVersion(const RsGxsMsgId &msgId){
|
|||
|
||||
int RsDataService::resetDataStore(){
|
||||
|
||||
#ifdef RS_DATA_SERVICE_DEBUG
|
||||
std::cerr << "resetDataStore() " << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string, RsNxsGrp*> grps;
|
||||
retrieveGrps(grps, false);
|
||||
std::map<std::string, RsNxsGrp*>::iterator mit
|
||||
= grps.begin();
|
||||
|
||||
for(; mit != grps.end(); mit++){
|
||||
std::string file = mServiceDir + "/" + mit->first;
|
||||
std::string msgFile = file + "-msgs";
|
||||
remove(file.c_str());
|
||||
remove(msgFile.c_str());
|
||||
}
|
||||
|
||||
mDb->closeDb();
|
||||
remove(mDbName.c_str());
|
||||
|
||||
initialise();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int RsDataService::removeGroups(const std::list<RsGxsGrpId> &grpIds){
|
||||
|
|
|
|||
|
|
@ -117,6 +117,7 @@ public:
|
|||
* Completely clear out data stored in
|
||||
* this data store and returns this to a state
|
||||
* as it was when first constructed
|
||||
* This also clears any data store items created in service directory
|
||||
*/
|
||||
int resetDataStore();
|
||||
|
||||
|
|
@ -125,6 +126,7 @@ private:
|
|||
|
||||
RsNxsMsg* getMessage(RetroCursor& c);
|
||||
RsNxsGrp* getGroup(RetroCursor& c);
|
||||
void initialise();
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ class RsGeneralDataService
|
|||
|
||||
public:
|
||||
|
||||
virtual ~RsGeneralDataService(){return;};
|
||||
/*!
|
||||
* Retrieves signed message
|
||||
* @param grpId
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@
|
|||
* The interface is sparse as this service is mostly making the requests to other GXS components
|
||||
*
|
||||
* Groups:
|
||||
* - As this is where exchanges occur between peers, this is also where groups relationships
|
||||
* - As this is where exchanges occur between peers, this is also where group's relationships
|
||||
* should get resolved as far as
|
||||
* - Per implemented GXS there are a set of rules which will determine whether data is transferred
|
||||
* between any set of groups
|
||||
|
|
@ -62,12 +62,13 @@ public:
|
|||
|
||||
/*!
|
||||
* Use this to set how far back synchronisation of messages should take place
|
||||
* @param range how far back from current time to synchronise with other peers
|
||||
* @param age the max age a sync item can to be allowed in a synchronisation
|
||||
*/
|
||||
virtual void setTimeRange(uint64_t range) = 0;
|
||||
virtual void setSyncAge(uint32_t age) = 0;
|
||||
|
||||
/*!
|
||||
* requests all the groups contained by a peer
|
||||
* Explicitly requests all the groups contained by a peer
|
||||
* Circumvents polling of peers for message
|
||||
* @param peerId id of peer
|
||||
*/
|
||||
virtual void requestGroupsOfPeer(const std::string& peerId) = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue