diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2011-06-11 17:34:17 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2011-06-11 17:34:17 +0900 |
| commit | cc82da3babdab3040d6e16624b5aefcd97138925 (patch) | |
| tree | 708a19e8a19d303db3eb9602e4475537f6e5ba78 /src | |
| parent | 533cdfa850b3bc29bf7ce49bf83ba6225fefc7f2 (diff) | |
Added StreamPieceSelector class.
This class abstracts the piece selection algorithm for HTTP/FTP
download.
Diffstat (limited to 'src')
| -rw-r--r-- | src/DefaultPieceStorage.cc | 8 | ||||
| -rw-r--r-- | src/DefaultPieceStorage.h | 5 | ||||
| -rw-r--r-- | src/DefaultStreamPieceSelector.cc | 57 | ||||
| -rw-r--r-- | src/DefaultStreamPieceSelector.h | 60 | ||||
| -rw-r--r-- | src/Makefile.am | 4 | ||||
| -rw-r--r-- | src/PieceStorage.h | 2 | ||||
| -rw-r--r-- | src/SegmentMan.cc | 4 | ||||
| -rw-r--r-- | src/StreamPieceSelector.h | 67 | ||||
| -rw-r--r-- | src/UnknownLengthPieceStorage.cc | 4 | ||||
| -rw-r--r-- | src/UnknownLengthPieceStorage.h | 2 |
10 files changed, 201 insertions, 12 deletions
diff --git a/src/DefaultPieceStorage.cc b/src/DefaultPieceStorage.cc index 4472d99b..0696f30c 100644 --- a/src/DefaultPieceStorage.cc +++ b/src/DefaultPieceStorage.cc @@ -56,6 +56,7 @@ #include "Option.h" #include "fmt.h" #include "RarestPieceSelector.h" +#include "DefaultStreamPieceSelector.h" #include "array_fun.h" #include "PieceStatMan.h" #include "wallclock.h" @@ -76,7 +77,8 @@ DefaultPieceStorage::DefaultPieceStorage endGamePieceNum_(END_GAME_PIECE_NUM), option_(option), pieceStatMan_(new PieceStatMan(downloadContext->getNumPieces(), true)), - pieceSelector_(new RarestPieceSelector(pieceStatMan_)) + pieceSelector_(new RarestPieceSelector(pieceStatMan_)), + streamPieceSelector_(new DefaultStreamPieceSelector(bitfieldMan_)) {} DefaultPieceStorage::~DefaultPieceStorage() @@ -338,11 +340,11 @@ bool DefaultPieceStorage::hasMissingUnusedPiece() return bitfieldMan_->getFirstMissingUnusedIndex(index); } -SharedHandle<Piece> DefaultPieceStorage::getSparseMissingUnusedPiece +SharedHandle<Piece> DefaultPieceStorage::getMissingPiece (size_t minSplitSize, const unsigned char* ignoreBitfield, size_t length) { size_t index; - if(bitfieldMan_->getSparseMissingUnusedIndex + if(streamPieceSelector_->select (index, minSplitSize, ignoreBitfield, length)) { return checkOutPiece(index); } else { diff --git a/src/DefaultPieceStorage.h b/src/DefaultPieceStorage.h index 0fb22ff3..bb38dc43 100644 --- a/src/DefaultPieceStorage.h +++ b/src/DefaultPieceStorage.h @@ -48,6 +48,7 @@ class DiskWriterFactory; class FileEntry; class PieceStatMan; class PieceSelector; +class StreamPieceSelector; #define END_GAME_PIECE_NUM 20 @@ -85,7 +86,7 @@ private: SharedHandle<PieceStatMan> pieceStatMan_; SharedHandle<PieceSelector> pieceSelector_; - + SharedHandle<StreamPieceSelector> streamPieceSelector_; #ifdef ENABLE_BITTORRENT void getMissingPiece (std::vector<SharedHandle<Piece> >& pieces, @@ -156,7 +157,7 @@ public: virtual bool hasMissingUnusedPiece(); - virtual SharedHandle<Piece> getSparseMissingUnusedPiece + virtual SharedHandle<Piece> getMissingPiece (size_t minSplitSize, const unsigned char* ignoreBitfield, size_t length); virtual SharedHandle<Piece> getMissingPiece(size_t index); diff --git a/src/DefaultStreamPieceSelector.cc b/src/DefaultStreamPieceSelector.cc new file mode 100644 index 00000000..2a899a89 --- /dev/null +++ b/src/DefaultStreamPieceSelector.cc @@ -0,0 +1,57 @@ +/* <!-- copyright */ +/* + * aria2 - The high speed download utility + * + * Copyright (C) 2011 Tatsuhiro Tsujikawa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ +/* copyright --> */ +#include "DefaultStreamPieceSelector.h" +#include "BitfieldMan.h" + +namespace aria2 { + +DefaultStreamPieceSelector::DefaultStreamPieceSelector +(BitfieldMan* bitfieldMan) + : bitfieldMan_(bitfieldMan) +{} + +DefaultStreamPieceSelector::~DefaultStreamPieceSelector() {} + +bool DefaultStreamPieceSelector::select +(size_t& index, + size_t minSplitSize, + const unsigned char* ignoreBitfield, + size_t length) +{ + return bitfieldMan_->getSparseMissingUnusedIndex + (index, minSplitSize, ignoreBitfield, length); +} + +} // namespace aria2 diff --git a/src/DefaultStreamPieceSelector.h b/src/DefaultStreamPieceSelector.h new file mode 100644 index 00000000..20f4f42c --- /dev/null +++ b/src/DefaultStreamPieceSelector.h @@ -0,0 +1,60 @@ +/* <!-- copyright */ +/* + * aria2 - The high speed download utility + * + * Copyright (C) 2011 Tatsuhiro Tsujikawa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ +/* copyright --> */ +#ifndef D_DEFAULT_STREAM_PIECE_SELECTOR_H +#define D_DEFAULT_STREAM_PIECE_SELECTOR_H + +#include "StreamPieceSelector.h" + +namespace aria2 { + +class BitfieldMan; + +class DefaultStreamPieceSelector:public StreamPieceSelector { +public: + DefaultStreamPieceSelector(BitfieldMan* bitfieldMan); + virtual ~DefaultStreamPieceSelector(); + + virtual bool select + (size_t& index, + size_t minSplitSize, + const unsigned char* ignoreBitfield, + size_t length); +private: + BitfieldMan* bitfieldMan_; +}; + +} // namespace aria2 + +#endif // D_DEFAULT_STREAM_PIECE_SELECTOR_H diff --git a/src/Makefile.am b/src/Makefile.am index 97e0ded3..a627c8f4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -221,7 +221,9 @@ SRCS = Socket.h\ HttpListenCommand.cc HttpListenCommand.h\ HttpServerCommand.cc HttpServerCommand.h\ HttpServerResponseCommand.cc HttpServerResponseCommand.h\ - HttpServer.cc HttpServer.h + HttpServer.cc HttpServer.h\ + StreamPieceSelector.h\ + DefaultStreamPieceSelector.cc DefaultStreamPieceSelector.h if ENABLE_XML_RPC SRCS += XmlRpcRequestParserController.cc XmlRpcRequestParserController.h\ diff --git a/src/PieceStorage.h b/src/PieceStorage.h index 6f3c09bc..762201de 100644 --- a/src/PieceStorage.h +++ b/src/PieceStorage.h @@ -131,7 +131,7 @@ public: * Returns a missing piece if available. Otherwise returns 0; * If ignoreBitfield is set, indexes of true bit are excluded. */ - virtual SharedHandle<Piece> getSparseMissingUnusedPiece + virtual SharedHandle<Piece> getMissingPiece (size_t minSplitSize, const unsigned char* ignoreBitfield, size_t length) = 0; /** diff --git a/src/SegmentMan.cc b/src/SegmentMan.cc index dcc04334..d4aa3122 100644 --- a/src/SegmentMan.cc +++ b/src/SegmentMan.cc @@ -173,7 +173,7 @@ void SegmentMan::getInFlightSegment SharedHandle<Segment> SegmentMan::getSegment(cuid_t cuid, size_t minSplitSize) { SharedHandle<Piece> piece = - pieceStorage_->getSparseMissingUnusedPiece + pieceStorage_->getMissingPiece (minSplitSize, ignoreBitfield_.getFilterBitfield(), ignoreBitfield_.getBitfieldLength()); return checkoutSegment(cuid, piece); @@ -193,7 +193,7 @@ void SegmentMan::getSegment while(segments.size() < maxSegments) { SharedHandle<Segment> segment = checkoutSegment(cuid, - pieceStorage_->getSparseMissingUnusedPiece + pieceStorage_->getMissingPiece (minSplitSize, filter.getFilterBitfield(), filter.getBitfieldLength())); if(!segment) { diff --git a/src/StreamPieceSelector.h b/src/StreamPieceSelector.h new file mode 100644 index 00000000..a8f95513 --- /dev/null +++ b/src/StreamPieceSelector.h @@ -0,0 +1,67 @@ +/* <!-- copyright */ +/* + * aria2 - The high speed download utility + * + * Copyright (C) 2011 Tatsuhiro Tsujikawa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ +/* copyright --> */ +#ifndef D_STREAM_PIECE_SELECTOR_H +#define D_STREAM_PIECE_SELECTOR_H + +#include "common.h" + +#include <cstdlib> + +namespace aria2 { + +// Select piece for HTTP/FTP download. For BitTorrent downloads, use +// PieceSelector interface. +class StreamPieceSelector { +public: + virtual ~StreamPieceSelector() {} + // Selected piece index will be stored in index. To ignore some + // piece indexes from selection, use ignoreBitfield and set + // corresponding bit. length is the number of byte of + // ignoreBitfield. The number of bits in ignoreBitfield must be + // equal to the number of blocks in BitfieldMan. If piece index is + // selected, returns true. Otherwise, returns false. minSplitSize + // is a advice to derived class not to select piece such which the + // distance between it and already selected piece is less than + // minSplitSize. + virtual bool select + (size_t& index, + size_t minSplitSize, + const unsigned char* ignoreBitfield, + size_t length) = 0; +}; + +} // namespace aria2 + +#endif // D_STREAM_PIECE_SELECTOR_H diff --git a/src/UnknownLengthPieceStorage.cc b/src/UnknownLengthPieceStorage.cc index abb40354..706d5e4b 100644 --- a/src/UnknownLengthPieceStorage.cc +++ b/src/UnknownLengthPieceStorage.cc @@ -129,7 +129,7 @@ bool UnknownLengthPieceStorage::hasMissingUnusedPiece() abort(); } -SharedHandle<Piece> UnknownLengthPieceStorage::getSparseMissingUnusedPiece +SharedHandle<Piece> UnknownLengthPieceStorage::getMissingPiece (size_t minSplitSize, const unsigned char* ignoreBitfield, size_t length) { if(downloadFinished_) { @@ -146,7 +146,7 @@ SharedHandle<Piece> UnknownLengthPieceStorage::getSparseMissingUnusedPiece SharedHandle<Piece> UnknownLengthPieceStorage::getMissingPiece(size_t index) { if(index == 0) { - return getSparseMissingUnusedPiece(0, 0, 0); + return getMissingPiece(0, 0, 0); } else { return SharedHandle<Piece>(); } diff --git a/src/UnknownLengthPieceStorage.h b/src/UnknownLengthPieceStorage.h index c1b7d4f2..e2531f14 100644 --- a/src/UnknownLengthPieceStorage.h +++ b/src/UnknownLengthPieceStorage.h @@ -106,7 +106,7 @@ public: /** * Returns a missing piece if available. Otherwise returns 0; */ - virtual SharedHandle<Piece> getSparseMissingUnusedPiece + virtual SharedHandle<Piece> getMissingPiece (size_t minSplitSize, const unsigned char* ignoreBitfield, size_t length); /** |
