From 335a0fb36f4c5222e36841c917eb5e43f3f09dbd Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 24 Aug 2008 09:43:45 +0000 Subject: [PATCH] 2008-08-24 Tatsuhiro Tsujikawa Bump up version number of .aria2 control file to 0001. New aria2 can still load version 0000 file but it saves the file in version 0001 format. It means that new aria2 can resume download started by old aria2 but the opposite is not true. * src/DefaultBtProgressInfoFile.cc * src/DefaultBtProgressInfoFile.h * test/DefaultBtProgressInfoFileTest.cc --- ChangeLog | 10 ++ src/DefaultBtProgressInfoFile.cc | 108 ++++++++++++++------ src/DefaultBtProgressInfoFile.h | 1 + test/DefaultBtProgressInfoFileTest.cc | 138 ++++++++++++++++++++++++-- test/load-nonBt-v0001.aria2 | Bin 0 -> 74 bytes test/load-v0001.aria2 | Bin 0 -> 94 bytes 6 files changed, 216 insertions(+), 41 deletions(-) create mode 100644 test/load-nonBt-v0001.aria2 create mode 100644 test/load-v0001.aria2 diff --git a/ChangeLog b/ChangeLog index 1941c760..2bfd2569 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-08-24 Tatsuhiro Tsujikawa + + Bump up version number of .aria2 control file to 0001. + New aria2 can still load version 0000 file but it saves the file in + version 0001 format. It means that new aria2 can resume download + started by old aria2 but the opposite is not true. + * src/DefaultBtProgressInfoFile.cc + * src/DefaultBtProgressInfoFile.h + * test/DefaultBtProgressInfoFileTest.cc + 2008-08-24 Tatsuhiro Tsujikawa Added ntoh64 and hton64 as inline functions. diff --git a/src/DefaultBtProgressInfoFile.cc b/src/DefaultBtProgressInfoFile.cc index be0b2a25..eb93a3ed 100644 --- a/src/DefaultBtProgressInfoFile.cc +++ b/src/DefaultBtProgressInfoFile.cc @@ -59,6 +59,7 @@ namespace aria2 { const std::string DefaultBtProgressInfoFile::V0000("0000"); +const std::string DefaultBtProgressInfoFile::V0001("0001"); static std::string createFilename(const SharedHandle& dctx) { @@ -88,6 +89,7 @@ bool DefaultBtProgressInfoFile::isTorrentDownload() return !dynamic_pointer_cast(_dctx).isNull(); } +// Since version 0001, Integers are saved in binary form, network byte order. void DefaultBtProgressInfoFile::save() { _logger->info(MSG_SAVING_SEGMENT_FILE, _filename.c_str()); std::string filenameTemp = _filename+"__temp"; @@ -96,9 +98,9 @@ void DefaultBtProgressInfoFile::save() { o.exceptions(std::ios::failbit); bool torrentDownload = isTorrentDownload(); // file version: 16 bits - // value: '0' - uint16_t version = 0; - o.write(reinterpret_cast(&version), sizeof(version)); + // values: '1' + char version[] = { 0x00, 0x01 }; + o.write(version, sizeof(version)); // extension: 32 bits // If this is BitTorrent download, then 0x00000001 // Otherwise, 0x00000000 @@ -112,9 +114,9 @@ void DefaultBtProgressInfoFile::save() { // infoHashLength: // length: 32 bits BtContextHandle btContext(dynamic_pointer_cast(_dctx)); - uint32_t infoHashLength = btContext->getInfoHashLength(); - o.write(reinterpret_cast(&infoHashLength), - sizeof(infoHashLength)); + uint32_t infoHashLengthNL = htonl(btContext->getInfoHashLength()); + o.write(reinterpret_cast(&infoHashLengthNL), + sizeof(infoHashLengthNL)); // infoHash: o.write(reinterpret_cast(btContext->getInfoHash()), btContext->getInfoHashLength()); @@ -126,44 +128,47 @@ void DefaultBtProgressInfoFile::save() { sizeof(infoHashLength)); } // pieceLength: 32 bits - uint32_t pieceLength = _dctx->getPieceLength(); - o.write(reinterpret_cast(&pieceLength), sizeof(pieceLength)); + uint32_t pieceLengthNL = htonl(_dctx->getPieceLength()); + o.write(reinterpret_cast(&pieceLengthNL), + sizeof(pieceLengthNL)); // totalLength: 64 bits - uint64_t totalLength = _dctx->getTotalLength(); - o.write(reinterpret_cast(&totalLength), sizeof(totalLength)); + uint64_t totalLengthNL = hton64(_dctx->getTotalLength()); + o.write(reinterpret_cast(&totalLengthNL), + sizeof(totalLengthNL)); // uploadLength: 64 bits - uint64_t uploadLength = 0; + uint64_t uploadLengthNL = 0; if(torrentDownload) { BtContextHandle btContext(dynamic_pointer_cast(_dctx)); TransferStat stat = PEER_STORAGE(btContext)->calculateStat(); - uploadLength = stat.getAllTimeUploadLength(); + uploadLengthNL = hton64(stat.getAllTimeUploadLength()); } - o.write(reinterpret_cast(&uploadLength), sizeof(uploadLength)); + o.write(reinterpret_cast(&uploadLengthNL), + sizeof(uploadLengthNL)); // bitfieldLength: 32 bits - uint32_t bitfieldLength = _pieceStorage->getBitfieldLength(); - o.write(reinterpret_cast(&bitfieldLength), - sizeof(bitfieldLength)); + uint32_t bitfieldLengthNL = htonl(_pieceStorage->getBitfieldLength()); + o.write(reinterpret_cast(&bitfieldLengthNL), + sizeof(bitfieldLengthNL)); // bitfield o.write(reinterpret_cast(_pieceStorage->getBitfield()), _pieceStorage->getBitfieldLength()); // the number of in-flight piece: 32 bits // TODO implement this - uint32_t numInFlightPiece = _pieceStorage->countInFlightPiece(); - o.write(reinterpret_cast(&numInFlightPiece), - sizeof(numInFlightPiece)); + uint32_t numInFlightPieceNL = htonl(_pieceStorage->countInFlightPiece()); + o.write(reinterpret_cast(&numInFlightPieceNL), + sizeof(numInFlightPieceNL)); Pieces inFlightPieces; _pieceStorage->getInFlightPieces(inFlightPieces); for(Pieces::const_iterator itr = inFlightPieces.begin(); itr != inFlightPieces.end(); ++itr) { - uint32_t index = (*itr)->getIndex(); - o.write(reinterpret_cast(&index), sizeof(index)); - uint32_t length = (*itr)->getLength(); - o.write(reinterpret_cast(&length), sizeof(length)); - uint32_t bitfieldLength = (*itr)->getBitfieldLength(); - o.write(reinterpret_cast(&bitfieldLength), - sizeof(bitfieldLength)); + uint32_t indexNL = htonl((*itr)->getIndex()); + o.write(reinterpret_cast(&indexNL), sizeof(indexNL)); + uint32_t lengthNL = htonl((*itr)->getLength()); + o.write(reinterpret_cast(&lengthNL), sizeof(lengthNL)); + uint32_t bitfieldLengthNL = htonl((*itr)->getBitfieldLength()); + o.write(reinterpret_cast(&bitfieldLengthNL), + sizeof(bitfieldLengthNL)); o.write(reinterpret_cast((*itr)->getBitfield()), - bitfieldLength); + (*itr)->getBitfieldLength()); } o.close(); @@ -179,6 +184,9 @@ void DefaultBtProgressInfoFile::save() { } } +// It is assumed that integers are saved as: +// 1) host byte order if version == 0000 +// 2) network byte order if version == 0001 void DefaultBtProgressInfoFile::load() { _logger->info(MSG_LOADING_SEGMENT_FILE, _filename.c_str()); @@ -187,13 +195,18 @@ void DefaultBtProgressInfoFile::load() unsigned char* savedBitfield = 0; try { in.exceptions(std::ios::failbit); - unsigned char version[2]; - in.read((char*)version, sizeof(version)); - if(DefaultBtProgressInfoFile::V0000 != - Util::toHex(version, sizeof(version))) { + unsigned char versionBuf[2]; + in.read((char*)versionBuf, sizeof(versionBuf)); + std::string versionHex = Util::toHex(versionBuf, sizeof(versionBuf)); + int version; + if(DefaultBtProgressInfoFile::V0000 == versionHex) { + version = 0; + } else if(DefaultBtProgressInfoFile::V0001 == versionHex) { + version = 1; + } else { throw DlAbortEx (StringFormat("Unsupported ctrl file version: %s", - Util::toHex(version, sizeof(version)).c_str()).str()); + versionHex.c_str()).str()); } unsigned char extension[4]; in.read((char*)extension, sizeof(extension)); @@ -206,6 +219,9 @@ void DefaultBtProgressInfoFile::load() uint32_t infoHashLength; in.read(reinterpret_cast(&infoHashLength), sizeof(infoHashLength)); + if(version >= 1) { + infoHashLength = ntohl(infoHashLength); + } if((infoHashLength < 0) || ((infoHashLength == 0) && infoHashCheckEnabled)) { throw DlAbortEx @@ -230,9 +246,15 @@ void DefaultBtProgressInfoFile::load() uint32_t pieceLength; in.read(reinterpret_cast(&pieceLength), sizeof(pieceLength)); + if(version >= 1) { + pieceLength = ntohl(pieceLength); + } uint64_t totalLength; in.read(reinterpret_cast(&totalLength), sizeof(totalLength)); + if(version >= 1) { + totalLength = ntoh64(totalLength); + } if(totalLength != _dctx->getTotalLength()) { throw DlAbortEx (StringFormat("total length mismatch. expected: %s, actual: %s", @@ -241,6 +263,9 @@ void DefaultBtProgressInfoFile::load() } uint64_t uploadLength; in.read(reinterpret_cast(&uploadLength), sizeof(uploadLength)); + if(version >= 1) { + uploadLength = ntoh64(uploadLength); + } if(isTorrentDownload()) { BT_RUNTIME(dynamic_pointer_cast(_dctx))-> setUploadLengthAtStartup(uploadLength); @@ -249,6 +274,9 @@ void DefaultBtProgressInfoFile::load() // TODO implement the conversion mechanism between different piece length. uint32_t bitfieldLength; in.read(reinterpret_cast(&bitfieldLength), sizeof(bitfieldLength)); + if(version >= 1) { + bitfieldLength = ntohl(bitfieldLength); + } uint32_t expectedBitfieldLength = ((totalLength+pieceLength-1)/pieceLength+7)/8; if(expectedBitfieldLength != bitfieldLength) { @@ -269,17 +297,25 @@ void DefaultBtProgressInfoFile::load() uint32_t numInFlightPiece; in.read(reinterpret_cast(&numInFlightPiece), sizeof(numInFlightPiece)); - + if(version >= 1) { + numInFlightPiece = ntohl(numInFlightPiece); + } Pieces inFlightPieces; while(numInFlightPiece--) { uint32_t index; in.read(reinterpret_cast(&index), sizeof(index)); + if(version >= 1) { + index = ntohl(index); + } if(!(index < _dctx->getNumPieces())) { throw DlAbortEx (StringFormat("piece index out of range: %u", index).str()); } uint32_t length; in.read(reinterpret_cast(&length), sizeof(length)); + if(version >= 1) { + length = ntohl(length); + } if(!(length <=_dctx->getPieceLength())) { throw DlAbortEx (StringFormat("piece length out of range: %u", length).str()); @@ -288,6 +324,9 @@ void DefaultBtProgressInfoFile::load() uint32_t bitfieldLength; in.read(reinterpret_cast(&bitfieldLength), sizeof(bitfieldLength)); + if(version >= 1) { + bitfieldLength = ntohl(bitfieldLength); + } if(piece->getBitfieldLength() != bitfieldLength) { throw DlAbortEx (StringFormat("piece bitfield length mismatch." @@ -314,6 +353,9 @@ void DefaultBtProgressInfoFile::load() uint32_t numInFlightPiece; in.read(reinterpret_cast(&numInFlightPiece), sizeof(numInFlightPiece)); + if(version >= 1) { + numInFlightPiece = ntohl(numInFlightPiece); + } BitfieldMan src(pieceLength, totalLength); src.setBitfield(savedBitfield, bitfieldLength); if((src.getCompletedLength() || numInFlightPiece) && diff --git a/src/DefaultBtProgressInfoFile.h b/src/DefaultBtProgressInfoFile.h index 3289017a..72757387 100644 --- a/src/DefaultBtProgressInfoFile.h +++ b/src/DefaultBtProgressInfoFile.h @@ -55,6 +55,7 @@ private: bool isTorrentDownload(); static const std::string V0000; + static const std::string V0001; public: DefaultBtProgressInfoFile(const SharedHandle& btContext, const SharedHandle& pieceStorage, diff --git a/test/DefaultBtProgressInfoFileTest.cc b/test/DefaultBtProgressInfoFileTest.cc index 94c9ece4..5a672fd1 100644 --- a/test/DefaultBtProgressInfoFileTest.cc +++ b/test/DefaultBtProgressInfoFileTest.cc @@ -24,9 +24,11 @@ class DefaultBtProgressInfoFileTest:public CppUnit::TestFixture { #ifdef ENABLE_BITTORRENT CPPUNIT_TEST(testSave); CPPUNIT_TEST(testLoad); + CPPUNIT_TEST(testLoad_compat); #endif // ENABLE_BITTORRENT CPPUNIT_TEST(testSave_nonBt); CPPUNIT_TEST(testLoad_nonBt); + CPPUNIT_TEST(testLoad_nonBt_compat); CPPUNIT_TEST(testLoad_nonBt_pieceLengthShorter); CPPUNIT_TEST(testUpdateFilename); CPPUNIT_TEST_SUITE_END(); @@ -85,8 +87,10 @@ public: void testSave(); void testLoad(); + void testLoad_compat(); void testSave_nonBt(); void testLoad_nonBt(); + void testLoad_nonBt_compat(); void testLoad_nonBt_pieceLengthShorter(); void testUpdateFilename(); }; @@ -98,7 +102,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(DefaultBtProgressInfoFileTest); #ifdef ENABLE_BITTORRENT -void DefaultBtProgressInfoFileTest::testLoad() +void DefaultBtProgressInfoFileTest::testLoad_compat() { initializeMembers(1024, 81920); @@ -114,6 +118,57 @@ void DefaultBtProgressInfoFileTest::testLoad() // check the contents of objects + // total length + CPPUNIT_ASSERT_EQUAL((uint64_t)81920, _btContext->getTotalLength()); + + // upload length + CPPUNIT_ASSERT_EQUAL((uint64_t)1024, BT_RUNTIME(_btContext)->getUploadLengthAtStartup()); + + // bitfield + CPPUNIT_ASSERT_EQUAL(std::string("fffffffffffffffffffe"), + Util::toHex(_bitfield->getBitfield(), _bitfield->getBitfieldLength())); + + // the number of in-flight pieces + CPPUNIT_ASSERT_EQUAL((size_t)2, + _pieceStorage->countInFlightPiece()); + + // piece index 1 + std::deque > inFlightPieces; + _pieceStorage->getInFlightPieces(inFlightPieces); + + SharedHandle piece1 = inFlightPieces[0]; + CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getIndex()); + CPPUNIT_ASSERT_EQUAL((size_t)1024, piece1->getLength()); + CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getBitfieldLength()); + CPPUNIT_ASSERT_EQUAL(std::string("00"), Util::toHex(piece1->getBitfield(), + piece1->getBitfieldLength())); + + // piece index 2 + SharedHandle piece2 = inFlightPieces[1]; + CPPUNIT_ASSERT_EQUAL((size_t)2, piece2->getIndex()); + CPPUNIT_ASSERT_EQUAL((size_t)512, piece2->getLength()); +} + +void DefaultBtProgressInfoFileTest::testLoad() +{ + initializeMembers(1024, 81920); + + _btContext->setName("load-v0001"); + _btContext->setPieceLength(1024); + _btContext->setTotalLength(81920); + _btContext->setNumPieces(80); + + DefaultBtProgressInfoFile infoFile(_btContext, _pieceStorage, _option.get()); + CPPUNIT_ASSERT_EQUAL(std::string("./load-v0001.aria2"), + infoFile.getFilename()); + + infoFile.load(); + + // check the contents of objects + + // total length + CPPUNIT_ASSERT_EQUAL((uint64_t)81920, _btContext->getTotalLength()); + // upload length CPPUNIT_ASSERT_EQUAL((uint64_t)1024, BT_RUNTIME(_btContext)->getUploadLengthAtStartup()); @@ -175,7 +230,8 @@ void DefaultBtProgressInfoFileTest::testSave() unsigned char version[2]; in.read((char*)version, sizeof(version)); - CPPUNIT_ASSERT_EQUAL(std::string("0000"), Util::toHex(version, sizeof(version))); + CPPUNIT_ASSERT_EQUAL(std::string("0001"), + Util::toHex(version, sizeof(version))); unsigned char extension[4]; in.read((char*)extension, sizeof(extension)); @@ -183,6 +239,7 @@ void DefaultBtProgressInfoFileTest::testSave() uint32_t infoHashLength; in.read(reinterpret_cast(&infoHashLength), sizeof(infoHashLength)); + infoHashLength = ntohl(infoHashLength); CPPUNIT_ASSERT_EQUAL((uint32_t)20, infoHashLength); unsigned char infoHashRead[20]; @@ -192,18 +249,22 @@ void DefaultBtProgressInfoFileTest::testSave() uint32_t pieceLength; in.read((char*)&pieceLength, sizeof(pieceLength)); + pieceLength = ntohl(pieceLength); CPPUNIT_ASSERT_EQUAL((uint32_t)1024, pieceLength); uint64_t totalLength; in.read((char*)&totalLength, sizeof(totalLength)); + totalLength = ntoh64(totalLength); CPPUNIT_ASSERT_EQUAL((uint64_t)81920/* 80*1024 */, totalLength); uint64_t uploadLength; in.read((char*)&uploadLength, sizeof(uploadLength)); + uploadLength = ntoh64(uploadLength); CPPUNIT_ASSERT_EQUAL((uint64_t)1024, uploadLength); uint32_t bitfieldLength; in.read((char*)&bitfieldLength, sizeof(bitfieldLength)); + bitfieldLength = ntohl(bitfieldLength); CPPUNIT_ASSERT_EQUAL((uint32_t)10, bitfieldLength); unsigned char bitfieldRead[10]; @@ -213,19 +274,23 @@ void DefaultBtProgressInfoFileTest::testSave() uint32_t numInFlightPiece; in.read((char*)&numInFlightPiece, sizeof(numInFlightPiece)); + numInFlightPiece = ntohl(numInFlightPiece); CPPUNIT_ASSERT_EQUAL((uint32_t)2, numInFlightPiece); // piece index 1 uint32_t index1; in.read((char*)&index1, sizeof(index1)); + index1 = ntohl(index1); CPPUNIT_ASSERT_EQUAL((uint32_t)1, index1); uint32_t pieceLength1; in.read((char*)&pieceLength1, sizeof(pieceLength1)); + pieceLength1 = ntohl(pieceLength1); CPPUNIT_ASSERT_EQUAL((uint32_t)1024, pieceLength1); uint32_t pieceBitfieldLength1; in.read((char*)&pieceBitfieldLength1, sizeof(pieceBitfieldLength1)); + pieceBitfieldLength1 = ntohl(pieceBitfieldLength1); CPPUNIT_ASSERT_EQUAL((uint32_t)1, pieceBitfieldLength1); unsigned char pieceBitfield1[1]; @@ -236,18 +301,18 @@ void DefaultBtProgressInfoFileTest::testSave() // piece index 2 uint32_t index2; in.read((char*)&index2, sizeof(index2)); + index2 = ntohl(index2); CPPUNIT_ASSERT_EQUAL((uint32_t)2, index2); uint32_t pieceLength2; in.read((char*)&pieceLength2, sizeof(pieceLength2)); + pieceLength2 = ntohl(pieceLength2); CPPUNIT_ASSERT_EQUAL((uint32_t)512, pieceLength2); - - } #endif // ENABLE_BITTORRENT -void DefaultBtProgressInfoFileTest::testLoad_nonBt() +void DefaultBtProgressInfoFileTest::testLoad_nonBt_compat() { initializeMembers(1024, 81920); @@ -260,6 +325,9 @@ void DefaultBtProgressInfoFileTest::testLoad_nonBt() // check the contents of objects + // total length + CPPUNIT_ASSERT_EQUAL((uint64_t)81920, dctx->getTotalLength()); + // bitfield CPPUNIT_ASSERT_EQUAL(std::string("fffffffffffffffffffe"), Util::toHex(_bitfield->getBitfield(), _bitfield->getBitfieldLength())); @@ -283,7 +351,48 @@ void DefaultBtProgressInfoFileTest::testLoad_nonBt() SharedHandle piece2 = inFlightPieces[1]; CPPUNIT_ASSERT_EQUAL((size_t)2, piece2->getIndex()); CPPUNIT_ASSERT_EQUAL((size_t)512, piece2->getLength()); +} +void DefaultBtProgressInfoFileTest::testLoad_nonBt() +{ + initializeMembers(1024, 81920); + + SharedHandle dctx + (new SingleFileDownloadContext(1024, 81920, "load-nonBt-v0001")); + + DefaultBtProgressInfoFile infoFile(dctx, _pieceStorage, _option.get()); + CPPUNIT_ASSERT_EQUAL(std::string("./load-nonBt-v0001.aria2"), + infoFile.getFilename()); + infoFile.load(); + + // check the contents of objects + + // total length + CPPUNIT_ASSERT_EQUAL((uint64_t)81920, dctx->getTotalLength()); + + // bitfield + CPPUNIT_ASSERT_EQUAL(std::string("fffffffffffffffffffe"), + Util::toHex(_bitfield->getBitfield(), _bitfield->getBitfieldLength())); + + // the number of in-flight pieces + CPPUNIT_ASSERT_EQUAL((size_t)2, + _pieceStorage->countInFlightPiece()); + + // piece index 1 + std::deque > inFlightPieces; + _pieceStorage->getInFlightPieces(inFlightPieces); + + SharedHandle piece1 = inFlightPieces[0]; + CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getIndex()); + CPPUNIT_ASSERT_EQUAL((size_t)1024, piece1->getLength()); + CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getBitfieldLength()); + CPPUNIT_ASSERT_EQUAL(std::string("00"), Util::toHex(piece1->getBitfield(), + piece1->getBitfieldLength())); + + // piece index 2 + SharedHandle piece2 = inFlightPieces[1]; + CPPUNIT_ASSERT_EQUAL((size_t)2, piece2->getIndex()); + CPPUNIT_ASSERT_EQUAL((size_t)512, piece2->getLength()); } void DefaultBtProgressInfoFileTest::testLoad_nonBt_pieceLengthShorter() @@ -292,10 +401,11 @@ void DefaultBtProgressInfoFileTest::testLoad_nonBt_pieceLengthShorter() _option->put(PREF_ALLOW_PIECE_LENGTH_CHANGE, V_TRUE); SharedHandle dctx - (new SingleFileDownloadContext(512, 81920, "load-nonBt")); + (new SingleFileDownloadContext(512, 81920, "load-nonBt-v0001")); DefaultBtProgressInfoFile infoFile(dctx, _pieceStorage, _option.get()); - CPPUNIT_ASSERT_EQUAL(std::string("./load-nonBt.aria2"), infoFile.getFilename()); + CPPUNIT_ASSERT_EQUAL(std::string("./load-nonBt-v0001.aria2"), + infoFile.getFilename()); infoFile.load(); // check the contents of objects @@ -339,7 +449,8 @@ void DefaultBtProgressInfoFileTest::testSave_nonBt() unsigned char version[2]; in.read((char*)version, sizeof(version)); - CPPUNIT_ASSERT_EQUAL(std::string("0000"), Util::toHex(version, sizeof(version))); + CPPUNIT_ASSERT_EQUAL(std::string("0001"), + Util::toHex(version, sizeof(version))); unsigned char extension[4]; in.read((char*)extension, sizeof(extension)); @@ -347,22 +458,27 @@ void DefaultBtProgressInfoFileTest::testSave_nonBt() uint32_t infoHashLength; in.read(reinterpret_cast(&infoHashLength), sizeof(infoHashLength)); + infoHashLength = ntohl(infoHashLength); CPPUNIT_ASSERT_EQUAL((uint32_t)0, infoHashLength); uint32_t pieceLength; in.read((char*)&pieceLength, sizeof(pieceLength)); + pieceLength = ntohl(pieceLength); CPPUNIT_ASSERT_EQUAL((uint32_t)1024, pieceLength); uint64_t totalLength; in.read((char*)&totalLength, sizeof(totalLength)); + totalLength = ntoh64(totalLength); CPPUNIT_ASSERT_EQUAL((uint64_t)81920/* 80*1024 */, totalLength); uint64_t uploadLength; in.read((char*)&uploadLength, sizeof(uploadLength)); + uploadLength = ntoh64(uploadLength); CPPUNIT_ASSERT_EQUAL((uint64_t)0, uploadLength); uint32_t bitfieldLength; in.read((char*)&bitfieldLength, sizeof(bitfieldLength)); + bitfieldLength = ntohl(bitfieldLength); CPPUNIT_ASSERT_EQUAL((uint32_t)10, bitfieldLength); unsigned char bitfieldRead[10]; @@ -372,19 +488,23 @@ void DefaultBtProgressInfoFileTest::testSave_nonBt() uint32_t numInFlightPiece; in.read((char*)&numInFlightPiece, sizeof(numInFlightPiece)); + numInFlightPiece = ntohl(numInFlightPiece); CPPUNIT_ASSERT_EQUAL((uint32_t)2, numInFlightPiece); // piece index 1 uint32_t index1; in.read((char*)&index1, sizeof(index1)); + index1 = ntohl(index1); CPPUNIT_ASSERT_EQUAL((uint32_t)1, index1); uint32_t pieceLength1; in.read((char*)&pieceLength1, sizeof(pieceLength1)); + pieceLength1 = ntohl(pieceLength1); CPPUNIT_ASSERT_EQUAL((uint32_t)1024, pieceLength1); uint32_t pieceBitfieldLength1; in.read((char*)&pieceBitfieldLength1, sizeof(pieceBitfieldLength1)); + pieceBitfieldLength1 = ntohl(pieceBitfieldLength1); CPPUNIT_ASSERT_EQUAL((uint32_t)1, pieceBitfieldLength1); unsigned char pieceBitfield1[1]; @@ -395,10 +515,12 @@ void DefaultBtProgressInfoFileTest::testSave_nonBt() // piece index 2 uint32_t index2; in.read((char*)&index2, sizeof(index2)); + index2 = ntohl(index2); CPPUNIT_ASSERT_EQUAL((uint32_t)2, index2); uint32_t pieceLength2; in.read((char*)&pieceLength2, sizeof(pieceLength2)); + pieceLength2 = ntohl(pieceLength2); CPPUNIT_ASSERT_EQUAL((uint32_t)512, pieceLength2); } diff --git a/test/load-nonBt-v0001.aria2 b/test/load-nonBt-v0001.aria2 new file mode 100644 index 0000000000000000000000000000000000000000..6a222a904267747554617968b063b86a2d80de25 GIT binary patch literal 74 ocmZQzWPk$}2#e7HE&^n5{fB{nKpqni19gB^f^`A~Kw>~a0CPDCQvd(} literal 0 HcmV?d00001 diff --git a/test/load-v0001.aria2 b/test/load-v0001.aria2 new file mode 100644 index 0000000000000000000000000000000000000000..d7057c7ab136d633d6eb3af1fd91db39e1ee4e3c GIT binary patch literal 94 zcmZQzWME(bVG%(kW0%mh@{XCScAvTX?mxqSAYfo%0ZIV@qXU?N^0`2AVDJwp%mk8$ N%79D)34p|af&kY!7GMAX literal 0 HcmV?d00001