2009-02-04 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Added --bt-external-ip option. You can specify the external IP
	address to report to a BitTorrent tracker. Although this
	function is named 'external', it can accept any kind of IP
	addresses.
	* src/DefaultBtAnnounce.cc
	* src/OptionHandlerFactory.cc
	* src/option_processing.cc
	* src/prefs.cc
	* src/prefs.h
	* src/usage_text.h
	* test/DefaultBtAnnounceTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2009-02-04 14:11:30 +00:00
parent 23a6eff88e
commit 0640ea6254
8 changed files with 68 additions and 1 deletions

View File

@ -1,3 +1,16 @@
2009-02-04 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added --bt-external-ip option. You can specify the external IP
address to report to a BitTorrent tracker. Although this function
is named 'external', it can accept any kind of IP addresses.
* src/DefaultBtAnnounce.cc
* src/OptionHandlerFactory.cc
* src/option_processing.cc
* src/prefs.cc
* src/prefs.h
* src/usage_text.h
* test/DefaultBtAnnounceTest.cc
2009-02-03 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Extracted the algorithm to find the longest incremental sequence

View File

@ -167,6 +167,9 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
} else {
url += "&supportcrypto=1";
}
if(option->defined(PREF_BT_EXTERNAL_IP)) {
url += "&ip="+option->get(PREF_BT_EXTERNAL_IP);
}
return url;
}

View File

@ -726,6 +726,15 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
handlers.push_back(op);
}
// BitTorrent Specific Options
{
SharedHandle<OptionHandler> op(new DefaultOptionHandler
(PREF_BT_EXTERNAL_IP,
TEXT_BT_EXTERNAL_IP,
NO_DEFAULT_VALUE,
"a numeric IP address"));
op->addTag(TAG_BITTORRENT);
handlers.push_back(op);
}
{
SharedHandle<OptionHandler> op(new NumberOptionHandler
(PREF_BT_KEEP_ALIVE_INTERVAL,

View File

@ -222,6 +222,7 @@ Option* option_processing(int argc, char* const argv[])
{ PREF_MAX_OVERALL_UPLOAD_LIMIT.c_str(), required_argument, &lopt, 36 },
{ PREF_BT_HASH_CHECK_SEED.c_str(), optional_argument, &lopt, 37 },
{ PREF_BT_MAX_PEERS.c_str(), required_argument, &lopt, 38 },
{ PREF_BT_EXTERNAL_IP.c_str(), required_argument, &lopt, 39 },
#endif // ENABLE_BITTORRENT
#ifdef ENABLE_METALINK
{ PREF_METALINK_FILE.c_str(), required_argument, NULL, 'M' },
@ -355,6 +356,9 @@ Option* option_processing(int argc, char* const argv[])
case 38:
cmdstream << PREF_BT_MAX_PEERS << "=" << optarg << "\n";
break;
case 39:
cmdstream << PREF_BT_EXTERNAL_IP << "=" << optarg << "\n";
break;
case 100:
cmdstream << PREF_METALINK_VERSION << "=" << optarg << "\n";
break;

View File

@ -277,6 +277,8 @@ const std::string PREF_BT_SEED_UNVERIFIED("bt-seed-unverified");
const std::string PREF_BT_HASH_CHECK_SEED("bt-hash-check-seed");
// values: 1*digit
const std::string PREF_BT_MAX_PEERS("bt-max-peers");
// values: a string (IP address)
const std::string PREF_BT_EXTERNAL_IP("bt-external-ip");
/**
* Metalink related preferences

View File

@ -281,6 +281,8 @@ extern const std::string PREF_BT_SEED_UNVERIFIED;
extern const std::string PREF_BT_HASH_CHECK_SEED;
// values: 1*digit
extern const std::string PREF_BT_MAX_PEERS;
// values: a string (IP address)
extern const std::string PREF_BT_EXTERNAL_IP;
/**
* Metalink related preferences

View File

@ -473,4 +473,8 @@ _(" --event-poll=POLL Specify the method for polling events.")
" web browser(console-based ones, such as elinks,\n"\
" w3m, are recommended) to connect the server and\n"\
" see what's what."
#define TEXT_BT_EXTERNAL_IP \
_(" --bt-external-ip=IPADDRESS Specify the external IP address to report to a\n"\
" BitTorrent tracker. Although this function is\n"\
" named 'external', it can accept any kind of IP\n"\
" addresses.")

View File

@ -15,6 +15,7 @@
#include "AnnounceTier.h"
#include "FixedNumberRandomizer.h"
#include "FileEntry.h"
#include "prefs.h"
namespace aria2 {
@ -23,6 +24,7 @@ class DefaultBtAnnounceTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(DefaultBtAnnounceTest);
CPPUNIT_TEST(testGetAnnounceUrl);
CPPUNIT_TEST(testGetAnnounceUrl_withQuery);
CPPUNIT_TEST(testGetAnnounceUrl_externalIP);
CPPUNIT_TEST(testNoMoreAnnounce);
CPPUNIT_TEST(testIsAllAnnounceFailed);
CPPUNIT_TEST(testURLOrderInStoppedEvent);
@ -79,6 +81,7 @@ public:
void testGetAnnounceUrl();
void testGetAnnounceUrl_withQuery();
void testGetAnnounceUrl_externalIP();
void testNoMoreAnnounce();
void testIsAllAnnounceFailed();
void testURLOrderInStoppedEvent();
@ -210,6 +213,33 @@ void DefaultBtAnnounceTest::testGetAnnounceUrl_withQuery()
btAnnounce.getAnnounceUrl());
}
void DefaultBtAnnounceTest::testGetAnnounceUrl_externalIP()
{
std::string trackerURI = "http://localhost/announce";
std::deque<std::string> uris;
uris.push_back(trackerURI);
SharedHandle<AnnounceTier> announceTier(new AnnounceTier(uris));
_btContext->addAnnounceTier(announceTier);
_option->put(PREF_BT_EXTERNAL_IP, "192.168.1.1");
DefaultBtAnnounce btAnnounce(_btContext, _option);
btAnnounce.setPieceStorage(_pieceStorage);
btAnnounce.setPeerStorage(_peerStorage);
btAnnounce.setBtRuntime(_btRuntime);
btAnnounce.setRandomizer(SharedHandle<Randomizer>(new FixedNumberRandomizer()));
btAnnounce.generateKey();
CPPUNIT_ASSERT_EQUAL
(std::string("http://localhost/announce?"
"info_hash=%01%23Eg%89%AB%CD%EF%01%23Eg%89%AB%CD%EF%01%23Eg&"
"peer_id=%2Daria2%2Dultrafastdltl&"
"uploaded=1572864&downloaded=1310720&left=1572864&compact=1&"
"key=AAAAAAAA&numwant=50&no_peer_id=1&port=6989&event=started&"
"supportcrypto=1&ip=192.168.1.1"),
btAnnounce.getAnnounceUrl());
}
void DefaultBtAnnounceTest::testIsAllAnnounceFailed()
{
std::string trackerURI1 = "http://localhost/announce";