summaryrefslogtreecommitdiff
path: root/src/SegmentMan.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-10-24 00:59:32 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-10-24 01:05:41 +0900
commit46bdaf0e8dae04d223d9b8b65ac80bc0773d8398 (patch)
tree5f485890eb8d58affb7289b92366298b5a6df27d /src/SegmentMan.cc
parentea456001d3f82829944e6cce8b2b76e8ec919b80 (diff)
Made HTTP/FTP download speed limiter more accurate
We have to do the same thing for BitTorrent.
Diffstat (limited to 'src/SegmentMan.cc')
-rw-r--r--src/SegmentMan.cc42
1 files changed, 6 insertions, 36 deletions
diff --git a/src/SegmentMan.cc b/src/SegmentMan.cc
index c8fec8c2..87187f8e 100644
--- a/src/SegmentMan.cc
+++ b/src/SegmentMan.cc
@@ -69,8 +69,6 @@ SegmentMan::SegmentMan
: option_(option),
downloadContext_(downloadContext),
pieceStorage_(pieceStorage),
- lastPeerStatDlspdMapUpdated_(0),
- cachedDlspd_(0),
ignoreBitfield_(downloadContext->getPieceLength(),
downloadContext->getTotalLength())
{
@@ -350,13 +348,6 @@ int64_t SegmentMan::getDownloadLength() const {
void SegmentMan::registerPeerStat(const SharedHandle<PeerStat>& peerStat)
{
- for(std::vector<SharedHandle<PeerStat> >::iterator i = peerStats_.begin(),
- eoi = peerStats_.end(); i != eoi; ++i) {
- if((*i)->getStatus() == PeerStat::IDLE) {
- *i = peerStat;
- return;
- }
- }
peerStats_.push_back(peerStat);
}
@@ -407,38 +398,17 @@ void SegmentMan::updateFastestPeerStat(const SharedHandle<PeerStat>& peerStat)
int SegmentMan::calculateDownloadSpeed()
{
int speed = 0;
- if(lastPeerStatDlspdMapUpdated_.differenceInMillis(global::wallclock())+
- A2_DELTA_MILLIS >= 250){
- lastPeerStatDlspdMapUpdated_ = global::wallclock();
- peerStatDlspdMap_.clear();
- for(std::vector<SharedHandle<PeerStat> >::const_iterator i =
- peerStats_.begin(), eoi = peerStats_.end(); i != eoi; ++i) {
- if((*i)->getStatus() == PeerStat::ACTIVE) {
- int s = (*i)->calculateDownloadSpeed();
- peerStatDlspdMap_[(*i)->getCuid()] = s;
- speed += s;
- }
+ for(std::vector<SharedHandle<PeerStat> >::const_iterator i =
+ peerStats_.begin(), eoi = peerStats_.end(); i != eoi; ++i) {
+ // PeerStat which is IDLE but its last download speed calculation
+ // interval is not over must be added to the result.
+ if((*i)->getStatus() == PeerStat::ACTIVE || (*i)->affectsOverallSpeed()) {
+ speed += (*i)->calculateDownloadSpeed();
}
- cachedDlspd_ = speed;
- } else {
- speed = cachedDlspd_;
}
return speed;
}
-void SegmentMan::updateDownloadSpeedFor(const SharedHandle<PeerStat>& pstat)
-{
- int newspd = pstat->calculateDownloadSpeed();
- int oldSpd = peerStatDlspdMap_[pstat->getCuid()];
- if(cachedDlspd_ > oldSpd) {
- cachedDlspd_ -= oldSpd;
- cachedDlspd_ += newspd;
- } else {
- cachedDlspd_ = newspd;
- }
- peerStatDlspdMap_[pstat->getCuid()] = newspd;
-}
-
namespace {
class PeerStatDownloadLengthOperator {
public: