Przeglądaj źródła

2008-06-04 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	Added --bt-request-peer-speed-limit option, which was a constant
	SLOW_SPEED_THRESHOLD.
	* src/ActivePeerConnectionCommand.cc
	* src/ActivePeerConnectionCommand.h
	* src/BtConstants.h
	* src/HelpItemFactory.cc
	* src/OptionHandlerFactory.cc
	* src/PeerReceiveHandshakeCommand.cc
	* src/option_processing.cc
	* src/prefs.cc
	* src/prefs.h
	* src/usage_text.h
Tatsuhiro Tsujikawa 17 lat temu
rodzic
commit
fc0725002d

+ 15 - 0
ChangeLog

@@ -1,3 +1,18 @@
+2008-06-04  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	Added --bt-request-peer-speed-limit option, which was a constant
+	SLOW_SPEED_THRESHOLD.
+	* src/ActivePeerConnectionCommand.cc
+	* src/ActivePeerConnectionCommand.h
+	* src/BtConstants.h
+	* src/HelpItemFactory.cc
+	* src/OptionHandlerFactory.cc
+	* src/PeerReceiveHandshakeCommand.cc
+	* src/option_processing.cc
+	* src/prefs.cc
+	* src/prefs.h
+	* src/usage_text.h
+
 2008-06-03  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
 	Removed repeated call of getTopDirPath(). Instead, call it once and

+ 1 - 1
src/ActivePeerConnectionCommand.cc

