mirror of https://github.com/aria2/aria2
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.ccpull/1/head
parent
f38eb15ca9
commit
7fdbd0e104
|
@ -50,13 +50,14 @@ ActivePeerConnectionCommand::ActivePeerConnectionCommand(int cuid,
|
||||||
RequestGroup* requestGroup,
|
RequestGroup* requestGroup,
|
||||||
DownloadEngine* e,
|
DownloadEngine* e,
|
||||||
const BtContextHandle& btContext,
|
const BtContextHandle& btContext,
|
||||||
int32_t interval)
|
int32_t interval,
|
||||||
|
int32_t thresholdSpeed)
|
||||||
:Command(cuid),
|
:Command(cuid),
|
||||||
BtContextAwareCommand(btContext),
|
BtContextAwareCommand(btContext),
|
||||||
RequestGroupAware(requestGroup),
|
RequestGroupAware(requestGroup),
|
||||||
interval(interval),
|
interval(interval),
|
||||||
e(e),
|
e(e),
|
||||||
_lowestSpeedLimit(50*1024),
|
_thresholdSpeed(thresholdSpeed),
|
||||||
_numNewConnection(5)
|
_numNewConnection(5)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -70,7 +71,7 @@ bool ActivePeerConnectionCommand::execute() {
|
||||||
checkPoint.reset();
|
checkPoint.reset();
|
||||||
TransferStat tstat = peerStorage->calculateStat();
|
TransferStat tstat = peerStorage->calculateStat();
|
||||||
size_t numAdd = btRuntime->lessThanEqMinPeer() ? MIN_PEERS-btRuntime->getConnections():_numNewConnection;
|
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) {
|
for(; numAdd > 0 && peerStorage->isPeerAvailable(); --numAdd) {
|
||||||
PeerHandle peer = peerStorage->getUnusedPeer();
|
PeerHandle peer = peerStorage->getUnusedPeer();
|
||||||
connectToPeer(peer);
|
connectToPeer(peer);
|
||||||
|
|
|
@ -53,14 +53,15 @@ private:
|
||||||
int32_t interval; // UNIT: sec
|
int32_t interval; // UNIT: sec
|
||||||
DownloadEngine* e;
|
DownloadEngine* e;
|
||||||
Time checkPoint;
|
Time checkPoint;
|
||||||
int32_t _lowestSpeedLimit; // UNIT: byte/sec
|
int32_t _thresholdSpeed; // UNIT: byte/sec
|
||||||
int32_t _numNewConnection; // the number of the connection to establish.
|
int32_t _numNewConnection; // the number of the connection to establish.
|
||||||
public:
|
public:
|
||||||
ActivePeerConnectionCommand(int cuid,
|
ActivePeerConnectionCommand(int cuid,
|
||||||
RequestGroup* requestGroup,
|
RequestGroup* requestGroup,
|
||||||
DownloadEngine* e,
|
DownloadEngine* e,
|
||||||
const SharedHandle<BtContext>& btContext,
|
const SharedHandle<BtContext>& btContext,
|
||||||
int32_t interval);
|
int32_t interval,
|
||||||
|
int32_t thresholdSpeed);
|
||||||
|
|
||||||
virtual ~ActivePeerConnectionCommand();
|
virtual ~ActivePeerConnectionCommand();
|
||||||
|
|
||||||
|
@ -68,9 +69,9 @@ public:
|
||||||
|
|
||||||
void connectToPeer(const SharedHandle<Peer>& peer);
|
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)
|
void setNumNewConnection(int32_t numNewConnection)
|
||||||
|
|
|
@ -80,11 +80,16 @@ Commands BtSetup::setup(RequestGroup* requestGroup,
|
||||||
e,
|
e,
|
||||||
btContext,
|
btContext,
|
||||||
10));
|
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(),
|
commands.push_back(new ActivePeerConnectionCommand(CUIDCounterSingletonHolder::instance()->newID(),
|
||||||
requestGroup,
|
requestGroup, e, btContext, 10,
|
||||||
e,
|
thresholdSpeed));
|
||||||
btContext,
|
}
|
||||||
10));
|
|
||||||
if(!btContext->isPrivate() && DHTSetup::initialized()) {
|
if(!btContext->isPrivate() && DHTSetup::initialized()) {
|
||||||
DHTRegistry::_peerAnnounceStorage->addPeerAnnounce(btContext);
|
DHTRegistry::_peerAnnounceStorage->addPeerAnnounce(btContext);
|
||||||
DHTGetPeersCommand* command = new DHTGetPeersCommand(CUIDCounterSingletonHolder::instance()->newID(),
|
DHTGetPeersCommand* command = new DHTGetPeersCommand(CUIDCounterSingletonHolder::instance()->newID(),
|
||||||
|
|
Loading…
Reference in New Issue