mirror of
https://github.com/aria2/aria2.git
synced 2025-04-06 05:57:36 +03:00
Use int32_t for piece length instead of size_t
This commit is contained in:
parent
12988e5282
commit
9d15d732ed
45 changed files with 196 additions and 183 deletions
|
@ -882,7 +882,7 @@ void AbstractCommand::createSocket()
|
|||
socket_.reset(new SocketCore());
|
||||
}
|
||||
|
||||
size_t AbstractCommand::calculateMinSplitSize() const
|
||||
int32_t AbstractCommand::calculateMinSplitSize() const
|
||||
{
|
||||
if(req_ && req_->isPipeliningEnabled()) {
|
||||
return getDownloadContext()->getPieceLength();
|
||||
|
|
|
@ -87,7 +87,7 @@ private:
|
|||
bool incNumConnection_;
|
||||
Timer serverStatTimer_;
|
||||
|
||||
size_t calculateMinSplitSize() const;
|
||||
int32_t calculateMinSplitSize() const;
|
||||
void useFasterRequest(const SharedHandle<Request>& fasterRequest);
|
||||
#ifdef ENABLE_ASYNC_DNS
|
||||
void setNameResolverCheck(const SharedHandle<AsyncNameResolver>& resolver);
|
||||
|
|
|
@ -44,7 +44,7 @@ using namespace aria2::expr;
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
BitfieldMan::BitfieldMan(size_t blockLength, off_t totalLength)
|
||||
BitfieldMan::BitfieldMan(int32_t blockLength, off_t totalLength)
|
||||
:blockLength_(blockLength),
|
||||
totalLength_(totalLength),
|
||||
bitfieldLength_(0),
|
||||
|
@ -130,12 +130,12 @@ BitfieldMan::~BitfieldMan() {
|
|||
delete [] filterBitfield_;
|
||||
}
|
||||
|
||||
size_t BitfieldMan::getLastBlockLength() const
|
||||
int32_t BitfieldMan::getLastBlockLength() const
|
||||
{
|
||||
return totalLength_-blockLength_*(blocks_-1);
|
||||
}
|
||||
|
||||
size_t BitfieldMan::getBlockLength(size_t index) const
|
||||
int32_t BitfieldMan::getBlockLength(size_t index) const
|
||||
{
|
||||
if(index == blocks_-1) {
|
||||
return getLastBlockLength();
|
||||
|
@ -230,10 +230,10 @@ namespace {
|
|||
template<typename Array>
|
||||
bool getSparseMissingUnusedIndex
|
||||
(size_t& index,
|
||||
size_t minSplitSize,
|
||||
int32_t minSplitSize,
|
||||
const Array& bitfield,
|
||||
const unsigned char* useBitfield,
|
||||
size_t blockLength_,
|
||||
int32_t blockLength,
|
||||
size_t blocks)
|
||||
{
|
||||
BitfieldMan::Range maxRange;
|
||||
|
@ -275,8 +275,8 @@ bool getSparseMissingUnusedIndex
|
|||
} else {
|
||||
if((!bitfield::test(useBitfield, blocks, maxRange.startIndex-1) &&
|
||||
bitfield::test(bitfield, blocks, maxRange.startIndex-1)) ||
|
||||
(static_cast<uint64_t>(maxRange.endIndex-maxRange.startIndex)*
|
||||
blockLength_ >= minSplitSize)) {
|
||||
(static_cast<int64_t>(maxRange.endIndex-maxRange.startIndex)*
|
||||
blockLength >= minSplitSize)) {
|
||||
index = maxRange.startIndex;
|
||||
return true;
|
||||
} else {
|
||||
|
@ -291,7 +291,7 @@ bool getSparseMissingUnusedIndex
|
|||
|
||||
bool BitfieldMan::getSparseMissingUnusedIndex
|
||||
(size_t& index,
|
||||
size_t minSplitSize,
|
||||
int32_t minSplitSize,
|
||||
const unsigned char* ignoreBitfield,
|
||||
size_t ignoreBitfieldLength) const
|
||||
{
|
||||
|
@ -313,10 +313,10 @@ namespace {
|
|||
template<typename Array>
|
||||
bool getGeomMissingUnusedIndex
|
||||
(size_t& index,
|
||||
size_t minSplitSize,
|
||||
int32_t minSplitSize,
|
||||
const Array& bitfield,
|
||||
const unsigned char* useBitfield,
|
||||
size_t blockLength,
|
||||
int32_t blockLength,
|
||||
size_t blocks,
|
||||
double base,
|
||||
size_t offsetIndex)
|
||||
|
@ -350,7 +350,7 @@ bool getGeomMissingUnusedIndex
|
|||
|
||||
bool BitfieldMan::getGeomMissingUnusedIndex
|
||||
(size_t& index,
|
||||
size_t minSplitSize,
|
||||
int32_t minSplitSize,
|
||||
const unsigned char* ignoreBitfield,
|
||||
size_t ignoreBitfieldLength,
|
||||
double base,
|
||||
|
@ -376,10 +376,10 @@ namespace {
|
|||
template<typename Array>
|
||||
bool getInorderMissingUnusedIndex
|
||||
(size_t& index,
|
||||
size_t minSplitSize,
|
||||
int32_t minSplitSize,
|
||||
const Array& bitfield,
|
||||
const unsigned char* useBitfield,
|
||||
size_t blockLength_,
|
||||
int32_t blockLength,
|
||||
size_t blocks)
|
||||
{
|
||||
// We always return first piece if it is available.
|
||||
|
@ -405,7 +405,7 @@ bool getInorderMissingUnusedIndex
|
|||
bitfield::test(useBitfield, blocks, j)) {
|
||||
break;
|
||||
}
|
||||
if((j-i+1)*blockLength_ >= minSplitSize) {
|
||||
if(static_cast<int64_t>(j-i+1)*blockLength >= minSplitSize) {
|
||||
index = j;
|
||||
return true;
|
||||
}
|
||||
|
@ -421,7 +421,7 @@ bool getInorderMissingUnusedIndex
|
|||
|
||||
bool BitfieldMan::getInorderMissingUnusedIndex
|
||||
(size_t& index,
|
||||
size_t minSplitSize,
|
||||
int32_t minSplitSize,
|
||||
const unsigned char* ignoreBitfield,
|
||||
size_t ignoreBitfieldLength) const
|
||||
{
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace aria2 {
|
|||
|
||||
class BitfieldMan {
|
||||
private:
|
||||
size_t blockLength_;
|
||||
int32_t blockLength_;
|
||||
off_t totalLength_;
|
||||
size_t bitfieldLength_;
|
||||
size_t blocks_;
|
||||
|
@ -84,20 +84,20 @@ public:
|
|||
bool operator==(const Range& range) const;
|
||||
};
|
||||
public:
|
||||
BitfieldMan(size_t blockLength, off_t totalLength);
|
||||
BitfieldMan(int32_t blockLength, off_t totalLength);
|
||||
BitfieldMan(const BitfieldMan& bitfieldMan);
|
||||
~BitfieldMan();
|
||||
|
||||
BitfieldMan& operator=(const BitfieldMan& bitfieldMan);
|
||||
|
||||
size_t getBlockLength() const
|
||||
int32_t getBlockLength() const
|
||||
{
|
||||
return blockLength_;
|
||||
}
|
||||
|
||||
size_t getLastBlockLength() const;
|
||||
int32_t getLastBlockLength() const;
|
||||
|
||||
size_t getBlockLength(size_t index) const;
|
||||
int32_t getBlockLength(size_t index) const;
|
||||
|
||||
off_t getTotalLength() const { return totalLength_; }
|
||||
|
||||
|
@ -131,7 +131,7 @@ public:
|
|||
// affected by filter
|
||||
bool getSparseMissingUnusedIndex
|
||||
(size_t& index,
|
||||
size_t minSplitSize,
|
||||
int32_t minSplitSize,
|
||||
const unsigned char* ignoreBitfield,
|
||||
size_t ignoreBitfieldLength) const;
|
||||
|
||||
|
@ -151,7 +151,7 @@ public:
|
|||
// affected by filter
|
||||
bool getGeomMissingUnusedIndex
|
||||
(size_t& index,
|
||||
size_t minSplitSize,
|
||||
int32_t minSplitSize,
|
||||
const unsigned char* ignoreBitfield,
|
||||
size_t ignoreBitfieldLength,
|
||||
double base,
|
||||
|
@ -165,7 +165,7 @@ public:
|
|||
// affected by filter
|
||||
bool getInorderMissingUnusedIndex
|
||||
(size_t& index,
|
||||
size_t minSplitSize,
|
||||
int32_t minSplitSize,
|
||||
const unsigned char* ignoreBitfield,
|
||||
size_t ignoreBitfieldLength) const;
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ ChunkChecksum::ChunkChecksum():pieceLength_(0) {}
|
|||
ChunkChecksum::ChunkChecksum
|
||||
(const std::string& hashType,
|
||||
const std::vector<std::string>& pieceHashes,
|
||||
size_t pieceLength)
|
||||
int32_t pieceLength)
|
||||
: hashType_(hashType),
|
||||
pieceHashes_(pieceHashes),
|
||||
pieceLength_(pieceLength)
|
||||
|
|
|
@ -48,14 +48,14 @@ class ChunkChecksum {
|
|||
private:
|
||||
std::string hashType_;
|
||||
std::vector<std::string> pieceHashes_;
|
||||
size_t pieceLength_;
|
||||
int32_t pieceLength_;
|
||||
public:
|
||||
ChunkChecksum();
|
||||
|
||||
ChunkChecksum
|
||||
(const std::string& hashType,
|
||||
const std::vector<std::string>& pieceHashes,
|
||||
size_t pieceLength);
|
||||
int32_t pieceLength);
|
||||
|
||||
bool validateChunk(const std::string& actualDigest,
|
||||
size_t index) const;
|
||||
|
@ -78,12 +78,12 @@ public:
|
|||
return hashType_;
|
||||
}
|
||||
|
||||
size_t getPieceLength() const
|
||||
int32_t getPieceLength() const
|
||||
{
|
||||
return pieceLength_;
|
||||
}
|
||||
|
||||
void setPieceLength(size_t length)
|
||||
void setPieceLength(int32_t length)
|
||||
{
|
||||
pieceLength_ = length;
|
||||
}
|
||||
|
|
|
@ -309,7 +309,7 @@ void DefaultBtProgressInfoFile::load()
|
|||
array_ptr<unsigned char> savedBitfield(new unsigned char[bitfieldLength]);
|
||||
READ_CHECK(fp, static_cast<unsigned char*>(savedBitfield),
|
||||
bitfieldLength);
|
||||
if(pieceLength == dctx_->getPieceLength()) {
|
||||
if(pieceLength == static_cast<uint32_t>(dctx_->getPieceLength())) {
|
||||
pieceStorage_->setBitfield(savedBitfield, bitfieldLength);
|
||||
|
||||
uint32_t numInFlightPiece;
|
||||
|
@ -333,7 +333,7 @@ void DefaultBtProgressInfoFile::load()
|
|||
if(version >= 1) {
|
||||
length = ntohl(length);
|
||||
}
|
||||
if(!(length <=dctx_->getPieceLength())) {
|
||||
if(!(length <= static_cast<uint32_t>(dctx_->getPieceLength()))) {
|
||||
throw DL_ABORT_EX(fmt("piece length out of range: %u", length));
|
||||
}
|
||||
SharedHandle<Piece> piece(new Piece(index, length));
|
||||
|
|
|
@ -649,7 +649,7 @@ DiskAdaptorHandle DefaultPieceStorage::getDiskAdaptor() {
|
|||
return diskAdaptor_;
|
||||
}
|
||||
|
||||
size_t DefaultPieceStorage::getPieceLength(size_t index)
|
||||
int32_t DefaultPieceStorage::getPieceLength(size_t index)
|
||||
{
|
||||
return bitfieldMan_->getBlockLength(index);
|
||||
}
|
||||
|
|
|
@ -234,7 +234,7 @@ public:
|
|||
|
||||
virtual SharedHandle<DiskAdaptor> getDiskAdaptor();
|
||||
|
||||
virtual size_t getPieceLength(size_t index);
|
||||
virtual int32_t getPieceLength(size_t index);
|
||||
|
||||
virtual void advertisePiece(cuid_t cuid, size_t index);
|
||||
|
||||
|
|
|
@ -148,7 +148,9 @@ bool DownloadCommand::executeInternal() {
|
|||
if(segment->getLength() > 0) {
|
||||
if(static_cast<off_t>(segment->getPosition()+segment->getLength()) <=
|
||||
getFileEntry()->getLastOffset()) {
|
||||
bufSize = std::min(segment->getLength()-segment->getWrittenLength(),
|
||||
bufSize =
|
||||
std::min(static_cast<size_t>(segment->getLength()
|
||||
-segment->getWrittenLength()),
|
||||
getSocketRecvBuffer()->getBufferLength());
|
||||
} else {
|
||||
bufSize =
|
||||
|
|
|
@ -56,7 +56,7 @@ DownloadContext::DownloadContext():
|
|||
downloadStopTime_(downloadStartTime_),
|
||||
metalinkServerContacted_(false) {}
|
||||
|
||||
DownloadContext::DownloadContext(size_t pieceLength,
|
||||
DownloadContext::DownloadContext(int32_t pieceLength,
|
||||
off_t totalLength,
|
||||
const std::string& path):
|
||||
pieceLength_(pieceLength),
|
||||
|
|
|
@ -61,7 +61,7 @@ private:
|
|||
|
||||
std::vector<std::string> pieceHashes_;
|
||||
|
||||
size_t pieceLength_;
|
||||
int32_t pieceLength_;
|
||||
|
||||
std::string pieceHashType_;
|
||||
|
||||
|
@ -92,7 +92,7 @@ public:
|
|||
|
||||
// Convenient constructor that creates single file download. path
|
||||
// should be escaped with util::escapePath(...).
|
||||
DownloadContext(size_t pieceLength,
|
||||
DownloadContext(int32_t pieceLength,
|
||||
off_t totalLength,
|
||||
const std::string& path = A2STR::NIL);
|
||||
|
||||
|
@ -146,9 +146,9 @@ public:
|
|||
fileEntries_.assign(first, last);
|
||||
}
|
||||
|
||||
size_t getPieceLength() const { return pieceLength_; }
|
||||
int32_t getPieceLength() const { return pieceLength_; }
|
||||
|
||||
void setPieceLength(size_t length) { pieceLength_ = length; }
|
||||
void setPieceLength(int32_t length) { pieceLength_ = length; }
|
||||
|
||||
size_t getNumPieces() const;
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ struct DownloadResult
|
|||
|
||||
std::string infoHash;
|
||||
|
||||
size_t pieceLength;
|
||||
int32_t pieceLength;
|
||||
|
||||
size_t numPieces;
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ GrowSegment::GrowSegment(const SharedHandle<Piece>& piece):
|
|||
|
||||
GrowSegment::~GrowSegment() {}
|
||||
|
||||
void GrowSegment::updateWrittenLength(size_t bytes)
|
||||
void GrowSegment::updateWrittenLength(int32_t bytes)
|
||||
{
|
||||
writtenLength_ += bytes;
|
||||
piece_->reconfigure(writtenLength_);
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace aria2 {
|
|||
class GrowSegment:public Segment {
|
||||
private:
|
||||
SharedHandle<Piece> piece_;
|
||||
size_t writtenLength_;
|
||||
int32_t writtenLength_;
|
||||
public:
|
||||
GrowSegment(const SharedHandle<Piece>& piece);
|
||||
|
||||
|
@ -68,27 +68,29 @@ public:
|
|||
return writtenLength_;
|
||||
}
|
||||
|
||||
virtual size_t getLength() const
|
||||
virtual int32_t getLength() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual size_t getSegmentLength() const
|
||||
virtual int32_t getSegmentLength() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual size_t getWrittenLength() const
|
||||
virtual int32_t getWrittenLength() const
|
||||
{
|
||||
return writtenLength_;
|
||||
}
|
||||
|
||||
virtual void updateWrittenLength(size_t bytes);
|
||||
virtual void updateWrittenLength(int32_t bytes);
|
||||
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
|
||||
virtual bool updateHash(uint32_t begin,
|
||||
const unsigned char* data, size_t dataLength)
|
||||
virtual bool updateHash
|
||||
(int32_t begin,
|
||||
const unsigned char* data,
|
||||
size_t dataLength)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -253,7 +253,7 @@ Metalink2RequestGroup::createRequestGroup
|
|||
AccumulateNonP2PUri(uris));
|
||||
// If piece hash is specified in the metalink,
|
||||
// make segment size equal to piece hash size.
|
||||
size_t pieceLength;
|
||||
int32_t pieceLength;
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
if(!entry->chunkChecksum) {
|
||||
pieceLength = option->getAsInt(PREF_PIECE_LENGTH);
|
||||
|
|
|
@ -73,7 +73,7 @@ void Peer::usedBy(cuid_t cuid)
|
|||
cuid_ = cuid;
|
||||
}
|
||||
|
||||
void Peer::allocateSessionResource(size_t pieceLength, off_t totalLength)
|
||||
void Peer::allocateSessionResource(int32_t pieceLength, off_t totalLength)
|
||||
{
|
||||
delete res_;
|
||||
res_ = new PeerSessionResource(pieceLength, totalLength);
|
||||
|
@ -81,7 +81,7 @@ void Peer::allocateSessionResource(size_t pieceLength, off_t totalLength)
|
|||
updateSeeder();
|
||||
}
|
||||
|
||||
void Peer::reconfigureSessionResource(size_t pieceLength, off_t totalLength)
|
||||
void Peer::reconfigureSessionResource(int32_t pieceLength, off_t totalLength)
|
||||
{
|
||||
assert(res_);
|
||||
res_->reconfigure(pieceLength, totalLength);
|
||||
|
@ -192,13 +192,13 @@ void Peer::snubbing(bool b)
|
|||
res_->snubbing(b);
|
||||
}
|
||||
|
||||
void Peer::updateUploadLength(size_t bytes)
|
||||
void Peer::updateUploadLength(int32_t bytes)
|
||||
{
|
||||
assert(res_);
|
||||
res_->updateUploadLength(bytes);
|
||||
}
|
||||
|
||||
void Peer::updateDownloadLength(size_t bytes)
|
||||
void Peer::updateDownloadLength(int32_t bytes)
|
||||
{
|
||||
assert(res_);
|
||||
res_->updateDownloadLength(bytes);
|
||||
|
|
|
@ -160,9 +160,9 @@ public:
|
|||
|
||||
bool isGood() const;
|
||||
|
||||
void allocateSessionResource(size_t pieceLength, off_t totalLength);
|
||||
void allocateSessionResource(int32_t pieceLength, off_t totalLength);
|
||||
|
||||
void reconfigureSessionResource(size_t pieceLength, off_t totalLength);
|
||||
void reconfigureSessionResource(int32_t pieceLength, off_t totalLength);
|
||||
|
||||
void releaseSessionResource();
|
||||
|
||||
|
@ -217,9 +217,9 @@ public:
|
|||
|
||||
void snubbing(bool b);
|
||||
|
||||
void updateUploadLength(size_t bytes);
|
||||
void updateUploadLength(int32_t bytes);
|
||||
|
||||
void updateDownloadLength(size_t bytes);
|
||||
void updateDownloadLength(int32_t bytes);
|
||||
|
||||
/**
|
||||
* Returns the transfer rate from localhost to remote host.
|
||||
|
|
|
@ -44,7 +44,8 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
PeerSessionResource::PeerSessionResource(size_t pieceLength, off_t totalLength):
|
||||
PeerSessionResource::PeerSessionResource(int32_t pieceLength, off_t totalLength)
|
||||
:
|
||||
amChoking_(true),
|
||||
amInterested_(false),
|
||||
peerChoking_(true),
|
||||
|
@ -130,7 +131,8 @@ void PeerSessionResource::updateBitfield(size_t index, int operation)
|
|||
}
|
||||
}
|
||||
|
||||
void PeerSessionResource::setBitfield(const unsigned char* bitfield, size_t bitfieldLength)
|
||||
void PeerSessionResource::setBitfield
|
||||
(const unsigned char* bitfield, size_t bitfieldLength)
|
||||
{
|
||||
bitfieldMan_->setBitfield(bitfield, bitfieldLength);
|
||||
}
|
||||
|
@ -242,7 +244,7 @@ off_t PeerSessionResource::uploadLength() const
|
|||
return peerStat_.getSessionUploadLength();
|
||||
}
|
||||
|
||||
void PeerSessionResource::updateUploadLength(size_t bytes)
|
||||
void PeerSessionResource::updateUploadLength(int32_t bytes)
|
||||
{
|
||||
peerStat_.updateUploadLength(bytes);
|
||||
}
|
||||
|
@ -252,7 +254,7 @@ off_t PeerSessionResource::downloadLength() const
|
|||
return peerStat_.getSessionDownloadLength();
|
||||
}
|
||||
|
||||
void PeerSessionResource::updateDownloadLength(size_t bytes)
|
||||
void PeerSessionResource::updateDownloadLength(int32_t bytes)
|
||||
{
|
||||
peerStat_.updateDownloadLength(bytes);
|
||||
|
||||
|
@ -275,7 +277,7 @@ size_t PeerSessionResource::countOutstandingUpload() const
|
|||
return dispatcher_->countOutstandingUpload();
|
||||
}
|
||||
|
||||
void PeerSessionResource::reconfigure(size_t pieceLength, off_t totalLenth)
|
||||
void PeerSessionResource::reconfigure(int32_t pieceLength, off_t totalLenth)
|
||||
{
|
||||
delete bitfieldMan_;
|
||||
bitfieldMan_ = new BitfieldMan(pieceLength, totalLenth);
|
||||
|
|
|
@ -83,7 +83,7 @@ private:
|
|||
|
||||
BtMessageDispatcher* dispatcher_;
|
||||
public:
|
||||
PeerSessionResource(size_t pieceLength, off_t totalLength);
|
||||
PeerSessionResource(int32_t pieceLength, off_t totalLength);
|
||||
|
||||
~PeerSessionResource();
|
||||
|
||||
|
@ -155,7 +155,7 @@ public:
|
|||
|
||||
size_t getBitfieldLength() const;
|
||||
|
||||
void reconfigure(size_t index, off_t totalLength);
|
||||
void reconfigure(int32_t pieceLength, off_t totalLength);
|
||||
|
||||
bool hasPiece(size_t index) const;
|
||||
|
||||
|
@ -212,11 +212,11 @@ public:
|
|||
|
||||
off_t uploadLength() const;
|
||||
|
||||
void updateUploadLength(size_t bytes);
|
||||
void updateUploadLength(int32_t bytes);
|
||||
|
||||
off_t downloadLength() const;
|
||||
|
||||
void updateDownloadLength(size_t bytes);
|
||||
void updateDownloadLength(int32_t bytes);
|
||||
|
||||
const Timer& getLastDownloadUpdate() const
|
||||
{
|
||||
|
|
24
src/Piece.cc
24
src/Piece.cc
|
@ -51,8 +51,10 @@ Piece::Piece():index_(0), length_(0), blockLength_(BLOCK_LENGTH), bitfield_(0),
|
|||
#endif // ENABLE_MESSAGE_DIGEST
|
||||
{}
|
||||
|
||||
Piece::Piece(size_t index, size_t length, size_t blockLength):
|
||||
index_(index), length_(length), blockLength_(blockLength),
|
||||
Piece::Piece(size_t index, int32_t length, int32_t blockLength)
|
||||
: index_(index),
|
||||
length_(length),
|
||||
blockLength_(blockLength),
|
||||
bitfield_(new BitfieldMan(blockLength_, length)),
|
||||
usedBySegment_(false)
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
|
@ -88,12 +90,12 @@ size_t Piece::countBlock() const
|
|||
return bitfield_->countBlock();
|
||||
}
|
||||
|
||||
size_t Piece::getBlockLength(size_t index) const
|
||||
int32_t Piece::getBlockLength(size_t index) const
|
||||
{
|
||||
return bitfield_->getBlockLength(index);
|
||||
}
|
||||
|
||||
size_t Piece::getBlockLength() const
|
||||
int32_t Piece::getBlockLength() const
|
||||
{
|
||||
return bitfield_->getBlockLength();
|
||||
}
|
||||
|
@ -167,12 +169,11 @@ bool Piece::getAllMissingBlockIndexes
|
|||
}
|
||||
|
||||
std::string Piece::toString() const {
|
||||
return fmt("piece: index=%lu, length=%lu",
|
||||
static_cast<unsigned long>(index_),
|
||||
static_cast<unsigned long>(length_));
|
||||
return fmt("piece: index=%lu, length=%d",
|
||||
static_cast<unsigned long>(index_), length_);
|
||||
}
|
||||
|
||||
void Piece::reconfigure(size_t length)
|
||||
void Piece::reconfigure(int32_t length)
|
||||
{
|
||||
delete bitfield_;
|
||||
length_ = length;
|
||||
|
@ -184,7 +185,7 @@ void Piece::setBitfield(const unsigned char* bitfield, size_t len)
|
|||
bitfield_->setBitfield(bitfield, len);
|
||||
}
|
||||
|
||||
size_t Piece::getCompletedLength()
|
||||
int32_t Piece::getCompletedLength()
|
||||
{
|
||||
return bitfield_->getCompletedLength();
|
||||
}
|
||||
|
@ -197,12 +198,13 @@ void Piece::setHashType(const std::string& hashType)
|
|||
}
|
||||
|
||||
bool Piece::updateHash
|
||||
(uint32_t begin, const unsigned char* data, size_t dataLength)
|
||||
(int32_t begin, const unsigned char* data, size_t dataLength)
|
||||
{
|
||||
if(hashType_.empty()) {
|
||||
return false;
|
||||
}
|
||||
if(begin == nextBegin_ && nextBegin_+dataLength <= length_) {
|
||||
if(begin == nextBegin_ &&
|
||||
nextBegin_+dataLength <= static_cast<size_t>(length_)) {
|
||||
if(!mdctx_) {
|
||||
mdctx_ = MessageDigest::create(hashType_);
|
||||
}
|
||||
|
|
24
src/Piece.h
24
src/Piece.h
|
@ -57,14 +57,14 @@ class MessageDigest;
|
|||
class Piece {
|
||||
private:
|
||||
size_t index_;
|
||||
size_t length_;
|
||||
size_t blockLength_;
|
||||
int32_t length_;
|
||||
int32_t blockLength_;
|
||||
BitfieldMan* bitfield_;
|
||||
std::vector<cuid_t> users_;
|
||||
bool usedBySegment_;
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
|
||||
size_t nextBegin_;
|
||||
int32_t nextBegin_;
|
||||
|
||||
std::string hashType_;
|
||||
|
||||
|
@ -77,11 +77,11 @@ private:
|
|||
Piece& operator=(const Piece& piece);
|
||||
public:
|
||||
|
||||
static const size_t BLOCK_LENGTH = 16*1024;
|
||||
static const int32_t BLOCK_LENGTH = 16*1024;
|
||||
|
||||
Piece();
|
||||
|
||||
Piece(size_t index, size_t length, size_t blockLength = BLOCK_LENGTH);
|
||||
Piece(size_t index, int32_t length, int32_t blockLength = BLOCK_LENGTH);
|
||||
|
||||
~Piece();
|
||||
|
||||
|
@ -125,17 +125,17 @@ public:
|
|||
|
||||
size_t countBlock() const;
|
||||
|
||||
size_t getBlockLength(size_t index) const;
|
||||
int32_t getBlockLength(size_t index) const;
|
||||
|
||||
size_t getBlockLength() const;
|
||||
int32_t getBlockLength() const;
|
||||
|
||||
size_t getIndex() const { return index_; }
|
||||
|
||||
void setIndex(size_t index) { index_ = index; }
|
||||
|
||||
size_t getLength() const { return length_; }
|
||||
int32_t getLength() const { return length_; }
|
||||
|
||||
void setLength(size_t length) { length_ = length; }
|
||||
void setLength(int32_t length) { length_ = length; }
|
||||
|
||||
const unsigned char* getBitfield() const;
|
||||
|
||||
|
@ -151,7 +151,7 @@ public:
|
|||
bool isBlockUsed(size_t index) const;
|
||||
|
||||
// Calculates completed length
|
||||
size_t getCompletedLength();
|
||||
int32_t getCompletedLength();
|
||||
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
|
||||
|
@ -160,7 +160,7 @@ public:
|
|||
// Updates hash value. This function compares begin and private variable
|
||||
// nextBegin_ and only when they are equal, hash is updated eating data and
|
||||
// returns true. Otherwise returns false.
|
||||
bool updateHash(uint32_t begin, const unsigned char* data, size_t dataLength);
|
||||
bool updateHash(int32_t begin, const unsigned char* data, size_t dataLength);
|
||||
|
||||
bool isHashCalculated() const;
|
||||
|
||||
|
@ -177,7 +177,7 @@ public:
|
|||
/**
|
||||
* Loses current bitfield state.
|
||||
*/
|
||||
void reconfigure(size_t length);
|
||||
void reconfigure(int32_t length);
|
||||
|
||||
void addUser(cuid_t cuid);
|
||||
void removeUser(cuid_t cuid);
|
||||
|
|
|
@ -228,7 +228,7 @@ public:
|
|||
|
||||
virtual SharedHandle<DiskAdaptor> getDiskAdaptor() = 0;
|
||||
|
||||
virtual size_t getPieceLength(size_t index) = 0;
|
||||
virtual int32_t getPieceLength(size_t index) = 0;
|
||||
|
||||
/**
|
||||
* Adds piece index to advertise to other commands. They send have message
|
||||
|
|
|
@ -39,8 +39,9 @@
|
|||
namespace aria2 {
|
||||
|
||||
PiecedSegment::PiecedSegment
|
||||
(size_t pieceLength, const SharedHandle<Piece>& piece):
|
||||
pieceLength_(pieceLength), piece_(piece)
|
||||
(int32_t pieceLength, const SharedHandle<Piece>& piece)
|
||||
: piece_(piece),
|
||||
pieceLength_(pieceLength)
|
||||
{
|
||||
size_t index;
|
||||
bool t = piece_->getFirstMissingBlockIndexWithoutLock(index);
|
||||
|
@ -70,14 +71,14 @@ off_t PiecedSegment::getPositionToWrite() const
|
|||
return getPosition()+writtenLength_;
|
||||
}
|
||||
|
||||
size_t PiecedSegment::getLength() const
|
||||
int32_t PiecedSegment::getLength() const
|
||||
{
|
||||
return piece_->getLength();
|
||||
}
|
||||
|
||||
void PiecedSegment::updateWrittenLength(size_t bytes)
|
||||
void PiecedSegment::updateWrittenLength(int32_t bytes)
|
||||
{
|
||||
size_t newWrittenLength = writtenLength_+bytes;
|
||||
int32_t newWrittenLength = writtenLength_+bytes;
|
||||
assert(newWrittenLength <= piece_->getLength());
|
||||
for(size_t i = writtenLength_/piece_->getBlockLength(),
|
||||
end = newWrittenLength/piece_->getBlockLength(); i < end; ++i) {
|
||||
|
@ -91,8 +92,10 @@ void PiecedSegment::updateWrittenLength(size_t bytes)
|
|||
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
|
||||
bool PiecedSegment::updateHash(uint32_t begin,
|
||||
const unsigned char* data, size_t dataLength)
|
||||
bool PiecedSegment::updateHash
|
||||
(int32_t begin,
|
||||
const unsigned char* data,
|
||||
size_t dataLength)
|
||||
{
|
||||
return piece_->updateHash(begin, data, dataLength);
|
||||
}
|
||||
|
|
|
@ -41,16 +41,16 @@ namespace aria2 {
|
|||
|
||||
class PiecedSegment:public Segment {
|
||||
private:
|
||||
SharedHandle<Piece> piece_;
|
||||
/**
|
||||
* Piece class has length property but it is a actual length of piece.
|
||||
* The last piece likely have shorter length than the other length.
|
||||
*/
|
||||
size_t pieceLength_;
|
||||
SharedHandle<Piece> piece_;
|
||||
size_t writtenLength_;
|
||||
int32_t pieceLength_;
|
||||
int32_t writtenLength_;
|
||||
|
||||
public:
|
||||
PiecedSegment(size_t pieceLength, const SharedHandle<Piece>& piece);
|
||||
PiecedSegment(int32_t pieceLength, const SharedHandle<Piece>& piece);
|
||||
|
||||
virtual ~PiecedSegment();
|
||||
|
||||
|
@ -62,25 +62,27 @@ public:
|
|||
|
||||
virtual off_t getPositionToWrite() const;
|
||||
|
||||
virtual size_t getLength() const;
|
||||
virtual int32_t getLength() const;
|
||||
|
||||
virtual size_t getSegmentLength() const
|
||||
virtual int32_t getSegmentLength() const
|
||||
{
|
||||
return pieceLength_;
|
||||
}
|
||||
|
||||
virtual size_t getWrittenLength() const
|
||||
virtual int32_t getWrittenLength() const
|
||||
{
|
||||
return writtenLength_;
|
||||
}
|
||||
|
||||
virtual void updateWrittenLength(size_t bytes);
|
||||
virtual void updateWrittenLength(int32_t bytes);
|
||||
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
|
||||
// `begin' is a offset inside this segment.
|
||||
virtual bool updateHash(uint32_t begin,
|
||||
const unsigned char* data, size_t dataLength);
|
||||
virtual bool updateHash
|
||||
(int32_t begin,
|
||||
const unsigned char* data,
|
||||
size_t dataLength);
|
||||
|
||||
virtual bool isHashCalculated() const;
|
||||
|
||||
|
|
|
@ -603,7 +603,7 @@ void createFileEntry
|
|||
(const SharedHandle<List>& files,
|
||||
InputIterator first, InputIterator last,
|
||||
off_t totalLength,
|
||||
size_t pieceLength,
|
||||
int32_t pieceLength,
|
||||
const std::string& bitfield)
|
||||
{
|
||||
BitfieldMan bf(pieceLength, totalLength);
|
||||
|
@ -619,7 +619,7 @@ void createFileEntry
|
|||
(const SharedHandle<List>& files,
|
||||
InputIterator first, InputIterator last,
|
||||
off_t totalLength,
|
||||
size_t pieceLength,
|
||||
int32_t pieceLength,
|
||||
const SharedHandle<PieceStorage>& ps)
|
||||
{
|
||||
BitfieldMan bf(pieceLength, totalLength);
|
||||
|
@ -680,7 +680,7 @@ void gatherProgressCommon
|
|||
}
|
||||
const SharedHandle<DownloadContext>& dctx = group->getDownloadContext();
|
||||
if(requested_key(keys, KEY_PIECE_LENGTH)) {
|
||||
entryDict->put(KEY_PIECE_LENGTH, util::uitos(dctx->getPieceLength()));
|
||||
entryDict->put(KEY_PIECE_LENGTH, util::itos(dctx->getPieceLength()));
|
||||
}
|
||||
if(requested_key(keys, KEY_NUM_PIECES)) {
|
||||
entryDict->put(KEY_NUM_PIECES, util::uitos(dctx->getNumPieces()));
|
||||
|
@ -897,7 +897,7 @@ void gatherStoppedDownload
|
|||
}
|
||||
}
|
||||
if(requested_key(keys, KEY_PIECE_LENGTH)) {
|
||||
entryDict->put(KEY_PIECE_LENGTH, util::uitos(ds->pieceLength));
|
||||
entryDict->put(KEY_PIECE_LENGTH, util::itos(ds->pieceLength));
|
||||
}
|
||||
if(requested_key(keys, KEY_NUM_PIECES)) {
|
||||
entryDict->put(KEY_NUM_PIECES, util::uitos(ds->numPieces));
|
||||
|
|
|
@ -58,19 +58,21 @@ public:
|
|||
|
||||
virtual off_t getPositionToWrite() const = 0;
|
||||
|
||||
virtual size_t getLength() const = 0;
|
||||
virtual int32_t getLength() const = 0;
|
||||
|
||||
virtual size_t getSegmentLength() const = 0;
|
||||
virtual int32_t getSegmentLength() const = 0;
|
||||
|
||||
virtual size_t getWrittenLength() const = 0;
|
||||
virtual int32_t getWrittenLength() const = 0;
|
||||
|
||||
virtual void updateWrittenLength(size_t bytes) = 0;
|
||||
virtual void updateWrittenLength(int32_t bytes) = 0;
|
||||
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
|
||||
// `begin' is a offset inside this segment.
|
||||
virtual bool updateHash(uint32_t begin,
|
||||
const unsigned char* data, size_t dataLength) = 0;
|
||||
virtual bool updateHash
|
||||
(int32_t begin,
|
||||
const unsigned char* data,
|
||||
size_t dataLength) = 0;
|
||||
|
||||
virtual bool isHashCalculated() const = 0;
|
||||
|
||||
|
|
|
@ -132,21 +132,19 @@ SharedHandle<Segment> SegmentMan::checkoutSegment
|
|||
}
|
||||
SegmentEntryHandle entry(new SegmentEntry(cuid, segment));
|
||||
usedSegmentEntries_.push_back(entry);
|
||||
A2_LOG_DEBUG(fmt("index=%lu, length=%lu, segmentLength=%lu,"
|
||||
" writtenLength=%lu",
|
||||
A2_LOG_DEBUG(fmt("index=%lu, length=%d, segmentLength=%d,"
|
||||
" writtenLength=%d",
|
||||
static_cast<unsigned long>(segment->getIndex()),
|
||||
static_cast<unsigned long>(segment->getLength()),
|
||||
static_cast<unsigned long>(segment->getSegmentLength()),
|
||||
static_cast<unsigned long>(segment->getWrittenLength())));
|
||||
segment->getLength(),
|
||||
segment->getSegmentLength(),
|
||||
segment->getWrittenLength()));
|
||||
if(piece->getLength() > 0) {
|
||||
std::map<size_t, size_t>::iterator positr =
|
||||
std::map<size_t, int32_t>::iterator positr =
|
||||
segmentWrittenLengthMemo_.find(segment->getIndex());
|
||||
if(positr != segmentWrittenLengthMemo_.end()) {
|
||||
const size_t writtenLength = (*positr).second;
|
||||
A2_LOG_DEBUG(fmt("writtenLength(in memo)=%lu, writtenLength=%lu",
|
||||
static_cast<unsigned long>(writtenLength),
|
||||
static_cast<unsigned long>(segment->getWrittenLength()))
|
||||
);
|
||||
const int32_t writtenLength = (*positr).second;
|
||||
A2_LOG_DEBUG(fmt("writtenLength(in memo)=%d, writtenLength=%d",
|
||||
writtenLength, segment->getWrittenLength()));
|
||||
// If the difference between cached writtenLength and segment's
|
||||
// writtenLength is less than one block, we assume that these
|
||||
// missing bytes are already downloaded.
|
||||
|
@ -261,9 +259,9 @@ void SegmentMan::cancelSegmentInternal
|
|||
segment->getPiece()->setUsedBySegment(false);
|
||||
pieceStorage_->cancelPiece(segment->getPiece(), cuid);
|
||||
segmentWrittenLengthMemo_[segment->getIndex()] = segment->getWrittenLength();
|
||||
A2_LOG_DEBUG(fmt("Memorized segment index=%lu, writtenLength=%lu",
|
||||
A2_LOG_DEBUG(fmt("Memorized segment index=%lu, writtenLength=%d",
|
||||
static_cast<unsigned long>(segment->getIndex()),
|
||||
static_cast<unsigned long>(segment->getWrittenLength())));
|
||||
segment->getWrittenLength()));
|
||||
}
|
||||
|
||||
void SegmentMan::cancelSegment(cuid_t cuid) {
|
||||
|
|
|
@ -86,7 +86,7 @@ private:
|
|||
|
||||
// Remember writtenLength for each segment. The key is an index of a
|
||||
// segment. The value is writtenLength for that segment.
|
||||
std::map<size_t, size_t> segmentWrittenLengthMemo_;
|
||||
std::map<size_t, int32_t> segmentWrittenLengthMemo_;
|
||||
|
||||
// Used for calculating download speed.
|
||||
std::vector<SharedHandle<PeerStat> > peerStats_;
|
||||
|
|
|
@ -220,7 +220,7 @@ DiskAdaptorHandle UnknownLengthPieceStorage::getDiskAdaptor()
|
|||
return diskAdaptor_;
|
||||
}
|
||||
|
||||
size_t UnknownLengthPieceStorage::getPieceLength(size_t index)
|
||||
int32_t UnknownLengthPieceStorage::getPieceLength(size_t index)
|
||||
{
|
||||
if(index == 0) {
|
||||
return totalLength_;
|
||||
|
|
|
@ -231,7 +231,7 @@ public:
|
|||
|
||||
virtual SharedHandle<DiskAdaptor> getDiskAdaptor();
|
||||
|
||||
virtual size_t getPieceLength(size_t index);
|
||||
virtual int32_t getPieceLength(size_t index);
|
||||
|
||||
/**
|
||||
* Adds piece index to advertise to other commands. They send have message
|
||||
|
|
|
@ -75,12 +75,12 @@ CPPUNIT_TEST_SUITE_REGISTRATION( BitfieldManTest );
|
|||
|
||||
void BitfieldManTest::testGetBlockSize() {
|
||||
BitfieldMan bt1(1024, 1024*10);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1024, bt1.getBlockLength(9));
|
||||
CPPUNIT_ASSERT_EQUAL(1024, bt1.getBlockLength(9));
|
||||
|
||||
BitfieldMan bt2(1024, 1024*10+1);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1024, bt2.getBlockLength(9));
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1, bt2.getBlockLength(10));
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)0, bt2.getBlockLength(11));
|
||||
CPPUNIT_ASSERT_EQUAL(1024, bt2.getBlockLength(9));
|
||||
CPPUNIT_ASSERT_EQUAL(1, bt2.getBlockLength(10));
|
||||
CPPUNIT_ASSERT_EQUAL(0, bt2.getBlockLength(11));
|
||||
}
|
||||
|
||||
void BitfieldManTest::testGetFirstMissingUnusedIndex()
|
||||
|
|
|
@ -293,7 +293,7 @@ void BittorrentHelperTest::testGetPieceLength() {
|
|||
SharedHandle<DownloadContext> dctx(new DownloadContext());
|
||||
load(A2_TEST_DIR"/test.torrent", dctx, option_);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)128, dctx->getPieceLength());
|
||||
CPPUNIT_ASSERT_EQUAL(128, dctx->getPieceLength());
|
||||
}
|
||||
|
||||
void BittorrentHelperTest::testGetInfoHashAsString() {
|
||||
|
|
|
@ -146,7 +146,7 @@ void DefaultBtProgressInfoFileTest::testLoad_compat()
|
|||
|
||||
SharedHandle<Piece> piece1 = inFlightPieces[0];
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1024, piece1->getLength());
|
||||
CPPUNIT_ASSERT_EQUAL(1024, piece1->getLength());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getBitfieldLength());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("00"), util::toHex(piece1->getBitfield(),
|
||||
piece1->getBitfieldLength()));
|
||||
|
@ -154,7 +154,7 @@ void DefaultBtProgressInfoFileTest::testLoad_compat()
|
|||
// piece index 2
|
||||
SharedHandle<Piece> piece2 = inFlightPieces[1];
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)2, piece2->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)512, piece2->getLength());
|
||||
CPPUNIT_ASSERT_EQUAL(512, piece2->getLength());
|
||||
}
|
||||
#endif // !WORDS_BIGENDIAN
|
||||
|
||||
|
@ -195,7 +195,7 @@ void DefaultBtProgressInfoFileTest::testLoad()
|
|||
|
||||
SharedHandle<Piece> piece1 = inFlightPieces[0];
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1024, piece1->getLength());
|
||||
CPPUNIT_ASSERT_EQUAL(1024, piece1->getLength());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getBitfieldLength());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("00"), util::toHex(piece1->getBitfield(),
|
||||
piece1->getBitfieldLength()));
|
||||
|
@ -203,7 +203,7 @@ void DefaultBtProgressInfoFileTest::testLoad()
|
|||
// piece index 2
|
||||
SharedHandle<Piece> piece2 = inFlightPieces[1];
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)2, piece2->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)512, piece2->getLength());
|
||||
CPPUNIT_ASSERT_EQUAL(512, piece2->getLength());
|
||||
}
|
||||
|
||||
void DefaultBtProgressInfoFileTest::testSave()
|
||||
|
@ -360,7 +360,7 @@ void DefaultBtProgressInfoFileTest::testLoad_nonBt_compat()
|
|||
|
||||
SharedHandle<Piece> piece1 = inFlightPieces[0];
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1024, piece1->getLength());
|
||||
CPPUNIT_ASSERT_EQUAL(1024, piece1->getLength());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getBitfieldLength());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("00"), util::toHex(piece1->getBitfield(),
|
||||
piece1->getBitfieldLength()));
|
||||
|
@ -368,7 +368,7 @@ void DefaultBtProgressInfoFileTest::testLoad_nonBt_compat()
|
|||
// piece index 2
|
||||
SharedHandle<Piece> piece2 = inFlightPieces[1];
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)2, piece2->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)512, piece2->getLength());
|
||||
CPPUNIT_ASSERT_EQUAL(512, piece2->getLength());
|
||||
}
|
||||
#endif // !WORDS_BIGENDIAN
|
||||
|
||||
|
@ -405,7 +405,7 @@ void DefaultBtProgressInfoFileTest::testLoad_nonBt()
|
|||
|
||||
SharedHandle<Piece> piece1 = inFlightPieces[0];
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1024, piece1->getLength());
|
||||
CPPUNIT_ASSERT_EQUAL(1024, piece1->getLength());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1, piece1->getBitfieldLength());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("00"), util::toHex(piece1->getBitfield(),
|
||||
piece1->getBitfieldLength()));
|
||||
|
@ -413,7 +413,7 @@ void DefaultBtProgressInfoFileTest::testLoad_nonBt()
|
|||
// piece index 2
|
||||
SharedHandle<Piece> piece2 = inFlightPieces[1];
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)2, piece2->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)512, piece2->getLength());
|
||||
CPPUNIT_ASSERT_EQUAL(512, piece2->getLength());
|
||||
}
|
||||
|
||||
void DefaultBtProgressInfoFileTest::testLoad_nonBt_pieceLengthShorter()
|
||||
|
|
|
@ -236,7 +236,7 @@ void DefaultPieceStorageTest::testGetPiece() {
|
|||
|
||||
SharedHandle<Piece> pieceGot = pss.getPiece(0);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)0, pieceGot->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)128, pieceGot->getLength());
|
||||
CPPUNIT_ASSERT_EQUAL(128, pieceGot->getLength());
|
||||
CPPUNIT_ASSERT_EQUAL(false, pieceGot->pieceComplete());
|
||||
}
|
||||
|
||||
|
@ -247,7 +247,7 @@ void DefaultPieceStorageTest::testGetPieceInUsedPieces() {
|
|||
pss.addUsedPiece(piece);
|
||||
SharedHandle<Piece> pieceGot = pss.getPiece(0);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)0, pieceGot->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)128, pieceGot->getLength());
|
||||
CPPUNIT_ASSERT_EQUAL(128, pieceGot->getLength());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1, pieceGot->countCompleteBlock());
|
||||
}
|
||||
|
||||
|
@ -257,7 +257,7 @@ void DefaultPieceStorageTest::testGetPieceCompletedPiece() {
|
|||
pss.completePiece(piece);
|
||||
SharedHandle<Piece> pieceGot = pss.getPiece(0);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)0, pieceGot->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)128, pieceGot->getLength());
|
||||
CPPUNIT_ASSERT_EQUAL(128, pieceGot->getLength());
|
||||
CPPUNIT_ASSERT_EQUAL(true, pieceGot->pieceComplete());
|
||||
}
|
||||
|
||||
|
@ -334,7 +334,7 @@ void DefaultPieceStorageTest::testGetCompletedLength()
|
|||
p->completeBlock(j);
|
||||
}
|
||||
inFlightPieces.push_back(p);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)512*1024, p->getCompletedLength());
|
||||
CPPUNIT_ASSERT_EQUAL(512*1024, p->getCompletedLength());
|
||||
}
|
||||
ps.addInFlightPiece(inFlightPieces);
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ class GZipDecodingStreamFilterTest:public CppUnit::TestFixture {
|
|||
public:
|
||||
MockSegment2():positionToWrite_(0) {}
|
||||
|
||||
virtual void updateWrittenLength(size_t bytes)
|
||||
virtual void updateWrittenLength(int32_t bytes)
|
||||
{
|
||||
positionToWrite_ += bytes;
|
||||
}
|
||||
|
|
|
@ -36,9 +36,9 @@ void GrowSegmentTest::testClear()
|
|||
{
|
||||
GrowSegment segment(SharedHandle<Piece>(new Piece()));
|
||||
segment.updateWrittenLength(32*1024);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)32*1024, segment.getWrittenLength());
|
||||
CPPUNIT_ASSERT_EQUAL(32*1024, segment.getWrittenLength());
|
||||
segment.clear();
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)0, segment.getWrittenLength());
|
||||
CPPUNIT_ASSERT_EQUAL(0, segment.getWrittenLength());
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -81,7 +81,7 @@ void Metalink2RequestGroupTest::testGenerate()
|
|||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), dctx->getPieceHashType());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)2, dctx->getPieceHashes().size());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)262144, dctx->getPieceLength());
|
||||
CPPUNIT_ASSERT_EQUAL(262144, dctx->getPieceLength());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), dctx->getHashType());
|
||||
CPPUNIT_ASSERT_EQUAL
|
||||
(std::string("4c255b0ed130f5ea880f0aa061c3da0487e251cc"),
|
||||
|
|
|
@ -240,7 +240,7 @@ void MetalinkParserControllerTest::testChunkChecksumTransaction()
|
|||
SharedHandle<Metalinker> m = ctrl.getResult();
|
||||
SharedHandle<ChunkChecksum> md = m->getEntries().front()->chunkChecksum;
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("md5"), md->getHashType());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)256*1024, md->getPieceLength());
|
||||
CPPUNIT_ASSERT_EQUAL(256*1024, md->getPieceLength());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)5, md->countPieceHash());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("1cbd18db4cc2f85cedef654fccc4a4d8"),
|
||||
md->getPieceHashes()[0]);
|
||||
|
@ -284,7 +284,7 @@ void MetalinkParserControllerTest::testChunkChecksumTransactionV4()
|
|||
SharedHandle<Metalinker> m = ctrl.getResult();
|
||||
SharedHandle<ChunkChecksum> md = m->getEntries().front()->chunkChecksum;
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), md->getHashType());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)256*1024, md->getPieceLength());
|
||||
CPPUNIT_ASSERT_EQUAL(256*1024, md->getPieceLength());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)3, md->countPieceHash());
|
||||
CPPUNIT_ASSERT_EQUAL
|
||||
(std::string("5bd9f7248df0f3a6a86ab6c95f48787d546efa14"),
|
||||
|
|
|
@ -99,7 +99,7 @@ void MetalinkProcessorTest::testParseFileV4()
|
|||
CPPUNIT_ASSERT(e->chunkChecksum);
|
||||
if(MessageDigest::supports("sha-256")) {
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("sha-256"), e->chunkChecksum->getHashType());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)262144, e->chunkChecksum->getPieceLength());
|
||||
CPPUNIT_ASSERT_EQUAL(262144, e->chunkChecksum->getPieceLength());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)3, e->chunkChecksum->countPieceHash());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("0245178074fd042e19b7c3885b360fc21064b30e73f5626c7e3b005d048069c5"),
|
||||
util::toHex(e->chunkChecksum->getPieceHash(0)));
|
||||
|
@ -109,7 +109,7 @@ void MetalinkProcessorTest::testParseFileV4()
|
|||
util::toHex(e->chunkChecksum->getPieceHash(2)));
|
||||
} else {
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), e->chunkChecksum->getHashType());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)262144, e->chunkChecksum->getPieceLength());
|
||||
CPPUNIT_ASSERT_EQUAL(262144, e->chunkChecksum->getPieceLength());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)3, e->chunkChecksum->countPieceHash());
|
||||
CPPUNIT_ASSERT_EQUAL
|
||||
(std::string("5bd9f7248df0f3a6a86ab6c95f48787d546efa14"),
|
||||
|
@ -559,7 +559,7 @@ void MetalinkProcessorTest::testParseFile()
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("4c255b0ed130f5ea880f0aa061c3da0487e251cc"),
|
||||
util::toHex(entry2->checksum->getDigest()));
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)2, entry2->chunkChecksum->countPieceHash());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)262144, entry2->chunkChecksum->getPieceLength());
|
||||
CPPUNIT_ASSERT_EQUAL(262144, entry2->chunkChecksum->getPieceLength());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("179463a88d79cbf0b1923991708aead914f26142"),
|
||||
util::toHex(entry2->chunkChecksum->getPieceHash(0)));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("fecf8bc9a1647505fe16746f94e97a477597dbf3"),
|
||||
|
@ -887,7 +887,7 @@ void MetalinkProcessorTest::testMultiplePieces()
|
|||
SharedHandle<ChunkChecksum> c = e->chunkChecksum;
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), c->getHashType());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1024, c->getPieceLength());
|
||||
CPPUNIT_ASSERT_EQUAL(1024, c->getPieceLength());
|
||||
} catch(Exception& e) {
|
||||
CPPUNIT_FAIL(e.stackTrace());
|
||||
}
|
||||
|
@ -919,7 +919,7 @@ void MetalinkProcessorTest::testBadPieceNo()
|
|||
SharedHandle<ChunkChecksum> c = e->chunkChecksum;
|
||||
|
||||
CPPUNIT_ASSERT(c);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1024, c->getPieceLength());
|
||||
CPPUNIT_ASSERT_EQUAL(1024, c->getPieceLength());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), c->getHashType());
|
||||
} catch(Exception& e) {
|
||||
CPPUNIT_FAIL(e.stackTrace());
|
||||
|
@ -951,7 +951,7 @@ void MetalinkProcessorTest::testBadPieceLength()
|
|||
SharedHandle<MetalinkEntry> e = m->getEntries()[0];
|
||||
SharedHandle<ChunkChecksum> c = e->chunkChecksum;
|
||||
CPPUNIT_ASSERT(c);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1024, c->getPieceLength());
|
||||
CPPUNIT_ASSERT_EQUAL(1024, c->getPieceLength());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), c->getHashType());
|
||||
} catch(Exception& e) {
|
||||
CPPUNIT_FAIL(e.stackTrace());
|
||||
|
@ -983,7 +983,7 @@ void MetalinkProcessorTest::testUnsupportedType_piece()
|
|||
SharedHandle<ChunkChecksum> c = e->chunkChecksum;
|
||||
|
||||
CPPUNIT_ASSERT(c);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1024, c->getPieceLength());
|
||||
CPPUNIT_ASSERT_EQUAL(1024, c->getPieceLength());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("sha-1"), c->getHashType());
|
||||
} catch(Exception& e) {
|
||||
CPPUNIT_FAIL(e.stackTrace());
|
||||
|
|
|
@ -21,7 +21,7 @@ private:
|
|||
bool selectiveDownloadingMode;
|
||||
bool endGame;
|
||||
SharedHandle<DiskAdaptor> diskAdaptor;
|
||||
std::deque<size_t> pieceLengthList;
|
||||
std::deque<int32_t> pieceLengthList;
|
||||
std::deque<SharedHandle<Piece> > inFlightPieces;
|
||||
bool downloadFinished_;
|
||||
bool allDownloadFinished_;
|
||||
|
@ -230,11 +230,11 @@ public:
|
|||
this->diskAdaptor = adaptor;
|
||||
}
|
||||
|
||||
virtual size_t getPieceLength(size_t index) {
|
||||
virtual int32_t getPieceLength(size_t index) {
|
||||
return pieceLengthList.at(index);
|
||||
}
|
||||
|
||||
void addPieceLengthList(size_t length) {
|
||||
void addPieceLengthList(int32_t length) {
|
||||
pieceLengthList.push_back(length);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,28 +29,28 @@ public:
|
|||
return 0;
|
||||
}
|
||||
|
||||
virtual size_t getLength() const
|
||||
virtual int32_t getLength() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual size_t getSegmentLength() const
|
||||
virtual int32_t getSegmentLength() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual size_t getWrittenLength() const
|
||||
virtual int32_t getWrittenLength() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual void updateWrittenLength(size_t bytes) {}
|
||||
virtual void updateWrittenLength(int32_t bytes) {}
|
||||
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
|
||||
// `begin' is a offset inside this segment.
|
||||
virtual bool updateHash
|
||||
(uint32_t begin, const unsigned char* data, size_t dataLength)
|
||||
(int32_t begin, const unsigned char* data, size_t dataLength)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ void PieceTest::testCompleteBlock()
|
|||
|
||||
void PieceTest::testGetCompletedLength()
|
||||
{
|
||||
size_t blockLength = 16*1024;
|
||||
int32_t blockLength = 16*1024;
|
||||
Piece p(0, blockLength*10+100, blockLength);
|
||||
|
||||
p.completeBlock(1);
|
||||
|
|
|
@ -66,9 +66,9 @@ void SegmentManTest::testNullBitfield()
|
|||
SharedHandle<Segment> segment = segmentMan.getSegment(1, minSplitSize);
|
||||
CPPUNIT_ASSERT(segment);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)0, segment->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)0, segment->getLength());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)0, segment->getSegmentLength());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)0, segment->getWrittenLength());
|
||||
CPPUNIT_ASSERT_EQUAL(0, segment->getLength());
|
||||
CPPUNIT_ASSERT_EQUAL(0, segment->getSegmentLength());
|
||||
CPPUNIT_ASSERT_EQUAL(0, segment->getWrittenLength());
|
||||
|
||||
SharedHandle<Segment> segment2 = segmentMan.getSegment(2, minSplitSize);
|
||||
CPPUNIT_ASSERT(!segment2);
|
||||
|
|
|
@ -32,7 +32,7 @@ void SegmentTest::testUpdateWrittenLength()
|
|||
{
|
||||
SharedHandle<Piece> p(new Piece(0, 16*1024*10));
|
||||
PiecedSegment s(16*1024*10, p);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)0, s.getWrittenLength());
|
||||
CPPUNIT_ASSERT_EQUAL(0, s.getWrittenLength());
|
||||
|
||||
s.updateWrittenLength(16*1024);
|
||||
CPPUNIT_ASSERT(p->hasBlock(0));
|
||||
|
@ -67,9 +67,9 @@ void SegmentTest::testClear()
|
|||
SharedHandle<Piece> p(new Piece(0, 16*1024*10));
|
||||
PiecedSegment s(16*1024*10, p);
|
||||
s.updateWrittenLength(16*1024*10);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)16*1024*10, s.getWrittenLength());
|
||||
CPPUNIT_ASSERT_EQUAL(16*1024*10, s.getWrittenLength());
|
||||
s.clear();
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)0, s.getWrittenLength());
|
||||
CPPUNIT_ASSERT_EQUAL(0, s.getWrittenLength());
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue