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

Method testSerialize6

test/DHTRoutingTableSerializerTest.cc:223–310  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

221}
222
223void DHTRoutingTableSerializerTest::testSerialize6()
224{
225 std::shared_ptr<DHTNode> localNode(new DHTNode());
226
227 std::vector<std::shared_ptr<DHTNode>> nodes(2);
228 for (size_t i = 0; i < nodes.size(); ++i) {
229 nodes[i].reset(new DHTNode());
230 nodes[i]->setIPAddress("2001::100" + util::uitos(i + 1));
231 nodes[i]->setPort(6881 + i);
232 }
233 nodes[1]->setIPAddress("non-numerical-name");
234
235 DHTRoutingTableSerializer s(AF_INET6);
236 s.setLocalNode(localNode);
237 s.setNodes(nodes);
238
239 std::string filename =
240 A2_TEST_OUT_DIR "/aria2_DHTRoutingTableSerializerTest_testSerialize6";
241 s.serialize(filename);
242
243 std::ifstream ss(filename.c_str(), std::ios::binary);
244
245 checkToLocalnode(ss, localNode);
246 size_t numNodes = 2;
247 checkNumNodes(ss, numNodes);
248
249 // 4bytes reserved
250 ss.read(buf, 4);
251 CPPUNIT_ASSERT(memcmp(zero, buf, 4) == 0);
252
253 // node[0]
254 // 1byte compatc peer format length
255 {
256 uint8_t len;
257 ss >> len;
258 CPPUNIT_ASSERT_EQUAL((uint8_t)18, len);
259 }
260 // 7bytes reserved
261 ss.read(buf, 7);
262 CPPUNIT_ASSERT(memcmp(zero, buf, 7) == 0);
263 // 18 bytes compact peer info
264 ss.read(buf, 18);
265 {
266 std::pair<std::string, uint16_t> peer = bittorrent::unpackcompact(
267 reinterpret_cast<const unsigned char*>(buf), AF_INET6);
268 CPPUNIT_ASSERT_EQUAL(std::string("2001::1001"), peer.first);
269 CPPUNIT_ASSERT_EQUAL((uint16_t)6881, peer.second);
270 }
271 // 6bytes reserved
272 ss.read(buf, 6);
273 CPPUNIT_ASSERT(memcmp(zero, buf, 6) == 0);
274 // localnode ID
275 ss.read(buf, DHT_ID_LENGTH);
276 CPPUNIT_ASSERT(memcmp(nodes[0]->getID(), buf, DHT_ID_LENGTH) == 0);
277 // 4bytes reserved
278 ss.read(buf, 4);
279 CPPUNIT_ASSERT(memcmp(zero, buf, 4) == 0);
280

Callers

nothing calls this directly

Calls 12

uitosFunction · 0.85
unpackcompactFunction · 0.85
setIPAddressMethod · 0.80
setNodesMethod · 0.80
serializeMethod · 0.80
getIDMethod · 0.80
eofMethod · 0.80
sizeMethod · 0.45
resetMethod · 0.45
setPortMethod · 0.45
setLocalNodeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected