summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-03-07 12:44:20 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-03-07 12:44:20 +0000
commite57a070a3fe1d5125fa61667982b9da062eb59de (patch)
treeee3d814d0cf339164ec8e2c9d7fa2066bc7bd716 /src
parentfc0fa4203a0295e69f5101838dded603fc48b9e4 (diff)
2008-03-07 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Removed subPiece related functions. * src/Piece.{h, cc} : Also rewritten getCompletedLength(). * src/DefaultPieceStorage.{h, cc} * test/PieceTest.cc * test/DefaultPieceStorageTest.cc
Diffstat (limited to 'src')
-rw-r--r--src/DefaultPieceStorage.cc30
-rw-r--r--src/DefaultPieceStorage.h1
-rw-r--r--src/Piece.cc91
-rw-r--r--src/Piece.h15
4 files changed, 2 insertions, 135 deletions
diff --git a/src/DefaultPieceStorage.cc b/src/DefaultPieceStorage.cc
index 39f34382..28884d2f 100644
--- a/src/DefaultPieceStorage.cc
+++ b/src/DefaultPieceStorage.cc
@@ -204,36 +204,6 @@ PieceHandle DefaultPieceStorage::getMissingPiece()
return checkOutPiece(bitfieldMan->getSparseMissingUnusedIndex());
}
-PieceHandle DefaultPieceStorage::getMissingPiece(const FileEntryHandle& fileEntry)
-{
- BitfieldMan temp(*bitfieldMan);
- temp.clearFilter();
- temp.addFilter(fileEntry->getOffset(), fileEntry->getLength());
- temp.enableFilter();
-
- int32_t firstPieceIndex = START_INDEX(fileEntry->getOffset(), downloadContext->getPieceLength());
- int32_t endPieceIndex = END_INDEX(fileEntry->getOffset(), fileEntry->getLength(), downloadContext->getPieceLength());
- if(!temp.isBitSet(firstPieceIndex) && !temp.isUseBitSet(firstPieceIndex)) {
- PieceHandle piece = findUsedPiece(firstPieceIndex);
- if(!piece.isNull()) {
- if(piece->isRangeComplete(fileEntry->getOffset()-firstPieceIndex*downloadContext->getPieceLength(),
- fileEntry->getLength() > downloadContext->getPieceLength() ?
- downloadContext->getPieceLength():fileEntry->getLength())) {
- temp.setBit(firstPieceIndex);
- }
- }
- }
- if(firstPieceIndex != endPieceIndex && !temp.isBitSet(endPieceIndex) && !temp.isUseBitSet(endPieceIndex)) {
- PieceHandle piece = findUsedPiece(endPieceIndex);
- if(!piece.isNull()) {
- if(piece->isRangeComplete(0, fileEntry->getOffset()+fileEntry->getLength()-endPieceIndex*downloadContext->getPieceLength())) {
- temp.setBit(endPieceIndex);
- }
- }
- }
- return checkOutPiece(temp.getSparseMissingUnusedIndex());
-}
-
PieceHandle DefaultPieceStorage::getMissingPiece(int32_t index)
{
if(hasPiece(index) || isPieceUsed(index)) {
diff --git a/src/DefaultPieceStorage.h b/src/DefaultPieceStorage.h
index 0f14505d..0d354c74 100644
--- a/src/DefaultPieceStorage.h
+++ b/src/DefaultPieceStorage.h
@@ -100,7 +100,6 @@ public:
virtual SharedHandle<Piece> getMissingFastPiece(const SharedHandle<Peer>& peer);
virtual SharedHandle<Piece> getMissingPiece();
- virtual SharedHandle<Piece> getMissingPiece(const SharedHandle<FileEntry>& fileEntry);
virtual SharedHandle<Piece> getMissingPiece(int32_t index);
diff --git a/src/Piece.cc b/src/Piece.cc
index 837bf11d..dcb28d8f 100644
--- a/src/Piece.cc
+++ b/src/Piece.cc
@@ -85,7 +85,6 @@ bool Piece::operator==(const Piece& piece) const
void Piece::completeBlock(int32_t blockIndex) {
bitfield->setBit(blockIndex);
bitfield->unsetUseBit(blockIndex);
- removeSubPiece(blockIndex);
}
void Piece::clearAllBlock() {
@@ -189,97 +188,9 @@ void Piece::setBitfield(const unsigned char* bitfield, int32_t len)
this->bitfield->setBitfield(bitfield, len);
}
-void Piece::addSubPiece(const PieceHandle& subPiece)
-{
- _subPieces.push_back(subPiece);
-}
-
-PieceHandle Piece::getSubPiece(int32_t blockIndex)
-{
- Pieces::iterator itr = getSubPieceIterator(blockIndex);
- if(itr == _subPieces.end()) {
- return 0;
- } else {
- return *itr;
- }
-}
-
-void Piece::removeSubPiece(int32_t blockIndex)
-{
- Pieces::iterator itr = getSubPieceIterator(blockIndex);
- if(itr != _subPieces.end()) {
- _subPieces.erase(itr);
- }
-}
-
-Pieces::iterator Piece::getSubPieceIterator(int32_t blockIndex)
-{
- for(Pieces::iterator itr = _subPieces.begin(); itr != _subPieces.end(); ++itr) {
- if((*itr)->getIndex() == blockIndex) {
- return itr;
- }
- }
- return _subPieces.end();
-}
-
-bool Piece::isRangeComplete(int32_t offset, int32_t length)
-{
- int32_t startIndex = START_INDEX(offset, _blockLength);
- int32_t endIndex = END_INDEX(offset, length, _blockLength);
- if(countBlock() <= endIndex) {
- endIndex = countBlock()-1;
- }
- if(startIndex+1 < endIndex) {
- if(!bitfield->isBitRangeSet(startIndex+1, endIndex-1)) {
- return false;
- }
- }
- if(startIndex == endIndex) {
- if(hasBlock(startIndex)) {
- return true;
- }
- PieceHandle subPiece = getSubPiece(startIndex);
- if(subPiece.isNull()) {
- return false;
- }
- return subPiece->isRangeComplete(offset, length);
- } else {
- if(!hasBlock(startIndex)) {
- PieceHandle subPiece = getSubPiece(startIndex);
- if(subPiece.isNull()) {
- return false;
- }
- if(!subPiece->isRangeComplete(offset-startIndex*_blockLength, length)) {
- return false;
- }
- }
- if(!hasBlock(endIndex)) {
- PieceHandle subPiece = getSubPiece(endIndex);
- if(subPiece.isNull()) {
- return false;
- }
- if(!subPiece->isRangeComplete(0, offset+length-endIndex*_blockLength)) {
- return false;
- }
- }
- return true;
- }
-}
-
int32_t Piece::getCompletedLength()
{
- int32_t length = 0;
- for(int32_t i = 0; i < countBlock(); ++i) {
- if(hasBlock(i)) {
- length += getBlockLength(i);
- } else {
- PieceHandle subPiece = getSubPiece(i);
- if(!subPiece.isNull()) {
- length += subPiece->getCompletedLength();
- }
- }
- }
- return length;
+ return bitfield->getCompletedLength();
}
} // namespace aria2
diff --git a/src/Piece.h b/src/Piece.h
index 1b1c5c1e..8c21f948 100644
--- a/src/Piece.h
+++ b/src/Piece.h
@@ -51,8 +51,6 @@ private:
int32_t length;
int32_t _blockLength;
BitfieldMan* bitfield;
-
- std::deque<SharedHandle<Piece> > _subPieces;
public:
static const int32_t BLOCK_LENGTH = 16*1024;
@@ -113,18 +111,7 @@ public:
bool isBlockUsed(int32_t index) const;
- void addSubPiece(const SharedHandle<Piece>& subPiece);
-
- SharedHandle<Piece> getSubPiece(int32_t blockIndex);
-
- void removeSubPiece(int32_t blockIndex);
-
- std::deque<SharedHandle<Piece> >::iterator
- getSubPieceIterator(int32_t blockIndex);
-
- bool isRangeComplete(int32_t offset, int32_t length);
-
- // Calculates completed length, taking into account SubPieces
+ // Calculates completed length
int32_t getCompletedLength();
/**