mirror of https://github.com/aria2/aria2
2008-03-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
type cleanup for allmost all remaining files.pull/1/head
parent
ca3f6e57f3
commit
032c7c2808
|
@ -1,3 +1,7 @@
|
|||
2008-03-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
type cleanup for allmost all remaining files.
|
||||
|
||||
2008-03-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Type clarification
|
||||
|
|
|
@ -119,13 +119,13 @@ bool AbstractCommand::execute() {
|
|||
checkPoint.reset();
|
||||
if(!_requestGroup->getPieceStorage().isNull()) {
|
||||
_segments = _requestGroup->getSegmentMan()->getInFlightSegment(cuid);
|
||||
int32_t maxSegments;
|
||||
size_t maxSegments;
|
||||
if(req->isKeepAlive() && e->option->get(PREF_ENABLE_HTTP_PIPELINING) == V_TRUE) {
|
||||
maxSegments = e->option->getAsInt(PREF_MAX_HTTP_PIPELINING);
|
||||
} else {
|
||||
maxSegments = 1;
|
||||
}
|
||||
while((int32_t)_segments.size() < maxSegments) {
|
||||
while(_segments.size() < maxSegments) {
|
||||
SegmentHandle segment = _requestGroup->getSegmentMan()->getSegment(cuid);
|
||||
if(segment.isNull()) {
|
||||
break;
|
||||
|
@ -156,7 +156,7 @@ bool AbstractCommand::execute() {
|
|||
logger->info(MSG_RESTARTING_DOWNLOAD, err, cuid, req->getUrl().c_str());
|
||||
req->addTryCount();
|
||||
bool isAbort = e->option->getAsInt(PREF_MAX_TRIES) != 0 &&
|
||||
req->getTryCount() >= e->option->getAsInt(PREF_MAX_TRIES);
|
||||
req->getTryCount() >= (unsigned int)e->option->getAsInt(PREF_MAX_TRIES);
|
||||
if(isAbort) {
|
||||
onAbort(err);
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ void AbstractCommand::tryReserved() {
|
|||
e->addCommand(commands);
|
||||
}
|
||||
|
||||
bool AbstractCommand::prepareForRetry(int32_t wait) {
|
||||
bool AbstractCommand::prepareForRetry(time_t wait) {
|
||||
if(!_requestGroup->getPieceStorage().isNull()) {
|
||||
_requestGroup->getSegmentMan()->cancelSegment(cuid);
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ class SocketCore;
|
|||
class AbstractCommand : public Command, public RequestGroupAware {
|
||||
private:
|
||||
Time checkPoint;
|
||||
int32_t timeout;
|
||||
time_t timeout;
|
||||
protected:
|
||||
SharedHandle<Request> req;
|
||||
DownloadEngine* e;
|
||||
|
@ -61,7 +61,7 @@ protected:
|
|||
std::deque<SharedHandle<Segment> > _segments;
|
||||
|
||||
void tryReserved();
|
||||
virtual bool prepareForRetry(int32_t wait);
|
||||
virtual bool prepareForRetry(time_t wait);
|
||||
virtual void onAbort(Exception* ex);
|
||||
virtual bool executeInternal() = 0;
|
||||
|
||||
|
@ -76,7 +76,7 @@ protected:
|
|||
void disableNameResolverCheck(const SharedHandle<NameResolver>& resolver);
|
||||
virtual bool nameResolveFinished() const;
|
||||
#endif // ENABLE_ASYNC_DNS
|
||||
void setTimeout(int32_t timeout) { this->timeout = timeout; }
|
||||
void setTimeout(time_t timeout) { this->timeout = timeout; }
|
||||
|
||||
void prepareForNextAction(Command* nextCommand = 0);
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ AbstractDiskWriter::~AbstractDiskWriter()
|
|||
closeFile();
|
||||
}
|
||||
|
||||
void AbstractDiskWriter::openFile(const std::string& filename, int64_t totalLength)
|
||||
void AbstractDiskWriter::openFile(const std::string& filename, uint64_t totalLength)
|
||||
{
|
||||
File f(filename);
|
||||
if(f.exists()) {
|
||||
|
@ -73,7 +73,7 @@ void AbstractDiskWriter::closeFile()
|
|||
}
|
||||
|
||||
void AbstractDiskWriter::openExistingFile(const std::string& filename,
|
||||
int64_t totalLength)
|
||||
uint64_t totalLength)
|
||||
{
|
||||
this->filename = filename;
|
||||
File f(filename);
|
||||
|
@ -86,7 +86,7 @@ void AbstractDiskWriter::openExistingFile(const std::string& filename,
|
|||
}
|
||||
}
|
||||
|
||||
void AbstractDiskWriter::createFile(const std::string& filename, int32_t addFlags)
|
||||
void AbstractDiskWriter::createFile(const std::string& filename, int addFlags)
|
||||
{
|
||||
this->filename = filename;
|
||||
assert(filename.size());
|
||||
|
@ -96,11 +96,11 @@ void AbstractDiskWriter::createFile(const std::string& filename, int32_t addFlag
|
|||
}
|
||||
}
|
||||
|
||||
int32_t AbstractDiskWriter::writeDataInternal(const unsigned char* data, int32_t len)
|
||||
ssize_t AbstractDiskWriter::writeDataInternal(const unsigned char* data, size_t len)
|
||||
{
|
||||
int32_t writtenLength = 0;
|
||||
while(writtenLength < len) {
|
||||
int32_t ret = 0;
|
||||
ssize_t writtenLength = 0;
|
||||
while((size_t)writtenLength < len) {
|
||||
ssize_t ret = 0;
|
||||
while((ret = write(fd, data+writtenLength, len-writtenLength)) == -1 && errno == EINTR);
|
||||
if(ret == -1) {
|
||||
return -1;
|
||||
|
@ -110,21 +110,21 @@ int32_t AbstractDiskWriter::writeDataInternal(const unsigned char* data, int32_t
|
|||
return writtenLength;
|
||||
}
|
||||
|
||||
int32_t AbstractDiskWriter::readDataInternal(unsigned char* data, int32_t len)
|
||||
ssize_t AbstractDiskWriter::readDataInternal(unsigned char* data, size_t len)
|
||||
{
|
||||
int32_t ret = 0;
|
||||
ssize_t ret = 0;
|
||||
while((ret = read(fd, data, len)) == -1 && errno == EINTR);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void AbstractDiskWriter::seek(int64_t offset)
|
||||
void AbstractDiskWriter::seek(off_t offset)
|
||||
{
|
||||
if(offset != lseek(fd, offset, SEEK_SET)) {
|
||||
throw new DlAbortEx(EX_FILE_SEEK, filename.c_str(), strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractDiskWriter::writeData(const unsigned char* data, int32_t len, int64_t offset)
|
||||
void AbstractDiskWriter::writeData(const unsigned char* data, size_t len, off_t offset)
|
||||
{
|
||||
seek(offset);
|
||||
if(writeDataInternal(data, len) < 0) {
|
||||
|
@ -132,9 +132,9 @@ void AbstractDiskWriter::writeData(const unsigned char* data, int32_t len, int64
|
|||
}
|
||||
}
|
||||
|
||||
int32_t AbstractDiskWriter::readData(unsigned char* data, int32_t len, int64_t offset)
|
||||
ssize_t AbstractDiskWriter::readData(unsigned char* data, size_t len, off_t offset)
|
||||
{
|
||||
int32_t ret;
|
||||
ssize_t ret;
|
||||
seek(offset);
|
||||
if((ret = readDataInternal(data, len)) < 0) {
|
||||
throw new DlAbortEx(EX_FILE_READ, filename.c_str(), strerror(errno));
|
||||
|
@ -142,7 +142,7 @@ int32_t AbstractDiskWriter::readData(unsigned char* data, int32_t len, int64_t o
|
|||
return ret;
|
||||
}
|
||||
|
||||
void AbstractDiskWriter::truncate(int64_t length)
|
||||
void AbstractDiskWriter::truncate(uint64_t length)
|
||||
{
|
||||
if(fd == -1) {
|
||||
throw new DlAbortEx("File not opened.");
|
||||
|
@ -151,7 +151,7 @@ void AbstractDiskWriter::truncate(int64_t length)
|
|||
}
|
||||
|
||||
// TODO the file descriptor fd must be opened before calling this function.
|
||||
int64_t AbstractDiskWriter::size() const
|
||||
uint64_t AbstractDiskWriter::size() const
|
||||
{
|
||||
if(fd == -1) {
|
||||
throw new DlAbortEx("File not opened.");
|
||||
|
@ -167,7 +167,7 @@ void AbstractDiskWriter::enableDirectIO()
|
|||
{
|
||||
#ifdef ENABLE_DIRECT_IO
|
||||
if(_directIOAllowed) {
|
||||
int32_t flg;
|
||||
int flg;
|
||||
while((flg = fcntl(fd, F_GETFL)) == -1 && errno == EINTR);
|
||||
while(fcntl(fd, F_SETFL, flg|O_DIRECT) == -1 && errno == EINTR);
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ void AbstractDiskWriter::enableDirectIO()
|
|||
void AbstractDiskWriter::disableDirectIO()
|
||||
{
|
||||
#ifdef ENABLE_DIRECT_IO
|
||||
int32_t flg;
|
||||
int flg;
|
||||
while((flg = fcntl(fd, F_GETFL)) == -1 && errno == EINTR);
|
||||
while(fcntl(fd, F_SETFL, flg&(~O_DIRECT)) == -1 && errno == EINTR);
|
||||
#endif // ENABLE_DIRECT_IO
|
||||
|
|
|
@ -45,34 +45,34 @@ class Logger;
|
|||
class AbstractDiskWriter : public DiskWriter {
|
||||
protected:
|
||||
std::string filename;
|
||||
int32_t fd;
|
||||
int fd;
|
||||
const Logger* logger;
|
||||
|
||||
void createFile(const std::string& filename, int32_t addFlags = 0);
|
||||
void createFile(const std::string& filename, int addFlags = 0);
|
||||
|
||||
private:
|
||||
int32_t writeDataInternal(const unsigned char* data, int32_t len);
|
||||
int32_t readDataInternal(unsigned char* data, int32_t len);
|
||||
ssize_t writeDataInternal(const unsigned char* data, size_t len);
|
||||
ssize_t readDataInternal(unsigned char* data, size_t len);
|
||||
|
||||
void seek(int64_t offset);
|
||||
void seek(off_t offset);
|
||||
|
||||
public:
|
||||
AbstractDiskWriter();
|
||||
virtual ~AbstractDiskWriter();
|
||||
|
||||
virtual void openFile(const std::string& filename, int64_t totalLength = 0);
|
||||
virtual void openFile(const std::string& filename, uint64_t totalLength = 0);
|
||||
|
||||
virtual void closeFile();
|
||||
|
||||
virtual void openExistingFile(const std::string& filename, int64_t totalLength = 0);
|
||||
virtual void openExistingFile(const std::string& filename, uint64_t totalLength = 0);
|
||||
|
||||
virtual void writeData(const unsigned char* data, int32_t len, int64_t offset);
|
||||
virtual void writeData(const unsigned char* data, size_t len, off_t offset);
|
||||
|
||||
virtual int32_t readData(unsigned char* data, int32_t len, int64_t offset);
|
||||
virtual ssize_t readData(unsigned char* data, size_t len, off_t offset);
|
||||
|
||||
virtual void truncate(int64_t length);
|
||||
virtual void truncate(uint64_t length);
|
||||
|
||||
virtual int64_t size() const;
|
||||
virtual uint64_t size() const;
|
||||
|
||||
virtual void enableDirectIO();
|
||||
|
||||
|
|
|
@ -65,12 +65,12 @@ void AbstractSingleDiskAdaptor::openExistingFile()
|
|||
diskWriter->openExistingFile(getFilePath(), totalLength);
|
||||
}
|
||||
|
||||
void AbstractSingleDiskAdaptor::writeData(const unsigned char* data, int32_t len, int64_t offset)
|
||||
void AbstractSingleDiskAdaptor::writeData(const unsigned char* data, size_t len, off_t offset)
|
||||
{
|
||||
diskWriter->writeData(data, len, offset);
|
||||
}
|
||||
|
||||
int32_t AbstractSingleDiskAdaptor::readData(unsigned char* data, int32_t len, int64_t offset)
|
||||
ssize_t AbstractSingleDiskAdaptor::readData(unsigned char* data, size_t len, off_t offset)
|
||||
{
|
||||
return diskWriter->readData(data, len, offset);
|
||||
}
|
||||
|
@ -80,12 +80,12 @@ bool AbstractSingleDiskAdaptor::fileExists()
|
|||
return File(getFilePath()).exists();
|
||||
}
|
||||
|
||||
int64_t AbstractSingleDiskAdaptor::size() const
|
||||
uint64_t AbstractSingleDiskAdaptor::size() const
|
||||
{
|
||||
return diskWriter->size();
|
||||
}
|
||||
|
||||
void AbstractSingleDiskAdaptor::truncate(int64_t length)
|
||||
void AbstractSingleDiskAdaptor::truncate(uint64_t length)
|
||||
{
|
||||
diskWriter->truncate(length);
|
||||
}
|
||||
|
@ -123,12 +123,12 @@ DiskWriterHandle AbstractSingleDiskAdaptor::getDiskWriter() const
|
|||
return diskWriter;
|
||||
}
|
||||
|
||||
void AbstractSingleDiskAdaptor::setTotalLength(const int64_t& totalLength)
|
||||
void AbstractSingleDiskAdaptor::setTotalLength(const uint64_t& totalLength)
|
||||
{
|
||||
this->totalLength = totalLength;
|
||||
}
|
||||
|
||||
int64_t AbstractSingleDiskAdaptor::getTotalLength() const
|
||||
uint64_t AbstractSingleDiskAdaptor::getTotalLength() const
|
||||
{
|
||||
return totalLength;
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ class FileAllocationIterator;
|
|||
class AbstractSingleDiskAdaptor : public DiskAdaptor {
|
||||
protected:
|
||||
SharedHandle<DiskWriter> diskWriter;
|
||||
int64_t totalLength;
|
||||
uint64_t totalLength;
|
||||
public:
|
||||
AbstractSingleDiskAdaptor();
|
||||
|
||||
|
@ -59,16 +59,16 @@ public:
|
|||
|
||||
virtual void openExistingFile();
|
||||
|
||||
virtual void writeData(const unsigned char* data, int32_t len,
|
||||
int64_t offset);
|
||||
virtual void writeData(const unsigned char* data, size_t len,
|
||||
off_t offset);
|
||||
|
||||
virtual int32_t readData(unsigned char* data, int32_t len, int64_t offset);
|
||||
virtual ssize_t readData(unsigned char* data, size_t len, off_t offset);
|
||||
|
||||
virtual bool fileExists();
|
||||
|
||||
virtual int64_t size() const;
|
||||
virtual uint64_t size() const;
|
||||
|
||||
virtual void truncate(int64_t length);
|
||||
virtual void truncate(uint64_t length);
|
||||
|
||||
virtual SharedHandle<FileAllocationIterator> fileAllocationIterator();
|
||||
|
||||
|
@ -82,9 +82,9 @@ public:
|
|||
|
||||
SharedHandle<DiskWriter> getDiskWriter() const;
|
||||
|
||||
void setTotalLength(const int64_t& totalLength);
|
||||
void setTotalLength(const uint64_t& totalLength);
|
||||
|
||||
int64_t getTotalLength() const;
|
||||
uint64_t getTotalLength() const;
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -53,7 +53,7 @@ ActivePeerConnectionCommand::ActivePeerConnectionCommand(int cuid,
|
|||
RequestGroup* requestGroup,
|
||||
DownloadEngine* e,
|
||||
const BtContextHandle& btContext,
|
||||
int32_t interval)
|
||||
time_t interval)
|
||||
:Command(cuid),
|
||||
BtContextAwareCommand(btContext),
|
||||
RequestGroupAware(requestGroup),
|
||||
|
@ -62,7 +62,7 @@ ActivePeerConnectionCommand::ActivePeerConnectionCommand(int cuid,
|
|||
_thresholdSpeed(SLOW_SPEED_THRESHOLD),
|
||||
_numNewConnection(5)
|
||||
{
|
||||
int32_t maxDownloadSpeed = e->option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT);
|
||||
unsigned int maxDownloadSpeed = e->option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT);
|
||||
if(maxDownloadSpeed > 0) {
|
||||
_thresholdSpeed = std::min(maxDownloadSpeed, _thresholdSpeed);
|
||||
}
|
||||
|
|
|
@ -50,17 +50,17 @@ class ActivePeerConnectionCommand : public Command,
|
|||
public RequestGroupAware
|
||||
{
|
||||
private:
|
||||
int32_t interval; // UNIT: sec
|
||||
time_t interval; // UNIT: sec
|
||||
DownloadEngine* e;
|
||||
Time checkPoint;
|
||||
int32_t _thresholdSpeed; // UNIT: byte/sec
|
||||
int32_t _numNewConnection; // the number of the connection to establish.
|
||||
unsigned int _thresholdSpeed; // UNIT: byte/sec
|
||||
size_t _numNewConnection; // the number of the connection to establish.
|
||||
public:
|
||||
ActivePeerConnectionCommand(int cuid,
|
||||
RequestGroup* requestGroup,
|
||||
DownloadEngine* e,
|
||||
const SharedHandle<BtContext>& btContext,
|
||||
int32_t interval);
|
||||
time_t interval);
|
||||
|
||||
virtual ~ActivePeerConnectionCommand();
|
||||
|
||||
|
@ -68,12 +68,12 @@ public:
|
|||
|
||||
void connectToPeer(const SharedHandle<Peer>& peer);
|
||||
|
||||
void setThresholdSpeed(int32_t speed)
|
||||
void setThresholdSpeed(unsigned int speed)
|
||||
{
|
||||
_thresholdSpeed = speed;
|
||||
}
|
||||
|
||||
void setNumNewConnection(int32_t numNewConnection)
|
||||
void setNumNewConnection(size_t numNewConnection)
|
||||
{
|
||||
_numNewConnection = numNewConnection;
|
||||
}
|
||||
|
|
|
@ -44,37 +44,34 @@ class AlphaNumberDecorator : public NumberDecorator
|
|||
{
|
||||
private:
|
||||
|
||||
int32_t _width;
|
||||
size_t _width;
|
||||
|
||||
std::string _zero;
|
||||
|
||||
std::string widen(const std::string& s, int32_t width)
|
||||
std::string widen(const std::string& s, size_t width)
|
||||
{
|
||||
std::string t = s;
|
||||
while(t.size() < (size_t)width) {
|
||||
while(t.size() < width) {
|
||||
t.insert(0, _zero);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
public:
|
||||
AlphaNumberDecorator(int32_t width, bool uppercase = false):
|
||||
AlphaNumberDecorator(size_t width, bool uppercase = false):
|
||||
_width(width), _zero(uppercase?"A":"a") {}
|
||||
|
||||
virtual ~AlphaNumberDecorator() {}
|
||||
|
||||
virtual std::string decorate(int32_t number)
|
||||
virtual std::string decorate(unsigned int number)
|
||||
{
|
||||
if(number < 0) {
|
||||
throw new DlAbortEx("The number must be greater than 0.");
|
||||
}
|
||||
if(number == 0) {
|
||||
return widen(_zero, _width);
|
||||
}
|
||||
int32_t base = 26;
|
||||
int base = 26;
|
||||
std::string x;
|
||||
while(number > 0) {
|
||||
int32_t r = number%base;
|
||||
int r = number%base;
|
||||
char alpha = _zero[0]+r;
|
||||
x.insert(0, std::string(1, alpha));
|
||||
number /= base;
|
||||
|
|
|
@ -187,11 +187,11 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
int32_t AnnounceList::countStoppedAllowedTier() const {
|
||||
size_t AnnounceList::countStoppedAllowedTier() const {
|
||||
return count_if(tiers.begin(), tiers.end(), FindStoppedAllowedTier());
|
||||
}
|
||||
|
||||
int32_t AnnounceList::countCompletedAllowedTier() const {
|
||||
size_t AnnounceList::countCompletedAllowedTier() const {
|
||||
return count_if(tiers.begin(), tiers.end(), FindCompletedAllowedTier());
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ public:
|
|||
void reconfigure(const MetaEntry* announceListEntry);
|
||||
void reconfigure(const std::string& url);
|
||||
|
||||
int32_t countTier() const {
|
||||
size_t countTier() const {
|
||||
return tiers.size();
|
||||
}
|
||||
|
||||
|
@ -102,12 +102,12 @@ public:
|
|||
/**
|
||||
* Counts the number of tiers to which the "stopped" event can be sent.
|
||||
*/
|
||||
int32_t countStoppedAllowedTier() const;
|
||||
size_t countStoppedAllowedTier() const;
|
||||
|
||||
/**
|
||||
* Counts the number of tiers to which the "completed" event can be sent.
|
||||
*/
|
||||
int32_t countCompletedAllowedTier() const;
|
||||
size_t countCompletedAllowedTier() const;
|
||||
|
||||
/**
|
||||
* Moves current tier pointer to the tier to which the "stopped" event can
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
AutoSaveCommand::AutoSaveCommand(int32_t cuid, DownloadEngine* e, int32_t interval):
|
||||
AutoSaveCommand::AutoSaveCommand(int32_t cuid, DownloadEngine* e, time_t interval):
|
||||
TimeBasedCommand(cuid, e, interval) {}
|
||||
|
||||
AutoSaveCommand::~AutoSaveCommand() {}
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace aria2 {
|
|||
class AutoSaveCommand : public TimeBasedCommand
|
||||
{
|
||||
public:
|
||||
AutoSaveCommand(int32_t cuid, DownloadEngine* e, int32_t interval);
|
||||
AutoSaveCommand(int32_t cuid, DownloadEngine* e, time_t interval);
|
||||
|
||||
virtual ~AutoSaveCommand();
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ void BencodeVisitor::visit(const Dictionary* d)
|
|||
_bencodedData += "d";
|
||||
|
||||
for(std::deque<std::string>::const_iterator itr = d->getOrder().begin(); itr != d->getOrder().end(); ++itr) {
|
||||
_bencodedData += Util::itos((int32_t)(*itr).size());
|
||||
_bencodedData += Util::uitos((*itr).size());
|
||||
_bencodedData += ":";
|
||||
_bencodedData += *itr;
|
||||
d->get(*itr)->accept(this);
|
||||
|
|
|
@ -44,11 +44,11 @@ class BinaryStream {
|
|||
public:
|
||||
virtual ~BinaryStream() {}
|
||||
|
||||
virtual void writeData(const unsigned char* data, int32_t len, int64_t offset) = 0;
|
||||
virtual void writeData(const unsigned char* data, size_t len, off_t offset) = 0;
|
||||
|
||||
virtual int32_t readData(unsigned char* data, int32_t len, int64_t offset) = 0;
|
||||
virtual ssize_t readData(unsigned char* data, size_t len, off_t offset) = 0;
|
||||
|
||||
virtual void truncate(int64_t length) = 0;
|
||||
virtual void truncate(uint64_t length) = 0;
|
||||
|
||||
virtual void enableDirectIO() = 0;
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ BitfieldManFactory::BitfieldManFactory():randomizer(0) {}
|
|||
BitfieldManFactory::~BitfieldManFactory() {}
|
||||
|
||||
BitfieldMan*
|
||||
BitfieldManFactory::createBitfieldMan(int32_t blockLength, int64_t totalLength)
|
||||
BitfieldManFactory::createBitfieldMan(size_t blockLength, uint64_t totalLength)
|
||||
{
|
||||
BitfieldMan* bitfieldMan = new BitfieldMan(blockLength, totalLength);
|
||||
bitfieldMan->setRandomizer(randomizer);
|
||||
|
|
|
@ -55,7 +55,7 @@ public:
|
|||
|
||||
static SharedHandle<BitfieldManFactory> getFactoryInstance();
|
||||
|
||||
BitfieldMan* createBitfieldMan(int32_t blockLength, int64_t totalLength);
|
||||
BitfieldMan* createBitfieldMan(size_t blockLength, uint64_t totalLength);
|
||||
|
||||
static void setDefaultRandomizer(const SharedHandle<Randomizer>& randomizer);
|
||||
|
||||
|
|
|
@ -41,11 +41,11 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
BtAllowedFastMessageHandle BtAllowedFastMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||
BtAllowedFastMessageHandle BtAllowedFastMessage::create(const unsigned char* data, size_t dataLength) {
|
||||
if(dataLength != 5) {
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "allowed fast", dataLength, 5);
|
||||
}
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "allowed fast", ID);
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ void BtAllowedFastMessage::doReceivedAction() {
|
|||
peer->addPeerAllowedIndex(index);
|
||||
}
|
||||
|
||||
int32_t BtAllowedFastMessage::MESSAGE_LENGTH = 9;
|
||||
size_t BtAllowedFastMessage::MESSAGE_LENGTH = 9;
|
||||
|
||||
const unsigned char* BtAllowedFastMessage::getMessage() {
|
||||
if(!msg) {
|
||||
|
@ -79,7 +79,7 @@ const unsigned char* BtAllowedFastMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
int32_t BtAllowedFastMessage::getMessageLength() {
|
||||
size_t BtAllowedFastMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,12 +45,12 @@ typedef SharedHandle<BtAllowedFastMessage> BtAllowedFastMessageHandle;
|
|||
|
||||
class BtAllowedFastMessage : public SimpleBtMessage {
|
||||
private:
|
||||
int32_t index;
|
||||
size_t index;
|
||||
unsigned char* msg;
|
||||
|
||||
static int32_t MESSAGE_LENGTH;
|
||||
static size_t MESSAGE_LENGTH;
|
||||
public:
|
||||
BtAllowedFastMessage(int32_t index = 0)
|
||||
BtAllowedFastMessage(size_t index = 0)
|
||||
:SimpleBtMessage(),
|
||||
index(index),
|
||||
msg(0) {}
|
||||
|
@ -59,22 +59,22 @@ public:
|
|||
delete [] msg;
|
||||
}
|
||||
|
||||
static const int8_t ID = 17;
|
||||
static const uint8_t ID = 17;
|
||||
|
||||
void setIndex(int32_t index) {
|
||||
void setIndex(size_t index) {
|
||||
this->index = index;
|
||||
}
|
||||
int32_t getIndex() const { return index; }
|
||||
size_t getIndex() const { return index; }
|
||||
|
||||
static BtAllowedFastMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
static BtAllowedFastMessageHandle create(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual int8_t getId() { return ID; }
|
||||
virtual uint8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual int32_t getMessageLength();
|
||||
virtual size_t getMessageLength();
|
||||
|
||||
virtual std::string toString() const;
|
||||
|
||||
|
|
|
@ -44,10 +44,10 @@ namespace aria2 {
|
|||
class BtAllowedFastMessageValidator : public BtMessageValidator {
|
||||
private:
|
||||
const BtAllowedFastMessage* message;
|
||||
int32_t numPiece;
|
||||
size_t numPiece;
|
||||
public:
|
||||
BtAllowedFastMessageValidator(const BtAllowedFastMessage* message,
|
||||
int32_t numPiece):
|
||||
size_t numPiece):
|
||||
message(message),
|
||||
numPiece(numPiece) {}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
void BtBitfieldMessage::setBitfield(const unsigned char* bitfield, int32_t bitfieldLength) {
|
||||
void BtBitfieldMessage::setBitfield(const unsigned char* bitfield, size_t bitfieldLength) {
|
||||
if(this->bitfield == bitfield) {
|
||||
return;
|
||||
}
|
||||
|
@ -54,12 +54,12 @@ void BtBitfieldMessage::setBitfield(const unsigned char* bitfield, int32_t bitfi
|
|||
}
|
||||
|
||||
BtBitfieldMessageHandle
|
||||
BtBitfieldMessage::create(const unsigned char* data, int32_t dataLength)
|
||||
BtBitfieldMessage::create(const unsigned char* data, size_t dataLength)
|
||||
{
|
||||
if(dataLength <= 1) {
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "bitfield", dataLength, 1);
|
||||
}
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "bitfield", ID);
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ const unsigned char* BtBitfieldMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
int32_t BtBitfieldMessage::getMessageLength() {
|
||||
size_t BtBitfieldMessage::getMessageLength() {
|
||||
getMessage();
|
||||
return msgLength;
|
||||
}
|
||||
|
|
|
@ -46,9 +46,9 @@ typedef SharedHandle<BtBitfieldMessage> BtBitfieldMessageHandle;
|
|||
class BtBitfieldMessage : public SimpleBtMessage {
|
||||
private:
|
||||
unsigned char* bitfield;
|
||||
int32_t bitfieldLength;
|
||||
size_t bitfieldLength;
|
||||
unsigned char* msg;
|
||||
int32_t msgLength;
|
||||
size_t msgLength;
|
||||
|
||||
void init() {
|
||||
bitfield = 0;
|
||||
|
@ -63,7 +63,7 @@ public:
|
|||
}
|
||||
|
||||
BtBitfieldMessage(const unsigned char* bitfield,
|
||||
int32_t bitfieldLength):SimpleBtMessage()
|
||||
size_t bitfieldLength):SimpleBtMessage()
|
||||
{
|
||||
init();
|
||||
setBitfield(bitfield, bitfieldLength);
|
||||
|
@ -74,23 +74,23 @@ public:
|
|||
delete [] msg;
|
||||
}
|
||||
|
||||
static const int8_t ID = 5;
|
||||
static const uint8_t ID = 5;
|
||||
|
||||
void setBitfield(const unsigned char* bitfield, int32_t bitfieldLength);
|
||||
void setBitfield(const unsigned char* bitfield, size_t bitfieldLength);
|
||||
|
||||
const unsigned char* getBitfield() const { return bitfield; }
|
||||
|
||||
int32_t getBitfieldLength() const { return bitfieldLength; }
|
||||
size_t getBitfieldLength() const { return bitfieldLength; }
|
||||
|
||||
static BtBitfieldMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
static BtBitfieldMessageHandle create(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual int8_t getId() { return ID; }
|
||||
virtual uint8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual int32_t getMessageLength();
|
||||
virtual size_t getMessageLength();
|
||||
|
||||
virtual std::string toString() const;
|
||||
};
|
||||
|
|
|
@ -43,10 +43,10 @@ namespace aria2 {
|
|||
class BtBitfieldMessageValidator : public BtMessageValidator {
|
||||
private:
|
||||
const BtBitfieldMessage* message;
|
||||
int32_t numPiece;
|
||||
size_t numPiece;
|
||||
public:
|
||||
BtBitfieldMessageValidator(const BtBitfieldMessage* message,
|
||||
int32_t numPiece):
|
||||
size_t numPiece):
|
||||
message(message),
|
||||
numPiece(numPiece) {}
|
||||
|
||||
|
|
|
@ -41,11 +41,11 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
BtCancelMessageHandle BtCancelMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||
BtCancelMessageHandle BtCancelMessage::create(const unsigned char* data, size_t dataLength) {
|
||||
if(dataLength != 13) {
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "cancel", dataLength, 13);
|
||||
}
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "cancel", ID);
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ void BtCancelMessage::doReceivedAction() {
|
|||
dispatcher->doCancelSendingPieceAction(index, begin, length);
|
||||
}
|
||||
|
||||
int32_t BtCancelMessage::MESSAGE_LENGTH = 17;
|
||||
size_t BtCancelMessage::MESSAGE_LENGTH = 17;
|
||||
|
||||
const unsigned char* BtCancelMessage::getMessage() {
|
||||
if(!msg) {
|
||||
|
@ -81,13 +81,13 @@ const unsigned char* BtCancelMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
int32_t BtCancelMessage::getMessageLength() {
|
||||
size_t BtCancelMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
std::string BtCancelMessage::toString() const {
|
||||
return "cancel index="+Util::itos(index)+", begin="+Util::itos(begin)+
|
||||
", length="+Util::itos(length);
|
||||
return "cancel index="+Util::uitos(index)+", begin="+Util::uitos(begin)+
|
||||
", length="+Util::uitos(length);
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -45,14 +45,14 @@ typedef SharedHandle<BtCancelMessage> BtCancelMessageHandle;
|
|||
|
||||
class BtCancelMessage : public SimpleBtMessage {
|
||||
private:
|
||||
int32_t index;
|
||||
int32_t begin;
|
||||
int32_t length;
|
||||
size_t index;
|
||||
uint32_t begin;
|
||||
size_t length;
|
||||
unsigned char* msg;
|
||||
|
||||
static int32_t MESSAGE_LENGTH;
|
||||
static size_t MESSAGE_LENGTH;
|
||||
public:
|
||||
BtCancelMessage(int32_t index = 0, int32_t begin = 0, int32_t length = 0)
|
||||
BtCancelMessage(size_t index = 0, uint32_t begin = 0, size_t length = 0)
|
||||
:SimpleBtMessage(),
|
||||
index(index),
|
||||
begin(begin),
|
||||
|
@ -65,27 +65,27 @@ public:
|
|||
|
||||
static const int8_t ID = 8;
|
||||
|
||||
int32_t getIndex() const { return index; }
|
||||
size_t getIndex() const { return index; }
|
||||
|
||||
void setIndex(int32_t index) { this->index = index; }
|
||||
void setIndex(size_t index) { this->index = index; }
|
||||
|
||||
int32_t getBegin() const { return begin; }
|
||||
uint32_t getBegin() const { return begin; }
|
||||
|
||||
void setBegin(int32_t begin) { this->begin = begin; }
|
||||
void setBegin(uint32_t begin) { this->begin = begin; }
|
||||
|
||||
int32_t getLength() const { return length; }
|
||||
size_t getLength() const { return length; }
|
||||
|
||||
void setLength(int32_t length) { this->length = length; }
|
||||
void setLength(size_t length) { this->length = length; }
|
||||
|
||||
static BtCancelMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
static BtCancelMessageHandle create(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual int8_t getId() { return ID; }
|
||||
virtual uint8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual int32_t getMessageLength();
|
||||
virtual size_t getMessageLength();
|
||||
|
||||
virtual std::string toString() const;
|
||||
};
|
||||
|
|
|
@ -44,12 +44,12 @@ namespace aria2 {
|
|||
class BtCancelMessageValidator : public BtMessageValidator {
|
||||
private:
|
||||
const BtCancelMessage* message;
|
||||
int32_t numPiece;
|
||||
int32_t pieceLength;
|
||||
size_t numPiece;
|
||||
size_t pieceLength;
|
||||
public:
|
||||
BtCancelMessageValidator(const BtCancelMessage* message,
|
||||
int32_t numPiece,
|
||||
int32_t pieceLength):
|
||||
size_t numPiece,
|
||||
size_t pieceLength):
|
||||
message(message),
|
||||
numPiece(numPiece),
|
||||
pieceLength(pieceLength) {}
|
||||
|
|
|
@ -41,36 +41,36 @@ namespace aria2 {
|
|||
|
||||
class BtCancelSendingPieceEvent : public BtEvent {
|
||||
private:
|
||||
int32_t index;
|
||||
int32_t begin;
|
||||
int32_t length;
|
||||
size_t index;
|
||||
uint32_t begin;
|
||||
size_t length;
|
||||
public:
|
||||
BtCancelSendingPieceEvent(int32_t index, int32_t begin, int32_t length):
|
||||
BtCancelSendingPieceEvent(size_t index, uint32_t begin, size_t length):
|
||||
index(index), begin(begin), length(length) {}
|
||||
|
||||
virtual ~BtCancelSendingPieceEvent() {}
|
||||
|
||||
void setIndex(int32_t index) {
|
||||
void setIndex(size_t index) {
|
||||
this->index = index;
|
||||
}
|
||||
|
||||
int32_t getIndex() const {
|
||||
size_t getIndex() const {
|
||||
return index;
|
||||
}
|
||||
|
||||
void setBegin(int32_t begin) {
|
||||
void setBegin(uint32_t begin) {
|
||||
this->begin = begin;
|
||||
}
|
||||
|
||||
int32_t getBegin() const {
|
||||
uint32_t getBegin() const {
|
||||
return begin;
|
||||
}
|
||||
|
||||
void setLength(int32_t length) {
|
||||
void setLength(size_t length) {
|
||||
this->length = length;
|
||||
}
|
||||
|
||||
int32_t getLength() const {
|
||||
size_t getLength() const {
|
||||
return length;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -42,11 +42,11 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
BtChokeMessageHandle BtChokeMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||
BtChokeMessageHandle BtChokeMessage::create(const unsigned char* data, size_t dataLength) {
|
||||
if(dataLength != 1) {
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "choke", dataLength, 1);
|
||||
}
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "choke", ID);
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ bool BtChokeMessage::sendPredicate() const {
|
|||
return !peer->amChoking();
|
||||
}
|
||||
|
||||
int32_t BtChokeMessage::MESSAGE_LENGTH = 5;
|
||||
size_t BtChokeMessage::MESSAGE_LENGTH = 5;
|
||||
|
||||
const unsigned char* BtChokeMessage::getMessage() {
|
||||
if(!msg) {
|
||||
|
@ -79,7 +79,7 @@ const unsigned char* BtChokeMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
int32_t BtChokeMessage::getMessageLength() {
|
||||
size_t BtChokeMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ class BtChokeMessage : public SimpleBtMessage {
|
|||
private:
|
||||
unsigned char* msg;
|
||||
|
||||
static int32_t MESSAGE_LENGTH;
|
||||
static size_t MESSAGE_LENGTH;
|
||||
public:
|
||||
BtChokeMessage():SimpleBtMessage(), msg(0) {}
|
||||
|
||||
|
@ -55,19 +55,19 @@ public:
|
|||
delete [] msg;
|
||||
}
|
||||
|
||||
static const int8_t ID = 0;
|
||||
static const uint8_t ID = 0;
|
||||
|
||||
virtual int8_t getId() { return ID; }
|
||||
virtual uint8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual int32_t getMessageLength();
|
||||
virtual size_t getMessageLength();
|
||||
|
||||
virtual std::string toString() const;
|
||||
|
||||
static BtChokeMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
static BtChokeMessageHandle create(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual bool sendPredicate() const;
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ const unsigned char* BtExtendedMessage::getMessage() {
|
|||
return _msg;
|
||||
}
|
||||
|
||||
int32_t BtExtendedMessage::getMessageLength() {
|
||||
size_t BtExtendedMessage::getMessageLength() {
|
||||
getMessage();
|
||||
return _msgLength;
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ BtExtendedMessage::create(const BtContextHandle& btContext,
|
|||
if(dataLength < 2) {
|
||||
throw new DlAbortEx(MSG_TOO_SMALL_PAYLOAD_SIZE, "extended", dataLength);
|
||||
}
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "extended", ID);
|
||||
}
|
||||
|
|
|
@ -63,13 +63,13 @@ public:
|
|||
const unsigned char* data,
|
||||
size_t dataLength);
|
||||
|
||||
virtual int8_t getId() { return ID; }
|
||||
virtual uint8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual int32_t getMessageLength();
|
||||
virtual size_t getMessageLength();
|
||||
|
||||
virtual bool sendPredicate() const;
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ void BtHandshakeMessage::init() {
|
|||
}
|
||||
|
||||
SharedHandle<BtHandshakeMessage>
|
||||
BtHandshakeMessage::create(const unsigned char* data, int32_t dataLength)
|
||||
BtHandshakeMessage::create(const unsigned char* data, size_t dataLength)
|
||||
{
|
||||
SharedHandle<BtHandshakeMessage> message = new BtHandshakeMessage();
|
||||
message->pstrlen = data[0];
|
||||
|
@ -93,7 +93,7 @@ const unsigned char* BtHandshakeMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
int32_t BtHandshakeMessage::getMessageLength() {
|
||||
size_t BtHandshakeMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,12 +41,12 @@ namespace aria2 {
|
|||
|
||||
class BtHandshakeMessage : public SimpleBtMessage {
|
||||
public:
|
||||
static const int32_t PSTR_LENGTH = 19;
|
||||
static const size_t PSTR_LENGTH = 19;
|
||||
static const unsigned char* BT_PSTR;
|
||||
static const int32_t RESERVED_LENGTH = 8;
|
||||
static const int32_t MESSAGE_LENGTH = 68;
|
||||
static const size_t RESERVED_LENGTH = 8;
|
||||
static const size_t MESSAGE_LENGTH = 68;
|
||||
private:
|
||||
int8_t pstrlen;
|
||||
uint8_t pstrlen;
|
||||
unsigned char* pstr;
|
||||
unsigned char* reserved;
|
||||
unsigned char* infoHash;
|
||||
|
@ -62,7 +62,7 @@ public:
|
|||
BtHandshakeMessage(const unsigned char* infoHash, const unsigned char* peerId);
|
||||
|
||||
static SharedHandle<BtHandshakeMessage>
|
||||
create(const unsigned char* data, int32_t dataLength);
|
||||
create(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual ~BtHandshakeMessage() {
|
||||
delete [] msg;
|
||||
|
@ -72,15 +72,15 @@ public:
|
|||
delete [] peerId;
|
||||
}
|
||||
|
||||
static const int8_t ID = INT8_MAX;
|
||||
static const uint8_t ID = INT8_MAX;
|
||||
|
||||
virtual int8_t getId() { return ID; }
|
||||
virtual uint8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction() {};
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual int32_t getMessageLength();
|
||||
virtual size_t getMessageLength();
|
||||
|
||||
virtual std::string toString() const;
|
||||
|
||||
|
@ -99,7 +99,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
int8_t getPstrlen() const {
|
||||
uint8_t getPstrlen() const {
|
||||
return pstrlen;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,11 +40,11 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
BtHaveAllMessageHandle BtHaveAllMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||
BtHaveAllMessageHandle BtHaveAllMessage::create(const unsigned char* data, size_t dataLength) {
|
||||
if(dataLength != 1) {
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "have all", dataLength, 1);
|
||||
}
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "have all", ID);
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ void BtHaveAllMessage::doReceivedAction() {
|
|||
peer->setAllBitfield();
|
||||
}
|
||||
|
||||
int32_t BtHaveAllMessage::MESSAGE_LENGTH = 5;
|
||||
size_t BtHaveAllMessage::MESSAGE_LENGTH = 5;
|
||||
|
||||
const unsigned char* BtHaveAllMessage::getMessage() {
|
||||
if(!msg) {
|
||||
|
@ -75,7 +75,7 @@ const unsigned char* BtHaveAllMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
int32_t BtHaveAllMessage::getMessageLength() {
|
||||
size_t BtHaveAllMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ class BtHaveAllMessage : public SimpleBtMessage {
|
|||
private:
|
||||
unsigned char* msg;
|
||||
|
||||
static int32_t MESSAGE_LENGTH;
|
||||
static size_t MESSAGE_LENGTH;
|
||||
public:
|
||||
BtHaveAllMessage():msg(0) {}
|
||||
|
||||
|
@ -55,17 +55,17 @@ public:
|
|||
delete [] msg;
|
||||
}
|
||||
|
||||
static const int8_t ID = 14;
|
||||
static const uint8_t ID = 14;
|
||||
|
||||
static BtHaveAllMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
static BtHaveAllMessageHandle create(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual int8_t getId() { return ID; }
|
||||
virtual uint8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual int32_t getMessageLength();
|
||||
virtual size_t getMessageLength();
|
||||
|
||||
virtual std::string toString() const;
|
||||
};
|
||||
|
|
|
@ -41,11 +41,11 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
BtHaveMessageHandle BtHaveMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||
BtHaveMessageHandle BtHaveMessage::create(const unsigned char* data, size_t dataLength) {
|
||||
if(dataLength != 5) {
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "have", dataLength, 5);
|
||||
}
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "have", ID);
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ void BtHaveMessage::doReceivedAction() {
|
|||
peer->updateBitfield(index, 1);
|
||||
}
|
||||
|
||||
int32_t BtHaveMessage::MESSAGE_LENGTH = 9;
|
||||
size_t BtHaveMessage::MESSAGE_LENGTH = 9;
|
||||
|
||||
const unsigned char* BtHaveMessage::getMessage() {
|
||||
if(!msg) {
|
||||
|
@ -75,7 +75,7 @@ const unsigned char* BtHaveMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
int32_t BtHaveMessage::getMessageLength() {
|
||||
size_t BtHaveMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,33 +45,33 @@ typedef SharedHandle<BtHaveMessage> BtHaveMessageHandle;
|
|||
|
||||
class BtHaveMessage : public SimpleBtMessage {
|
||||
private:
|
||||
int32_t index;
|
||||
size_t index;
|
||||
unsigned char* msg;
|
||||
static int32_t MESSAGE_LENGTH;
|
||||
static size_t MESSAGE_LENGTH;
|
||||
public:
|
||||
BtHaveMessage(int32_t index = 0):index(index), msg(0) {}
|
||||
BtHaveMessage(size_t index = 0):index(index), msg(0) {}
|
||||
|
||||
virtual ~BtHaveMessage() {
|
||||
delete [] msg;
|
||||
}
|
||||
|
||||
static const int8_t ID = 4;
|
||||
static const uint8_t ID = 4;
|
||||
|
||||
void setIndex(int32_t index) {
|
||||
void setIndex(size_t index) {
|
||||
this->index = index;
|
||||
}
|
||||
|
||||
int32_t getIndex() const { return index; }
|
||||
size_t getIndex() const { return index; }
|
||||
|
||||
static BtHaveMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
static BtHaveMessageHandle create(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual int8_t getId() { return ID; }
|
||||
virtual uint8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual int32_t getMessageLength();
|
||||
virtual size_t getMessageLength();
|
||||
|
||||
virtual std::string toString() const;
|
||||
};
|
||||
|
|
|
@ -44,10 +44,10 @@ namespace aria2 {
|
|||
class BtHaveMessageValidator : public BtMessageValidator {
|
||||
private:
|
||||
const BtHaveMessage* message;
|
||||
int32_t numPiece;
|
||||
size_t numPiece;
|
||||
public:
|
||||
BtHaveMessageValidator(const BtHaveMessage* message,
|
||||
int32_t numPiece):
|
||||
size_t numPiece):
|
||||
message(message),
|
||||
numPiece(numPiece) {}
|
||||
|
||||
|
|
|
@ -40,11 +40,11 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
BtHaveNoneMessageHandle BtHaveNoneMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||
BtHaveNoneMessageHandle BtHaveNoneMessage::create(const unsigned char* data, size_t dataLength) {
|
||||
if(dataLength != 1) {
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "have none", dataLength, 1);
|
||||
}
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "have none", ID);
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ void BtHaveNoneMessage::doReceivedAction() {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t BtHaveNoneMessage::MESSAGE_LENGTH = 5;
|
||||
size_t BtHaveNoneMessage::MESSAGE_LENGTH = 5;
|
||||
|
||||
const unsigned char* BtHaveNoneMessage::getMessage() {
|
||||
if(!msg) {
|
||||
|
@ -74,7 +74,7 @@ const unsigned char* BtHaveNoneMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
int32_t BtHaveNoneMessage::getMessageLength() {
|
||||
size_t BtHaveNoneMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ class BtHaveNoneMessage : public SimpleBtMessage {
|
|||
private:
|
||||
unsigned char* msg;
|
||||
|
||||
static int32_t MESSAGE_LENGTH;
|
||||
static size_t MESSAGE_LENGTH;
|
||||
public:
|
||||
BtHaveNoneMessage():msg(0) {}
|
||||
|
||||
|
@ -55,17 +55,17 @@ public:
|
|||
delete [] msg;
|
||||
}
|
||||
|
||||
static const int8_t ID = 15;
|
||||
static const uint8_t ID = 15;
|
||||
|
||||
static BtHaveNoneMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
static BtHaveNoneMessageHandle create(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual int8_t getId() { return ID; }
|
||||
virtual uint8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual int32_t getMessageLength();
|
||||
virtual size_t getMessageLength();
|
||||
|
||||
virtual std::string toString() const;
|
||||
};
|
||||
|
|
|
@ -60,7 +60,7 @@ public:
|
|||
|
||||
virtual void sendPendingMessage() = 0;
|
||||
|
||||
virtual int32_t countPendingMessage() = 0;
|
||||
virtual size_t countPendingMessage() = 0;
|
||||
|
||||
virtual bool isSendingMessageInProgress() = 0;
|
||||
|
||||
|
|
|
@ -40,11 +40,11 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
BtInterestedMessageHandle BtInterestedMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||
BtInterestedMessageHandle BtInterestedMessage::create(const unsigned char* data, size_t dataLength) {
|
||||
if(dataLength != 1) {
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "interested", dataLength, 1);
|
||||
}
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "interested", ID);
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ bool BtInterestedMessage::sendPredicate() const {
|
|||
return !peer->amInterested();
|
||||
}
|
||||
|
||||
int32_t BtInterestedMessage::MESSAGE_LENGTH = 5;
|
||||
size_t BtInterestedMessage::MESSAGE_LENGTH = 5;
|
||||
|
||||
const unsigned char* BtInterestedMessage::getMessage() {
|
||||
if(!msg) {
|
||||
|
@ -75,7 +75,7 @@ const unsigned char* BtInterestedMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
int32_t BtInterestedMessage::getMessageLength() {
|
||||
size_t BtInterestedMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ class BtInterestedMessage : public SimpleBtMessage {
|
|||
private:
|
||||
unsigned char* msg;
|
||||
|
||||
static int32_t MESSAGE_LENGTH;
|
||||
static size_t MESSAGE_LENGTH;
|
||||
public:
|
||||
BtInterestedMessage():msg(0) {}
|
||||
|
||||
|
@ -55,17 +55,17 @@ public:
|
|||
delete [] msg;
|
||||
}
|
||||
|
||||
static const int8_t ID = 2;
|
||||
static const uint8_t ID = 2;
|
||||
|
||||
static BtInterestedMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
static BtInterestedMessageHandle create(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual int8_t getId() { return ID; }
|
||||
virtual uint8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual int32_t getMessageLength();
|
||||
virtual size_t getMessageLength();
|
||||
|
||||
virtual std::string toString() const;
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
int32_t BtKeepAliveMessage::MESSAGE_LENGTH = 4;
|
||||
size_t BtKeepAliveMessage::MESSAGE_LENGTH = 4;
|
||||
|
||||
const unsigned char* BtKeepAliveMessage::getMessage() {
|
||||
if(!msg) {
|
||||
|
@ -50,7 +50,7 @@ const unsigned char* BtKeepAliveMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
int32_t BtKeepAliveMessage::getMessageLength() {
|
||||
size_t BtKeepAliveMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ class BtKeepAliveMessage : public SimpleBtMessage {
|
|||
private:
|
||||
unsigned char* msg;
|
||||
|
||||
static int32_t MESSAGE_LENGTH;
|
||||
static size_t MESSAGE_LENGTH;
|
||||
public:
|
||||
BtKeepAliveMessage():msg(0) {}
|
||||
|
||||
|
@ -55,15 +55,15 @@ public:
|
|||
delete [] msg;
|
||||
}
|
||||
|
||||
static const int8_t ID = 99;
|
||||
static const uint8_t ID = 99;
|
||||
|
||||
virtual int8_t getId() { return ID; }
|
||||
virtual uint8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction() {}
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual int32_t getMessageLength();
|
||||
virtual size_t getMessageLength();
|
||||
|
||||
virtual std::string toString() const {
|
||||
return "keep alive";
|
||||
|
|
|
@ -54,7 +54,7 @@ public:
|
|||
|
||||
virtual bool isUploading() = 0;
|
||||
|
||||
virtual int8_t getId() = 0;
|
||||
virtual uint8_t getId() = 0;
|
||||
|
||||
virtual void doReceivedAction() = 0;
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ public:
|
|||
|
||||
virtual void sendMessages() = 0;
|
||||
|
||||
virtual void doCancelSendingPieceAction(int32_t index, int32_t begin, int32_t length) = 0;
|
||||
virtual void doCancelSendingPieceAction(size_t index, uint32_t begin, size_t length) = 0;
|
||||
|
||||
virtual void doCancelSendingPieceAction(const SharedHandle<Piece>& piece) = 0;
|
||||
|
||||
|
@ -70,13 +70,13 @@ public:
|
|||
|
||||
virtual bool isSendingInProgress() = 0;
|
||||
|
||||
virtual int32_t countMessageInQueue() = 0;
|
||||
virtual size_t countMessageInQueue() = 0;
|
||||
|
||||
virtual int32_t countOutstandingRequest() = 0;
|
||||
virtual size_t countOutstandingRequest() = 0;
|
||||
|
||||
virtual bool isOutstandingRequest(int32_t index, int32_t blockIndex) = 0;
|
||||
virtual bool isOutstandingRequest(size_t index, size_t blockIndex) = 0;
|
||||
|
||||
virtual RequestSlot getOutstandingRequest(int32_t index, int32_t begin, int32_t length) = 0;
|
||||
virtual RequestSlot getOutstandingRequest(size_t index, uint32_t begin, size_t length) = 0;
|
||||
|
||||
virtual void removeOutstandingRequest(const RequestSlot& slot) = 0;
|
||||
|
||||
|
|
|
@ -49,25 +49,25 @@ public:
|
|||
virtual ~BtMessageFactory() {}
|
||||
|
||||
virtual SharedHandle<BtMessage>
|
||||
createBtMessage(const unsigned char* msg, int32_t msgLength) = 0;
|
||||
createBtMessage(const unsigned char* msg, size_t msgLength) = 0;
|
||||
|
||||
virtual SharedHandle<BtMessage>
|
||||
createHandshakeMessage(const unsigned char* msg, int32_t msgLength) = 0;
|
||||
createHandshakeMessage(const unsigned char* msg, size_t msgLength) = 0;
|
||||
|
||||
virtual SharedHandle<BtMessage>
|
||||
createHandshakeMessage(const unsigned char* infoHash,
|
||||
const unsigned char* peerId) = 0;
|
||||
|
||||
virtual SharedHandle<BtMessage>
|
||||
createRequestMessage(const SharedHandle<Piece>& piece, int32_t blockIndex) = 0;
|
||||
createRequestMessage(const SharedHandle<Piece>& piece, size_t blockIndex) = 0;
|
||||
|
||||
virtual SharedHandle<BtMessage>
|
||||
createCancelMessage(int32_t index, int32_t begin, int32_t length) = 0;
|
||||
createCancelMessage(size_t index, uint32_t begin, size_t length) = 0;
|
||||
|
||||
virtual SharedHandle<BtMessage>
|
||||
createPieceMessage(int32_t index, int32_t begin, int32_t length) = 0;
|
||||
createPieceMessage(size_t index, uint32_t begin, size_t length) = 0;
|
||||
|
||||
virtual SharedHandle<BtMessage> createHaveMessage(int32_t index) = 0;
|
||||
virtual SharedHandle<BtMessage> createHaveMessage(size_t index) = 0;
|
||||
|
||||
virtual SharedHandle<BtMessage> createChokeMessage() = 0;
|
||||
|
||||
|
@ -86,9 +86,9 @@ public:
|
|||
virtual SharedHandle<BtMessage> createHaveNoneMessage() = 0;
|
||||
|
||||
virtual SharedHandle<BtMessage>
|
||||
createRejectMessage(int32_t index, int32_t begin, int32_t length) = 0;
|
||||
createRejectMessage(size_t index, uint32_t begin, size_t length) = 0;
|
||||
|
||||
virtual SharedHandle<BtMessage> createAllowedFastMessage(int32_t index) = 0;
|
||||
virtual SharedHandle<BtMessage> createAllowedFastMessage(size_t index) = 0;
|
||||
|
||||
virtual SharedHandle<BtMessage> createPortMessage(uint16_t port) = 0;
|
||||
|
||||
|
|
|
@ -40,11 +40,11 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
BtNotInterestedMessageHandle BtNotInterestedMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||
BtNotInterestedMessageHandle BtNotInterestedMessage::create(const unsigned char* data, size_t dataLength) {
|
||||
if(dataLength != 1) {
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "not interested", dataLength, 1);
|
||||
}
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "not interested", ID);
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ bool BtNotInterestedMessage::sendPredicate() const {
|
|||
return peer->amInterested();
|
||||
}
|
||||
|
||||
int32_t BtNotInterestedMessage::MESSAGE_LENGTH = 5;
|
||||
size_t BtNotInterestedMessage::MESSAGE_LENGTH = 5;
|
||||
|
||||
const unsigned char* BtNotInterestedMessage::getMessage() {
|
||||
if(!msg) {
|
||||
|
@ -75,7 +75,7 @@ const unsigned char* BtNotInterestedMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
int32_t BtNotInterestedMessage::getMessageLength() {
|
||||
size_t BtNotInterestedMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ class BtNotInterestedMessage : public SimpleBtMessage {
|
|||
private:
|
||||
unsigned char* msg;
|
||||
|
||||
static int32_t MESSAGE_LENGTH;
|
||||
static size_t MESSAGE_LENGTH;
|
||||
public:
|
||||
BtNotInterestedMessage():msg(0) {}
|
||||
|
||||
|
@ -55,17 +55,17 @@ public:
|
|||
delete [] msg;
|
||||
}
|
||||
|
||||
static const int8_t ID = 3;
|
||||
static const uint8_t ID = 3;
|
||||
|
||||
static BtNotInterestedMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
static BtNotInterestedMessageHandle create(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual int8_t getId() { return ID; }
|
||||
virtual uint8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual int32_t getMessageLength();
|
||||
virtual size_t getMessageLength();
|
||||
|
||||
virtual std::string toString() const;
|
||||
|
||||
|
|
|
@ -54,18 +54,18 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
void BtPieceMessage::setBlock(const unsigned char* block, int32_t blockLength) {
|
||||
void BtPieceMessage::setBlock(const unsigned char* block, size_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, int32_t dataLength) {
|
||||
BtPieceMessageHandle BtPieceMessage::create(const unsigned char* data, size_t dataLength) {
|
||||
if(dataLength <= 9) {
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "piece", dataLength, 9);
|
||||
}
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "piece", ID);
|
||||
}
|
||||
|
@ -85,16 +85,12 @@ void BtPieceMessage::doReceivedAction() {
|
|||
peer->snubbing(false);
|
||||
peer->updateLatency(slot.getLatencyInMillis());
|
||||
PieceHandle piece = pieceStorage->getPiece(index);
|
||||
int64_t offset =
|
||||
((int64_t)index)*btContext->getPieceLength()+begin;
|
||||
off_t offset = (off_t)index*btContext->getPieceLength()+begin;
|
||||
logger->debug(MSG_PIECE_RECEIVED,
|
||||
cuid, index, begin, blockLength, offset, slot.getBlockIndex());
|
||||
pieceStorage->getDiskAdaptor()->writeData(block,
|
||||
blockLength,
|
||||
offset);
|
||||
pieceStorage->getDiskAdaptor()->writeData(block, blockLength, offset);
|
||||
piece->completeBlock(slot.getBlockIndex());
|
||||
logger->debug(MSG_PIECE_BITFIELD,
|
||||
cuid,
|
||||
logger->debug(MSG_PIECE_BITFIELD, cuid,
|
||||
Util::toHex(piece->getBitfield(),
|
||||
piece->getBitfieldLength()).c_str());
|
||||
dispatcher->removeOutstandingRequest(slot);
|
||||
|
@ -108,7 +104,7 @@ void BtPieceMessage::doReceivedAction() {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t BtPieceMessage::MESSAGE_HEADER_LENGTH = 13;
|
||||
size_t BtPieceMessage::MESSAGE_HEADER_LENGTH = 13;
|
||||
|
||||
const unsigned char* BtPieceMessage::getMessageHeader() {
|
||||
if(!msgHeader) {
|
||||
|
@ -128,7 +124,7 @@ const unsigned char* BtPieceMessage::getMessageHeader() {
|
|||
return msgHeader;
|
||||
}
|
||||
|
||||
int32_t BtPieceMessage::getMessageHeaderLength() {
|
||||
size_t BtPieceMessage::getMessageHeaderLength() {
|
||||
return MESSAGE_HEADER_LENGTH;
|
||||
}
|
||||
|
||||
|
@ -145,7 +141,7 @@ void BtPieceMessage::send() {
|
|||
leftDataLength = getMessageHeaderLength();
|
||||
sendingInProgress = true;
|
||||
}
|
||||
int32_t writtenLength
|
||||
size_t writtenLength
|
||||
= peerConnection->sendMessage(msgHeader+getMessageHeaderLength()-leftDataLength,
|
||||
leftDataLength);
|
||||
if(writtenLength == leftDataLength) {
|
||||
|
@ -157,10 +153,9 @@ void BtPieceMessage::send() {
|
|||
}
|
||||
if(headerSent) {
|
||||
sendingInProgress = false;
|
||||
int64_t pieceDataOffset =
|
||||
((int64_t)index)*btContext->getPieceLength()+begin+blockLength-leftDataLength;
|
||||
int32_t writtenLength =
|
||||
sendPieceData(pieceDataOffset, leftDataLength);
|
||||
off_t pieceDataOffset =
|
||||
(off_t)index*btContext->getPieceLength()+begin+blockLength-leftDataLength;
|
||||
size_t writtenLength = sendPieceData(pieceDataOffset, leftDataLength);
|
||||
peer->updateUploadLength(writtenLength);
|
||||
if(writtenLength < leftDataLength) {
|
||||
sendingInProgress = true;
|
||||
|
@ -169,28 +164,26 @@ void BtPieceMessage::send() {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t BtPieceMessage::sendPieceData(int64_t offset, int32_t length) const {
|
||||
int32_t BUF_SIZE = 256;
|
||||
size_t BtPieceMessage::sendPieceData(off_t offset, size_t length) const {
|
||||
size_t BUF_SIZE = 256;
|
||||
unsigned char buf[BUF_SIZE];
|
||||
int32_t iteration = length/BUF_SIZE;
|
||||
int32_t writtenLength = 0;
|
||||
for(int32_t i = 0; i < iteration; i++) {
|
||||
if(pieceStorage->getDiskAdaptor()->readData(buf, BUF_SIZE, offset+i*BUF_SIZE) < BUF_SIZE) {
|
||||
div_t res = div(length, BUF_SIZE);
|
||||
size_t writtenLength = 0;
|
||||
for(int i = 0; i < res.quot; i++) {
|
||||
if((size_t)pieceStorage->getDiskAdaptor()->readData(buf, BUF_SIZE, offset+i*BUF_SIZE) < BUF_SIZE) {
|
||||
throw new DlAbortEx(EX_DATA_READ);
|
||||
}
|
||||
int32_t ws = peerConnection->sendMessage(buf, BUF_SIZE);
|
||||
size_t ws = peerConnection->sendMessage(buf, BUF_SIZE);
|
||||
writtenLength += ws;
|
||||
if(ws != BUF_SIZE) {
|
||||
return writtenLength;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t rem = length%BUF_SIZE;
|
||||
if(rem > 0) {
|
||||
if(pieceStorage->getDiskAdaptor()->readData(buf, rem, offset+iteration*BUF_SIZE) < rem) {
|
||||
if(res.rem > 0) {
|
||||
if(pieceStorage->getDiskAdaptor()->readData(buf, res.rem, offset+res.quot*BUF_SIZE) < res.rem) {
|
||||
throw new DlAbortEx(EX_DATA_READ);
|
||||
}
|
||||
int32_t ws = peerConnection->sendMessage(buf, rem);
|
||||
size_t ws = peerConnection->sendMessage(buf, res.rem);
|
||||
writtenLength += ws;
|
||||
}
|
||||
return writtenLength;
|
||||
|
@ -202,8 +195,7 @@ std::string BtPieceMessage::toString() const {
|
|||
}
|
||||
|
||||
bool BtPieceMessage::checkPieceHash(const PieceHandle& piece) {
|
||||
int64_t offset =
|
||||
((int64_t)piece->getIndex())*btContext->getPieceLength();
|
||||
off_t offset = (off_t)piece->getIndex()*btContext->getPieceLength();
|
||||
|
||||
return MessageDigestHelper::staticSHA1Digest(pieceStorage->getDiskAdaptor(), offset, piece->getLength())
|
||||
== btContext->getPieceHash(piece->getIndex());
|
||||
|
|
|
@ -48,15 +48,15 @@ typedef SharedHandle<BtPieceMessage> BtPieceMessageHandle;
|
|||
|
||||
class BtPieceMessage : public AbstractBtMessage {
|
||||
private:
|
||||
int32_t index;
|
||||
int32_t begin;
|
||||
int32_t blockLength;
|
||||
size_t index;
|
||||
uint32_t begin;
|
||||
uint32_t blockLength;
|
||||
unsigned char* block;
|
||||
int32_t leftDataLength;
|
||||
size_t leftDataLength;
|
||||
bool headerSent;
|
||||
unsigned char* msgHeader;
|
||||
|
||||
static int32_t MESSAGE_HEADER_LENGTH;
|
||||
static size_t MESSAGE_HEADER_LENGTH;
|
||||
|
||||
bool checkPieceHash(const SharedHandle<Piece>& piece);
|
||||
|
||||
|
@ -66,7 +66,7 @@ private:
|
|||
|
||||
void erasePieceOnDisk(const SharedHandle<Piece>& piece);
|
||||
|
||||
int32_t sendPieceData(int64_t offset, int32_t length) const;
|
||||
size_t sendPieceData(off_t offset, size_t length) const;
|
||||
|
||||
class BtChokingEventListener : public AbstractBtEventListener {
|
||||
private:
|
||||
|
@ -94,7 +94,7 @@ private:
|
|||
|
||||
typedef SharedHandle<BtCancelSendingPieceEventListener> BtCancelSendingPieceEventListenerHandle;
|
||||
public:
|
||||
BtPieceMessage(int32_t index = 0, int32_t begin = 0, int32_t blockLength = 0)
|
||||
BtPieceMessage(size_t index = 0, uint32_t begin = 0, size_t blockLength = 0)
|
||||
:index(index),
|
||||
begin(begin),
|
||||
blockLength(blockLength),
|
||||
|
@ -113,33 +113,33 @@ public:
|
|||
delete [] block;
|
||||
}
|
||||
|
||||
static const int8_t ID = 7;
|
||||
static const uint8_t ID = 7;
|
||||
|
||||
int32_t getIndex() const { return index; }
|
||||
size_t getIndex() const { return index; }
|
||||
|
||||
void setIndex(int32_t index) { this->index = index; }
|
||||
void setIndex(size_t index) { this->index = index; }
|
||||
|
||||
int32_t getBegin() const { return begin; }
|
||||
uint32_t getBegin() const { return begin; }
|
||||
|
||||
void setBegin(int32_t begin) { this->begin = begin; }
|
||||
void setBegin(uint32_t begin) { this->begin = begin; }
|
||||
|
||||
const unsigned char* getBlock() const { return block; }
|
||||
|
||||
void setBlock(const unsigned char* block, int32_t blockLength);
|
||||
void setBlock(const unsigned char* block, size_t blockLength);
|
||||
|
||||
int32_t getBlockLength() const { return blockLength; }
|
||||
size_t getBlockLength() const { return blockLength; }
|
||||
|
||||
void setBlockLength(int32_t blockLength) { this->blockLength = blockLength; }
|
||||
void setBlockLength(size_t blockLength) { this->blockLength = blockLength; }
|
||||
|
||||
static BtPieceMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
static BtPieceMessageHandle create(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual int8_t getId() { return ID; }
|
||||
virtual uint8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
const unsigned char* getMessageHeader();
|
||||
|
||||
int32_t getMessageHeaderLength();
|
||||
size_t getMessageHeaderLength();
|
||||
|
||||
virtual void send();
|
||||
|
||||
|
|
|
@ -44,12 +44,12 @@ namespace aria2 {
|
|||
class BtPieceMessageValidator : public BtMessageValidator {
|
||||
private:
|
||||
const BtPieceMessage* message;
|
||||
int32_t numPiece;
|
||||
int32_t pieceLength;
|
||||
size_t numPiece;
|
||||
size_t pieceLength;
|
||||
public:
|
||||
BtPieceMessageValidator(const BtPieceMessage* message,
|
||||
int32_t numPiece,
|
||||
int32_t pieceLength):
|
||||
size_t numPiece,
|
||||
size_t pieceLength):
|
||||
message(message),
|
||||
numPiece(numPiece),
|
||||
pieceLength(pieceLength) {}
|
||||
|
|
|
@ -54,12 +54,12 @@ BtPortMessage::~BtPortMessage()
|
|||
delete [] _msg;
|
||||
}
|
||||
|
||||
SharedHandle<BtPortMessage> BtPortMessage::create(const unsigned char* data, int32_t dataLength)
|
||||
SharedHandle<BtPortMessage> BtPortMessage::create(const unsigned char* data, size_t dataLength)
|
||||
{
|
||||
if(dataLength != 3) {
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "port", dataLength, 3);
|
||||
}
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "piece", ID);
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ const unsigned char* BtPortMessage::getMessage() {
|
|||
return _msg;
|
||||
}
|
||||
|
||||
int32_t BtPortMessage::getMessageLength() {
|
||||
size_t BtPortMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
|
|
|
@ -62,19 +62,19 @@ public:
|
|||
|
||||
virtual ~BtPortMessage();
|
||||
|
||||
static const int8_t ID = 9;
|
||||
static const uint8_t ID = 9;
|
||||
|
||||
uint16_t getPort() const { return _port; }
|
||||
|
||||
static SharedHandle<BtPortMessage> create(const unsigned char* data, int32_t dataLength);
|
||||
static SharedHandle<BtPortMessage> create(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual int8_t getId() { return ID; }
|
||||
virtual uint8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual int32_t getMessageLength();
|
||||
virtual size_t getMessageLength();
|
||||
|
||||
virtual std::string toString() const;
|
||||
|
||||
|
|
|
@ -43,11 +43,11 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
BtRejectMessageHandle BtRejectMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||
BtRejectMessageHandle BtRejectMessage::create(const unsigned char* data, size_t dataLength) {
|
||||
if(dataLength != 13) {
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "reject", dataLength, 13);
|
||||
}
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "reject", ID);
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ void BtRejectMessage::doReceivedAction() {
|
|||
|
||||
}
|
||||
|
||||
int32_t BtRejectMessage::MESSAGE_LENGTH = 17;
|
||||
size_t BtRejectMessage::MESSAGE_LENGTH = 17;
|
||||
|
||||
const unsigned char* BtRejectMessage::getMessage() {
|
||||
if(!msg) {
|
||||
|
@ -95,13 +95,13 @@ const unsigned char* BtRejectMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
int32_t BtRejectMessage::getMessageLength() {
|
||||
size_t BtRejectMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
std::string BtRejectMessage::toString() const {
|
||||
return "reject index="+Util::itos(index)+", begin="+Util::itos(begin)+
|
||||
", length="+Util::itos(length);
|
||||
return "reject index="+Util::uitos(index)+", begin="+Util::uitos(begin)+
|
||||
", length="+Util::uitos(length);
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -45,13 +45,13 @@ typedef SharedHandle<BtRejectMessage> BtRejectMessageHandle;
|
|||
|
||||
class BtRejectMessage : public SimpleBtMessage {
|
||||
private:
|
||||
int32_t index;
|
||||
int32_t begin;
|
||||
int32_t length;
|
||||
size_t index;
|
||||
uint32_t begin;
|
||||
size_t length;
|
||||
unsigned char* msg;
|
||||
static int32_t MESSAGE_LENGTH;
|
||||
static size_t MESSAGE_LENGTH;
|
||||
public:
|
||||
BtRejectMessage(int32_t index = 0, int32_t begin = 0, int32_t length = 0)
|
||||
BtRejectMessage(size_t index = 0, uint32_t begin = 0, size_t length = 0)
|
||||
:index(index),
|
||||
begin(begin),
|
||||
length(length),
|
||||
|
@ -61,26 +61,26 @@ public:
|
|||
delete [] msg;
|
||||
}
|
||||
|
||||
static const int8_t ID = 16;
|
||||
static const uint8_t ID = 16;
|
||||
|
||||
int32_t getIndex() const { return index; }
|
||||
void setIndex(int32_t index) { this->index = index; }
|
||||
size_t getIndex() const { return index; }
|
||||
void setIndex(size_t index) { this->index = index; }
|
||||
|
||||
int32_t getBegin() const { return begin; }
|
||||
void setBegin(int32_t begin) { this->begin = begin; }
|
||||
uint32_t getBegin() const { return begin; }
|
||||
void setBegin(uint32_t begin) { this->begin = begin; }
|
||||
|
||||
int32_t getLength() const { return length; }
|
||||
void setLength(int32_t length) { this->length = length; }
|
||||
size_t getLength() const { return length; }
|
||||
void setLength(size_t length) { this->length = length; }
|
||||
|
||||
static BtRejectMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
static BtRejectMessageHandle create(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual int8_t getId() { return ID; }
|
||||
virtual uint8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual int32_t getMessageLength();
|
||||
virtual size_t getMessageLength();
|
||||
|
||||
virtual std::string toString() const;
|
||||
};
|
||||
|
|
|
@ -44,12 +44,12 @@ namespace aria2 {
|
|||
class BtRejectMessageValidator : public BtMessageValidator {
|
||||
private:
|
||||
const BtRejectMessage* message;
|
||||
int32_t numPiece;
|
||||
int32_t pieceLength;
|
||||
size_t numPiece;
|
||||
size_t pieceLength;
|
||||
public:
|
||||
BtRejectMessageValidator(const BtRejectMessage* message,
|
||||
int32_t numPiece,
|
||||
int32_t pieceLength):
|
||||
size_t numPiece,
|
||||
size_t pieceLength):
|
||||
message(message),
|
||||
numPiece(numPiece),
|
||||
pieceLength(pieceLength) {}
|
||||
|
|
|
@ -54,7 +54,7 @@ public:
|
|||
|
||||
virtual void removeAllTargetPiece() = 0;
|
||||
|
||||
virtual int32_t countTargetPiece() = 0;
|
||||
virtual size_t countTargetPiece() = 0;
|
||||
|
||||
virtual void removeCompletedPiece() = 0;
|
||||
|
||||
|
|
|
@ -47,11 +47,11 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
BtRequestMessageHandle BtRequestMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||
BtRequestMessageHandle BtRequestMessage::create(const unsigned char* data, size_t dataLength) {
|
||||
if(dataLength != 13) {
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "request", dataLength, 13);
|
||||
}
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "request", ID);
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ void BtRequestMessage::doReceivedAction() {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t BtRequestMessage::MESSAGE_LENGTH = 17;
|
||||
size_t BtRequestMessage::MESSAGE_LENGTH = 17;
|
||||
|
||||
const unsigned char* BtRequestMessage::getMessage() {
|
||||
if(!msg) {
|
||||
|
@ -101,13 +101,13 @@ const unsigned char* BtRequestMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
int32_t BtRequestMessage::getMessageLength() {
|
||||
size_t BtRequestMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
std::string BtRequestMessage::toString() const {
|
||||
return "request index="+Util::itos(index)+", begin="+Util::itos(begin)+
|
||||
", length="+Util::itos(length);
|
||||
return "request index="+Util::uitos(index)+", begin="+Util::uitos(begin)+
|
||||
", length="+Util::uitos(length);
|
||||
}
|
||||
|
||||
void BtRequestMessage::onQueued() {
|
||||
|
|
|
@ -46,13 +46,13 @@ typedef SharedHandle<BtRequestMessage> BtRequestMessageHandle;
|
|||
|
||||
class BtRequestMessage : public SimpleBtMessage {
|
||||
private:
|
||||
int32_t index;
|
||||
int32_t begin;
|
||||
int32_t length;
|
||||
int32_t blockIndex;
|
||||
size_t index;
|
||||
uint32_t begin;
|
||||
uint32_t length;
|
||||
size_t blockIndex;
|
||||
unsigned char* msg;
|
||||
|
||||
static int32_t MESSAGE_LENGTH;
|
||||
static size_t MESSAGE_LENGTH;
|
||||
|
||||
class BtAbortOutstandingRequestEventListener : public AbstractBtEventListener {
|
||||
private:
|
||||
|
@ -67,10 +67,10 @@ private:
|
|||
|
||||
typedef SharedHandle<BtAbortOutstandingRequestEventListener> BtAbortOutstandingRequestEventListenerHandle;
|
||||
public:
|
||||
BtRequestMessage(int32_t index = 0,
|
||||
int32_t begin = 0,
|
||||
int32_t length = 0,
|
||||
int32_t blockIndex = 0)
|
||||
BtRequestMessage(size_t index = 0,
|
||||
uint32_t begin = 0,
|
||||
uint32_t length = 0,
|
||||
size_t blockIndex = 0)
|
||||
:index(index),
|
||||
begin(begin),
|
||||
length(length),
|
||||
|
@ -84,29 +84,29 @@ public:
|
|||
delete [] msg;
|
||||
}
|
||||
|
||||
static const int8_t ID = 6;
|
||||
static const uint8_t ID = 6;
|
||||
|
||||
int32_t getIndex() const { return index; }
|
||||
void setIndex(int32_t index) { this->index = index; }
|
||||
size_t getIndex() const { return index; }
|
||||
void setIndex(size_t index) { this->index = index; }
|
||||
|
||||
int32_t getBegin() const { return begin; }
|
||||
void setBegin(int32_t begin) { this->begin = begin; }
|
||||
uint32_t getBegin() const { return begin; }
|
||||
void setBegin(uint32_t begin) { this->begin = begin; }
|
||||
|
||||
int32_t getLength() const { return length; }
|
||||
void setLength(int32_t length) { this->length = length; }
|
||||
uint32_t getLength() const { return length; }
|
||||
void setLength(uint32_t length) { this->length = length; }
|
||||
|
||||
int32_t getBlockIndex() const { return blockIndex; }
|
||||
void setBlockIndex(int32_t blockIndex) { this->blockIndex = blockIndex; }
|
||||
size_t getBlockIndex() const { return blockIndex; }
|
||||
void setBlockIndex(size_t blockIndex) { this->blockIndex = blockIndex; }
|
||||
|
||||
static BtRequestMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
static BtRequestMessageHandle create(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual int8_t getId() { return ID; }
|
||||
virtual uint8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual int32_t getMessageLength();
|
||||
virtual size_t getMessageLength();
|
||||
|
||||
virtual std::string toString() const;
|
||||
|
||||
|
|
|
@ -44,12 +44,12 @@ namespace aria2 {
|
|||
class BtRequestMessageValidator : public BtMessageValidator {
|
||||
private:
|
||||
const BtRequestMessage* message;
|
||||
int32_t numPiece;
|
||||
int32_t pieceLength;
|
||||
size_t numPiece;
|
||||
size_t pieceLength;
|
||||
public:
|
||||
BtRequestMessageValidator(const BtRequestMessage* message,
|
||||
int32_t numPiece,
|
||||
int32_t pieceLength):
|
||||
size_t numPiece,
|
||||
size_t pieceLength):
|
||||
message(message),
|
||||
numPiece(numPiece),
|
||||
pieceLength(pieceLength) {}
|
||||
|
|
|
@ -44,10 +44,10 @@ namespace aria2 {
|
|||
|
||||
class BtRuntime {
|
||||
private:
|
||||
int64_t uploadLengthAtStartup;
|
||||
int32_t port;
|
||||
uint64_t uploadLengthAtStartup;
|
||||
uint16_t port;
|
||||
bool halt;
|
||||
int32_t connections;
|
||||
unsigned int connections;
|
||||
bool _ready;
|
||||
public:
|
||||
BtRuntime():
|
||||
|
@ -60,19 +60,19 @@ public:
|
|||
|
||||
~BtRuntime() {}
|
||||
|
||||
int64_t getUploadLengthAtStartup() const {
|
||||
uint64_t getUploadLengthAtStartup() const {
|
||||
return uploadLengthAtStartup;
|
||||
}
|
||||
|
||||
void setUploadLengthAtStartup(int64_t length) {
|
||||
void setUploadLengthAtStartup(uint64_t length) {
|
||||
this->uploadLengthAtStartup = length;
|
||||
}
|
||||
|
||||
void setListenPort(int32_t port) {
|
||||
void setListenPort(uint16_t port) {
|
||||
this->port = port;
|
||||
}
|
||||
|
||||
int32_t getListenPort() const { return port; }
|
||||
uint16_t getListenPort() const { return port; }
|
||||
|
||||
bool isHalt() const { return halt; }
|
||||
|
||||
|
@ -80,7 +80,7 @@ public:
|
|||
this->halt = halt;
|
||||
}
|
||||
|
||||
int32_t getConnections() const { return connections; }
|
||||
unsigned int getConnections() const { return connections; }
|
||||
|
||||
void increaseConnections() { connections++; }
|
||||
|
||||
|
|
|
@ -40,11 +40,11 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
BtSuggestPieceMessageHandle BtSuggestPieceMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||
BtSuggestPieceMessageHandle BtSuggestPieceMessage::create(const unsigned char* data, size_t dataLength) {
|
||||
if(dataLength != 5) {
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "suggest piece", dataLength, 5);
|
||||
}
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "suggest piece", ID);
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ BtSuggestPieceMessageHandle BtSuggestPieceMessage::create(const unsigned char* d
|
|||
return message;
|
||||
}
|
||||
|
||||
int32_t BtSuggestPieceMessage::MESSAGE_LENGTH = 9;
|
||||
size_t BtSuggestPieceMessage::MESSAGE_LENGTH = 9;
|
||||
|
||||
const unsigned char* BtSuggestPieceMessage::getMessage() {
|
||||
if(!msg) {
|
||||
|
@ -70,7 +70,7 @@ const unsigned char* BtSuggestPieceMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
int32_t BtSuggestPieceMessage::getMessageLength() {
|
||||
size_t BtSuggestPieceMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,9 +45,9 @@ typedef SharedHandle<BtSuggestPieceMessage> BtSuggestPieceMessageHandle;
|
|||
|
||||
class BtSuggestPieceMessage : public SimpleBtMessage {
|
||||
private:
|
||||
int32_t index;
|
||||
size_t index;
|
||||
unsigned char* msg;
|
||||
static int32_t MESSAGE_LENGTH;
|
||||
static size_t MESSAGE_LENGTH;
|
||||
public:
|
||||
BtSuggestPieceMessage():index(0), msg(0) {}
|
||||
|
||||
|
@ -55,17 +55,17 @@ public:
|
|||
delete [] msg;
|
||||
}
|
||||
|
||||
static const int8_t ID = 13;
|
||||
static const uint8_t ID = 13;
|
||||
|
||||
void setIndex(int32_t index) {
|
||||
void setIndex(size_t index) {
|
||||
this->index = index;
|
||||
}
|
||||
|
||||
int32_t getIndex() const { return index; }
|
||||
size_t getIndex() const { return index; }
|
||||
|
||||
static BtSuggestPieceMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
static BtSuggestPieceMessageHandle create(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual int8_t getId() { return ID; }
|
||||
virtual uint8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction() {
|
||||
// TODO Current implementation ignores this message.
|
||||
|
@ -73,7 +73,7 @@ public:
|
|||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual int32_t getMessageLength();
|
||||
virtual size_t getMessageLength();
|
||||
|
||||
virtual std::string toString() const;
|
||||
};
|
||||
|
|
|
@ -44,10 +44,10 @@ namespace aria2 {
|
|||
class BtSuggestPieceMessageValidator : public BtMessageValidator {
|
||||
private:
|
||||
const BtSuggestPieceMessage* message;
|
||||
int32_t numPiece;
|
||||
size_t numPiece;
|
||||
public:
|
||||
BtSuggestPieceMessageValidator(const BtSuggestPieceMessage* message,
|
||||
int32_t numPiece):
|
||||
size_t numPiece):
|
||||
message(message),
|
||||
numPiece(numPiece) {}
|
||||
|
||||
|
|
|
@ -40,11 +40,11 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
BtUnchokeMessageHandle BtUnchokeMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||
BtUnchokeMessageHandle BtUnchokeMessage::create(const unsigned char* data, size_t dataLength) {
|
||||
if(dataLength != 1) {
|
||||
throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "unchoke", dataLength, 1);
|
||||
}
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "unchoke", ID);
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ bool BtUnchokeMessage::sendPredicate() const {
|
|||
return peer->amChoking();
|
||||
}
|
||||
|
||||
int32_t BtUnchokeMessage::MESSAGE_LENGTH = 5;
|
||||
size_t BtUnchokeMessage::MESSAGE_LENGTH = 5;
|
||||
|
||||
const unsigned char* BtUnchokeMessage::getMessage() {
|
||||
if(!msg) {
|
||||
|
@ -75,7 +75,7 @@ const unsigned char* BtUnchokeMessage::getMessage() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
int32_t BtUnchokeMessage::getMessageLength() {
|
||||
size_t BtUnchokeMessage::getMessageLength() {
|
||||
return MESSAGE_LENGTH;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ typedef SharedHandle<BtUnchokeMessage> BtUnchokeMessageHandle;
|
|||
class BtUnchokeMessage : public SimpleBtMessage {
|
||||
private:
|
||||
unsigned char* msg;
|
||||
static int32_t MESSAGE_LENGTH;
|
||||
static size_t MESSAGE_LENGTH;
|
||||
public:
|
||||
BtUnchokeMessage():msg(0) {}
|
||||
|
||||
|
@ -54,17 +54,17 @@ public:
|
|||
delete [] msg;
|
||||
}
|
||||
|
||||
static const int8_t ID = 1;
|
||||
static const uint8_t ID = 1;
|
||||
|
||||
static BtUnchokeMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||
static BtUnchokeMessageHandle create(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual int8_t getId() { return ID; }
|
||||
virtual uint8_t getId() { return ID; }
|
||||
|
||||
virtual void doReceivedAction();
|
||||
|
||||
virtual const unsigned char* getMessage();
|
||||
|
||||
virtual int32_t getMessageLength();
|
||||
virtual size_t getMessageLength();
|
||||
|
||||
virtual std::string toString() const;
|
||||
|
||||
|
|
|
@ -47,27 +47,27 @@ void ByteArrayDiskWriter::clear()
|
|||
}
|
||||
|
||||
void ByteArrayDiskWriter::initAndOpenFile(const std::string& filename,
|
||||
int64_t totalLength)
|
||||
uint64_t totalLength)
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
void ByteArrayDiskWriter::openFile(const std::string& filename,
|
||||
int64_t totalLength) {}
|
||||
uint64_t totalLength) {}
|
||||
|
||||
void ByteArrayDiskWriter::closeFile() {}
|
||||
|
||||
void ByteArrayDiskWriter::openExistingFile(const std::string& filename,
|
||||
int64_t totalLength)
|
||||
uint64_t totalLength)
|
||||
{
|
||||
openFile(filename);
|
||||
}
|
||||
|
||||
void ByteArrayDiskWriter::writeData(const unsigned char* data, int32_t dataLength, int64_t position)
|
||||
void ByteArrayDiskWriter::writeData(const unsigned char* data, size_t dataLength, off_t position)
|
||||
{
|
||||
if(size() < position) {
|
||||
if(size() < (uint64_t)position) {
|
||||
buf.seekp(size(), std::ios::beg);
|
||||
for(int64_t i = size(); i < position; ++i) {
|
||||
for(uint64_t i = size(); i < (uint64_t)position; ++i) {
|
||||
buf.put('\0');
|
||||
}
|
||||
} else {
|
||||
|
@ -76,7 +76,7 @@ void ByteArrayDiskWriter::writeData(const unsigned char* data, int32_t dataLengt
|
|||
buf.write(reinterpret_cast<const char*>(data), dataLength);
|
||||
}
|
||||
|
||||
int32_t ByteArrayDiskWriter::readData(unsigned char* data, int32_t len, int64_t position)
|
||||
ssize_t ByteArrayDiskWriter::readData(unsigned char* data, size_t len, off_t position)
|
||||
{
|
||||
buf.seekg(position, std::ios::beg);
|
||||
buf.read(reinterpret_cast<char*>(data), len);
|
||||
|
|
|
@ -49,21 +49,21 @@ public:
|
|||
ByteArrayDiskWriter();
|
||||
virtual ~ByteArrayDiskWriter();
|
||||
|
||||
virtual void initAndOpenFile(const std::string& filename, int64_t totalLength = 0);
|
||||
virtual void initAndOpenFile(const std::string& filename, uint64_t totalLength = 0);
|
||||
|
||||
virtual void openFile(const std::string& filename, int64_t totalLength = 0);
|
||||
virtual void openFile(const std::string& filename, uint64_t totalLength = 0);
|
||||
|
||||
virtual void closeFile();
|
||||
|
||||
virtual void openExistingFile(const std::string& filename, int64_t totalLength = 0);
|
||||
virtual void openExistingFile(const std::string& filename, uint64_t totalLength = 0);
|
||||
|
||||
virtual void writeData(const unsigned char* data, int32_t len, int64_t position);
|
||||
virtual int32_t readData(unsigned char* data, int32_t len, int64_t position);
|
||||
virtual void writeData(const unsigned char* data, size_t len, off_t position);
|
||||
virtual ssize_t readData(unsigned char* data, size_t len, off_t position);
|
||||
|
||||
// Not implemented yet
|
||||
virtual void truncate(int64_t length) {}
|
||||
virtual void truncate(uint64_t length) {}
|
||||
|
||||
virtual int64_t size() const
|
||||
virtual uint64_t size() const
|
||||
{
|
||||
return buf.str().size();
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ void CheckIntegrityEntry::validateChunk()
|
|||
_validator->validateChunk();
|
||||
}
|
||||
|
||||
int64_t CheckIntegrityEntry::getTotalLength()
|
||||
uint64_t CheckIntegrityEntry::getTotalLength()
|
||||
{
|
||||
if(_validator.isNull()) {
|
||||
return 0;
|
||||
|
@ -59,7 +59,7 @@ int64_t CheckIntegrityEntry::getTotalLength()
|
|||
}
|
||||
}
|
||||
|
||||
int64_t CheckIntegrityEntry::getCurrentLength()
|
||||
off_t CheckIntegrityEntry::getCurrentLength()
|
||||
{
|
||||
if(_validator.isNull()) {
|
||||
return 0;
|
||||
|
|
|
@ -53,9 +53,9 @@ public:
|
|||
|
||||
virtual ~CheckIntegrityEntry();
|
||||
|
||||
virtual int64_t getTotalLength();
|
||||
virtual uint64_t getTotalLength();
|
||||
|
||||
virtual int64_t getCurrentLength();
|
||||
virtual off_t getCurrentLength();
|
||||
|
||||
virtual void validateChunk();
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ CheckIntegrityEntryHandle CheckIntegrityMan::getFirstCheckIntegrityEntry() const
|
|||
}
|
||||
}
|
||||
|
||||
int32_t CheckIntegrityMan::countCheckIntegrityEntry() const
|
||||
size_t CheckIntegrityMan::countCheckIntegrityEntry() const
|
||||
{
|
||||
return _checkIntegrityEntries.size();
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ public:
|
|||
|
||||
SharedHandle<CheckIntegrityEntry> getFirstCheckIntegrityEntry() const;
|
||||
|
||||
int32_t countCheckIntegrityEntry() const;
|
||||
size_t countCheckIntegrityEntry() const;
|
||||
};
|
||||
|
||||
typedef SharedHandle<CheckIntegrityMan> CheckIntegrityManHandle;
|
||||
|
|
|
@ -46,40 +46,40 @@ class ChunkChecksum {
|
|||
private:
|
||||
std::string _algo;
|
||||
std::deque<std::string> _checksums;
|
||||
int32_t _checksumLength;
|
||||
size_t _checksumLength;
|
||||
public:
|
||||
ChunkChecksum():_checksumLength(0) {}
|
||||
|
||||
ChunkChecksum(const std::string& algo,
|
||||
const std::deque<std::string>& checksums,
|
||||
int32_t checksumLength):
|
||||
size_t checksumLength):
|
||||
_algo(algo),
|
||||
_checksums(checksums),
|
||||
_checksumLength(checksumLength) {}
|
||||
|
||||
bool validateChunk(const std::string& actualChecksum,
|
||||
int32_t checksumIndex) const
|
||||
size_t checksumIndex) const
|
||||
{
|
||||
if(checksumIndex < (int32_t)_checksums.size()) {
|
||||
if(checksumIndex < _checksums.size()) {
|
||||
return actualChecksum == getChecksum(checksumIndex);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t getEstimatedDataLength() const
|
||||
uint64_t getEstimatedDataLength() const
|
||||
{
|
||||
return ((int64_t)_checksumLength)*_checksums.size();
|
||||
return ((uint64_t)_checksumLength)*_checksums.size();
|
||||
}
|
||||
|
||||
int32_t countChecksum() const
|
||||
size_t countChecksum() const
|
||||
{
|
||||
return _checksums.size();
|
||||
}
|
||||
|
||||
std::string getChecksum(int32_t index) const
|
||||
std::string getChecksum(size_t index) const
|
||||
{
|
||||
if(index < (int32_t)_checksums.size()) {
|
||||
if(index < _checksums.size()) {
|
||||
return _checksums[index];
|
||||
} else {
|
||||
return "";
|
||||
|
@ -91,7 +91,7 @@ public:
|
|||
return _checksums;
|
||||
}
|
||||
|
||||
int32_t getChecksumLength() const
|
||||
size_t getChecksumLength() const
|
||||
{
|
||||
return _checksumLength;
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ public:
|
|||
_algo = algo;
|
||||
}
|
||||
|
||||
void setChecksumLength(int32_t length)
|
||||
void setChecksumLength(size_t length)
|
||||
{
|
||||
_checksumLength = length;
|
||||
}
|
||||
|
|
|
@ -63,11 +63,11 @@ bool ChunkedEncoding::finished() {
|
|||
|
||||
void ChunkedEncoding::end() {}
|
||||
|
||||
void ChunkedEncoding::inflate(unsigned char* outbuf, int32_t& outlen,
|
||||
const unsigned char* inbuf, int32_t inlen) {
|
||||
void ChunkedEncoding::inflate(unsigned char* outbuf, size_t& outlen,
|
||||
const unsigned char* inbuf, size_t inlen) {
|
||||
addBuffer(inbuf, inlen);
|
||||
unsigned char* p = strbuf;
|
||||
int32_t clen = 0;
|
||||
size_t clen = 0;
|
||||
while(1) {
|
||||
if(state == READ_SIZE) {
|
||||
if(readChunkSize(&p) == 0) {
|
||||
|
@ -98,7 +98,7 @@ void ChunkedEncoding::inflate(unsigned char* outbuf, int32_t& outlen,
|
|||
strbufTail = strbuf;
|
||||
} else {
|
||||
// copy string between [p, strbufTail]
|
||||
int32_t unreadSize = strbufTail-p;
|
||||
size_t unreadSize = strbufTail-p;
|
||||
unsigned char* temp = new unsigned char[strbufSize];
|
||||
memcpy(temp, p, unreadSize);
|
||||
delete [] strbuf;
|
||||
|
@ -108,9 +108,9 @@ void ChunkedEncoding::inflate(unsigned char* outbuf, int32_t& outlen,
|
|||
outlen = clen;
|
||||
}
|
||||
|
||||
int32_t ChunkedEncoding::readData(unsigned char** pp,
|
||||
unsigned char* buf, int32_t& len,
|
||||
int32_t maxlen)
|
||||
int ChunkedEncoding::readData(unsigned char** pp,
|
||||
unsigned char* buf, size_t& len,
|
||||
size_t maxlen)
|
||||
{
|
||||
if(buf+len == buf+maxlen) {
|
||||
return -1;
|
||||
|
@ -118,11 +118,11 @@ int32_t ChunkedEncoding::readData(unsigned char** pp,
|
|||
if(chunkSize == 0) {
|
||||
return readDataEOL(pp);
|
||||
}
|
||||
int32_t wsize;
|
||||
if(strbufTail-*pp < chunkSize) {
|
||||
wsize = strbufTail-*pp <= maxlen-len ? strbufTail-*pp : maxlen-len;
|
||||
size_t wsize;
|
||||
if((size_t)(strbufTail-*pp) < chunkSize) {
|
||||
wsize = std::min((size_t)(strbufTail-*pp), maxlen-len);
|
||||
} else {
|
||||
wsize = chunkSize <= maxlen-len ? chunkSize : maxlen-len;
|
||||
wsize = std::min(chunkSize, maxlen-len);
|
||||
}
|
||||
memcpy(buf+len, *pp, wsize);
|
||||
chunkSize -= wsize;
|
||||
|
@ -135,7 +135,7 @@ int32_t ChunkedEncoding::readData(unsigned char** pp,
|
|||
}
|
||||
}
|
||||
|
||||
int32_t ChunkedEncoding::readDataEOL(unsigned char** pp) {
|
||||
int ChunkedEncoding::readDataEOL(unsigned char** pp) {
|
||||
unsigned char* np = reinterpret_cast<unsigned char*>(memchr(*pp, '\n', strbufTail-*pp));
|
||||
unsigned char* rp = reinterpret_cast<unsigned char*>(memchr(*pp, '\r', strbufTail-*pp));
|
||||
if(np != NULL && rp != NULL && np-rp == 1 && *pp == rp) {
|
||||
|
@ -148,7 +148,7 @@ int32_t ChunkedEncoding::readDataEOL(unsigned char** pp) {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t ChunkedEncoding::readChunkSize(unsigned char** pp) {
|
||||
int ChunkedEncoding::readChunkSize(unsigned char** pp) {
|
||||
// we read chunk-size from *pp
|
||||
unsigned char* p;
|
||||
unsigned char* np = reinterpret_cast<unsigned char*>(memchr(*pp, '\n', strbufTail-*pp));
|
||||
|
@ -172,8 +172,8 @@ int32_t ChunkedEncoding::readChunkSize(unsigned char** pp) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void ChunkedEncoding::addBuffer(const unsigned char* inbuf, int32_t inlen) {
|
||||
int32_t realbufSize = strbufTail-strbuf;
|
||||
void ChunkedEncoding::addBuffer(const unsigned char* inbuf, size_t inlen) {
|
||||
size_t realbufSize = strbufTail-strbuf;
|
||||
if(realbufSize+inlen >= strbufSize) {
|
||||
if(realbufSize+inlen > MAX_BUFSIZE) {
|
||||
throw new DlAbortEx(EX_TOO_LARGE_CHUNK, realbufSize+inlen);
|
||||
|
|
|
@ -46,21 +46,21 @@ private:
|
|||
READ_DATA,
|
||||
FINISH
|
||||
};
|
||||
int32_t chunkSize;
|
||||
int32_t state;
|
||||
size_t chunkSize;
|
||||
STATE state;
|
||||
unsigned char* strbuf;
|
||||
int32_t strbufSize;
|
||||
size_t strbufSize;
|
||||
unsigned char* strbufTail;
|
||||
|
||||
/**
|
||||
* Returns 0 if the size of chunk is retrieved successfully,
|
||||
* otherwise returns non-zero value.
|
||||
*/
|
||||
int32_t readChunkSize(unsigned char** pp);
|
||||
int32_t readData(unsigned char** pp, unsigned char* buf, int32_t& len,
|
||||
int32_t maxlen);
|
||||
void addBuffer(const unsigned char* inbuf, int32_t inlen);
|
||||
int32_t readDataEOL(unsigned char** pp);
|
||||
int readChunkSize(unsigned char** pp);
|
||||
int readData(unsigned char** pp, unsigned char* buf, size_t& len,
|
||||
size_t maxlen);
|
||||
void addBuffer(const unsigned char* inbuf, size_t inlen);
|
||||
int readDataEOL(unsigned char** pp);
|
||||
|
||||
|
||||
public:
|
||||
|
@ -68,8 +68,8 @@ public:
|
|||
~ChunkedEncoding();
|
||||
|
||||
void init();
|
||||
void inflate(unsigned char* outbuf, int32_t& outlen,
|
||||
const unsigned char* inbuf, int32_t inlen);
|
||||
void inflate(unsigned char* outbuf, size_t& outlen,
|
||||
const unsigned char* inbuf, size_t inlen);
|
||||
bool finished();
|
||||
void end();
|
||||
};
|
||||
|
|
|
@ -38,9 +38,7 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
CompactPeerListProcessor::CompactPeerListProcessor(int32_t pieceLength, int64_t totalLength):
|
||||
pieceLength(pieceLength),
|
||||
totalLength(totalLength) {}
|
||||
CompactPeerListProcessor::CompactPeerListProcessor() {}
|
||||
|
||||
CompactPeerListProcessor::~CompactPeerListProcessor() {}
|
||||
|
||||
|
@ -55,7 +53,7 @@ Peers CompactPeerListProcessor::extractPeer(const MetaEntry* peersEntry) {
|
|||
return peers;
|
||||
}
|
||||
if(peersData->getLen()%6 == 0) {
|
||||
for(int32_t i = 0; i < peersData->getLen(); i += 6) {
|
||||
for(size_t i = 0; i < peersData->getLen(); i += 6) {
|
||||
struct in_addr in;
|
||||
in.s_addr = *(uint32_t*)(peersData->getData()+i);
|
||||
std::string ipaddr = inet_ntoa(in);
|
||||
|
|
|
@ -39,11 +39,8 @@
|
|||
namespace aria2 {
|
||||
|
||||
class CompactPeerListProcessor : public PeerListProcessor {
|
||||
private:
|
||||
int32_t pieceLength;
|
||||
int64_t totalLength;
|
||||
public:
|
||||
CompactPeerListProcessor(int32_t pieceLength, int64_t totalLength);
|
||||
CompactPeerListProcessor();
|
||||
|
||||
virtual ~CompactPeerListProcessor();
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ ConsoleStatCalc::calculateStat(const RequestGroupManHandle& requestGroupMan,
|
|||
if(requestGroupMan->countRequestGroup() > 0) {
|
||||
RequestGroupHandle firstRequestGroup = requestGroupMan->getRequestGroup(0);
|
||||
TransferStat stat = firstRequestGroup->calculateStat();
|
||||
int32_t eta = 0;
|
||||
unsigned int eta = 0;
|
||||
if(firstRequestGroup->getTotalLength() > 0 && stat.getDownloadSpeed() > 0) {
|
||||
eta = (firstRequestGroup->getTotalLength()-firstRequestGroup->getCompletedLength())/stat.getDownloadSpeed();
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ void CopyDiskAdaptor::onDownloadComplete()
|
|||
|
||||
void CopyDiskAdaptor::fixFilename()
|
||||
{
|
||||
int64_t offset = 0;
|
||||
off_t offset = 0;
|
||||
for(FileEntries::iterator itr = fileEntries.begin();
|
||||
itr != fileEntries.end(); itr++) {
|
||||
if(!(*itr)->isExtracted() && (*itr)->isRequested()) {
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
DHTAutoSaveCommand::DHTAutoSaveCommand(int32_t cuid, DownloadEngine* e, int32_t interval):
|
||||
DHTAutoSaveCommand::DHTAutoSaveCommand(int32_t cuid, DownloadEngine* e, time_t interval):
|
||||
TimeBasedCommand(cuid, e, interval),
|
||||
_localNode(0),
|
||||
_routingTable(0) {}
|
||||
|
|
|
@ -52,7 +52,7 @@ private:
|
|||
|
||||
void save();
|
||||
public:
|
||||
DHTAutoSaveCommand(int32_t cuid, DownloadEngine* e, int32_t interval);
|
||||
DHTAutoSaveCommand(int32_t cuid, DownloadEngine* e, time_t interval);
|
||||
|
||||
virtual ~DHTAutoSaveCommand();
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ uint16_t DHTConnectionImpl::bind(uint16_t port)
|
|||
{
|
||||
try {
|
||||
_socket->bind(port);
|
||||
std::pair<std::string, int32_t> svaddr;
|
||||
std::pair<std::string, uint16_t> svaddr;
|
||||
_socket->getAddrInfo(svaddr);
|
||||
_logger->info("Bind socket for DHT. port=%u", port);
|
||||
return svaddr.second;
|
||||
|
|
|
@ -113,7 +113,7 @@ std::string DHTNode::toString() const
|
|||
return "DHTNode ID="+Util::toHex(_id, DHT_ID_LENGTH)+
|
||||
", Host="+_ipaddr+":"+Util::uitos(_port)+
|
||||
", Condition="+Util::uitos(_condition)+
|
||||
", RTT="+Util::itos(_rtt);
|
||||
", RTT="+Util::uitos(_rtt);
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -52,9 +52,9 @@ private:
|
|||
uint16_t _port;
|
||||
|
||||
// in milli sec
|
||||
int32_t _rtt;
|
||||
unsigned int _rtt;
|
||||
|
||||
uint32_t _condition;
|
||||
unsigned int _condition;
|
||||
|
||||
Time _lastContact;
|
||||
public:
|
||||
|
@ -72,7 +72,7 @@ public:
|
|||
return _id;
|
||||
}
|
||||
|
||||
void updateRTT(int32_t millisec)
|
||||
void updateRTT(unsigned int millisec)
|
||||
{
|
||||
_rtt = millisec;
|
||||
}
|
||||
|
|
|
@ -38,12 +38,12 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
Data::Data(const unsigned char* data, int32_t len, bool number):number(number)
|
||||
Data::Data(const unsigned char* data, size_t len, bool number):number(number)
|
||||
{
|
||||
init(data, len);
|
||||
}
|
||||
|
||||
Data::Data(const char* data, int32_t len, bool number):number(number) {
|
||||
Data::Data(const char* data, size_t len, bool number):number(number) {
|
||||
init(reinterpret_cast<const unsigned char*>(data), len);
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ Data::Data(const std::string& data, bool number):number(number)
|
|||
init(reinterpret_cast<const unsigned char*>(data.c_str()), data.size());
|
||||
}
|
||||
|
||||
void Data::init(const unsigned char* src, int32_t slen)
|
||||
void Data::init(const unsigned char* src, size_t slen)
|
||||
{
|
||||
if(src) {
|
||||
data = new unsigned char[slen];
|
||||
|
@ -80,7 +80,7 @@ const unsigned char* Data::getData() const {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t Data::getLen() const {
|
||||
size_t Data::getLen() const {
|
||||
return len;
|
||||
}
|
||||
|
||||
|
|
10
src/Data.h
10
src/Data.h
|
@ -42,19 +42,19 @@ namespace aria2 {
|
|||
|
||||
class Data : public MetaEntry {
|
||||
private:
|
||||
int32_t len;
|
||||
size_t len;
|
||||
unsigned char* data;
|
||||
bool number;
|
||||
|
||||
void init(const unsigned char* data, int32_t len);
|
||||
void init(const unsigned char* data, size_t len);
|
||||
public:
|
||||
/**
|
||||
* This class stores the copy of data. So caller must take care of freeing
|
||||
* memory of data.
|
||||
*/
|
||||
Data(const char* data, int32_t len, bool number = false);
|
||||
Data(const char* data, size_t len, bool number = false);
|
||||
|
||||
Data(const unsigned char* data, int32_t len, bool number = false);
|
||||
Data(const unsigned char* data, size_t len, bool number = false);
|
||||
|
||||
Data(const std::string& data, bool number = false);
|
||||
|
||||
|
@ -65,7 +65,7 @@ public:
|
|||
int64_t toLLInt() const;
|
||||
|
||||
const unsigned char* getData() const;
|
||||
int32_t getLen() const;
|
||||
size_t getLen() const;
|
||||
bool isNumber() const;
|
||||
|
||||
void accept(MetaEntryVisitor* v) const;
|
||||
|
|
|
@ -129,13 +129,12 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
|
|||
} else {
|
||||
return "";
|
||||
}
|
||||
int32_t numWant = 50;
|
||||
if(!btRuntime->lessThanEqMinPeer() ||
|
||||
btRuntime->isHalt()) {
|
||||
unsigned int numWant = 50;
|
||||
if(!btRuntime->lessThanEqMinPeer() || btRuntime->isHalt()) {
|
||||
numWant = 0;
|
||||
}
|
||||
TransferStat stat = peerStorage->calculateStat();
|
||||
int64_t left = pieceStorage->getTotalLength()-pieceStorage->getCompletedLength();
|
||||
uint64_t left = pieceStorage->getTotalLength()-pieceStorage->getCompletedLength();
|
||||
if(left < 0) {
|
||||
left = 0;
|
||||
}
|
||||
|
@ -143,15 +142,15 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
|
|||
"info_hash="+Util::torrentUrlencode(btContext->getInfoHash(),
|
||||
btContext->getInfoHashLength())+"&"+
|
||||
"peer_id="+Util::torrentUrlencode(btContext->getPeerId(), 20)+"&"+
|
||||
"uploaded="+Util::itos(stat.getSessionUploadLength())+"&"+
|
||||
"downloaded="+Util::itos(stat.getSessionDownloadLength())+"&"+
|
||||
"left="+Util::itos(left)+"&"+
|
||||
"uploaded="+Util::uitos(stat.getSessionUploadLength())+"&"+
|
||||
"downloaded="+Util::uitos(stat.getSessionDownloadLength())+"&"+
|
||||
"left="+Util::uitos(left)+"&"+
|
||||
"compact=1"+"&"+
|
||||
"key="+key+"&"+
|
||||
"numwant="+Util::itos(numWant)+"&"+
|
||||
"numwant="+Util::uitos(numWant)+"&"+
|
||||
"no_peer_id=1";
|
||||
if(btRuntime->getListenPort() > 0) {
|
||||
url += std::string("&")+"port="+Util::itos(btRuntime->getListenPort());
|
||||
url += std::string("&")+"port="+Util::uitos(btRuntime->getListenPort());
|
||||
}
|
||||
std::string event = announceList.getEventString();
|
||||
if(!event.empty()) {
|
||||
|
@ -218,7 +217,7 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse,
|
|||
}
|
||||
const Data* intervalData = dynamic_cast<const Data*>(response->get("interval"));
|
||||
if(intervalData) {
|
||||
int32_t t = intervalData->toInt();
|
||||
time_t t = intervalData->toInt();
|
||||
if(t > 0) {
|
||||
interval = intervalData->toInt();
|
||||
logger->debug("Interval:%d", interval);
|
||||
|
@ -226,7 +225,7 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse,
|
|||
}
|
||||
const Data* minIntervalData = dynamic_cast<const Data*>(response->get("min interval"));
|
||||
if(minIntervalData) {
|
||||
int32_t t = minIntervalData->toInt();
|
||||
time_t t = minIntervalData->toInt();
|
||||
if(t > 0) {
|
||||
minInterval = minIntervalData->toInt();
|
||||
logger->debug("Min interval:%d", minInterval);
|
||||
|
@ -249,8 +248,7 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse,
|
|||
if(peersEntry &&
|
||||
!btRuntime->isHalt() &&
|
||||
btRuntime->lessThanMinPeer()) {
|
||||
DelegatingPeerListProcessor proc(btContext->getPieceLength(),
|
||||
btContext->getTotalLength());
|
||||
DelegatingPeerListProcessor proc;
|
||||
Peers peers = proc.extractPeer(peersEntry);
|
||||
peerStorage->addPeer(peers);
|
||||
}
|
||||
|
|
|
@ -54,12 +54,12 @@ class Randomizer;
|
|||
class DefaultBtAnnounce : public BtAnnounce {
|
||||
private:
|
||||
SharedHandle<BtContext> btContext;
|
||||
int32_t trackers;
|
||||
unsigned int trackers;
|
||||
Time prevAnnounceTime;
|
||||
int32_t interval;
|
||||
int32_t minInterval;
|
||||
int32_t complete;
|
||||
int32_t incomplete;
|
||||
time_t interval;
|
||||
time_t minInterval;
|
||||
unsigned int complete;
|
||||
unsigned int incomplete;
|
||||
AnnounceList announceList;
|
||||
std::string trackerId;
|
||||
std::string key;
|
||||
|
@ -118,22 +118,22 @@ public:
|
|||
|
||||
void setRandomizer(const SharedHandle<Randomizer>& randomizer);
|
||||
|
||||
int32_t getInterval() const
|
||||
time_t getInterval() const
|
||||
{
|
||||
return interval;
|
||||
}
|
||||
|
||||
int32_t getMinInterval() const
|
||||
time_t getMinInterval() const
|
||||
{
|
||||
return minInterval;
|
||||
}
|
||||
|
||||
int32_t getComplete() const
|
||||
unsigned int getComplete() const
|
||||
{
|
||||
return complete;
|
||||
}
|
||||
|
||||
int32_t getIncomplete() const
|
||||
unsigned int getIncomplete() const
|
||||
{
|
||||
return incomplete;
|
||||
}
|
||||
|
|
|
@ -101,8 +101,8 @@ void DefaultBtContext::clear() {
|
|||
void DefaultBtContext::extractPieceHash(const unsigned char* hashData,
|
||||
size_t hashDataLength,
|
||||
size_t hashLength) {
|
||||
int32_t numPieces = hashDataLength/hashLength;
|
||||
for(int32_t i = 0; i < numPieces; i++) {
|
||||
size_t numPieces = hashDataLength/hashLength;
|
||||
for(size_t i = 0; i < numPieces; i++) {
|
||||
pieceHashes.push_back(Util::toHex(&hashData[i*hashLength],
|
||||
hashLength));
|
||||
}
|
||||
|
|
|
@ -281,7 +281,7 @@ void DefaultBtInteractive::decideInterest() {
|
|||
}
|
||||
}
|
||||
|
||||
void DefaultBtInteractive::fillPiece(int maxPieceNum) {
|
||||
void DefaultBtInteractive::fillPiece(size_t maxPieceNum) {
|
||||
if(pieceStorage->hasMissingPiece(peer)) {
|
||||
if(peer->peerChoking()) {
|
||||
if(peer->isFastExtensionEnabled()) {
|
||||
|
@ -308,7 +308,7 @@ void DefaultBtInteractive::fillPiece(int maxPieceNum) {
|
|||
}
|
||||
|
||||
void DefaultBtInteractive::addRequests() {
|
||||
int32_t MAX_PENDING_REQUEST;
|
||||
size_t MAX_PENDING_REQUEST;
|
||||
if(peer->getLatency() < 500) {
|
||||
MAX_PENDING_REQUEST = 24;
|
||||
} else if(peer->getLatency() < 1500) {
|
||||
|
@ -316,16 +316,16 @@ void DefaultBtInteractive::addRequests() {
|
|||
} else {
|
||||
MAX_PENDING_REQUEST = 6;
|
||||
}
|
||||
int32_t pieceNum;
|
||||
size_t pieceNum;
|
||||
if(pieceStorage->isEndGame()) {
|
||||
pieceNum = 1;
|
||||
} else {
|
||||
int32_t blocks = DIV_FLOOR(btContext->getPieceLength(), Piece::BLOCK_LENGTH);
|
||||
size_t blocks = DIV_FLOOR(btContext->getPieceLength(), Piece::BLOCK_LENGTH);
|
||||
pieceNum = DIV_FLOOR(MAX_PENDING_REQUEST, blocks);
|
||||
}
|
||||
fillPiece(pieceNum);
|
||||
|
||||
int32_t reqNumToCreate =
|
||||
size_t reqNumToCreate =
|
||||
MAX_PENDING_REQUEST <= dispatcher->countOutstandingRequest() ?
|
||||
0 : MAX_PENDING_REQUEST-dispatcher->countOutstandingRequest();
|
||||
if(reqNumToCreate > 0) {
|
||||
|
@ -453,7 +453,7 @@ void DefaultBtInteractive::setLocalNode(const WeakHandle<DHTNode>& node)
|
|||
_localNode = node;
|
||||
}
|
||||
|
||||
int32_t DefaultBtInteractive::countPendingMessage()
|
||||
size_t DefaultBtInteractive::countPendingMessage()
|
||||
{
|
||||
return dispatcher->countMessageInQueue();
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "BtInteractive.h"
|
||||
#include "BtContextAwareCommand.h"
|
||||
#include "TimeA2.h"
|
||||
#include <limits.h>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -53,28 +54,28 @@ class Logger;
|
|||
|
||||
class FloodingStat {
|
||||
private:
|
||||
int32_t chokeUnchokeCount;
|
||||
int32_t keepAliveCount;
|
||||
unsigned int chokeUnchokeCount;
|
||||
unsigned int keepAliveCount;
|
||||
public:
|
||||
FloodingStat():chokeUnchokeCount(0), keepAliveCount(0) {}
|
||||
|
||||
void incChokeUnchokeCount() {
|
||||
if(chokeUnchokeCount < INT32_MAX) {
|
||||
if(chokeUnchokeCount < UINT_MAX) {
|
||||
chokeUnchokeCount++;
|
||||
}
|
||||
}
|
||||
|
||||
void incKeepAliveCount() {
|
||||
if(keepAliveCount < INT32_MAX) {
|
||||
if(keepAliveCount < UINT_MAX) {
|
||||
keepAliveCount++;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t getChokeUnchokeCount() const {
|
||||
unsigned int getChokeUnchokeCount() const {
|
||||
return chokeUnchokeCount;
|
||||
}
|
||||
|
||||
int32_t getKeepAliveCount() const {
|
||||
unsigned int getKeepAliveCount() const {
|
||||
return keepAliveCount;
|
||||
}
|
||||
|
||||
|
@ -98,21 +99,21 @@ private:
|
|||
WeakHandle<DHTNode> _localNode;
|
||||
|
||||
const Logger* logger;
|
||||
int32_t allowedFastSetSize;
|
||||
size_t allowedFastSetSize;
|
||||
Time haveCheckPoint;
|
||||
Time keepAliveCheckPoint;
|
||||
Time floodingCheckPoint;
|
||||
FloodingStat floodingStat;
|
||||
Time inactiveCheckPoint;
|
||||
Time _pexCheckPoint;
|
||||
int32_t keepAliveInterval;
|
||||
int32_t maxDownloadSpeedLimit;
|
||||
time_t keepAliveInterval;
|
||||
unsigned int maxDownloadSpeedLimit;
|
||||
bool _utPexEnabled;
|
||||
bool _dhtEnabled;
|
||||
|
||||
size_t _numReceivedMessage;
|
||||
|
||||
static const int32_t FLOODING_CHECK_INTERVAL = 5;
|
||||
static const time_t FLOODING_CHECK_INTERVAL = 5;
|
||||
|
||||
void addBitfieldMessageToQueue();
|
||||
void addAllowedFastMessageToQueue();
|
||||
|
@ -121,7 +122,7 @@ private:
|
|||
void checkHave();
|
||||
void sendKeepAlive();
|
||||
void decideInterest();
|
||||
void fillPiece(int maxPieceNum);
|
||||
void fillPiece(size_t maxPieceNum);
|
||||
void addRequests();
|
||||
void detectMessageFlooding();
|
||||
void checkActiveInteraction();
|
||||
|
@ -150,7 +151,7 @@ public:
|
|||
|
||||
size_t receiveMessages();
|
||||
|
||||
virtual int32_t countPendingMessage();
|
||||
virtual size_t countPendingMessage();
|
||||
|
||||
virtual bool isSendingMessageInProgress();
|
||||
|
||||
|
@ -174,11 +175,11 @@ public:
|
|||
|
||||
void setBtMessageFactory(const WeakHandle<BtMessageFactory>& factory);
|
||||
|
||||
void setKeepAliveInterval(int32_t keepAliveInterval) {
|
||||
void setKeepAliveInterval(time_t keepAliveInterval) {
|
||||
this->keepAliveInterval = keepAliveInterval;
|
||||
}
|
||||
|
||||
void setMaxDownloadSpeedLimit(int32_t maxDownloadSpeedLimit) {
|
||||
void setMaxDownloadSpeedLimit(unsigned int maxDownloadSpeedLimit) {
|
||||
this->maxDownloadSpeedLimit = maxDownloadSpeedLimit;
|
||||
}
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ void DefaultBtMessageDispatcher::sendMessages() {
|
|||
}
|
||||
|
||||
// Cancel sending piece message to peer.
|
||||
void DefaultBtMessageDispatcher::doCancelSendingPieceAction(int32_t index, int32_t begin, int32_t length)
|
||||
void DefaultBtMessageDispatcher::doCancelSendingPieceAction(size_t index, uint32_t begin, size_t length)
|
||||
{
|
||||
BtCancelSendingPieceEventHandle event =
|
||||
new BtCancelSendingPieceEvent(index, begin, length);
|
||||
|
@ -222,12 +222,12 @@ bool DefaultBtMessageDispatcher::isSendingInProgress()
|
|||
}
|
||||
}
|
||||
|
||||
int32_t DefaultBtMessageDispatcher::countOutstandingRequest()
|
||||
size_t DefaultBtMessageDispatcher::countOutstandingRequest()
|
||||
{
|
||||
return requestSlots.size();
|
||||
}
|
||||
|
||||
bool DefaultBtMessageDispatcher::isOutstandingRequest(int32_t index, int32_t blockIndex) {
|
||||
bool DefaultBtMessageDispatcher::isOutstandingRequest(size_t index, size_t blockIndex) {
|
||||
for(RequestSlots::const_iterator itr = requestSlots.begin();
|
||||
itr != requestSlots.end(); itr++) {
|
||||
const RequestSlot& slot = *itr;
|
||||
|
@ -239,7 +239,7 @@ bool DefaultBtMessageDispatcher::isOutstandingRequest(int32_t index, int32_t blo
|
|||
}
|
||||
|
||||
RequestSlot
|
||||
DefaultBtMessageDispatcher::getOutstandingRequest(int32_t index, int32_t begin, int32_t length)
|
||||
DefaultBtMessageDispatcher::getOutstandingRequest(size_t index, uint32_t begin, size_t length)
|
||||
{
|
||||
for(RequestSlots::iterator itr = requestSlots.begin();
|
||||
itr != requestSlots.end(); itr++) {
|
||||
|
|
|
@ -58,8 +58,8 @@ private:
|
|||
SharedHandle<PieceStorage> pieceStorage;
|
||||
WeakHandle<BtMessageFactory> messageFactory;
|
||||
SharedHandle<Peer> peer;
|
||||
int32_t maxUploadSpeedLimit;
|
||||
int32_t requestTimeout;
|
||||
unsigned int maxUploadSpeedLimit;
|
||||
time_t requestTimeout;
|
||||
const Logger* logger;
|
||||
public:
|
||||
DefaultBtMessageDispatcher();
|
||||
|
@ -72,7 +72,7 @@ public:
|
|||
|
||||
virtual void sendMessages();
|
||||
|
||||
virtual void doCancelSendingPieceAction(int32_t index, int32_t begin, int32_t length);
|
||||
virtual void doCancelSendingPieceAction(size_t index, uint32_t begin, size_t length);
|
||||
|
||||
virtual void doCancelSendingPieceAction(const SharedHandle<Piece>& piece);
|
||||
|
||||
|
@ -86,15 +86,15 @@ public:
|
|||
|
||||
virtual bool isSendingInProgress();
|
||||
|
||||
virtual int32_t countMessageInQueue() {
|
||||
virtual size_t countMessageInQueue() {
|
||||
return messageQueue.size();
|
||||
}
|
||||
|
||||
virtual int32_t countOutstandingRequest();
|
||||
virtual size_t countOutstandingRequest();
|
||||
|
||||
virtual bool isOutstandingRequest(int32_t index, int32_t blockIndex);
|
||||
virtual bool isOutstandingRequest(size_t index, size_t blockIndex);
|
||||
|
||||
virtual RequestSlot getOutstandingRequest(int32_t index, int32_t begin, int32_t length);
|
||||
virtual RequestSlot getOutstandingRequest(size_t index, uint32_t begin, size_t length);
|
||||
|
||||
virtual void removeOutstandingRequest(const RequestSlot& slot);
|
||||
|
||||
|
@ -114,11 +114,11 @@ public:
|
|||
this->cuid = cuid;
|
||||
}
|
||||
|
||||
void setMaxUploadSpeedLimit(int32_t maxUploadSpeedLimit) {
|
||||
void setMaxUploadSpeedLimit(unsigned int maxUploadSpeedLimit) {
|
||||
this->maxUploadSpeedLimit = maxUploadSpeedLimit;
|
||||
}
|
||||
|
||||
void setRequestTimeout(int32_t requestTimeout) {
|
||||
void setRequestTimeout(time_t requestTimeout) {
|
||||
this->requestTimeout = requestTimeout;
|
||||
}
|
||||
|
||||
|
|
|
@ -81,14 +81,14 @@ DefaultBtMessageFactory::DefaultBtMessageFactory():cuid(0),
|
|||
DefaultBtMessageFactory::~DefaultBtMessageFactory() {}
|
||||
|
||||
BtMessageHandle
|
||||
DefaultBtMessageFactory::createBtMessage(const unsigned char* data, int32_t dataLength)
|
||||
DefaultBtMessageFactory::createBtMessage(const unsigned char* data, size_t dataLength)
|
||||
{
|
||||
AbstractBtMessageHandle msg(0);
|
||||
if(dataLength == 0) {
|
||||
// keep-alive
|
||||
msg = new BtKeepAliveMessage();
|
||||
} else {
|
||||
int8_t id = PeerMessageUtil::getId(data);
|
||||
uint8_t id = PeerMessageUtil::getId(data);
|
||||
switch(id) {
|
||||
case BtChokeMessage::ID:
|
||||
msg = BtChokeMessage::create(data, dataLength);
|
||||
|
@ -194,7 +194,7 @@ DefaultBtMessageFactory::createBtMessage(const unsigned char* data, int32_t data
|
|||
break;
|
||||
}
|
||||
default:
|
||||
throw new DlAbortEx("Invalid message ID. id=%d", id);
|
||||
throw new DlAbortEx("Invalid message ID. id=%u", id);
|
||||
}
|
||||
}
|
||||
setCommonProperty(msg);
|
||||
|
@ -212,7 +212,7 @@ void DefaultBtMessageFactory::setCommonProperty(const AbstractBtMessageHandle& m
|
|||
}
|
||||
|
||||
BtMessageHandle
|
||||
DefaultBtMessageFactory::createHandshakeMessage(const unsigned char* data, int32_t dataLength)
|
||||
DefaultBtMessageFactory::createHandshakeMessage(const unsigned char* data, size_t dataLength)
|
||||
{
|
||||
SharedHandle<BtHandshakeMessage> msg = BtHandshakeMessage::create(data, dataLength);
|
||||
BtMessageValidatorHandle validator =
|
||||
|
@ -238,7 +238,7 @@ DefaultBtMessageFactory::createHandshakeMessage(const unsigned char* infoHash,
|
|||
}
|
||||
|
||||
BtMessageHandle
|
||||
DefaultBtMessageFactory::createRequestMessage(const PieceHandle& piece, int32_t blockIndex)
|
||||
DefaultBtMessageFactory::createRequestMessage(const PieceHandle& piece, size_t blockIndex)
|
||||
{
|
||||
BtRequestMessageHandle msg =
|
||||
new BtRequestMessage(piece->getIndex(),
|
||||
|
@ -255,7 +255,7 @@ DefaultBtMessageFactory::createRequestMessage(const PieceHandle& piece, int32_t
|
|||
}
|
||||
|
||||
BtMessageHandle
|
||||
DefaultBtMessageFactory::createCancelMessage(int32_t index, int32_t begin, int32_t length)
|
||||
DefaultBtMessageFactory::createCancelMessage(size_t index, uint32_t begin, size_t length)
|
||||
{
|
||||
BtCancelMessageHandle msg = new BtCancelMessage(index, begin, length);
|
||||
BtMessageValidatorHandle validator =
|
||||
|
@ -268,7 +268,7 @@ DefaultBtMessageFactory::createCancelMessage(int32_t index, int32_t begin, int32
|
|||
}
|
||||
|
||||
BtMessageHandle
|
||||
DefaultBtMessageFactory::createPieceMessage(int32_t index, int32_t begin, int32_t length)
|
||||
DefaultBtMessageFactory::createPieceMessage(size_t index, uint32_t begin, size_t length)
|
||||
{
|
||||
BtPieceMessageHandle msg = new BtPieceMessage(index, begin, length);
|
||||
BtMessageValidatorHandle validator =
|
||||
|
@ -281,7 +281,7 @@ DefaultBtMessageFactory::createPieceMessage(int32_t index, int32_t begin, int32_
|
|||
}
|
||||
|
||||
BtMessageHandle
|
||||
DefaultBtMessageFactory::createHaveMessage(int32_t index)
|
||||
DefaultBtMessageFactory::createHaveMessage(size_t index)
|
||||
{
|
||||
BtHaveMessageHandle msg = new BtHaveMessage(index);
|
||||
msg->setBtMessageValidator(new BtHaveMessageValidator(msg.get(),
|
||||
|
@ -359,7 +359,7 @@ DefaultBtMessageFactory::createHaveNoneMessage()
|
|||
}
|
||||
|
||||
BtMessageHandle
|
||||
DefaultBtMessageFactory::createRejectMessage(int32_t index, int32_t begin, int32_t length)
|
||||
DefaultBtMessageFactory::createRejectMessage(size_t index, uint32_t begin, size_t length)
|
||||
{
|
||||
BtRejectMessageHandle msg = new BtRejectMessage(index, begin, length);
|
||||
BtMessageValidatorHandle validator =
|
||||
|
@ -372,7 +372,7 @@ DefaultBtMessageFactory::createRejectMessage(int32_t index, int32_t begin, int32
|
|||
}
|
||||
|
||||
BtMessageHandle
|
||||
DefaultBtMessageFactory::createAllowedFastMessage(int32_t index)
|
||||
DefaultBtMessageFactory::createAllowedFastMessage(size_t index)
|
||||
{
|
||||
BtAllowedFastMessageHandle msg = new BtAllowedFastMessage(index);
|
||||
BtMessageValidatorHandle validator =
|
||||
|
|
|
@ -81,25 +81,25 @@ public:
|
|||
virtual ~DefaultBtMessageFactory();
|
||||
|
||||
virtual SharedHandle<BtMessage>
|
||||
createBtMessage(const unsigned char* msg, int32_t msgLength);
|
||||
createBtMessage(const unsigned char* msg, size_t msgLength);
|
||||
|
||||
virtual SharedHandle<BtMessage>
|
||||
createHandshakeMessage(const unsigned char* msg, int32_t msgLength);
|
||||
createHandshakeMessage(const unsigned char* msg, size_t msgLength);
|
||||
|
||||
virtual SharedHandle<BtMessage>
|
||||
createHandshakeMessage(const unsigned char* infoHash,
|
||||
const unsigned char* peerId);
|
||||
|
||||
virtual SharedHandle<BtMessage>
|
||||
createRequestMessage(const SharedHandle<Piece>& piece, int32_t blockIndex);
|
||||
createRequestMessage(const SharedHandle<Piece>& piece, size_t blockIndex);
|
||||
|
||||
virtual SharedHandle<BtMessage>
|
||||
createCancelMessage(int32_t index, int32_t begin, int32_t length);
|
||||
createCancelMessage(size_t index, uint32_t begin, size_t length);
|
||||
|
||||
virtual SharedHandle<BtMessage>
|
||||
createPieceMessage(int32_t index, int32_t begin, int32_t length);
|
||||
createPieceMessage(size_t index, uint32_t begin, size_t length);
|
||||
|
||||
virtual SharedHandle<BtMessage> createHaveMessage(int32_t index);
|
||||
virtual SharedHandle<BtMessage> createHaveMessage(size_t index);
|
||||
|
||||
virtual SharedHandle<BtMessage> createChokeMessage();
|
||||
|
||||
|
@ -118,9 +118,9 @@ public:
|
|||
virtual SharedHandle<BtMessage> createHaveNoneMessage();
|
||||
|
||||
virtual SharedHandle<BtMessage>
|
||||
createRejectMessage(int32_t index, int32_t begin, int32_t length);
|
||||
createRejectMessage(size_t index, uint32_t begin, size_t length);
|
||||
|
||||
virtual SharedHandle<BtMessage> createAllowedFastMessage(int32_t index);
|
||||
virtual SharedHandle<BtMessage> createAllowedFastMessage(size_t index);
|
||||
|
||||
virtual SharedHandle<BtMessage> createPortMessage(uint16_t port);
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ DefaultBtMessageReceiver::~DefaultBtMessageReceiver()
|
|||
|
||||
BtMessageHandle DefaultBtMessageReceiver::receiveHandshake(bool quickReply) {
|
||||
unsigned char data[BtHandshakeMessage::MESSAGE_LENGTH];
|
||||
int32_t dataLength = BtHandshakeMessage::MESSAGE_LENGTH;
|
||||
size_t dataLength = BtHandshakeMessage::MESSAGE_LENGTH;
|
||||
bool retval = peerConnection->receiveHandshake(data, dataLength);
|
||||
// To handle tracker's NAT-checking feature
|
||||
if(!handshakeSent && quickReply && dataLength >= 48) {
|
||||
|
@ -99,7 +99,7 @@ void DefaultBtMessageReceiver::sendHandshake() {
|
|||
|
||||
BtMessageHandle DefaultBtMessageReceiver::receiveMessage() {
|
||||
unsigned char data[MAX_PAYLOAD_LEN];
|
||||
int32_t dataLength = 0;
|
||||
size_t dataLength = 0;
|
||||
if(!peerConnection->receiveMessage(data, dataLength)) {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ public:
|
|||
|
||||
virtual void removeAllTargetPiece();
|
||||
|
||||
virtual int32_t countTargetPiece() {
|
||||
virtual size_t countTargetPiece() {
|
||||
return pieces.size();
|
||||
}
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue