mirror of
https://github.com/aria2/aria2.git
synced 2025-01-24 10:41:18 +00:00
2bd5020f81
Added bittorrent::packcompact() which replaces bittorrent::createcompact() and supports IPv6 addresses. Rewritten bittorrent::unpackcompact() and bittorrent::extractPeer() to support IPv6 addresses. Fixed added.f flags in ut_pex. * src/BtConstants.h * src/DHTFindNodeReplyMessage.cc * src/DHTGetPeersReplyMessage.cc * src/DHTMessageFactoryImpl.cc * src/DHTRoutingTableDeserializer.cc * src/DHTRoutingTableSerializer.cc * src/DHTTokenTracker.cc * src/DefaultBtAnnounce.cc * src/UTPexExtensionMessage.cc * src/bittorrent_helper.cc * src/bittorrent_helper.h * test/BittorrentHelperTest.cc * test/DHTFindNodeReplyMessageTest.cc * test/DHTGetPeersReplyMessageTest.cc * test/DHTMessageFactoryImplTest.cc * test/DHTRoutingTableSerializerTest.cc * test/DefaultExtensionMessageFactoryTest.cc * test/UTPexExtensionMessageTest.cc
73 lines
2.0 KiB
C++
73 lines
2.0 KiB
C++
#include "DHTFindNodeReplyMessage.h"
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
#include "DHTNode.h"
|
|
#include "Exception.h"
|
|
#include "util.h"
|
|
#include "DHTBucket.h"
|
|
#include "bittorrent_helper.h"
|
|
#include "bencode2.h"
|
|
|
|
namespace aria2 {
|
|
|
|
class DHTFindNodeReplyMessageTest:public CppUnit::TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(DHTFindNodeReplyMessageTest);
|
|
CPPUNIT_TEST(testGetBencodedMessage);
|
|
CPPUNIT_TEST_SUITE_END();
|
|
public:
|
|
void setUp() {}
|
|
|
|
void tearDown() {}
|
|
|
|
void testGetBencodedMessage();
|
|
};
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(DHTFindNodeReplyMessageTest);
|
|
|
|
void DHTFindNodeReplyMessageTest::testGetBencodedMessage()
|
|
{
|
|
SharedHandle<DHTNode> localNode(new DHTNode());
|
|
SharedHandle<DHTNode> remoteNode(new DHTNode());
|
|
|
|
unsigned char tid[DHT_TRANSACTION_ID_LENGTH];
|
|
util::generateRandomData(tid, DHT_TRANSACTION_ID_LENGTH);
|
|
std::string transactionID(&tid[0], &tid[DHT_TRANSACTION_ID_LENGTH]);
|
|
|
|
DHTFindNodeReplyMessage msg(localNode, remoteNode, transactionID);
|
|
msg.setVersion("A200");
|
|
std::string compactNodeInfo;
|
|
SharedHandle<DHTNode> nodes[8];
|
|
for(size_t i = 0; i < DHTBucket::K; ++i) {
|
|
nodes[i].reset(new DHTNode());
|
|
nodes[i]->setIPAddress("192.168.0."+util::uitos(i+1));
|
|
nodes[i]->setPort(6881+i);
|
|
|
|
unsigned char buf[COMPACT_LEN_IPV6];
|
|
bittorrent::packcompact
|
|
(buf, nodes[i]->getIPAddress(), nodes[i]->getPort());
|
|
compactNodeInfo +=
|
|
std::string(&nodes[i]->getID()[0], &nodes[i]->getID()[DHT_ID_LENGTH])+
|
|
std::string(&buf[0], &buf[COMPACT_LEN_IPV4]);
|
|
}
|
|
msg.setClosestKNodes
|
|
(std::vector<SharedHandle<DHTNode> >(&nodes[0], &nodes[DHTBucket::K]));
|
|
|
|
std::string msgbody = msg.getBencodedMessage();
|
|
|
|
Dict dict;
|
|
dict.put("t", transactionID);
|
|
dict.put("v", "A200");
|
|
dict.put("y", "r");
|
|
SharedHandle<Dict> rDict = Dict::g();
|
|
rDict->put("id", String::g(localNode->getID(), DHT_ID_LENGTH));
|
|
rDict->put("nodes", compactNodeInfo);
|
|
dict.put("r", rDict);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(bencode2::encode(&dict), msgbody);
|
|
}
|
|
|
|
} // namespace aria2
|