2010-01-06 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Untabify. Fixed one line in copyright which is longer than 80
	columns.
	* src
	* test
pull/1/head
Tatsuhiro Tsujikawa 2010-01-05 16:01:46 +00:00
parent 338e8aca09
commit 4db349c1f3
827 changed files with 7343 additions and 7336 deletions

View File

@ -1,3 +1,10 @@
2010-01-06 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Untabify. Fixed one line in copyright which is longer than 80
columns.
* src
* test
2009-12-27 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2009-12-27 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Release 1.8.0 Release 1.8.0

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -55,7 +55,7 @@ public:
void init(const unsigned char* key, size_t keyLength) {} void init(const unsigned char* key, size_t keyLength) {}
void decrypt(unsigned char* out, size_t outLength, void decrypt(unsigned char* out, size_t outLength,
const unsigned char* in, size_t inLength) {} const unsigned char* in, size_t inLength) {}
}; };
} // namespace aria2 } // namespace aria2

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -55,7 +55,7 @@ public:
void init(const unsigned char* key, size_t keyLength) {} void init(const unsigned char* key, size_t keyLength) {}
void encrypt(unsigned char* out, size_t outLength, void encrypt(unsigned char* out, size_t outLength,
const unsigned char* in, size_t inLength) {} const unsigned char* in, size_t inLength) {}
}; };
} // namespace aria2 } // namespace aria2

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -68,11 +68,11 @@
namespace aria2 { namespace aria2 {
AbstractCommand::AbstractCommand(int32_t cuid, AbstractCommand::AbstractCommand(int32_t cuid,
const SharedHandle<Request>& req, const SharedHandle<Request>& req,
const SharedHandle<FileEntry>& fileEntry, const SharedHandle<FileEntry>& fileEntry,
RequestGroup* requestGroup, RequestGroup* requestGroup,
DownloadEngine* e, DownloadEngine* e,
const SocketHandle& s): const SocketHandle& s):
Command(cuid), _requestGroup(requestGroup), Command(cuid), _requestGroup(requestGroup),
req(req), _fileEntry(fileEntry), e(e), socket(s), req(req), _fileEntry(fileEntry), e(e), socket(s),
checkSocketIsReadable(false), checkSocketIsWritable(false), checkSocketIsReadable(false), checkSocketIsWritable(false),
@ -98,7 +98,7 @@ AbstractCommand::~AbstractCommand() {
bool AbstractCommand::execute() { bool AbstractCommand::execute() {
logger->debug("CUID#%d - socket: read:%d, write:%d, hup:%d, err:%d", logger->debug("CUID#%d - socket: read:%d, write:%d, hup:%d, err:%d",
cuid, _readEvent, _writeEvent, _hupEvent, _errorEvent); cuid, _readEvent, _writeEvent, _hupEvent, _errorEvent);
try { try {
if(_requestGroup->downloadFinished() || _requestGroup->isHaltRequested()) { if(_requestGroup->downloadFinished() || _requestGroup->isHaltRequested()) {
//logger->debug("CUID#%d - finished.", cuid); //logger->debug("CUID#%d - finished.", cuid);
@ -110,19 +110,19 @@ bool AbstractCommand::execute() {
!_requestGroup->getPieceStorage()->hasMissingUnusedPiece()) { !_requestGroup->getPieceStorage()->hasMissingUnusedPiece()) {
SharedHandle<Request> fasterRequest = _fileEntry->findFasterRequest(req); SharedHandle<Request> fasterRequest = _fileEntry->findFasterRequest(req);
if(!fasterRequest.isNull()) { if(!fasterRequest.isNull()) {
logger->info("CUID#%d - Use faster Request hostname=%s, port=%u", logger->info("CUID#%d - Use faster Request hostname=%s, port=%u",
cuid, cuid,
fasterRequest->getHost().c_str(), fasterRequest->getHost().c_str(),
fasterRequest->getPort()); fasterRequest->getPort());
// Cancel current Request object and use faster one. // Cancel current Request object and use faster one.
_fileEntry->removeRequest(req); _fileEntry->removeRequest(req);
Command* command = Command* command =
InitiateConnectionCommandFactory::createInitiateConnectionCommand InitiateConnectionCommandFactory::createInitiateConnectionCommand
(cuid, fasterRequest, _fileEntry, _requestGroup, e); (cuid, fasterRequest, _fileEntry, _requestGroup, e);
e->setNoWait(true); e->setNoWait(true);
e->commands.push_back(command); e->commands.push_back(command);
return true; return true;
} }
} }
if((checkSocketIsReadable && _readEvent) || if((checkSocketIsReadable && _readEvent) ||
@ -134,54 +134,54 @@ bool AbstractCommand::execute() {
(!checkSocketIsReadable && !checkSocketIsWritable && !nameResolverCheck)) { (!checkSocketIsReadable && !checkSocketIsWritable && !nameResolverCheck)) {
checkPoint.reset(); checkPoint.reset();
if(!_requestGroup->getPieceStorage().isNull()) { if(!_requestGroup->getPieceStorage().isNull()) {
_segments.clear(); _segments.clear();
_requestGroup->getSegmentMan()->getInFlightSegment(_segments, cuid); _requestGroup->getSegmentMan()->getInFlightSegment(_segments, cuid);
if(req.isNull() || req->getMaxPipelinedRequest() == 1 || if(req.isNull() || req->getMaxPipelinedRequest() == 1 ||
_requestGroup->getDownloadContext()->getFileEntries().size() == 1) { _requestGroup->getDownloadContext()->getFileEntries().size() == 1) {
if(_segments.empty()) { if(_segments.empty()) {
SharedHandle<Segment> segment = SharedHandle<Segment> segment =
_requestGroup->getSegmentMan()->getSegment(cuid); _requestGroup->getSegmentMan()->getSegment(cuid);
if(!segment.isNull()) { if(!segment.isNull()) {
_segments.push_back(segment); _segments.push_back(segment);
} }
} }
if(_segments.empty()) { if(_segments.empty()) {
// TODO socket could be pooled here if pipelining is enabled... // TODO socket could be pooled here if pipelining is enabled...
logger->info(MSG_NO_SEGMENT_AVAILABLE, cuid); logger->info(MSG_NO_SEGMENT_AVAILABLE, cuid);
// When all segments are ignored in SegmentMan, there are // When all segments are ignored in SegmentMan, there are
// no URIs available, so don't retry. // no URIs available, so don't retry.
if(_requestGroup->getSegmentMan()->allSegmentsIgnored()) { if(_requestGroup->getSegmentMan()->allSegmentsIgnored()) {
return true; return true;
} else { } else {
return prepareForRetry(1); return prepareForRetry(1);
} }
} }
} else { } else {
size_t maxSegments = req->getMaxPipelinedRequest(); size_t maxSegments = req->getMaxPipelinedRequest();
if(_segments.size() < maxSegments) { if(_segments.size() < maxSegments) {
_requestGroup->getSegmentMan()->getSegment _requestGroup->getSegmentMan()->getSegment
(_segments, cuid, _fileEntry, maxSegments); (_segments, cuid, _fileEntry, maxSegments);
} }
if(_segments.empty()) { if(_segments.empty()) {
return prepareForRetry(0); return prepareForRetry(0);
} }
} }
} }
return executeInternal(); return executeInternal();
} else if(_errorEvent) { } else if(_errorEvent) {
throw DL_RETRY_EX throw DL_RETRY_EX
(StringFormat(MSG_NETWORK_PROBLEM, (StringFormat(MSG_NETWORK_PROBLEM,
socket->getSocketError().c_str()).str()); socket->getSocketError().c_str()).str());
} else { } else {
if(checkPoint.elapsed(timeout)) { if(checkPoint.elapsed(timeout)) {
// timeout triggers ServerStat error state. // timeout triggers ServerStat error state.
SharedHandle<ServerStat> ss = SharedHandle<ServerStat> ss =
e->_requestGroupMan->getOrCreateServerStat(req->getHost(), e->_requestGroupMan->getOrCreateServerStat(req->getHost(),
req->getProtocol()); req->getProtocol());
ss->setError(); ss->setError();
throw DL_RETRY_EX2(EX_TIME_OUT, downloadresultcode::TIME_OUT); throw DL_RETRY_EX2(EX_TIME_OUT, downloadresultcode::TIME_OUT);
} }
e->commands.push_back(this); e->commands.push_back(this);
return false; return false;
@ -191,9 +191,9 @@ bool AbstractCommand::execute() {
logger->debug(EX_EXCEPTION_CAUGHT, err); logger->debug(EX_EXCEPTION_CAUGHT, err);
} else { } else {
logger->error(MSG_DOWNLOAD_ABORTED, logger->error(MSG_DOWNLOAD_ABORTED,
DL_ABORT_EX2(StringFormat DL_ABORT_EX2(StringFormat
("URI=%s", req->getCurrentUrl().c_str()).str(),err), ("URI=%s", req->getCurrentUrl().c_str()).str(),err),
cuid, req->getUrl().c_str()); cuid, req->getUrl().c_str());
_fileEntry->addURIResult(req->getUrl(), err.getCode()); _fileEntry->addURIResult(req->getUrl(), err.getCode());
_requestGroup->setLastUriResult(req->getUrl(), err.getCode()); _requestGroup->setLastUriResult(req->getUrl(), err.getCode());
} }
@ -203,9 +203,9 @@ bool AbstractCommand::execute() {
} catch(DlRetryEx& err) { } catch(DlRetryEx& err) {
assert(!req.isNull()); assert(!req.isNull());
logger->info(MSG_RESTARTING_DOWNLOAD, logger->info(MSG_RESTARTING_DOWNLOAD,
DL_RETRY_EX2(StringFormat DL_RETRY_EX2(StringFormat
("URI=%s", req->getCurrentUrl().c_str()).str(),err), ("URI=%s", req->getCurrentUrl().c_str()).str(),err),
cuid, req->getUrl().c_str()); cuid, req->getUrl().c_str());
req->addTryCount(); req->addTryCount();
req->resetRedirectCount(); req->resetRedirectCount();
const unsigned int maxTries = getOption()->getAsInt(PREF_MAX_TRIES); const unsigned int maxTries = getOption()->getAsInt(PREF_MAX_TRIES);
@ -241,8 +241,8 @@ void AbstractCommand::tryReserved() {
// can assume that there are no in-flight request object. // can assume that there are no in-flight request object.
if(entry->getLength() == 0 && entry->getRemainingUris().empty()) { if(entry->getLength() == 0 && entry->getRemainingUris().empty()) {
logger->debug("CUID#%d - Not trying next request." logger->debug("CUID#%d - Not trying next request."
" No reserved/pooled request is remaining and" " No reserved/pooled request is remaining and"
" total length is still unknown.", cuid); " total length is still unknown.", cuid);
return; return;
} }
} }
@ -260,7 +260,7 @@ bool AbstractCommand::prepareForRetry(time_t wait) {
if(!req.isNull()) { if(!req.isNull()) {
_fileEntry->poolRequest(req); _fileEntry->poolRequest(req);
logger->debug("CUID#%d - Pooling request URI=%s", logger->debug("CUID#%d - Pooling request URI=%s",
cuid, req->getUrl().c_str()); cuid, req->getUrl().c_str());
if(!_requestGroup->getSegmentMan().isNull()) { if(!_requestGroup->getSegmentMan().isNull()) {
_requestGroup->getSegmentMan()->recognizeSegmentFor(_fileEntry); _requestGroup->getSegmentMan()->recognizeSegmentFor(_fileEntry);
} }
@ -272,7 +272,7 @@ bool AbstractCommand::prepareForRetry(time_t wait) {
e->commands.push_back(command); e->commands.push_back(command);
} else { } else {
SleepCommand* scom = new SleepCommand(cuid, e, _requestGroup, SleepCommand* scom = new SleepCommand(cuid, e, _requestGroup,
command, wait); command, wait);
e->commands.push_back(scom); e->commands.push_back(scom);
} }
return true; return true;
@ -282,7 +282,7 @@ void AbstractCommand::onAbort() {
if(!req.isNull()) { if(!req.isNull()) {
// TODO This might be a problem if the failure is caused by proxy. // TODO This might be a problem if the failure is caused by proxy.
e->_requestGroupMan->getOrCreateServerStat(req->getHost(), e->_requestGroupMan->getOrCreateServerStat(req->getHost(),
req->getProtocol())->setError(); req->getProtocol())->setError();
_fileEntry->removeIdenticalURI(req->getUrl()); _fileEntry->removeIdenticalURI(req->getUrl());
_fileEntry->removeRequest(req); _fileEntry->removeRequest(req);
} }
@ -307,9 +307,9 @@ void AbstractCommand::setReadCheckSocket(const SocketHandle& socket) {
} else { } else {
if(checkSocketIsReadable) { if(checkSocketIsReadable) {
if(readCheckTarget != socket) { if(readCheckTarget != socket) {
e->deleteSocketForReadCheck(readCheckTarget, this); e->deleteSocketForReadCheck(readCheckTarget, this);
e->addSocketForReadCheck(socket, this); e->addSocketForReadCheck(socket, this);
readCheckTarget = socket; readCheckTarget = socket;
} }
} else { } else {
e->addSocketForReadCheck(socket, this); e->addSocketForReadCheck(socket, this);
@ -343,9 +343,9 @@ void AbstractCommand::setWriteCheckSocket(const SocketHandle& socket) {
} else { } else {
if(checkSocketIsWritable) { if(checkSocketIsWritable) {
if(writeCheckTarget != socket) { if(writeCheckTarget != socket) {
e->deleteSocketForWriteCheck(writeCheckTarget, this); e->deleteSocketForWriteCheck(writeCheckTarget, this);
e->addSocketForWriteCheck(socket, this); e->addSocketForWriteCheck(socket, this);
writeCheckTarget = socket; writeCheckTarget = socket;
} }
} else { } else {
e->addSocketForWriteCheck(socket, this); e->addSocketForWriteCheck(socket, this);
@ -366,7 +366,7 @@ void AbstractCommand::setWriteCheckSocketIf
} }
static const std::string& getProxyStringFor(const std::string& proxyPref, static const std::string& getProxyStringFor(const std::string& proxyPref,
const SharedHandle<Option>& option) const SharedHandle<Option>& option)
{ {
if(option->defined(proxyPref)) { if(option->defined(proxyPref)) {
return option->get(proxyPref); return option->get(proxyPref);
@ -376,7 +376,7 @@ static const std::string& getProxyStringFor(const std::string& proxyPref,
} }
static bool isProxyUsed(const std::string& proxyPref, static bool isProxyUsed(const std::string& proxyPref,
const SharedHandle<Option>& option) const SharedHandle<Option>& option)
{ {
std::string proxy = getProxyStringFor(proxyPref, option); std::string proxy = getProxyStringFor(proxyPref, option);
if(proxy.empty()) { if(proxy.empty()) {
@ -387,7 +387,7 @@ static bool isProxyUsed(const std::string& proxyPref,
} }
static bool isProxyRequest(const std::string& protocol, static bool isProxyRequest(const std::string& protocol,
const SharedHandle<Option>& option) const SharedHandle<Option>& option)
{ {
return return
(protocol == Request::PROTO_HTTP && isProxyUsed(PREF_HTTP_PROXY, option)) || (protocol == Request::PROTO_HTTP && isProxyUsed(PREF_HTTP_PROXY, option)) ||
@ -412,7 +412,7 @@ public:
}; };
static bool inNoProxy(const SharedHandle<Request>& req, static bool inNoProxy(const SharedHandle<Request>& req,
const std::string& noProxy) const std::string& noProxy)
{ {
std::vector<std::string> entries; std::vector<std::string> entries;
util::split(noProxy, std::back_inserter(entries), ",", true); util::split(noProxy, std::back_inserter(entries), ",", true);
@ -421,7 +421,7 @@ static bool inNoProxy(const SharedHandle<Request>& req,
} }
return return
std::find_if(entries.begin(), entries.end(), std::find_if(entries.begin(), entries.end(),
DomainMatch("."+req->getHost())) != entries.end(); DomainMatch("."+req->getHost())) != entries.end();
} }
bool AbstractCommand::isProxyDefined() const bool AbstractCommand::isProxyDefined() const
@ -431,7 +431,7 @@ bool AbstractCommand::isProxyDefined() const
} }
static const std::string& getProxyString(const SharedHandle<Request>& req, static const std::string& getProxyString(const SharedHandle<Request>& req,
const SharedHandle<Option>& option) const SharedHandle<Option>& option)
{ {
if(req->getProtocol() == Request::PROTO_HTTP) { if(req->getProtocol() == Request::PROTO_HTTP) {
return getProxyStringFor(PREF_HTTP_PROXY, option); return getProxyStringFor(PREF_HTTP_PROXY, option);
@ -486,11 +486,11 @@ bool AbstractCommand::asyncResolveHostname()
case AsyncNameResolver::STATUS_ERROR: case AsyncNameResolver::STATUS_ERROR:
if(!isProxyRequest(req->getProtocol(), getOption())) { if(!isProxyRequest(req->getProtocol(), getOption())) {
e->_requestGroupMan->getOrCreateServerStat e->_requestGroupMan->getOrCreateServerStat
(req->getHost(), req->getProtocol())->setError(); (req->getHost(), req->getProtocol())->setError();
} }
throw DL_ABORT_EX(StringFormat(MSG_NAME_RESOLUTION_FAILED, cuid, throw DL_ABORT_EX(StringFormat(MSG_NAME_RESOLUTION_FAILED, cuid,
_asyncNameResolver->getHostname().c_str(), _asyncNameResolver->getHostname().c_str(),
_asyncNameResolver->getError().c_str()).str()); _asyncNameResolver->getError().c_str()).str());
default: default:
return false; return false;
} }
@ -548,24 +548,24 @@ bool AbstractCommand::checkIfConnectionEstablished
// See also InitiateConnectionCommand::executeInternal() // See also InitiateConnectionCommand::executeInternal()
e->markBadIPAddress(connectedHostname, connectedAddr, connectedPort); e->markBadIPAddress(connectedHostname, connectedAddr, connectedPort);
if(!e->findCachedIPAddress(connectedHostname, connectedPort).empty()) { if(!e->findCachedIPAddress(connectedHostname, connectedPort).empty()) {
logger->info(MSG_CONNECT_FAILED_AND_RETRY, logger->info(MSG_CONNECT_FAILED_AND_RETRY,
cuid, connectedAddr.c_str(), connectedPort); cuid, connectedAddr.c_str(), connectedPort);
Command* command = Command* command =
InitiateConnectionCommandFactory::createInitiateConnectionCommand InitiateConnectionCommandFactory::createInitiateConnectionCommand
(cuid, req, _fileEntry, _requestGroup, e); (cuid, req, _fileEntry, _requestGroup, e);
e->setNoWait(true); e->setNoWait(true);
e->commands.push_back(command); e->commands.push_back(command);
return false; return false;
} }
e->removeCachedIPAddress(connectedHostname, connectedPort); e->removeCachedIPAddress(connectedHostname, connectedPort);
// Don't set error if proxy server is used and its method is GET. // Don't set error if proxy server is used and its method is GET.
if(resolveProxyMethod(req->getProtocol()) != V_GET || if(resolveProxyMethod(req->getProtocol()) != V_GET ||
!isProxyRequest(req->getProtocol(), getOption())) { !isProxyRequest(req->getProtocol(), getOption())) {
e->_requestGroupMan->getOrCreateServerStat e->_requestGroupMan->getOrCreateServerStat
(req->getHost(), req->getProtocol())->setError(); (req->getHost(), req->getProtocol())->setError();
} }
throw DL_RETRY_EX throw DL_RETRY_EX
(StringFormat(MSG_ESTABLISHING_CONNECTION_FAILED, error.c_str()).str()); (StringFormat(MSG_ESTABLISHING_CONNECTION_FAILED, error.c_str()).str());
} }
} }
return true; return true;

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -153,9 +153,9 @@ private:
#endif // ENABLE_ASYNC_DNS #endif // ENABLE_ASYNC_DNS
public: public:
AbstractCommand(int32_t cuid, const SharedHandle<Request>& req, AbstractCommand(int32_t cuid, const SharedHandle<Request>& req,
const SharedHandle<FileEntry>& fileEntry, const SharedHandle<FileEntry>& fileEntry,
RequestGroup* requestGroup, DownloadEngine* e, RequestGroup* requestGroup, DownloadEngine* e,
const SharedHandle<SocketCore>& s = SharedHandle<SocketCore>()); const SharedHandle<SocketCore>& s = SharedHandle<SocketCore>());
virtual ~AbstractCommand(); virtual ~AbstractCommand();
bool execute(); bool execute();

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -110,9 +110,9 @@ void AbstractDiskWriter::createFile(int addFlags)
assert(!_filename.empty()); assert(!_filename.empty());
util::mkdirs(File(_filename).getDirname()); util::mkdirs(File(_filename).getDirname());
if((fd = open(_filename.c_str(), O_CREAT|O_RDWR|O_TRUNC|O_BINARY|addFlags, if((fd = open(_filename.c_str(), O_CREAT|O_RDWR|O_TRUNC|O_BINARY|addFlags,
OPEN_MODE)) < 0) { OPEN_MODE)) < 0) {
throw DL_ABORT_EX(StringFormat(EX_FILE_OPEN, throw DL_ABORT_EX(StringFormat(EX_FILE_OPEN,
_filename.c_str(), strerror(errno)).str()); _filename.c_str(), strerror(errno)).str());
} }
} }
@ -153,10 +153,10 @@ void AbstractDiskWriter::writeData(const unsigned char* data, size_t len, off_t
// DownloadFailureException and abort download instantly. // DownloadFailureException and abort download instantly.
if(errno == ENOSPC) { if(errno == ENOSPC) {
throw DOWNLOAD_FAILURE_EXCEPTION throw DOWNLOAD_FAILURE_EXCEPTION
(StringFormat(EX_FILE_WRITE, _filename.c_str(), strerror(errno)).str()); (StringFormat(EX_FILE_WRITE, _filename.c_str(), strerror(errno)).str());
} }
throw DL_ABORT_EX(StringFormat(EX_FILE_WRITE, throw DL_ABORT_EX(StringFormat(EX_FILE_WRITE,
_filename.c_str(), strerror(errno)).str()); _filename.c_str(), strerror(errno)).str());
} }
} }
@ -166,7 +166,7 @@ ssize_t AbstractDiskWriter::readData(unsigned char* data, size_t len, off_t offs
seek(offset); seek(offset);
if((ret = readDataInternal(data, len)) < 0) { if((ret = readDataInternal(data, len)) < 0) {
throw DL_ABORT_EX(StringFormat(EX_FILE_READ, throw DL_ABORT_EX(StringFormat(EX_FILE_READ,
_filename.c_str(), strerror(errno)).str()); _filename.c_str(), strerror(errno)).str());
} }
return ret; return ret;
} }
@ -183,12 +183,12 @@ void AbstractDiskWriter::truncate(uint64_t length)
seek(length); seek(length);
if(SetEndOfFile(handle) == 0) { if(SetEndOfFile(handle) == 0) {
throw DL_ABORT_EX(StringFormat("SetEndOfFile failed. cause: %s", throw DL_ABORT_EX(StringFormat("SetEndOfFile failed. cause: %s",
GetLastError()).str()); GetLastError()).str());
} }
#else #else
if(ftruncate(fd, length) == -1) { if(ftruncate(fd, length) == -1) {
throw DL_ABORT_EX(StringFormat("ftruncate failed. cause: %s", throw DL_ABORT_EX(StringFormat("ftruncate failed. cause: %s",
strerror(errno)).str()); strerror(errno)).str());
} }
#endif #endif
} }
@ -202,7 +202,7 @@ void AbstractDiskWriter::allocate(off_t offset, uint64_t length)
int r = posix_fallocate(fd, offset, length); int r = posix_fallocate(fd, offset, length);
if(r != 0) { if(r != 0) {
throw DL_ABORT_EX(StringFormat("posix_fallocate failed. cause: %s", throw DL_ABORT_EX(StringFormat("posix_fallocate failed. cause: %s",
strerror(r)).str()); strerror(r)).str());
} }
} }
#endif // HAVE_POSIX_FALLOCATE #endif // HAVE_POSIX_FALLOCATE

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -55,12 +55,12 @@ protected:
virtual bool executeInternal(); virtual bool executeInternal();
public: public:
AbstractProxyRequestCommand(int cuid, AbstractProxyRequestCommand(int cuid,
const SharedHandle<Request>& req, const SharedHandle<Request>& req,
const SharedHandle<FileEntry>& fileEntry, const SharedHandle<FileEntry>& fileEntry,
RequestGroup* requestGroup, RequestGroup* requestGroup,
DownloadEngine* e, DownloadEngine* e,
const SharedHandle<Request>& proxyRequest, const SharedHandle<Request>& proxyRequest,
const SharedHandle<SocketCore>& s); const SharedHandle<SocketCore>& s);
virtual ~AbstractProxyRequestCommand(); virtual ~AbstractProxyRequestCommand();

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -103,7 +103,7 @@ FileAllocationIteratorHandle AbstractSingleDiskAdaptor::fileAllocationIterator()
#endif // HAVE_POSIX_FALLOCATE #endif // HAVE_POSIX_FALLOCATE
{ {
SingleFileAllocationIteratorHandle h SingleFileAllocationIteratorHandle h
(new SingleFileAllocationIterator(this, size(), totalLength)); (new SingleFileAllocationIterator(this, size(), totalLength));
h->init(); h->init();
return h; return h;
} }

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -61,7 +61,7 @@ public:
virtual void openExistingFile(); virtual void openExistingFile();
virtual void writeData(const unsigned char* data, size_t len, virtual void writeData(const unsigned char* data, size_t len,
off_t offset); off_t offset);
virtual ssize_t readData(unsigned char* data, size_t len, off_t offset); virtual ssize_t readData(unsigned char* data, size_t len, off_t offset);

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -86,7 +86,7 @@ bool ActivePeerConnectionCommand::execute() {
if(_requestGroup->getDownloadContext()-> if(_requestGroup->getDownloadContext()->
getAttribute(bittorrent::BITTORRENT).containsKey(bittorrent::METADATA)) { getAttribute(bittorrent::BITTORRENT).containsKey(bittorrent::METADATA)) {
thresholdSpeed = thresholdSpeed =
_requestGroup->getOption()->getAsInt(PREF_BT_REQUEST_PEER_SPEED_LIMIT); _requestGroup->getOption()->getAsInt(PREF_BT_REQUEST_PEER_SPEED_LIMIT);
} else { } else {
thresholdSpeed = 0; thresholdSpeed = 0;
} }
@ -95,31 +95,31 @@ bool ActivePeerConnectionCommand::execute() {
} }
if(// for seeder state if(// for seeder state
(_pieceStorage->downloadFinished() && _btRuntime->lessThanMaxPeers() && (_pieceStorage->downloadFinished() && _btRuntime->lessThanMaxPeers() &&
(maxUploadLimit == 0 || tstat.getUploadSpeed() < maxUploadLimit*0.8)) || (maxUploadLimit == 0 || tstat.getUploadSpeed() < maxUploadLimit*0.8)) ||
// for leecher state // for leecher state
(!_pieceStorage->downloadFinished() && (!_pieceStorage->downloadFinished() &&
(tstat.getDownloadSpeed() < thresholdSpeed || (tstat.getDownloadSpeed() < thresholdSpeed ||
_btRuntime->lessThanMinPeers()))) { _btRuntime->lessThanMinPeers()))) {
unsigned int numConnection = 0; unsigned int numConnection = 0;
if(_pieceStorage->downloadFinished()) { if(_pieceStorage->downloadFinished()) {
if(_btRuntime->getMaxPeers() > _btRuntime->getConnections()) { if(_btRuntime->getMaxPeers() > _btRuntime->getConnections()) {
numConnection = numConnection =
std::min(_numNewConnection, std::min(_numNewConnection,
_btRuntime->getMaxPeers()-_btRuntime->getConnections()); _btRuntime->getMaxPeers()-_btRuntime->getConnections());
} }
} else { } else {
numConnection = _numNewConnection; numConnection = _numNewConnection;
} }
for(unsigned int numAdd = numConnection; for(unsigned int numAdd = numConnection;
numAdd > 0 && _peerStorage->isPeerAvailable(); --numAdd) { numAdd > 0 && _peerStorage->isPeerAvailable(); --numAdd) {
PeerHandle peer = _peerStorage->getUnusedPeer(); PeerHandle peer = _peerStorage->getUnusedPeer();
connectToPeer(peer); connectToPeer(peer);
} }
if(_btRuntime->getConnections() == 0 && if(_btRuntime->getConnections() == 0 &&
!_pieceStorage->downloadFinished()) { !_pieceStorage->downloadFinished()) {
_btAnnounce->overrideMinInterval(BtAnnounce::DEFAULT_ANNOUNCE_INTERVAL); _btAnnounce->overrideMinInterval(BtAnnounce::DEFAULT_ANNOUNCE_INTERVAL);
} }
} }
} }
@ -135,12 +135,12 @@ void ActivePeerConnectionCommand::connectToPeer(const PeerHandle& peer)
peer->usedBy(e->newCUID()); peer->usedBy(e->newCUID());
PeerInitiateConnectionCommand* command = PeerInitiateConnectionCommand* command =
new PeerInitiateConnectionCommand(peer->usedBy(), _requestGroup, peer, e, new PeerInitiateConnectionCommand(peer->usedBy(), _requestGroup, peer, e,
_btRuntime); _btRuntime);
command->setPeerStorage(_peerStorage); command->setPeerStorage(_peerStorage);
command->setPieceStorage(_pieceStorage); command->setPieceStorage(_pieceStorage);
e->commands.push_back(command); e->commands.push_back(command);
logger->info(MSG_CONNECTING_TO_PEER, logger->info(MSG_CONNECTING_TO_PEER,
cuid, peer->ipaddr.c_str()); cuid, peer->ipaddr.c_str());
} }
void ActivePeerConnectionCommand::setBtRuntime void ActivePeerConnectionCommand::setBtRuntime

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -63,9 +63,9 @@ private:
unsigned int _numNewConnection; // the number of the connection to establish. unsigned int _numNewConnection; // the number of the connection to establish.
public: public:
ActivePeerConnectionCommand(int cuid, ActivePeerConnectionCommand(int cuid,
RequestGroup* requestGroup, RequestGroup* requestGroup,
DownloadEngine* e, DownloadEngine* e,
time_t interval); time_t interval);
virtual ~ActivePeerConnectionCommand(); virtual ~ActivePeerConnectionCommand();

View File

@ -17,7 +17,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -75,7 +75,7 @@ AdaptiveURISelector::~AdaptiveURISelector() {}
std::string AdaptiveURISelector::select(FileEntry* fileEntry) std::string AdaptiveURISelector::select(FileEntry* fileEntry)
{ {
_logger->debug("AdaptiveURISelector: called %d", _logger->debug("AdaptiveURISelector: called %d",
_requestGroup->getNumConnection()); _requestGroup->getNumConnection());
std::deque<std::string>& uris = fileEntry->getRemainingUris(); std::deque<std::string>& uris = fileEntry->getRemainingUris();
if (uris.empty() && _requestGroup->getNumConnection() <= 1) { if (uris.empty() && _requestGroup->getNumConnection() <= 1) {
// here we know the download will fail, trying to find previously // here we know the download will fail, trying to find previously
@ -101,13 +101,13 @@ void AdaptiveURISelector::mayRetryWithIncreasedTimeout(FileEntry* fileEntry)
std::deque<URIResult> timeouts; std::deque<URIResult> timeouts;
fileEntry->extractURIResult(timeouts, downloadresultcode::TIME_OUT); fileEntry->extractURIResult(timeouts, downloadresultcode::TIME_OUT);
std::transform(timeouts.begin(), timeouts.end(), std::back_inserter(uris), std::transform(timeouts.begin(), timeouts.end(), std::back_inserter(uris),
std::mem_fun_ref(&URIResult::getURI)); std::mem_fun_ref(&URIResult::getURI));
for(std::deque<std::string>::const_iterator i = uris.begin(); i != uris.end(); for(std::deque<std::string>::const_iterator i = uris.begin(); i != uris.end();
++i) { ++i) {
_logger->debug("AdaptiveURISelector: will retry server with increased" _logger->debug("AdaptiveURISelector: will retry server with increased"
" timeout (%d s): %s", " timeout (%d s): %s",
_requestGroup->getTimeout(), (*i).c_str()); _requestGroup->getTimeout(), (*i).c_str());
} }
} }
@ -122,7 +122,7 @@ std::string AdaptiveURISelector::selectOne(const std::deque<std::string>& uris)
bool reservedContext = numPieces > 0 && bool reservedContext = numPieces > 0 &&
_nbConnections > std::min(numPieces, _nbConnections > std::min(numPieces,
_requestGroup->getNumConcurrentCommand()); _requestGroup->getNumConcurrentCommand());
bool selectBest = numPieces == 0 || reservedContext; bool selectBest = numPieces == 0 || reservedContext;
if(numPieces > 0) if(numPieces > 0)
@ -132,8 +132,8 @@ std::string AdaptiveURISelector::selectOne(const std::deque<std::string>& uris)
if(getNbTestedServers(uris) < 3) { if(getNbTestedServers(uris) < 3) {
std::string notTested = getFirstNotTestedUri(uris); std::string notTested = getFirstNotTestedUri(uris);
if(notTested != A2STR::NIL) { if(notTested != A2STR::NIL) {
_logger->debug("AdaptiveURISelector: choosing the first non tested" _logger->debug("AdaptiveURISelector: choosing the first non tested"
" mirror: %s", notTested.c_str()); " mirror: %s", notTested.c_str());
--_nbServerToEvaluate; --_nbServerToEvaluate;
return notTested; return notTested;
} }
@ -144,20 +144,20 @@ std::string AdaptiveURISelector::selectOne(const std::deque<std::string>& uris)
std::string notTested = getFirstNotTestedUri(uris); std::string notTested = getFirstNotTestedUri(uris);
if(notTested != A2STR::NIL) { if(notTested != A2STR::NIL) {
/* Here we return the first untested mirror */ /* Here we return the first untested mirror */
_logger->debug("AdaptiveURISelector: choosing non tested mirror %s for" _logger->debug("AdaptiveURISelector: choosing non tested mirror %s for"
" connection #%d", notTested.c_str(), _nbConnections); " connection #%d", notTested.c_str(), _nbConnections);
return notTested; return notTested;
} else { } else {
/* Here we return a mirror which need to be tested again */ /* Here we return a mirror which need to be tested again */
std::string toReTest = getFirstToTestUri(uris); std::string toReTest = getFirstToTestUri(uris);
if(toReTest != A2STR::NIL) { if(toReTest != A2STR::NIL) {
_logger->debug("AdaptiveURISelector: choosing mirror %s which has not" _logger->debug("AdaptiveURISelector: choosing mirror %s which has not"
" been tested recently for connection #%d", " been tested recently for connection #%d",
toReTest.c_str(), _nbConnections); toReTest.c_str(), _nbConnections);
return toReTest; return toReTest;
} else { } else {
return getBestMirror(uris); return getBestMirror(uris);
} }
} }
} }
else { else {
@ -177,14 +177,14 @@ std::string AdaptiveURISelector::getBestMirror
if (bests.size() < 2) { if (bests.size() < 2) {
std::string uri = getMaxDownloadSpeedUri(uris); std::string uri = getMaxDownloadSpeedUri(uris);
_logger->debug("AdaptiveURISelector: choosing the best mirror :" _logger->debug("AdaptiveURISelector: choosing the best mirror :"
" %.2fKB/s %s (other mirrors are at least 25%% slower)", " %.2fKB/s %s (other mirrors are at least 25%% slower)",
(float) max/1024, uri.c_str()); (float) max/1024, uri.c_str());
return uri; return uri;
} else { } else {
std::string uri = selectRandomUri(bests); std::string uri = selectRandomUri(bests);
_logger->debug("AdaptiveURISelector: choosing randomly one of the best" _logger->debug("AdaptiveURISelector: choosing randomly one of the best"
" mirrors (range [%.2fKB/s, %.2fKB/s]): %s", " mirrors (range [%.2fKB/s, %.2fKB/s]): %s",
(float) min/1024, (float) max/1024, uri.c_str()); (float) min/1024, (float) max/1024, uri.c_str());
return uri; return uri;
} }
} }
@ -212,11 +212,11 @@ void AdaptiveURISelector::adjustLowestSpeedLimit
unsigned int max = getMaxDownloadSpeed(uris); unsigned int max = getMaxDownloadSpeed(uris);
if (max > 0 && lowest > max / 4) { if (max > 0 && lowest > max / 4) {
_logger->notice("Lowering lowest-speed-limit since known max speed is too" _logger->notice("Lowering lowest-speed-limit since known max speed is too"
" near (new:%d was:%d max:%d)", max / 4, lowest, max); " near (new:%d was:%d max:%d)", max / 4, lowest, max);
command->setLowestDownloadSpeedLimit(max / 4); command->setLowestDownloadSpeedLimit(max / 4);
} else if (max == 0 && lowest > low_lowest) { } else if (max == 0 && lowest > low_lowest) {
_logger->notice("Lowering lowest-speed-limit since we have no clue about" _logger->notice("Lowering lowest-speed-limit since we have no clue about"
" available speed (now:%d was:%d)", low_lowest, lowest); " available speed (now:%d was:%d)", low_lowest, lowest);
command->setLowestDownloadSpeedLimit(low_lowest); command->setLowestDownloadSpeedLimit(low_lowest);
} }
} }
@ -225,7 +225,7 @@ void AdaptiveURISelector::adjustLowestSpeedLimit
static unsigned int getUriMaxSpeed(SharedHandle<ServerStat> ss) static unsigned int getUriMaxSpeed(SharedHandle<ServerStat> ss)
{ {
return std::max(ss->getSingleConnectionAvgSpeed(), return std::max(ss->getSingleConnectionAvgSpeed(),
ss->getMultiConnectionAvgSpeed()); ss->getMultiConnectionAvgSpeed());
} }
unsigned int AdaptiveURISelector::getMaxDownloadSpeed unsigned int AdaptiveURISelector::getMaxDownloadSpeed
@ -265,12 +265,12 @@ std::deque<std::string> AdaptiveURISelector::getUrisBySpeed
{ {
std::deque<std::string> bests; std::deque<std::string> bests;
for(std::deque<std::string>::const_iterator i = uris.begin(); for(std::deque<std::string>::const_iterator i = uris.begin();
i != uris.end(); ++i) { i != uris.end(); ++i) {
SharedHandle<ServerStat> ss = getServerStats(*i); SharedHandle<ServerStat> ss = getServerStats(*i);
if(ss.isNull()) if(ss.isNull())
continue; continue;
if(ss->getSingleConnectionAvgSpeed() > min || if(ss->getSingleConnectionAvgSpeed() > min ||
ss->getMultiConnectionAvgSpeed() > min) { ss->getMultiConnectionAvgSpeed() > min) {
bests.push_back(*i); bests.push_back(*i);
} }
} }
@ -304,7 +304,7 @@ std::string AdaptiveURISelector::getFirstToTestUri
unsigned int counter; unsigned int counter;
int power; int power;
for(std::deque<std::string>::const_iterator i = uris.begin(); for(std::deque<std::string>::const_iterator i = uris.begin();
i != uris.end(); ++i) { i != uris.end(); ++i) {
SharedHandle<ServerStat> ss = getServerStats(*i); SharedHandle<ServerStat> ss = getServerStats(*i);
if(ss.isNull()) if(ss.isNull())
continue; continue;

View File

@ -17,7 +17,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -61,11 +61,11 @@ private:
std::string selectOne(const std::deque<std::string>& uris); std::string selectOne(const std::deque<std::string>& uris);
void adjustLowestSpeedLimit(const std::deque<std::string>& uris, void adjustLowestSpeedLimit(const std::deque<std::string>& uris,
DownloadCommand* command) const; DownloadCommand* command) const;
unsigned int getMaxDownloadSpeed(const std::deque<std::string>& uris) const; unsigned int getMaxDownloadSpeed(const std::deque<std::string>& uris) const;
std::string getMaxDownloadSpeedUri(const std::deque<std::string>& uris) const; std::string getMaxDownloadSpeedUri(const std::deque<std::string>& uris) const;
std::deque<std::string> getUrisBySpeed(const std::deque<std::string>& uris, std::deque<std::string> getUrisBySpeed(const std::deque<std::string>& uris,
unsigned int min) const; unsigned int min) const;
std::string selectRandomUri(const std::deque<std::string>& uris) const; std::string selectRandomUri(const std::deque<std::string>& uris) const;
std::string getFirstNotTestedUri(const std::deque<std::string>& uris) const; std::string getFirstNotTestedUri(const std::deque<std::string>& uris) const;
std::string getFirstToTestUri(const std::deque<std::string>& uris) const; std::string getFirstToTestUri(const std::deque<std::string>& uris) const;
@ -74,13 +74,13 @@ private:
std::string getBestMirror(const std::deque<std::string>& uris) const; std::string getBestMirror(const std::deque<std::string>& uris) const;
public: public:
AdaptiveURISelector(const SharedHandle<ServerStatMan>& serverStatMan, AdaptiveURISelector(const SharedHandle<ServerStatMan>& serverStatMan,
RequestGroup* requestGroup); RequestGroup* requestGroup);
virtual ~AdaptiveURISelector(); virtual ~AdaptiveURISelector();
virtual std::string select(FileEntry* fileEntry); virtual std::string select(FileEntry* fileEntry);
virtual void tuneDownloadCommand(const std::deque<std::string>& uris, virtual void tuneDownloadCommand(const std::deque<std::string>& uris,
DownloadCommand* command); DownloadCommand* command);
virtual void resetCounters(); virtual void resetCounters();
}; };

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -63,22 +63,22 @@ void AnnounceList::reconfigure(const BDE& announceList)
{ {
if(announceList.isList()) { if(announceList.isList()) {
for(BDE::List::const_iterator itr = announceList.listBegin(); for(BDE::List::const_iterator itr = announceList.listBegin();
itr != announceList.listEnd(); ++itr) { itr != announceList.listEnd(); ++itr) {
const BDE& elemList = *itr; const BDE& elemList = *itr;
if(!elemList.isList()) { if(!elemList.isList()) {
continue; continue;
} }
std::deque<std::string> urls; std::deque<std::string> urls;
for(BDE::List::const_iterator elemItr = elemList.listBegin(); for(BDE::List::const_iterator elemItr = elemList.listBegin();
elemItr != elemList.listEnd(); ++elemItr) { elemItr != elemList.listEnd(); ++elemItr) {
const BDE& data = *elemItr; const BDE& data = *elemItr;
if(data.isString()) { if(data.isString()) {
urls.push_back(data.s()); urls.push_back(data.s());
} }
} }
if(!urls.empty()) { if(!urls.empty()) {
AnnounceTierHandle tier(new AnnounceTier(urls)); AnnounceTierHandle tier(new AnnounceTier(urls));
tiers.push_back(tier); tiers.push_back(tier);
} }
} }
resetIterator(); resetIterator();
@ -129,9 +129,9 @@ void AnnounceList::announceFailure() {
(*currentTier)->nextEventIfAfterStarted(); (*currentTier)->nextEventIfAfterStarted();
++currentTier; ++currentTier;
if(currentTier == tiers.end()) { if(currentTier == tiers.end()) {
currentTrackerInitialized = false; currentTrackerInitialized = false;
} else { } else {
currentTracker = (*currentTier)->urls.begin(); currentTracker = (*currentTier)->urls.begin();
} }
} }
} }
@ -215,7 +215,7 @@ void AnnounceList::setCurrentTier(const AnnounceTiers::iterator& itr) {
template<class InputIterator, class Predicate> template<class InputIterator, class Predicate>
InputIterator InputIterator
find_wrap_if(InputIterator first, InputIterator last, find_wrap_if(InputIterator first, InputIterator last,
InputIterator current, Predicate pred) { InputIterator current, Predicate pred) {
InputIterator itr = std::find_if(current, last, pred); InputIterator itr = std::find_if(current, last, pred);
if(itr == last) { if(itr == last) {
itr = std::find_if(first, current, pred); itr = std::find_if(first, current, pred);
@ -225,15 +225,15 @@ find_wrap_if(InputIterator first, InputIterator last,
void AnnounceList::moveToStoppedAllowedTier() { void AnnounceList::moveToStoppedAllowedTier() {
AnnounceTiers::iterator itr = find_wrap_if(tiers.begin(), tiers.end(), AnnounceTiers::iterator itr = find_wrap_if(tiers.begin(), tiers.end(),
currentTier, currentTier,
FindStoppedAllowedTier()); FindStoppedAllowedTier());
setCurrentTier(itr); setCurrentTier(itr);
} }
void AnnounceList::moveToCompletedAllowedTier() { void AnnounceList::moveToCompletedAllowedTier() {
AnnounceTiers::iterator itr = find_wrap_if(tiers.begin(), tiers.end(), AnnounceTiers::iterator itr = find_wrap_if(tiers.begin(), tiers.end(),
currentTier, currentTier,
FindCompletedAllowedTier()); FindCompletedAllowedTier());
setCurrentTier(itr); setCurrentTier(itr);
} }
@ -242,7 +242,7 @@ void AnnounceList::shuffle() {
itr != tiers.end(); ++itr) { itr != tiers.end(); ++itr) {
std::deque<std::string>& urls = (*itr)->urls; std::deque<std::string>& urls = (*itr)->urls;
std::random_shuffle(urls.begin(), urls.end(), std::random_shuffle(urls.begin(), urls.end(),
*(SimpleRandomizer::getInstance().get())); *(SimpleRandomizer::getInstance().get()));
} }
} }

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -42,7 +42,7 @@ namespace aria2 {
#ifdef HAVE_LIBCARES1_5 #ifdef HAVE_LIBCARES1_5
void callback(void* arg, int status, int timeouts, struct hostent* host) void callback(void* arg, int status, int timeouts, struct hostent* host)
#else #else
void callback(void* arg, int status, struct hostent* host) void callback(void* arg, int status, struct hostent* host)
#endif // HAVE_LIBCARES1_5 #endif // HAVE_LIBCARES1_5
{ {
AsyncNameResolver* resolverPtr = reinterpret_cast<AsyncNameResolver*>(arg); AsyncNameResolver* resolverPtr = reinterpret_cast<AsyncNameResolver*>(arg);
@ -98,7 +98,7 @@ int AsyncNameResolver::getsock(sock_t* sockets) const
{ {
// TODO cast to int* might cause problem with Windows SOCKET? // TODO cast to int* might cause problem with Windows SOCKET?
return ares_getsock(channel, reinterpret_cast<int*>(sockets), return ares_getsock(channel, reinterpret_cast<int*>(sockets),
ARES_GETSOCK_MAXNUM); ARES_GETSOCK_MAXNUM);
} }
void AsyncNameResolver::process(ares_socket_t readfd, ares_socket_t writefd) void AsyncNameResolver::process(ares_socket_t readfd, ares_socket_t writefd)

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -64,51 +64,51 @@ AuthConfigFactory::createAuthConfig
if(op->getAsBool(PREF_HTTP_AUTH_CHALLENGE)) { if(op->getAsBool(PREF_HTTP_AUTH_CHALLENGE)) {
if(!request->getUsername().empty()) { if(!request->getUsername().empty()) {
updateBasicCred(BasicCred(request->getUsername(), updateBasicCred(BasicCred(request->getUsername(),
request->getPassword(), request->getPassword(),
request->getHost(), request->getDir(), true)); request->getHost(), request->getDir(), true));
return createAuthConfig(request->getUsername(), request->getPassword()); return createAuthConfig(request->getUsername(), request->getPassword());
} }
std::deque<BasicCred>::const_iterator i = std::deque<BasicCred>::const_iterator i =
findBasicCred(request->getHost(), request->getDir()); findBasicCred(request->getHost(), request->getDir());
if(i == _basicCreds.end()) { if(i == _basicCreds.end()) {
return SharedHandle<AuthConfig>(); return SharedHandle<AuthConfig>();
} else { } else {
return createAuthConfig((*i)._user, (*i)._password); return createAuthConfig((*i)._user, (*i)._password);
} }
} else { } else {
if(!request->getUsername().empty()) { if(!request->getUsername().empty()) {
return createAuthConfig(request->getUsername(), request->getPassword()); return createAuthConfig(request->getUsername(), request->getPassword());
} else { } else {
return return
createHttpAuthResolver(op)->resolveAuthConfig(request->getHost()); createHttpAuthResolver(op)->resolveAuthConfig(request->getHost());
} }
} }
} else if(request->getProtocol() == Request::PROTO_FTP) { } else if(request->getProtocol() == Request::PROTO_FTP) {
if(!request->getUsername().empty()) { if(!request->getUsername().empty()) {
if(request->hasPassword()) { if(request->hasPassword()) {
return createAuthConfig(request->getUsername(), request->getPassword()); return createAuthConfig(request->getUsername(), request->getPassword());
} else { } else {
if(!op->getAsBool(PREF_NO_NETRC)) { if(!op->getAsBool(PREF_NO_NETRC)) {
// First, check we have password corresponding to host and // First, check we have password corresponding to host and
// username // username
NetrcAuthResolver authResolver; NetrcAuthResolver authResolver;
authResolver.setNetrc(_netrc); authResolver.setNetrc(_netrc);
SharedHandle<AuthConfig> ac = SharedHandle<AuthConfig> ac =
authResolver.resolveAuthConfig(request->getHost()); authResolver.resolveAuthConfig(request->getHost());
if(!ac.isNull() && ac->getUser() == request->getUsername()) { if(!ac.isNull() && ac->getUser() == request->getUsername()) {
return ac; return ac;
} }
} }
// We don't have password for host and username. Return // We don't have password for host and username. Return
// password specified by --ftp-passwd // password specified by --ftp-passwd
return return
createAuthConfig(request->getUsername(), op->get(PREF_FTP_PASSWD)); createAuthConfig(request->getUsername(), op->get(PREF_FTP_PASSWD));
} }
} else { } else {
return return
createFtpAuthResolver(op)->resolveAuthConfig(request->getHost()); createFtpAuthResolver(op)->resolveAuthConfig(request->getHost());
} }
} else { } else {
return SharedHandle<AuthConfig>(); return SharedHandle<AuthConfig>();
@ -157,7 +157,7 @@ AuthResolverHandle AuthConfigFactory::createFtpAuthResolver
(createAuthConfig(op->get(PREF_FTP_USER), op->get(PREF_FTP_PASSWD))); (createAuthConfig(op->get(PREF_FTP_USER), op->get(PREF_FTP_PASSWD)));
SharedHandle<AuthConfig> defaultAuthConfig SharedHandle<AuthConfig> defaultAuthConfig
(new AuthConfig(AuthConfigFactory::ANONYMOUS, (new AuthConfig(AuthConfigFactory::ANONYMOUS,
AuthConfigFactory::ARIA2USER_AT)); AuthConfigFactory::ARIA2USER_AT));
resolver->setDefaultAuthConfig(defaultAuthConfig); resolver->setDefaultAuthConfig(defaultAuthConfig);
return resolver; return resolver;
} }
@ -191,7 +191,7 @@ bool AuthConfigFactory::activateBasicCred
return false; return false;
} else { } else {
BasicCred bc(authConfig->getUser(), authConfig->getPassword(), BasicCred bc(authConfig->getUser(), authConfig->getPassword(),
host, path, true); host, path, true);
i = std::lower_bound(_basicCreds.begin(), _basicCreds.end(), bc); i = std::lower_bound(_basicCreds.begin(), _basicCreds.end(), bc);
_basicCreds.insert(i, bc); _basicCreds.insert(i, bc);
return true; return true;
@ -241,7 +241,7 @@ bool AuthConfigFactory::BasicCred::operator<(const BasicCred& cred) const
std::deque<AuthConfigFactory::BasicCred>::iterator std::deque<AuthConfigFactory::BasicCred>::iterator
AuthConfigFactory::findBasicCred(const std::string& host, AuthConfigFactory::findBasicCred(const std::string& host,
const std::string& path) const std::string& path)
{ {
BasicCred bc("", "", host, path); BasicCred bc("", "", host, path);
std::deque<BasicCred>::iterator i = std::deque<BasicCred>::iterator i =

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -56,7 +56,7 @@ private:
SharedHandle<Netrc> _netrc; SharedHandle<Netrc> _netrc;
SharedHandle<AuthConfig> createAuthConfig(const std::string& user, SharedHandle<AuthConfig> createAuthConfig(const std::string& user,
const std::string& password) const; const std::string& password) const;
SharedHandle<AuthResolver> createHttpAuthResolver(const Option* op) const; SharedHandle<AuthResolver> createHttpAuthResolver(const Option* op) const;
@ -71,8 +71,8 @@ public:
bool _activated; bool _activated;
BasicCred(const std::string& user, const std::string& password, BasicCred(const std::string& user, const std::string& password,
const std::string& host, const std::string& path, const std::string& host, const std::string& path,
bool activated = false); bool activated = false);
void activate(); void activate();

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -42,14 +42,14 @@ const BDE BDE::none;
BDE::BDE():_type(TYPE_NONE), _bobject(new BObject()) {} BDE::BDE():_type(TYPE_NONE), _bobject(new BObject()) {}
BDE::BDE(Integer integer):_type(TYPE_INTEGER), BDE::BDE(Integer integer):_type(TYPE_INTEGER),
_bobject(new BInteger(integer)) {} _bobject(new BInteger(integer)) {}
BDE::BDE(const std::string& string):_type(TYPE_STRING), BDE::BDE(const std::string& string):_type(TYPE_STRING),
_bobject(new BString(std::string(string))) {} _bobject(new BString(std::string(string))) {}
BDE::BDE(const char* cstring):_type(TYPE_STRING), BDE::BDE(const char* cstring):_type(TYPE_STRING),
_bobject(new BString(std::string(cstring))) {} _bobject(new BString(std::string(cstring))) {}
BDE::BDE(const char* data, size_t length): BDE::BDE(const char* data, size_t length):
_type(TYPE_STRING), _type(TYPE_STRING),

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -115,7 +115,7 @@ SharedHandle<DHTBucket> BNode::findBucketFor(BNode* b, const unsigned char* key)
void BNode::findClosestKNodes(std::deque<SharedHandle<DHTNode> >& nodes, void BNode::findClosestKNodes(std::deque<SharedHandle<DHTNode> >& nodes,
BNode* b, const unsigned char* key) BNode* b, const unsigned char* key)
{ {
BNode* bnode = findBNodeFor(b, key); BNode* bnode = findBNodeFor(b, key);
if(!bnode) { if(!bnode) {
@ -149,11 +149,11 @@ void BNode::findClosestKNodes(std::deque<SharedHandle<DHTNode> >& nodes,
bnode = bnode->getUp(); bnode = bnode->getUp();
} else { } else {
if(std::find(visited.begin(), visited.end(), firstfunc(bnode)) == visited.end()) { if(std::find(visited.begin(), visited.end(), firstfunc(bnode)) == visited.end()) {
bnode = firstfunc(bnode); bnode = firstfunc(bnode);
} else if(std::find(visited.begin(), visited.end(), secondfunc(bnode)) == visited.end()) { } else if(std::find(visited.begin(), visited.end(), secondfunc(bnode)) == visited.end()) {
bnode = secondfunc(bnode); bnode = secondfunc(bnode);
} else { } else {
bnode = bnode->getUp(); bnode = bnode->getUp();
} }
} }
if(!bnode) { if(!bnode) {
@ -163,21 +163,21 @@ void BNode::findClosestKNodes(std::deque<SharedHandle<DHTNode> >& nodes,
{ {
SharedHandle<DHTBucket> bucket = bnode->getBucket(); SharedHandle<DHTBucket> bucket = bnode->getBucket();
if(!bucket.isNull()) { if(!bucket.isNull()) {
std::deque<SharedHandle<DHTNode> > goodNodes; std::deque<SharedHandle<DHTNode> > goodNodes;
bucket->getGoodNodes(goodNodes); bucket->getGoodNodes(goodNodes);
size_t r = DHTBucket::K-nodes.size(); size_t r = DHTBucket::K-nodes.size();
if(goodNodes.size() <= r) { if(goodNodes.size() <= r) {
nodes.insert(nodes.end(), goodNodes.begin(), goodNodes.end()); nodes.insert(nodes.end(), goodNodes.begin(), goodNodes.end());
} else { } else {
nodes.insert(nodes.end(), goodNodes.begin(), goodNodes.begin()+r); nodes.insert(nodes.end(), goodNodes.begin(), goodNodes.begin()+r);
} }
} }
} }
} }
} }
void BNode::enumerateBucket(std::deque<SharedHandle<DHTBucket> >& buckets, void BNode::enumerateBucket(std::deque<SharedHandle<DHTBucket> >& buckets,
const BNode* b) const BNode* b)
{ {
std::deque<const BNode*> visited; std::deque<const BNode*> visited;
visited.push_back(b); visited.push_back(b);

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -94,10 +94,10 @@ public:
static SharedHandle<DHTBucket> findBucketFor(BNode* b, const unsigned char* key); static SharedHandle<DHTBucket> findBucketFor(BNode* b, const unsigned char* key);
static void findClosestKNodes(std::deque<SharedHandle<DHTNode> >& nodes, static void findClosestKNodes(std::deque<SharedHandle<DHTNode> >& nodes,
BNode* b, const unsigned char* key); BNode* b, const unsigned char* key);
static void enumerateBucket(std::deque<SharedHandle<DHTBucket> >& buckets, static void enumerateBucket(std::deque<SharedHandle<DHTBucket> >& buckets,
const BNode* b); const BNode* b);
}; };
} // namespace aria2 } // namespace aria2

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -67,7 +67,7 @@ static const int INDEX_TABLE[] = {
}; };
void Base64::encode(unsigned char*& result, size_t& rlength, void Base64::encode(unsigned char*& result, size_t& rlength,
const unsigned char* src, size_t slength) const unsigned char* src, size_t slength)
{ {
if(slength == 0) { if(slength == 0) {
rlength = 0; rlength = 0;
@ -107,9 +107,9 @@ void Base64::encode(unsigned char*& result, size_t& rlength,
} }
void Base64::removeNonBase64Chars(unsigned char*& nsrc, void Base64::removeNonBase64Chars(unsigned char*& nsrc,
size_t& nlength, size_t& nlength,
const unsigned char* src, const unsigned char* src,
size_t slength) size_t slength)
{ {
unsigned char* temp = new unsigned char[slength]; unsigned char* temp = new unsigned char[slength];
const unsigned char* end = src+slength; const unsigned char* end = src+slength;
@ -124,7 +124,7 @@ void Base64::removeNonBase64Chars(unsigned char*& nsrc,
} }
void Base64::decode(unsigned char*& result, size_t& rlength, void Base64::decode(unsigned char*& result, size_t& rlength,
const unsigned char* src, size_t slength) const unsigned char* src, size_t slength)
{ {
if(slength == 0) { if(slength == 0) {
rlength = 0; rlength = 0;

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -47,7 +47,7 @@ private:
* Caller must delete nsrc. * Caller must delete nsrc.
*/ */
static void removeNonBase64Chars(unsigned char*& nsrc, size_t& nlength, static void removeNonBase64Chars(unsigned char*& nsrc, size_t& nlength,
const unsigned char* src, size_t slength); const unsigned char* src, size_t slength);
public: public:
/** /**
@ -59,13 +59,13 @@ public:
* A caller must deallocate the memory used by result. * A caller must deallocate the memory used by result.
*/ */
static void encode(unsigned char*& result, size_t& rlength, static void encode(unsigned char*& result, size_t& rlength,
const unsigned char* src, size_t slength); const unsigned char* src, size_t slength);
static void encode(unsigned char*& result, size_t& rlength, static void encode(unsigned char*& result, size_t& rlength,
const char* src, size_t slength) const char* src, size_t slength)
{ {
encode(result, rlength, reinterpret_cast<const unsigned char*>(src), encode(result, rlength, reinterpret_cast<const unsigned char*>(src),
slength); slength);
} }
static std::string encode(const std::string& s); static std::string encode(const std::string& s);
@ -80,13 +80,13 @@ public:
* A caller must deallocate the memory used by result. * A caller must deallocate the memory used by result.
*/ */
static void decode(unsigned char*& result, size_t& rlength, static void decode(unsigned char*& result, size_t& rlength,
const unsigned char* src, size_t slength); const unsigned char* src, size_t slength);
static void decode(unsigned char*& result, size_t& rlength, static void decode(unsigned char*& result, size_t& rlength,
const char* src, size_t slength) const char* src, size_t slength)
{ {
decode(result, rlength, reinterpret_cast<const unsigned char*>(src), decode(result, rlength, reinterpret_cast<const unsigned char*>(src),
slength); slength);
} }
static std::string decode(const std::string& s); static std::string decode(const std::string& s);

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -153,8 +153,8 @@ BitfieldMan::getNthBitIndex(const unsigned char bitfield, size_t nth) const
if(bitfield & mask) { if(bitfield & mask) {
nth--; nth--;
if(nth == 0) { if(nth == 0) {
index = 7-bs; index = 7-bs;
break; break;
} }
} }
} }
@ -163,8 +163,8 @@ BitfieldMan::getNthBitIndex(const unsigned char bitfield, size_t nth) const
template<typename Array> template<typename Array>
bool BitfieldMan::getMissingIndexRandomly(size_t& index, bool BitfieldMan::getMissingIndexRandomly(size_t& index,
const Array& bitfield, const Array& bitfield,
size_t bitfieldLength) const size_t bitfieldLength) const
{ {
size_t byte = randomizer->getRandomNumber(bitfieldLength); size_t byte = randomizer->getRandomNumber(bitfieldLength);
for(size_t i = 0; i < bitfieldLength; ++i) { for(size_t i = 0; i < bitfieldLength; ++i) {
@ -247,8 +247,8 @@ bool BitfieldMan::getFirstMissingIndex(size_t& index, const Array& bitfield, siz
size_t tindex = i*8; size_t tindex = i*8;
for(size_t bi = 0; bi < 8 && tindex < blocks; ++bi, mask >>= 1, ++tindex) { for(size_t bi = 0; bi < 8 && tindex < blocks; ++bi, mask >>= 1, ++tindex) {
if(bits & mask) { if(bits & mask) {
index = tindex; index = tindex;
return true; return true;
} }
} }
} }
@ -272,7 +272,7 @@ bool BitfieldMan::getFirstMissingIndex(size_t& index) const
{ {
if(filterEnabled) { if(filterEnabled) {
return getFirstMissingIndex(index, ~array(bitfield)&array(filterBitfield), return getFirstMissingIndex(index, ~array(bitfield)&array(filterBitfield),
bitfieldLength); bitfieldLength);
} else { } else {
return getFirstMissingIndex(index, ~array(bitfield), bitfieldLength); return getFirstMissingIndex(index, ~array(bitfield), bitfieldLength);
} }
@ -332,14 +332,14 @@ static bool getSparseMissingUnusedIndex
size_t nextIndex = 0; size_t nextIndex = 0;
while(nextIndex < blocks) { while(nextIndex < blocks) {
currentRange.startIndex = currentRange.startIndex =
getStartIndex(nextIndex, bitfield, blocks); getStartIndex(nextIndex, bitfield, blocks);
if(currentRange.startIndex == blocks) { if(currentRange.startIndex == blocks) {
break; break;
} }
currentRange.endIndex = currentRange.endIndex =
getEndIndex(currentRange.startIndex, bitfield, blocks); getEndIndex(currentRange.startIndex, bitfield, blocks);
if(maxRange < currentRange) { if(maxRange < currentRange) {
maxRange = currentRange; maxRange = currentRange;
} }
nextIndex = currentRange.endIndex; nextIndex = currentRange.endIndex;
} }
@ -401,8 +401,8 @@ bool BitfieldMan::getAllMissingIndexes(unsigned char* misbitfield, size_t len)
} }
bool BitfieldMan::getAllMissingIndexes(unsigned char* misbitfield, size_t len, bool BitfieldMan::getAllMissingIndexes(unsigned char* misbitfield, size_t len,
const unsigned char* peerBitfield, const unsigned char* peerBitfield,
size_t peerBitfieldLength) const size_t peerBitfieldLength) const
{ {
assert(len == bitfieldLength); assert(len == bitfieldLength);
if(bitfieldLength != peerBitfieldLength) { if(bitfieldLength != peerBitfieldLength) {
@ -420,9 +420,9 @@ bool BitfieldMan::getAllMissingIndexes(unsigned char* misbitfield, size_t len,
} }
bool BitfieldMan::getAllMissingUnusedIndexes(unsigned char* misbitfield, bool BitfieldMan::getAllMissingUnusedIndexes(unsigned char* misbitfield,
size_t len, size_t len,
const unsigned char* peerBitfield, const unsigned char* peerBitfield,
size_t peerBitfieldLength) const size_t peerBitfieldLength) const
{ {
assert(len == bitfieldLength); assert(len == bitfieldLength);
if(bitfieldLength != peerBitfieldLength) { if(bitfieldLength != peerBitfieldLength) {
@ -502,7 +502,7 @@ bool BitfieldMan::isFilteredAllBitSet() const {
if(filterEnabled) { if(filterEnabled) {
for(size_t i = 0; i < bitfieldLength; ++i) { for(size_t i = 0; i < bitfieldLength; ++i) {
if((bitfield[i]&filterBitfield[i]) != filterBitfield[i]) { if((bitfield[i]&filterBitfield[i]) != filterBitfield[i]) {
return false; return false;
} }
} }
return true; return true;
@ -681,7 +681,7 @@ uint64_t BitfieldMan::getCompletedLength(bool useFilter) const {
for(size_t i = 0; i < bitfieldLength; ++i) { for(size_t i = 0; i < bitfieldLength; ++i) {
temp[i] = bitfield[i]; temp[i] = bitfield[i];
if(filterEnabled) { if(filterEnabled) {
temp[i] &= filterBitfield[i]; temp[i] &= filterBitfield[i];
} }
} }
} else { } else {

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -67,14 +67,14 @@ private:
template<typename Array> template<typename Array>
bool getMissingIndexRandomly(size_t& index, const Array& bitfield, bool getMissingIndexRandomly(size_t& index, const Array& bitfield,
size_t bitfieldLength) const; size_t bitfieldLength) const;
template<typename Array> template<typename Array>
bool getFirstMissingIndex(size_t& index, const Array& bitfield, size_t bitfieldLength) const; bool getFirstMissingIndex(size_t& index, const Array& bitfield, size_t bitfieldLength) const;
template<typename Array> template<typename Array>
bool getAllMissingIndexes(std::deque<size_t>& indexes, bool getAllMissingIndexes(std::deque<size_t>& indexes,
const Array& bitfield, const Array& bitfield,
size_t bitfieldLength) const; size_t bitfieldLength) const;
bool setBitInternal(unsigned char* bitfield, size_t index, bool on); bool setBitInternal(unsigned char* bitfield, size_t index, bool on);
bool setFilterBit(size_t index); bool setFilterBit(size_t index);
@ -94,7 +94,7 @@ public:
size_t startIndex; size_t startIndex;
size_t endIndex; size_t endIndex;
Range(size_t startIndex = 0, size_t endIndex = 0):startIndex(startIndex), Range(size_t startIndex = 0, size_t endIndex = 0):startIndex(startIndex),
endIndex(endIndex) {} endIndex(endIndex) {}
size_t getSize() const { size_t getSize() const {
return endIndex-startIndex; return endIndex-startIndex;
@ -177,13 +177,13 @@ public:
* affected by filter * affected by filter
*/ */
bool getAllMissingIndexes(unsigned char* misbitfield, size_t mislen, bool getAllMissingIndexes(unsigned char* misbitfield, size_t mislen,
const unsigned char* bitfield, size_t len) const; const unsigned char* bitfield, size_t len) const;
/** /**
* affected by filter * affected by filter
*/ */
bool getAllMissingUnusedIndexes(unsigned char* misbitfield, size_t mislen, bool getAllMissingUnusedIndexes(unsigned char* misbitfield, size_t mislen,
const unsigned char* bitfield, const unsigned char* bitfield,
size_t len) const; size_t len) const;
/** /**
* affected by filter * affected by filter
*/ */

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -51,7 +51,7 @@ void BtAllowedFastMessage::doReceivedAction() {
if(!peer->isFastExtensionEnabled()) { if(!peer->isFastExtensionEnabled()) {
throw DL_ABORT_EX throw DL_ABORT_EX
(StringFormat("%s received while fast extension is disabled", (StringFormat("%s received while fast extension is disabled",
toString().c_str()).str()); toString().c_str()).str());
} }
if(_metadataGetMode) { if(_metadataGetMode) {
return; return;

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -93,7 +93,7 @@ public:
* Processes the repsponse from the tracker. * Processes the repsponse from the tracker.
*/ */
virtual void processAnnounceResponse(const unsigned char* trackerResponse, virtual void processAnnounceResponse(const unsigned char* trackerResponse,
size_t trackerResponseLength) = 0; size_t trackerResponseLength) = 0;
/** /**
* Returns true if no more announce is needed. * Returns true if no more announce is needed.

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -63,7 +63,7 @@ public:
} }
BtBitfieldMessage(const unsigned char* bitfield, BtBitfieldMessage(const unsigned char* bitfield,
size_t bitfieldLength):SimpleBtMessage(ID, NAME) size_t bitfieldLength):SimpleBtMessage(ID, NAME)
{ {
init(); init();
setBitfield(bitfield, bitfieldLength); setBitfield(bitfield, bitfieldLength);

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -47,15 +47,15 @@ private:
size_t numPiece; size_t numPiece;
public: public:
BtBitfieldMessageValidator(const BtBitfieldMessage* message, BtBitfieldMessageValidator(const BtBitfieldMessage* message,
size_t numPiece): size_t numPiece):
message(message), message(message),
numPiece(numPiece) {} numPiece(numPiece) {}
virtual bool validate(Errors& error) { virtual bool validate(Errors& error) {
// TODO // TODO
bittorrent::checkBitfield(message->getBitfield(), bittorrent::checkBitfield(message->getBitfield(),
message->getBitfieldLength(), message->getBitfieldLength(),
numPiece); numPiece);
return true; return true;
} }
}; };

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -50,7 +50,7 @@ BtCheckIntegrityEntry::BtCheckIntegrityEntry(RequestGroup* requestGroup):
BtCheckIntegrityEntry::~BtCheckIntegrityEntry() {} BtCheckIntegrityEntry::~BtCheckIntegrityEntry() {}
void BtCheckIntegrityEntry::onDownloadIncomplete(std::deque<Command*>& commands, void BtCheckIntegrityEntry::onDownloadIncomplete(std::deque<Command*>& commands,
DownloadEngine* e) DownloadEngine* e)
{ {
const SharedHandle<DiskAdaptor>& diskAdaptor = const SharedHandle<DiskAdaptor>& diskAdaptor =
_requestGroup->getPieceStorage()->getDiskAdaptor(); _requestGroup->getPieceStorage()->getDiskAdaptor();
@ -66,7 +66,7 @@ void BtCheckIntegrityEntry::onDownloadIncomplete(std::deque<Command*>& commands,
} }
void BtCheckIntegrityEntry::onDownloadFinished(std::deque<Command*>& commands, void BtCheckIntegrityEntry::onDownloadFinished(std::deque<Command*>& commands,
DownloadEngine* e) DownloadEngine* e)
{ {
// TODO Currently,when all the checksums // TODO Currently,when all the checksums
// are valid, then aira2 goes to seeding mode. Sometimes it is better // are valid, then aira2 goes to seeding mode. Sometimes it is better

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -46,10 +46,10 @@ public:
virtual ~BtCheckIntegrityEntry(); virtual ~BtCheckIntegrityEntry();
virtual void onDownloadFinished(std::deque<Command*>& commands, virtual void onDownloadFinished(std::deque<Command*>& commands,
DownloadEngine* e); DownloadEngine* e);
virtual void onDownloadIncomplete(std::deque<Command*>& commands, virtual void onDownloadIncomplete(std::deque<Command*>& commands,
DownloadEngine* e); DownloadEngine* e);
}; };
typedef SharedHandle<BtCheckIntegrityEntry> BtCheckIntegrityEntryHandle; typedef SharedHandle<BtCheckIntegrityEntry> BtCheckIntegrityEntryHandle;

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -51,7 +51,7 @@
namespace aria2 { namespace aria2 {
BtDependency::BtDependency(const RequestGroupWeakHandle& dependant, BtDependency::BtDependency(const RequestGroupWeakHandle& dependant,
const RequestGroupHandle& dependee): const RequestGroupHandle& dependee):
_dependant(dependant), _dependant(dependant),
_dependee(dependee), _dependee(dependee),
_logger(LogFactory::getInstance()) {} _logger(LogFactory::getInstance()) {}
@ -68,41 +68,41 @@ bool BtDependency::resolve()
context->setDir(_dependant->getDownloadContext()->getDir()); context->setDir(_dependant->getDownloadContext()->getDir());
try { try {
DiskAdaptorHandle diskAdaptor = DiskAdaptorHandle diskAdaptor =
dependee->getPieceStorage()->getDiskAdaptor(); dependee->getPieceStorage()->getDiskAdaptor();
diskAdaptor->openExistingFile(); diskAdaptor->openExistingFile();
std::string content = util::toString(diskAdaptor); std::string content = util::toString(diskAdaptor);
if(dependee->getDownloadContext()->hasAttribute(bittorrent::BITTORRENT)) { if(dependee->getDownloadContext()->hasAttribute(bittorrent::BITTORRENT)) {
const BDE& attrs = const BDE& attrs =
dependee->getDownloadContext()->getAttribute(bittorrent::BITTORRENT); dependee->getDownloadContext()->getAttribute(bittorrent::BITTORRENT);
bittorrent::loadFromMemory bittorrent::loadFromMemory
(bittorrent::metadata2Torrent(content, attrs), context, "default"); (bittorrent::metadata2Torrent(content, attrs), context, "default");
} else { } else {
bittorrent::loadFromMemory bittorrent::loadFromMemory
(content, context, File(dependee->getFirstFilePath()).getBasename()); (content, context, File(dependee->getFirstFilePath()).getBasename());
} }
if(context->getFileEntries().size() != if(context->getFileEntries().size() !=
_dependant->getDownloadContext()->getFileEntries().size()) { _dependant->getDownloadContext()->getFileEntries().size()) {
throw DL_ABORT_EX("The number of file in torrent doesn't match to" throw DL_ABORT_EX("The number of file in torrent doesn't match to"
" the dependent."); " the dependent.");
} }
// Copy file path in _dependant's FileEntries to newly created // Copy file path in _dependant's FileEntries to newly created
// context's FileEntries to endorse the path structure of // context's FileEntries to endorse the path structure of
// _dependant. URIs and singleHostMultiConnection are also copied. // _dependant. URIs and singleHostMultiConnection are also copied.
for(std::vector<SharedHandle<FileEntry> >::const_iterator s = for(std::vector<SharedHandle<FileEntry> >::const_iterator s =
_dependant->getDownloadContext()->getFileEntries().begin(), _dependant->getDownloadContext()->getFileEntries().begin(),
d = context->getFileEntries().begin(); d = context->getFileEntries().begin();
d != context->getFileEntries().end(); ++s, ++d) { d != context->getFileEntries().end(); ++s, ++d) {
(*d)->setPath((*s)->getPath()); (*d)->setPath((*s)->getPath());
(*d)->addUris((*s)->getRemainingUris().begin(), (*d)->addUris((*s)->getRemainingUris().begin(),
(*s)->getRemainingUris().end()); (*s)->getRemainingUris().end());
if(!(*s)->isSingleHostMultiConnectionEnabled()) { if(!(*s)->isSingleHostMultiConnectionEnabled()) {
(*d)->disableSingleHostMultiConnection(); (*d)->disableSingleHostMultiConnection();
} }
} }
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
_logger->error(EX_EXCEPTION_CAUGHT, e); _logger->error(EX_EXCEPTION_CAUGHT, e);
_logger->info("BtDependency for GID#%d failed. Go without Bt.", _logger->info("BtDependency for GID#%d failed. Go without Bt.",
_dependant->getGID()); _dependant->getGID());
return true; return true;
} }
_logger->debug("Dependency resolved for GID#%d", _dependant->getGID()); _logger->debug("Dependency resolved for GID#%d", _dependant->getGID());
@ -113,7 +113,7 @@ bool BtDependency::resolve()
// cut reference here // cut reference here
_dependee.reset(); _dependee.reset();
_logger->debug("BtDependency for GID#%d failed. Go without Bt.", _logger->debug("BtDependency for GID#%d failed. Go without Bt.",
_dependant->getGID()); _dependant->getGID());
return true; return true;
} else { } else {
return false; return false;

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -51,7 +51,7 @@ private:
Logger* _logger; Logger* _logger;
public: public:
BtDependency(const WeakHandle<RequestGroup>& dependant, BtDependency(const WeakHandle<RequestGroup>& dependant,
const SharedHandle<RequestGroup>& dependee); const SharedHandle<RequestGroup>& dependee);
virtual ~BtDependency(); virtual ~BtDependency();

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -99,14 +99,14 @@ std::string BtExtendedMessage::toString() const {
BtExtendedMessageHandle BtExtendedMessageHandle
BtExtendedMessage::create(const SharedHandle<ExtensionMessageFactory>& factory, BtExtendedMessage::create(const SharedHandle<ExtensionMessageFactory>& factory,
const PeerHandle& peer, const PeerHandle& peer,
const unsigned char* data, size_t dataLength) const unsigned char* data, size_t dataLength)
{ {
bittorrent::assertPayloadLengthGreater(1, dataLength, NAME); bittorrent::assertPayloadLengthGreater(1, dataLength, NAME);
bittorrent::assertID(ID, data, NAME); bittorrent::assertID(ID, data, NAME);
assert(!factory.isNull()); assert(!factory.isNull());
ExtensionMessageHandle extmsg = factory->createMessage(data+1, ExtensionMessageHandle extmsg = factory->createMessage(data+1,
dataLength-1); dataLength-1);
BtExtendedMessageHandle message(new BtExtendedMessage(extmsg)); BtExtendedMessageHandle message(new BtExtendedMessage(extmsg));
return message; return message;
} }

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -54,7 +54,7 @@ private:
size_t _msgLength; size_t _msgLength;
public: public:
BtExtendedMessage(const SharedHandle<ExtensionMessage>& extensionMessage = BtExtendedMessage(const SharedHandle<ExtensionMessage>& extensionMessage =
SharedHandle<ExtensionMessage>()); SharedHandle<ExtensionMessage>());
virtual ~BtExtendedMessage(); virtual ~BtExtendedMessage();
@ -63,10 +63,10 @@ public:
static const std::string NAME; static const std::string NAME;
static BtExtendedMessageHandle create static BtExtendedMessageHandle create
(const SharedHandle<ExtensionMessageFactory>& factory, (const SharedHandle<ExtensionMessageFactory>& factory,
const SharedHandle<Peer>& peer, const SharedHandle<Peer>& peer,
const unsigned char* data, const unsigned char* data,
size_t dataLength); size_t dataLength);
virtual void doReceivedAction(); virtual void doReceivedAction();

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -50,7 +50,7 @@ BtFileAllocationEntry::BtFileAllocationEntry(RequestGroup* requestGroup):
BtFileAllocationEntry::~BtFileAllocationEntry() {} BtFileAllocationEntry::~BtFileAllocationEntry() {}
void BtFileAllocationEntry::prepareForNextAction(std::deque<Command*>& commands, void BtFileAllocationEntry::prepareForNextAction(std::deque<Command*>& commands,
DownloadEngine* e) DownloadEngine* e)
{ {
BtSetup().setup(commands, _requestGroup, e, _requestGroup->getOption().get()); BtSetup().setup(commands, _requestGroup, e, _requestGroup->getOption().get());
if(!_requestGroup->downloadFinished()) { if(!_requestGroup->downloadFinished()) {

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -46,7 +46,7 @@ public:
virtual ~BtFileAllocationEntry(); virtual ~BtFileAllocationEntry();
virtual void prepareForNextAction(std::deque<Command*>& commands, virtual void prepareForNextAction(std::deque<Command*>& commands,
DownloadEngine* e); DownloadEngine* e);
}; };
typedef SharedHandle<BtFileAllocationEntry> BtFileAllocationEntryHandle; typedef SharedHandle<BtFileAllocationEntry> BtFileAllocationEntryHandle;

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -53,7 +53,7 @@ BtHandshakeMessage::BtHandshakeMessage():SimpleBtMessage(ID, NAME)
} }
BtHandshakeMessage::BtHandshakeMessage(const unsigned char* infoHash, BtHandshakeMessage::BtHandshakeMessage(const unsigned char* infoHash,
const unsigned char* peerId): const unsigned char* peerId):
SimpleBtMessage(ID, NAME) SimpleBtMessage(ID, NAME)
{ {
init(); init();
@ -106,9 +106,9 @@ size_t BtHandshakeMessage::getMessageLength() {
std::string BtHandshakeMessage::toString() const { std::string BtHandshakeMessage::toString() const {
return strconcat(NAME, " peerId=", return strconcat(NAME, " peerId=",
util::urlencode(peerId, PEER_ID_LENGTH), util::urlencode(peerId, PEER_ID_LENGTH),
", reserved=", ", reserved=",
util::toHex(reserved, RESERVED_LENGTH)); util::toHex(reserved, RESERVED_LENGTH));
} }
bool BtHandshakeMessage::isFastExtensionSupported() const { bool BtHandshakeMessage::isFastExtensionSupported() const {

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -51,7 +51,7 @@ private:
unsigned char infoHash[20]; unsigned char infoHash[20];
public: public:
BtHandshakeMessageValidator(const BtHandshakeMessage* message, BtHandshakeMessageValidator(const BtHandshakeMessage* message,
const unsigned char* infoHash): const unsigned char* infoHash):
message(message) message(message)
{ {
memcpy(this->infoHash, infoHash, sizeof(this->infoHash)); memcpy(this->infoHash, infoHash, sizeof(this->infoHash));
@ -61,18 +61,18 @@ public:
// TODO // TODO
if(message->getPstrlen() != 19) { if(message->getPstrlen() != 19) {
throw DL_ABORT_EX(StringFormat("invalid handshake pstrlen=%u", throw DL_ABORT_EX(StringFormat("invalid handshake pstrlen=%u",
message->getPstrlen()).str()); message->getPstrlen()).str());
} }
if(memcmp(BtHandshakeMessage::BT_PSTR, message->getPstr(), 19) != 0) { if(memcmp(BtHandshakeMessage::BT_PSTR, message->getPstr(), 19) != 0) {
throw DL_ABORT_EX throw DL_ABORT_EX
(StringFormat("invalid handshake pstr=%s", (StringFormat("invalid handshake pstr=%s",
util::urlencode(message->getPstr(), 19).c_str()).str()); util::urlencode(message->getPstr(), 19).c_str()).str());
} }
if(memcmp(infoHash, message->getInfoHash(), 20) != 0) { if(memcmp(infoHash, message->getInfoHash(), 20) != 0) {
throw DL_ABORT_EX throw DL_ABORT_EX
(StringFormat("invalid handshake info hash: expected:%s, actual:%s", (StringFormat("invalid handshake info hash: expected:%s, actual:%s",
util::toHex(infoHash, 20).c_str(), util::toHex(infoHash, 20).c_str(),
util::toHex(message->getInfoHash(), 20).c_str()).str()); util::toHex(message->getInfoHash(), 20).c_str()).str());
} }
return true; return true;
} }

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -54,13 +54,13 @@ void BtHaveAllMessage::doReceivedAction()
if(!peer->isFastExtensionEnabled()) { if(!peer->isFastExtensionEnabled()) {
throw DL_ABORT_EX throw DL_ABORT_EX
(StringFormat("%s received while fast extension is disabled", (StringFormat("%s received while fast extension is disabled",
toString().c_str()).str()); toString().c_str()).str());
} }
if(_metadataGetMode) { if(_metadataGetMode) {
return; return;
} }
pieceStorage->subtractPieceStats(peer->getBitfield(), pieceStorage->subtractPieceStats(peer->getBitfield(),
peer->getBitfieldLength()); peer->getBitfieldLength());
peer->setAllBitfield(); peer->setAllBitfield();
pieceStorage->addPieceStats(peer->getBitfield(), peer->getBitfieldLength()); pieceStorage->addPieceStats(peer->getBitfield(), peer->getBitfieldLength());
if(peer->isSeeder() && pieceStorage->downloadFinished()) { if(peer->isSeeder() && pieceStorage->downloadFinished()) {

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -52,7 +52,7 @@ void BtHaveNoneMessage::doReceivedAction()
if(!peer->isFastExtensionEnabled()) { if(!peer->isFastExtensionEnabled()) {
throw DL_ABORT_EX throw DL_ABORT_EX
(StringFormat("%s received while fast extension is disabled", (StringFormat("%s received while fast extension is disabled",
toString().c_str()).str()); toString().c_str()).str());
} }
} }

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -56,7 +56,7 @@ BtLeecherStateChoke::PeerEntry::PeerEntry
_peer(peer), _downloadSpeed(peer->calculateDownloadSpeed(now)), _peer(peer), _downloadSpeed(peer->calculateDownloadSpeed(now)),
// peer must be interested to us and sent block in the last 30 seconds // peer must be interested to us and sent block in the last 30 seconds
_regularUnchoker(peer->peerInterested() && _regularUnchoker(peer->peerInterested() &&
!peer->getLastDownloadUpdate().elapsed(30)) {} !peer->getLastDownloadUpdate().elapsed(30)) {}
const SharedHandle<Peer>& BtLeecherStateChoke::PeerEntry::getPeer() const const SharedHandle<Peer>& BtLeecherStateChoke::PeerEntry::getPeer() const
{ {
@ -123,14 +123,14 @@ void BtLeecherStateChoke::plannedOptimisticUnchoke
(std::deque<PeerEntry>& peerEntries) (std::deque<PeerEntry>& peerEntries)
{ {
std::for_each(peerEntries.begin(), peerEntries.end(), std::for_each(peerEntries.begin(), peerEntries.end(),
std::mem_fun_ref(&PeerEntry::disableOptUnchoking)); std::mem_fun_ref(&PeerEntry::disableOptUnchoking));
std::deque<PeerEntry>::iterator i = std::deque<PeerEntry>::iterator i =
std::partition(peerEntries.begin(), peerEntries.end(), std::partition(peerEntries.begin(), peerEntries.end(),
PeerFilter(true, true)); PeerFilter(true, true));
if(i != peerEntries.begin()) { if(i != peerEntries.begin()) {
std::random_shuffle(peerEntries.begin(), i, std::random_shuffle(peerEntries.begin(), i,
*(SimpleRandomizer::getInstance().get())); *(SimpleRandomizer::getInstance().get()));
(*peerEntries.begin()).enableOptUnchoking(); (*peerEntries.begin()).enableOptUnchoking();
_logger->info("POU: %s", (*peerEntries.begin()).getPeer()->ipaddr.c_str()); _logger->info("POU: %s", (*peerEntries.begin()).getPeer()->ipaddr.c_str());
} }
@ -140,7 +140,7 @@ void BtLeecherStateChoke::regularUnchoke(std::deque<PeerEntry>& peerEntries)
{ {
std::deque<PeerEntry>::iterator rest = std::deque<PeerEntry>::iterator rest =
std::partition(peerEntries.begin(), peerEntries.end(), std::partition(peerEntries.begin(), peerEntries.end(),
std::mem_fun_ref(&PeerEntry::isRegularUnchoker)); std::mem_fun_ref(&PeerEntry::isRegularUnchoker));
struct timeval now; struct timeval now;
gettimeofday(&now, 0); gettimeofday(&now, 0);
@ -155,8 +155,8 @@ void BtLeecherStateChoke::regularUnchoke(std::deque<PeerEntry>& peerEntries)
for(;peerIter != rest && count; ++peerIter, --count) { for(;peerIter != rest && count; ++peerIter, --count) {
(*peerIter).disableChokingRequired(); (*peerIter).disableChokingRequired();
_logger->info("RU: %s, dlspd=%u", _logger->info("RU: %s, dlspd=%u",
(*peerIter).getPeer()->ipaddr.c_str(), (*peerIter).getPeer()->ipaddr.c_str(),
(*peerIter).getDownloadSpeed()); (*peerIter).getDownloadSpeed());
if((*peerIter).getPeer()->optUnchoking()) { if((*peerIter).getPeer()->optUnchoking()) {
fastOptUnchoker = true; fastOptUnchoker = true;
(*peerIter).disableOptUnchoking(); (*peerIter).disableOptUnchoking();
@ -164,16 +164,16 @@ void BtLeecherStateChoke::regularUnchoke(std::deque<PeerEntry>& peerEntries)
} }
if(fastOptUnchoker) { if(fastOptUnchoker) {
std::random_shuffle(peerIter, peerEntries.end(), std::random_shuffle(peerIter, peerEntries.end(),
*(SimpleRandomizer::getInstance().get())); *(SimpleRandomizer::getInstance().get()));
for(std::deque<PeerEntry>::iterator i = peerIter; i != peerEntries.end(); for(std::deque<PeerEntry>::iterator i = peerIter; i != peerEntries.end();
++i) { ++i) {
if((*i).getPeer()->peerInterested()) { if((*i).getPeer()->peerInterested()) {
(*i).enableOptUnchoking(); (*i).enableOptUnchoking();
_logger->info("OU: %s", (*i).getPeer()->ipaddr.c_str()); _logger->info("OU: %s", (*i).getPeer()->ipaddr.c_str());
break; break;
} else { } else {
(*i).disableChokingRequired(); (*i).disableChokingRequired();
_logger->info("OU: %s", (*i).getPeer()->ipaddr.c_str()); _logger->info("OU: %s", (*i).getPeer()->ipaddr.c_str());
} }
} }
} }
@ -203,15 +203,15 @@ BtLeecherStateChoke::executeChoke(const std::deque<SharedHandle<Peer> >& peerSet
std::deque<PeerEntry> peerEntries; std::deque<PeerEntry> peerEntries;
std::transform(peerSet.begin(), peerSet.end(), std::transform(peerSet.begin(), peerSet.end(),
std::back_inserter(peerEntries), std::back_inserter(peerEntries),
BtLeecherStateChokeGenPeerEntry()); BtLeecherStateChokeGenPeerEntry());
peerEntries.erase(std::remove_if(peerEntries.begin(), peerEntries.end(), peerEntries.erase(std::remove_if(peerEntries.begin(), peerEntries.end(),
std::mem_fun_ref(&PeerEntry::isSnubbing)), std::mem_fun_ref(&PeerEntry::isSnubbing)),
peerEntries.end()); peerEntries.end());
std::for_each(peerEntries.begin(), peerEntries.end(), std::for_each(peerEntries.begin(), peerEntries.end(),
std::mem_fun_ref(&PeerEntry::enableChokingRequired)); std::mem_fun_ref(&PeerEntry::enableChokingRequired));
// planned optimistic unchoke // planned optimistic unchoke
if(_round == 0) { if(_round == 0) {

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -57,7 +57,7 @@ public:
virtual SharedHandle<BtHandshakeMessage> virtual SharedHandle<BtHandshakeMessage>
createHandshakeMessage(const unsigned char* infoHash, createHandshakeMessage(const unsigned char* infoHash,
const unsigned char* peerId) = 0; const unsigned char* peerId) = 0;
virtual SharedHandle<BtMessage> virtual SharedHandle<BtMessage>
createRequestMessage(const SharedHandle<Piece>& piece, size_t blockIndex) = 0; createRequestMessage(const SharedHandle<Piece>& piece, size_t blockIndex) = 0;

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -81,8 +81,8 @@ void BtPieceMessage::doReceivedAction() {
return; return;
} }
RequestSlot slot = dispatcher->getOutstandingRequest(index, RequestSlot slot = dispatcher->getOutstandingRequest(index,
begin, begin,
blockLength); blockLength);
peer->updateDownloadLength(blockLength); peer->updateDownloadLength(blockLength);
if(!RequestSlot::isNull(slot)) { if(!RequestSlot::isNull(slot)) {
peer->snubbing(false); peer->snubbing(false);
@ -90,24 +90,24 @@ void BtPieceMessage::doReceivedAction() {
PieceHandle piece = pieceStorage->getPiece(index); PieceHandle piece = pieceStorage->getPiece(index);
off_t offset = (off_t)index*_downloadContext->getPieceLength()+begin; off_t offset = (off_t)index*_downloadContext->getPieceLength()+begin;
logger->debug(MSG_PIECE_RECEIVED, logger->debug(MSG_PIECE_RECEIVED,
cuid, index, begin, blockLength, offset, slot.getBlockIndex()); cuid, index, begin, blockLength, offset, slot.getBlockIndex());
pieceStorage->getDiskAdaptor()->writeData(block, blockLength, offset); pieceStorage->getDiskAdaptor()->writeData(block, blockLength, offset);
piece->completeBlock(slot.getBlockIndex()); piece->completeBlock(slot.getBlockIndex());
logger->debug(MSG_PIECE_BITFIELD, cuid, logger->debug(MSG_PIECE_BITFIELD, cuid,
util::toHex(piece->getBitfield(), util::toHex(piece->getBitfield(),
piece->getBitfieldLength()).c_str()); piece->getBitfieldLength()).c_str());
piece->updateHash(begin, block, blockLength); piece->updateHash(begin, block, blockLength);
dispatcher->removeOutstandingRequest(slot); dispatcher->removeOutstandingRequest(slot);
if(piece->pieceComplete()) { if(piece->pieceComplete()) {
if(checkPieceHash(piece)) { if(checkPieceHash(piece)) {
onNewPiece(piece); onNewPiece(piece);
} else { } else {
onWrongPiece(piece); onWrongPiece(piece);
} }
} }
} else { } else {
logger->debug("CUID#%d - RequestSlot not found, index=%d, begin=%d", logger->debug("CUID#%d - RequestSlot not found, index=%d, begin=%d",
cuid, index, begin); cuid, index, begin);
} }
} }
@ -124,7 +124,7 @@ const unsigned char* BtPieceMessage::getMessageHeader() {
*/ */
msgHeader = new unsigned char[MESSAGE_HEADER_LENGTH]; msgHeader = new unsigned char[MESSAGE_HEADER_LENGTH];
bittorrent::createPeerMessageString(msgHeader, MESSAGE_HEADER_LENGTH, bittorrent::createPeerMessageString(msgHeader, MESSAGE_HEADER_LENGTH,
9+blockLength, ID); 9+blockLength, ID);
bittorrent::setIntParam(&msgHeader[5], index); bittorrent::setIntParam(&msgHeader[5], index);
bittorrent::setIntParam(&msgHeader[9], begin); bittorrent::setIntParam(&msgHeader[9], begin);
} }
@ -141,16 +141,16 @@ void BtPieceMessage::send() {
} }
if(!sendingInProgress) { if(!sendingInProgress) {
logger->info(MSG_SEND_PEER_MESSAGE, logger->info(MSG_SEND_PEER_MESSAGE,
cuid, peer->ipaddr.c_str(), peer->port, cuid, peer->ipaddr.c_str(), peer->port,
toString().c_str()); toString().c_str());
getMessageHeader(); getMessageHeader();
peerConnection->sendMessage(msgHeader, getMessageHeaderLength()); peerConnection->sendMessage(msgHeader, getMessageHeaderLength());
off_t pieceDataOffset = off_t pieceDataOffset =
(off_t)index*_downloadContext->getPieceLength()+begin; (off_t)index*_downloadContext->getPieceLength()+begin;
size_t writtenLength = sendPieceData(pieceDataOffset, blockLength); size_t writtenLength = sendPieceData(pieceDataOffset, blockLength);
logger->debug("msglength = %lu bytes", logger->debug("msglength = %lu bytes",
static_cast<unsigned long>(getMessageHeaderLength()+ static_cast<unsigned long>(getMessageHeaderLength()+
blockLength)); blockLength));
peer->updateUploadLength(writtenLength); peer->updateUploadLength(writtenLength);
} else { } else {
ssize_t writtenLength = peerConnection->sendPendingData(); ssize_t writtenLength = peerConnection->sendPendingData();
@ -172,13 +172,13 @@ size_t BtPieceMessage::sendPieceData(off_t offset, size_t length) const {
std::string BtPieceMessage::toString() const { std::string BtPieceMessage::toString() const {
return strconcat(NAME, " index=", util::itos(index), ", begin=", return strconcat(NAME, " index=", util::itos(index), ", begin=",
util::itos(begin), ", length=", util::itos(blockLength)); util::itos(begin), ", length=", util::itos(blockLength));
} }
bool BtPieceMessage::checkPieceHash(const PieceHandle& piece) { bool BtPieceMessage::checkPieceHash(const PieceHandle& piece) {
if(piece->isHashCalculated()) { if(piece->isHashCalculated()) {
logger->debug("Hash is available!! index=%lu", logger->debug("Hash is available!! index=%lu",
static_cast<unsigned long>(piece->getIndex())); static_cast<unsigned long>(piece->getIndex()));
return return
piece->getHashString()==_downloadContext->getPieceHash(piece->getIndex()); piece->getHashString()==_downloadContext->getPieceHash(piece->getIndex());
} else { } else {
@ -224,15 +224,15 @@ void BtPieceMessage::onChokingEvent(const BtChokingEvent& event)
!sendingInProgress && !sendingInProgress &&
!peer->isInAmAllowedIndexSet(index)) { !peer->isInAmAllowedIndexSet(index)) {
logger->debug(MSG_REJECT_PIECE_CHOKED, logger->debug(MSG_REJECT_PIECE_CHOKED,
cuid, cuid,
index, index,
begin, begin,
blockLength); blockLength);
if(peer->isFastExtensionEnabled()) { if(peer->isFastExtensionEnabled()) {
BtMessageHandle rej = messageFactory->createRejectMessage(index, BtMessageHandle rej = messageFactory->createRejectMessage(index,
begin, begin,
blockLength); blockLength);
dispatcher->addMessageToQueue(rej); dispatcher->addMessageToQueue(rej);
} }
invalidate = true; invalidate = true;
@ -248,11 +248,11 @@ void BtPieceMessage::onCancelSendingPieceEvent
begin == event.getBegin() && begin == event.getBegin() &&
blockLength == event.getLength()) { blockLength == event.getLength()) {
logger->debug(MSG_REJECT_PIECE_CANCEL, logger->debug(MSG_REJECT_PIECE_CANCEL,
cuid, index, begin, blockLength); cuid, index, begin, blockLength);
if(peer->isFastExtensionEnabled()) { if(peer->isFastExtensionEnabled()) {
BtMessageHandle rej = messageFactory->createRejectMessage(index, BtMessageHandle rej = messageFactory->createRejectMessage(index,
begin, begin,
blockLength); blockLength);
dispatcher->addMessageToQueue(rej); dispatcher->addMessageToQueue(rej);
} }
invalidate = true; invalidate = true;

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -48,8 +48,8 @@ private:
size_t pieceLength; size_t pieceLength;
public: public:
BtPieceMessageValidator(const BtPieceMessage* message, BtPieceMessageValidator(const BtPieceMessage* message,
size_t numPiece, size_t numPiece,
size_t pieceLength): size_t pieceLength):
message(message), message(message),
numPiece(numPiece), numPiece(numPiece),
pieceLength(pieceLength) {} pieceLength(pieceLength) {}

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the

View File

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* In addition, as a special exception, the copyright holders give * In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the * permission to link the code of portions of this program with the
@ -67,7 +67,7 @@ void BtPostDownloadHandler::getNextRequestGroups
RequestGroup* requestGroup) RequestGroup* requestGroup)
{ {
_logger->debug("Generating RequestGroups for Torrent file %s", _logger->debug("Generating RequestGroups for Torrent file %s",
requestGroup->getFirstFilePath().c_str()); requestGroup->getFirstFilePath().c_str());
std::string content; std::string content;
try { try {
requestGroup->getPieceStorage()->getDiskAdaptor()->openExistingFile(); requestGroup->getPieceStorage()->getDiskAdaptor()->openExistingFile();
@ -79,8 +79,8 @@ void BtPostDownloadHandler::getNextRequestGroups
} }
std::deque<SharedHandle<RequestGroup> > newRgs; std::deque<SharedHandle<RequestGroup> > newRgs;
createRequestGroupForBitTorrent(newRgs, requestGroup->getOption(), createRequestGroupForBitTorrent(newRgs, requestGroup->getOption(),
std::deque<std::string>(), std::deque<std::string>(),
content); content);
requestGroup->followedBy(newRgs.begin(), newRgs.end()); requestGroup->followedBy(newRgs.begin(), newRgs.end());
groups.insert(groups.end(), newRgs.begin(), newRgs.end()); groups.insert(groups.end(), newRgs.begin(), newRgs.end());
} }

Some files were not shown because too many files have changed in this diff Show More