DefaultPieceStorage.cc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - The high speed download utility
  4. *
  5. * Copyright (C) 2006 Tatsuhiro Tsujikawa
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * In addition, as a special exception, the copyright holders give
  22. * permission to link the code of portions of this program with the
  23. * OpenSSL library under certain conditions as described in each
  24. * individual source file, and distribute linked combinations
  25. * including the two.
  26. * You must obey the GNU General Public License in all respects
  27. * for all of the code used other than OpenSSL. If you modify
  28. * file(s) with this exception, you may extend this exception to your
  29. * version of the file(s), but you are not obligated to do so. If you
  30. * do not wish to do so, delete this exception statement from your
  31. * version. If you delete this exception statement from all source
  32. * files in the program, then also delete it here.
  33. */
  34. /* copyright --> */
  35. #include "DefaultPieceStorage.h"
  36. #include "DownloadContext.h"
  37. #include "Piece.h"
  38. #include "Peer.h"
  39. #include "LogFactory.h"
  40. #include "Logger.h"
  41. #include "prefs.h"
  42. #include "DirectDiskAdaptor.h"
  43. #include "MultiDiskAdaptor.h"
  44. #include "CopyDiskAdaptor.h"
  45. #include "DiskWriter.h"
  46. #include "BitfieldManFactory.h"
  47. #include "BitfieldMan.h"
  48. #include "message.h"
  49. #include "DefaultDiskWriterFactory.h"
  50. #include "FileEntry.h"
  51. #include "DlAbortEx.h"
  52. #include "Util.h"
  53. #include "a2functional.h"
  54. #include "Option.h"
  55. #include "StringFormat.h"
  56. #include "RarestPieceSelector.h"
  57. #include <numeric>
  58. #include <algorithm>
  59. namespace aria2 {
  60. DefaultPieceStorage::DefaultPieceStorage(const DownloadContextHandle& downloadContext, const Option* option, bool randomPieceStatsOrdering):
  61. downloadContext(downloadContext),
  62. bitfieldMan(BitfieldManFactory::getFactoryInstance()->
  63. createBitfieldMan(downloadContext->getPieceLength(),
  64. downloadContext->getTotalLength())),
  65. _diskWriterFactory(new DefaultDiskWriterFactory()),
  66. endGamePieceNum(END_GAME_PIECE_NUM),
  67. logger(LogFactory::getInstance()),
  68. option(option),
  69. _pieceSelector(new RarestPieceSelector(downloadContext->getNumPieces(),
  70. randomPieceStatsOrdering))
  71. {}
  72. DefaultPieceStorage::~DefaultPieceStorage() {
  73. delete bitfieldMan;
  74. }
  75. bool DefaultPieceStorage::hasMissingPiece(const PeerHandle& peer)
  76. {
  77. return bitfieldMan->hasMissingPiece(peer->getBitfield(),
  78. peer->getBitfieldLength());
  79. }
  80. bool DefaultPieceStorage::isEndGame()
  81. {
  82. return bitfieldMan->countMissingBlock() <= endGamePieceNum;
  83. }
  84. bool DefaultPieceStorage::getMissingPieceIndex(size_t& index, const PeerHandle& peer)
  85. {
  86. std::deque<size_t> indexes;
  87. bool r;
  88. if(isEndGame()) {
  89. r = bitfieldMan->getAllMissingIndexes(indexes, peer->getBitfield(),
  90. peer->getBitfieldLength());
  91. } else {
  92. r = bitfieldMan->getAllMissingUnusedIndexes(indexes,
  93. peer->getBitfield(),
  94. peer->getBitfieldLength());
  95. }
  96. if(r) {
  97. // We assume indexes is sorted using comparator less.
  98. _pieceSelector->select(index, indexes);
  99. return true;
  100. } else {
  101. return false;
  102. }
  103. }
  104. PieceHandle DefaultPieceStorage::checkOutPiece(size_t index)
  105. {
  106. bitfieldMan->setUseBit(index);
  107. PieceHandle piece = findUsedPiece(index);
  108. if(piece.isNull()) {
  109. piece.reset(new Piece(index, bitfieldMan->getBlockLength(index)));
  110. #ifdef ENABLE_MESSAGE_DIGEST
  111. piece->setHashAlgo(downloadContext->getPieceHashAlgo());
  112. #endif // ENABLE_MESSAGE_DIGEST
  113. addUsedPiece(piece);
  114. return piece;
  115. } else {
  116. return piece;
  117. }
  118. }
  119. /**
  120. * Newly instantiated piece is not added to usedPieces.
  121. * Because it is waste of memory and there is no chance to use them later.
  122. */
  123. PieceHandle DefaultPieceStorage::getPiece(size_t index)
  124. {
  125. PieceHandle piece;
  126. if(0 <= index && index <= bitfieldMan->getMaxIndex()) {
  127. piece = findUsedPiece(index);
  128. if(piece.isNull()) {
  129. piece.reset(new Piece(index, bitfieldMan->getBlockLength(index)));
  130. if(hasPiece(index)) {
  131. piece->setAllBlock();
  132. }
  133. }
  134. }
  135. return piece;
  136. }
  137. void DefaultPieceStorage::addUsedPiece(const PieceHandle& piece)
  138. {
  139. std::deque<SharedHandle<Piece> >::iterator i =
  140. std::lower_bound(usedPieces.begin(), usedPieces.end(), piece);
  141. usedPieces.insert(i, piece);
  142. logger->debug("usedPieces.size()=%zu", usedPieces.size());
  143. }
  144. PieceHandle DefaultPieceStorage::findUsedPiece(size_t index) const
  145. {
  146. SharedHandle<Piece> p(new Piece());
  147. p->setIndex(index);
  148. std::deque<SharedHandle<Piece> >::const_iterator i =
  149. std::lower_bound(usedPieces.begin(), usedPieces.end(), p);
  150. if(i != usedPieces.end() && (*i) == p) {
  151. return *i;
  152. } else {
  153. p.reset(0);
  154. return p;
  155. }
  156. }
  157. PieceHandle DefaultPieceStorage::getMissingPiece(const PeerHandle& peer)
  158. {
  159. size_t index;
  160. if(getMissingPieceIndex(index, peer)) {
  161. return checkOutPiece(index);
  162. } else {
  163. return SharedHandle<Piece>();
  164. }
  165. }
  166. bool DefaultPieceStorage::getMissingFastPieceIndex(size_t& index,
  167. const PeerHandle& peer)
  168. {
  169. if(peer->isFastExtensionEnabled() && peer->countPeerAllowedIndexSet() > 0) {
  170. BitfieldMan tempBitfield(bitfieldMan->getBlockLength(),
  171. bitfieldMan->getTotalLength());
  172. for(std::deque<size_t>::const_iterator itr = peer->getPeerAllowedIndexSet().begin();
  173. itr != peer->getPeerAllowedIndexSet().end(); itr++) {
  174. if(!bitfieldMan->isBitSet(*itr) && peer->hasPiece(*itr)) {
  175. tempBitfield.setBit(*itr);
  176. }
  177. }
  178. if(isEndGame()) {
  179. return bitfieldMan->getMissingIndex(index, tempBitfield.getBitfield(),
  180. tempBitfield.getBitfieldLength());
  181. } else {
  182. return bitfieldMan->getMissingUnusedIndex(index,
  183. tempBitfield.getBitfield(),
  184. tempBitfield.getBitfieldLength());
  185. }
  186. }
  187. return false;
  188. }
  189. PieceHandle DefaultPieceStorage::getMissingFastPiece(const PeerHandle& peer)
  190. {
  191. size_t index;
  192. if(getMissingFastPieceIndex(index, peer)) {
  193. return checkOutPiece(index);
  194. } else {
  195. return SharedHandle<Piece>();
  196. }
  197. }
  198. PieceHandle DefaultPieceStorage::getMissingPiece()
  199. {
  200. size_t index;
  201. if(bitfieldMan->getSparseMissingUnusedIndex(index)) {
  202. return checkOutPiece(index);
  203. } else {
  204. return SharedHandle<Piece>();
  205. }
  206. }
  207. PieceHandle DefaultPieceStorage::getMissingPiece(size_t index)
  208. {
  209. if(hasPiece(index) || isPieceUsed(index)) {
  210. return SharedHandle<Piece>();
  211. } else {
  212. return checkOutPiece(index);
  213. }
  214. }
  215. void DefaultPieceStorage::deleteUsedPiece(const PieceHandle& piece)
  216. {
  217. if(piece.isNull()) {
  218. return;
  219. }
  220. std::deque<SharedHandle<Piece> >::iterator i =
  221. std::lower_bound(usedPieces.begin(), usedPieces.end(), piece);
  222. if(i != usedPieces.end() && (*i) == piece) {
  223. usedPieces.erase(i);
  224. }
  225. }
  226. // void DefaultPieceStorage::reduceUsedPieces(size_t upperBound)
  227. // {
  228. // size_t usedPiecesSize = usedPieces.size();
  229. // if(usedPiecesSize <= upperBound) {
  230. // return;
  231. // }
  232. // size_t delNum = usedPiecesSize-upperBound;
  233. // int fillRate = 10;
  234. // while(delNum && fillRate <= 15) {
  235. // delNum -= deleteUsedPiecesByFillRate(fillRate, delNum);
  236. // fillRate += 5;
  237. // }
  238. // }
  239. // size_t DefaultPieceStorage::deleteUsedPiecesByFillRate(int fillRate,
  240. // size_t delNum)
  241. // {
  242. // size_t deleted = 0;
  243. // for(Pieces::iterator itr = usedPieces.begin();
  244. // itr != usedPieces.end() && deleted < delNum;) {
  245. // PieceHandle& piece = *itr;
  246. // if(!bitfieldMan->isUseBitSet(piece->getIndex()) &&
  247. // piece->countCompleteBlock() <= piece->countBlock()*(fillRate/100.0)) {
  248. // logger->info(MSG_DELETING_USED_PIECE,
  249. // piece->getIndex(),
  250. // (piece->countCompleteBlock()*100)/piece->countBlock(),
  251. // fillRate);
  252. // itr = usedPieces.erase(itr);
  253. // ++deleted;
  254. // } else {
  255. // ++itr;
  256. // }
  257. // }
  258. // return deleted;
  259. // }
  260. void DefaultPieceStorage::completePiece(const PieceHandle& piece)
  261. {
  262. if(piece.isNull()) {
  263. return;
  264. }
  265. deleteUsedPiece(piece);
  266. // if(!isEndGame()) {
  267. // reduceUsedPieces(100);
  268. // }
  269. if(allDownloadFinished()) {
  270. return;
  271. }
  272. bitfieldMan->setBit(piece->getIndex());
  273. bitfieldMan->unsetUseBit(piece->getIndex());
  274. addPieceStats(piece->getIndex());
  275. if(downloadFinished()) {
  276. diskAdaptor->onDownloadComplete();
  277. if(isSelectiveDownloadingMode()) {
  278. logger->notice(MSG_SELECTIVE_DOWNLOAD_COMPLETED);
  279. // following line was commented out in order to stop sending request
  280. // message after user-specified files were downloaded.
  281. //finishSelectiveDownloadingMode();
  282. } else {
  283. logger->info(MSG_DOWNLOAD_COMPLETED);
  284. }
  285. }
  286. }
  287. bool DefaultPieceStorage::isSelectiveDownloadingMode()
  288. {
  289. return bitfieldMan->isFilterEnabled();
  290. }
  291. void DefaultPieceStorage::finishSelectiveDownloadingMode()
  292. {
  293. bitfieldMan->clearFilter();
  294. diskAdaptor->addAllDownloadEntry();
  295. }
  296. // not unittested
  297. void DefaultPieceStorage::cancelPiece(const PieceHandle& piece)
  298. {
  299. if(piece.isNull()) {
  300. return;
  301. }
  302. bitfieldMan->unsetUseBit(piece->getIndex());
  303. if(!isEndGame()) {
  304. if(piece->getCompletedLength() == 0) {
  305. deleteUsedPiece(piece);
  306. }
  307. }
  308. }
  309. bool DefaultPieceStorage::hasPiece(size_t index)
  310. {
  311. return bitfieldMan->isBitSet(index);
  312. }
  313. bool DefaultPieceStorage::isPieceUsed(size_t index)
  314. {
  315. return bitfieldMan->isUseBitSet(index);
  316. }
  317. uint64_t DefaultPieceStorage::getTotalLength()
  318. {
  319. return bitfieldMan->getTotalLength();
  320. }
  321. uint64_t DefaultPieceStorage::getFilteredTotalLength()
  322. {
  323. return bitfieldMan->getFilteredTotalLength();
  324. }
  325. uint64_t DefaultPieceStorage::getCompletedLength()
  326. {
  327. return bitfieldMan->getCompletedLength()+getInFlightPieceCompletedLength();
  328. }
  329. uint64_t DefaultPieceStorage::getFilteredCompletedLength()
  330. {
  331. return bitfieldMan->getFilteredCompletedLength()+getInFlightPieceCompletedLength();
  332. }
  333. size_t DefaultPieceStorage::getInFlightPieceCompletedLength() const
  334. {
  335. return std::accumulate(usedPieces.begin(), usedPieces.end(), 0, adopt2nd(std::plus<size_t>(), mem_fun_sh(&Piece::getCompletedLength)));
  336. }
  337. // not unittested
  338. void DefaultPieceStorage::setFileFilter(const std::deque<std::string>& filePaths)
  339. {
  340. if(downloadContext->getFileMode() != DownloadContext::MULTI || filePaths.empty()) {
  341. return;
  342. }
  343. diskAdaptor->removeAllDownloadEntry();
  344. for(std::deque<std::string>::const_iterator pitr = filePaths.begin();
  345. pitr != filePaths.end(); pitr++) {
  346. if(!diskAdaptor->addDownloadEntry(*pitr)) {
  347. throw DlAbortEx(StringFormat(EX_NO_SUCH_FILE_ENTRY, (*pitr).c_str()).str());
  348. }
  349. FileEntryHandle fileEntry = diskAdaptor->getFileEntryFromPath(*pitr);
  350. bitfieldMan->addFilter(fileEntry->getOffset(), fileEntry->getLength());
  351. }
  352. bitfieldMan->enableFilter();
  353. }
  354. void DefaultPieceStorage::setFileFilter(IntSequence seq)
  355. {
  356. std::deque<int32_t> fileIndexes = seq.flush();
  357. // TODO Is sorting necessary?
  358. std::sort(fileIndexes.begin(), fileIndexes.end());
  359. fileIndexes.erase(std::unique(fileIndexes.begin(), fileIndexes.end()), fileIndexes.end());
  360. std::deque<std::string> filePaths;
  361. const FileEntries& entries = diskAdaptor->getFileEntries();
  362. for(size_t i = 0; i < entries.size(); i++) {
  363. if(std::find(fileIndexes.begin(), fileIndexes.end(), i+1) != fileIndexes.end()) {
  364. logger->debug("index=%d is %s", i+1, entries[i]->getPath().c_str());
  365. filePaths.push_back(entries[i]->getPath());
  366. }
  367. }
  368. setFileFilter(filePaths);
  369. }
  370. // not unittested
  371. void DefaultPieceStorage::clearFileFilter()
  372. {
  373. bitfieldMan->clearFilter();
  374. diskAdaptor->addAllDownloadEntry();
  375. }
  376. // not unittested
  377. bool DefaultPieceStorage::downloadFinished()
  378. {
  379. // TODO iterate all requested FileEntry and Call bitfieldMan->isBitSetOffsetRange()
  380. return bitfieldMan->isFilteredAllBitSet();
  381. }
  382. // not unittested
  383. bool DefaultPieceStorage::allDownloadFinished()
  384. {
  385. return bitfieldMan->isAllBitSet();
  386. }
  387. // not unittested
  388. void DefaultPieceStorage::initStorage()
  389. {
  390. if(downloadContext->getFileMode() == DownloadContext::SINGLE) {
  391. logger->debug("Instantiating DirectDiskAdaptor");
  392. DiskWriterHandle writer = _diskWriterFactory->newDiskWriter();
  393. writer->setDirectIOAllowed(option->getAsBool(PREF_ENABLE_DIRECT_IO));
  394. DirectDiskAdaptorHandle directDiskAdaptor(new DirectDiskAdaptor());
  395. directDiskAdaptor->setDiskWriter(writer);
  396. directDiskAdaptor->setTotalLength(downloadContext->getTotalLength());
  397. this->diskAdaptor = directDiskAdaptor;
  398. } else {
  399. // file mode == DownloadContext::MULTI
  400. if(option->getAsBool(PREF_DIRECT_FILE_MAPPING)) {
  401. logger->debug("Instantiating MultiDiskAdaptor");
  402. MultiDiskAdaptorHandle multiDiskAdaptor(new MultiDiskAdaptor());
  403. multiDiskAdaptor->setDirectIOAllowed(option->getAsBool(PREF_ENABLE_DIRECT_IO));
  404. multiDiskAdaptor->setPieceLength(downloadContext->getPieceLength());
  405. multiDiskAdaptor->setTopDir(downloadContext->getName());
  406. multiDiskAdaptor->setMaxOpenFiles(option->getAsInt(PREF_BT_MAX_OPEN_FILES));
  407. this->diskAdaptor = multiDiskAdaptor;
  408. } else {
  409. logger->debug("Instantiating CopyDiskAdaptor");
  410. DiskWriterHandle writer = _diskWriterFactory->newDiskWriter();
  411. writer->setDirectIOAllowed(option->getAsBool(PREF_ENABLE_DIRECT_IO));
  412. CopyDiskAdaptorHandle copyDiskAdaptor(new CopyDiskAdaptor());
  413. copyDiskAdaptor->setDiskWriter(writer);
  414. copyDiskAdaptor->setTempFilename(downloadContext->getName()+".a2tmp");
  415. copyDiskAdaptor->setTotalLength(downloadContext->getTotalLength());
  416. copyDiskAdaptor->setTopDir(downloadContext->getName());
  417. this->diskAdaptor = copyDiskAdaptor;
  418. }
  419. }
  420. diskAdaptor->setStoreDir(downloadContext->getDir());
  421. diskAdaptor->setFileEntries(downloadContext->getFileEntries());
  422. }
  423. void DefaultPieceStorage::setBitfield(const unsigned char* bitfield,
  424. size_t bitfieldLength)
  425. {
  426. bitfieldMan->setBitfield(bitfield, bitfieldLength);
  427. addPieceStats(bitfield, bitfieldLength);
  428. }
  429. size_t DefaultPieceStorage::getBitfieldLength()
  430. {
  431. return bitfieldMan->getBitfieldLength();
  432. }
  433. const unsigned char* DefaultPieceStorage::getBitfield()
  434. {
  435. return bitfieldMan->getBitfield();
  436. }
  437. DiskAdaptorHandle DefaultPieceStorage::getDiskAdaptor() {
  438. return diskAdaptor;
  439. }
  440. size_t DefaultPieceStorage::getPieceLength(size_t index)
  441. {
  442. return bitfieldMan->getBlockLength(index);
  443. }
  444. void DefaultPieceStorage::advertisePiece(int32_t cuid, size_t index)
  445. {
  446. HaveEntry entry(cuid, index);
  447. haves.push_front(entry);
  448. }
  449. void
  450. DefaultPieceStorage::getAdvertisedPieceIndexes(std::deque<size_t>& indexes,
  451. int32_t myCuid,
  452. const Time& lastCheckTime)
  453. {
  454. for(Haves::const_iterator itr = haves.begin(); itr != haves.end(); itr++) {
  455. const Haves::value_type& have = *itr;
  456. if(have.getCuid() == myCuid) {
  457. continue;
  458. }
  459. if(lastCheckTime.isNewer(have.getRegisteredTime())) {
  460. break;
  461. }
  462. indexes.push_back(have.getIndex());
  463. }
  464. }
  465. class FindElapsedHave
  466. {
  467. private:
  468. time_t elapsed;
  469. public:
  470. FindElapsedHave(time_t elapsed):elapsed(elapsed) {}
  471. bool operator()(const HaveEntry& have) {
  472. if(have.getRegisteredTime().elapsed(elapsed)) {
  473. return true;
  474. } else {
  475. return false;
  476. }
  477. }
  478. };
  479. void DefaultPieceStorage::removeAdvertisedPiece(time_t elapsed)
  480. {
  481. Haves::iterator itr =
  482. std::find_if(haves.begin(), haves.end(), FindElapsedHave(elapsed));
  483. if(itr != haves.end()) {
  484. logger->debug(MSG_REMOVED_HAVE_ENTRY, haves.end()-itr);
  485. haves.erase(itr, haves.end());
  486. }
  487. }
  488. void DefaultPieceStorage::markAllPiecesDone()
  489. {
  490. bitfieldMan->setAllBit();
  491. }
  492. void DefaultPieceStorage::markPiecesDone(uint64_t length)
  493. {
  494. if(length == bitfieldMan->getTotalLength()) {
  495. bitfieldMan->setAllBit();
  496. } else {
  497. size_t numPiece = length/bitfieldMan->getBlockLength();
  498. if(numPiece > 0) {
  499. bitfieldMan->setBitRange(0, numPiece-1);
  500. }
  501. size_t r = (length%bitfieldMan->getBlockLength())/Piece::BLOCK_LENGTH;
  502. if(r > 0) {
  503. PieceHandle p(new Piece(numPiece, bitfieldMan->getBlockLength(numPiece)));
  504. for(size_t i = 0; i < r; ++i) {
  505. p->completeBlock(i);
  506. }
  507. #ifdef ENABLE_MESSAGE_DIGEST
  508. p->setHashAlgo(downloadContext->getPieceHashAlgo());
  509. #endif // ENABLE_MESSAGE_DIGEST
  510. addUsedPiece(p);
  511. }
  512. }
  513. }
  514. void DefaultPieceStorage::markPieceMissing(size_t index)
  515. {
  516. bitfieldMan->unsetBit(index);
  517. }
  518. void DefaultPieceStorage::addInFlightPiece(const Pieces& pieces)
  519. {
  520. usedPieces.insert(usedPieces.end(), pieces.begin(), pieces.end());
  521. std::sort(usedPieces.begin(), usedPieces.end());
  522. }
  523. size_t DefaultPieceStorage::countInFlightPiece()
  524. {
  525. return usedPieces.size();
  526. }
  527. void DefaultPieceStorage::getInFlightPieces(std::deque<SharedHandle<Piece> >& pieces)
  528. {
  529. pieces.insert(pieces.end(), usedPieces.begin(), usedPieces.end());
  530. }
  531. void DefaultPieceStorage::setDiskWriterFactory(const DiskWriterFactoryHandle& diskWriterFactory)
  532. {
  533. _diskWriterFactory = diskWriterFactory;
  534. }
  535. void DefaultPieceStorage::addPieceStats(const unsigned char* bitfield,
  536. size_t bitfieldLength)
  537. {
  538. _pieceSelector->addPieceStats(bitfield, bitfieldLength);
  539. }
  540. void DefaultPieceStorage::subtractPieceStats(const unsigned char* bitfield,
  541. size_t bitfieldLength)
  542. {
  543. _pieceSelector->subtractPieceStats(bitfield, bitfieldLength);
  544. }
  545. void DefaultPieceStorage::updatePieceStats(const unsigned char* newBitfield,
  546. size_t newBitfieldLength,
  547. const unsigned char* oldBitfield)
  548. {
  549. _pieceSelector->updatePieceStats(newBitfield, newBitfieldLength,
  550. oldBitfield);
  551. }
  552. void DefaultPieceStorage::addPieceStats(size_t index)
  553. {
  554. _pieceSelector->addPieceStats(index);
  555. }
  556. } // namespace aria2