mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 06:06:10 -04:00
- lots of debugging.
- added missing bits to turtle router for better handling symmetric traffic git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-GenericTunneling@6321 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
56e71b51fa
commit
1c3ff8c54b
7 changed files with 169 additions and 80 deletions
|
@ -578,7 +578,7 @@ void p3turtle::locked_closeTunnel(TurtleTunnelId tid,std::vector<std::pair<Turtl
|
|||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " Tunnel is a ending point. Also removing associated outgoing hash." ;
|
||||
#endif
|
||||
std::map<TurtleFileHash,std::string>::iterator itHash = _outgoing_file_hashes.find(it->second.hash);
|
||||
std::map<TurtleFileHash,RsTurtleClientService*>::iterator itHash = _outgoing_file_hashes.find(it->second.hash);
|
||||
if(itHash != _outgoing_file_hashes.end())
|
||||
_outgoing_file_hashes.erase(itHash) ;
|
||||
}
|
||||
|
@ -1094,7 +1094,7 @@ bool p3turtle::getTunnelServiceInfo(TurtleTunnelId tunnel_id,std::string& vpid,s
|
|||
if(it2 == _local_tunnels.end())
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << "p3turtle: got file CRC32 map with unknown tunnel id " << (void*)item->tunnelId() << std::endl ;
|
||||
std::cerr << "p3turtle: unknown tunnel id " << (void*)item->tunnelId() << std::endl ;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
@ -1113,15 +1113,39 @@ bool p3turtle::getTunnelServiceInfo(TurtleTunnelId tunnel_id,std::string& vpid,s
|
|||
vpid = tunnel.vpid ;
|
||||
hash = tunnel.hash ;
|
||||
|
||||
std::map<TurtleFileHash,TurtleHashInfo>::const_iterator it = _incoming_file_hashes.find(hash) ;
|
||||
// Now sort out the case of client vs. server side items.
|
||||
//
|
||||
std::string ownid = mLinkMgr->getOwnId() ;
|
||||
|
||||
if(it == _incoming_file_hashes.end())
|
||||
if(tunnel.local_src == ownid)
|
||||
{
|
||||
std::cerr << "p3turtle::handleRecvGenericTunnelItem(): hash " << hash << " for tunnel " << (void*)(it2->first) << " has no attached service! Dropping the item. This is a serious consistency error." << std::endl;
|
||||
return false;
|
||||
}
|
||||
std::map<TurtleFileHash,TurtleHashInfo>::const_iterator it = _incoming_file_hashes.find(hash) ;
|
||||
|
||||
service = it->second.service ;
|
||||
if(it == _incoming_file_hashes.end())
|
||||
{
|
||||
std::cerr << "p3turtle::handleRecvGenericTunnelItem(): hash " << hash << " for tunnel " << (void*)(it2->first) << " has no attached service! Dropping the item. This is a serious consistency error." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
service = it->second.service ;
|
||||
}
|
||||
else if(tunnel.local_dst == ownid)
|
||||
{
|
||||
std::map<TurtleFileHash,RsTurtleClientService*>::const_iterator it = _outgoing_file_hashes.find(hash) ;
|
||||
|
||||
if(it == _outgoing_file_hashes.end())
|
||||
{
|
||||
std::cerr << "p3turtle::handleRecvGenericTunnelItem(): hash " << hash << " for tunnel " << (void*)(it2->first) << " has no attached service! Dropping the item. This is a serious consistency error." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
service = it->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "p3turtle::handleRecvGenericTunnelItem(): hash " << hash << " for tunnel " << (void*)(it2->first) << ". Tunnel is not a end-point or a starting tunnel!! This is a serious consistency error." << std::endl;
|
||||
return false ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
@ -1391,13 +1415,14 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
|
|||
|
||||
bool found = false ;
|
||||
std::string info ;
|
||||
RsTurtleClientService *service = NULL ;
|
||||
|
||||
if(item->PeerId() != mLinkMgr->getOwnId())
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " Request not from us. Performing local search" << std::endl ;
|
||||
#endif
|
||||
found = performLocalHashSearch(item->file_hash,item->PeerId(),info) ;
|
||||
found = performLocalHashSearch(item->file_hash,item->PeerId(),service) ;
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -1435,9 +1460,15 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
|
|||
|
||||
// Store some info string about the tunnel.
|
||||
//
|
||||
_outgoing_file_hashes[item->file_hash] = info ;
|
||||
_outgoing_file_hashes[item->file_hash] = service ;
|
||||
|
||||
// Notify the client service that there's a new virtual peer id available as a client.
|
||||
//
|
||||
service->addVirtualPeer(item->file_hash,_local_tunnels[res_item->tunnel_id].vpid,RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ;
|
||||
|
||||
// We return straight, because when something is found, there's no need to digg a tunnel further.
|
||||
//
|
||||
|
||||
return ;
|
||||
}
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
|
@ -1646,7 +1677,7 @@ void p3turtle::handleTunnelResult(RsTurtleTunnelOkItem *item)
|
|||
// so we deported this code here.
|
||||
//
|
||||
if(new_tunnel && service != NULL)
|
||||
service->addVirtualPeer(new_hash,new_vpid) ;
|
||||
service->addVirtualPeer(new_hash,new_vpid,RsTurtleGenericTunnelItem::DIRECTION_SERVER) ;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
|
@ -1857,14 +1888,17 @@ void p3turtle::returnSearchResult(RsTurtleSearchResultItem *item)
|
|||
/// Warning: this function should never be called while the turtle mutex is locked.
|
||||
/// Otherwize this is a possible source of cross-lock with the File mutex.
|
||||
//
|
||||
bool p3turtle::performLocalHashSearch(const TurtleFileHash& hash,const std::string& peer_id,std::string& description_string)
|
||||
bool p3turtle::performLocalHashSearch(const TurtleFileHash& hash,const std::string& peer_id,RsTurtleClientService *& service)
|
||||
{
|
||||
if(_registered_services.empty())
|
||||
std::cerr << "Turtle router has no services registered. Tunnel requests cannot be handled." << std::endl;
|
||||
|
||||
for(std::list<RsTurtleClientService*>::const_iterator it(_registered_services.begin());it!=_registered_services.end();++it)
|
||||
if( (*it)->handleTunnelRequest(hash,peer_id,description_string))
|
||||
if( (*it)->handleTunnelRequest(hash,peer_id))
|
||||
{
|
||||
service = *it ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
return false ;
|
||||
}
|
||||
|
|
|
@ -369,7 +369,7 @@ class p3turtle: public p3Service, public RsTurtle, public p3Config
|
|||
void returnSearchResult(RsTurtleSearchResultItem *item) ;
|
||||
|
||||
/// Returns true if the file with given hash is hosted locally, and accessible in anonymous mode the supplied peer.
|
||||
virtual bool performLocalHashSearch(const TurtleFileHash& hash,const std::string& client_peer_id,std::string& info) ;
|
||||
virtual bool performLocalHashSearch(const TurtleFileHash& hash,const std::string& client_peer_id,RsTurtleClientService *& service);
|
||||
|
||||
//--------------------------- Local variables --------------------------------//
|
||||
|
||||
|
@ -389,7 +389,7 @@ class p3turtle: public p3Service, public RsTurtle, public p3Config
|
|||
std::map<TurtleFileHash,TurtleHashInfo> _incoming_file_hashes ;
|
||||
|
||||
/// stores file info for each file we provide.
|
||||
std::map<TurtleFileHash,std::string> _outgoing_file_hashes ;
|
||||
std::map<TurtleFileHash,RsTurtleClientService *> _outgoing_file_hashes ;
|
||||
|
||||
/// local tunnels, stored by ids (Either transiting or ending).
|
||||
std::map<TurtleTunnelId,TurtleTunnel > _local_tunnels ;
|
||||
|
|
|
@ -45,7 +45,7 @@ class RsTurtleClientService
|
|||
// The output info_string is used by the turtle router to display info about tunnels it manages. It is
|
||||
// not passed to the tunnel.
|
||||
|
||||
virtual bool handleTunnelRequest(const std::string& hash,const std::string& peer_id,std::string& description_info_string) { return false ; }
|
||||
virtual bool handleTunnelRequest(const std::string& hash,const std::string& peer_id) { return false ; }
|
||||
|
||||
// This method is called by the turtle router to send data that comes out of a turtle tunnel.
|
||||
// The turtle router stays responsible for the memory management of data. Most of the time the
|
||||
|
@ -78,7 +78,7 @@ class RsTurtleClientService
|
|||
|
||||
// These methods are called by the turtle router to add/remove virtual peers when tunnels are created/deleted
|
||||
//
|
||||
virtual void addVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualPeerId& virtual_peer_id) = 0 ;
|
||||
virtual void addVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction dir) = 0 ;
|
||||
virtual void removeVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualPeerId& virtual_peer_id) = 0 ;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue