added missing code for remote search by hash, fixing the bug of direct sources not added

This commit is contained in:
csoler 2017-09-03 23:32:48 +02:00
parent 8d146038c2
commit 160ab7b4f3
4 changed files with 39 additions and 7 deletions

View File

@ -923,7 +923,12 @@ bool RemoteDirectoryStorage::deserialiseUpdateDirEntry(const EntryIndex& indx,co
return true ;
}
int RemoteDirectoryStorage::searchHash(const RsFileHash& hash, EntryIndex& result) const
{
RS_STACK_MUTEX(mDirStorageMtx) ;
return mFileHierarchy->searchHash(hash,result);
}

View File

@ -203,6 +203,18 @@ public:
* \return
*/
time_t& lastSweepTime() { return mLastSweepTime ; }
/*!
* \brief searchHash
* Looks into local database of shared files for the given hash.
* \param hash hash to look for
* \param results Entry index of the file that is found
* \return
* true is a file is found
* false otherwise.
*/
virtual int searchHash(const RsFileHash& hash, EntryIndex& results) const ;
private:
time_t mLastSweepTime ;
};

View File

@ -1089,7 +1089,23 @@ bool p3FileDatabase::search(const RsFileHash &hash, FileSearchFlags hintflags, F
if(hintflags & RS_FILE_HINTS_REMOTE)
{
NOT_IMPLEMENTED();
EntryIndex indx;
bool found = false ;
for(uint32_t i=0;i<mRemoteDirectories.size();++i)
if(mRemoteDirectories[i] != NULL && mRemoteDirectories[i]->searchHash(hash,indx))
{
TransferInfo ti ;
ti.peerId = mRemoteDirectories[i]->peerId();
info.hash = hash ;
info.peers.push_back(ti) ;
found = true ;
}
if(found)
return true;
}
return false;
}

View File

@ -69,10 +69,9 @@
* #define CONTROL_DEBUG 1
* #define DEBUG_DWLQUEUE 1
*****/
#define CONTROL_DEBUG 1
static const int32_t SAVE_TRANSFERS_DELAY = 60;//301 ; // save transfer progress every 301 seconds.
static const int32_t INACTIVE_CHUNKS_CHECK_DELAY = 240 ; // time after which an inactive chunk is released
static const int32_t SAVE_TRANSFERS_DELAY = 301 ; // save transfer progress every 301 seconds.
static const int32_t INACTIVE_CHUNKS_CHECK_DELAY = 240 ; // time after which an inactive chunk is released
static const int32_t MAX_TIME_INACTIVE_REQUEUED = 120 ; // time after which an inactive ftFileControl is bt-queued
static const int32_t FT_FILECONTROL_QUEUE_ADD_END = 0 ;
@ -235,14 +234,14 @@ void ftController::data_tick()
time_t now = time(NULL) ;
if(now > last_save_time + SAVE_TRANSFERS_DELAY)
{
searchForDirectSources() ;
IndicateConfigChanged() ;
last_save_time = now ;
}
if(now > last_clean_time + INACTIVE_CHUNKS_CHECK_DELAY)
{
searchForDirectSources() ;
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
for(std::map<RsFileHash,ftFileControl*>::iterator it(mDownloads.begin());it!=mDownloads.end();++it)