diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 38efb452e..5e112cc43 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -546,42 +546,68 @@ void ftServer::removeVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualP bool ftServer::handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_id) { FileInfo info ; - bool res = FileDetails(hash, RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_SPEC_ONLY, info); + RsFileHash real_hash ; + bool found = false ; - if(info.transfer_info_flags & RS_FILE_REQ_ENCRYPTED) + if(FileDetails(hash, RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_SPEC_ONLY, info)) { + if(info.transfer_info_flags & RS_FILE_REQ_ENCRYPTED) + { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "handleTunnelRequest: openning encrypted FT tunnel for H(H(F))=" << hash << " and H(F)=" << info.hash << std::endl; + FTSERVER_DEBUG() << "handleTunnelRequest: openning encrypted FT tunnel for H(H(F))=" << hash << " and H(F)=" << info.hash << std::endl; #endif - RS_STACK_MUTEX(srvMutex) ; - mEncryptedHashes[hash] = info.hash; - } -#warning needs to tweak for swarming with encrypted FT - if( (!res) && FileDetails(hash,RS_FILE_HINTS_DOWNLOAD,info)) - { - // This file is currently being downloaded. Let's look if we already have a chunk or not. If not, no need to - // share the file! + RS_STACK_MUTEX(srvMutex) ; + mEncryptedHashes[hash] = info.hash; - FileChunksInfo info2 ; - if(rsFiles->FileDownloadChunksDetails(hash, info2)) - for(uint32_t i=0;i::const_iterator it = mEncryptedHashes.find(hash) ; + + if(it != mEncryptedHashes.end()) + real_hash = it->second ; + else + real_hash = hash ; + } + + if(FileDetails(real_hash,RS_FILE_HINTS_DOWNLOAD,info)) + { + // This file is currently being downloaded. Let's look if we already have a chunk or not. If not, no need to + // share the file! + + FileChunksInfo info2 ; + if(rsFiles->FileDownloadChunksDetails(hash, info2)) + for(uint32_t i=0;icomputePeerPermissionFlags(peer_id,info.storage_permission_flags,info.parent_groups)) ; + found = found && (RS_FILE_HINTS_NETWORK_WIDE & rsPeers->computePeerPermissionFlags(peer_id,info.storage_permission_flags,info.parent_groups)) ; - return res ; + return found ; } /***************************************************************/