summaryrefslogtreecommitdiff
path: root/src/PeerInteractionCommand.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-10-11 16:58:24 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-10-11 16:58:24 +0000
commit048a2cf59737f761876e81a77e8d064c45c752d7 (patch)
tree65c9d5498aafe6a8c8e640ddfcc43c7013504d0d /src/PeerInteractionCommand.cc
parente26bbbb9eee140ba24402fe872a752b42f0077de (diff)
2007-10-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Implemented BitTorrent/http/ftp integrated download. I've rewritten lots of files and now some headers have forward class declarations to reduce compile time. The implementation is extremely alpha stage, I recommend to use this for testing purpose only.
Diffstat (limited to 'src/PeerInteractionCommand.cc')
-rw-r--r--src/PeerInteractionCommand.cc31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/PeerInteractionCommand.cc b/src/PeerInteractionCommand.cc
index 522b02ab..7d9794ac 100644
--- a/src/PeerInteractionCommand.cc
+++ b/src/PeerInteractionCommand.cc
@@ -33,6 +33,7 @@
*/
/* copyright --> */
#include "PeerInteractionCommand.h"
+#include "DownloadEngine.h"
#include "PeerInitiateConnectionCommand.h"
#include "PeerMessageUtil.h"
#include "DefaultBtInteractive.h"
@@ -45,17 +46,20 @@
#include "DefaultBtRequestFactory.h"
#include "DefaultBtMessageFactory.h"
#include "DefaultBtInteractive.h"
-#include "PeerConnection.h"
#include "CUIDCounter.h"
#include <algorithm>
PeerInteractionCommand::PeerInteractionCommand(int32_t cuid,
+ RequestGroup* requestGroup,
const PeerHandle& p,
- TorrentDownloadEngine* e,
+ DownloadEngine* e,
const BtContextHandle& btContext,
const SocketHandle& s,
- Seq sequence)
- :PeerAbstractCommand(cuid, p, e, btContext, s),
+ Seq sequence,
+ const PeerConnectionHandle& passedPeerConnection)
+ :PeerAbstractCommand(cuid, p, e, s),
+ BtContextAwareCommand(btContext),
+ RequestGroupAware(requestGroup),
sequence(sequence),
btInteractive(0),
maxDownloadSpeedLimit(0)
@@ -71,8 +75,8 @@ PeerInteractionCommand::PeerInteractionCommand(int32_t cuid,
factory->setBtContext(btContext);
factory->setPeer(peer);
- PeerConnectionHandle peerConnection =
- new PeerConnection(cuid, socket, e->option);
+ PeerConnectionHandle peerConnection = passedPeerConnection.isNull() ?
+ new PeerConnection(cuid, socket, e->option) : passedPeerConnection;
DefaultBtMessageDispatcherHandle dispatcher = new DefaultBtMessageDispatcher();
dispatcher->setCuid(cuid);
@@ -128,12 +132,15 @@ PeerInteractionCommand::PeerInteractionCommand(int32_t cuid,
peer->activate();
maxDownloadSpeedLimit = e->option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT);
+
+ btRuntime->increaseConnections();
}
PeerInteractionCommand::~PeerInteractionCommand() {
peer->deactivate();
PEER_OBJECT_CLUSTER(btContext)->unregisterHandle(peer->getId());
-
+
+ btRuntime->decreaseConnections();
//logger->debug("CUID#%d - unregistered message factory using ID:%s",
//cuid, peer->getId().c_str());
}
@@ -205,6 +212,7 @@ bool PeerInteractionCommand::prepareForNextPeer(int32_t wait) {
peer->cuid = CUIDCounterSingletonHolder::instance()->newID();
PeerInitiateConnectionCommand* command =
new PeerInitiateConnectionCommand(peer->cuid,
+ _requestGroup,
peer,
e,
btContext);
@@ -220,5 +228,12 @@ bool PeerInteractionCommand::prepareForRetry(int32_t wait) {
void PeerInteractionCommand::onAbort(Exception* ex) {
btInteractive->cancelAllPiece();
- PeerAbstractCommand::onAbort(ex);
+ peerStorage->returnPeer(peer);
+ //PeerAbstractCommand::onAbort(ex);
}
+
+bool PeerInteractionCommand::exitBeforeExecute()
+{
+ return btRuntime->isHalt();
+}
+