mirror of https://github.com/aria2/aria2
2010-09-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Use uri::parse instead of Request::setUri() where just URI parser is needed. * src/AbstractCommand.cc * src/AdaptiveURISelector.cc * src/DefaultBtAnnounce.cc * src/FeedbackURISelector.cc * src/FileEntry.cc * src/HttpResponseCommand.cc * src/ProtocolDetector.cc * src/Request.cc * src/RequestGroupMan.ccpull/1/head
parent
ec3bd81486
commit
80edde0205
14
ChangeLog
14
ChangeLog
|
@ -1,3 +1,17 @@
|
||||||
|
2010-09-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Use uri::parse instead of Request::setUri() where just URI parser
|
||||||
|
is needed.
|
||||||
|
* src/AbstractCommand.cc
|
||||||
|
* src/AdaptiveURISelector.cc
|
||||||
|
* src/DefaultBtAnnounce.cc
|
||||||
|
* src/FeedbackURISelector.cc
|
||||||
|
* src/FileEntry.cc
|
||||||
|
* src/HttpResponseCommand.cc
|
||||||
|
* src/ProtocolDetector.cc
|
||||||
|
* src/Request.cc
|
||||||
|
* src/RequestGroupMan.cc
|
||||||
|
|
||||||
2010-09-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2010-09-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Moved URI parser code to uri.h, uri.cc to provide fast URI parser
|
Moved URI parser code to uri.h, uri.cc to provide fast URI parser
|
||||||
|
|
|
@ -68,6 +68,7 @@
|
||||||
#include "NameResolver.h"
|
#include "NameResolver.h"
|
||||||
#include "ServerStatMan.h"
|
#include "ServerStatMan.h"
|
||||||
#include "FileAllocationEntry.h"
|
#include "FileAllocationEntry.h"
|
||||||
|
#include "uri.h"
|
||||||
#ifdef ENABLE_MESSAGE_DIGEST
|
#ifdef ENABLE_MESSAGE_DIGEST
|
||||||
# include "ChecksumCheckIntegrityEntry.h"
|
# include "ChecksumCheckIntegrityEntry.h"
|
||||||
#endif // ENABLE_MESSAGE_DIGEST
|
#endif // ENABLE_MESSAGE_DIGEST
|
||||||
|
@ -556,7 +557,8 @@ static bool isProxyRequest
|
||||||
(const std::string& protocol, const SharedHandle<Option>& option)
|
(const std::string& protocol, const SharedHandle<Option>& option)
|
||||||
{
|
{
|
||||||
const std::string& proxyUri = getProxyUri(protocol, option);
|
const std::string& proxyUri = getProxyUri(protocol, option);
|
||||||
return !proxyUri.empty() && Request().setUri(proxyUri);
|
uri::UriStruct us;
|
||||||
|
return !proxyUri.empty() && uri::parse(us, proxyUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
|
@ -51,6 +51,7 @@
|
||||||
#include "SimpleRandomizer.h"
|
#include "SimpleRandomizer.h"
|
||||||
#include "SocketCore.h"
|
#include "SocketCore.h"
|
||||||
#include "FileEntry.h"
|
#include "FileEntry.h"
|
||||||
|
#include "uri.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -341,9 +342,12 @@ std::string AdaptiveURISelector::getFirstToTestUri
|
||||||
SharedHandle<ServerStat> AdaptiveURISelector::getServerStats
|
SharedHandle<ServerStat> AdaptiveURISelector::getServerStats
|
||||||
(const std::string& uri) const
|
(const std::string& uri) const
|
||||||
{
|
{
|
||||||
Request r;
|
uri::UriStruct us;
|
||||||
r.setUri(uri);
|
if(uri::parse(us, uri)) {
|
||||||
return serverStatMan_->find(r.getHost(), r.getProtocol());
|
return serverStatMan_->find(us.host, us.protocol);
|
||||||
|
} else {
|
||||||
|
return SharedHandle<ServerStat>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int AdaptiveURISelector::getNbTestedServers
|
unsigned int AdaptiveURISelector::getNbTestedServers
|
||||||
|
|
|
@ -48,10 +48,10 @@
|
||||||
#include "Option.h"
|
#include "Option.h"
|
||||||
#include "StringFormat.h"
|
#include "StringFormat.h"
|
||||||
#include "A2STR.h"
|
#include "A2STR.h"
|
||||||
#include "Request.h"
|
|
||||||
#include "bencode2.h"
|
#include "bencode2.h"
|
||||||
#include "bittorrent_helper.h"
|
#include "bittorrent_helper.h"
|
||||||
#include "wallclock.h"
|
#include "wallclock.h"
|
||||||
|
#include "uri.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -105,9 +105,12 @@ bool DefaultBtAnnounce::isAnnounceReady() {
|
||||||
|
|
||||||
static bool uriHasQuery(const std::string& uri)
|
static bool uriHasQuery(const std::string& uri)
|
||||||
{
|
{
|
||||||
Request req;
|
uri::UriStruct us;
|
||||||
req.setUri(uri);
|
if(uri::parse(us, uri)) {
|
||||||
return !req.getQuery().empty();
|
return !us.query.empty();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DefaultBtAnnounce::getAnnounceUrl() {
|
std::string DefaultBtAnnounce::getAnnounceUrl() {
|
||||||
|
|
|
@ -39,12 +39,12 @@
|
||||||
|
|
||||||
#include "ServerStatMan.h"
|
#include "ServerStatMan.h"
|
||||||
#include "ServerStat.h"
|
#include "ServerStat.h"
|
||||||
#include "Request.h"
|
|
||||||
#include "A2STR.h"
|
#include "A2STR.h"
|
||||||
#include "FileEntry.h"
|
#include "FileEntry.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "LogFactory.h"
|
#include "LogFactory.h"
|
||||||
#include "a2algo.h"
|
#include "a2algo.h"
|
||||||
|
#include "uri.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -109,19 +109,19 @@ std::string FeedbackURISelector::selectRarer
|
||||||
std::vector<std::pair<std::string, std::string> > cands;
|
std::vector<std::pair<std::string, std::string> > cands;
|
||||||
for(std::deque<std::string>::const_iterator i = uris.begin(),
|
for(std::deque<std::string>::const_iterator i = uris.begin(),
|
||||||
eoi = uris.end(); i != eoi; ++i) {
|
eoi = uris.end(); i != eoi; ++i) {
|
||||||
Request r;
|
uri::UriStruct us;
|
||||||
if(!r.setUri(*i)) {
|
if(!uri::parse(us, *i)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
SharedHandle<ServerStat> ss =
|
SharedHandle<ServerStat> ss =
|
||||||
serverStatMan_->find(r.getHost(), r.getProtocol());
|
serverStatMan_->find(us.host, us.protocol);
|
||||||
if(!ss.isNull() && ss->isError()) {
|
if(!ss.isNull() && ss->isError()) {
|
||||||
if(logger_->debug()) {
|
if(logger_->debug()) {
|
||||||
logger_->debug("Error not considered: %s", (*i).c_str());
|
logger_->debug("Error not considered: %s", (*i).c_str());
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
cands.push_back(std::make_pair(r.getHost(), *i));
|
cands.push_back(std::make_pair(us.host, *i));
|
||||||
}
|
}
|
||||||
for(std::vector<std::pair<size_t, std::string> >::const_iterator i =
|
for(std::vector<std::pair<size_t, std::string> >::const_iterator i =
|
||||||
usedHosts.begin(), eoi = usedHosts.end(); i != eoi; ++i) {
|
usedHosts.begin(), eoi = usedHosts.end(); i != eoi; ++i) {
|
||||||
|
@ -148,11 +148,11 @@ std::string FeedbackURISelector::selectFaster
|
||||||
std::vector<std::string> normCands;
|
std::vector<std::string> normCands;
|
||||||
for(std::deque<std::string>::const_iterator i = uris.begin(),
|
for(std::deque<std::string>::const_iterator i = uris.begin(),
|
||||||
eoi = uris.end(); i != eoi && fastCands.size() < NUM_URI; ++i) {
|
eoi = uris.end(); i != eoi && fastCands.size() < NUM_URI; ++i) {
|
||||||
Request r;
|
uri::UriStruct us;
|
||||||
if(!r.setUri(*i)) {
|
if(!uri::parse(us, *i)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(findSecond(usedHosts.begin(), usedHosts.end(), r.getHost()) !=
|
if(findSecond(usedHosts.begin(), usedHosts.end(), us.host) !=
|
||||||
usedHosts.end()) {
|
usedHosts.end()) {
|
||||||
if(logger_->debug()) {
|
if(logger_->debug()) {
|
||||||
logger_->debug("%s is in usedHosts, not considered", (*i).c_str());
|
logger_->debug("%s is in usedHosts, not considered", (*i).c_str());
|
||||||
|
@ -160,7 +160,7 @@ std::string FeedbackURISelector::selectFaster
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
SharedHandle<ServerStat> ss =
|
SharedHandle<ServerStat> ss =
|
||||||
serverStatMan_->find(r.getHost(), r.getProtocol());
|
serverStatMan_->find(us.host, us.protocol);
|
||||||
if(ss.isNull()) {
|
if(ss.isNull()) {
|
||||||
normCands.push_back(*i);
|
normCands.push_back(*i);
|
||||||
} else if(ss->isOK()) {
|
} else if(ss->isOK()) {
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#include "LogFactory.h"
|
#include "LogFactory.h"
|
||||||
#include "wallclock.h"
|
#include "wallclock.h"
|
||||||
#include "a2algo.h"
|
#include "a2algo.h"
|
||||||
|
#include "uri.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -108,10 +109,11 @@ static OutputIterator
|
||||||
enumerateInFlightHosts
|
enumerateInFlightHosts
|
||||||
(InputIterator first, InputIterator last, OutputIterator out)
|
(InputIterator first, InputIterator last, OutputIterator out)
|
||||||
{
|
{
|
||||||
Request r;
|
|
||||||
for(; first != last; ++first) {
|
for(; first != last; ++first) {
|
||||||
r.setUri((*first)->getUri());
|
uri::UriStruct us;
|
||||||
*out++ = r.getHost();
|
if(uri::parse(us, (*first)->getUri())) {
|
||||||
|
*out++ = us.host;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
@ -259,11 +261,13 @@ bool FileEntry::removeRequest(const SharedHandle<Request>& request)
|
||||||
void FileEntry::removeURIWhoseHostnameIs(const std::string& hostname)
|
void FileEntry::removeURIWhoseHostnameIs(const std::string& hostname)
|
||||||
{
|
{
|
||||||
std::deque<std::string> newURIs;
|
std::deque<std::string> newURIs;
|
||||||
Request req;
|
|
||||||
for(std::deque<std::string>::const_iterator itr = uris_.begin(),
|
for(std::deque<std::string>::const_iterator itr = uris_.begin(),
|
||||||
eoi = uris_.end(); itr != eoi; ++itr) {
|
eoi = uris_.end(); itr != eoi; ++itr) {
|
||||||
if(((*itr).find(hostname) == std::string::npos) ||
|
uri::UriStruct us;
|
||||||
(req.setUri(*itr) && (req.getHost() != hostname))) {
|
if(!uri::parse(us, *itr)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(us.host != hostname) {
|
||||||
newURIs.push_back(*itr);
|
newURIs.push_back(*itr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -271,7 +275,7 @@ void FileEntry::removeURIWhoseHostnameIs(const std::string& hostname)
|
||||||
logger_->debug("Removed %d duplicate hostname URIs for path=%s",
|
logger_->debug("Removed %d duplicate hostname URIs for path=%s",
|
||||||
uris_.size()-newURIs.size(), getPath().c_str());
|
uris_.size()-newURIs.size(), getPath().c_str());
|
||||||
}
|
}
|
||||||
uris_ = newURIs;
|
uris_.swap(newURIs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileEntry::removeIdenticalURI(const std::string& uri)
|
void FileEntry::removeIdenticalURI(const std::string& uri)
|
||||||
|
@ -337,11 +341,11 @@ void FileEntry::reuseUri(const std::vector<std::string>& ignore)
|
||||||
errorUris.begin(), errorUris.end(),
|
errorUris.begin(), errorUris.end(),
|
||||||
std::back_inserter(reusableURIs));
|
std::back_inserter(reusableURIs));
|
||||||
std::vector<std::string>::iterator insertionPoint = reusableURIs.begin();
|
std::vector<std::string>::iterator insertionPoint = reusableURIs.begin();
|
||||||
Request req;
|
|
||||||
for(std::vector<std::string>::iterator i = reusableURIs.begin(),
|
for(std::vector<std::string>::iterator i = reusableURIs.begin(),
|
||||||
eoi = reusableURIs.end(); i != eoi; ++i) {
|
eoi = reusableURIs.end(); i != eoi; ++i) {
|
||||||
req.setUri(*i);
|
uri::UriStruct us;
|
||||||
if(std::find(ignore.begin(), ignore.end(), req.getHost()) == ignore.end()) {
|
if(uri::parse(us, *i) &&
|
||||||
|
std::find(ignore.begin(), ignore.end(), us.host) == ignore.end()) {
|
||||||
if(i != insertionPoint) {
|
if(i != insertionPoint) {
|
||||||
*insertionPoint = *i;
|
*insertionPoint = *i;
|
||||||
}
|
}
|
||||||
|
@ -429,7 +433,8 @@ size_t FileEntry::setUris(const std::vector<std::string>& uris)
|
||||||
|
|
||||||
bool FileEntry::addUri(const std::string& uri)
|
bool FileEntry::addUri(const std::string& uri)
|
||||||
{
|
{
|
||||||
if(Request().setUri(uri)) {
|
uri::UriStruct us;
|
||||||
|
if(uri::parse(us, uri)) {
|
||||||
uris_.push_back(uri);
|
uris_.push_back(uri);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -439,7 +444,8 @@ bool FileEntry::addUri(const std::string& uri)
|
||||||
|
|
||||||
bool FileEntry::insertUri(const std::string& uri, size_t pos)
|
bool FileEntry::insertUri(const std::string& uri, size_t pos)
|
||||||
{
|
{
|
||||||
if(Request().setUri(uri)) {
|
uri::UriStruct us;
|
||||||
|
if(uri::parse(us, uri)) {
|
||||||
pos = std::min(pos, uris_.size());
|
pos = std::min(pos, uris_.size());
|
||||||
uris_.insert(uris_.begin()+pos, uri);
|
uris_.insert(uris_.begin()+pos, uri);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -73,6 +73,7 @@
|
||||||
#include "SinkStreamFilter.h"
|
#include "SinkStreamFilter.h"
|
||||||
#include "ChunkedDecodingStreamFilter.h"
|
#include "ChunkedDecodingStreamFilter.h"
|
||||||
#include "GZipDecodingStreamFilter.h"
|
#include "GZipDecodingStreamFilter.h"
|
||||||
|
#include "uri.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -155,9 +156,10 @@ bool HttpResponseCommand::executeInternal()
|
||||||
if(getFileEntry()->isUniqueProtocol()) {
|
if(getFileEntry()->isUniqueProtocol()) {
|
||||||
// Redirection should be considered here. We need to parse
|
// Redirection should be considered here. We need to parse
|
||||||
// original URI to get hostname.
|
// original URI to get hostname.
|
||||||
Request req;
|
uri::UriStruct us;
|
||||||
req.setUri(getRequest()->getUri());
|
if(uri::parse(us, getRequest()->getUri())) {
|
||||||
getFileEntry()->removeURIWhoseHostnameIs(req.getHost());
|
getFileEntry()->removeURIWhoseHostnameIs(us.host);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(getPieceStorage().isNull()) {
|
if(getPieceStorage().isNull()) {
|
||||||
uint64_t totalLength = httpResponse->getEntityLength();
|
uint64_t totalLength = httpResponse->getEntityLength();
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#include "File.h"
|
#include "File.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "RecoverableException.h"
|
#include "RecoverableException.h"
|
||||||
|
#include "uri.h"
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
# include "bittorrent_helper.h"
|
# include "bittorrent_helper.h"
|
||||||
#endif // ENABLE_BITTORRENT
|
#endif // ENABLE_BITTORRENT
|
||||||
|
@ -54,7 +55,8 @@ ProtocolDetector::~ProtocolDetector() {}
|
||||||
|
|
||||||
bool ProtocolDetector::isStreamProtocol(const std::string& uri) const
|
bool ProtocolDetector::isStreamProtocol(const std::string& uri) const
|
||||||
{
|
{
|
||||||
return Request().setUri(uri);
|
uri::UriStruct us;
|
||||||
|
return uri::parse(us, uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProtocolDetector::guessTorrentFile(const std::string& uri) const
|
bool ProtocolDetector::guessTorrentFile(const std::string& uri) const
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "Request.h"
|
#include "Request.h"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
@ -181,9 +182,10 @@ const SharedHandle<PeerStat>& Request::initPeerStat()
|
||||||
{
|
{
|
||||||
// Use host and protocol in original URI, because URI selector
|
// Use host and protocol in original URI, because URI selector
|
||||||
// selects URI based on original URI, not redirected one.
|
// selects URI based on original URI, not redirected one.
|
||||||
Request origReq;
|
uri::UriStruct us;
|
||||||
origReq.setUri(uri_);
|
bool v = uri::parse(us, uri_);
|
||||||
peerStat_.reset(new PeerStat(0, origReq.getHost(), origReq.getProtocol()));
|
assert(v);
|
||||||
|
peerStat_.reset(new PeerStat(0, us.host, us.protocol));
|
||||||
return peerStat_;
|
return peerStat_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,7 @@
|
||||||
#include "CheckIntegrityEntry.h"
|
#include "CheckIntegrityEntry.h"
|
||||||
#include "Segment.h"
|
#include "Segment.h"
|
||||||
#include "DlAbortEx.h"
|
#include "DlAbortEx.h"
|
||||||
|
#include "uri.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -894,25 +895,25 @@ bool RequestGroupMan::doesOverallUploadSpeedExceed()
|
||||||
void RequestGroupMan::getUsedHosts
|
void RequestGroupMan::getUsedHosts
|
||||||
(std::vector<std::pair<size_t, std::string> >& usedHosts)
|
(std::vector<std::pair<size_t, std::string> >& usedHosts)
|
||||||
{
|
{
|
||||||
Request r;
|
|
||||||
for(std::deque<SharedHandle<RequestGroup> >::const_iterator i =
|
for(std::deque<SharedHandle<RequestGroup> >::const_iterator i =
|
||||||
requestGroups_.begin(), eoi = requestGroups_.end(); i != eoi; ++i) {
|
requestGroups_.begin(), eoi = requestGroups_.end(); i != eoi; ++i) {
|
||||||
const std::deque<SharedHandle<Request> >& inFlightReqs =
|
const std::deque<SharedHandle<Request> >& inFlightReqs =
|
||||||
(*i)->getDownloadContext()->getFirstFileEntry()->getInFlightRequests();
|
(*i)->getDownloadContext()->getFirstFileEntry()->getInFlightRequests();
|
||||||
for(std::deque<SharedHandle<Request> >::const_iterator j =
|
for(std::deque<SharedHandle<Request> >::const_iterator j =
|
||||||
inFlightReqs.begin(), eoj = inFlightReqs.end(); j != eoj; ++j) {
|
inFlightReqs.begin(), eoj = inFlightReqs.end(); j != eoj; ++j) {
|
||||||
if(r.setUri((*j)->getUri())) {
|
uri::UriStruct us;
|
||||||
|
if(uri::parse(us, (*j)->getUri())) {
|
||||||
std::vector<std::pair<size_t, std::string> >::iterator k;
|
std::vector<std::pair<size_t, std::string> >::iterator k;
|
||||||
std::vector<std::pair<size_t, std::string> >::iterator eok =
|
std::vector<std::pair<size_t, std::string> >::iterator eok =
|
||||||
usedHosts.end();
|
usedHosts.end();
|
||||||
for(k = usedHosts.begin(); k != eok; ++k) {
|
for(k = usedHosts.begin(); k != eok; ++k) {
|
||||||
if((*k).second == r.getHost()) {
|
if((*k).second == us.host) {
|
||||||
++(*k).first;
|
++(*k).first;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(k == eok) {
|
if(k == eok) {
|
||||||
usedHosts.push_back(std::make_pair(1, r.getHost()));
|
usedHosts.push_back(std::make_pair(1, us.host));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue