Merge pull request #1009 from csoler/v0.6-FT

V0.6 ft
This commit is contained in:
csoler 2017-09-04 16:48:17 +02:00 committed by GitHub
commit c6ffe07cd1
5 changed files with 78 additions and 22 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

@ -1073,9 +1073,8 @@ bool p3FileDatabase::search(const RsFileHash &hash, FileSearchFlags hintflags, F
RsFileHash real_hash ;
EntryIndex indx;
if(!mLocalSharedDirs->searchHash(hash,real_hash,indx))
return false;
if(mLocalSharedDirs->searchHash(hash,real_hash,indx))
{
mLocalSharedDirs->getFileInfo(indx,info) ;
if(!real_hash.isNull())
@ -1086,11 +1085,27 @@ bool p3FileDatabase::search(const RsFileHash &hash, FileSearchFlags hintflags, F
return true;
}
}
if(hintflags & RS_FILE_HINTS_REMOTE)
{
NOT_IMPLEMENTED();
return false;
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

@ -222,8 +222,8 @@ void ftController::data_tick()
usleep(1*1000*1000); // 1 sec
#ifdef CONTROL_DEBUG
std::cerr << "ftController::run()";
std::cerr << std::endl;
//std::cerr << "ftController::run()";
//std::cerr << std::endl;
#endif
bool doPending = false;
{
@ -234,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)
@ -280,12 +280,24 @@ void ftController::data_tick()
void ftController::searchForDirectSources()
{
#ifdef CONTROL_DEBUG
std::cerr << "ftController::searchForDirectSources()" << std::endl;
#endif
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
if (!mSearch) return;
if (!mSearch)
{
#ifdef CONTROL_DEBUG
std::cerr << " search module not available!" << std::endl;
#endif
return;
}
for(std::map<RsFileHash,ftFileControl*>::iterator it(mDownloads.begin()); it != mDownloads.end(); ++it )
if(it->second->mState != ftFileControl::QUEUED && it->second->mState != ftFileControl::PAUSED )
{
#ifdef CONTROL_DEBUG
std::cerr << " file " << it->first << ":" << std::endl;
#endif
FileInfo info ; // Info needs to be re-allocated each time, to start with a clear list of peers (it's not cleared down there)
if( mSearch->search(it->first, RS_FILE_HINTS_REMOTE | RS_FILE_HINTS_SPEC_ONLY, info) )
@ -300,8 +312,19 @@ void ftController::searchForDirectSources()
if( bAllowDirectDL )
if( it->second->mTransfer->addFileSource(pit->peerId) ) /* if the sources don't exist already - add in */
setPeerState( it->second->mTransfer, pit->peerId, FT_CNTRL_STANDARD_RATE, mServiceCtrl->isPeerConnected(mFtServiceType, pit->peerId) );
#ifdef CONTROL_DEBUG
std::cerr << " found source " << pit->peerId << ", allowDirectDL=" << bAllowDirectDL << ". " << (bAllowDirectDL?"adding":"not adding") << std::endl;
#endif
}
#ifdef CONTROL_DEBUG
else
std::cerr << " search returned empty.: " << std::endl;
#endif
}
#ifdef CONTROL_DEBUG
else
std::cerr << " file " << it->first << ": state is " << it->second->mState << ": ignored." << std::endl;
#endif
}
void ftController::tickTransfers()
@ -311,7 +334,7 @@ void ftController::tickTransfers()
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
#ifdef CONTROL_DEBUG
std::cerr << "ticking transfers." << std::endl ;
// std::cerr << "ticking transfers." << std::endl ;
#endif
// Collect all non queued files.
//

View File

@ -160,7 +160,8 @@ void ftServer::SetupFtServer()
void ftServer::connectToFileDatabase(p3FileDatabase *fdb)
{
mFileDatabase = fdb ;
mFtSearch->addSearchMode(fdb, RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_REMOTE);
mFtSearch->addSearchMode(fdb, RS_FILE_HINTS_LOCAL); // due to a bug in addSearchModule, modules can only be added one by one. Using | between flags wont work.
mFtSearch->addSearchMode(fdb, RS_FILE_HINTS_REMOTE);
}
void ftServer::connectToTurtleRouter(p3turtle *fts)
{