|
@@ -98,7 +98,8 @@ DefaultBtInteractive::DefaultBtInteractive
|
|
|
maxOutstandingRequest_(DEFAULT_MAX_OUTSTANDING_REQUEST),
|
|
|
requestGroupMan_(0),
|
|
|
tcpPort_(0),
|
|
|
- haveLastSent_(global::wallclock())
|
|
|
+ haveLastSent_(global::wallclock()),
|
|
|
+ baseSpeed_(0)
|
|
|
{}
|
|
|
|
|
|
DefaultBtInteractive::~DefaultBtInteractive() {}
|
|
@@ -321,13 +322,25 @@ size_t DefaultBtInteractive::receiveMessages() {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- if(!pieceStorage_->isEndGame() &&
|
|
|
- countOldOutstandingRequest > dispatcher_->countOutstandingRequest() &&
|
|
|
- (countOldOutstandingRequest - dispatcher_->countOutstandingRequest())*2 >=
|
|
|
- maxOutstandingRequest_) {
|
|
|
- maxOutstandingRequest_ =
|
|
|
- std::min((size_t)UB_MAX_OUTSTANDING_REQUEST,
|
|
|
- maxOutstandingRequest_+OUTSTANDING_REQUEST_STEP);
|
|
|
+
|
|
|
+ if(!pieceStorage_->isEndGame() && !pieceStorage_->downloadFinished()) {
|
|
|
+ if(baseSpeed_ == 0) {
|
|
|
+ if(countOldOutstandingRequest &&
|
|
|
+ dispatcher_->countOutstandingRequest() == 0) {
|
|
|
+ baseSpeed_ = peer_->calculateDownloadSpeed();
|
|
|
+ maxOutstandingRequest_ *= 2;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ int speed = peer_->calculateDownloadSpeed();
|
|
|
+ // Double the number of outstanding request if 20% download rate
|
|
|
+ // increase is observed.
|
|
|
+ if(baseSpeed_*12 <= speed*10) {
|
|
|
+ maxOutstandingRequest_ =
|
|
|
+ std::min((size_t)UB_MAX_OUTSTANDING_REQUEST,
|
|
|
+ maxOutstandingRequest_*2);
|
|
|
+ baseSpeed_ = speed;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
return msgcount;
|
|
|
}
|