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

Method testCreateFindNodeReplyMessage6

test/DHTMessageFactoryImplTest.cc:199–244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

197}
198
199void DHTMessageFactoryImplTest::testCreateFindNodeReplyMessage6()
200{
201 factory = make_unique<DHTMessageFactoryImpl>(AF_INET6);
202 factory->setLocalNode(localNode);
203 factory->setRoutingTable(routingTable.get());
204 try {
205 Dict dict;
206 dict.put("t", String::g(transactionID, DHT_TRANSACTION_ID_LENGTH));
207 dict.put("y", "r");
208 auto rDict = Dict::g();
209 rDict->put("id", String::g(remoteNodeID, DHT_ID_LENGTH));
210 std::string compactNodeInfo;
211 std::shared_ptr<DHTNode> nodes[8];
212 for (size_t i = 0; i < DHTBucket::K; ++i) {
213 nodes[i] = std::make_shared<DHTNode>();
214 nodes[i]->setIPAddress("2001::000" + util::uitos(i + 1));
215 nodes[i]->setPort(6881 + i);
216
217 unsigned char buf[COMPACT_LEN_IPV6];
218 CPPUNIT_ASSERT_EQUAL(COMPACT_LEN_IPV6, bittorrent::packcompact(
219 buf, nodes[i]->getIPAddress(),
220 nodes[i]->getPort()));
221 compactNodeInfo += std::string(&nodes[i]->getID()[0],
222 &nodes[i]->getID()[DHT_ID_LENGTH]) +
223 std::string(&buf[0], &buf[COMPACT_LEN_IPV6]);
224 }
225 rDict->put("nodes6", compactNodeInfo);
226 dict.put("r", std::move(rDict));
227
228 auto r = factory->createResponseMessage("find_node", &dict,
229 remoteNode_->getIPAddress(),
230 remoteNode_->getPort());
231 auto m = dynamic_cast<DHTFindNodeReplyMessage*>(r.get());
232
233 CPPUNIT_ASSERT(*localNode == *m->getLocalNode());
234 CPPUNIT_ASSERT(*remoteNode_ == *m->getRemoteNode());
235 CPPUNIT_ASSERT_EQUAL((size_t)DHTBucket::K, m->getClosestKNodes().size());
236 CPPUNIT_ASSERT(*nodes[0] == *m->getClosestKNodes()[0]);
237 CPPUNIT_ASSERT(*nodes[7] == *m->getClosestKNodes()[7]);
238 CPPUNIT_ASSERT_EQUAL(util::toHex(transactionID, DHT_TRANSACTION_ID_LENGTH),
239 util::toHex(m->getTransactionID()));
240 }
241 catch (Exception& e) {
242 CPPUNIT_FAIL(e.stackTrace());
243 }
244}
245
246void DHTMessageFactoryImplTest::testCreateGetPeersMessage()
247{

Callers

nothing calls this directly

Calls 15

uitosFunction · 0.85
packcompactFunction · 0.85
toHexFunction · 0.85
setIPAddressMethod · 0.80
getIDMethod · 0.80
getRemoteNodeMethod · 0.80
getClosestKNodesMethod · 0.80
stackTraceMethod · 0.80
setLocalNodeMethod · 0.45
setRoutingTableMethod · 0.45
getMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected