2006-12-24 06:25:21 +00:00
|
|
|
#include "BtHandshakeMessage.h"
|
2008-11-27 15:29:15 +00:00
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2006-12-24 06:25:21 +00:00
|
|
|
#include "PeerMessageUtil.h"
|
|
|
|
#include "Util.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "BtConstants.h"
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
2006-12-24 06:25:21 +00:00
|
|
|
|
|
|
|
class BtHandshakeMessageTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(BtHandshakeMessageTest);
|
|
|
|
CPPUNIT_TEST(testCreate);
|
|
|
|
CPPUNIT_TEST(testGetMessage);
|
|
|
|
CPPUNIT_TEST(testToString);
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
CPPUNIT_TEST(testSetDHTEnabled);
|
2006-12-24 06:25:21 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setUp() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void testCreate();
|
|
|
|
void testGetMessage();
|
|
|
|
void testToString();
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
void testSetDHTEnabled();
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
static std::string BTPSTR;
|
2006-12-24 06:25:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string BtHandshakeMessageTest::BTPSTR = "BitTorrent protocol";
|
2006-12-24 06:25:21 +00:00
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(BtHandshakeMessageTest);
|
|
|
|
|
|
|
|
void createHandshakeMessageData(unsigned char* msg) {
|
|
|
|
msg[0] = 19;
|
|
|
|
memcpy(&msg[1], BtHandshakeMessageTest::BTPSTR.c_str(),
|
|
|
|
BtHandshakeMessageTest::BTPSTR.size());
|
2007-12-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added uTorrent compatible Peer Exchange.
* src/BencodeVisitor.{h, cc}
* test/BencodeVisitorTest.cc
* src/BtConstants.h
* src/BtContext.h: Added 'private' flag.
* src/BtExtendedMessage.{h, cc}
* test/BtExtendedMessageTest.cc
* src/BtHandshakeMessage.{h, cc}: Set extended messaging bit in
reserved field.
* test/BtHandshakeMessageTest.cc
* src/BtMessageFactory.h
* src/BtRegistry.h
* src/BtRuntime.h: This class holds default extension message
IDs for
aria2. By default, aria2 uses ID 8 for ut_pex.
* src/DefaultBtContext.cc
* src/DefaultBtInteractive.{h, cc}: This class holds
_utPexEnabled.
When it is true, aria2 enables ut_pex. This value is set by
PeerInteractionCommand.
* src/DefaultBtMessageFactory.{h, cc}
* test/DefaultBtMessageFactoryTest.cc
* src/DefaultBtMessageReceiver.cc: Moved the code of fast
extension
handling to DefaultBtInteractive class.
* src/DefaultExtensionMessageFactory.{h, cc}
* test/DefaultExtensionMessageFactoryTest.cc
* src/DefaultPeerStorage.cc: Returns false if a peer is already
in
the container(peers and incomingPeers. The equality is
determined by
Peer::id).
* test/DefaultPeerStorageTest.cc
* src/ExtensionMessage.h
* test/MockExtensionMessage.h
* src/ExtensionMessageFactory.h
* test/MockExtensionMessageFactory.h
* src/HandshakeExtensionMessage.{h, cc}
* test/HandshakeExtensionMessageTest.cc
* src/MetaEntry.h
* src/Peer.{h, cc}
* src/PeerInteractionCommand.cc
* src/PeerReceiveHandshakeCommand.cc: Evaluate the return value
of
addIncomingPeer.
* src/PeerMessageUtil.{h, cc}
* src/PeerObject.h
* src/UTPexExtensionMessage.{h, cc}
* test/UTPexExtensionMessageTest.cc
* src/message.h
* src/prefs.h
Fixed the bug that returns incomplete data when it contains null
character. A convenient constructor was also added.
* src/Data.{h, cc}
Rewritten.
* src/CompactPeerListProcessor.cc
Fixed typos.
* src/message.h
* src/MetaFileUtil.cc
2007-12-22 03:57:55 +00:00
|
|
|
unsigned char reserved[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x04 };
|
2006-12-24 06:25:21 +00:00
|
|
|
memcpy(&msg[20], reserved, sizeof(reserved));
|
|
|
|
unsigned char infoHash[] = { 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff };
|
|
|
|
memcpy(&msg[28], infoHash, sizeof(infoHash));
|
|
|
|
unsigned char peerId[] = { 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
|
|
|
|
0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
|
|
|
|
0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
|
|
|
|
0xf0, 0xf0, 0xf0, 0xf0, 0xf0 };
|
|
|
|
memcpy(&msg[48], peerId, sizeof(peerId));
|
|
|
|
}
|
|
|
|
|
|
|
|
void BtHandshakeMessageTest::testCreate() {
|
|
|
|
unsigned char msg[68];
|
|
|
|
createHandshakeMessageData(msg);
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<BtHandshakeMessage> message = BtHandshakeMessage::create(&msg[0], sizeof(msg));
|
2008-03-09 12:24:01 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint8_t)INT8_MAX, message->getId());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((uint8_t)19, message->getPstrlen());
|
2006-12-24 06:25:21 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(Util::toHex((const unsigned char*)BTPSTR.c_str(), BTPSTR.size()),
|
|
|
|
Util::toHex(message->getPstr(), BtHandshakeMessage::PSTR_LENGTH));
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("0000000000100004"),
|
2006-12-24 06:25:21 +00:00
|
|
|
Util::toHex(message->getReserved(), BtHandshakeMessage::RESERVED_LENGTH));
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("ffffffffffffffffffffffffffffffffffffffff"),
|
2006-12-24 06:25:21 +00:00
|
|
|
Util::toHex(message->getInfoHash(), INFO_HASH_LENGTH));
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0"),
|
2006-12-24 06:25:21 +00:00
|
|
|
Util::toHex(message->getPeerId(), PEER_ID_LENGTH));
|
|
|
|
}
|
|
|
|
|
|
|
|
void BtHandshakeMessageTest::testGetMessage() {
|
|
|
|
unsigned char infoHash[] = { 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff };
|
|
|
|
unsigned char peerId[] = { 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
|
|
|
|
0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
|
|
|
|
0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
|
|
|
|
0xf0, 0xf0, 0xf0, 0xf0, 0xf0 };
|
|
|
|
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<BtHandshakeMessage> msg(new BtHandshakeMessage());
|
2006-12-24 06:25:21 +00:00
|
|
|
msg->setInfoHash(infoHash);
|
|
|
|
msg->setPeerId(peerId);
|
|
|
|
|
|
|
|
unsigned char data[68];
|
|
|
|
createHandshakeMessageData(data);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(Util::toHex((const unsigned char*)data, 68),
|
|
|
|
Util::toHex((const unsigned char*)msg->getMessage(), 68));
|
|
|
|
}
|
|
|
|
|
|
|
|
void BtHandshakeMessageTest::testToString() {
|
|
|
|
unsigned char infoHash[] = { 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff };
|
|
|
|
unsigned char peerId[] = { 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
|
|
|
|
0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
|
|
|
|
0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
|
|
|
|
0xf0, 0xf0, 0xf0, 0xf0, 0xf0 };
|
|
|
|
|
|
|
|
BtHandshakeMessage msg;
|
|
|
|
msg.setInfoHash(infoHash);
|
|
|
|
msg.setPeerId(peerId);
|
|
|
|
|
2008-11-27 15:29:15 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("handshake peerId=%F0%F0%F0%F0%F0%F0%F0%F0%F0%F0%F0%F0%F0%F0%F0%F0%F0%F0%F0%F0, reserved=0000000000100004"), msg.toString());
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
|
|
|
|
void BtHandshakeMessageTest::testSetDHTEnabled()
|
|
|
|
{
|
|
|
|
BtHandshakeMessage msg;
|
|
|
|
CPPUNIT_ASSERT(!msg.isDHTEnabled());
|
|
|
|
msg.setDHTEnabled(false);
|
|
|
|
CPPUNIT_ASSERT(!msg.isDHTEnabled());
|
|
|
|
msg.setDHTEnabled(true);
|
|
|
|
CPPUNIT_ASSERT(msg.isDHTEnabled());
|
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
} // namespace aria2
|