2008-06-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Actively establish connection to peers in seeding, when peer 
cache
	is not full and max upload speed limit is not reached.
	* src/ActivePeerConnectionCommand.cc
	* src/ActivePeerConnectionCommand.h
pull/1/head
Tatsuhiro Tsujikawa 2008-06-10 11:31:35 +00:00
parent 7a74971caa
commit 46627da9a8
3 changed files with 16 additions and 3 deletions

View File

@ -1,3 +1,10 @@
2008-06-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Actively establish connection to peers in seeding, when peer cache
is not full and max upload speed limit is not reached.
* src/ActivePeerConnectionCommand.cc
* src/ActivePeerConnectionCommand.h
2008-06-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Always remove a peer from cache in DefaultPeerStorage::returnPeer(),

View File

@ -61,6 +61,7 @@ ActivePeerConnectionCommand::ActivePeerConnectionCommand(int cuid,
interval(interval),
e(e),
_thresholdSpeed(e->option->getAsInt(PREF_BT_REQUEST_PEER_SPEED_LIMIT)),
_maxUploadSpeedLimit(e->option->getAsInt(PREF_MAX_UPLOAD_LIMIT)),
_numNewConnection(5)
{
unsigned int maxDownloadSpeed = e->option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT);
@ -75,11 +76,15 @@ bool ActivePeerConnectionCommand::execute() {
if(btRuntime->isHalt()) {
return true;
}
if(!pieceStorage->downloadFinished() && checkPoint.elapsed(interval)) {
if(checkPoint.elapsed(interval)) {
checkPoint.reset();
TransferStat tstat = peerStorage->calculateStat();
if(tstat.getDownloadSpeed() < _thresholdSpeed ||
btRuntime->lessThanMinPeers()) {
if(// for seeder state
(pieceStorage->downloadFinished() && btRuntime->lessThanMaxPeers() &&
(_maxUploadSpeedLimit == 0 || tstat.getUploadSpeed() < _maxUploadSpeedLimit)) ||
// for leecher state
(tstat.getDownloadSpeed() < _thresholdSpeed ||
btRuntime->lessThanMinPeers())) {
for(size_t numAdd = _numNewConnection;
numAdd > 0 && peerStorage->isPeerAvailable(); --numAdd) {
PeerHandle peer = peerStorage->getUnusedPeer();

View File

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