| 74 | } |
| 75 | |
| 76 | void DHTFindNodeReplyMessageTest::testGetBencodedMessage6() |
| 77 | { |
| 78 | std::shared_ptr<DHTNode> localNode(new DHTNode()); |
| 79 | std::shared_ptr<DHTNode> remoteNode(new DHTNode()); |
| 80 | |
| 81 | unsigned char tid[DHT_TRANSACTION_ID_LENGTH]; |
| 82 | util::generateRandomData(tid, DHT_TRANSACTION_ID_LENGTH); |
| 83 | std::string transactionID(&tid[0], &tid[DHT_TRANSACTION_ID_LENGTH]); |
| 84 | |
| 85 | DHTFindNodeReplyMessage msg(AF_INET6, localNode, remoteNode, transactionID); |
| 86 | msg.setVersion("A200"); |
| 87 | std::string compactNodeInfo; |
| 88 | std::shared_ptr<DHTNode> nodes[8]; |
| 89 | for (size_t i = 0; i < DHTBucket::K; ++i) { |
| 90 | nodes[i].reset(new DHTNode()); |
| 91 | nodes[i]->setIPAddress("2001::000" + util::uitos(i + 1)); |
| 92 | nodes[i]->setPort(6881 + i); |
| 93 | |
| 94 | unsigned char buf[COMPACT_LEN_IPV6]; |
| 95 | CPPUNIT_ASSERT_EQUAL(COMPACT_LEN_IPV6, |
| 96 | bittorrent::packcompact(buf, nodes[i]->getIPAddress(), |
| 97 | nodes[i]->getPort())); |
| 98 | compactNodeInfo += |
| 99 | std::string(&nodes[i]->getID()[0], &nodes[i]->getID()[DHT_ID_LENGTH]) + |
| 100 | std::string(&buf[0], &buf[COMPACT_LEN_IPV6]); |
| 101 | } |
| 102 | msg.setClosestKNodes( |
| 103 | std::vector<std::shared_ptr<DHTNode>>(&nodes[0], &nodes[DHTBucket::K])); |
| 104 | |
| 105 | std::string msgbody = msg.getBencodedMessage(); |
| 106 | |
| 107 | Dict dict; |
| 108 | dict.put("t", transactionID); |
| 109 | dict.put("v", "A200"); |
| 110 | dict.put("y", "r"); |
| 111 | auto rDict = Dict::g(); |
| 112 | rDict->put("id", String::g(localNode->getID(), DHT_ID_LENGTH)); |
| 113 | rDict->put("nodes6", compactNodeInfo); |
| 114 | dict.put("r", std::move(rDict)); |
| 115 | |
| 116 | CPPUNIT_ASSERT_EQUAL(bencode2::encode(&dict), msgbody); |
| 117 | } |
| 118 | |
| 119 | } // namespace aria2 |
nothing calls this directly
no test coverage detected