From 5e319b1261cb2f8e8ff7d69dd631e013f591840c Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 20 Jun 2013 19:12:33 +0000 Subject: [PATCH] fixed autoWash() method in p3turtle. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6447 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/turtle/p3turtle.cc | 51 ++++++++++++++-------------- libretroshare/src/turtle/p3turtle.h | 2 +- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/libretroshare/src/turtle/p3turtle.cc b/libretroshare/src/turtle/p3turtle.cc index 35de031a1..abd2baa84 100644 --- a/libretroshare/src/turtle/p3turtle.cc +++ b/libretroshare/src/turtle/p3turtle.cc @@ -383,7 +383,7 @@ void p3turtle::autoWash() // Remove hashes that are marked as such. // - std::vector > peers_to_remove ; + std::vector > > services_vpids_to_remove ; { RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/ @@ -417,7 +417,7 @@ void p3turtle::autoWash() std::cerr << ")" << std::endl ; #endif for(unsigned int k=0;kfirst) ; } + for(unsigned int i=0;i::iterator it(_incoming_file_hashes.find(peers_to_remove[i].first)) ; - - if(it != _incoming_file_hashes.end()) - service = it->second.service ; - else - std::cerr << "p3turtle::autowash(): ERROR. No service associated to hash " << peers_to_remove[i].first << ": this is super weird." << std::endl; - } - // All calls to services are done off-mutex, to avoir cross-lock - // - if(service != NULL) - service->removeVirtualPeer(peers_to_remove[i].first,peers_to_remove[i].second) ; +//#ifdef P3TURTLE_DEBUG + std::cerr << " removing virtual peer id " << services_vpids_to_remove[i].second.second << " for service " << services_vpids_to_remove[i].first <<", for hash " << services_vpids_to_remove[i].second.first << std::endl ; +//#endif + services_vpids_to_remove[i].first->removeVirtualPeer(services_vpids_to_remove[i].second.first,services_vpids_to_remove[i].second.second) ; } } -void p3turtle::locked_closeTunnel(TurtleTunnelId tid,std::vector >& sources_to_remove) +void p3turtle::locked_closeTunnel(TurtleTunnelId tid,std::vector > >& sources_to_remove) { // This is closing a given tunnel, removing it from file sources, and from the list of tunnels of its // corresponding file hash. In the original turtle4privacy paradigm, they also send back and forward @@ -545,7 +535,7 @@ void p3turtle::locked_closeTunnel(TurtleTunnelId tid,std::vector(hash,vpid)) ; + std::pair hash_vpid(hash,vpid) ; // Let's be cautious. Normally we should never be here without consistent information, // but still, this happens, rarely. @@ -571,6 +561,8 @@ void p3turtle::locked_closeTunnel(TurtleTunnelId tid,std::vector >(it->second.service,hash_vpid)) ; } } else if(it->second.local_dst == mLinkMgr->getOwnId()) // This is a ending tunnel. We also remove the virtual peer id @@ -580,7 +572,16 @@ void p3turtle::locked_closeTunnel(TurtleTunnelId tid,std::vector::iterator itHash = _outgoing_file_hashes.find(it->second.hash); if(itHash != _outgoing_file_hashes.end()) + { + TurtleVirtualPeerId vpid = it->second.vpid ; + TurtleFileHash hash = it->second.hash ; + + std::pair hash_vpid(hash,vpid) ; + + sources_to_remove.push_back(std::pair >(itHash->second,hash_vpid)) ; + _outgoing_file_hashes.erase(itHash) ; + } } _local_tunnels.erase(it) ; @@ -1009,11 +1010,11 @@ void p3turtle::routeGenericTunnelItem(RsTurtleGenericTunnelItem *item) item->setTravelingDirection(RsTurtleGenericTunnelItem::DIRECTION_SERVER) ; else { - std::cerr << "(EE) critical error in p3turtle::routeGenericTunnelItem(): item mismatches tunnel src/dst ids." << std::endl; + std::cerr << "(EE) p3turtle::routeGenericTunnelItem(): item mismatches tunnel src/dst ids." << std::endl; std::cerr << "(EE) tunnel.local_src = " << tunnel.local_src << std::endl; std::cerr << "(EE) tunnel.local_dst = " << tunnel.local_dst << std::endl; std::cerr << "(EE) item->PeerId() = " << item->PeerId() << std::endl; - std::cerr << "(EE) Deleting this item." << std::endl ; + std::cerr << "(EE) This item is probably lost while tunnel route got redefined. Deleting this item." << std::endl ; delete item ; return ; } diff --git a/libretroshare/src/turtle/p3turtle.h b/libretroshare/src/turtle/p3turtle.h index aaa3f6d96..99b200cc5 100644 --- a/libretroshare/src/turtle/p3turtle.h +++ b/libretroshare/src/turtle/p3turtle.h @@ -342,7 +342,7 @@ class p3turtle: public p3Service, public RsTurtle, public p3Config /// The hashes and peers to remove (by calling /// ftController::removeFileSource() are happended to the supplied vector /// so that they can be removed off the turtle mutex. - void locked_closeTunnel(TurtleTunnelId tid,std::vector >& peers_to_remove) ; + void locked_closeTunnel(TurtleTunnelId tid,std::vector > >& peers_to_remove) ; /// Main routing function int handleIncoming();