Revert to existing "proper" coding style

The rule is simple: don't try to change the coding style of the
existing codebase.
pull/235/merge
Tatsuhiro Tsujikawa 2014-06-03 23:22:18 +09:00
parent 83f4bced07
commit adeead6f03
9 changed files with 235 additions and 236 deletions

View File

@ -74,15 +74,15 @@
namespace aria2 { namespace aria2 {
AbstractCommand::AbstractCommand( AbstractCommand::AbstractCommand
cuid_t cuid, (cuid_t cuid,
const std::shared_ptr<Request>& req, const std::shared_ptr<Request>& req,
const std::shared_ptr<FileEntry>& fileEntry, const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup, RequestGroup* requestGroup,
DownloadEngine* e, DownloadEngine* e,
const std::shared_ptr<SocketCore>& s, const std::shared_ptr<SocketCore>& s,
const std::shared_ptr<SocketRecvBuffer>& socketRecvBuffer, const std::shared_ptr<SocketRecvBuffer>& socketRecvBuffer,
bool incNumConnection) bool incNumConnection)
: Command(cuid), : Command(cuid),
req_(req), req_(req),
fileEntry_(fileEntry), fileEntry_(fileEntry),
@ -137,9 +137,9 @@ AbstractCommand::useFasterRequest(const std::shared_ptr<Request>& fasterRequest)
// Cancel current Request object and use faster one. // Cancel current Request object and use faster one.
fileEntry_->removeRequest(req_); fileEntry_->removeRequest(req_);
e_->setNoWait(true); e_->setNoWait(true);
e_->addCommand( e_->addCommand
InitiateConnectionCommandFactory::createInitiateConnectionCommand( (InitiateConnectionCommandFactory::createInitiateConnectionCommand
getCuid(), fasterRequest, fileEntry_, requestGroup_, e_)); (getCuid(), fasterRequest, fileEntry_, requestGroup_, e_));
} }
bool AbstractCommand::shouldProcess() const bool AbstractCommand::shouldProcess() const
@ -243,8 +243,8 @@ bool AbstractCommand::execute()
if (getOption()->getAsBool(PREF_SELECT_LEAST_USED_HOST)) { if (getOption()->getAsBool(PREF_SELECT_LEAST_USED_HOST)) {
getDownloadEngine()->getRequestGroupMan()->getUsedHosts(usedHosts); getDownloadEngine()->getRequestGroupMan()->getUsedHosts(usedHosts);
} }
auto fasterRequest = fileEntry_->findFasterRequest( auto fasterRequest = fileEntry_->findFasterRequest
req_, usedHosts, e_->getRequestGroupMan()->getServerStatMan()); (req_, usedHosts, e_->getRequestGroupMan()->getServerStatMan());
if (fasterRequest) { if (fasterRequest) {
useFasterRequest(fasterRequest); useFasterRequest(fasterRequest);
return true; return true;
@ -296,8 +296,8 @@ bool AbstractCommand::execute()
size_t minSplitSize = calculateMinSplitSize(); size_t minSplitSize = calculateMinSplitSize();
size_t maxSegments = req_->getMaxPipelinedRequest(); size_t maxSegments = req_->getMaxPipelinedRequest();
if (segments_.size() < maxSegments) { if (segments_.size() < maxSegments) {
sm->getSegment( sm->getSegment
segments_, getCuid(), minSplitSize, fileEntry_, maxSegments); (segments_, getCuid(), minSplitSize, fileEntry_, maxSegments);
} }
if (segments_.empty()) { if (segments_.empty()) {
return prepareForRetry(0); return prepareForRetry(0);
@ -308,14 +308,14 @@ bool AbstractCommand::execute()
} }
if (errorEventEnabled()) { if (errorEventEnabled()) {
throw DL_RETRY_EX( throw DL_RETRY_EX
fmt(MSG_NETWORK_PROBLEM, socket_->getSocketError().c_str())); (fmt(MSG_NETWORK_PROBLEM, socket_->getSocketError().c_str()));
} }
if (checkPoint_.difference(global::wallclock()) >= timeout_) { if (checkPoint_.difference(global::wallclock()) >= timeout_) {
// timeout triggers ServerStat error state. // timeout triggers ServerStat error state.
auto ss = e_->getRequestGroupMan()->getOrCreateServerStat( auto ss = e_->getRequestGroupMan()->getOrCreateServerStat
req_->getHost(), req_->getProtocol()); (req_->getHost(), req_->getProtocol());
ss->setError(); ss->setError();
// When DNS query was timeout, req_->getConnectedAddr() is // When DNS query was timeout, req_->getConnectedAddr() is
// empty. // empty.
@ -345,9 +345,9 @@ bool AbstractCommand::execute()
catch (DlAbortEx& err) { catch (DlAbortEx& err) {
requestGroup_->setLastErrorCode(err.getErrorCode()); requestGroup_->setLastErrorCode(err.getErrorCode());
if (req_) { if (req_) {
A2_LOG_ERROR_EX( A2_LOG_ERROR_EX
fmt(MSG_DOWNLOAD_ABORTED, getCuid(), req_->getUri().c_str()), (fmt(MSG_DOWNLOAD_ABORTED, getCuid(), req_->getUri().c_str()),
DL_ABORT_EX2(fmt("URI=%s", req_->getCurrentUri().c_str()), err)); DL_ABORT_EX2(fmt("URI=%s", req_->getCurrentUri().c_str()), err));
fileEntry_->addURIResult(req_->getUri(), err.getErrorCode()); fileEntry_->addURIResult(req_->getUri(), err.getErrorCode());
if (err.getErrorCode() == error_code::CANNOT_RESUME) { if (err.getErrorCode() == error_code::CANNOT_RESUME) {
requestGroup_->increaseResumeFailureCount(); requestGroup_->increaseResumeFailureCount();
@ -362,9 +362,9 @@ bool AbstractCommand::execute()
} }
catch (DlRetryEx& err) { catch (DlRetryEx& err) {
assert(req_); assert(req_);
A2_LOG_INFO_EX( A2_LOG_INFO_EX
fmt(MSG_RESTARTING_DOWNLOAD, getCuid(), req_->getUri().c_str()), (fmt(MSG_RESTARTING_DOWNLOAD, getCuid(), req_->getUri().c_str()),
DL_RETRY_EX2(fmt("URI=%s", req_->getCurrentUri().c_str()), err)); DL_RETRY_EX2(fmt("URI=%s", req_->getCurrentUri().c_str()), err));
req_->addTryCount(); req_->addTryCount();
req_->resetRedirectCount(); req_->resetRedirectCount();
req_->resetUri(); req_->resetUri();
@ -373,8 +373,8 @@ bool AbstractCommand::execute()
bool isAbort = maxTries != 0 && req_->getTryCount() >= maxTries; bool isAbort = maxTries != 0 && req_->getTryCount() >= maxTries;
if (isAbort) { if (isAbort) {
A2_LOG_INFO(fmt(MSG_MAX_TRY, getCuid(), req_->getTryCount())); A2_LOG_INFO(fmt(MSG_MAX_TRY, getCuid(), req_->getTryCount()));
A2_LOG_ERROR_EX( A2_LOG_ERROR_EX
fmt(MSG_DOWNLOAD_ABORTED, getCuid(), req_->getUri().c_str()), err); (fmt(MSG_DOWNLOAD_ABORTED, getCuid(), req_->getUri().c_str()), err);
fileEntry_->addURIResult(req_->getUri(), err.getErrorCode()); fileEntry_->addURIResult(req_->getUri(), err.getErrorCode());
requestGroup_->setLastErrorCode(err.getErrorCode()); requestGroup_->setLastErrorCode(err.getErrorCode());
if (err.getErrorCode() == error_code::CANNOT_RESUME) { if (err.getErrorCode() == error_code::CANNOT_RESUME) {
@ -393,9 +393,9 @@ bool AbstractCommand::execute()
catch (DownloadFailureException& err) { catch (DownloadFailureException& err) {
requestGroup_->setLastErrorCode(err.getErrorCode()); requestGroup_->setLastErrorCode(err.getErrorCode());
if (req_) { if (req_) {
A2_LOG_ERROR_EX( A2_LOG_ERROR_EX
fmt(MSG_DOWNLOAD_ABORTED, getCuid(), req_->getUri().c_str()), (fmt(MSG_DOWNLOAD_ABORTED, getCuid(), req_->getUri().c_str()),
DL_ABORT_EX2(fmt("URI=%s", req_->getCurrentUri().c_str()), err)); DL_ABORT_EX2(fmt("URI=%s", req_->getCurrentUri().c_str()), err));
fileEntry_->addURIResult(req_->getUri(), err.getErrorCode()); fileEntry_->addURIResult(req_->getUri(), err.getErrorCode());
} else { } else {
A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, err); A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, err);
@ -421,8 +421,8 @@ void AbstractCommand::tryReserved()
return; return;
} }
} }
A2_LOG_DEBUG( A2_LOG_DEBUG
fmt("CUID#%" PRId64 " - Trying reserved/pooled request.", getCuid())); (fmt("CUID#%" PRId64 " - Trying reserved/pooled request.", getCuid()));
std::vector<std::unique_ptr<Command>> commands; std::vector<std::unique_ptr<Command>> commands;
requestGroup_->createNextCommand(commands, e_, 1); requestGroup_->createNextCommand(commands, e_, 1);
e_->setNoWait(true); e_->setNoWait(true);
@ -603,8 +603,8 @@ AbstractCommand::setWriteCheckSocket(const std::shared_ptr<SocketCore>& socket)
writeCheckTarget_ = socket; writeCheckTarget_ = socket;
} }
void AbstractCommand::setWriteCheckSocketIf( void AbstractCommand::setWriteCheckSocketIf
const std::shared_ptr<SocketCore>& socket, bool pred) (const std::shared_ptr<SocketCore>& socket, bool pred)
{ {
if (pred) { if (pred) {
setWriteCheckSocket(socket); setWriteCheckSocket(socket);
@ -653,8 +653,8 @@ std::string getProxyOptionFor(PrefPtr proxyPref,
{ {
std::string uri = makeProxyUri(proxyPref, proxyUser, proxyPasswd, option); std::string uri = makeProxyUri(proxyPref, proxyUser, proxyPasswd, option);
if (uri.empty()) { if (uri.empty()) {
return makeProxyUri( return makeProxyUri
PREF_ALL_PROXY, PREF_ALL_PROXY_USER, PREF_ALL_PROXY_PASSWD, option); (PREF_ALL_PROXY, PREF_ALL_PROXY_USER, PREF_ALL_PROXY_PASSWD, option);
} }
return uri; return uri;
@ -666,8 +666,8 @@ std::string getProxyOptionFor(PrefPtr proxyPref,
std::string getProxyUri(const std::string& protocol, const Option* option) std::string getProxyUri(const std::string& protocol, const Option* option)
{ {
if (protocol == "http") { if (protocol == "http") {
return getProxyOptionFor( return getProxyOptionFor
PREF_HTTP_PROXY, PREF_HTTP_PROXY_USER, PREF_HTTP_PROXY_PASSWD, option); (PREF_HTTP_PROXY, PREF_HTTP_PROXY_USER, PREF_HTTP_PROXY_PASSWD, option);
} }
if (protocol == "https") { if (protocol == "https") {
@ -678,8 +678,8 @@ std::string getProxyUri(const std::string& protocol, const Option* option)
} }
if (protocol == "ftp") { if (protocol == "ftp") {
return getProxyOptionFor( return getProxyOptionFor
PREF_FTP_PROXY, PREF_FTP_PROXY_USER, PREF_FTP_PROXY_PASSWD, option); (PREF_FTP_PROXY, PREF_FTP_PROXY_USER, PREF_FTP_PROXY_PASSWD, option);
} }
return A2STR::NIL; return A2STR::NIL;
@ -700,8 +700,8 @@ namespace {
bool inNoProxy(const std::shared_ptr<Request>& req, const std::string& noProxy) bool inNoProxy(const std::shared_ptr<Request>& req, const std::string& noProxy)
{ {
std::vector<Scip> entries; std::vector<Scip> entries;
util::splitIter( util::splitIter
noProxy.begin(), noProxy.end(), std::back_inserter(entries), ',', true); (noProxy.begin(), noProxy.end(), std::back_inserter(entries), ',', true);
if (entries.empty()) { if (entries.empty()) {
return false; return false;
} }
@ -751,8 +751,8 @@ std::shared_ptr<Request> AbstractCommand::createProxyRequest() const
A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Using proxy", getCuid())); A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Using proxy", getCuid()));
} }
else { else {
A2_LOG_DEBUG( A2_LOG_DEBUG
fmt("CUID#%" PRId64 " - Failed to parse proxy string", getCuid())); (fmt("CUID#%" PRId64 " - Failed to parse proxy string", getCuid()));
proxyRequest.reset(); proxyRequest.reset();
} }
} }
@ -832,21 +832,21 @@ std::string AbstractCommand::resolveHostname(std::vector<std::string>& addrs,
return ipaddr; return ipaddr;
} }
void AbstractCommand::prepareForNextAction( void AbstractCommand::prepareForNextAction
std::unique_ptr<CheckIntegrityEntry> checkEntry) (std::unique_ptr<CheckIntegrityEntry> checkEntry)
{ {
std::vector<std::unique_ptr<Command>> commands; std::vector<std::unique_ptr<Command>> commands;
requestGroup_->processCheckIntegrityEntry( requestGroup_->processCheckIntegrityEntry
commands, std::move(checkEntry), e_); (commands, std::move(checkEntry), e_);
e_->addCommand(std::move(commands)); e_->addCommand(std::move(commands));
e_->setNoWait(true); e_->setNoWait(true);
} }
bool AbstractCommand::checkIfConnectionEstablished( bool AbstractCommand::checkIfConnectionEstablished
const std::shared_ptr<SocketCore>& socket, (const std::shared_ptr<SocketCore>& socket,
const std::string& connectedHostname, const std::string& connectedHostname,
const std::string& connectedAddr, const std::string& connectedAddr,
uint16_t connectedPort) uint16_t connectedPort)
{ {
std::string error = socket->getSocketError(); std::string error = socket->getSocketError();
if (error.empty()) { if (error.empty()) {
@ -872,9 +872,9 @@ bool AbstractCommand::checkIfConnectionEstablished(
connectedAddr.c_str(), connectedAddr.c_str(),
connectedPort)); connectedPort));
e_->setNoWait(true); e_->setNoWait(true);
e_->addCommand( e_->addCommand
InitiateConnectionCommandFactory::createInitiateConnectionCommand( (InitiateConnectionCommandFactory::createInitiateConnectionCommand
getCuid(), req_, fileEntry_, requestGroup_, e_)); (getCuid(), req_, fileEntry_, requestGroup_, e_));
return false; return false;
} }

View File

@ -672,9 +672,9 @@ bool DownloadEngine::validateToken(const std::string& token)
std::deque<double> mm; std::deque<double> mm;
for (auto i = 0; i < 10; ++i) { for (auto i = 0; i < 10; ++i) {
auto c = std::clock(); auto c = std::clock();
tokenExpected_ = make_unique<HMACResult>( tokenExpected_ = make_unique<HMACResult>
PBKDF2(tokenHMAC_.get(), option_->get(PREF_RPC_SECRET), (PBKDF2(tokenHMAC_.get(), option_->get(PREF_RPC_SECRET),
tokenIterations_)); tokenIterations_));
mm.push_back((std::clock() - c) / (double)CLOCKS_PER_SEC); mm.push_back((std::clock() - c) / (double)CLOCKS_PER_SEC);
} }
std::sort(mm.begin(), mm.end()); std::sort(mm.begin(), mm.end());
@ -698,9 +698,9 @@ bool DownloadEngine::validateToken(const std::string& token)
tokenIterations_ *= kTokenTimeSweetspot / duration; tokenIterations_ *= kTokenTimeSweetspot / duration;
auto c = std::clock(); auto c = std::clock();
tokenExpected_ = make_unique<HMACResult>( tokenExpected_ = make_unique<HMACResult>
PBKDF2(tokenHMAC_.get(), option_->get(PREF_RPC_SECRET), (PBKDF2(tokenHMAC_.get(), option_->get(PREF_RPC_SECRET),
tokenIterations_)); tokenIterations_));
duration = (std::clock() - c) / (double)CLOCKS_PER_SEC; duration = (std::clock() - c) / (double)CLOCKS_PER_SEC;
A2_LOG_INFO(fmt("Took us %.4f secs to perform PBKDF2 with %zu iterations", A2_LOG_INFO(fmt("Took us %.4f secs to perform PBKDF2 with %zu iterations",
duration, tokenIterations_)); duration, tokenIterations_));

View File

@ -93,13 +93,13 @@ bool HttpDownloadCommand::prepareForNextSegment()
if (getRequest()->isPipeliningEnabled() || if (getRequest()->isPipeliningEnabled() ||
(getRequest()->isKeepAliveEnabled() && (getRequest()->isKeepAliveEnabled() &&
( (
// Make sure that all filters are finished to pool socket // Make sure that all filters are finished to pool socket
(!util::endsWith(streamFilterName, SinkStreamFilter::NAME) && (!util::endsWith(streamFilterName, SinkStreamFilter::NAME) &&
getStreamFilter()->finished()) || getStreamFilter()->finished()) ||
getRequestEndOffset() == getRequestEndOffset() ==
getFileEntry()->gtoloff(getSegments().front()->getPositionToWrite()) getFileEntry()->gtoloff(getSegments().front()->getPositionToWrite())
) )
) )
) { ) {
// TODO What if server sends EOF when non-SinkStreamFilter is // TODO What if server sends EOF when non-SinkStreamFilter is
// used and server didn't send Connection: close? We end up to // used and server didn't send Connection: close? We end up to
@ -120,9 +120,9 @@ bool HttpDownloadCommand::prepareForNextSegment()
!downloadFinished) { !downloadFinished) {
const std::shared_ptr<Segment>& segment = getSegments().front(); const std::shared_ptr<Segment>& segment = getSegments().front();
int64_t lastOffset =getFileEntry()->gtoloff( int64_t lastOffset =getFileEntry()->gtoloff
std::min(segment->getPosition()+segment->getLength(), (std::min(segment->getPosition()+segment->getLength(),
getFileEntry()->getLastOffset())); getFileEntry()->getLastOffset()));
auto range = httpResponse_->getHttpHeader()->getRange(); auto range = httpResponse_->getHttpHeader()->getRange();
if (lastOffset == range.endByte + 1) { if (lastOffset == range.endByte + 1) {
return prepareForRetry(0); return prepareForRetry(0);

View File

@ -118,8 +118,8 @@ void HttpResponse::validateResponse() const
std::string HttpResponse::determineFilename() const std::string HttpResponse::determineFilename() const
{ {
std::string contentDisposition = util::getContentDispositionFilename( std::string contentDisposition = util::getContentDispositionFilename
httpHeader_->find(HttpHeader::CONTENT_DISPOSITION)); (httpHeader_->find(HttpHeader::CONTENT_DISPOSITION));
if (contentDisposition.empty()) { if (contentDisposition.empty()) {
auto file = httpRequest_->getFile(); auto file = httpRequest_->getFile();
file = util::percentDecode(file.begin(), file.end()); file = util::percentDecode(file.begin(), file.end());
@ -140,11 +140,11 @@ void HttpResponse::retrieveCookie()
Time now; Time now;
auto r = httpHeader_->equalRange(HttpHeader::SET_COOKIE); auto r = httpHeader_->equalRange(HttpHeader::SET_COOKIE);
for (; r.first != r.second; ++r.first) { for (; r.first != r.second; ++r.first) {
httpRequest_->getCookieStorage()->parseAndStore( httpRequest_->getCookieStorage()->parseAndStore
(*r.first).second, ((*r.first).second,
httpRequest_->getHost(), httpRequest_->getHost(),
httpRequest_->getDir(), httpRequest_->getDir(),
now.getTime()); now.getTime());
} }
} }
@ -362,9 +362,9 @@ bool parseMetalinkHttpLink(MetalinkHttpEntry& result, const std::string& s)
// Metalink/HTTP is defined by http://tools.ietf.org/html/rfc6249. // Metalink/HTTP is defined by http://tools.ietf.org/html/rfc6249.
// Link header field is defined by http://tools.ietf.org/html/rfc5988. // Link header field is defined by http://tools.ietf.org/html/rfc5988.
void HttpResponse::getMetalinKHttpEntries( void HttpResponse::getMetalinKHttpEntries
std::vector<MetalinkHttpEntry>& result, (std::vector<MetalinkHttpEntry>& result,
const std::shared_ptr<Option>& option) const const std::shared_ptr<Option>& option) const
{ {
auto p = httpHeader_->equalRange(HttpHeader::LINK); auto p = httpHeader_->equalRange(HttpHeader::LINK);
for (; p.first != p.second; ++p.first) { for (; p.first != p.second; ++p.first) {

View File

@ -85,9 +85,9 @@ namespace aria2 {
namespace { namespace {
std::unique_ptr<StreamFilter> getTransferEncodingStreamFilter( std::unique_ptr<StreamFilter> getTransferEncodingStreamFilter
HttpResponse* httpResponse, (HttpResponse* httpResponse,
std::unique_ptr<StreamFilter> delegate = nullptr) std::unique_ptr<StreamFilter> delegate = nullptr)
{ {
if (httpResponse->isTransferEncodingSpecified()) { if (httpResponse->isTransferEncodingSpecified()) {
auto filter = httpResponse->getTransferEncodingStreamFilter(); auto filter = httpResponse->getTransferEncodingStreamFilter();
@ -103,9 +103,9 @@ std::unique_ptr<StreamFilter> getTransferEncodingStreamFilter(
return delegate; return delegate;
} }
std::unique_ptr<StreamFilter> getContentEncodingStreamFilter( std::unique_ptr<StreamFilter> getContentEncodingStreamFilter
HttpResponse* httpResponse, (HttpResponse* httpResponse,
std::unique_ptr<StreamFilter> delegate = nullptr) std::unique_ptr<StreamFilter> delegate = nullptr)
{ {
if (httpResponse->isContentEncodingSpecified()) { if (httpResponse->isContentEncodingSpecified()) {
auto filter = httpResponse->getContentEncodingStreamFilter(); auto filter = httpResponse->getContentEncodingStreamFilter();
@ -125,16 +125,15 @@ std::unique_ptr<StreamFilter> getContentEncodingStreamFilter(
} // namespace } // namespace
HttpResponseCommand::HttpResponseCommand( HttpResponseCommand::HttpResponseCommand
cuid_t cuid, (cuid_t cuid,
const std::shared_ptr<Request>& req, const std::shared_ptr<Request>& req,
const std::shared_ptr<FileEntry>& fileEntry, const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup, RequestGroup* requestGroup,
const std::shared_ptr<HttpConnection>& httpConnection, const std::shared_ptr<HttpConnection>& httpConnection,
DownloadEngine* e, DownloadEngine* e,
const std::shared_ptr<SocketCore>& s) const std::shared_ptr<SocketCore>& s)
: : AbstractCommand(cuid, req, fileEntry, requestGroup, e, s,
AbstractCommand(cuid, req, fileEntry, requestGroup, e, s,
httpConnection->getSocketRecvBuffer()), httpConnection->getSocketRecvBuffer()),
httpConnection_(httpConnection) httpConnection_(httpConnection)
{ {
@ -164,11 +163,11 @@ bool HttpResponseCommand::executeInternal()
// Connection: close is received or the remote server is not HTTP/1.1. // Connection: close is received or the remote server is not HTTP/1.1.
// We don't care whether non-HTTP/1.1 server returns Connection: keep-alive. // We don't care whether non-HTTP/1.1 server returns Connection: keep-alive.
auto& req = getRequest(); auto& req = getRequest();
req->supportsPersistentConnection( req->supportsPersistentConnection
httpResponse->supportsPersistentConnection()); (httpResponse->supportsPersistentConnection());
if (req->isPipeliningEnabled()) { if (req->isPipeliningEnabled()) {
req->setMaxPipelinedRequest( req->setMaxPipelinedRequest
getOption()->getAsInt(PREF_MAX_HTTP_PIPELINING)); (getOption()->getAsInt(PREF_MAX_HTTP_PIPELINING));
} }
else { else {
req->setMaxPipelinedRequest(1); req->setMaxPipelinedRequest(1);
@ -297,18 +296,18 @@ bool HttpResponseCommand::executeInternal()
// Also we can't resume in this case too. So truncate the file // Also we can't resume in this case too. So truncate the file
// anyway. // anyway.
getPieceStorage()->getDiskAdaptor()->truncate(0); getPieceStorage()->getDiskAdaptor()->truncate(0);
auto teFilter = getTransferEncodingStreamFilter( auto teFilter = getTransferEncodingStreamFilter
httpResponse.get(), (httpResponse.get(),
getContentEncodingStreamFilter(httpResponse.get())); getContentEncodingStreamFilter(httpResponse.get()));
getDownloadEngine()->addCommand( getDownloadEngine()->addCommand
createHttpDownloadCommand(std::move(httpResponse), (createHttpDownloadCommand(std::move(httpResponse),
std::move(teFilter))); std::move(teFilter)));
} }
else { else {
auto teFilter = getTransferEncodingStreamFilter(httpResponse.get()); auto teFilter = getTransferEncodingStreamFilter(httpResponse.get());
getDownloadEngine()->addCommand( getDownloadEngine()->addCommand
createHttpDownloadCommand(std::move(httpResponse), (createHttpDownloadCommand(std::move(httpResponse),
std::move(teFilter))); std::move(teFilter)));
} }
return true; return true;
@ -321,8 +320,8 @@ void HttpResponseCommand::updateLastModifiedTime(const Time& lastModified)
} }
} }
bool HttpResponseCommand::shouldInflateContentEncoding( bool HttpResponseCommand::shouldInflateContentEncoding
HttpResponse* httpResponse) (HttpResponse* httpResponse)
{ {
// Basically, on the fly inflation cannot be made with segment // Basically, on the fly inflation cannot be made with segment
// download, because in each segment we don't know where the date // download, because in each segment we don't know where the date
@ -336,11 +335,11 @@ bool HttpResponseCommand::shouldInflateContentEncoding(
(ce == "gzip" || ce == "deflate"); (ce == "gzip" || ce == "deflate");
} }
bool HttpResponseCommand::handleDefaultEncoding( bool HttpResponseCommand::handleDefaultEncoding
std::unique_ptr<HttpResponse> httpResponse) (std::unique_ptr<HttpResponse> httpResponse)
{ {
auto progressInfoFile = std::make_shared<DefaultBtProgressInfoFile>( auto progressInfoFile = std::make_shared<DefaultBtProgressInfoFile>
getDownloadContext(), std::shared_ptr<PieceStorage>{}, getOption().get()); (getDownloadContext(), std::shared_ptr<PieceStorage>{}, getOption().get());
getRequestGroup()->adjustFilename(progressInfoFile); getRequestGroup()->adjustFilename(progressInfoFile);
getRequestGroup()->initPieceStorage(); getRequestGroup()->initPieceStorage();
@ -368,9 +367,9 @@ bool HttpResponseCommand::handleDefaultEncoding(
segment && segment->getPositionToWrite() == 0 && segment && segment->getPositionToWrite() == 0 &&
!getRequest()->isPipeliningEnabled()) { !getRequest()->isPipeliningEnabled()) {
auto teFilter = getTransferEncodingStreamFilter(httpResponse.get()); auto teFilter = getTransferEncodingStreamFilter(httpResponse.get());
checkEntry->pushNextCommand( checkEntry->pushNextCommand
createHttpDownloadCommand(std::move(httpResponse), (createHttpDownloadCommand(std::move(httpResponse),
std::move(teFilter))); std::move(teFilter)));
} }
else { else {
getSegmentMan()->cancelSegment(getCuid()); getSegmentMan()->cancelSegment(getCuid());
@ -387,8 +386,8 @@ bool HttpResponseCommand::handleDefaultEncoding(
return true; return true;
} }
bool HttpResponseCommand::handleOtherEncoding( bool HttpResponseCommand::handleOtherEncoding
std::unique_ptr<HttpResponse> httpResponse) (std::unique_ptr<HttpResponse> httpResponse)
{ {
// We assume that RequestGroup::getTotalLength() == 0 here // We assume that RequestGroup::getTotalLength() == 0 here
if (getOption()->getAsBool(PREF_DRY_RUN)) { if (getOption()->getAsBool(PREF_DRY_RUN)) {
@ -406,8 +405,8 @@ bool HttpResponseCommand::handleOtherEncoding(
// In this context, knowsTotalLength() is true only when the file is // In this context, knowsTotalLength() is true only when the file is
// really zero-length. // really zero-length.
auto streamFilter = getTransferEncodingStreamFilter( auto streamFilter = getTransferEncodingStreamFilter
httpResponse.get(), getContentEncodingStreamFilter(httpResponse.get())); (httpResponse.get(), getContentEncodingStreamFilter(httpResponse.get()));
// If chunked transfer-encoding is specified, we have to read end of // If chunked transfer-encoding is specified, we have to read end of
// chunk markers(0\r\n\r\n, for example). // chunk markers(0\r\n\r\n, for example).
bool chunkedUsed = streamFilter && bool chunkedUsed = streamFilter &&
@ -469,23 +468,23 @@ bool HttpResponseCommand::handleOtherEncoding(
// AbstractCommand::execute() // AbstractCommand::execute()
getSegmentMan()->getSegmentWithIndex(getCuid(), 0); getSegmentMan()->getSegmentWithIndex(getCuid(), 0);
getDownloadEngine()->addCommand( getDownloadEngine()->addCommand
createHttpDownloadCommand(std::move(httpResponse), (createHttpDownloadCommand(std::move(httpResponse),
std::move(streamFilter))); std::move(streamFilter)));
return true; return true;
} }
bool HttpResponseCommand::skipResponseBody( bool HttpResponseCommand::skipResponseBody
std::unique_ptr<HttpResponse> httpResponse) (std::unique_ptr<HttpResponse> httpResponse)
{ {
auto filter = getTransferEncodingStreamFilter(httpResponse.get()); auto filter = getTransferEncodingStreamFilter(httpResponse.get());
// We don't use Content-Encoding here because this response body is just // We don't use Content-Encoding here because this response body is just
// thrown away. // thrown away.
auto httpResponsePtr = httpResponse.get(); auto httpResponsePtr = httpResponse.get();
auto command = make_unique<HttpSkipResponseCommand>( auto command = make_unique<HttpSkipResponseCommand>
getCuid(), getRequest(), getFileEntry(), getRequestGroup(), (getCuid(), getRequest(), getFileEntry(), getRequestGroup(),
httpConnection_, std::move(httpResponse), getDownloadEngine(), httpConnection_, std::move(httpResponse), getDownloadEngine(),
getSocket()); getSocket());
command->installStreamFilter(std::move(filter)); command->installStreamFilter(std::move(filter));
// If request method is HEAD or the response body is zero-length, // If request method is HEAD or the response body is zero-length,
@ -524,25 +523,25 @@ bool decideFileAllocation(StreamFilter* filter)
} // namespace } // namespace
std::unique_ptr<HttpDownloadCommand> std::unique_ptr<HttpDownloadCommand>
HttpResponseCommand::createHttpDownloadCommand( HttpResponseCommand::createHttpDownloadCommand
std::unique_ptr<HttpResponse> httpResponse, (std::unique_ptr<HttpResponse> httpResponse,
std::unique_ptr<StreamFilter> filter) std::unique_ptr<StreamFilter> filter)
{ {
auto command = make_unique<HttpDownloadCommand>( auto command = make_unique<HttpDownloadCommand>
getCuid(), getRequest(), getFileEntry(), getRequestGroup(), (getCuid(), getRequest(), getFileEntry(), getRequestGroup(),
std::move(httpResponse), httpConnection_, getDownloadEngine(), std::move(httpResponse), httpConnection_, getDownloadEngine(),
getSocket()); getSocket());
command->setStartupIdleTime(getOption()->getAsInt(PREF_STARTUP_IDLE_TIME)); command->setStartupIdleTime(getOption()->getAsInt(PREF_STARTUP_IDLE_TIME));
command->setLowestDownloadSpeedLimit( command->setLowestDownloadSpeedLimit
getOption()->getAsInt(PREF_LOWEST_SPEED_LIMIT)); (getOption()->getAsInt(PREF_LOWEST_SPEED_LIMIT));
if (getRequestGroup()->isFileAllocationEnabled() && if (getRequestGroup()->isFileAllocationEnabled() &&
!decideFileAllocation(filter.get())) { !decideFileAllocation(filter.get())) {
getRequestGroup()->setFileAllocationEnabled(false); getRequestGroup()->setFileAllocationEnabled(false);
} }
command->installStreamFilter(std::move(filter)); command->installStreamFilter(std::move(filter));
getRequestGroup()->getURISelector()->tuneDownloadCommand( getRequestGroup()->getURISelector()->tuneDownloadCommand
getFileEntry()->getRemainingUris(), command.get()); (getFileEntry()->getRemainingUris(), command.get());
return std::move(command); return std::move(command);
} }
@ -562,8 +561,8 @@ void HttpResponseCommand::onDryRunFileFound()
poolConnection(); poolConnection();
} }
bool HttpResponseCommand::checkChecksum( bool HttpResponseCommand::checkChecksum
const std::shared_ptr<DownloadContext>& dctx, const Checksum& checksum) (const std::shared_ptr<DownloadContext>& dctx, const Checksum& checksum)
{ {
if (dctx->getHashType() == checksum.getHashType()) { if (dctx->getHashType() == checksum.getHashType()) {
if (dctx->getDigest() != checksum.getDigest()) { if (dctx->getDigest() != checksum.getDigest()) {

View File

@ -116,8 +116,8 @@ bool GnuTLSContext::addP12CredentialFile(const std::string& p12file)
(unsigned char*)datastr.c_str(), (unsigned char*)datastr.c_str(),
(unsigned int)datastr.length() (unsigned int)datastr.length()
}; };
int err = gnutls_certificate_set_x509_simple_pkcs12_mem( int err = gnutls_certificate_set_x509_simple_pkcs12_mem
certCred_, &data, GNUTLS_X509_FMT_DER, ""); (certCred_, &data, GNUTLS_X509_FMT_DER, "");
if (err != GNUTLS_E_SUCCESS) { if (err != GNUTLS_E_SUCCESS) {
A2_LOG_ERROR("Failed to import PKCS12 file. " A2_LOG_ERROR("Failed to import PKCS12 file. "
"If you meant to use PEM, you'll also have to specify " "If you meant to use PEM, you'll also have to specify "

View File

@ -86,9 +86,9 @@ int GnuTLSSession::init(sock_t sockfd)
rv_ = gnutls_init(&sslSession_, flags); rv_ = gnutls_init(&sslSession_, flags);
#else // GNUTLS_VERSION_NUMBER >= 0x030000 #else // GNUTLS_VERSION_NUMBER >= 0x030000
rv_ = gnutls_init( rv_ = gnutls_init
&sslSession_, (&sslSession_,
tlsContext_->getSide() == TLS_CLIENT ? GNUTLS_CLIENT : GNUTLS_SERVER); tlsContext_->getSide() == TLS_CLIENT ? GNUTLS_CLIENT : GNUTLS_SERVER);
#endif // GNUTLS_VERSION_NUMBER >= 0x030000 #endif // GNUTLS_VERSION_NUMBER >= 0x030000
if(rv_ != GNUTLS_E_SUCCESS) { if(rv_ != GNUTLS_E_SUCCESS) {
return TLS_ERR_ERROR; return TLS_ERR_ERROR;

View File

@ -260,14 +260,14 @@ std::unique_ptr<CheckIntegrityEntry> RequestGroup::createCheckIntegrityEntry()
auto tempEntry = make_unique<ChecksumCheckIntegrityEntry>(this); auto tempEntry = make_unique<ChecksumCheckIntegrityEntry>(this);
tempEntry->setRedownload(true); tempEntry->setRedownload(true);
return std::move(tempEntry); return std::move(tempEntry);
} }
loadAndOpenFile(infoFile); loadAndOpenFile(infoFile);
return make_unique<StreamCheckIntegrityEntry>(this); return make_unique<StreamCheckIntegrityEntry>(this);
} }
void RequestGroup::createInitialCommand( void RequestGroup::createInitialCommand
std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e) (std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e)
{ {
// Start session timer here. When file size becomes known, it will // Start session timer here. When file size becomes known, it will
// be reset again in *FileAllocationEntry, because hash check and // be reset again in *FileAllocationEntry, because hash check and
@ -279,8 +279,8 @@ void RequestGroup::createInitialCommand(
auto torrentAttrs = bittorrent::getTorrentAttrs(downloadContext_); auto torrentAttrs = bittorrent::getTorrentAttrs(downloadContext_);
bool metadataGetMode = torrentAttrs->metadata.empty(); bool metadataGetMode = torrentAttrs->metadata.empty();
if (option_->getAsBool(PREF_DRY_RUN)) { if (option_->getAsBool(PREF_DRY_RUN)) {
throw DOWNLOAD_FAILURE_EXCEPTION( throw DOWNLOAD_FAILURE_EXCEPTION
"Cancel BitTorrent download in dry-run context."); ("Cancel BitTorrent download in dry-run context.");
} }
auto& btRegistry = e->getBtRegistry(); auto& btRegistry = e->getBtRegistry();
if (btRegistry->getDownloadContext(torrentAttrs->infoHash)) { if (btRegistry->getDownloadContext(torrentAttrs->infoHash)) {
@ -308,10 +308,10 @@ void RequestGroup::createInitialCommand(
std::shared_ptr<DefaultBtProgressInfoFile> progressInfoFile; std::shared_ptr<DefaultBtProgressInfoFile> progressInfoFile;
if(!metadataGetMode) { if(!metadataGetMode) {
progressInfoFile = std::make_shared<DefaultBtProgressInfoFile>( progressInfoFile = std::make_shared<DefaultBtProgressInfoFile>
downloadContext_, (downloadContext_,
pieceStorage_, pieceStorage_,
option_.get()); option_.get());
} }
auto btRuntime = std::make_shared<BtRuntime>(); auto btRuntime = std::make_shared<BtRuntime>();
@ -329,24 +329,24 @@ void RequestGroup::createInitialCommand(
progressInfoFile->setPeerStorage(peerStorage); progressInfoFile->setPeerStorage(peerStorage);
} }
auto btAnnounce = std::make_shared<DefaultBtAnnounce>( auto btAnnounce = std::make_shared<DefaultBtAnnounce>
downloadContext_.get(), (downloadContext_.get(),
option_.get()); option_.get());
btAnnounce->setBtRuntime(btRuntime); btAnnounce->setBtRuntime(btRuntime);
btAnnounce->setPieceStorage(pieceStorage_); btAnnounce->setPieceStorage(pieceStorage_);
btAnnounce->setPeerStorage(peerStorage); btAnnounce->setPeerStorage(peerStorage);
btAnnounce->setUserDefinedInterval( btAnnounce->setUserDefinedInterval
option_->getAsInt(PREF_BT_TRACKER_INTERVAL)); (option_->getAsInt(PREF_BT_TRACKER_INTERVAL));
btAnnounce->shuffleAnnounce(); btAnnounce->shuffleAnnounce();
assert(!btRegistry->get(gid_->getNumericId())); assert(!btRegistry->get(gid_->getNumericId()));
btRegistry->put(gid_->getNumericId(), make_unique<BtObject> btRegistry->put(gid_->getNumericId(), make_unique<BtObject>
(downloadContext_, (downloadContext_,
pieceStorage_, pieceStorage_,
peerStorage, peerStorage,
btAnnounce, btAnnounce,
btRuntime, btRuntime,
(progressInfoFile ? (progressInfoFile ?
progressInfoFile : progressInfoFile_))); progressInfoFile : progressInfoFile_)));
if (option_->getAsBool(PREF_ENABLE_DHT) || if (option_->getAsBool(PREF_ENABLE_DHT) ||
@ -365,8 +365,8 @@ void RequestGroup::createInitialCommand(
// TODO Are nodes in torrent IPv4 only? // TODO Are nodes in torrent IPv4 only?
if(!torrentAttrs->privateTorrent && if(!torrentAttrs->privateTorrent &&
!nodes.empty() && DHTRegistry::isInitialized()) { !nodes.empty() && DHTRegistry::isInitialized()) {
auto command = make_unique<DHTEntryPointNameResolveCommand>( auto command = make_unique<DHTEntryPointNameResolveCommand>
e->newCUID(), e, nodes); (e->newCUID(), e, nodes);
command->setTaskQueue(DHTRegistry::getData().taskQueue.get()); command->setTaskQueue(DHTRegistry::getData().taskQueue.get());
command->setTaskFactory(DHTRegistry::getData().taskFactory.get()); command->setTaskFactory(DHTRegistry::getData().taskFactory.get());
command->setRoutingTable(DHTRegistry::getData().routingTable.get()); command->setRoutingTable(DHTRegistry::getData().routingTable.get());
@ -408,8 +408,8 @@ void RequestGroup::createInitialCommand(
} }
else if(pieceStorage_->getDiskAdaptor()->fileExists()) { else if(pieceStorage_->getDiskAdaptor()->fileExists()) {
if(!option_->getAsBool(PREF_CHECK_INTEGRITY) && if(!option_->getAsBool(PREF_CHECK_INTEGRITY) &&
!option_->getAsBool(PREF_ALLOW_OVERWRITE) && !option_->getAsBool(PREF_ALLOW_OVERWRITE) &&
!option_->getAsBool(PREF_BT_SEED_UNVERIFIED)) { !option_->getAsBool(PREF_BT_SEED_UNVERIFIED)) {
// TODO we need this->haltRequested = true? // TODO we need this->haltRequested = true?
throw DOWNLOAD_FAILURE_EXCEPTION2(fmt(MSG_FILE_ALREADY_EXISTS, throw DOWNLOAD_FAILURE_EXCEPTION2(fmt(MSG_FILE_ALREADY_EXISTS,
downloadContext_->getBasePath().c_str()), downloadContext_->getBasePath().c_str()),
@ -443,14 +443,14 @@ void RequestGroup::createInitialCommand(
// TODO I assume here when totallength is set to DownloadContext and it is // TODO I assume here when totallength is set to DownloadContext and it is
// not 0, then filepath is also set DownloadContext correctly.... // not 0, then filepath is also set DownloadContext correctly....
if (option_->getAsBool(PREF_DRY_RUN) || if (option_->getAsBool(PREF_DRY_RUN) ||
downloadContext_->getTotalLength() == 0) { downloadContext_->getTotalLength() == 0) {
createNextCommand(commands, e, 1); createNextCommand(commands, e, 1);
return; return;
} }
auto progressInfoFile = std::make_shared<DefaultBtProgressInfoFile>( auto progressInfoFile = std::make_shared<DefaultBtProgressInfoFile>
downloadContext_, (downloadContext_,
nullptr, nullptr,
option_.get()); option_.get());
adjustFilename(progressInfoFile); adjustFilename(progressInfoFile);
initPieceStorage(); initPieceStorage();
auto checkEntry = createCheckIntegrityEntry(); auto checkEntry = createCheckIntegrityEntry();
@ -462,8 +462,8 @@ void RequestGroup::createInitialCommand(
// TODO --dry-run is not supported for multifile download for now. // TODO --dry-run is not supported for multifile download for now.
if (option_->getAsBool(PREF_DRY_RUN)) { if (option_->getAsBool(PREF_DRY_RUN)) {
throw DOWNLOAD_FAILURE_EXCEPTION( throw DOWNLOAD_FAILURE_EXCEPTION
"--dry-run in multi-file download is not supported yet."); ("--dry-run in multi-file download is not supported yet.");
} }
// TODO file size is known in this context? // TODO file size is known in this context?
@ -478,10 +478,10 @@ void RequestGroup::createInitialCommand(
if (downloadContext_->getFileEntries().size() > 1) { if (downloadContext_->getFileEntries().size() > 1) {
pieceStorage_->setupFileFilter(); pieceStorage_->setupFileFilter();
} }
auto progressInfoFile = std::make_shared<DefaultBtProgressInfoFile>( auto progressInfoFile = std::make_shared<DefaultBtProgressInfoFile>
downloadContext_, (downloadContext_,
pieceStorage_, pieceStorage_,
option_.get()); option_.get());
removeDefunctControlFile(progressInfoFile); removeDefunctControlFile(progressInfoFile);
// Call Load, Save and file allocation command here // Call Load, Save and file allocation command here
if (progressInfoFile->exists()) { if (progressInfoFile->exists()) {
@ -506,9 +506,9 @@ void RequestGroup::createInitialCommand(
e); e);
} }
void RequestGroup::processCheckIntegrityEntry( void RequestGroup::processCheckIntegrityEntry
std::vector<std::unique_ptr<Command>>& commands, (std::vector<std::unique_ptr<Command>>& commands,
std::unique_ptr<CheckIntegrityEntry> entry, DownloadEngine* e) std::unique_ptr<CheckIntegrityEntry> entry, DownloadEngine* e)
{ {
int64_t actualFileSize = pieceStorage_->getDiskAdaptor()->size(); int64_t actualFileSize = pieceStorage_->getDiskAdaptor()->size();
if(actualFileSize > downloadContext_->getTotalLength()) { if(actualFileSize > downloadContext_->getTotalLength()) {
@ -544,12 +544,12 @@ void RequestGroup::initPieceStorage()
#endif // ENABLE_BITTORRENT #endif // ENABLE_BITTORRENT
)) { )) {
#ifdef ENABLE_BITTORRENT #ifdef ENABLE_BITTORRENT
auto ps = std::make_shared<DefaultPieceStorage>( auto ps = std::make_shared<DefaultPieceStorage>
downloadContext_, option_.get()); (downloadContext_, option_.get());
if (downloadContext_->hasAttribute(CTX_ATTR_BT)) { if (downloadContext_->hasAttribute(CTX_ATTR_BT)) {
if (isUriSuppliedForRequsetFileEntry( if (isUriSuppliedForRequsetFileEntry
downloadContext_->getFileEntries().begin(), (downloadContext_->getFileEntries().begin(),
downloadContext_->getFileEntries().end())) { downloadContext_->getFileEntries().end())) {
// Use LongestSequencePieceSelector when HTTP/FTP/BitTorrent // Use LongestSequencePieceSelector when HTTP/FTP/BitTorrent
// integrated downloads. Currently multi-file integrated // integrated downloads. Currently multi-file integrated
// download is not supported. // download is not supported.
@ -566,16 +566,16 @@ void RequestGroup::initPieceStorage()
if (!result.empty()) { if (!result.empty()) {
std::random_shuffle(std::begin(result), std::end(result), std::random_shuffle(std::begin(result), std::end(result),
*SimpleRandomizer::getInstance()); *SimpleRandomizer::getInstance());
auto priSelector = make_unique<PriorityPieceSelector>( auto priSelector = make_unique<PriorityPieceSelector>
ps->popPieceSelector()); (ps->popPieceSelector());
priSelector->setPriorityPiece(std::begin(result), std::end(result)); priSelector->setPriorityPiece(std::begin(result), std::end(result));
ps->setPieceSelector(std::move(priSelector)); ps->setPieceSelector(std::move(priSelector));
} }
} }
} }
#else // !ENABLE_BITTORRENT #else // !ENABLE_BITTORRENT
auto ps = std::make_shared<DefaultPieceStorage>( auto ps = std::make_shared<DefaultPieceStorage>
downloadContext_, option_.get()); (downloadContext_, option_.get());
#endif // !ENABLE_BITTORRENT #endif // !ENABLE_BITTORRENT
if (requestGroupMan_) { if (requestGroupMan_) {
ps->setWrDiskCache(requestGroupMan_->getWrDiskCache()); ps->setWrDiskCache(requestGroupMan_->getWrDiskCache());
@ -621,8 +621,8 @@ bool RequestGroup::downloadFinishedByFileLength()
return false; return false;
} }
void RequestGroup::adjustFilename( void RequestGroup::adjustFilename
const std::shared_ptr<BtProgressInfoFile>& infoFile) (const std::shared_ptr<BtProgressInfoFile>& infoFile)
{ {
if(!isPreLocalFileCheckEnabled()) { if(!isPreLocalFileCheckEnabled()) {
// OK, no need to care about filename. // OK, no need to care about filename.
@ -653,19 +653,19 @@ void RequestGroup::adjustFilename(
File outfile(getFirstFilePath()); File outfile(getFirstFilePath());
if(outfile.exists() && option_->getAsBool(PREF_CONTINUE) && if(outfile.exists() && option_->getAsBool(PREF_CONTINUE) &&
outfile.size() <= downloadContext_->getTotalLength()) { outfile.size() <= downloadContext_->getTotalLength()) {
// File exists but user decided to resume it. // File exists but user decided to resume it.
} }
else if(outfile.exists() && isCheckIntegrityReady()) { else if(outfile.exists() && isCheckIntegrityReady()) {
// check-integrity existing file // check-integrity existing file
} }
else { else {
shouldCancelDownloadForSafety(); shouldCancelDownloadForSafety();
} }
} }
void RequestGroup::removeDefunctControlFile( void RequestGroup::removeDefunctControlFile
const std::shared_ptr<BtProgressInfoFile>& progressInfoFile) (const std::shared_ptr<BtProgressInfoFile>& progressInfoFile)
{ {
// Remove the control file if download file doesn't exist // Remove the control file if download file doesn't exist
if(progressInfoFile->exists() && if(progressInfoFile->exists() &&
@ -677,8 +677,8 @@ void RequestGroup::removeDefunctControlFile(
} }
} }
void RequestGroup::loadAndOpenFile( void RequestGroup::loadAndOpenFile
const std::shared_ptr<BtProgressInfoFile>& progressInfoFile) (const std::shared_ptr<BtProgressInfoFile>& progressInfoFile)
{ {
try { try {
if(!isPreLocalFileCheckEnabled()) { if(!isPreLocalFileCheckEnabled()) {
@ -693,7 +693,7 @@ void RequestGroup::loadAndOpenFile(
else { else {
File outfile(getFirstFilePath()); File outfile(getFirstFilePath());
if (outfile.exists() && option_->getAsBool(PREF_CONTINUE) && if (outfile.exists() && option_->getAsBool(PREF_CONTINUE) &&
outfile.size() <= getTotalLength()) { outfile.size() <= getTotalLength()) {
pieceStorage_->getDiskAdaptor()->openExistingFile(); pieceStorage_->getDiskAdaptor()->openExistingFile();
pieceStorage_->markPiecesDone(outfile.size()); pieceStorage_->markPiecesDone(outfile.size());
} }
@ -754,9 +754,9 @@ void RequestGroup::tryAutoFileRenaming()
error_code::FILE_RENAMING_FAILED); error_code::FILE_RENAMING_FAILED);
} }
void RequestGroup::createNextCommandWithAdj( void RequestGroup::createNextCommandWithAdj
std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e, (std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e,
int numAdj) int numAdj)
{ {
int numCommand; int numCommand;
if (getTotalLength() == 0) { if (getTotalLength() == 0) {
@ -773,8 +773,8 @@ void RequestGroup::createNextCommandWithAdj(
} }
} }
void RequestGroup::createNextCommand( void RequestGroup::createNextCommand
std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e) (std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e)
{ {
int numCommand; int numCommand;
if (getTotalLength() == 0) { if (getTotalLength() == 0) {
@ -797,13 +797,13 @@ void RequestGroup::createNextCommand(
} }
} }
void RequestGroup::createNextCommand( void RequestGroup::createNextCommand
std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e, (std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e,
int numCommand) int numCommand)
{ {
for (; numCommand > 0; --numCommand) { for (; numCommand > 0; --numCommand) {
commands.push_back(make_unique<CreateRequestCommand>( commands.push_back(make_unique<CreateRequestCommand>
e->newCUID(), this, e)); (e->newCUID(), this, e));
} }
if (!commands.empty()) { if (!commands.empty()) {
e->setNoWait(true); e->setNoWait(true);
@ -1003,8 +1003,8 @@ void RequestGroup::preDownloadProcessing()
return; return;
} }
void RequestGroup::postDownloadProcessing( void RequestGroup::postDownloadProcessing
std::vector<std::shared_ptr<RequestGroup> >& groups) (std::vector<std::shared_ptr<RequestGroup> >& groups)
{ {
A2_LOG_DEBUG(fmt("Finding PostDownloadHandler for path %s.", A2_LOG_DEBUG(fmt("Finding PostDownloadHandler for path %s.",
getFirstFilePath().c_str())); getFirstFilePath().c_str()));
@ -1070,8 +1070,8 @@ void RequestGroup::dependsOn(const std::shared_ptr<Dependency>& dep)
dependency_ = dep; dependency_ = dep;
} }
void RequestGroup::setDiskWriterFactory( void RequestGroup::setDiskWriterFactory
const std::shared_ptr<DiskWriterFactory>& diskWriterFactory) (const std::shared_ptr<DiskWriterFactory>& diskWriterFactory)
{ {
diskWriterFactory_ = diskWriterFactory; diskWriterFactory_ = diskWriterFactory;
} }
@ -1096,14 +1096,14 @@ void RequestGroup::clearPreDownloadHandler()
preDownloadHandlers_.clear(); preDownloadHandlers_.clear();
} }
void RequestGroup::setPieceStorage( void RequestGroup::setPieceStorage
const std::shared_ptr<PieceStorage>& pieceStorage) (const std::shared_ptr<PieceStorage>& pieceStorage)
{ {
pieceStorage_ = pieceStorage; pieceStorage_ = pieceStorage;
} }
void RequestGroup::setProgressInfoFile( void RequestGroup::setProgressInfoFile
const std::shared_ptr<BtProgressInfoFile>& progressInfoFile) (const std::shared_ptr<BtProgressInfoFile>& progressInfoFile)
{ {
progressInfoFile_ = progressInfoFile; progressInfoFile_ = progressInfoFile;
} }
@ -1137,7 +1137,7 @@ std::shared_ptr<DownloadResult> RequestGroup::createDownloadResult() const
if(pieceStorage_ && pieceStorage_->getBitfieldLength() > 0) { if(pieceStorage_ && pieceStorage_->getBitfieldLength() > 0) {
res->bitfield.assign(pieceStorage_->getBitfield(), res->bitfield.assign(pieceStorage_->getBitfield(),
pieceStorage_->getBitfield() + pieceStorage_->getBitfield() +
pieceStorage_->getBitfieldLength()); pieceStorage_->getBitfieldLength());
} }
#ifdef ENABLE_BITTORRENT #ifdef ENABLE_BITTORRENT
if(downloadContext_->hasAttribute(CTX_ATTR_BT)) { if(downloadContext_->hasAttribute(CTX_ATTR_BT)) {
@ -1203,7 +1203,7 @@ void RequestGroup::increaseAndValidateFileNotFoundCount()
++fileNotFoundCount_; ++fileNotFoundCount_;
const int maxCount = option_->getAsInt(PREF_MAX_FILE_NOT_FOUND); const int maxCount = option_->getAsInt(PREF_MAX_FILE_NOT_FOUND);
if (maxCount > 0 && fileNotFoundCount_ >= maxCount && if (maxCount > 0 && fileNotFoundCount_ >= maxCount &&
downloadContext_->getNetStat().getSessionDownloadLength() == 0) { downloadContext_->getNetStat().getSessionDownloadLength() == 0) {
throw DOWNLOAD_FAILURE_EXCEPTION2(fmt("Reached max-file-not-found count=%d", throw DOWNLOAD_FAILURE_EXCEPTION2(fmt("Reached max-file-not-found count=%d",
maxCount), maxCount),
error_code::MAX_FILE_NOT_FOUND); error_code::MAX_FILE_NOT_FOUND);
@ -1244,8 +1244,8 @@ void RequestGroup::removeControlFile() const
progressInfoFile_->removeFile(); progressInfoFile_->removeFile();
} }
void RequestGroup::setDownloadContext( void RequestGroup::setDownloadContext
const std::shared_ptr<DownloadContext>& downloadContext) (const std::shared_ptr<DownloadContext>& downloadContext)
{ {
downloadContext_ = downloadContext; downloadContext_ = downloadContext;
if(downloadContext_) { if(downloadContext_) {

View File

@ -196,8 +196,8 @@ private:
// returns error_code::UNKNOWN_ERROR. // returns error_code::UNKNOWN_ERROR.
error_code::Value downloadResult() const; error_code::Value downloadResult() const;
void removeDefunctControlFile( void removeDefunctControlFile
const std::shared_ptr<BtProgressInfoFile>& progressInfoFile); (const std::shared_ptr<BtProgressInfoFile>& progressInfoFile);
public: public:
RequestGroup(const std::shared_ptr<GroupId>& gid, RequestGroup(const std::shared_ptr<GroupId>& gid,
@ -296,8 +296,8 @@ public:
void setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage); void setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage);
void setProgressInfoFile( void setProgressInfoFile
const std::shared_ptr<BtProgressInfoFile>& progressInfoFile); (const std::shared_ptr<BtProgressInfoFile>& progressInfoFile);
void increaseStreamCommand(); void increaseStreamCommand();
@ -392,10 +392,10 @@ public:
void clearPreDownloadHandler(); void clearPreDownloadHandler();
void processCheckIntegrityEntry( void processCheckIntegrityEntry
std::vector<std::unique_ptr<Command>>& commands, (std::vector<std::unique_ptr<Command>>& commands,
std::unique_ptr<CheckIntegrityEntry> entry, std::unique_ptr<CheckIntegrityEntry> entry,
DownloadEngine* e); DownloadEngine* e);
// Initializes pieceStorage_ and segmentMan_. We guarantee that // Initializes pieceStorage_ and segmentMan_. We guarantee that
// either both of pieceStorage_ and segmentMan_ are initialized or // either both of pieceStorage_ and segmentMan_ are initialized or