changed std::string into RsFileHash for all file hashes

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-IdCleaning@7137 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2014-02-20 21:12:04 +00:00
parent 533216c9e3
commit acf34cd7ad
84 changed files with 698 additions and 718 deletions

View file

@ -261,10 +261,10 @@ int p3turtle::tick()
//
void p3turtle::locked_addDistantPeer(const TurtleFileHash&,TurtleTunnelId tid)
{
unsigned char tmp[SSLIdType::SIZE_IN_BYTES] ;
unsigned char tmp[RsPeerId::SIZE_IN_BYTES] ;
((uint32_t*)tmp)[0] = tid ;
SSLIdType virtual_peer_id(tmp) ;
RsPeerId virtual_peer_id(tmp) ;
_virtual_peers[virtual_peer_id] = tid ;
#ifdef P3TURTLE_DEBUG
@ -603,7 +603,7 @@ void p3turtle::locked_closeTunnel(TurtleTunnelId tid,std::vector<std::pair<RsTur
_local_tunnels.erase(it) ;
}
void p3turtle::stopMonitoringTunnels(const std::string& hash)
void p3turtle::stopMonitoringTunnels(const RsFileHash& hash)
{
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
@ -721,7 +721,7 @@ uint32_t p3turtle::generatePersonalFilePrint(const TurtleFileHash& hash,uint32_t
// The only important thing is that the saem couple (hash,SSL id) produces the same tunnel
// id. The result uses a boolean to allow generating non symmetric tunnel ids.
std::string buff(hash + mLinkMgr->getOwnId().toStdString()) ;
std::string buff(hash.toStdString() + mLinkMgr->getOwnId().toStdString()) ;
uint32_t res = seed ;
uint32_t decal = 0 ;
@ -869,7 +869,7 @@ void p3turtle::handleSearchRequest(RsTurtleSearchRequestItem *item)
}
res_item->result.push_back(result.front()) ;
item_size += 8 /* size */ + result.front().hash.size() + result.front().name.size() ;
item_size += 8 /* size */ + result.front().hash.serial_size() + result.front().name.size() ;
result.pop_front() ;
if(item_size > RSTURTLE_MAX_SEARCH_RESPONSE_SIZE || result.empty())
@ -893,13 +893,13 @@ void p3turtle::handleSearchRequest(RsTurtleSearchRequestItem *item)
if(item->depth < TURTLE_MAX_SEARCH_DEPTH || random_bypass)
{
std::list<SSLIdType> onlineIds ;
std::list<RsPeerId> onlineIds ;
mLinkMgr->getOnlineList(onlineIds);
#ifdef P3TURTLE_DEBUG
std::cerr << " Looking for online peers" << std::endl ;
#endif
for(std::list<SSLIdType>::const_iterator it(onlineIds.begin());it!=onlineIds.end();++it)
for(std::list<RsPeerId>::const_iterator it(onlineIds.begin());it!=onlineIds.end();++it)
{
if(!(RS_SERVICE_PERM_TURTLE & rsPeers->servicePermissionFlags(*it)))
continue ;
@ -1086,8 +1086,8 @@ void p3turtle::handleRecvGenericTunnelItem(RsTurtleGenericTunnelItem *item)
std::cerr << "p3Turtle: received Generic tunnel item:" << std::endl ;
item->print(std::cerr,1) ;
#endif
std::string hash ;
SSLIdType vpid ;
RsFileHash hash ;
RsPeerId vpid ;
RsTurtleClientService *service ;
if(!getTunnelServiceInfo(item->tunnelId(),vpid,hash,service))
@ -1096,7 +1096,7 @@ void p3turtle::handleRecvGenericTunnelItem(RsTurtleGenericTunnelItem *item)
service->receiveTurtleData(item,hash,vpid,item->travelingDirection()) ;
}
bool p3turtle::getTunnelServiceInfo(TurtleTunnelId tunnel_id,SSLIdType& vpid,std::string& hash,RsTurtleClientService *& service)
bool p3turtle::getTunnelServiceInfo(TurtleTunnelId tunnel_id,RsPeerId& vpid,RsFileHash& hash,RsTurtleClientService *& service)
{
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
@ -1126,7 +1126,7 @@ bool p3turtle::getTunnelServiceInfo(TurtleTunnelId tunnel_id,SSLIdType& vpid,std
// Now sort out the case of client vs. server side items.
//
SSLIdType ownid = mLinkMgr->getOwnId() ;
RsPeerId ownid = mLinkMgr->getOwnId() ;
if(tunnel.local_src == ownid)
{
@ -1162,7 +1162,7 @@ bool p3turtle::getTunnelServiceInfo(TurtleTunnelId tunnel_id,SSLIdType& vpid,std
}
// Send a data request into the correct tunnel for the given file hash
//
void p3turtle::sendTurtleData(const SSLIdType& virtual_peer_id,RsTurtleGenericTunnelItem *item)
void p3turtle::sendTurtleData(const RsPeerId& virtual_peer_id,RsTurtleGenericTunnelItem *item)
{
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
@ -1190,7 +1190,7 @@ void p3turtle::sendTurtleData(const SSLIdType& virtual_peer_id,RsTurtleGenericTu
item->tunnel_id = tunnel_id ; // we should randomly select a tunnel, or something more clever.
SSLIdType ownid = mLinkMgr->getOwnId() ;
RsPeerId ownid = mLinkMgr->getOwnId() ;
uint32_t ss = item->serial_size() ;
if(item->shouldStampTunnel())
@ -1223,14 +1223,14 @@ void p3turtle::sendTurtleData(const SSLIdType& virtual_peer_id,RsTurtleGenericTu
sendItem(item) ;
}
bool p3turtle::isTurtlePeer(const SSLIdType& peer_id) const
bool p3turtle::isTurtlePeer(const RsPeerId& peer_id) const
{
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
return _virtual_peers.find(peer_id) != _virtual_peers.end() ;
}
SSLIdType p3turtle::getTurtlePeerId(TurtleTunnelId tid) const
RsPeerId p3turtle::getTurtlePeerId(TurtleTunnelId tid) const
{
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
@ -1244,7 +1244,7 @@ SSLIdType p3turtle::getTurtlePeerId(TurtleTunnelId tid) const
return it->second.vpid ;
}
bool p3turtle::isOnline(const SSLIdType& peer_id) const
bool p3turtle::isOnline(const RsPeerId& peer_id) const
{
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
@ -1469,13 +1469,13 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
if(item->depth < TURTLE_MAX_SEARCH_DEPTH || random_bypass)
{
std::list<SSLIdType> onlineIds ;
std::list<RsPeerId> onlineIds ;
mLinkMgr->getOnlineList(onlineIds);
for(std::list<SSLIdType>::iterator it(onlineIds.begin());it!=onlineIds.end();)
for(std::list<RsPeerId>::iterator it(onlineIds.begin());it!=onlineIds.end();)
if(!(RS_SERVICE_PERM_TURTLE & rsPeers->servicePermissionFlags(*it)))
{
std::list<SSLIdType>::iterator tmp = it++ ;
std::list<RsPeerId>::iterator tmp = it++ ;
onlineIds.erase(tmp) ;
}
else
@ -1499,7 +1499,7 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
std::cerr << " Forwarding tunnel request: Looking for online peers" << std::endl ;
#endif
for(std::list<SSLIdType>::const_iterator it(onlineIds.begin());it!=onlineIds.end();++it)
for(std::list<RsPeerId>::const_iterator it(onlineIds.begin());it!=onlineIds.end();++it)
{
uint32_t linkType = mLinkMgr->getLinkType(*it);
@ -1544,7 +1544,7 @@ void p3turtle::handleTunnelResult(RsTurtleTunnelOkItem *item)
{
bool new_tunnel = false ;
TurtleFileHash new_hash ;
SSLIdType new_vpid ;
RsPeerId new_vpid ;
RsTurtleClientService *service = NULL ;
{
@ -1819,7 +1819,7 @@ TurtleRequestId p3turtle::turtleSearch(const LinearizedExpression& expr)
return id ;
}
void p3turtle::monitorTunnels(const std::string& hash,RsTurtleClientService *client_service)
void p3turtle::monitorTunnels(const RsFileHash& hash,RsTurtleClientService *client_service)
{
{
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
@ -1875,7 +1875,7 @@ 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 SSLIdType& peer_id,RsTurtleClientService *& service)
bool p3turtle::performLocalHashSearch(const TurtleFileHash& hash,const RsPeerId& peer_id,RsTurtleClientService *& service)
{
if(_registered_services.empty())
std::cerr << "Turtle router has no services registered. Tunnel requests cannot be handled." << std::endl;
@ -1953,7 +1953,7 @@ void p3turtle::getTrafficStatistics(TurtleTrafficStatisticsInfo& info) const
float distance_to_maximum = std::min(100.0f,info.tr_up_Bps/(float)(TUNNEL_REQUEST_PACKET_SIZE*_max_tr_up_rate)) ;
info.forward_probabilities.clear() ;
std::list<SSLIdType> onlineIds ;
std::list<RsPeerId> onlineIds ;
mLinkMgr->getOnlineList(onlineIds);
int nb_online_ids = onlineIds.size() ;
@ -1992,7 +1992,7 @@ void p3turtle::getInfo( std::vector<std::vector<std::string> >& hashes_info,
std::vector<std::string>& hashes(hashes_info.back()) ;
hashes.push_back(it->first) ;
hashes.push_back(it->first.toStdString()) ;
//hashes.push_back(it->second.name) ;
hashes.push_back("Name not available") ;
hashes.push_back(printNumber(it->second.tunnels.size())) ;
@ -2019,7 +2019,7 @@ void p3turtle::getInfo( std::vector<std::vector<std::string> >& hashes_info,
else
tunnel.push_back(it->second.local_dst.toStdString());
tunnel.push_back(it->second.hash) ;
tunnel.push_back(it->second.hash.toStdString()) ;
tunnel.push_back(printNumber(now-it->second.time_stamp) + " secs ago") ;
tunnel.push_back(printFloatNumber(it->second.speed_Bps,true)) ;
}

View file

@ -250,12 +250,12 @@ class p3turtle: public p3Service, public RsTurtle, public p3Config
// This function should be called in addition to ftServer::FileRequest() so that the turtle router
// automatically provide tunnels for the file to download.
//
virtual void monitorTunnels(const std::string& file_hash,RsTurtleClientService *client_service) ;
virtual void monitorTunnels(const RsFileHash& file_hash,RsTurtleClientService *client_service) ;
/// This should be called when canceling a file download, so that the turtle router stops
/// handling tunnels for this file.
///
virtual void stopMonitoringTunnels(const std::string& file_hash) ;
virtual void stopMonitoringTunnels(const RsFileHash& file_hash) ;
/// Adds a client tunnel service. This means that the service will be added
/// to the list of services that might respond to tunnel requests.
@ -352,7 +352,7 @@ class p3turtle: public p3Service, public RsTurtle, public p3Config
/// specific routing functions for handling particular packets.
void handleRecvGenericTunnelItem(RsTurtleGenericTunnelItem *item);
bool getTunnelServiceInfo(TurtleTunnelId, SSLIdType& virtual_peer_id, std::string& hash, RsTurtleClientService*&) ;
bool getTunnelServiceInfo(TurtleTunnelId, SSLIdType& virtual_peer_id, RsFileHash& hash, RsTurtleClientService*&) ;
// following functions should go to ftServer
void handleSearchRequest(RsTurtleSearchRequestItem *item);

View file

@ -60,7 +60,7 @@ uint32_t RsTurtleSearchResultItem::serial_size()
for(std::list<TurtleFileInfo>::const_iterator it(result.begin());it!=result.end();++it)
{
s += 8 ; // file size
s += GetTlvStringSize(it->hash) ; // file hash
s += it->hash.serial_size(); // file hash
s += GetTlvStringSize(it->name) ; // file name
}
@ -72,7 +72,7 @@ uint32_t RsTurtleOpenTunnelItem::serial_size()
uint32_t s = 0 ;
s += 8 ; // header
s += GetTlvStringSize(file_hash) ; // file hash
s += file_hash.serial_size() ; // file hash
s += 4 ; // tunnel request id
s += 4 ; // partial tunnel id
s += 2 ; // depth
@ -333,8 +333,8 @@ bool RsTurtleSearchResultItem::serialize(void *data,uint32_t& pktsize)
for(std::list<TurtleFileInfo>::const_iterator it(result.begin());it!=result.end();++it)
{
ok &= setRawUInt64(data, tlvsize, &offset, it->size); // file size
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_HASH_SHA1, it->hash); // file hash
ok &= setRawUInt64(data, tlvsize, &offset, it->size); // file size
ok &= it->hash.serialise(data, tlvsize, offset); // file hash
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, it->name); // file name
}
@ -377,7 +377,7 @@ RsTurtleSearchResultItem::RsTurtleSearchResultItem(void *data,uint32_t pktsize)
TurtleFileInfo f ;
ok &= getRawUInt64(data, pktsize, &offset, &(f.size)); // file size
ok &= GetTlvString(data, pktsize, &offset, TLV_TYPE_STR_HASH_SHA1, f.hash); // file hash
ok &= f.hash.deserialise(data, pktsize, offset); // file hash
ok &= GetTlvString(data, pktsize, &offset, TLV_TYPE_STR_NAME, f.name); // file name
result.push_back(f) ;
@ -412,7 +412,7 @@ bool RsTurtleOpenTunnelItem::serialize(void *data,uint32_t& pktsize)
/* add mandatory parts first */
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_HASH_SHA1, file_hash); // file hash
ok &= file_hash.serialise(data, tlvsize, offset); // file hash
ok &= setRawUInt32(data, tlvsize, &offset, request_id);
ok &= setRawUInt32(data, tlvsize, &offset, partial_tunnel_id);
ok &= setRawUInt16(data, tlvsize, &offset, depth);
@ -441,7 +441,7 @@ RsTurtleOpenTunnelItem::RsTurtleOpenTunnelItem(void *data,uint32_t pktsize)
/* add mandatory parts first */
bool ok = true ;
ok &= GetTlvString(data, pktsize, &offset, TLV_TYPE_STR_HASH_SHA1, file_hash); // file hash
ok &= file_hash.deserialise(data, pktsize, offset); // file hash
ok &= getRawUInt32(data, pktsize, &offset, &request_id);
ok &= getRawUInt32(data, pktsize, &offset, &partial_tunnel_id) ;
ok &= getRawUInt16(data, pktsize, &offset, &depth);

View file

@ -46,7 +46,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 SSLIdType& /*peer_id*/) { return false ; }
virtual bool handleTunnelRequest(const RsFileHash& /*hash*/,const RsPeerId& /*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
@ -66,7 +66,7 @@ class RsTurtleClientService
// By default (if not overloaded), the method will just free the data, as any subclass should do as well.
// Note: p3turtle stays owner of the item, so the client should not delete it!
//
virtual void receiveTurtleData(RsTurtleGenericTunnelItem */*item*/,const std::string& /*hash*/,const SSLIdType& /*virtual_peer_id*/,RsTurtleGenericTunnelItem::Direction /*direction*/)
virtual void receiveTurtleData(RsTurtleGenericTunnelItem */*item*/,const RsFileHash& /*hash*/,const RsPeerId& /*virtual_peer_id*/,RsTurtleGenericTunnelItem::Direction /*direction*/)
{
std::cerr << "!!!!!! Received Data from turtle router, but the client service is not handling it !!!!!!!!!!" << std::endl ;
}

View file

@ -2,9 +2,9 @@
#include "retroshare/rsturtle.h"
typedef SSLIdType TurtlePeerId ;
typedef SSLIdType TurtleVirtualPeerId ;
typedef std::string TurtleFileHash ;
typedef RsPeerId TurtlePeerId ;
typedef RsPeerId TurtleVirtualPeerId ;
typedef RsFileHash TurtleFileHash ;
typedef std::string TurtleFileName ;
typedef TurtleRequestId TurtleSearchRequestId ;