MCPcopy Create free account
hub / github.com/aria2/aria2 / testGetBencodedMessage

Method testGetBencodedMessage

test/DHTFindNodeReplyMessageTest.cc:33–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31CPPUNIT_TEST_SUITE_REGISTRATION(DHTFindNodeReplyMessageTest);
32
33void DHTFindNodeReplyMessageTest::testGetBencodedMessage()
34{
35 std::shared_ptr<DHTNode> localNode(new DHTNode());
36 std::shared_ptr<DHTNode> remoteNode(new DHTNode());
37
38 unsigned char tid[DHT_TRANSACTION_ID_LENGTH];
39 util::generateRandomData(tid, DHT_TRANSACTION_ID_LENGTH);
40 std::string transactionID(&tid[0], &tid[DHT_TRANSACTION_ID_LENGTH]);
41
42 DHTFindNodeReplyMessage msg(AF_INET, localNode, remoteNode, transactionID);
43 msg.setVersion("A200");
44 std::string compactNodeInfo;
45 std::shared_ptr<DHTNode> nodes[8];
46 for (size_t i = 0; i < DHTBucket::K; ++i) {
47 nodes[i].reset(new DHTNode());
48 nodes[i]->setIPAddress("192.168.0." + util::uitos(i + 1));
49 nodes[i]->setPort(6881 + i);
50
51 unsigned char buf[COMPACT_LEN_IPV6];
52 CPPUNIT_ASSERT_EQUAL(COMPACT_LEN_IPV4,
53 bittorrent::packcompact(buf, nodes[i]->getIPAddress(),
54 nodes[i]->getPort()));
55 compactNodeInfo +=
56 std::string(&nodes[i]->getID()[0], &nodes[i]->getID()[DHT_ID_LENGTH]) +
57 std::string(&buf[0], &buf[COMPACT_LEN_IPV4]);
58 }
59 msg.setClosestKNodes(
60 std::vector<std::shared_ptr<DHTNode>>(&nodes[0], &nodes[DHTBucket::K]));
61
62 std::string msgbody = msg.getBencodedMessage();
63
64 Dict dict;
65 dict.put("t", transactionID);
66 dict.put("v", "A200");
67 dict.put("y", "r");
68 auto rDict = Dict::g();
69 rDict->put("id", String::g(localNode->getID(), DHT_ID_LENGTH));
70 rDict->put("nodes", compactNodeInfo);
71 dict.put("r", std::move(rDict));
72
73 CPPUNIT_ASSERT_EQUAL(bencode2::encode(&dict), msgbody);
74}
75
76void DHTFindNodeReplyMessageTest::testGetBencodedMessage6()
77{

Callers

nothing calls this directly

Calls 13

generateRandomDataFunction · 0.85
uitosFunction · 0.85
packcompactFunction · 0.85
setIPAddressMethod · 0.80
getIDMethod · 0.80
getBencodedMessageMethod · 0.80
encodeFunction · 0.50
setVersionMethod · 0.45
resetMethod · 0.45
setPortMethod · 0.45
getPortMethod · 0.45
setClosestKNodesMethod · 0.45

Tested by

no test coverage detected