fixed bug preventing search by hash to be called on own files

This commit is contained in:
csoler 2017-09-03 22:52:31 +02:00
parent 063783a859
commit 8d146038c2
3 changed files with 41 additions and 17 deletions

View File

@ -1073,24 +1073,23 @@ bool p3FileDatabase::search(const RsFileHash &hash, FileSearchFlags hintflags, F
RsFileHash real_hash ; RsFileHash real_hash ;
EntryIndex indx; EntryIndex indx;
if(!mLocalSharedDirs->searchHash(hash,real_hash,indx)) if(mLocalSharedDirs->searchHash(hash,real_hash,indx))
return false; {
mLocalSharedDirs->getFileInfo(indx,info) ;
mLocalSharedDirs->getFileInfo(indx,info) ; if(!real_hash.isNull())
{
info.hash = real_hash ;
info.transfer_info_flags |= RS_FILE_REQ_ENCRYPTED ;
}
if(!real_hash.isNull()) return true;
{ }
info.hash = real_hash ;
info.transfer_info_flags |= RS_FILE_REQ_ENCRYPTED ;
}
return true;
} }
if(hintflags & RS_FILE_HINTS_REMOTE) if(hintflags & RS_FILE_HINTS_REMOTE)
{ {
NOT_IMPLEMENTED(); NOT_IMPLEMENTED();
return false;
} }
return false; return false;
} }

View File

@ -69,8 +69,9 @@
* #define CONTROL_DEBUG 1 * #define CONTROL_DEBUG 1
* #define DEBUG_DWLQUEUE 1 * #define DEBUG_DWLQUEUE 1
*****/ *****/
#define CONTROL_DEBUG 1
static const int32_t SAVE_TRANSFERS_DELAY = 301 ; // save transfer progress every 301 seconds. 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 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 MAX_TIME_INACTIVE_REQUEUED = 120 ; // time after which an inactive ftFileControl is bt-queued
@ -222,8 +223,8 @@ void ftController::data_tick()
usleep(1*1000*1000); // 1 sec usleep(1*1000*1000); // 1 sec
#ifdef CONTROL_DEBUG #ifdef CONTROL_DEBUG
std::cerr << "ftController::run()"; //std::cerr << "ftController::run()";
std::cerr << std::endl; //std::cerr << std::endl;
#endif #endif
bool doPending = false; bool doPending = false;
{ {
@ -280,12 +281,24 @@ void ftController::data_tick()
void ftController::searchForDirectSources() void ftController::searchForDirectSources()
{ {
#ifdef CONTROL_DEBUG
std::cerr << "ftController::searchForDirectSources()" << std::endl;
#endif
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/ 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 ) for(std::map<RsFileHash,ftFileControl*>::iterator it(mDownloads.begin()); it != mDownloads.end(); ++it )
if(it->second->mState != ftFileControl::QUEUED && it->second->mState != ftFileControl::PAUSED ) 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) 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) ) if( mSearch->search(it->first, RS_FILE_HINTS_REMOTE | RS_FILE_HINTS_SPEC_ONLY, info) )
@ -300,8 +313,19 @@ void ftController::searchForDirectSources()
if( bAllowDirectDL ) if( bAllowDirectDL )
if( it->second->mTransfer->addFileSource(pit->peerId) ) /* if the sources don't exist already - add in */ 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) ); 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() void ftController::tickTransfers()
@ -311,7 +335,7 @@ void ftController::tickTransfers()
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/ RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
#ifdef CONTROL_DEBUG #ifdef CONTROL_DEBUG
std::cerr << "ticking transfers." << std::endl ; // std::cerr << "ticking transfers." << std::endl ;
#endif #endif
// Collect all non queued files. // Collect all non queued files.
// //

View File

@ -160,7 +160,8 @@ void ftServer::SetupFtServer()
void ftServer::connectToFileDatabase(p3FileDatabase *fdb) void ftServer::connectToFileDatabase(p3FileDatabase *fdb)
{ {
mFileDatabase = 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) void ftServer::connectToTurtleRouter(p3turtle *fts)
{ {