nxsnetservice, changed how resources are managed and rationalised interface

also mainly to switch windows dev system


git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-new_cache_system@5226 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2012-06-16 13:59:40 +00:00
parent a8676302ce
commit 7a22d4fe69
3 changed files with 33 additions and 65 deletions

View File

@ -37,9 +37,7 @@ void RsGxsNetService::recvNxsItemQueue(){
// accumulate // accumulate
if(handleTransaction(ni)) if(handleTransaction(ni))
delete ni ; continue ;
continue ; // don't delete! It's handled by handleRecvChatMsgItem in some specific cases only.
} }
@ -84,7 +82,6 @@ bool RsGxsNetService::handleTransaction(RsNxsItem* item){
bool transExists = false; bool transExists = false;
NxsTransaction* tr = NULL; NxsTransaction* tr = NULL;
uint32_t transN = item->transactionNumber; uint32_t transN = item->transactionNumber;
bool complete = false;
if(peerTransExists) if(peerTransExists)
{ {
@ -132,10 +129,7 @@ bool RsGxsNetService::locked_processTransac(RsNxsTransac* item)
TransactionIdMap& transMap = mTransactions[peer]; TransactionIdMap& transMap = mTransactions[peer];
if(transExists) if(transExists)
{ return false;
delete transMap[transN];
transMap.erase(transN);
}
// create new transaction // create new transaction
tr = new NxsTransaction(); tr = new NxsTransaction();
@ -148,11 +142,10 @@ bool RsGxsNetService::locked_processTransac(RsNxsTransac* item)
}else if(item->transactFlag & RsNxsTransac::FLAG_BEGIN_P2){ }else if(item->transactFlag & RsNxsTransac::FLAG_BEGIN_P2){
// transaction must already exist // transaction does not exist
if(!peerTrExists || !transExists){ if(!peerTrExists || !transExists)
delete item;
return false; return false;
}
// this means you need to start a transaction // this means you need to start a transaction
TransactionIdMap& transMap = mTransactions[mOwnId]; TransactionIdMap& transMap = mTransactions[mOwnId];
@ -161,9 +154,8 @@ bool RsGxsNetService::locked_processTransac(RsNxsTransac* item)
}else if(item->transactFlag & RsNxsTransac::FLAG_END_SUCCESS){ }else if(item->transactFlag & RsNxsTransac::FLAG_END_SUCCESS){
// transaction must already exist // transaction does not exist
if(!peerTrExists || !transExists){ if(!peerTrExists || !transExists){
delete item;
return false; return false;
} }
@ -171,22 +163,10 @@ bool RsGxsNetService::locked_processTransac(RsNxsTransac* item)
TransactionIdMap& transMap = mTransactions[mOwnId]; TransactionIdMap& transMap = mTransactions[mOwnId];
NxsTransaction* tr = transMap[transN]; NxsTransaction* tr = transMap[transN];
tr->mFlag = NxsTransaction::FLAG_STATE_COMPLETED; tr->mFlag = NxsTransaction::FLAG_STATE_COMPLETED;
}else{ // any other flag indicates a failure
// transaction must already exist
if(!peerTrExists || !transExists){
delete item;
return false;
}
// this means you need to start a transaction
TransactionIdMap& transMap = mTransactions[mOwnId];
NxsTransaction* tr = transMap[transN];
tr->mFlag = NxsTransaction::FLAG_STATE_FAILED;
} }
return true; return false;
} }
void RsGxsNetService::run(){ void RsGxsNetService::run(){
@ -374,14 +354,14 @@ void RsGxsNetService::processCompletedTransactions()
std::list<RsNxsItem*>::iterator lit = tr->mItems.begin(); std::list<RsNxsItem*>::iterator lit = tr->mItems.begin();
std::list<RsNxsGrp*> grps; std::list<RsNxsGrp*> grps;
for(; lit != tr->mItems.end(); lit++) while(tr->mItems.size() != 0)
{ {
RsNxsGrp* grp = dynamic_cast<RsNxsGrp*>(tr->mItems.front());
RsNxsGrp* grp = dynamic_cast<RsNxsGrp*>(*lit); if(grp)
tr->mItems.pop_front();
if(grp){ else
grps.push_back(grp); {
}else{
#ifdef NXS_NET_DEBUG #ifdef NXS_NET_DEBUG
std::cerr << "RsGxsNetService::processCompletedTransactions(): item did not caste to grp" std::cerr << "RsGxsNetService::processCompletedTransactions(): item did not caste to grp"
<< std::endl; << std::endl;
@ -399,26 +379,25 @@ void RsGxsNetService::processCompletedTransactions()
std::list<RsNxsItem*>::iterator lit = tr->mItems.begin(); std::list<RsNxsItem*>::iterator lit = tr->mItems.begin();
std::list<RsNxsMsg*> msgs; std::list<RsNxsMsg*> msgs;
for(; lit != tr->mItems.end(); lit++) while(tr->mItems.size() > 0)
{ {
RsNxsMsg* msg = dynamic_cast<RsNxsMsg*>(*lit); RsNxsMsg* msg = dynamic_cast<RsNxsMsg*>(tr->mItems.front());
if(msg)
if(msg){ {
msgs.push_back(msg); tr->mItems.pop_front();
}else{ }else
{
#ifdef NXS_NET_DEBUG #ifdef NXS_NET_DEBUG
std::cerr << "RsGxsNetService::processCompletedTransactions(): item did not caste to msg" std::cerr << "RsGxsNetService::processCompletedTransactions(): item did not caste to msg"
<< std::endl; << std::endl;
#endif #endif
} }
} }
// notify listener of msgs // notify listener of msgs
notifyListenerMsgs(msgs); notifyListenerMsgs(msgs);
} }
tr->mItems.clear();
delete tr; delete tr;
mComplTransactions.pop_front(); mComplTransactions.pop_front();
} }
@ -607,11 +586,6 @@ void RsGxsNetService::pauseSynchronisation(bool enabled)
} }
void RsGxsNetService::subscribeToGroup(const std::string& grpId, bool subscribe)
{
}
void RsGxsNetService::setSyncAge(uint32_t age) void RsGxsNetService::setSyncAge(uint32_t age)
{ {
@ -620,11 +594,20 @@ void RsGxsNetService::setSyncAge(uint32_t age)
/** NxsTransaction definition **/ /** NxsTransaction definition **/
NxsTransaction::NxsTransaction() NxsTransaction::NxsTransaction()
:mTransaction(NULL), mFlag(0), mTimestamp(0) { : mFlag(0), mTimestamp(0), mTransaction(NULL) {
} }
NxsTransaction::~NxsTransaction(){ NxsTransaction::~NxsTransaction(){
std::list<RsNxsItem*>::iterator lit = mItems.begin();
for(; lit != mItems.end(); lit++)
{
delete *lit;
*lit = NULL;
}
delete mTransaction; delete mTransaction;
mTransaction = NULL;
} }

View File

@ -17,6 +17,7 @@
* This represents a transaction made * This represents a transaction made
* with the NxsNetService in all states * with the NxsNetService in all states
* of operation until completion * of operation until completion
*
*/ */
class NxsTransaction class NxsTransaction
{ {
@ -71,7 +72,7 @@ typedef std::map<std::string, TransactionIdMap > TransactionsPeerMap;
/*! /*!
* * Resource use,
* *
*/ */
class RsGxsNetService : public RsNetworkExchangeService, public RsThread, class RsGxsNetService : public RsNetworkExchangeService, public RsThread,
@ -112,14 +113,6 @@ public:
*/ */
void requestMessagesOfPeer(const std::string& peerId, const RsGxsGrpId& grpId){ return; } void requestMessagesOfPeer(const std::string& peerId, const RsGxsGrpId& grpId){ return; }
/*!
* subscribes the associated service to this group. This RsNetworktExchangeService
* now regularly polls all peers for new messages of this group
* @param grpId the id of the group to subscribe to
* @param subscribe set to true to subscribe or false to unsubscribe
*/
void subscribeToGroup(const std::string& grpId, bool subscribe);
/*! /*!
* Initiates a search through the network * Initiates a search through the network
* This returns messages which contains the search terms set in RsGxsSearch * This returns messages which contains the search terms set in RsGxsSearch

View File

@ -83,14 +83,6 @@ public:
*/ */
virtual void requestMessagesOfPeer(const std::string& peerId, const RsGxsGrpId& grpId) = 0; virtual void requestMessagesOfPeer(const std::string& peerId, const RsGxsGrpId& grpId) = 0;
/*!
* subscribes the associated service to this group. This RsNetworktExchangeService
* now regularly polls all peers for new messages of this group
* @param grpId the id of the group to subscribe to
* @param subscribe set to true to subscribe or false to unsubscribe
*/
virtual void subscribeToGroup(const std::string& grpId, bool subscribe) = 0;
/*! /*!
* Initiates a search through the network * Initiates a search through the network
* This returns messages which contains the search terms set in RsGxsSearch * This returns messages which contains the search terms set in RsGxsSearch
@ -102,7 +94,7 @@ public:
/*! /*!
* Initiates a search of groups through the network which goes * Initiates a search of groups through the network which goes
* a given number of hosp deep into your friend's network * a given number of hops deep into your friend network
* @param search contains search term requested from service * @param search contains search term requested from service
* @param hops number of hops deep into peer network * @param hops number of hops deep into peer network
* @return search token that can be redeemed later * @return search token that can be redeemed later