2008-02-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Use PREF_MAX_DOWNLOAD_LIMIT as a threshold for
	ActivePeerConnectionCommand when it is given and
	PREF_MAX_DOWNLOAD_LIMIT < default threshold.
	* src/ActivePeerConnectionCommand.{h, cc}
	* src/BtSetup.cc
pull/1/head
Tatsuhiro Tsujikawa 2008-02-08 18:30:46 +00:00
parent f38eb15ca9
commit 7fdbd0e104
3 changed files with 19 additions and 12 deletions

View File

@ -50,13 +50,14 @@ ActivePeerConnectionCommand::ActivePeerConnectionCommand(int cuid,
RequestGroup* requestGroup,
DownloadEngine* e,
const BtContextHandle& btContext,
int32_t interval)
int32_t interval,
int32_t thresholdSpeed)
:Command(cuid),
BtContextAwareCommand(btContext),
RequestGroupAware(requestGroup),
interval(interval),
e(e),
_lowestSpeedLimit(50*1024),
_thresholdSpeed(thresholdSpeed),
_numNewConnection(5)
{}
@ -70,7 +71,7 @@ bool ActivePeerConnectionCommand::execute() {
checkPoint.reset();
TransferStat tstat = peerStorage->calculateStat();
size_t numAdd = btRuntime->lessThanEqMinPeer() ? MIN_PEERS-btRuntime->getConnections():_numNewConnection;
if(tstat.getDownloadSpeed() < _lowestSpeedLimit || btRuntime->lessThanEqMinPeer()) {
if(tstat.getDownloadSpeed() < _thresholdSpeed || btRuntime->lessThanEqMinPeer()) {
for(; numAdd > 0 && peerStorage->isPeerAvailable(); --numAdd) {
PeerHandle peer = peerStorage->getUnusedPeer();
connectToPeer(peer);

View File

@ -53,14 +53,15 @@ private:
int32_t interval; // UNIT: sec
DownloadEngine* e;
Time checkPoint;
int32_t _lowestSpeedLimit; // UNIT: byte/sec
int32_t _thresholdSpeed; // UNIT: byte/sec
int32_t _numNewConnection; // the number of the connection to establish.
public:
ActivePeerConnectionCommand(int cuid,
RequestGroup* requestGroup,
DownloadEngine* e,
const SharedHandle<BtContext>& btContext,
int32_t interval);
int32_t interval,
int32_t thresholdSpeed);
virtual ~ActivePeerConnectionCommand();
@ -68,9 +69,9 @@ public:
void connectToPeer(const SharedHandle<Peer>& peer);
void setLowestSpeedLimit(int32_t speed)
void setThresholdSpeed(int32_t speed)
{
_lowestSpeedLimit = speed;
_thresholdSpeed = speed;
}
void setNumNewConnection(int32_t numNewConnection)

View File

@ -80,11 +80,16 @@ Commands BtSetup::setup(RequestGroup* requestGroup,
e,
btContext,
10));
commands.push_back(new ActivePeerConnectionCommand(CUIDCounterSingletonHolder::instance()->newID(),
requestGroup,
e,
btContext,
10));
{
int32_t thresholdSpeed = 50*1024;
int32_t maxDownloadSpeed = option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT);
if(maxDownloadSpeed > 0) {
thresholdSpeed = std::min(maxDownloadSpeed, thresholdSpeed);
}
commands.push_back(new ActivePeerConnectionCommand(CUIDCounterSingletonHolder::instance()->newID(),
requestGroup, e, btContext, 10,
thresholdSpeed));
}
if(!btContext->isPrivate() && DHTSetup::initialized()) {
DHTRegistry::_peerAnnounceStorage->addPeerAnnounce(btContext);
DHTGetPeersCommand* command = new DHTGetPeersCommand(CUIDCounterSingletonHolder::instance()->newID(),