2009-05-07 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Don't retrieve PREF_MAX_DOWNLOAD_LIMIT and PREF_MAX_UPLOAD_LIMIT
	from option directly. Instead, get them from RequestGroup.
	* src/ActivePeerConnectionCommand.cc
	* src/ActivePeerConnectionCommand.h
	* src/PeerReceiveHandshakeCommand.cc
	* src/RequestGroup.h
pull/1/head
Tatsuhiro Tsujikawa 2009-05-07 08:40:45 +00:00
parent 22ab845df5
commit 40d5c1e763
5 changed files with 36 additions and 14 deletions

View File

@ -1,3 +1,12 @@
2009-05-07 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Don't retrieve PREF_MAX_DOWNLOAD_LIMIT and PREF_MAX_UPLOAD_LIMIT
from option directly. Instead, get them from RequestGroup.
* src/ActivePeerConnectionCommand.cc
* src/ActivePeerConnectionCommand.h
* src/PeerReceiveHandshakeCommand.cc
* src/RequestGroup.h
2009-05-07 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2009-05-07 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Removed unused uploadLimitCheck and uploadLimit from Removed unused uploadLimitCheck and uploadLimit from

View File

@ -64,13 +64,8 @@ ActivePeerConnectionCommand::ActivePeerConnectionCommand
interval(interval), interval(interval),
e(e), e(e),
_thresholdSpeed(e->option->getAsInt(PREF_BT_REQUEST_PEER_SPEED_LIMIT)), _thresholdSpeed(e->option->getAsInt(PREF_BT_REQUEST_PEER_SPEED_LIMIT)),
_maxUploadSpeedLimit(e->option->getAsInt(PREF_MAX_UPLOAD_LIMIT)),
_numNewConnection(5) _numNewConnection(5)
{ {
unsigned int maxDownloadSpeed = e->option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT);
if(maxDownloadSpeed > 0) {
_thresholdSpeed = std::min(maxDownloadSpeed, _thresholdSpeed);
}
_requestGroup->increaseNumCommand(); _requestGroup->increaseNumCommand();
} }
@ -86,13 +81,19 @@ bool ActivePeerConnectionCommand::execute() {
if(checkPoint.elapsed(interval)) { if(checkPoint.elapsed(interval)) {
checkPoint.reset(); checkPoint.reset();
TransferStat tstat = _requestGroup->calculateStat(); TransferStat tstat = _requestGroup->calculateStat();
const unsigned int maxDownloadLimit =
_requestGroup->getMaxDownloadSpeedLimit();
const unsigned int maxUploadLimit = _requestGroup->getMaxUploadSpeedLimit();
unsigned int thresholdSpeed = _thresholdSpeed;
if(maxDownloadLimit > 0) {
thresholdSpeed = std::min(maxDownloadLimit, _thresholdSpeed);
}
if(// for seeder state if(// for seeder state
(_pieceStorage->downloadFinished() && _btRuntime->lessThanMaxPeers() && (_pieceStorage->downloadFinished() && _btRuntime->lessThanMaxPeers() &&
(_maxUploadSpeedLimit == 0 || (maxUploadLimit == 0 || tstat.getUploadSpeed() < maxUploadLimit*0.8)) ||
tstat.getUploadSpeed() < _maxUploadSpeedLimit*0.8)) ||
// for leecher state // for leecher state
(!_pieceStorage->downloadFinished() && (!_pieceStorage->downloadFinished() &&
(tstat.getDownloadSpeed() < _thresholdSpeed || (tstat.getDownloadSpeed() < thresholdSpeed ||
_btRuntime->lessThanMinPeers()))) { _btRuntime->lessThanMinPeers()))) {
unsigned int numConnection = 0; unsigned int numConnection = 0;

View File

@ -63,7 +63,6 @@ private:
DownloadEngine* e; DownloadEngine* e;
Time checkPoint; Time checkPoint;
unsigned int _thresholdSpeed; // UNIT: byte/sec unsigned int _thresholdSpeed; // UNIT: byte/sec
unsigned int _maxUploadSpeedLimit;
unsigned int _numNewConnection; // the number of the connection to establish. unsigned int _numNewConnection; // the number of the connection to establish.
public: public:
ActivePeerConnectionCommand(int cuid, ActivePeerConnectionCommand(int cuid,

View File

@ -73,10 +73,6 @@ PeerReceiveHandshakeCommand::PeerReceiveHandshakeCommand
if(_peerConnection.isNull()) { if(_peerConnection.isNull()) {
_peerConnection.reset(new PeerConnection(cuid, socket, e->option)); _peerConnection.reset(new PeerConnection(cuid, socket, e->option));
} }
unsigned int maxDownloadSpeed = e->option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT);
if(maxDownloadSpeed > 0) {
_thresholdSpeed = std::min(maxDownloadSpeed, _thresholdSpeed);
}
} }
PeerReceiveHandshakeCommand::~PeerReceiveHandshakeCommand() {} PeerReceiveHandshakeCommand::~PeerReceiveHandshakeCommand() {}
@ -111,8 +107,15 @@ bool PeerReceiveHandshakeCommand::executeInternal()
(StringFormat("Unknown info hash %s", infoHash.c_str()).str()); (StringFormat("Unknown info hash %s", infoHash.c_str()).str());
} }
TransferStat tstat = btContext->getOwnerRequestGroup()->calculateStat(); TransferStat tstat = btContext->getOwnerRequestGroup()->calculateStat();
const unsigned int maxDownloadLimit =
btContext->getOwnerRequestGroup()->getMaxDownloadSpeedLimit();
unsigned int thresholdSpeed = _thresholdSpeed;
if(maxDownloadLimit > 0) {
thresholdSpeed = std::min(maxDownloadLimit, _thresholdSpeed);
}
if((!pieceStorage->downloadFinished() && if((!pieceStorage->downloadFinished() &&
tstat.getDownloadSpeed() < _thresholdSpeed) || tstat.getDownloadSpeed() < thresholdSpeed) ||
btRuntime->lessThanMaxPeers()) { btRuntime->lessThanMaxPeers()) {
if(peerStorage->addPeer(peer)) { if(peerStorage->addPeer(peer)) {

View File

@ -458,6 +458,16 @@ public:
// _maxUploadSpeedLimit. Always returns false if // _maxUploadSpeedLimit. Always returns false if
// _maxUploadSpeedLimit == 0. Otherwise returns false. // _maxUploadSpeedLimit == 0. Otherwise returns false.
bool doesUploadSpeedExceed(); bool doesUploadSpeedExceed();
unsigned int getMaxDownloadSpeedLimit() const
{
return _maxDownloadSpeedLimit;
}
unsigned int getMaxUploadSpeedLimit() const
{
return _maxUploadSpeedLimit;
}
}; };
typedef SharedHandle<RequestGroup> RequestGroupHandle; typedef SharedHandle<RequestGroup> RequestGroupHandle;