summaryrefslogtreecommitdiff
path: root/src/ActivePeerConnectionCommand.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-11-03 06:49:02 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-11-03 06:49:02 +0000
commit7cf589e78483e6ca7daff2ddd1a30af8091a4448 (patch)
treed595de6899aa7ddad9ad6242c9f50dd6c2a85e22 /src/ActivePeerConnectionCommand.cc
parent93edc7bd202df92174cc4ce3b8c0c0c7684170fd (diff)
2008-11-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Made BtRegistry non-static object. Now DownloadEngine has a reference to its object. * src/AbstractBtMessage.cc * src/ActivePeerConnectionCommand.cc * src/ActivePeerConnectionCommand.h * src/BtContextAwareCommand.cc * src/BtContextAwareCommand.h * src/BtExtendedMessage.cc * src/BtExtendedMessage.h * src/BtInterestedMessage.cc * src/BtInterestedMessage.h * src/BtNotInterestedMessage.cc * src/BtNotInterestedMessage.h * src/BtRegistry.cc * src/BtRegistry.h * src/BtSeederStateChoke.cc * src/BtSetup.cc * src/DHTGetPeersCommand.cc * src/DHTGetPeersCommand.h * src/DHTPeerAnnounceEntry.cc * src/DHTPeerAnnounceEntry.h * src/DHTPeerAnnounceStorage.cc * src/DHTPeerAnnounceStorage.h * src/DHTPeerLookupTask.cc * src/DHTPeerLookupTask.h * src/DHTSetup.cc * src/DHTSetup.h * src/DHTTaskFactory.h * src/DHTTaskFactoryImpl.cc * src/DHTTaskFactoryImpl.h * src/DefaultBtAnnounce.cc * src/DefaultBtInteractive.cc * src/DefaultBtInteractive.h * src/DefaultBtMessageDispatcher.cc * src/DefaultBtMessageDispatcher.h * src/DefaultBtMessageFactory.cc * src/DefaultBtMessageFactory.h * src/DefaultBtMessageReceiver.cc * src/DefaultBtProgressInfoFile.cc * src/DefaultBtProgressInfoFile.h * src/DefaultBtRequestFactory.cc * src/DefaultBtRequestFactory.h * src/DefaultExtensionMessageFactory.cc * src/DefaultExtensionMessageFactory.h * src/DefaultPeerStorage.cc * src/DefaultPeerStorage.h * src/DownloadEngine.cc * src/DownloadEngine.h * src/InitiatorMSEHandshakeCommand.cc * src/InitiatorMSEHandshakeCommand.h * src/MSEHandshake.cc * src/MSEHandshake.h * src/Makefile.am * src/Makefile.in * src/PeerChokeCommand.cc * src/PeerChokeCommand.h * src/PeerInitiateConnectionCommand.cc * src/PeerInitiateConnectionCommand.h * src/PeerInteractionCommand.cc * src/PeerInteractionCommand.h * src/PeerObject.h * src/PeerReceiveHandshakeCommand.cc * src/PeerReceiveHandshakeCommand.h * src/ReceiverMSEHandshakeCommand.cc * src/RequestGroup.cc * src/RequestGroup.h * src/RequestGroupMan.cc * src/RequestGroupMan.h * src/SeedCheckCommand.cc * src/SeedCheckCommand.h * src/ShareRatioSeedCriteria.h * src/SimpleBtMessage.cc * src/TrackerWatcherCommand.cc * src/TrackerWatcherCommand.h * src/UTPexExtensionMessage.cc * src/UTPexExtensionMessage.h * test/BtCancelMessageTest.cc * test/BtChokeMessageTest.cc * test/BtExtendedMessageTest.cc * test/BtInterestedMessageTest.cc * test/BtNotInterestedMessageTest.cc * test/BtPieceMessageTest.cc * test/BtPortMessageTest.cc * test/BtRegistryTest.cc * test/BtRejectMessageTest.cc * test/BtRequestMessageTest.cc * test/DHTPeerAnnounceEntryTest.cc * test/DHTPeerAnnounceStorageTest.cc * test/DefaultBtMessageDispatcherTest.cc * test/DefaultBtMessageFactoryTest.cc * test/DefaultBtProgressInfoFileTest.cc * test/DefaultBtRequestFactoryTest.cc * test/DefaultExtensionMessageFactoryTest.cc * test/MSEHandshakeTest.cc * test/MockDHTTaskFactory.h * test/ShareRatioSeedCriteriaTest.cc * test/UTPexExtensionMessageTest.cc
Diffstat (limited to 'src/ActivePeerConnectionCommand.cc')
-rw-r--r--src/ActivePeerConnectionCommand.cc79
1 files changed, 54 insertions, 25 deletions
diff --git a/src/ActivePeerConnectionCommand.cc b/src/ActivePeerConnectionCommand.cc
index 36a7416f..1941b2a8 100644
--- a/src/ActivePeerConnectionCommand.cc
+++ b/src/ActivePeerConnectionCommand.cc
@@ -52,19 +52,21 @@
namespace aria2 {
-ActivePeerConnectionCommand::ActivePeerConnectionCommand(int cuid,
- RequestGroup* requestGroup,
- DownloadEngine* e,
- const BtContextHandle& btContext,
- time_t interval)
- :Command(cuid),
- BtContextAwareCommand(btContext),
- RequestGroupAware(requestGroup),
- interval(interval),
- e(e),
- _thresholdSpeed(e->option->getAsInt(PREF_BT_REQUEST_PEER_SPEED_LIMIT)),
- _maxUploadSpeedLimit(e->option->getAsInt(PREF_MAX_UPLOAD_LIMIT)),
- _numNewConnection(5)
+ActivePeerConnectionCommand::ActivePeerConnectionCommand
+(int cuid,
+ RequestGroup* requestGroup,
+ DownloadEngine* e,
+ const BtContextHandle& btContext,
+ time_t interval)
+ :
+ Command(cuid),
+ RequestGroupAware(requestGroup),
+ _btContext(btContext),
+ 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);
if(maxDownloadSpeed > 0) {
@@ -75,32 +77,32 @@ ActivePeerConnectionCommand::ActivePeerConnectionCommand(int cuid,
ActivePeerConnectionCommand::~ActivePeerConnectionCommand() {}
bool ActivePeerConnectionCommand::execute() {
- if(btRuntime->isHalt()) {
+ if(_btRuntime->isHalt()) {
return true;
}
if(checkPoint.elapsed(interval)) {
checkPoint.reset();
TransferStat tstat = _requestGroup->calculateStat();
if(// for seeder state
- (pieceStorage->downloadFinished() && btRuntime->lessThanMaxPeers() &&
+ (_pieceStorage->downloadFinished() && _btRuntime->lessThanMaxPeers() &&
(_maxUploadSpeedLimit == 0 ||
tstat.getUploadSpeed() < _maxUploadSpeedLimit*0.8)) ||
// for leecher state
- (!pieceStorage->downloadFinished() &&
+ (!_pieceStorage->downloadFinished() &&
(tstat.getDownloadSpeed() < _thresholdSpeed ||
- btRuntime->lessThanMinPeers()))) {
- unsigned int numConnection = pieceStorage->downloadFinished() ?
+ _btRuntime->lessThanMinPeers()))) {
+ unsigned int numConnection = _pieceStorage->downloadFinished() ?
std::min(_numNewConnection,
- BtRuntime::MAX_PEERS-btRuntime->getConnections()) :
+ BtRuntime::MAX_PEERS-_btRuntime->getConnections()) :
_numNewConnection;
for(unsigned int numAdd = numConnection;
- numAdd > 0 && peerStorage->isPeerAvailable(); --numAdd) {
- PeerHandle peer = peerStorage->getUnusedPeer();
+ numAdd > 0 && _peerStorage->isPeerAvailable(); --numAdd) {
+ PeerHandle peer = _peerStorage->getUnusedPeer();
connectToPeer(peer);
}
- if(btRuntime->getConnections() == 0 &&
- !pieceStorage->downloadFinished()) {
- btAnnounce->overrideMinInterval(BtAnnounce::DEFAULT_ANNOUNCE_INTERVAL);
+ if(_btRuntime->getConnections() == 0 &&
+ !_pieceStorage->downloadFinished()) {
+ _btAnnounce->overrideMinInterval(BtAnnounce::DEFAULT_ANNOUNCE_INTERVAL);
}
}
}
@@ -115,10 +117,37 @@ void ActivePeerConnectionCommand::connectToPeer(const PeerHandle& peer)
}
peer->usedBy(CUIDCounterSingletonHolder::instance()->newID());
PeerInitiateConnectionCommand* command =
- new PeerInitiateConnectionCommand(peer->usedBy(), _requestGroup, peer, e, btContext);
+ new PeerInitiateConnectionCommand(peer->usedBy(), _requestGroup, peer, e,
+ _btContext, _btRuntime);
+ command->setPeerStorage(_peerStorage);
+ command->setPieceStorage(_pieceStorage);
e->commands.push_back(command);
logger->info(MSG_CONNECTING_TO_PEER,
cuid, peer->ipaddr.c_str());
}
+void ActivePeerConnectionCommand::setBtRuntime
+(const SharedHandle<BtRuntime>& btRuntime)
+{
+ _btRuntime = btRuntime;
+}
+
+void ActivePeerConnectionCommand::setPieceStorage
+(const SharedHandle<PieceStorage>& pieceStorage)
+{
+ _pieceStorage = pieceStorage;
+}
+
+void ActivePeerConnectionCommand::setPeerStorage
+(const SharedHandle<PeerStorage>& peerStorage)
+{
+ _peerStorage = peerStorage;
+}
+
+void ActivePeerConnectionCommand::setBtAnnounce
+(const SharedHandle<BtAnnounce>& btAnnounce)
+{
+ _btAnnounce = btAnnounce;
+}
+
} // namespace aria2