mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-07 14:12:43 -04:00
replace std::vector for std::set to represent _hashes_to_remove, so as to avoid duplicates (suggested by Jo)
This commit is contained in:
parent
1fd624ccb4
commit
b62b66a24c
2 changed files with 13 additions and 18 deletions
|
@ -430,21 +430,21 @@ void p3turtle::autoWash()
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
for(unsigned int i=0;i<_hashes_to_remove.size();++i)
|
for(std::set<RsFileHash>::const_iterator hit(_hashes_to_remove.begin());hit!=_hashes_to_remove.end();++hit)
|
||||||
{
|
{
|
||||||
std::map<TurtleFileHash,TurtleHashInfo>::iterator it(_incoming_file_hashes.find(_hashes_to_remove[i])) ;
|
std::map<TurtleFileHash,TurtleHashInfo>::iterator it(_incoming_file_hashes.find(*hit)) ;
|
||||||
|
|
||||||
if(it == _incoming_file_hashes.end())
|
if(it == _incoming_file_hashes.end())
|
||||||
{
|
{
|
||||||
#ifdef P3TURTLE_DEBUG
|
#ifdef P3TURTLE_DEBUG
|
||||||
std::cerr << "p3turtle: asked to stop monitoring file hash " << _hashes_to_remove[i] << ", but this hash is actually not handled by the turtle router." << std::endl ;
|
std::cerr << "p3turtle: asked to stop monitoring file hash " << *hit << ", but this hash is actually not handled by the turtle router." << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
continue ;
|
continue ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy the list of tunnels to remove.
|
// copy the list of tunnels to remove.
|
||||||
#ifdef P3TURTLE_DEBUG
|
#ifdef P3TURTLE_DEBUG
|
||||||
std::cerr << "p3turtle: stopping monitoring for file hash " << _hashes_to_remove[i] << ", and closing " << it->second.tunnels.size() << " tunnels (" ;
|
std::cerr << "p3turtle: stopping monitoring for file hash " << *hit << ", and closing " << it->second.tunnels.size() << " tunnels (" ;
|
||||||
#endif
|
#endif
|
||||||
std::vector<TurtleTunnelId> tunnels_to_remove ;
|
std::vector<TurtleTunnelId> tunnels_to_remove ;
|
||||||
|
|
||||||
|
@ -463,11 +463,8 @@ void p3turtle::autoWash()
|
||||||
|
|
||||||
_incoming_file_hashes.erase(it) ;
|
_incoming_file_hashes.erase(it) ;
|
||||||
}
|
}
|
||||||
if(!_hashes_to_remove.empty())
|
|
||||||
{
|
_hashes_to_remove.clear() ;
|
||||||
IndicateConfigChanged() ; // initiates saving of handled hashes.
|
|
||||||
_hashes_to_remove.clear() ;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// look for tunnels and stored temporary info that have not been used for a while.
|
// look for tunnels and stored temporary info that have not been used for a while.
|
||||||
|
@ -657,7 +654,7 @@ void p3turtle::stopMonitoringTunnels(const RsFileHash& hash)
|
||||||
std::cerr << "p3turtle: Marking hash " << hash << " to be removed during autowash." << std::endl ;
|
std::cerr << "p3turtle: Marking hash " << hash << " to be removed during autowash." << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
// We don't do the deletion in this process, because it can cause a race with tunnel management.
|
// We don't do the deletion in this process, because it can cause a race with tunnel management.
|
||||||
_hashes_to_remove.push_back(hash) ;
|
_hashes_to_remove.insert(hash) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
|
@ -1855,15 +1852,13 @@ void p3turtle::monitorTunnels(const RsFileHash& hash,RsTurtleClientService *clie
|
||||||
|
|
||||||
// First, check if the hash is tagged for removal (there's a delay)
|
// First, check if the hash is tagged for removal (there's a delay)
|
||||||
|
|
||||||
for(uint32_t i=0;i<_hashes_to_remove.size();++i)
|
if(_hashes_to_remove.find(hash) != _hashes_to_remove.end())
|
||||||
if(_hashes_to_remove[i] == hash)
|
{
|
||||||
{
|
_hashes_to_remove.erase(hash) ;
|
||||||
_hashes_to_remove[i] = _hashes_to_remove.back() ;
|
|
||||||
_hashes_to_remove.pop_back() ;
|
|
||||||
#ifdef P3TURTLE_DEBUG
|
#ifdef P3TURTLE_DEBUG
|
||||||
std::cerr << "p3turtle: File hash " << hash << " Was scheduled for removal. Canceling the removal." << std::endl ;
|
std::cerr << "p3turtle: File hash " << hash << " Was scheduled for removal. Canceling the removal." << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then, check if the hash is already there
|
// Then, check if the hash is already there
|
||||||
//
|
//
|
||||||
|
|
|
@ -409,7 +409,7 @@ class p3turtle: public p3Service, public RsTurtle, public p3Config
|
||||||
std::map<TurtleVirtualPeerId,TurtleTunnelId> _virtual_peers ;
|
std::map<TurtleVirtualPeerId,TurtleTunnelId> _virtual_peers ;
|
||||||
|
|
||||||
/// Hashes marked to be deleted.
|
/// Hashes marked to be deleted.
|
||||||
std::vector<TurtleFileHash> _hashes_to_remove ;
|
std::set<TurtleFileHash> _hashes_to_remove ;
|
||||||
|
|
||||||
/// List of client services that have regitered.
|
/// List of client services that have regitered.
|
||||||
std::list<RsTurtleClientService*> _registered_services ;
|
std::list<RsTurtleClientService*> _registered_services ;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue