mirror of https://github.com/aria2/aria2
2009-10-05 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Included version number in Peer ID and client version. Peer ID now starts with "aria2/VERSION-", where VERSION is MAJOR.MINOR.MICRO. Client version is aria2/VERSION. * src/DefaultBtInteractive.cc * src/OptionHandlerFactory.cc * src/bittorrent_helper.cc * src/bittorrent_helper.h * src/main.cc * src/usage_text.h * test/BittorrentHelperTest.ccpull/1/head
parent
51ba780c76
commit
436448dd8a
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
||||||
|
2009-10-05 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Included version number in Peer ID and client version. Peer ID
|
||||||
|
now starts with "aria2/VERSION-", where VERSION is
|
||||||
|
MAJOR.MINOR.MICRO. Client version is aria2/VERSION.
|
||||||
|
* src/DefaultBtInteractive.cc
|
||||||
|
* src/OptionHandlerFactory.cc
|
||||||
|
* src/bittorrent_helper.cc
|
||||||
|
* src/bittorrent_helper.h
|
||||||
|
* src/main.cc
|
||||||
|
* src/usage_text.h
|
||||||
|
* test/BittorrentHelperTest.cc
|
||||||
|
|
||||||
2009-10-05 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2009-10-05 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Fixed memory leak.
|
Fixed memory leak.
|
||||||
|
|
|
@ -161,7 +161,7 @@ void DefaultBtInteractive::addPortMessageToQueue()
|
||||||
|
|
||||||
void DefaultBtInteractive::addHandshakeExtendedMessageToQueue()
|
void DefaultBtInteractive::addHandshakeExtendedMessageToQueue()
|
||||||
{
|
{
|
||||||
static const std::string CLIENT_ARIA2("aria2");
|
static const std::string CLIENT_ARIA2("aria2/"PACKAGE_VERSION);
|
||||||
HandshakeExtensionMessageHandle m(new HandshakeExtensionMessage());
|
HandshakeExtensionMessageHandle m(new HandshakeExtensionMessage());
|
||||||
m->setClientVersion(CLIENT_ARIA2);
|
m->setClientVersion(CLIENT_ARIA2);
|
||||||
m->setTCPPort(_btRuntime->getListenPort());
|
m->setTCPPort(_btRuntime->getListenPort());
|
||||||
|
|
|
@ -1140,7 +1140,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
|
||||||
SharedHandle<OptionHandler> op(new DefaultOptionHandler
|
SharedHandle<OptionHandler> op(new DefaultOptionHandler
|
||||||
(PREF_PEER_ID_PREFIX,
|
(PREF_PEER_ID_PREFIX,
|
||||||
TEXT_PEER_ID_PREFIX,
|
TEXT_PEER_ID_PREFIX,
|
||||||
"-aria2-"));
|
"aria2/"PACKAGE_VERSION"-"));
|
||||||
op->addTag(TAG_BITTORRENT);
|
op->addTag(TAG_BITTORRENT);
|
||||||
handlers.push_back(op);
|
handlers.push_back(op);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@
|
||||||
#include "a2netcompat.h"
|
#include "a2netcompat.h"
|
||||||
#include "BtConstants.h"
|
#include "BtConstants.h"
|
||||||
#include "bitfield.h"
|
#include "bitfield.h"
|
||||||
|
#include "DHTUtil.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -93,7 +94,7 @@ static const std::string C_COMMENT_UTF8("comment.utf-8");
|
||||||
|
|
||||||
static const std::string C_CREATED_BY("created by");
|
static const std::string C_CREATED_BY("created by");
|
||||||
|
|
||||||
static const std::string DEFAULT_PEER_ID_PREFIX("-aria2-");
|
static const std::string DEFAULT_PEER_ID_PREFIX("aria2-");
|
||||||
|
|
||||||
const std::string INFO_HASH("infoHash");
|
const std::string INFO_HASH("infoHash");
|
||||||
|
|
||||||
|
@ -618,12 +619,16 @@ void computeFastSet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string generatePeerId
|
std::string generatePeerId(const std::string& peerIdPrefix)
|
||||||
(const std::string& peerIdPrefix, const SharedHandle<Randomizer>& randomizer)
|
|
||||||
{
|
{
|
||||||
std::string peerId = peerIdPrefix;
|
std::string peerId = peerIdPrefix;
|
||||||
peerId += Util::randomAlpha(20-peerIdPrefix.size(), randomizer);
|
unsigned char buf[20];
|
||||||
if(peerId.size() > 20) {
|
int len = 20-peerIdPrefix.size();
|
||||||
|
if(len > 0) {
|
||||||
|
DHTUtil::generateRandomData(buf, len);
|
||||||
|
|
||||||
|
peerId += std::string(&buf[0], &buf[len]);
|
||||||
|
} if(peerId.size() > 20) {
|
||||||
peerId.erase(20);
|
peerId.erase(20);
|
||||||
}
|
}
|
||||||
return peerId;
|
return peerId;
|
||||||
|
@ -631,11 +636,10 @@ std::string generatePeerId
|
||||||
|
|
||||||
static std::string peerId;
|
static std::string peerId;
|
||||||
|
|
||||||
const std::string& generateStaticPeerId
|
const std::string& generateStaticPeerId(const std::string& peerIdPrefix)
|
||||||
(const std::string& peerIdPrefix, const SharedHandle<Randomizer>& randomizer)
|
|
||||||
{
|
{
|
||||||
if(peerId.empty()) {
|
if(peerId.empty()) {
|
||||||
peerId = generatePeerId(peerIdPrefix, randomizer);
|
peerId = generatePeerId(peerIdPrefix);
|
||||||
}
|
}
|
||||||
return peerId;
|
return peerId;
|
||||||
}
|
}
|
||||||
|
@ -646,12 +650,13 @@ void setStaticPeerId(const std::string& newPeerId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If PeerID is not generated, it is created with default peerIdPrefix
|
// If PeerID is not generated, it is created with default peerIdPrefix
|
||||||
// (-aria2-) and SimpleRandomizer.
|
// (aria2-).
|
||||||
const unsigned char* getStaticPeerId()
|
const unsigned char* getStaticPeerId()
|
||||||
{
|
{
|
||||||
if(peerId.empty()) {
|
if(peerId.empty()) {
|
||||||
return
|
return
|
||||||
reinterpret_cast<const unsigned char*>(generateStaticPeerId(DEFAULT_PEER_ID_PREFIX, SimpleRandomizer::getInstance()).data());
|
reinterpret_cast<const unsigned char*>
|
||||||
|
(generateStaticPeerId(DEFAULT_PEER_ID_PREFIX).data());
|
||||||
} else {
|
} else {
|
||||||
return reinterpret_cast<const unsigned char*>(peerId.data());
|
return reinterpret_cast<const unsigned char*>(peerId.data());
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,17 +119,15 @@ void loadFromMemory(const std::string& context,
|
||||||
// length. This function uses peerIdPrefix as a Peer ID and it is
|
// length. This function uses peerIdPrefix as a Peer ID and it is
|
||||||
// less than 20bytes, random bytes are generated and appened to it. If
|
// less than 20bytes, random bytes are generated and appened to it. If
|
||||||
// peerIdPrefix is larger than 20bytes, first 20bytes are used.
|
// peerIdPrefix is larger than 20bytes, first 20bytes are used.
|
||||||
std::string generatePeerId
|
std::string generatePeerId(const std::string& peerIdPrefix);
|
||||||
(const std::string& peerIdPrefix, const SharedHandle<Randomizer>& randomizer);
|
|
||||||
|
|
||||||
// Generates Peer ID and stores it in static variable. This function
|
// Generates Peer ID and stores it in static variable. This function
|
||||||
// uses generatePeerId(peerIdPrefix, randomizer) to produce Peer ID.
|
// uses generatePeerId(peerIdPrefix) to produce Peer ID.
|
||||||
const std::string& generateStaticPeerId
|
const std::string& generateStaticPeerId(const std::string& peerIdPrefix);
|
||||||
(const std::string& peerIdPrefix, const SharedHandle<Randomizer>& randomizer);
|
|
||||||
|
|
||||||
// Returns Peer ID statically stored by generateStaticPeerId(). If
|
// Returns Peer ID statically stored by generateStaticPeerId(). If
|
||||||
// Peer ID is not stored yet, this function calls
|
// Peer ID is not stored yet, this function calls
|
||||||
// generateStaticPeerId("-aria2-", randomizer)
|
// generateStaticPeerId("aria2-")
|
||||||
const unsigned char* getStaticPeerId();
|
const unsigned char* getStaticPeerId();
|
||||||
|
|
||||||
// Set newPeerId as a static Peer ID. newPeerId must be 20-byte
|
// Set newPeerId as a static Peer ID. newPeerId must be 20-byte
|
||||||
|
|
|
@ -174,8 +174,7 @@ downloadresultcode::RESULT main(int argc, char* argv[])
|
||||||
SimpleRandomizer::init();
|
SimpleRandomizer::init();
|
||||||
BitfieldManFactory::setDefaultRandomizer(SimpleRandomizer::getInstance());
|
BitfieldManFactory::setDefaultRandomizer(SimpleRandomizer::getInstance());
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
bittorrent::generateStaticPeerId(op->get(PREF_PEER_ID_PREFIX),
|
bittorrent::generateStaticPeerId(op->get(PREF_PEER_ID_PREFIX));
|
||||||
SimpleRandomizer::getInstance());
|
|
||||||
#endif // ENABLE_BITTORRENT
|
#endif // ENABLE_BITTORRENT
|
||||||
if(op->get(PREF_LOG) == "-") {
|
if(op->get(PREF_LOG) == "-") {
|
||||||
LogFactory::setLogFile(DEV_STDOUT);
|
LogFactory::setLogFile(DEV_STDOUT);
|
||||||
|
|
|
@ -287,10 +287,9 @@ _(" --seed-ratio=RATIO Specify share ratio. Seed completed torrents\n"
|
||||||
#define TEXT_PEER_ID_PREFIX \
|
#define TEXT_PEER_ID_PREFIX \
|
||||||
_(" --peer-id-prefix=PEER_ID_PREFIX Specify the prefix of peer ID. The peer ID in\n"\
|
_(" --peer-id-prefix=PEER_ID_PREFIX Specify the prefix of peer ID. The peer ID in\n"\
|
||||||
" BitTorrent is 20 byte length. If more than 20\n"\
|
" BitTorrent is 20 byte length. If more than 20\n"\
|
||||||
" bytes are specified, only first 20\n"\
|
" bytes are specified, only first 20 bytes are\n"\
|
||||||
" bytes are used. If less than 20 bytes are\n"\
|
" used. If less than 20 bytes are specified, random\n"\
|
||||||
" specified, the random alphabet characters are\n"\
|
" byte data are added to make its length 20 bytes.")
|
||||||
" added to make it's length 20 bytes.")
|
|
||||||
#define TEXT_ENABLE_PEER_EXCHANGE \
|
#define TEXT_ENABLE_PEER_EXCHANGE \
|
||||||
_(" --enable-peer-exchange[=true|false] Enable Peer Exchange extension.")
|
_(" --enable-peer-exchange[=true|false] Enable Peer Exchange extension.")
|
||||||
#define TEXT_ENABLE_DHT \
|
#define TEXT_ENABLE_DHT \
|
||||||
|
|
|
@ -284,11 +284,9 @@ void BittorrentHelperTest::testGetInfoHashAsString() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BittorrentHelperTest::testGetPeerId() {
|
void BittorrentHelperTest::testGetPeerId() {
|
||||||
SharedHandle<DownloadContext> dctx(new DownloadContext());
|
std::string peerId = generatePeerId("aria2-");
|
||||||
CPPUNIT_ASSERT_EQUAL
|
CPPUNIT_ASSERT(peerId.find("aria2-") == 0);
|
||||||
(std::string("-aria-AAAAAAAAAAAAAA"),
|
CPPUNIT_ASSERT_EQUAL((size_t)20, peerId.size());
|
||||||
generatePeerId("-aria-",
|
|
||||||
SharedHandle<Randomizer>(new FixedNumberRandomizer())));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BittorrentHelperTest::testComputeFastSet()
|
void BittorrentHelperTest::testComputeFastSet()
|
||||||
|
|
Loading…
Reference in New Issue