mirror of https://github.com/aria2/aria2
2008-03-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Type clarification: size_t for length or size, uint64_t for file length, off_t for file offset. * src/DefaultBtProgressInfoFile.cc * src/DefaultBtContext.{h, cc} * src/DefaultBtInteractive.cc * src/DownloadCommand.{h, cc} * src/IteratableChunkChecksumValidator.{h, cc} * src/SegmentMan.{h, cc} * src/SingleFileDownloadContext.{h, cc} * src/IteratableChecksumValidator.{h, cc} * src/BtContext.h * src/IteratableValidator.h * src/DownloadContext.h * test/SingleFileDownloadContextTest.cc * test/DefaultBtContextTest.cc * test/MockBtContext.h * test/Metalink2RequestGroupTest.ccpull/1/head
parent
518a200d57
commit
c64a191061
20
ChangeLog
20
ChangeLog
|
@ -1,3 +1,23 @@
|
||||||
|
2008-03-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
|
Type clarification: size_t for length or size, uint64_t for file
|
||||||
|
length, off_t for file offset.
|
||||||
|
* src/DefaultBtProgressInfoFile.cc
|
||||||
|
* src/DefaultBtContext.{h, cc}
|
||||||
|
* src/DefaultBtInteractive.cc
|
||||||
|
* src/DownloadCommand.{h, cc}
|
||||||
|
* src/IteratableChunkChecksumValidator.{h, cc}
|
||||||
|
* src/SegmentMan.{h, cc}
|
||||||
|
* src/SingleFileDownloadContext.{h, cc}
|
||||||
|
* src/IteratableChecksumValidator.{h, cc}
|
||||||
|
* src/BtContext.h
|
||||||
|
* src/IteratableValidator.h
|
||||||
|
* src/DownloadContext.h
|
||||||
|
* test/SingleFileDownloadContextTest.cc
|
||||||
|
* test/DefaultBtContextTest.cc
|
||||||
|
* test/MockBtContext.h
|
||||||
|
* test/Metalink2RequestGroupTest.cc
|
||||||
|
|
||||||
2008-03-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
2008-03-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
Type clarification: size_t for length or size, uint64_t for file
|
Type clarification: size_t for length or size, uint64_t for file
|
||||||
|
|
|
@ -54,7 +54,7 @@ public:
|
||||||
|
|
||||||
virtual const unsigned char* getInfoHash() const = 0;
|
virtual const unsigned char* getInfoHash() const = 0;
|
||||||
|
|
||||||
virtual int32_t getInfoHashLength() const = 0;
|
virtual size_t getInfoHashLength() const = 0;
|
||||||
|
|
||||||
virtual std::string getInfoHashAsString() const = 0;
|
virtual std::string getInfoHashAsString() const = 0;
|
||||||
|
|
||||||
|
@ -73,8 +73,8 @@ public:
|
||||||
return _private;
|
return _private;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::deque<int32_t>
|
virtual std::deque<size_t>
|
||||||
computeFastSet(const std::string& ipaddr, int32_t fastSetSize) = 0;
|
computeFastSet(const std::string& ipaddr, size_t fastSetSize) = 0;
|
||||||
|
|
||||||
virtual RequestGroup* getOwnerRequestGroup() = 0;
|
virtual RequestGroup* getOwnerRequestGroup() = 0;
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ const unsigned char* DefaultBtContext::getInfoHash() const {
|
||||||
return infoHash;
|
return infoHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t DefaultBtContext::getInfoHashLength() const {
|
size_t DefaultBtContext::getInfoHashLength() const {
|
||||||
return INFO_HASH_LENGTH;
|
return INFO_HASH_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,8 +99,8 @@ void DefaultBtContext::clear() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtContext::extractPieceHash(const unsigned char* hashData,
|
void DefaultBtContext::extractPieceHash(const unsigned char* hashData,
|
||||||
int32_t hashDataLength,
|
size_t hashDataLength,
|
||||||
int32_t hashLength) {
|
size_t hashLength) {
|
||||||
int32_t numPieces = hashDataLength/hashLength;
|
int32_t numPieces = hashDataLength/hashLength;
|
||||||
for(int32_t i = 0; i < numPieces; i++) {
|
for(int32_t i = 0; i < numPieces; i++) {
|
||||||
pieceHashes.push_back(Util::toHex(&hashData[i*hashLength],
|
pieceHashes.push_back(Util::toHex(&hashData[i*hashLength],
|
||||||
|
@ -119,8 +119,8 @@ void DefaultBtContext::extractFileEntries(const Dictionary* infoDic,
|
||||||
}
|
}
|
||||||
const List* files = dynamic_cast<const List*>(infoDic->get("files"));
|
const List* files = dynamic_cast<const List*>(infoDic->get("files"));
|
||||||
if(files) {
|
if(files) {
|
||||||
int64_t length = 0;
|
uint64_t length = 0;
|
||||||
int64_t offset = 0;
|
off_t offset = 0;
|
||||||
// multi-file mode
|
// multi-file mode
|
||||||
fileMode = BtContext::MULTI;
|
fileMode = BtContext::MULTI;
|
||||||
const std::deque<MetaEntry*>& metaList = files->getList();
|
const std::deque<MetaEntry*>& metaList = files->getList();
|
||||||
|
@ -142,7 +142,7 @@ void DefaultBtContext::extractFileEntries(const Dictionary* infoDic,
|
||||||
}
|
}
|
||||||
const std::deque<MetaEntry*>& paths = pathList->getList();
|
const std::deque<MetaEntry*>& paths = pathList->getList();
|
||||||
std::string path;
|
std::string path;
|
||||||
for(int32_t i = 0; i < (int32_t)paths.size()-1; i++) {
|
for(size_t i = 0; i < paths.size()-1; i++) {
|
||||||
const Data* subpath = dynamic_cast<const Data*>(paths[i]);
|
const Data* subpath = dynamic_cast<const Data*>(paths[i]);
|
||||||
if(subpath) {
|
if(subpath) {
|
||||||
path += subpath->toString()+"/";
|
path += subpath->toString()+"/";
|
||||||
|
@ -259,7 +259,7 @@ void DefaultBtContext::extractNodes(const List* nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtContext::loadFromMemory(const unsigned char* content,
|
void DefaultBtContext::loadFromMemory(const unsigned char* content,
|
||||||
int32_t length,
|
size_t length,
|
||||||
const std::string& defaultName)
|
const std::string& defaultName)
|
||||||
{
|
{
|
||||||
SharedHandle<MetaEntry> rootEntry = MetaFileUtil::bdecoding(content, length);
|
SharedHandle<MetaEntry> rootEntry = MetaFileUtil::bdecoding(content, length);
|
||||||
|
@ -344,14 +344,15 @@ void DefaultBtContext::processRootDictionary(const Dictionary* rootDic, const st
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DefaultBtContext::getPieceHash(int32_t index) const {
|
std::string DefaultBtContext::getPieceHash(size_t index) const {
|
||||||
if(index < 0 || numPieces <= index) {
|
if(index < numPieces) {
|
||||||
|
return pieceHashes[index];
|
||||||
|
} else {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return pieceHashes[index];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t DefaultBtContext::getTotalLength() const {
|
uint64_t DefaultBtContext::getTotalLength() const {
|
||||||
return totalLength;
|
return totalLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,11 +372,11 @@ std::string DefaultBtContext::getName() const {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t DefaultBtContext::getPieceLength() const {
|
size_t DefaultBtContext::getPieceLength() const {
|
||||||
return pieceLength;
|
return pieceLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t DefaultBtContext::getNumPieces() const {
|
size_t DefaultBtContext::getNumPieces() const {
|
||||||
return numPieces;
|
return numPieces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384,9 +385,9 @@ std::string DefaultBtContext::getActualBasePath() const
|
||||||
return _dir+"/"+name;
|
return _dir+"/"+name;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::deque<int32_t> DefaultBtContext::computeFastSet(const std::string& ipaddr, int32_t fastSetSize)
|
std::deque<size_t> DefaultBtContext::computeFastSet(const std::string& ipaddr, size_t fastSetSize)
|
||||||
{
|
{
|
||||||
std::deque<int32_t> fastSet;
|
std::deque<size_t> fastSet;
|
||||||
unsigned char compact[6];
|
unsigned char compact[6];
|
||||||
if(!PeerMessageUtil::createcompact(compact, ipaddr, 0)) {
|
if(!PeerMessageUtil::createcompact(compact, ipaddr, 0)) {
|
||||||
return fastSet;
|
return fastSet;
|
||||||
|
@ -402,13 +403,13 @@ std::deque<int32_t> DefaultBtContext::computeFastSet(const std::string& ipaddr,
|
||||||
memcpy(tx+4, infoHash, 20);
|
memcpy(tx+4, infoHash, 20);
|
||||||
unsigned char x[20];
|
unsigned char x[20];
|
||||||
MessageDigestHelper::digest(x, sizeof(x), "sha1", tx, 24);
|
MessageDigestHelper::digest(x, sizeof(x), "sha1", tx, 24);
|
||||||
while((int32_t)fastSet.size() < fastSetSize) {
|
while(fastSet.size() < fastSetSize) {
|
||||||
for(int32_t i = 0; i < 5 && (int32_t)fastSet.size() < fastSetSize; i++) {
|
for(size_t i = 0; i < 5 && fastSet.size() < fastSetSize; i++) {
|
||||||
int32_t j = i*4;
|
size_t j = i*4;
|
||||||
uint32_t ny;
|
uint32_t ny;
|
||||||
memcpy(&ny, x+j, 4);
|
memcpy(&ny, x+j, 4);
|
||||||
uint32_t y = ntohl(ny);
|
uint32_t y = ntohl(ny);
|
||||||
int32_t index = y%numPieces;
|
size_t index = y%numPieces;
|
||||||
if(std::find(fastSet.begin(), fastSet.end(), index) == fastSet.end()) {
|
if(std::find(fastSet.begin(), fastSet.end(), index) == fastSet.end()) {
|
||||||
fastSet.push_back(index);
|
fastSet.push_back(index);
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,10 +57,10 @@ private:
|
||||||
std::deque<std::string> pieceHashes;
|
std::deque<std::string> pieceHashes;
|
||||||
std::deque<SharedHandle<FileEntry> > fileEntries;
|
std::deque<SharedHandle<FileEntry> > fileEntries;
|
||||||
FILE_MODE fileMode;
|
FILE_MODE fileMode;
|
||||||
int64_t totalLength;
|
uint64_t totalLength;
|
||||||
int32_t pieceLength;
|
size_t pieceLength;
|
||||||
std::string name;
|
std::string name;
|
||||||
int32_t numPieces;
|
size_t numPieces;
|
||||||
std::string peerId;
|
std::string peerId;
|
||||||
std::string _peerIdPrefix;
|
std::string _peerIdPrefix;
|
||||||
std::deque<SharedHandle<AnnounceTier> > announceTiers;
|
std::deque<SharedHandle<AnnounceTier> > announceTiers;
|
||||||
|
@ -73,8 +73,8 @@ private:
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
void extractPieceHash(const unsigned char* hashData,
|
void extractPieceHash(const unsigned char* hashData,
|
||||||
int32_t hashDataLength,
|
size_t hashDataLength,
|
||||||
int32_t hashLength);
|
size_t hashLength);
|
||||||
void extractFileEntries(const Dictionary* infoDic,
|
void extractFileEntries(const Dictionary* infoDic,
|
||||||
const std::string& defaultName,
|
const std::string& defaultName,
|
||||||
const std::deque<std::string>& urlList);
|
const std::deque<std::string>& urlList);
|
||||||
|
@ -93,18 +93,18 @@ private:
|
||||||
|
|
||||||
virtual const unsigned char* getInfoHash() const;
|
virtual const unsigned char* getInfoHash() const;
|
||||||
|
|
||||||
virtual int32_t getInfoHashLength() const;
|
virtual size_t getInfoHashLength() const;
|
||||||
|
|
||||||
virtual std::string getInfoHashAsString() const;
|
virtual std::string getInfoHashAsString() const;
|
||||||
|
|
||||||
virtual std::string getPieceHash(int32_t index) const;
|
virtual std::string getPieceHash(size_t index) const;
|
||||||
|
|
||||||
virtual const std::deque<std::string>& getPieceHashes() const
|
virtual const std::deque<std::string>& getPieceHashes() const
|
||||||
{
|
{
|
||||||
return pieceHashes;
|
return pieceHashes;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int64_t getTotalLength() const;
|
virtual uint64_t getTotalLength() const;
|
||||||
|
|
||||||
virtual FILE_MODE getFileMode() const;
|
virtual FILE_MODE getFileMode() const;
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ private:
|
||||||
|
|
||||||
virtual void load(const std::string& torrentFile);
|
virtual void load(const std::string& torrentFile);
|
||||||
|
|
||||||
void loadFromMemory(const unsigned char* content, int32_t length,
|
void loadFromMemory(const unsigned char* content, size_t length,
|
||||||
const std::string& defaultName);
|
const std::string& defaultName);
|
||||||
|
|
||||||
void loadFromMemory(const std::string& context, const std::string& defaultName)
|
void loadFromMemory(const std::string& context, const std::string& defaultName)
|
||||||
|
@ -130,9 +130,9 @@ private:
|
||||||
|
|
||||||
virtual std::string getName() const;
|
virtual std::string getName() const;
|
||||||
|
|
||||||
virtual int32_t getPieceLength() const;
|
virtual size_t getPieceLength() const;
|
||||||
|
|
||||||
virtual int32_t getNumPieces() const;
|
virtual size_t getNumPieces() const;
|
||||||
|
|
||||||
virtual std::string getActualBasePath() const;
|
virtual std::string getActualBasePath() const;
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ private:
|
||||||
return reinterpret_cast<const unsigned char*>(peerId.c_str());
|
return reinterpret_cast<const unsigned char*>(peerId.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::deque<int32_t> computeFastSet(const std::string& ipaddr, int32_t fastSetSize);
|
virtual std::deque<size_t> computeFastSet(const std::string& ipaddr, size_t fastSetSize);
|
||||||
|
|
||||||
virtual RequestGroup* getOwnerRequestGroup()
|
virtual RequestGroup* getOwnerRequestGroup()
|
||||||
{
|
{
|
||||||
|
@ -165,7 +165,7 @@ private:
|
||||||
memcpy(this->infoHash, infoHash, sizeof(this->infoHash));
|
memcpy(this->infoHash, infoHash, sizeof(this->infoHash));
|
||||||
}
|
}
|
||||||
|
|
||||||
void setNumPieces(int32_t numPieces)
|
void setNumPieces(size_t numPieces)
|
||||||
{
|
{
|
||||||
this->numPieces = numPieces;
|
this->numPieces = numPieces;
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,9 +177,9 @@ void DefaultBtInteractive::addBitfieldMessageToQueue() {
|
||||||
|
|
||||||
void DefaultBtInteractive::addAllowedFastMessageToQueue() {
|
void DefaultBtInteractive::addAllowedFastMessageToQueue() {
|
||||||
if(peer->isFastExtensionEnabled()) {
|
if(peer->isFastExtensionEnabled()) {
|
||||||
std::deque<int32_t> fastSet = btContext->computeFastSet(peer->ipaddr,
|
std::deque<size_t> fastSet = btContext->computeFastSet(peer->ipaddr,
|
||||||
allowedFastSetSize);
|
allowedFastSetSize);
|
||||||
for(std::deque<int32_t>::const_iterator itr = fastSet.begin();
|
for(std::deque<size_t>::const_iterator itr = fastSet.begin();
|
||||||
itr != fastSet.end(); itr++) {
|
itr != fastSet.end(); itr++) {
|
||||||
dispatcher->addMessageToQueue(messageFactory->createAllowedFastMessage(*itr));
|
dispatcher->addMessageToQueue(messageFactory->createAllowedFastMessage(*itr));
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,8 +83,8 @@ void DefaultBtProgressInfoFile::save() {
|
||||||
bool torrentDownload = isTorrentDownload();
|
bool torrentDownload = isTorrentDownload();
|
||||||
// file version: 16 bits
|
// file version: 16 bits
|
||||||
// value: '0'
|
// value: '0'
|
||||||
int16_t version = 0;
|
uint16_t version = 0;
|
||||||
o.write(reinterpret_cast<const char*>(&version), sizeof(int16_t));
|
o.write(reinterpret_cast<const char*>(&version), sizeof(version));
|
||||||
// extension: 32 bits
|
// extension: 32 bits
|
||||||
// If this is BitTorrent download, then 0x00000001
|
// If this is BitTorrent download, then 0x00000001
|
||||||
// Otherwise, 0x00000000
|
// Otherwise, 0x00000000
|
||||||
|
@ -98,49 +98,49 @@ void DefaultBtProgressInfoFile::save() {
|
||||||
// infoHashLength:
|
// infoHashLength:
|
||||||
// length: 32 bits
|
// length: 32 bits
|
||||||
BtContextHandle btContext = _dctx;
|
BtContextHandle btContext = _dctx;
|
||||||
int32_t infoHashLength = btContext->getInfoHashLength();
|
uint32_t infoHashLength = btContext->getInfoHashLength();
|
||||||
o.write(reinterpret_cast<const char*>(&infoHashLength), sizeof(int32_t));
|
o.write(reinterpret_cast<const char*>(&infoHashLength), sizeof(infoHashLength));
|
||||||
// infoHash:
|
// infoHash:
|
||||||
o.write(reinterpret_cast<const char*>(btContext->getInfoHash()),
|
o.write(reinterpret_cast<const char*>(btContext->getInfoHash()),
|
||||||
btContext->getInfoHashLength());
|
btContext->getInfoHashLength());
|
||||||
} else {
|
} else {
|
||||||
// infoHashLength:
|
// infoHashLength:
|
||||||
// length: 32 bits
|
// length: 32 bits
|
||||||
int32_t infoHashLength = 0;
|
uint32_t infoHashLength = 0;
|
||||||
o.write(reinterpret_cast<const char*>(&infoHashLength), sizeof(int32_t));
|
o.write(reinterpret_cast<const char*>(&infoHashLength), sizeof(infoHashLength));
|
||||||
}
|
}
|
||||||
// pieceLength: 32 bits
|
// pieceLength: 32 bits
|
||||||
int32_t pieceLength = _dctx->getPieceLength();
|
uint32_t pieceLength = _dctx->getPieceLength();
|
||||||
o.write(reinterpret_cast<const char*>(&pieceLength), sizeof(int32_t));
|
o.write(reinterpret_cast<const char*>(&pieceLength), sizeof(pieceLength));
|
||||||
// totalLength: 64 bits
|
// totalLength: 64 bits
|
||||||
int64_t totalLength = _dctx->getTotalLength();
|
uint64_t totalLength = _dctx->getTotalLength();
|
||||||
o.write(reinterpret_cast<const char*>(&totalLength), sizeof(int64_t));
|
o.write(reinterpret_cast<const char*>(&totalLength), sizeof(totalLength));
|
||||||
// uploadLength: 64 bits
|
// uploadLength: 64 bits
|
||||||
int64_t uploadLength = 0;
|
uint64_t uploadLength = 0;
|
||||||
if(torrentDownload) {
|
if(torrentDownload) {
|
||||||
BtContextHandle btContext = _dctx;
|
BtContextHandle btContext = _dctx;
|
||||||
TransferStat stat = PEER_STORAGE(btContext)->calculateStat();
|
TransferStat stat = PEER_STORAGE(btContext)->calculateStat();
|
||||||
uploadLength = stat.getAllTimeUploadLength();
|
uploadLength = stat.getAllTimeUploadLength();
|
||||||
}
|
}
|
||||||
o.write(reinterpret_cast<const char*>(&uploadLength), sizeof(int64_t));
|
o.write(reinterpret_cast<const char*>(&uploadLength), sizeof(uploadLength));
|
||||||
// bitfieldLength: 32 bits
|
// bitfieldLength: 32 bits
|
||||||
int32_t bitfieldLength = _pieceStorage->getBitfieldLength();
|
uint32_t bitfieldLength = _pieceStorage->getBitfieldLength();
|
||||||
o.write(reinterpret_cast<const char*>(&bitfieldLength), sizeof(int32_t));
|
o.write(reinterpret_cast<const char*>(&bitfieldLength), sizeof(bitfieldLength));
|
||||||
// bitfield
|
// bitfield
|
||||||
o.write(reinterpret_cast<const char*>(_pieceStorage->getBitfield()), _pieceStorage->getBitfieldLength());
|
o.write(reinterpret_cast<const char*>(_pieceStorage->getBitfield()), _pieceStorage->getBitfieldLength());
|
||||||
// the number of in-flight piece: 32 bits
|
// the number of in-flight piece: 32 bits
|
||||||
// TODO implement this
|
// TODO implement this
|
||||||
int32_t numInFlightPiece = _pieceStorage->countInFlightPiece();
|
uint32_t numInFlightPiece = _pieceStorage->countInFlightPiece();
|
||||||
o.write(reinterpret_cast<const char*>(&numInFlightPiece), sizeof(int32_t));
|
o.write(reinterpret_cast<const char*>(&numInFlightPiece), sizeof(numInFlightPiece));
|
||||||
Pieces inFlightPieces = _pieceStorage->getInFlightPieces();
|
Pieces inFlightPieces = _pieceStorage->getInFlightPieces();
|
||||||
for(Pieces::const_iterator itr = inFlightPieces.begin();
|
for(Pieces::const_iterator itr = inFlightPieces.begin();
|
||||||
itr != inFlightPieces.end(); ++itr) {
|
itr != inFlightPieces.end(); ++itr) {
|
||||||
int32_t index = (*itr)->getIndex();
|
uint32_t index = (*itr)->getIndex();
|
||||||
o.write(reinterpret_cast<const char*>(&index), sizeof(int32_t));
|
o.write(reinterpret_cast<const char*>(&index), sizeof(index));
|
||||||
int32_t length = (*itr)->getLength();
|
uint32_t length = (*itr)->getLength();
|
||||||
o.write(reinterpret_cast<const char*>(&length), sizeof(int32_t));
|
o.write(reinterpret_cast<const char*>(&length), sizeof(length));
|
||||||
int32_t bitfieldLength = (*itr)->getBitfieldLength();
|
uint32_t bitfieldLength = (*itr)->getBitfieldLength();
|
||||||
o.write(reinterpret_cast<const char*>(&bitfieldLength), sizeof(int32_t));
|
o.write(reinterpret_cast<const char*>(&bitfieldLength), sizeof(bitfieldLength));
|
||||||
o.write(reinterpret_cast<const char*>((*itr)->getBitfield()), bitfieldLength);
|
o.write(reinterpret_cast<const char*>((*itr)->getBitfield()), bitfieldLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ void DefaultBtProgressInfoFile::load()
|
||||||
_logger->debug("InfoHash checking enabled.");
|
_logger->debug("InfoHash checking enabled.");
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t infoHashLength;
|
uint32_t infoHashLength;
|
||||||
in.read(reinterpret_cast<char*>(&infoHashLength), sizeof(infoHashLength));
|
in.read(reinterpret_cast<char*>(&infoHashLength), sizeof(infoHashLength));
|
||||||
if(infoHashLength < 0 || infoHashLength == 0 && infoHashCheckEnabled) {
|
if(infoHashLength < 0 || infoHashLength == 0 && infoHashCheckEnabled) {
|
||||||
throw new DlAbortEx("Invalid info hash length: %d", infoHashLength);
|
throw new DlAbortEx("Invalid info hash length: %d", infoHashLength);
|
||||||
|
@ -199,26 +199,26 @@ void DefaultBtProgressInfoFile::load()
|
||||||
savedInfoHash = 0;
|
savedInfoHash = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t pieceLength;
|
uint32_t pieceLength;
|
||||||
in.read(reinterpret_cast<char*>(&pieceLength), sizeof(pieceLength));
|
in.read(reinterpret_cast<char*>(&pieceLength), sizeof(pieceLength));
|
||||||
|
|
||||||
int64_t totalLength;
|
uint64_t totalLength;
|
||||||
in.read(reinterpret_cast<char*>(&totalLength), sizeof(totalLength));
|
in.read(reinterpret_cast<char*>(&totalLength), sizeof(totalLength));
|
||||||
if(totalLength != _dctx->getTotalLength()) {
|
if(totalLength != _dctx->getTotalLength()) {
|
||||||
throw new DlAbortEx("total length mismatch. expected: %s, actual: %s",
|
throw new DlAbortEx("total length mismatch. expected: %s, actual: %s",
|
||||||
Util::itos(_dctx->getTotalLength()).c_str(),
|
Util::itos(_dctx->getTotalLength()).c_str(),
|
||||||
Util::itos(totalLength).c_str());
|
Util::itos(totalLength).c_str());
|
||||||
}
|
}
|
||||||
int64_t uploadLength;
|
uint64_t uploadLength;
|
||||||
in.read(reinterpret_cast<char*>(&uploadLength), sizeof(uploadLength));
|
in.read(reinterpret_cast<char*>(&uploadLength), sizeof(uploadLength));
|
||||||
if(isTorrentDownload()) {
|
if(isTorrentDownload()) {
|
||||||
BT_RUNTIME(BtContextHandle(_dctx))->setUploadLengthAtStartup(uploadLength);
|
BT_RUNTIME(BtContextHandle(_dctx))->setUploadLengthAtStartup(uploadLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO implement the conversion mechanism between different piece length.
|
// TODO implement the conversion mechanism between different piece length.
|
||||||
int32_t bitfieldLength;
|
uint32_t bitfieldLength;
|
||||||
in.read(reinterpret_cast<char*>(&bitfieldLength), sizeof(bitfieldLength));
|
in.read(reinterpret_cast<char*>(&bitfieldLength), sizeof(bitfieldLength));
|
||||||
int32_t expectedBitfieldLength = ((totalLength+pieceLength-1)/pieceLength+7)/8;
|
uint32_t expectedBitfieldLength = ((totalLength+pieceLength-1)/pieceLength+7)/8;
|
||||||
if(expectedBitfieldLength != bitfieldLength) {
|
if(expectedBitfieldLength != bitfieldLength) {
|
||||||
throw new DlAbortEx("bitfield length mismatch. expected: %d, actual: %d",
|
throw new DlAbortEx("bitfield length mismatch. expected: %d, actual: %d",
|
||||||
expectedBitfieldLength,
|
expectedBitfieldLength,
|
||||||
|
|
|
@ -162,7 +162,7 @@ void DownloadCommand::checkLowestDownloadSpeed() const
|
||||||
{
|
{
|
||||||
// calculate downloading speed
|
// calculate downloading speed
|
||||||
if(peerStat->getDownloadStartTime().elapsed(startupIdleTime)) {
|
if(peerStat->getDownloadStartTime().elapsed(startupIdleTime)) {
|
||||||
int32_t nowSpeed = peerStat->calculateDownloadSpeed();
|
unsigned int nowSpeed = peerStat->calculateDownloadSpeed();
|
||||||
if(lowestDownloadSpeedLimit > 0 && nowSpeed <= lowestDownloadSpeedLimit) {
|
if(lowestDownloadSpeedLimit > 0 && nowSpeed <= lowestDownloadSpeedLimit) {
|
||||||
throw new DlAbortEx(EX_TOO_SLOW_DOWNLOAD_SPEED,
|
throw new DlAbortEx(EX_TOO_SLOW_DOWNLOAD_SPEED,
|
||||||
nowSpeed,
|
nowSpeed,
|
||||||
|
|
|
@ -47,9 +47,9 @@ class MessageDigestContext;
|
||||||
|
|
||||||
class DownloadCommand : public AbstractCommand {
|
class DownloadCommand : public AbstractCommand {
|
||||||
private:
|
private:
|
||||||
int32_t maxDownloadSpeedLimit;
|
unsigned int maxDownloadSpeedLimit;
|
||||||
int32_t startupIdleTime;
|
time_t startupIdleTime;
|
||||||
int32_t lowestDownloadSpeedLimit;
|
unsigned int lowestDownloadSpeedLimit;
|
||||||
SharedHandle<PeerStat> peerStat;
|
SharedHandle<PeerStat> peerStat;
|
||||||
#ifdef ENABLE_MESSAGE_DIGEST
|
#ifdef ENABLE_MESSAGE_DIGEST
|
||||||
MessageDigestContext* _messageDigestContext;
|
MessageDigestContext* _messageDigestContext;
|
||||||
|
@ -75,15 +75,15 @@ public:
|
||||||
|
|
||||||
void setTransferDecoder(const SharedHandle<TransferEncoding>& transferDecoder);
|
void setTransferDecoder(const SharedHandle<TransferEncoding>& transferDecoder);
|
||||||
|
|
||||||
void setMaxDownloadSpeedLimit(int32_t maxDownloadSpeedLimit) {
|
void setMaxDownloadSpeedLimit(unsigned int maxDownloadSpeedLimit) {
|
||||||
this->maxDownloadSpeedLimit = maxDownloadSpeedLimit;
|
this->maxDownloadSpeedLimit = maxDownloadSpeedLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setStartupIdleTime(int32_t startupIdleTime) {
|
void setStartupIdleTime(time_t startupIdleTime) {
|
||||||
this->startupIdleTime = startupIdleTime;
|
this->startupIdleTime = startupIdleTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setLowestDownloadSpeedLimit(int32_t lowestDownloadSpeedLimit) {
|
void setLowestDownloadSpeedLimit(unsigned int lowestDownloadSpeedLimit) {
|
||||||
this->lowestDownloadSpeedLimit = lowestDownloadSpeedLimit;
|
this->lowestDownloadSpeedLimit = lowestDownloadSpeedLimit;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -60,11 +60,11 @@ public:
|
||||||
MULTI
|
MULTI
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual std::string getPieceHash(int32_t index) const = 0;
|
virtual std::string getPieceHash(size_t index) const = 0;
|
||||||
|
|
||||||
virtual const std::deque<std::string>& getPieceHashes() const = 0;
|
virtual const std::deque<std::string>& getPieceHashes() const = 0;
|
||||||
|
|
||||||
virtual int64_t getTotalLength() const = 0;
|
virtual uint64_t getTotalLength() const = 0;
|
||||||
|
|
||||||
virtual FILE_MODE getFileMode() const = 0;
|
virtual FILE_MODE getFileMode() const = 0;
|
||||||
|
|
||||||
|
@ -72,9 +72,9 @@ public:
|
||||||
|
|
||||||
virtual std::string getName() const = 0;
|
virtual std::string getName() const = 0;
|
||||||
|
|
||||||
virtual int32_t getPieceLength() const = 0;
|
virtual size_t getPieceLength() const = 0;
|
||||||
|
|
||||||
virtual int32_t getNumPieces() const = 0;
|
virtual size_t getNumPieces() const = 0;
|
||||||
|
|
||||||
virtual std::string getPieceHashAlgo() const = 0;
|
virtual std::string getPieceHashAlgo() const = 0;
|
||||||
|
|
||||||
|
|
|
@ -66,9 +66,9 @@ IteratableChecksumValidator::~IteratableChecksumValidator()
|
||||||
void IteratableChecksumValidator::validateChunk()
|
void IteratableChecksumValidator::validateChunk()
|
||||||
{
|
{
|
||||||
if(!finished()) {
|
if(!finished()) {
|
||||||
int32_t length = _pieceStorage->getDiskAdaptor()->readData(_buffer,
|
size_t length = _pieceStorage->getDiskAdaptor()->readData(_buffer,
|
||||||
BUFSIZE,
|
BUFSIZE,
|
||||||
_currentOffset);
|
_currentOffset);
|
||||||
_ctx->digestUpdate(_buffer, length);
|
_ctx->digestUpdate(_buffer, length);
|
||||||
_currentOffset += length;
|
_currentOffset += length;
|
||||||
if(finished()) {
|
if(finished()) {
|
||||||
|
@ -85,7 +85,7 @@ void IteratableChecksumValidator::validateChunk()
|
||||||
|
|
||||||
bool IteratableChecksumValidator::finished() const
|
bool IteratableChecksumValidator::finished() const
|
||||||
{
|
{
|
||||||
if(_currentOffset >= _dctx->getTotalLength()) {
|
if((uint16_t)_currentOffset >= _dctx->getTotalLength()) {
|
||||||
_pieceStorage->getDiskAdaptor()->disableDirectIO();
|
_pieceStorage->getDiskAdaptor()->disableDirectIO();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -93,7 +93,7 @@ bool IteratableChecksumValidator::finished() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t IteratableChecksumValidator::getTotalLength() const
|
uint64_t IteratableChecksumValidator::getTotalLength() const
|
||||||
{
|
{
|
||||||
return _dctx->getTotalLength();
|
return _dctx->getTotalLength();
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ private:
|
||||||
|
|
||||||
SharedHandle<PieceStorage> _pieceStorage;
|
SharedHandle<PieceStorage> _pieceStorage;
|
||||||
|
|
||||||
int64_t _currentOffset;
|
off_t _currentOffset;
|
||||||
|
|
||||||
SharedHandle<MessageDigestContext> _ctx;
|
SharedHandle<MessageDigestContext> _ctx;
|
||||||
|
|
||||||
|
@ -71,12 +71,12 @@ public:
|
||||||
|
|
||||||
virtual bool finished() const;
|
virtual bool finished() const;
|
||||||
|
|
||||||
virtual int64_t getCurrentOffset() const
|
virtual off_t getCurrentOffset() const
|
||||||
{
|
{
|
||||||
return _currentOffset;
|
return _currentOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int64_t getTotalLength() const;
|
virtual uint64_t getTotalLength() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<IteratableChecksumValidator> IteratableChecksumValidatorHandle;
|
typedef SharedHandle<IteratableChecksumValidator> IteratableChecksumValidatorHandle;
|
||||||
|
|
|
@ -101,10 +101,10 @@ void IteratableChunkChecksumValidator::validateChunk()
|
||||||
|
|
||||||
std::string IteratableChunkChecksumValidator::calculateActualChecksum()
|
std::string IteratableChunkChecksumValidator::calculateActualChecksum()
|
||||||
{
|
{
|
||||||
int64_t offset = getCurrentOffset();
|
off_t offset = getCurrentOffset();
|
||||||
int32_t length;
|
size_t length;
|
||||||
// When validating last piece
|
// When validating last piece
|
||||||
if(_currentIndex+1 == (uint32_t)_dctx->getNumPieces()) {
|
if(_currentIndex+1 == _dctx->getNumPieces()) {
|
||||||
length = _dctx->getTotalLength()-offset;
|
length = _dctx->getTotalLength()-offset;
|
||||||
} else {
|
} else {
|
||||||
length = _dctx->getPieceLength();
|
length = _dctx->getPieceLength();
|
||||||
|
@ -129,25 +129,25 @@ void IteratableChunkChecksumValidator::init()
|
||||||
_currentIndex = 0;
|
_currentIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string IteratableChunkChecksumValidator::digest(int64_t offset, int32_t length)
|
std::string IteratableChunkChecksumValidator::digest(off_t offset, size_t length)
|
||||||
{
|
{
|
||||||
_ctx->digestReset();
|
_ctx->digestReset();
|
||||||
int64_t curoffset = offset/ALIGNMENT*ALIGNMENT;
|
off_t curoffset = offset/ALIGNMENT*ALIGNMENT;
|
||||||
int64_t max = offset+length;
|
off_t max = offset+length;
|
||||||
int32_t woffset;
|
off_t woffset;
|
||||||
if(curoffset < offset) {
|
if(curoffset < offset) {
|
||||||
woffset = offset-curoffset;
|
woffset = offset-curoffset;
|
||||||
} else {
|
} else {
|
||||||
woffset = 0;
|
woffset = 0;
|
||||||
}
|
}
|
||||||
while(curoffset < max) {
|
while(curoffset < max) {
|
||||||
int32_t r = _pieceStorage->getDiskAdaptor()->readData(_buffer, BUFSIZE,
|
size_t r = _pieceStorage->getDiskAdaptor()->readData(_buffer, BUFSIZE,
|
||||||
curoffset);
|
curoffset);
|
||||||
if(r == 0) {
|
if(r == 0) {
|
||||||
throw new DlAbortEx(EX_FILE_READ, _dctx->getActualBasePath().c_str(),
|
throw new DlAbortEx(EX_FILE_READ, _dctx->getActualBasePath().c_str(),
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
}
|
}
|
||||||
int32_t wlength;
|
size_t wlength;
|
||||||
if(max < curoffset+r) {
|
if(max < curoffset+r) {
|
||||||
wlength = max-curoffset-woffset;
|
wlength = max-curoffset-woffset;
|
||||||
} else {
|
} else {
|
||||||
|
@ -163,7 +163,7 @@ std::string IteratableChunkChecksumValidator::digest(int64_t offset, int32_t len
|
||||||
|
|
||||||
bool IteratableChunkChecksumValidator::finished() const
|
bool IteratableChunkChecksumValidator::finished() const
|
||||||
{
|
{
|
||||||
if(_currentIndex >= (uint32_t)_dctx->getNumPieces()) {
|
if(_currentIndex >= _dctx->getNumPieces()) {
|
||||||
_pieceStorage->getDiskAdaptor()->disableDirectIO();
|
_pieceStorage->getDiskAdaptor()->disableDirectIO();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -171,12 +171,12 @@ bool IteratableChunkChecksumValidator::finished() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t IteratableChunkChecksumValidator::getCurrentOffset() const
|
off_t IteratableChunkChecksumValidator::getCurrentOffset() const
|
||||||
{
|
{
|
||||||
return (int64_t)_currentIndex*_dctx->getPieceLength();
|
return (off_t)_currentIndex*_dctx->getPieceLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t IteratableChunkChecksumValidator::getTotalLength() const
|
uint64_t IteratableChunkChecksumValidator::getTotalLength() const
|
||||||
{
|
{
|
||||||
return _dctx->getTotalLength();
|
return _dctx->getTotalLength();
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,14 +51,14 @@ private:
|
||||||
SharedHandle<DownloadContext> _dctx;
|
SharedHandle<DownloadContext> _dctx;
|
||||||
SharedHandle<PieceStorage> _pieceStorage;
|
SharedHandle<PieceStorage> _pieceStorage;
|
||||||
BitfieldMan* _bitfield;
|
BitfieldMan* _bitfield;
|
||||||
uint32_t _currentIndex;
|
size_t _currentIndex;
|
||||||
const Logger* _logger;
|
const Logger* _logger;
|
||||||
SharedHandle<MessageDigestContext> _ctx;
|
SharedHandle<MessageDigestContext> _ctx;
|
||||||
unsigned char* _buffer;
|
unsigned char* _buffer;
|
||||||
|
|
||||||
std::string calculateActualChecksum();
|
std::string calculateActualChecksum();
|
||||||
|
|
||||||
std::string digest(int64_t offset, int32_t length);
|
std::string digest(off_t offset, size_t length);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IteratableChunkChecksumValidator(const SharedHandle<DownloadContext>& dctx,
|
IteratableChunkChecksumValidator(const SharedHandle<DownloadContext>& dctx,
|
||||||
|
@ -72,9 +72,9 @@ public:
|
||||||
|
|
||||||
virtual bool finished() const;
|
virtual bool finished() const;
|
||||||
|
|
||||||
virtual int64_t getCurrentOffset() const;
|
virtual off_t getCurrentOffset() const;
|
||||||
|
|
||||||
virtual int64_t getTotalLength() const;
|
virtual uint64_t getTotalLength() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<IteratableChunkChecksumValidator> IteratableChunkChecksumValidatorHandle;
|
typedef SharedHandle<IteratableChunkChecksumValidator> IteratableChunkChecksumValidatorHandle;
|
||||||
|
|
|
@ -59,9 +59,9 @@ public:
|
||||||
|
|
||||||
virtual bool finished() const = 0;
|
virtual bool finished() const = 0;
|
||||||
|
|
||||||
virtual int64_t getCurrentOffset() const = 0;
|
virtual off_t getCurrentOffset() const = 0;
|
||||||
|
|
||||||
virtual int64_t getTotalLength() const = 0;
|
virtual uint64_t getTotalLength() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<IteratableValidator> IteratableValidatorHandle;
|
typedef SharedHandle<IteratableValidator> IteratableValidatorHandle;
|
||||||
|
|
|
@ -78,7 +78,7 @@ void SegmentMan::init()
|
||||||
// TODO Do we have to do something about DownloadContext and PieceStorage here?
|
// TODO Do we have to do something about DownloadContext and PieceStorage here?
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t SegmentMan::getTotalLength() const
|
uint64_t SegmentMan::getTotalLength() const
|
||||||
{
|
{
|
||||||
if(_pieceStorage.isNull()) {
|
if(_pieceStorage.isNull()) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -123,7 +123,7 @@ SegmentHandle SegmentMan::checkoutSegment(int32_t cuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
SegmentEntryHandle SegmentMan::findSlowerSegmentEntry(const PeerStatHandle& peerStat) const {
|
SegmentEntryHandle SegmentMan::findSlowerSegmentEntry(const PeerStatHandle& peerStat) const {
|
||||||
int32_t speed = (int32_t)(peerStat->getAvgDownloadSpeed()*0.8);
|
unsigned int speed = peerStat->getAvgDownloadSpeed()*0.8;
|
||||||
SegmentEntryHandle slowSegmentEntry(0);
|
SegmentEntryHandle slowSegmentEntry(0);
|
||||||
for(SegmentEntries::const_iterator itr = usedSegmentEntries.begin();
|
for(SegmentEntries::const_iterator itr = usedSegmentEntries.begin();
|
||||||
itr != usedSegmentEntries.end(); ++itr) {
|
itr != usedSegmentEntries.end(); ++itr) {
|
||||||
|
@ -137,7 +137,7 @@ SegmentEntryHandle SegmentMan::findSlowerSegmentEntry(const PeerStatHandle& peer
|
||||||
!p->getDownloadStartTime().elapsed(_option->getAsInt(PREF_STARTUP_IDLE_TIME))) {
|
!p->getDownloadStartTime().elapsed(_option->getAsInt(PREF_STARTUP_IDLE_TIME))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int32_t pSpeed = p->calculateDownloadSpeed();
|
unsigned int pSpeed = p->calculateDownloadSpeed();
|
||||||
if(pSpeed < speed) {
|
if(pSpeed < speed) {
|
||||||
speed = pSpeed;
|
speed = pSpeed;
|
||||||
slowSegmentEntry = segmentEntry;
|
slowSegmentEntry = segmentEntry;
|
||||||
|
@ -184,8 +184,8 @@ SegmentHandle SegmentMan::getSegment(int32_t cuid) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SegmentHandle SegmentMan::getSegment(int32_t cuid, int32_t index) {
|
SegmentHandle SegmentMan::getSegment(int32_t cuid, size_t index) {
|
||||||
if(index < 0 || _downloadContext->getNumPieces() <= index) {
|
if(_downloadContext->getNumPieces() <= index) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return checkoutSegment(cuid, _pieceStorage->getMissingPiece(index));
|
return checkoutSegment(cuid, _pieceStorage->getMissingPiece(index));
|
||||||
|
@ -229,11 +229,11 @@ bool SegmentMan::completeSegment(int32_t cuid, const SegmentHandle& segment) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SegmentMan::hasSegment(int32_t index) const {
|
bool SegmentMan::hasSegment(size_t index) const {
|
||||||
return _pieceStorage->hasPiece(index);
|
return _pieceStorage->hasPiece(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t SegmentMan::getDownloadLength() const {
|
uint64_t SegmentMan::getDownloadLength() const {
|
||||||
if(_pieceStorage.isNull()) {
|
if(_pieceStorage.isNull()) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -259,8 +259,8 @@ PeerStatHandle SegmentMan::getPeerStat(int32_t cuid) const
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t SegmentMan::calculateDownloadSpeed() const {
|
unsigned int SegmentMan::calculateDownloadSpeed() const {
|
||||||
int32_t speed = 0;
|
unsigned int speed = 0;
|
||||||
for(std::deque<SharedHandle<PeerStat> >::const_iterator itr = peerStats.begin(); itr != peerStats.end(); itr++) {
|
for(std::deque<SharedHandle<PeerStat> >::const_iterator itr = peerStats.begin(); itr != peerStats.end(); itr++) {
|
||||||
const PeerStatHandle& peerStat = *itr;
|
const PeerStatHandle& peerStat = *itr;
|
||||||
if(peerStat->getStatus() == PeerStat::ACTIVE) {
|
if(peerStat->getStatus() == PeerStat::ACTIVE) {
|
||||||
|
@ -270,9 +270,10 @@ int32_t SegmentMan::calculateDownloadSpeed() const {
|
||||||
return speed;
|
return speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t SegmentMan::countFreePieceFrom(int32_t index) const
|
size_t SegmentMan::countFreePieceFrom(size_t index) const
|
||||||
{
|
{
|
||||||
for(int32_t i = index; i < _downloadContext->getNumPieces(); ++i) {
|
size_t numPieces = _downloadContext->getNumPieces();
|
||||||
|
for(size_t i = index; i < numPieces; ++i) {
|
||||||
if(_pieceStorage->hasPiece(i) || _pieceStorage->isPieceUsed(i)) {
|
if(_pieceStorage->hasPiece(i) || _pieceStorage->isPieceUsed(i)) {
|
||||||
return i-index;
|
return i-index;
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ public:
|
||||||
* If Transfer-Encoding is Chunked or Content-Length header is not provided,
|
* If Transfer-Encoding is Chunked or Content-Length header is not provided,
|
||||||
* then this value is set to be 0.
|
* then this value is set to be 0.
|
||||||
*/
|
*/
|
||||||
int64_t getTotalLength() const;
|
uint64_t getTotalLength() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returs true when the download has finished.
|
* Returs true when the download has finished.
|
||||||
|
@ -124,7 +124,7 @@ public:
|
||||||
* to another cuid or has been downloaded, then returns a segment instance
|
* to another cuid or has been downloaded, then returns a segment instance
|
||||||
* whose isNull call is true.
|
* whose isNull call is true.
|
||||||
*/
|
*/
|
||||||
SharedHandle<Segment> getSegment(int32_t cuid, int32_t index);
|
SharedHandle<Segment> getSegment(int32_t cuid, size_t index);
|
||||||
/**
|
/**
|
||||||
* Updates download status.
|
* Updates download status.
|
||||||
*/
|
*/
|
||||||
|
@ -152,11 +152,11 @@ public:
|
||||||
/**
|
/**
|
||||||
* Returns true if the segment whose index is index has been downloaded.
|
* Returns true if the segment whose index is index has been downloaded.
|
||||||
*/
|
*/
|
||||||
bool hasSegment(int32_t index) const;
|
bool hasSegment(size_t index) const;
|
||||||
/**
|
/**
|
||||||
* Returns the length of bytes downloaded.
|
* Returns the length of bytes downloaded.
|
||||||
*/
|
*/
|
||||||
int64_t getDownloadLength() const;
|
uint64_t getDownloadLength() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers given peerStat if it has not been registerd.
|
* Registers given peerStat if it has not been registerd.
|
||||||
|
@ -173,9 +173,9 @@ public:
|
||||||
/**
|
/**
|
||||||
* Returns current download speed in bytes per sec.
|
* Returns current download speed in bytes per sec.
|
||||||
*/
|
*/
|
||||||
int32_t calculateDownloadSpeed() const;
|
unsigned int calculateDownloadSpeed() const;
|
||||||
|
|
||||||
int32_t countFreePieceFrom(int32_t index) const;
|
size_t countFreePieceFrom(size_t index) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<SegmentMan> SegmentManHandle;
|
typedef SharedHandle<SegmentMan> SegmentManHandle;
|
||||||
|
|
|
@ -37,8 +37,8 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
SingleFileDownloadContext::SingleFileDownloadContext(int32_t pieceLength,
|
SingleFileDownloadContext::SingleFileDownloadContext(size_t pieceLength,
|
||||||
int64_t totalLength,
|
uint64_t totalLength,
|
||||||
const std::string& filename,
|
const std::string& filename,
|
||||||
const std::string& ufilename):
|
const std::string& ufilename):
|
||||||
_pieceLength(pieceLength),
|
_pieceLength(pieceLength),
|
||||||
|
@ -66,7 +66,7 @@ SingleFileDownloadContext::getPieceHashes() const
|
||||||
return _pieceHashes;
|
return _pieceHashes;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t SingleFileDownloadContext::getTotalLength() const
|
uint64_t SingleFileDownloadContext::getTotalLength() const
|
||||||
{
|
{
|
||||||
return _fileEntry->getLength();
|
return _fileEntry->getLength();
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ SingleFileDownloadContext::getFileEntries() const
|
||||||
return fs;
|
return fs;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t SingleFileDownloadContext::getNumPieces() const
|
size_t SingleFileDownloadContext::getNumPieces() const
|
||||||
{
|
{
|
||||||
return (_fileEntry->getLength()+_pieceLength-1)/_pieceLength;
|
return (_fileEntry->getLength()+_pieceLength-1)/_pieceLength;
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ std::string SingleFileDownloadContext::getActualBasePath() const
|
||||||
return _dir+"/"+_fileEntry->getPath();
|
return _dir+"/"+_fileEntry->getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SingleFileDownloadContext::setTotalLength(int64_t totalLength)
|
void SingleFileDownloadContext::setTotalLength(uint64_t totalLength)
|
||||||
{
|
{
|
||||||
_fileEntry->setLength(totalLength);
|
_fileEntry->setLength(totalLength);
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ namespace aria2 {
|
||||||
class SingleFileDownloadContext:public DownloadContext
|
class SingleFileDownloadContext:public DownloadContext
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int32_t _pieceLength;
|
size_t _pieceLength;
|
||||||
/**
|
/**
|
||||||
* Actual file path is _dir + _filename.
|
* Actual file path is _dir + _filename.
|
||||||
* If _ufilename is not zero-length string, then _dir + _ufilename.
|
* If _ufilename is not zero-length string, then _dir + _ufilename.
|
||||||
|
@ -67,24 +67,25 @@ private:
|
||||||
|
|
||||||
void updateFileEntry();
|
void updateFileEntry();
|
||||||
public:
|
public:
|
||||||
SingleFileDownloadContext(int32_t pieceLength,
|
SingleFileDownloadContext(size_t pieceLength,
|
||||||
int64_t totalLength,
|
uint64_t totalLength,
|
||||||
const std::string& filename,
|
const std::string& filename,
|
||||||
const std::string& ufilename = "");
|
const std::string& ufilename = "");
|
||||||
|
|
||||||
virtual ~SingleFileDownloadContext() {}
|
virtual ~SingleFileDownloadContext() {}
|
||||||
|
|
||||||
virtual std::string getPieceHash(int32_t index) const
|
virtual std::string getPieceHash(size_t index) const
|
||||||
{
|
{
|
||||||
if(index < 0 || _pieceHashes.size() <= (size_t)index) {
|
if(index < _pieceHashes.size()) {
|
||||||
|
return _pieceHashes[index];
|
||||||
|
} else {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return _pieceHashes[index];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual const std::deque<std::string>& getPieceHashes() const;
|
virtual const std::deque<std::string>& getPieceHashes() const;
|
||||||
|
|
||||||
virtual int64_t getTotalLength() const;
|
virtual uint64_t getTotalLength() const;
|
||||||
|
|
||||||
virtual FILE_MODE getFileMode() const
|
virtual FILE_MODE getFileMode() const
|
||||||
{
|
{
|
||||||
|
@ -98,12 +99,12 @@ public:
|
||||||
return _filename;
|
return _filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int32_t getPieceLength() const
|
virtual size_t getPieceLength() const
|
||||||
{
|
{
|
||||||
return _pieceLength;
|
return _pieceLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int32_t getNumPieces() const;
|
virtual size_t getNumPieces() const;
|
||||||
|
|
||||||
virtual std::string getActualBasePath() const;
|
virtual std::string getActualBasePath() const;
|
||||||
|
|
||||||
|
@ -149,7 +150,7 @@ public:
|
||||||
updateFileEntry();
|
updateFileEntry();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTotalLength(int64_t totalLength);
|
void setTotalLength(uint64_t totalLength);
|
||||||
|
|
||||||
void setPieceHashAlgo(const std::string& algo)
|
void setPieceHashAlgo(const std::string& algo)
|
||||||
{
|
{
|
||||||
|
|
|
@ -70,7 +70,7 @@ void DefaultBtContextTest::testGetInfoHash() {
|
||||||
|
|
||||||
std::string correctHash = "248d0a1cd08284299de78d5c1ed359bb46717d8c";
|
std::string correctHash = "248d0a1cd08284299de78d5c1ed359bb46717d8c";
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL((int32_t)20, btContext.getInfoHashLength());
|
CPPUNIT_ASSERT_EQUAL((size_t)20, btContext.getInfoHashLength());
|
||||||
CPPUNIT_ASSERT_EQUAL(correctHash, Util::toHex(btContext.getInfoHash(),
|
CPPUNIT_ASSERT_EQUAL(correctHash, Util::toHex(btContext.getInfoHash(),
|
||||||
btContext.getInfoHashLength()));
|
btContext.getInfoHashLength()));
|
||||||
}
|
}
|
||||||
|
@ -127,48 +127,42 @@ void DefaultBtContextTest::testGetTotalLength() {
|
||||||
DefaultBtContext btContext;
|
DefaultBtContext btContext;
|
||||||
btContext.load("test.torrent");
|
btContext.load("test.torrent");
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL((long long int)384,
|
CPPUNIT_ASSERT_EQUAL(384ULL, btContext.getTotalLength());
|
||||||
btContext.getTotalLength());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtContextTest::testGetTotalLengthSingle() {
|
void DefaultBtContextTest::testGetTotalLengthSingle() {
|
||||||
DefaultBtContext btContext;
|
DefaultBtContext btContext;
|
||||||
btContext.load("single.torrent");
|
btContext.load("single.torrent");
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL((long long int)384,
|
CPPUNIT_ASSERT_EQUAL(384ULL, btContext.getTotalLength());
|
||||||
btContext.getTotalLength());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtContextTest::testGetFileModeMulti() {
|
void DefaultBtContextTest::testGetFileModeMulti() {
|
||||||
DefaultBtContext btContext;
|
DefaultBtContext btContext;
|
||||||
btContext.load("test.torrent");
|
btContext.load("test.torrent");
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(BtContext::MULTI,
|
CPPUNIT_ASSERT_EQUAL(BtContext::MULTI, btContext.getFileMode());
|
||||||
btContext.getFileMode());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtContextTest::testGetFileModeSingle() {
|
void DefaultBtContextTest::testGetFileModeSingle() {
|
||||||
DefaultBtContext btContext;
|
DefaultBtContext btContext;
|
||||||
btContext.load("single.torrent");
|
btContext.load("single.torrent");
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(BtContext::SINGLE,
|
CPPUNIT_ASSERT_EQUAL(BtContext::SINGLE, btContext.getFileMode());
|
||||||
btContext.getFileMode());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtContextTest::testGetNameMulti() {
|
void DefaultBtContextTest::testGetNameMulti() {
|
||||||
DefaultBtContext btContext;
|
DefaultBtContext btContext;
|
||||||
btContext.load("test.torrent");
|
btContext.load("test.torrent");
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2-test"),
|
CPPUNIT_ASSERT_EQUAL(std::string("aria2-test"), btContext.getName());
|
||||||
btContext.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtContextTest::testGetNameSingle() {
|
void DefaultBtContextTest::testGetNameSingle() {
|
||||||
DefaultBtContext btContext;
|
DefaultBtContext btContext;
|
||||||
btContext.load("single.torrent");
|
btContext.load("single.torrent");
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2-0.8.2.tar.bz2"),
|
CPPUNIT_ASSERT_EQUAL(std::string("aria2-0.8.2.tar.bz2"), btContext.getName());
|
||||||
btContext.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtContextTest::testGetAnnounceTier() {
|
void DefaultBtContextTest::testGetAnnounceTier() {
|
||||||
|
@ -178,13 +172,11 @@ void DefaultBtContextTest::testGetAnnounceTier() {
|
||||||
std::deque<SharedHandle<AnnounceTier> > tiers = btContext.getAnnounceTiers();
|
std::deque<SharedHandle<AnnounceTier> > tiers = btContext.getAnnounceTiers();
|
||||||
|
|
||||||
// There is 1 tier.
|
// There is 1 tier.
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1,
|
CPPUNIT_ASSERT_EQUAL((size_t)1, tiers.size());
|
||||||
tiers.size());
|
|
||||||
|
|
||||||
std::deque<SharedHandle<AnnounceTier> >::iterator itr = tiers.begin();
|
std::deque<SharedHandle<AnnounceTier> >::iterator itr = tiers.begin();
|
||||||
SharedHandle<AnnounceTier> tier1 = *itr;
|
SharedHandle<AnnounceTier> tier1 = *itr;
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1,
|
CPPUNIT_ASSERT_EQUAL((size_t)1, tier1->urls.size());
|
||||||
tier1->urls.size());
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com/announce.php"),
|
CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com/announce.php"),
|
||||||
tier1->urls.at(0));
|
tier1->urls.at(0));
|
||||||
|
|
||||||
|
@ -197,35 +189,27 @@ void DefaultBtContextTest::testGetAnnounceTierAnnounceList() {
|
||||||
std::deque<SharedHandle<AnnounceTier> > tiers = btContext.getAnnounceTiers();
|
std::deque<SharedHandle<AnnounceTier> > tiers = btContext.getAnnounceTiers();
|
||||||
|
|
||||||
// There are 3 tiers.
|
// There are 3 tiers.
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)3,
|
CPPUNIT_ASSERT_EQUAL((size_t)3, tiers.size());
|
||||||
tiers.size());
|
|
||||||
|
|
||||||
SharedHandle<AnnounceTier> tier1 = tiers.at(0);
|
SharedHandle<AnnounceTier> tier1 = tiers.at(0);
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1,
|
CPPUNIT_ASSERT_EQUAL((size_t)1, tier1->urls.size());
|
||||||
tier1->urls.size());
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("http://tracker1"),
|
CPPUNIT_ASSERT_EQUAL(std::string("http://tracker1"),
|
||||||
tier1->urls.at(0));
|
tier1->urls.at(0));
|
||||||
|
|
||||||
SharedHandle<AnnounceTier> tier2 = tiers.at(1);
|
SharedHandle<AnnounceTier> tier2 = tiers.at(1);
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1,
|
CPPUNIT_ASSERT_EQUAL((size_t)1, tier2->urls.size());
|
||||||
tier2->urls.size());
|
CPPUNIT_ASSERT_EQUAL(std::string("http://tracker2"), tier2->urls.at(0));
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("http://tracker2"),
|
|
||||||
tier2->urls.at(0));
|
|
||||||
|
|
||||||
SharedHandle<AnnounceTier> tier3 = tiers.at(2);
|
SharedHandle<AnnounceTier> tier3 = tiers.at(2);
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1,
|
CPPUNIT_ASSERT_EQUAL((size_t)1, tier3->urls.size());
|
||||||
tier3->urls.size());
|
CPPUNIT_ASSERT_EQUAL(std::string("http://tracker3"), tier3->urls.at(0));
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("http://tracker3"),
|
|
||||||
tier3->urls.at(0));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtContextTest::testGetPieceLength() {
|
void DefaultBtContextTest::testGetPieceLength() {
|
||||||
DefaultBtContext btContext;
|
DefaultBtContext btContext;
|
||||||
btContext.load("test.torrent");
|
btContext.load("test.torrent");
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL((int32_t)128,
|
CPPUNIT_ASSERT_EQUAL((size_t)128, btContext.getPieceLength());
|
||||||
btContext.getPieceLength());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtContextTest::testGetInfoHashAsString() {
|
void DefaultBtContextTest::testGetInfoHashAsString() {
|
||||||
|
@ -256,18 +240,18 @@ void DefaultBtContextTest::testComputeFastSet()
|
||||||
btContext.setInfoHash(infoHash);
|
btContext.setInfoHash(infoHash);
|
||||||
btContext.setNumPieces(pieces);
|
btContext.setNumPieces(pieces);
|
||||||
|
|
||||||
std::deque<int32_t> fastSet = btContext.computeFastSet(ipaddr, fastSetSize);
|
std::deque<size_t> fastSet = btContext.computeFastSet(ipaddr, fastSetSize);
|
||||||
//for_each(fastSet.begin(), fastSet.end(), Printer());
|
//for_each(fastSet.begin(), fastSet.end(), Printer());
|
||||||
//cerr << endl;
|
//cerr << endl;
|
||||||
int ans1[] = { 686, 459, 278, 200, 404, 834, 64, 203, 760, 950 };
|
size_t ans1[] = { 686, 459, 278, 200, 404, 834, 64, 203, 760, 950 };
|
||||||
std::deque<int32_t> ansSet1(&ans1[0], &ans1[10]);
|
std::deque<size_t> ansSet1(&ans1[0], &ans1[10]);
|
||||||
CPPUNIT_ASSERT(equal(fastSet.begin(), fastSet.end(), ansSet1.begin()));
|
CPPUNIT_ASSERT(std::equal(fastSet.begin(), fastSet.end(), ansSet1.begin()));
|
||||||
|
|
||||||
ipaddr = "10.0.0.1";
|
ipaddr = "10.0.0.1";
|
||||||
fastSet = btContext.computeFastSet(ipaddr, fastSetSize);
|
fastSet = btContext.computeFastSet(ipaddr, fastSetSize);
|
||||||
int ans2[] = { 568, 188, 466, 452, 550, 662, 109, 226, 398, 11 };
|
size_t ans2[] = { 568, 188, 466, 452, 550, 662, 109, 226, 398, 11 };
|
||||||
std::deque<int32_t> ansSet2(&ans2[0], &ans2[10]);
|
std::deque<size_t> ansSet2(&ans2[0], &ans2[10]);
|
||||||
CPPUNIT_ASSERT(equal(fastSet.begin(), fastSet.end(), ansSet2.begin()));
|
CPPUNIT_ASSERT(std::equal(fastSet.begin(), fastSet.end(), ansSet2.begin()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtContextTest::testGetFileEntries_multiFileUrlList() {
|
void DefaultBtContextTest::testGetFileEntries_multiFileUrlList() {
|
||||||
|
@ -327,7 +311,7 @@ void DefaultBtContextTest::testLoadFromMemory()
|
||||||
|
|
||||||
std::string correctHash = "248d0a1cd08284299de78d5c1ed359bb46717d8c";
|
std::string correctHash = "248d0a1cd08284299de78d5c1ed359bb46717d8c";
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL((int32_t)20, btContext.getInfoHashLength());
|
CPPUNIT_ASSERT_EQUAL((size_t)20, btContext.getInfoHashLength());
|
||||||
CPPUNIT_ASSERT_EQUAL(correctHash, Util::toHex(btContext.getInfoHash(),
|
CPPUNIT_ASSERT_EQUAL(correctHash, Util::toHex(btContext.getInfoHash(),
|
||||||
btContext.getInfoHashLength()));
|
btContext.getInfoHashLength()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ void Metalink2RequestGroupTest::testGenerate()
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("http://httphost/aria2-0.5.2.tar.bz2"), uris[1]);
|
CPPUNIT_ASSERT_EQUAL(std::string("http://httphost/aria2-0.5.2.tar.bz2"), uris[1]);
|
||||||
SharedHandle<SingleFileDownloadContext> dctx = rg->getDownloadContext();
|
SharedHandle<SingleFileDownloadContext> dctx = rg->getDownloadContext();
|
||||||
CPPUNIT_ASSERT(!dctx.isNull());
|
CPPUNIT_ASSERT(!dctx.isNull());
|
||||||
CPPUNIT_ASSERT_EQUAL((int64_t)0, dctx->getTotalLength());
|
CPPUNIT_ASSERT_EQUAL(0ULL, dctx->getTotalLength());
|
||||||
#ifdef ENABLE_MESSAGE_DIGEST
|
#ifdef ENABLE_MESSAGE_DIGEST
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("sha1"), dctx->getChecksumHashAlgo());
|
CPPUNIT_ASSERT_EQUAL(std::string("sha1"), dctx->getChecksumHashAlgo());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("a96cf3f0266b91d87d5124cf94326422800b627d"),
|
CPPUNIT_ASSERT_EQUAL(std::string("a96cf3f0266b91d87d5124cf94326422800b627d"),
|
||||||
|
@ -61,7 +61,7 @@ void Metalink2RequestGroupTest::testGenerate()
|
||||||
#ifdef ENABLE_MESSAGE_DIGEST
|
#ifdef ENABLE_MESSAGE_DIGEST
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("sha1"), dctx->getPieceHashAlgo());
|
CPPUNIT_ASSERT_EQUAL(std::string("sha1"), dctx->getPieceHashAlgo());
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)2, dctx->getPieceHashes().size());
|
CPPUNIT_ASSERT_EQUAL((size_t)2, dctx->getPieceHashes().size());
|
||||||
CPPUNIT_ASSERT_EQUAL((int32_t)262144, dctx->getPieceLength());
|
CPPUNIT_ASSERT_EQUAL((size_t)262144, dctx->getPieceLength());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string(""), dctx->getChecksumHashAlgo());
|
CPPUNIT_ASSERT_EQUAL(std::string(""), dctx->getChecksumHashAlgo());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string(""), dctx->getChecksum());
|
CPPUNIT_ASSERT_EQUAL(std::string(""), dctx->getChecksum());
|
||||||
#endif // ENABLE_MESSAGE_DIGEST
|
#endif // ENABLE_MESSAGE_DIGEST
|
||||||
|
|
|
@ -11,16 +11,16 @@ class MockBtContext : public BtContext {
|
||||||
private:
|
private:
|
||||||
unsigned char infoHash[20];
|
unsigned char infoHash[20];
|
||||||
std::deque<std::string> pieceHashes;
|
std::deque<std::string> pieceHashes;
|
||||||
int64_t totalLength;
|
uint64_t totalLength;
|
||||||
FILE_MODE fileMode;
|
FILE_MODE fileMode;
|
||||||
std::string name;
|
std::string name;
|
||||||
int32_t pieceLength;
|
size_t pieceLength;
|
||||||
int32_t numPieces;
|
size_t numPieces;
|
||||||
unsigned char peerId[20];
|
unsigned char peerId[20];
|
||||||
std::deque<SharedHandle<FileEntry> > fileEntries;
|
std::deque<SharedHandle<FileEntry> > fileEntries;
|
||||||
std::deque<SharedHandle<AnnounceTier> > announceTiers;
|
std::deque<SharedHandle<AnnounceTier> > announceTiers;
|
||||||
std::deque<std::pair<std::string, uint16_t> > _nodes;
|
std::deque<std::pair<std::string, uint16_t> > _nodes;
|
||||||
std::deque<int32_t> fastSet;
|
std::deque<size_t> fastSet;
|
||||||
public:
|
public:
|
||||||
MockBtContext():totalLength(0),
|
MockBtContext():totalLength(0),
|
||||||
pieceLength(0),
|
pieceLength(0),
|
||||||
|
@ -36,7 +36,7 @@ public:
|
||||||
memcpy(this->infoHash, infoHash, sizeof(this->infoHash));
|
memcpy(this->infoHash, infoHash, sizeof(this->infoHash));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int32_t getInfoHashLength() const {
|
virtual size_t getInfoHashLength() const {
|
||||||
return sizeof(infoHash);
|
return sizeof(infoHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ public:
|
||||||
return Util::toHex(infoHash, sizeof(infoHash));
|
return Util::toHex(infoHash, sizeof(infoHash));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::string getPieceHash(int32_t index) const {
|
virtual std::string getPieceHash(size_t index) const {
|
||||||
return pieceHashes.at(index);
|
return pieceHashes.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,11 +56,11 @@ public:
|
||||||
pieceHashes.push_back(pieceHash);
|
pieceHashes.push_back(pieceHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int64_t getTotalLength() const {
|
virtual uint64_t getTotalLength() const {
|
||||||
return totalLength;
|
return totalLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTotalLength(int64_t length) {
|
void setTotalLength(uint64_t length) {
|
||||||
this->totalLength = length;
|
this->totalLength = length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,19 +98,19 @@ public:
|
||||||
this->name = name;
|
this->name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int32_t getPieceLength() const {
|
virtual size_t getPieceLength() const {
|
||||||
return pieceLength;
|
return pieceLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPieceLength(int32_t pieceLength) {
|
void setPieceLength(size_t pieceLength) {
|
||||||
this->pieceLength = pieceLength;
|
this->pieceLength = pieceLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int32_t getNumPieces() const {
|
virtual size_t getNumPieces() const {
|
||||||
return numPieces;
|
return numPieces;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setNumPieces(int32_t numPieces) {
|
void setNumPieces(size_t numPieces) {
|
||||||
this->numPieces = numPieces;
|
this->numPieces = numPieces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,12 +122,12 @@ public:
|
||||||
memcpy(this->peerId, peerId, sizeof(this->peerId));
|
memcpy(this->peerId, peerId, sizeof(this->peerId));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::deque<int32_t> computeFastSet(const std::string& ipaddr, int32_t fastSetSize)
|
virtual std::deque<size_t> computeFastSet(const std::string& ipaddr, size_t fastSetSize)
|
||||||
{
|
{
|
||||||
return fastSet;
|
return fastSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setFastSet(const std::deque<int32_t>& fastSet)
|
void setFastSet(const std::deque<size_t>& fastSet)
|
||||||
{
|
{
|
||||||
this->fastSet = fastSet;
|
this->fastSet = fastSet;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ void SingleFileDownloadContextTest::testGetPieceHash()
|
||||||
void SingleFileDownloadContextTest::testGetNumPieces()
|
void SingleFileDownloadContextTest::testGetNumPieces()
|
||||||
{
|
{
|
||||||
SingleFileDownloadContext ctx(345, 9889, "");
|
SingleFileDownloadContext ctx(345, 9889, "");
|
||||||
CPPUNIT_ASSERT_EQUAL((int32_t)29, ctx.getNumPieces());
|
CPPUNIT_ASSERT_EQUAL((size_t)29, ctx.getNumPieces());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SingleFileDownloadContextTest::testGetActualBasePath()
|
void SingleFileDownloadContextTest::testGetActualBasePath()
|
||||||
|
|
Loading…
Reference in New Issue