@@ -60,7 +60,7 @@ ActivePeerConnectionCommand::ActivePeerConnectionCommand(int cuid,
    RequestGroupAware(requestGroup),
    interval(interval),
    e(e),
-   _thresholdSpeed(SLOW_SPEED_THRESHOLD),
+   _thresholdSpeed(e->option->getAsInt(PREF_BT_REQUEST_PEER_SPEED_LIMIT)),
    _numNewConnection(5)
 {
   unsigned int maxDownloadSpeed = e->option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT);

+ 0 - 5
src/ActivePeerConnectionCommand.h

@@ -68,11 +68,6 @@ public:
 
   void connectToPeer(const SharedHandle<Peer>& peer);
 
-  void setThresholdSpeed(unsigned int speed)
-  {
-    _thresholdSpeed = speed;
-  }
-
   void setNumNewConnection(size_t numNewConnection)
   {
     _numNewConnection = numNewConnection;

+ 0 - 2
src/BtConstants.h

@@ -51,6 +51,4 @@ typedef std::map<std::string, uint8_t> Extensions;
 
 #define DEFAULT_LATENCY 1500
 
-#define SLOW_SPEED_THRESHOLD (50*1024)
-
 #endif // _D_BT_CONSTANTS_

+ 7 - 0
src/HelpItemFactory.cc

@@ -374,6 +374,13 @@ TagContainerHandle HelpItemFactory::createHelpItems(const Option* op)
     item->addTag(TAG_BITTORRENT);
     tc->addItem(item);
   }
+  {
+    HelpItemHandle item(new HelpItem(PREF_BT_REQUEST_PEER_SPEED_LIMIT,
+				     TEXT_BT_REQUEST_PEER_SPEED_LIMIT,
+				     op->get(PREF_BT_REQUEST_PEER_SPEED_LIMIT)));
+    item->addTag(TAG_BITTORRENT);
+    tc->addItem(item);
+  }
 #endif // ENABLE_BITTORRENT
 #ifdef ENABLE_METALINK
   {

+ 1 - 0
src/OptionHandlerFactory.cc

@@ -126,6 +126,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
   handlers.push_back(SH(new NumberOptionHandler(PREF_STOP, 0, INT32_MAX)));
   handlers.push_back(SH(new ParameterOptionHandler(PREF_BT_MIN_CRYPTO_LEVEL, V_PLAIN, V_ARC4)));
   handlers.push_back(SH(new BooleanOptionHandler(PREF_BT_REQUIRE_CRYPTO)));
+  handlers.push_back(SH(new NumberOptionHandler(PREF_BT_REQUEST_PEER_SPEED_LIMIT, 0)));
   handlers.push_back(SH(new CumulativeOptionHandler(PREF_HEADER, "\n")));
   handlers.push_back(SH(new BooleanOptionHandler(PREF_QUIET)));
 #ifdef ENABLE_ASYNC_DNS

+ 1 - 1
src/PeerReceiveHandshakeCommand.cc

@@ -63,7 +63,7 @@ PeerReceiveHandshakeCommand::PeerReceiveHandshakeCommand(int32_t cuid,
 							 const SharedHandle<PeerConnection>& peerConnection):
   PeerAbstractCommand(cuid, peer, e, s),
   _peerConnection(peerConnection),
-  _thresholdSpeed(SLOW_SPEED_THRESHOLD)
+  _thresholdSpeed(e->option->getAsInt(PREF_BT_REQUEST_PEER_SPEED_LIMIT))
 {
   if(_peerConnection.isNull()) {
     _peerConnection.reset(new PeerConnection(cuid, socket, e->option));

+ 5 - 0
src/option_processing.cc

@@ -143,6 +143,7 @@ Option* createDefaultOption()
   op->put(PREF_DHT_FILE_PATH, Util::getHomeDir()+"/.aria2/dht.dat");
   op->put(PREF_BT_MIN_CRYPTO_LEVEL, V_PLAIN);
   op->put(PREF_BT_REQUIRE_CRYPTO, V_FALSE);
+  op->put(PREF_BT_REQUEST_PEER_SPEED_LIMIT, "51200");
   op->put(PREF_QUIET, V_FALSE);
   op->put(PREF_STOP, "0");
 #ifdef ENABLE_ASYNC_DNS
@@ -252,6 +253,7 @@ Option* option_processing(int argc, char* const argv[])
       { PREF_DHT_ENTRY_POINT.c_str(), required_argument, &lopt, 29 },
       { PREF_BT_MIN_CRYPTO_LEVEL.c_str(), required_argument, &lopt, 30 },
       { PREF_BT_REQUIRE_CRYPTO.c_str(), required_argument, &lopt, 31 },
+      { PREF_BT_REQUEST_PEER_SPEED_LIMIT.c_str(), required_argument, &lopt, 32 },
 #endif // ENABLE_BITTORRENT
 #ifdef ENABLE_METALINK
       { PREF_METALINK_FILE.c_str(), required_argument, NULL, 'M' },
@@ -362,6 +364,9 @@ Option* option_processing(int argc, char* const argv[])
       case 31:
 	cmdstream << PREF_BT_REQUIRE_CRYPTO << "=" << optarg << "\n";
 	break;
+      case 32:
+	cmdstream << PREF_BT_REQUEST_PEER_SPEED_LIMIT << "=" << optarg << "\n";
+	break;
       case 100:
 	cmdstream << PREF_METALINK_VERSION << "=" << optarg << "\n";
 	break;

+ 2 - 0
src/prefs.cc

@@ -247,6 +247,8 @@ const std::string V_PLAIN("plain");
 const std::string V_ARC4("arc4");
 // values:: true | false
 const std::string PREF_BT_REQUIRE_CRYPTO("bt-require-crypto");
+// values: 1*digit
+const std::string PREF_BT_REQUEST_PEER_SPEED_LIMIT("bt-request-peer-speed-limit");
 
 /**
  * Metalink related preferences

+ 2 - 0
src/prefs.h

@@ -251,6 +251,8 @@ extern const std::string V_PLAIN;
 extern const std::string V_ARC4;
 // values:: true | false
 extern const std::string PREF_BT_REQUIRE_CRYPTO;
+// values: 1*digit
+extern const std::string PREF_BT_REQUEST_PEER_SPEED_LIMIT;
 
 /**
  * Metalink related preferences

+ 5 - 0
src/usage_text.h

@@ -274,6 +274,11 @@ _(" --bt-require-crypto=true|false If true is given, aria2 doesn't accept and\n"
   "                              establish connection with legacy BitTorrent\n"\
   "                              handshake. Thus aria2 always uses Obfuscation\n"\
   "                              handshake.")
+#define TEXT_BT_REQUEST_PEER_SPEED_LIMIT \
+_(" --bt-request-peer-speed-limit=SPEED In BitTorrent downloads, if the download\n"\
+  "                              speed is lower than SPEED, aria2 initiates and\n"\
+  "                              accepts connections ignoring max peer cap.\n"\
+  "                              You can append K or M(1K = 1024, 1M = 1024K).")
 #define TEXT_METALINK_FILE \
 _(" -M, --metalink-file=METALINK_FILE The file path to the .metalink file.")
 #define TEXT_METALINK_SERVERS \