mirror of https://github.com/aria2/aria2
2007-01-26 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* src/message.h: Added EX_INVALID_PAYLOAD_SIZE and EX_INVALID_BT_MESSAGE_ID. Following source files affected. * src/BtAllowedFastMessage.cc: * src/BtBitfieldMessage.cc * src/BtCancelMessage.cc * src/BtChokeMessage.cc * src/BtHaveAllMessage.cc * src/BtHaveMessage.cc * src/BtHaveNoneMessage.cc * src/BtInterestedMessage.cc * src/BtNotInterestedMessage.cc * src/BtPieceMessage.cc * src/BtPortMessage.cc * src/BtRejectMessage.cc * src/BtRequestMessage.cc * src/BtSuggestPieceMessage.cc * src/BtUnchokeMessage.cc * src/message.h: Added EX_INVALID_CHUNK_CHECKSUM. Following source files are affected. * src/ChunkChecksumValidator.cc * src/SegmentMan.ccpull/1/head
parent
139f46332e
commit
cd9e35bc63
25
ChangeLog
25
ChangeLog
|
@ -1,3 +1,28 @@
|
|||
2007-01-26 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
* src/message.h: Added EX_INVALID_PAYLOAD_SIZE and
|
||||
EX_INVALID_BT_MESSAGE_ID. Following source files affected.
|
||||
* src/BtAllowedFastMessage.cc:
|
||||
* src/BtBitfieldMessage.cc
|
||||
* src/BtCancelMessage.cc
|
||||
* src/BtChokeMessage.cc
|
||||
* src/BtHaveAllMessage.cc
|
||||
* src/BtHaveMessage.cc
|
||||
* src/BtHaveNoneMessage.cc
|
||||
* src/BtInterestedMessage.cc
|
||||
* src/BtNotInterestedMessage.cc
|
||||
* src/BtPieceMessage.cc
|
||||
* src/BtPortMessage.cc
|
||||
* src/BtRejectMessage.cc
|
||||
* src/BtRequestMessage.cc
|
||||
* src/BtSuggestPieceMessage.cc
|
||||
* src/BtUnchokeMessage.cc
|
||||
|
||||
* src/message.h: Added EX_INVALID_CHUNK_CHECKSUM. Following source
|
||||
files are affected.
|
||||
* src/ChunkChecksumValidator.cc
|
||||
* src/SegmentMan.cc
|
||||
|
||||
2007-01-23 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
To add chunk checksum validation:
|
||||
|
|
2
TODO
2
TODO
|
@ -23,8 +23,8 @@
|
|||
* Fix DefaultBtProgressInfoFile.cc: save(), load()
|
||||
* remove blockIndex
|
||||
* Add an ability of seeding
|
||||
* Continue file allocation with existing file
|
||||
|
||||
* Stopping while piece hash checking and file allocation
|
||||
* Stop download after selective download completes
|
||||
* Remove -pg option in Makefile.am
|
||||
* Continue file allocation with existing file
|
|
@ -55,7 +55,7 @@ AbstractDiskWriter::~AbstractDiskWriter()
|
|||
closeFile();
|
||||
}
|
||||
|
||||
void AbstractDiskWriter::openFile(const string& filename, uint64_t totalLength) {
|
||||
void AbstractDiskWriter::openFile(const string& filename, int64_t totalLength) {
|
||||
File f(filename);
|
||||
if(f.exists()) {
|
||||
openExistingFile(filename);
|
||||
|
@ -95,15 +95,15 @@ void AbstractDiskWriter::createFile(const string& filename, int32_t addFlags) {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t AbstractDiskWriter::writeDataInternal(const char* data, uint32_t len) {
|
||||
int32_t AbstractDiskWriter::writeDataInternal(const char* data, int32_t len) {
|
||||
return write(fd, data, len);
|
||||
}
|
||||
|
||||
int AbstractDiskWriter::readDataInternal(char* data, uint32_t len) {
|
||||
int32_t AbstractDiskWriter::readDataInternal(char* data, int32_t len) {
|
||||
return read(fd, data, len);
|
||||
}
|
||||
|
||||
string AbstractDiskWriter::messageDigest(int64_t offset, uint64_t length,
|
||||
string AbstractDiskWriter::messageDigest(int64_t offset, int64_t length,
|
||||
const MessageDigestContext::DigestAlgo& algo)
|
||||
{
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
|
@ -112,7 +112,7 @@ string AbstractDiskWriter::messageDigest(int64_t offset, uint64_t length,
|
|||
|
||||
int32_t BUFSIZE = 16*1024;
|
||||
char buf[BUFSIZE];
|
||||
for(uint64_t i = 0; i < length/BUFSIZE; i++) {
|
||||
for(int64_t i = 0; i < length/BUFSIZE; i++) {
|
||||
int32_t rs = readData(buf, BUFSIZE, offset);
|
||||
if(BUFSIZE != readData(buf, BUFSIZE, offset)) {
|
||||
throw new DlAbortEx(EX_FILE_SHA1SUM, filename.c_str(), strerror(errno));
|
||||
|
@ -143,14 +143,14 @@ void AbstractDiskWriter::seek(int64_t offset) {
|
|||
}
|
||||
}
|
||||
|
||||
void AbstractDiskWriter::writeData(const char* data, uint32_t len, int64_t offset) {
|
||||
void AbstractDiskWriter::writeData(const char* data, int32_t len, int64_t offset) {
|
||||
seek(offset);
|
||||
if(writeDataInternal(data, len) < 0) {
|
||||
throw new DlAbortEx(EX_FILE_WRITE, filename.c_str(), strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
int AbstractDiskWriter::readData(char* data, uint32_t len, int64_t offset) {
|
||||
int32_t AbstractDiskWriter::readData(char* data, int32_t len, int64_t offset) {
|
||||
int32_t ret;
|
||||
seek(offset);
|
||||
if((ret = readDataInternal(data, len)) < 0) {
|
||||
|
|
|
@ -49,8 +49,8 @@ protected:
|
|||
void createFile(const string& filename, int32_t addFlags = 0);
|
||||
|
||||
private:
|
||||
int writeDataInternal(const char* data, uint32_t len);
|
||||
int readDataInternal(char* data, uint32_t len);
|
||||
int32_t writeDataInternal(const char* data, int32_t len);
|
||||
int32_t readDataInternal(char* data, int32_t len);
|
||||
|
||||
void seek(int64_t offset);
|
||||
|
||||
|
@ -58,18 +58,18 @@ public:
|
|||
AbstractDiskWriter();
|
||||
virtual ~AbstractDiskWriter();
|
||||
|
||||
virtual void openFile(const string& filename, uint64_t totalLength = 0);
|
||||
virtual void openFile(const string& filename, int64_t totalLength = 0);
|
||||
|
||||
virtual void closeFile();
|
||||
|
||||
virtual void openExistingFile(const string& filename);
|
||||
|
||||
virtual string messageDigest(int64_t offset, uint64_t length,
|
||||
virtual string messageDigest(int64_t offset, int64_t length,
|
||||
const MessageDigestContext::DigestAlgo& algo);
|
||||
|
||||
virtual void writeData(const char* data, uint32_t len, int64_t offset);
|
||||
virtual void writeData(const char* data, int32_t len, int64_t offset);
|
||||
|
||||
virtual int readData(char* data, uint32_t len, int64_t offset);
|
||||
virtual int32_t readData(char* data, int32_t len, int64_t offset);
|
||||
|
||||
void setFileAllocator(const FileAllocatorHandle& fileAllocator) {
|
||||
this->fileAllocator = fileAllocator;
|
||||
|
|
|
@ -51,15 +51,15 @@ void AbstractSingleDiskAdaptor::openExistingFile() {
|
|||
diskWriter->openExistingFile(getFilePath());
|
||||
}
|
||||
|
||||
void AbstractSingleDiskAdaptor::writeData(const unsigned char* data, uint32_t len, int64_t offset) {
|
||||
void AbstractSingleDiskAdaptor::writeData(const unsigned char* data, int32_t len, int64_t offset) {
|
||||
diskWriter->writeData(data, len, offset);
|
||||
}
|
||||
|
||||
int AbstractSingleDiskAdaptor::readData(unsigned char* data, uint32_t len, int64_t offset) {
|
||||
int32_t AbstractSingleDiskAdaptor::readData(unsigned char* data, int32_t len, int64_t offset) {
|
||||
return diskWriter->readData(data, len, offset);
|
||||
}
|
||||
|
||||
string AbstractSingleDiskAdaptor::messageDigest(int64_t offset, uint64_t length, const MessageDigestContext::DigestAlgo& algo) {
|
||||
string AbstractSingleDiskAdaptor::messageDigest(int64_t offset, int64_t length, const MessageDigestContext::DigestAlgo& algo) {
|
||||
return diskWriter->messageDigest(offset, length, algo);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
class AbstractSingleDiskAdaptor : public DiskAdaptor {
|
||||
protected:
|
||||
DiskWriterHandle diskWriter;
|
||||
uint64_t totalLength;
|
||||
int64_t totalLength;
|
||||
public:
|
||||
AbstractSingleDiskAdaptor():diskWriter(0), totalLength(0) {}
|
||||
|
||||
|
@ -55,12 +55,12 @@ public:
|
|||
|
||||
virtual void openExistingFile();
|
||||
|
||||
virtual void writeData(const unsigned char* data, uint32_t len,
|
||||
virtual void writeData(const unsigned char* data, int32_t len,
|
||||
int64_t offset);
|
||||
|
||||
virtual int readData(unsigned char* data, uint32_t len, int64_t offset);
|
||||
virtual int32_t readData(unsigned char* data, int32_t len, int64_t offset);
|
||||
|
||||
virtual string messageDigest(int64_t offset, uint64_t length,
|
||||
virtual string messageDigest(int64_t offset, int64_t length,
|
||||
const MessageDigestContext::DigestAlgo& algo);
|
||||
|
||||
virtual bool fileExists();
|
||||
|
@ -71,11 +71,11 @@ public:
|
|||
|
||||
DiskWriterHandle getDiskWriter() const { return diskWriter; }
|
||||
|
||||
void setTotalLength(const uint64_t& totalLength) {
|
||||
void setTotalLength(const int64_t& totalLength) {
|
||||
this->totalLength = totalLength;
|
||||
}
|
||||
|
||||
uint64_t getTotalLength() const { return totalLength; }
|
||||
int64_t getTotalLength() const { return totalLength; }
|
||||
};
|
||||
|
||||
#endif // _D_ABSTRACT_SINGLE_DISK_ADAPTOR_H_
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
#include "Util.h"
|
||||
#include <string.h>
|
||||
|
||||
BitfieldMan::BitfieldMan(uint32_t blockLength, uint64_t totalLength)
|
||||
BitfieldMan::BitfieldMan(int32_t blockLength, int64_t totalLength)
|
||||
:blockLength(blockLength),
|
||||
totalLength(totalLength),
|
||||
bitfield(0),
|
||||
|
@ -104,19 +104,19 @@ BitfieldMan::~BitfieldMan() {
|
|||
delete [] filterBitfield;
|
||||
}
|
||||
|
||||
uint32_t BitfieldMan::countSetBit(const unsigned char* bitfield, uint32_t len) const {
|
||||
uint32_t count = 0;
|
||||
uint32_t size = sizeof(uint32_t);
|
||||
for(uint32_t i = 0; i < len/size; i++) {
|
||||
int32_t BitfieldMan::countSetBit(const unsigned char* bitfield, int32_t len) const {
|
||||
int32_t count = 0;
|
||||
int32_t size = sizeof(int32_t);
|
||||
for(int32_t i = 0; i < len/size; ++i) {
|
||||
count += Util::countBit(*(uint32_t*)&bitfield[i*size]);
|
||||
}
|
||||
for(uint32_t i = len-len%size; i < len; i++) {
|
||||
for(int32_t i = len-len%size; i < len; i++) {
|
||||
count += Util::countBit((uint32_t)bitfield[i]);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
int32_t BitfieldMan::getNthBitIndex(const unsigned char bitfield, uint32_t nth) const {
|
||||
int32_t BitfieldMan::getNthBitIndex(const unsigned char bitfield, int32_t nth) const {
|
||||
int32_t index = -1;
|
||||
for(int bs = 7; bs >= 0; bs--) {
|
||||
unsigned char mask = 1 << bs;
|
||||
|
@ -133,22 +133,22 @@ int32_t BitfieldMan::getNthBitIndex(const unsigned char bitfield, uint32_t nth)
|
|||
|
||||
int32_t
|
||||
BitfieldMan::getMissingIndexRandomly(const unsigned char* bitfield,
|
||||
uint32_t bitfieldLength) const
|
||||
int32_t bitfieldLength) const
|
||||
{
|
||||
uint32_t byte = (int32_t)(((double)bitfieldLength)*
|
||||
int32_t byte = (int32_t)(((double)bitfieldLength)*
|
||||
randomizer->getRandomNumber()/
|
||||
(randomizer->getMaxRandomNumber()+1.0));
|
||||
|
||||
unsigned char lastMask = 0;
|
||||
// the number of bytes in the last byte of bitfield
|
||||
uint32_t lastByteLength = totalLength%(blockLength*8);
|
||||
int32_t lastByteLength = totalLength%(blockLength*8);
|
||||
// the number of block in the last byte of bitfield
|
||||
uint32_t lastBlockCount = DIV_FLOOR(lastByteLength, blockLength);
|
||||
for(uint32_t i = 0; i < lastBlockCount; i++) {
|
||||
int32_t lastBlockCount = DIV_FLOOR(lastByteLength, blockLength);
|
||||
for(int32_t i = 0; i < lastBlockCount; ++i) {
|
||||
lastMask >>= 1;
|
||||
lastMask |= 0x80;
|
||||
}
|
||||
for(uint32_t i = 0; i < bitfieldLength; i++) {
|
||||
for(int32_t i = 0; i < bitfieldLength; ++i) {
|
||||
unsigned char mask;
|
||||
if(byte == bitfieldLength-1) {
|
||||
mask = lastMask;
|
||||
|
@ -167,12 +167,12 @@ BitfieldMan::getMissingIndexRandomly(const unsigned char* bitfield,
|
|||
return -1;
|
||||
}
|
||||
|
||||
bool BitfieldMan::hasMissingPiece(const unsigned char* peerBitfield, uint32_t length) const {
|
||||
bool BitfieldMan::hasMissingPiece(const unsigned char* peerBitfield, int32_t length) const {
|
||||
if(bitfieldLength != length) {
|
||||
return false;
|
||||
}
|
||||
bool retval = false;
|
||||
for(uint32_t i = 0; i < bitfieldLength; i++) {
|
||||
for(int32_t i = 0; i < bitfieldLength; ++i) {
|
||||
unsigned char temp = peerBitfield[i] & ~bitfield[i];
|
||||
if(filterEnabled) {
|
||||
temp &= filterBitfield[i];
|
||||
|
@ -185,12 +185,12 @@ bool BitfieldMan::hasMissingPiece(const unsigned char* peerBitfield, uint32_t le
|
|||
return retval;
|
||||
}
|
||||
|
||||
int32_t BitfieldMan::getMissingIndex(const unsigned char* peerBitfield, uint32_t length) const {
|
||||
int32_t BitfieldMan::getMissingIndex(const unsigned char* peerBitfield, int32_t length) const {
|
||||
if(bitfieldLength != length) {
|
||||
return -1;
|
||||
}
|
||||
unsigned char* tempBitfield = new unsigned char[bitfieldLength];
|
||||
for(uint32_t i = 0; i < bitfieldLength; i++) {
|
||||
for(int32_t i = 0; i < bitfieldLength; ++i) {
|
||||
tempBitfield[i] = peerBitfield[i] & ~bitfield[i];
|
||||
if(filterEnabled) {
|
||||
tempBitfield[i] &= filterBitfield[i];
|
||||
|
@ -201,12 +201,12 @@ int32_t BitfieldMan::getMissingIndex(const unsigned char* peerBitfield, uint32_t
|
|||
return index;
|
||||
}
|
||||
|
||||
int32_t BitfieldMan::getMissingUnusedIndex(const unsigned char* peerBitfield, uint32_t length) const {
|
||||
int32_t BitfieldMan::getMissingUnusedIndex(const unsigned char* peerBitfield, int32_t length) const {
|
||||
if(bitfieldLength != length) {
|
||||
return -1;
|
||||
}
|
||||
unsigned char* tempBitfield = new unsigned char[bitfieldLength];
|
||||
for(uint32_t i = 0; i < bitfieldLength; i++) {
|
||||
for(int32_t i = 0; i < bitfieldLength; ++i) {
|
||||
tempBitfield[i] = peerBitfield[i] & ~bitfield[i] & ~useBitfield[i];
|
||||
if(filterEnabled) {
|
||||
tempBitfield[i] &= filterBitfield[i];
|
||||
|
@ -217,11 +217,11 @@ int32_t BitfieldMan::getMissingUnusedIndex(const unsigned char* peerBitfield, ui
|
|||
return index;
|
||||
}
|
||||
|
||||
int32_t BitfieldMan::getFirstMissingUnusedIndex(const unsigned char* peerBitfield, uint32_t length) const {
|
||||
int32_t BitfieldMan::getFirstMissingUnusedIndex(const unsigned char* peerBitfield, int32_t length) const {
|
||||
if(bitfieldLength != length) {
|
||||
return -1;
|
||||
}
|
||||
for(uint32_t i = 0; i < bitfieldLength; i++) {
|
||||
for(int32_t i = 0; i < bitfieldLength; ++i) {
|
||||
unsigned char bit = peerBitfield[i] & ~bitfield[i] & ~useBitfield[i];
|
||||
if(filterEnabled) {
|
||||
bit &= filterBitfield[i];
|
||||
|
@ -237,7 +237,7 @@ int32_t BitfieldMan::getFirstMissingUnusedIndex(const unsigned char* peerBitfiel
|
|||
}
|
||||
|
||||
int32_t BitfieldMan::getFirstMissingUnusedIndex() const {
|
||||
for(uint32_t i = 0; i < bitfieldLength; i++) {
|
||||
for(int32_t i = 0; i < bitfieldLength; ++i) {
|
||||
unsigned char bit = ~bitfield[i] & ~useBitfield[i];
|
||||
if(filterEnabled) {
|
||||
bit &= filterBitfield[i];
|
||||
|
@ -254,7 +254,7 @@ int32_t BitfieldMan::getFirstMissingUnusedIndex() const {
|
|||
|
||||
int32_t BitfieldMan::getMissingIndex() const {
|
||||
unsigned char* tempBitfield = new unsigned char[bitfieldLength];
|
||||
for(uint32_t i = 0; i < bitfieldLength; i++) {
|
||||
for(int32_t i = 0; i < bitfieldLength; ++i) {
|
||||
tempBitfield[i] = ~bitfield[i];
|
||||
if(filterEnabled) {
|
||||
tempBitfield[i] &= filterBitfield[i];
|
||||
|
@ -281,7 +281,7 @@ public:
|
|||
Range(int32_t startIndex = 0, int32_t endIndex = 0):startIndex(startIndex),
|
||||
endIndex(endIndex) {}
|
||||
|
||||
uint32_t getSize() const {
|
||||
int32_t getSize() const {
|
||||
return endIndex-startIndex;
|
||||
}
|
||||
|
||||
|
@ -317,7 +317,7 @@ int32_t BitfieldMan::getEndIndex(int32_t index) const {
|
|||
int32_t BitfieldMan::getSparseMissingUnusedIndex() const {
|
||||
Range maxRange;
|
||||
int32_t index = 0;
|
||||
uint32_t blocks = countBlock();
|
||||
int32_t blocks = countBlock();
|
||||
Range currentRange;
|
||||
while(index < (int32_t)blocks) {
|
||||
currentRange.startIndex = getStartIndex(index);
|
||||
|
@ -343,7 +343,7 @@ int32_t BitfieldMan::getSparseMissingUnusedIndex() const {
|
|||
|
||||
BlockIndexes BitfieldMan::getAllMissingIndexes() const {
|
||||
BlockIndexes missingIndexes;
|
||||
for(uint32_t i = 0; i < bitfieldLength; i++) {
|
||||
for(int32_t i = 0; i < bitfieldLength; ++i) {
|
||||
unsigned char bit = ~bitfield[i];
|
||||
if(filterEnabled) {
|
||||
bit &= filterBitfield[i];
|
||||
|
@ -358,12 +358,12 @@ BlockIndexes BitfieldMan::getAllMissingIndexes() const {
|
|||
return missingIndexes;
|
||||
}
|
||||
|
||||
BlockIndexes BitfieldMan::getAllMissingIndexes(const unsigned char* peerBitfield, uint32_t peerBitfieldLength) const {
|
||||
BlockIndexes BitfieldMan::getAllMissingIndexes(const unsigned char* peerBitfield, int32_t peerBitfieldLength) const {
|
||||
BlockIndexes missingIndexes;
|
||||
if(bitfieldLength != peerBitfieldLength) {
|
||||
return missingIndexes;
|
||||
}
|
||||
for(uint32_t i = 0; i < bitfieldLength; i++) {
|
||||
for(int32_t i = 0; i < bitfieldLength; ++i) {
|
||||
unsigned char bit = peerBitfield[i] & ~bitfield[i];
|
||||
if(filterEnabled) {
|
||||
bit &= filterBitfield[i];
|
||||
|
@ -378,17 +378,17 @@ BlockIndexes BitfieldMan::getAllMissingIndexes(const unsigned char* peerBitfield
|
|||
return missingIndexes;
|
||||
}
|
||||
|
||||
uint32_t BitfieldMan::countMissingBlock() const {
|
||||
int32_t BitfieldMan::countMissingBlock() const {
|
||||
return cachedNumMissingBlock;
|
||||
}
|
||||
|
||||
uint32_t BitfieldMan::countMissingBlockNow() const {
|
||||
int32_t BitfieldMan::countMissingBlockNow() const {
|
||||
if(filterEnabled) {
|
||||
unsigned char* temp = new unsigned char[bitfieldLength];
|
||||
for(uint32_t i = 0; i < bitfieldLength; i++) {
|
||||
for(int32_t i = 0; i < bitfieldLength; ++i) {
|
||||
temp[i] = bitfield[i]&filterBitfield[i];
|
||||
}
|
||||
uint32_t count = countSetBit(filterBitfield, bitfieldLength)-
|
||||
int32_t count = countSetBit(filterBitfield, bitfieldLength)-
|
||||
countSetBit(temp, bitfieldLength);
|
||||
delete [] temp;
|
||||
return count;
|
||||
|
@ -397,7 +397,7 @@ uint32_t BitfieldMan::countMissingBlockNow() const {
|
|||
}
|
||||
}
|
||||
|
||||
uint32_t BitfieldMan::countBlock() const {
|
||||
int32_t BitfieldMan::countBlock() const {
|
||||
if(filterEnabled) {
|
||||
return cachedNumFilteredBlock;
|
||||
} else {
|
||||
|
@ -405,7 +405,7 @@ uint32_t BitfieldMan::countBlock() const {
|
|||
}
|
||||
}
|
||||
|
||||
uint32_t BitfieldMan::countFilteredBlockNow() const {
|
||||
int32_t BitfieldMan::countFilteredBlockNow() const {
|
||||
if(filterEnabled) {
|
||||
return countSetBit(filterBitfield, bitfieldLength);
|
||||
} else {
|
||||
|
@ -446,14 +446,14 @@ bool BitfieldMan::unsetBit(int32_t index) {
|
|||
|
||||
bool BitfieldMan::isAllBitSet() const {
|
||||
if(filterEnabled) {
|
||||
for(uint32_t i = 0; i < bitfieldLength; i++) {
|
||||
for(int32_t i = 0; i < bitfieldLength; ++i) {
|
||||
if((bitfield[i]&filterBitfield[i]) != filterBitfield[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
for(uint32_t i = 0; i < bitfieldLength-1; i++) {
|
||||
for(int32_t i = 0; i < bitfieldLength-1; ++i) {
|
||||
if(bitfield[i] != 0xff) {
|
||||
return false;
|
||||
}
|
||||
|
@ -480,7 +480,7 @@ bool BitfieldMan::isUseBitSet(int32_t index) const {
|
|||
return isBitSetInternal(useBitfield, index);
|
||||
}
|
||||
|
||||
void BitfieldMan::setBitfield(const unsigned char* bitfield, uint32_t bitfieldLength) {
|
||||
void BitfieldMan::setBitfield(const unsigned char* bitfield, int32_t bitfieldLength) {
|
||||
if(this->bitfieldLength != bitfieldLength) {
|
||||
return;
|
||||
}
|
||||
|
@ -495,7 +495,7 @@ void BitfieldMan::clearAllBit() {
|
|||
}
|
||||
|
||||
void BitfieldMan::setAllBit() {
|
||||
for(uint32_t i = 0; i < blocks; i++) {
|
||||
for(int32_t i = 0; i < blocks; ++i) {
|
||||
setBitInternal(bitfield, i, true);
|
||||
}
|
||||
updateCache();
|
||||
|
@ -507,7 +507,7 @@ void BitfieldMan::clearAllUseBit() {
|
|||
}
|
||||
|
||||
void BitfieldMan::setAllUseBit() {
|
||||
for(uint32_t i = 0; i < blocks; i++) {
|
||||
for(int32_t i = 0; i < blocks; ++i) {
|
||||
setBitInternal(useBitfield, i, true);
|
||||
}
|
||||
}
|
||||
|
@ -516,7 +516,7 @@ bool BitfieldMan::setFilterBit(int32_t index) {
|
|||
return setBitInternal(filterBitfield, index, true);
|
||||
}
|
||||
|
||||
void BitfieldMan::addFilter(int64_t offset, uint64_t length) {
|
||||
void BitfieldMan::addFilter(int64_t offset, int64_t length) {
|
||||
if(!filterBitfield) {
|
||||
filterBitfield = new unsigned char[bitfieldLength];
|
||||
memset(filterBitfield, 0, bitfieldLength);
|
||||
|
@ -552,29 +552,29 @@ bool BitfieldMan::isFilterEnabled() const {
|
|||
return filterEnabled;
|
||||
}
|
||||
|
||||
uint64_t BitfieldMan::getFilteredTotalLength() const {
|
||||
int64_t BitfieldMan::getFilteredTotalLength() const {
|
||||
return cachedFilteredTotalLength;
|
||||
}
|
||||
|
||||
uint64_t BitfieldMan::getFilteredTotalLengthNow() const {
|
||||
int64_t BitfieldMan::getFilteredTotalLengthNow() const {
|
||||
if(!filterBitfield) {
|
||||
return 0;
|
||||
}
|
||||
uint32_t filteredBlocks = countSetBit(filterBitfield, bitfieldLength);
|
||||
int32_t filteredBlocks = countSetBit(filterBitfield, bitfieldLength);
|
||||
if(filteredBlocks == 0) {
|
||||
return 0;
|
||||
}
|
||||
if(isBitSetInternal(filterBitfield, blocks-1)) {
|
||||
return ((uint64_t)filteredBlocks-1)*blockLength+getLastBlockLength();
|
||||
return ((int64_t)filteredBlocks-1)*blockLength+getLastBlockLength();
|
||||
} else {
|
||||
return ((uint64_t)filteredBlocks)*blockLength;
|
||||
return ((int64_t)filteredBlocks)*blockLength;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t BitfieldMan::getCompletedLength(bool useFilter) const {
|
||||
int64_t BitfieldMan::getCompletedLength(bool useFilter) const {
|
||||
unsigned char* temp = new unsigned char[bitfieldLength];
|
||||
if(useFilter) {
|
||||
for(uint32_t i = 0; i < bitfieldLength; i++) {
|
||||
for(int32_t i = 0; i < bitfieldLength; ++i) {
|
||||
temp[i] = bitfield[i];
|
||||
if(filterEnabled) {
|
||||
temp[i] &= filterBitfield[i];
|
||||
|
@ -583,34 +583,34 @@ uint64_t BitfieldMan::getCompletedLength(bool useFilter) const {
|
|||
} else {
|
||||
memcpy(temp, bitfield, bitfieldLength);
|
||||
}
|
||||
uint32_t completedBlocks = countSetBit(temp, bitfieldLength);
|
||||
uint64_t completedLength = 0;
|
||||
int32_t completedBlocks = countSetBit(temp, bitfieldLength);
|
||||
int64_t completedLength = 0;
|
||||
if(completedBlocks == 0) {
|
||||
completedLength = 0;
|
||||
} else {
|
||||
if(isBitSetInternal(temp, blocks-1)) {
|
||||
completedLength = ((uint64_t)completedBlocks-1)*blockLength+getLastBlockLength();
|
||||
completedLength = ((int64_t)completedBlocks-1)*blockLength+getLastBlockLength();
|
||||
} else {
|
||||
completedLength = ((uint64_t)completedBlocks)*blockLength;
|
||||
completedLength = ((int64_t)completedBlocks)*blockLength;
|
||||
}
|
||||
}
|
||||
delete [] temp;
|
||||
return completedLength;
|
||||
}
|
||||
|
||||
uint64_t BitfieldMan::getCompletedLength() const {
|
||||
int64_t BitfieldMan::getCompletedLength() const {
|
||||
return cachedCompletedLength;
|
||||
}
|
||||
|
||||
uint64_t BitfieldMan::getCompletedLengthNow() const {
|
||||
int64_t BitfieldMan::getCompletedLengthNow() const {
|
||||
return getCompletedLength(false);
|
||||
}
|
||||
|
||||
uint64_t BitfieldMan::getFilteredCompletedLength() const {
|
||||
int64_t BitfieldMan::getFilteredCompletedLength() const {
|
||||
return cachedFilteredComletedLength;
|
||||
}
|
||||
|
||||
uint64_t BitfieldMan::getFilteredCompletedLengthNow() const {
|
||||
int64_t BitfieldMan::getFilteredCompletedLengthNow() const {
|
||||
return getCompletedLength(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -43,26 +43,26 @@ typedef deque<int> BlockIndexes;
|
|||
|
||||
class BitfieldMan {
|
||||
private:
|
||||
uint32_t blockLength;
|
||||
uint64_t totalLength;
|
||||
int32_t blockLength;
|
||||
int64_t totalLength;
|
||||
unsigned char* bitfield;
|
||||
unsigned char* useBitfield;
|
||||
unsigned char* filterBitfield;
|
||||
uint32_t bitfieldLength;
|
||||
uint32_t blocks;
|
||||
int32_t bitfieldLength;
|
||||
int32_t blocks;
|
||||
bool filterEnabled;
|
||||
RandomizerHandle randomizer;
|
||||
|
||||
// for caching
|
||||
uint32_t cachedNumMissingBlock;
|
||||
uint32_t cachedNumFilteredBlock;
|
||||
uint64_t cachedCompletedLength;
|
||||
uint64_t cachedFilteredComletedLength;
|
||||
uint64_t cachedFilteredTotalLength;
|
||||
int32_t cachedNumMissingBlock;
|
||||
int32_t cachedNumFilteredBlock;
|
||||
int64_t cachedCompletedLength;
|
||||
int64_t cachedFilteredComletedLength;
|
||||
int64_t cachedFilteredTotalLength;
|
||||
|
||||
uint32_t countSetBit(const unsigned char* bitfield, uint32_t len) const;
|
||||
int32_t getNthBitIndex(const unsigned char bit, uint32_t nth) const;
|
||||
int32_t getMissingIndexRandomly(const unsigned char* bitfield, uint32_t len) const;
|
||||
int32_t countSetBit(const unsigned char* bitfield, int32_t len) const;
|
||||
int32_t getNthBitIndex(const unsigned char bit, int32_t nth) const;
|
||||
int32_t getMissingIndexRandomly(const unsigned char* bitfield, int32_t len) const;
|
||||
bool isBitSetInternal(const unsigned char* bitfield, int32_t index) const;
|
||||
bool setBitInternal(unsigned char* bitfield, int32_t index, bool on);
|
||||
bool setFilterBit(int32_t index);
|
||||
|
@ -70,9 +70,9 @@ private:
|
|||
int32_t getStartIndex(int32_t index) const;
|
||||
int32_t getEndIndex(int32_t index) const;
|
||||
|
||||
uint64_t getCompletedLength(bool useFilter) const;
|
||||
int64_t getCompletedLength(bool useFilter) const;
|
||||
public:
|
||||
BitfieldMan(uint32_t blockLength, uint64_t totalLength);
|
||||
BitfieldMan(int32_t blockLength, int64_t totalLength);
|
||||
BitfieldMan(const BitfieldMan& bitfieldMan);
|
||||
~BitfieldMan();
|
||||
|
||||
|
@ -105,13 +105,13 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
uint32_t getBlockLength() const { return blockLength; }
|
||||
int32_t getBlockLength() const { return blockLength; }
|
||||
|
||||
uint32_t getLastBlockLength() const {
|
||||
int32_t getLastBlockLength() const {
|
||||
return totalLength-blockLength*(blocks-1);
|
||||
}
|
||||
|
||||
uint32_t getBlockLength(int32_t index) const {
|
||||
int32_t getBlockLength(int32_t index) const {
|
||||
if(index == (int32_t)(blocks-1)) {
|
||||
return getLastBlockLength();
|
||||
} else if(0 <= index && index < (int32_t)(blocks-1)) {
|
||||
|
@ -121,16 +121,16 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
uint64_t getTotalLength() const { return totalLength; }
|
||||
int64_t getTotalLength() const { return totalLength; }
|
||||
|
||||
/**
|
||||
* affected by filter
|
||||
*/
|
||||
bool hasMissingPiece(const unsigned char* bitfield, uint32_t len) const;
|
||||
bool hasMissingPiece(const unsigned char* bitfield, int32_t len) const;
|
||||
/**
|
||||
* affected by filter
|
||||
*/
|
||||
int32_t getMissingIndex(const unsigned char* bitfield, uint32_t len) const;
|
||||
int32_t getMissingIndex(const unsigned char* bitfield, int32_t len) const;
|
||||
/**
|
||||
* affected by filter
|
||||
*/
|
||||
|
@ -138,7 +138,7 @@ public:
|
|||
/**
|
||||
* affected by filter
|
||||
*/
|
||||
int32_t getFirstMissingUnusedIndex(const unsigned char* bitfield, uint32_t len) const;
|
||||
int32_t getFirstMissingUnusedIndex(const unsigned char* bitfield, int32_t len) const;
|
||||
/**
|
||||
* affected by filter
|
||||
*/
|
||||
|
@ -146,7 +146,7 @@ public:
|
|||
/**
|
||||
* affected by filter
|
||||
*/
|
||||
int32_t getMissingUnusedIndex(const unsigned char* bitfield, uint32_t len) const;
|
||||
int32_t getMissingUnusedIndex(const unsigned char* bitfield, int32_t len) const;
|
||||
/**
|
||||
* affected by filter
|
||||
*/
|
||||
|
@ -162,15 +162,15 @@ public:
|
|||
/**
|
||||
* affected by filter
|
||||
*/
|
||||
BlockIndexes getAllMissingIndexes(const unsigned char* bitfield, uint32_t len) const;
|
||||
BlockIndexes getAllMissingIndexes(const unsigned char* bitfield, int32_t len) const;
|
||||
/**
|
||||
* affected by filter
|
||||
*/
|
||||
uint32_t countMissingBlock() const;
|
||||
int32_t countMissingBlock() const;
|
||||
/**
|
||||
* affected by filter
|
||||
*/
|
||||
uint32_t countMissingBlockNow() const;
|
||||
int32_t countMissingBlockNow() const;
|
||||
|
||||
bool setUseBit(int32_t index);
|
||||
bool unsetUseBit(int32_t index);
|
||||
|
@ -187,20 +187,20 @@ public:
|
|||
bool isAllBitSet() const;
|
||||
|
||||
const unsigned char* getBitfield() const { return bitfield; }
|
||||
uint32_t getBitfieldLength() const { return bitfieldLength; }
|
||||
int32_t getBitfieldLength() const { return bitfieldLength; }
|
||||
|
||||
/**
|
||||
* affected by filter
|
||||
*/
|
||||
uint32_t countBlock() const;
|
||||
int32_t countBlock() const;
|
||||
/**
|
||||
* affected by filter
|
||||
*/
|
||||
uint32_t countFilteredBlockNow() const;
|
||||
int32_t countFilteredBlockNow() const;
|
||||
|
||||
int32_t getMaxIndex() const { return blocks-1; }
|
||||
|
||||
void setBitfield(const unsigned char* bitfield, uint32_t bitfieldLength);
|
||||
void setBitfield(const unsigned char* bitfield, int32_t bitfieldLength);
|
||||
|
||||
void clearAllBit();
|
||||
void setAllBit();
|
||||
|
@ -208,7 +208,7 @@ public:
|
|||
void clearAllUseBit();
|
||||
void setAllUseBit();
|
||||
|
||||
void addFilter(int64_t offset, uint64_t length);
|
||||
void addFilter(int64_t offset, int64_t length);
|
||||
/**
|
||||
* Clears filter and disables filter
|
||||
*/
|
||||
|
@ -220,24 +220,24 @@ public:
|
|||
/**
|
||||
* affected by filter
|
||||
*/
|
||||
uint64_t getFilteredTotalLength() const;
|
||||
int64_t getFilteredTotalLength() const;
|
||||
/**
|
||||
* affected by filter
|
||||
*/
|
||||
uint64_t getFilteredTotalLengthNow() const;
|
||||
int64_t getFilteredTotalLengthNow() const;
|
||||
|
||||
uint64_t getCompletedLength() const;
|
||||
int64_t getCompletedLength() const;
|
||||
|
||||
uint64_t getCompletedLengthNow() const;
|
||||
int64_t getCompletedLengthNow() const;
|
||||
|
||||
/**
|
||||
* affected by filter
|
||||
*/
|
||||
uint64_t getFilteredCompletedLength() const;
|
||||
int64_t getFilteredCompletedLength() const;
|
||||
/**
|
||||
* affected by filter
|
||||
*/
|
||||
uint64_t getFilteredCompletedLengthNow() const;
|
||||
int64_t getFilteredCompletedLengthNow() const;
|
||||
|
||||
void setRandomizer(const RandomizerHandle& randomizer) {
|
||||
this->randomizer = randomizer;
|
||||
|
|
|
@ -36,15 +36,15 @@
|
|||
#include "PeerMessageUtil.h"
|
||||
#include "Util.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "message.h"
|
||||
|
||||
BtAllowedFastMessageHandle BtAllowedFastMessage::create(const unsigned char* data, uint32_t dataLength) {
|
||||
BtAllowedFastMessageHandle BtAllowedFastMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||
if(dataLength != 5) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %u. It should be %d", "allowed fast", dataLength, 5);
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "allowed fast", dataLength, 5);
|
||||
}
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%u for %s. It should be %d.",
|
||||
id, "allowed fast", ID);
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "allowed fast", ID);
|
||||
}
|
||||
BtAllowedFastMessageHandle message = new BtAllowedFastMessage();
|
||||
message->setIndex(PeerMessageUtil::getIntParam(data, 1));
|
||||
|
@ -59,7 +59,7 @@ void BtAllowedFastMessage::doReceivedAction() {
|
|||
peer->addPeerAllowedIndex(index);
|
||||
}
|
||||
|
||||
uint32_t BtAllowedFastMessage::MESSAGE_LENGTH = 9;
|
||||
int32_t BtAllowedFastMessage::MESSAGE_LENGTH = 9;
|
||||
|
||||
const unsigned char* BtAllowedFastMessage::getMessage() {
|
||||
if(!msg) {
|
||||
|
@ -76,7 +76,7 @@ const unsigned char* BtAllowedFastMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
uint32_t BtAllowedFastMessage::getMessageLength() {
|
||||
int32_t BtAllowedFastMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ private:
|
|||
int32_t index;
|
||||
unsigned char* msg;
|
||||
|
||||
static uint32_t MESSAGE_LENGTH;
|
||||
static int32_t MESSAGE_LENGTH;
|
||||
public:
|
||||
BtAllowedFastMessage(int32_t index = 0)
|
||||
:SimpleBtMessage(),
|
||||
|
@ -57,22 +57,22 @@ public:
|
|||
delete [] msg;
|
||||
}
|
||||
|
||||
static const uint8_t ID = 17;
|
||||
static const int8_t ID = 17;
|
||||
|
||||
void setIndex(int32_t index) {
|
||||
this->index = index;
|
||||
}
|
||||
int32_t getIndex() const { return index; }
|
||||
|
||||
static BtAllowedFastMessageHandle create(const unsigned char* data, uint32_t dataLength);
|
||||
static BtAllowedFastMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
|
||||
virtual uint8_t getId() { return ID; }
|
||||
virtual int8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual uint32_t getMessageLength();
|
||||
virtual int32_t getMessageLength();
|
||||
|
||||
virtual string toString() const;
|
||||
|
||||
|
|
|
@ -41,10 +41,10 @@
|
|||
class BtAllowedFastMessageValidator : public BtMessageValidator {
|
||||
private:
|
||||
const BtAllowedFastMessage* message;
|
||||
uint32_t numPiece;
|
||||
int32_t numPiece;
|
||||
public:
|
||||
BtAllowedFastMessageValidator(const BtAllowedFastMessage* message,
|
||||
uint32_t numPiece):
|
||||
int32_t numPiece):
|
||||
message(message),
|
||||
numPiece(numPiece) {}
|
||||
|
||||
|
|
|
@ -36,8 +36,9 @@
|
|||
#include "PeerMessageUtil.h"
|
||||
#include "Util.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "message.h"
|
||||
|
||||
void BtBitfieldMessage::setBitfield(const unsigned char* bitfield, uint32_t bitfieldLength) {
|
||||
void BtBitfieldMessage::setBitfield(const unsigned char* bitfield, int32_t bitfieldLength) {
|
||||
if(this->bitfield == bitfield) {
|
||||
return;
|
||||
}
|
||||
|
@ -49,15 +50,14 @@ void BtBitfieldMessage::setBitfield(const unsigned char* bitfield, uint32_t bitf
|
|||
}
|
||||
|
||||
BtBitfieldMessageHandle
|
||||
BtBitfieldMessage::create(const unsigned char* data, uint32_t dataLength)
|
||||
BtBitfieldMessage::create(const unsigned char* data, int32_t dataLength)
|
||||
{
|
||||
if(dataLength <= 1) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %d. It should be greater than %d", "bitfield", dataLength, 1);
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "bitfield", dataLength, 1);
|
||||
}
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%d for %s. It should be %d.",
|
||||
id, "bitfield", ID);
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "bitfield", ID);
|
||||
}
|
||||
BtBitfieldMessageHandle message = new BtBitfieldMessage();
|
||||
message->setBitfield((unsigned char*)data+1, dataLength-1);
|
||||
|
@ -85,7 +85,7 @@ const unsigned char* BtBitfieldMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
uint32_t BtBitfieldMessage::getMessageLength() {
|
||||
int32_t BtBitfieldMessage::getMessageLength() {
|
||||
getMessage();
|
||||
return msgLength;
|
||||
}
|
||||
|
|
|
@ -44,9 +44,9 @@ typedef SharedHandle<BtBitfieldMessage> BtBitfieldMessageHandle;
|
|||
class BtBitfieldMessage : public SimpleBtMessage {
|
||||
private:
|
||||
unsigned char* bitfield;
|
||||
uint32_t bitfieldLength;
|
||||
int32_t bitfieldLength;
|
||||
unsigned char* msg;
|
||||
uint32_t msgLength;
|
||||
int32_t msgLength;
|
||||
|
||||
void init() {
|
||||
bitfield = 0;
|
||||
|
@ -61,7 +61,7 @@ public:
|
|||
}
|
||||
|
||||
BtBitfieldMessage(const unsigned char* bitfield,
|
||||
uint32_t bitfieldLength):SimpleBtMessage()
|
||||
int32_t bitfieldLength):SimpleBtMessage()
|
||||
{
|
||||
init();
|
||||
setBitfield(bitfield, bitfieldLength);
|
||||
|
@ -72,23 +72,23 @@ public:
|
|||
delete [] msg;
|
||||
}
|
||||
|
||||
static const uint8_t ID = 5;
|
||||
static const int8_t ID = 5;
|
||||
|
||||
void setBitfield(const unsigned char* bitfield, uint32_t bitfieldLength);
|
||||
void setBitfield(const unsigned char* bitfield, int32_t bitfieldLength);
|
||||
|
||||
const unsigned char* getBitfield() const { return bitfield; }
|
||||
|
||||
uint32_t getBitfieldLength() const { return bitfieldLength; }
|
||||
int32_t getBitfieldLength() const { return bitfieldLength; }
|
||||
|
||||
static BtBitfieldMessageHandle create(const unsigned char* data, uint32_t dataLength);
|
||||
static BtBitfieldMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
|
||||
virtual uint8_t getId() { return ID; }
|
||||
virtual int8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual uint32_t getMessageLength();
|
||||
virtual int32_t getMessageLength();
|
||||
|
||||
virtual string toString() const;
|
||||
};
|
||||
|
|
|
@ -36,15 +36,15 @@
|
|||
#include "PeerMessageUtil.h"
|
||||
#include "Util.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "message.h"
|
||||
|
||||
BtCancelMessageHandle BtCancelMessage::create(const unsigned char* data, uint32_t dataLength) {
|
||||
BtCancelMessageHandle BtCancelMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||
if(dataLength != 13) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %u. It should be %d", "cancel", dataLength, 13);
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "cancel", dataLength, 13);
|
||||
}
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%u for %s. It should be %d.",
|
||||
id, "cancel", ID);
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "cancel", ID);
|
||||
}
|
||||
BtCancelMessageHandle message = new BtCancelMessage();
|
||||
message->setIndex(PeerMessageUtil::getIntParam(data, 1));
|
||||
|
@ -57,7 +57,7 @@ void BtCancelMessage::doReceivedAction() {
|
|||
dispatcher->doCancelSendingPieceAction(index, begin, length);
|
||||
}
|
||||
|
||||
uint32_t BtCancelMessage::MESSAGE_LENGTH = 17;
|
||||
int32_t BtCancelMessage::MESSAGE_LENGTH = 17;
|
||||
|
||||
const unsigned char* BtCancelMessage::getMessage() {
|
||||
if(!msg) {
|
||||
|
@ -78,11 +78,11 @@ const unsigned char* BtCancelMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
uint32_t BtCancelMessage::getMessageLength() {
|
||||
int32_t BtCancelMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
string BtCancelMessage::toString() const {
|
||||
return "cancel index="+Util::itos(index)+", begin="+Util::itos(begin)+
|
||||
", length="+Util::uitos(length);
|
||||
", length="+Util::itos(length);
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#define _D_BT_CANCEL_MESSAGE_H_
|
||||
|
||||
#include "SimpleBtMessage.h"
|
||||
#include "message.h"
|
||||
|
||||
class BtCancelMessage;
|
||||
|
||||
|
@ -45,12 +46,12 @@ class BtCancelMessage : public SimpleBtMessage {
|
|||
private:
|
||||
int32_t index;
|
||||
int32_t begin;
|
||||
uint32_t length;
|
||||
int32_t length;
|
||||
unsigned char* msg;
|
||||
|
||||
static uint32_t MESSAGE_LENGTH;
|
||||
static int32_t MESSAGE_LENGTH;
|
||||
public:
|
||||
BtCancelMessage(int32_t index = 0, int32_t begin = 0, uint32_t length = 0)
|
||||
BtCancelMessage(int32_t index = 0, int32_t begin = 0, int32_t length = 0)
|
||||
:SimpleBtMessage(),
|
||||
index(index),
|
||||
begin(begin),
|
||||
|
@ -61,7 +62,7 @@ public:
|
|||
delete [] msg;
|
||||
}
|
||||
|
||||
static const uint8_t ID = 8;
|
||||
static const int8_t ID = 8;
|
||||
|
||||
int32_t getIndex() const { return index; }
|
||||
|
||||
|
@ -71,19 +72,19 @@ public:
|
|||
|
||||
void setBegin(int32_t begin) { this->begin = begin; }
|
||||
|
||||
uint32_t getLength() const { return length; }
|
||||
int32_t getLength() const { return length; }
|
||||
|
||||
void setLength(uint32_t length) { this->length = length; }
|
||||
void setLength(int32_t length) { this->length = length; }
|
||||
|
||||
static BtCancelMessageHandle create(const unsigned char* data, uint32_t dataLength);
|
||||
static BtCancelMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
|
||||
virtual uint8_t getId() { return ID; }
|
||||
virtual int8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual uint32_t getMessageLength();
|
||||
virtual int32_t getMessageLength();
|
||||
|
||||
virtual string toString() const;
|
||||
};
|
||||
|
|
|
@ -41,12 +41,12 @@
|
|||
class BtCancelMessageValidator : public BtMessageValidator {
|
||||
private:
|
||||
const BtCancelMessage* message;
|
||||
uint32_t numPiece;
|
||||
uint32_t pieceLength;
|
||||
int32_t numPiece;
|
||||
int32_t pieceLength;
|
||||
public:
|
||||
BtCancelMessageValidator(const BtCancelMessage* message,
|
||||
uint32_t numPiece,
|
||||
uint32_t pieceLength):
|
||||
int32_t numPiece,
|
||||
int32_t pieceLength):
|
||||
message(message),
|
||||
numPiece(numPiece),
|
||||
pieceLength(pieceLength) {}
|
||||
|
|
|
@ -41,9 +41,9 @@ class BtCancelSendingPieceEvent : public BtEvent {
|
|||
private:
|
||||
int32_t index;
|
||||
int32_t begin;
|
||||
uint32_t length;
|
||||
int32_t length;
|
||||
public:
|
||||
BtCancelSendingPieceEvent(int32_t index, int32_t begin, uint32_t length):
|
||||
BtCancelSendingPieceEvent(int32_t index, int32_t begin, int32_t length):
|
||||
index(index), begin(begin), length(length) {}
|
||||
|
||||
virtual ~BtCancelSendingPieceEvent() {}
|
||||
|
@ -64,11 +64,11 @@ public:
|
|||
return begin;
|
||||
}
|
||||
|
||||
void setLength(uint32_t length) {
|
||||
void setLength(int32_t length) {
|
||||
this->length = length;
|
||||
}
|
||||
|
||||
uint32_t getLength() const {
|
||||
int32_t getLength() const {
|
||||
return length;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -35,15 +35,15 @@
|
|||
#include "BtChokeMessage.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "message.h"
|
||||
|
||||
BtChokeMessageHandle BtChokeMessage::create(const unsigned char* data, uint32_t dataLength) {
|
||||
BtChokeMessageHandle BtChokeMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||
if(dataLength != 1) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %d. It should be %d", "choke", dataLength, 1);
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "choke", dataLength, 1);
|
||||
}
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%d for %s. It should be %d.",
|
||||
id, "choke", ID);
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "choke", ID);
|
||||
}
|
||||
BtChokeMessageHandle chokeMessage = new BtChokeMessage();
|
||||
return chokeMessage;
|
||||
|
@ -59,7 +59,7 @@ bool BtChokeMessage::sendPredicate() const {
|
|||
return !peer->amChoking;
|
||||
}
|
||||
|
||||
uint32_t BtChokeMessage::MESSAGE_LENGTH = 5;
|
||||
int32_t BtChokeMessage::MESSAGE_LENGTH = 5;
|
||||
|
||||
const unsigned char* BtChokeMessage::getMessage() {
|
||||
if(!msg) {
|
||||
|
@ -74,7 +74,7 @@ const unsigned char* BtChokeMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
uint32_t BtChokeMessage::getMessageLength() {
|
||||
int32_t BtChokeMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ class BtChokeMessage : public SimpleBtMessage {
|
|||
private:
|
||||
unsigned char* msg;
|
||||
|
||||
static uint32_t MESSAGE_LENGTH;
|
||||
static int32_t MESSAGE_LENGTH;
|
||||
public:
|
||||
BtChokeMessage():SimpleBtMessage(), msg(0) {}
|
||||
|
||||
|
@ -53,19 +53,19 @@ public:
|
|||
delete [] msg;
|
||||
}
|
||||
|
||||
static const uint8_t ID = 0;
|
||||
static const int8_t ID = 0;
|
||||
|
||||
virtual uint8_t getId() { return ID; }
|
||||
virtual int8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual uint32_t getMessageLength();
|
||||
virtual int32_t getMessageLength();
|
||||
|
||||
virtual string toString() const;
|
||||
|
||||
static BtChokeMessageHandle create(const unsigned char* data, uint32_t dataLength);
|
||||
static BtChokeMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
|
||||
virtual bool sendPredicate() const;
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ void BtHandshakeMessage::init() {
|
|||
this->reserved[7] |= 0x04;
|
||||
}
|
||||
|
||||
BtHandshakeMessageHandle BtHandshakeMessage::create(const unsigned char* data, uint32_t dataLength) {
|
||||
BtHandshakeMessageHandle BtHandshakeMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||
BtHandshakeMessageHandle message = new BtHandshakeMessage();
|
||||
message->pstrlen = data[0];
|
||||
memcpy(message->pstr, &data[1], PSTR_LENGTH);
|
||||
|
@ -85,7 +85,7 @@ const unsigned char* BtHandshakeMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
uint32_t BtHandshakeMessage::getMessageLength() {
|
||||
int32_t BtHandshakeMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,12 +43,12 @@ typedef SharedHandle<BtHandshakeMessage> BtHandshakeMessageHandle;
|
|||
|
||||
class BtHandshakeMessage : public SimpleBtMessage {
|
||||
public:
|
||||
static const uint32_t PSTR_LENGTH = 19;
|
||||
static const int32_t PSTR_LENGTH = 19;
|
||||
static const unsigned char* BT_PSTR;
|
||||
static const uint32_t RESERVED_LENGTH = 8;
|
||||
static const uint32_t MESSAGE_LENGTH = 68;
|
||||
static const int32_t RESERVED_LENGTH = 8;
|
||||
static const int32_t MESSAGE_LENGTH = 68;
|
||||
private:
|
||||
uint8_t pstrlen;
|
||||
int8_t pstrlen;
|
||||
unsigned char* pstr;
|
||||
unsigned char* reserved;
|
||||
unsigned char* infoHash;
|
||||
|
@ -63,7 +63,7 @@ public:
|
|||
*/
|
||||
BtHandshakeMessage(const unsigned char* infoHash, const unsigned char* peerId);
|
||||
|
||||
static BtHandshakeMessageHandle create(const unsigned char* data, uint32_t dataLength);
|
||||
static BtHandshakeMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
|
||||
virtual ~BtHandshakeMessage() {
|
||||
delete [] msg;
|
||||
|
@ -73,21 +73,21 @@ public:
|
|||
delete [] peerId;
|
||||
}
|
||||
|
||||
static const uint8_t ID = UINT8_MAX;
|
||||
static const int8_t ID = INT8_MAX;
|
||||
|
||||
virtual uint8_t getId() { return ID; }
|
||||
virtual int8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction() {};
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual uint32_t getMessageLength();
|
||||
virtual int32_t getMessageLength();
|
||||
|
||||
virtual string toString() const;
|
||||
|
||||
bool isFastExtensionSupported() const;
|
||||
|
||||
uint8_t getPstrlen() const {
|
||||
int8_t getPstrlen() const {
|
||||
return pstrlen;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,15 +35,15 @@
|
|||
#include "BtHaveAllMessage.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include "message.h"
|
||||
|
||||
BtHaveAllMessageHandle BtHaveAllMessage::create(const unsigned char* data, uint32_t dataLength) {
|
||||
BtHaveAllMessageHandle BtHaveAllMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||
if(dataLength != 1) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %d. It should be %d", "have all", dataLength, 1);
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "have all", dataLength, 1);
|
||||
}
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%d for %s. It should be %d.",
|
||||
id, "have all", ID);
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "have all", ID);
|
||||
}
|
||||
BtHaveAllMessageHandle message = new BtHaveAllMessage();
|
||||
return message;
|
||||
|
@ -57,7 +57,7 @@ void BtHaveAllMessage::doReceivedAction() {
|
|||
peer->setAllBitfield();
|
||||
}
|
||||
|
||||
uint32_t BtHaveAllMessage::MESSAGE_LENGTH = 5;
|
||||
int32_t BtHaveAllMessage::MESSAGE_LENGTH = 5;
|
||||
|
||||
const unsigned char* BtHaveAllMessage::getMessage() {
|
||||
if(!msg) {
|
||||
|
@ -72,7 +72,7 @@ const unsigned char* BtHaveAllMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
uint32_t BtHaveAllMessage::getMessageLength() {
|
||||
int32_t BtHaveAllMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ class BtHaveAllMessage : public SimpleBtMessage {
|
|||
private:
|
||||
unsigned char* msg;
|
||||
|
||||
static uint32_t MESSAGE_LENGTH;
|
||||
static int32_t MESSAGE_LENGTH;
|
||||
public:
|
||||
BtHaveAllMessage():msg(0) {}
|
||||
|
||||
|
@ -53,17 +53,17 @@ public:
|
|||
delete [] msg;
|
||||
}
|
||||
|
||||
static const uint8_t ID = 14;
|
||||
static const int8_t ID = 14;
|
||||
|
||||
static BtHaveAllMessageHandle create(const unsigned char* data, uint32_t dataLength);
|
||||
static BtHaveAllMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
|
||||
virtual uint8_t getId() { return ID; }
|
||||
virtual int8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual uint32_t getMessageLength();
|
||||
virtual int32_t getMessageLength();
|
||||
|
||||
virtual string toString() const;
|
||||
};
|
||||
|
|
|
@ -36,15 +36,15 @@
|
|||
#include "PeerMessageUtil.h"
|
||||
#include "Util.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "message.h"
|
||||
|
||||
BtHaveMessageHandle BtHaveMessage::create(const unsigned char* data, uint32_t dataLength) {
|
||||
BtHaveMessageHandle BtHaveMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||
if(dataLength != 5) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %u. It should be %d", "have", dataLength, 5);
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "have", dataLength, 5);
|
||||
}
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%u for %s. It should be %d.",
|
||||
id, "have", ID);
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "have", ID);
|
||||
}
|
||||
BtHaveMessageHandle message = new BtHaveMessage();
|
||||
message->setIndex(PeerMessageUtil::getIntParam(data, 1));
|
||||
|
@ -59,7 +59,7 @@ bool BtHaveMessage::sendPredicate() const {
|
|||
return !peer->hasPiece(index);
|
||||
}
|
||||
|
||||
uint32_t BtHaveMessage::MESSAGE_LENGTH = 9;
|
||||
int32_t BtHaveMessage::MESSAGE_LENGTH = 9;
|
||||
|
||||
const unsigned char* BtHaveMessage::getMessage() {
|
||||
if(!msg) {
|
||||
|
@ -76,7 +76,7 @@ const unsigned char* BtHaveMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
uint32_t BtHaveMessage::getMessageLength() {
|
||||
int32_t BtHaveMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ class BtHaveMessage : public SimpleBtMessage {
|
|||
private:
|
||||
int32_t index;
|
||||
unsigned char* msg;
|
||||
static uint32_t MESSAGE_LENGTH;
|
||||
static int32_t MESSAGE_LENGTH;
|
||||
public:
|
||||
BtHaveMessage(int32_t index = 0):index(index), msg(0) {}
|
||||
|
||||
|
@ -53,7 +53,7 @@ public:
|
|||
delete [] msg;
|
||||
}
|
||||
|
||||
static const uint8_t ID = 4;
|
||||
static const int8_t ID = 4;
|
||||
|
||||
void setIndex(int32_t index) {
|
||||
this->index = index;
|
||||
|
@ -61,15 +61,15 @@ public:
|
|||
|
||||
int32_t getIndex() const { return index; }
|
||||
|
||||
static BtHaveMessageHandle create(const unsigned char* data, uint32_t dataLength);
|
||||
static BtHaveMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
|
||||
virtual uint8_t getId() { return ID; }
|
||||
virtual int8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual uint32_t getMessageLength();
|
||||
virtual int32_t getMessageLength();
|
||||
|
||||
virtual bool sendPredicate() const;
|
||||
|
||||
|
|
|
@ -35,15 +35,15 @@
|
|||
#include "BtHaveNoneMessage.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include "message.h"
|
||||
|
||||
BtHaveNoneMessageHandle BtHaveNoneMessage::create(const unsigned char* data, uint32_t dataLength) {
|
||||
BtHaveNoneMessageHandle BtHaveNoneMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||
if(dataLength != 1) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %d. It should be %d", "have none", dataLength, 1);
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "have none", dataLength, 1);
|
||||
}
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%d for %s. It should be %d.",
|
||||
id, "have none", ID);
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "have none", ID);
|
||||
}
|
||||
BtHaveNoneMessageHandle message = new BtHaveNoneMessage();
|
||||
return message;
|
||||
|
@ -56,7 +56,7 @@ void BtHaveNoneMessage::doReceivedAction() {
|
|||
}
|
||||
}
|
||||
|
||||
uint32_t BtHaveNoneMessage::MESSAGE_LENGTH = 5;
|
||||
int32_t BtHaveNoneMessage::MESSAGE_LENGTH = 5;
|
||||
|
||||
const unsigned char* BtHaveNoneMessage::getMessage() {
|
||||
if(!msg) {
|
||||
|
@ -71,7 +71,7 @@ const unsigned char* BtHaveNoneMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
uint32_t BtHaveNoneMessage::getMessageLength() {
|
||||
int32_t BtHaveNoneMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ class BtHaveNoneMessage : public SimpleBtMessage {
|
|||
private:
|
||||
unsigned char* msg;
|
||||
|
||||
static uint32_t MESSAGE_LENGTH;
|
||||
static int32_t MESSAGE_LENGTH;
|
||||
public:
|
||||
BtHaveNoneMessage():msg(0) {}
|
||||
|
||||
|
@ -53,17 +53,17 @@ public:
|
|||
delete [] msg;
|
||||
}
|
||||
|
||||
static const uint8_t ID = 15;
|
||||
static const int8_t ID = 15;
|
||||
|
||||
static BtHaveNoneMessageHandle create(const unsigned char* data, uint32_t dataLength);
|
||||
static BtHaveNoneMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
|
||||
virtual uint8_t getId() { return ID; }
|
||||
virtual int8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual uint32_t getMessageLength();
|
||||
virtual int32_t getMessageLength();
|
||||
|
||||
virtual string toString() const;
|
||||
};
|
||||
|
|
|
@ -56,7 +56,7 @@ public:
|
|||
|
||||
virtual void sendPendingMessage() = 0;
|
||||
|
||||
virtual uint32_t countPendingMessage() = 0;
|
||||
virtual int32_t countPendingMessage() = 0;
|
||||
|
||||
virtual bool isSendingMessageInProgress() = 0;
|
||||
};
|
||||
|
|
|
@ -35,15 +35,15 @@
|
|||
#include "BtInterestedMessage.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "message.h"
|
||||
|
||||
BtInterestedMessageHandle BtInterestedMessage::create(const unsigned char* data, uint32_t dataLength) {
|
||||
BtInterestedMessageHandle BtInterestedMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||
if(dataLength != 1) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %d. It should be %d", "interested", dataLength, 1);
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "interested", dataLength, 1);
|
||||
}
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%d for %s. It should be %d.",
|
||||
id, "interested", ID);
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "interested", ID);
|
||||
}
|
||||
BtInterestedMessageHandle message = new BtInterestedMessage();
|
||||
return message;
|
||||
|
@ -57,7 +57,7 @@ bool BtInterestedMessage::sendPredicate() const {
|
|||
return !peer->amInterested;
|
||||
}
|
||||
|
||||
uint32_t BtInterestedMessage::MESSAGE_LENGTH = 5;
|
||||
int32_t BtInterestedMessage::MESSAGE_LENGTH = 5;
|
||||
|
||||
const unsigned char* BtInterestedMessage::getMessage() {
|
||||
if(!msg) {
|
||||
|
@ -72,7 +72,7 @@ const unsigned char* BtInterestedMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
uint32_t BtInterestedMessage::getMessageLength() {
|
||||
int32_t BtInterestedMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ class BtInterestedMessage : public SimpleBtMessage {
|
|||
private:
|
||||
unsigned char* msg;
|
||||
|
||||
static uint32_t MESSAGE_LENGTH;
|
||||
static int32_t MESSAGE_LENGTH;
|
||||
public:
|
||||
BtInterestedMessage():msg(0) {}
|
||||
|
||||
|
@ -53,17 +53,17 @@ public:
|
|||
delete [] msg;
|
||||
}
|
||||
|
||||
static const uint8_t ID = 2;
|
||||
static const int8_t ID = 2;
|
||||
|
||||
static BtInterestedMessageHandle create(const unsigned char* data, uint32_t dataLength);
|
||||
static BtInterestedMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
|
||||
virtual uint8_t getId() { return ID; }
|
||||
virtual int8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual uint32_t getMessageLength();
|
||||
virtual int32_t getMessageLength();
|
||||
|
||||
virtual string toString() const;
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
/* copyright --> */
|
||||
#include "BtKeepAliveMessage.h"
|
||||
|
||||
uint32_t BtKeepAliveMessage::MESSAGE_LENGTH = 4;
|
||||
int32_t BtKeepAliveMessage::MESSAGE_LENGTH = 4;
|
||||
|
||||
const unsigned char* BtKeepAliveMessage::getMessage() {
|
||||
if(!msg) {
|
||||
|
@ -48,6 +48,6 @@ const unsigned char* BtKeepAliveMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
uint32_t BtKeepAliveMessage::getMessageLength() {
|
||||
int32_t BtKeepAliveMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ class BtKeepAliveMessage : public SimpleBtMessage {
|
|||
private:
|
||||
unsigned char* msg;
|
||||
|
||||
static uint32_t MESSAGE_LENGTH;
|
||||
static int32_t MESSAGE_LENGTH;
|
||||
public:
|
||||
BtKeepAliveMessage():msg(0) {}
|
||||
|
||||
|
@ -53,15 +53,15 @@ public:
|
|||
delete [] msg;
|
||||
}
|
||||
|
||||
static const uint8_t ID = 99;
|
||||
static const int8_t ID = 99;
|
||||
|
||||
virtual uint8_t getId() { return ID; }
|
||||
virtual int8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction() {}
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual uint32_t getMessageLength();
|
||||
virtual int32_t getMessageLength();
|
||||
|
||||
virtual string toString() const {
|
||||
return "keep alive";
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
|
||||
virtual bool isUploading() = 0;
|
||||
|
||||
virtual uint8_t getId() = 0;
|
||||
virtual int8_t getId() = 0;
|
||||
|
||||
virtual void doReceivedAction() = 0;
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
|
||||
virtual void sendMessages() = 0;
|
||||
|
||||
virtual void doCancelSendingPieceAction(int32_t index, int32_t begin, uint32_t length) = 0;
|
||||
virtual void doCancelSendingPieceAction(int32_t index, int32_t begin, int32_t length) = 0;
|
||||
|
||||
virtual void doCancelSendingPieceAction(const PieceHandle& piece) = 0;
|
||||
|
||||
|
@ -64,13 +64,13 @@ public:
|
|||
|
||||
virtual bool isSendingInProgress() = 0;
|
||||
|
||||
virtual uint32_t countMessageInQueue() = 0;
|
||||
virtual int32_t countMessageInQueue() = 0;
|
||||
|
||||
virtual uint32_t countOutstandingRequest() = 0;
|
||||
virtual int32_t countOutstandingRequest() = 0;
|
||||
|
||||
virtual bool isOutstandingRequest(int32_t index, int32_t blockIndex) = 0;
|
||||
|
||||
virtual RequestSlot getOutstandingRequest(int32_t index, int32_t begin, uint32_t length) = 0;
|
||||
virtual RequestSlot getOutstandingRequest(int32_t index, int32_t begin, int32_t length) = 0;
|
||||
|
||||
virtual void removeOutstandingRequest(const RequestSlot& slot) = 0;
|
||||
|
||||
|
|
|
@ -44,10 +44,10 @@ public:
|
|||
virtual ~BtMessageFactory() {}
|
||||
|
||||
virtual BtMessageHandle
|
||||
createBtMessage(const unsigned char* msg, uint32_t msgLength) = 0;
|
||||
createBtMessage(const unsigned char* msg, int32_t msgLength) = 0;
|
||||
|
||||
virtual BtMessageHandle
|
||||
createHandshakeMessage(const unsigned char* msg, uint32_t msgLength) = 0;
|
||||
createHandshakeMessage(const unsigned char* msg, int32_t msgLength) = 0;
|
||||
|
||||
virtual BtMessageHandle
|
||||
createHandshakeMessage(const unsigned char* infoHash,
|
||||
|
@ -57,10 +57,10 @@ public:
|
|||
createRequestMessage(const PieceHandle& piece, int32_t blockIndex) = 0;
|
||||
|
||||
virtual BtMessageHandle
|
||||
createCancelMessage(int32_t index, int32_t begin, uint32_t length) = 0;
|
||||
createCancelMessage(int32_t index, int32_t begin, int32_t length) = 0;
|
||||
|
||||
virtual BtMessageHandle
|
||||
createPieceMessage(int32_t index, int32_t begin, uint32_t length) = 0;
|
||||
createPieceMessage(int32_t index, int32_t begin, int32_t length) = 0;
|
||||
|
||||
virtual BtMessageHandle createHaveMessage(int32_t index) = 0;
|
||||
|
||||
|
@ -81,7 +81,7 @@ public:
|
|||
virtual BtMessageHandle createHaveNoneMessage() = 0;
|
||||
|
||||
virtual BtMessageHandle
|
||||
createRejectMessage(int32_t index, int32_t begin, uint32_t length) = 0;
|
||||
createRejectMessage(int32_t index, int32_t begin, int32_t length) = 0;
|
||||
|
||||
virtual BtMessageHandle createAllowedFastMessage(int32_t index) = 0;
|
||||
};
|
||||
|
|
|
@ -35,15 +35,15 @@
|
|||
#include "BtNotInterestedMessage.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "message.h"
|
||||
|
||||
BtNotInterestedMessageHandle BtNotInterestedMessage::create(const unsigned char* data, uint32_t dataLength) {
|
||||
BtNotInterestedMessageHandle BtNotInterestedMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||
if(dataLength != 1) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %d. It should be %d", "not interested", dataLength, 1);
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "not interested", dataLength, 1);
|
||||
}
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%d for %s. It should be %d.",
|
||||
id, "not interested", ID);
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "not interested", ID);
|
||||
}
|
||||
BtNotInterestedMessageHandle message = new BtNotInterestedMessage();
|
||||
return message;
|
||||
|
@ -57,7 +57,7 @@ bool BtNotInterestedMessage::sendPredicate() const {
|
|||
return peer->amInterested;
|
||||
}
|
||||
|
||||
uint32_t BtNotInterestedMessage::MESSAGE_LENGTH = 5;
|
||||
int32_t BtNotInterestedMessage::MESSAGE_LENGTH = 5;
|
||||
|
||||
const unsigned char* BtNotInterestedMessage::getMessage() {
|
||||
if(!msg) {
|
||||
|
@ -72,7 +72,7 @@ const unsigned char* BtNotInterestedMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
uint32_t BtNotInterestedMessage::getMessageLength() {
|
||||
int32_t BtNotInterestedMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ class BtNotInterestedMessage : public SimpleBtMessage {
|
|||
private:
|
||||
unsigned char* msg;
|
||||
|
||||
static uint32_t MESSAGE_LENGTH;
|
||||
static int32_t MESSAGE_LENGTH;
|
||||
public:
|
||||
BtNotInterestedMessage():msg(0) {}
|
||||
|
||||
|
@ -53,17 +53,17 @@ public:
|
|||
delete [] msg;
|
||||
}
|
||||
|
||||
static const uint8_t ID = 3;
|
||||
static const int8_t ID = 3;
|
||||
|
||||
static BtNotInterestedMessageHandle create(const unsigned char* data, uint32_t dataLength);
|
||||
static BtNotInterestedMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
|
||||
virtual uint8_t getId() { return ID; }
|
||||
virtual int8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual uint32_t getMessageLength();
|
||||
virtual int32_t getMessageLength();
|
||||
|
||||
virtual string toString() const;
|
||||
|
||||
|
|
|
@ -40,21 +40,20 @@
|
|||
#include "BtChokingEvent.h"
|
||||
#include "BtCancelSendingPieceEvent.h"
|
||||
|
||||
void BtPieceMessage::setBlock(const unsigned char* block, uint32_t blockLength) {
|
||||
void BtPieceMessage::setBlock(const unsigned char* block, int32_t blockLength) {
|
||||
delete [] this->block;
|
||||
this->blockLength = blockLength;
|
||||
this->block = new unsigned char[this->blockLength];
|
||||
memcpy(this->block, block, this->blockLength);
|
||||
}
|
||||
|
||||
BtPieceMessageHandle BtPieceMessage::create(const unsigned char* data, uint32_t dataLength) {
|
||||
BtPieceMessageHandle BtPieceMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||
if(dataLength <= 9) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %u. It should be greater than %d", "piece", dataLength, 9);
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "piece", dataLength, 9);
|
||||
}
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%u for %s. It should be %d.",
|
||||
id, "piece", ID);
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "piece", ID);
|
||||
}
|
||||
BtPieceMessageHandle message = new BtPieceMessage();
|
||||
message->setIndex(PeerMessageUtil::getIntParam(data, 1));
|
||||
|
@ -74,7 +73,7 @@ void BtPieceMessage::doReceivedAction() {
|
|||
PieceHandle piece = pieceStorage->getPiece(index);
|
||||
int64_t offset =
|
||||
((int64_t)index)*btContext->getPieceLength()+begin;
|
||||
logger->debug("CUID#%d - Piece received. index=%d, begin=%d, length=%u, offset=%llu, blockIndex=%u",
|
||||
logger->debug("CUID#%d - Piece received. index=%d, begin=%d, length=%d, offset=%llu, blockIndex=%d",
|
||||
cuid, index, begin, blockLength, offset, slot.getBlockIndex());
|
||||
pieceStorage->getDiskAdaptor()->writeData(block,
|
||||
blockLength,
|
||||
|
@ -95,7 +94,7 @@ void BtPieceMessage::doReceivedAction() {
|
|||
}
|
||||
}
|
||||
|
||||
uint32_t BtPieceMessage::MESSAGE_HEADER_LENGTH = 13;
|
||||
int32_t BtPieceMessage::MESSAGE_HEADER_LENGTH = 13;
|
||||
|
||||
const unsigned char* BtPieceMessage::getMessageHeader() {
|
||||
if(!msgHeader) {
|
||||
|
@ -115,7 +114,7 @@ const unsigned char* BtPieceMessage::getMessageHeader() {
|
|||
return msgHeader;
|
||||
}
|
||||
|
||||
uint32_t BtPieceMessage::getMessageHeaderLength() {
|
||||
int32_t BtPieceMessage::getMessageHeaderLength() {
|
||||
return MESSAGE_HEADER_LENGTH;
|
||||
}
|
||||
|
||||
|
@ -132,7 +131,7 @@ void BtPieceMessage::send() {
|
|||
leftDataLength = getMessageHeaderLength();
|
||||
sendingInProgress = true;
|
||||
}
|
||||
uint32_t writtenLength
|
||||
int32_t writtenLength
|
||||
= peerConnection->sendMessage(msgHeader+getMessageHeaderLength()-leftDataLength,
|
||||
leftDataLength);
|
||||
if(writtenLength == leftDataLength) {
|
||||
|
@ -146,7 +145,7 @@ void BtPieceMessage::send() {
|
|||
sendingInProgress = false;
|
||||
int64_t pieceDataOffset =
|
||||
((int64_t)index)*btContext->getPieceLength()+begin+blockLength-leftDataLength;
|
||||
uint32_t writtenLength =
|
||||
int32_t writtenLength =
|
||||
sendPieceData(pieceDataOffset, leftDataLength);
|
||||
peer->updateUploadLength(writtenLength);
|
||||
if(writtenLength < leftDataLength) {
|
||||
|
@ -156,16 +155,16 @@ void BtPieceMessage::send() {
|
|||
}
|
||||
}
|
||||
|
||||
uint32_t BtPieceMessage::sendPieceData(int64_t offset, uint32_t length) const {
|
||||
uint32_t BUF_SIZE = 256;
|
||||
int32_t BtPieceMessage::sendPieceData(int64_t offset, int32_t length) const {
|
||||
int32_t BUF_SIZE = 256;
|
||||
unsigned char buf[BUF_SIZE];
|
||||
int32_t iteration = length/BUF_SIZE;
|
||||
uint32_t writtenLength = 0;
|
||||
int32_t writtenLength = 0;
|
||||
for(int32_t i = 0; i < iteration; i++) {
|
||||
if(pieceStorage->getDiskAdaptor()->readData(buf, BUF_SIZE, offset+i*BUF_SIZE) < (int32_t)BUF_SIZE) {
|
||||
if(pieceStorage->getDiskAdaptor()->readData(buf, BUF_SIZE, offset+i*BUF_SIZE) < BUF_SIZE) {
|
||||
throw new DlAbortEx("Failed to read data from disk.");
|
||||
}
|
||||
uint32_t ws = peerConnection->sendMessage(buf, BUF_SIZE);
|
||||
int32_t ws = peerConnection->sendMessage(buf, BUF_SIZE);
|
||||
writtenLength += ws;
|
||||
if(ws != BUF_SIZE) {
|
||||
return writtenLength;
|
||||
|
@ -177,7 +176,7 @@ uint32_t BtPieceMessage::sendPieceData(int64_t offset, uint32_t length) const {
|
|||
if(pieceStorage->getDiskAdaptor()->readData(buf, rem, offset+iteration*BUF_SIZE) < rem) {
|
||||
throw new DlAbortEx("Failed to read data from disk.");
|
||||
}
|
||||
uint32_t ws = peerConnection->sendMessage(buf, rem);
|
||||
int32_t ws = peerConnection->sendMessage(buf, rem);
|
||||
writtenLength += ws;
|
||||
}
|
||||
return writtenLength;
|
||||
|
@ -185,7 +184,7 @@ uint32_t BtPieceMessage::sendPieceData(int64_t offset, uint32_t length) const {
|
|||
|
||||
string BtPieceMessage::toString() const {
|
||||
return "piece index="+Util::itos(index)+", begin="+Util::itos(begin)+
|
||||
", length="+Util::uitos(blockLength);
|
||||
", length="+Util::itos(blockLength);
|
||||
}
|
||||
|
||||
bool BtPieceMessage::checkPieceHash(const PieceHandle& piece) {
|
||||
|
@ -271,7 +270,7 @@ void BtPieceMessage::handleCancelSendingPieceEvent(const BtEventHandle& event) {
|
|||
begin == intEvent->getBegin() &&
|
||||
blockLength == intEvent->getLength()) {
|
||||
logger->debug("CUID#%d - Reject piece message in queue because cancel"
|
||||
" message received. index=%d, begin=%d, length=%u",
|
||||
" message received. index=%d, begin=%d, length=%d",
|
||||
cuid, index, begin, blockLength);
|
||||
if(peer->isFastExtensionEnabled()) {
|
||||
BtMessageHandle rej = messageFactory->createRejectMessage(index,
|
||||
|
|
|
@ -49,13 +49,13 @@ class BtPieceMessage : public AbstractBtMessage {
|
|||
private:
|
||||
int32_t index;
|
||||
int32_t begin;
|
||||
uint32_t blockLength;
|
||||
int32_t blockLength;
|
||||
unsigned char* block;
|
||||
uint32_t leftDataLength;
|
||||
int32_t leftDataLength;
|
||||
bool headerSent;
|
||||
unsigned char* msgHeader;
|
||||
|
||||
static uint32_t MESSAGE_HEADER_LENGTH;
|
||||
static int32_t MESSAGE_HEADER_LENGTH;
|
||||
|
||||
bool checkPieceHash(const PieceHandle& piece);
|
||||
|
||||
|
@ -65,7 +65,7 @@ private:
|
|||
|
||||
void erasePieceOnDisk(const PieceHandle& piece);
|
||||
|
||||
uint32_t sendPieceData(int64_t offset, uint32_t length) const;
|
||||
int32_t sendPieceData(int64_t offset, int32_t length) const;
|
||||
|
||||
class BtChokingEventListener : public AbstractBtEventListener {
|
||||
private:
|
||||
|
@ -93,7 +93,7 @@ private:
|
|||
|
||||
typedef SharedHandle<BtCancelSendingPieceEventListener> BtCancelSendingPieceEventListenerHandle;
|
||||
public:
|
||||
BtPieceMessage(int32_t index = 0, int32_t begin = 0, uint32_t blockLength = 0)
|
||||
BtPieceMessage(int32_t index = 0, int32_t begin = 0, int32_t blockLength = 0)
|
||||
:index(index),
|
||||
begin(begin),
|
||||
blockLength(blockLength),
|
||||
|
@ -112,7 +112,7 @@ public:
|
|||
delete [] block;
|
||||
}
|
||||
|
||||
static const uint8_t ID = 7;
|
||||
static const int8_t ID = 7;
|
||||
|
||||
int32_t getIndex() const { return index; }
|
||||
|
||||
|
@ -124,21 +124,21 @@ public:
|
|||
|
||||
const unsigned char* getBlock() const { return block; }
|
||||
|
||||
void setBlock(const unsigned char* block, uint32_t blockLength);
|
||||
void setBlock(const unsigned char* block, int32_t blockLength);
|
||||
|
||||
uint32_t getBlockLength() const { return blockLength; }
|
||||
int32_t getBlockLength() const { return blockLength; }
|
||||
|
||||
void setBlockLength(uint32_t blockLength) { this->blockLength = blockLength; }
|
||||
void setBlockLength(int32_t blockLength) { this->blockLength = blockLength; }
|
||||
|
||||
static BtPieceMessageHandle create(const unsigned char* data, uint32_t dataLength);
|
||||
static BtPieceMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
|
||||
virtual uint8_t getId() { return ID; }
|
||||
virtual int8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
const unsigned char* getMessageHeader();
|
||||
|
||||
uint32_t getMessageHeaderLength();
|
||||
int32_t getMessageHeaderLength();
|
||||
|
||||
virtual void send();
|
||||
|
||||
|
|
|
@ -41,12 +41,12 @@
|
|||
class BtPieceMessageValidator : public BtMessageValidator {
|
||||
private:
|
||||
const BtPieceMessage* message;
|
||||
uint32_t numPiece;
|
||||
uint32_t pieceLength;
|
||||
int32_t numPiece;
|
||||
int32_t pieceLength;
|
||||
public:
|
||||
BtPieceMessageValidator(const BtPieceMessage* message,
|
||||
uint32_t numPiece,
|
||||
uint32_t pieceLength):
|
||||
int32_t numPiece,
|
||||
int32_t pieceLength):
|
||||
message(message),
|
||||
numPiece(numPiece),
|
||||
pieceLength(pieceLength) {}
|
||||
|
|
|
@ -36,15 +36,15 @@
|
|||
#include "PeerMessageUtil.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "Util.h"
|
||||
#include "message.h"
|
||||
|
||||
BtPortMessageHandle BtPortMessage::create(const unsigned char* data, uint32_t dataLength) {
|
||||
BtPortMessageHandle BtPortMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||
if(dataLength != 3) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %d. It should be %d", "port", dataLength, 3);
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "port", dataLength, 3);
|
||||
}
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%d for %s. It should be %d.",
|
||||
id, "piece", ID);
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "piece", ID);
|
||||
}
|
||||
BtPortMessageHandle message = new BtPortMessage();
|
||||
message->setPort(PeerMessageUtil::getShortIntParam(data, 1));
|
||||
|
@ -52,5 +52,5 @@ BtPortMessageHandle BtPortMessage::create(const unsigned char* data, uint32_t da
|
|||
}
|
||||
|
||||
string BtPortMessage::toString() const {
|
||||
return "port port="+Util::uitos(port);
|
||||
return "port port="+Util::itos(port);
|
||||
}
|
||||
|
|
|
@ -43,21 +43,21 @@ typedef SharedHandle<BtPortMessage> BtPortMessageHandle;
|
|||
|
||||
class BtPortMessage : public AbstractBtMessage {
|
||||
private:
|
||||
uint16_t port;
|
||||
int16_t port;
|
||||
public:
|
||||
BtPortMessage(uint16_t port = 0):port(port) {}
|
||||
BtPortMessage(int16_t port = 0):port(port) {}
|
||||
|
||||
virtual ~BtPortMessage() {}
|
||||
|
||||
static const uint8_t ID = 9;
|
||||
static const int8_t ID = 9;
|
||||
|
||||
uint16_t getPort() const { return port; }
|
||||
int16_t getPort() const { return port; }
|
||||
|
||||
void setPort(uint16_t port) { this->port = port; }
|
||||
void setPort(int16_t port) { this->port = port; }
|
||||
|
||||
virtual uint8_t getId() { return ID; }
|
||||
virtual int8_t getId() { return ID; }
|
||||
|
||||
static BtPortMessageHandle create(const unsigned char* data, uint32_t dataLength);
|
||||
static BtPortMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
|
||||
virtual void doReceivedAction() {
|
||||
logger->info("DHT is not supported yet.");
|
||||
|
|
|
@ -36,15 +36,15 @@
|
|||
#include "PeerMessageUtil.h"
|
||||
#include "Util.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "message.h"
|
||||
|
||||
BtRejectMessageHandle BtRejectMessage::create(const unsigned char* data, uint32_t dataLength) {
|
||||
BtRejectMessageHandle BtRejectMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||
if(dataLength != 13) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %u. It should be %d", "reject", dataLength, 13);
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "reject", dataLength, 13);
|
||||
}
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%u for %s. It should be %d.",
|
||||
id, "reject", ID);
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "reject", ID);
|
||||
}
|
||||
BtRejectMessageHandle message = new BtRejectMessage();
|
||||
message->setIndex(PeerMessageUtil::getIntParam(data, 1));
|
||||
|
@ -69,7 +69,7 @@ void BtRejectMessage::doReceivedAction() {
|
|||
|
||||
}
|
||||
|
||||
uint32_t BtRejectMessage::MESSAGE_LENGTH = 17;
|
||||
int32_t BtRejectMessage::MESSAGE_LENGTH = 17;
|
||||
|
||||
const unsigned char* BtRejectMessage::getMessage() {
|
||||
if(!msg) {
|
||||
|
@ -90,11 +90,11 @@ const unsigned char* BtRejectMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
uint32_t BtRejectMessage::getMessageLength() {
|
||||
int32_t BtRejectMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
string BtRejectMessage::toString() const {
|
||||
return "reject index="+Util::itos(index)+", begin="+Util::itos(begin)+
|
||||
", length="+Util::uitos(length);
|
||||
", length="+Util::itos(length);
|
||||
}
|
||||
|
|
|
@ -45,11 +45,11 @@ class BtRejectMessage : public SimpleBtMessage {
|
|||
private:
|
||||
int32_t index;
|
||||
int32_t begin;
|
||||
uint32_t length;
|
||||
int32_t length;
|
||||
unsigned char* msg;
|
||||
static uint32_t MESSAGE_LENGTH;
|
||||
static int32_t MESSAGE_LENGTH;
|
||||
public:
|
||||
BtRejectMessage(int32_t index = 0, int32_t begin = 0, uint32_t length = 0)
|
||||
BtRejectMessage(int32_t index = 0, int32_t begin = 0, int32_t length = 0)
|
||||
:index(index),
|
||||
begin(begin),
|
||||
length(length),
|
||||
|
@ -59,7 +59,7 @@ public:
|
|||
delete [] msg;
|
||||
}
|
||||
|
||||
static const uint8_t ID = 16;
|
||||
static const int8_t ID = 16;
|
||||
|
||||
int32_t getIndex() const { return index; }
|
||||
void setIndex(int32_t index) { this->index = index; }
|
||||
|
@ -67,18 +67,18 @@ public:
|
|||
int32_t getBegin() const { return begin; }
|
||||
void setBegin(int32_t begin) { this->begin = begin; }
|
||||
|
||||
uint32_t getLength() const { return length; }
|
||||
void setLength(uint32_t length) { this->length = length; }
|
||||
int32_t getLength() const { return length; }
|
||||
void setLength(int32_t length) { this->length = length; }
|
||||
|
||||
static BtRejectMessageHandle create(const unsigned char* data, uint32_t dataLength);
|
||||
static BtRejectMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
|
||||
virtual uint8_t getId() { return ID; }
|
||||
virtual int8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual uint32_t getMessageLength();
|
||||
virtual int32_t getMessageLength();
|
||||
|
||||
virtual string toString() const;
|
||||
};
|
||||
|
|
|
@ -41,12 +41,12 @@
|
|||
class BtRejectMessageValidator : public BtMessageValidator {
|
||||
private:
|
||||
const BtRejectMessage* message;
|
||||
uint32_t numPiece;
|
||||
uint32_t pieceLength;
|
||||
int32_t numPiece;
|
||||
int32_t pieceLength;
|
||||
public:
|
||||
BtRejectMessageValidator(const BtRejectMessage* message,
|
||||
uint32_t numPiece,
|
||||
uint32_t pieceLength):
|
||||
int32_t numPiece,
|
||||
int32_t pieceLength):
|
||||
message(message),
|
||||
numPiece(numPiece),
|
||||
pieceLength(pieceLength) {}
|
||||
|
|
|
@ -60,13 +60,13 @@ public:
|
|||
* addTargetPiece() and returns them.
|
||||
* The number of objects returned is capped by max.
|
||||
*/
|
||||
virtual BtMessages createRequestMessages(uint32_t max) = 0;
|
||||
virtual BtMessages createRequestMessages(int32_t max) = 0;
|
||||
|
||||
/**
|
||||
* Use this method in end game mode.
|
||||
*
|
||||
*/
|
||||
virtual BtMessages createRequestMessagesOnEndGame(uint32_t max) = 0;
|
||||
virtual BtMessages createRequestMessagesOnEndGame(int32_t max) = 0;
|
||||
};
|
||||
|
||||
typedef SharedHandle<BtRequestFactory> BtRequestFactoryHandle;
|
||||
|
|
|
@ -37,15 +37,15 @@
|
|||
#include "Util.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "BtAbortOutstandingRequestEvent.h"
|
||||
#include "message.h"
|
||||
|
||||
BtRequestMessageHandle BtRequestMessage::create(const unsigned char* data, uint32_t dataLength) {
|
||||
BtRequestMessageHandle BtRequestMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||
if(dataLength != 13) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %u. It should be %d", "request", dataLength, 13);
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "request", dataLength, 13);
|
||||
}
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%d for %s. It should be %d.",
|
||||
id, "request", ID);
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "request", ID);
|
||||
}
|
||||
BtRequestMessageHandle message = new BtRequestMessage();
|
||||
message->setIndex(PeerMessageUtil::getIntParam(data, 1));
|
||||
|
@ -72,7 +72,7 @@ void BtRequestMessage::doReceivedAction() {
|
|||
}
|
||||
}
|
||||
|
||||
uint32_t BtRequestMessage::MESSAGE_LENGTH = 17;
|
||||
int32_t BtRequestMessage::MESSAGE_LENGTH = 17;
|
||||
|
||||
const unsigned char* BtRequestMessage::getMessage() {
|
||||
if(!msg) {
|
||||
|
@ -93,13 +93,13 @@ const unsigned char* BtRequestMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
uint32_t BtRequestMessage::getMessageLength() {
|
||||
int32_t BtRequestMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
string BtRequestMessage::toString() const {
|
||||
return "request index="+Util::itos(index)+", begin="+Util::itos(begin)+
|
||||
", length="+Util::uitos(length);
|
||||
", length="+Util::itos(length);
|
||||
}
|
||||
|
||||
void BtRequestMessage::onQueued() {
|
||||
|
|
|
@ -48,11 +48,11 @@ class BtRequestMessage : public SimpleBtMessage {
|
|||
private:
|
||||
int32_t index;
|
||||
int32_t begin;
|
||||
uint32_t length;
|
||||
int32_t length;
|
||||
int32_t blockIndex;
|
||||
unsigned char* msg;
|
||||
|
||||
static uint32_t MESSAGE_LENGTH;
|
||||
static int32_t MESSAGE_LENGTH;
|
||||
|
||||
class BtAbortOutstandingRequestEventListener : public AbstractBtEventListener {
|
||||
private:
|
||||
|
@ -69,7 +69,7 @@ private:
|
|||
public:
|
||||
BtRequestMessage(int32_t index = 0,
|
||||
int32_t begin = 0,
|
||||
uint32_t length = 0,
|
||||
int32_t length = 0,
|
||||
int32_t blockIndex = 0)
|
||||
:index(index),
|
||||
begin(begin),
|
||||
|
@ -84,7 +84,7 @@ public:
|
|||
delete [] msg;
|
||||
}
|
||||
|
||||
static const uint8_t ID = 6;
|
||||
static const int8_t ID = 6;
|
||||
|
||||
int32_t getIndex() const { return index; }
|
||||
void setIndex(int32_t index) { this->index = index; }
|
||||
|
@ -92,21 +92,21 @@ public:
|
|||
int32_t getBegin() const { return begin; }
|
||||
void setBegin(int32_t begin) { this->begin = begin; }
|
||||
|
||||
uint32_t getLength() const { return length; }
|
||||
void setLength(uint32_t length) { this->length = length; }
|
||||
int32_t getLength() const { return length; }
|
||||
void setLength(int32_t length) { this->length = length; }
|
||||
|
||||
int32_t getBlockIndex() const { return blockIndex; }
|
||||
void setBlockIndex(int32_t blockIndex) { this->blockIndex = blockIndex; }
|
||||
|
||||
static BtRequestMessageHandle create(const unsigned char* data, uint32_t dataLength);
|
||||
static BtRequestMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
|
||||
virtual uint8_t getId() { return ID; }
|
||||
virtual int8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual uint32_t getMessageLength();
|
||||
virtual int32_t getMessageLength();
|
||||
|
||||
virtual string toString() const;
|
||||
|
||||
|
|
|
@ -41,12 +41,12 @@
|
|||
class BtRequestMessageValidator : public BtMessageValidator {
|
||||
private:
|
||||
const BtRequestMessage* message;
|
||||
uint32_t numPiece;
|
||||
uint32_t pieceLength;
|
||||
int32_t numPiece;
|
||||
int32_t pieceLength;
|
||||
public:
|
||||
BtRequestMessageValidator(const BtRequestMessage* message,
|
||||
uint32_t numPiece,
|
||||
uint32_t pieceLength):
|
||||
int32_t numPiece,
|
||||
int32_t pieceLength):
|
||||
message(message),
|
||||
numPiece(numPiece),
|
||||
pieceLength(pieceLength) {}
|
||||
|
|
|
@ -36,22 +36,22 @@
|
|||
#include "PeerMessageUtil.h"
|
||||
#include "Util.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "message.h"
|
||||
|
||||
BtSuggestPieceMessageHandle BtSuggestPieceMessage::create(const unsigned char* data, uint32_t dataLength) {
|
||||
BtSuggestPieceMessageHandle BtSuggestPieceMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||
if(dataLength != 5) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %u. It should be %d", "suggest piece", dataLength, 5);
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "suggest piece", dataLength, 5);
|
||||
}
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%u for %s. It should be %d.",
|
||||
id, "suggest piece", ID);
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "suggest piece", ID);
|
||||
}
|
||||
BtSuggestPieceMessageHandle message = new BtSuggestPieceMessage();
|
||||
message->setIndex(PeerMessageUtil::getIntParam(data, 1));
|
||||
return message;
|
||||
}
|
||||
|
||||
uint32_t BtSuggestPieceMessage::MESSAGE_LENGTH = 9;
|
||||
int32_t BtSuggestPieceMessage::MESSAGE_LENGTH = 9;
|
||||
|
||||
const unsigned char* BtSuggestPieceMessage::getMessage() {
|
||||
if(!msg) {
|
||||
|
@ -68,7 +68,7 @@ const unsigned char* BtSuggestPieceMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
uint32_t BtSuggestPieceMessage::getMessageLength() {
|
||||
int32_t BtSuggestPieceMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ class BtSuggestPieceMessage : public SimpleBtMessage {
|
|||
private:
|
||||
int32_t index;
|
||||
unsigned char* msg;
|
||||
static uint32_t MESSAGE_LENGTH;
|
||||
static int32_t MESSAGE_LENGTH;
|
||||
public:
|
||||
BtSuggestPieceMessage():index(0), msg(0) {}
|
||||
|
||||
|
@ -53,7 +53,7 @@ public:
|
|||
delete [] msg;
|
||||
}
|
||||
|
||||
static const uint8_t ID = 13;
|
||||
static const int8_t ID = 13;
|
||||
|
||||
void setIndex(int32_t index) {
|
||||
this->index = index;
|
||||
|
@ -61,9 +61,9 @@ public:
|
|||
|
||||
int32_t getIndex() const { return index; }
|
||||
|
||||
static BtSuggestPieceMessageHandle create(const unsigned char* data, uint32_t dataLength);
|
||||
static BtSuggestPieceMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
|
||||
virtual uint8_t getId() { return ID; }
|
||||
virtual int8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction() {
|
||||
// TODO Current implementation ignores this message.
|
||||
|
@ -71,7 +71,7 @@ public:
|
|||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual uint32_t getMessageLength();
|
||||
virtual int32_t getMessageLength();
|
||||
|
||||
virtual string toString() const;
|
||||
};
|
||||
|
|
|
@ -35,15 +35,15 @@
|
|||
#include "BtUnchokeMessage.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "message.h"
|
||||
|
||||
BtUnchokeMessageHandle BtUnchokeMessage::create(const unsigned char* data, uint32_t dataLength) {
|
||||
BtUnchokeMessageHandle BtUnchokeMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||
if(dataLength != 1) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %d. It should be %d", "unchoke", dataLength, 1);
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "unchoke", dataLength, 1);
|
||||
}
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%d for %s. It should be %d.",
|
||||
id, "unchoke", ID);
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "unchoke", ID);
|
||||
}
|
||||
BtUnchokeMessageHandle message = new BtUnchokeMessage();
|
||||
return message;
|
||||
|
@ -57,7 +57,7 @@ bool BtUnchokeMessage::sendPredicate() const {
|
|||
return peer->amChoking;
|
||||
}
|
||||
|
||||
uint32_t BtUnchokeMessage::MESSAGE_LENGTH = 5;
|
||||
int32_t BtUnchokeMessage::MESSAGE_LENGTH = 5;
|
||||
|
||||
const unsigned char* BtUnchokeMessage::getMessage() {
|
||||
if(!msg) {
|
||||
|
@ -72,7 +72,7 @@ const unsigned char* BtUnchokeMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
uint32_t BtUnchokeMessage::getMessageLength() {
|
||||
int32_t BtUnchokeMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ typedef SharedHandle<BtUnchokeMessage> BtUnchokeMessageHandle;
|
|||
class BtUnchokeMessage : public SimpleBtMessage {
|
||||
private:
|
||||
unsigned char* msg;
|
||||
static uint32_t MESSAGE_LENGTH;
|
||||
static int32_t MESSAGE_LENGTH;
|
||||
public:
|
||||
BtUnchokeMessage():msg(0) {}
|
||||
|
||||
|
@ -52,17 +52,17 @@ public:
|
|||
delete [] msg;
|
||||
}
|
||||
|
||||
static const uint8_t ID = 1;
|
||||
static const int8_t ID = 1;
|
||||
|
||||
static BtUnchokeMessageHandle create(const unsigned char* data, uint32_t dataLength);
|
||||
static BtUnchokeMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
|
||||
virtual uint8_t getId() { return ID; }
|
||||
virtual int8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual uint32_t getMessageLength();
|
||||
virtual int32_t getMessageLength();
|
||||
|
||||
virtual string toString() const;
|
||||
|
||||
|
|
|
@ -54,13 +54,13 @@ void ByteArrayDiskWriter::init() {
|
|||
}
|
||||
|
||||
void ByteArrayDiskWriter::initAndOpenFile(const string& filename,
|
||||
uint64_t totalLength) {
|
||||
int64_t totalLength) {
|
||||
clear();
|
||||
init();
|
||||
}
|
||||
|
||||
void ByteArrayDiskWriter::openFile(const string& filename,
|
||||
uint64_t totalLength) {
|
||||
int64_t totalLength) {
|
||||
initAndOpenFile(filename);
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ void ByteArrayDiskWriter::openExistingFile(const string& filename) {
|
|||
openFile(filename);
|
||||
}
|
||||
|
||||
void ByteArrayDiskWriter::writeData(const char* data, uint32_t dataLength, int64_t position) {
|
||||
void ByteArrayDiskWriter::writeData(const char* data, int32_t dataLength, int64_t position) {
|
||||
if(bufLength+dataLength >= maxBufLength) {
|
||||
maxBufLength = Util::expandBuffer(&buf, bufLength, bufLength+dataLength);
|
||||
}
|
||||
|
@ -80,11 +80,11 @@ void ByteArrayDiskWriter::writeData(const char* data, uint32_t dataLength, int64
|
|||
bufLength += dataLength;
|
||||
}
|
||||
|
||||
int ByteArrayDiskWriter::readData(char* data, uint32_t len, int64_t position) {
|
||||
int ByteArrayDiskWriter::readData(char* data, int32_t len, int64_t position) {
|
||||
if(position >= bufLength) {
|
||||
return 0;
|
||||
}
|
||||
uint32_t readLength;
|
||||
int32_t readLength;
|
||||
if(position+len <= bufLength) {
|
||||
readLength = len;
|
||||
} else {
|
||||
|
|
|
@ -40,8 +40,8 @@
|
|||
class ByteArrayDiskWriter : public DiskWriter {
|
||||
private:
|
||||
char* buf;
|
||||
uint32_t maxBufLength;
|
||||
uint32_t bufLength;
|
||||
int32_t maxBufLength;
|
||||
int32_t bufLength;
|
||||
|
||||
void init();
|
||||
void clear();
|
||||
|
@ -49,19 +49,19 @@ public:
|
|||
ByteArrayDiskWriter();
|
||||
virtual ~ByteArrayDiskWriter();
|
||||
|
||||
virtual void initAndOpenFile(const string& filename, uint64_t totalLength = 0);
|
||||
virtual void initAndOpenFile(const string& filename, int64_t totalLength = 0);
|
||||
|
||||
virtual void openFile(const string& filename, uint64_t totalLength = 0);
|
||||
virtual void openFile(const string& filename, int64_t totalLength = 0);
|
||||
|
||||
virtual void closeFile();
|
||||
|
||||
virtual void openExistingFile(const string& filename);
|
||||
|
||||
// position is ignored
|
||||
virtual void writeData(const char* data, uint32_t len, int64_t position = 0);
|
||||
virtual int readData(char* data, uint32_t len, int64_t position);
|
||||
virtual void writeData(const char* data, int32_t len, int64_t position = 0);
|
||||
virtual int readData(char* data, int32_t len, int64_t position);
|
||||
// not implemented yet
|
||||
virtual string messageDigest(int64_t offset, uint64_t length,
|
||||
virtual string messageDigest(int64_t offset, int64_t length,
|
||||
const MessageDigestContext::DigestAlgo& algo) { return ""; }
|
||||
|
||||
const char* getByteArray() const {
|
||||
|
|
|
@ -36,18 +36,20 @@
|
|||
#include "Util.h"
|
||||
#include "Exception.h"
|
||||
#include "TimeA2.h"
|
||||
#include "message.h"
|
||||
|
||||
void ChunkChecksumValidator::validateSameLengthChecksum(BitfieldMan* bitfieldMan,
|
||||
int32_t index,
|
||||
const string& expectedChecksum,
|
||||
uint32_t dataLength,
|
||||
uint32_t checksumLength)
|
||||
int32_t dataLength,
|
||||
int32_t checksumLength)
|
||||
{
|
||||
int64_t offset = index*checksumLength;
|
||||
int64_t offset = ((int64_t)index)*checksumLength;
|
||||
string actualChecksum = diskWriter->messageDigest(offset, dataLength, algo);
|
||||
if(actualChecksum != expectedChecksum) {
|
||||
logger->error("Chunk checksum validation failed. checksumIndex=%d, offset=%lld, length=%u, expected=%s, actual=%s",
|
||||
index, offset, dataLength, expectedChecksum.c_str(), actualChecksum.c_str());
|
||||
logger->error(EX_INVALID_CHUNK_CHECKSUM,
|
||||
index, offset, dataLength,
|
||||
expectedChecksum.c_str(), actualChecksum.c_str());
|
||||
bitfieldMan->unsetBit(index);
|
||||
}
|
||||
}
|
||||
|
@ -55,10 +57,10 @@ void ChunkChecksumValidator::validateSameLengthChecksum(BitfieldMan* bitfieldMan
|
|||
void ChunkChecksumValidator::validateDifferentLengthChecksum(BitfieldMan* bitfieldMan,
|
||||
int32_t index,
|
||||
const string& expectedChecksum,
|
||||
uint32_t dataLength,
|
||||
uint32_t checksumLength)
|
||||
int32_t dataLength,
|
||||
int32_t checksumLength)
|
||||
{
|
||||
int64_t offset = index*checksumLength;
|
||||
int64_t offset = ((int64_t)index)*checksumLength;
|
||||
int32_t startIndex;
|
||||
int32_t endIndex;
|
||||
Util::indexRange(startIndex, endIndex, offset,
|
||||
|
@ -67,7 +69,7 @@ void ChunkChecksumValidator::validateDifferentLengthChecksum(BitfieldMan* bitfie
|
|||
string actualChecksum = diskWriter->messageDigest(offset, dataLength, algo);
|
||||
if(expectedChecksum != actualChecksum) {
|
||||
// wrong checksum
|
||||
logger->error("Chunk checksum validation failed. checksumIndex=%d, offset=%lld, length=%u, expected=%s, actual=%s",
|
||||
logger->error(EX_INVALID_CHUNK_CHECKSUM,
|
||||
index, offset, dataLength,
|
||||
expectedChecksum.c_str(), actualChecksum.c_str());
|
||||
bitfieldMan->unsetBitRange(startIndex, endIndex);
|
||||
|
@ -77,18 +79,19 @@ void ChunkChecksumValidator::validateDifferentLengthChecksum(BitfieldMan* bitfie
|
|||
|
||||
void ChunkChecksumValidator::validate(BitfieldMan* bitfieldMan,
|
||||
const Strings& checksums,
|
||||
uint32_t checksumLength)
|
||||
int32_t checksumLength)
|
||||
{
|
||||
// We assume file is already opened using DiskWriter::open or openExistingFile.
|
||||
if(checksumLength*checksums.size() < bitfieldMan->getTotalLength()) {
|
||||
if(((int64_t)checksumLength*checksums.size()) < bitfieldMan->getTotalLength()) {
|
||||
// insufficient checksums.
|
||||
logger->error("Insufficient checksums. checksumLength=%u, numChecksum=%u",
|
||||
logger->error("Insufficient checksums. checksumLength=%d, numChecksum=%d",
|
||||
checksumLength, checksums.size());
|
||||
return;
|
||||
}
|
||||
uint32_t x = bitfieldMan->getTotalLength()/checksumLength;
|
||||
uint32_t r = bitfieldMan->getTotalLength()%checksumLength;
|
||||
void (ChunkChecksumValidator::*f)(BitfieldMan*, int32_t, const string&, uint32_t, uint32_t);
|
||||
assert(bitfieldMan->getTotalLength()/checksumLength <= INT32_MAX);
|
||||
int32_t x = bitfieldMan->getTotalLength()/checksumLength;
|
||||
int32_t r = bitfieldMan->getTotalLength()%checksumLength;
|
||||
void (ChunkChecksumValidator::*f)(BitfieldMan*, int32_t, const string&, int32_t, int32_t);
|
||||
|
||||
if(checksumLength == bitfieldMan->getBlockLength()) {
|
||||
f = &ChunkChecksumValidator::validateSameLengthChecksum;
|
||||
|
@ -101,7 +104,7 @@ void ChunkChecksumValidator::validate(BitfieldMan* bitfieldMan,
|
|||
fileAllocationMonitor->setCurrentValue(0);
|
||||
fileAllocationMonitor->showProgress();
|
||||
Time cp;
|
||||
for(uint32_t i = 0; i < x; ++i) {
|
||||
for(int32_t i = 0; i < x; ++i) {
|
||||
(this->*f)(bitfieldMan, i, checksums.at(i), checksumLength, checksumLength);
|
||||
if(cp.elapsedInMillis(500)) {
|
||||
fileAllocationMonitor->setCurrentValue(i*checksumLength);
|
||||
|
|
|
@ -56,14 +56,14 @@ private:
|
|||
void validateSameLengthChecksum(BitfieldMan* bitfieldMan,
|
||||
int32_t index,
|
||||
const string& expectedChecksum,
|
||||
uint32_t thisLength,
|
||||
uint32_t checksumLength);
|
||||
int32_t thisLength,
|
||||
int32_t checksumLength);
|
||||
|
||||
void validateDifferentLengthChecksum(BitfieldMan* bitfieldMan,
|
||||
int32_t index,
|
||||
const string& expectedChecksum,
|
||||
uint32_t thisLength,
|
||||
uint32_t checksumLength);
|
||||
int32_t thisLength,
|
||||
int32_t checksumLength);
|
||||
public:
|
||||
ChunkChecksumValidator():
|
||||
diskWriter(0),
|
||||
|
@ -76,7 +76,7 @@ public:
|
|||
|
||||
void validate(BitfieldMan* bitfieldMan,
|
||||
const Strings& checksums,
|
||||
uint32_t checksumLength);
|
||||
int32_t checksumLength);
|
||||
|
||||
void setDiskWriter(const DiskWriterHandle& diskWriter) {
|
||||
this->diskWriter = diskWriter;
|
||||
|
|
|
@ -36,23 +36,24 @@
|
|||
#include "Util.h"
|
||||
|
||||
void ConsoleFileAllocationMonitor::showProgress() {
|
||||
uint32_t progressPercentage = (uint32_t)(((current-min)*1.0/(max-min))*100);
|
||||
uint32_t numOfStar = progressPercentage/10*2;
|
||||
int32_t progressPercentage = (int32_t)(((current-min)*1.0/(max-min))*100);
|
||||
int32_t numOfStar = progressPercentage/10*2;
|
||||
|
||||
cout << "\r ";
|
||||
cout << "\r";
|
||||
cout << "|";
|
||||
for(uint32_t i = 0; i < numOfStar; i++) {
|
||||
for(int32_t i = 0; i < numOfStar; ++i) {
|
||||
cout << "*";
|
||||
}
|
||||
for(uint32_t i = 0; i < 20-numOfStar; i++) {
|
||||
for(int32_t i = 0; i < 20-numOfStar; ++i) {
|
||||
cout << " ";
|
||||
}
|
||||
cout << "|";
|
||||
cout << progressPercentage << "%";
|
||||
cout << "(";
|
||||
cout << Util::ullitos(current, true) << "/" << Util::ullitos(max, true);
|
||||
cout << ") done";
|
||||
cout << ")";
|
||||
cout << flush;
|
||||
// |******************* | 95%(1,333,3256/1,553,3232 bytes) done
|
||||
// Example,
|
||||
// |******************* | 95%(1,333,3256/1,553,3232 bytes)
|
||||
}
|
||||
|
|
|
@ -40,9 +40,9 @@
|
|||
class ConsoleFileAllocationMonitor : public FileAllocationMonitor {
|
||||
private:
|
||||
string filename;
|
||||
uint64_t min;
|
||||
uint64_t max;
|
||||
uint64_t current;
|
||||
int64_t min;
|
||||
int64_t max;
|
||||
int64_t current;
|
||||
public:
|
||||
ConsoleFileAllocationMonitor():min(0), max(0), current(0) {}
|
||||
|
||||
|
@ -52,7 +52,7 @@ public:
|
|||
this->filename = filename;
|
||||
}
|
||||
|
||||
virtual void setMinValue(const uint64_t& min) {
|
||||
virtual void setMinValue(const int64_t& min) {
|
||||
if(max < min) {
|
||||
this->min = max;
|
||||
} else {
|
||||
|
@ -60,11 +60,11 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
uint64_t getMinValue() const {
|
||||
int64_t getMinValue() const {
|
||||
return min;
|
||||
}
|
||||
|
||||
virtual void setMaxValue(const uint64_t& max) {
|
||||
virtual void setMaxValue(const int64_t& max) {
|
||||
if(max < min) {
|
||||
this->max = min;
|
||||
} else {
|
||||
|
@ -72,11 +72,11 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
uint64_t getMaxValue() const {
|
||||
int64_t getMaxValue() const {
|
||||
return max;
|
||||
}
|
||||
|
||||
virtual void setCurrentValue(const uint64_t& current) {
|
||||
virtual void setCurrentValue(const int64_t& current) {
|
||||
if(current > max) {
|
||||
this->current = max;
|
||||
} else {
|
||||
|
@ -84,7 +84,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
uint64_t getCurrentValue() const {
|
||||
int64_t getCurrentValue() const {
|
||||
return current;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ void CopyDiskAdaptor::onDownloadComplete() {
|
|||
}
|
||||
|
||||
void CopyDiskAdaptor::fixFilename() {
|
||||
long long int offset = 0;
|
||||
int64_t offset = 0;
|
||||
for(FileEntries::iterator itr = fileEntries.begin();
|
||||
itr != fileEntries.end(); itr++) {
|
||||
if(!(*itr)->isExtracted() && (*itr)->isRequested()) {
|
||||
|
|
|
@ -105,8 +105,8 @@ void DefaultBtContext::extractFileEntries(Dictionary* infoDic,
|
|||
// TODO use dynamic_cast
|
||||
List* files = (List*)infoDic->get("files");
|
||||
if(files) {
|
||||
long long int length = 0;
|
||||
long long int offset = 0;
|
||||
int64_t length = 0;
|
||||
int64_t offset = 0;
|
||||
// multi-file mode
|
||||
fileMode = BtContext::MULTI;
|
||||
const MetaList& metaList = files->getList();
|
||||
|
@ -120,7 +120,7 @@ void DefaultBtContext::extractFileEntries(Dictionary* infoDic,
|
|||
List* pathList = (List*)fileDic->get("path");
|
||||
const MetaList& paths = pathList->getList();
|
||||
string path;
|
||||
for(int i = 0; i < (int)paths.size()-1; i++) {
|
||||
for(int32_t i = 0; i < (int32_t)paths.size()-1; i++) {
|
||||
Data* subpath = (Data*)paths.at(i);
|
||||
path += subpath->toString()+"/";
|
||||
}
|
||||
|
|
|
@ -220,7 +220,7 @@ void DefaultBtInteractive::fillPiece(int maxPieceNum) {
|
|||
}
|
||||
|
||||
void DefaultBtInteractive::addRequests() {
|
||||
uint32_t MAX_PENDING_REQUEST;
|
||||
int32_t MAX_PENDING_REQUEST;
|
||||
if(peer->getLatency() < 500) {
|
||||
MAX_PENDING_REQUEST = 24;
|
||||
} else if(peer->getLatency() < 1500) {
|
||||
|
@ -228,20 +228,19 @@ void DefaultBtInteractive::addRequests() {
|
|||
} else {
|
||||
MAX_PENDING_REQUEST = 6;
|
||||
}
|
||||
uint32_t pieceNum;
|
||||
int32_t pieceNum;
|
||||
if(pieceStorage->isEndGame()) {
|
||||
pieceNum = 1;
|
||||
} else {
|
||||
uint32_t blocks = DIV_FLOOR(btContext->getPieceLength(), BLOCK_LENGTH);
|
||||
int32_t blocks = DIV_FLOOR(btContext->getPieceLength(), BLOCK_LENGTH);
|
||||
pieceNum = DIV_FLOOR(MAX_PENDING_REQUEST, blocks);
|
||||
}
|
||||
fillPiece(pieceNum);
|
||||
|
||||
uint32_t reqNumToCreate =
|
||||
int32_t reqNumToCreate =
|
||||
MAX_PENDING_REQUEST <= dispatcher->countOutstandingRequest() ?
|
||||
0 : MAX_PENDING_REQUEST-dispatcher->countOutstandingRequest();
|
||||
if(reqNumToCreate > 0) {
|
||||
//logger->debug("CUID#%d - %u requets to go.", cuid, reqNumToCreate);
|
||||
BtMessages requests;
|
||||
if(pieceStorage->isEndGame()) {
|
||||
requests = btRequestFactory->createRequestMessagesOnEndGame(reqNumToCreate);
|
||||
|
|
|
@ -51,28 +51,28 @@
|
|||
|
||||
class FloodingStat {
|
||||
private:
|
||||
uint32_t chokeUnchokeCount;
|
||||
uint32_t keepAliveCount;
|
||||
int32_t chokeUnchokeCount;
|
||||
int32_t keepAliveCount;
|
||||
public:
|
||||
FloodingStat():chokeUnchokeCount(0), keepAliveCount(0) {}
|
||||
|
||||
void incChokeUnchokeCount() {
|
||||
if(chokeUnchokeCount < UINT32_MAX) {
|
||||
if(chokeUnchokeCount < INT32_MAX) {
|
||||
chokeUnchokeCount++;
|
||||
}
|
||||
}
|
||||
|
||||
void incKeepAliveCount() {
|
||||
if(keepAliveCount < UINT32_MAX) {
|
||||
if(keepAliveCount < INT32_MAX) {
|
||||
keepAliveCount++;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t getChokeUnchokeCount() const {
|
||||
int32_t getChokeUnchokeCount() const {
|
||||
return chokeUnchokeCount;
|
||||
}
|
||||
|
||||
uint32_t getKeepAliveCount() const {
|
||||
int32_t getKeepAliveCount() const {
|
||||
return keepAliveCount;
|
||||
}
|
||||
|
||||
|
@ -95,15 +95,15 @@ private:
|
|||
PeerConnectionWeakHandle peerConnection;
|
||||
BtMessageFactoryWeakHandle messageFactory;
|
||||
const Logger* logger;
|
||||
uint32_t allowedFastSetSize;
|
||||
int32_t allowedFastSetSize;
|
||||
Time haveCheckPoint;
|
||||
Time keepAliveCheckPoint;
|
||||
Time floodingCheckPoint;
|
||||
FloodingStat floodingStat;
|
||||
uint32_t keepAliveInterval;
|
||||
uint32_t maxDownloadSpeedLimit;
|
||||
int32_t keepAliveInterval;
|
||||
int32_t maxDownloadSpeedLimit;
|
||||
|
||||
static const uint32_t FLOODING_CHECK_INTERVAL = 5;
|
||||
static const int32_t FLOODING_CHECK_INTERVAL = 5;
|
||||
|
||||
void addBitfieldMessageToQueue();
|
||||
void addAllowedFastMessageToQueue();
|
||||
|
@ -147,7 +147,7 @@ public:
|
|||
|
||||
void receiveMessages();
|
||||
|
||||
virtual uint32_t countPendingMessage() {
|
||||
virtual int32_t countPendingMessage() {
|
||||
return dispatcher->countMessageInQueue();
|
||||
}
|
||||
|
||||
|
@ -185,11 +185,11 @@ public:
|
|||
this->peerConnection = peerConnection;
|
||||
}
|
||||
|
||||
void setKeepAliveInterval(uint32_t keepAliveInterval) {
|
||||
void setKeepAliveInterval(int32_t keepAliveInterval) {
|
||||
this->keepAliveInterval = keepAliveInterval;
|
||||
}
|
||||
|
||||
void setMaxDownloadSpeedLimit(uint32_t maxDownloadSpeedLimit) {
|
||||
void setMaxDownloadSpeedLimit(int32_t maxDownloadSpeedLimit) {
|
||||
this->maxDownloadSpeedLimit = maxDownloadSpeedLimit;
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ void DefaultBtMessageDispatcher::sendMessages() {
|
|||
}
|
||||
|
||||
// Cancel sending piece message to peer.
|
||||
void DefaultBtMessageDispatcher::doCancelSendingPieceAction(int32_t index, int32_t begin, uint32_t length)
|
||||
void DefaultBtMessageDispatcher::doCancelSendingPieceAction(int32_t index, int32_t begin, int32_t length)
|
||||
{
|
||||
BtCancelSendingPieceEventHandle event =
|
||||
new BtCancelSendingPieceEvent(index, begin, length);
|
||||
|
@ -199,7 +199,7 @@ bool DefaultBtMessageDispatcher::isSendingInProgress()
|
|||
}
|
||||
}
|
||||
|
||||
uint32_t DefaultBtMessageDispatcher::countOutstandingRequest()
|
||||
int32_t DefaultBtMessageDispatcher::countOutstandingRequest()
|
||||
{
|
||||
return requestSlots.size();
|
||||
}
|
||||
|
|
|
@ -56,8 +56,8 @@ private:
|
|||
PieceStorageHandle pieceStorage;
|
||||
BtMessageFactoryWeakHandle messageFactory;
|
||||
PeerHandle peer;
|
||||
uint32_t maxUploadSpeedLimit;
|
||||
uint32_t requestTimeout;
|
||||
int32_t maxUploadSpeedLimit;
|
||||
int32_t requestTimeout;
|
||||
const Logger* logger;
|
||||
public:
|
||||
DefaultBtMessageDispatcher():
|
||||
|
@ -78,7 +78,7 @@ public:
|
|||
|
||||
virtual void sendMessages();
|
||||
|
||||
virtual void doCancelSendingPieceAction(int32_t index, int32_t begin, uint32_t length);
|
||||
virtual void doCancelSendingPieceAction(int32_t index, int32_t begin, int32_t length);
|
||||
|
||||
virtual void doCancelSendingPieceAction(const PieceHandle& piece);
|
||||
|
||||
|
@ -92,15 +92,15 @@ public:
|
|||
|
||||
virtual bool isSendingInProgress();
|
||||
|
||||
virtual uint32_t countMessageInQueue() {
|
||||
virtual int32_t countMessageInQueue() {
|
||||
return messageQueue.size();
|
||||
}
|
||||
|
||||
virtual uint32_t countOutstandingRequest();
|
||||
virtual int32_t countOutstandingRequest();
|
||||
|
||||
virtual bool isOutstandingRequest(int32_t index, int32_t blockIndex);
|
||||
|
||||
virtual RequestSlot getOutstandingRequest(int32_t index, int32_t begin, uint32_t length) {
|
||||
virtual RequestSlot getOutstandingRequest(int32_t index, int32_t begin, int32_t length) {
|
||||
for(RequestSlots::iterator itr = requestSlots.begin();
|
||||
itr != requestSlots.end(); itr++) {
|
||||
if(itr->getIndex() == index &&
|
||||
|
@ -146,11 +146,11 @@ public:
|
|||
this->cuid = cuid;
|
||||
}
|
||||
|
||||
void setMaxUploadSpeedLimit(uint32_t maxUploadSpeedLimit) {
|
||||
void setMaxUploadSpeedLimit(int32_t maxUploadSpeedLimit) {
|
||||
this->maxUploadSpeedLimit = maxUploadSpeedLimit;
|
||||
}
|
||||
|
||||
void setRequestTimeout(uint32_t requestTimeout) {
|
||||
void setRequestTimeout(int32_t requestTimeout) {
|
||||
this->requestTimeout = requestTimeout;
|
||||
}
|
||||
|
||||
|
|
|
@ -63,14 +63,14 @@
|
|||
#include "BtHandshakeMessageValidator.h"
|
||||
|
||||
BtMessageHandle
|
||||
DefaultBtMessageFactory::createBtMessage(const unsigned char* data, uint32_t dataLength)
|
||||
DefaultBtMessageFactory::createBtMessage(const unsigned char* data, int32_t dataLength)
|
||||
{
|
||||
AbstractBtMessageHandle msg(0);
|
||||
if(dataLength == 0) {
|
||||
// keep-alive
|
||||
msg = new BtKeepAliveMessage();
|
||||
} else {
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
switch(id) {
|
||||
case BtChokeMessage::ID:
|
||||
msg = BtChokeMessage::create(data, dataLength);
|
||||
|
@ -162,7 +162,7 @@ DefaultBtMessageFactory::createBtMessage(const unsigned char* data, uint32_t dat
|
|||
break;
|
||||
}
|
||||
default:
|
||||
throw new DlAbortEx("Invalid message id. id = %u", id);
|
||||
throw new DlAbortEx("Invalid message ID. id=%d", id);
|
||||
}
|
||||
}
|
||||
setCommonProperty(msg);
|
||||
|
@ -180,7 +180,7 @@ void DefaultBtMessageFactory::setCommonProperty(const AbstractBtMessageHandle& m
|
|||
}
|
||||
|
||||
BtMessageHandle
|
||||
DefaultBtMessageFactory::createHandshakeMessage(const unsigned char* data, uint32_t dataLength)
|
||||
DefaultBtMessageFactory::createHandshakeMessage(const unsigned char* data, int32_t dataLength)
|
||||
{
|
||||
BtHandshakeMessageHandle msg = BtHandshakeMessage::create(data, dataLength);
|
||||
BtMessageValidatorHandle validator =
|
||||
|
@ -222,7 +222,7 @@ DefaultBtMessageFactory::createRequestMessage(const PieceHandle& piece, int32_t
|
|||
}
|
||||
|
||||
BtMessageHandle
|
||||
DefaultBtMessageFactory::createCancelMessage(int32_t index, int32_t begin, uint32_t length)
|
||||
DefaultBtMessageFactory::createCancelMessage(int32_t index, int32_t begin, int32_t length)
|
||||
{
|
||||
BtCancelMessageHandle msg = new BtCancelMessage(index, begin, length);
|
||||
BtMessageValidatorHandle validator =
|
||||
|
@ -235,7 +235,7 @@ DefaultBtMessageFactory::createCancelMessage(int32_t index, int32_t begin, uint3
|
|||
}
|
||||
|
||||
BtMessageHandle
|
||||
DefaultBtMessageFactory::createPieceMessage(int32_t index, int32_t begin, uint32_t length)
|
||||
DefaultBtMessageFactory::createPieceMessage(int32_t index, int32_t begin, int32_t length)
|
||||
{
|
||||
BtPieceMessageHandle msg = new BtPieceMessage(index, begin, length);
|
||||
BtMessageValidatorHandle validator =
|
||||
|
@ -326,7 +326,7 @@ DefaultBtMessageFactory::createHaveNoneMessage()
|
|||
}
|
||||
|
||||
BtMessageHandle
|
||||
DefaultBtMessageFactory::createRejectMessage(int32_t index, int32_t begin, uint32_t length)
|
||||
DefaultBtMessageFactory::createRejectMessage(int32_t index, int32_t begin, int32_t length)
|
||||
{
|
||||
BtRejectMessageHandle msg = new BtRejectMessage(index, begin, length);
|
||||
BtMessageValidatorHandle validator =
|
||||
|
|
|
@ -69,10 +69,10 @@ public:
|
|||
}
|
||||
|
||||
virtual BtMessageHandle
|
||||
createBtMessage(const unsigned char* msg, uint32_t msgLength);
|
||||
createBtMessage(const unsigned char* msg, int32_t msgLength);
|
||||
|
||||
virtual BtMessageHandle
|
||||
createHandshakeMessage(const unsigned char* msg, uint32_t msgLength);
|
||||
createHandshakeMessage(const unsigned char* msg, int32_t msgLength);
|
||||
|
||||
virtual BtMessageHandle
|
||||
createHandshakeMessage(const unsigned char* infoHash,
|
||||
|
@ -82,10 +82,10 @@ public:
|
|||
createRequestMessage(const PieceHandle& piece, int32_t blockIndex);
|
||||
|
||||
virtual BtMessageHandle
|
||||
createCancelMessage(int32_t index, int32_t begin, uint32_t length);
|
||||
createCancelMessage(int32_t index, int32_t begin, int32_t length);
|
||||
|
||||
virtual BtMessageHandle
|
||||
createPieceMessage(int32_t index, int32_t begin, uint32_t length);
|
||||
createPieceMessage(int32_t index, int32_t begin, int32_t length);
|
||||
|
||||
virtual BtMessageHandle createHaveMessage(int32_t index);
|
||||
|
||||
|
@ -106,7 +106,7 @@ public:
|
|||
virtual BtMessageHandle createHaveNoneMessage();
|
||||
|
||||
virtual BtMessageHandle
|
||||
createRejectMessage(int32_t index, int32_t begin, uint32_t length);
|
||||
createRejectMessage(int32_t index, int32_t begin, int32_t length);
|
||||
|
||||
virtual BtMessageHandle createAllowedFastMessage(int32_t index);
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
BtMessageHandle DefaultBtMessageReceiver::receiveHandshake(bool quickReply) {
|
||||
unsigned char data[BtHandshakeMessage::MESSAGE_LENGTH];
|
||||
uint32_t dataLength = sizeof(data);
|
||||
int32_t dataLength = BtHandshakeMessage::MESSAGE_LENGTH;
|
||||
bool retval = peerConnection->receiveHandshake(data, dataLength);
|
||||
// To handle tracker's NAT-checking feature
|
||||
if(!handshakeSent && quickReply && dataLength >= 48) {
|
||||
|
@ -77,7 +77,7 @@ void DefaultBtMessageReceiver::sendHandshake() {
|
|||
|
||||
BtMessageHandle DefaultBtMessageReceiver::receiveMessage() {
|
||||
unsigned char data[MAX_PAYLOAD_LEN];
|
||||
uint32_t dataLength = 0;
|
||||
int32_t dataLength = 0;
|
||||
if(!peerConnection->receiveMessage(data, dataLength)) {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ void DefaultBtRequestFactory::removeAllTargetPiece() {
|
|||
pieces.clear();
|
||||
}
|
||||
|
||||
BtMessages DefaultBtRequestFactory::createRequestMessages(uint32_t max) {
|
||||
BtMessages DefaultBtRequestFactory::createRequestMessages(int32_t max) {
|
||||
BtMessages requests;
|
||||
for(Pieces::iterator itr = pieces.begin();
|
||||
itr != pieces.end() && requests.size() < (size_t)max; itr++) {
|
||||
|
@ -90,7 +90,7 @@ BtMessages DefaultBtRequestFactory::createRequestMessages(uint32_t max) {
|
|||
return requests;
|
||||
}
|
||||
|
||||
BtMessages DefaultBtRequestFactory::createRequestMessagesOnEndGame(uint32_t max) {
|
||||
BtMessages DefaultBtRequestFactory::createRequestMessagesOnEndGame(int32_t max) {
|
||||
BtMessages requests;
|
||||
for(Pieces::iterator itr = pieces.begin();
|
||||
itr != pieces.end() && requests.size() < (size_t)max; itr++) {
|
||||
|
|
|
@ -85,9 +85,9 @@ public:
|
|||
|
||||
virtual void doChokedAction();
|
||||
|
||||
virtual BtMessages createRequestMessages(uint32_t max);
|
||||
virtual BtMessages createRequestMessages(int32_t max);
|
||||
|
||||
virtual BtMessages createRequestMessagesOnEndGame(uint32_t max);
|
||||
virtual BtMessages createRequestMessagesOnEndGame(int32_t max);
|
||||
|
||||
Pieces& getTargetPieces() {
|
||||
return pieces;
|
||||
|
|
|
@ -46,7 +46,7 @@ DefaultDiskWriter::DefaultDiskWriter():AbstractDiskWriter() {}
|
|||
DefaultDiskWriter::~DefaultDiskWriter() {}
|
||||
|
||||
void DefaultDiskWriter::initAndOpenFile(const string& filename,
|
||||
uint64_t totalLength)
|
||||
int64_t totalLength)
|
||||
{
|
||||
createFile(filename);
|
||||
try {
|
||||
|
|
|
@ -45,7 +45,7 @@ public:
|
|||
virtual ~DefaultDiskWriter();
|
||||
|
||||
virtual void initAndOpenFile(const string& filename,
|
||||
uint64_t totalLength = 0);
|
||||
int64_t totalLength = 0);
|
||||
|
||||
static DefaultDiskWriter* createNewDiskWriter(const Option* option);
|
||||
};
|
||||
|
|
|
@ -71,7 +71,7 @@ private:
|
|||
BitfieldMan* bitfieldMan;
|
||||
DiskAdaptorHandle diskAdaptor;
|
||||
Pieces usedPieces;
|
||||
uint32_t endGamePieceNum;
|
||||
int32_t endGamePieceNum;
|
||||
Logger* logger;
|
||||
const Option* option;
|
||||
Haves haves;
|
||||
|
@ -127,11 +127,11 @@ public:
|
|||
|
||||
virtual const unsigned char* getBitfield();
|
||||
|
||||
void setEndGamePieceNum(uint32_t num) {
|
||||
void setEndGamePieceNum(int32_t num) {
|
||||
endGamePieceNum = num;
|
||||
}
|
||||
|
||||
uint32_t getEndGamePieceNum() const {
|
||||
int32_t getEndGamePieceNum() const {
|
||||
return endGamePieceNum;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,11 +57,11 @@ public:
|
|||
|
||||
virtual void initAndOpenFile() = 0;
|
||||
|
||||
virtual void writeData(const unsigned char* data, uint32_t len, int64_t offset) = 0;
|
||||
virtual void writeData(const unsigned char* data, int32_t len, int64_t offset) = 0;
|
||||
|
||||
virtual int readData(unsigned char* data, uint32_t len, int64_t offset) = 0;
|
||||
virtual int32_t readData(unsigned char* data, int32_t len, int64_t offset) = 0;
|
||||
|
||||
virtual string messageDigest(int64_t offset, uint64_t length,
|
||||
virtual string messageDigest(int64_t offset, int64_t length,
|
||||
const MessageDigestContext::DigestAlgo& algo) = 0;
|
||||
|
||||
virtual void onDownloadComplete() = 0;
|
||||
|
|
|
@ -47,12 +47,12 @@ public:
|
|||
|
||||
virtual ~DiskAdaptorWriter() {}
|
||||
|
||||
virtual void initAndOpenFile(const string& filename, uint64_t totalLength = 0)
|
||||
virtual void initAndOpenFile(const string& filename, int64_t totalLength = 0)
|
||||
{
|
||||
diskAdaptor->initAndOpenFile();
|
||||
}
|
||||
|
||||
virtual void openFile(const string& filename, uint64_t totalLength = 0)
|
||||
virtual void openFile(const string& filename, int64_t totalLength = 0)
|
||||
{
|
||||
diskAdaptor->openFile();
|
||||
}
|
||||
|
@ -67,17 +67,17 @@ public:
|
|||
diskAdaptor->openExistingFile();
|
||||
}
|
||||
|
||||
virtual void writeData(const char* data, uint32_t len, int64_t position = 0)
|
||||
virtual void writeData(const char* data, int32_t len, int64_t position = 0)
|
||||
{
|
||||
diskAdaptor->writeData((const unsigned char*)data, len, position);
|
||||
}
|
||||
|
||||
virtual int readData(char* data, uint32_t len, int64_t position)
|
||||
virtual int32_t readData(char* data, int32_t len, int64_t position)
|
||||
{
|
||||
return diskAdaptor->readData((unsigned char*)data, len, position);
|
||||
}
|
||||
|
||||
virtual string messageDigest(int64_t offset, uint64_t length,
|
||||
virtual string messageDigest(int64_t offset, int64_t length,
|
||||
const MessageDigestContext::DigestAlgo& algo)
|
||||
{
|
||||
return diskAdaptor->messageDigest(offset, length, algo);
|
||||
|
|
|
@ -55,9 +55,9 @@ public:
|
|||
* If the file exists, then it is truncated to 0 length.
|
||||
* @param filename the file name to be opened.
|
||||
*/
|
||||
virtual void initAndOpenFile(const string& filename, uint64_t totalLength = 0) = 0;
|
||||
virtual void initAndOpenFile(const string& filename, int64_t totalLength = 0) = 0;
|
||||
|
||||
virtual void openFile(const string& filename, uint64_t totalLength = 0) = 0;
|
||||
virtual void openFile(const string& filename, int64_t totalLength = 0) = 0;
|
||||
|
||||
/**
|
||||
* Closes this output stream.
|
||||
|
@ -81,18 +81,18 @@ public:
|
|||
* @param len the number of bytes to write
|
||||
* @param position the offset of this binary stream
|
||||
*/
|
||||
virtual void writeData(const char* data, uint32_t len, int64_t position = 0) = 0;
|
||||
virtual void writeData(const unsigned char* data, uint32_t len, int64_t position = 0)
|
||||
virtual void writeData(const char* data, int32_t len, int64_t position = 0) = 0;
|
||||
virtual void writeData(const unsigned char* data, int32_t len, int64_t position = 0)
|
||||
{
|
||||
writeData((const char*)data, len, position);
|
||||
}
|
||||
|
||||
virtual int readData(char* data, uint32_t len, int64_t position) = 0;
|
||||
virtual int readData(unsigned char* data, uint32_t len, int64_t position) {
|
||||
virtual int readData(char* data, int32_t len, int64_t position) = 0;
|
||||
virtual int readData(unsigned char* data, int32_t len, int64_t position) {
|
||||
return readData((char*)data, len, position);
|
||||
}
|
||||
|
||||
virtual string messageDigest(int64_t offset, uint64_t length,
|
||||
virtual string messageDigest(int64_t offset, int64_t length,
|
||||
const MessageDigestContext::DigestAlgo& algo) = 0;
|
||||
};
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ bool DownloadCommand::executeInternal(Segment& segment) {
|
|||
}
|
||||
// calculate downloading speed
|
||||
if(peerStat->getDownloadStartTime().elapsed(startupIdleTime)) {
|
||||
uint32_t nowSpeed = peerStat->calculateDownloadSpeed();
|
||||
int32_t nowSpeed = peerStat->calculateDownloadSpeed();
|
||||
if(lowestDownloadSpeedLimit > 0 && nowSpeed <= lowestDownloadSpeedLimit) {
|
||||
throw new DlAbortEx("CUID#%d - Too slow Downloading speed: %d <= %d(B/s)",
|
||||
cuid,
|
||||
|
|
|
@ -45,9 +45,9 @@ using namespace std;
|
|||
class DownloadCommand : public AbstractCommand {
|
||||
private:
|
||||
long long int lastSize;
|
||||
uint32_t maxDownloadSpeedLimit;
|
||||
uint32_t startupIdleTime;
|
||||
uint32_t lowestDownloadSpeedLimit;
|
||||
int32_t maxDownloadSpeedLimit;
|
||||
int32_t startupIdleTime;
|
||||
int32_t lowestDownloadSpeedLimit;
|
||||
PeerStatHandle peerStat;
|
||||
protected:
|
||||
bool executeInternal(Segment& segment);
|
||||
|
@ -62,15 +62,15 @@ public:
|
|||
|
||||
string transferEncoding;
|
||||
|
||||
void setMaxDownloadSpeedLimit(uint32_t maxDownloadSpeedLimit) {
|
||||
void setMaxDownloadSpeedLimit(int32_t maxDownloadSpeedLimit) {
|
||||
this->maxDownloadSpeedLimit = maxDownloadSpeedLimit;
|
||||
}
|
||||
|
||||
void setStartupIdleTime(uint32_t startupIdleTime) {
|
||||
void setStartupIdleTime(int32_t startupIdleTime) {
|
||||
this->startupIdleTime = startupIdleTime;
|
||||
}
|
||||
|
||||
void setLowestDownloadSpeedLimit(uint32_t lowestDownloadSpeedLimit) {
|
||||
void setLowestDownloadSpeedLimit(int32_t lowestDownloadSpeedLimit) {
|
||||
this->lowestDownloadSpeedLimit = lowestDownloadSpeedLimit;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
#include "FileProgressMonitor.h"
|
||||
|
||||
typedef FileProgressMonitor<uint64_t> FileAllocationMonitor;
|
||||
typedef FileProgressMonitor<int64_t> FileAllocationMonitor;
|
||||
typedef SharedHandle<FileAllocationMonitor> FileAllocationMonitorHandle;
|
||||
|
||||
class FileAllocationMonitorFactory;
|
||||
|
|
|
@ -40,21 +40,21 @@
|
|||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
void FileAllocator::allocate(int fd, uint64_t totalLength)
|
||||
void FileAllocator::allocate(int fd, int64_t totalLength)
|
||||
{
|
||||
if(0 != lseek(fd, 0, SEEK_SET)) {
|
||||
throw new DlAbortEx("Seek failed: %s", strerror(errno));
|
||||
}
|
||||
uint32_t bufSize = 4096;
|
||||
int32_t bufSize = 4096;
|
||||
char buf[4096];
|
||||
memset(buf, 0, bufSize);
|
||||
uint64_t x = (totalLength+bufSize-1)/bufSize;
|
||||
int64_t x = (totalLength+bufSize-1)/bufSize;
|
||||
fileAllocationMonitor->setMinValue(0);
|
||||
fileAllocationMonitor->setMaxValue(totalLength);
|
||||
fileAllocationMonitor->setCurrentValue(0);
|
||||
fileAllocationMonitor->showProgress();
|
||||
Time cp;
|
||||
for(uint64_t i = 0; i < x; i++) {
|
||||
for(int64_t i = 0; i < x; ++i) {
|
||||
if(write(fd, buf, bufSize) < 0) {
|
||||
throw new DlAbortEx("Allocation failed: %s", strerror(errno));
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
|
||||
~FileAllocator() {}
|
||||
|
||||
void allocate(int fd, uint64_t totalLength);
|
||||
void allocate(int fd, int64_t totalLength);
|
||||
|
||||
void setFileAllocationMonitor(const FileAllocationMonitorHandle& monitor)
|
||||
{
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
class MetalinkChunkChecksum {
|
||||
public:
|
||||
MessageDigestContext::DigestAlgo digestAlgo;
|
||||
uint32_t pieceLength;
|
||||
int32_t pieceLength;
|
||||
Strings pieceHashes;
|
||||
public:
|
||||
MetalinkChunkChecksum():pieceLength(0) {}
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
string version;
|
||||
string language;
|
||||
string os;
|
||||
uint64_t size;
|
||||
int64_t size;
|
||||
Checksum checksum;
|
||||
public:
|
||||
MetalinkResources resources;
|
||||
|
|
|
@ -102,16 +102,16 @@ void MultiDiskAdaptor::onDownloadComplete() {
|
|||
openFile();
|
||||
}
|
||||
|
||||
void MultiDiskAdaptor::writeData(const unsigned char* data, uint32_t len,
|
||||
void MultiDiskAdaptor::writeData(const unsigned char* data, int32_t len,
|
||||
int64_t offset)
|
||||
{
|
||||
int64_t fileOffset = offset;
|
||||
bool writing = false;
|
||||
uint32_t rem = len;
|
||||
int32_t rem = len;
|
||||
for(DiskWriterEntries::iterator itr = diskWriterEntries.begin();
|
||||
itr != diskWriterEntries.end() && rem != 0; itr++) {
|
||||
if(isInRange(*itr, offset) || writing) {
|
||||
uint32_t writeLength = calculateLength(*itr, fileOffset, rem);
|
||||
int32_t writeLength = calculateLength(*itr, fileOffset, rem);
|
||||
(*itr)->getDiskWriter()->writeData(data+(len-rem), writeLength, fileOffset);
|
||||
rem -= writeLength;
|
||||
writing = true;
|
||||
|
@ -132,11 +132,11 @@ bool MultiDiskAdaptor::isInRange(const DiskWriterEntryHandle entry,
|
|||
offset < entry->getFileEntry()->getOffset()+entry->getFileEntry()->getLength();
|
||||
}
|
||||
|
||||
uint32_t MultiDiskAdaptor::calculateLength(const DiskWriterEntryHandle entry,
|
||||
int64_t fileOffset,
|
||||
uint32_t rem) const
|
||||
int32_t MultiDiskAdaptor::calculateLength(const DiskWriterEntryHandle entry,
|
||||
int64_t fileOffset,
|
||||
int32_t rem) const
|
||||
{
|
||||
uint32_t length;
|
||||
int32_t length;
|
||||
if(entry->getFileEntry()->getLength() < fileOffset+rem) {
|
||||
length = entry->getFileEntry()->getLength()-fileOffset;
|
||||
} else {
|
||||
|
@ -145,16 +145,16 @@ uint32_t MultiDiskAdaptor::calculateLength(const DiskWriterEntryHandle entry,
|
|||
return length;
|
||||
}
|
||||
|
||||
int MultiDiskAdaptor::readData(unsigned char* data, uint32_t len, int64_t offset)
|
||||
int MultiDiskAdaptor::readData(unsigned char* data, int32_t len, int64_t offset)
|
||||
{
|
||||
int64_t fileOffset = offset;
|
||||
bool reading = false;
|
||||
uint32_t rem = len;
|
||||
uint32_t totalReadLength = 0;
|
||||
int32_t rem = len;
|
||||
int32_t totalReadLength = 0;
|
||||
for(DiskWriterEntries::iterator itr = diskWriterEntries.begin();
|
||||
itr != diskWriterEntries.end() && rem != 0; itr++) {
|
||||
if(isInRange(*itr, offset) || reading) {
|
||||
uint32_t readLength = calculateLength((*itr), fileOffset, rem);
|
||||
int32_t readLength = calculateLength((*itr), fileOffset, rem);
|
||||
totalReadLength += (*itr)->getDiskWriter()->readData(data+(len-rem), readLength, fileOffset);
|
||||
rem -= readLength;
|
||||
reading = true;
|
||||
|
@ -171,18 +171,18 @@ int MultiDiskAdaptor::readData(unsigned char* data, uint32_t len, int64_t offset
|
|||
|
||||
void MultiDiskAdaptor::hashUpdate(MessageDigestContext& ctx,
|
||||
const DiskWriterEntryHandle& entry,
|
||||
int64_t offset, uint64_t length)
|
||||
int64_t offset, int64_t length)
|
||||
{
|
||||
uint32_t BUFSIZE = 16*1024;
|
||||
int32_t BUFSIZE = 16*1024;
|
||||
unsigned char buf[BUFSIZE];
|
||||
for(uint64_t i = 0; i < length/BUFSIZE; i++) {
|
||||
if((int32_t)BUFSIZE != entry->getDiskWriter()->readData(buf, BUFSIZE, offset)) {
|
||||
for(int64_t i = 0; i < length/BUFSIZE; i++) {
|
||||
if(BUFSIZE != entry->getDiskWriter()->readData(buf, BUFSIZE, offset)) {
|
||||
throw new DlAbortEx(EX_FILE_SHA1SUM, "", strerror(errno));
|
||||
}
|
||||
ctx.digestUpdate(buf, BUFSIZE);
|
||||
offset += BUFSIZE;
|
||||
}
|
||||
uint32_t r = length%BUFSIZE;
|
||||
int32_t r = length%BUFSIZE;
|
||||
if(r > 0) {
|
||||
if((int32_t)r != entry->getDiskWriter()->readData(buf, r, offset)) {
|
||||
throw new DlAbortEx(EX_FILE_SHA1SUM, "", strerror(errno));
|
||||
|
@ -191,18 +191,18 @@ void MultiDiskAdaptor::hashUpdate(MessageDigestContext& ctx,
|
|||
}
|
||||
}
|
||||
|
||||
string MultiDiskAdaptor::messageDigest(int64_t offset, uint64_t length,
|
||||
string MultiDiskAdaptor::messageDigest(int64_t offset, int64_t length,
|
||||
const MessageDigestContext::DigestAlgo& algo) {
|
||||
int64_t fileOffset = offset;
|
||||
bool reading = false;
|
||||
uint32_t rem = length;
|
||||
int32_t rem = length;
|
||||
MessageDigestContext ctx(algo);
|
||||
ctx.digestInit();
|
||||
|
||||
for(DiskWriterEntries::iterator itr = diskWriterEntries.begin();
|
||||
itr != diskWriterEntries.end() && rem != 0; itr++) {
|
||||
if(isInRange(*itr, offset) || reading) {
|
||||
uint32_t readLength = calculateLength((*itr), fileOffset, rem);
|
||||
int32_t readLength = calculateLength((*itr), fileOffset, rem);
|
||||
hashUpdate(ctx, *itr, fileOffset, readLength);
|
||||
rem -= readLength;
|
||||
reading = true;
|
||||
|
|
|
@ -101,7 +101,7 @@ typedef deque<DiskWriterEntryHandle> DiskWriterEntries;
|
|||
class MultiDiskAdaptor : public DiskAdaptor {
|
||||
private:
|
||||
string topDir;
|
||||
uint32_t pieceLength;
|
||||
int32_t pieceLength;
|
||||
DiskWriterEntries diskWriterEntries;
|
||||
const Option* option;
|
||||
|
||||
|
@ -111,13 +111,13 @@ private:
|
|||
|
||||
bool isInRange(const DiskWriterEntryHandle entry, int64_t offset) const;
|
||||
|
||||
uint32_t calculateLength(const DiskWriterEntryHandle entry,
|
||||
int64_t fileOffset,
|
||||
uint32_t rem) const;
|
||||
int32_t calculateLength(const DiskWriterEntryHandle entry,
|
||||
int64_t fileOffset,
|
||||
int32_t rem) const;
|
||||
|
||||
void hashUpdate(MessageDigestContext& ctx,
|
||||
const DiskWriterEntryHandle& entry,
|
||||
int64_t offset, uint64_t length);
|
||||
int64_t offset, int64_t length);
|
||||
|
||||
string getTopDirPath() const;
|
||||
public:
|
||||
|
@ -137,12 +137,12 @@ public:
|
|||
|
||||
virtual void onDownloadComplete();
|
||||
|
||||
virtual void writeData(const unsigned char* data, uint32_t len,
|
||||
virtual void writeData(const unsigned char* data, int32_t len,
|
||||
int64_t offset);
|
||||
|
||||
virtual int readData(unsigned char* data, uint32_t len, int64_t offset);
|
||||
virtual int readData(unsigned char* data, int32_t len, int64_t offset);
|
||||
|
||||
virtual string messageDigest(int64_t offset, uint64_t length,
|
||||
virtual string messageDigest(int64_t offset, int64_t length,
|
||||
const MessageDigestContext::DigestAlgo& algo);
|
||||
|
||||
virtual bool fileExists();
|
||||
|
@ -159,11 +159,11 @@ public:
|
|||
return topDir;
|
||||
}
|
||||
|
||||
void setPieceLength(uint32_t pieceLength) {
|
||||
void setPieceLength(int32_t pieceLength) {
|
||||
this->pieceLength = pieceLength;
|
||||
}
|
||||
|
||||
uint32_t getPieceLength() const {
|
||||
int32_t getPieceLength() const {
|
||||
return pieceLength;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,11 +45,11 @@ public:
|
|||
|
||||
virtual void setFilename(const string& filename) {}
|
||||
|
||||
virtual void setMinValue(const uint64_t& min) {}
|
||||
virtual void setMinValue(const int64_t& min) {}
|
||||
|
||||
virtual void setMaxValue(const uint64_t& max) {}
|
||||
virtual void setMaxValue(const int64_t& max) {}
|
||||
|
||||
virtual void setCurrentValue(const uint64_t& current) {}
|
||||
virtual void setCurrentValue(const int64_t& current) {}
|
||||
|
||||
virtual void showProgress() {}
|
||||
|
||||
|
|
|
@ -56,8 +56,8 @@ PeerConnection::PeerConnection(int32_t cuid,
|
|||
|
||||
PeerConnection::~PeerConnection() {}
|
||||
|
||||
uint32_t PeerConnection::sendMessage(const unsigned char* data, uint32_t dataLength) {
|
||||
uint32_t writtenLength = 0;
|
||||
int32_t PeerConnection::sendMessage(const unsigned char* data, int32_t dataLength) {
|
||||
int32_t writtenLength = 0;
|
||||
if(socket->isWritable(0)) {
|
||||
// TODO fix this
|
||||
socket->writeData((const char*)data, dataLength);
|
||||
|
@ -66,14 +66,14 @@ uint32_t PeerConnection::sendMessage(const unsigned char* data, uint32_t dataLen
|
|||
return writtenLength;
|
||||
}
|
||||
|
||||
bool PeerConnection::receiveMessage(unsigned char* data, uint32_t& dataLength) {
|
||||
bool PeerConnection::receiveMessage(unsigned char* data, int32_t& dataLength) {
|
||||
if(!socket->isReadable(0)) {
|
||||
return false;
|
||||
}
|
||||
if(resbufLength == 0 && lenbufLength != 4) {
|
||||
// read payload size, 4-byte integer
|
||||
uint32_t remain = 4-lenbufLength;
|
||||
uint32_t temp = remain;
|
||||
int32_t remain = 4-lenbufLength;
|
||||
int32_t temp = remain;
|
||||
// TODO fix this
|
||||
socket->readData((char*)lenbuf+lenbufLength, (int&)temp);
|
||||
if(temp == 0) {
|
||||
|
@ -86,7 +86,7 @@ bool PeerConnection::receiveMessage(unsigned char* data, uint32_t& dataLength) {
|
|||
return false;
|
||||
}
|
||||
//payloadLen = ntohl(nPayloadLen);
|
||||
uint32_t payloadLength = ntohl(*((uint32_t*)lenbuf));
|
||||
int32_t payloadLength = ntohl(*((int32_t*)lenbuf));
|
||||
if(payloadLength > MAX_PAYLOAD_LEN || payloadLength < 0) {
|
||||
throw new DlAbortEx("max payload length exceeded or invalid. length = %d",
|
||||
payloadLength);
|
||||
|
@ -97,7 +97,7 @@ bool PeerConnection::receiveMessage(unsigned char* data, uint32_t& dataLength) {
|
|||
return false;
|
||||
}
|
||||
// we have currentPayloadLen-resbufLen bytes to read
|
||||
uint32_t remaining = currentPayloadLength-resbufLength;
|
||||
int32_t remaining = currentPayloadLength-resbufLength;
|
||||
if(remaining > 0) {
|
||||
socket->readData((char*)resbuf+resbufLength, (int&)remaining);
|
||||
if(remaining == 0) {
|
||||
|
@ -118,13 +118,13 @@ bool PeerConnection::receiveMessage(unsigned char* data, uint32_t& dataLength) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool PeerConnection::receiveHandshake(unsigned char* data, uint32_t& dataLength) {
|
||||
bool PeerConnection::receiveHandshake(unsigned char* data, int32_t& dataLength) {
|
||||
if(!socket->isReadable(0)) {
|
||||
dataLength = 0;
|
||||
return false;
|
||||
}
|
||||
uint32_t remain = BtHandshakeMessage::MESSAGE_LENGTH-resbufLength;
|
||||
uint32_t temp = remain;
|
||||
int32_t remain = BtHandshakeMessage::MESSAGE_LENGTH-resbufLength;
|
||||
int32_t temp = remain;
|
||||
socket->readData((char*)resbuf+resbufLength, (int&)temp);
|
||||
if(temp == 0) {
|
||||
// we got EOF
|
||||
|
@ -138,7 +138,7 @@ bool PeerConnection::receiveHandshake(unsigned char* data, uint32_t& dataLength)
|
|||
}
|
||||
resbufLength += temp;
|
||||
// we got whole handshake payload
|
||||
uint32_t writeLength = resbufLength > dataLength ? dataLength : resbufLength;
|
||||
int32_t writeLength = resbufLength > dataLength ? dataLength : resbufLength;
|
||||
memcpy(data, resbuf, writeLength);
|
||||
dataLength = writeLength;
|
||||
if(retval) {
|
||||
|
|
|
@ -52,19 +52,19 @@ private:
|
|||
const Logger* logger;
|
||||
|
||||
char resbuf[MAX_PAYLOAD_LEN];
|
||||
uint32_t resbufLength;
|
||||
uint32_t currentPayloadLength;
|
||||
int32_t resbufLength;
|
||||
int32_t currentPayloadLength;
|
||||
unsigned char lenbuf[4];
|
||||
uint32_t lenbufLength;
|
||||
int32_t lenbufLength;
|
||||
|
||||
public:
|
||||
PeerConnection(int32_t cuid, const SocketHandle& socket, const Option* op);
|
||||
~PeerConnection();
|
||||
|
||||
// Returns the number of bytes written
|
||||
uint32_t sendMessage(const unsigned char* data, uint32_t dataLength);
|
||||
int32_t sendMessage(const unsigned char* data, int32_t dataLength);
|
||||
|
||||
bool receiveMessage(unsigned char* data, uint32_t& dataLength);
|
||||
bool receiveMessage(unsigned char* data, int32_t& dataLength);
|
||||
|
||||
/**
|
||||
* Returns true if a handshake message is fully received, otherwise returns
|
||||
|
@ -72,7 +72,7 @@ public:
|
|||
* In both cases, 'msg' is filled with received bytes and the filled length
|
||||
* is assigned to 'length'.
|
||||
*/
|
||||
bool receiveHandshake(unsigned char* data, uint32_t& dataLength);
|
||||
bool receiveHandshake(unsigned char* data, int32_t& dataLength);
|
||||
};
|
||||
|
||||
typedef SharedHandle<PeerConnection> PeerConnectionHandle;
|
||||
|
|
|
@ -42,7 +42,7 @@ class PeerInteractionCommand : public PeerAbstractCommand {
|
|||
private:
|
||||
int sequence;
|
||||
BtInteractiveHandle btInteractive;
|
||||
uint32_t maxDownloadSpeedLimit;
|
||||
int32_t maxDownloadSpeedLimit;
|
||||
protected:
|
||||
virtual bool executeInternal();
|
||||
virtual bool prepareForRetry(int wait);
|
||||
|
|
|
@ -37,89 +37,89 @@
|
|||
#include "Util.h"
|
||||
#include <netinet/in.h>
|
||||
|
||||
uint8_t PeerMessageUtil::getId(const unsigned char* msg) {
|
||||
int8_t PeerMessageUtil::getId(const unsigned char* msg) {
|
||||
return msg[0];
|
||||
}
|
||||
|
||||
uint32_t PeerMessageUtil::getIntParam(const unsigned char* msg, int32_t offset) {
|
||||
uint32_t nParam;
|
||||
memcpy(&nParam, msg+offset, sizeof(uint32_t));
|
||||
int32_t PeerMessageUtil::getIntParam(const unsigned char* msg, int32_t offset) {
|
||||
int32_t nParam;
|
||||
memcpy(&nParam, msg+offset, sizeof(int32_t));
|
||||
return ntohl(nParam);
|
||||
}
|
||||
|
||||
uint16_t PeerMessageUtil::getShortIntParam(const unsigned char* msg, int32_t offset) {
|
||||
uint16_t nParam;
|
||||
memcpy(&nParam, msg+offset, sizeof(uint16_t));
|
||||
int16_t PeerMessageUtil::getShortIntParam(const unsigned char* msg, int32_t offset) {
|
||||
int16_t nParam;
|
||||
memcpy(&nParam, msg+offset, sizeof(int16_t));
|
||||
return ntohs(nParam);
|
||||
}
|
||||
|
||||
void PeerMessageUtil::checkIndex(int32_t index, uint32_t pieces) {
|
||||
void PeerMessageUtil::checkIndex(int32_t index, int32_t pieces) {
|
||||
if(!(0 <= index && index < (int32_t)pieces)) {
|
||||
throw new DlAbortEx("invalid index = %u", index);
|
||||
throw new DlAbortEx("Invalid index: %d", index);
|
||||
}
|
||||
}
|
||||
|
||||
void PeerMessageUtil::checkBegin(int32_t begin, uint32_t pieceLength) {
|
||||
void PeerMessageUtil::checkBegin(int32_t begin, int32_t pieceLength) {
|
||||
if(!(0 <= begin && begin < (int32_t)pieceLength)) {
|
||||
throw new DlAbortEx("invalid begin = %u", begin);
|
||||
throw new DlAbortEx("Invalid begin: %d", begin);
|
||||
}
|
||||
}
|
||||
|
||||
void PeerMessageUtil::checkLength(uint32_t length) {
|
||||
void PeerMessageUtil::checkLength(int32_t length) {
|
||||
if(length > MAX_BLOCK_LENGTH) {
|
||||
throw new DlAbortEx("too large length %u > %dKB", length,
|
||||
throw new DlAbortEx("Length too long: %d > %dKB", length,
|
||||
MAX_BLOCK_LENGTH/1024);
|
||||
}
|
||||
if(length <= 0) {
|
||||
throw new DlAbortEx("invalid length %u", length);
|
||||
throw new DlAbortEx("Invalid length: %d", length);
|
||||
}
|
||||
if(!Util::isPowerOf(length, 2)) {
|
||||
throw new DlAbortEx("invalid length %u, which is not power of 2",
|
||||
throw new DlAbortEx("Invalid length: %d It is not power of 2",
|
||||
length);
|
||||
}
|
||||
}
|
||||
|
||||
void PeerMessageUtil::checkRange(int32_t begin, uint32_t length, uint32_t pieceLength) {
|
||||
void PeerMessageUtil::checkRange(int32_t begin, int32_t length, int32_t pieceLength) {
|
||||
if(!(0 <= begin && 0 < length)) {
|
||||
throw new DlAbortEx("invalid range, begin = %u, length = %u",
|
||||
throw new DlAbortEx("Invalid range: begin=%d, length=%d",
|
||||
begin, length);
|
||||
}
|
||||
uint32_t end = begin+length;
|
||||
int32_t end = begin+length;
|
||||
if(!(0 < end && end <= pieceLength)) {
|
||||
throw new DlAbortEx("invalid range, begin = %u, length = %u",
|
||||
throw new DlAbortEx("Invalid range: begin=%d, length=%d",
|
||||
begin, length);
|
||||
}
|
||||
}
|
||||
|
||||
void PeerMessageUtil::checkBitfield(const unsigned char* bitfield,
|
||||
uint32_t bitfieldLength,
|
||||
uint32_t pieces) {
|
||||
int32_t bitfieldLength,
|
||||
int32_t pieces) {
|
||||
if(!(bitfieldLength == BITFIELD_LEN_FROM_PIECES(pieces))) {
|
||||
throw new DlAbortEx("invalid bitfield length = %d",
|
||||
throw new DlAbortEx("Invalid bitfield length: %d",
|
||||
bitfieldLength);
|
||||
}
|
||||
char lastbyte = bitfield[bitfieldLength-1];
|
||||
for(uint32_t i = 0; i < 8-pieces%8 && pieces%8 != 0; i++) {
|
||||
for(int32_t i = 0; i < 8-pieces%8 && pieces%8 != 0; ++i) {
|
||||
if(!(((lastbyte >> i) & 1) == 0)) {
|
||||
throw new DlAbortEx("invalid bitfield");
|
||||
throw new DlAbortEx("Invalid bitfield");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PeerMessageUtil::setIntParam(unsigned char* dest, uint32_t param) {
|
||||
uint32_t nParam = htonl(param);
|
||||
memcpy(dest, &nParam, sizeof(uint32_t));
|
||||
void PeerMessageUtil::setIntParam(unsigned char* dest, int32_t param) {
|
||||
int32_t nParam = htonl(param);
|
||||
memcpy(dest, &nParam, sizeof(int32_t));
|
||||
}
|
||||
|
||||
void PeerMessageUtil::setShortIntParam(unsigned char* dest, uint16_t param) {
|
||||
uint16_t nParam = htons(param);
|
||||
memcpy(dest, &nParam, sizeof(uint16_t));
|
||||
void PeerMessageUtil::setShortIntParam(unsigned char* dest, int16_t param) {
|
||||
int16_t nParam = htons(param);
|
||||
memcpy(dest, &nParam, sizeof(int16_t));
|
||||
}
|
||||
|
||||
void PeerMessageUtil::createPeerMessageString(unsigned char* msg,
|
||||
uint32_t msgLength,
|
||||
uint32_t payloadLength,
|
||||
uint8_t messageId) {
|
||||
int32_t msgLength,
|
||||
int32_t payloadLength,
|
||||
int8_t messageId) {
|
||||
assert(msgLength >= 5);
|
||||
memset(msg, 0, msgLength);
|
||||
setIntParam(msg, payloadLength);
|
||||
|
|
|
@ -43,28 +43,28 @@ class PeerMessageUtil {
|
|||
private:
|
||||
PeerMessageUtil() {}
|
||||
public:
|
||||
static uint32_t getIntParam(const unsigned char* msg, int32_t offset);
|
||||
static int32_t getIntParam(const unsigned char* msg, int32_t offset);
|
||||
|
||||
static uint16_t getShortIntParam(const unsigned char* msg, int32_t offset);
|
||||
static int16_t getShortIntParam(const unsigned char* msg, int32_t offset);
|
||||
|
||||
static void setIntParam(unsigned char* dest, uint32_t param);
|
||||
static void setIntParam(unsigned char* dest, int32_t param);
|
||||
|
||||
static void setShortIntParam(unsigned char* dest, uint16_t param);
|
||||
static void setShortIntParam(unsigned char* dest, int16_t param);
|
||||
|
||||
static uint8_t getId(const unsigned char* msg);
|
||||
static int8_t getId(const unsigned char* msg);
|
||||
|
||||
static void checkIndex(int32_t index, uint32_t pieces);
|
||||
static void checkBegin(int32_t begin, uint32_t pieceLength);
|
||||
static void checkLength(uint32_t length);
|
||||
static void checkRange(int32_t begin, uint32_t length, uint32_t pieceLength);
|
||||
static void checkIndex(int32_t index, int32_t pieces);
|
||||
static void checkBegin(int32_t begin, int32_t pieceLength);
|
||||
static void checkLength(int32_t length);
|
||||
static void checkRange(int32_t begin, int32_t length, int32_t pieceLength);
|
||||
static void checkBitfield(const unsigned char* bitfield,
|
||||
uint32_t bitfieldLength,
|
||||
uint32_t pieces);
|
||||
int32_t bitfieldLength,
|
||||
int32_t pieces);
|
||||
|
||||
static void createPeerMessageString(unsigned char* msg,
|
||||
uint32_t msgLength,
|
||||
uint32_t payloadLength,
|
||||
uint8_t messageId);
|
||||
int32_t msgLength,
|
||||
int32_t payloadLength,
|
||||
int8_t messageId);
|
||||
};
|
||||
|
||||
#endif // _D_PEER_MESSAGE_UTIL_H_
|
||||
|
|
|
@ -40,45 +40,45 @@
|
|||
|
||||
class TransferStat {
|
||||
public:
|
||||
uint32_t downloadSpeed;
|
||||
uint32_t uploadSpeed;
|
||||
uint64_t sessionDownloadLength;
|
||||
uint64_t sessionUploadLength;
|
||||
int32_t downloadSpeed;
|
||||
int32_t uploadSpeed;
|
||||
int64_t sessionDownloadLength;
|
||||
int64_t sessionUploadLength;
|
||||
public:
|
||||
TransferStat():downloadSpeed(0), uploadSpeed(0),
|
||||
sessionDownloadLength(0), sessionUploadLength(0) {}
|
||||
|
||||
uint32_t getDownloadSpeed() const {
|
||||
int32_t getDownloadSpeed() const {
|
||||
return downloadSpeed;
|
||||
}
|
||||
|
||||
void setDownloadSpeed(uint32_t s) { downloadSpeed = s; }
|
||||
void setDownloadSpeed(int32_t s) { downloadSpeed = s; }
|
||||
|
||||
uint32_t getUploadSpeed() const {
|
||||
int32_t getUploadSpeed() const {
|
||||
return uploadSpeed;
|
||||
}
|
||||
|
||||
void setUploadSpeed(uint32_t s) { uploadSpeed = s; }
|
||||
void setUploadSpeed(int32_t s) { uploadSpeed = s; }
|
||||
|
||||
/**
|
||||
* Returns the number of bytes downloaded since the program started.
|
||||
* This is not the total number of bytes downloaded.
|
||||
*/
|
||||
uint64_t getSessionDownloadLength() const {
|
||||
int64_t getSessionDownloadLength() const {
|
||||
return sessionDownloadLength;
|
||||
}
|
||||
|
||||
void setSessionDownloadLength(uint64_t s) { sessionDownloadLength = s; }
|
||||
void setSessionDownloadLength(int64_t s) { sessionDownloadLength = s; }
|
||||
|
||||
/**
|
||||
* Returns the number of bytes uploaded since the program started.
|
||||
* This is not the total number of bytes uploaded.
|
||||
*/
|
||||
uint64_t getSessionUploadLength() const {
|
||||
int64_t getSessionUploadLength() const {
|
||||
return sessionUploadLength;
|
||||
}
|
||||
|
||||
void setSessionUploadLength(uint64_t s) { sessionUploadLength = s; }
|
||||
void setSessionUploadLength(int64_t s) { sessionUploadLength = s; }
|
||||
};
|
||||
|
||||
class PeerStorage {
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
#include "RequestSlot.h"
|
||||
#include "Util.h"
|
||||
|
||||
RequestSlot::RequestSlot(int32_t index, int32_t begin, uint32_t length, int32_t blockIndex)
|
||||
RequestSlot::RequestSlot(int32_t index, int32_t begin, int32_t length, int32_t blockIndex)
|
||||
:index(index), begin(begin), length(length), blockIndex(blockIndex) {}
|
||||
|
||||
RequestSlot::RequestSlot(const RequestSlot& requestSlot) {
|
||||
|
|
|
@ -43,11 +43,11 @@ private:
|
|||
Time dispatchedTime;
|
||||
int32_t index;
|
||||
int32_t begin;
|
||||
uint32_t length;
|
||||
int32_t length;
|
||||
int32_t blockIndex;
|
||||
void copy(const RequestSlot& requestSlot);
|
||||
public:
|
||||
RequestSlot(int32_t index, int32_t begin, uint32_t length, int32_t blockIndex);
|
||||
RequestSlot(int32_t index, int32_t begin, int32_t length, int32_t blockIndex);
|
||||
RequestSlot(const RequestSlot& requestSlot);
|
||||
~RequestSlot() {}
|
||||
|
||||
|
@ -76,8 +76,8 @@ public:
|
|||
int32_t getBegin() const { return begin; }
|
||||
void setBegin(int32_t begin) { this->begin = begin; }
|
||||
|
||||
uint32_t getLength() const { return length; }
|
||||
void setLength(uint32_t length) { this->length = length; }
|
||||
int32_t getLength() const { return length; }
|
||||
void setLength(int32_t length) { this->length = length; }
|
||||
|
||||
int32_t getBlockIndex() const { return blockIndex; }
|
||||
void setBlockIndex(int32_t blockIndex) { this->blockIndex = blockIndex; }
|
||||
|
|
|
@ -432,7 +432,7 @@ void SegmentMan::registerPeerStat(const PeerStatHandle& peerStat) {
|
|||
}
|
||||
}
|
||||
|
||||
uint32_t SegmentMan::calculateDownloadSpeed() const {
|
||||
int32_t SegmentMan::calculateDownloadSpeed() const {
|
||||
int speed = 0;
|
||||
for(PeerStats::const_iterator itr = peerStats.begin();
|
||||
itr != peerStats.end(); itr++) {
|
||||
|
@ -473,7 +473,7 @@ void SegmentMan::checkIntegrity()
|
|||
|
||||
bool SegmentMan::isChunkChecksumValidationReady() const {
|
||||
return bitfield &&
|
||||
pieceHashes.size()*chunkHashLength == bitfield->getBlockLength()*(bitfield->getMaxIndex()+1);
|
||||
((int64_t)pieceHashes.size())*chunkHashLength == ((int64_t)bitfield->getBlockLength())*(bitfield->getMaxIndex()+1);
|
||||
}
|
||||
|
||||
void SegmentMan::tryChunkChecksumValidation(const Segment& segment)
|
||||
|
@ -499,7 +499,7 @@ void SegmentMan::tryChunkChecksumValidation(const Segment& segment)
|
|||
logger->debug("No chunk to verify.");
|
||||
return;
|
||||
}
|
||||
int64_t hashOffset = hashStartIndex*chunkHashLength;
|
||||
int64_t hashOffset = ((int64_t)hashStartIndex)*chunkHashLength;
|
||||
int32_t startIndex;
|
||||
int32_t endIndex;
|
||||
Util::indexRange(startIndex, endIndex,
|
||||
|
@ -509,15 +509,15 @@ void SegmentMan::tryChunkChecksumValidation(const Segment& segment)
|
|||
logger->debug("startIndex=%d, endIndex=%d", startIndex, endIndex);
|
||||
if(bitfield->isBitRangeSet(startIndex, endIndex)) {
|
||||
for(int32_t index = hashStartIndex; index <= hashEndIndex; ++index) {
|
||||
int64_t offset = index*chunkHashLength;
|
||||
uint32_t dataLength =
|
||||
int64_t offset = ((int64_t)index)*chunkHashLength;
|
||||
int32_t dataLength =
|
||||
offset+chunkHashLength <= totalSize ? chunkHashLength : totalSize-offset;
|
||||
string actualChecksum = diskWriter->messageDigest(offset, dataLength, digestAlgo);
|
||||
string expectedChecksum = pieceHashes.at(index);
|
||||
if(expectedChecksum == actualChecksum) {
|
||||
logger->info("Chunk checksum validation succeeded.");
|
||||
logger->info("Good chunk checksum.");
|
||||
} else {
|
||||
logger->error("Chunk checksum validation failed. checksumIndex=%d, offset=%lld, length=%u, expected=%s, actual=%s",
|
||||
logger->error(EX_INVALID_CHUNK_CHECKSUM,
|
||||
index, offset, dataLength,
|
||||
expectedChecksum.c_str(), actualChecksum.c_str());
|
||||
logger->info("Unset bit from %d to %d(inclusive)", startIndex, endIndex);
|
||||
|
|
|
@ -158,7 +158,7 @@ public:
|
|||
Requests reserved;
|
||||
|
||||
Strings pieceHashes;
|
||||
uint32_t chunkHashLength;
|
||||
int32_t chunkHashLength;
|
||||
MessageDigestContext::DigestAlgo digestAlgo;
|
||||
|
||||
SegmentMan();
|
||||
|
@ -275,7 +275,7 @@ public:
|
|||
/**
|
||||
* Returns current download speed in bytes per sec.
|
||||
*/
|
||||
uint32_t calculateDownloadSpeed() const;
|
||||
int32_t calculateDownloadSpeed() const;
|
||||
|
||||
bool fileExists();
|
||||
|
||||
|
|
|
@ -41,11 +41,11 @@ class RefCount {
|
|||
public:
|
||||
RefCount():totalRefCount(0), strongRefCount(0) {}
|
||||
|
||||
RefCount(uint32_t totalRefCount, uint32_t strongRefCount)
|
||||
RefCount(int32_t totalRefCount, int32_t strongRefCount)
|
||||
:totalRefCount(totalRefCount), strongRefCount(strongRefCount) {}
|
||||
|
||||
uint32_t totalRefCount;
|
||||
uint32_t strongRefCount;
|
||||
int32_t totalRefCount;
|
||||
int32_t strongRefCount;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
|
|
@ -49,7 +49,7 @@ public:
|
|||
|
||||
virtual const unsigned char* getMessage() = 0;
|
||||
|
||||
virtual uint32_t getMessageLength() = 0;
|
||||
virtual int32_t getMessageLength() = 0;
|
||||
|
||||
virtual void onSendComplete() {};
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ class HeadResult {
|
|||
public:
|
||||
HeadResult():totalLength(0) {}
|
||||
string filename;
|
||||
uint64_t totalLength;
|
||||
int64_t totalLength;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& o, const HeadResult& hr);
|
||||
|
@ -51,7 +51,7 @@ private:
|
|||
Strings urls;
|
||||
int maxConnections;
|
||||
MessageDigestContext::DigestAlgo digestAlgo;
|
||||
uint32_t chunkChecksumLength;
|
||||
int32_t chunkChecksumLength;
|
||||
Strings chunkChecksums;
|
||||
|
||||
RequestInfo* createNextRequestInfo() const;
|
||||
|
@ -76,7 +76,7 @@ public:
|
|||
this->digestAlgo = algo;
|
||||
}
|
||||
|
||||
void setChunkChecksumLength(uint32_t chunkChecksumLength) {
|
||||
void setChunkChecksumLength(int32_t chunkChecksumLength) {
|
||||
this->chunkChecksumLength = chunkChecksumLength;
|
||||
}
|
||||
|
||||
|
|
12
src/Util.cc
12
src/Util.cc
|
@ -571,7 +571,7 @@ static int nbits[] = {
|
|||
4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,
|
||||
};
|
||||
|
||||
uint32_t Util::countBit(uint32_t n) {
|
||||
int32_t Util::countBit(uint32_t n) {
|
||||
return
|
||||
nbits[n&0xffu]+
|
||||
nbits[(n >> 8)&0xffu]+
|
||||
|
@ -638,9 +638,13 @@ void Util::setGlobalSignalHandler(int signal, void (*handler)(int), int flags) {
|
|||
}
|
||||
|
||||
void Util::indexRange(int32_t& startIndex, int32_t& endIndex,
|
||||
int64_t offset, uint32_t srcLength, uint32_t destLength)
|
||||
int64_t offset, int32_t srcLength, int32_t destLength)
|
||||
{
|
||||
startIndex = offset/destLength;
|
||||
endIndex = (offset+srcLength-1)/destLength;
|
||||
int64_t _startIndex = offset/destLength;
|
||||
int64_t _endIndex = (offset+srcLength-1)/destLength;
|
||||
assert(_startIndex <= INT32_MAX);
|
||||
assert(_endIndex <= INT32_MAX);
|
||||
startIndex = _startIndex;
|
||||
endIndex = _endIndex;
|
||||
}
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue