summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-04-03 10:52:31 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-04-03 10:52:31 +0000
commitf030408d8e657fe1a5acc5f642f9e7561b23a753 (patch)
treeafc9ed14d5fa6f8c244c69777c07355e896e5a83 /src
parent5377be3680a2c11c3fdd371c140f6af54c1e63b9 (diff)
2007-04-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Connect to a peer actively when download speed is lower than specified speed in torrent download: * src/ActivePeerConnectionCommand.h: New class.
Diffstat (limited to 'src')
-rw-r--r--src/ActivePeerConnectionCommand.cc68
-rw-r--r--src/ActivePeerConnectionCommand.h78
-rw-r--r--src/DownloadEngineFactory.cc5
-rw-r--r--src/Makefile.am3
-rw-r--r--src/Makefile.in8
5 files changed, 159 insertions, 3 deletions
diff --git a/src/ActivePeerConnectionCommand.cc b/src/ActivePeerConnectionCommand.cc
new file mode 100644
index 00000000..508e65ef
--- /dev/null
+++ b/src/ActivePeerConnectionCommand.cc
@@ -0,0 +1,68 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2006 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL. If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so. If you
+ * do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#include "ActivePeerConnectionCommand.h"
+#include "PeerInitiateConnectionCommand.h"
+
+bool ActivePeerConnectionCommand::execute() {
+ if(btRuntime->isHalt()) {
+ return true;
+ }
+ if(checkPoint.elapsed(interval)) {
+ checkPoint.reset();
+
+ TransferStat tstat = peerStorage->calculateStat();
+ if(tstat.getDownloadSpeed() < _lowestSpeedLimit) {
+ for(int i = 0; i < _numNewConnection && peerStorage->isPeerAvailable(); ++i) {
+ PeerHandle peer = peerStorage->getUnusedPeer();
+ connectToPeer(peer);
+ }
+ }
+ }
+ e->commands.push_back(this);
+ return false;
+}
+
+void ActivePeerConnectionCommand::connectToPeer(const PeerHandle& peer)
+{
+ if(peer.isNull()) {
+ return;
+ }
+ peer->cuid = btRuntime->getNewCuid();
+ PeerInitiateConnectionCommand* command =
+ new PeerInitiateConnectionCommand(peer->cuid, peer, e, btContext);
+ e->commands.push_back(command);
+ logger->info("CUID#%d - Active Connect to the peer %s",
+ cuid, peer->ipaddr.c_str());
+}
diff --git a/src/ActivePeerConnectionCommand.h b/src/ActivePeerConnectionCommand.h
new file mode 100644
index 00000000..2bc919f9
--- /dev/null
+++ b/src/ActivePeerConnectionCommand.h
@@ -0,0 +1,78 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2006 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL. If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so. If you
+ * do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#ifndef _D_ACTIVE_PEER_CONNECTION_COMMAND_H_
+#define _D_ACTIVE_PEER_CONNECTION_COMMAND_H_
+
+#include "BtContextAwareCommand.h"
+#include "TorrentDownloadEngine.h"
+#include "TimeA2.h"
+
+class ActivePeerConnectionCommand : public BtContextAwareCommand {
+private:
+ int32_t interval; // UNIT: sec
+ TorrentDownloadEngine* e;
+ Time checkPoint;
+ int32_t _lowestSpeedLimit; // UNIT: byte/sec
+ int32_t _numNewConnection; // the number of the connection to establish.
+public:
+ ActivePeerConnectionCommand(int cuid,
+ TorrentDownloadEngine* e,
+ const BtContextHandle& btContext,
+ int32_t interval)
+ :BtContextAwareCommand(cuid, btContext),
+ interval(interval),
+ e(e),
+ _lowestSpeedLimit(20*1024),
+ _numNewConnection(5)
+ {}
+
+ virtual ~ActivePeerConnectionCommand() {}
+
+ virtual bool execute();
+
+ void connectToPeer(const PeerHandle& peer);
+
+ void setLowestSpeedLimit(int32_t speed)
+ {
+ _lowestSpeedLimit = speed;
+ }
+
+ void setNumNewConnection(int32_t numNewConnection)
+ {
+ _numNewConnection = numNewConnection;
+ }
+};
+
+#endif // _D_ACTIVE_PEER_CONNECTION_COMMAND_H_
diff --git a/src/DownloadEngineFactory.cc b/src/DownloadEngineFactory.cc
index 01ac5b91..0921eaac 100644
--- a/src/DownloadEngineFactory.cc
+++ b/src/DownloadEngineFactory.cc
@@ -48,6 +48,7 @@
# include "SeedCheckCommand.h"
# include "PeerChokeCommand.h"
# include "HaveEraseCommand.h"
+# include "ActivePeerConnectionCommand.h"
# include "UnionSeedCriteria.h"
# include "TimeSeedCriteria.h"
# include "ShareRatioSeedCriteria.h"
@@ -173,6 +174,10 @@ DownloadEngineFactory::newTorrentConsoleEngine(const BtContextHandle& btContext,
te,
btContext,
10));
+ te->commands.push_back(new ActivePeerConnectionCommand(btRuntime->getNewCuid(),
+ te,
+ btContext,
+ 30));
SharedHandle<UnionSeedCriteria> unionCri = new UnionSeedCriteria();
if(op->defined(PREF_SEED_TIME)) {
diff --git a/src/Makefile.am b/src/Makefile.am
index e5893aa7..aeff28a1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -186,7 +186,8 @@ SRCS += MetaEntry.h\
BtChokingEvent.h\
BtInteractive.h\
DefaultBtInteractive.cc DefaultBtInteractive.h\
- PeerObject.h
+ PeerObject.h\
+ ActivePeerConnectionCommand.cc ActivePeerConnectionCommand.h
endif # ENABLE_BITTORRENT
if ENABLE_METALINK
diff --git a/src/Makefile.in b/src/Makefile.in
index 1bed9d87..64535cfd 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -140,7 +140,8 @@ bin_PROGRAMS = aria2c$(EXEEXT)
@ENABLE_BITTORRENT_TRUE@ BtChokingEvent.h\
@ENABLE_BITTORRENT_TRUE@ BtInteractive.h\
@ENABLE_BITTORRENT_TRUE@ DefaultBtInteractive.cc DefaultBtInteractive.h\
-@ENABLE_BITTORRENT_TRUE@ PeerObject.h
+@ENABLE_BITTORRENT_TRUE@ PeerObject.h\
+@ENABLE_BITTORRENT_TRUE@ ActivePeerConnectionCommand.cc ActivePeerConnectionCommand.h
@ENABLE_METALINK_TRUE@am__append_2 = Metalinker.cc Metalinker.h\
@ENABLE_METALINK_TRUE@ MetalinkEntry.cc MetalinkEntry.h\
@@ -288,6 +289,7 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
BtCancelSendingPieceEvent.h BtAbortOutstandingRequestEvent.h \
BtChokedEvent.h BtChokingEvent.h BtInteractive.h \
DefaultBtInteractive.cc DefaultBtInteractive.h PeerObject.h \
+ ActivePeerConnectionCommand.cc ActivePeerConnectionCommand.h \
Metalinker.cc Metalinker.h MetalinkEntry.cc MetalinkEntry.h \
MetalinkResource.cc MetalinkResource.h MetalinkProcessor.h \
Xml2MetalinkProcessor.cc Xml2MetalinkProcessor.h \
@@ -355,7 +357,8 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
@ENABLE_BITTORRENT_TRUE@ DefaultBtMessageDispatcher.$(OBJEXT) \
@ENABLE_BITTORRENT_TRUE@ DefaultBtMessageReceiver.$(OBJEXT) \
@ENABLE_BITTORRENT_TRUE@ DefaultBtRequestFactory.$(OBJEXT) \
-@ENABLE_BITTORRENT_TRUE@ DefaultBtInteractive.$(OBJEXT)
+@ENABLE_BITTORRENT_TRUE@ DefaultBtInteractive.$(OBJEXT) \
+@ENABLE_BITTORRENT_TRUE@ ActivePeerConnectionCommand.$(OBJEXT)
@ENABLE_METALINK_TRUE@am__objects_2 = Metalinker.$(OBJEXT) \
@ENABLE_METALINK_TRUE@ MetalinkEntry.$(OBJEXT) \
@ENABLE_METALINK_TRUE@ MetalinkResource.$(OBJEXT) \
@@ -704,6 +707,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AbstractProxyRequestCommand.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AbstractProxyResponseCommand.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AbstractSingleDiskAdaptor.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ActivePeerConnectionCommand.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AnnounceList.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AuthConfig.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Base64.Po@am__quote@