small updates for fttransfermodule.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@723 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
ewensun 2008-09-09 07:24:06 +00:00
parent 7b609a6aea
commit 86ffedb50d
2 changed files with 47 additions and 11 deletions

View File

@ -54,8 +54,15 @@ bool ftTransferModule::setFileSources(std::list<std::string> 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<std::string,peerInfo>::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<std::string>::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;
}

View File

@ -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<std::string> mOnlinePeers;
std::map<std::string,peerInfo> 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;