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

Method testGetBencodedMessage6

test/DHTGetPeersReplyMessageTest.cc:97–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

95}
96
97void DHTGetPeersReplyMessageTest::testGetBencodedMessage6()
98{
99 std::shared_ptr<DHTNode> localNode(new DHTNode());
100 std::shared_ptr<DHTNode> remoteNode(new DHTNode());
101
102 unsigned char tid[DHT_TRANSACTION_ID_LENGTH];
103 util::generateRandomData(tid, DHT_TRANSACTION_ID_LENGTH);
104 std::string transactionID(&tid[0], &tid[DHT_TRANSACTION_ID_LENGTH]);
105
106 std::string token = "token";
107
108 DHTGetPeersReplyMessage msg(AF_INET6, localNode, remoteNode, token,
109 transactionID);
110 msg.setVersion("A200");
111 Dict dict;
112 dict.put("t", transactionID);
113 dict.put("v", "A200");
114 dict.put("y", "r");
115 auto rDict = Dict::g();
116 rDict->put("id", String::g(localNode->getID(), DHT_ID_LENGTH));
117 rDict->put("token", token);
118 {
119 std::string compactNodeInfo;
120 std::shared_ptr<DHTNode> nodes[8];
121 for (size_t i = 0; i < DHTBucket::K; ++i) {
122 nodes[i].reset(new DHTNode());
123 nodes[i]->setIPAddress("2001::000" + util::uitos(i + 1));
124 nodes[i]->setPort(6881 + i);
125
126 unsigned char buf[COMPACT_LEN_IPV6];
127 CPPUNIT_ASSERT_EQUAL(COMPACT_LEN_IPV6, bittorrent::packcompact(
128 buf, nodes[i]->getIPAddress(),
129 nodes[i]->getPort()));
130 compactNodeInfo += std::string(&nodes[i]->getID()[0],
131 &nodes[i]->getID()[DHT_ID_LENGTH]) +
132 std::string(&buf[0], &buf[COMPACT_LEN_IPV6]);
133 }
134 msg.setClosestKNodes(
135 std::vector<std::shared_ptr<DHTNode>>(&nodes[0], &nodes[DHTBucket::K]));
136 rDict->put("nodes6", compactNodeInfo);
137
138 std::vector<std::shared_ptr<Peer>> peers;
139 auto valuesList = List::g();
140 for (size_t i = 0; i < 4; ++i) {
141 auto peer =
142 std::make_shared<Peer>("2001::100" + util::uitos(i + 1), 6881 + i);
143 unsigned char buffer[COMPACT_LEN_IPV6];
144 CPPUNIT_ASSERT_EQUAL(COMPACT_LEN_IPV6,
145 bittorrent::packcompact(buffer, peer->getIPAddress(),
146 peer->getPort()));
147 valuesList->append(String::g(buffer, COMPACT_LEN_IPV6));
148 peers.push_back(peer);
149 }
150 msg.setValues(peers);
151 rDict->put("values", std::move(valuesList));
152 dict.put("r", std::move(rDict));
153
154 std::string msgbody = msg.getBencodedMessage();

Callers

nothing calls this directly

Calls 15

generateRandomDataFunction · 0.85
uitosFunction · 0.85
packcompactFunction · 0.85
percentEncodeFunction · 0.85
getIDMethod · 0.80
setIPAddressMethod · 0.80
push_backMethod · 0.80
setValuesMethod · 0.80
getBencodedMessageMethod · 0.80
encodeFunction · 0.50
setVersionMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected