mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
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:
parent
7b609a6aea
commit
86ffedb50d
@ -54,8 +54,15 @@ bool ftTransferModule::setFileSources(std::list<std::string> peerIds)
|
|||||||
return true;
|
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;
|
std::map<std::string,peerInfo>::iterator mit;
|
||||||
mit = mFileSources.find(peerId);
|
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).state=state;
|
||||||
(mit->second).desiredRate=maxRate;
|
(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;
|
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);
|
return mFileCreator -> addFileData(offset, chunk_size, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ftTransferModule::queryInactive()
|
bool ftTransferModule::queryInactive()
|
||||||
{
|
{
|
||||||
#ifdef FT_DEBUG
|
#ifdef FT_DEBUG
|
||||||
std::cerr << "ftTransferModule::queryInactive()" << std::endl;
|
std::cerr << "ftTransferModule::queryInactive()" << std::endl;
|
||||||
@ -195,7 +215,11 @@ void ftTransferModule::queryInactive()
|
|||||||
mFileStatus.stat = ftFileStatus::PQIFILE_DOWNLOADING;
|
mFileStatus.stat = ftFileStatus::PQIFILE_DOWNLOADING;
|
||||||
|
|
||||||
if (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);
|
int ts = time(NULL);
|
||||||
uint64_t req_offset;
|
uint64_t req_offset;
|
||||||
@ -270,7 +294,8 @@ void ftTransferModule::queryInactive()
|
|||||||
break;
|
break;
|
||||||
}//switch
|
}//switch
|
||||||
}//for
|
}//for
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ftTransferModule::pauseTransfer()
|
bool ftTransferModule::pauseTransfer()
|
||||||
@ -317,9 +342,20 @@ bool ftTransferModule::completeFileTransfer()
|
|||||||
int ftTransferModule::tick()
|
int ftTransferModule::tick()
|
||||||
{
|
{
|
||||||
queryInactive();
|
queryInactive();
|
||||||
if (mFlag != 1) adjustSpeed();
|
switch (mFlag)
|
||||||
else
|
{
|
||||||
completeFileTransfer();
|
case 0:
|
||||||
|
adjustSpeed();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
completeFileTransfer();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
/* tell me what to do here */
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ public:
|
|||||||
uint64_t offset;
|
uint64_t offset;
|
||||||
uint32_t chunkSize;
|
uint32_t chunkSize;
|
||||||
|
|
||||||
//already received data size
|
//already received data size for current request
|
||||||
uint32_t receivedSize;
|
uint32_t receivedSize;
|
||||||
|
|
||||||
time_t lastTS;
|
time_t lastTS;
|
||||||
@ -152,7 +152,7 @@ public:
|
|||||||
uint64_t size() { return mSize; }
|
uint64_t size() { return mSize; }
|
||||||
|
|
||||||
//internal used functions
|
//internal used functions
|
||||||
void queryInactive();
|
bool queryInactive();
|
||||||
void adjustSpeed();
|
void adjustSpeed();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -170,7 +170,7 @@ private:
|
|||||||
std::list<std::string> mOnlinePeers;
|
std::list<std::string> mOnlinePeers;
|
||||||
std::map<std::string,peerInfo> mFileSources;
|
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 desiredRate;
|
||||||
double actualRate;
|
double actualRate;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user