mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-26 01:31:30 -05:00
added cleanup function to test hub
refined group retrieval for RsDataService also added fix for RsNxsTrasac flag masks added group data send transaction generation, and fix for request generation git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-new_cache_system@5298 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
24f6f874f2
commit
d3e5ec2836
@ -545,10 +545,54 @@ int RsDataService::storeGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
|
|||||||
|
|
||||||
int RsDataService::retrieveNxsGrps(std::map<std::string, RsNxsGrp *> &grp, bool cache){
|
int RsDataService::retrieveNxsGrps(std::map<std::string, RsNxsGrp *> &grp, bool cache){
|
||||||
|
|
||||||
|
if(grp.empty()){
|
||||||
|
|
||||||
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpColumns, "", "");
|
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpColumns, "", "");
|
||||||
|
|
||||||
if(c){
|
if(c)
|
||||||
|
{
|
||||||
|
std::vector<RsNxsGrp*> grps;
|
||||||
|
|
||||||
|
retrieveGroups(c, grps);
|
||||||
|
std::vector<RsNxsGrp*>::iterator vit = grps.begin();
|
||||||
|
|
||||||
|
for(; vit != grps.end(); vit++)
|
||||||
|
{
|
||||||
|
grp[(*vit)->grpId] = *vit;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete c;
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
|
||||||
|
std::map<std::string, RsNxsGrp *>::iterator mit = grp.begin();
|
||||||
|
|
||||||
|
for(; mit != grp.end(); mit++)
|
||||||
|
{
|
||||||
|
const std::string& grpId = mit->first;
|
||||||
|
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpColumns, "grpId='" + grpId + "'", "");
|
||||||
|
|
||||||
|
if(c)
|
||||||
|
{
|
||||||
|
std::vector<RsNxsGrp*> grps;
|
||||||
|
retrieveGroups(c, grps);
|
||||||
|
std::vector<RsNxsGrp*>::iterator vit = grps.begin();
|
||||||
|
|
||||||
|
for(; vit != grps.end(); vit++)
|
||||||
|
{
|
||||||
|
grp[(*vit)->grpId] = *vit;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RsDataService::retrieveGroups(RetroCursor* c, std::vector<RsNxsGrp*>& grps){
|
||||||
|
|
||||||
|
if(c){
|
||||||
bool valid = c->moveToFirst();
|
bool valid = c->moveToFirst();
|
||||||
|
|
||||||
while(valid){
|
while(valid){
|
||||||
@ -557,15 +601,10 @@ int RsDataService::retrieveNxsGrps(std::map<std::string, RsNxsGrp *> &grp, bool
|
|||||||
// only add the latest grp info
|
// only add the latest grp info
|
||||||
if(g)
|
if(g)
|
||||||
{
|
{
|
||||||
grp[g->grpId] = g;
|
grps.push_back(g);
|
||||||
}
|
}
|
||||||
valid = c->moveToNext();
|
valid = c->moveToNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
delete c;
|
|
||||||
return 1;
|
|
||||||
}else{
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -704,8 +743,8 @@ int RsDataService::resetDataStore()
|
|||||||
for(; mit != grps.end(); mit++){
|
for(; mit != grps.end(); mit++){
|
||||||
std::string file = mServiceDir + "/" + mit->first;
|
std::string file = mServiceDir + "/" + mit->first;
|
||||||
std::string msgFile = file + "-msgs";
|
std::string msgFile = file + "-msgs";
|
||||||
remove(file.c_str());
|
remove(file.c_str()); // remove group file
|
||||||
remove(msgFile.c_str());
|
remove(msgFile.c_str()); // and remove messages file
|
||||||
}
|
}
|
||||||
|
|
||||||
mDb->closeDb();
|
mDb->closeDb();
|
||||||
|
@ -22,7 +22,8 @@ public:
|
|||||||
int retrieveNxsMsgs(const GxsMsgReq& reqIds, GxsMsgResult& msg, bool cache);
|
int retrieveNxsMsgs(const GxsMsgReq& reqIds, GxsMsgResult& msg, bool cache);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Retrieves all groups stored (most current versions only)
|
* Retrieves groups, if empty, retrieves all grps, if map is not empty
|
||||||
|
* only retrieve entries
|
||||||
* @param grp retrieved groups
|
* @param grp retrieved groups
|
||||||
* @param cache whether to store retrieval in mem for faster later retrieval
|
* @param cache whether to store retrieval in mem for faster later retrieval
|
||||||
* @return error code
|
* @return error code
|
||||||
@ -114,6 +115,13 @@ private:
|
|||||||
*/
|
*/
|
||||||
void retrieveMessages(RetroCursor* c, std::vector<RsNxsMsg*>& msgs);
|
void retrieveMessages(RetroCursor* c, std::vector<RsNxsMsg*>& msgs);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Retrieves all the msg results from a cursor
|
||||||
|
* @param c cursor to result set
|
||||||
|
* @param msgs messages retrieved from cursor are stored here
|
||||||
|
*/
|
||||||
|
void retrieveGroups(RetroCursor* c, std::vector<RsNxsGrp*>& msgs);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* extracts a msg meta item from a cursor at its
|
* extracts a msg meta item from a cursor at its
|
||||||
* current position
|
* current position
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
#include "rsgxsnetservice.h"
|
#include "rsgxsnetservice.h"
|
||||||
|
|
||||||
#define SYNC_PERIOD 1000 // every 10 seconds
|
#define NXS_NET_DEBUG
|
||||||
#define TRANSAC_TIMEOUT 10 // 10 seconds
|
|
||||||
|
#define SYNC_PERIOD 1 // in microseconds every 10 seconds (1 second for testing)
|
||||||
|
#define TRANSAC_TIMEOUT 5 // 5 seconds
|
||||||
|
|
||||||
|
|
||||||
RsGxsNetService::RsGxsNetService(uint16_t servType, RsGeneralDataService *gds,
|
RsGxsNetService::RsGxsNetService(uint16_t servType, RsGeneralDataService *gds,
|
||||||
RsNxsNetMgr *netMgr, RsNxsObserver *nxsObs)
|
RsNxsNetMgr *netMgr, RsNxsObserver *nxsObs)
|
||||||
: p3Config(servType), p3ThreadedService(servType), mServType(servType), mDataStore(gds),
|
: p3Config(servType), p3ThreadedService(servType),
|
||||||
|
mTransactionTimeOut(TRANSAC_TIMEOUT), mServType(servType), mDataStore(gds),
|
||||||
mObserver(nxsObs), mNxsMutex("RsGxsNetService"), mNetMgr(netMgr), mSYNC_PERIOD(SYNC_PERIOD)
|
mObserver(nxsObs), mNxsMutex("RsGxsNetService"), mNetMgr(netMgr), mSYNC_PERIOD(SYNC_PERIOD)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -30,6 +34,7 @@ int RsGxsNetService::tick(){
|
|||||||
if((mSYNC_PERIOD + mSyncTs) < now)
|
if((mSYNC_PERIOD + mSyncTs) < now)
|
||||||
{
|
{
|
||||||
syncWithPeers();
|
syncWithPeers();
|
||||||
|
mSyncTs = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@ -47,6 +52,7 @@ void RsGxsNetService::syncWithPeers()
|
|||||||
for(; sit != peers.end(); sit++)
|
for(; sit != peers.end(); sit++)
|
||||||
{
|
{
|
||||||
RsNxsSyncGrp *grp = new RsNxsSyncGrp(mServType);
|
RsNxsSyncGrp *grp = new RsNxsSyncGrp(mServType);
|
||||||
|
grp->clear();
|
||||||
grp->PeerId(*sit);
|
grp->PeerId(*sit);
|
||||||
sendItem(grp);
|
sendItem(grp);
|
||||||
}
|
}
|
||||||
@ -88,6 +94,11 @@ void RsGxsNetService::recvNxsItemQueue(){
|
|||||||
// a live transaction has a non zero value
|
// a live transaction has a non zero value
|
||||||
if(ni->transactionNumber != 0){
|
if(ni->transactionNumber != 0){
|
||||||
|
|
||||||
|
#ifdef NXS_NET_DEBUG
|
||||||
|
std::cerr << "recvNxsItemQueue()" << std::endl;
|
||||||
|
std::cerr << "handlingTransaction, transN" << ni->transactionNumber << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
if(handleTransaction(ni))
|
if(handleTransaction(ni))
|
||||||
continue ;
|
continue ;
|
||||||
}
|
}
|
||||||
@ -142,6 +153,13 @@ bool RsGxsNetService::handleTransaction(RsNxsItem* item){
|
|||||||
transExists = transMap.find(transN) != transMap.end();
|
transExists = transMap.find(transN) != transMap.end();
|
||||||
|
|
||||||
if(transExists){
|
if(transExists){
|
||||||
|
|
||||||
|
#ifdef NXS_NET_DEBUG
|
||||||
|
std::cerr << "handleTransaction() " << std::endl;
|
||||||
|
std::cerr << "Consuming Transaction content, transN: " << item->transactionNumber << std::endl;
|
||||||
|
std::cerr << "Consuming Transaction content, from Peer: " << item->PeerId() << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
tr = transMap[transN];
|
tr = transMap[transN];
|
||||||
tr->mItems.push_back(item);
|
tr->mItems.push_back(item);
|
||||||
}
|
}
|
||||||
@ -174,8 +192,17 @@ bool RsGxsNetService::locked_processTransac(RsNxsTransac* item)
|
|||||||
|
|
||||||
const std::string& peer = item->PeerId();
|
const std::string& peer = item->PeerId();
|
||||||
uint32_t transN = item->transactionNumber;
|
uint32_t transN = item->transactionNumber;
|
||||||
|
item->timestamp = time(NULL); // register time received
|
||||||
NxsTransaction* tr = NULL;
|
NxsTransaction* tr = NULL;
|
||||||
|
|
||||||
|
#ifdef NXS_NET_DEBUG
|
||||||
|
|
||||||
|
std::cerr << "locked_processTransac() " << std::endl;
|
||||||
|
std::cerr << "locked_processTransac(), Received transaction item: " << transN << std::endl;
|
||||||
|
std::cerr << "locked_processTransac(), With peer: " << item->PeerId() << std::endl;
|
||||||
|
std::cerr << "locked_processTransac(), trans type: " << item->transactFlag << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
bool peerTrExists = mTransactions.find(peer) != mTransactions.end();
|
bool peerTrExists = mTransactions.find(peer) != mTransactions.end();
|
||||||
bool transExists = false;
|
bool transExists = false;
|
||||||
|
|
||||||
@ -204,7 +231,7 @@ bool RsGxsNetService::locked_processTransac(RsNxsTransac* item)
|
|||||||
tr = new NxsTransaction();
|
tr = new NxsTransaction();
|
||||||
transMap[transN] = tr;
|
transMap[transN] = tr;
|
||||||
tr->mTransaction = item;
|
tr->mTransaction = item;
|
||||||
tr->mTimestamp = time(NULL);
|
tr->mTimeOut = item->timestamp;
|
||||||
|
|
||||||
// note state as receiving, commencement item
|
// note state as receiving, commencement item
|
||||||
// is sent on next run() loop
|
// is sent on next run() loop
|
||||||
@ -264,6 +291,10 @@ void RsGxsNetService::run(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RsGxsNetService::checkTransacTimedOut(NxsTransaction* tr)
|
||||||
|
{
|
||||||
|
return tr->mTimeOut < ((uint32_t) time(NULL));
|
||||||
|
}
|
||||||
|
|
||||||
void RsGxsNetService::processTransactions(){
|
void RsGxsNetService::processTransactions(){
|
||||||
|
|
||||||
@ -292,9 +323,29 @@ void RsGxsNetService::processTransactions(){
|
|||||||
std::list<RsNxsItem*>::iterator lit, lit_end;
|
std::list<RsNxsItem*>::iterator lit, lit_end;
|
||||||
uint32_t transN = tr->mTransaction->transactionNumber;
|
uint32_t transN = tr->mTransaction->transactionNumber;
|
||||||
|
|
||||||
|
// first check transaction has not expired
|
||||||
|
if(checkTransacTimedOut(tr))
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifdef NXS_NET_DEBUG
|
||||||
|
std::cerr << "processTransactions() " << std::endl;
|
||||||
|
std::cerr << "Transaction has failed, tranN: " << transN << std::endl;
|
||||||
|
std::cerr << "Transaction has failed, Peer: " << mit->first << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
tr->mFlag = NxsTransaction::FLAG_STATE_FAILED;
|
||||||
|
toRemove.push_back(transN);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// send items requested
|
// send items requested
|
||||||
if(flag & NxsTransaction::FLAG_STATE_SENDING){
|
if(flag & NxsTransaction::FLAG_STATE_SENDING){
|
||||||
|
|
||||||
|
#ifdef NXS_NET_DEBUG
|
||||||
|
std::cerr << "processTransactions() " << std::endl;
|
||||||
|
std::cerr << "Sending Transaction content, transN: " << transN << std::endl;
|
||||||
|
std::cerr << "with peer: " << tr->mTransaction->PeerId();
|
||||||
|
#endif
|
||||||
lit = tr->mItems.begin();
|
lit = tr->mItems.begin();
|
||||||
lit_end = tr->mItems.end();
|
lit_end = tr->mItems.end();
|
||||||
|
|
||||||
@ -302,7 +353,7 @@ void RsGxsNetService::processTransactions(){
|
|||||||
sendItem(*lit);
|
sendItem(*lit);
|
||||||
}
|
}
|
||||||
|
|
||||||
tr->mItems.clear();
|
tr->mItems.clear(); // clear so they don't get deleted in trans cleaning
|
||||||
tr->mFlag = NxsTransaction::FLAG_STATE_WAITING_CONFIRM;
|
tr->mFlag = NxsTransaction::FLAG_STATE_WAITING_CONFIRM;
|
||||||
|
|
||||||
}else if(flag & NxsTransaction::FLAG_STATE_WAITING_CONFIRM){
|
}else if(flag & NxsTransaction::FLAG_STATE_WAITING_CONFIRM){
|
||||||
@ -313,6 +364,15 @@ void RsGxsNetService::processTransactions(){
|
|||||||
// move to completed transactions
|
// move to completed transactions
|
||||||
toRemove.push_back(transN);
|
toRemove.push_back(transN);
|
||||||
mComplTransactions.push_back(tr);
|
mComplTransactions.push_back(tr);
|
||||||
|
}else{
|
||||||
|
|
||||||
|
std::cerr << "processTransactions() " << std::endl;
|
||||||
|
std::cerr << "processTransactions(), Unknown flag for active transaction, transN: " << transN
|
||||||
|
<< std::endl;
|
||||||
|
std::cerr << "processTransactions(), Unknown flag, Peer: " << mit->first;
|
||||||
|
toRemove.push_back(transN);
|
||||||
|
tr->mFlag = NxsTransaction::FLAG_STATE_FAILED;
|
||||||
|
mComplTransactions.push_back(tr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -344,6 +404,21 @@ void RsGxsNetService::processTransactions(){
|
|||||||
uint16_t flag = tr->mFlag;
|
uint16_t flag = tr->mFlag;
|
||||||
uint32_t transN = tr->mTransaction->transactionNumber;
|
uint32_t transN = tr->mTransaction->transactionNumber;
|
||||||
|
|
||||||
|
// first check transaction has not expired
|
||||||
|
if(checkTransacTimedOut(tr))
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifdef NXS_NET_DEBUG
|
||||||
|
std::cerr << "processTransactions() " << std::endl;
|
||||||
|
std::cerr << "Transaction has failed, tranN: " << transN << std::endl;
|
||||||
|
std::cerr << "Transaction has failed, Peer: " << mit->first << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
tr->mFlag = NxsTransaction::FLAG_STATE_FAILED;
|
||||||
|
toRemove.push_back(transN);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if(flag & NxsTransaction::FLAG_STATE_RECEIVING){
|
if(flag & NxsTransaction::FLAG_STATE_RECEIVING){
|
||||||
|
|
||||||
// if the number it item received equal that indicated
|
// if the number it item received equal that indicated
|
||||||
@ -375,19 +450,22 @@ void RsGxsNetService::processTransactions(){
|
|||||||
// send item to tell peer your are ready to start
|
// send item to tell peer your are ready to start
|
||||||
RsNxsTransac* trans = new RsNxsTransac(mServType);
|
RsNxsTransac* trans = new RsNxsTransac(mServType);
|
||||||
trans->clear();
|
trans->clear();
|
||||||
trans->transactFlag = RsNxsTransac::FLAG_BEGIN_P2;
|
trans->transactFlag = RsNxsTransac::FLAG_BEGIN_P2 |
|
||||||
|
(tr->mTransaction->transactFlag & RsNxsTransac::FLAG_TYPE_MASK);
|
||||||
trans->transactionNumber = transN;
|
trans->transactionNumber = transN;
|
||||||
trans->PeerId(tr->mTransaction->PeerId());
|
trans->PeerId(tr->mTransaction->PeerId());
|
||||||
|
sendItem(trans);
|
||||||
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|
||||||
// unrecognised state
|
std::cerr << "processTransactions() " << std::endl;
|
||||||
std::cerr << "RsGxsNetService::processTransactions() Unrecognised statem, deleting " << std::endl;
|
std::cerr << "processTransactions(), Unknown flag for active transaction, transN: " << transN
|
||||||
std::cerr << "RsGxsNetService::processTransactions() Id: "
|
<< std::endl;
|
||||||
<< transN << std::endl;
|
std::cerr << "processTransactions(), Unknown flag, Peer: " << mit->first;
|
||||||
|
toRemove.push_back(mmit->first);
|
||||||
toRemove.push_back(transN);
|
mComplTransactions.push_back(tr);
|
||||||
|
tr->mFlag = NxsTransaction::FLAG_STATE_FAILED; // flag as a failed transaction
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -414,8 +492,26 @@ void RsGxsNetService::processCompletedTransactions()
|
|||||||
|
|
||||||
NxsTransaction* tr = mComplTransactions.front();
|
NxsTransaction* tr = mComplTransactions.front();
|
||||||
|
|
||||||
|
bool outgoing = tr->mTransaction->PeerId() == mOwnId;
|
||||||
|
|
||||||
|
if(outgoing){
|
||||||
|
processCompletedOutgoingTrans(tr);
|
||||||
|
}else{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
delete tr;
|
||||||
|
mComplTransactions.pop_front();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RsGxsNetService::processCompletedIncomingTrans(NxsTransaction* tr)
|
||||||
|
{
|
||||||
|
|
||||||
uint16_t flag = tr->mTransaction->transactFlag;
|
uint16_t flag = tr->mTransaction->transactFlag;
|
||||||
|
|
||||||
|
if(tr->mFlag & NxsTransaction::FLAG_STATE_COMPLETED){
|
||||||
// for a completed list response transaction
|
// for a completed list response transaction
|
||||||
// one needs generate requests from this
|
// one needs generate requests from this
|
||||||
if(flag & RsNxsTransac::FLAG_TYPE_MSG_LIST_RESP)
|
if(flag & RsNxsTransac::FLAG_TYPE_MSG_LIST_RESP)
|
||||||
@ -427,12 +523,16 @@ void RsGxsNetService::processCompletedTransactions()
|
|||||||
{
|
{
|
||||||
genReqGrpTransaction(tr);
|
genReqGrpTransaction(tr);
|
||||||
}
|
}
|
||||||
else if( (flag & RsNxsTransac::FLAG_TYPE_MSG_LIST_REQ) ||
|
// you've finished receiving request information now gen
|
||||||
(flag & RsNxsTransac::FLAG_TYPE_GRP_LIST_REQ) )
|
else if(flag & RsNxsTransac::FLAG_TYPE_MSG_LIST_REQ)
|
||||||
{
|
{
|
||||||
// don't do anything, this should simply be removed
|
genSendMsgsTransaction(tr);
|
||||||
|
}
|
||||||
}else if(flag & RsNxsTransac::FLAG_TYPE_GRPS)
|
else if(flag & RsNxsTransac::FLAG_TYPE_GRP_LIST_REQ)
|
||||||
|
{
|
||||||
|
genSendGrpsTransaction(tr);
|
||||||
|
}
|
||||||
|
else if(flag & RsNxsTransac::FLAG_TYPE_GRPS)
|
||||||
{
|
{
|
||||||
|
|
||||||
std::list<RsNxsItem*>::iterator lit = tr->mItems.begin();
|
std::list<RsNxsItem*>::iterator lit = tr->mItems.begin();
|
||||||
@ -487,11 +587,75 @@ void RsGxsNetService::processCompletedTransactions()
|
|||||||
mObserver->notifyNewMessages(msgs);
|
mObserver->notifyNewMessages(msgs);
|
||||||
|
|
||||||
}
|
}
|
||||||
delete tr;
|
}else if(tr->mFlag == NxsTransaction::FLAG_STATE_FAILED){
|
||||||
mComplTransactions.pop_front();
|
// don't do anything transaction will simply be cleaned
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RsGxsNetService::processCompletedOutgoingTrans(NxsTransaction* tr)
|
||||||
|
{
|
||||||
|
uint16_t flag = tr->mTransaction->transactFlag;
|
||||||
|
|
||||||
|
if(tr->mFlag & NxsTransaction::FLAG_STATE_COMPLETED){
|
||||||
|
// for a completed list response transaction
|
||||||
|
// one needs generate requests from this
|
||||||
|
if(flag & RsNxsTransac::FLAG_TYPE_MSG_LIST_RESP)
|
||||||
|
{
|
||||||
|
#ifdef NXS_NET_DEBUG
|
||||||
|
std::cerr << "processCompletedOutgoingTrans()" << std::endl;
|
||||||
|
std::cerr << "complete Sending Msg List Response, transN: " <<
|
||||||
|
tr->mTransaction->transactionNumber << std::endl;
|
||||||
|
#endif
|
||||||
|
}else if(flag & RsNxsTransac::FLAG_TYPE_GRP_LIST_RESP)
|
||||||
|
{
|
||||||
|
#ifdef NXS_NET_DEBUG
|
||||||
|
std::cerr << "processCompletedOutgoingTrans()" << std::endl;
|
||||||
|
std::cerr << "complete Sending Grp Response, transN: " <<
|
||||||
|
tr->mTransaction->transactionNumber << std::endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
// you've finished sending a request so don't do anything
|
||||||
|
else if( (flag & RsNxsTransac::FLAG_TYPE_MSG_LIST_REQ) ||
|
||||||
|
(flag & RsNxsTransac::FLAG_TYPE_GRP_LIST_REQ) )
|
||||||
|
{
|
||||||
|
#ifdef NXS_NET_DEBUG
|
||||||
|
std::cerr << "processCompletedOutgoingTrans()" << std::endl;
|
||||||
|
std::cerr << "complete Sending Msg/Grp Request, transN: " <<
|
||||||
|
tr->mTransaction->transactionNumber << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}else if(flag & RsNxsTransac::FLAG_TYPE_GRPS)
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifdef NXS_NET_DEBUG
|
||||||
|
std::cerr << "processCompletedOutgoingTrans()" << std::endl;
|
||||||
|
std::cerr << "complete Sending Grp Data, transN: " <<
|
||||||
|
tr->mTransaction->transactionNumber << std::endl;
|
||||||
|
#endif
|
||||||
|
}else if(flag & RsNxsTransac::FLAG_TYPE_MSGS)
|
||||||
|
{
|
||||||
|
#ifdef NXS_NET_DEBUG
|
||||||
|
std::cerr << "processCompletedOutgoingTrans()" << std::endl;
|
||||||
|
std::cerr << "complete Sending Msg Data, transN: " <<
|
||||||
|
tr->mTransaction->transactionNumber << std::endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}else if(tr->mFlag == NxsTransaction::FLAG_STATE_FAILED){
|
||||||
|
#ifdef NXS_NET_DEBUG
|
||||||
|
std::cerr << "processCompletedOutgoingTrans()" << std::endl;
|
||||||
|
std::cerr << "Failed transaction! transN: " <<
|
||||||
|
tr->mTransaction->transactionNumber << std::endl;
|
||||||
|
#endif
|
||||||
|
}else{
|
||||||
|
|
||||||
|
#ifdef NXS_NET_DEBUG
|
||||||
|
std::cerr << "processCompletedOutgoingTrans()" << std::endl;
|
||||||
|
std::cerr << "Serious error unrecognised trans Flag! transN: " <<
|
||||||
|
tr->mTransaction->transactionNumber << std::endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void RsGxsNetService::genReqMsgTransaction(NxsTransaction* tr)
|
void RsGxsNetService::genReqMsgTransaction(NxsTransaction* tr)
|
||||||
@ -544,7 +708,7 @@ void RsGxsNetService::genReqMsgTransaction(NxsTransaction* tr)
|
|||||||
uint32_t transN = getTransactionId();
|
uint32_t transN = getTransactionId();
|
||||||
|
|
||||||
|
|
||||||
// now do compare and add loop
|
// add msgs that you don't have to request list
|
||||||
std::list<RsNxsSyncMsgItem*>::iterator llit = msgItemL.begin();
|
std::list<RsNxsSyncMsgItem*>::iterator llit = msgItemL.begin();
|
||||||
std::list<RsNxsItem*> reqList;
|
std::list<RsNxsItem*> reqList;
|
||||||
|
|
||||||
@ -566,14 +730,22 @@ void RsGxsNetService::genReqMsgTransaction(NxsTransaction* tr)
|
|||||||
RsNxsTransac* transac = new RsNxsTransac(mServType);
|
RsNxsTransac* transac = new RsNxsTransac(mServType);
|
||||||
transac->transactFlag = RsNxsTransac::FLAG_TYPE_MSG_LIST_REQ
|
transac->transactFlag = RsNxsTransac::FLAG_TYPE_MSG_LIST_REQ
|
||||||
| RsNxsTransac::FLAG_BEGIN_P1;
|
| RsNxsTransac::FLAG_BEGIN_P1;
|
||||||
transac->timeout = mTransactionTimeOut;
|
transac->timestamp = 0;
|
||||||
transac->nItems = reqList.size();
|
transac->nItems = reqList.size();
|
||||||
|
transac->PeerId(tr->mTransaction->PeerId());
|
||||||
|
|
||||||
NxsTransaction* newTrans = new NxsTransaction();
|
NxsTransaction* newTrans = new NxsTransaction();
|
||||||
newTrans->mItems = reqList;
|
newTrans->mItems = reqList;
|
||||||
newTrans->mFlag = NxsTransaction::FLAG_STATE_STARTING;
|
newTrans->mFlag = NxsTransaction::FLAG_STATE_WAITING_CONFIRM;
|
||||||
newTrans->mTimestamp = 0;
|
newTrans->mTimeOut = 0;
|
||||||
newTrans->mTransaction = transac;
|
|
||||||
|
// create transaction copy with your id to indicate
|
||||||
|
// its an outgoing transaction
|
||||||
|
newTrans->mTransaction = new RsNxsTransac(*transac);
|
||||||
|
newTrans->mTransaction->PeerId(mOwnId);
|
||||||
|
|
||||||
|
sendItem(transac);
|
||||||
|
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mNxsMutex);
|
RsStackMutex stack(mNxsMutex);
|
||||||
if(!locked_addTransaction(newTrans))
|
if(!locked_addTransaction(newTrans))
|
||||||
@ -609,8 +781,6 @@ void RsGxsNetService::genReqGrpTransaction(NxsTransaction* tr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RsNxsSyncGrpItem* item = grpItemL.front();
|
|
||||||
const std::string& grpId = item->grpId;
|
|
||||||
std::map<std::string, RsGxsGrpMetaData*> grpMetaMap;
|
std::map<std::string, RsGxsGrpMetaData*> grpMetaMap;
|
||||||
mDataStore->retrieveGxsGrpMetaData(grpMetaMap);
|
mDataStore->retrieveGxsGrpMetaData(grpMetaMap);
|
||||||
|
|
||||||
@ -636,16 +806,20 @@ void RsGxsNetService::genReqGrpTransaction(NxsTransaction* tr)
|
|||||||
|
|
||||||
|
|
||||||
RsNxsTransac* transac = new RsNxsTransac(mServType);
|
RsNxsTransac* transac = new RsNxsTransac(mServType);
|
||||||
transac->transactFlag = RsNxsTransac::FLAG_TYPE_MSG_LIST_REQ
|
transac->transactFlag = RsNxsTransac::FLAG_TYPE_GRP_LIST_REQ
|
||||||
| RsNxsTransac::FLAG_BEGIN_P1;
|
| RsNxsTransac::FLAG_BEGIN_P1;
|
||||||
transac->timeout = mTransactionTimeOut;
|
transac->timestamp = 0;
|
||||||
transac->nItems = reqList.size();
|
transac->nItems = reqList.size();
|
||||||
|
transac->PeerId(tr->mTransaction->PeerId());
|
||||||
|
|
||||||
NxsTransaction* newTrans = new NxsTransaction();
|
NxsTransaction* newTrans = new NxsTransaction();
|
||||||
newTrans->mItems = reqList;
|
newTrans->mItems = reqList;
|
||||||
newTrans->mFlag = NxsTransaction::FLAG_STATE_STARTING;
|
newTrans->mFlag = NxsTransaction::FLAG_STATE_WAITING_CONFIRM;
|
||||||
newTrans->mTimestamp = 0;
|
newTrans->mTimeOut = 0;
|
||||||
newTrans->mTransaction = transac;
|
newTrans->mTransaction = new RsNxsTransac(*transac);
|
||||||
|
newTrans->mTransaction->PeerId(mOwnId);
|
||||||
|
|
||||||
|
sendItem(transac);
|
||||||
|
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mNxsMutex);
|
RsStackMutex stack(mNxsMutex);
|
||||||
@ -654,6 +828,53 @@ void RsGxsNetService::genReqGrpTransaction(NxsTransaction* tr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RsGxsNetService::genSendGrpsTransaction(NxsTransaction* tr)
|
||||||
|
{
|
||||||
|
|
||||||
|
// go groups requested in transaction tr
|
||||||
|
|
||||||
|
std::list<RsNxsItem*>::iterator lit = tr->mItems.begin();
|
||||||
|
|
||||||
|
std::map<std::string, RsNxsGrp*> grps;
|
||||||
|
|
||||||
|
for(;lit != tr->mItems.end(); lit++)
|
||||||
|
{
|
||||||
|
RsNxsSyncGrpItem* item = dynamic_cast<RsNxsSyncGrpItem*>(*lit);
|
||||||
|
grps[item->grpId] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
mDataStore->retrieveNxsGrps(grps, false);
|
||||||
|
|
||||||
|
NxsTransaction* newTr = new NxsTransaction();
|
||||||
|
newTr->mFlag = NxsTransaction::FLAG_STATE_WAITING_CONFIRM;
|
||||||
|
|
||||||
|
// store grp items to send in transaction
|
||||||
|
std::map<std::string, RsNxsGrp*>::iterator mit = grps.begin();
|
||||||
|
for(;mit != grps.end(); mit++)
|
||||||
|
{
|
||||||
|
newTr->mItems.push_back(mit->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
RsNxsTransac* ntr = new RsNxsTransac(mServType);
|
||||||
|
ntr->transactionNumber = getTransactionId();
|
||||||
|
ntr->transactFlag = RsNxsTransac::FLAG_BEGIN_P1 |
|
||||||
|
RsNxsTransac::FLAG_TYPE_GRPS;
|
||||||
|
ntr->nItems = grps.size();
|
||||||
|
|
||||||
|
newTr->mTransaction = new RsNxsTransac(*ntr);
|
||||||
|
newTr->mTransaction->PeerId(mOwnId);
|
||||||
|
|
||||||
|
ntr->PeerId(tr->mTransaction->PeerId());
|
||||||
|
sendItem(ntr);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RsGxsNetService::genSendMsgsTransaction(NxsTransaction* tr)
|
||||||
|
{
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
uint32_t RsGxsNetService::getTransactionId()
|
uint32_t RsGxsNetService::getTransactionId()
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mNxsMutex);
|
RsStackMutex stack(mNxsMutex);
|
||||||
@ -670,6 +891,11 @@ bool RsGxsNetService::locked_addTransaction(NxsTransaction* tr)
|
|||||||
|
|
||||||
|
|
||||||
if(transNumExist){
|
if(transNumExist){
|
||||||
|
#ifdef NXS_NET_DEBUG
|
||||||
|
std::cerr << "locked_addTransaction() " << std::endl;
|
||||||
|
std::cerr << "Transaction number exist already, transN: " << transN
|
||||||
|
<< std::endl;
|
||||||
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}else{
|
}else{
|
||||||
transMap[transN] = tr;
|
transMap[transN] = tr;
|
||||||
@ -693,7 +919,6 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrp* item)
|
|||||||
{
|
{
|
||||||
|
|
||||||
std::string peer = item->PeerId();
|
std::string peer = item->PeerId();
|
||||||
delete item;
|
|
||||||
|
|
||||||
std::map<std::string, RsGxsGrpMetaData*> grp;
|
std::map<std::string, RsGxsGrpMetaData*> grp;
|
||||||
mDataStore->retrieveGxsGrpMetaData(grp);
|
mDataStore->retrieveGxsGrpMetaData(grp);
|
||||||
@ -724,14 +949,14 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrp* item)
|
|||||||
trItem->transactFlag = RsNxsTransac::FLAG_BEGIN_P1
|
trItem->transactFlag = RsNxsTransac::FLAG_BEGIN_P1
|
||||||
| RsNxsTransac::FLAG_TYPE_GRP_LIST_RESP;
|
| RsNxsTransac::FLAG_TYPE_GRP_LIST_RESP;
|
||||||
trItem->nItems = itemL.size();
|
trItem->nItems = itemL.size();
|
||||||
time_t now;
|
|
||||||
gmtime(&now);
|
trItem->timestamp = time(NULL);
|
||||||
trItem->timeout = now + TRANSAC_TIMEOUT;
|
|
||||||
trItem->PeerId(peer);
|
trItem->PeerId(peer);
|
||||||
trItem->transactionNumber = getTransactionId();
|
trItem->transactionNumber = getTransactionId();
|
||||||
|
|
||||||
// also make a copy for the resident transaction
|
// also make a copy for the resident transaction
|
||||||
tr->mTransaction = new RsNxsTransac(*trItem);
|
tr->mTransaction = new RsNxsTransac(*trItem);
|
||||||
|
tr->mTransaction->PeerId(mOwnId);
|
||||||
|
|
||||||
// signal peer to prepare for transaction
|
// signal peer to prepare for transaction
|
||||||
sendItem(trItem);
|
sendItem(trItem);
|
||||||
@ -771,7 +996,7 @@ const uint8_t NxsTransaction::FLAG_STATE_WAITING_CONFIRM = 0x0020;
|
|||||||
|
|
||||||
|
|
||||||
NxsTransaction::NxsTransaction()
|
NxsTransaction::NxsTransaction()
|
||||||
: mFlag(0), mTimestamp(0), mTransaction(NULL) {
|
: mFlag(0), mTimeOut(0), mTransaction(NULL) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,12 +31,11 @@ public:
|
|||||||
static const uint8_t FLAG_STATE_FAILED;
|
static const uint8_t FLAG_STATE_FAILED;
|
||||||
static const uint8_t FLAG_STATE_WAITING_CONFIRM;
|
static const uint8_t FLAG_STATE_WAITING_CONFIRM;
|
||||||
|
|
||||||
|
|
||||||
NxsTransaction();
|
NxsTransaction();
|
||||||
~NxsTransaction();
|
~NxsTransaction();
|
||||||
|
|
||||||
uint32_t mFlag; // current state of transaction
|
uint32_t mFlag; // current state of transaction
|
||||||
uint32_t mTimestamp;
|
uint32_t mTimeOut;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* this contains who we
|
* this contains who we
|
||||||
@ -50,11 +49,15 @@ public:
|
|||||||
std::list<RsNxsItem*> mItems; // items received or sent
|
std::list<RsNxsItem*> mItems; // items received or sent
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* An abstraction of the net manager
|
||||||
|
* for retrieving Rs peers whom you will be synchronising
|
||||||
|
* and also you own Id
|
||||||
|
* Useful for testing also (abstracts away Rs's p3NetMgr)
|
||||||
|
*/
|
||||||
class RsNxsNetMgr
|
class RsNxsNetMgr
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual std::string getOwnId() = 0;
|
virtual std::string getOwnId() = 0;
|
||||||
@ -205,6 +208,18 @@ private:
|
|||||||
*/
|
*/
|
||||||
void processCompletedTransactions();
|
void processCompletedTransactions();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Process transaction owned/started by user
|
||||||
|
* @param tr transaction to process, ownership stays with callee
|
||||||
|
*/
|
||||||
|
void processCompletedOutgoingTrans(NxsTransaction* tr);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Process transactions started/owned by other peers
|
||||||
|
* @param tr transaction to process, ownership stays with callee
|
||||||
|
*/
|
||||||
|
void processCompletedIncomingTrans(NxsTransaction* tr);
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Process a transaction item, assumes a general lock
|
* Process a transaction item, assumes a general lock
|
||||||
@ -246,22 +261,47 @@ private:
|
|||||||
//void notifyListenerMsgs(std::list<RsNxsMsg*>& msgs);
|
//void notifyListenerMsgs(std::list<RsNxsMsg*>& msgs);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
* Generates new transaction to send msg requests based on list
|
||||||
|
* of msgs received from peer stored in passed transaction
|
||||||
* @param tr transaction responsible for generating msg request
|
* @param tr transaction responsible for generating msg request
|
||||||
*/
|
*/
|
||||||
void genReqMsgTransaction(NxsTransaction* tr);
|
void genReqMsgTransaction(NxsTransaction* tr);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
* Generates new transaction to send grp requests based on list
|
||||||
|
* of grps received from peer stored in passed transaction
|
||||||
* @param tr transaction responsible for generating grp request
|
* @param tr transaction responsible for generating grp request
|
||||||
*/
|
*/
|
||||||
void genReqGrpTransaction(NxsTransaction* tr);
|
void genReqGrpTransaction(NxsTransaction* tr);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
* Generates new transaction to send msg data based on list
|
||||||
|
* of grpids received from peer stored in passed transaction
|
||||||
|
* @param tr transaction responsible for generating grp request
|
||||||
|
*/
|
||||||
|
void genSendMsgsTransaction(NxsTransaction* tr);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Generates new transaction to send grp data based on list
|
||||||
|
* of grps received from peer stored in passed transaction
|
||||||
|
* @param tr transaction responsible for generating grp request
|
||||||
|
*/
|
||||||
|
void genSendGrpsTransaction(NxsTransaction* tr);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* convenience function to add a transaction to list
|
||||||
* @param tr transaction to add
|
* @param tr transaction to add
|
||||||
*/
|
*/
|
||||||
bool locked_addTransaction(NxsTransaction* tr);
|
bool locked_addTransaction(NxsTransaction* tr);
|
||||||
|
|
||||||
void cleanTransactionItems(NxsTransaction* tr) const;
|
void cleanTransactionItems(NxsTransaction* tr) const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @param tr the transaction to check for timeout
|
||||||
|
* @return false if transaction has timed out, true otherwise
|
||||||
|
*/
|
||||||
|
bool checkTransacTimedOut(NxsTransaction* tr);
|
||||||
|
|
||||||
/** E: Transaction processing **/
|
/** E: Transaction processing **/
|
||||||
|
|
||||||
/** S: item handlers **/
|
/** S: item handlers **/
|
||||||
@ -316,8 +356,12 @@ private:
|
|||||||
RsNxsObserver* mObserver;
|
RsNxsObserver* mObserver;
|
||||||
RsGeneralDataService* mDataStore;
|
RsGeneralDataService* mDataStore;
|
||||||
uint16_t mServType;
|
uint16_t mServType;
|
||||||
|
|
||||||
|
// how much time must elapse before a timeout failure
|
||||||
|
// for an active transaction
|
||||||
uint32_t mTransactionTimeOut;
|
uint32_t mTransactionTimeOut;
|
||||||
|
|
||||||
|
|
||||||
std::string mOwnId;
|
std::string mOwnId;
|
||||||
|
|
||||||
RsNxsNetMgr* mNetMgr;
|
RsNxsNetMgr* mNetMgr;
|
||||||
|
@ -397,7 +397,7 @@ bool RsNxsSerialiser::serialiseNxsTrans(RsNxsTransac *item, void *data, uint32_t
|
|||||||
ok &= setRawUInt32(data, *size, &offset, item->transactionNumber);
|
ok &= setRawUInt32(data, *size, &offset, item->transactionNumber);
|
||||||
ok &= setRawUInt16(data, *size, &offset, item->transactFlag);
|
ok &= setRawUInt16(data, *size, &offset, item->transactFlag);
|
||||||
ok &= setRawUInt32(data, *size, &offset, item->nItems);
|
ok &= setRawUInt32(data, *size, &offset, item->nItems);
|
||||||
ok &= setRawUInt32(data, *size, &offset, item->timeout);
|
ok &= setRawUInt32(data, *size, &offset, item->timestamp);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -836,7 +836,7 @@ RsNxsTransac* RsNxsSerialiser::deserialNxsTrans(void *data, uint32_t *size){
|
|||||||
ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber));
|
ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber));
|
||||||
ok &= getRawUInt16(data, *size, &offset, &(item->transactFlag));
|
ok &= getRawUInt16(data, *size, &offset, &(item->transactFlag));
|
||||||
ok &= getRawUInt32(data, *size, &offset, &(item->nItems));
|
ok &= getRawUInt32(data, *size, &offset, &(item->nItems));
|
||||||
ok &= getRawUInt32(data, *size, &offset, &(item->timeout));
|
ok &= getRawUInt32(data, *size, &offset, &(item->timestamp));
|
||||||
|
|
||||||
if (offset != rssize)
|
if (offset != rssize)
|
||||||
{
|
{
|
||||||
@ -1155,7 +1155,7 @@ void RsNxsSyncMsgItem::clear()
|
|||||||
void RsNxsTransac::clear(){
|
void RsNxsTransac::clear(){
|
||||||
transactFlag = 0;
|
transactFlag = 0;
|
||||||
nItems = 0;
|
nItems = 0;
|
||||||
timeout = 0;
|
timestamp = 0;
|
||||||
transactionNumber = 0;
|
transactionNumber = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1289,7 +1289,7 @@ std::ostream& RsNxsTransac::print(std::ostream &out, uint16_t indent){
|
|||||||
printIndent(out , int_Indent);
|
printIndent(out , int_Indent);
|
||||||
out << "nItems: " << nItems << std::endl;
|
out << "nItems: " << nItems << std::endl;
|
||||||
printIndent(out , int_Indent);
|
printIndent(out , int_Indent);
|
||||||
out << "timeout: " << timeout << std::endl;
|
out << "timeout: " << timestamp << std::endl;
|
||||||
printIndent(out , int_Indent);
|
printIndent(out , int_Indent);
|
||||||
out << "transactionNumber: " << transactionNumber << std::endl;
|
out << "transactionNumber: " << transactionNumber << std::endl;
|
||||||
printIndent(out , int_Indent);
|
printIndent(out , int_Indent);
|
||||||
|
@ -111,8 +111,8 @@ class RsNxsTransac : public RsNxsItem {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static const uint16_t FLAG_TRANS_MASK = 0xf;
|
static const uint16_t FLAG_STATE_MASK = 0xff;
|
||||||
static const uint16_t FLAG_TYPE_MASK = 0xff;
|
static const uint16_t FLAG_TYPE_MASK = 0xff00;
|
||||||
|
|
||||||
/** transaction state **/
|
/** transaction state **/
|
||||||
static const uint16_t FLAG_BEGIN_P1;
|
static const uint16_t FLAG_BEGIN_P1;
|
||||||
@ -140,7 +140,7 @@ public:
|
|||||||
|
|
||||||
uint16_t transactFlag;
|
uint16_t transactFlag;
|
||||||
uint32_t nItems;
|
uint32_t nItems;
|
||||||
uint32_t timeout;
|
uint32_t timestamp;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -66,9 +66,12 @@ void NxsTestHub::run()
|
|||||||
netServicePairs.second->join();
|
netServicePairs.second->join();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NxsTestHub::cleanUp()
|
||||||
|
{
|
||||||
|
mTestScenario->cleanUp();
|
||||||
|
}
|
||||||
|
|
||||||
bool NxsTestHub::testsPassed()
|
bool NxsTestHub::testsPassed()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -94,6 +94,7 @@ public:
|
|||||||
void run();
|
void run();
|
||||||
|
|
||||||
|
|
||||||
|
void cleanUp();
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::pair<p3Service*, p3Service*> mServicePairs;
|
std::pair<p3Service*, p3Service*> mServicePairs;
|
||||||
|
@ -88,8 +88,8 @@ void NxsMessageTest::populateStore(RsGeneralDataService* dStore)
|
|||||||
init_item(*msg);
|
init_item(*msg);
|
||||||
init_item(msgMeta);
|
init_item(msgMeta);
|
||||||
std::pair<RsNxsMsg*, RsGxsMsgMetaData*> p(msg, msgMeta);
|
std::pair<RsNxsMsg*, RsGxsMsgMetaData*> p(msg, msgMeta);
|
||||||
int chosen = 0;
|
|
||||||
|
|
||||||
|
// pick a grp at random to associate the msg to
|
||||||
const std::string& grpId = grpIdList[rand()%nGrp];
|
const std::string& grpId = grpIdList[rand()%nGrp];
|
||||||
msgMeta->mMsgId = msg->msgId;
|
msgMeta->mMsgId = msg->msgId;
|
||||||
msgMeta->mGroupId = msg->grpId = grpId;
|
msgMeta->mGroupId = msg->grpId = grpId;
|
||||||
@ -145,3 +145,11 @@ RsGeneralDataService* NxsMessageTest::dummyDataService2()
|
|||||||
{
|
{
|
||||||
return mStorePair.second;
|
return mStorePair.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NxsMessageTest::cleanUp()
|
||||||
|
{
|
||||||
|
mStorePair.first->resetDataStore();
|
||||||
|
mStorePair.second->resetDataStore();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
@ -24,6 +24,12 @@ public:
|
|||||||
virtual RsGeneralDataService* dummyDataService1() = 0;
|
virtual RsGeneralDataService* dummyDataService1() = 0;
|
||||||
virtual RsGeneralDataService* dummyDataService2() = 0;
|
virtual RsGeneralDataService* dummyDataService2() = 0;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Call to remove files created
|
||||||
|
* in the test directory
|
||||||
|
*/
|
||||||
|
virtual void cleanUp() = 0;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -38,6 +44,12 @@ public:
|
|||||||
RsGeneralDataService* dummyDataService1();
|
RsGeneralDataService* dummyDataService1();
|
||||||
RsGeneralDataService* dummyDataService2();
|
RsGeneralDataService* dummyDataService2();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Call to remove files created
|
||||||
|
* in the test directory
|
||||||
|
*/
|
||||||
|
void cleanUp();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -23,11 +23,13 @@ int main()
|
|||||||
createThread(hub);
|
createThread(hub);
|
||||||
|
|
||||||
// put this thread to sleep for 10 secs
|
// put this thread to sleep for 10 secs
|
||||||
usleep(10000);
|
sleep(10);
|
||||||
|
|
||||||
hub.join();
|
hub.join();
|
||||||
CHECK(hub.testsPassed());
|
CHECK(hub.testsPassed());
|
||||||
|
|
||||||
|
hub.cleanUp();
|
||||||
|
|
||||||
FINALREPORT("RsGxsNetService Tests");
|
FINALREPORT("RsGxsNetService Tests");
|
||||||
|
|
||||||
return TESTRESULT();
|
return TESTRESULT();
|
||||||
|
@ -86,7 +86,7 @@ RsSerialType* init_item(RsNxsTransac& rstx){
|
|||||||
|
|
||||||
rstx.clear();
|
rstx.clear();
|
||||||
|
|
||||||
rstx.timeout = rand()%14141;
|
rstx.timestamp = rand()%14141;
|
||||||
rstx.transactFlag = rand()%2424;
|
rstx.transactFlag = rand()%2424;
|
||||||
rstx.nItems = rand()%33132;
|
rstx.nItems = rand()%33132;
|
||||||
rstx.transactionNumber = rand()%242112;
|
rstx.transactionNumber = rand()%242112;
|
||||||
@ -162,7 +162,7 @@ bool operator==(const RsNxsTransac& l, const RsNxsTransac& r){
|
|||||||
|
|
||||||
if(l.transactFlag != r.transactFlag) return false;
|
if(l.transactFlag != r.transactFlag) return false;
|
||||||
if(l.transactionNumber != r.transactionNumber) return false;
|
if(l.transactionNumber != r.transactionNumber) return false;
|
||||||
if(l.timeout != r.timeout) return false;
|
if(l.timestamp != r.timestamp) return false;
|
||||||
if(l.nItems != r.nItems) return false;
|
if(l.nItems != r.nItems) return false;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user