mirror of https://github.com/aria2/aria2
2007-07-21 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Converted int's to in32_t. long long int's are also converted to int64_tpull/1/head
parent
cd6b6e3591
commit
6574e44f88
|
@ -1,3 +1,8 @@
|
||||||
|
2007-07-21 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
|
Converted int's to in32_t. long long int's are also converted to
|
||||||
|
int64_t
|
||||||
|
|
||||||
2007-07-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
2007-07-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
Fixed the bug that prevents cookies from being sent to the server
|
Fixed the bug that prevents cookies from being sent to the server
|
||||||
|
|
8
TODO
8
TODO
|
@ -25,3 +25,11 @@
|
||||||
* consider life cycle of requestGroup and segmentMan
|
* consider life cycle of requestGroup and segmentMan
|
||||||
* exit status: all downloads have been successful-> EXIT_SUCCESS,
|
* exit status: all downloads have been successful-> EXIT_SUCCESS,
|
||||||
some of downloads have been failed -> EXIT_FAILURE
|
some of downloads have been failed -> EXIT_FAILURE
|
||||||
|
|
||||||
|
* Fix log and stdout message in Metalink related class.
|
||||||
|
* Fix Cookie header's value. ';' is not necessary at the end of it.
|
||||||
|
* It is possible to replace all %lld to %s, using Util::llitos(...) ?.
|
||||||
|
* Time::getTimeInMillis() returns int64_t.
|
||||||
|
* Util::secfmt, What happens if sec is less than 0?
|
||||||
|
* Rewrite ChunkedEncoding
|
||||||
|
* typedef int32_t CUID in common.h or a2types.h
|
|
@ -43,7 +43,7 @@
|
||||||
#include "DNSCache.h"
|
#include "DNSCache.h"
|
||||||
#include "FatalException.h"
|
#include "FatalException.h"
|
||||||
|
|
||||||
AbstractCommand::AbstractCommand(int cuid,
|
AbstractCommand::AbstractCommand(int32_t cuid,
|
||||||
const RequestHandle& req,
|
const RequestHandle& req,
|
||||||
RequestGroup* requestGroup,
|
RequestGroup* requestGroup,
|
||||||
DownloadEngine* e,
|
DownloadEngine* e,
|
||||||
|
@ -147,7 +147,7 @@ void AbstractCommand::tryReserved() {
|
||||||
e->addCommand(commands);
|
e->addCommand(commands);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AbstractCommand::prepareForRetry(int wait) {
|
bool AbstractCommand::prepareForRetry(int32_t wait) {
|
||||||
_requestGroup->getSegmentMan()->cancelSegment(cuid);
|
_requestGroup->getSegmentMan()->cancelSegment(cuid);
|
||||||
Command* command = InitiateConnectionCommandFactory::createInitiateConnectionCommand(cuid, req, _requestGroup, e);
|
Command* command = InitiateConnectionCommandFactory::createInitiateConnectionCommand(cuid, req, _requestGroup, e);
|
||||||
if(wait == 0) {
|
if(wait == 0) {
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
class AbstractCommand : public Command {
|
class AbstractCommand : public Command {
|
||||||
private:
|
private:
|
||||||
Time checkPoint;
|
Time checkPoint;
|
||||||
int timeout;
|
int32_t timeout;
|
||||||
protected:
|
protected:
|
||||||
RequestHandle req;
|
RequestHandle req;
|
||||||
RequestGroup* _requestGroup;
|
RequestGroup* _requestGroup;
|
||||||
|
@ -55,7 +55,7 @@ protected:
|
||||||
SegmentHandle segment;
|
SegmentHandle segment;
|
||||||
|
|
||||||
void tryReserved();
|
void tryReserved();
|
||||||
virtual bool prepareForRetry(int wait);
|
virtual bool prepareForRetry(int32_t wait);
|
||||||
virtual void onAbort(Exception* ex);
|
virtual void onAbort(Exception* ex);
|
||||||
virtual bool executeInternal() = 0;
|
virtual bool executeInternal() = 0;
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ protected:
|
||||||
void disableNameResolverCheck(const NameResolverHandle& resolver);
|
void disableNameResolverCheck(const NameResolverHandle& resolver);
|
||||||
virtual bool nameResolveFinished() const;
|
virtual bool nameResolveFinished() const;
|
||||||
#endif // ENABLE_ASYNC_DNS
|
#endif // ENABLE_ASYNC_DNS
|
||||||
void setTimeout(int timeout) { this->timeout = timeout; }
|
void setTimeout(int32_t timeout) { this->timeout = timeout; }
|
||||||
private:
|
private:
|
||||||
bool checkSocketIsReadable;
|
bool checkSocketIsReadable;
|
||||||
bool checkSocketIsWritable;
|
bool checkSocketIsWritable;
|
||||||
|
@ -77,7 +77,7 @@ private:
|
||||||
SocketHandle writeCheckTarget;
|
SocketHandle writeCheckTarget;
|
||||||
bool nameResolverCheck;
|
bool nameResolverCheck;
|
||||||
public:
|
public:
|
||||||
AbstractCommand(int cuid, const RequestHandle& req, RequestGroup* requestGroup, DownloadEngine* e, const SocketHandle& s = SocketHandle());
|
AbstractCommand(int32_t cuid, const RequestHandle& req, RequestGroup* requestGroup, DownloadEngine* e, const SocketHandle& s = SocketHandle());
|
||||||
virtual ~AbstractCommand();
|
virtual ~AbstractCommand();
|
||||||
bool execute();
|
bool execute();
|
||||||
};
|
};
|
||||||
|
|
|
@ -176,11 +176,11 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
int AnnounceList::countStoppedAllowedTier() const {
|
int32_t AnnounceList::countStoppedAllowedTier() const {
|
||||||
return count_if(tiers.begin(), tiers.end(), FindStoppedAllowedTier());
|
return count_if(tiers.begin(), tiers.end(), FindStoppedAllowedTier());
|
||||||
}
|
}
|
||||||
|
|
||||||
int AnnounceList::countCompletedAllowedTier() const {
|
int32_t AnnounceList::countCompletedAllowedTier() const {
|
||||||
return count_if(tiers.begin(), tiers.end(), FindCompletedAllowedTier());
|
return count_if(tiers.begin(), tiers.end(), FindCompletedAllowedTier());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ public:
|
||||||
void reconfigure(const MetaEntry* announceListEntry);
|
void reconfigure(const MetaEntry* announceListEntry);
|
||||||
void reconfigure(const string& url);
|
void reconfigure(const string& url);
|
||||||
|
|
||||||
int countTier() const {
|
int32_t countTier() const {
|
||||||
return tiers.size();
|
return tiers.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,12 +98,12 @@ public:
|
||||||
/**
|
/**
|
||||||
* Counts the number of tiers to which the "stopped" event can be sent.
|
* Counts the number of tiers to which the "stopped" event can be sent.
|
||||||
*/
|
*/
|
||||||
int countStoppedAllowedTier() const;
|
int32_t countStoppedAllowedTier() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Counts the number of tiers to which the "completed" event can be sent.
|
* Counts the number of tiers to which the "completed" event can be sent.
|
||||||
*/
|
*/
|
||||||
int countCompletedAllowedTier() const;
|
int32_t countCompletedAllowedTier() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves current tier pointer to the tier to which the "stopped" event can
|
* Moves current tier pointer to the tier to which the "stopped" event can
|
||||||
|
|
|
@ -45,34 +45,34 @@ static char base64_table[64] = {
|
||||||
'4', '5', '6', '7', '8', '9', '+', '/',
|
'4', '5', '6', '7', '8', '9', '+', '/',
|
||||||
};
|
};
|
||||||
|
|
||||||
void Base64::part_encode(const unsigned char* sub, int subLength,
|
void Base64::part_encode(const unsigned char* sub, int32_t subLength,
|
||||||
unsigned char* buf)
|
unsigned char* buf)
|
||||||
{
|
{
|
||||||
int shift = 2;
|
int32_t shift = 2;
|
||||||
unsigned char carry = 0;
|
unsigned char carry = 0;
|
||||||
int index;
|
int32_t index;
|
||||||
for(index = 0; index < subLength; index++) {
|
for(index = 0; index < subLength; index++) {
|
||||||
unsigned char cur = sub[index] >> shift | carry;
|
unsigned char cur = sub[index] >> shift | carry;
|
||||||
carry = (sub[index] << (6-shift)) & 0x3f;
|
carry = (sub[index] << (6-shift)) & 0x3f;
|
||||||
shift += 2;
|
shift += 2;
|
||||||
buf[index] = base64_table[(unsigned int)cur];
|
buf[index] = base64_table[(uint32_t)cur];
|
||||||
}
|
}
|
||||||
if(subLength == 1) {
|
if(subLength == 1) {
|
||||||
buf[index] = base64_table[(unsigned int)carry];
|
buf[index] = base64_table[(uint32_t)carry];
|
||||||
buf[index+1] = buf[index+2] = '=';
|
buf[index+1] = buf[index+2] = '=';
|
||||||
} else if(subLength == 2) {
|
} else if(subLength == 2) {
|
||||||
buf[index] = base64_table[(unsigned int)carry];
|
buf[index] = base64_table[(uint32_t)carry];
|
||||||
buf[index+1] = '=';
|
buf[index+1] = '=';
|
||||||
} else {
|
} else {
|
||||||
unsigned char cur = sub[subLength-1] & 0x3f;
|
unsigned char cur = sub[subLength-1] & 0x3f;
|
||||||
buf[index] = base64_table[(unsigned int)cur];
|
buf[index] = base64_table[(uint32_t)cur];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string Base64::encode(const string& plainSrc)
|
string Base64::encode(const string& plainSrc)
|
||||||
{
|
{
|
||||||
unsigned char* result = 0;
|
unsigned char* result = 0;
|
||||||
int resultLength = 0;
|
int32_t resultLength = 0;
|
||||||
|
|
||||||
encode((const unsigned char*)plainSrc.c_str(), plainSrc.size(),
|
encode((const unsigned char*)plainSrc.c_str(), plainSrc.size(),
|
||||||
result, resultLength);
|
result, resultLength);
|
||||||
|
@ -81,12 +81,12 @@ string Base64::encode(const string& plainSrc)
|
||||||
return encoded;
|
return encoded;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Base64::encode(const unsigned char* src, int srcLength,
|
void Base64::encode(const unsigned char* src, int32_t srcLength,
|
||||||
unsigned char*& result, int& resultLength) {
|
unsigned char*& result, int32_t& resultLength) {
|
||||||
resultLength = (srcLength+(srcLength%3 == 0 ? 0 : 3-srcLength%3))/3*4;
|
resultLength = (srcLength+(srcLength%3 == 0 ? 0 : 3-srcLength%3))/3*4;
|
||||||
result = new unsigned char[resultLength];
|
result = new unsigned char[resultLength];
|
||||||
unsigned char* tail = result;
|
unsigned char* tail = result;
|
||||||
for(int index = 0; srcLength > index; index += 3) {
|
for(int32_t index = 0; srcLength > index; index += 3) {
|
||||||
unsigned char temp[4];
|
unsigned char temp[4];
|
||||||
part_encode(&src[index],
|
part_encode(&src[index],
|
||||||
srcLength >= index+3 ? 3 : srcLength-index,
|
srcLength >= index+3 ? 3 : srcLength-index,
|
||||||
|
@ -119,10 +119,10 @@ char Base64::getValue(char ch)
|
||||||
|
|
||||||
string Base64::part_decode(const string& subCrypted)
|
string Base64::part_decode(const string& subCrypted)
|
||||||
{
|
{
|
||||||
int shift = 2;
|
int32_t shift = 2;
|
||||||
string plain;
|
string plain;
|
||||||
|
|
||||||
for(unsigned int index = 0; index < subCrypted.size()-1; ++index) {
|
for(uint32_t index = 0; index < subCrypted.size()-1; ++index) {
|
||||||
if(subCrypted.at(index) == '=') break;
|
if(subCrypted.at(index) == '=') break;
|
||||||
char cur = getValue(subCrypted.at(index)) << shift;
|
char cur = getValue(subCrypted.at(index)) << shift;
|
||||||
char carry = getValue(subCrypted.at(index+1)) >> (6-shift);
|
char carry = getValue(subCrypted.at(index+1)) >> (6-shift);
|
||||||
|
@ -136,8 +136,8 @@ string Base64::part_decode(const string& subCrypted)
|
||||||
string Base64::decode(const string& crypted)
|
string Base64::decode(const string& crypted)
|
||||||
{
|
{
|
||||||
string plain;
|
string plain;
|
||||||
int sIndex = 0;
|
int32_t sIndex = 0;
|
||||||
for(int index = 0; crypted.size() > (unsigned int)index; index +=4) {
|
for(int32_t index = 0; crypted.size() > (uint32_t)index; index +=4) {
|
||||||
string subCrypted = crypted.substr(sIndex, 4);
|
string subCrypted = crypted.substr(sIndex, 4);
|
||||||
string subPlain = part_decode(subCrypted);
|
string subPlain = part_decode(subCrypted);
|
||||||
sIndex += 4;
|
sIndex += 4;
|
||||||
|
|
10
src/Base64.h
10
src/Base64.h
|
@ -41,7 +41,7 @@ using namespace std;
|
||||||
class Base64
|
class Base64
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
static void part_encode(const unsigned char* sub, int subLength,
|
static void part_encode(const unsigned char* sub, int32_t subLength,
|
||||||
unsigned char* buf);
|
unsigned char* buf);
|
||||||
|
|
||||||
static string part_encode(const string& subplain);
|
static string part_encode(const string& subplain);
|
||||||
|
@ -50,12 +50,12 @@ private:
|
||||||
public:
|
public:
|
||||||
static string encode(const string& plain);
|
static string encode(const string& plain);
|
||||||
// caller must deallocate the memory used by result.
|
// caller must deallocate the memory used by result.
|
||||||
static void encode(const unsigned char* src, int srcLength,
|
static void encode(const unsigned char* src, int32_t srcLength,
|
||||||
unsigned char*& result, int& resultLength);
|
unsigned char*& result, int32_t& resultLength);
|
||||||
static string decode(const string& crypted);
|
static string decode(const string& crypted);
|
||||||
// caller must deallocate the memory used by result.
|
// caller must deallocate the memory used by result.
|
||||||
static void decode(const unsigned char* src, int srcLength,
|
static void decode(const unsigned char* src, int32_t srcLength,
|
||||||
unsigned char*& result, int& resultLength);
|
unsigned char*& result, int32_t& resultLength);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _BASE64_H_
|
#endif // _BASE64_H_
|
||||||
|
|
|
@ -60,7 +60,7 @@ public:
|
||||||
return factory;
|
return factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
BitfieldMan* createBitfieldMan(int blockLength, long long int totalLength) {
|
BitfieldMan* createBitfieldMan(int32_t blockLength, int64_t totalLength) {
|
||||||
BitfieldMan* bitfieldMan = new BitfieldMan(blockLength, totalLength);
|
BitfieldMan* bitfieldMan = new BitfieldMan(blockLength, totalLength);
|
||||||
bitfieldMan->setRandomizer(randomizer);
|
bitfieldMan->setRandomizer(randomizer);
|
||||||
return bitfieldMan;
|
return bitfieldMan;
|
||||||
|
|
|
@ -41,10 +41,10 @@
|
||||||
class BtBitfieldMessageValidator : public BtMessageValidator {
|
class BtBitfieldMessageValidator : public BtMessageValidator {
|
||||||
private:
|
private:
|
||||||
const BtBitfieldMessage* message;
|
const BtBitfieldMessage* message;
|
||||||
int numPiece;
|
int32_t numPiece;
|
||||||
public:
|
public:
|
||||||
BtBitfieldMessageValidator(const BtBitfieldMessage* message,
|
BtBitfieldMessageValidator(const BtBitfieldMessage* message,
|
||||||
int numPiece):
|
int32_t numPiece):
|
||||||
message(message),
|
message(message),
|
||||||
numPiece(numPiece) {}
|
numPiece(numPiece) {}
|
||||||
|
|
||||||
|
|
|
@ -42,10 +42,10 @@
|
||||||
class BtHaveMessageValidator : public BtMessageValidator {
|
class BtHaveMessageValidator : public BtMessageValidator {
|
||||||
private:
|
private:
|
||||||
const BtHaveMessage* message;
|
const BtHaveMessage* message;
|
||||||
int numPiece;
|
int32_t numPiece;
|
||||||
public:
|
public:
|
||||||
BtHaveMessageValidator(const BtHaveMessage* message,
|
BtHaveMessageValidator(const BtHaveMessage* message,
|
||||||
int numPiece):
|
int32_t numPiece):
|
||||||
message(message),
|
message(message),
|
||||||
numPiece(numPiece) {}
|
numPiece(numPiece) {}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ public:
|
||||||
|
|
||||||
virtual void removeAllTargetPiece() = 0;
|
virtual void removeAllTargetPiece() = 0;
|
||||||
|
|
||||||
virtual int countTargetPiece() = 0;
|
virtual int32_t countTargetPiece() = 0;
|
||||||
|
|
||||||
virtual void removeCompletedPiece() = 0;
|
virtual void removeCompletedPiece() = 0;
|
||||||
|
|
||||||
|
|
|
@ -42,10 +42,10 @@
|
||||||
|
|
||||||
class BtRuntime {
|
class BtRuntime {
|
||||||
private:
|
private:
|
||||||
long long int uploadLengthAtStartup;
|
int64_t uploadLengthAtStartup;
|
||||||
int port;
|
int32_t port;
|
||||||
bool halt;
|
bool halt;
|
||||||
int connections;
|
int32_t connections;
|
||||||
public:
|
public:
|
||||||
BtRuntime():
|
BtRuntime():
|
||||||
uploadLengthAtStartup(0),
|
uploadLengthAtStartup(0),
|
||||||
|
@ -55,19 +55,19 @@ public:
|
||||||
{}
|
{}
|
||||||
~BtRuntime() {}
|
~BtRuntime() {}
|
||||||
|
|
||||||
long long int getUploadLengthAtStartup() const {
|
int64_t getUploadLengthAtStartup() const {
|
||||||
return uploadLengthAtStartup;
|
return uploadLengthAtStartup;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setUploadLengthAtStartup(long long int length) {
|
void setUploadLengthAtStartup(int64_t length) {
|
||||||
this->uploadLengthAtStartup = length;
|
this->uploadLengthAtStartup = length;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setListenPort(int port) {
|
void setListenPort(int32_t port) {
|
||||||
this->port = port;
|
this->port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getListenPort() const { return port; }
|
int32_t getListenPort() const { return port; }
|
||||||
|
|
||||||
bool isHalt() const { return halt; }
|
bool isHalt() const { return halt; }
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ public:
|
||||||
this->halt = halt;
|
this->halt = halt;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getConnections() const { return connections; }
|
int32_t getConnections() const { return connections; }
|
||||||
|
|
||||||
void increaseConnections() { connections++; }
|
void increaseConnections() { connections++; }
|
||||||
|
|
||||||
|
|
|
@ -41,10 +41,10 @@
|
||||||
class BtSuggestPieceMessageValidator : public BtMessageValidator {
|
class BtSuggestPieceMessageValidator : public BtMessageValidator {
|
||||||
private:
|
private:
|
||||||
const BtSuggestPieceMessage* message;
|
const BtSuggestPieceMessage* message;
|
||||||
int numPiece;
|
int32_t numPiece;
|
||||||
public:
|
public:
|
||||||
BtSuggestPieceMessageValidator(const BtSuggestPieceMessage* message,
|
BtSuggestPieceMessageValidator(const BtSuggestPieceMessage* message,
|
||||||
int numPiece):
|
int32_t numPiece):
|
||||||
message(message),
|
message(message),
|
||||||
numPiece(numPiece) {}
|
numPiece(numPiece) {}
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ void ByteArrayDiskWriter::writeData(const char* data, int32_t dataLength, int64_
|
||||||
buf.write(data, dataLength);
|
buf.write(data, dataLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ByteArrayDiskWriter::readData(char* data, int32_t len, int64_t position) {
|
int32_t ByteArrayDiskWriter::readData(char* data, int32_t len, int64_t position) {
|
||||||
buf.seekg(position, ios_base::beg);
|
buf.seekg(position, ios_base::beg);
|
||||||
buf.read(data, len);
|
buf.read(data, len);
|
||||||
// TODO we have to call buf.clear() here? YES
|
// TODO we have to call buf.clear() here? YES
|
||||||
|
|
|
@ -57,7 +57,7 @@ public:
|
||||||
|
|
||||||
// position is ignored
|
// position is ignored
|
||||||
virtual void writeData(const char* data, int32_t len, int64_t position = 0);
|
virtual void writeData(const char* data, int32_t len, int64_t position = 0);
|
||||||
virtual int readData(char* data, int32_t len, int64_t position);
|
virtual int32_t readData(char* data, int32_t len, int64_t position);
|
||||||
|
|
||||||
// Not implemented yet
|
// Not implemented yet
|
||||||
virtual void truncate(int64_t length) {}
|
virtual void truncate(int64_t length) {}
|
||||||
|
|
|
@ -64,10 +64,10 @@ bool ChunkedEncoding::finished() {
|
||||||
|
|
||||||
void ChunkedEncoding::end() {}
|
void ChunkedEncoding::end() {}
|
||||||
|
|
||||||
void ChunkedEncoding::inflate(char* outbuf, int& outlen, const char* inbuf, int inlen) {
|
void ChunkedEncoding::inflate(char* outbuf, int32_t& outlen, const char* inbuf, int32_t inlen) {
|
||||||
addBuffer(inbuf, inlen);
|
addBuffer(inbuf, inlen);
|
||||||
char* p = strbuf;
|
char* p = strbuf;
|
||||||
int clen = 0;
|
int32_t clen = 0;
|
||||||
while(1) {
|
while(1) {
|
||||||
if(state == READ_SIZE) {
|
if(state == READ_SIZE) {
|
||||||
if(readChunkSize(&p) == 0) {
|
if(readChunkSize(&p) == 0) {
|
||||||
|
@ -98,7 +98,7 @@ void ChunkedEncoding::inflate(char* outbuf, int& outlen, const char* inbuf, int
|
||||||
strbufTail = strbuf;
|
strbufTail = strbuf;
|
||||||
} else {
|
} else {
|
||||||
// copy string between [p, strbufTail]
|
// copy string between [p, strbufTail]
|
||||||
int unreadSize = strbufTail-p;
|
int32_t unreadSize = strbufTail-p;
|
||||||
char* temp = new char[strbufSize];
|
char* temp = new char[strbufSize];
|
||||||
memcpy(temp, p, unreadSize);
|
memcpy(temp, p, unreadSize);
|
||||||
delete [] strbuf;
|
delete [] strbuf;
|
||||||
|
@ -108,14 +108,14 @@ void ChunkedEncoding::inflate(char* outbuf, int& outlen, const char* inbuf, int
|
||||||
outlen = clen;
|
outlen = clen;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ChunkedEncoding::readData(char** pp, char* buf, int& len, int maxlen) {
|
int32_t ChunkedEncoding::readData(char** pp, char* buf, int32_t& len, int32_t maxlen) {
|
||||||
if(buf+len == buf+maxlen) {
|
if(buf+len == buf+maxlen) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(chunkSize == 0) {
|
if(chunkSize == 0) {
|
||||||
return readDataEOL(pp);
|
return readDataEOL(pp);
|
||||||
}
|
}
|
||||||
int wsize;
|
int32_t wsize;
|
||||||
if(strbufTail-*pp < chunkSize) {
|
if(strbufTail-*pp < chunkSize) {
|
||||||
wsize = strbufTail-*pp <= maxlen-len ? strbufTail-*pp : maxlen-len;
|
wsize = strbufTail-*pp <= maxlen-len ? strbufTail-*pp : maxlen-len;
|
||||||
} else {
|
} else {
|
||||||
|
@ -132,7 +132,7 @@ int ChunkedEncoding::readData(char** pp, char* buf, int& len, int maxlen) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ChunkedEncoding::readDataEOL(char** pp) {
|
int32_t ChunkedEncoding::readDataEOL(char** pp) {
|
||||||
char* np = (char*)memchr(*pp, '\n', strbufTail-*pp);
|
char* np = (char*)memchr(*pp, '\n', strbufTail-*pp);
|
||||||
char* rp = (char*)memchr(*pp, '\r', strbufTail-*pp);
|
char* rp = (char*)memchr(*pp, '\r', strbufTail-*pp);
|
||||||
if(np != NULL && rp != NULL && np-rp == 1 && *pp == rp) {
|
if(np != NULL && rp != NULL && np-rp == 1 && *pp == rp) {
|
||||||
|
@ -145,7 +145,7 @@ int ChunkedEncoding::readDataEOL(char** pp) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ChunkedEncoding::readChunkSize(char** pp) {
|
int32_t ChunkedEncoding::readChunkSize(char** pp) {
|
||||||
// we read chunk-size from *pp
|
// we read chunk-size from *pp
|
||||||
char* p;
|
char* p;
|
||||||
char* np = (char*)memchr(*pp, '\n', strbufTail-*pp);
|
char* np = (char*)memchr(*pp, '\n', strbufTail-*pp);
|
||||||
|
@ -170,15 +170,15 @@ int ChunkedEncoding::readChunkSize(char** pp) {
|
||||||
delete [] temp;
|
delete [] temp;
|
||||||
if(chunkSize < 0) {
|
if(chunkSize < 0) {
|
||||||
throw new DlAbortEx(EX_INVALID_CHUNK_SIZE);
|
throw new DlAbortEx(EX_INVALID_CHUNK_SIZE);
|
||||||
} else if(errno == ERANGE && (chunkSize == LONG_MAX || chunkSize == LONG_MIN)) {
|
} else if(errno == ERANGE && (chunkSize == INT32_MAX || chunkSize == INT32_MIN)) {
|
||||||
throw new DlAbortEx(strerror(errno));
|
throw new DlAbortEx(strerror(errno));
|
||||||
}
|
}
|
||||||
*pp = p+2;
|
*pp = p+2;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChunkedEncoding::addBuffer(const char* inbuf, int inlen) {
|
void ChunkedEncoding::addBuffer(const char* inbuf, int32_t inlen) {
|
||||||
int realbufSize = strbufTail-strbuf;
|
int32_t realbufSize = strbufTail-strbuf;
|
||||||
if(realbufSize+inlen >= strbufSize) {
|
if(realbufSize+inlen >= strbufSize) {
|
||||||
if(realbufSize+inlen > MAX_BUFSIZE) {
|
if(realbufSize+inlen > MAX_BUFSIZE) {
|
||||||
throw new DlAbortEx(EX_TOO_LARGE_CHUNK, realbufSize+inlen);
|
throw new DlAbortEx(EX_TOO_LARGE_CHUNK, realbufSize+inlen);
|
||||||
|
|
|
@ -44,16 +44,20 @@ private:
|
||||||
READ_DATA,
|
READ_DATA,
|
||||||
FINISH
|
FINISH
|
||||||
};
|
};
|
||||||
long int chunkSize;
|
int32_t chunkSize;
|
||||||
int state;
|
int32_t state;
|
||||||
char* strbuf;
|
char* strbuf;
|
||||||
int strbufSize;
|
int32_t strbufSize;
|
||||||
char* strbufTail;
|
char* strbufTail;
|
||||||
|
|
||||||
int readChunkSize(char** pp);
|
/**
|
||||||
int readData(char** pp, char* buf, int& len, int maxlen);
|
* Returns 0 if the size of chunk is retrieved successfully,
|
||||||
void addBuffer(const char* inbuf, int inlen);
|
* otherwise returns non-zero value.
|
||||||
int readDataEOL(char** pp);
|
*/
|
||||||
|
int32_t readChunkSize(char** pp);
|
||||||
|
int32_t readData(char** pp, char* buf, int32_t& len, int32_t maxlen);
|
||||||
|
void addBuffer(const char* inbuf, int32_t inlen);
|
||||||
|
int32_t readDataEOL(char** pp);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -61,7 +65,7 @@ public:
|
||||||
~ChunkedEncoding();
|
~ChunkedEncoding();
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void inflate(char* outbuf, int& outlen, const char* inbuf, int inlen);
|
void inflate(char* outbuf, int32_t& outlen, const char* inbuf, int32_t inlen);
|
||||||
bool finished();
|
bool finished();
|
||||||
void end();
|
void end();
|
||||||
};
|
};
|
||||||
|
|
|
@ -34,4 +34,4 @@
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "Command.h"
|
#include "Command.h"
|
||||||
|
|
||||||
int Command::uuidGen = 0;
|
int32_t Command::uuidGen = 0;
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "LogFactory.h"
|
#include "LogFactory.h"
|
||||||
|
|
||||||
typedef int CommandUuid;
|
typedef int32_t CommandUuid;
|
||||||
|
|
||||||
class Command {
|
class Command {
|
||||||
public:
|
public:
|
||||||
|
@ -50,19 +50,19 @@ public:
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
CommandUuid uuid;
|
CommandUuid uuid;
|
||||||
static int uuidGen;
|
static int32_t uuidGen;
|
||||||
STATUS status;
|
STATUS status;
|
||||||
protected:
|
protected:
|
||||||
int cuid;
|
int32_t cuid;
|
||||||
const Logger* logger;
|
const Logger* logger;
|
||||||
public:
|
public:
|
||||||
Command(int cuid):uuid(uuidGen++), status(STATUS_INACTIVE), cuid(cuid) {
|
Command(int32_t cuid):uuid(uuidGen++), status(STATUS_INACTIVE), cuid(cuid) {
|
||||||
logger = LogFactory::getInstance();
|
logger = LogFactory::getInstance();
|
||||||
}
|
}
|
||||||
virtual ~Command() {}
|
virtual ~Command() {}
|
||||||
virtual bool execute() = 0;
|
virtual bool execute() = 0;
|
||||||
|
|
||||||
int getCuid() const { return cuid; }
|
int32_t getCuid() const { return cuid; }
|
||||||
const CommandUuid& getUuid() const { return uuid; }
|
const CommandUuid& getUuid() const { return uuid; }
|
||||||
|
|
||||||
void setStatusActive() { this->status = STATUS_ACTIVE; }
|
void setStatusActive() { this->status = STATUS_ACTIVE; }
|
||||||
|
|
|
@ -44,18 +44,17 @@ Peers CompactPeerListProcessor::extractPeer(const MetaEntry* peersEntry) {
|
||||||
|
|
||||||
const Data* peersData = (const Data*)peersEntry;
|
const Data* peersData = (const Data*)peersEntry;
|
||||||
if(peersData->getLen() > 0) {
|
if(peersData->getLen() > 0) {
|
||||||
for(int i = 0; i < peersData->getLen(); i += 6) {
|
for(int32_t i = 0; i < peersData->getLen(); i += 6) {
|
||||||
unsigned int ipaddr1 = (unsigned char)*(peersData->getData()+i);
|
uint32_t ipaddr1 = (unsigned char)*(peersData->getData()+i);
|
||||||
unsigned int ipaddr2 = (unsigned char)*(peersData->getData()+i+1);
|
uint32_t ipaddr2 = (unsigned char)*(peersData->getData()+i+1);
|
||||||
unsigned int ipaddr3 = (unsigned char)*(peersData->getData()+i+2);
|
uint32_t ipaddr3 = (unsigned char)*(peersData->getData()+i+2);
|
||||||
unsigned int ipaddr4 = (unsigned char)*(peersData->getData()+i+3);
|
uint32_t ipaddr4 = (unsigned char)*(peersData->getData()+i+3);
|
||||||
unsigned int port = ntohs(*(unsigned short int*)(peersData->getData()+i+4));
|
int32_t port = ntohs(*(uint16_t*)(peersData->getData()+i+4));
|
||||||
char ipaddr[16];
|
char ipaddr[16];
|
||||||
|
|
||||||
snprintf(ipaddr, sizeof(ipaddr), "%d.%d.%d.%d",
|
snprintf(ipaddr, sizeof(ipaddr), "%d.%d.%d.%d",
|
||||||
ipaddr1, ipaddr2, ipaddr3, ipaddr4);
|
ipaddr1, ipaddr2, ipaddr3, ipaddr4);
|
||||||
PeerHandle peer =
|
PeerHandle peer = new Peer(ipaddr, port, pieceLength, totalLength);
|
||||||
PeerHandle(new Peer(ipaddr, port, pieceLength, totalLength));
|
|
||||||
|
|
||||||
peers.push_back(peer);
|
peers.push_back(peer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,10 +38,10 @@
|
||||||
|
|
||||||
class CompactPeerListProcessor : public PeerListProcessor {
|
class CompactPeerListProcessor : public PeerListProcessor {
|
||||||
private:
|
private:
|
||||||
int pieceLength;
|
int32_t pieceLength;
|
||||||
long long int totalLength;
|
int64_t totalLength;
|
||||||
public:
|
public:
|
||||||
CompactPeerListProcessor(int pieceLength, long long int totalLength)
|
CompactPeerListProcessor(int32_t pieceLength, int64_t totalLength)
|
||||||
:pieceLength(pieceLength),
|
:pieceLength(pieceLength),
|
||||||
totalLength(totalLength) {}
|
totalLength(totalLength) {}
|
||||||
|
|
||||||
|
|
|
@ -43,20 +43,7 @@ ConsoleDownloadEngine::ConsoleDownloadEngine() {}
|
||||||
|
|
||||||
ConsoleDownloadEngine::~ConsoleDownloadEngine() {}
|
ConsoleDownloadEngine::~ConsoleDownloadEngine() {}
|
||||||
|
|
||||||
void ConsoleDownloadEngine::sendStatistics(long long int currentSize, long long int totalSize) {
|
void ConsoleDownloadEngine::sendStatistics(int64_t currentSize, int64_t totalSize) {
|
||||||
/*
|
|
||||||
printf("\r ");
|
|
||||||
printf("\r");
|
|
||||||
printf("%s/%s Bytes %d%% %s %.2f KB/s %d connections",
|
|
||||||
Util::llitos(currentSize, true).c_str(),
|
|
||||||
Util::llitos(totalSize, true).c_str(),
|
|
||||||
(totalSize == 0 ? 0 : (int)((currentSize*100)/totalSize)),
|
|
||||||
avgSpeed == 0 ? "-" : Util::secfmt(eta).c_str(),
|
|
||||||
speed/1024.0,
|
|
||||||
commands.size());
|
|
||||||
fflush(stdout);
|
|
||||||
*/
|
|
||||||
|
|
||||||
cout << "\r ";
|
cout << "\r ";
|
||||||
cout << "\r";
|
cout << "\r";
|
||||||
if(_requestGroupMan->countRequestGroup() > 0) {
|
if(_requestGroupMan->countRequestGroup() > 0) {
|
||||||
|
@ -166,15 +153,15 @@ void ConsoleDownloadEngine::initStatistics() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConsoleDownloadEngine::calculateStatistics() {
|
void ConsoleDownloadEngine::calculateStatistics() {
|
||||||
long long int dlSize = _requestGroupMan->getDownloadLength();
|
int64_t dlSize = _requestGroupMan->getDownloadLength();
|
||||||
if(!isStartupLengthSet && dlSize > 0) {
|
if(!isStartupLengthSet && dlSize > 0) {
|
||||||
startupLength = dlSize;
|
startupLength = dlSize;
|
||||||
psize = dlSize;
|
psize = dlSize;
|
||||||
isStartupLengthSet = true;
|
isStartupLengthSet = true;
|
||||||
}
|
}
|
||||||
int elapsed = cp.difference();
|
int32_t elapsed = cp.difference();
|
||||||
if(elapsed >= 1) {
|
if(elapsed >= 1) {
|
||||||
int nspeed = (int)((dlSize-psize)/elapsed);
|
int32_t nspeed = (dlSize-psize)/elapsed;
|
||||||
if(nspeed < 0) {
|
if(nspeed < 0) {
|
||||||
nspeed = 0;
|
nspeed = 0;
|
||||||
}
|
}
|
||||||
|
@ -182,9 +169,9 @@ void ConsoleDownloadEngine::calculateStatistics() {
|
||||||
cp.reset();
|
cp.reset();
|
||||||
psize = dlSize;
|
psize = dlSize;
|
||||||
|
|
||||||
int elapsedFromStartup = startup.difference();
|
int32_t elapsedFromStartup = startup.difference();
|
||||||
if(elapsedFromStartup > 0) {
|
if(elapsedFromStartup > 0) {
|
||||||
avgSpeed = (int)((dlSize-startupLength)/elapsedFromStartup);
|
avgSpeed = (dlSize-startupLength)/elapsedFromStartup;
|
||||||
}
|
}
|
||||||
int64_t totalLength = _requestGroupMan->getTotalLength();
|
int64_t totalLength = _requestGroupMan->getTotalLength();
|
||||||
if(avgSpeed < 0) {
|
if(avgSpeed < 0) {
|
||||||
|
|
|
@ -41,19 +41,19 @@
|
||||||
class ConsoleDownloadEngine : public DownloadEngine {
|
class ConsoleDownloadEngine : public DownloadEngine {
|
||||||
private:
|
private:
|
||||||
Time cp;
|
Time cp;
|
||||||
long long int psize;
|
int64_t psize;
|
||||||
int speed;
|
int32_t speed;
|
||||||
// The time when startup
|
// The time when startup
|
||||||
Time startup;
|
Time startup;
|
||||||
// The number of bytes downloaded at startup
|
// The number of bytes downloaded at startup
|
||||||
long long int startupLength;
|
int64_t startupLength;
|
||||||
bool isStartupLengthSet;
|
bool isStartupLengthSet;
|
||||||
// The average speed(bytes per second) since startup
|
// The average speed(bytes per second) since startup
|
||||||
int avgSpeed;
|
int32_t avgSpeed;
|
||||||
// The estimated remaining time to complete the download.
|
// The estimated remaining time to complete the download.
|
||||||
int eta;
|
int32_t eta;
|
||||||
protected:
|
protected:
|
||||||
void sendStatistics(long long int currentSize, long long int totalSize);
|
void sendStatistics(int64_t currentSize, int64_t totalSize);
|
||||||
virtual void initStatistics();
|
virtual void initStatistics();
|
||||||
virtual void calculateStatistics();
|
virtual void calculateStatistics();
|
||||||
virtual void onEndOfRun();
|
virtual void onEndOfRun();
|
||||||
|
|
10
src/Data.cc
10
src/Data.cc
|
@ -35,7 +35,7 @@
|
||||||
#include "Data.h"
|
#include "Data.h"
|
||||||
#include "MetaEntryVisitor.h"
|
#include "MetaEntryVisitor.h"
|
||||||
|
|
||||||
Data::Data(const char* data, int len, bool number):number(number) {
|
Data::Data(const char* data, int32_t len, bool number):number(number) {
|
||||||
if(data == NULL) {
|
if(data == NULL) {
|
||||||
this->data = NULL;
|
this->data = NULL;
|
||||||
this->len = 0;
|
this->len = 0;
|
||||||
|
@ -71,15 +71,15 @@ const char* Data::getData() const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Data::getLen() const {
|
int32_t Data::getLen() const {
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Data::toInt() const {
|
int32_t Data::toInt() const {
|
||||||
return (int)toLLInt();
|
return toLLInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
long long int Data::toLLInt() const {
|
int64_t Data::toLLInt() const {
|
||||||
if(len == 0) {
|
if(len == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
|
|
10
src/Data.h
10
src/Data.h
|
@ -42,7 +42,7 @@ using namespace std;
|
||||||
|
|
||||||
class Data : public MetaEntry {
|
class Data : public MetaEntry {
|
||||||
private:
|
private:
|
||||||
int len;
|
int32_t len;
|
||||||
char* data;
|
char* data;
|
||||||
bool number;
|
bool number;
|
||||||
public:
|
public:
|
||||||
|
@ -50,15 +50,15 @@ public:
|
||||||
* This class stores the copy of data. So caller must take care of freeing
|
* This class stores the copy of data. So caller must take care of freeing
|
||||||
* memory of data.
|
* memory of data.
|
||||||
*/
|
*/
|
||||||
Data(const char* data, int len, bool number = false);
|
Data(const char* data, int32_t len, bool number = false);
|
||||||
~Data();
|
~Data();
|
||||||
|
|
||||||
string toString() const;
|
string toString() const;
|
||||||
int toInt() const;
|
int32_t toInt() const;
|
||||||
long long int toLLInt() const;
|
int64_t toLLInt() const;
|
||||||
|
|
||||||
const char* getData() const;
|
const char* getData() const;
|
||||||
int getLen() const;
|
int32_t getLen() const;
|
||||||
bool isNumber() const;
|
bool isNumber() const;
|
||||||
|
|
||||||
void accept(MetaEntryVisitor* v) const;
|
void accept(MetaEntryVisitor* v) const;
|
||||||
|
|
|
@ -111,13 +111,13 @@ string DefaultBtAnnounce::getAnnounceUrl() {
|
||||||
announceList.setEvent(AnnounceTier::STARTED_AFTER_COMPLETION);
|
announceList.setEvent(AnnounceTier::STARTED_AFTER_COMPLETION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int numWant = 50;
|
int32_t numWant = 50;
|
||||||
if(!btRuntime->lessThanEqMinPeer() ||
|
if(!btRuntime->lessThanEqMinPeer() ||
|
||||||
btRuntime->isHalt()) {
|
btRuntime->isHalt()) {
|
||||||
numWant = 0;
|
numWant = 0;
|
||||||
}
|
}
|
||||||
TransferStat stat = peerStorage->calculateStat();
|
TransferStat stat = peerStorage->calculateStat();
|
||||||
long long int left = pieceStorage->getTotalLength()-pieceStorage->getCompletedLength();
|
int64_t left = pieceStorage->getTotalLength()-pieceStorage->getCompletedLength();
|
||||||
if(left < 0) {
|
if(left < 0) {
|
||||||
left = 0;
|
left = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,16 +50,16 @@
|
||||||
class DefaultBtAnnounce : public BtAnnounce {
|
class DefaultBtAnnounce : public BtAnnounce {
|
||||||
private:
|
private:
|
||||||
BtContextHandle btContext;
|
BtContextHandle btContext;
|
||||||
int trackers;
|
int32_t trackers;
|
||||||
Time prevAnnounceTime;
|
Time prevAnnounceTime;
|
||||||
int interval;
|
int32_t interval;
|
||||||
int minInterval;
|
int32_t minInterval;
|
||||||
int complete;
|
int32_t complete;
|
||||||
int incomplete;
|
int32_t incomplete;
|
||||||
AnnounceList announceList;
|
AnnounceList announceList;
|
||||||
string trackerId;
|
string trackerId;
|
||||||
string key;
|
string key;
|
||||||
int trackerNumTry;
|
int32_t trackerNumTry;
|
||||||
const Option* option;
|
const Option* option;
|
||||||
Logger* logger;
|
Logger* logger;
|
||||||
BtRuntimeHandle btRuntime;
|
BtRuntimeHandle btRuntime;
|
||||||
|
|
|
@ -70,12 +70,12 @@ void DefaultBtProgressInfoFile::save() {
|
||||||
throw string("writeError:bitfield");
|
throw string("writeError:bitfield");
|
||||||
}
|
}
|
||||||
TransferStat stat = peerStorage->calculateStat();
|
TransferStat stat = peerStorage->calculateStat();
|
||||||
long long int allTimeDownloadLength = pieceStorage->getCompletedLength();
|
int64_t allTimeDownloadLength = pieceStorage->getCompletedLength();
|
||||||
if(fwrite(&allTimeDownloadLength,
|
if(fwrite(&allTimeDownloadLength,
|
||||||
sizeof(allTimeDownloadLength), 1, file) < 1) {
|
sizeof(allTimeDownloadLength), 1, file) < 1) {
|
||||||
throw string("writeError:download length");
|
throw string("writeError:download length");
|
||||||
}
|
}
|
||||||
long long int allTimeUploadLength =
|
int64_t allTimeUploadLength =
|
||||||
btRuntime->getUploadLengthAtStartup()+
|
btRuntime->getUploadLengthAtStartup()+
|
||||||
stat.getSessionUploadLength();
|
stat.getSessionUploadLength();
|
||||||
if(fwrite(&allTimeUploadLength,
|
if(fwrite(&allTimeUploadLength,
|
||||||
|
@ -112,12 +112,12 @@ void DefaultBtProgressInfoFile::load() {
|
||||||
pieceStorage->setBitfield(savedBitfield,
|
pieceStorage->setBitfield(savedBitfield,
|
||||||
pieceStorage->getBitfieldLength());
|
pieceStorage->getBitfieldLength());
|
||||||
// allTimeDownloadLength exists for only a compatibility reason.
|
// allTimeDownloadLength exists for only a compatibility reason.
|
||||||
long long int allTimeDownloadLength;
|
int64_t allTimeDownloadLength;
|
||||||
if(fread(&allTimeDownloadLength,
|
if(fread(&allTimeDownloadLength,
|
||||||
sizeof(allTimeDownloadLength), 1, file) < 1) {
|
sizeof(allTimeDownloadLength), 1, file) < 1) {
|
||||||
throw string("readError");
|
throw string("readError");
|
||||||
}
|
}
|
||||||
long long int allTimeUploadLength;
|
int64_t allTimeUploadLength;
|
||||||
if(fread(&allTimeUploadLength,
|
if(fread(&allTimeUploadLength,
|
||||||
sizeof(allTimeUploadLength), 1, file) < 1) {
|
sizeof(allTimeUploadLength), 1, file) < 1) {
|
||||||
throw string("readError");
|
throw string("readError");
|
||||||
|
|
|
@ -77,7 +77,7 @@ public:
|
||||||
|
|
||||||
virtual void removeAllTargetPiece();
|
virtual void removeAllTargetPiece();
|
||||||
|
|
||||||
virtual int countTargetPiece() {
|
virtual int32_t countTargetPiece() {
|
||||||
return pieces.size();
|
return pieces.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,10 +60,8 @@ Peers DefaultPeerListProcessor::extractPeer(const MetaEntry* peersEntry) {
|
||||||
if(!ip || !port || !port->isNumber()) {
|
if(!ip || !port || !port->isNumber()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
PeerHandle peer = PeerHandle(new Peer(ip->toString(),
|
PeerHandle peer = new Peer(ip->toString(), port->toInt(), pieceLength,
|
||||||
port->toInt(),
|
totalLength);
|
||||||
pieceLength,
|
|
||||||
totalLength));
|
|
||||||
peers.push_back(peer);
|
peers.push_back(peer);
|
||||||
}
|
}
|
||||||
return peers;
|
return peers;
|
||||||
|
|
|
@ -39,10 +39,10 @@
|
||||||
|
|
||||||
class DefaultPeerListProcessor : public PeerListProcessor {
|
class DefaultPeerListProcessor : public PeerListProcessor {
|
||||||
private:
|
private:
|
||||||
int pieceLength;
|
int32_t pieceLength;
|
||||||
long long int totalLength;
|
int64_t totalLength;
|
||||||
public:
|
public:
|
||||||
DefaultPeerListProcessor(int pieceLength, long long int totalLength)
|
DefaultPeerListProcessor(int32_t pieceLength, int64_t totalLength)
|
||||||
:pieceLength(pieceLength),
|
:pieceLength(pieceLength),
|
||||||
totalLength(totalLength) {}
|
totalLength(totalLength) {}
|
||||||
|
|
||||||
|
|
|
@ -111,9 +111,9 @@ PeerHandle DefaultPeerStorage::getUnusedPeer() {
|
||||||
class FindPeer {
|
class FindPeer {
|
||||||
private:
|
private:
|
||||||
string ipaddr;
|
string ipaddr;
|
||||||
int port;
|
int32_t port;
|
||||||
public:
|
public:
|
||||||
FindPeer(const string& ipaddr, int port):ipaddr(ipaddr), port(port) {}
|
FindPeer(const string& ipaddr, int32_t port):ipaddr(ipaddr), port(port) {}
|
||||||
|
|
||||||
bool operator()(const PeerHandle& peer) const {
|
bool operator()(const PeerHandle& peer) const {
|
||||||
return ipaddr == peer->ipaddr && port == peer->port;
|
return ipaddr == peer->ipaddr && port == peer->port;
|
||||||
|
@ -121,7 +121,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
PeerHandle DefaultPeerStorage::getPeer(const string& ipaddr,
|
PeerHandle DefaultPeerStorage::getPeer(const string& ipaddr,
|
||||||
int port) const {
|
int32_t port) const {
|
||||||
Peers::const_iterator itr = find_if(peers.begin(), peers.end(),
|
Peers::const_iterator itr = find_if(peers.begin(), peers.end(),
|
||||||
FindPeer(ipaddr, port));
|
FindPeer(ipaddr, port));
|
||||||
if(itr == peers.end()) {
|
if(itr == peers.end()) {
|
||||||
|
@ -194,7 +194,7 @@ TransferStat DefaultPeerStorage::calculateStat() {
|
||||||
return stat;
|
return stat;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultPeerStorage::deleteUnusedPeer(int delSize) {
|
void DefaultPeerStorage::deleteUnusedPeer(int32_t delSize) {
|
||||||
Peers temp;
|
Peers temp;
|
||||||
for(Peers::reverse_iterator itr = peers.rbegin();
|
for(Peers::reverse_iterator itr = peers.rbegin();
|
||||||
itr != peers.rend(); ++itr) {
|
itr != peers.rend(); ++itr) {
|
||||||
|
|
|
@ -50,11 +50,11 @@ private:
|
||||||
const Option* option;
|
const Option* option;
|
||||||
Peers peers;
|
Peers peers;
|
||||||
Peers incomingPeers;
|
Peers incomingPeers;
|
||||||
int maxPeerListSize;
|
int32_t maxPeerListSize;
|
||||||
Logger* logger;
|
Logger* logger;
|
||||||
BtRuntimeHandle btRuntime;
|
BtRuntimeHandle btRuntime;
|
||||||
long long int removedPeerSessionDownloadLength;
|
int64_t removedPeerSessionDownloadLength;
|
||||||
long long int removedPeerSessionUploadLength;
|
int64_t removedPeerSessionUploadLength;
|
||||||
public:
|
public:
|
||||||
DefaultPeerStorage(BtContextHandle btContext, const Option* option);
|
DefaultPeerStorage(BtContextHandle btContext, const Option* option);
|
||||||
virtual ~DefaultPeerStorage();
|
virtual ~DefaultPeerStorage();
|
||||||
|
@ -72,7 +72,7 @@ public:
|
||||||
|
|
||||||
virtual PeerHandle getUnusedPeer();
|
virtual PeerHandle getUnusedPeer();
|
||||||
|
|
||||||
PeerHandle getPeer(const string& ipaddr, int port) const;
|
PeerHandle getPeer(const string& ipaddr, int32_t port) const;
|
||||||
|
|
||||||
virtual void addPeer(const Peers& peers);
|
virtual void addPeer(const Peers& peers);
|
||||||
|
|
||||||
|
@ -86,11 +86,11 @@ public:
|
||||||
|
|
||||||
virtual void returnPeer(const PeerHandle& peer);
|
virtual void returnPeer(const PeerHandle& peer);
|
||||||
|
|
||||||
void setMaxPeerListSize(int size) { this->maxPeerListSize = size; }
|
void setMaxPeerListSize(int32_t size) { this->maxPeerListSize = size; }
|
||||||
|
|
||||||
int getMaxPeerListSize() const { return maxPeerListSize; }
|
int32_t getMaxPeerListSize() const { return maxPeerListSize; }
|
||||||
|
|
||||||
void deleteUnusedPeer(int delSize);
|
void deleteUnusedPeer(int32_t delSize);
|
||||||
|
|
||||||
void onErasingPeer(const PeerHandle& peer);
|
void onErasingPeer(const PeerHandle& peer);
|
||||||
|
|
||||||
|
|
|
@ -72,8 +72,8 @@ bool DefaultPieceStorage::isEndGame() {
|
||||||
return bitfieldMan->countMissingBlock() <= endGamePieceNum;
|
return bitfieldMan->countMissingBlock() <= endGamePieceNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DefaultPieceStorage::getMissingPieceIndex(const PeerHandle& peer) {
|
int32_t DefaultPieceStorage::getMissingPieceIndex(const PeerHandle& peer) {
|
||||||
int index = -1;
|
int32_t index = -1;
|
||||||
if(isEndGame()) {
|
if(isEndGame()) {
|
||||||
index = bitfieldMan->getMissingIndex(peer->getBitfield(),
|
index = bitfieldMan->getMissingIndex(peer->getBitfield(),
|
||||||
peer->getBitfieldLength());
|
peer->getBitfieldLength());
|
||||||
|
@ -84,7 +84,7 @@ int DefaultPieceStorage::getMissingPieceIndex(const PeerHandle& peer) {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
PieceHandle DefaultPieceStorage::checkOutPiece(int index) {
|
PieceHandle DefaultPieceStorage::checkOutPiece(int32_t index) {
|
||||||
if(index == -1) {
|
if(index == -1) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ PieceHandle DefaultPieceStorage::checkOutPiece(int index) {
|
||||||
* Newly instantiated piece is not added to usedPieces.
|
* Newly instantiated piece is not added to usedPieces.
|
||||||
* Because it is waste of memory and there is no chance to use them later.
|
* Because it is waste of memory and there is no chance to use them later.
|
||||||
*/
|
*/
|
||||||
PieceHandle DefaultPieceStorage::getPiece(int index) {
|
PieceHandle DefaultPieceStorage::getPiece(int32_t index) {
|
||||||
if(0 <= index && index <= bitfieldMan->getMaxIndex()) {
|
if(0 <= index && index <= bitfieldMan->getMaxIndex()) {
|
||||||
PieceHandle piece = findUsedPiece(index);
|
PieceHandle piece = findUsedPiece(index);
|
||||||
if(piece.isNull()) {
|
if(piece.isNull()) {
|
||||||
|
@ -125,16 +125,16 @@ void DefaultPieceStorage::addUsedPiece(const PieceHandle& piece) {
|
||||||
|
|
||||||
class FindPiece {
|
class FindPiece {
|
||||||
private:
|
private:
|
||||||
int index;
|
int32_t index;
|
||||||
public:
|
public:
|
||||||
FindPiece(int index):index(index) {}
|
FindPiece(int32_t index):index(index) {}
|
||||||
|
|
||||||
bool operator()(const PieceHandle& piece) {
|
bool operator()(const PieceHandle& piece) {
|
||||||
return piece->getIndex() == index;
|
return piece->getIndex() == index;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
PieceHandle DefaultPieceStorage::findUsedPiece(int index) const {
|
PieceHandle DefaultPieceStorage::findUsedPiece(int32_t index) const {
|
||||||
Pieces::const_iterator itr = find_if(usedPieces.begin(),
|
Pieces::const_iterator itr = find_if(usedPieces.begin(),
|
||||||
usedPieces.end(),
|
usedPieces.end(),
|
||||||
FindPiece(index));
|
FindPiece(index));
|
||||||
|
@ -146,12 +146,12 @@ PieceHandle DefaultPieceStorage::findUsedPiece(int index) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
PieceHandle DefaultPieceStorage::getMissingPiece(const PeerHandle& peer) {
|
PieceHandle DefaultPieceStorage::getMissingPiece(const PeerHandle& peer) {
|
||||||
int index = getMissingPieceIndex(peer);
|
int32_t index = getMissingPieceIndex(peer);
|
||||||
return checkOutPiece(index);
|
return checkOutPiece(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DefaultPieceStorage::getMissingFastPieceIndex(const PeerHandle& peer) {
|
int32_t DefaultPieceStorage::getMissingFastPieceIndex(const PeerHandle& peer) {
|
||||||
int index = -1;
|
int32_t index = -1;
|
||||||
if(peer->isFastExtensionEnabled() && peer->countFastSet() > 0) {
|
if(peer->isFastExtensionEnabled() && peer->countFastSet() > 0) {
|
||||||
BitfieldMan tempBitfield(bitfieldMan->getBlockLength(),
|
BitfieldMan tempBitfield(bitfieldMan->getBlockLength(),
|
||||||
bitfieldMan->getTotalLength());
|
bitfieldMan->getTotalLength());
|
||||||
|
@ -173,7 +173,7 @@ int DefaultPieceStorage::getMissingFastPieceIndex(const PeerHandle& peer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
PieceHandle DefaultPieceStorage::getMissingFastPiece(const PeerHandle& peer) {
|
PieceHandle DefaultPieceStorage::getMissingFastPiece(const PeerHandle& peer) {
|
||||||
int index = getMissingFastPieceIndex(peer);
|
int32_t index = getMissingFastPieceIndex(peer);
|
||||||
return checkOutPiece(index);
|
return checkOutPiece(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,14 +187,14 @@ void DefaultPieceStorage::deleteUsedPiece(const PieceHandle& piece) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultPieceStorage::reduceUsedPieces(int delMax) {
|
void DefaultPieceStorage::reduceUsedPieces(int32_t delMax) {
|
||||||
int toDelete = usedPieces.size()-delMax;
|
int32_t toDelete = usedPieces.size()-delMax;
|
||||||
if(toDelete <= 0) {
|
if(toDelete <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int fillRate = 10;
|
int32_t fillRate = 10;
|
||||||
while(fillRate < 50) {
|
while(fillRate < 50) {
|
||||||
int deleted = deleteUsedPiecesByFillRate(fillRate, toDelete);
|
int32_t deleted = deleteUsedPiecesByFillRate(fillRate, toDelete);
|
||||||
if(deleted == 0) {
|
if(deleted == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -203,9 +203,9 @@ void DefaultPieceStorage::reduceUsedPieces(int delMax) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int DefaultPieceStorage::deleteUsedPiecesByFillRate(int fillRate,
|
int32_t DefaultPieceStorage::deleteUsedPiecesByFillRate(int32_t fillRate,
|
||||||
int toDelete) {
|
int32_t toDelete) {
|
||||||
int deleted = 0;
|
int32_t deleted = 0;
|
||||||
for(Pieces::iterator itr = usedPieces.begin();
|
for(Pieces::iterator itr = usedPieces.begin();
|
||||||
itr != usedPieces.end() && deleted < toDelete;) {
|
itr != usedPieces.end() && deleted < toDelete;) {
|
||||||
PieceHandle& piece = *itr;
|
PieceHandle& piece = *itr;
|
||||||
|
@ -272,23 +272,23 @@ void DefaultPieceStorage::cancelPiece(const PieceHandle& piece) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DefaultPieceStorage::hasPiece(int index) {
|
bool DefaultPieceStorage::hasPiece(int32_t index) {
|
||||||
return bitfieldMan->isBitSet(index);
|
return bitfieldMan->isBitSet(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
long long int DefaultPieceStorage::getTotalLength() {
|
int64_t DefaultPieceStorage::getTotalLength() {
|
||||||
return bitfieldMan->getTotalLength();
|
return bitfieldMan->getTotalLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
long long int DefaultPieceStorage::getFilteredTotalLength() {
|
int64_t DefaultPieceStorage::getFilteredTotalLength() {
|
||||||
return bitfieldMan->getFilteredTotalLength();
|
return bitfieldMan->getFilteredTotalLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
long long int DefaultPieceStorage::getCompletedLength() {
|
int64_t DefaultPieceStorage::getCompletedLength() {
|
||||||
return bitfieldMan->getCompletedLength();
|
return bitfieldMan->getCompletedLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
long long int DefaultPieceStorage::getFilteredCompletedLength() {
|
int64_t DefaultPieceStorage::getFilteredCompletedLength() {
|
||||||
return bitfieldMan->getFilteredCompletedLength();
|
return bitfieldMan->getFilteredCompletedLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,7 +312,7 @@ void DefaultPieceStorage::setFileFilter(const Strings& filePaths) {
|
||||||
void DefaultPieceStorage::setFileFilter(const Integers& fileIndexes) {
|
void DefaultPieceStorage::setFileFilter(const Integers& fileIndexes) {
|
||||||
Strings filePaths;
|
Strings filePaths;
|
||||||
const FileEntries& entries = diskAdaptor->getFileEntries();
|
const FileEntries& entries = diskAdaptor->getFileEntries();
|
||||||
for(int i = 0; i < (int)entries.size(); i++) {
|
for(int32_t i = 0; i < (int32_t)entries.size(); i++) {
|
||||||
if(find(fileIndexes.begin(), fileIndexes.end(), i+1) != fileIndexes.end()) {
|
if(find(fileIndexes.begin(), fileIndexes.end(), i+1) != fileIndexes.end()) {
|
||||||
logger->debug("index=%d is %s", i+1, entries[i]->getPath().c_str());
|
logger->debug("index=%d is %s", i+1, entries[i]->getPath().c_str());
|
||||||
filePaths.push_back(entries[i]->getPath());
|
filePaths.push_back(entries[i]->getPath());
|
||||||
|
@ -373,11 +373,11 @@ void DefaultPieceStorage::initStorage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultPieceStorage::setBitfield(const unsigned char* bitfield,
|
void DefaultPieceStorage::setBitfield(const unsigned char* bitfield,
|
||||||
int bitfieldLength) {
|
int32_t bitfieldLength) {
|
||||||
bitfieldMan->setBitfield(bitfield, bitfieldLength);
|
bitfieldMan->setBitfield(bitfield, bitfieldLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DefaultPieceStorage::getBitfieldLength() {
|
int32_t DefaultPieceStorage::getBitfieldLength() {
|
||||||
return bitfieldMan->getBitfieldLength();
|
return bitfieldMan->getBitfieldLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,16 +389,16 @@ DiskAdaptorHandle DefaultPieceStorage::getDiskAdaptor() {
|
||||||
return diskAdaptor;
|
return diskAdaptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DefaultPieceStorage::getPieceLength(int index) {
|
int32_t DefaultPieceStorage::getPieceLength(int32_t index) {
|
||||||
return bitfieldMan->getBlockLength(index);
|
return bitfieldMan->getBlockLength(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultPieceStorage::advertisePiece(int cuid, int index) {
|
void DefaultPieceStorage::advertisePiece(int32_t cuid, int32_t index) {
|
||||||
HaveEntry entry(cuid, index);
|
HaveEntry entry(cuid, index);
|
||||||
haves.push_front(entry);
|
haves.push_front(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
Integers DefaultPieceStorage::getAdvertisedPieceIndexes(int myCuid,
|
Integers DefaultPieceStorage::getAdvertisedPieceIndexes(int32_t myCuid,
|
||||||
const Time& lastCheckTime) {
|
const Time& lastCheckTime) {
|
||||||
Integers indexes;
|
Integers indexes;
|
||||||
for(Haves::const_iterator itr = haves.begin(); itr != haves.end(); itr++) {
|
for(Haves::const_iterator itr = haves.begin(); itr != haves.end(); itr++) {
|
||||||
|
@ -417,9 +417,9 @@ Integers DefaultPieceStorage::getAdvertisedPieceIndexes(int myCuid,
|
||||||
class FindElapsedHave
|
class FindElapsedHave
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int elapsed;
|
int32_t elapsed;
|
||||||
public:
|
public:
|
||||||
FindElapsedHave(int elapsed):elapsed(elapsed) {}
|
FindElapsedHave(int32_t elapsed):elapsed(elapsed) {}
|
||||||
|
|
||||||
bool operator()(const HaveEntry& have) {
|
bool operator()(const HaveEntry& have) {
|
||||||
if(have.getRegisteredTime().elapsed(elapsed)) {
|
if(have.getRegisteredTime().elapsed(elapsed)) {
|
||||||
|
@ -430,7 +430,7 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void DefaultPieceStorage::removeAdvertisedPiece(int elapsed) {
|
void DefaultPieceStorage::removeAdvertisedPiece(int32_t elapsed) {
|
||||||
Haves::iterator itr =
|
Haves::iterator itr =
|
||||||
find_if(haves.begin(), haves.end(), FindElapsedHave(elapsed));
|
find_if(haves.begin(), haves.end(), FindElapsedHave(elapsed));
|
||||||
if(itr != haves.end()) {
|
if(itr != haves.end()) {
|
||||||
|
|
|
@ -48,17 +48,17 @@
|
||||||
|
|
||||||
class HaveEntry {
|
class HaveEntry {
|
||||||
private:
|
private:
|
||||||
int cuid;
|
int32_t cuid;
|
||||||
int index;
|
int32_t index;
|
||||||
Time registeredTime;
|
Time registeredTime;
|
||||||
public:
|
public:
|
||||||
HaveEntry(int cuid, int index):
|
HaveEntry(int32_t cuid, int32_t index):
|
||||||
cuid(cuid),
|
cuid(cuid),
|
||||||
index(index) {}
|
index(index) {}
|
||||||
|
|
||||||
int getCuid() const { return cuid; }
|
int32_t getCuid() const { return cuid; }
|
||||||
|
|
||||||
int getIndex() const { return index; }
|
int32_t getIndex() const { return index; }
|
||||||
|
|
||||||
const Time& getRegisteredTime() const { return registeredTime; }
|
const Time& getRegisteredTime() const { return registeredTime; }
|
||||||
};
|
};
|
||||||
|
@ -77,13 +77,13 @@ private:
|
||||||
Haves haves;
|
Haves haves;
|
||||||
FileAllocatorHandle createFileAllocator();
|
FileAllocatorHandle createFileAllocator();
|
||||||
|
|
||||||
int getMissingPieceIndex(const PeerHandle& peer);
|
int32_t getMissingPieceIndex(const PeerHandle& peer);
|
||||||
int getMissingFastPieceIndex(const PeerHandle& peer);
|
int32_t getMissingFastPieceIndex(const PeerHandle& peer);
|
||||||
PieceHandle checkOutPiece(int index);
|
PieceHandle checkOutPiece(int32_t index);
|
||||||
int deleteUsedPiecesByFillRate(int fillRate, int toDelete);
|
int32_t deleteUsedPiecesByFillRate(int32_t fillRate, int32_t toDelete);
|
||||||
void reduceUsedPieces(int delMax);
|
void reduceUsedPieces(int32_t delMax);
|
||||||
void deleteUsedPiece(const PieceHandle& piece);
|
void deleteUsedPiece(const PieceHandle& piece);
|
||||||
PieceHandle findUsedPiece(int index) const;
|
PieceHandle findUsedPiece(int32_t index) const;
|
||||||
public:
|
public:
|
||||||
DefaultPieceStorage(BtContextHandle btContext, const Option* option);
|
DefaultPieceStorage(BtContextHandle btContext, const Option* option);
|
||||||
virtual ~DefaultPieceStorage();
|
virtual ~DefaultPieceStorage();
|
||||||
|
@ -94,21 +94,21 @@ public:
|
||||||
|
|
||||||
virtual PieceHandle getMissingFastPiece(const PeerHandle& peer);
|
virtual PieceHandle getMissingFastPiece(const PeerHandle& peer);
|
||||||
|
|
||||||
virtual PieceHandle getPiece(int index);
|
virtual PieceHandle getPiece(int32_t index);
|
||||||
|
|
||||||
virtual void completePiece(const PieceHandle& piece);
|
virtual void completePiece(const PieceHandle& piece);
|
||||||
|
|
||||||
virtual void cancelPiece(const PieceHandle& piece);
|
virtual void cancelPiece(const PieceHandle& piece);
|
||||||
|
|
||||||
virtual bool hasPiece(int index);
|
virtual bool hasPiece(int32_t index);
|
||||||
|
|
||||||
virtual long long int getTotalLength();
|
virtual int64_t getTotalLength();
|
||||||
|
|
||||||
virtual long long int getFilteredTotalLength();
|
virtual int64_t getFilteredTotalLength();
|
||||||
|
|
||||||
virtual long long int getCompletedLength();
|
virtual int64_t getCompletedLength();
|
||||||
|
|
||||||
virtual long long int getFilteredCompletedLength();
|
virtual int64_t getFilteredCompletedLength();
|
||||||
|
|
||||||
virtual void initStorage();
|
virtual void initStorage();
|
||||||
|
|
||||||
|
@ -123,9 +123,9 @@ public:
|
||||||
virtual bool allDownloadFinished();
|
virtual bool allDownloadFinished();
|
||||||
|
|
||||||
virtual void setBitfield(const unsigned char* bitfield,
|
virtual void setBitfield(const unsigned char* bitfield,
|
||||||
int bitfieldLength);
|
int32_t bitfieldLength);
|
||||||
|
|
||||||
virtual int getBitfieldLength();
|
virtual int32_t getBitfieldLength();
|
||||||
|
|
||||||
virtual const unsigned char* getBitfield();
|
virtual const unsigned char* getBitfield();
|
||||||
|
|
||||||
|
@ -145,14 +145,14 @@ public:
|
||||||
|
|
||||||
virtual DiskAdaptorHandle getDiskAdaptor();
|
virtual DiskAdaptorHandle getDiskAdaptor();
|
||||||
|
|
||||||
virtual int getPieceLength(int index);
|
virtual int32_t getPieceLength(int32_t index);
|
||||||
|
|
||||||
virtual void advertisePiece(int cuid, int index);
|
virtual void advertisePiece(int32_t cuid, int32_t index);
|
||||||
|
|
||||||
virtual Integers getAdvertisedPieceIndexes(int myCuid,
|
virtual Integers getAdvertisedPieceIndexes(int32_t myCuid,
|
||||||
const Time& lastCheckTime);
|
const Time& lastCheckTime);
|
||||||
|
|
||||||
virtual void removeAdvertisedPiece(int elapsed);
|
virtual void removeAdvertisedPiece(int32_t elapsed);
|
||||||
|
|
||||||
virtual void markAllPiecesDone();
|
virtual void markAllPiecesDone();
|
||||||
|
|
||||||
|
|
|
@ -42,11 +42,11 @@ typedef deque<PeerListProcessorHandle> PeerListProcessors;
|
||||||
|
|
||||||
class DelegatingPeerListProcessor : public PeerListProcessor {
|
class DelegatingPeerListProcessor : public PeerListProcessor {
|
||||||
private:
|
private:
|
||||||
int pieceLength;
|
int32_t pieceLength;
|
||||||
long long int totalLength;
|
int64_t totalLength;
|
||||||
PeerListProcessors processors;
|
PeerListProcessors processors;
|
||||||
public:
|
public:
|
||||||
DelegatingPeerListProcessor(int pieceLength, long long int totalLength)
|
DelegatingPeerListProcessor(int32_t pieceLength, int64_t totalLength)
|
||||||
:pieceLength(pieceLength),
|
:pieceLength(pieceLength),
|
||||||
totalLength(totalLength) {
|
totalLength(totalLength) {
|
||||||
processors.push_back(new DefaultPeerListProcessor(pieceLength, totalLength));
|
processors.push_back(new DefaultPeerListProcessor(pieceLength, totalLength));
|
||||||
|
|
|
@ -35,7 +35,6 @@
|
||||||
#ifndef _D_DISK_WRITER_H_
|
#ifndef _D_DISK_WRITER_H_
|
||||||
#define _D_DISK_WRITER_H_
|
#define _D_DISK_WRITER_H_
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#ifdef ENABLE_MESSAGE_DIGEST
|
#ifdef ENABLE_MESSAGE_DIGEST
|
||||||
#include "messageDigest.h"
|
#include "messageDigest.h"
|
||||||
|
@ -87,8 +86,8 @@ public:
|
||||||
writeData((const char*)data, len, position);
|
writeData((const char*)data, len, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int readData(char* data, int32_t len, int64_t position) = 0;
|
virtual int32_t readData(char* data, int32_t len, int64_t position) = 0;
|
||||||
virtual int readData(unsigned char* data, int32_t len, int64_t position) {
|
virtual int32_t readData(unsigned char* data, int32_t len, int64_t position) {
|
||||||
return readData((char*)data, len, position);
|
return readData((char*)data, len, position);
|
||||||
}
|
}
|
||||||
#ifdef ENABLE_MESSAGE_DIGEST
|
#ifdef ENABLE_MESSAGE_DIGEST
|
||||||
|
|
|
@ -66,8 +66,8 @@ void DownloadEngine::cleanQueue() {
|
||||||
|
|
||||||
void DownloadEngine::executeCommand(Command::STATUS statusFilter)
|
void DownloadEngine::executeCommand(Command::STATUS statusFilter)
|
||||||
{
|
{
|
||||||
int max = commands.size();
|
int32_t max = commands.size();
|
||||||
for(int i = 0; i < max; i++) {
|
for(int32_t i = 0; i < max; i++) {
|
||||||
Command* com = commands.front();
|
Command* com = commands.front();
|
||||||
commands.pop_front();
|
commands.pop_front();
|
||||||
if(com->statusMatch(statusFilter)) {
|
if(com->statusMatch(statusFilter)) {
|
||||||
|
@ -116,7 +116,7 @@ void DownloadEngine::shortSleep() const {
|
||||||
void DownloadEngine::waitData() {
|
void DownloadEngine::waitData() {
|
||||||
fd_set rfds;
|
fd_set rfds;
|
||||||
fd_set wfds;
|
fd_set wfds;
|
||||||
int retval = 0;
|
int32_t retval = 0;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
memcpy(&rfds, &rfdset, sizeof(fd_set));
|
memcpy(&rfds, &rfdset, sizeof(fd_set));
|
||||||
|
@ -160,7 +160,7 @@ void DownloadEngine::updateFdSet() {
|
||||||
for(NameResolverEntries::iterator itr = nameResolverEntries.begin();
|
for(NameResolverEntries::iterator itr = nameResolverEntries.begin();
|
||||||
itr != nameResolverEntries.end(); ++itr) {
|
itr != nameResolverEntries.end(); ++itr) {
|
||||||
NameResolverEntry& entry = *itr;
|
NameResolverEntry& entry = *itr;
|
||||||
int fd = entry.nameResolver->getFds(&rfdset, &wfdset);
|
int32_t fd = entry.nameResolver->getFds(&rfdset, &wfdset);
|
||||||
if(fdmax < fd) {
|
if(fdmax < fd) {
|
||||||
fdmax = fd;
|
fdmax = fd;
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ void DownloadEngine::updateFdSet() {
|
||||||
for(SocketEntries::iterator itr = socketEntries.begin();
|
for(SocketEntries::iterator itr = socketEntries.begin();
|
||||||
itr != socketEntries.end(); ++itr) {
|
itr != socketEntries.end(); ++itr) {
|
||||||
SocketEntry& entry = *itr;
|
SocketEntry& entry = *itr;
|
||||||
int fd = entry.socket->getSockfd();
|
int32_t fd = entry.socket->getSockfd();
|
||||||
switch(entry.type) {
|
switch(entry.type) {
|
||||||
case SocketEntry::TYPE_RD:
|
case SocketEntry::TYPE_RD:
|
||||||
FD_SET(fd, &rfdset);
|
FD_SET(fd, &rfdset);
|
||||||
|
|
|
@ -106,7 +106,7 @@ private:
|
||||||
#endif // ENABLE_ASYNC_DNS
|
#endif // ENABLE_ASYNC_DNS
|
||||||
fd_set rfdset;
|
fd_set rfdset;
|
||||||
fd_set wfdset;
|
fd_set wfdset;
|
||||||
int fdmax;
|
int32_t fdmax;
|
||||||
|
|
||||||
void shortSleep() const;
|
void shortSleep() const;
|
||||||
bool addSocket(const SocketEntry& socketEntry);
|
bool addSocket(const SocketEntry& socketEntry);
|
||||||
|
|
|
@ -184,8 +184,8 @@ DownloadEngineFactory::newTorrentConsoleEngine(const BtContextHandle& btContext,
|
||||||
PeerListenCommand* listenCommand =
|
PeerListenCommand* listenCommand =
|
||||||
new PeerListenCommand(CUIDCounterSingletonHolder::instance()->newID(),
|
new PeerListenCommand(CUIDCounterSingletonHolder::instance()->newID(),
|
||||||
te, btContext);
|
te, btContext);
|
||||||
int port;
|
int32_t port;
|
||||||
int listenPort = op->getAsInt(PREF_LISTEN_PORT);
|
int32_t listenPort = op->getAsInt(PREF_LISTEN_PORT);
|
||||||
if(listenPort == -1) {
|
if(listenPort == -1) {
|
||||||
port = listenCommand->bindPort(6881, 6999);
|
port = listenCommand->bindPort(6881, 6999);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -50,7 +50,7 @@ FeatureConfig::FeatureConfig() {
|
||||||
PortMap::value_type("https", 443),
|
PortMap::value_type("https", 443),
|
||||||
PortMap::value_type("ftp", 21),
|
PortMap::value_type("ftp", 21),
|
||||||
};
|
};
|
||||||
int portArraySize = sizeof(portArray)/sizeof(PortMap::value_type);
|
int32_t portArraySize = sizeof(portArray)/sizeof(PortMap::value_type);
|
||||||
defaultPorts.insert(&portArray[0],
|
defaultPorts.insert(&portArray[0],
|
||||||
&portArray[portArraySize]);
|
&portArray[portArraySize]);
|
||||||
|
|
||||||
|
@ -94,11 +94,11 @@ FeatureConfig::FeatureConfig() {
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
int featureArraySize = sizeof(featureArray)/sizeof(FeatureMap::value_type);
|
int32_t featureArraySize = sizeof(featureArray)/sizeof(FeatureMap::value_type);
|
||||||
supportedFeatures.insert(&featureArray[0],
|
supportedFeatures.insert(&featureArray[0],
|
||||||
&featureArray[featureArraySize]);
|
&featureArray[featureArraySize]);
|
||||||
|
|
||||||
for(int i = 0; i < featureArraySize; i++) {
|
for(int32_t i = 0; i < featureArraySize; i++) {
|
||||||
features.push_back(featureArray[i].first);
|
features.push_back(featureArray[i].first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
typedef map<string, int> PortMap;
|
typedef map<string, int32_t> PortMap;
|
||||||
typedef map<string, bool> FeatureMap;
|
typedef map<string, bool> FeatureMap;
|
||||||
|
|
||||||
class FeatureConfig {
|
class FeatureConfig {
|
||||||
|
@ -64,7 +64,7 @@ public:
|
||||||
featureConfig = 0;
|
featureConfig = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getDefaultPort(const string& protocol) const {
|
int32_t getDefaultPort(const string& protocol) const {
|
||||||
PortMap::const_iterator itr = defaultPorts.find(protocol);
|
PortMap::const_iterator itr = defaultPorts.find(protocol);
|
||||||
if(itr == defaultPorts.end()) {
|
if(itr == defaultPorts.end()) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -43,7 +43,7 @@ File::File(const string& name):name(name) {}
|
||||||
|
|
||||||
File::~File() {}
|
File::~File() {}
|
||||||
|
|
||||||
int File::fillStat(struct stat& fstat) {
|
int32_t File::fillStat(struct stat& fstat) {
|
||||||
return stat(name.c_str(), &fstat);
|
return stat(name.c_str(), &fstat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,11 @@ using namespace std;
|
||||||
class File {
|
class File {
|
||||||
private:
|
private:
|
||||||
string name;
|
string name;
|
||||||
int fillStat(struct stat& fstat);
|
|
||||||
|
/**
|
||||||
|
* Returns the return value of stat(...)
|
||||||
|
*/
|
||||||
|
int32_t fillStat(struct stat& fstat);
|
||||||
public:
|
public:
|
||||||
File(const string& name);
|
File(const string& name);
|
||||||
~File();
|
~File();
|
||||||
|
|
|
@ -38,8 +38,8 @@
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
|
|
||||||
FileEntry::FileEntry(const string& path,
|
FileEntry::FileEntry(const string& path,
|
||||||
long long int length,
|
int64_t length,
|
||||||
long long int offset):
|
int64_t offset):
|
||||||
path(path), length(length), offset(offset),
|
path(path), length(length), offset(offset),
|
||||||
extracted(false), requested(true) {}
|
extracted(false), requested(true) {}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ private:
|
||||||
public:
|
public:
|
||||||
FileEntry():length(0), offset(0), extracted(false), requested(false) {}
|
FileEntry():length(0), offset(0), extracted(false), requested(false) {}
|
||||||
|
|
||||||
FileEntry(const string& path, long long int length, long long int offset);
|
FileEntry(const string& path, int64_t length, int64_t offset);
|
||||||
|
|
||||||
FileEntry& operator=(const FileEntry& entry)
|
FileEntry& operator=(const FileEntry& entry)
|
||||||
{
|
{
|
||||||
|
@ -80,11 +80,11 @@ public:
|
||||||
|
|
||||||
int64_t getLength() const { return length; }
|
int64_t getLength() const { return length; }
|
||||||
|
|
||||||
void setLength(long long int length) { this->length = length; }
|
void setLength(int64_t length) { this->length = length; }
|
||||||
|
|
||||||
long long int getOffset() const { return offset; }
|
int64_t getOffset() const { return offset; }
|
||||||
|
|
||||||
void setOffset(long long int offset) { this->offset = offset; }
|
void setOffset(int64_t offset) { this->offset = offset; }
|
||||||
|
|
||||||
bool isExtracted() const { return extracted; }
|
bool isExtracted() const { return extracted; }
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
#include "prefs.h"
|
#include "prefs.h"
|
||||||
#include "LogFactory.h"
|
#include "LogFactory.h"
|
||||||
|
|
||||||
FtpConnection::FtpConnection(int cuid, const SocketHandle& socket,
|
FtpConnection::FtpConnection(int32_t cuid, const SocketHandle& socket,
|
||||||
const RequestHandle req, const Option* op)
|
const RequestHandle req, const Option* op)
|
||||||
:cuid(cuid), socket(socket), req(req), option(op) {
|
:cuid(cuid), socket(socket), req(req), option(op) {
|
||||||
logger = LogFactory::getInstance();
|
logger = LogFactory::getInstance();
|
||||||
|
@ -94,9 +94,9 @@ SocketHandle FtpConnection::sendPort() const {
|
||||||
SocketHandle serverSocket;
|
SocketHandle serverSocket;
|
||||||
serverSocket->beginListen();
|
serverSocket->beginListen();
|
||||||
|
|
||||||
pair<string, int> addrinfo;
|
pair<string, int32_t> addrinfo;
|
||||||
socket->getAddrInfo(addrinfo);
|
socket->getAddrInfo(addrinfo);
|
||||||
int ipaddr[4];
|
int32_t ipaddr[4];
|
||||||
sscanf(addrinfo.first.c_str(), "%d.%d.%d.%d",
|
sscanf(addrinfo.first.c_str(), "%d.%d.%d.%d",
|
||||||
&ipaddr[0], &ipaddr[1], &ipaddr[2], &ipaddr[3]);
|
&ipaddr[0], &ipaddr[1], &ipaddr[2], &ipaddr[3]);
|
||||||
serverSocket->getAddrInfo(addrinfo);
|
serverSocket->getAddrInfo(addrinfo);
|
||||||
|
@ -121,8 +121,8 @@ void FtpConnection::sendRetr() const {
|
||||||
socket->writeData(request);
|
socket->writeData(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
int FtpConnection::getStatus(const string& response) const {
|
int32_t FtpConnection::getStatus(const string& response) const {
|
||||||
int status;
|
int32_t status;
|
||||||
// When the response is not like "%d %*s",
|
// When the response is not like "%d %*s",
|
||||||
// we return 0.
|
// we return 0.
|
||||||
if(response.find_first_not_of("0123456789") != 3
|
if(response.find_first_not_of("0123456789") != 3
|
||||||
|
@ -136,7 +136,7 @@ int FtpConnection::getStatus(const string& response) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FtpConnection::isEndOfResponse(int status, const string& response) const {
|
bool FtpConnection::isEndOfResponse(int32_t status, const string& response) const {
|
||||||
if(response.size() <= 4) {
|
if(response.size() <= 4) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -156,10 +156,10 @@ bool FtpConnection::isEndOfResponse(int status, const string& response) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FtpConnection::bulkReceiveResponse(pair<int, string>& response) {
|
bool FtpConnection::bulkReceiveResponse(pair<int32_t, string>& response) {
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
while(socket->isReadable(0)) {
|
while(socket->isReadable(0)) {
|
||||||
int size = sizeof(buf)-1;
|
int32_t size = sizeof(buf)-1;
|
||||||
socket->readData(buf, size);
|
socket->readData(buf, size);
|
||||||
if(size == 0) {
|
if(size == 0) {
|
||||||
throw new DlRetryEx(EX_GOT_EOF);
|
throw new DlRetryEx(EX_GOT_EOF);
|
||||||
|
@ -167,7 +167,7 @@ bool FtpConnection::bulkReceiveResponse(pair<int, string>& response) {
|
||||||
buf[size] = '\0';
|
buf[size] = '\0';
|
||||||
strbuf += buf;
|
strbuf += buf;
|
||||||
}
|
}
|
||||||
int status;
|
int32_t status;
|
||||||
if(strbuf.size() >= 4) {
|
if(strbuf.size() >= 4) {
|
||||||
status = getStatus(strbuf);
|
status = getStatus(strbuf);
|
||||||
if(status == 0) {
|
if(status == 0) {
|
||||||
|
@ -188,8 +188,8 @@ bool FtpConnection::bulkReceiveResponse(pair<int, string>& response) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int FtpConnection::receiveResponse() {
|
int32_t FtpConnection::receiveResponse() {
|
||||||
pair<int, string> response;
|
pair<int32_t, string> response;
|
||||||
if(bulkReceiveResponse(response)) {
|
if(bulkReceiveResponse(response)) {
|
||||||
return response.first;
|
return response.first;
|
||||||
} else {
|
} else {
|
||||||
|
@ -197,8 +197,8 @@ int FtpConnection::receiveResponse() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int FtpConnection::receiveSizeResponse(long long int& size) {
|
int32_t FtpConnection::receiveSizeResponse(int64_t& size) {
|
||||||
pair<int, string> response;
|
pair<int32_t, string> response;
|
||||||
if(bulkReceiveResponse(response)) {
|
if(bulkReceiveResponse(response)) {
|
||||||
if(response.first == 213) {
|
if(response.first == 213) {
|
||||||
sscanf(response.second.c_str(), "%*d %Ld", &size);
|
sscanf(response.second.c_str(), "%*d %Ld", &size);
|
||||||
|
@ -209,12 +209,12 @@ int FtpConnection::receiveSizeResponse(long long int& size) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int FtpConnection::receivePasvResponse(pair<string, int>& dest) {
|
int32_t FtpConnection::receivePasvResponse(pair<string, int32_t>& dest) {
|
||||||
pair<int, string> response;
|
pair<int32_t, string> response;
|
||||||
if(bulkReceiveResponse(response)) {
|
if(bulkReceiveResponse(response)) {
|
||||||
if(response.first == 227) {
|
if(response.first == 227) {
|
||||||
// we assume the format of response is "227 Entering Passive Mode (h1,h2,h3,h4,p1,p2)."
|
// we assume the format of response is "227 Entering Passive Mode (h1,h2,h3,h4,p1,p2)."
|
||||||
int h1, h2, h3, h4, p1, p2;
|
int32_t h1, h2, h3, h4, p1, p2;
|
||||||
string::size_type p = response.second.find("(");
|
string::size_type p = response.second.find("(");
|
||||||
if(p >= 4) {
|
if(p >= 4) {
|
||||||
sscanf(response.second.substr(response.second.find("(")).c_str(),
|
sscanf(response.second.substr(response.second.find("(")).c_str(),
|
||||||
|
|
|
@ -47,7 +47,7 @@ using namespace std;
|
||||||
|
|
||||||
class FtpConnection {
|
class FtpConnection {
|
||||||
private:
|
private:
|
||||||
int cuid;
|
int32_t cuid;
|
||||||
SocketHandle socket;
|
SocketHandle socket;
|
||||||
RequestHandle req;
|
RequestHandle req;
|
||||||
const Option* option;
|
const Option* option;
|
||||||
|
@ -55,11 +55,11 @@ private:
|
||||||
|
|
||||||
string strbuf;
|
string strbuf;
|
||||||
|
|
||||||
int getStatus(const string& response) const;
|
int32_t getStatus(const string& response) const;
|
||||||
bool isEndOfResponse(int status, const string& response) const;
|
bool isEndOfResponse(int32_t status, const string& response) const;
|
||||||
bool bulkReceiveResponse(pair<int, string>& response);
|
bool bulkReceiveResponse(pair<int32_t, string>& response);
|
||||||
public:
|
public:
|
||||||
FtpConnection(int cuid, const SocketHandle& socket,
|
FtpConnection(int32_t cuid, const SocketHandle& socket,
|
||||||
const RequestHandle req, const Option* op);
|
const RequestHandle req, const Option* op);
|
||||||
~FtpConnection();
|
~FtpConnection();
|
||||||
void sendUser() const;
|
void sendUser() const;
|
||||||
|
@ -72,9 +72,9 @@ public:
|
||||||
void sendRest(const SegmentHandle& segment) const;
|
void sendRest(const SegmentHandle& segment) const;
|
||||||
void sendRetr() const;
|
void sendRetr() const;
|
||||||
|
|
||||||
int receiveResponse();
|
int32_t receiveResponse();
|
||||||
int receiveSizeResponse(long long int& size);
|
int32_t receiveSizeResponse(int64_t& size);
|
||||||
int receivePasvResponse(pair<string, int>& dest);
|
int32_t receivePasvResponse(pair<string, int32_t>& dest);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _D_FTP_CONNECTION_H_
|
#endif // _D_FTP_CONNECTION_H_
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "FatalException.h"
|
#include "FatalException.h"
|
||||||
|
|
||||||
FtpNegotiationCommand::FtpNegotiationCommand(int cuid,
|
FtpNegotiationCommand::FtpNegotiationCommand(int32_t cuid,
|
||||||
const RequestHandle& req,
|
const RequestHandle& req,
|
||||||
RequestGroup* requestGroup,
|
RequestGroup* requestGroup,
|
||||||
DownloadEngine* e,
|
DownloadEngine* e,
|
||||||
|
@ -82,7 +82,7 @@ bool FtpNegotiationCommand::recvGreeting() {
|
||||||
disableWriteCheckSocket();
|
disableWriteCheckSocket();
|
||||||
setReadCheckSocket(socket);
|
setReadCheckSocket(socket);
|
||||||
|
|
||||||
int status = ftp->receiveResponse();
|
int32_t status = ftp->receiveResponse();
|
||||||
if(status == 0) {
|
if(status == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ bool FtpNegotiationCommand::sendUser() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FtpNegotiationCommand::recvUser() {
|
bool FtpNegotiationCommand::recvUser() {
|
||||||
int status = ftp->receiveResponse();
|
int32_t status = ftp->receiveResponse();
|
||||||
switch(status) {
|
switch(status) {
|
||||||
case 0:
|
case 0:
|
||||||
return false;
|
return false;
|
||||||
|
@ -124,7 +124,7 @@ bool FtpNegotiationCommand::sendPass() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FtpNegotiationCommand::recvPass() {
|
bool FtpNegotiationCommand::recvPass() {
|
||||||
int status = ftp->receiveResponse();
|
int32_t status = ftp->receiveResponse();
|
||||||
if(status == 0) {
|
if(status == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ bool FtpNegotiationCommand::sendType() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FtpNegotiationCommand::recvType() {
|
bool FtpNegotiationCommand::recvType() {
|
||||||
int status = ftp->receiveResponse();
|
int32_t status = ftp->receiveResponse();
|
||||||
if(status == 0) {
|
if(status == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -160,7 +160,7 @@ bool FtpNegotiationCommand::sendCwd() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FtpNegotiationCommand::recvCwd() {
|
bool FtpNegotiationCommand::recvCwd() {
|
||||||
int status = ftp->receiveResponse();
|
int32_t status = ftp->receiveResponse();
|
||||||
if(status == 0) {
|
if(status == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -178,8 +178,8 @@ bool FtpNegotiationCommand::sendSize() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FtpNegotiationCommand::recvSize() {
|
bool FtpNegotiationCommand::recvSize() {
|
||||||
long long int size = 0;
|
int64_t size = 0;
|
||||||
int status = ftp->receiveSizeResponse(size);
|
int32_t status = ftp->receiveSizeResponse(size);
|
||||||
if(status == 0) {
|
if(status == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -253,7 +253,7 @@ bool FtpNegotiationCommand::sendPort() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FtpNegotiationCommand::recvPort() {
|
bool FtpNegotiationCommand::recvPort() {
|
||||||
int status = ftp->receiveResponse();
|
int32_t status = ftp->receiveResponse();
|
||||||
if(status == 0) {
|
if(status == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -271,8 +271,8 @@ bool FtpNegotiationCommand::sendPasv() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FtpNegotiationCommand::recvPasv() {
|
bool FtpNegotiationCommand::recvPasv() {
|
||||||
pair<string, int> dest;
|
pair<string, int32_t> dest;
|
||||||
int status = ftp->receivePasvResponse(dest);
|
int32_t status = ftp->receivePasvResponse(dest);
|
||||||
if(status == 0) {
|
if(status == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -306,7 +306,7 @@ bool FtpNegotiationCommand::sendRest(const SegmentHandle& segment) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FtpNegotiationCommand::recvRest() {
|
bool FtpNegotiationCommand::recvRest() {
|
||||||
int status = ftp->receiveResponse();
|
int32_t status = ftp->receiveResponse();
|
||||||
if(status == 0) {
|
if(status == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -325,7 +325,7 @@ bool FtpNegotiationCommand::sendRetr() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FtpNegotiationCommand::recvRetr() {
|
bool FtpNegotiationCommand::recvRetr() {
|
||||||
int status = ftp->receiveResponse();
|
int32_t status = ftp->receiveResponse();
|
||||||
if(status == 0) {
|
if(status == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,12 +91,12 @@ private:
|
||||||
|
|
||||||
SocketHandle dataSocket;
|
SocketHandle dataSocket;
|
||||||
SocketHandle serverSocket;
|
SocketHandle serverSocket;
|
||||||
int sequence;
|
int32_t sequence;
|
||||||
FtpConnection* ftp;
|
FtpConnection* ftp;
|
||||||
protected:
|
protected:
|
||||||
virtual bool executeInternal();
|
virtual bool executeInternal();
|
||||||
public:
|
public:
|
||||||
FtpNegotiationCommand(int cuid,
|
FtpNegotiationCommand(int32_t cuid,
|
||||||
const RequestHandle& req,
|
const RequestHandle& req,
|
||||||
RequestGroup* requestGroup,
|
RequestGroup* requestGroup,
|
||||||
DownloadEngine* e,
|
DownloadEngine* e,
|
||||||
|
|
|
@ -34,10 +34,10 @@
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "HaveEraseCommand.h"
|
#include "HaveEraseCommand.h"
|
||||||
|
|
||||||
HaveEraseCommand::HaveEraseCommand(int cuid,
|
HaveEraseCommand::HaveEraseCommand(int32_t cuid,
|
||||||
TorrentDownloadEngine* e,
|
TorrentDownloadEngine* e,
|
||||||
const BtContextHandle& btContext,
|
const BtContextHandle& btContext,
|
||||||
int interval)
|
int32_t interval)
|
||||||
:BtContextAwareCommand(cuid, btContext),
|
:BtContextAwareCommand(cuid, btContext),
|
||||||
e(e),
|
e(e),
|
||||||
interval(interval) {}
|
interval(interval) {}
|
||||||
|
|
|
@ -42,12 +42,12 @@ class HaveEraseCommand : public BtContextAwareCommand {
|
||||||
private:
|
private:
|
||||||
TorrentDownloadEngine* e;
|
TorrentDownloadEngine* e;
|
||||||
Time cp;
|
Time cp;
|
||||||
int interval;
|
int32_t interval;
|
||||||
public:
|
public:
|
||||||
HaveEraseCommand(int cuid,
|
HaveEraseCommand(int32_t cuid,
|
||||||
TorrentDownloadEngine* e,
|
TorrentDownloadEngine* e,
|
||||||
const BtContextHandle& btContext,
|
const BtContextHandle& btContext,
|
||||||
int interval);
|
int32_t interval);
|
||||||
|
|
||||||
virtual ~HaveEraseCommand() {}
|
virtual ~HaveEraseCommand() {}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
#include "LogFactory.h"
|
#include "LogFactory.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
HttpConnection::HttpConnection(int cuid,
|
HttpConnection::HttpConnection(int32_t cuid,
|
||||||
const SocketHandle& socket,
|
const SocketHandle& socket,
|
||||||
const Option* op):
|
const Option* op):
|
||||||
cuid(cuid), socket(socket), option(op), logger(LogFactory::getInstance())
|
cuid(cuid), socket(socket), option(op), logger(LogFactory::getInstance())
|
||||||
|
|
|
@ -75,7 +75,7 @@ typedef deque<HttpRequestEntryHandle> HttpRequestEntries;
|
||||||
|
|
||||||
class HttpConnection {
|
class HttpConnection {
|
||||||
private:
|
private:
|
||||||
int cuid;
|
int32_t cuid;
|
||||||
SocketHandle socket;
|
SocketHandle socket;
|
||||||
const Option* option;
|
const Option* option;
|
||||||
const Logger* logger;
|
const Logger* logger;
|
||||||
|
@ -84,7 +84,7 @@ private:
|
||||||
|
|
||||||
string eraseConfidentialInfo(const string& request);
|
string eraseConfidentialInfo(const string& request);
|
||||||
public:
|
public:
|
||||||
HttpConnection(int cuid,
|
HttpConnection(int32_t cuid,
|
||||||
const SocketHandle& socket,
|
const SocketHandle& socket,
|
||||||
const Option* op);
|
const Option* op);
|
||||||
|
|
||||||
|
|
|
@ -61,11 +61,11 @@ Strings HttpHeader::get(const string& name) const {
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
int HttpHeader::getFirstAsInt(const string& name) const {
|
int32_t HttpHeader::getFirstAsInt(const string& name) const {
|
||||||
return (int)getFirstAsLLInt(name);
|
return getFirstAsLLInt(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
long long int HttpHeader::getFirstAsLLInt(const string& name) const {
|
int64_t HttpHeader::getFirstAsLLInt(const string& name) const {
|
||||||
string value = getFirst(name);
|
string value = getFirst(name);
|
||||||
if(value == "") {
|
if(value == "") {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -52,8 +52,8 @@ public:
|
||||||
bool defined(const string& name) const;
|
bool defined(const string& name) const;
|
||||||
string getFirst(const string& name) const;
|
string getFirst(const string& name) const;
|
||||||
Strings get(const string& name) const;
|
Strings get(const string& name) const;
|
||||||
int getFirstAsInt(const string& name) const;
|
int32_t getFirstAsInt(const string& name) const;
|
||||||
long long int getFirstAsLLInt(const string& name) const;
|
int64_t getFirstAsLLInt(const string& name) const;
|
||||||
|
|
||||||
RangeHandle getRange() const;
|
RangeHandle getRange() const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -63,7 +63,7 @@ bool HttpRequest::isRangeSatisfied(const RangeHandle& range) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string HttpRequest::getHostText(const string& host, in_port_t port) const
|
string HttpRequest::getHostText(const string& host, int32_t port) const
|
||||||
{
|
{
|
||||||
return host+(port == 80 || port == 443 ? "" : ":"+Util::llitos(port));
|
return host+(port == 80 || port == 443 ? "" : ":"+Util::llitos(port));
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ private:
|
||||||
|
|
||||||
string userAgent;
|
string userAgent;
|
||||||
|
|
||||||
string getHostText(const string& host, in_port_t port) const;
|
string getHostText(const string& host, int32_t port) const;
|
||||||
|
|
||||||
string getProxyAuthString() const;
|
string getProxyAuthString() const;
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ public:
|
||||||
return request->getHost();
|
return request->getHost();
|
||||||
}
|
}
|
||||||
|
|
||||||
in_port_t getPort() const
|
int32_t getPort() const
|
||||||
{
|
{
|
||||||
return request->getPort();
|
return request->getPort();
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
|
|
||||||
MetaEntry* MetaFileUtil::parseMetaFile(const string& file) {
|
MetaEntry* MetaFileUtil::parseMetaFile(const string& file) {
|
||||||
File f(file);
|
File f(file);
|
||||||
int len = f.size();
|
int32_t len = f.size();
|
||||||
char* buf = new char[len];
|
char* buf = new char[len];
|
||||||
FILE* fp = fopen(file.c_str(), "r+");
|
FILE* fp = fopen(file.c_str(), "r+");
|
||||||
try {
|
try {
|
||||||
|
@ -66,7 +66,7 @@ MetaEntry* MetaFileUtil::parseMetaFile(const string& file) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MetaEntry* MetaFileUtil::bdecoding(const char* buf, int len) {
|
MetaEntry* MetaFileUtil::bdecoding(const char* buf, int32_t len) {
|
||||||
MetaEntry* entry = NULL;
|
MetaEntry* entry = NULL;
|
||||||
try{
|
try{
|
||||||
const char* p = buf;
|
const char* p = buf;
|
||||||
|
@ -157,7 +157,7 @@ Data* MetaFileUtil::decodeInt(const char** pp, const char* end) {
|
||||||
if(endTerm == NULL) {
|
if(endTerm == NULL) {
|
||||||
throw new DlAbortEx(EX_MULFORMED_META_INFO);
|
throw new DlAbortEx(EX_MULFORMED_META_INFO);
|
||||||
}
|
}
|
||||||
int numSize = endTerm-*pp;
|
int32_t numSize = endTerm-*pp;
|
||||||
|
|
||||||
Data* data = new Data(*pp, numSize, true);
|
Data* data = new Data(*pp, numSize, true);
|
||||||
*pp += numSize+1;
|
*pp += numSize+1;
|
||||||
|
@ -173,12 +173,12 @@ Data* MetaFileUtil::decodeWord(const char** pp, const char* end) {
|
||||||
if(delim == *pp || delim == NULL) {
|
if(delim == *pp || delim == NULL) {
|
||||||
throw new DlAbortEx(EX_MULFORMED_META_INFO);
|
throw new DlAbortEx(EX_MULFORMED_META_INFO);
|
||||||
}
|
}
|
||||||
int numSize = delim-*pp;
|
int32_t numSize = delim-*pp;
|
||||||
char* temp = new char[numSize+1];
|
char* temp = new char[numSize+1];
|
||||||
memcpy(temp, *pp, numSize);
|
memcpy(temp, *pp, numSize);
|
||||||
temp[numSize] = '\0';
|
temp[numSize] = '\0';
|
||||||
char* endptr;
|
char* endptr;
|
||||||
int size = strtol(temp, &endptr, 10);
|
int32_t size = strtol(temp, &endptr, 10);
|
||||||
if(*endptr != '\0') {
|
if(*endptr != '\0') {
|
||||||
delete [] temp;
|
delete [] temp;
|
||||||
throw new DlAbortEx(EX_MULFORMED_META_INFO);
|
throw new DlAbortEx(EX_MULFORMED_META_INFO);
|
||||||
|
|
|
@ -57,7 +57,7 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static MetaEntry* parseMetaFile(const string& file);
|
static MetaEntry* parseMetaFile(const string& file);
|
||||||
static MetaEntry* bdecoding(const char* buf, int len);
|
static MetaEntry* bdecoding(const char* buf, int32_t len);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _D_META_FILE_UTIL_H_
|
#endif // _D_META_FILE_UTIL_H_
|
||||||
|
|
|
@ -48,9 +48,9 @@ MetalinkEntry::~MetalinkEntry() {}
|
||||||
class AddLocationPreference {
|
class AddLocationPreference {
|
||||||
private:
|
private:
|
||||||
string location;
|
string location;
|
||||||
int preferenceToAdd;
|
int32_t preferenceToAdd;
|
||||||
public:
|
public:
|
||||||
AddLocationPreference(const string& location, int preferenceToAdd):
|
AddLocationPreference(const string& location, int32_t preferenceToAdd):
|
||||||
location(location), preferenceToAdd(preferenceToAdd) {}
|
location(location), preferenceToAdd(preferenceToAdd) {}
|
||||||
|
|
||||||
void operator()(MetalinkResourceHandle& res) {
|
void operator()(MetalinkResourceHandle& res) {
|
||||||
|
@ -60,7 +60,7 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void MetalinkEntry::setLocationPreference(const string& location, int preferenceToAdd) {
|
void MetalinkEntry::setLocationPreference(const string& location, int32_t preferenceToAdd) {
|
||||||
for_each(resources.begin(), resources.end(),
|
for_each(resources.begin(), resources.end(),
|
||||||
AddLocationPreference(location, preferenceToAdd));
|
AddLocationPreference(location, preferenceToAdd));
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,7 +94,7 @@ public:
|
||||||
|
|
||||||
void reorderResourcesByPreference();
|
void reorderResourcesByPreference();
|
||||||
|
|
||||||
void setLocationPreference(const string& location, int preferenceToAdd);
|
void setLocationPreference(const string& location, int32_t preferenceToAdd);
|
||||||
|
|
||||||
static FileEntries toFileEntry(const MetalinkEntries& metalinkEntries);
|
static FileEntries toFileEntry(const MetalinkEntries& metalinkEntries);
|
||||||
};
|
};
|
||||||
|
|
|
@ -43,10 +43,9 @@
|
||||||
class AccumulateNonP2PUrl {
|
class AccumulateNonP2PUrl {
|
||||||
private:
|
private:
|
||||||
Strings* urlsPtr;
|
Strings* urlsPtr;
|
||||||
int split;
|
int32_t split;
|
||||||
public:
|
public:
|
||||||
AccumulateNonP2PUrl(Strings* urlsPtr,
|
AccumulateNonP2PUrl(Strings* urlsPtr, int32_t split)
|
||||||
int split)
|
|
||||||
:urlsPtr(urlsPtr),
|
:urlsPtr(urlsPtr),
|
||||||
split(split) {}
|
split(split) {}
|
||||||
|
|
||||||
|
@ -55,7 +54,7 @@ public:
|
||||||
case MetalinkResource::TYPE_HTTP:
|
case MetalinkResource::TYPE_HTTP:
|
||||||
case MetalinkResource::TYPE_HTTPS:
|
case MetalinkResource::TYPE_HTTPS:
|
||||||
case MetalinkResource::TYPE_FTP:
|
case MetalinkResource::TYPE_FTP:
|
||||||
for(int s = 1; s <= split; s++) {
|
for(int32_t s = 1; s <= split; s++) {
|
||||||
urlsPtr->push_back(resource->url);
|
urlsPtr->push_back(resource->url);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -48,9 +48,9 @@ public:
|
||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
string url;
|
string url;
|
||||||
int type;
|
TYPE type;
|
||||||
string location;
|
string location;
|
||||||
int preference;
|
int32_t preference;
|
||||||
public:
|
public:
|
||||||
MetalinkResource();
|
MetalinkResource();
|
||||||
~MetalinkResource();
|
~MetalinkResource();
|
||||||
|
|
|
@ -145,7 +145,7 @@ int32_t MultiDiskAdaptor::calculateLength(const DiskWriterEntryHandle entry,
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MultiDiskAdaptor::readData(unsigned char* data, int32_t len, int64_t offset)
|
int32_t MultiDiskAdaptor::readData(unsigned char* data, int32_t len, int64_t offset)
|
||||||
{
|
{
|
||||||
int64_t fileOffset = offset;
|
int64_t fileOffset = offset;
|
||||||
bool reading = false;
|
bool reading = false;
|
||||||
|
|
|
@ -140,7 +140,7 @@ public:
|
||||||
virtual void writeData(const unsigned char* data, int32_t len,
|
virtual void writeData(const unsigned char* data, int32_t len,
|
||||||
int64_t offset);
|
int64_t offset);
|
||||||
|
|
||||||
virtual int readData(unsigned char* data, int32_t len, int64_t offset);
|
virtual int32_t readData(unsigned char* data, int32_t len, int64_t offset);
|
||||||
|
|
||||||
virtual string messageDigest(int64_t offset, int64_t length,
|
virtual string messageDigest(int64_t offset, int64_t length,
|
||||||
const MessageDigestContext::DigestAlgo& algo);
|
const MessageDigestContext::DigestAlgo& algo);
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
|
|
||||||
#ifdef ENABLE_ASYNC_DNS
|
#ifdef ENABLE_ASYNC_DNS
|
||||||
|
|
||||||
void callback(void* arg, int status, struct hostent* host) {
|
void callback(void* arg, int32_t status, struct hostent* host) {
|
||||||
NameResolver* resolverPtr = (NameResolver*)arg;
|
NameResolver* resolverPtr = (NameResolver*)arg;
|
||||||
#ifdef HAVE_LIBARES
|
#ifdef HAVE_LIBARES
|
||||||
// This block is required since the assertion in ares_strerror fails
|
// This block is required since the assertion in ares_strerror fails
|
||||||
|
@ -75,7 +75,7 @@ void NameResolver::resolve(const string& hostname)
|
||||||
ai.ai_socktype = SOCK_STREAM;
|
ai.ai_socktype = SOCK_STREAM;
|
||||||
ai.ai_protocol = 0;
|
ai.ai_protocol = 0;
|
||||||
struct addrinfo* res;
|
struct addrinfo* res;
|
||||||
int ec;
|
int32_t ec;
|
||||||
if((ec = getaddrinfo(hostname.c_str(), 0, &ai, &res)) != 0) {
|
if((ec = getaddrinfo(hostname.c_str(), 0, &ai, &res)) != 0) {
|
||||||
throw new DlAbortEx(EX_RESOLVE_HOSTNAME,
|
throw new DlAbortEx(EX_RESOLVE_HOSTNAME,
|
||||||
hostname.c_str(), gai_strerror(ec));
|
hostname.c_str(), gai_strerror(ec));
|
||||||
|
|
|
@ -51,10 +51,10 @@ extern "C" {
|
||||||
} /* end of extern "C" */
|
} /* end of extern "C" */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void callback(void* arg, int status, struct hostent* host);
|
void callback(void* arg, int32_t status, struct hostent* host);
|
||||||
|
|
||||||
class NameResolver {
|
class NameResolver {
|
||||||
friend void callback(void* arg, int status, struct hostent* host);
|
friend void callback(void* arg, int32_t status, struct hostent* host);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum STATUS {
|
enum STATUS {
|
||||||
|
@ -100,7 +100,7 @@ public:
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getFds(fd_set* rfdsPtr, fd_set* wfdsPtr) const {
|
int32_t getFds(fd_set* rfdsPtr, fd_set* wfdsPtr) const {
|
||||||
return ares_fds(channel, rfdsPtr, wfdsPtr);
|
return ares_fds(channel, rfdsPtr, wfdsPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,16 +56,16 @@ string Option::get(const string& name) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Option::getAsInt(const string& name) const {
|
int32_t Option::getAsInt(const string& name) const {
|
||||||
string value = get(name);
|
string value = get(name);
|
||||||
if(value == "") {
|
if(value == "") {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
return (int)strtol(value.c_str(), NULL, 10);
|
return strtol(value.c_str(), NULL, 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
long long int Option::getAsLLInt(const string& name) const {
|
int64_t Option::getAsLLInt(const string& name) const {
|
||||||
string value = get(name);
|
string value = get(name);
|
||||||
if(value == "") {
|
if(value == "") {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -51,8 +51,8 @@ public:
|
||||||
void put(const string& name, const string& value);
|
void put(const string& name, const string& value);
|
||||||
bool defined(const string& name) const;
|
bool defined(const string& name) const;
|
||||||
string get(const string& name) const;
|
string get(const string& name) const;
|
||||||
int getAsInt(const string& name) const;
|
int32_t getAsInt(const string& name) const;
|
||||||
long long int getAsLLInt(const string& name) const;
|
int64_t getAsLLInt(const string& name) const;
|
||||||
bool getAsBool(const string& name) const;
|
bool getAsBool(const string& name) const;
|
||||||
double getAsDouble(const string& name) const;
|
double getAsDouble(const string& name) const;
|
||||||
|
|
||||||
|
|
20
src/Peer.cc
20
src/Peer.cc
|
@ -36,7 +36,7 @@
|
||||||
#include "BitfieldManFactory.h"
|
#include "BitfieldManFactory.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|
||||||
Peer::Peer(string ipaddr, int port, int pieceLength, long long int totalLength):
|
Peer::Peer(string ipaddr, int32_t port, int32_t pieceLength, int64_t totalLength):
|
||||||
ipaddr(ipaddr),
|
ipaddr(ipaddr),
|
||||||
port(port),
|
port(port),
|
||||||
sessionUploadLength(0),
|
sessionUploadLength(0),
|
||||||
|
@ -62,7 +62,7 @@ Peer::Peer():entryId(0), ipaddr(""), port(0), bitfield(0),
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void Peer::updateBitfield(int index, int operation) {
|
void Peer::updateBitfield(int32_t index, int32_t operation) {
|
||||||
if(operation == 1) {
|
if(operation == 1) {
|
||||||
bitfield->setBit(index);
|
bitfield->setBit(index);
|
||||||
} else if(operation == 0) {
|
} else if(operation == 0) {
|
||||||
|
@ -79,7 +79,7 @@ bool Peer::shouldBeChoking() const {
|
||||||
return chokingRequired;
|
return chokingRequired;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Peer::hasPiece(int index) const {
|
bool Peer::hasPiece(int32_t index) const {
|
||||||
return bitfield->isBitSet(index);
|
return bitfield->isBitSet(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,33 +105,33 @@ void Peer::resetStatus() {
|
||||||
peerStat.reset();
|
peerStat.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Peer::isInFastSet(int index) const {
|
bool Peer::isInFastSet(int32_t index) const {
|
||||||
return find(fastSet.begin(), fastSet.end(), index) != fastSet.end();
|
return find(fastSet.begin(), fastSet.end(), index) != fastSet.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Peer::addFastSetIndex(int index) {
|
void Peer::addFastSetIndex(int32_t index) {
|
||||||
if(!isInFastSet(index)) {
|
if(!isInFastSet(index)) {
|
||||||
fastSet.push_back(index);
|
fastSet.push_back(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Peer::isInPeerAllowedIndexSet(int index) const {
|
bool Peer::isInPeerAllowedIndexSet(int32_t index) const {
|
||||||
return find(peerAllowedIndexSet.begin(), peerAllowedIndexSet.end(),
|
return find(peerAllowedIndexSet.begin(), peerAllowedIndexSet.end(),
|
||||||
index) != peerAllowedIndexSet.end();
|
index) != peerAllowedIndexSet.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Peer::addPeerAllowedIndex(int index) {
|
void Peer::addPeerAllowedIndex(int32_t index) {
|
||||||
if(!isInPeerAllowedIndexSet(index)) {
|
if(!isInPeerAllowedIndexSet(index)) {
|
||||||
peerAllowedIndexSet.push_back(index);
|
peerAllowedIndexSet.push_back(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Peer::isInAmAllowedIndexSet(int index) const {
|
bool Peer::isInAmAllowedIndexSet(int32_t index) const {
|
||||||
return find(amAllowedIndexSet.begin(), amAllowedIndexSet.end(),
|
return find(amAllowedIndexSet.begin(), amAllowedIndexSet.end(),
|
||||||
index) != amAllowedIndexSet.end();
|
index) != amAllowedIndexSet.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Peer::addAmAllowedIndex(int index) {
|
void Peer::addAmAllowedIndex(int32_t index) {
|
||||||
if(!isInAmAllowedIndexSet(index)) {
|
if(!isInAmAllowedIndexSet(index)) {
|
||||||
amAllowedIndexSet.push_back(index);
|
amAllowedIndexSet.push_back(index);
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,7 @@ void Peer::setAllBitfield() {
|
||||||
bitfield->setAllBit();
|
bitfield->setAllBit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Peer::updateLatency(int latency) {
|
void Peer::updateLatency(int32_t latency) {
|
||||||
this->latency = (this->latency*20+latency*80)/200;
|
this->latency = (this->latency*20+latency*80)/200;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
52
src/Peer.h
52
src/Peer.h
|
@ -53,13 +53,13 @@ class Peer {
|
||||||
friend bool operator!=(const Peer& p1, const Peer& p2);
|
friend bool operator!=(const Peer& p1, const Peer& p2);
|
||||||
public:
|
public:
|
||||||
string ipaddr;
|
string ipaddr;
|
||||||
int port;
|
int32_t port;
|
||||||
bool amChoking;
|
bool amChoking;
|
||||||
bool amInterested;
|
bool amInterested;
|
||||||
bool peerChoking;
|
bool peerChoking;
|
||||||
bool peerInterested;
|
bool peerInterested;
|
||||||
int tryCount;
|
int32_t tryCount;
|
||||||
int cuid;
|
int32_t cuid;
|
||||||
bool chokingRequired;
|
bool chokingRequired;
|
||||||
bool optUnchoking;
|
bool optUnchoking;
|
||||||
bool snubbing;
|
bool snubbing;
|
||||||
|
@ -74,16 +74,16 @@ private:
|
||||||
// fast index set which localhost has sent to a peer.
|
// fast index set which localhost has sent to a peer.
|
||||||
Integers amAllowedIndexSet;
|
Integers amAllowedIndexSet;
|
||||||
PeerStat peerStat;
|
PeerStat peerStat;
|
||||||
long long int sessionUploadLength;
|
int64_t sessionUploadLength;
|
||||||
long long int sessionDownloadLength;
|
int64_t sessionDownloadLength;
|
||||||
int pieceLength;
|
int32_t pieceLength;
|
||||||
int latency;
|
int32_t latency;
|
||||||
bool active;
|
bool active;
|
||||||
string id;
|
string id;
|
||||||
Time _badConditionStartTime;
|
Time _badConditionStartTime;
|
||||||
int _badConditionInterval;
|
int32_t _badConditionInterval;
|
||||||
public:
|
public:
|
||||||
Peer(string ipaddr, int port, int pieceLength, long long int totalLength);
|
Peer(string ipaddr, int32_t port, int32_t pieceLength, int64_t totalLength);
|
||||||
|
|
||||||
~Peer() {
|
~Peer() {
|
||||||
delete bitfield;
|
delete bitfield;
|
||||||
|
@ -100,12 +100,12 @@ public:
|
||||||
|
|
||||||
void resetStatus();
|
void resetStatus();
|
||||||
|
|
||||||
void updateUploadLength(int bytes) {
|
void updateUploadLength(int32_t bytes) {
|
||||||
peerStat.updateUploadLength(bytes);
|
peerStat.updateUploadLength(bytes);
|
||||||
sessionUploadLength += bytes;
|
sessionUploadLength += bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateDownloadLength(int bytes) {
|
void updateDownloadLength(int32_t bytes) {
|
||||||
peerStat.updateDownloadLength(bytes);
|
peerStat.updateDownloadLength(bytes);
|
||||||
sessionDownloadLength += bytes;
|
sessionDownloadLength += bytes;
|
||||||
}
|
}
|
||||||
|
@ -135,14 +135,14 @@ public:
|
||||||
/**
|
/**
|
||||||
* Returns the number of bytes uploaded to the remote host.
|
* Returns the number of bytes uploaded to the remote host.
|
||||||
*/
|
*/
|
||||||
long long int getSessionUploadLength() const {
|
int64_t getSessionUploadLength() const {
|
||||||
return sessionUploadLength;
|
return sessionUploadLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of bytes downloaded from the remote host.
|
* Returns the number of bytes downloaded from the remote host.
|
||||||
*/
|
*/
|
||||||
long long int getSessionDownloadLength() const {
|
int64_t getSessionDownloadLength() const {
|
||||||
return sessionDownloadLength;
|
return sessionDownloadLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,43 +165,43 @@ public:
|
||||||
}
|
}
|
||||||
const unsigned char* getPeerId() const { return this->peerId; }
|
const unsigned char* getPeerId() const { return this->peerId; }
|
||||||
|
|
||||||
void setBitfield(const unsigned char* bitfield, int bitfieldLength) {
|
void setBitfield(const unsigned char* bitfield, int32_t bitfieldLength) {
|
||||||
this->bitfield->setBitfield(bitfield, bitfieldLength);
|
this->bitfield->setBitfield(bitfield, bitfieldLength);
|
||||||
}
|
}
|
||||||
const unsigned char* getBitfield() const { return bitfield->getBitfield(); }
|
const unsigned char* getBitfield() const { return bitfield->getBitfield(); }
|
||||||
int getBitfieldLength() const { return bitfield->getBitfieldLength(); }
|
int32_t getBitfieldLength() const { return bitfield->getBitfieldLength(); }
|
||||||
void setAllBitfield();
|
void setAllBitfield();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* operation = 1: set index-th bit to 1
|
* operation = 1: set index-th bit to 1
|
||||||
* operation = 0: set index-th bit to 0
|
* operation = 0: set index-th bit to 0
|
||||||
*/
|
*/
|
||||||
void updateBitfield(int index, int operation);
|
void updateBitfield(int32_t index, int32_t operation);
|
||||||
|
|
||||||
void setFastExtensionEnabled(bool enabled) {
|
void setFastExtensionEnabled(bool enabled) {
|
||||||
fastExtensionEnabled = enabled;
|
fastExtensionEnabled = enabled;
|
||||||
}
|
}
|
||||||
bool isFastExtensionEnabled() const { return fastExtensionEnabled; }
|
bool isFastExtensionEnabled() const { return fastExtensionEnabled; }
|
||||||
|
|
||||||
void addFastSetIndex(int index);
|
void addFastSetIndex(int32_t index);
|
||||||
const Integers& getFastSet() const { return fastSet; }
|
const Integers& getFastSet() const { return fastSet; }
|
||||||
bool isInFastSet(int index) const;
|
bool isInFastSet(int32_t index) const;
|
||||||
int countFastSet() const { return fastSet.size(); }
|
int32_t countFastSet() const { return fastSet.size(); }
|
||||||
|
|
||||||
void addPeerAllowedIndex(int index);
|
void addPeerAllowedIndex(int32_t index);
|
||||||
bool isInPeerAllowedIndexSet(int index) const;
|
bool isInPeerAllowedIndexSet(int32_t index) const;
|
||||||
|
|
||||||
void addAmAllowedIndex(int index);
|
void addAmAllowedIndex(int32_t index);
|
||||||
bool isInAmAllowedIndexSet(int index) const;
|
bool isInAmAllowedIndexSet(int32_t index) const;
|
||||||
|
|
||||||
bool shouldBeChoking() const;
|
bool shouldBeChoking() const;
|
||||||
|
|
||||||
bool hasPiece(int index) const;
|
bool hasPiece(int32_t index) const;
|
||||||
|
|
||||||
bool isSeeder() const;
|
bool isSeeder() const;
|
||||||
|
|
||||||
void updateLatency(int latency);
|
void updateLatency(int32_t latency);
|
||||||
int getLatency() const { return latency; }
|
int32_t getLatency() const { return latency; }
|
||||||
|
|
||||||
const string& getId() const {
|
const string& getId() const {
|
||||||
return id;
|
return id;
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "prefs.h"
|
#include "prefs.h"
|
||||||
|
|
||||||
PeerAbstractCommand::PeerAbstractCommand(int cuid, const PeerHandle& peer,
|
PeerAbstractCommand::PeerAbstractCommand(int32_t cuid, const PeerHandle& peer,
|
||||||
TorrentDownloadEngine* e,
|
TorrentDownloadEngine* e,
|
||||||
const BtContextHandle& btContext,
|
const BtContextHandle& btContext,
|
||||||
const SocketHandle& s)
|
const SocketHandle& s)
|
||||||
|
@ -88,11 +88,11 @@ bool PeerAbstractCommand::execute() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO this method removed when PeerBalancerCommand is implemented
|
// TODO this method removed when PeerBalancerCommand is implemented
|
||||||
bool PeerAbstractCommand::prepareForNextPeer(int wait) {
|
bool PeerAbstractCommand::prepareForNextPeer(int32_t wait) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PeerAbstractCommand::prepareForRetry(int wait) {
|
bool PeerAbstractCommand::prepareForRetry(int32_t wait) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ void PeerAbstractCommand::setWriteCheckSocket(const SocketHandle& socket) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerAbstractCommand::setUploadLimit(int uploadLimit) {
|
void PeerAbstractCommand::setUploadLimit(int32_t uploadLimit) {
|
||||||
this->uploadLimit = uploadLimit;
|
this->uploadLimit = uploadLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,22 +44,22 @@
|
||||||
class PeerAbstractCommand : public BtContextAwareCommand {
|
class PeerAbstractCommand : public BtContextAwareCommand {
|
||||||
private:
|
private:
|
||||||
Time checkPoint;
|
Time checkPoint;
|
||||||
int timeout;
|
int32_t timeout;
|
||||||
protected:
|
protected:
|
||||||
TorrentDownloadEngine* e;
|
TorrentDownloadEngine* e;
|
||||||
SocketHandle socket;
|
SocketHandle socket;
|
||||||
PeerHandle peer;
|
PeerHandle peer;
|
||||||
|
|
||||||
void setTimeout(int timeout) { this->timeout = timeout; }
|
void setTimeout(int32_t timeout) { this->timeout = timeout; }
|
||||||
virtual bool prepareForNextPeer(int wait);
|
virtual bool prepareForNextPeer(int32_t wait);
|
||||||
virtual bool prepareForRetry(int wait);
|
virtual bool prepareForRetry(int32_t wait);
|
||||||
virtual void onAbort(Exception* ex);
|
virtual void onAbort(Exception* ex);
|
||||||
virtual bool executeInternal() = 0;
|
virtual bool executeInternal() = 0;
|
||||||
void setReadCheckSocket(const SocketHandle& socket);
|
void setReadCheckSocket(const SocketHandle& socket);
|
||||||
void setWriteCheckSocket(const SocketHandle& socket);
|
void setWriteCheckSocket(const SocketHandle& socket);
|
||||||
void disableReadCheckSocket();
|
void disableReadCheckSocket();
|
||||||
void disableWriteCheckSocket();
|
void disableWriteCheckSocket();
|
||||||
void setUploadLimit(int uploadLimit);
|
void setUploadLimit(int32_t uploadLimit);
|
||||||
void setUploadLimitCheck(bool check);
|
void setUploadLimitCheck(bool check);
|
||||||
void setNoCheck(bool check);
|
void setNoCheck(bool check);
|
||||||
private:
|
private:
|
||||||
|
@ -68,10 +68,10 @@ private:
|
||||||
SocketHandle readCheckTarget;
|
SocketHandle readCheckTarget;
|
||||||
SocketHandle writeCheckTarget;
|
SocketHandle writeCheckTarget;
|
||||||
bool uploadLimitCheck;
|
bool uploadLimitCheck;
|
||||||
int uploadLimit;
|
int32_t uploadLimit;
|
||||||
bool noCheck;
|
bool noCheck;
|
||||||
public:
|
public:
|
||||||
PeerAbstractCommand(int cuid, const PeerHandle& peer,
|
PeerAbstractCommand(int32_t cuid, const PeerHandle& peer,
|
||||||
TorrentDownloadEngine* e,
|
TorrentDownloadEngine* e,
|
||||||
const BtContextHandle& btContext,
|
const BtContextHandle& btContext,
|
||||||
const SocketHandle& s = SocketHandle());
|
const SocketHandle& s = SocketHandle());
|
||||||
|
|
|
@ -35,10 +35,10 @@
|
||||||
#include "PeerChokeCommand.h"
|
#include "PeerChokeCommand.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|
||||||
PeerChokeCommand::PeerChokeCommand(int cuid,
|
PeerChokeCommand::PeerChokeCommand(int32_t cuid,
|
||||||
TorrentDownloadEngine* e,
|
TorrentDownloadEngine* e,
|
||||||
const BtContextHandle& btContext,
|
const BtContextHandle& btContext,
|
||||||
int interval):
|
int32_t interval):
|
||||||
BtContextAwareCommand(cuid, btContext),
|
BtContextAwareCommand(cuid, btContext),
|
||||||
interval(interval),
|
interval(interval),
|
||||||
e(e),
|
e(e),
|
||||||
|
@ -59,7 +59,7 @@ void PeerChokeCommand::optUnchokingPeer(Peers& peers) const {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
random_shuffle(peers.begin(), peers.end());
|
random_shuffle(peers.begin(), peers.end());
|
||||||
int optUnchokCount = 1;
|
int32_t optUnchokCount = 1;
|
||||||
for(Peers::iterator itr = peers.begin(); itr != peers.end(); itr++) {
|
for(Peers::iterator itr = peers.begin(); itr != peers.end(); itr++) {
|
||||||
Peers::value_type peer = *itr;
|
Peers::value_type peer = *itr;
|
||||||
if(optUnchokCount > 0 && !peer->snubbing) {
|
if(optUnchokCount > 0 && !peer->snubbing) {
|
||||||
|
@ -108,7 +108,7 @@ bool PeerChokeCommand::execute() {
|
||||||
} else {
|
} else {
|
||||||
orderByDownloadRate(peers);
|
orderByDownloadRate(peers);
|
||||||
}
|
}
|
||||||
int unchokingCount = 4;//peers.size() >= 4 ? 4 : peers.size();
|
int32_t unchokingCount = 4;//peers.size() >= 4 ? 4 : peers.size();
|
||||||
for(Peers::iterator itr = peers.begin(); itr != peers.end() && unchokingCount > 0; ) {
|
for(Peers::iterator itr = peers.begin(); itr != peers.end() && unchokingCount > 0; ) {
|
||||||
PeerHandle peer = *itr;
|
PeerHandle peer = *itr;
|
||||||
if(peer->peerInterested && !peer->snubbing) {
|
if(peer->peerInterested && !peer->snubbing) {
|
||||||
|
|
|
@ -41,9 +41,9 @@
|
||||||
|
|
||||||
class PeerChokeCommand : public BtContextAwareCommand {
|
class PeerChokeCommand : public BtContextAwareCommand {
|
||||||
private:
|
private:
|
||||||
int interval;
|
int32_t interval;
|
||||||
TorrentDownloadEngine* e;
|
TorrentDownloadEngine* e;
|
||||||
int rotate;
|
int32_t rotate;
|
||||||
Time checkPoint;
|
Time checkPoint;
|
||||||
|
|
||||||
void orderByUploadRate(Peers& peers) const;
|
void orderByUploadRate(Peers& peers) const;
|
||||||
|
@ -51,10 +51,10 @@ private:
|
||||||
void optUnchokingPeer(Peers& peers) const;
|
void optUnchokingPeer(Peers& peers) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PeerChokeCommand(int cuid,
|
PeerChokeCommand(int32_t cuid,
|
||||||
TorrentDownloadEngine* e,
|
TorrentDownloadEngine* e,
|
||||||
const BtContextHandle& btContext,
|
const BtContextHandle& btContext,
|
||||||
int interval);
|
int32_t interval);
|
||||||
|
|
||||||
virtual ~PeerChokeCommand();
|
virtual ~PeerChokeCommand();
|
||||||
|
|
||||||
|
|
|
@ -49,12 +49,12 @@
|
||||||
#include "CUIDCounter.h"
|
#include "CUIDCounter.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
PeerInteractionCommand::PeerInteractionCommand(int cuid,
|
PeerInteractionCommand::PeerInteractionCommand(int32_t cuid,
|
||||||
const PeerHandle& p,
|
const PeerHandle& p,
|
||||||
TorrentDownloadEngine* e,
|
TorrentDownloadEngine* e,
|
||||||
const BtContextHandle& btContext,
|
const BtContextHandle& btContext,
|
||||||
const SocketHandle& s,
|
const SocketHandle& s,
|
||||||
int sequence)
|
Seq sequence)
|
||||||
:PeerAbstractCommand(cuid, p, e, btContext, s),
|
:PeerAbstractCommand(cuid, p, e, btContext, s),
|
||||||
sequence(sequence),
|
sequence(sequence),
|
||||||
btInteractive(0),
|
btInteractive(0),
|
||||||
|
@ -199,7 +199,7 @@ bool PeerInteractionCommand::executeInternal() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO this method removed when PeerBalancerCommand is implemented
|
// TODO this method removed when PeerBalancerCommand is implemented
|
||||||
bool PeerInteractionCommand::prepareForNextPeer(int wait) {
|
bool PeerInteractionCommand::prepareForNextPeer(int32_t wait) {
|
||||||
if(peerStorage->isPeerAvailable() && btRuntime->lessThanEqMinPeer()) {
|
if(peerStorage->isPeerAvailable() && btRuntime->lessThanEqMinPeer()) {
|
||||||
PeerHandle peer = peerStorage->getUnusedPeer();
|
PeerHandle peer = peerStorage->getUnusedPeer();
|
||||||
peer->cuid = CUIDCounterSingletonHolder::instance()->newID();
|
peer->cuid = CUIDCounterSingletonHolder::instance()->newID();
|
||||||
|
@ -213,7 +213,7 @@ bool PeerInteractionCommand::prepareForNextPeer(int wait) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PeerInteractionCommand::prepareForRetry(int wait) {
|
bool PeerInteractionCommand::prepareForRetry(int32_t wait) {
|
||||||
e->commands.push_back(this);
|
e->commands.push_back(this);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,31 +39,32 @@
|
||||||
#include "BtInteractive.h"
|
#include "BtInteractive.h"
|
||||||
|
|
||||||
class PeerInteractionCommand : public PeerAbstractCommand {
|
class PeerInteractionCommand : public PeerAbstractCommand {
|
||||||
|
public:
|
||||||
|
enum Seq {
|
||||||
|
INITIATOR_SEND_HANDSHAKE,
|
||||||
|
INITIATOR_WAIT_HANDSHAKE,
|
||||||
|
//RECEIVER_SEND_HANDSHAKE,
|
||||||
|
RECEIVER_WAIT_HANDSHAKE,
|
||||||
|
WIRED};
|
||||||
private:
|
private:
|
||||||
int sequence;
|
Seq sequence;
|
||||||
BtInteractiveHandle btInteractive;
|
BtInteractiveHandle btInteractive;
|
||||||
int32_t maxDownloadSpeedLimit;
|
int32_t maxDownloadSpeedLimit;
|
||||||
protected:
|
protected:
|
||||||
virtual bool executeInternal();
|
virtual bool executeInternal();
|
||||||
virtual bool prepareForRetry(int wait);
|
virtual bool prepareForRetry(int32_t wait);
|
||||||
virtual bool prepareForNextPeer(int wait);
|
virtual bool prepareForNextPeer(int32_t wait);
|
||||||
virtual void onAbort(Exception* ex);
|
virtual void onAbort(Exception* ex);
|
||||||
public:
|
public:
|
||||||
PeerInteractionCommand(int cuid,
|
PeerInteractionCommand(int32_t cuid,
|
||||||
const PeerHandle& peer,
|
const PeerHandle& peer,
|
||||||
TorrentDownloadEngine* e,
|
TorrentDownloadEngine* e,
|
||||||
const BtContextHandle& btContext,
|
const BtContextHandle& btContext,
|
||||||
const SocketHandle& s,
|
const SocketHandle& s,
|
||||||
int sequence);
|
Seq sequence);
|
||||||
|
|
||||||
~PeerInteractionCommand();
|
virtual ~PeerInteractionCommand();
|
||||||
|
|
||||||
enum Seq {
|
|
||||||
INITIATOR_SEND_HANDSHAKE,
|
|
||||||
INITIATOR_WAIT_HANDSHAKE,
|
|
||||||
RECEIVER_SEND_HANDSHAKE,
|
|
||||||
RECEIVER_WAIT_HANDSHAKE,
|
|
||||||
WIRED};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _D_PEER_INTERACTION_COMMAND_H_
|
#endif // _D_PEER_INTERACTION_COMMAND_H_
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
#include "CUIDCounter.h"
|
#include "CUIDCounter.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
|
|
||||||
PeerListenCommand::PeerListenCommand(int cuid,
|
PeerListenCommand::PeerListenCommand(int32_t cuid,
|
||||||
TorrentDownloadEngine* e,
|
TorrentDownloadEngine* e,
|
||||||
const BtContextHandle& btContext)
|
const BtContextHandle& btContext)
|
||||||
:BtContextAwareCommand(cuid, btContext),
|
:BtContextAwareCommand(cuid, btContext),
|
||||||
|
@ -47,11 +47,11 @@ PeerListenCommand::PeerListenCommand(int cuid,
|
||||||
|
|
||||||
PeerListenCommand::~PeerListenCommand() {}
|
PeerListenCommand::~PeerListenCommand() {}
|
||||||
|
|
||||||
int PeerListenCommand::bindPort(int portRangeStart, int portRangeEnd) {
|
int32_t PeerListenCommand::bindPort(int32_t portRangeStart, int32_t portRangeEnd) {
|
||||||
if(portRangeStart > portRangeEnd) {
|
if(portRangeStart > portRangeEnd) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
for(int port = portRangeStart; port <= portRangeEnd; port++) {
|
for(int32_t port = portRangeStart; port <= portRangeEnd; port++) {
|
||||||
try {
|
try {
|
||||||
socket->beginListen(port);
|
socket->beginListen(port);
|
||||||
logger->info(MSG_LISTENING_PORT,
|
logger->info(MSG_LISTENING_PORT,
|
||||||
|
@ -71,13 +71,13 @@ bool PeerListenCommand::execute() {
|
||||||
if(btRuntime->isHalt()) {
|
if(btRuntime->isHalt()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for(int i = 0; i < 3 && socket->isReadable(0); i++) {
|
for(int32_t i = 0; i < 3 && socket->isReadable(0); i++) {
|
||||||
SocketHandle peerSocket;
|
SocketHandle peerSocket;
|
||||||
try {
|
try {
|
||||||
peerSocket = socket->acceptConnection();
|
peerSocket = socket->acceptConnection();
|
||||||
pair<string, int> peerInfo;
|
pair<string, int32_t> peerInfo;
|
||||||
peerSocket->getPeerInfo(peerInfo);
|
peerSocket->getPeerInfo(peerInfo);
|
||||||
pair<string, int> localInfo;
|
pair<string, int32_t> localInfo;
|
||||||
peerSocket->getAddrInfo(localInfo);
|
peerSocket->getAddrInfo(localInfo);
|
||||||
|
|
||||||
TransferStat tstat = peerStorage->calculateStat();
|
TransferStat tstat = peerStorage->calculateStat();
|
||||||
|
|
|
@ -44,15 +44,15 @@ private:
|
||||||
SocketHandle socket;
|
SocketHandle socket;
|
||||||
int32_t _lowestSpeedLimit;
|
int32_t _lowestSpeedLimit;
|
||||||
public:
|
public:
|
||||||
PeerListenCommand(int cuid,
|
PeerListenCommand(int32_t cuid,
|
||||||
TorrentDownloadEngine* e,
|
TorrentDownloadEngine* e,
|
||||||
const BtContextHandle& btContext);
|
const BtContextHandle& btContext);
|
||||||
|
|
||||||
~PeerListenCommand();
|
virtual ~PeerListenCommand();
|
||||||
|
|
||||||
bool execute();
|
bool execute();
|
||||||
|
|
||||||
int bindPort(int portRangeStart, int portRangeEnd);
|
int32_t bindPort(int32_t portRangeStart, int32_t portRangeEnd);
|
||||||
|
|
||||||
void setLowestSpeedLimit(int32_t speed)
|
void setLowestSpeedLimit(int32_t speed)
|
||||||
{
|
{
|
||||||
|
|
|
@ -48,14 +48,14 @@ public:
|
||||||
REQUEST_IDLE,
|
REQUEST_IDLE,
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
int cuid;
|
int32_t cuid;
|
||||||
SpeedCalc downloadSpeed;
|
SpeedCalc downloadSpeed;
|
||||||
SpeedCalc uploadSpeed;
|
SpeedCalc uploadSpeed;
|
||||||
Time downloadStartTime;
|
Time downloadStartTime;
|
||||||
PeerStat::STATUS status;
|
PeerStat::STATUS status;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PeerStat(int cuid = 0):cuid(cuid), status(PeerStat::IDLE) {}
|
PeerStat(int32_t cuid = 0):cuid(cuid), status(PeerStat::IDLE) {}
|
||||||
|
|
||||||
~PeerStat() {}
|
~PeerStat() {}
|
||||||
|
|
||||||
|
@ -78,27 +78,27 @@ public:
|
||||||
return uploadSpeed.calculateSpeed(now);
|
return uploadSpeed.calculateSpeed(now);
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateDownloadLength(int bytes) {
|
void updateDownloadLength(int32_t bytes) {
|
||||||
downloadSpeed.update(bytes);
|
downloadSpeed.update(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateUploadLength(int bytes) {
|
void updateUploadLength(int32_t bytes) {
|
||||||
uploadSpeed.update(bytes);
|
uploadSpeed.update(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
int getMaxDownloadSpeed() const {
|
int32_t getMaxDownloadSpeed() const {
|
||||||
return downloadSpeed.getMaxSpeed();
|
return downloadSpeed.getMaxSpeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
int getMaxUploadSpeed() const {
|
int32_t getMaxUploadSpeed() const {
|
||||||
return uploadSpeed.getMaxSpeed();
|
return uploadSpeed.getMaxSpeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
int getAvgDownloadSpeed() const {
|
int32_t getAvgDownloadSpeed() const {
|
||||||
return downloadSpeed.getAvgSpeed();
|
return downloadSpeed.getAvgSpeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
int getAvgUploadSpeed() const {
|
int32_t getAvgUploadSpeed() const {
|
||||||
return uploadSpeed.getAvgSpeed();
|
return uploadSpeed.getAvgSpeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ public:
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getCuid() const {
|
int32_t getCuid() const {
|
||||||
return cuid;
|
return cuid;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
14
src/Piece.cc
14
src/Piece.cc
|
@ -38,7 +38,7 @@
|
||||||
|
|
||||||
Piece::Piece():index(0), length(0), bitfield(0) {}
|
Piece::Piece():index(0), length(0), bitfield(0) {}
|
||||||
|
|
||||||
Piece::Piece(int index, int length):index(index), length(length) {
|
Piece::Piece(int32_t index, int32_t length):index(index), length(length) {
|
||||||
bitfield =
|
bitfield =
|
||||||
BitfieldManFactory::getFactoryInstance()->createBitfieldMan(BLOCK_LENGTH, length);
|
BitfieldManFactory::getFactoryInstance()->createBitfieldMan(BLOCK_LENGTH, length);
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ Piece::Piece(const Piece& piece) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Piece::completeBlock(int blockIndex) {
|
void Piece::completeBlock(int32_t blockIndex) {
|
||||||
bitfield->setBit(blockIndex);
|
bitfield->setBit(blockIndex);
|
||||||
bitfield->unsetUseBit(blockIndex);
|
bitfield->unsetUseBit(blockIndex);
|
||||||
}
|
}
|
||||||
|
@ -72,12 +72,12 @@ bool Piece::pieceComplete() const {
|
||||||
return bitfield->isAllBitSet();
|
return bitfield->isAllBitSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Piece::cancelBlock(int blockIndex) {
|
void Piece::cancelBlock(int32_t blockIndex) {
|
||||||
bitfield->unsetUseBit(blockIndex);
|
bitfield->unsetUseBit(blockIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Piece::getMissingUnusedBlockIndex() const {
|
int32_t Piece::getMissingUnusedBlockIndex() const {
|
||||||
int blockIndex = bitfield->getFirstMissingUnusedIndex();
|
int32_t blockIndex = bitfield->getFirstMissingUnusedIndex();
|
||||||
if(blockIndex == -1) {
|
if(blockIndex == -1) {
|
||||||
return blockIndex;
|
return blockIndex;
|
||||||
}
|
}
|
||||||
|
@ -85,8 +85,8 @@ int Piece::getMissingUnusedBlockIndex() const {
|
||||||
return blockIndex;
|
return blockIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Piece::getMissingBlockIndex() const {
|
int32_t Piece::getMissingBlockIndex() const {
|
||||||
int blockIndex = bitfield->getMissingIndex();
|
int32_t blockIndex = bitfield->getMissingIndex();
|
||||||
if(blockIndex == -1) {
|
if(blockIndex == -1) {
|
||||||
return blockIndex;
|
return blockIndex;
|
||||||
}
|
}
|
||||||
|
|
38
src/Piece.h
38
src/Piece.h
|
@ -42,13 +42,13 @@
|
||||||
|
|
||||||
class Piece {
|
class Piece {
|
||||||
private:
|
private:
|
||||||
int index;
|
int32_t index;
|
||||||
int length;
|
int32_t length;
|
||||||
BitfieldMan* bitfield;
|
BitfieldMan* bitfield;
|
||||||
public:
|
public:
|
||||||
Piece();
|
Piece();
|
||||||
|
|
||||||
Piece(int index, int length);
|
Piece(int32_t index, int32_t length);
|
||||||
|
|
||||||
Piece(const Piece& piece);
|
Piece(const Piece& piece);
|
||||||
|
|
||||||
|
@ -76,15 +76,15 @@ public:
|
||||||
return index == piece.index;
|
return index == piece.index;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getMissingUnusedBlockIndex() const;
|
int32_t getMissingUnusedBlockIndex() const;
|
||||||
int getMissingBlockIndex() const;
|
int32_t getMissingBlockIndex() const;
|
||||||
BlockIndexes getAllMissingBlockIndexes() const;
|
BlockIndexes getAllMissingBlockIndexes() const;
|
||||||
void completeBlock(int blockIndex);
|
void completeBlock(int32_t blockIndex);
|
||||||
void cancelBlock(int blockIndex);
|
void cancelBlock(int32_t blockIndex);
|
||||||
int countCompleteBlock() const {
|
int32_t countCompleteBlock() const {
|
||||||
return bitfield->countBlock()-bitfield->countMissingBlock();
|
return bitfield->countBlock()-bitfield->countMissingBlock();
|
||||||
}
|
}
|
||||||
bool hasBlock(int blockIndex) const {
|
bool hasBlock(int32_t blockIndex) const {
|
||||||
return bitfield->isBitSet(blockIndex);
|
return bitfield->isBitSet(blockIndex);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -92,20 +92,20 @@ public:
|
||||||
* returns false.
|
* returns false.
|
||||||
*/
|
*/
|
||||||
bool pieceComplete() const;
|
bool pieceComplete() const;
|
||||||
int countBlock() const { return bitfield->countBlock(); }
|
int32_t countBlock() const { return bitfield->countBlock(); }
|
||||||
int getBlockLength(int index) const {
|
int32_t getBlockLength(int32_t index) const {
|
||||||
return bitfield->getBlockLength(index);
|
return bitfield->getBlockLength(index);
|
||||||
}
|
}
|
||||||
int getBlockLength() const { return bitfield->getBlockLength(); }
|
int32_t getBlockLength() const { return bitfield->getBlockLength(); }
|
||||||
int getIndex() const { return index; }
|
int32_t getIndex() const { return index; }
|
||||||
void setIndex(int index) { this->index = index; }
|
void setIndex(int32_t index) { this->index = index; }
|
||||||
int getLength() const { return length; }
|
int32_t getLength() const { return length; }
|
||||||
void setLength(int index) { this->length = length; }
|
void setLength(int32_t index) { this->length = length; }
|
||||||
|
|
||||||
const unsigned char* getBitfield() const { return bitfield->getBitfield(); }
|
const unsigned char* getBitfield() const { return bitfield->getBitfield(); }
|
||||||
void setBitfield(const unsigned char* bitfield, int len);
|
void setBitfield(const unsigned char* bitfield, int32_t len);
|
||||||
|
|
||||||
int getBitfieldLength() const {
|
int32_t getBitfieldLength() const {
|
||||||
return bitfield->getBitfieldLength();
|
return bitfield->getBitfieldLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ public:
|
||||||
|
|
||||||
string toString() const;
|
string toString() const;
|
||||||
|
|
||||||
bool isBlockUsed(int index) const {
|
bool isBlockUsed(int32_t index) const {
|
||||||
return bitfield->isUseBitSet(index);
|
return bitfield->isUseBitSet(index);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -70,7 +70,7 @@ public:
|
||||||
* Returns the piece denoted by index.
|
* Returns the piece denoted by index.
|
||||||
* No status of the piece is changed in this method.
|
* No status of the piece is changed in this method.
|
||||||
*/
|
*/
|
||||||
virtual PieceHandle getPiece(int index) = 0;
|
virtual PieceHandle getPiece(int32_t index) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells that the download of the specfied piece completes.
|
* Tells that the download of the specfied piece completes.
|
||||||
|
@ -86,15 +86,15 @@ public:
|
||||||
* Returns true if the specified piece is already downloaded.
|
* Returns true if the specified piece is already downloaded.
|
||||||
* Otherwise returns false.
|
* Otherwise returns false.
|
||||||
*/
|
*/
|
||||||
virtual bool hasPiece(int index) = 0;
|
virtual bool hasPiece(int32_t index) = 0;
|
||||||
|
|
||||||
virtual long long int getTotalLength() = 0;
|
virtual int64_t getTotalLength() = 0;
|
||||||
|
|
||||||
virtual long long int getFilteredTotalLength() = 0;
|
virtual int64_t getFilteredTotalLength() = 0;
|
||||||
|
|
||||||
virtual long long int getCompletedLength() = 0;
|
virtual int64_t getCompletedLength() = 0;
|
||||||
|
|
||||||
virtual long long int getFilteredCompletedLength() = 0;
|
virtual int64_t getFilteredCompletedLength() = 0;
|
||||||
|
|
||||||
virtual void setFileFilter(const Strings& filePaths) = 0;
|
virtual void setFileFilter(const Strings& filePaths) = 0;
|
||||||
|
|
||||||
|
@ -124,9 +124,9 @@ public:
|
||||||
virtual const unsigned char* getBitfield() = 0;
|
virtual const unsigned char* getBitfield() = 0;
|
||||||
|
|
||||||
virtual void setBitfield(const unsigned char* bitfield,
|
virtual void setBitfield(const unsigned char* bitfield,
|
||||||
int bitfieldLength) = 0;
|
int32_t bitfieldLength) = 0;
|
||||||
|
|
||||||
virtual int getBitfieldLength() = 0;
|
virtual int32_t getBitfieldLength() = 0;
|
||||||
|
|
||||||
virtual bool isSelectiveDownloadingMode() = 0;
|
virtual bool isSelectiveDownloadingMode() = 0;
|
||||||
|
|
||||||
|
@ -136,26 +136,26 @@ public:
|
||||||
|
|
||||||
virtual DiskAdaptorHandle getDiskAdaptor() = 0;
|
virtual DiskAdaptorHandle getDiskAdaptor() = 0;
|
||||||
|
|
||||||
virtual int getPieceLength(int index) = 0;
|
virtual int32_t getPieceLength(int32_t index) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds piece index to advertise to other commands. They send have message
|
* Adds piece index to advertise to other commands. They send have message
|
||||||
* based on this information.
|
* based on this information.
|
||||||
*/
|
*/
|
||||||
virtual void advertisePiece(int cuid, int index) = 0;
|
virtual void advertisePiece(int32_t cuid, int32_t index) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns piece index which is not advertised by the caller command and
|
* Returns piece index which is not advertised by the caller command and
|
||||||
* newer than lastCheckTime.
|
* newer than lastCheckTime.
|
||||||
*/
|
*/
|
||||||
virtual Integers getAdvertisedPieceIndexes(int myCuid,
|
virtual Integers getAdvertisedPieceIndexes(int32_t myCuid,
|
||||||
const Time& lastCheckTime) = 0;
|
const Time& lastCheckTime) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes have entry if specified seconds have elapsed since its
|
* Removes have entry if specified seconds have elapsed since its
|
||||||
* registration.
|
* registration.
|
||||||
*/
|
*/
|
||||||
virtual void removeAdvertisedPiece(int elapsed) = 0;
|
virtual void removeAdvertisedPiece(int32_t elapsed) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets all bits in bitfield to 1.
|
* Sets all bits in bitfield to 1.
|
||||||
|
|
|
@ -41,9 +41,9 @@ class Randomizer {
|
||||||
public:
|
public:
|
||||||
virtual ~Randomizer() {}
|
virtual ~Randomizer() {}
|
||||||
|
|
||||||
virtual int getRandomNumber() = 0;
|
virtual long int getRandomNumber() = 0;
|
||||||
|
|
||||||
virtual int getMaxRandomNumber() = 0;
|
virtual long int getMaxRandomNumber() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<Randomizer> RandomizerHandle;
|
typedef SharedHandle<Randomizer> RandomizerHandle;
|
||||||
|
|
|
@ -95,7 +95,7 @@ bool Request::parseUrl(const string& url) {
|
||||||
string::size_type hp = tempUrl.find("://");
|
string::size_type hp = tempUrl.find("://");
|
||||||
if(hp == string::npos) return false;
|
if(hp == string::npos) return false;
|
||||||
protocol = tempUrl.substr(0, hp);
|
protocol = tempUrl.substr(0, hp);
|
||||||
int defPort;
|
int32_t defPort;
|
||||||
if((defPort = FeatureConfig::getInstance()->getDefaultPort(protocol)) == 0) {
|
if((defPort = FeatureConfig::getInstance()->getDefaultPort(protocol)) == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ bool Request::parseUrl(const string& url) {
|
||||||
Util::split(hostAndPort, tempUrl.substr(hp, hep-hp), ':');
|
Util::split(hostAndPort, tempUrl.substr(hp, hep-hp), ':');
|
||||||
host = hostAndPort.first;
|
host = hostAndPort.first;
|
||||||
if(hostAndPort.second != "") {
|
if(hostAndPort.second != "") {
|
||||||
port = (int)strtol(hostAndPort.second.c_str(), NULL, 10);
|
port = strtol(hostAndPort.second.c_str(), NULL, 10);
|
||||||
if(!(0 < port && port <= 65535)) {
|
if(!(0 < port && port <= 65535)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,14 @@
|
||||||
#define METALINK_MARK "#!metalink3!"
|
#define METALINK_MARK "#!metalink3!"
|
||||||
|
|
||||||
class Request {
|
class Request {
|
||||||
|
public:
|
||||||
|
enum TRACKER_EVENT {
|
||||||
|
AUTO,
|
||||||
|
STARTED,
|
||||||
|
STOPPED,
|
||||||
|
COMPLETED,
|
||||||
|
AFTER_COMPLETED
|
||||||
|
};
|
||||||
private:
|
private:
|
||||||
string url;
|
string url;
|
||||||
string currentUrl;
|
string currentUrl;
|
||||||
|
@ -64,11 +72,11 @@ private:
|
||||||
string referer;
|
string referer;
|
||||||
string protocol;
|
string protocol;
|
||||||
string host;
|
string host;
|
||||||
int port;
|
int32_t port;
|
||||||
string dir;
|
string dir;
|
||||||
string file;
|
string file;
|
||||||
int tryCount;
|
int32_t tryCount;
|
||||||
int trackerEvent;
|
TRACKER_EVENT trackerEvent;
|
||||||
bool keepAlive;
|
bool keepAlive;
|
||||||
string method;
|
string method;
|
||||||
|
|
||||||
|
@ -95,7 +103,7 @@ public:
|
||||||
bool resetUrl();
|
bool resetUrl();
|
||||||
void resetTryCount() { tryCount = 0; }
|
void resetTryCount() { tryCount = 0; }
|
||||||
void addTryCount() { tryCount++; }
|
void addTryCount() { tryCount++; }
|
||||||
int getTryCount() const { return tryCount; }
|
int32_t getTryCount() const { return tryCount; }
|
||||||
//bool noMoreTry() const { return tryCount >= PREF_MAX_TRY; }
|
//bool noMoreTry() const { return tryCount >= PREF_MAX_TRY; }
|
||||||
|
|
||||||
string getUrl() const { return url; }
|
string getUrl() const { return url; }
|
||||||
|
@ -105,13 +113,13 @@ public:
|
||||||
void setReferer(const string& url) { referer = previousUrl = url; }
|
void setReferer(const string& url) { referer = previousUrl = url; }
|
||||||
string getProtocol() const { return protocol; }
|
string getProtocol() const { return protocol; }
|
||||||
string getHost() const { return host; }
|
string getHost() const { return host; }
|
||||||
int getPort() const { return port; }
|
int32_t getPort() const { return port; }
|
||||||
string getDir() const { return dir; }
|
string getDir() const { return dir; }
|
||||||
string getFile() const { return file;}
|
string getFile() const { return file;}
|
||||||
bool isKeepAlive() const { return keepAlive; }
|
bool isKeepAlive() const { return keepAlive; }
|
||||||
void setKeepAlive(bool keepAlive) { this->keepAlive = keepAlive; }
|
void setKeepAlive(bool keepAlive) { this->keepAlive = keepAlive; }
|
||||||
void setTrackerEvent(int event) { trackerEvent = event; }
|
void setTrackerEvent(TRACKER_EVENT event) { trackerEvent = event; }
|
||||||
int getTrackerEvent() const { return trackerEvent; }
|
TRACKER_EVENT getTrackerEvent() const { return trackerEvent; }
|
||||||
|
|
||||||
void setMethod(const string& method) {
|
void setMethod(const string& method) {
|
||||||
this->method = method;
|
this->method = method;
|
||||||
|
@ -145,14 +153,6 @@ public:
|
||||||
static const string METHOD_GET;
|
static const string METHOD_GET;
|
||||||
static const string METHOD_HEAD;
|
static const string METHOD_HEAD;
|
||||||
|
|
||||||
enum TRACKER_EVENT {
|
|
||||||
AUTO,
|
|
||||||
STARTED,
|
|
||||||
STOPPED,
|
|
||||||
COMPLETED,
|
|
||||||
AFTER_COMPLETED
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<Request> RequestHandle;
|
typedef SharedHandle<Request> RequestHandle;
|
||||||
|
|
|
@ -43,13 +43,13 @@ class DownloadCommand;
|
||||||
|
|
||||||
class RequestGroupEntry : public ProgressAwareEntry {
|
class RequestGroupEntry : public ProgressAwareEntry {
|
||||||
protected:
|
protected:
|
||||||
int _cuid;
|
int32_t _cuid;
|
||||||
RequestHandle _currentRequest;
|
RequestHandle _currentRequest;
|
||||||
RequestGroup* _requestGroup;
|
RequestGroup* _requestGroup;
|
||||||
DownloadCommand* _nextDownloadCommand;
|
DownloadCommand* _nextDownloadCommand;
|
||||||
bool _shouldAddNumConnection;
|
bool _shouldAddNumConnection;
|
||||||
public:
|
public:
|
||||||
RequestGroupEntry(int cuid,
|
RequestGroupEntry(int32_t cuid,
|
||||||
const RequestHandle& currentRequest,
|
const RequestHandle& currentRequest,
|
||||||
RequestGroup* requestGroup,
|
RequestGroup* requestGroup,
|
||||||
DownloadCommand* nextDownloadCommand = 0):
|
DownloadCommand* nextDownloadCommand = 0):
|
||||||
|
@ -73,7 +73,7 @@ public:
|
||||||
return _requestGroup->getTotalLength();
|
return _requestGroup->getTotalLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
int getCUID() const
|
int32_t getCUID() const
|
||||||
{
|
{
|
||||||
return _cuid;
|
return _cuid;
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ bool RequestSlot::isTimeout(time_t timeoutSec) const {
|
||||||
return dispatchedTime.elapsed(timeoutSec);
|
return dispatchedTime.elapsed(timeoutSec);
|
||||||
}
|
}
|
||||||
|
|
||||||
int RequestSlot::getLatencyInMillis() const {
|
int32_t RequestSlot::getLatencyInMillis() const {
|
||||||
return dispatchedTime.differenceInMillis();
|
return dispatchedTime.differenceInMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ public:
|
||||||
void setDispatchedTime(time_t secFromEpoch);
|
void setDispatchedTime(time_t secFromEpoch);
|
||||||
|
|
||||||
bool isTimeout(time_t timeoutSec) const;
|
bool isTimeout(time_t timeoutSec) const;
|
||||||
int getLatencyInMillis() const;
|
int32_t getLatencyInMillis() const;
|
||||||
|
|
||||||
int32_t getIndex() const { return index; }
|
int32_t getIndex() const { return index; }
|
||||||
void setIndex(int32_t index) { this->index = index; }
|
void setIndex(int32_t index) { this->index = index; }
|
||||||
|
|
|
@ -42,12 +42,12 @@ using namespace std;
|
||||||
|
|
||||||
class Segment {
|
class Segment {
|
||||||
public:
|
public:
|
||||||
int index;
|
int32_t index;
|
||||||
int length;
|
int32_t length;
|
||||||
int segmentLength;
|
int32_t segmentLength;
|
||||||
int writtenLength;
|
int32_t writtenLength;
|
||||||
|
|
||||||
Segment(int index, int length, int segmentLength, int writtenLength = 0)
|
Segment(int32_t index, int32_t length, int32_t segmentLength, int32_t writtenLength = 0)
|
||||||
:index(index), length(length), segmentLength(segmentLength),
|
:index(index), length(length), segmentLength(segmentLength),
|
||||||
writtenLength(writtenLength) {}
|
writtenLength(writtenLength) {}
|
||||||
|
|
||||||
|
|
|
@ -111,12 +111,12 @@ void SegmentMan::save() const {
|
||||||
if(fwrite(&totalSize, sizeof(totalSize), 1, segFile) < 1) {
|
if(fwrite(&totalSize, sizeof(totalSize), 1, segFile) < 1) {
|
||||||
throw string("writeError");
|
throw string("writeError");
|
||||||
}
|
}
|
||||||
int segmentLength = bitfield->getBlockLength();
|
int32_t segmentLength = bitfield->getBlockLength();
|
||||||
if(fwrite(&segmentLength, sizeof(segmentLength), 1, segFile) < 1) {
|
if(fwrite(&segmentLength, sizeof(segmentLength), 1, segFile) < 1) {
|
||||||
throw string("writeError");
|
throw string("writeError");
|
||||||
}
|
}
|
||||||
if(bitfield) {
|
if(bitfield) {
|
||||||
int bitfieldLength = bitfield->getBitfieldLength();
|
int32_t bitfieldLength = bitfield->getBitfieldLength();
|
||||||
if(fwrite(&bitfieldLength, sizeof(bitfieldLength), 1, segFile) < 1) {
|
if(fwrite(&bitfieldLength, sizeof(bitfieldLength), 1, segFile) < 1) {
|
||||||
throw string("writeError");
|
throw string("writeError");
|
||||||
}
|
}
|
||||||
|
@ -125,12 +125,12 @@ void SegmentMan::save() const {
|
||||||
throw string("writeError");
|
throw string("writeError");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int i = 0;
|
int32_t i = 0;
|
||||||
if(fwrite(&i, sizeof(i), 1, segFile) < 1) {
|
if(fwrite(&i, sizeof(i), 1, segFile) < 1) {
|
||||||
throw string("writeError");
|
throw string("writeError");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int usedSegmentCount = usedSegmentEntries.size();
|
int32_t usedSegmentCount = usedSegmentEntries.size();
|
||||||
if(fwrite(&usedSegmentCount, sizeof(usedSegmentCount), 1, segFile) < 1) {
|
if(fwrite(&usedSegmentCount, sizeof(usedSegmentCount), 1, segFile) < 1) {
|
||||||
throw string("writeError");
|
throw string("writeError");
|
||||||
}
|
}
|
||||||
|
@ -163,11 +163,11 @@ void SegmentMan::read(FILE* file) {
|
||||||
if(fread(&totalSize, sizeof(totalSize), 1, file) < 1) {
|
if(fread(&totalSize, sizeof(totalSize), 1, file) < 1) {
|
||||||
throw string("readError");
|
throw string("readError");
|
||||||
}
|
}
|
||||||
int segmentSize;
|
int32_t segmentSize;
|
||||||
if(fread(&segmentSize, sizeof(segmentSize), 1, file) < 1) {
|
if(fread(&segmentSize, sizeof(segmentSize), 1, file) < 1) {
|
||||||
throw string("readError");
|
throw string("readError");
|
||||||
}
|
}
|
||||||
int bitfieldLength;
|
int32_t bitfieldLength;
|
||||||
if(fread(&bitfieldLength, sizeof(bitfieldLength), 1, file) < 1) {
|
if(fread(&bitfieldLength, sizeof(bitfieldLength), 1, file) < 1) {
|
||||||
throw string("readError");
|
throw string("readError");
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,7 @@ void SegmentMan::read(FILE* file) {
|
||||||
delete [] savedBitfield;
|
delete [] savedBitfield;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int segmentCount;
|
int32_t segmentCount;
|
||||||
if(fread(&segmentCount, sizeof(segmentCount), 1, file) < 1) {
|
if(fread(&segmentCount, sizeof(segmentCount), 1, file) < 1) {
|
||||||
throw string("readError");
|
throw string("readError");
|
||||||
}
|
}
|
||||||
|
@ -277,7 +277,7 @@ SegmentHandle SegmentMan::onNullBitfield(int32_t cuid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SegmentEntryHandle SegmentMan::findSlowerSegmentEntry(const PeerStatHandle& peerStat) const {
|
SegmentEntryHandle SegmentMan::findSlowerSegmentEntry(const PeerStatHandle& peerStat) const {
|
||||||
int speed = (int)(peerStat->getAvgDownloadSpeed()*0.8);
|
int32_t speed = (int32_t)(peerStat->getAvgDownloadSpeed()*0.8);
|
||||||
SegmentEntryHandle slowSegmentEntry(0);
|
SegmentEntryHandle slowSegmentEntry(0);
|
||||||
for(SegmentEntries::const_iterator itr = usedSegmentEntries.begin();
|
for(SegmentEntries::const_iterator itr = usedSegmentEntries.begin();
|
||||||
itr != usedSegmentEntries.end(); ++itr) {
|
itr != usedSegmentEntries.end(); ++itr) {
|
||||||
|
@ -291,7 +291,7 @@ SegmentEntryHandle SegmentMan::findSlowerSegmentEntry(const PeerStatHandle& peer
|
||||||
!p->getDownloadStartTime().elapsed(option->getAsInt(PREF_STARTUP_IDLE_TIME))) {
|
!p->getDownloadStartTime().elapsed(option->getAsInt(PREF_STARTUP_IDLE_TIME))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int pSpeed = p->calculateDownloadSpeed();
|
int32_t pSpeed = p->calculateDownloadSpeed();
|
||||||
if(pSpeed < speed) {
|
if(pSpeed < speed) {
|
||||||
speed = pSpeed;
|
speed = pSpeed;
|
||||||
slowSegmentEntry = segmentEntry;
|
slowSegmentEntry = segmentEntry;
|
||||||
|
@ -308,7 +308,7 @@ SegmentHandle SegmentMan::getSegment(int32_t cuid) {
|
||||||
if(!segmentEntry.isNull()) {
|
if(!segmentEntry.isNull()) {
|
||||||
return segmentEntry->segment;
|
return segmentEntry->segment;
|
||||||
}
|
}
|
||||||
int index = bitfield->getSparseMissingUnusedIndex();
|
int32_t index = bitfield->getSparseMissingUnusedIndex();
|
||||||
if(index == -1) {
|
if(index == -1) {
|
||||||
PeerStatHandle myPeerStat = getPeerStat(cuid);
|
PeerStatHandle myPeerStat = getPeerStat(cuid);
|
||||||
if(!myPeerStat.get()) {
|
if(!myPeerStat.get()) {
|
||||||
|
@ -423,7 +423,7 @@ void SegmentMan::registerPeerStat(const PeerStatHandle& peerStat) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t SegmentMan::calculateDownloadSpeed() const {
|
int32_t SegmentMan::calculateDownloadSpeed() const {
|
||||||
int speed = 0;
|
int32_t speed = 0;
|
||||||
for(PeerStats::const_iterator itr = peerStats.begin();
|
for(PeerStats::const_iterator itr = peerStats.begin();
|
||||||
itr != peerStats.end(); itr++) {
|
itr != peerStats.end(); itr++) {
|
||||||
const PeerStatHandle& peerStat = *itr;
|
const PeerStatHandle& peerStat = *itr;
|
||||||
|
|
|
@ -50,10 +50,10 @@ using namespace std;
|
||||||
|
|
||||||
class SegmentEntry {
|
class SegmentEntry {
|
||||||
public:
|
public:
|
||||||
int cuid;
|
int32_t cuid;
|
||||||
SegmentHandle segment;
|
SegmentHandle segment;
|
||||||
public:
|
public:
|
||||||
SegmentEntry(int cuid, const SegmentHandle& segment)
|
SegmentEntry(int32_t cuid, const SegmentHandle& segment)
|
||||||
:cuid(cuid), segment(segment) {}
|
:cuid(cuid), segment(segment) {}
|
||||||
~SegmentEntry() {}
|
~SegmentEntry() {}
|
||||||
};
|
};
|
||||||
|
@ -77,7 +77,7 @@ private:
|
||||||
SegmentHandle onNullBitfield(int32_t cuid);
|
SegmentHandle onNullBitfield(int32_t cuid);
|
||||||
SegmentHandle checkoutSegment(int32_t cuid, int32_t index);
|
SegmentHandle checkoutSegment(int32_t cuid, int32_t index);
|
||||||
SegmentEntryHandle findSlowerSegmentEntry(const PeerStatHandle& peerStat) const;
|
SegmentEntryHandle findSlowerSegmentEntry(const PeerStatHandle& peerStat) const;
|
||||||
SegmentEntryHandle getSegmentEntryByIndex(int index) {
|
SegmentEntryHandle getSegmentEntryByIndex(int32_t index) {
|
||||||
for(SegmentEntries::const_iterator itr = usedSegmentEntries.begin();
|
for(SegmentEntries::const_iterator itr = usedSegmentEntries.begin();
|
||||||
itr != usedSegmentEntries.end(); ++itr) {
|
itr != usedSegmentEntries.end(); ++itr) {
|
||||||
const SegmentEntryHandle& segmentEntry = *itr;
|
const SegmentEntryHandle& segmentEntry = *itr;
|
||||||
|
@ -88,7 +88,7 @@ private:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SegmentEntryHandle getSegmentEntryByCuid(int cuid) {
|
SegmentEntryHandle getSegmentEntryByCuid(int32_t cuid) {
|
||||||
for(SegmentEntries::const_iterator itr = usedSegmentEntries.begin();
|
for(SegmentEntries::const_iterator itr = usedSegmentEntries.begin();
|
||||||
itr != usedSegmentEntries.end(); ++itr) {
|
itr != usedSegmentEntries.end(); ++itr) {
|
||||||
const SegmentEntryHandle& segmentEntry = *itr;
|
const SegmentEntryHandle& segmentEntry = *itr;
|
||||||
|
@ -99,7 +99,7 @@ private:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SegmentEntries::iterator getSegmentEntryIteratorByCuid(int cuid) {
|
SegmentEntries::iterator getSegmentEntryIteratorByCuid(int32_t cuid) {
|
||||||
for(SegmentEntries::iterator itr = usedSegmentEntries.begin();
|
for(SegmentEntries::iterator itr = usedSegmentEntries.begin();
|
||||||
itr != usedSegmentEntries.end(); ++itr) {
|
itr != usedSegmentEntries.end(); ++itr) {
|
||||||
const SegmentEntryHandle& segmentEntry = *itr;
|
const SegmentEntryHandle& segmentEntry = *itr;
|
||||||
|
@ -151,7 +151,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Represents the number of failures(usually, DlAbortEx) in downloads.
|
* Represents the number of failures(usually, DlAbortEx) in downloads.
|
||||||
*/
|
*/
|
||||||
int errors;
|
int32_t errors;
|
||||||
|
|
||||||
const Option* option;
|
const Option* option;
|
||||||
DiskWriterHandle diskWriter;
|
DiskWriterHandle diskWriter;
|
||||||
|
@ -268,7 +268,7 @@ public:
|
||||||
* Returns peerStat whose cuid is given cuid. If it is not found, returns
|
* Returns peerStat whose cuid is given cuid. If it is not found, returns
|
||||||
* 0.
|
* 0.
|
||||||
*/
|
*/
|
||||||
PeerStatHandle getPeerStat(int cuid) const {
|
PeerStatHandle getPeerStat(int32_t cuid) const {
|
||||||
for(PeerStats::const_iterator itr = peerStats.begin(); itr != peerStats.end(); ++itr) {
|
for(PeerStats::const_iterator itr = peerStats.begin(); itr != peerStats.end(); ++itr) {
|
||||||
const PeerStatHandle& peerStat = *itr;
|
const PeerStatHandle& peerStat = *itr;
|
||||||
if(peerStat->getCuid() == cuid) {
|
if(peerStat->getCuid() == cuid) {
|
||||||
|
|
|
@ -66,7 +66,7 @@ public:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
TransferStat stat = peerStorage->calculateStat();
|
TransferStat stat = peerStorage->calculateStat();
|
||||||
long long int allTimeUploadLength =
|
int64_t allTimeUploadLength =
|
||||||
btRuntime->getUploadLengthAtStartup()+stat.getSessionUploadLength();
|
btRuntime->getUploadLengthAtStartup()+stat.getSessionUploadLength();
|
||||||
return ratio <=
|
return ratio <=
|
||||||
((double)allTimeUploadLength)/pieceStorage->getCompletedLength();
|
((double)allTimeUploadLength)/pieceStorage->getCompletedLength();
|
||||||
|
|
|
@ -46,14 +46,14 @@ void SimpleBtMessage::send() {
|
||||||
}
|
}
|
||||||
if(sendPredicate() || sendingInProgress) {
|
if(sendPredicate() || sendingInProgress) {
|
||||||
const unsigned char* msg = getMessage();
|
const unsigned char* msg = getMessage();
|
||||||
int msgLength = getMessageLength();
|
int32_t msgLength = getMessageLength();
|
||||||
if(!sendingInProgress) {
|
if(!sendingInProgress) {
|
||||||
logger->info(MSG_SEND_PEER_MESSAGE,
|
logger->info(MSG_SEND_PEER_MESSAGE,
|
||||||
cuid, peer->ipaddr.c_str(), peer->port, toString().c_str());
|
cuid, peer->ipaddr.c_str(), peer->port, toString().c_str());
|
||||||
leftDataLength = getMessageLength();
|
leftDataLength = getMessageLength();
|
||||||
}
|
}
|
||||||
sendingInProgress = false;
|
sendingInProgress = false;
|
||||||
int writtenLength = peerConnection->sendMessage(msg+msgLength-leftDataLength, leftDataLength);
|
int32_t writtenLength = peerConnection->sendMessage(msg+msgLength-leftDataLength, leftDataLength);
|
||||||
if(writtenLength == leftDataLength) {
|
if(writtenLength == leftDataLength) {
|
||||||
onSendComplete();
|
onSendComplete();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
class SimpleBtMessage : public AbstractBtMessage {
|
class SimpleBtMessage : public AbstractBtMessage {
|
||||||
private:
|
private:
|
||||||
int leftDataLength;
|
int32_t leftDataLength;
|
||||||
public:
|
public:
|
||||||
SimpleBtMessage();
|
SimpleBtMessage();
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ void SimpleLogger::closeFile() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleLogger::setStdout(int level, bool enabled) {
|
void SimpleLogger::setStdout(Logger::LEVEL level, bool enabled) {
|
||||||
if(enabled) {
|
if(enabled) {
|
||||||
stdoutField |= level;
|
stdoutField |= level;
|
||||||
} else {
|
} else {
|
||||||
|
@ -84,7 +84,7 @@ void SimpleLogger::writeHeader(FILE* file, string date, string level) const {
|
||||||
fprintf(file, "%s %s - ", date.c_str(), level.c_str());
|
fprintf(file, "%s %s - ", date.c_str(), level.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleLogger::writeLog(FILE* file, int level, const char* msg, va_list ap, Exception* e, bool printHeader) const
|
void SimpleLogger::writeLog(FILE* file, Logger::LEVEL level, const char* msg, va_list ap, Exception* e, bool printHeader) const
|
||||||
{
|
{
|
||||||
string levelStr;
|
string levelStr;
|
||||||
switch(level) {
|
switch(level) {
|
||||||
|
@ -125,7 +125,7 @@ void SimpleLogger::writeLog(FILE* file, int level, const char* msg, va_list ap,
|
||||||
fflush(file);
|
fflush(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleLogger::writeFile(int level, const char* msg, va_list ap, Exception* e) const {
|
void SimpleLogger::writeFile(Logger::LEVEL level, const char* msg, va_list ap, Exception* e) const {
|
||||||
writeLog(file, level, msg, ap, e);
|
writeLog(file, level, msg, ap, e);
|
||||||
if(stdoutField&level) {
|
if(stdoutField&level) {
|
||||||
fprintf(stdout, "\n");
|
fprintf(stdout, "\n");
|
||||||
|
|
|
@ -39,11 +39,11 @@
|
||||||
|
|
||||||
class SimpleLogger:public Logger {
|
class SimpleLogger:public Logger {
|
||||||
private:
|
private:
|
||||||
void writeFile(int level, const char* msg, va_list ap, Exception* e = 0) const;
|
void writeFile(Logger::LEVEL level, const char* msg, va_list ap, Exception* e = 0) const;
|
||||||
void writeHeader(FILE* file, string date, string level) const;
|
void writeHeader(FILE* file, string date, string level) const;
|
||||||
void writeLog(FILE* file, int level, const char* msg, va_list ap, Exception* e = 0, bool printHeader = true) const;
|
void writeLog(FILE* file, Logger::LEVEL level, const char* msg, va_list ap, Exception* e = 0, bool printHeader = true) const;
|
||||||
FILE* file;
|
FILE* file;
|
||||||
int stdoutField;
|
int32_t stdoutField;
|
||||||
public:
|
public:
|
||||||
SimpleLogger(FILE* logfile = 0);
|
SimpleLogger(FILE* logfile = 0);
|
||||||
~SimpleLogger();
|
~SimpleLogger();
|
||||||
|
@ -61,7 +61,7 @@ public:
|
||||||
virtual void error(const char* msg, ...) const;
|
virtual void error(const char* msg, ...) const;
|
||||||
virtual void error(const char* msg, Exception* ex, ...) const;
|
virtual void error(const char* msg, Exception* ex, ...) const;
|
||||||
|
|
||||||
void setStdout(int level, bool enabled);
|
void setStdout(Logger::LEVEL level, bool enabled);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _D_SIMPLE_LOGGER_H_
|
#endif // _D_SIMPLE_LOGGER_H_
|
||||||
|
|
|
@ -59,12 +59,12 @@ public:
|
||||||
|
|
||||||
virtual ~SimpleRandomizer() {}
|
virtual ~SimpleRandomizer() {}
|
||||||
|
|
||||||
virtual int getRandomNumber() {
|
virtual long int getRandomNumber() {
|
||||||
return random();
|
return random();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int getMaxRandomNumber() {
|
virtual long int getMaxRandomNumber() {
|
||||||
return RAND_MAX;
|
return RAND_MAX;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue