diff --git a/libretroshare/src/ft/fttransfermodule.cc b/libretroshare/src/ft/fttransfermodule.cc index c63815035..b2d71c77b 100644 --- a/libretroshare/src/ft/fttransfermodule.cc +++ b/libretroshare/src/ft/fttransfermodule.cc @@ -54,8 +54,15 @@ bool ftTransferModule::setFileSources(std::list peerIds) return true; } -bool ftTransferModule::setPeerState(std::string peerId,uint32_t state,uint32_t maxRate) //state = ONLINE/OFFLINE +bool ftTransferModule::setPeerState(std::string peerId,uint32_t state,uint32_t maxRate) { +#ifdef FT_DEBUG + std::cerr << "ftTransferModule::setPeerState()"; + std::cerr << " peerId: " << peerId; + std::cerr << " state: " << state; + std::cerr << " maxRate: " << maxRate << std::endl; +#endif + std::map::iterator mit; mit = mFileSources.find(peerId); @@ -64,7 +71,20 @@ bool ftTransferModule::setPeerState(std::string peerId,uint32_t state,uint32_t m (mit->second).state=state; (mit->second).desiredRate=maxRate; - if (state==PQIPEER_IDLE) mOnlinePeers.push_back(peerId); + std::list::iterator it; + it=mOnlinePeers.begin(); + while((it!=mOnlinePeers.end())&&(*it!=peerId)) it++; + + if (state!=PQIPEER_NOT_ONLINE) + { + //change to online, add peerId in online peer list + if (it==mOnlinePeers.end()) mOnlinePeers.push_back(peerId); + } + else + { + //change to offline, remove peerId in online peer list + if (it!=mOnlinePeers.end()) mOnlinePeers.erase(it); + } return true; } @@ -185,7 +205,7 @@ bool ftTransferModule::storeData(uint64_t offset, uint32_t chunk_size,void *data return mFileCreator -> addFileData(offset, chunk_size, data); } -void ftTransferModule::queryInactive() +bool ftTransferModule::queryInactive() { #ifdef FT_DEBUG std::cerr << "ftTransferModule::queryInactive()" << std::endl; @@ -195,7 +215,11 @@ void ftTransferModule::queryInactive() mFileStatus.stat = ftFileStatus::PQIFILE_DOWNLOADING; if (mFileStatus.stat != ftFileStatus::PQIFILE_DOWNLOADING) - return; + { + if (mFileStatus.stat == ftFileStatus::PQIFILE_FAIL_CANCEL) + mFlag = 2; //file canceled by user + return false; + } int ts = time(NULL); uint64_t req_offset; @@ -270,7 +294,8 @@ void ftTransferModule::queryInactive() break; }//switch }//for - + + return true; } bool ftTransferModule::pauseTransfer() @@ -317,9 +342,20 @@ bool ftTransferModule::completeFileTransfer() int ftTransferModule::tick() { queryInactive(); - if (mFlag != 1) adjustSpeed(); - else - completeFileTransfer(); + switch (mFlag) + { + case 0: + adjustSpeed(); + break; + case 1: + completeFileTransfer(); + break; + case 2: + /* tell me what to do here */ + break; + default: + break; + } return 0; } diff --git a/libretroshare/src/ft/fttransfermodule.h b/libretroshare/src/ft/fttransfermodule.h index 88cbd4b03..7d7c2a26f 100644 --- a/libretroshare/src/ft/fttransfermodule.h +++ b/libretroshare/src/ft/fttransfermodule.h @@ -90,7 +90,7 @@ public: uint64_t offset; uint32_t chunkSize; - //already received data size + //already received data size for current request uint32_t receivedSize; time_t lastTS; @@ -152,7 +152,7 @@ public: uint64_t size() { return mSize; } //internal used functions - void queryInactive(); + bool queryInactive(); void adjustSpeed(); private: @@ -170,7 +170,7 @@ private: std::list mOnlinePeers; std::map mFileSources; - bool mFlag; //1:transfer complete, 0: not complete + uint16_t mFlag; //2:file canceled, 1:transfer complete, 0: not complete double desiredRate; double actualRate;