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

Method testCreateGetPeersReplyMessage6

test/DHTMessageFactoryImplTest.cc:336–403  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

334}
335
336void DHTMessageFactoryImplTest::testCreateGetPeersReplyMessage6()
337{
338 factory = make_unique<DHTMessageFactoryImpl>(AF_INET6);
339 factory->setLocalNode(localNode);
340 factory->setRoutingTable(routingTable.get());
341 try {
342 Dict dict;
343 dict.put("t", String::g(transactionID, DHT_TRANSACTION_ID_LENGTH));
344 dict.put("y", "r");
345 auto rDict = Dict::g();
346 rDict->put("id", String::g(remoteNodeID, DHT_ID_LENGTH));
347 std::string compactNodeInfo;
348 std::shared_ptr<DHTNode> nodes[8];
349 for (size_t i = 0; i < DHTBucket::K; ++i) {
350 nodes[i] = std::make_shared<DHTNode>();
351 nodes[i]->setIPAddress("2001::000" + util::uitos(i + 1));
352 nodes[i]->setPort(6881 + i);
353
354 unsigned char buf[COMPACT_LEN_IPV6];
355 CPPUNIT_ASSERT_EQUAL(COMPACT_LEN_IPV6, bittorrent::packcompact(
356 buf, nodes[i]->getIPAddress(),
357 nodes[i]->getPort()));
358 compactNodeInfo += std::string(&nodes[i]->getID()[0],
359 &nodes[i]->getID()[DHT_ID_LENGTH]) +
360 std::string(&buf[0], &buf[COMPACT_LEN_IPV6]);
361 }
362 rDict->put("nodes6", compactNodeInfo);
363
364 std::deque<std::shared_ptr<Peer>> peers;
365 auto valuesList = List::g();
366 for (size_t i = 0; i < 4; ++i) {
367 auto peer =
368 std::make_shared<Peer>("2001::100" + util::uitos(i + 1), 6881 + i);
369 unsigned char buffer[COMPACT_LEN_IPV6];
370 CPPUNIT_ASSERT_EQUAL(COMPACT_LEN_IPV6,
371 bittorrent::packcompact(buffer, peer->getIPAddress(),
372 peer->getPort()));
373 valuesList->append(String::g(buffer, COMPACT_LEN_IPV6));
374 peers.push_back(peer);
375 }
376 rDict->put("values", std::move(valuesList));
377 rDict->put("token", "token");
378 dict.put("r", std::move(rDict));
379
380 auto r = factory->createResponseMessage("get_peers", &dict,
381 remoteNode_->getIPAddress(),
382 remoteNode_->getPort());
383 auto m = dynamic_cast<DHTGetPeersReplyMessage*>(r.get());
384
385 CPPUNIT_ASSERT(*localNode == *m->getLocalNode());
386 CPPUNIT_ASSERT(*remoteNode_ == *m->getRemoteNode());
387 CPPUNIT_ASSERT_EQUAL(std::string("token"), m->getToken());
388 CPPUNIT_ASSERT_EQUAL((size_t)DHTBucket::K, m->getClosestKNodes().size());
389 CPPUNIT_ASSERT(*nodes[0] == *m->getClosestKNodes()[0]);
390 CPPUNIT_ASSERT(*nodes[7] == *m->getClosestKNodes()[7]);
391 CPPUNIT_ASSERT_EQUAL((size_t)4, m->getValues().size());
392 for (int i = 0; i < 4; ++i) {
393 CPPUNIT_ASSERT_EQUAL(peers[i]->getIPAddress(),

Callers

nothing calls this directly

Calls 15

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

Tested by

no test coverage detected