mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
commit
286e7e0b1a
@ -272,6 +272,8 @@ bool GxsSecurity::generateKeyPair(RsTlvPublicRSAKey& public_key,RsTlvPrivateRSAK
|
|||||||
RSA_generate_key_ex(rsa, 2048, ebn, NULL);
|
RSA_generate_key_ex(rsa, 2048, ebn, NULL);
|
||||||
RSA *rsa_pub = RSAPublicKey_dup(rsa);
|
RSA *rsa_pub = RSAPublicKey_dup(rsa);
|
||||||
|
|
||||||
|
BN_clear_free(ebn) ;
|
||||||
|
|
||||||
public_key.keyFlags = RSTLV_KEY_TYPE_PUBLIC_ONLY ;
|
public_key.keyFlags = RSTLV_KEY_TYPE_PUBLIC_ONLY ;
|
||||||
private_key.keyFlags = RSTLV_KEY_TYPE_FULL ;
|
private_key.keyFlags = RSTLV_KEY_TYPE_FULL ;
|
||||||
|
|
||||||
@ -580,6 +582,8 @@ bool GxsSecurity::encrypt(uint8_t *& out, uint32_t &outlen, const uint8_t *in, u
|
|||||||
// intialize context and send store encrypted cipher in ek
|
// intialize context and send store encrypted cipher in ek
|
||||||
if(!EVP_SealInit(ctx, EVP_aes_128_cbc(), &ek, &eklen, iv, &public_key, 1)) return false;
|
if(!EVP_SealInit(ctx, EVP_aes_128_cbc(), &ek, &eklen, iv, &public_key, 1)) return false;
|
||||||
|
|
||||||
|
EVP_PKEY_free(public_key) ;
|
||||||
|
|
||||||
// now assign memory to out accounting for data, and cipher block size, key length, and key length val
|
// now assign memory to out accounting for data, and cipher block size, key length, and key length val
|
||||||
out = (uint8_t*)rs_malloc(inlen + cipher_block_size + size_net_ekl + eklen + EVP_MAX_IV_LENGTH) ;
|
out = (uint8_t*)rs_malloc(inlen + cipher_block_size + size_net_ekl + eklen + EVP_MAX_IV_LENGTH) ;
|
||||||
|
|
||||||
@ -857,6 +861,7 @@ bool GxsSecurity::decrypt(uint8_t *& out, uint32_t & outlen, const uint8_t *in,
|
|||||||
std::cerr << "(EE) Cannot decrypt data. Most likely reason: private GXS key is missing." << std::endl;
|
std::cerr << "(EE) Cannot decrypt data. Most likely reason: private GXS key is missing." << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
EVP_PKEY_free(privateKey) ;
|
||||||
|
|
||||||
if(inlen < (uint32_t)in_offset)
|
if(inlen < (uint32_t)in_offset)
|
||||||
{
|
{
|
||||||
|
@ -702,20 +702,20 @@ RsNxsMsg* RsDataService::locked_getMessage(RetroCursor &c)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int RsDataService::storeMessage(std::map<RsNxsMsg *, RsGxsMsgMetaData *> &msg)
|
int RsDataService::storeMessage(const std::list<RsNxsMsg*>& msg)
|
||||||
{
|
{
|
||||||
|
|
||||||
RsStackMutex stack(mDbMutex);
|
RsStackMutex stack(mDbMutex);
|
||||||
|
|
||||||
std::map<RsNxsMsg*, RsGxsMsgMetaData* >::iterator mit = msg.begin();
|
|
||||||
|
|
||||||
// start a transaction
|
// start a transaction
|
||||||
mDb->beginTransaction();
|
mDb->beginTransaction();
|
||||||
|
|
||||||
for(; mit != msg.end(); ++mit)
|
for(std::list<RsNxsMsg*>::const_iterator mit = msg.begin(); mit != msg.end(); ++mit)
|
||||||
{
|
{
|
||||||
RsNxsMsg* msgPtr = mit->first;
|
RsNxsMsg* msgPtr = *mit;
|
||||||
RsGxsMsgMetaData* msgMetaPtr = mit->second;
|
RsGxsMsgMetaData* msgMetaPtr = msgPtr->metaData;
|
||||||
|
|
||||||
|
assert(msgMetaPtr != NULL);
|
||||||
|
|
||||||
#ifdef RS_DATA_SERVICE_DEBUG
|
#ifdef RS_DATA_SERVICE_DEBUG
|
||||||
std::cerr << "RsDataService::storeMessage() ";
|
std::cerr << "RsDataService::storeMessage() ";
|
||||||
@ -790,16 +790,6 @@ int RsDataService::storeMessage(std::map<RsNxsMsg *, RsGxsMsgMetaData *> &msg)
|
|||||||
// finish transaction
|
// finish transaction
|
||||||
bool ret = mDb->commitTransaction();
|
bool ret = mDb->commitTransaction();
|
||||||
|
|
||||||
for(mit = msg.begin(); mit != msg.end(); ++mit)
|
|
||||||
{
|
|
||||||
//TODO: API encourages aliasing, remove this abomination
|
|
||||||
if(mit->second != mit->first->metaData)
|
|
||||||
delete mit->second;
|
|
||||||
|
|
||||||
delete mit->first;
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -811,104 +801,94 @@ bool RsDataService::validSize(RsNxsMsg* msg) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int RsDataService::storeGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
|
int RsDataService::storeGroup(const std::list<RsNxsGrp*>& grp)
|
||||||
{
|
{
|
||||||
|
|
||||||
RsStackMutex stack(mDbMutex);
|
RsStackMutex stack(mDbMutex);
|
||||||
|
|
||||||
std::map<RsNxsGrp*, RsGxsGrpMetaData* >::iterator sit = grp.begin();
|
|
||||||
|
|
||||||
// begin transaction
|
// begin transaction
|
||||||
mDb->beginTransaction();
|
mDb->beginTransaction();
|
||||||
|
|
||||||
for(; sit != grp.end(); ++sit)
|
for(std::list<RsNxsGrp*>::const_iterator sit = grp.begin();sit != grp.end(); ++sit)
|
||||||
{
|
{
|
||||||
|
RsNxsGrp* grpPtr = *sit;
|
||||||
|
RsGxsGrpMetaData* grpMetaPtr = grpPtr->metaData;
|
||||||
|
|
||||||
RsNxsGrp* grpPtr = sit->first;
|
assert(grpMetaPtr != NULL);
|
||||||
RsGxsGrpMetaData* grpMetaPtr = sit->second;
|
|
||||||
|
|
||||||
// if data is larger than max item size do not add
|
// if data is larger than max item size do not add
|
||||||
if(!validSize(grpPtr)) continue;
|
if(!validSize(grpPtr)) continue;
|
||||||
|
|
||||||
#ifdef RS_DATA_SERVICE_DEBUG
|
#ifdef RS_DATA_SERVICE_DEBUG
|
||||||
std::cerr << "RsDataService::storeGroup() GrpId: " << grpPtr->grpId.toStdString();
|
std::cerr << "RsDataService::storeGroup() GrpId: " << grpPtr->grpId.toStdString();
|
||||||
std::cerr << " CircleType: " << (uint32_t) grpMetaPtr->mCircleType;
|
std::cerr << " CircleType: " << (uint32_t) grpMetaPtr->mCircleType;
|
||||||
std::cerr << " CircleId: " << grpMetaPtr->mCircleId.toStdString();
|
std::cerr << " CircleId: " << grpMetaPtr->mCircleId.toStdString();
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* STORE data, data len,
|
* STORE data, data len,
|
||||||
* grpId, flags, publish time stamp, identity,
|
* grpId, flags, publish time stamp, identity,
|
||||||
* id signature, admin signatue, key set, last posting ts
|
* id signature, admin signatue, key set, last posting ts
|
||||||
* and meta data
|
* and meta data
|
||||||
**/
|
**/
|
||||||
ContentValue cv;
|
ContentValue cv;
|
||||||
|
|
||||||
uint32_t dataLen = grpPtr->grp.TlvSize();
|
uint32_t dataLen = grpPtr->grp.TlvSize();
|
||||||
char grpData[dataLen];
|
char grpData[dataLen];
|
||||||
uint32_t offset = 0;
|
uint32_t offset = 0;
|
||||||
grpPtr->grp.SetTlv(grpData, dataLen, &offset);
|
grpPtr->grp.SetTlv(grpData, dataLen, &offset);
|
||||||
cv.put(KEY_NXS_DATA, dataLen, grpData);
|
cv.put(KEY_NXS_DATA, dataLen, grpData);
|
||||||
|
|
||||||
cv.put(KEY_NXS_DATA_LEN, (int32_t) dataLen);
|
cv.put(KEY_NXS_DATA_LEN, (int32_t) dataLen);
|
||||||
cv.put(KEY_GRP_ID, grpPtr->grpId.toStdString());
|
cv.put(KEY_GRP_ID, grpPtr->grpId.toStdString());
|
||||||
cv.put(KEY_GRP_NAME, grpMetaPtr->mGroupName);
|
cv.put(KEY_GRP_NAME, grpMetaPtr->mGroupName);
|
||||||
cv.put(KEY_ORIG_GRP_ID, grpMetaPtr->mOrigGrpId.toStdString());
|
cv.put(KEY_ORIG_GRP_ID, grpMetaPtr->mOrigGrpId.toStdString());
|
||||||
cv.put(KEY_NXS_SERV_STRING, grpMetaPtr->mServiceString);
|
cv.put(KEY_NXS_SERV_STRING, grpMetaPtr->mServiceString);
|
||||||
cv.put(KEY_NXS_FLAGS, (int32_t)grpMetaPtr->mGroupFlags);
|
cv.put(KEY_NXS_FLAGS, (int32_t)grpMetaPtr->mGroupFlags);
|
||||||
cv.put(KEY_TIME_STAMP, (int32_t)grpMetaPtr->mPublishTs);
|
cv.put(KEY_TIME_STAMP, (int32_t)grpMetaPtr->mPublishTs);
|
||||||
cv.put(KEY_GRP_SIGN_FLAGS, (int32_t)grpMetaPtr->mSignFlags);
|
cv.put(KEY_GRP_SIGN_FLAGS, (int32_t)grpMetaPtr->mSignFlags);
|
||||||
cv.put(KEY_GRP_CIRCLE_ID, grpMetaPtr->mCircleId.toStdString());
|
cv.put(KEY_GRP_CIRCLE_ID, grpMetaPtr->mCircleId.toStdString());
|
||||||
cv.put(KEY_GRP_CIRCLE_TYPE, (int32_t)grpMetaPtr->mCircleType);
|
cv.put(KEY_GRP_CIRCLE_TYPE, (int32_t)grpMetaPtr->mCircleType);
|
||||||
cv.put(KEY_GRP_INTERNAL_CIRCLE, grpMetaPtr->mInternalCircle.toStdString());
|
cv.put(KEY_GRP_INTERNAL_CIRCLE, grpMetaPtr->mInternalCircle.toStdString());
|
||||||
cv.put(KEY_GRP_ORIGINATOR, grpMetaPtr->mOriginator.toStdString());
|
cv.put(KEY_GRP_ORIGINATOR, grpMetaPtr->mOriginator.toStdString());
|
||||||
cv.put(KEY_GRP_AUTHEN_FLAGS, (int32_t)grpMetaPtr->mAuthenFlags);
|
cv.put(KEY_GRP_AUTHEN_FLAGS, (int32_t)grpMetaPtr->mAuthenFlags);
|
||||||
cv.put(KEY_PARENT_GRP_ID, grpMetaPtr->mParentGrpId.toStdString());
|
cv.put(KEY_PARENT_GRP_ID, grpMetaPtr->mParentGrpId.toStdString());
|
||||||
cv.put(KEY_NXS_HASH, grpMetaPtr->mHash.toStdString());
|
cv.put(KEY_NXS_HASH, grpMetaPtr->mHash.toStdString());
|
||||||
cv.put(KEY_RECV_TS, (int32_t)grpMetaPtr->mRecvTS);
|
cv.put(KEY_RECV_TS, (int32_t)grpMetaPtr->mRecvTS);
|
||||||
cv.put(KEY_GRP_REP_CUTOFF, (int32_t)grpMetaPtr->mReputationCutOff);
|
cv.put(KEY_GRP_REP_CUTOFF, (int32_t)grpMetaPtr->mReputationCutOff);
|
||||||
cv.put(KEY_NXS_IDENTITY, grpMetaPtr->mAuthorId.toStdString());
|
cv.put(KEY_NXS_IDENTITY, grpMetaPtr->mAuthorId.toStdString());
|
||||||
|
|
||||||
offset = 0;
|
offset = 0;
|
||||||
char keySetData[grpMetaPtr->keys.TlvSize()];
|
char keySetData[grpMetaPtr->keys.TlvSize()];
|
||||||
grpMetaPtr->keys.SetTlv(keySetData, grpMetaPtr->keys.TlvSize(), &offset);
|
grpMetaPtr->keys.SetTlv(keySetData, grpMetaPtr->keys.TlvSize(), &offset);
|
||||||
cv.put(KEY_KEY_SET, grpMetaPtr->keys.TlvSize(), keySetData);
|
cv.put(KEY_KEY_SET, grpMetaPtr->keys.TlvSize(), keySetData);
|
||||||
|
|
||||||
offset = 0;
|
offset = 0;
|
||||||
char metaData[grpPtr->meta.TlvSize()];
|
char metaData[grpPtr->meta.TlvSize()];
|
||||||
grpPtr->meta.SetTlv(metaData, grpPtr->meta.TlvSize(), &offset);
|
grpPtr->meta.SetTlv(metaData, grpPtr->meta.TlvSize(), &offset);
|
||||||
cv.put(KEY_NXS_META, grpPtr->meta.TlvSize(), metaData);
|
cv.put(KEY_NXS_META, grpPtr->meta.TlvSize(), metaData);
|
||||||
|
|
||||||
// local meta data
|
// local meta data
|
||||||
cv.put(KEY_GRP_SUBCR_FLAG, (int32_t)grpMetaPtr->mSubscribeFlags);
|
cv.put(KEY_GRP_SUBCR_FLAG, (int32_t)grpMetaPtr->mSubscribeFlags);
|
||||||
cv.put(KEY_GRP_POP, (int32_t)grpMetaPtr->mPop);
|
cv.put(KEY_GRP_POP, (int32_t)grpMetaPtr->mPop);
|
||||||
cv.put(KEY_MSG_COUNT, (int32_t)grpMetaPtr->mVisibleMsgCount);
|
cv.put(KEY_MSG_COUNT, (int32_t)grpMetaPtr->mVisibleMsgCount);
|
||||||
cv.put(KEY_GRP_STATUS, (int32_t)grpMetaPtr->mGroupStatus);
|
cv.put(KEY_GRP_STATUS, (int32_t)grpMetaPtr->mGroupStatus);
|
||||||
cv.put(KEY_GRP_LAST_POST, (int32_t)grpMetaPtr->mLastPost);
|
cv.put(KEY_GRP_LAST_POST, (int32_t)grpMetaPtr->mLastPost);
|
||||||
|
|
||||||
locked_clearGrpMetaCache(grpMetaPtr->mGroupId);
|
locked_clearGrpMetaCache(grpMetaPtr->mGroupId);
|
||||||
|
|
||||||
if (!mDb->sqlInsert(GRP_TABLE_NAME, "", cv))
|
if (!mDb->sqlInsert(GRP_TABLE_NAME, "", cv))
|
||||||
{
|
{
|
||||||
std::cerr << "RsDataService::storeGroup() sqlInsert Failed";
|
std::cerr << "RsDataService::storeGroup() sqlInsert Failed";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
std::cerr << "\t For GroupId: " << grpMetaPtr->mGroupId.toStdString();
|
std::cerr << "\t For GroupId: " << grpMetaPtr->mGroupId.toStdString();
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// finish transaction
|
// finish transaction
|
||||||
bool ret = mDb->commitTransaction();
|
bool ret = mDb->commitTransaction();
|
||||||
|
|
||||||
for(sit = grp.begin(); sit != grp.end(); ++sit)
|
|
||||||
{
|
|
||||||
//TODO: API encourages aliasing, remove this abomination
|
|
||||||
if(sit->second != sit->first->metaData)
|
|
||||||
delete sit->second;
|
|
||||||
delete sit->first;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -918,21 +898,21 @@ void RsDataService::locked_clearGrpMetaCache(const RsGxsGroupId& gid)
|
|||||||
mGrpMetaDataCache_ContainsAllDatabase = false;
|
mGrpMetaDataCache_ContainsAllDatabase = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int RsDataService::updateGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
|
int RsDataService::updateGroup(const std::list<RsNxsGrp *> &grp)
|
||||||
{
|
{
|
||||||
|
|
||||||
RsStackMutex stack(mDbMutex);
|
RsStackMutex stack(mDbMutex);
|
||||||
|
|
||||||
std::map<RsNxsGrp*, RsGxsGrpMetaData* >::iterator sit = grp.begin();
|
|
||||||
|
|
||||||
// begin transaction
|
// begin transaction
|
||||||
mDb->beginTransaction();
|
mDb->beginTransaction();
|
||||||
|
|
||||||
for(; sit != grp.end(); ++sit)
|
for( std::list<RsNxsGrp*>::const_iterator sit = grp.begin(); sit != grp.end(); ++sit)
|
||||||
{
|
{
|
||||||
|
|
||||||
RsNxsGrp* grpPtr = sit->first;
|
RsNxsGrp* grpPtr = *sit;
|
||||||
RsGxsGrpMetaData* grpMetaPtr = sit->second;
|
RsGxsGrpMetaData* grpMetaPtr = grpPtr->metaData;
|
||||||
|
|
||||||
|
assert(grpMetaPtr != NULL);
|
||||||
|
|
||||||
// if data is larger than max item size do not add
|
// if data is larger than max item size do not add
|
||||||
if(!validSize(grpPtr)) continue;
|
if(!validSize(grpPtr)) continue;
|
||||||
@ -991,15 +971,6 @@ int RsDataService::updateGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
|
|||||||
// finish transaction
|
// finish transaction
|
||||||
bool ret = mDb->commitTransaction();
|
bool ret = mDb->commitTransaction();
|
||||||
|
|
||||||
for(sit = grp.begin(); sit != grp.end(); ++sit)
|
|
||||||
{
|
|
||||||
//TODO: API encourages aliasing, remove this abomination
|
|
||||||
if(sit->second != sit->first->metaData)
|
|
||||||
delete sit->second;
|
|
||||||
delete sit->first;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,21 +127,21 @@ public:
|
|||||||
* @param msg map of message and decoded meta data information
|
* @param msg map of message and decoded meta data information
|
||||||
* @return error code
|
* @return error code
|
||||||
*/
|
*/
|
||||||
int storeMessage(std::map<RsNxsMsg*, RsGxsMsgMetaData*>& msg);
|
int storeMessage(const std::list<RsNxsMsg*>& msg);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Stores a list of groups in data store
|
* Stores a list of groups in data store
|
||||||
* @param grp map of group and decoded meta data
|
* @param grp map of group and decoded meta data
|
||||||
* @return error code
|
* @return error code
|
||||||
*/
|
*/
|
||||||
int storeGroup(std::map<RsNxsGrp*, RsGxsGrpMetaData*>& grp);
|
int storeGroup(const std::list<RsNxsGrp*>& grp);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Updates group entries in Db
|
* Updates group entries in Db
|
||||||
* @param grp map of group and decoded meta data
|
* @param grp map of group and decoded meta data
|
||||||
* @return error code
|
* @return error code
|
||||||
*/
|
*/
|
||||||
int updateGroup(std::map<RsNxsGrp*, RsGxsGrpMetaData*>& grsp);
|
int updateGroup(const std::list<RsNxsGrp*>& grsp);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @param metaData The meta data item to update
|
* @param metaData The meta data item to update
|
||||||
|
@ -223,14 +223,14 @@ public:
|
|||||||
* @param msg map of message and decoded meta data information
|
* @param msg map of message and decoded meta data information
|
||||||
* @return error code
|
* @return error code
|
||||||
*/
|
*/
|
||||||
virtual int storeMessage(std::map<RsNxsMsg*, RsGxsMsgMetaData*>& msgs) = 0;
|
virtual int storeMessage(const std::list<RsNxsMsg*>& msgs) = 0;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Stores a list of groups in data store
|
* Stores a list of groups in data store
|
||||||
* @param grp map of group and decoded meta data
|
* @param grp map of group and decoded meta data
|
||||||
* @return error code
|
* @return error code
|
||||||
*/
|
*/
|
||||||
virtual int storeGroup(std::map<RsNxsGrp*, RsGxsGrpMetaData*>& grsp) = 0;
|
virtual int storeGroup(const std::list<RsNxsGrp*>& grsp) = 0;
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -238,7 +238,7 @@ public:
|
|||||||
* @param grp map of group and decoded meta data
|
* @param grp map of group and decoded meta data
|
||||||
* @return error code
|
* @return error code
|
||||||
*/
|
*/
|
||||||
virtual int updateGroup(std::map<RsNxsGrp*, RsGxsGrpMetaData*>& grsp) = 0;
|
virtual int updateGroup(const std::list<RsNxsGrp*>& grsp) = 0;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @param metaData
|
* @param metaData
|
||||||
|
@ -117,6 +117,14 @@ RsGenExchange::~RsGenExchange()
|
|||||||
delete mDataStore;
|
delete mDataStore;
|
||||||
mDataStore = NULL;
|
mDataStore = NULL;
|
||||||
|
|
||||||
|
for(uint32_t i=0;i<mNotifications.size();++i)
|
||||||
|
delete mNotifications[i] ;
|
||||||
|
|
||||||
|
for(uint32_t i=0;i<mGrpsToPublish.size();++i)
|
||||||
|
delete mGrpsToPublish[i].mItem ;
|
||||||
|
|
||||||
|
mNotifications.clear();
|
||||||
|
mGrpsToPublish.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsGenExchange::getGroupServerUpdateTS(const RsGxsGroupId& gid, time_t& grp_server_update_TS, time_t& msg_server_update_TS)
|
bool RsGenExchange::getGroupServerUpdateTS(const RsGxsGroupId& gid, time_t& grp_server_update_TS, time_t& msg_server_update_TS)
|
||||||
@ -1331,11 +1339,16 @@ bool RsGenExchange::deserializeGroupData(unsigned char *data, uint32_t size,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
mReceivedGrps.push_back(
|
if(mGrpPendingValidate.find(nxs_grp->grpId) != mGrpPendingValidate.end())
|
||||||
GxsPendingItem<RsNxsGrp*, RsGxsGroupId>(
|
{
|
||||||
nxs_grp, nxs_grp->grpId,time(NULL)) );
|
std::cerr << "(WW) Group " << nxs_grp->grpId << " is already pending validation. Not adding again." << std::endl;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if(gId) *gId = nxs_grp->grpId;
|
if(gId)
|
||||||
|
*gId = nxs_grp->grpId;
|
||||||
|
|
||||||
|
mGrpPendingValidate.insert(std::make_pair(nxs_grp->grpId, GxsPendingItem<RsNxsGrp*, RsGxsGroupId>(nxs_grp, nxs_grp->grpId,time(NULL))));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1568,20 +1581,18 @@ void RsGenExchange::notifyNewGroups(std::vector<RsNxsGrp *> &groups)
|
|||||||
for(; vit != groups.end(); ++vit)
|
for(; vit != groups.end(); ++vit)
|
||||||
{
|
{
|
||||||
RsNxsGrp* grp = *vit;
|
RsNxsGrp* grp = *vit;
|
||||||
NxsGrpPendValidVect::iterator received = std::find(mReceivedGrps.begin(),
|
NxsGrpPendValidVect::iterator received = mGrpPendingValidate.find(grp->grpId);
|
||||||
mReceivedGrps.end(), grp->grpId);
|
|
||||||
|
|
||||||
// drop group if you already have them
|
// drop group if you already have them
|
||||||
// TODO: move this to nxs layer to save bandwidth
|
// TODO: move this to nxs layer to save bandwidth
|
||||||
if(received == mReceivedGrps.end())
|
if(received == mGrpPendingValidate.end())
|
||||||
{
|
{
|
||||||
#ifdef GEN_EXCH_DEBUG
|
#ifdef GEN_EXCH_DEBUG
|
||||||
std::cerr << "RsGenExchange::notifyNewGroups() Received GrpId: " << grp->grpId;
|
std::cerr << "RsGenExchange::notifyNewGroups() Received GrpId: " << grp->grpId;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
GxsPendingItem<RsNxsGrp*, RsGxsGroupId> gpsi(grp, grp->grpId,time(NULL));
|
mGrpPendingValidate.insert(std::make_pair(grp->grpId, GxsPendingItem<RsNxsGrp*, RsGxsGroupId>(grp, grp->grpId,time(NULL))));
|
||||||
mReceivedGrps.push_back(gpsi);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1596,37 +1607,36 @@ void RsGenExchange::notifyNewMessages(std::vector<RsNxsMsg *>& messages)
|
|||||||
{
|
{
|
||||||
RS_STACK_MUTEX(mGenMtx) ;
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
|
|
||||||
std::vector<RsNxsMsg*>::iterator vit = messages.begin();
|
// store these for tick() to pick them up
|
||||||
|
|
||||||
// store these for tick() to pick them up
|
for(uint32_t i=0;i<messages.size();++i)
|
||||||
for(; vit != messages.end(); ++vit)
|
|
||||||
{
|
|
||||||
RsNxsMsg* msg = *vit;
|
|
||||||
|
|
||||||
NxsMsgPendingVect::iterator it =
|
|
||||||
std::find(mMsgPendingValidate.begin(), mMsgPendingValidate.end(), getMsgIdPair(*msg));
|
|
||||||
|
|
||||||
// if we have msg already just delete it
|
|
||||||
if(it == mMsgPendingValidate.end())
|
|
||||||
{
|
{
|
||||||
#ifdef GEN_EXCH_DEBUG
|
RsNxsMsg* msg = messages[i];
|
||||||
std::cerr << "RsGenExchange::notifyNewMessages() Received Msg: ";
|
NxsMsgPendingVect::iterator it = mMsgPendingValidate.find(msg->msgId) ;
|
||||||
std::cerr << " GrpId: " << msg->grpId;
|
|
||||||
std::cerr << " MsgId: " << msg->msgId;
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
mReceivedMsgs.push_back(msg);
|
// if we have msg already just delete it
|
||||||
}
|
if(it == mMsgPendingValidate.end())
|
||||||
else
|
{
|
||||||
{
|
|
||||||
#ifdef GEN_EXCH_DEBUG
|
#ifdef GEN_EXCH_DEBUG
|
||||||
std::cerr << " message is already in pending validation list. dropping." << std::endl;
|
std::cerr << "RsGenExchange::notifyNewMessages() Received Msg: ";
|
||||||
|
std::cerr << " GrpId: " << msg->grpId;
|
||||||
|
std::cerr << " MsgId: " << msg->msgId;
|
||||||
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
delete msg;
|
RsGxsGrpMsgIdPair id;
|
||||||
}
|
id.first = msg->grpId;
|
||||||
}
|
id.second = msg->msgId;
|
||||||
|
|
||||||
|
mMsgPendingValidate.insert(std::make_pair(msg->msgId,GxsPendingItem<RsNxsMsg*, RsGxsGrpMsgIdPair>(msg, id,time(NULL))));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#ifdef GEN_EXCH_DEBUG
|
||||||
|
std::cerr << " message is already in pending validation list. dropping." << std::endl;
|
||||||
|
#endif
|
||||||
|
delete msg;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RsGenExchange::notifyReceivePublishKey(const RsGxsGroupId &grpId)
|
void RsGenExchange::notifyReceivePublishKey(const RsGxsGroupId &grpId)
|
||||||
@ -2264,6 +2274,8 @@ void RsGenExchange::publishMsgs()
|
|||||||
|
|
||||||
computeHash(msg->msg, msg->metaData->mHash);
|
computeHash(msg->msg, msg->metaData->mHash);
|
||||||
mDataAccess->addMsgData(msg);
|
mDataAccess->addMsgData(msg);
|
||||||
|
delete msg ;
|
||||||
|
|
||||||
msgChangeMap[grpId].push_back(msgId);
|
msgChangeMap[grpId].push_back(msgId);
|
||||||
|
|
||||||
delete[] metaDataBuff;
|
delete[] metaDataBuff;
|
||||||
@ -2664,9 +2676,9 @@ void RsGenExchange::publishGrps()
|
|||||||
mDataAccess->updateGroupData(grp);
|
mDataAccess->updateGroupData(grp);
|
||||||
else
|
else
|
||||||
mDataAccess->addGroupData(grp);
|
mDataAccess->addGroupData(grp);
|
||||||
#warning csoler: this is bad: addGroupData/updateGroupData actially deletes grp. But it may be used below? grp should be a class object and not deleted manually!
|
|
||||||
|
|
||||||
groups_to_subscribe.push_back(grpId) ;
|
delete grp ;
|
||||||
|
groups_to_subscribe.push_back(grpId) ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2857,13 +2869,31 @@ void RsGenExchange::processRecvdMessages()
|
|||||||
if(!mMsgPendingValidate.empty())
|
if(!mMsgPendingValidate.empty())
|
||||||
std::cerr << "processing received messages" << std::endl;
|
std::cerr << "processing received messages" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
NxsMsgPendingVect::iterator pend_it = mMsgPendingValidate.begin();
|
// 1 - First, make sure items metadata is deserialised, clean old failed items, and collect the groups Ids we have to check
|
||||||
|
|
||||||
for(; pend_it != mMsgPendingValidate.end();)
|
RsGxsGrpMetaTemporaryMap grpMetas;
|
||||||
|
|
||||||
|
for(NxsMsgPendingVect::iterator pend_it = mMsgPendingValidate.begin();pend_it != mMsgPendingValidate.end();)
|
||||||
{
|
{
|
||||||
GxsPendingItem<RsNxsMsg*, RsGxsGrpMsgIdPair>& gpsi = *pend_it;
|
GxsPendingItem<RsNxsMsg*, RsGxsGrpMsgIdPair>& gpsi = pend_it->second;
|
||||||
|
RsNxsMsg *msg = gpsi.mItem ;
|
||||||
|
|
||||||
if(gpsi.mFirstTryTS + VALIDATE_MAX_WAITING_TIME < now)
|
if(msg->metaData == NULL)
|
||||||
|
{
|
||||||
|
RsGxsMsgMetaData* meta = new RsGxsMsgMetaData();
|
||||||
|
|
||||||
|
if(msg->meta.bin_len != 0 && meta->deserialise(msg->meta.bin_data, &(msg->meta.bin_len)))
|
||||||
|
msg->metaData = meta;
|
||||||
|
else
|
||||||
|
delete meta;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool accept_new_msg = msg->metaData != NULL && acceptNewMessage(msg->metaData,msg->msg.bin_len);
|
||||||
|
|
||||||
|
if(!accept_new_msg)
|
||||||
|
messages_to_reject.push_back(msg->metaData->mMsgId); // This prevents reloading the message again at next sync.
|
||||||
|
|
||||||
|
if(!accept_new_msg || gpsi.mFirstTryTS + VALIDATE_MAX_WAITING_TIME < now)
|
||||||
{
|
{
|
||||||
std::cerr << "Pending validation grp=" << gpsi.mId.first << ", msg=" << gpsi.mId.second << ", has exceeded validation time limit. The author's key can probably not be obtained. This is unexpected." << std::endl;
|
std::cerr << "Pending validation grp=" << gpsi.mId.first << ", msg=" << gpsi.mId.second << ", has exceeded validation time limit. The author's key can probably not be obtained. This is unexpected." << std::endl;
|
||||||
|
|
||||||
@ -2872,46 +2902,27 @@ void RsGenExchange::processRecvdMessages()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef GEN_EXCH_DEBUG
|
grpMetas.insert(std::make_pair(pend_it->second.mItem->grpId, (RsGxsGrpMetaData*)NULL));
|
||||||
std::cerr << " movign to recvd." << std::endl;
|
|
||||||
#endif
|
|
||||||
mReceivedMsgs.push_back(gpsi.mItem);
|
|
||||||
++pend_it;
|
++pend_it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mReceivedMsgs.empty())
|
// 2 - Retrieve the metadata for the associated groups.
|
||||||
return;
|
|
||||||
|
|
||||||
std::vector<RsNxsMsg*>::iterator vit = mReceivedMsgs.begin();
|
|
||||||
GxsMsgReq msgIds;
|
|
||||||
std::map<RsNxsMsg*, RsGxsMsgMetaData*> msgs;
|
|
||||||
|
|
||||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMetas;
|
|
||||||
|
|
||||||
// coalesce group meta retrieval for performance
|
|
||||||
for(; vit != mReceivedMsgs.end(); ++vit)
|
|
||||||
{
|
|
||||||
RsNxsMsg* msg = *vit;
|
|
||||||
grpMetas.insert(std::make_pair(msg->grpId, (RsGxsGrpMetaData*)NULL));
|
|
||||||
}
|
|
||||||
|
|
||||||
mDataStore->retrieveGxsGrpMetaData(grpMetas);
|
mDataStore->retrieveGxsGrpMetaData(grpMetas);
|
||||||
|
|
||||||
|
GxsMsgReq msgIds;
|
||||||
|
RsNxsMsgDataTemporaryList msgs_to_store;
|
||||||
|
|
||||||
#ifdef GEN_EXCH_DEBUG
|
#ifdef GEN_EXCH_DEBUG
|
||||||
std::cerr << " updating received messages:" << std::endl;
|
std::cerr << " updating received messages:" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
for(vit = mReceivedMsgs.begin(); vit != mReceivedMsgs.end(); ++vit)
|
|
||||||
|
// 3 - Validate each message
|
||||||
|
|
||||||
|
for(NxsMsgPendingVect::iterator pend_it = mMsgPendingValidate.begin();pend_it != mMsgPendingValidate.end();)
|
||||||
{
|
{
|
||||||
RsNxsMsg* msg = *vit;
|
RsNxsMsg* msg = pend_it->second.mItem;
|
||||||
RsGxsMsgMetaData* meta = new RsGxsMsgMetaData();
|
|
||||||
|
|
||||||
bool ok = false;
|
|
||||||
|
|
||||||
if(msg->meta.bin_len != 0)
|
|
||||||
ok = meta->deserialise(msg->meta.bin_data, &(msg->meta.bin_len));
|
|
||||||
|
|
||||||
msg->metaData = meta;
|
|
||||||
|
|
||||||
// (cyril) Normally we should discard posts that are older than the sync request. But that causes a problem because
|
// (cyril) Normally we should discard posts that are older than the sync request. But that causes a problem because
|
||||||
// RsGxsNetService requests posts to sync by chunks of 20. So if the 20 are discarded, they will be re-synced next time, and the sync process
|
// RsGxsNetService requests posts to sync by chunks of 20. So if the 20 are discarded, they will be re-synced next time, and the sync process
|
||||||
@ -2928,143 +2939,95 @@ void RsGenExchange::processRecvdMessages()
|
|||||||
#ifdef GEN_EXCH_DEBUG
|
#ifdef GEN_EXCH_DEBUG
|
||||||
std::cerr << " deserialised info: grp id=" << meta->mGroupId << ", msg id=" << meta->mMsgId ;
|
std::cerr << " deserialised info: grp id=" << meta->mGroupId << ", msg id=" << meta->mMsgId ;
|
||||||
#endif
|
#endif
|
||||||
uint8_t validateReturn = VALIDATE_FAIL;
|
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grpMetas.find(msg->grpId);
|
||||||
bool accept_new_msg = acceptNewMessage(meta,msg->msg.bin_len);
|
|
||||||
|
|
||||||
if(!accept_new_msg && mNetService != NULL)
|
|
||||||
mNetService->rejectMessage(meta->mMsgId) ; // This prevents reloading the message again at next sync.
|
|
||||||
|
|
||||||
if(ok && accept_new_msg)
|
|
||||||
{
|
|
||||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grpMetas.find(msg->grpId);
|
|
||||||
|
|
||||||
#ifdef GEN_EXCH_DEBUG
|
#ifdef GEN_EXCH_DEBUG
|
||||||
std::cerr << " msg info : grp id=" << msg->grpId << ", msg id=" << msg->msgId << std::endl;
|
std::cerr << " msg info : grp id=" << msg->grpId << ", msg id=" << msg->msgId << std::endl;
|
||||||
#endif
|
#endif
|
||||||
RsGxsGrpMetaData* grpMeta = NULL ;
|
// validate msg
|
||||||
|
|
||||||
// validate msg
|
if(mit == grpMetas.end())
|
||||||
if(mit != grpMetas.end())
|
{
|
||||||
{
|
std::cerr << "RsGenExchange::processRecvdMessages(): impossible situation: grp meta " << msg->grpId << " not available." << std::endl;
|
||||||
grpMeta = mit->second;
|
++pend_it ;
|
||||||
GxsSecurity::createPublicKeysFromPrivateKeys(grpMeta->keys); // make sure we have the public keys that correspond to the private ones, as it happens. Most of the time this call does nothing.
|
continue ;
|
||||||
|
}
|
||||||
|
|
||||||
validateReturn = validateMsg(msg, grpMeta->mGroupFlags, grpMeta->mSignFlags, grpMeta->keys);
|
RsGxsGrpMetaData *grpMeta = mit->second;
|
||||||
|
|
||||||
|
GxsSecurity::createPublicKeysFromPrivateKeys(grpMeta->keys); // make sure we have the public keys that correspond to the private ones, as it happens. Most of the time this call does nothing.
|
||||||
|
|
||||||
|
int validateReturn = validateMsg(msg, grpMeta->mGroupFlags, grpMeta->mSignFlags, grpMeta->keys);
|
||||||
|
|
||||||
#ifdef GEN_EXCH_DEBUG
|
#ifdef GEN_EXCH_DEBUG
|
||||||
std::cerr << " grpMeta.mSignFlags: " << std::hex << grpMeta->mSignFlags << std::dec << std::endl;
|
std::cerr << " grpMeta.mSignFlags: " << std::hex << grpMeta->mSignFlags << std::dec << std::endl;
|
||||||
std::cerr << " grpMeta.mAuthFlags: " << std::hex << grpMeta->mAuthenFlags << std::dec << std::endl;
|
std::cerr << " grpMeta.mAuthFlags: " << std::hex << grpMeta->mAuthenFlags << std::dec << std::endl;
|
||||||
std::cerr << " message validation result: " << (int)validateReturn << std::endl;
|
std::cerr << " message validation result: " << (int)validateReturn << std::endl;
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
if(validateReturn == VALIDATE_SUCCESS)
|
|
||||||
{
|
|
||||||
meta->mMsgStatus = GXS_SERV::GXS_MSG_STATUS_UNPROCESSED | GXS_SERV::GXS_MSG_STATUS_GUI_NEW | GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD;
|
|
||||||
msgs.insert(std::make_pair(msg, meta));
|
|
||||||
|
|
||||||
std::vector<RsGxsMessageId> &msgv = msgIds[msg->grpId];
|
|
||||||
if (std::find(msgv.begin(), msgv.end(), msg->msgId) == msgv.end())
|
|
||||||
{
|
|
||||||
msgv.push_back(msg->msgId);
|
|
||||||
}
|
|
||||||
|
|
||||||
NxsMsgPendingVect::iterator validated_entry = std::find(mMsgPendingValidate.begin(), mMsgPendingValidate.end(),
|
|
||||||
getMsgIdPair(*msg));
|
|
||||||
|
|
||||||
if(validated_entry != mMsgPendingValidate.end()) mMsgPendingValidate.erase(validated_entry);
|
|
||||||
|
|
||||||
computeHash(msg->msg, meta->mHash);
|
|
||||||
meta->recvTS = time(NULL);
|
|
||||||
#ifdef GEN_EXCH_DEBUG
|
|
||||||
std::cerr << " new status flags: " << meta->mMsgStatus << std::endl;
|
|
||||||
std::cerr << " computed hash: " << meta->mHash << std::endl;
|
|
||||||
std::cerr << "Message received. Identity=" << msg->metaData->mAuthorId << ", from peer " << msg->PeerId() << std::endl;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(!msg->metaData->mAuthorId.isNull())
|
if(validateReturn == VALIDATE_SUCCESS)
|
||||||
mRoutingClues[msg->metaData->mAuthorId].insert(msg->PeerId()) ;
|
{
|
||||||
}
|
msg->metaData->mMsgStatus = GXS_SERV::GXS_MSG_STATUS_UNPROCESSED | GXS_SERV::GXS_MSG_STATUS_GUI_NEW | GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD;
|
||||||
|
msgs_to_store.push_back(msg);
|
||||||
|
|
||||||
if(validateReturn == VALIDATE_FAIL)
|
std::vector<RsGxsMessageId> &msgv = msgIds[msg->grpId];
|
||||||
{
|
|
||||||
// In this case, we notify the network exchange service not to DL the message again, at least not yet.
|
if (std::find(msgv.begin(), msgv.end(), msg->msgId) == msgv.end())
|
||||||
|
msgv.push_back(msg->msgId);
|
||||||
|
|
||||||
|
computeHash(msg->msg, msg->metaData->mHash);
|
||||||
|
msg->metaData->recvTS = time(NULL);
|
||||||
|
|
||||||
#ifdef GEN_EXCH_DEBUG
|
#ifdef GEN_EXCH_DEBUG
|
||||||
std::cerr << "Notifying the network service to not download this message again." << std::endl;
|
std::cerr << " new status flags: " << meta->mMsgStatus << std::endl;
|
||||||
|
std::cerr << " computed hash: " << meta->mHash << std::endl;
|
||||||
|
std::cerr << "Message received. Identity=" << msg->metaData->mAuthorId << ", from peer " << msg->PeerId() << std::endl;
|
||||||
#endif
|
#endif
|
||||||
messages_to_reject.push_back(msg->msgId) ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#ifdef GEN_EXCH_DEBUG
|
|
||||||
std::cerr << " deserialisation failed!" <<std::endl;
|
|
||||||
#endif
|
|
||||||
validateReturn = VALIDATE_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(validateReturn == VALIDATE_FAIL)
|
if(!msg->metaData->mAuthorId.isNull())
|
||||||
{
|
mRoutingClues[msg->metaData->mAuthorId].insert(msg->PeerId()) ;
|
||||||
|
}
|
||||||
|
else if(validateReturn == VALIDATE_FAIL)
|
||||||
|
{
|
||||||
|
// In this case, we notify the network exchange service not to DL the message again, at least not yet.
|
||||||
|
|
||||||
#ifdef GEN_EXCH_DEBUG
|
#ifdef GEN_EXCH_DEBUG
|
||||||
std::cerr << "Validation failed for message id "
|
std::cerr << "Validation failed for message id "
|
||||||
<< "msg->grpId: " << msg->grpId << ", msgId: " << msg->msgId << std::endl;
|
<< "msg->grpId: " << msg->grpId << ", msgId: " << msg->msgId << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
messages_to_reject.push_back(msg->msgId) ;
|
||||||
|
delete msg ;
|
||||||
|
}
|
||||||
|
else if(validateReturn == VALIDATE_FAIL_TRY_LATER)
|
||||||
|
{
|
||||||
|
++pend_it ;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
NxsMsgPendingVect::iterator failed_entry = std::find(mMsgPendingValidate.begin(), mMsgPendingValidate.end(),
|
// Remove the entry from mMsgPendingValidate, but do not delete msg since it's either pushed into msg_to_store or deleted in the FAIL case!
|
||||||
getMsgIdPair(*msg));
|
|
||||||
|
|
||||||
if(failed_entry != mMsgPendingValidate.end()) mMsgPendingValidate.erase(failed_entry);
|
NxsMsgPendingVect::iterator tmp = pend_it ;
|
||||||
delete msg;
|
++tmp ;
|
||||||
|
mMsgPendingValidate.erase(pend_it) ;
|
||||||
|
pend_it = tmp ;
|
||||||
}
|
|
||||||
else if(validateReturn == VALIDATE_FAIL_TRY_LATER)
|
|
||||||
{
|
|
||||||
|
|
||||||
#ifdef GEN_EXCH_DEBUG
|
|
||||||
std::cerr << "failed to validate msg, trying again: "
|
|
||||||
<< "msg->grpId: " << msg->grpId << ", msgId: " << msg->msgId << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
RsGxsGrpMsgIdPair id;
|
|
||||||
id.first = msg->grpId;
|
|
||||||
id.second = msg->msgId;
|
|
||||||
|
|
||||||
// first check you haven't made too many attempts
|
|
||||||
|
|
||||||
NxsMsgPendingVect::iterator vit = std::find(mMsgPendingValidate.begin(), mMsgPendingValidate.end(), id);
|
|
||||||
|
|
||||||
if(vit == mMsgPendingValidate.end())
|
|
||||||
mMsgPendingValidate.push_back(GxsPendingItem<RsNxsMsg*, RsGxsGrpMsgIdPair>(msg, id,time(NULL)));
|
|
||||||
// else
|
|
||||||
// delete msg ;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// clean up resources from group meta retrieval
|
|
||||||
freeAndClearContainerResource<std::map<RsGxsGroupId, RsGxsGrpMetaData*>,
|
|
||||||
RsGxsGrpMetaData*>(grpMetas);
|
|
||||||
|
|
||||||
if(!msgIds.empty())
|
if(!msgIds.empty())
|
||||||
{
|
{
|
||||||
#ifdef GEN_EXCH_DEBUG
|
#ifdef GEN_EXCH_DEBUG
|
||||||
std::cerr << " removing existing and old messages from incoming list." << std::endl;
|
std::cerr << " removing existing and old messages from incoming list." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
removeDeleteExistingMessages(msgs, msgIds);
|
removeDeleteExistingMessages(msgs_to_store, msgIds);
|
||||||
|
|
||||||
#ifdef GEN_EXCH_DEBUG
|
#ifdef GEN_EXCH_DEBUG
|
||||||
std::cerr << " storing remaining messages" << std::endl;
|
std::cerr << " storing remaining messages" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
mDataStore->storeMessage(msgs);
|
mDataStore->storeMessage(msgs_to_store);
|
||||||
|
|
||||||
RsGxsMsgChange* c = new RsGxsMsgChange(RsGxsNotify::TYPE_RECEIVE, false);
|
RsGxsMsgChange* c = new RsGxsMsgChange(RsGxsNotify::TYPE_RECEIVE, false);
|
||||||
c->msgChangeMap = msgIds;
|
c->msgChangeMap = msgIds;
|
||||||
mNotifications.push_back(c);
|
mNotifications.push_back(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
mReceivedMsgs.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Done off-mutex to avoid cross deadlocks in the netservice that might call the RsGenExchange as an observer..
|
// Done off-mutex to avoid cross deadlocks in the netservice that might call the RsGenExchange as an observer..
|
||||||
@ -3081,122 +3044,115 @@ void RsGenExchange::processRecvdGroups()
|
|||||||
{
|
{
|
||||||
RS_STACK_MUTEX(mGenMtx) ;
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
|
|
||||||
if(mReceivedGrps.empty())
|
if(mGrpPendingValidate.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#ifdef GEN_EXCH_DEBUG
|
#ifdef GEN_EXCH_DEBUG
|
||||||
std::cerr << "RsGenExchange::Processing received groups" << std::endl;
|
std::cerr << "RsGenExchange::Processing received groups" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
NxsGrpPendValidVect::iterator vit = mReceivedGrps.begin();
|
|
||||||
std::vector<RsGxsGroupId> existingGrpIds;
|
|
||||||
std::list<RsGxsGroupId> grpIds;
|
std::list<RsGxsGroupId> grpIds;
|
||||||
|
RsNxsGrpDataTemporaryList grps_to_store;
|
||||||
|
|
||||||
std::map<RsNxsGrp*, RsGxsGrpMetaData*> grps;
|
// 1 - retrieve the existing groups so as to check what's not new
|
||||||
|
std::vector<RsGxsGroupId> existingGrpIds;
|
||||||
mDataStore->retrieveGroupIds(existingGrpIds);
|
mDataStore->retrieveGroupIds(existingGrpIds);
|
||||||
|
|
||||||
while( vit != mReceivedGrps.end())
|
// 2 - go through each and every new group data and validate the signatures.
|
||||||
|
|
||||||
|
for(NxsGrpPendValidVect::iterator vit = mGrpPendingValidate.begin(); vit != mGrpPendingValidate.end();)
|
||||||
{
|
{
|
||||||
GxsPendingItem<RsNxsGrp*, RsGxsGroupId>& gpsi = *vit;
|
GxsPendingItem<RsNxsGrp*, RsGxsGroupId>& gpsi = vit->second;
|
||||||
RsNxsGrp* grp = gpsi.mItem;
|
RsNxsGrp* grp = gpsi.mItem;
|
||||||
RsGxsGrpMetaData* meta = new RsGxsGrpMetaData();
|
|
||||||
bool deserialOk = false;
|
|
||||||
|
|
||||||
if(grp->meta.bin_len != 0)
|
|
||||||
deserialOk = meta->deserialise(grp->meta.bin_data, grp->meta.bin_len);
|
|
||||||
|
|
||||||
bool erase = true;
|
|
||||||
|
|
||||||
if(deserialOk && acceptNewGroup(meta))
|
|
||||||
{
|
|
||||||
#ifdef GEN_EXCH_DEBUG
|
|
||||||
std::cerr << " processing validation for group " << meta->mGroupId << ", original attempt time: " << time(NULL) - gpsi.mFirstTryTS << " seconds ago" << std::endl;
|
|
||||||
#endif
|
|
||||||
grp->metaData = meta;
|
|
||||||
uint8_t ret = validateGrp(grp);
|
|
||||||
|
|
||||||
if(ret == VALIDATE_SUCCESS)
|
|
||||||
{
|
|
||||||
meta->mGroupStatus = GXS_SERV::GXS_GRP_STATUS_UNPROCESSED | GXS_SERV::GXS_GRP_STATUS_UNREAD;
|
|
||||||
|
|
||||||
computeHash(grp->grp, meta->mHash);
|
|
||||||
|
|
||||||
// group has been validated. Let's notify the global router for the clue
|
|
||||||
|
|
||||||
if(!meta->mAuthorId.isNull())
|
|
||||||
{
|
|
||||||
#ifdef GEN_EXCH_DEBUG
|
|
||||||
std::cerr << "Group routage info: Identity=" << meta->mAuthorId << " from " << grp->PeerId() << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
mRoutingClues[meta->mAuthorId].insert(grp->PeerId()) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This has been moved here (as opposed to inside part for new groups below) because it is used to update the server TS when updates
|
|
||||||
// of grp metadata arrive.
|
|
||||||
|
|
||||||
meta->mRecvTS = time(NULL);
|
|
||||||
|
|
||||||
// now check if group already existss
|
|
||||||
if(std::find(existingGrpIds.begin(), existingGrpIds.end(), grp->grpId) == existingGrpIds.end())
|
|
||||||
{
|
|
||||||
//if(meta->mCircleType == GXS_CIRCLE_TYPE_YOUREYESONLY)
|
|
||||||
meta->mOriginator = grp->PeerId();
|
|
||||||
|
|
||||||
meta->mSubscribeFlags = GXS_SERV::GROUP_SUBSCRIBE_NOT_SUBSCRIBED;
|
|
||||||
|
|
||||||
grps.insert(std::make_pair(grp, meta));
|
|
||||||
grpIds.push_back(grp->grpId);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GroupUpdate update;
|
|
||||||
update.newGrp = grp;
|
|
||||||
mGroupUpdates.push_back(update);
|
|
||||||
}
|
|
||||||
erase = true;
|
|
||||||
}
|
|
||||||
else if(ret == VALIDATE_FAIL)
|
|
||||||
{
|
|
||||||
#ifdef GEN_EXCH_DEBUG
|
|
||||||
std::cerr << " failed to validate incoming meta, grpId: " << grp->grpId << ": wrong signature" << std::endl;
|
|
||||||
#endif
|
|
||||||
delete grp;
|
|
||||||
erase = true;
|
|
||||||
}
|
|
||||||
else if(ret == VALIDATE_FAIL_TRY_LATER)
|
|
||||||
{
|
|
||||||
|
|
||||||
#ifdef GEN_EXCH_DEBUG
|
#ifdef GEN_EXCH_DEBUG
|
||||||
std::cerr << " failed to validate incoming grp, trying again. grpId: " << grp->grpId << std::endl;
|
std::cerr << " processing validation for group " << meta->mGroupId << ", original attempt time: " << time(NULL) - gpsi.mFirstTryTS << " seconds ago" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
if(grp->metaData == NULL)
|
||||||
|
{
|
||||||
|
RsGxsGrpMetaData* meta = new RsGxsGrpMetaData();
|
||||||
|
|
||||||
if(gpsi.mFirstTryTS + VALIDATE_MAX_WAITING_TIME < time(NULL))
|
if(grp->meta.bin_len != 0 && meta->deserialise(grp->meta.bin_data, grp->meta.bin_len))
|
||||||
{
|
grp->metaData = meta ;
|
||||||
#ifdef GEN_EXCH_DEBUG
|
else
|
||||||
std::cerr << " validation time got group " << grp->grpId << " exceeded maximum. Will delete group " << std::endl;
|
delete meta ;
|
||||||
#endif
|
|
||||||
delete grp;
|
|
||||||
erase = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
erase = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(!deserialOk)
|
|
||||||
std::cerr << "(EE) deserialise error in group meta data" << std::endl;
|
|
||||||
|
|
||||||
delete grp;
|
|
||||||
delete meta;
|
|
||||||
erase = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(erase)
|
// early deletion of group from the pending list if it's malformed, not accepted, or has been tried unsuccessfully for too long
|
||||||
vit = mReceivedGrps.erase(vit);
|
|
||||||
else
|
if(grp->metaData == NULL || !acceptNewGroup(grp->metaData) || gpsi.mFirstTryTS + VALIDATE_MAX_WAITING_TIME < time(NULL))
|
||||||
++vit;
|
{
|
||||||
|
NxsGrpPendValidVect::iterator tmp(vit) ;
|
||||||
|
++tmp ;
|
||||||
|
delete grp ;
|
||||||
|
mGrpPendingValidate.erase(vit) ;
|
||||||
|
vit = tmp ;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// group signature validation
|
||||||
|
|
||||||
|
uint8_t ret = validateGrp(grp);
|
||||||
|
|
||||||
|
if(ret == VALIDATE_SUCCESS)
|
||||||
|
{
|
||||||
|
grp->metaData->mGroupStatus = GXS_SERV::GXS_GRP_STATUS_UNPROCESSED | GXS_SERV::GXS_GRP_STATUS_UNREAD;
|
||||||
|
|
||||||
|
computeHash(grp->grp, grp->metaData->mHash);
|
||||||
|
|
||||||
|
// group has been validated. Let's notify the global router for the clue
|
||||||
|
|
||||||
|
if(!grp->metaData->mAuthorId.isNull())
|
||||||
|
{
|
||||||
|
#ifdef GEN_EXCH_DEBUG
|
||||||
|
std::cerr << "Group routage info: Identity=" << meta->mAuthorId << " from " << grp->PeerId() << std::endl;
|
||||||
|
#endif
|
||||||
|
mRoutingClues[grp->metaData->mAuthorId].insert(grp->PeerId()) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This has been moved here (as opposed to inside part for new groups below) because it is used to update the server TS when updates
|
||||||
|
// of grp metadata arrive.
|
||||||
|
|
||||||
|
grp->metaData->mRecvTS = time(NULL);
|
||||||
|
|
||||||
|
// now check if group already exists
|
||||||
|
|
||||||
|
if(std::find(existingGrpIds.begin(), existingGrpIds.end(), grp->grpId) == existingGrpIds.end())
|
||||||
|
{
|
||||||
|
grp->metaData->mOriginator = grp->PeerId();
|
||||||
|
grp->metaData->mSubscribeFlags = GXS_SERV::GROUP_SUBSCRIBE_NOT_SUBSCRIBED;
|
||||||
|
|
||||||
|
grps_to_store.push_back(grp);
|
||||||
|
grpIds.push_back(grp->grpId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GroupUpdate update;
|
||||||
|
update.newGrp = grp;
|
||||||
|
mGroupUpdates.push_back(update);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(ret == VALIDATE_FAIL)
|
||||||
|
{
|
||||||
|
#ifdef GEN_EXCH_DEBUG
|
||||||
|
std::cerr << " failed to validate incoming meta, grpId: " << grp->grpId << ": wrong signature" << std::endl;
|
||||||
|
#endif
|
||||||
|
delete grp;
|
||||||
|
}
|
||||||
|
else if(ret == VALIDATE_FAIL_TRY_LATER)
|
||||||
|
{
|
||||||
|
#ifdef GEN_EXCH_DEBUG
|
||||||
|
std::cerr << " failed to validate incoming grp, trying again later. grpId: " << grp->grpId << std::endl;
|
||||||
|
#endif
|
||||||
|
++vit ;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Erase entry from the list
|
||||||
|
|
||||||
|
NxsGrpPendValidVect::iterator tmp(vit) ;
|
||||||
|
++tmp ;
|
||||||
|
mGrpPendingValidate.erase(vit) ;
|
||||||
|
vit = tmp ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!grpIds.empty())
|
if(!grpIds.empty())
|
||||||
@ -3204,7 +3160,7 @@ void RsGenExchange::processRecvdGroups()
|
|||||||
RsGxsGroupChange* c = new RsGxsGroupChange(RsGxsNotify::TYPE_RECEIVE, false);
|
RsGxsGroupChange* c = new RsGxsGroupChange(RsGxsNotify::TYPE_RECEIVE, false);
|
||||||
c->mGrpIdList = grpIds;
|
c->mGrpIdList = grpIds;
|
||||||
mNotifications.push_back(c);
|
mNotifications.push_back(c);
|
||||||
mDataStore->storeGroup(grps);
|
mDataStore->storeGroup(grps_to_store);
|
||||||
#ifdef GEN_EXCH_DEBUG
|
#ifdef GEN_EXCH_DEBUG
|
||||||
std::cerr << " adding the following grp ids to notification: " << std::endl;
|
std::cerr << " adding the following grp ids to notification: " << std::endl;
|
||||||
for(std::list<RsGxsGroupId>::const_iterator it(grpIds.begin());it!=grpIds.end();++it)
|
for(std::list<RsGxsGroupId>::const_iterator it(grpIds.begin());it!=grpIds.end();++it)
|
||||||
@ -3250,7 +3206,9 @@ void RsGenExchange::performUpdateValidation()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
vit = mGroupUpdates.begin();
|
vit = mGroupUpdates.begin();
|
||||||
std::map<RsNxsGrp*, RsGxsGrpMetaData*> grps;
|
|
||||||
|
RsNxsGrpDataTemporaryList grps ;
|
||||||
|
|
||||||
for(; vit != mGroupUpdates.end(); ++vit)
|
for(; vit != mGroupUpdates.end(); ++vit)
|
||||||
{
|
{
|
||||||
GroupUpdate& gu = *vit;
|
GroupUpdate& gu = *vit;
|
||||||
@ -3265,7 +3223,7 @@ void RsGenExchange::performUpdateValidation()
|
|||||||
|
|
||||||
gu.newGrp->metaData->mSubscribeFlags = gu.oldGrpMeta->mSubscribeFlags ;
|
gu.newGrp->metaData->mSubscribeFlags = gu.oldGrpMeta->mSubscribeFlags ;
|
||||||
|
|
||||||
grps.insert(std::make_pair(gu.newGrp, gu.newGrp->metaData));
|
grps.push_back(gu.newGrp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -3353,14 +3311,14 @@ void RsGenExchange::setGroupReputationCutOff(uint32_t& token, const RsGxsGroupId
|
|||||||
mGrpLocMetaMap.insert(std::make_pair(token, g));
|
mGrpLocMetaMap.insert(std::make_pair(token, g));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RsGenExchange::removeDeleteExistingMessages( RsGeneralDataService::MsgStoreMap& msgs, GxsMsgReq& msgIdsNotify)
|
void RsGenExchange::removeDeleteExistingMessages( std::list<RsNxsMsg*>& msgs, GxsMsgReq& msgIdsNotify)
|
||||||
{
|
{
|
||||||
// first get grp ids of messages to be stored
|
// first get grp ids of messages to be stored
|
||||||
|
|
||||||
RsGxsGroupId::std_set mGrpIdsUnique;
|
RsGxsGroupId::std_set mGrpIdsUnique;
|
||||||
|
|
||||||
for(RsGeneralDataService::MsgStoreMap::const_iterator cit = msgs.begin(); cit != msgs.end(); ++cit)
|
for(std::list<RsNxsMsg*>::const_iterator cit = msgs.begin(); cit != msgs.end(); ++cit)
|
||||||
mGrpIdsUnique.insert(cit->second->mGroupId);
|
mGrpIdsUnique.insert((*cit)->metaData->mGroupId);
|
||||||
|
|
||||||
//RsGxsGroupId::std_list grpIds(mGrpIdsUnique.begin(), mGrpIdsUnique.end());
|
//RsGxsGroupId::std_list grpIds(mGrpIdsUnique.begin(), mGrpIdsUnique.end());
|
||||||
//RsGxsGroupId::std_list::const_iterator it = grpIds.begin();
|
//RsGxsGroupId::std_list::const_iterator it = grpIds.begin();
|
||||||
@ -3381,13 +3339,10 @@ void RsGenExchange::removeDeleteExistingMessages( RsGeneralDataService::MsgStore
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
//RsGeneralDataService::MsgStoreMap::iterator cit2 = msgs.begin();
|
|
||||||
RsGeneralDataService::MsgStoreMap filtered;
|
|
||||||
|
|
||||||
// now for each msg to be stored that exist in the retrieved msg/grp "index" delete and erase from map
|
// now for each msg to be stored that exist in the retrieved msg/grp "index" delete and erase from map
|
||||||
for(RsGeneralDataService::MsgStoreMap::iterator cit2 = msgs.begin(); cit2 != msgs.end(); ++cit2)
|
for(std::list<RsNxsMsg*>::iterator cit2 = msgs.begin(); cit2 != msgs.end();)
|
||||||
{
|
{
|
||||||
const RsGxsMessageId::std_vector& msgIds = msgIdReq[cit2->second->mGroupId];
|
const RsGxsMessageId::std_vector& msgIds = msgIdReq[(*cit2)->metaData->mGroupId];
|
||||||
|
|
||||||
#ifdef GEN_EXCH_DEBUG
|
#ifdef GEN_EXCH_DEBUG
|
||||||
std::cerr << " grpid=" << cit2->second->mGroupId << ", msgid=" << cit2->second->mMsgId ;
|
std::cerr << " grpid=" << cit2->second->mGroupId << ", msgid=" << cit2->second->mMsgId ;
|
||||||
@ -3395,38 +3350,29 @@ void RsGenExchange::removeDeleteExistingMessages( RsGeneralDataService::MsgStore
|
|||||||
|
|
||||||
// Avoid storing messages that are already in the database, as well as messages that are too old (or generally do not pass the database storage test)
|
// Avoid storing messages that are already in the database, as well as messages that are too old (or generally do not pass the database storage test)
|
||||||
//
|
//
|
||||||
if(std::find(msgIds.begin(), msgIds.end(), cit2->second->mMsgId) == msgIds.end() && messagePublicationTest(*cit2->second))
|
if(std::find(msgIds.begin(), msgIds.end(), (*cit2)->metaData->mMsgId) != msgIds.end() || !messagePublicationTest( *(*cit2)->metaData))
|
||||||
{
|
{
|
||||||
// passes tests, so add to filtered list
|
// msg exist in retrieved index. We should use a std::set here instead of a vector.
|
||||||
//
|
|
||||||
filtered.insert(*cit2);
|
RsGxsMessageId::std_vector& notifyIds = msgIdsNotify[ (*cit2)->metaData->mGroupId];
|
||||||
#ifdef GEN_EXCH_DEBUG
|
RsGxsMessageId::std_vector::iterator it2 = std::find(notifyIds.begin(), notifyIds.end(), (*cit2)->metaData->mMsgId);
|
||||||
std::cerr << " keeping " << cit2->second->mMsgId << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else // remove message from list
|
|
||||||
{
|
|
||||||
// msg exist in retrieved index
|
|
||||||
RsGxsMessageId::std_vector& notifyIds = msgIdsNotify[cit2->second->mGroupId];
|
|
||||||
RsGxsMessageId::std_vector::iterator it2 = std::find(notifyIds.begin(),
|
|
||||||
notifyIds.end(), cit2->second->mMsgId);
|
|
||||||
if(it2 != notifyIds.end())
|
if(it2 != notifyIds.end())
|
||||||
{
|
{
|
||||||
notifyIds.erase(it2);
|
notifyIds.erase(it2);
|
||||||
if (notifyIds.empty())
|
if (notifyIds.empty())
|
||||||
{
|
{
|
||||||
msgIdsNotify.erase(cit2->second->mGroupId);
|
msgIdsNotify.erase( (*cit2)->metaData->mGroupId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef GEN_EXCH_DEBUG
|
#ifdef GEN_EXCH_DEBUG
|
||||||
std::cerr << " discarding " << cit2->second->mMsgId << std::endl;
|
std::cerr << " discarding " << cit2->second->mMsgId << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
delete cit2->first;
|
delete *cit2;
|
||||||
// cit2->second will be deleted too in the destructor of cit2->first (RsNxsMsg)
|
cit2 = msgs.erase(cit2);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
++cit2;
|
||||||
}
|
}
|
||||||
|
|
||||||
msgs = filtered;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -850,7 +850,7 @@ private:
|
|||||||
* @param msgs messages to be filtered
|
* @param msgs messages to be filtered
|
||||||
* @param msgIdsNotify message notification map to be filtered
|
* @param msgIdsNotify message notification map to be filtered
|
||||||
*/
|
*/
|
||||||
void removeDeleteExistingMessages(RsGeneralDataService::MsgStoreMap& msgs, GxsMsgReq& msgIdsNotify);
|
void removeDeleteExistingMessages(std::list<RsNxsMsg*>& msgs, GxsMsgReq& msgIdsNotify);
|
||||||
|
|
||||||
RsMutex mGenMtx;
|
RsMutex mGenMtx;
|
||||||
RsGxsDataAccess* mDataAccess;
|
RsGxsDataAccess* mDataAccess;
|
||||||
@ -863,8 +863,8 @@ private:
|
|||||||
|
|
||||||
std::vector<RsNxsMsg*> mReceivedMsgs;
|
std::vector<RsNxsMsg*> mReceivedMsgs;
|
||||||
|
|
||||||
typedef std::vector<GxsPendingItem<RsNxsGrp*, RsGxsGroupId> > NxsGrpPendValidVect;
|
typedef std::map<RsGxsGroupId,GxsPendingItem<RsNxsGrp*, RsGxsGroupId> > NxsGrpPendValidVect;
|
||||||
NxsGrpPendValidVect mReceivedGrps;
|
NxsGrpPendValidVect mGrpPendingValidate;
|
||||||
|
|
||||||
std::vector<GxsGrpPendingSign> mGrpsToPublish;
|
std::vector<GxsGrpPendingSign> mGrpsToPublish;
|
||||||
typedef std::vector<GxsGrpPendingSign> NxsGrpSignPendVect;
|
typedef std::vector<GxsGrpPendingSign> NxsGrpSignPendVect;
|
||||||
@ -885,11 +885,10 @@ private:
|
|||||||
/// authentication policy
|
/// authentication policy
|
||||||
uint32_t mAuthenPolicy;
|
uint32_t mAuthenPolicy;
|
||||||
|
|
||||||
std::map<uint32_t, GxsPendingItem<RsGxsMsgItem*, uint32_t> >
|
std::map<uint32_t, GxsPendingItem<RsGxsMsgItem*, uint32_t> > mMsgPendingSign;
|
||||||
mMsgPendingSign;
|
|
||||||
|
|
||||||
std::vector<GxsPendingItem<RsNxsMsg*, RsGxsGrpMsgIdPair> > mMsgPendingValidate;
|
typedef std::map<RsGxsMessageId,GxsPendingItem<RsNxsMsg*, RsGxsGrpMsgIdPair> > NxsMsgPendingVect;
|
||||||
typedef std::vector<GxsPendingItem<RsNxsMsg*, RsGxsGrpMsgIdPair> > NxsMsgPendingVect;
|
NxsMsgPendingVect mMsgPendingValidate;
|
||||||
|
|
||||||
bool mCleaning;
|
bool mCleaning;
|
||||||
time_t mLastClean;
|
time_t mLastClean;
|
||||||
|
@ -45,6 +45,11 @@ RsGxsDataAccess::RsGxsDataAccess(RsGeneralDataService* ds) :
|
|||||||
mDataStore(ds), mDataMutex("RsGxsDataAccess"), mNextToken(0) {}
|
mDataStore(ds), mDataMutex("RsGxsDataAccess"), mNextToken(0) {}
|
||||||
|
|
||||||
|
|
||||||
|
RsGxsDataAccess::~RsGxsDataAccess()
|
||||||
|
{
|
||||||
|
for(std::map<uint32_t, GxsRequest*>::const_iterator it(mRequests.begin());it!=mRequests.end();++it)
|
||||||
|
delete it->second ;
|
||||||
|
}
|
||||||
bool RsGxsDataAccess::requestGroupInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts,
|
bool RsGxsDataAccess::requestGroupInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts,
|
||||||
const std::list<RsGxsGroupId> &groupIds)
|
const std::list<RsGxsGroupId> &groupIds)
|
||||||
{
|
{
|
||||||
@ -1803,8 +1808,8 @@ bool RsGxsDataAccess::addGroupData(RsNxsGrp* grp) {
|
|||||||
|
|
||||||
RsStackMutex stack(mDataMutex);
|
RsStackMutex stack(mDataMutex);
|
||||||
|
|
||||||
std::map<RsNxsGrp*, RsGxsGrpMetaData*> grpM;
|
std::list<RsNxsGrp*> grpM;
|
||||||
grpM.insert(std::make_pair(grp, grp->metaData));
|
grpM.push_back(grp);
|
||||||
return mDataStore->storeGroup(grpM);
|
return mDataStore->storeGroup(grpM);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1812,8 +1817,8 @@ bool RsGxsDataAccess::updateGroupData(RsNxsGrp* grp) {
|
|||||||
|
|
||||||
RsStackMutex stack(mDataMutex);
|
RsStackMutex stack(mDataMutex);
|
||||||
|
|
||||||
std::map<RsNxsGrp*, RsGxsGrpMetaData*> grpM;
|
std::list<RsNxsGrp*> grpM;
|
||||||
grpM.insert(std::make_pair(grp, grp->metaData));
|
grpM.push_back(grp);
|
||||||
return mDataStore->updateGroup(grpM);
|
return mDataStore->updateGroup(grpM);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1821,8 +1826,8 @@ bool RsGxsDataAccess::addMsgData(RsNxsMsg* msg) {
|
|||||||
|
|
||||||
RsStackMutex stack(mDataMutex);
|
RsStackMutex stack(mDataMutex);
|
||||||
|
|
||||||
std::map<RsNxsMsg*, RsGxsMsgMetaData*> msgM;
|
std::list<RsNxsMsg*> msgM;
|
||||||
msgM.insert(std::make_pair(msg, msg->metaData));
|
msgM.push_back(msg);
|
||||||
return mDataStore->storeMessage(msgM);
|
return mDataStore->storeMessage(msgM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ class RsGxsDataAccess : public RsTokenService
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsGxsDataAccess(RsGeneralDataService* ds);
|
RsGxsDataAccess(RsGeneralDataService* ds);
|
||||||
virtual ~RsGxsDataAccess() { return ;}
|
virtual ~RsGxsDataAccess() ;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -551,14 +551,13 @@ void RsGxsNetService::syncWithPeers()
|
|||||||
|
|
||||||
#ifndef GXS_DISABLE_SYNC_MSGS
|
#ifndef GXS_DISABLE_SYNC_MSGS
|
||||||
|
|
||||||
typedef RsGxsMetaDataTemporaryMap<RsGxsGrpMetaData> GrpMetaMap;
|
RsGxsGrpMetaTemporaryMap grpMeta;
|
||||||
GrpMetaMap grpMeta;
|
|
||||||
|
|
||||||
mDataStore->retrieveGxsGrpMetaData(grpMeta);
|
mDataStore->retrieveGxsGrpMetaData(grpMeta);
|
||||||
|
|
||||||
GrpMetaMap toRequest;
|
RsGxsGrpMetaTemporaryMap toRequest;
|
||||||
|
|
||||||
for(GrpMetaMap::iterator mit = grpMeta.begin(); mit != grpMeta.end(); ++mit)
|
for(RsGxsGrpMetaTemporaryMap::iterator mit = grpMeta.begin(); mit != grpMeta.end(); ++mit)
|
||||||
{
|
{
|
||||||
RsGxsGrpMetaData* meta = mit->second;
|
RsGxsGrpMetaData* meta = mit->second;
|
||||||
|
|
||||||
@ -596,7 +595,7 @@ void RsGxsNetService::syncWithPeers()
|
|||||||
GXSNETDEBUG_P_(peerId) << " syncing messages with peer " << peerId << std::endl;
|
GXSNETDEBUG_P_(peerId) << " syncing messages with peer " << peerId << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
GrpMetaMap::const_iterator mmit = toRequest.begin();
|
RsGxsGrpMetaTemporaryMap::const_iterator mmit = toRequest.begin();
|
||||||
for(; mmit != toRequest.end(); ++mmit)
|
for(; mmit != toRequest.end(); ++mmit)
|
||||||
{
|
{
|
||||||
const RsGxsGrpMetaData* meta = mmit->second;
|
const RsGxsGrpMetaData* meta = mmit->second;
|
||||||
@ -678,7 +677,7 @@ void RsGxsNetService::syncGrpStatistics()
|
|||||||
#ifdef NXS_NET_DEBUG_6
|
#ifdef NXS_NET_DEBUG_6
|
||||||
GXSNETDEBUG___<< "Sync-ing group statistics." << std::endl;
|
GXSNETDEBUG___<< "Sync-ing group statistics." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
RsGxsMetaDataTemporaryMap<RsGxsGrpMetaData> grpMeta;
|
RsGxsGrpMetaTemporaryMap grpMeta;
|
||||||
|
|
||||||
mDataStore->retrieveGxsGrpMetaData(grpMeta);
|
mDataStore->retrieveGxsGrpMetaData(grpMeta);
|
||||||
|
|
||||||
@ -751,7 +750,7 @@ void RsGxsNetService::handleRecvSyncGrpStatistics(RsNxsSyncGrpStatsItem *grs)
|
|||||||
#ifdef NXS_NET_DEBUG_6
|
#ifdef NXS_NET_DEBUG_6
|
||||||
GXSNETDEBUG_PG(grs->PeerId(),grs->grpId) << "Received Grp update stats Request for group " << grs->grpId << " from friend " << grs->PeerId() << std::endl;
|
GXSNETDEBUG_PG(grs->PeerId(),grs->grpId) << "Received Grp update stats Request for group " << grs->grpId << " from friend " << grs->PeerId() << std::endl;
|
||||||
#endif
|
#endif
|
||||||
RsGxsMetaDataTemporaryMap<RsGxsGrpMetaData> grpMetas;
|
RsGxsGrpMetaTemporaryMap grpMetas;
|
||||||
grpMetas[grs->grpId] = NULL;
|
grpMetas[grs->grpId] = NULL;
|
||||||
|
|
||||||
mDataStore->retrieveGxsGrpMetaData(grpMetas);
|
mDataStore->retrieveGxsGrpMetaData(grpMetas);
|
||||||
@ -1905,7 +1904,7 @@ void RsGxsNetService::updateClientSyncTS()
|
|||||||
|
|
||||||
void RsGxsNetService::updateServerSyncTS()
|
void RsGxsNetService::updateServerSyncTS()
|
||||||
{
|
{
|
||||||
RsGxsMetaDataTemporaryMap<RsGxsGrpMetaData> gxsMap;
|
RsGxsGrpMetaTemporaryMap gxsMap;
|
||||||
|
|
||||||
#ifdef NXS_NET_DEBUG_0
|
#ifdef NXS_NET_DEBUG_0
|
||||||
GXSNETDEBUG___<< "updateServerSyncTS(): updating last modification time stamp of local data." << std::endl;
|
GXSNETDEBUG___<< "updateServerSyncTS(): updating last modification time stamp of local data." << std::endl;
|
||||||
@ -2719,7 +2718,7 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
|
|||||||
GXSNETDEBUG_PG(item->PeerId(),grpId) << " grpId = " << grpId << std::endl;
|
GXSNETDEBUG_PG(item->PeerId(),grpId) << " grpId = " << grpId << std::endl;
|
||||||
GXSNETDEBUG_PG(item->PeerId(),grpId) << " retrieving grp mesta data..." << std::endl;
|
GXSNETDEBUG_PG(item->PeerId(),grpId) << " retrieving grp mesta data..." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
RsGxsMetaDataTemporaryMap<RsGxsGrpMetaData> grpMetaMap;
|
RsGxsGrpMetaTemporaryMap grpMetaMap;
|
||||||
grpMetaMap[grpId] = NULL;
|
grpMetaMap[grpId] = NULL;
|
||||||
|
|
||||||
mDataStore->retrieveGxsGrpMetaData(grpMetaMap);
|
mDataStore->retrieveGxsGrpMetaData(grpMetaMap);
|
||||||
@ -2977,7 +2976,7 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::list<RsNxsSyncGrpItem*> grpItemL;
|
std::list<RsNxsSyncGrpItem*> grpItemL;
|
||||||
RsGxsMetaDataTemporaryMap<RsGxsGrpMetaData> grpMetaMap;
|
RsGxsGrpMetaTemporaryMap grpMetaMap;
|
||||||
|
|
||||||
for(std::list<RsNxsItem*>::iterator lit = tr->mItems.begin(); lit != tr->mItems.end(); ++lit)
|
for(std::list<RsNxsItem*>::iterator lit = tr->mItems.begin(); lit != tr->mItems.end(); ++lit)
|
||||||
{
|
{
|
||||||
@ -3086,7 +3085,7 @@ void RsGxsNetService::locked_genSendGrpsTransaction(NxsTransaction* tr)
|
|||||||
|
|
||||||
std::list<RsNxsItem*>::iterator lit = tr->mItems.begin();
|
std::list<RsNxsItem*>::iterator lit = tr->mItems.begin();
|
||||||
|
|
||||||
RsGxsMetaDataTemporaryMap<RsNxsGrp> grps ;
|
t_RsGxsGenericDataTemporaryMap<RsGxsGroupId,RsNxsGrp> grps ;
|
||||||
|
|
||||||
for(;lit != tr->mItems.end(); ++lit)
|
for(;lit != tr->mItems.end(); ++lit)
|
||||||
{
|
{
|
||||||
@ -3803,7 +3802,7 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrpReqItem *item)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RsGxsMetaDataTemporaryMap<RsGxsGrpMetaData> grp;
|
RsGxsGrpMetaTemporaryMap grp;
|
||||||
mDataStore->retrieveGxsGrpMetaData(grp);
|
mDataStore->retrieveGxsGrpMetaData(grp);
|
||||||
|
|
||||||
#ifdef NXS_NET_DEBUG_0
|
#ifdef NXS_NET_DEBUG_0
|
||||||
@ -4089,7 +4088,7 @@ void RsGxsNetService::handleRecvSyncMessage(RsNxsSyncMsgReqItem *item,bool item_
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RsGxsMetaDataTemporaryMap<RsGxsGrpMetaData> grpMetas;
|
RsGxsGrpMetaTemporaryMap grpMetas;
|
||||||
grpMetas[item->grpId] = NULL;
|
grpMetas[item->grpId] = NULL;
|
||||||
|
|
||||||
mDataStore->retrieveGxsGrpMetaData(grpMetas);
|
mDataStore->retrieveGxsGrpMetaData(grpMetas);
|
||||||
@ -4628,7 +4627,7 @@ void RsGxsNetService::sharePublishKeysPending()
|
|||||||
|
|
||||||
// Get the meta data for this group Id
|
// Get the meta data for this group Id
|
||||||
//
|
//
|
||||||
RsGxsMetaDataTemporaryMap<RsGxsGrpMetaData> grpMetaMap;
|
RsGxsGrpMetaTemporaryMap grpMetaMap;
|
||||||
grpMetaMap[mit->first] = NULL;
|
grpMetaMap[mit->first] = NULL;
|
||||||
mDataStore->retrieveGxsGrpMetaData(grpMetaMap);
|
mDataStore->retrieveGxsGrpMetaData(grpMetaMap);
|
||||||
|
|
||||||
@ -4712,7 +4711,7 @@ void RsGxsNetService::handleRecvPublishKeys(RsNxsGroupPublishKeyItem *item)
|
|||||||
|
|
||||||
// Get the meta data for this group Id
|
// Get the meta data for this group Id
|
||||||
//
|
//
|
||||||
RsGxsMetaDataTemporaryMap<RsGxsGrpMetaData> grpMetaMap;
|
RsGxsGrpMetaTemporaryMap grpMetaMap;
|
||||||
grpMetaMap[item->grpId] = NULL;
|
grpMetaMap[item->grpId] = NULL;
|
||||||
|
|
||||||
mDataStore->retrieveGxsGrpMetaData(grpMetaMap);
|
mDataStore->retrieveGxsGrpMetaData(grpMetaMap);
|
||||||
|
@ -71,13 +71,10 @@ class RsGroupNetworkStatsRecord
|
|||||||
* Incoming transaction are in 3 different states
|
* Incoming transaction are in 3 different states
|
||||||
* 1. START 2. RECEIVING 3. END
|
* 1. START 2. RECEIVING 3. END
|
||||||
*/
|
*/
|
||||||
class RsGxsNetService : public RsNetworkExchangeService, public p3ThreadedService,
|
class RsGxsNetService : public RsNetworkExchangeService, public p3ThreadedService, public p3Config
|
||||||
public p3Config
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef RsSharedPtr<RsGxsNetService> pointer;
|
|
||||||
|
|
||||||
static const uint32_t FRAGMENT_SIZE;
|
static const uint32_t FRAGMENT_SIZE;
|
||||||
/*!
|
/*!
|
||||||
* only one observer is allowed
|
* only one observer is allowed
|
||||||
|
@ -33,55 +33,48 @@
|
|||||||
class RsGixs ;
|
class RsGixs ;
|
||||||
class RsGenExchange ;
|
class RsGenExchange ;
|
||||||
|
|
||||||
/*!
|
|
||||||
* Handy function for cleaning out meta result containers
|
|
||||||
* @param container
|
|
||||||
*/
|
|
||||||
template <class Container, class Item>
|
|
||||||
void freeAndClearContainerResource(Container container)
|
|
||||||
{
|
|
||||||
typename Container::iterator meta_it = container.begin();
|
|
||||||
|
|
||||||
for(; meta_it != container.end(); ++meta_it)
|
|
||||||
if(meta_it->second != NULL)
|
|
||||||
delete meta_it->second;
|
|
||||||
|
|
||||||
container.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
// temporary holds a map of pointers to class T, and destroys all pointers on delete.
|
// temporary holds a map of pointers to class T, and destroys all pointers on delete.
|
||||||
|
|
||||||
template<class T>
|
class non_copiable
|
||||||
class RsGxsMetaDataTemporaryMap: public std::map<RsGxsGroupId,T*>
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~RsGxsMetaDataTemporaryMap()
|
non_copiable() {}
|
||||||
|
private:
|
||||||
|
non_copiable& operator=(const non_copiable&) { return *this ;}
|
||||||
|
non_copiable(const non_copiable&) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class IdClass,class IdData>
|
||||||
|
class t_RsGxsGenericDataTemporaryMap: public std::map<IdClass,IdData *>, public non_copiable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~t_RsGxsGenericDataTemporaryMap()
|
||||||
{
|
{
|
||||||
clear() ;
|
clear() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void clear()
|
virtual void clear()
|
||||||
{
|
{
|
||||||
for(typename RsGxsMetaDataTemporaryMap<T>::iterator it = this->begin();it!=this->end();++it)
|
for(typename t_RsGxsGenericDataTemporaryMap<IdClass,IdData>::iterator it = this->begin();it!=this->end();++it)
|
||||||
if(it->second != NULL)
|
if(it->second != NULL)
|
||||||
delete it->second ;
|
delete it->second ;
|
||||||
|
|
||||||
std::map<RsGxsGroupId,T*>::clear() ;
|
std::map<IdClass,IdData*>::clear() ;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
class RsGxsMetaDataTemporaryMapVector: public std::map<RsGxsGroupId,std::vector<T*> >
|
class t_RsGxsGenericDataTemporaryMapVector: public std::map<RsGxsGroupId,std::vector<T*> >, public non_copiable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~RsGxsMetaDataTemporaryMapVector()
|
virtual ~t_RsGxsGenericDataTemporaryMapVector()
|
||||||
{
|
{
|
||||||
clear() ;
|
clear() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void clear()
|
virtual void clear()
|
||||||
{
|
{
|
||||||
for(typename RsGxsMetaDataTemporaryMapVector<T>::iterator it = this->begin();it!=this->end();++it)
|
for(typename t_RsGxsGenericDataTemporaryMapVector<T>::iterator it = this->begin();it!=this->end();++it)
|
||||||
{
|
{
|
||||||
for(uint32_t i=0;i<it->second.size();++i)
|
for(uint32_t i=0;i<it->second.size();++i)
|
||||||
delete it->second[i] ;
|
delete it->second[i] ;
|
||||||
@ -92,6 +85,34 @@ public:
|
|||||||
std::map<RsGxsGroupId,std::vector<T*> >::clear() ;
|
std::map<RsGxsGroupId,std::vector<T*> >::clear() ;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
class t_RsGxsGenericDataTemporaryList: public std::list<T*>, public non_copiable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~t_RsGxsGenericDataTemporaryList()
|
||||||
|
{
|
||||||
|
clear() ;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void clear()
|
||||||
|
{
|
||||||
|
for(typename t_RsGxsGenericDataTemporaryList<T>::iterator it = this->begin();it!=this->end();++it)
|
||||||
|
delete *it;
|
||||||
|
|
||||||
|
std::list<T*>::clear() ;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef t_RsGxsGenericDataTemporaryMap<RsGxsGroupId,RsGxsGrpMetaData> RsGxsGrpMetaTemporaryMap;
|
||||||
|
typedef t_RsGxsGenericDataTemporaryMap<RsGxsGroupId,RsNxsGrp> RsNxsGrpDataTemporaryMap;
|
||||||
|
|
||||||
|
typedef t_RsGxsGenericDataTemporaryMapVector<RsGxsMsgMetaData> RsGxsMsgMetaTemporaryMap ;
|
||||||
|
typedef t_RsGxsGenericDataTemporaryMapVector<RsNxsMsg> RsNxsMsgDataTemporaryMap ;
|
||||||
|
|
||||||
|
typedef t_RsGxsGenericDataTemporaryList<RsNxsGrp> RsNxsGrpDataTemporaryList ;
|
||||||
|
typedef t_RsGxsGenericDataTemporaryList<RsNxsMsg> RsNxsMsgDataTemporaryList ;
|
||||||
|
|
||||||
#ifdef UNUSED
|
#ifdef UNUSED
|
||||||
template<class T>
|
template<class T>
|
||||||
class RsGxsMetaDataTemporaryMapVector: public std::vector<T*>
|
class RsGxsMetaDataTemporaryMapVector: public std::vector<T*>
|
||||||
|
@ -2320,6 +2320,7 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
|
|||||||
std::cerr << "(II) Loaded group in new format. ID = " << info.id << std::endl;
|
std::cerr << "(II) Loaded group in new format. ID = " << info.id << std::endl;
|
||||||
groupList[info.id] = info ;
|
groupList[info.id] = info ;
|
||||||
|
|
||||||
|
delete *it ;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
RsPeerBandwidthLimitsItem *pblitem = dynamic_cast<RsPeerBandwidthLimitsItem*>(*it) ;
|
RsPeerBandwidthLimitsItem *pblitem = dynamic_cast<RsPeerBandwidthLimitsItem*>(*it) ;
|
||||||
|
@ -238,7 +238,7 @@ class RsMsgParentId : public RsMessageItem
|
|||||||
class RsMsgSerialiser: public RsServiceSerializer
|
class RsMsgSerialiser: public RsServiceSerializer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsMsgSerialiser(SerializationFlags flags)
|
RsMsgSerialiser(SerializationFlags flags = RsServiceSerializer::SERIALIZATION_FLAG_NONE)
|
||||||
:RsServiceSerializer(RS_SERVICE_TYPE_MSG,RsGenericSerializer::FORMAT_BINARY,flags){}
|
:RsServiceSerializer(RS_SERVICE_TYPE_MSG,RsGenericSerializer::FORMAT_BINARY,flags){}
|
||||||
|
|
||||||
virtual ~RsMsgSerialiser() {}
|
virtual ~RsMsgSerialiser() {}
|
||||||
|
@ -2047,7 +2047,7 @@ bool p3GxsCircles::processMembershipRequests(uint32_t token)
|
|||||||
#ifdef DEBUG_CIRCLES
|
#ifdef DEBUG_CIRCLES
|
||||||
std::cerr << "Processing circle membership requests." << std::endl;
|
std::cerr << "Processing circle membership requests." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
RsGxsMetaDataTemporaryMapVector<RsGxsMsgItem> msgItems;
|
t_RsGxsGenericDataTemporaryMapVector<RsGxsMsgItem> msgItems;
|
||||||
|
|
||||||
if(!RsGenExchange::getMsgData(token, msgItems))
|
if(!RsGenExchange::getMsgData(token, msgItems))
|
||||||
{
|
{
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Not thread safe!!
|
* Not thread safe!!
|
||||||
|
* And also has a memory leak. Do not use (csoler, 24 Jul 2017).
|
||||||
*/
|
*/
|
||||||
template<class T>
|
template<class T>
|
||||||
class RsSharedPtr
|
class RsSharedPtr
|
||||||
|
@ -23,6 +23,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
BWGraphSource() ;
|
BWGraphSource() ;
|
||||||
|
virtual ~BWGraphSource() {}
|
||||||
|
|
||||||
enum { SELECTOR_TYPE_FRIEND=0x00, SELECTOR_TYPE_SERVICE=0x01 };
|
enum { SELECTOR_TYPE_FRIEND=0x00, SELECTOR_TYPE_SERVICE=0x01 };
|
||||||
enum { GRAPH_TYPE_SINGLE=0x00, GRAPH_TYPE_ALL=0x01, GRAPH_TYPE_SUM=0x02 };
|
enum { GRAPH_TYPE_SINGLE=0x00, GRAPH_TYPE_ALL=0x01, GRAPH_TYPE_SUM=0x02 };
|
||||||
|
@ -151,7 +151,7 @@ void init_item(RsGxsMsgMetaData* metaMsg)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
RsSerialType* init_item(RsNxsGrp& nxg)
|
void init_item(RsNxsGrp& nxg,RsSerialType **ser)
|
||||||
{
|
{
|
||||||
nxg.clear();
|
nxg.clear();
|
||||||
|
|
||||||
@ -160,11 +160,12 @@ RsSerialType* init_item(RsNxsGrp& nxg)
|
|||||||
init_item(nxg.grp);
|
init_item(nxg.grp);
|
||||||
init_item(nxg.meta);
|
init_item(nxg.meta);
|
||||||
|
|
||||||
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
if(ser)
|
||||||
|
*ser = new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RsSerialType* init_item(RsNxsMsg& nxm)
|
void init_item(RsNxsMsg& nxm,RsSerialType **ser)
|
||||||
{
|
{
|
||||||
nxm.clear();
|
nxm.clear();
|
||||||
|
|
||||||
@ -174,20 +175,22 @@ RsSerialType* init_item(RsNxsMsg& nxm)
|
|||||||
init_item(nxm.meta);
|
init_item(nxm.meta);
|
||||||
nxm.transactionNumber = rand()%23;
|
nxm.transactionNumber = rand()%23;
|
||||||
|
|
||||||
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
if(ser)
|
||||||
|
*ser = new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
RsSerialType* init_item(RsNxsSyncGrpReqItem& rsg)
|
void init_item(RsNxsSyncGrpReqItem& rsg,RsSerialType **ser)
|
||||||
{
|
{
|
||||||
rsg.clear();
|
rsg.clear();
|
||||||
rsg.flag = RsNxsSyncGrpItem::FLAG_USE_SYNC_HASH;
|
rsg.flag = RsNxsSyncGrpItem::FLAG_USE_SYNC_HASH;
|
||||||
rsg.createdSince = rand()%2423;
|
rsg.createdSince = rand()%2423;
|
||||||
randString(3124,rsg.syncHash);
|
randString(3124,rsg.syncHash);
|
||||||
|
|
||||||
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
if(ser)
|
||||||
|
*ser = new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
RsSerialType* init_item(RsNxsSyncMsgReqItem& rsgm)
|
void init_item(RsNxsSyncMsgReqItem& rsgm,RsSerialType **ser)
|
||||||
{
|
{
|
||||||
rsgm.clear();
|
rsgm.clear();
|
||||||
|
|
||||||
@ -197,10 +200,11 @@ RsSerialType* init_item(RsNxsSyncMsgReqItem& rsgm)
|
|||||||
init_random(rsgm.grpId) ;
|
init_random(rsgm.grpId) ;
|
||||||
randString(SHORT_STR, rsgm.syncHash);
|
randString(SHORT_STR, rsgm.syncHash);
|
||||||
|
|
||||||
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
if(ser)
|
||||||
|
*ser = new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
RsSerialType* init_item(RsNxsSyncGrpItem& rsgl)
|
void init_item(RsNxsSyncGrpItem& rsgl,RsSerialType **ser)
|
||||||
{
|
{
|
||||||
rsgl.clear();
|
rsgl.clear();
|
||||||
|
|
||||||
@ -209,10 +213,11 @@ RsSerialType* init_item(RsNxsSyncGrpItem& rsgl)
|
|||||||
rsgl.publishTs = rand()%23;
|
rsgl.publishTs = rand()%23;
|
||||||
init_random(rsgl.grpId) ;
|
init_random(rsgl.grpId) ;
|
||||||
|
|
||||||
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
if(ser)
|
||||||
|
*ser = new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
RsSerialType* init_item(RsNxsSyncMsgItem& rsgml)
|
void init_item(RsNxsSyncMsgItem& rsgml,RsSerialType **ser)
|
||||||
{
|
{
|
||||||
rsgml.clear();
|
rsgml.clear();
|
||||||
|
|
||||||
@ -221,11 +226,12 @@ RsSerialType* init_item(RsNxsSyncMsgItem& rsgml)
|
|||||||
init_random(rsgml.grpId) ;
|
init_random(rsgml.grpId) ;
|
||||||
init_random(rsgml.msgId) ;
|
init_random(rsgml.msgId) ;
|
||||||
|
|
||||||
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
if(ser)
|
||||||
|
*ser = new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
RsSerialType* init_item(RsNxsTransacItem &rstx){
|
void init_item(RsNxsTransacItem &rstx,RsSerialType **ser)
|
||||||
|
{
|
||||||
rstx.clear();
|
rstx.clear();
|
||||||
|
|
||||||
rstx.timestamp = rand()%14141;
|
rstx.timestamp = rand()%14141;
|
||||||
@ -233,7 +239,8 @@ RsSerialType* init_item(RsNxsTransacItem &rstx){
|
|||||||
rstx.nItems = rand()%33132;
|
rstx.nItems = rand()%33132;
|
||||||
rstx.transactionNumber = rand()%242112;
|
rstx.transactionNumber = rand()%242112;
|
||||||
|
|
||||||
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
if(ser)
|
||||||
|
*ser = new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,13 +21,13 @@ void init_item(RsGxsGrpMetaData* metaGrp);
|
|||||||
void init_item(RsGxsMsgMetaData* metaMsg);
|
void init_item(RsGxsMsgMetaData* metaMsg);
|
||||||
|
|
||||||
|
|
||||||
RsSerialType* init_item(RsNxsGrp& nxg);
|
void init_item(RsNxsGrp& nxg ,RsSerialType ** = NULL);
|
||||||
RsSerialType* init_item(RsNxsMsg& nxm);
|
void init_item(RsNxsMsg& nxm ,RsSerialType ** = NULL);
|
||||||
RsSerialType* init_item(RsNxsSyncGrpReqItem &rsg);
|
void init_item(RsNxsSyncGrpReqItem &rsg ,RsSerialType ** = NULL);
|
||||||
RsSerialType* init_item(RsNxsSyncMsgReqItem &rsgm);
|
void init_item(RsNxsSyncMsgReqItem &rsgm,RsSerialType ** = NULL);
|
||||||
RsSerialType* init_item(RsNxsSyncGrpItem& rsgl);
|
void init_item(RsNxsSyncGrpItem& rsgl ,RsSerialType ** = NULL);
|
||||||
RsSerialType* init_item(RsNxsSyncMsgItem& rsgml);
|
void init_item(RsNxsSyncMsgItem& rsgml ,RsSerialType ** = NULL);
|
||||||
RsSerialType* init_item(RsNxsTransacItem& rstx);
|
void init_item(RsNxsTransacItem& rstx ,RsSerialType ** = NULL);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void copy_all_but(T& ex, const std::list<T>& s, std::list<T>& d)
|
void copy_all_but(T& ex, const std::list<T>& s, std::list<T>& d)
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "libretroshare/gxs/common/data_support.h"
|
#include "libretroshare/gxs/common/data_support.h"
|
||||||
#include "rsdataservice_test.h"
|
#include "rsdataservice_test.h"
|
||||||
#include "gxs/rsgds.h"
|
#include "gxs/rsgds.h"
|
||||||
|
#include "gxs/rsgxsutil.h"
|
||||||
#include "gxs/rsdataservice.h"
|
#include "gxs/rsdataservice.h"
|
||||||
|
|
||||||
#define DATA_BASE_NAME "msg_grp_Store"
|
#define DATA_BASE_NAME "msg_grp_Store"
|
||||||
@ -35,46 +36,38 @@ void test_groupStoreAndRetrieve(){
|
|||||||
setUp();
|
setUp();
|
||||||
|
|
||||||
int nGrp = rand()%32;
|
int nGrp = rand()%32;
|
||||||
std::map<RsNxsGrp*, RsGxsGrpMetaData*> grps, grps_copy;
|
RsNxsGrpDataTemporaryList grps, grps_copy;
|
||||||
RsNxsGrp* grp;
|
RsNxsGrp* grp;
|
||||||
RsGxsGrpMetaData* grpMeta;
|
RsGxsGrpMetaData* grpMeta;
|
||||||
for(int i = 0; i < nGrp; i++){
|
|
||||||
std::pair<RsNxsGrp*, RsGxsGrpMetaData*> p;
|
for(int i = 0; i < nGrp; i++)
|
||||||
grp = new RsNxsGrp(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
{
|
||||||
grpMeta = new RsGxsGrpMetaData();
|
std::pair<RsNxsGrp*, RsGxsGrpMetaData*> p;
|
||||||
p.first = grp;
|
grp = new RsNxsGrp(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||||
p.second = grpMeta;
|
grpMeta = new RsGxsGrpMetaData();
|
||||||
init_item(*grp);
|
|
||||||
init_item(grpMeta);
|
init_item(*grp);
|
||||||
grpMeta->mGroupId = grp->grpId;
|
init_item(grpMeta);
|
||||||
grps.insert(p);
|
|
||||||
RsNxsGrp* grp_copy = new RsNxsGrp(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
grpMeta->mGroupId = grp->grpId;
|
||||||
*grp_copy = *grp;
|
grp->metaData = grpMeta ;
|
||||||
RsGxsGrpMetaData* grpMeta_copy = new RsGxsGrpMetaData();
|
|
||||||
*grpMeta_copy = *grpMeta;
|
grps.push_back(grp);
|
||||||
grps_copy.insert(std::make_pair(grp_copy, grpMeta_copy ));
|
}
|
||||||
grpMeta = NULL;
|
|
||||||
grp = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
dStore->storeGroup(grps);
|
dStore->storeGroup(grps);
|
||||||
|
|
||||||
//use copy, a grps are deleted in store
|
RsNxsGrpDataTemporaryMap gR;
|
||||||
grps.clear();
|
RsGxsGrpMetaTemporaryMap grpMetaR;
|
||||||
grps = grps_copy;
|
|
||||||
|
|
||||||
std::map<RsGxsGroupId, RsNxsGrp*> gR;
|
|
||||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMetaR;
|
|
||||||
dStore->retrieveNxsGrps(gR, false, false);
|
dStore->retrieveNxsGrps(gR, false, false);
|
||||||
dStore->retrieveGxsGrpMetaData(grpMetaR);
|
dStore->retrieveGxsGrpMetaData(grpMetaR);
|
||||||
|
|
||||||
std::map<RsNxsGrp*, RsGxsGrpMetaData*>::iterator mit = grps.begin();
|
|
||||||
|
|
||||||
bool grpMatch = true, grpMetaMatch = true;
|
bool grpMatch = true, grpMetaMatch = true;
|
||||||
|
|
||||||
for(; mit != grps.end(); mit++)
|
for( std::list<RsNxsGrp*>::iterator mit = grps.begin(); mit != grps.end(); mit++)
|
||||||
{
|
{
|
||||||
const RsGxsGroupId grpId = mit->first->grpId;
|
const RsGxsGroupId grpId = (*mit)->metaData->mGroupId;
|
||||||
|
|
||||||
// check if it exists
|
// check if it exists
|
||||||
if(gR.find(grpId) == gR.end()) {
|
if(gR.find(grpId) == gR.end()) {
|
||||||
@ -82,8 +75,8 @@ void test_groupStoreAndRetrieve(){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
RsNxsGrp *l = mit->first,
|
RsNxsGrp *l = *mit;
|
||||||
*r = gR[grpId];
|
RsNxsGrp *r = gR[grpId];
|
||||||
|
|
||||||
// assign transaction number
|
// assign transaction number
|
||||||
// to right to as tn is not stored
|
// to right to as tn is not stored
|
||||||
@ -104,7 +97,7 @@ void test_groupStoreAndRetrieve(){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
RsGxsGrpMetaData *l_Meta = mit->second,
|
RsGxsGrpMetaData *l_Meta = (*mit)->metaData,
|
||||||
*r_Meta = grpMetaR[grpId];
|
*r_Meta = grpMetaR[grpId];
|
||||||
|
|
||||||
// assign signSet and mGrpSize
|
// assign signSet and mGrpSize
|
||||||
@ -118,12 +111,6 @@ void test_groupStoreAndRetrieve(){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* release resources */
|
|
||||||
delete l_Meta;
|
|
||||||
delete r_Meta;
|
|
||||||
delete l;
|
|
||||||
delete r;
|
|
||||||
|
|
||||||
remove(grpId.toStdString().c_str());
|
remove(grpId.toStdString().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,15 +137,18 @@ void test_messageStoresAndRetrieve()
|
|||||||
grpV.push_back(grpId0);
|
grpV.push_back(grpId0);
|
||||||
grpV.push_back(grpId1);
|
grpV.push_back(grpId1);
|
||||||
|
|
||||||
std::map<RsNxsMsg*, RsGxsMsgMetaData*> msgs;
|
RsNxsMsgDataTemporaryList msgs;
|
||||||
std::map<RsNxsMsg*, RsGxsMsgMetaData*> msgs_copy;
|
|
||||||
RsNxsMsg* msg = NULL;
|
RsNxsMsg* msg = NULL;
|
||||||
RsGxsMsgMetaData* msgMeta = NULL;
|
RsGxsMsgMetaData* msgMeta = NULL;
|
||||||
int nMsgs = rand()%120;
|
int nMsgs = rand()%120;
|
||||||
GxsMsgReq req;
|
GxsMsgReq req;
|
||||||
|
|
||||||
std::map<RsGxsMessageId, RsNxsMsg*> VergrpId0, VergrpId1;
|
// These ones are not in auto-delete structures because the data is deleted as part of the RsNxsMsg struct in the msgs list.
|
||||||
std::map<RsGxsMessageId, RsGxsMsgMetaData*> VerMetagrpId0, VerMetagrpId1;
|
std::map<RsGxsMessageId,RsNxsMsg*> VergrpId0 ;
|
||||||
|
std::map<RsGxsMessageId,RsNxsMsg*> VergrpId1 ;
|
||||||
|
|
||||||
|
std::map<RsGxsMessageId, RsGxsMsgMetaData*> VerMetagrpId0;
|
||||||
|
std::map<RsGxsMessageId, RsGxsMsgMetaData*> VerMetagrpId1;
|
||||||
|
|
||||||
for(int i=0; i<nMsgs; i++)
|
for(int i=0; i<nMsgs; i++)
|
||||||
{
|
{
|
||||||
@ -166,6 +156,9 @@ void test_messageStoresAndRetrieve()
|
|||||||
msgMeta = new RsGxsMsgMetaData();
|
msgMeta = new RsGxsMsgMetaData();
|
||||||
init_item(*msg);
|
init_item(*msg);
|
||||||
init_item(msgMeta);
|
init_item(msgMeta);
|
||||||
|
|
||||||
|
msg->metaData = msgMeta ;
|
||||||
|
|
||||||
std::pair<RsNxsMsg*, RsGxsMsgMetaData*> p(msg, msgMeta);
|
std::pair<RsNxsMsg*, RsGxsMsgMetaData*> p(msg, msgMeta);
|
||||||
int chosen = 0;
|
int chosen = 0;
|
||||||
if(rand()%50 > 24){
|
if(rand()%50 > 24){
|
||||||
@ -181,15 +174,9 @@ void test_messageStoresAndRetrieve()
|
|||||||
msgMeta->mMsgId = msg->msgId;
|
msgMeta->mMsgId = msg->msgId;
|
||||||
msgMeta->mGroupId = msg->grpId = grpId;
|
msgMeta->mGroupId = msg->grpId = grpId;
|
||||||
|
|
||||||
RsNxsMsg* msg_copy = new RsNxsMsg(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
|
||||||
RsGxsMsgMetaData* msgMeta_copy = new RsGxsMsgMetaData();
|
|
||||||
|
|
||||||
*msg_copy = *msg;
|
|
||||||
*msgMeta_copy = *msgMeta;
|
|
||||||
|
|
||||||
// store msgs in map to use for verification
|
// store msgs in map to use for verification
|
||||||
std::pair<RsGxsMessageId, RsNxsMsg*> vP(msg->msgId, msg_copy);
|
std::pair<RsGxsMessageId, RsNxsMsg*> vP(msg->msgId, msg);
|
||||||
std::pair<RsGxsMessageId, RsGxsMsgMetaData*> vPmeta(msg->msgId, msgMeta_copy);
|
std::pair<RsGxsMessageId, RsGxsMsgMetaData*> vPmeta(msg->msgId, msgMeta);
|
||||||
|
|
||||||
if(!chosen)
|
if(!chosen)
|
||||||
{
|
{
|
||||||
@ -203,27 +190,20 @@ void test_messageStoresAndRetrieve()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
msgs.push_back(msg);
|
||||||
msg = NULL;
|
|
||||||
msgMeta = NULL;
|
|
||||||
|
|
||||||
msgs.insert(p);
|
|
||||||
msgs_copy.insert(std::make_pair(msg_copy, msgMeta_copy));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
req[grpV[0]] = std::vector<RsGxsMessageId>(); // assign empty list for other
|
req[grpV[0]] = std::vector<RsGxsMessageId>(); // assign empty list for other
|
||||||
|
|
||||||
dStore->storeMessage(msgs);
|
dStore->storeMessage(msgs);
|
||||||
msgs.clear();
|
|
||||||
msgs = msgs_copy;
|
|
||||||
|
|
||||||
// now retrieve msgs for comparison
|
// now retrieve msgs for comparison
|
||||||
// first selective retrieval
|
// first selective retrieval
|
||||||
|
|
||||||
GxsMsgResult msgResult;
|
t_RsGxsGenericDataTemporaryMapVector<RsNxsMsg> msgResult ; //GxsMsgResult msgResult;. The temporary version cleans up itself.
|
||||||
GxsMsgMetaResult msgMetaResult;
|
t_RsGxsGenericDataTemporaryMapVector<RsGxsMsgMetaData> msgMetaResult ;
|
||||||
dStore->retrieveNxsMsgs(req, msgResult, false);
|
|
||||||
|
|
||||||
|
dStore->retrieveNxsMsgs(req, msgResult, false);
|
||||||
dStore->retrieveGxsMsgMetaData(req, msgMetaResult);
|
dStore->retrieveGxsMsgMetaData(req, msgMetaResult);
|
||||||
|
|
||||||
// now look at result for grpId 1
|
// now look at result for grpId 1
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
#include "genexchangetestservice.h"
|
#include "genexchangetestservice.h"
|
||||||
|
|
||||||
GenExchangeTestService::GenExchangeTestService(RsGeneralDataService *dataServ, RsNetworkExchangeService * netService,
|
GenExchangeTestService::GenExchangeTestService(RsGeneralDataService *dataServ, RsNetworkExchangeService * netService, RsGixs* gixs)
|
||||||
RsGixs* gixs)
|
: RsGenExchange(dataServ, netService, mSerializer = new RsDummySerialiser(), RS_SERVICE_TYPE_DUMMY, gixs, 0)
|
||||||
: RsGenExchange(dataServ, netService, new RsDummySerialiser(), RS_SERVICE_TYPE_DUMMY, gixs, 0)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GenExchangeTestService::~GenExchangeTestService()
|
||||||
|
{
|
||||||
|
delete mSerializer ;
|
||||||
|
}
|
||||||
RsServiceInfo GenExchangeTestService::getServiceInfo()
|
RsServiceInfo GenExchangeTestService::getServiceInfo()
|
||||||
{
|
{
|
||||||
RsServiceInfo info;
|
RsServiceInfo info;
|
||||||
|
@ -11,6 +11,7 @@ class GenExchangeTestService : public RsGenExchange
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GenExchangeTestService(RsGeneralDataService* dataServ, RsNetworkExchangeService* nxs, RsGixs* gixs);
|
GenExchangeTestService(RsGeneralDataService* dataServ, RsNetworkExchangeService* nxs, RsGixs* gixs);
|
||||||
|
virtual ~GenExchangeTestService();
|
||||||
|
|
||||||
void notifyChanges(std::vector<RsGxsNotify*>& changes);
|
void notifyChanges(std::vector<RsGxsNotify*>& changes);
|
||||||
|
|
||||||
@ -104,6 +105,7 @@ public:
|
|||||||
|
|
||||||
void service_tick();
|
void service_tick();
|
||||||
|
|
||||||
|
RsSerialType *mSerializer ;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GENEXCHANGETESTSERVICE_H
|
#endif // GENEXCHANGETESTSERVICE_H
|
||||||
|
@ -39,6 +39,8 @@ TEST(libretroshare_gxs, DISABLED_RsGenExchange)
|
|||||||
|
|
||||||
//GxsPublishMsgTest testMsgPublishing(&testService, dataStore);
|
//GxsPublishMsgTest testMsgPublishing(&testService, dataStore);
|
||||||
//testMsgPublishing.runTests();
|
//testMsgPublishing.runTests();
|
||||||
|
|
||||||
|
//delete dataStore ; // deleted as a member of RsGenExchange
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(libretroshare_gxs, GetStats)
|
TEST(libretroshare_gxs, GetStats)
|
||||||
@ -54,4 +56,6 @@ TEST(libretroshare_gxs, GetStats)
|
|||||||
|
|
||||||
//GxsPublishMsgTest testMsgPublishing(&testService, dataStore);
|
//GxsPublishMsgTest testMsgPublishing(&testService, dataStore);
|
||||||
//testMsgPublishing.runTests();
|
//testMsgPublishing.runTests();
|
||||||
|
|
||||||
|
//delete dataStore ; // deleted as a member of RsGenExchange
|
||||||
}
|
}
|
||||||
|
@ -82,8 +82,8 @@ NxsGrpSync::NxsGrpSync(RsGcxs* circle, RsGixsReputation* reputation):
|
|||||||
|
|
||||||
RsGxsGroupId grpId = grp->grpId;
|
RsGxsGroupId grpId = grp->grpId;
|
||||||
|
|
||||||
RsGeneralDataService::GrpStoreMap gsp;
|
RsNxsGrpDataTemporaryList gsp;
|
||||||
gsp.insert(std::make_pair(grp, meta));
|
gsp.push_back(grp);
|
||||||
mit->second->storeGroup(gsp);
|
mit->second->storeGroup(gsp);
|
||||||
|
|
||||||
// the expected result is that each peer has the group of the others
|
// the expected result is that each peer has the group of the others
|
||||||
|
@ -17,6 +17,20 @@
|
|||||||
|
|
||||||
using namespace rs_nxs_test;
|
using namespace rs_nxs_test;
|
||||||
|
|
||||||
|
rs_nxs_test::NxsMsgSync::~NxsMsgSync()
|
||||||
|
{
|
||||||
|
for(std::map<RsPeerId,RsNxsNetMgr*>::const_iterator it(mNxsNetMgrs.begin());it!=mNxsNetMgrs.end();++it)
|
||||||
|
delete it->second ;
|
||||||
|
|
||||||
|
for(DataMap::const_iterator it(mDataServices.begin());it!=mDataServices.end();++it)
|
||||||
|
delete it->second ;
|
||||||
|
|
||||||
|
delete mRep ;
|
||||||
|
delete mCircles;
|
||||||
|
delete mPgpUtils;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
rs_nxs_test::NxsMsgSync::NxsMsgSync()
|
rs_nxs_test::NxsMsgSync::NxsMsgSync()
|
||||||
: mPgpUtils(NULL), mServType(0) {
|
: mPgpUtils(NULL), mServType(0) {
|
||||||
int numPeers = 2;
|
int numPeers = 2;
|
||||||
@ -79,8 +93,8 @@ rs_nxs_test::NxsMsgSync::NxsMsgSync()
|
|||||||
// first store grp
|
// first store grp
|
||||||
RsGeneralDataService* ds = mit->second;
|
RsGeneralDataService* ds = mit->second;
|
||||||
RsNxsGrp* grp_clone = grp->clone();
|
RsNxsGrp* grp_clone = grp->clone();
|
||||||
RsGeneralDataService::GrpStoreMap gsp;
|
RsNxsGrpDataTemporaryList gsp;
|
||||||
gsp.insert(std::make_pair(grp_clone, grp_clone->metaData));
|
gsp.push_back(grp_clone);
|
||||||
ds->storeGroup(gsp);
|
ds->storeGroup(gsp);
|
||||||
|
|
||||||
RsGxsGroupId grpId = grp->grpId;
|
RsGxsGroupId grpId = grp->grpId;
|
||||||
@ -95,10 +109,12 @@ rs_nxs_test::NxsMsgSync::NxsMsgSync()
|
|||||||
msg->grpId = grp->grpId;
|
msg->grpId = grp->grpId;
|
||||||
RsGxsMsgMetaData* msgMeta = new RsGxsMsgMetaData();
|
RsGxsMsgMetaData* msgMeta = new RsGxsMsgMetaData();
|
||||||
init_item(msgMeta);
|
init_item(msgMeta);
|
||||||
|
msg->metaData = msgMeta;
|
||||||
msgMeta->mGroupId = grp->grpId;
|
msgMeta->mGroupId = grp->grpId;
|
||||||
msgMeta->mMsgId = msg->msgId;
|
msgMeta->mMsgId = msg->msgId;
|
||||||
RsGeneralDataService::MsgStoreMap msm;
|
|
||||||
msm.insert(std::make_pair(msg , msgMeta));
|
RsNxsMsgDataTemporaryList msm;
|
||||||
|
msm.push_back(msg);
|
||||||
RsGxsMessageId msgId = msg->msgId;
|
RsGxsMessageId msgId = msg->msgId;
|
||||||
ds->storeMessage(msm);
|
ds->storeMessage(msm);
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ namespace rs_nxs_test {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
NxsMsgSync();
|
NxsMsgSync();
|
||||||
|
virtual ~NxsMsgSync();
|
||||||
void getPeers(std::list<RsPeerId>& peerIds);
|
void getPeers(std::list<RsPeerId>& peerIds);
|
||||||
RsGeneralDataService* getDataService(const RsPeerId& peerId);
|
RsGeneralDataService* getDataService(const RsPeerId& peerId);
|
||||||
RsNxsNetMgr* getDummyNetManager(const RsPeerId& peerId);
|
RsNxsNetMgr* getDummyNetManager(const RsPeerId& peerId);
|
||||||
|
@ -60,7 +60,7 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
rs_nxs_test::NxsTestHub::NxsTestHub(NxsTestScenario::pointer testScenario)
|
rs_nxs_test::NxsTestHub::NxsTestHub(NxsTestScenario *testScenario)
|
||||||
: mTestScenario(testScenario), mMtx("NxsTestHub Mutex")
|
: mTestScenario(testScenario), mMtx("NxsTestHub Mutex")
|
||||||
{
|
{
|
||||||
std::list<RsPeerId> peers;
|
std::list<RsPeerId> peers;
|
||||||
@ -73,31 +73,43 @@ rs_nxs_test::NxsTestHub::NxsTestHub(NxsTestScenario::pointer testScenario)
|
|||||||
|
|
||||||
for(; cit != peers.end(); cit++)
|
for(; cit != peers.end(); cit++)
|
||||||
{
|
{
|
||||||
RsGxsNetService::pointer ns = RsGxsNetService::pointer(
|
NotifyWithPeerId *noti = new NotifyWithPeerId(*cit, *this) ;
|
||||||
new RsGxsNetService(
|
|
||||||
mTestScenario->getServiceType(),
|
|
||||||
mTestScenario->getDataService(*cit),
|
|
||||||
mTestScenario->getDummyNetManager(*cit),
|
|
||||||
new NotifyWithPeerId(*cit, *this),
|
|
||||||
mTestScenario->getServiceInfo(),
|
|
||||||
mTestScenario->getDummyReputations(*cit),
|
|
||||||
mTestScenario->getDummyCircles(*cit),
|
|
||||||
NULL,
|
|
||||||
mTestScenario->getDummyPgpUtils(),
|
|
||||||
true
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
NxsTestHubConnection *connection =
|
mNotifys.push_back(noti) ;
|
||||||
new NxsTestHubConnection(*cit, this);
|
|
||||||
|
RsGxsNetService *ns = new RsGxsNetService(
|
||||||
|
mTestScenario->getServiceType(),
|
||||||
|
mTestScenario->getDataService(*cit),
|
||||||
|
mTestScenario->getDummyNetManager(*cit),
|
||||||
|
noti,
|
||||||
|
mTestScenario->getServiceInfo(),
|
||||||
|
mTestScenario->getDummyReputations(*cit),
|
||||||
|
mTestScenario->getDummyCircles(*cit),
|
||||||
|
NULL,
|
||||||
|
mTestScenario->getDummyPgpUtils(),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
NxsTestHubConnection *connection = new NxsTestHubConnection(*cit, this);
|
||||||
ns->setServiceServer(connection);
|
ns->setServiceServer(connection);
|
||||||
|
|
||||||
|
mConnections.push_back(connection) ;
|
||||||
|
|
||||||
mPeerNxsMap.insert(std::make_pair(*cit, ns));
|
mPeerNxsMap.insert(std::make_pair(*cit, ns));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
rs_nxs_test::NxsTestHub::~NxsTestHub() {
|
rs_nxs_test::NxsTestHub::~NxsTestHub()
|
||||||
|
{
|
||||||
|
for(PeerNxsMap::const_iterator it(mPeerNxsMap.begin());it!=mPeerNxsMap.end();++it)
|
||||||
|
delete it->second ;
|
||||||
|
|
||||||
|
for(std::list<NotifyWithPeerId*>::const_iterator it(mNotifys.begin());it!=mNotifys.end();++it)
|
||||||
|
delete *it ;
|
||||||
|
|
||||||
|
for(std::list<NxsTestHubConnection*>::const_iterator it(mConnections.begin());it!=mConnections.end();++it)
|
||||||
|
delete *it ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -137,7 +149,7 @@ void rs_nxs_test::NxsTestHub::notifyNewMessages(const RsPeerId& pid,
|
|||||||
{
|
{
|
||||||
RS_STACK_MUTEX(mMtx); /***** MTX LOCKED *****/
|
RS_STACK_MUTEX(mMtx); /***** MTX LOCKED *****/
|
||||||
|
|
||||||
std::map<RsNxsMsg*, RsGxsMsgMetaData*> toStore;
|
RsNxsMsgDataTemporaryList toStore;
|
||||||
std::vector<RsNxsMsg*>::iterator it = messages.begin();
|
std::vector<RsNxsMsg*>::iterator it = messages.begin();
|
||||||
for(; it != messages.end(); it++)
|
for(; it != messages.end(); it++)
|
||||||
{
|
{
|
||||||
@ -145,13 +157,17 @@ void rs_nxs_test::NxsTestHub::notifyNewMessages(const RsPeerId& pid,
|
|||||||
RsGxsMsgMetaData* meta = new RsGxsMsgMetaData();
|
RsGxsMsgMetaData* meta = new RsGxsMsgMetaData();
|
||||||
// local meta is not touched by the deserialisation routine
|
// local meta is not touched by the deserialisation routine
|
||||||
// have to initialise it
|
// have to initialise it
|
||||||
|
|
||||||
|
msg->metaData = meta ;
|
||||||
|
|
||||||
meta->mMsgStatus = 0;
|
meta->mMsgStatus = 0;
|
||||||
meta->mMsgSize = 0;
|
meta->mMsgSize = 0;
|
||||||
meta->mChildTs = 0;
|
meta->mChildTs = 0;
|
||||||
meta->recvTS = 0;
|
meta->recvTS = 0;
|
||||||
meta->validated = false;
|
meta->validated = false;
|
||||||
meta->deserialise(msg->meta.bin_data, &(msg->meta.bin_len));
|
meta->deserialise(msg->meta.bin_data, &(msg->meta.bin_len));
|
||||||
toStore.insert(std::make_pair(msg, meta));
|
|
||||||
|
toStore.push_back(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
RsGeneralDataService* ds = mTestScenario->getDataService(pid);
|
RsGeneralDataService* ds = mTestScenario->getDataService(pid);
|
||||||
@ -163,14 +179,15 @@ void rs_nxs_test::NxsTestHub::notifyNewGroups(const RsPeerId& pid, std::vector<R
|
|||||||
{
|
{
|
||||||
RS_STACK_MUTEX(mMtx); /***** MTX LOCKED *****/
|
RS_STACK_MUTEX(mMtx); /***** MTX LOCKED *****/
|
||||||
|
|
||||||
std::map<RsNxsGrp*, RsGxsGrpMetaData*> toStore;
|
RsNxsGrpDataTemporaryList toStore;
|
||||||
std::vector<RsNxsGrp*>::iterator it = groups.begin();
|
std::vector<RsNxsGrp*>::iterator it = groups.begin();
|
||||||
for(; it != groups.end(); it++)
|
for(; it != groups.end(); it++)
|
||||||
{
|
{
|
||||||
RsNxsGrp* grp = *it;
|
RsNxsGrp* grp = *it;
|
||||||
RsGxsGrpMetaData* meta = new RsGxsGrpMetaData();
|
RsGxsGrpMetaData* meta = new RsGxsGrpMetaData();
|
||||||
|
grp->metaData = meta ;
|
||||||
meta->deserialise(grp->meta.bin_data, grp->meta.bin_len);
|
meta->deserialise(grp->meta.bin_data, grp->meta.bin_len);
|
||||||
toStore.insert(std::make_pair(grp, meta));
|
toStore.push_back(grp);
|
||||||
}
|
}
|
||||||
|
|
||||||
RsGeneralDataService* ds = mTestScenario->getDataService(pid);
|
RsGeneralDataService* ds = mTestScenario->getDataService(pid);
|
||||||
@ -227,7 +244,7 @@ void rs_nxs_test::NxsTestHub::data_tick()
|
|||||||
// then tick net services
|
// then tick net services
|
||||||
for(; it != mPeerNxsMap.end(); it++)
|
for(; it != mPeerNxsMap.end(); it++)
|
||||||
{
|
{
|
||||||
RsGxsNetService::pointer s = it->second;
|
RsGxsNetService *s = it->second;
|
||||||
s->tick();
|
s->tick();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,8 @@
|
|||||||
// hence one could envision synchronising between an arbitrary number
|
// hence one could envision synchronising between an arbitrary number
|
||||||
// of peers
|
// of peers
|
||||||
|
|
||||||
|
class NotifyWithPeerId;
|
||||||
|
class NxsTestHubConnection ;
|
||||||
|
|
||||||
namespace rs_nxs_test
|
namespace rs_nxs_test
|
||||||
{
|
{
|
||||||
@ -44,7 +45,7 @@ namespace rs_nxs_test
|
|||||||
* This constructs the test hub
|
* This constructs the test hub
|
||||||
* for a give scenario in mind
|
* for a give scenario in mind
|
||||||
*/
|
*/
|
||||||
NxsTestHub(NxsTestScenario::pointer testScenario);
|
NxsTestHub(NxsTestScenario* testScenario);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* This cleans up what ever testing resources are left
|
* This cleans up what ever testing resources are left
|
||||||
@ -101,13 +102,14 @@ namespace rs_nxs_test
|
|||||||
|
|
||||||
typedef std::pair<RsPeerId, RsRawItem*> PayLoad;
|
typedef std::pair<RsPeerId, RsRawItem*> PayLoad;
|
||||||
|
|
||||||
typedef std::map<RsPeerId, RsGxsNetService::pointer > PeerNxsMap ;
|
typedef std::map<RsPeerId, RsGxsNetService* > PeerNxsMap ;
|
||||||
|
|
||||||
NxsTestScenario::pointer mTestScenario;
|
NxsTestScenario *mTestScenario;
|
||||||
RsMutex mMtx;
|
RsMutex mMtx;
|
||||||
PeerNxsMap mPeerNxsMap;
|
PeerNxsMap mPeerNxsMap;
|
||||||
std::queue<PayLoad> mPayLoad;
|
std::queue<PayLoad> mPayLoad;
|
||||||
|
std::list<NotifyWithPeerId*> mNotifys;
|
||||||
|
std::list<NxsTestHubConnection *> mConnections;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif // NXSTESTHUB_H
|
#endif // NXSTESTHUB_H
|
||||||
|
@ -15,8 +15,7 @@
|
|||||||
// disabled, because it fails after rebase to current master (did not fail in 2015, fails in 2016)
|
// disabled, because it fails after rebase to current master (did not fail in 2015, fails in 2016)
|
||||||
TEST(libretroshare_gxs, DISABLED_gxs_grp_sync)
|
TEST(libretroshare_gxs, DISABLED_gxs_grp_sync)
|
||||||
{
|
{
|
||||||
rs_nxs_test::NxsTestScenario::pointer gsync_test = rs_nxs_test::NxsTestScenario::pointer(
|
rs_nxs_test::NxsTestScenario *gsync_test = new rs_nxs_test::NxsGrpSync();
|
||||||
new rs_nxs_test::NxsGrpSync());
|
|
||||||
rs_nxs_test::NxsTestHub tHub(gsync_test);
|
rs_nxs_test::NxsTestHub tHub(gsync_test);
|
||||||
tHub.StartTest();
|
tHub.StartTest();
|
||||||
|
|
||||||
@ -28,13 +27,13 @@ TEST(libretroshare_gxs, DISABLED_gxs_grp_sync)
|
|||||||
ASSERT_TRUE(tHub.testsPassed());
|
ASSERT_TRUE(tHub.testsPassed());
|
||||||
|
|
||||||
tHub.CleanUpTest();
|
tHub.CleanUpTest();
|
||||||
|
delete gsync_test ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// disabled, not implemented (does currently the same as NxsGrpSync)
|
// disabled, not implemented (does currently the same as NxsGrpSync)
|
||||||
TEST(libretroshare_gxs, DISABLED_gxs_grp_sync_delayed)
|
TEST(libretroshare_gxs, DISABLED_gxs_grp_sync_delayed)
|
||||||
{
|
{
|
||||||
rs_nxs_test::NxsTestScenario::pointer gsync_test = rs_nxs_test::NxsTestScenario::pointer(
|
rs_nxs_test::NxsTestScenario *gsync_test = new rs_nxs_test::NxsGrpSyncDelayed();
|
||||||
new rs_nxs_test::NxsGrpSyncDelayed());
|
|
||||||
rs_nxs_test::NxsTestHub tHub(gsync_test);
|
rs_nxs_test::NxsTestHub tHub(gsync_test);
|
||||||
tHub.StartTest();
|
tHub.StartTest();
|
||||||
|
|
||||||
@ -47,12 +46,12 @@ TEST(libretroshare_gxs, DISABLED_gxs_grp_sync_delayed)
|
|||||||
|
|
||||||
tHub.CleanUpTest();
|
tHub.CleanUpTest();
|
||||||
|
|
||||||
|
delete gsync_test ;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(libretroshare_gxs, gxs_msg_sync)
|
TEST(libretroshare_gxs, gxs_msg_sync)
|
||||||
{
|
{
|
||||||
rs_nxs_test::NxsTestScenario::pointer gsync_test = rs_nxs_test::NxsTestScenario::pointer(
|
rs_nxs_test::NxsTestScenario *gsync_test = new rs_nxs_test::NxsMsgSync();
|
||||||
new rs_nxs_test::NxsMsgSync);
|
|
||||||
rs_nxs_test::NxsTestHub tHub(gsync_test);
|
rs_nxs_test::NxsTestHub tHub(gsync_test);
|
||||||
tHub.StartTest();
|
tHub.StartTest();
|
||||||
|
|
||||||
@ -64,6 +63,7 @@ TEST(libretroshare_gxs, gxs_msg_sync)
|
|||||||
ASSERT_TRUE(tHub.testsPassed());
|
ASSERT_TRUE(tHub.testsPassed());
|
||||||
|
|
||||||
tHub.CleanUpTest();
|
tHub.CleanUpTest();
|
||||||
|
delete gsync_test ;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(libretroshare_gxs, gxs_msg_sync_delayed)
|
TEST(libretroshare_gxs, gxs_msg_sync_delayed)
|
||||||
|
@ -63,7 +63,7 @@ TEST(libretroshare_gxs, GxsSecurity)
|
|||||||
// create some random data and sign it / verify the signature.
|
// create some random data and sign it / verify the signature.
|
||||||
|
|
||||||
uint32_t data_len = 1000 + RSRandom::random_u32()%100 ;
|
uint32_t data_len = 1000 + RSRandom::random_u32()%100 ;
|
||||||
char *data = new char[data_len] ;
|
RsTemporaryMemory data(data_len) ;
|
||||||
|
|
||||||
RSRandom::random_bytes((unsigned char *)data,data_len) ;
|
RSRandom::random_bytes((unsigned char *)data,data_len) ;
|
||||||
|
|
||||||
@ -71,8 +71,8 @@ TEST(libretroshare_gxs, GxsSecurity)
|
|||||||
|
|
||||||
RsTlvKeySignature signature ;
|
RsTlvKeySignature signature ;
|
||||||
|
|
||||||
EXPECT_TRUE(GxsSecurity::getSignature(data,data_len,priv_key,signature) );
|
EXPECT_TRUE(GxsSecurity::getSignature((char*)(unsigned char*)data,data_len,priv_key,signature) );
|
||||||
EXPECT_TRUE(GxsSecurity::validateSignature(data,data_len,pub_key,signature) );
|
EXPECT_TRUE(GxsSecurity::validateSignature((char*)(unsigned char*)data,data_len,pub_key,signature) );
|
||||||
|
|
||||||
std::cerr << " Signature: size=" << signature.signData.bin_len << ", Hash=" << RsDirUtil::sha1sum((const uint8_t*)signature.signData.bin_data,signature.signData.bin_len) << std::endl;
|
std::cerr << " Signature: size=" << signature.signData.bin_len << ", Hash=" << RsDirUtil::sha1sum((const uint8_t*)signature.signData.bin_data,signature.signData.bin_len) << std::endl;
|
||||||
|
|
||||||
@ -95,6 +95,9 @@ TEST(libretroshare_gxs, GxsSecurity)
|
|||||||
//
|
//
|
||||||
EXPECT_TRUE(data_len == outlen2) ;
|
EXPECT_TRUE(data_len == outlen2) ;
|
||||||
EXPECT_TRUE(!memcmp(data,out2,outlen2)) ;
|
EXPECT_TRUE(!memcmp(data,out2,outlen2)) ;
|
||||||
|
|
||||||
|
free(out2) ;
|
||||||
|
free(out) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,11 +38,9 @@ bool operator==(const RsGxsIdGroupItem& it1,const RsGxsIdGroupItem& it2)
|
|||||||
|
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
RsSerialType* init_item(RsGxsIdGroupItem& item)
|
void init_item(RsGxsIdGroupItem& item)
|
||||||
{
|
{
|
||||||
item.mPgpIdSign = "hello";
|
item.mPgpIdSign = "hello";
|
||||||
|
|
||||||
return new RsGxsIdSerialiser();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -50,7 +48,7 @@ TEST(libretroshare_serialiser, RsGxsIdItem)
|
|||||||
{
|
{
|
||||||
for(uint32_t i=0;i<20;++i)
|
for(uint32_t i=0;i<20;++i)
|
||||||
{
|
{
|
||||||
test_RsItem< RsGxsIdGroupItem >();
|
test_RsItem< RsGxsIdGroupItem,RsGxsIdSerialiser >();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,15 +11,14 @@
|
|||||||
#include "rsitems/rsgxsupdateitems.h"
|
#include "rsitems/rsgxsupdateitems.h"
|
||||||
#define RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM 0x0010
|
#define RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM 0x0010
|
||||||
|
|
||||||
RsSerialType* init_item(RsGxsGrpUpdateItem& i)
|
void init_item(RsGxsGrpUpdateItem& i)
|
||||||
{
|
{
|
||||||
i.clear();
|
i.clear();
|
||||||
i.grpUpdateTS = rand()%2424;
|
i.grpUpdateTS = rand()%2424;
|
||||||
i.peerID = RsPeerId::random();
|
i.peerID = RsPeerId::random();
|
||||||
return new RsGxsUpdateSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RsSerialType* init_item(RsGxsMsgUpdateItem& i)
|
void init_item(RsGxsMsgUpdateItem& i)
|
||||||
{
|
{
|
||||||
i.clear();
|
i.clear();
|
||||||
i.peerID = RsPeerId::random();
|
i.peerID = RsPeerId::random();
|
||||||
@ -33,24 +32,19 @@ RsSerialType* init_item(RsGxsMsgUpdateItem& i)
|
|||||||
info.time_stamp = rand()%45;
|
info.time_stamp = rand()%45;
|
||||||
i.msgUpdateInfos[RsGxsGroupId::random()] = info;
|
i.msgUpdateInfos[RsGxsGroupId::random()] = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RsGxsUpdateSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RsSerialType* init_item(RsGxsServerGrpUpdateItem& i)
|
void init_item(RsGxsServerGrpUpdateItem& i)
|
||||||
{
|
{
|
||||||
i.clear();
|
i.clear();
|
||||||
i.grpUpdateTS = rand()%2424;
|
i.grpUpdateTS = rand()%2424;
|
||||||
|
|
||||||
return new RsGxsUpdateSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RsSerialType* init_item(RsGxsServerMsgUpdateItem& i)
|
void init_item(RsGxsServerMsgUpdateItem& i)
|
||||||
{
|
{
|
||||||
i.clear();
|
i.clear();
|
||||||
i.grpId = RsGxsGroupId::random();
|
i.grpId = RsGxsGroupId::random();
|
||||||
i.msgUpdateTS = rand()%4252;
|
i.msgUpdateTS = rand()%4252;
|
||||||
return new RsGxsUpdateSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator ==(const RsGxsGrpUpdateItem& l, const RsGxsGrpUpdateItem& r)
|
bool operator ==(const RsGxsGrpUpdateItem& l, const RsGxsGrpUpdateItem& r)
|
||||||
@ -105,8 +99,8 @@ bool operator ==(const RsGxsServerMsgUpdateItem& l,
|
|||||||
|
|
||||||
TEST(libretroshare_serialiser, RsGxsGrpUpateItem)
|
TEST(libretroshare_serialiser, RsGxsGrpUpateItem)
|
||||||
{
|
{
|
||||||
test_RsItem<RsGxsGrpUpdateItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
test_RsItem<RsGxsGrpUpdateItem,RsGxsUpdateSerialiser>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||||
test_RsItem<RsGxsMsgUpdateItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
test_RsItem<RsGxsMsgUpdateItem,RsGxsUpdateSerialiser>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||||
test_RsItem<RsGxsServerGrpUpdateItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
test_RsItem<RsGxsServerGrpUpdateItem,RsGxsUpdateSerialiser>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||||
test_RsItem<RsGxsServerMsgUpdateItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
test_RsItem<RsGxsServerMsgUpdateItem,RsGxsUpdateSerialiser>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||||
}
|
}
|
||||||
|
@ -33,19 +33,16 @@
|
|||||||
#include "rstlvutil.h"
|
#include "rstlvutil.h"
|
||||||
|
|
||||||
|
|
||||||
RsSerialType* init_item(RsChatMsgItem& cmi)
|
void init_item(RsChatMsgItem& cmi)
|
||||||
{
|
{
|
||||||
cmi.chatFlags = rand()%34;
|
cmi.chatFlags = rand()%34;
|
||||||
cmi.sendTime = rand()%422224;
|
cmi.sendTime = rand()%422224;
|
||||||
randString(LARGE_STR, cmi.message);
|
randString(LARGE_STR, cmi.message);
|
||||||
|
|
||||||
return new RsChatSerialiser();
|
|
||||||
}
|
}
|
||||||
RsSerialType* init_item(RsChatLobbyListRequestItem& )
|
void init_item(RsChatLobbyListRequestItem& )
|
||||||
{
|
{
|
||||||
return new RsChatSerialiser();
|
|
||||||
}
|
}
|
||||||
RsSerialType* init_item(RsChatLobbyListItem& cmi)
|
void init_item(RsChatLobbyListItem& cmi)
|
||||||
{
|
{
|
||||||
int n = rand()%20 ;
|
int n = rand()%20 ;
|
||||||
|
|
||||||
@ -59,41 +56,33 @@ RsSerialType* init_item(RsChatLobbyListItem& cmi)
|
|||||||
info.flags = ChatLobbyFlags(RSRandom::random_u32()%3) ;
|
info.flags = ChatLobbyFlags(RSRandom::random_u32()%3) ;
|
||||||
cmi.lobbies.push_back(info);
|
cmi.lobbies.push_back(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RsChatSerialiser();
|
|
||||||
}
|
}
|
||||||
RsSerialType* init_item(RsChatLobbyMsgItem& cmi)
|
void init_item(RsChatLobbyMsgItem& cmi)
|
||||||
{
|
{
|
||||||
RsSerialType *serial = init_item( *dynamic_cast<RsChatMsgItem*>(&cmi)) ;
|
init_item( *dynamic_cast<RsChatMsgItem*>(&cmi)) ;
|
||||||
|
|
||||||
cmi.msg_id = RSRandom::random_u64() ;
|
cmi.msg_id = RSRandom::random_u64() ;
|
||||||
cmi.lobby_id = RSRandom::random_u64() ;
|
cmi.lobby_id = RSRandom::random_u64() ;
|
||||||
cmi.nick = "My nickname" ;
|
cmi.nick = "My nickname" ;
|
||||||
cmi.parent_msg_id = RSRandom::random_u64() ;
|
cmi.parent_msg_id = RSRandom::random_u64() ;
|
||||||
|
|
||||||
return serial ;
|
|
||||||
}
|
}
|
||||||
RsSerialType *init_item(RsChatLobbyEventItem& cmi)
|
void init_item(RsChatLobbyEventItem& cmi)
|
||||||
{
|
{
|
||||||
cmi.lobby_id = RSRandom::random_u64() ;
|
cmi.lobby_id = RSRandom::random_u64() ;
|
||||||
cmi.msg_id = RSRandom::random_u64() ;
|
cmi.msg_id = RSRandom::random_u64() ;
|
||||||
randString(20, cmi.nick);
|
randString(20, cmi.nick);
|
||||||
cmi.event_type = RSRandom::random_u32()%256 ;
|
cmi.event_type = RSRandom::random_u32()%256 ;
|
||||||
randString(20, cmi.string1);
|
randString(20, cmi.string1);
|
||||||
|
|
||||||
return new RsChatSerialiser();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RsSerialType* init_item(RsChatLobbyInviteItem& cmi)
|
void init_item(RsChatLobbyInviteItem& cmi)
|
||||||
{
|
{
|
||||||
cmi.lobby_id = RSRandom::random_u64() ;
|
cmi.lobby_id = RSRandom::random_u64() ;
|
||||||
cmi.lobby_name = "Name of the lobby" ;
|
cmi.lobby_name = "Name of the lobby" ;
|
||||||
cmi.lobby_topic = "Topic of the lobby" ;
|
cmi.lobby_topic = "Topic of the lobby" ;
|
||||||
|
|
||||||
return new RsChatSerialiser();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RsSerialType* init_item(RsPrivateChatMsgConfigItem& pcmi)
|
void init_item(RsPrivateChatMsgConfigItem& pcmi)
|
||||||
{
|
{
|
||||||
pcmi.configPeerId = RsPeerId::random();
|
pcmi.configPeerId = RsPeerId::random();
|
||||||
pcmi.chatFlags = rand()%34;
|
pcmi.chatFlags = rand()%34;
|
||||||
@ -101,33 +90,27 @@ RsSerialType* init_item(RsPrivateChatMsgConfigItem& pcmi)
|
|||||||
pcmi.sendTime = rand()%422224;
|
pcmi.sendTime = rand()%422224;
|
||||||
randString(LARGE_STR, pcmi.message);
|
randString(LARGE_STR, pcmi.message);
|
||||||
pcmi.recvTime = rand()%344443;
|
pcmi.recvTime = rand()%344443;
|
||||||
|
|
||||||
return new RsChatSerialiser();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RsSerialType* init_item(RsChatStatusItem& csi)
|
void init_item(RsChatStatusItem& csi)
|
||||||
{
|
{
|
||||||
|
|
||||||
randString(SHORT_STR, csi.status_string);
|
randString(SHORT_STR, csi.status_string);
|
||||||
csi.flags = rand()%232;
|
csi.flags = rand()%232;
|
||||||
|
|
||||||
return new RsChatSerialiser();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RsSerialType* init_item(RsChatAvatarItem& cai)
|
void init_item(RsChatAvatarItem& cai)
|
||||||
{
|
{
|
||||||
std::string image_data;
|
std::string image_data;
|
||||||
randString(LARGE_STR, image_data);
|
randString(LARGE_STR, image_data);
|
||||||
cai.image_data = new unsigned char[image_data.size()];
|
cai.image_data = (unsigned char*)malloc(image_data.size());
|
||||||
|
|
||||||
memcpy(cai.image_data, image_data.c_str(), image_data.size());
|
memcpy(cai.image_data, image_data.c_str(), image_data.size());
|
||||||
cai.image_size = image_data.size();
|
cai.image_size = image_data.size();
|
||||||
|
|
||||||
return new RsChatSerialiser();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RsSerialType* init_item(RsMsgItem& mi)
|
void init_item(RsMsgItem& mi)
|
||||||
{
|
{
|
||||||
init_item(mi.attachment);
|
init_item(mi.attachment);
|
||||||
init_item(mi.rspeerid_msgbcc);
|
init_item(mi.rspeerid_msgbcc);
|
||||||
@ -141,21 +124,17 @@ RsSerialType* init_item(RsMsgItem& mi)
|
|||||||
mi.recvTime = rand()%44252;
|
mi.recvTime = rand()%44252;
|
||||||
mi.sendTime = mi.recvTime;
|
mi.sendTime = mi.recvTime;
|
||||||
mi.msgFlags = mi.recvTime;
|
mi.msgFlags = mi.recvTime;
|
||||||
|
|
||||||
return new RsMsgSerialiser(RsServiceSerializer::SERIALIZATION_FLAG_NONE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RsSerialType* init_item(RsMsgTagType& mtt)
|
void init_item(RsMsgTagType& mtt)
|
||||||
{
|
{
|
||||||
mtt.rgb_color = rand()%5353;
|
mtt.rgb_color = rand()%5353;
|
||||||
mtt.tagId = rand()%24242;
|
mtt.tagId = rand()%24242;
|
||||||
randString(SHORT_STR, mtt.text);
|
randString(SHORT_STR, mtt.text);
|
||||||
|
|
||||||
return new RsMsgSerialiser(RsServiceSerializer::SERIALIZATION_FLAG_NONE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RsSerialType* init_item(RsMsgTags& mt)
|
void init_item(RsMsgTags& mt)
|
||||||
{
|
{
|
||||||
mt.msgId = rand()%3334;
|
mt.msgId = rand()%3334;
|
||||||
|
|
||||||
@ -163,24 +142,18 @@ RsSerialType* init_item(RsMsgTags& mt)
|
|||||||
for (i = 0; i < 10; i++) {
|
for (i = 0; i < 10; i++) {
|
||||||
mt.tagIds.push_back(rand()%21341);
|
mt.tagIds.push_back(rand()%21341);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RsMsgSerialiser(RsServiceSerializer::SERIALIZATION_FLAG_NONE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RsSerialType* init_item(RsMsgSrcId& ms)
|
void init_item(RsMsgSrcId& ms)
|
||||||
{
|
{
|
||||||
ms.msgId = rand()%434;
|
ms.msgId = rand()%434;
|
||||||
ms.srcId = RsPeerId::random();
|
ms.srcId = RsPeerId::random();
|
||||||
|
|
||||||
return new RsMsgSerialiser(RsServiceSerializer::SERIALIZATION_FLAG_NONE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RsSerialType* init_item(RsMsgParentId& ms)
|
void init_item(RsMsgParentId& ms)
|
||||||
{
|
{
|
||||||
ms.msgId = rand()%354;
|
ms.msgId = rand()%354;
|
||||||
ms.msgParentId = rand()%476;
|
ms.msgParentId = rand()%476;
|
||||||
|
|
||||||
return new RsMsgSerialiser(RsServiceSerializer::SERIALIZATION_FLAG_NONE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator ==(const struct VisibleChatLobbyInfo& l, const struct VisibleChatLobbyInfo& r)
|
bool operator ==(const struct VisibleChatLobbyInfo& l, const struct VisibleChatLobbyInfo& r)
|
||||||
@ -335,19 +308,19 @@ bool operator ==(const RsMsgParentId& msLeft, const RsMsgParentId& msRight)
|
|||||||
|
|
||||||
TEST(libretroshare_serialiser, RsMsgItem)
|
TEST(libretroshare_serialiser, RsMsgItem)
|
||||||
{
|
{
|
||||||
test_RsItem<RsChatMsgItem >();
|
test_RsItem<RsChatMsgItem ,RsChatSerialiser>();
|
||||||
test_RsItem<RsChatLobbyMsgItem >();
|
test_RsItem<RsChatLobbyMsgItem ,RsChatSerialiser>();
|
||||||
test_RsItem<RsChatLobbyInviteItem >();
|
test_RsItem<RsChatLobbyInviteItem ,RsChatSerialiser>();
|
||||||
test_RsItem<RsChatLobbyEventItem >();
|
test_RsItem<RsChatLobbyEventItem ,RsChatSerialiser>();
|
||||||
test_RsItem<RsChatLobbyListRequestItem >();
|
test_RsItem<RsChatLobbyListRequestItem ,RsChatSerialiser>();
|
||||||
test_RsItem<RsChatLobbyListItem >();
|
test_RsItem<RsChatLobbyListItem ,RsChatSerialiser>();
|
||||||
test_RsItem<RsChatStatusItem >();
|
test_RsItem<RsChatStatusItem ,RsChatSerialiser>();
|
||||||
test_RsItem<RsChatAvatarItem >();
|
test_RsItem<RsChatAvatarItem ,RsChatSerialiser>();
|
||||||
test_RsItem<RsMsgItem >();
|
test_RsItem<RsMsgItem ,RsMsgSerialiser>();
|
||||||
test_RsItem<RsMsgTagType>();
|
test_RsItem<RsMsgTagType ,RsMsgSerialiser>();
|
||||||
test_RsItem<RsMsgTags>();
|
test_RsItem<RsMsgTags ,RsMsgSerialiser>();
|
||||||
test_RsItem<RsMsgSrcId>();
|
test_RsItem<RsMsgSrcId ,RsMsgSerialiser>();
|
||||||
test_RsItem<RsMsgParentId>();
|
test_RsItem<RsMsgParentId ,RsMsgSerialiser>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,11 +10,11 @@
|
|||||||
|
|
||||||
TEST(libretroshare_serialiser, RsNxsItem)
|
TEST(libretroshare_serialiser, RsNxsItem)
|
||||||
{
|
{
|
||||||
test_RsItem<RsNxsGrp>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
test_RsItem<RsNxsGrp,RsNxsSerialiser>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||||
test_RsItem<RsNxsMsg>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
test_RsItem<RsNxsMsg,RsNxsSerialiser>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||||
test_RsItem<RsNxsSyncGrpItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
test_RsItem<RsNxsSyncGrpItem,RsNxsSerialiser>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||||
test_RsItem<RsNxsSyncMsgItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
test_RsItem<RsNxsSyncMsgItem,RsNxsSerialiser>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||||
test_RsItem<RsNxsSyncGrpItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
test_RsItem<RsNxsSyncGrpItem,RsNxsSerialiser>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||||
test_RsItem<RsNxsSyncMsgItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
test_RsItem<RsNxsSyncMsgItem,RsNxsSerialiser>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||||
test_RsItem<RsNxsTransacItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
test_RsItem<RsNxsTransacItem,RsNxsSerialiser>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||||
}
|
}
|
||||||
|
@ -27,12 +27,11 @@
|
|||||||
#include "support.h"
|
#include "support.h"
|
||||||
#include "rsitems/rsstatusitems.h"
|
#include "rsitems/rsstatusitems.h"
|
||||||
|
|
||||||
RsSerialType* init_item(RsStatusItem& rsi)
|
void init_item(RsStatusItem& rsi)
|
||||||
{
|
{
|
||||||
|
|
||||||
rsi.sendTime = rand()%5353;
|
rsi.sendTime = rand()%5353;
|
||||||
rsi.status = rand()%2032;
|
rsi.status = rand()%2032;
|
||||||
return new RsStatusSerialiser();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator ==(RsStatusItem& rsi1, RsStatusItem& rsi2)
|
bool operator ==(RsStatusItem& rsi1, RsStatusItem& rsi2)
|
||||||
@ -48,5 +47,5 @@ bool operator ==(RsStatusItem& rsi1, RsStatusItem& rsi2)
|
|||||||
|
|
||||||
TEST(libretroshare_serialiser, test_RsStatusItem)
|
TEST(libretroshare_serialiser, test_RsStatusItem)
|
||||||
{
|
{
|
||||||
test_RsItem<RsStatusItem >();
|
test_RsItem<RsStatusItem,RsStatusSerialiser >();
|
||||||
}
|
}
|
||||||
|
@ -172,6 +172,8 @@ int test_TlvSet(std::vector<RsTlvItem *> items, int maxsize)
|
|||||||
test_CreateTlvStack(std::cerr, items, data, &size);
|
test_CreateTlvStack(std::cerr, items, data, &size);
|
||||||
test_StepThroughTlvStack(std::cerr, data, size);
|
test_StepThroughTlvStack(std::cerr, data, size);
|
||||||
|
|
||||||
|
free(data) ;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,8 +42,6 @@ RsSerialType* init_item(CompressedChunkMap& map)
|
|||||||
map._map.clear() ;
|
map._map.clear() ;
|
||||||
for(uint32_t i=0;i<15;++i)
|
for(uint32_t i=0;i<15;++i)
|
||||||
map._map.push_back(rand()) ;
|
map._map.push_back(rand()) ;
|
||||||
|
|
||||||
return new RsTurtleSerialiser();
|
|
||||||
}
|
}
|
||||||
bool operator==(const CompressedChunkMap& m1,const CompressedChunkMap& m2)
|
bool operator==(const CompressedChunkMap& m1,const CompressedChunkMap& m2)
|
||||||
{
|
{
|
||||||
@ -62,11 +60,10 @@ bool operator==(const RsTurtleFileMapRequestItem& it1,const RsTurtleFileMapReque
|
|||||||
|
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
RsSerialType* init_item(RsTurtleFileMapRequestItem& item)
|
void init_item(RsTurtleFileMapRequestItem& item)
|
||||||
{
|
{
|
||||||
item.direction = 1 ;
|
item.direction = 1 ;
|
||||||
item.tunnel_id = 0x4ff823e2 ;
|
item.tunnel_id = 0x4ff823e2 ;
|
||||||
return new RsTurtleSerialiser();
|
|
||||||
}
|
}
|
||||||
bool operator==(const RsTurtleFileMapItem& it1,const RsTurtleFileMapItem& it2)
|
bool operator==(const RsTurtleFileMapItem& it1,const RsTurtleFileMapItem& it2)
|
||||||
{
|
{
|
||||||
@ -76,14 +73,13 @@ bool operator==(const RsTurtleFileMapItem& it1,const RsTurtleFileMapItem& it2)
|
|||||||
|
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
RsSerialType* init_item(RsTurtleFileMapItem& item)
|
void init_item(RsTurtleFileMapItem& item)
|
||||||
{
|
{
|
||||||
item.direction = 1 ;
|
item.direction = 1 ;
|
||||||
item.tunnel_id = 0xf48fe232 ;
|
item.tunnel_id = 0xf48fe232 ;
|
||||||
init_item(item.compressed_map) ;
|
init_item(item.compressed_map) ;
|
||||||
return new RsTurtleSerialiser();
|
|
||||||
}
|
}
|
||||||
RsSerialType* init_item(RsTurtleFileDataItem& item)
|
void init_item(RsTurtleFileDataItem& item)
|
||||||
{
|
{
|
||||||
static const uint32_t S = 3456 ;
|
static const uint32_t S = 3456 ;
|
||||||
item.tunnel_id = 0x33eef982 ;
|
item.tunnel_id = 0x33eef982 ;
|
||||||
@ -92,7 +88,6 @@ RsSerialType* init_item(RsTurtleFileDataItem& item)
|
|||||||
item.chunk_data = new unsigned char[S] ;
|
item.chunk_data = new unsigned char[S] ;
|
||||||
for(uint32_t i=0;i<S;++i)
|
for(uint32_t i=0;i<S;++i)
|
||||||
((unsigned char *)item.chunk_data)[i] = rand()%256 ;
|
((unsigned char *)item.chunk_data)[i] = rand()%256 ;
|
||||||
return new RsTurtleSerialiser();
|
|
||||||
}
|
}
|
||||||
bool operator==(const RsTurtleFileDataItem& i1,const RsTurtleFileDataItem& i2)
|
bool operator==(const RsTurtleFileDataItem& i1,const RsTurtleFileDataItem& i2)
|
||||||
{
|
{
|
||||||
@ -104,12 +99,11 @@ bool operator==(const RsTurtleFileDataItem& i1,const RsTurtleFileDataItem& i2)
|
|||||||
return false ;
|
return false ;
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
RsSerialType* init_item(RsTurtleFileRequestItem& item)
|
void init_item(RsTurtleFileRequestItem& item)
|
||||||
{
|
{
|
||||||
item.tunnel_id = rand() ;
|
item.tunnel_id = rand() ;
|
||||||
item.chunk_offset = 0x25ea228437894379ull ;
|
item.chunk_offset = 0x25ea228437894379ull ;
|
||||||
item.chunk_size = rand() ;
|
item.chunk_size = rand() ;
|
||||||
return new RsTurtleSerialiser();
|
|
||||||
}
|
}
|
||||||
bool operator==(const RsTurtleFileRequestItem& it1,const RsTurtleFileRequestItem& it2)
|
bool operator==(const RsTurtleFileRequestItem& it1,const RsTurtleFileRequestItem& it2)
|
||||||
{
|
{
|
||||||
@ -119,11 +113,10 @@ bool operator==(const RsTurtleFileRequestItem& it1,const RsTurtleFileRequestItem
|
|||||||
|
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
RsSerialType* init_item(RsTurtleTunnelOkItem& item)
|
void init_item(RsTurtleTunnelOkItem& item)
|
||||||
{
|
{
|
||||||
item.tunnel_id = rand() ;
|
item.tunnel_id = rand() ;
|
||||||
item.request_id = rand() ;
|
item.request_id = rand() ;
|
||||||
return new RsTurtleSerialiser();
|
|
||||||
}
|
}
|
||||||
bool operator==(const RsTurtleTunnelOkItem& it1,const RsTurtleTunnelOkItem& it2)
|
bool operator==(const RsTurtleTunnelOkItem& it1,const RsTurtleTunnelOkItem& it2)
|
||||||
{
|
{
|
||||||
@ -131,13 +124,12 @@ bool operator==(const RsTurtleTunnelOkItem& it1,const RsTurtleTunnelOkItem& it2)
|
|||||||
if(it1.request_id != it2.request_id) return false ;
|
if(it1.request_id != it2.request_id) return false ;
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
RsSerialType* init_item(RsTurtleOpenTunnelItem& item)
|
void init_item(RsTurtleOpenTunnelItem& item)
|
||||||
{
|
{
|
||||||
item.depth = rand() ;
|
item.depth = rand() ;
|
||||||
item.request_id = rand() ;
|
item.request_id = rand() ;
|
||||||
item.partial_tunnel_id = rand() ;
|
item.partial_tunnel_id = rand() ;
|
||||||
item.file_hash = RsFileHash("c0edcfecc0844ef175d61dd589ab288d262b6bc8") ;
|
item.file_hash = RsFileHash("c0edcfecc0844ef175d61dd589ab288d262b6bc8") ;
|
||||||
return new RsTurtleSerialiser();
|
|
||||||
}
|
}
|
||||||
bool operator==(const RsTurtleOpenTunnelItem& it1,const RsTurtleOpenTunnelItem& it2)
|
bool operator==(const RsTurtleOpenTunnelItem& it1,const RsTurtleOpenTunnelItem& it2)
|
||||||
{
|
{
|
||||||
@ -147,7 +139,7 @@ bool operator==(const RsTurtleOpenTunnelItem& it1,const RsTurtleOpenTunnelItem&
|
|||||||
if(it1.file_hash != it2.file_hash) return false ;
|
if(it1.file_hash != it2.file_hash) return false ;
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
RsSerialType* init_item(RsTurtleRegExpSearchRequestItem& item)
|
void init_item(RsTurtleRegExpSearchRequestItem& item)
|
||||||
{
|
{
|
||||||
item.request_id = rand() ;
|
item.request_id = rand() ;
|
||||||
item.depth = rand() ;
|
item.depth = rand() ;
|
||||||
@ -158,7 +150,6 @@ RsSerialType* init_item(RsTurtleRegExpSearchRequestItem& item)
|
|||||||
for(uint32_t i=0;i<10u;++i) item.expr._tokens.push_back(rand()%8) ;
|
for(uint32_t i=0;i<10u;++i) item.expr._tokens.push_back(rand()%8) ;
|
||||||
for(uint32_t i=0;i<6u;++i) item.expr._ints.push_back(rand()) ;
|
for(uint32_t i=0;i<6u;++i) item.expr._ints.push_back(rand()) ;
|
||||||
for(uint32_t i=0;i<8u;++i) item.expr._strings.push_back("test string") ;
|
for(uint32_t i=0;i<8u;++i) item.expr._strings.push_back("test string") ;
|
||||||
return new RsTurtleSerialiser();
|
|
||||||
}
|
}
|
||||||
bool operator==(const RsTurtleRegExpSearchRequestItem& it1,const RsTurtleRegExpSearchRequestItem& it2)
|
bool operator==(const RsTurtleRegExpSearchRequestItem& it1,const RsTurtleRegExpSearchRequestItem& it2)
|
||||||
{
|
{
|
||||||
@ -172,12 +163,11 @@ bool operator==(const RsTurtleRegExpSearchRequestItem& it1,const RsTurtleRegExpS
|
|||||||
for(uint32_t i=0;i<it1.expr._strings.size();++i) if(it1.expr._strings[i] != it2.expr._strings[i]) return false ;
|
for(uint32_t i=0;i<it1.expr._strings.size();++i) if(it1.expr._strings[i] != it2.expr._strings[i]) return false ;
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
RsSerialType* init_item(RsTurtleStringSearchRequestItem& item)
|
void init_item(RsTurtleStringSearchRequestItem& item)
|
||||||
{
|
{
|
||||||
item.request_id = rand() ;
|
item.request_id = rand() ;
|
||||||
item.depth = rand() ;
|
item.depth = rand() ;
|
||||||
item.match_string = std::string("432hkjfdsjkhjk43r3fw") ;
|
item.match_string = std::string("432hkjfdsjkhjk43r3fw") ;
|
||||||
return new RsTurtleSerialiser();
|
|
||||||
}
|
}
|
||||||
bool operator==(const RsTurtleStringSearchRequestItem& it1,const RsTurtleStringSearchRequestItem& it2)
|
bool operator==(const RsTurtleStringSearchRequestItem& it1,const RsTurtleStringSearchRequestItem& it2)
|
||||||
{
|
{
|
||||||
@ -200,7 +190,7 @@ bool operator==(const TurtleFileInfo& it1,const TurtleFileInfo& it2)
|
|||||||
if(it1.size != it2.size) return false ;
|
if(it1.size != it2.size) return false ;
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
RsSerialType* init_item(RsTurtleSearchResultItem& item)
|
void init_item(RsTurtleSearchResultItem& item)
|
||||||
{
|
{
|
||||||
item.depth = rand() ;
|
item.depth = rand() ;
|
||||||
item.request_id = rand() ;
|
item.request_id = rand() ;
|
||||||
@ -212,7 +202,6 @@ RsSerialType* init_item(RsTurtleSearchResultItem& item)
|
|||||||
init_item(f) ;
|
init_item(f) ;
|
||||||
item.result.push_back(f) ;
|
item.result.push_back(f) ;
|
||||||
}
|
}
|
||||||
return new RsTurtleSerialiser();
|
|
||||||
}
|
}
|
||||||
bool operator==(const RsTurtleSearchResultItem& it1,const RsTurtleSearchResultItem& it2)
|
bool operator==(const RsTurtleSearchResultItem& it1,const RsTurtleSearchResultItem& it2)
|
||||||
{
|
{
|
||||||
@ -237,11 +226,12 @@ TEST(libretroshare_serialiser, RsTurtleItem)
|
|||||||
//test_RsItem<RsTurtleFileMapItem >();
|
//test_RsItem<RsTurtleFileMapItem >();
|
||||||
//test_RsItem<RsTurtleFileDataItem >();
|
//test_RsItem<RsTurtleFileDataItem >();
|
||||||
//test_RsItem<RsTurtleFileRequestItem >();
|
//test_RsItem<RsTurtleFileRequestItem >();
|
||||||
test_RsItem<RsTurtleTunnelOkItem >();
|
|
||||||
test_RsItem<RsTurtleOpenTunnelItem >();
|
test_RsItem<RsTurtleTunnelOkItem ,RsTurtleSerialiser>();
|
||||||
test_RsItem<RsTurtleSearchResultItem >();
|
test_RsItem<RsTurtleOpenTunnelItem ,RsTurtleSerialiser>();
|
||||||
test_RsItem<RsTurtleStringSearchRequestItem >();
|
test_RsItem<RsTurtleSearchResultItem ,RsTurtleSerialiser>();
|
||||||
test_RsItem<RsTurtleRegExpSearchRequestItem >();
|
test_RsItem<RsTurtleStringSearchRequestItem ,RsTurtleSerialiser>();
|
||||||
|
test_RsItem<RsTurtleRegExpSearchRequestItem ,RsTurtleSerialiser>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,15 +100,17 @@ bool operator==(const RsTlvKeySignatureSet& , const RsTlvKeySignatureSet& );
|
|||||||
* @param T the item you want to test
|
* @param T the item you want to test
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template<class T> int test_RsItem()
|
template<class ItemClass,class ItemSerialiser> int test_RsItem()
|
||||||
{
|
{
|
||||||
/* make a serialisable RsTurtleItem */
|
/* make a serialisable RsTurtleItem */
|
||||||
|
|
||||||
RsSerialiser srl;
|
RsSerialiser srl;
|
||||||
|
|
||||||
/* initialise */
|
/* initialise */
|
||||||
T rsfi ;
|
ItemClass rsfi ;
|
||||||
RsSerialType *rsfis = init_item(rsfi) ;
|
RsSerialType *rsfis = new ItemSerialiser;
|
||||||
|
|
||||||
|
init_item(rsfi);
|
||||||
|
|
||||||
/* attempt to serialise it before we add it to the serialiser */
|
/* attempt to serialise it before we add it to the serialiser */
|
||||||
std::cerr << "### These errors are expected." << std::endl;
|
std::cerr << "### These errors are expected." << std::endl;
|
||||||
@ -149,7 +151,7 @@ template<class T> int test_RsItem()
|
|||||||
|
|
||||||
EXPECT_TRUE(sersize2 == sersize);
|
EXPECT_TRUE(sersize2 == sersize);
|
||||||
|
|
||||||
T *outfi = dynamic_cast<T *>(output);
|
ItemClass *outfi = dynamic_cast<ItemClass *>(output);
|
||||||
|
|
||||||
EXPECT_TRUE(outfi != NULL);
|
EXPECT_TRUE(outfi != NULL);
|
||||||
if (!outfi)
|
if (!outfi)
|
||||||
@ -173,23 +175,24 @@ template<class T> int test_RsItem()
|
|||||||
EXPECT_TRUE(done2) ;
|
EXPECT_TRUE(done2) ;
|
||||||
EXPECT_TRUE(sersize2 == sersize);
|
EXPECT_TRUE(sersize2 == sersize);
|
||||||
|
|
||||||
// displayRawPacket(std::cerr, (void *) buffer, 16 * 8 + sersize2);
|
std::cerr << "Deleting output" <<std::endl;
|
||||||
|
delete output ;
|
||||||
delete[] buffer ;
|
delete[] buffer ;
|
||||||
//delete rsfis;
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T> int test_RsItem(uint16_t servtype)
|
template<class ItemClass,class ItemSerialiser> int test_RsItem(uint16_t servtype)
|
||||||
{
|
{
|
||||||
/* make a serialisable RsTurtleItem */
|
/* make a serialisable RsTurtleItem */
|
||||||
|
|
||||||
RsSerialiser srl;
|
RsSerialiser srl;
|
||||||
|
|
||||||
/* initialise */
|
/* initialise */
|
||||||
T rsfi(servtype) ;
|
ItemClass rsfi(servtype) ;
|
||||||
RsSerialType *rsfis = init_item(rsfi) ; // deleted on destruction of srl
|
RsSerialType *rsfis = new ItemSerialiser(servtype) ;
|
||||||
|
|
||||||
|
init_item(rsfi) ; // deleted on destruction of srl
|
||||||
|
|
||||||
/* attempt to serialise it before we add it to the serialiser */
|
/* attempt to serialise it before we add it to the serialiser */
|
||||||
std::cerr << "### These errors are expected." << std::endl;
|
std::cerr << "### These errors are expected." << std::endl;
|
||||||
@ -224,7 +227,7 @@ template<class T> int test_RsItem(uint16_t servtype)
|
|||||||
EXPECT_TRUE(output != NULL);
|
EXPECT_TRUE(output != NULL);
|
||||||
EXPECT_TRUE(sersize2 == sersize);
|
EXPECT_TRUE(sersize2 == sersize);
|
||||||
|
|
||||||
T *outfi = dynamic_cast<T *>(output);
|
ItemClass *outfi = dynamic_cast<ItemClass *>(output);
|
||||||
|
|
||||||
EXPECT_TRUE(outfi != NULL);
|
EXPECT_TRUE(outfi != NULL);
|
||||||
|
|
||||||
@ -240,6 +243,7 @@ template<class T> int test_RsItem(uint16_t servtype)
|
|||||||
// displayRawPacket(std::cerr, (void *) buffer, 16 * 8 + sersize2);
|
// displayRawPacket(std::cerr, (void *) buffer, 16 * 8 + sersize2);
|
||||||
|
|
||||||
delete[] buffer ;
|
delete[] buffer ;
|
||||||
|
delete output ;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -45,8 +45,8 @@ TEST(libretroshare_serialiser, test_RsTlvStack)
|
|||||||
|
|
||||||
/* now create a set of TLV items for the random generator */
|
/* now create a set of TLV items for the random generator */
|
||||||
|
|
||||||
RsTlvBinaryData *bd1 = new RsTlvBinaryData(123);
|
RsTlvBinaryData bd1(123);
|
||||||
RsTlvBinaryData *bd2 = new RsTlvBinaryData(125);
|
RsTlvBinaryData bd2(125);
|
||||||
|
|
||||||
char data[BIN_LEN] = {0};
|
char data[BIN_LEN] = {0};
|
||||||
int i;
|
int i;
|
||||||
@ -55,31 +55,31 @@ TEST(libretroshare_serialiser, test_RsTlvStack)
|
|||||||
data[i] = i%13;
|
data[i] = i%13;
|
||||||
}
|
}
|
||||||
|
|
||||||
bd1->setBinData(data, 5);
|
bd1.setBinData(data, 5);
|
||||||
bd2->setBinData(data, 21);
|
bd2.setBinData(data, 21);
|
||||||
|
|
||||||
RsTlvFileItem *fi1 = new RsTlvFileItem();
|
RsTlvFileItem fi1;
|
||||||
RsTlvFileItem *fi2 = new RsTlvFileItem();
|
RsTlvFileItem fi2;
|
||||||
|
|
||||||
/* initialise */
|
/* initialise */
|
||||||
fi1->filesize = 101010;
|
fi1.filesize = 101010;
|
||||||
fi1->hash = RsFileHash("123456789ABCDEF67890123456789ABCDEF67890");//SHA1_SIZE*2 = 40
|
fi1.hash = RsFileHash("123456789ABCDEF67890123456789ABCDEF67890");//SHA1_SIZE*2 = 40
|
||||||
fi1->name = "TestFile.txt";
|
fi1.name = "TestFile.txt";
|
||||||
fi1->pop = 12;
|
fi1.pop = 12;
|
||||||
fi1->age = 456;
|
fi1.age = 456;
|
||||||
|
|
||||||
fi2->filesize = 101010;
|
fi2.filesize = 101010;
|
||||||
fi2->hash = RsFileHash("123456789ABCDEF67890123456789ABCDEF67890");//SHA1_SIZE*2 = 40
|
fi2.hash = RsFileHash("123456789ABCDEF67890123456789ABCDEF67890");//SHA1_SIZE*2 = 40
|
||||||
fi2->name = "TestFile.txt";
|
fi2.name = "TestFile.txt";
|
||||||
fi2->pop = 0;
|
fi2.pop = 0;
|
||||||
fi2->age = 0;;
|
fi2.age = 0;;
|
||||||
|
|
||||||
std::vector<RsTlvItem *> items;
|
std::vector<RsTlvItem *> items;
|
||||||
items.resize(4);
|
items.resize(4);
|
||||||
items[0] = bd1;
|
items[0] = &bd1;
|
||||||
items[1] = bd2;
|
items[1] = &bd2;
|
||||||
items[2] = fi1;
|
items[2] = &fi1;
|
||||||
items[3] = fi2;
|
items[3] = &fi2;
|
||||||
|
|
||||||
test_TlvSet(items, 1024);
|
test_TlvSet(items, 1024);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user