added some security checks to turtle router

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2208 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-02-05 22:45:52 +00:00
parent b47762cf12
commit 3e921bb254

View File

@ -367,29 +367,40 @@ void p3turtle::locked_closeTunnel(TurtleTunnelId tid)
std::cerr << " Associated file source." << std::endl ; std::cerr << " Associated file source." << std::endl ;
#endif #endif
_ft_controller->removeFileSource(hash,vpid) ; _ft_controller->removeFileSource(hash,vpid) ;
_virtual_peers.erase(_virtual_peers.find(vpid)) ;
std::vector<TurtleTunnelId>& tunnels(_incoming_file_hashes[hash].tunnels) ; // Let's be cautious. Normally we should never be here without consistent information,
// but still, this happens, rarely.
// Remove tunnel id from it's corresponding hash. For security we
// go through the whole tab, although the tunnel id should only be listed once
// in this tab.
// //
for(unsigned int i=0;i<tunnels.size();) if(_virtual_peers.find(vpid) != _virtual_peers.end())
if(tunnels[i] == tid) _virtual_peers.erase(_virtual_peers.find(vpid)) ;
{
tunnels[i] = tunnels.back() ; std::map<TurtleFileHash,TurtleFileHashInfo>::iterator it(_incoming_file_hashes.find(hash)) ;
tunnels.pop_back() ;
} if(it != _incoming_file_hashes.end())
else {
++i ; std::vector<TurtleTunnelId>& tunnels(it->second.tunnels) ;
// Remove tunnel id from it's corresponding hash. For security we
// go through the whole tab, although the tunnel id should only be listed once
// in this tab.
//
for(unsigned int i=0;i<tunnels.size();)
if(tunnels[i] == tid)
{
tunnels[i] = tunnels.back() ;
tunnels.pop_back() ;
}
else
++i ;
}
} }
else if(it->second.local_dst == mConnMgr->getOwnId()) // This is a ending tunnel. We also remove the virtual peer id else if(it->second.local_dst == mConnMgr->getOwnId()) // This is a ending tunnel. We also remove the virtual peer id
{ {
#ifdef P3TURTLE_DEBUG #ifdef P3TURTLE_DEBUG
std::cerr << " Tunnel is a ending point. Also removing associated outgoing hash." ; std::cerr << " Tunnel is a ending point. Also removing associated outgoing hash." ;
#endif #endif
_outgoing_file_hashes.erase(_outgoing_file_hashes.find(it->second.hash)) ; if(_outgoing_file_hashes.find(it->second.hash) != _outgoing_file_hashes.end())
_outgoing_file_hashes.erase(_outgoing_file_hashes.find(it->second.hash)) ;
} }
_local_tunnels.erase(it) ; _local_tunnels.erase(it) ;