mirror of https://github.com/aria2/aria2
Replace timer facility with chrono lib
parent
2874f6ab09
commit
99cd73c092
|
@ -237,7 +237,8 @@ bool AbstractCommand::execute()
|
||||||
if (req_ && fileEntry_->getLength() > 0 &&
|
if (req_ && fileEntry_->getLength() > 0 &&
|
||||||
e_->getRequestGroupMan()->getMaxOverallDownloadSpeedLimit() == 0 &&
|
e_->getRequestGroupMan()->getMaxOverallDownloadSpeedLimit() == 0 &&
|
||||||
requestGroup_->getMaxDownloadSpeedLimit() == 0 &&
|
requestGroup_->getMaxDownloadSpeedLimit() == 0 &&
|
||||||
serverStatTimer_.difference(global::wallclock()) >= 10) {
|
serverStatTimer_.difference(global::wallclock()) >=
|
||||||
|
std::chrono::seconds(10)) {
|
||||||
serverStatTimer_ = global::wallclock();
|
serverStatTimer_ = global::wallclock();
|
||||||
std::vector<std::pair<size_t, std::string>> usedHosts;
|
std::vector<std::pair<size_t, std::string>> usedHosts;
|
||||||
if (getOption()->getAsBool(PREF_SELECT_LEAST_USED_HOST)) {
|
if (getOption()->getAsBool(PREF_SELECT_LEAST_USED_HOST)) {
|
||||||
|
@ -284,7 +285,7 @@ bool AbstractCommand::execute()
|
||||||
A2_LOG_DEBUG("All segments are ignored.");
|
A2_LOG_DEBUG("All segments are ignored.");
|
||||||
// This will execute other idle Commands and let them
|
// This will execute other idle Commands and let them
|
||||||
// finish quickly.
|
// finish quickly.
|
||||||
e_->setRefreshInterval(0);
|
e_->setRefreshInterval(std::chrono::milliseconds(0));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,7 +387,8 @@ bool AbstractCommand::execute()
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer wakeTime(global::wallclock());
|
Timer wakeTime(global::wallclock());
|
||||||
wakeTime.advance(getOption()->getAsInt(PREF_RETRY_WAIT));
|
wakeTime.advance(
|
||||||
|
std::chrono::seconds(getOption()->getAsInt(PREF_RETRY_WAIT)));
|
||||||
req_->setWakeTime(wakeTime);
|
req_->setWakeTime(wakeTime);
|
||||||
return prepareForRetry(0);
|
return prepareForRetry(0);
|
||||||
}
|
}
|
||||||
|
@ -401,7 +403,7 @@ bool AbstractCommand::execute()
|
||||||
A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, err);
|
A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, err);
|
||||||
}
|
}
|
||||||
requestGroup_->setHaltRequested(true);
|
requestGroup_->setHaltRequested(true);
|
||||||
getDownloadEngine()->setRefreshInterval(0);
|
getDownloadEngine()->setRefreshInterval(std::chrono::milliseconds(0));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -457,7 +459,7 @@ bool AbstractCommand::prepareForRetry(time_t wait)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// We don't use wait so that Command can be executed by
|
// We don't use wait so that Command can be executed by
|
||||||
// DownloadEngine::setRefreshInterval(0).
|
// DownloadEngine::setRefreshInterval(std::chrono::milliseconds(0)).
|
||||||
command->setStatus(Command::STATUS_INACTIVE);
|
command->setStatus(Command::STATUS_INACTIVE);
|
||||||
}
|
}
|
||||||
e_->addCommand(std::move(command));
|
e_->addCommand(std::move(command));
|
||||||
|
|
|
@ -83,7 +83,7 @@ private:
|
||||||
|
|
||||||
Timer checkPoint_;
|
Timer checkPoint_;
|
||||||
Timer serverStatTimer_;
|
Timer serverStatTimer_;
|
||||||
time_t timeout_;
|
std::chrono::seconds timeout_;
|
||||||
|
|
||||||
bool checkSocketIsReadable_;
|
bool checkSocketIsReadable_;
|
||||||
bool checkSocketIsWritable_;
|
bool checkSocketIsWritable_;
|
||||||
|
@ -185,14 +185,14 @@ public:
|
||||||
// check.
|
// check.
|
||||||
void swapSocket(std::shared_ptr<SocketCore>& socket);
|
void swapSocket(std::shared_ptr<SocketCore>& socket);
|
||||||
|
|
||||||
time_t getTimeout() const
|
std::chrono::seconds getTimeout() const
|
||||||
{
|
{
|
||||||
return timeout_;
|
return timeout_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTimeout(time_t timeout)
|
void setTimeout(std::chrono::seconds timeout)
|
||||||
{
|
{
|
||||||
timeout_ = timeout;
|
timeout_ = std::move(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void prepareForNextAction(std::unique_ptr<CheckIntegrityEntry> checkEntry);
|
void prepareForNextAction(std::unique_ptr<CheckIntegrityEntry> checkEntry);
|
||||||
|
|
|
@ -119,7 +119,8 @@ bool AbstractHttpServerResponseCommand::execute()
|
||||||
afterSend(httpServer_, e_);
|
afterSend(httpServer_, e_);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if(timeoutTimer_.difference(global::wallclock()) >= 30) {
|
if (timeoutTimer_.difference(global::wallclock()) >=
|
||||||
|
std::chrono::seconds(30)) {
|
||||||
A2_LOG_INFO(fmt("CUID#%" PRId64
|
A2_LOG_INFO(fmt("CUID#%" PRId64
|
||||||
" - HttpServer: Timeout while trasmitting response.",
|
" - HttpServer: Timeout while trasmitting response.",
|
||||||
getCuid()));
|
getCuid()));
|
||||||
|
|
|
@ -64,7 +64,7 @@ AbstractProxyRequestCommand::AbstractProxyRequestCommand
|
||||||
(std::make_shared<HttpConnection>
|
(std::make_shared<HttpConnection>
|
||||||
(cuid, s, std::make_shared<SocketRecvBuffer>(s)))
|
(cuid, s, std::make_shared<SocketRecvBuffer>(s)))
|
||||||
{
|
{
|
||||||
setTimeout(getOption()->getAsInt(PREF_CONNECT_TIMEOUT));
|
setTimeout(std::chrono::seconds(getOption()->getAsInt(PREF_CONNECT_TIMEOUT)));
|
||||||
disableReadCheckSocket();
|
disableReadCheckSocket();
|
||||||
setWriteCheckSocket(getSocket());
|
setWriteCheckSocket(getSocket());
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,10 +60,10 @@ ActivePeerConnectionCommand::ActivePeerConnectionCommand
|
||||||
(cuid_t cuid,
|
(cuid_t cuid,
|
||||||
RequestGroup* requestGroup,
|
RequestGroup* requestGroup,
|
||||||
DownloadEngine* e,
|
DownloadEngine* e,
|
||||||
time_t interval)
|
std::chrono::seconds interval)
|
||||||
: Command(cuid),
|
: Command(cuid),
|
||||||
requestGroup_(requestGroup),
|
requestGroup_(requestGroup),
|
||||||
interval_(interval),
|
interval_(std::move(interval)),
|
||||||
e_(e),
|
e_(e),
|
||||||
numNewConnection_(5)
|
numNewConnection_(5)
|
||||||
{
|
{
|
||||||
|
|
|
@ -59,7 +59,7 @@ private:
|
||||||
std::shared_ptr<PeerStorage> peerStorage_;
|
std::shared_ptr<PeerStorage> peerStorage_;
|
||||||
std::shared_ptr<BtAnnounce> btAnnounce_;
|
std::shared_ptr<BtAnnounce> btAnnounce_;
|
||||||
|
|
||||||
time_t interval_; // UNIT: sec
|
std::chrono::seconds interval_;
|
||||||
DownloadEngine* e_;
|
DownloadEngine* e_;
|
||||||
Timer checkPoint_;
|
Timer checkPoint_;
|
||||||
int numNewConnection_; // the number of the connection to establish.
|
int numNewConnection_; // the number of the connection to establish.
|
||||||
|
@ -67,7 +67,7 @@ public:
|
||||||
ActivePeerConnectionCommand(cuid_t cuid,
|
ActivePeerConnectionCommand(cuid_t cuid,
|
||||||
RequestGroup* requestGroup,
|
RequestGroup* requestGroup,
|
||||||
DownloadEngine* e,
|
DownloadEngine* e,
|
||||||
time_t interval);
|
std::chrono::seconds interval);
|
||||||
|
|
||||||
virtual ~ActivePeerConnectionCommand();
|
virtual ~ActivePeerConnectionCommand();
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,10 @@ std::string AdaptiveURISelector::select
|
||||||
return selected;
|
return selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
constexpr auto MAX_TIMEOUT = std::chrono::seconds(60);
|
||||||
|
} // namespace
|
||||||
|
|
||||||
void AdaptiveURISelector::mayRetryWithIncreasedTimeout(FileEntry* fileEntry)
|
void AdaptiveURISelector::mayRetryWithIncreasedTimeout(FileEntry* fileEntry)
|
||||||
{
|
{
|
||||||
if (requestGroup_->getTimeout()*2 >= MAX_TIMEOUT) return;
|
if (requestGroup_->getTimeout()*2 >= MAX_TIMEOUT) return;
|
||||||
|
@ -111,10 +115,11 @@ void AdaptiveURISelector::mayRetryWithIncreasedTimeout(FileEntry* fileEntry)
|
||||||
if(A2_LOG_DEBUG_ENABLED) {
|
if(A2_LOG_DEBUG_ENABLED) {
|
||||||
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) {
|
||||||
A2_LOG_DEBUG(fmt("AdaptiveURISelector: will retry server with increased"
|
A2_LOG_DEBUG(
|
||||||
" timeout (%ld s): %s",
|
fmt("AdaptiveURISelector: will retry server with increased"
|
||||||
static_cast<long int>(requestGroup_->getTimeout()),
|
" timeout (%ld s): %s",
|
||||||
(*i).c_str()));
|
static_cast<long int>(requestGroup_->getTimeout().count()),
|
||||||
|
(*i).c_str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
#include "URISelector.h"
|
#include "URISelector.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -53,8 +54,6 @@ private:
|
||||||
int nbServerToEvaluate_;
|
int nbServerToEvaluate_;
|
||||||
int nbConnections_;
|
int nbConnections_;
|
||||||
|
|
||||||
static const time_t MAX_TIMEOUT = 60;
|
|
||||||
|
|
||||||
void mayRetryWithIncreasedTimeout(FileEntry* fileEntry);
|
void mayRetryWithIncreasedTimeout(FileEntry* fileEntry);
|
||||||
|
|
||||||
std::string selectOne(const std::deque<std::string>& uris);
|
std::string selectOne(const std::deque<std::string>& uris);
|
||||||
|
|
|
@ -38,9 +38,9 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
AutoSaveCommand::AutoSaveCommand
|
AutoSaveCommand::AutoSaveCommand(cuid_t cuid, DownloadEngine* e,
|
||||||
(cuid_t cuid, DownloadEngine* e, time_t interval)
|
std::chrono::seconds interval)
|
||||||
: TimeBasedCommand(cuid, e, interval, true)
|
: TimeBasedCommand(cuid, e, std::move(interval), true)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
AutoSaveCommand::~AutoSaveCommand() {}
|
AutoSaveCommand::~AutoSaveCommand() {}
|
||||||
|
|
|
@ -42,7 +42,8 @@ namespace aria2 {
|
||||||
class AutoSaveCommand : public TimeBasedCommand
|
class AutoSaveCommand : public TimeBasedCommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AutoSaveCommand(cuid_t cuid, DownloadEngine* e, time_t interval);
|
AutoSaveCommand(cuid_t cuid, DownloadEngine* e,
|
||||||
|
std::chrono::seconds interval);
|
||||||
|
|
||||||
virtual ~AutoSaveCommand();
|
virtual ~AutoSaveCommand();
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,8 @@ bool BackupIPv4ConnectCommand::execute()
|
||||||
// TODO Although we check 300ms initial timeout as described in
|
// TODO Although we check 300ms initial timeout as described in
|
||||||
// RFC 6555, the interval will be much longer and around 1 second
|
// RFC 6555, the interval will be much longer and around 1 second
|
||||||
// due to the refresh interval mechanism in DownloadEngine.
|
// due to the refresh interval mechanism in DownloadEngine.
|
||||||
if(startTime_.differenceInMillis(global::wallclock()) >= 300) {
|
if(startTime_.difference(global::wallclock()) >=
|
||||||
|
std::chrono::milliseconds(300)) {
|
||||||
socket_ = std::make_shared<SocketCore>();
|
socket_ = std::make_shared<SocketCore>();
|
||||||
try {
|
try {
|
||||||
socket_->establishConnection(ipaddr_, port_);
|
socket_->establishConnection(ipaddr_, port_);
|
||||||
|
|
|
@ -81,7 +81,7 @@ private:
|
||||||
DownloadEngine* e_;
|
DownloadEngine* e_;
|
||||||
Timer startTime_;
|
Timer startTime_;
|
||||||
Timer timeoutCheck_;
|
Timer timeoutCheck_;
|
||||||
time_t timeout_;
|
std::chrono::seconds timeout_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -54,4 +54,6 @@ const std::string BtAnnounce::PEERS("peers");
|
||||||
|
|
||||||
const std::string BtAnnounce::PEERS6("peers6");
|
const std::string BtAnnounce::PEERS6("peers6");
|
||||||
|
|
||||||
|
constexpr std::chrono::seconds BtAnnounce::DEFAULT_ANNOUNCE_INTERVAL;
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -116,7 +116,7 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual void shuffleAnnounce() = 0;
|
virtual void shuffleAnnounce() = 0;
|
||||||
|
|
||||||
virtual void overrideMinInterval(time_t interval) = 0;
|
virtual void overrideMinInterval(std::chrono::seconds interval) = 0;
|
||||||
|
|
||||||
virtual void setTcpPort(uint16_t port) = 0;
|
virtual void setTcpPort(uint16_t port) = 0;
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ public:
|
||||||
|
|
||||||
static const std::string PEERS6;
|
static const std::string PEERS6;
|
||||||
|
|
||||||
static const time_t DEFAULT_ANNOUNCE_INTERVAL = 120;
|
constexpr static auto DEFAULT_ANNOUNCE_INTERVAL = std::chrono::seconds(120);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -47,17 +47,20 @@ namespace aria2 {
|
||||||
|
|
||||||
BtLeecherStateChoke::BtLeecherStateChoke()
|
BtLeecherStateChoke::BtLeecherStateChoke()
|
||||||
: round_(0),
|
: round_(0),
|
||||||
lastRound_(0)
|
lastRound_(Timer::zero())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
BtLeecherStateChoke::~BtLeecherStateChoke() {}
|
BtLeecherStateChoke::~BtLeecherStateChoke() {}
|
||||||
|
|
||||||
BtLeecherStateChoke::PeerEntry::PeerEntry(const std::shared_ptr<Peer>& peer):
|
BtLeecherStateChoke::PeerEntry::PeerEntry(const std::shared_ptr<Peer>& peer)
|
||||||
peer_(peer), downloadSpeed_(peer->calculateDownloadSpeed()),
|
: peer_(peer),
|
||||||
// peer must be interested to us and sent block in the last 30 seconds
|
downloadSpeed_(peer->calculateDownloadSpeed()),
|
||||||
regularUnchoker_
|
// peer must be interested to us and sent block in the last 30 seconds
|
||||||
(peer->peerInterested() &&
|
regularUnchoker_(peer->peerInterested() &&
|
||||||
peer->getLastDownloadUpdate().difference(global::wallclock()) < 30) {}
|
peer->getLastDownloadUpdate().difference(
|
||||||
|
global::wallclock()) < std::chrono::seconds(30))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
BtLeecherStateChoke::PeerEntry::PeerEntry(const PeerEntry& c)
|
BtLeecherStateChoke::PeerEntry::PeerEntry(const PeerEntry& c)
|
||||||
: peer_(c.peer_),
|
: peer_(c.peer_),
|
||||||
|
|
|
@ -47,11 +47,15 @@ namespace aria2 {
|
||||||
|
|
||||||
BtSeederStateChoke::BtSeederStateChoke()
|
BtSeederStateChoke::BtSeederStateChoke()
|
||||||
: round_(0),
|
: round_(0),
|
||||||
lastRound_(0)
|
lastRound_(Timer::zero())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
BtSeederStateChoke::~BtSeederStateChoke() {}
|
BtSeederStateChoke::~BtSeederStateChoke() {}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
constexpr auto TIME_FRAME = std::chrono::seconds(20);
|
||||||
|
} // namespace
|
||||||
|
|
||||||
BtSeederStateChoke::PeerEntry::PeerEntry
|
BtSeederStateChoke::PeerEntry::PeerEntry
|
||||||
(const std::shared_ptr<Peer>& peer):
|
(const std::shared_ptr<Peer>& peer):
|
||||||
peer_(peer),
|
peer_(peer),
|
||||||
|
|
|
@ -61,7 +61,6 @@ private:
|
||||||
bool recentUnchoking_;
|
bool recentUnchoking_;
|
||||||
int uploadSpeed_;
|
int uploadSpeed_;
|
||||||
|
|
||||||
const static time_t TIME_FRAME = 20;
|
|
||||||
public:
|
public:
|
||||||
PeerEntry(const std::shared_ptr<Peer>& peer);
|
PeerEntry(const std::shared_ptr<Peer>& peer);
|
||||||
PeerEntry(const PeerEntry& c);
|
PeerEntry(const PeerEntry& c);
|
||||||
|
|
|
@ -125,8 +125,9 @@ void BtSetup::setup(std::vector<std::unique_ptr<Command>>& commands,
|
||||||
commands.push_back(std::move(c));
|
commands.push_back(std::move(c));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto c = make_unique<ActivePeerConnectionCommand>
|
auto c = make_unique<ActivePeerConnectionCommand>(
|
||||||
(e->newCUID(), requestGroup, e, metadataGetMode?2:10);
|
e->newCUID(), requestGroup, e,
|
||||||
|
std::chrono::seconds(metadataGetMode ? 2 : 10));
|
||||||
c->setBtRuntime(btRuntime);
|
c->setBtRuntime(btRuntime);
|
||||||
c->setPieceStorage(pieceStorage);
|
c->setPieceStorage(pieceStorage);
|
||||||
c->setPeerStorage(peerStorage);
|
c->setPeerStorage(peerStorage);
|
||||||
|
@ -158,8 +159,8 @@ void BtSetup::setup(std::vector<std::unique_ptr<Command>>& commands,
|
||||||
if(!metadataGetMode) {
|
if(!metadataGetMode) {
|
||||||
auto unionCri = make_unique<UnionSeedCriteria>();
|
auto unionCri = make_unique<UnionSeedCriteria>();
|
||||||
if(option->defined(PREF_SEED_TIME)) {
|
if(option->defined(PREF_SEED_TIME)) {
|
||||||
unionCri->addSeedCriteria(make_unique<TimeSeedCriteria>
|
unionCri->addSeedCriteria(make_unique<TimeSeedCriteria>(
|
||||||
(option->getAsInt(PREF_SEED_TIME)*60));
|
std::chrono::seconds(option->getAsInt(PREF_SEED_TIME) * 60)));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
double ratio = option->getAsDouble(PREF_SEED_RATIO);
|
double ratio = option->getAsDouble(PREF_SEED_RATIO);
|
||||||
|
@ -271,10 +272,10 @@ void BtSetup::setup(std::vector<std::unique_ptr<Command>>& commands,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
time_t btStopTimeout = option->getAsInt(PREF_BT_STOP_TIMEOUT);
|
auto btStopTimeout = option->getAsInt(PREF_BT_STOP_TIMEOUT);
|
||||||
if(btStopTimeout > 0) {
|
if(btStopTimeout > 0) {
|
||||||
auto stopDownloadCommand = make_unique<BtStopDownloadCommand>
|
auto stopDownloadCommand = make_unique<BtStopDownloadCommand>
|
||||||
(e->newCUID(), requestGroup, e, btStopTimeout);
|
(e->newCUID(), requestGroup, e, std::chrono::seconds(btStopTimeout));
|
||||||
stopDownloadCommand->setBtRuntime(btRuntime);
|
stopDownloadCommand->setBtRuntime(btRuntime);
|
||||||
stopDownloadCommand->setPieceStorage(pieceStorage);
|
stopDownloadCommand->setPieceStorage(pieceStorage);
|
||||||
commands.push_back(std::move(stopDownloadCommand));
|
commands.push_back(std::move(stopDownloadCommand));
|
||||||
|
|
|
@ -50,10 +50,10 @@ BtStopDownloadCommand::BtStopDownloadCommand
|
||||||
(cuid_t cuid,
|
(cuid_t cuid,
|
||||||
RequestGroup* requestGroup,
|
RequestGroup* requestGroup,
|
||||||
DownloadEngine* e,
|
DownloadEngine* e,
|
||||||
time_t timeout)
|
std::chrono::seconds timeout)
|
||||||
: TimeBasedCommand(cuid, e, 1),
|
: TimeBasedCommand(cuid, e, std::chrono::seconds(1)),
|
||||||
requestGroup_(requestGroup),
|
requestGroup_(requestGroup),
|
||||||
timeout_(timeout)
|
timeout_(std::move(timeout))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void BtStopDownloadCommand::preProcess()
|
void BtStopDownloadCommand::preProcess()
|
||||||
|
@ -66,7 +66,7 @@ void BtStopDownloadCommand::preProcess()
|
||||||
" --bt-stop-timeout option."),
|
" --bt-stop-timeout option."),
|
||||||
GroupId::toHex(requestGroup_->getGID()).c_str()));
|
GroupId::toHex(requestGroup_->getGID()).c_str()));
|
||||||
requestGroup_->setForceHaltRequested(true);
|
requestGroup_->setForceHaltRequested(true);
|
||||||
getDownloadEngine()->setRefreshInterval(0);
|
getDownloadEngine()->setRefreshInterval(std::chrono::milliseconds(0));
|
||||||
enableExit();
|
enableExit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ class BtStopDownloadCommand:public TimeBasedCommand {
|
||||||
private:
|
private:
|
||||||
RequestGroup* requestGroup_;
|
RequestGroup* requestGroup_;
|
||||||
|
|
||||||
time_t timeout_;
|
std::chrono::seconds timeout_;
|
||||||
|
|
||||||
Timer checkPoint_;
|
Timer checkPoint_;
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ public:
|
||||||
(cuid_t cuid,
|
(cuid_t cuid,
|
||||||
RequestGroup* requestGroup,
|
RequestGroup* requestGroup,
|
||||||
DownloadEngine* e,
|
DownloadEngine* e,
|
||||||
time_t timeout);
|
std::chrono::seconds timeout);
|
||||||
|
|
||||||
virtual void preProcess() CXX11_OVERRIDE;
|
virtual void preProcess() CXX11_OVERRIDE;
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ ConnectCommand::ConnectCommand(cuid_t cuid,
|
||||||
: AbstractCommand(cuid, req, fileEntry, requestGroup, e, s),
|
: AbstractCommand(cuid, req, fileEntry, requestGroup, e, s),
|
||||||
proxyRequest_(proxyRequest)
|
proxyRequest_(proxyRequest)
|
||||||
{
|
{
|
||||||
setTimeout(getOption()->getAsInt(PREF_CONNECT_TIMEOUT));
|
setTimeout(std::chrono::seconds(getOption()->getAsInt(PREF_CONNECT_TIMEOUT)));
|
||||||
disableReadCheckSocket();
|
disableReadCheckSocket();
|
||||||
setWriteCheckSocket(getSocket());
|
setWriteCheckSocket(getSocket());
|
||||||
}
|
}
|
||||||
|
|
|
@ -265,10 +265,10 @@ void printProgressSummary(const RequestGroupList& groups, size_t cols,
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
ConsoleStatCalc::ConsoleStatCalc(time_t summaryInterval,
|
ConsoleStatCalc::ConsoleStatCalc(std::chrono::seconds summaryInterval,
|
||||||
bool colorOutput,
|
bool colorOutput,
|
||||||
bool humanReadable):
|
bool humanReadable):
|
||||||
summaryInterval_(summaryInterval),
|
summaryInterval_(std::move(summaryInterval)),
|
||||||
readoutVisibility_(true),
|
readoutVisibility_(true),
|
||||||
truncate_(true),
|
truncate_(true),
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
|
@ -288,7 +288,8 @@ ConsoleStatCalc::ConsoleStatCalc(time_t summaryInterval,
|
||||||
void
|
void
|
||||||
ConsoleStatCalc::calculateStat(const DownloadEngine* e)
|
ConsoleStatCalc::calculateStat(const DownloadEngine* e)
|
||||||
{
|
{
|
||||||
if(cp_.differenceInMillis(global::wallclock())+A2_DELTA_MILLIS < 1000) {
|
if(cp_.difference(global::wallclock()) + A2_DELTA_MILLIS <
|
||||||
|
std::chrono::milliseconds(1000)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cp_ = global::wallclock();
|
cp_ = global::wallclock();
|
||||||
|
@ -317,8 +318,8 @@ ConsoleStatCalc::calculateStat(const DownloadEngine* e)
|
||||||
}
|
}
|
||||||
ColorizedStream o;
|
ColorizedStream o;
|
||||||
if(e->getRequestGroupMan()->countRequestGroup() > 0) {
|
if(e->getRequestGroupMan()->countRequestGroup() > 0) {
|
||||||
if((summaryInterval_ > 0) &&
|
if((summaryInterval_ > std::chrono::seconds(0)) &&
|
||||||
lastSummaryNotified_.differenceInMillis(global::wallclock())+
|
lastSummaryNotified_.difference(global::wallclock())+
|
||||||
A2_DELTA_MILLIS >= summaryInterval_*1000) {
|
A2_DELTA_MILLIS >= summaryInterval_*1000) {
|
||||||
lastSummaryNotified_ = global::wallclock();
|
lastSummaryNotified_ = global::wallclock();
|
||||||
printProgressSummary(e->getRequestGroupMan()->getRequestGroups(), cols, e,
|
printProgressSummary(e->getRequestGroupMan()->getRequestGroups(), cols, e,
|
||||||
|
|
|
@ -61,7 +61,7 @@ private:
|
||||||
|
|
||||||
Timer lastSummaryNotified_;
|
Timer lastSummaryNotified_;
|
||||||
|
|
||||||
time_t summaryInterval_;
|
std::chrono::seconds summaryInterval_;
|
||||||
|
|
||||||
std::unique_ptr<SizeFormatter> sizeFormatter_;
|
std::unique_ptr<SizeFormatter> sizeFormatter_;
|
||||||
bool readoutVisibility_;
|
bool readoutVisibility_;
|
||||||
|
@ -69,7 +69,7 @@ private:
|
||||||
bool isTTY_;
|
bool isTTY_;
|
||||||
bool colorOutput_;
|
bool colorOutput_;
|
||||||
public:
|
public:
|
||||||
ConsoleStatCalc(time_t summaryInterval, bool colorOutput = true,
|
ConsoleStatCalc(std::chrono::seconds summaryInterval, bool colorOutput = true,
|
||||||
bool humanReadable = true);
|
bool humanReadable = true);
|
||||||
|
|
||||||
virtual ~ConsoleStatCalc() {}
|
virtual ~ConsoleStatCalc() {}
|
||||||
|
|
|
@ -57,8 +57,8 @@
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
DHTAutoSaveCommand::DHTAutoSaveCommand
|
DHTAutoSaveCommand::DHTAutoSaveCommand
|
||||||
(cuid_t cuid, DownloadEngine* e, int family, time_t interval)
|
(cuid_t cuid, DownloadEngine* e, int family, std::chrono::seconds interval)
|
||||||
: TimeBasedCommand{cuid, e, interval},
|
: TimeBasedCommand{cuid, e, std::move(interval)},
|
||||||
family_{family},
|
family_{family},
|
||||||
routingTable_{nullptr}
|
routingTable_{nullptr}
|
||||||
{}
|
{}
|
||||||
|
|
|
@ -56,7 +56,7 @@ private:
|
||||||
void save();
|
void save();
|
||||||
public:
|
public:
|
||||||
DHTAutoSaveCommand
|
DHTAutoSaveCommand
|
||||||
(cuid_t cuid, DownloadEngine* e, int family, time_t interval);
|
(cuid_t cuid, DownloadEngine* e, int family, std::chrono::seconds interval);
|
||||||
|
|
||||||
virtual ~DHTAutoSaveCommand();
|
virtual ~DHTAutoSaveCommand();
|
||||||
|
|
||||||
|
|
|
@ -43,8 +43,8 @@
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
DHTBucketRefreshCommand::DHTBucketRefreshCommand
|
DHTBucketRefreshCommand::DHTBucketRefreshCommand
|
||||||
(cuid_t cuid, DownloadEngine* e, time_t interval)
|
(cuid_t cuid, DownloadEngine* e, std::chrono::seconds interval)
|
||||||
: TimeBasedCommand{cuid, e, interval},
|
: TimeBasedCommand{cuid, e, std::move(interval)},
|
||||||
routingTable_{nullptr},
|
routingTable_{nullptr},
|
||||||
taskQueue_{nullptr},
|
taskQueue_{nullptr},
|
||||||
taskFactory_{nullptr}
|
taskFactory_{nullptr}
|
||||||
|
|
|
@ -53,7 +53,8 @@ private:
|
||||||
|
|
||||||
DHTTaskFactory* taskFactory_;
|
DHTTaskFactory* taskFactory_;
|
||||||
public:
|
public:
|
||||||
DHTBucketRefreshCommand(cuid_t cuid, DownloadEngine* e, time_t interval);
|
DHTBucketRefreshCommand(cuid_t cuid, DownloadEngine* e,
|
||||||
|
std::chrono::seconds interval);
|
||||||
|
|
||||||
virtual ~DHTBucketRefreshCommand();
|
virtual ~DHTBucketRefreshCommand();
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,9 @@
|
||||||
#ifndef D_DHT_CONSTANTS_H
|
#ifndef D_DHT_CONSTANTS_H
|
||||||
#define D_DHT_CONSTANTS_H
|
#define D_DHT_CONSTANTS_H
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
#include "TimerA2.h"
|
||||||
|
|
||||||
// Increment this if major improvements or bug fixes are made in DHT
|
// Increment this if major improvements or bug fixes are made in DHT
|
||||||
// code. This is 2 bytes unsigned integer.
|
// code. This is 2 bytes unsigned integer.
|
||||||
#define DHT_VERSION 3U
|
#define DHT_VERSION 3U
|
||||||
|
@ -46,20 +49,20 @@
|
||||||
#define DHT_TOKEN_LENGTH 4
|
#define DHT_TOKEN_LENGTH 4
|
||||||
|
|
||||||
// See --dht-message-timeout option.
|
// See --dht-message-timeout option.
|
||||||
#define DHT_MESSAGE_TIMEOUT 10
|
constexpr auto DHT_MESSAGE_TIMEOUT = std::chrono::seconds(10);
|
||||||
|
|
||||||
#define DHT_NODE_CONTACT_INTERVAL (15*60)
|
constexpr auto DHT_NODE_CONTACT_INTERVAL = std::chrono::minutes(15);
|
||||||
|
|
||||||
#define DHT_BUCKET_REFRESH_INTERVAL (15*60)
|
constexpr auto DHT_BUCKET_REFRESH_INTERVAL = std::chrono::minutes(15);
|
||||||
|
|
||||||
#define DHT_BUCKET_REFRESH_CHECK_INTERVAL (5*60)
|
constexpr auto DHT_BUCKET_REFRESH_CHECK_INTERVAL = std::chrono::minutes(5);
|
||||||
|
|
||||||
#define DHT_PEER_ANNOUNCE_PURGE_INTERVAL (30*60)
|
constexpr auto DHT_PEER_ANNOUNCE_PURGE_INTERVAL = std::chrono::minutes(30);
|
||||||
|
|
||||||
#define DHT_PEER_ANNOUNCE_INTERVAL (15*60)
|
constexpr auto DHT_PEER_ANNOUNCE_INTERVAL = std::chrono::minutes(15);
|
||||||
|
|
||||||
#define DHT_PEER_ANNOUNCE_CHECK_INTERVAL (5*60)
|
constexpr auto DHT_PEER_ANNOUNCE_CHECK_INTERVAL = std::chrono::minutes(5);
|
||||||
|
|
||||||
#define DHT_TOKEN_UPDATE_INTERVAL (10*60)
|
constexpr auto DHT_TOKEN_UPDATE_INTERVAL = std::chrono::minutes(10);
|
||||||
|
|
||||||
#endif // D_DHT_CONSTANTS_H
|
#endif // D_DHT_CONSTANTS_H
|
||||||
|
|
|
@ -55,13 +55,13 @@ namespace aria2 {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
const time_t GET_PEER_INTERVAL = (15*60);
|
constexpr auto GET_PEER_INTERVAL = std::chrono::minutes(15);
|
||||||
// Interval when the size of peer list is low.
|
// Interval when the size of peer list is low.
|
||||||
const time_t GET_PEER_INTERVAL_LOW = (5*60);
|
constexpr auto GET_PEER_INTERVAL_LOW = std::chrono::minutes(5);
|
||||||
// Interval when the peer list is empty.
|
// Interval when the peer list is empty.
|
||||||
const time_t GET_PEER_INTERVAL_ZERO = 60;
|
constexpr auto GET_PEER_INTERVAL_ZERO = std::chrono::minutes(1);
|
||||||
// Interval for retry.
|
// Interval for retry.
|
||||||
const time_t GET_PEER_INTERVAL_RETRY = 5;
|
constexpr auto GET_PEER_INTERVAL_RETRY = std::chrono::seconds(5);
|
||||||
// Maximum retries. Try more than 5 to drop bad node.
|
// Maximum retries. Try more than 5 to drop bad node.
|
||||||
const int MAX_RETRIES = 10;
|
const int MAX_RETRIES = 10;
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ DHTGetPeersCommand::DHTGetPeersCommand
|
||||||
taskQueue_{nullptr},
|
taskQueue_{nullptr},
|
||||||
taskFactory_{nullptr},
|
taskFactory_{nullptr},
|
||||||
numRetry_{0},
|
numRetry_{0},
|
||||||
lastGetPeerTime_{0}
|
lastGetPeerTime_{Timer::zero()}
|
||||||
{
|
{
|
||||||
requestGroup_->increaseNumCommand();
|
requestGroup_->increaseNumCommand();
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ bool DHTGetPeersCommand::execute()
|
||||||
if(btRuntime_->isHalt()) {
|
if(btRuntime_->isHalt()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
time_t elapsed = lastGetPeerTime_.difference(global::wallclock());
|
auto elapsed = lastGetPeerTime_.difference(global::wallclock());
|
||||||
if(!task_ &&
|
if(!task_ &&
|
||||||
(elapsed >= GET_PEER_INTERVAL ||
|
(elapsed >= GET_PEER_INTERVAL ||
|
||||||
(((btRuntime_->lessThanMinPeers() &&
|
(((btRuntime_->lessThanMinPeers() &&
|
||||||
|
|
|
@ -52,7 +52,7 @@ public:
|
||||||
|
|
||||||
virtual void
|
virtual void
|
||||||
addMessageToQueue(std::unique_ptr<DHTMessage> message,
|
addMessageToQueue(std::unique_ptr<DHTMessage> message,
|
||||||
time_t timeout,
|
std::chrono::seconds timeout,
|
||||||
std::unique_ptr<DHTMessageCallback> callback =
|
std::unique_ptr<DHTMessageCallback> callback =
|
||||||
std::unique_ptr<DHTMessageCallback>{}) = 0;
|
std::unique_ptr<DHTMessageCallback>{}) = 0;
|
||||||
|
|
||||||
|
|
|
@ -56,11 +56,11 @@ DHTMessageDispatcherImpl::DHTMessageDispatcherImpl
|
||||||
void
|
void
|
||||||
DHTMessageDispatcherImpl::addMessageToQueue
|
DHTMessageDispatcherImpl::addMessageToQueue
|
||||||
(std::unique_ptr<DHTMessage> message,
|
(std::unique_ptr<DHTMessage> message,
|
||||||
time_t timeout,
|
std::chrono::seconds timeout,
|
||||||
std::unique_ptr<DHTMessageCallback> callback)
|
std::unique_ptr<DHTMessageCallback> callback)
|
||||||
{
|
{
|
||||||
messageQueue_.push_back(make_unique<DHTMessageEntry>
|
messageQueue_.push_back(make_unique<DHTMessageEntry>(
|
||||||
(std::move(message), timeout, std::move(callback)));
|
std::move(message), std::move(timeout), std::move(callback)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -92,7 +92,7 @@ bool DHTMessageDispatcherImpl::sendMessage(DHTMessageEntry* entry)
|
||||||
// DHTTask(such as DHTAbstractNodeLookupTask) don't finish
|
// DHTTask(such as DHTAbstractNodeLookupTask) don't finish
|
||||||
// forever.
|
// forever.
|
||||||
if(!entry->message->isReply()) {
|
if(!entry->message->isReply()) {
|
||||||
tracker_->addMessage(entry->message.get(), 0,
|
tracker_->addMessage(entry->message.get(), std::chrono::seconds(0),
|
||||||
std::move(entry->callback));
|
std::move(entry->callback));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ private:
|
||||||
|
|
||||||
std::deque<std::unique_ptr<DHTMessageEntry>> messageQueue_;
|
std::deque<std::unique_ptr<DHTMessageEntry>> messageQueue_;
|
||||||
|
|
||||||
time_t timeout_;
|
std::chrono::seconds timeout_;
|
||||||
|
|
||||||
bool sendMessage(DHTMessageEntry* msg);
|
bool sendMessage(DHTMessageEntry* msg);
|
||||||
public:
|
public:
|
||||||
|
@ -57,7 +57,7 @@ public:
|
||||||
|
|
||||||
virtual void
|
virtual void
|
||||||
addMessageToQueue(std::unique_ptr<DHTMessage> message,
|
addMessageToQueue(std::unique_ptr<DHTMessage> message,
|
||||||
time_t timeout,
|
std::chrono::seconds timeout,
|
||||||
std::unique_ptr<DHTMessageCallback> callback =
|
std::unique_ptr<DHTMessageCallback> callback =
|
||||||
std::unique_ptr<DHTMessageCallback>{})
|
std::unique_ptr<DHTMessageCallback>{})
|
||||||
CXX11_OVERRIDE;
|
CXX11_OVERRIDE;
|
||||||
|
@ -72,9 +72,9 @@ public:
|
||||||
|
|
||||||
virtual size_t countMessageInQueue() const CXX11_OVERRIDE;
|
virtual size_t countMessageInQueue() const CXX11_OVERRIDE;
|
||||||
|
|
||||||
void setTimeout(time_t timeout)
|
void setTimeout(std::chrono::seconds timeout)
|
||||||
{
|
{
|
||||||
timeout_ = timeout;
|
timeout_ = std::move(timeout);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -41,10 +41,10 @@ namespace aria2 {
|
||||||
|
|
||||||
DHTMessageEntry::DHTMessageEntry
|
DHTMessageEntry::DHTMessageEntry
|
||||||
(std::unique_ptr<DHTMessage> message,
|
(std::unique_ptr<DHTMessage> message,
|
||||||
time_t timeout,
|
std::chrono::seconds timeout,
|
||||||
std::unique_ptr<DHTMessageCallback> callback)
|
std::unique_ptr<DHTMessageCallback> callback)
|
||||||
: message{std::move(message)},
|
: message{std::move(message)},
|
||||||
timeout{timeout},
|
timeout{std::move(timeout)},
|
||||||
callback{std::move(callback)}
|
callback{std::move(callback)}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
|
@ -48,11 +48,11 @@ class DHTMessageCallback;
|
||||||
|
|
||||||
struct DHTMessageEntry {
|
struct DHTMessageEntry {
|
||||||
std::unique_ptr<DHTMessage> message;
|
std::unique_ptr<DHTMessage> message;
|
||||||
time_t timeout;
|
std::chrono::seconds timeout;
|
||||||
std::unique_ptr<DHTMessageCallback> callback;
|
std::unique_ptr<DHTMessageCallback> callback;
|
||||||
|
|
||||||
DHTMessageEntry(std::unique_ptr<DHTMessage> message,
|
DHTMessageEntry(std::unique_ptr<DHTMessage> message,
|
||||||
time_t timeout,
|
std::chrono::seconds timeout,
|
||||||
std::unique_ptr<DHTMessageCallback> callback);
|
std::unique_ptr<DHTMessageCallback> callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -58,14 +58,14 @@ DHTMessageTracker::DHTMessageTracker()
|
||||||
|
|
||||||
void DHTMessageTracker::addMessage
|
void DHTMessageTracker::addMessage
|
||||||
(DHTMessage* message,
|
(DHTMessage* message,
|
||||||
time_t timeout,
|
std::chrono::seconds timeout,
|
||||||
std::unique_ptr<DHTMessageCallback> callback)
|
std::unique_ptr<DHTMessageCallback> callback)
|
||||||
{
|
{
|
||||||
entries_.push_back(make_unique<DHTMessageTrackerEntry>
|
entries_.push_back(make_unique<DHTMessageTrackerEntry>
|
||||||
(message->getRemoteNode(),
|
(message->getRemoteNode(),
|
||||||
message->getTransactionID(),
|
message->getTransactionID(),
|
||||||
message->getMessageType(),
|
message->getMessageType(),
|
||||||
timeout, std::move(callback)));
|
std::move(timeout), std::move(callback)));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<std::unique_ptr<DHTResponseMessage>,
|
std::pair<std::unique_ptr<DHTResponseMessage>,
|
||||||
|
@ -93,8 +93,9 @@ DHTMessageTracker::messageArrived
|
||||||
targetNode->getIPAddress(),
|
targetNode->getIPAddress(),
|
||||||
targetNode->getPort());
|
targetNode->getPort());
|
||||||
|
|
||||||
int64_t rtt = entry->getElapsedMillis();
|
auto rtt = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
A2_LOG_DEBUG(fmt("RTT is %" PRId64 "", rtt));
|
entry->getElapsed());
|
||||||
|
A2_LOG_DEBUG(fmt("RTT is %" PRId64 "", rtt.count()));
|
||||||
message->getRemoteNode()->updateRTT(rtt);
|
message->getRemoteNode()->updateRTT(rtt);
|
||||||
if(*targetNode != *message->getRemoteNode()) {
|
if(*targetNode != *message->getRemoteNode()) {
|
||||||
// Node ID has changed. Drop previous node ID from
|
// Node ID has changed. Drop previous node ID from
|
||||||
|
@ -124,7 +125,8 @@ void DHTMessageTracker::handleTimeoutEntry(DHTMessageTrackerEntry* entry)
|
||||||
auto& node = entry->getTargetNode();
|
auto& node = entry->getTargetNode();
|
||||||
A2_LOG_DEBUG(fmt("Message timeout: To:%s:%u",
|
A2_LOG_DEBUG(fmt("Message timeout: To:%s:%u",
|
||||||
node->getIPAddress().c_str(), node->getPort()));
|
node->getIPAddress().c_str(), node->getPort()));
|
||||||
node->updateRTT(entry->getElapsedMillis());
|
node->updateRTT(std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
|
entry->getElapsed()));
|
||||||
node->timeout();
|
node->timeout();
|
||||||
if(node->isBad()) {
|
if(node->isBad()) {
|
||||||
A2_LOG_DEBUG(fmt("Marked bad: %s:%u",
|
A2_LOG_DEBUG(fmt("Marked bad: %s:%u",
|
||||||
|
|
|
@ -64,7 +64,7 @@ public:
|
||||||
DHTMessageTracker();
|
DHTMessageTracker();
|
||||||
|
|
||||||
void addMessage(DHTMessage* message,
|
void addMessage(DHTMessage* message,
|
||||||
time_t timeout,
|
std::chrono::seconds timeout,
|
||||||
std::unique_ptr<DHTMessageCallback> callback =
|
std::unique_ptr<DHTMessageCallback> callback =
|
||||||
std::unique_ptr<DHTMessageCallback>{});
|
std::unique_ptr<DHTMessageCallback>{});
|
||||||
|
|
||||||
|
|
|
@ -46,14 +46,14 @@ DHTMessageTrackerEntry::DHTMessageTrackerEntry
|
||||||
(std::shared_ptr<DHTNode> targetNode,
|
(std::shared_ptr<DHTNode> targetNode,
|
||||||
std::string transactionID,
|
std::string transactionID,
|
||||||
std::string messageType,
|
std::string messageType,
|
||||||
time_t timeout,
|
std::chrono::seconds timeout,
|
||||||
std::unique_ptr<DHTMessageCallback> callback)
|
std::unique_ptr<DHTMessageCallback> callback)
|
||||||
: targetNode_{std::move(targetNode)},
|
: targetNode_{std::move(targetNode)},
|
||||||
transactionID_{std::move(transactionID)},
|
transactionID_{std::move(transactionID)},
|
||||||
messageType_{std::move(messageType)},
|
messageType_{std::move(messageType)},
|
||||||
callback_{std::move(callback)},
|
callback_{std::move(callback)},
|
||||||
dispatchedTime_{global::wallclock()},
|
dispatchedTime_{global::wallclock()},
|
||||||
timeout_{timeout}
|
timeout_{std::move(timeout)}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool DHTMessageTrackerEntry::isTimeout() const
|
bool DHTMessageTrackerEntry::isTimeout() const
|
||||||
|
@ -80,9 +80,9 @@ bool DHTMessageTrackerEntry::match(const std::string& transactionID, const std::
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t DHTMessageTrackerEntry::getElapsedMillis() const
|
Timer::Clock::duration DHTMessageTrackerEntry::getElapsed() const
|
||||||
{
|
{
|
||||||
return dispatchedTime_.differenceInMillis(global::wallclock());
|
return dispatchedTime_.difference(global::wallclock());
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::shared_ptr<DHTNode>& DHTMessageTrackerEntry::getTargetNode() const
|
const std::shared_ptr<DHTNode>& DHTMessageTrackerEntry::getTargetNode() const
|
||||||
|
|
|
@ -61,12 +61,12 @@ private:
|
||||||
|
|
||||||
Timer dispatchedTime_;
|
Timer dispatchedTime_;
|
||||||
|
|
||||||
time_t timeout_;
|
std::chrono::seconds timeout_;
|
||||||
public:
|
public:
|
||||||
DHTMessageTrackerEntry(std::shared_ptr<DHTNode> targetNode,
|
DHTMessageTrackerEntry(std::shared_ptr<DHTNode> targetNode,
|
||||||
std::string transactionID,
|
std::string transactionID,
|
||||||
std::string messageType,
|
std::string messageType,
|
||||||
time_t timeout,
|
std::chrono::seconds timeout,
|
||||||
std::unique_ptr<DHTMessageCallback> callback =
|
std::unique_ptr<DHTMessageCallback> callback =
|
||||||
std::unique_ptr<DHTMessageCallback>{});
|
std::unique_ptr<DHTMessageCallback>{});
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ public:
|
||||||
const std::string& getMessageType() const;
|
const std::string& getMessageType() const;
|
||||||
const std::unique_ptr<DHTMessageCallback>& getCallback() const;
|
const std::unique_ptr<DHTMessageCallback>& getCallback() const;
|
||||||
std::unique_ptr<DHTMessageCallback> popCallback();
|
std::unique_ptr<DHTMessageCallback> popCallback();
|
||||||
int64_t getElapsedMillis() const;
|
Timer::Clock::duration getElapsed() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -43,12 +43,14 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
DHTNode::DHTNode():port_(0), rtt_(0), condition_(0), lastContact_(0)
|
DHTNode::DHTNode()
|
||||||
|
: port_(0), rtt_(0), condition_(0), lastContact_(Timer::zero())
|
||||||
{
|
{
|
||||||
generateID();
|
generateID();
|
||||||
}
|
}
|
||||||
|
|
||||||
DHTNode::DHTNode(const unsigned char* id):port_(0), rtt_(0), condition_(1), lastContact_(0)
|
DHTNode::DHTNode(const unsigned char* id)
|
||||||
|
: port_(0), rtt_(0), condition_(1), lastContact_(Timer::zero())
|
||||||
{
|
{
|
||||||
memcpy(id_, id, DHT_ID_LENGTH);
|
memcpy(id_, id, DHT_ID_LENGTH);
|
||||||
}
|
}
|
||||||
|
@ -122,12 +124,12 @@ void DHTNode::timeout()
|
||||||
|
|
||||||
std::string DHTNode::toString() const
|
std::string DHTNode::toString() const
|
||||||
{
|
{
|
||||||
return fmt("DHTNode ID=%s, Host=%s(%u), Condition=%d, RTT=%d",
|
return fmt("DHTNode ID=%s, Host=%s(%u), Condition=%d, RTT=%ld",
|
||||||
util::toHex(id_, DHT_ID_LENGTH).c_str(),
|
util::toHex(id_, DHT_ID_LENGTH).c_str(),
|
||||||
ipaddr_.c_str(),
|
ipaddr_.c_str(),
|
||||||
port_,
|
port_,
|
||||||
condition_,
|
condition_,
|
||||||
rtt_);
|
rtt_.count());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTNode::setID(const unsigned char* id)
|
void DHTNode::setID(const unsigned char* id)
|
||||||
|
|
|
@ -52,8 +52,7 @@ private:
|
||||||
|
|
||||||
uint16_t port_;
|
uint16_t port_;
|
||||||
|
|
||||||
// in milli sec
|
std::chrono::milliseconds rtt_;
|
||||||
int rtt_;
|
|
||||||
|
|
||||||
int condition_;
|
int condition_;
|
||||||
|
|
||||||
|
@ -75,9 +74,9 @@ public:
|
||||||
return id_;
|
return id_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateRTT(int millisec)
|
void updateRTT(std::chrono::milliseconds t)
|
||||||
{
|
{
|
||||||
rtt_ = millisec;
|
rtt_ = std::move(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& getIPAddress() const
|
const std::string& getIPAddress() const
|
||||||
|
|
|
@ -44,8 +44,8 @@
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
DHTPeerAnnounceCommand::DHTPeerAnnounceCommand
|
DHTPeerAnnounceCommand::DHTPeerAnnounceCommand
|
||||||
(cuid_t cuid, DownloadEngine* e, time_t interval)
|
(cuid_t cuid, DownloadEngine* e, std::chrono::seconds interval)
|
||||||
: TimeBasedCommand{cuid, e, interval},
|
: TimeBasedCommand{cuid, e, std::move(interval)},
|
||||||
peerAnnounceStorage_{nullptr}
|
peerAnnounceStorage_{nullptr}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,8 @@ class DHTPeerAnnounceCommand:public TimeBasedCommand {
|
||||||
private:
|
private:
|
||||||
DHTPeerAnnounceStorage* peerAnnounceStorage_;
|
DHTPeerAnnounceStorage* peerAnnounceStorage_;
|
||||||
public:
|
public:
|
||||||
DHTPeerAnnounceCommand(cuid_t cuid, DownloadEngine* e, time_t interval);
|
DHTPeerAnnounceCommand(cuid_t cuid, DownloadEngine* e,
|
||||||
|
std::chrono::seconds interval);
|
||||||
|
|
||||||
virtual ~DHTPeerAnnounceCommand();
|
virtual ~DHTPeerAnnounceCommand();
|
||||||
|
|
||||||
|
|
|
@ -66,28 +66,16 @@ size_t DHTPeerAnnounceEntry::countPeerAddrEntry() const
|
||||||
return peerAddrEntries_.size();
|
return peerAddrEntries_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
void DHTPeerAnnounceEntry::removeStalePeerAddrEntry(
|
||||||
class FindStaleEntry {
|
const std::chrono::seconds& timeout)
|
||||||
private:
|
|
||||||
time_t timeout_;
|
|
||||||
public:
|
|
||||||
FindStaleEntry(time_t timeout):timeout_(timeout) {}
|
|
||||||
|
|
||||||
bool operator()(const PeerAddrEntry& entry) const
|
|
||||||
{
|
|
||||||
if(entry.getLastUpdated().difference(global::wallclock()) >= timeout_) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
void DHTPeerAnnounceEntry::removeStalePeerAddrEntry(time_t timeout)
|
|
||||||
{
|
{
|
||||||
peerAddrEntries_.erase(std::remove_if(peerAddrEntries_.begin(), peerAddrEntries_.end(),
|
peerAddrEntries_.erase(
|
||||||
FindStaleEntry(timeout)), peerAddrEntries_.end());
|
std::remove_if(std::begin(peerAddrEntries_), std::end(peerAddrEntries_),
|
||||||
|
[&timeout](const PeerAddrEntry& entry) {
|
||||||
|
return entry.getLastUpdated().difference(global::wallclock()) >=
|
||||||
|
timeout;
|
||||||
|
}),
|
||||||
|
std::end(peerAddrEntries_));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DHTPeerAnnounceEntry::empty() const
|
bool DHTPeerAnnounceEntry::empty() const
|
||||||
|
|
|
@ -71,7 +71,7 @@ public:
|
||||||
return peerAddrEntries_;
|
return peerAddrEntries_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeStalePeerAddrEntry(time_t timeout);
|
void removeStalePeerAddrEntry(const std::chrono::seconds& timeout);
|
||||||
|
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
|
|
||||||
|
|
|
@ -108,24 +108,16 @@ void DHTPeerAnnounceStorage::getPeers(std::vector<std::shared_ptr<Peer> >& peers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
|
||||||
class RemoveStalePeerAddrEntry
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void operator()(const std::shared_ptr<DHTPeerAnnounceEntry>& e)
|
|
||||||
{
|
|
||||||
e->removeStalePeerAddrEntry(DHT_PEER_ANNOUNCE_PURGE_INTERVAL);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
void DHTPeerAnnounceStorage::handleTimeout()
|
void DHTPeerAnnounceStorage::handleTimeout()
|
||||||
{
|
{
|
||||||
A2_LOG_DEBUG(fmt("Now purge peer announces(%lu entries) which are timed out.",
|
A2_LOG_DEBUG(fmt("Now purge peer announces(%lu entries) which are timed out.",
|
||||||
static_cast<unsigned long>(entries_.size())));
|
static_cast<unsigned long>(entries_.size())));
|
||||||
std::for_each(entries_.begin(), entries_.end(), RemoveStalePeerAddrEntry());
|
std::for_each(std::begin(entries_), std::end(entries_),
|
||||||
for(auto i = entries_.begin(),
|
[](const std::shared_ptr<DHTPeerAnnounceEntry>& e) {
|
||||||
eoi = entries_.end(); i != eoi;) {
|
e->removeStalePeerAddrEntry(DHT_PEER_ANNOUNCE_PURGE_INTERVAL);
|
||||||
|
});
|
||||||
|
|
||||||
|
for(auto i = std::begin(entries_); i != std::end(entries_); ) {
|
||||||
if((*i)->empty()) {
|
if((*i)->empty()) {
|
||||||
entries_.erase(i++);
|
entries_.erase(i++);
|
||||||
} else {
|
} else {
|
||||||
|
@ -140,7 +132,8 @@ void DHTPeerAnnounceStorage::announcePeer()
|
||||||
{
|
{
|
||||||
A2_LOG_DEBUG("Now announcing peer.");
|
A2_LOG_DEBUG("Now announcing peer.");
|
||||||
for (auto& e: entries_) {
|
for (auto& e: entries_) {
|
||||||
if(e->getLastUpdated().difference(global::wallclock()) < DHT_PEER_ANNOUNCE_INTERVAL) {
|
if (e->getLastUpdated().difference(global::wallclock()) <
|
||||||
|
DHT_PEER_ANNOUNCE_INTERVAL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
e->notifyUpdate();
|
e->notifyUpdate();
|
||||||
|
|
|
@ -52,7 +52,7 @@ private:
|
||||||
|
|
||||||
bool pingSuccessful_;
|
bool pingSuccessful_;
|
||||||
|
|
||||||
time_t timeout_;
|
std::chrono::seconds timeout_;
|
||||||
|
|
||||||
void addMessage();
|
void addMessage();
|
||||||
public:
|
public:
|
||||||
|
@ -66,9 +66,9 @@ public:
|
||||||
|
|
||||||
void onTimeout(const std::shared_ptr<DHTNode>& node);
|
void onTimeout(const std::shared_ptr<DHTNode>& node);
|
||||||
|
|
||||||
void setTimeout(time_t timeout)
|
void setTimeout(std::chrono::seconds timeout)
|
||||||
{
|
{
|
||||||
timeout_ = timeout;
|
timeout_ = std::move(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isPingSuccessful() const;
|
bool isPingSuccessful() const;
|
||||||
|
|
|
@ -51,7 +51,7 @@ private:
|
||||||
|
|
||||||
int numRetry_;
|
int numRetry_;
|
||||||
|
|
||||||
time_t timeout_;
|
std::chrono::seconds timeout_;
|
||||||
|
|
||||||
void sendMessage();
|
void sendMessage();
|
||||||
public:
|
public:
|
||||||
|
@ -66,9 +66,9 @@ public:
|
||||||
|
|
||||||
void onTimeout(const std::shared_ptr<DHTNode>& node);
|
void onTimeout(const std::shared_ptr<DHTNode>& node);
|
||||||
|
|
||||||
void setTimeout(time_t timeout)
|
void setTimeout(std::chrono::seconds timeout)
|
||||||
{
|
{
|
||||||
timeout_ = timeout;
|
timeout_ = std::move(timeout);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -148,13 +148,13 @@ std::vector<std::unique_ptr<Command>> DHTSetup::setup
|
||||||
auto tokenTracker = make_unique<DHTTokenTracker>();
|
auto tokenTracker = make_unique<DHTTokenTracker>();
|
||||||
// For now, UDPTrackerClient was enabled along with DHT
|
// For now, UDPTrackerClient was enabled along with DHT
|
||||||
auto udpTrackerClient = std::make_shared<UDPTrackerClient>();
|
auto udpTrackerClient = std::make_shared<UDPTrackerClient>();
|
||||||
const time_t messageTimeout =
|
const auto messageTimeout =
|
||||||
e->getOption()->getAsInt(PREF_DHT_MESSAGE_TIMEOUT);
|
e->getOption()->getAsInt(PREF_DHT_MESSAGE_TIMEOUT);
|
||||||
// wiring up
|
// wiring up
|
||||||
tracker->setRoutingTable(routingTable.get());
|
tracker->setRoutingTable(routingTable.get());
|
||||||
tracker->setMessageFactory(factory.get());
|
tracker->setMessageFactory(factory.get());
|
||||||
|
|
||||||
dispatcher->setTimeout(messageTimeout);
|
dispatcher->setTimeout(std::chrono::seconds(messageTimeout));
|
||||||
|
|
||||||
receiver->setMessageFactory(factory.get());
|
receiver->setMessageFactory(factory.get());
|
||||||
receiver->setRoutingTable(routingTable.get());
|
receiver->setRoutingTable(routingTable.get());
|
||||||
|
@ -164,7 +164,7 @@ std::vector<std::unique_ptr<Command>> DHTSetup::setup
|
||||||
taskFactory->setMessageDispatcher(dispatcher.get());
|
taskFactory->setMessageDispatcher(dispatcher.get());
|
||||||
taskFactory->setMessageFactory(factory.get());
|
taskFactory->setMessageFactory(factory.get());
|
||||||
taskFactory->setTaskQueue(taskQueue.get());
|
taskFactory->setTaskQueue(taskQueue.get());
|
||||||
taskFactory->setTimeout(messageTimeout);
|
taskFactory->setTimeout(std::chrono::seconds(messageTimeout));
|
||||||
|
|
||||||
routingTable->setTaskQueue(taskQueue.get());
|
routingTable->setTaskQueue(taskQueue.get());
|
||||||
routingTable->setTaskFactory(taskFactory.get());
|
routingTable->setTaskFactory(taskFactory.get());
|
||||||
|
@ -234,8 +234,8 @@ std::vector<std::unique_ptr<Command>> DHTSetup::setup
|
||||||
tempCommands.push_back(std::move(command));
|
tempCommands.push_back(std::move(command));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto command = make_unique<DHTAutoSaveCommand>
|
auto command = make_unique<DHTAutoSaveCommand>(e->newCUID(), e, family,
|
||||||
(e->newCUID(), e, family, 30*60);
|
std::chrono::minutes(30));
|
||||||
command->setLocalNode(localNode);
|
command->setLocalNode(localNode);
|
||||||
command->setRoutingTable(routingTable.get());
|
command->setRoutingTable(routingTable.get());
|
||||||
tempCommands.push_back(std::move(command));
|
tempCommands.push_back(std::move(command));
|
||||||
|
|
|
@ -64,7 +64,7 @@ std::shared_ptr<DHTTask>
|
||||||
DHTTaskFactoryImpl::createPingTask(const std::shared_ptr<DHTNode>& remoteNode,
|
DHTTaskFactoryImpl::createPingTask(const std::shared_ptr<DHTNode>& remoteNode,
|
||||||
int numRetry)
|
int numRetry)
|
||||||
{
|
{
|
||||||
std::shared_ptr<DHTPingTask> task(new DHTPingTask(remoteNode, numRetry));
|
auto task = std::make_shared<DHTPingTask>(remoteNode, numRetry);
|
||||||
task->setTimeout(timeout_);
|
task->setTimeout(timeout_);
|
||||||
setCommonProperty(task);
|
setCommonProperty(task);
|
||||||
return task;
|
return task;
|
||||||
|
|
|
@ -59,7 +59,7 @@ private:
|
||||||
|
|
||||||
DHTTaskQueue* taskQueue_;
|
DHTTaskQueue* taskQueue_;
|
||||||
|
|
||||||
time_t timeout_;
|
std::chrono::seconds timeout_;
|
||||||
|
|
||||||
void setCommonProperty(const std::shared_ptr<DHTAbstractTask>& task);
|
void setCommonProperty(const std::shared_ptr<DHTAbstractTask>& task);
|
||||||
public:
|
public:
|
||||||
|
@ -100,9 +100,9 @@ public:
|
||||||
|
|
||||||
void setLocalNode(const std::shared_ptr<DHTNode>& localNode);
|
void setLocalNode(const std::shared_ptr<DHTNode>& localNode);
|
||||||
|
|
||||||
void setTimeout(time_t timeout)
|
void setTimeout(std::chrono::seconds timeout)
|
||||||
{
|
{
|
||||||
timeout_ = timeout;
|
timeout_ = std::move(timeout);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,8 @@
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
DHTTokenUpdateCommand::DHTTokenUpdateCommand
|
DHTTokenUpdateCommand::DHTTokenUpdateCommand
|
||||||
(cuid_t cuid, DownloadEngine* e, time_t interval)
|
(cuid_t cuid, DownloadEngine* e, std::chrono::seconds interval)
|
||||||
: TimeBasedCommand{cuid, e, interval},
|
: TimeBasedCommand{cuid, e, std::move(interval)},
|
||||||
tokenTracker_{nullptr}
|
tokenTracker_{nullptr}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,8 @@ class DHTTokenUpdateCommand:public TimeBasedCommand {
|
||||||
private:
|
private:
|
||||||
DHTTokenTracker* tokenTracker_;
|
DHTTokenTracker* tokenTracker_;
|
||||||
public:
|
public:
|
||||||
DHTTokenUpdateCommand(cuid_t cuid, DownloadEngine* e, time_t interval);
|
DHTTokenUpdateCommand(cuid_t cuid, DownloadEngine* e,
|
||||||
|
std::chrono::seconds interval);
|
||||||
|
|
||||||
virtual ~DHTTokenUpdateCommand();
|
virtual ~DHTTokenUpdateCommand();
|
||||||
|
|
||||||
|
|
|
@ -61,10 +61,10 @@ DefaultBtAnnounce::DefaultBtAnnounce
|
||||||
(DownloadContext* downloadContext, const Option* option)
|
(DownloadContext* downloadContext, const Option* option)
|
||||||
: downloadContext_{downloadContext},
|
: downloadContext_{downloadContext},
|
||||||
trackers_(0),
|
trackers_(0),
|
||||||
prevAnnounceTimer_(0),
|
prevAnnounceTimer_(Timer::zero()),
|
||||||
interval_(DEFAULT_ANNOUNCE_INTERVAL),
|
interval_(DEFAULT_ANNOUNCE_INTERVAL),
|
||||||
minInterval_(DEFAULT_ANNOUNCE_INTERVAL),
|
minInterval_(DEFAULT_ANNOUNCE_INTERVAL),
|
||||||
userDefinedInterval_(0),
|
userDefinedInterval_(std::chrono::seconds(0)),
|
||||||
complete_(0),
|
complete_(0),
|
||||||
incomplete_(0),
|
incomplete_(0),
|
||||||
announceList_(bittorrent::getTorrentAttrs(downloadContext)->announceList),
|
announceList_(bittorrent::getTorrentAttrs(downloadContext)->announceList),
|
||||||
|
@ -77,12 +77,11 @@ DefaultBtAnnounce::~DefaultBtAnnounce() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DefaultBtAnnounce::isDefaultAnnounceReady() {
|
bool DefaultBtAnnounce::isDefaultAnnounceReady() {
|
||||||
return
|
return (trackers_ == 0 &&
|
||||||
(trackers_ == 0 &&
|
prevAnnounceTimer_.difference(global::wallclock()) >=
|
||||||
prevAnnounceTimer_.
|
(userDefinedInterval_.count() == 0 ? minInterval_
|
||||||
difference(global::wallclock()) >= (userDefinedInterval_==0?
|
: userDefinedInterval_) &&
|
||||||
minInterval_:userDefinedInterval_) &&
|
!announceList_.allTiersFailed());
|
||||||
!announceList_.allTiersFailed());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DefaultBtAnnounce::isStoppedAnnounceReady() {
|
bool DefaultBtAnnounce::isStoppedAnnounceReady() {
|
||||||
|
@ -305,13 +304,14 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse,
|
||||||
}
|
}
|
||||||
const Integer* ival = downcast<Integer>(dict->get(BtAnnounce::INTERVAL));
|
const Integer* ival = downcast<Integer>(dict->get(BtAnnounce::INTERVAL));
|
||||||
if(ival && ival->i() > 0) {
|
if(ival && ival->i() > 0) {
|
||||||
interval_ = ival->i();
|
interval_ = std::chrono::seconds(ival->i());
|
||||||
A2_LOG_DEBUG(fmt("Interval:%ld", static_cast<long int>(interval_)));
|
A2_LOG_DEBUG(fmt("Interval:%ld", static_cast<long int>(interval_.count())));
|
||||||
}
|
}
|
||||||
const Integer* mival = downcast<Integer>(dict->get(BtAnnounce::MIN_INTERVAL));
|
const Integer* mival = downcast<Integer>(dict->get(BtAnnounce::MIN_INTERVAL));
|
||||||
if(mival && mival->i() > 0) {
|
if(mival && mival->i() > 0) {
|
||||||
minInterval_ = mival->i();
|
minInterval_ = std::chrono::seconds(mival->i());
|
||||||
A2_LOG_DEBUG(fmt("Min interval:%ld", static_cast<long int>(minInterval_)));
|
A2_LOG_DEBUG(
|
||||||
|
fmt("Min interval:%ld", static_cast<long int>(minInterval_.count())));
|
||||||
minInterval_ = std::min(minInterval_, interval_);
|
minInterval_ = std::min(minInterval_, interval_);
|
||||||
} else {
|
} else {
|
||||||
// Use interval as a minInterval if minInterval is not supplied.
|
// Use interval as a minInterval if minInterval is not supplied.
|
||||||
|
@ -355,8 +355,9 @@ void DefaultBtAnnounce::processUDPTrackerResponse
|
||||||
const std::shared_ptr<UDPTrackerReply>& reply = req->reply;
|
const std::shared_ptr<UDPTrackerReply>& reply = req->reply;
|
||||||
A2_LOG_DEBUG("Now processing UDP tracker response.");
|
A2_LOG_DEBUG("Now processing UDP tracker response.");
|
||||||
if(reply->interval > 0) {
|
if(reply->interval > 0) {
|
||||||
minInterval_ = reply->interval;
|
minInterval_ = std::chrono::seconds(reply->interval);
|
||||||
A2_LOG_DEBUG(fmt("Min interval:%ld", static_cast<long int>(minInterval_)));
|
A2_LOG_DEBUG(
|
||||||
|
fmt("Min interval:%ld", static_cast<long int>(minInterval_.count())));
|
||||||
interval_ = minInterval_;
|
interval_ = minInterval_;
|
||||||
}
|
}
|
||||||
complete_ = reply->seeders;
|
complete_ = reply->seeders;
|
||||||
|
@ -401,9 +402,9 @@ void DefaultBtAnnounce::setPeerStorage
|
||||||
peerStorage_ = peerStorage;
|
peerStorage_ = peerStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtAnnounce::overrideMinInterval(time_t interval)
|
void DefaultBtAnnounce::overrideMinInterval(std::chrono::seconds interval)
|
||||||
{
|
{
|
||||||
minInterval_ = interval;
|
minInterval_ = std::move(interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -53,9 +53,9 @@ private:
|
||||||
DownloadContext* downloadContext_;
|
DownloadContext* downloadContext_;
|
||||||
int trackers_;
|
int trackers_;
|
||||||
Timer prevAnnounceTimer_;
|
Timer prevAnnounceTimer_;
|
||||||
time_t interval_;
|
std::chrono::seconds interval_;
|
||||||
time_t minInterval_;
|
std::chrono::seconds minInterval_;
|
||||||
time_t userDefinedInterval_;
|
std::chrono::seconds userDefinedInterval_;
|
||||||
int complete_;
|
int complete_;
|
||||||
int incomplete_;
|
int incomplete_;
|
||||||
AnnounceList announceList_;
|
AnnounceList announceList_;
|
||||||
|
@ -129,7 +129,8 @@ public:
|
||||||
|
|
||||||
virtual void shuffleAnnounce() CXX11_OVERRIDE;
|
virtual void shuffleAnnounce() CXX11_OVERRIDE;
|
||||||
|
|
||||||
virtual void overrideMinInterval(time_t interval) CXX11_OVERRIDE;
|
virtual void
|
||||||
|
overrideMinInterval(std::chrono::seconds interval) CXX11_OVERRIDE;
|
||||||
|
|
||||||
virtual void setTcpPort(uint16_t port) CXX11_OVERRIDE
|
virtual void setTcpPort(uint16_t port) CXX11_OVERRIDE
|
||||||
{
|
{
|
||||||
|
@ -138,12 +139,12 @@ public:
|
||||||
|
|
||||||
void setRandomizer(Randomizer* randomizer);
|
void setRandomizer(Randomizer* randomizer);
|
||||||
|
|
||||||
time_t getInterval() const
|
const std::chrono::seconds& getInterval() const
|
||||||
{
|
{
|
||||||
return interval_;
|
return interval_;
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t getMinInterval() const
|
const std::chrono::seconds& getMinInterval() const
|
||||||
{
|
{
|
||||||
return minInterval_;
|
return minInterval_;
|
||||||
}
|
}
|
||||||
|
@ -163,9 +164,9 @@ public:
|
||||||
return trackerId_;
|
return trackerId_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setUserDefinedInterval(time_t interval)
|
void setUserDefinedInterval(std::chrono::seconds interval)
|
||||||
{
|
{
|
||||||
userDefinedInterval_ = interval;
|
userDefinedInterval_ = std::move(interval);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -172,10 +172,10 @@ DefaultBtInteractive::receiveAndSendHandshake()
|
||||||
|
|
||||||
void DefaultBtInteractive::doPostHandshakeProcessing() {
|
void DefaultBtInteractive::doPostHandshakeProcessing() {
|
||||||
// Set time 0 to haveTimer to cache http/ftp download piece completion
|
// Set time 0 to haveTimer to cache http/ftp download piece completion
|
||||||
haveTimer_.reset(0);
|
haveTimer_ = Timer::zero();
|
||||||
keepAliveTimer_ = global::wallclock();
|
keepAliveTimer_ = global::wallclock();
|
||||||
floodingTimer_ = global::wallclock();
|
floodingTimer_ = global::wallclock();
|
||||||
pexTimer_.reset(0);
|
pexTimer_ = Timer::zero();
|
||||||
if(peer_->isExtendedMessagingEnabled()) {
|
if(peer_->isExtendedMessagingEnabled()) {
|
||||||
addHandshakeExtendedMessageToQueue();
|
addHandshakeExtendedMessageToQueue();
|
||||||
}
|
}
|
||||||
|
@ -254,9 +254,12 @@ void DefaultBtInteractive::decideChoking() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
constexpr auto MAX_HAVE_DELAY_SEC = std::chrono::seconds(10);
|
||||||
|
} // namespace
|
||||||
|
|
||||||
void DefaultBtInteractive::checkHave() {
|
void DefaultBtInteractive::checkHave() {
|
||||||
const size_t MIN_HAVE_PACK_SIZE = 20;
|
const size_t MIN_HAVE_PACK_SIZE = 20;
|
||||||
const time_t MAX_HAVE_DELAY_SEC = 10;
|
|
||||||
pieceStorage_->getAdvertisedPieceIndexes(haveIndexes_, cuid_, haveTimer_);
|
pieceStorage_->getAdvertisedPieceIndexes(haveIndexes_, cuid_, haveTimer_);
|
||||||
haveTimer_ = global::wallclock();
|
haveTimer_ = global::wallclock();
|
||||||
if(haveIndexes_.size() >= MIN_HAVE_PACK_SIZE) {
|
if(haveIndexes_.size() >= MIN_HAVE_PACK_SIZE) {
|
||||||
|
@ -430,6 +433,10 @@ void DefaultBtInteractive::sendPendingMessage() {
|
||||||
dispatcher_->sendMessages();
|
dispatcher_->sendMessages();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
constexpr auto FLOODING_CHECK_INTERVAL = std::chrono::seconds(5);
|
||||||
|
} // namespace
|
||||||
|
|
||||||
void DefaultBtInteractive::detectMessageFlooding() {
|
void DefaultBtInteractive::detectMessageFlooding() {
|
||||||
if(floodingTimer_.
|
if(floodingTimer_.
|
||||||
difference(global::wallclock()) >= FLOODING_CHECK_INTERVAL) {
|
difference(global::wallclock()) >= FLOODING_CHECK_INTERVAL) {
|
||||||
|
@ -445,13 +452,13 @@ void DefaultBtInteractive::detectMessageFlooding() {
|
||||||
|
|
||||||
void DefaultBtInteractive::checkActiveInteraction()
|
void DefaultBtInteractive::checkActiveInteraction()
|
||||||
{
|
{
|
||||||
time_t inactiveTime = inactiveTimer_.difference(global::wallclock());
|
auto inactiveTime = inactiveTimer_.difference(global::wallclock());
|
||||||
// To allow aria2 to accept mutially interested peer, disconnect uninterested
|
// To allow aria2 to accept mutially interested peer, disconnect uninterested
|
||||||
// peer.
|
// peer.
|
||||||
{
|
{
|
||||||
const time_t interval = 30;
|
const time_t interval = 30;
|
||||||
if(!peer_->amInterested() && !peer_->peerInterested() &&
|
if(!peer_->amInterested() && !peer_->peerInterested() &&
|
||||||
inactiveTime >= interval) {
|
inactiveTime >= std::chrono::seconds(interval)) {
|
||||||
peer_->setDisconnectedGracefully(true);
|
peer_->setDisconnectedGracefully(true);
|
||||||
// TODO change the message
|
// TODO change the message
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
|
@ -465,7 +472,7 @@ void DefaultBtInteractive::checkActiveInteraction()
|
||||||
// are disconnected in a certain time period.
|
// are disconnected in a certain time period.
|
||||||
{
|
{
|
||||||
const time_t interval = 60;
|
const time_t interval = 60;
|
||||||
if(inactiveTime >= interval) {
|
if(inactiveTime >= std::chrono::seconds(interval)) {
|
||||||
peer_->setDisconnectedGracefully(true);
|
peer_->setDisconnectedGracefully(true);
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
(fmt(EX_DROP_INACTIVE_CONNECTION,
|
(fmt(EX_DROP_INACTIVE_CONNECTION,
|
||||||
|
@ -522,7 +529,8 @@ void DefaultBtInteractive::doInteractionProcessing() {
|
||||||
dispatcher_->addMessageToQueue(std::move(i));
|
dispatcher_->addMessageToQueue(std::move(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(perSecTimer_.difference(global::wallclock()) >= 1) {
|
if(perSecTimer_.difference(global::wallclock()) >=
|
||||||
|
std::chrono::seconds(1)) {
|
||||||
perSecTimer_ = global::wallclock();
|
perSecTimer_ = global::wallclock();
|
||||||
// Drop timeout request after queuing message to give a chance
|
// Drop timeout request after queuing message to give a chance
|
||||||
// to other connection to request piece.
|
// to other connection to request piece.
|
||||||
|
@ -540,7 +548,8 @@ void DefaultBtInteractive::doInteractionProcessing() {
|
||||||
checkActiveInteraction();
|
checkActiveInteraction();
|
||||||
decideChoking();
|
decideChoking();
|
||||||
detectMessageFlooding();
|
detectMessageFlooding();
|
||||||
if(perSecTimer_.difference(global::wallclock()) >= 1) {
|
if(perSecTimer_.difference(global::wallclock()) >=
|
||||||
|
std::chrono::seconds(1)) {
|
||||||
perSecTimer_ = global::wallclock();
|
perSecTimer_ = global::wallclock();
|
||||||
dispatcher_->checkRequestSlotAndDoNecessaryThing();
|
dispatcher_->checkRequestSlotAndDoNecessaryThing();
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,7 +132,7 @@ private:
|
||||||
Timer inactiveTimer_;
|
Timer inactiveTimer_;
|
||||||
Timer pexTimer_;
|
Timer pexTimer_;
|
||||||
Timer perSecTimer_;
|
Timer perSecTimer_;
|
||||||
time_t keepAliveInterval_;
|
std::chrono::seconds keepAliveInterval_;
|
||||||
bool utPexEnabled_;
|
bool utPexEnabled_;
|
||||||
bool dhtEnabled_;
|
bool dhtEnabled_;
|
||||||
|
|
||||||
|
@ -147,8 +147,6 @@ private:
|
||||||
std::vector<size_t> haveIndexes_;
|
std::vector<size_t> haveIndexes_;
|
||||||
Timer haveLastSent_;
|
Timer haveLastSent_;
|
||||||
|
|
||||||
static const time_t FLOODING_CHECK_INTERVAL = 5;
|
|
||||||
|
|
||||||
void addBitfieldMessageToQueue();
|
void addBitfieldMessageToQueue();
|
||||||
void addAllowedFastMessageToQueue();
|
void addAllowedFastMessageToQueue();
|
||||||
void addHandshakeExtendedMessageToQueue();
|
void addHandshakeExtendedMessageToQueue();
|
||||||
|
@ -224,8 +222,8 @@ public:
|
||||||
void setExtensionMessageRegistry
|
void setExtensionMessageRegistry
|
||||||
(std::unique_ptr<ExtensionMessageRegistry> registry);
|
(std::unique_ptr<ExtensionMessageRegistry> registry);
|
||||||
|
|
||||||
void setKeepAliveInterval(time_t keepAliveInterval) {
|
void setKeepAliveInterval(std::chrono::seconds keepAliveInterval) {
|
||||||
keepAliveInterval_ = keepAliveInterval;
|
keepAliveInterval_ = std::move(keepAliveInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setUTPexEnabled(bool f)
|
void setUTPexEnabled(bool f)
|
||||||
|
|
|
@ -62,7 +62,7 @@ private:
|
||||||
BtMessageFactory* messageFactory_;
|
BtMessageFactory* messageFactory_;
|
||||||
std::shared_ptr<Peer> peer_;
|
std::shared_ptr<Peer> peer_;
|
||||||
RequestGroupMan* requestGroupMan_;
|
RequestGroupMan* requestGroupMan_;
|
||||||
time_t requestTimeout_;
|
std::chrono::seconds requestTimeout_;
|
||||||
public:
|
public:
|
||||||
DefaultBtMessageDispatcher();
|
DefaultBtMessageDispatcher();
|
||||||
|
|
||||||
|
@ -140,9 +140,9 @@ public:
|
||||||
cuid_ = cuid;
|
cuid_ = cuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setRequestTimeout(time_t requestTimeout)
|
void setRequestTimeout(std::chrono::seconds requestTimeout)
|
||||||
{
|
{
|
||||||
requestTimeout_ = requestTimeout;
|
requestTimeout_ = std::move(requestTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPeerConnection(PeerConnection* peerConnection)
|
void setPeerConnection(PeerConnection* peerConnection)
|
||||||
|
|
|
@ -62,7 +62,7 @@ DefaultPeerStorage::DefaultPeerStorage()
|
||||||
: maxPeerListSize_(MAX_PEER_LIST_SIZE),
|
: maxPeerListSize_(MAX_PEER_LIST_SIZE),
|
||||||
seederStateChoke_(make_unique<BtSeederStateChoke>()),
|
seederStateChoke_(make_unique<BtSeederStateChoke>()),
|
||||||
leecherStateChoke_(make_unique<BtLeecherStateChoke>()),
|
leecherStateChoke_(make_unique<BtLeecherStateChoke>()),
|
||||||
lastTransferStatMapUpdated_(0)
|
lastTransferStatMapUpdated_(Timer::zero())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
DefaultPeerStorage::~DefaultPeerStorage()
|
DefaultPeerStorage::~DefaultPeerStorage()
|
||||||
|
@ -183,11 +183,11 @@ bool DefaultPeerStorage::isPeerAvailable() {
|
||||||
bool DefaultPeerStorage::isBadPeer(const std::string& ipaddr)
|
bool DefaultPeerStorage::isBadPeer(const std::string& ipaddr)
|
||||||
{
|
{
|
||||||
auto i = badPeers_.find(ipaddr);
|
auto i = badPeers_.find(ipaddr);
|
||||||
if(i == badPeers_.end()) {
|
if(i == std::end(badPeers_)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(global::wallclock().getTime() >= (*i).second) {
|
if((*i).second <= global::wallclock()) {
|
||||||
badPeers_.erase(i);
|
badPeers_.erase(i);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -197,10 +197,10 @@ bool DefaultPeerStorage::isBadPeer(const std::string& ipaddr)
|
||||||
|
|
||||||
void DefaultPeerStorage::addBadPeer(const std::string& ipaddr)
|
void DefaultPeerStorage::addBadPeer(const std::string& ipaddr)
|
||||||
{
|
{
|
||||||
if(lastBadPeerCleaned_.difference(global::wallclock()) >= 3600) {
|
if(lastBadPeerCleaned_.difference(global::wallclock()) >=
|
||||||
for(auto i = badPeers_.begin(),
|
std::chrono::hours(1)) {
|
||||||
eoi = badPeers_.end(); i != eoi;) {
|
for(auto i = std::begin(badPeers_); i != std::end(badPeers_);) {
|
||||||
if(global::wallclock().getTime() >= (*i).second) {
|
if((*i).second <= global::wallclock()) {
|
||||||
A2_LOG_DEBUG(fmt("Purge %s from bad peer", (*i).first.c_str()));
|
A2_LOG_DEBUG(fmt("Purge %s from bad peer", (*i).first.c_str()));
|
||||||
badPeers_.erase(i++);
|
badPeers_.erase(i++);
|
||||||
// badPeers_.end() will not be invalidated.
|
// badPeers_.end() will not be invalidated.
|
||||||
|
@ -212,8 +212,11 @@ void DefaultPeerStorage::addBadPeer(const std::string& ipaddr)
|
||||||
}
|
}
|
||||||
A2_LOG_DEBUG(fmt("Added %s as bad peer", ipaddr.c_str()));
|
A2_LOG_DEBUG(fmt("Added %s as bad peer", ipaddr.c_str()));
|
||||||
// We use variable timeout to avoid many bad peers wake up at once.
|
// We use variable timeout to avoid many bad peers wake up at once.
|
||||||
badPeers_[ipaddr] = global::wallclock().getTime()+
|
auto t = global::wallclock();
|
||||||
std::max(SimpleRandomizer::getInstance()->getRandomNumber(601), 120L);
|
t.advance(std::chrono::seconds(
|
||||||
|
std::max(SimpleRandomizer::getInstance()->getRandomNumber(601), 120L)));
|
||||||
|
|
||||||
|
badPeers_[ipaddr] = std::move(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultPeerStorage::deleteUnusedPeer(size_t delSize) {
|
void DefaultPeerStorage::deleteUnusedPeer(size_t delSize) {
|
||||||
|
@ -281,7 +284,7 @@ void DefaultPeerStorage::returnPeer(const std::shared_ptr<Peer>& peer)
|
||||||
|
|
||||||
bool DefaultPeerStorage::chokeRoundIntervalElapsed()
|
bool DefaultPeerStorage::chokeRoundIntervalElapsed()
|
||||||
{
|
{
|
||||||
const time_t CHOKE_ROUND_INTERVAL = 10;
|
constexpr auto CHOKE_ROUND_INTERVAL = std::chrono::seconds(10);
|
||||||
if(pieceStorage_->downloadFinished()) {
|
if(pieceStorage_->downloadFinished()) {
|
||||||
return seederStateChoke_->getLastRound().
|
return seederStateChoke_->getLastRound().
|
||||||
difference(global::wallclock()) >= CHOKE_ROUND_INTERVAL;
|
difference(global::wallclock()) >= CHOKE_ROUND_INTERVAL;
|
||||||
|
|
|
@ -71,7 +71,7 @@ private:
|
||||||
|
|
||||||
Timer lastTransferStatMapUpdated_;
|
Timer lastTransferStatMapUpdated_;
|
||||||
|
|
||||||
std::map<std::string, time_t> badPeers_;
|
std::map<std::string, Timer> badPeers_;
|
||||||
Timer lastBadPeerCleaned_;
|
Timer lastBadPeerCleaned_;
|
||||||
|
|
||||||
bool isPeerAlreadyAdded(const std::shared_ptr<Peer>& peer);
|
bool isPeerAlreadyAdded(const std::shared_ptr<Peer>& peer);
|
||||||
|
|
|
@ -725,32 +725,18 @@ DefaultPieceStorage::getAdvertisedPieceIndexes(std::vector<size_t>& indexes,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
void
|
||||||
class FindElapsedHave
|
DefaultPieceStorage::removeAdvertisedPiece(const std::chrono::seconds& elapsed)
|
||||||
{
|
{
|
||||||
private:
|
auto itr = std::find_if(std::begin(haves_), std::end(haves_),
|
||||||
time_t elapsed;
|
[&elapsed](const HaveEntry& have) {
|
||||||
public:
|
return have.getRegisteredTime().difference(global::wallclock()) >= elapsed;
|
||||||
FindElapsedHave(time_t elapsed):elapsed(elapsed) {}
|
});
|
||||||
|
|
||||||
bool operator()(const HaveEntry& have) {
|
if(itr != std::end(haves_)) {
|
||||||
if(have.getRegisteredTime().difference(global::wallclock()) >= elapsed) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
void DefaultPieceStorage::removeAdvertisedPiece(time_t elapsed)
|
|
||||||
{
|
|
||||||
auto itr = std::find_if(haves_.begin(), haves_.end(),
|
|
||||||
FindElapsedHave(elapsed));
|
|
||||||
if(itr != haves_.end()) {
|
|
||||||
A2_LOG_DEBUG(fmt(MSG_REMOVED_HAVE_ENTRY,
|
A2_LOG_DEBUG(fmt(MSG_REMOVED_HAVE_ENTRY,
|
||||||
static_cast<unsigned long>(haves_.end()-itr)));
|
static_cast<unsigned long>(std::end(haves_) - itr)));
|
||||||
haves_.erase(itr, haves_.end());
|
haves_.erase(itr, std::end(haves_));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -262,7 +262,8 @@ public:
|
||||||
cuid_t myCuid, const Timer& lastCheckTime)
|
cuid_t myCuid, const Timer& lastCheckTime)
|
||||||
CXX11_OVERRIDE;
|
CXX11_OVERRIDE;
|
||||||
|
|
||||||
virtual void removeAdvertisedPiece(time_t elapsed) CXX11_OVERRIDE;
|
virtual void
|
||||||
|
removeAdvertisedPiece(const std::chrono::seconds& elapsed) CXX11_OVERRIDE;
|
||||||
|
|
||||||
virtual void markAllPiecesDone() CXX11_OVERRIDE;
|
virtual void markAllPiecesDone() CXX11_OVERRIDE;
|
||||||
|
|
||||||
|
|
|
@ -59,9 +59,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DelayedCommand(cuid_t cuid, DownloadEngine* e, time_t delay,
|
DelayedCommand(cuid_t cuid, DownloadEngine* e, std::chrono::seconds delay,
|
||||||
std::unique_ptr<Command> command, bool noWait)
|
std::unique_ptr<Command> command, bool noWait)
|
||||||
: TimeBasedCommand(cuid, e, delay),
|
: TimeBasedCommand(cuid, e, std::move(delay)),
|
||||||
command_{std::move(command)},
|
command_{std::move(command)},
|
||||||
noWait_{noWait}
|
noWait_{noWait}
|
||||||
{
|
{
|
||||||
|
|
|
@ -328,7 +328,7 @@ bool DownloadCommand::prepareForNextSegment() {
|
||||||
// Following 2lines are needed for DownloadEngine to detect
|
// Following 2lines are needed for DownloadEngine to detect
|
||||||
// completed RequestGroups without 1sec delay.
|
// completed RequestGroups without 1sec delay.
|
||||||
getDownloadEngine()->setNoWait(true);
|
getDownloadEngine()->setNoWait(true);
|
||||||
getDownloadEngine()->setRefreshInterval(0);
|
getDownloadEngine()->setRefreshInterval(std::chrono::milliseconds(0));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// The number of segments should be 1 in order to pass through the next
|
// The number of segments should be 1 in order to pass through the next
|
||||||
|
|
|
@ -53,7 +53,7 @@ private:
|
||||||
|
|
||||||
std::unique_ptr<MessageDigest> messageDigest_;
|
std::unique_ptr<MessageDigest> messageDigest_;
|
||||||
|
|
||||||
time_t startupIdleTime_;
|
std::chrono::seconds startupIdleTime_;
|
||||||
|
|
||||||
int lowestDownloadSpeedLimit_;
|
int lowestDownloadSpeedLimit_;
|
||||||
|
|
||||||
|
@ -99,9 +99,9 @@ public:
|
||||||
|
|
||||||
void installStreamFilter(std::unique_ptr<StreamFilter> streamFilter);
|
void installStreamFilter(std::unique_ptr<StreamFilter> streamFilter);
|
||||||
|
|
||||||
void setStartupIdleTime(time_t startupIdleTime)
|
void setStartupIdleTime(std::chrono::seconds startupIdleTime)
|
||||||
{
|
{
|
||||||
startupIdleTime_ = startupIdleTime;
|
startupIdleTime_ = std::move(startupIdleTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setLowestDownloadSpeedLimit(int lowestDownloadSpeedLimit)
|
void setLowestDownloadSpeedLimit(int lowestDownloadSpeedLimit)
|
||||||
|
|
|
@ -50,7 +50,7 @@ namespace aria2 {
|
||||||
DownloadContext::DownloadContext()
|
DownloadContext::DownloadContext()
|
||||||
: ownerRequestGroup_(nullptr),
|
: ownerRequestGroup_(nullptr),
|
||||||
attrs_(MAX_CTX_ATTR),
|
attrs_(MAX_CTX_ATTR),
|
||||||
downloadStopTime_(0),
|
downloadStopTime_(Timer::zero()),
|
||||||
pieceLength_(0),
|
pieceLength_(0),
|
||||||
checksumVerified_(false),
|
checksumVerified_(false),
|
||||||
knowsTotalLength_(true),
|
knowsTotalLength_(true),
|
||||||
|
@ -62,7 +62,7 @@ DownloadContext::DownloadContext(int32_t pieceLength,
|
||||||
std::string path)
|
std::string path)
|
||||||
: ownerRequestGroup_(nullptr),
|
: ownerRequestGroup_(nullptr),
|
||||||
attrs_(MAX_CTX_ATTR),
|
attrs_(MAX_CTX_ATTR),
|
||||||
downloadStopTime_(0),
|
downloadStopTime_(Timer::zero()),
|
||||||
pieceLength_(pieceLength),
|
pieceLength_(pieceLength),
|
||||||
checksumVerified_(false),
|
checksumVerified_(false),
|
||||||
knowsTotalLength_(true),
|
knowsTotalLength_(true),
|
||||||
|
@ -76,7 +76,7 @@ DownloadContext::~DownloadContext() {}
|
||||||
|
|
||||||
void DownloadContext::resetDownloadStartTime()
|
void DownloadContext::resetDownloadStartTime()
|
||||||
{
|
{
|
||||||
downloadStopTime_.reset(0);
|
downloadStopTime_ = Timer::zero();
|
||||||
netStat_.downloadStart();
|
netStat_.downloadStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,10 +86,10 @@ void DownloadContext::resetDownloadStopTime()
|
||||||
netStat_.downloadStop();
|
netStat_.downloadStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t DownloadContext::calculateSessionTime() const
|
Timer::Clock::duration DownloadContext::calculateSessionTime() const
|
||||||
{
|
{
|
||||||
const Timer& startTime = netStat_.getDownloadStartTime();
|
const Timer& startTime = netStat_.getDownloadStartTime();
|
||||||
return startTime.differenceInMillis(downloadStopTime_);
|
return startTime.difference(downloadStopTime_);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<FileEntry>
|
std::shared_ptr<FileEntry>
|
||||||
|
|
|
@ -222,7 +222,7 @@ public:
|
||||||
return downloadStopTime_;
|
return downloadStopTime_;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t calculateSessionTime() const;
|
Timer::Clock::duration calculateSessionTime() const;
|
||||||
|
|
||||||
// Returns FileEntry at given offset. std::shared_ptr<FileEntry>() is
|
// Returns FileEntry at given offset. std::shared_ptr<FileEntry>() is
|
||||||
// returned if no such FileEntry is found.
|
// returned if no such FileEntry is found.
|
||||||
|
|
|
@ -90,12 +90,16 @@ volatile sig_atomic_t globalHaltRequested = 0;
|
||||||
|
|
||||||
} // namespace global
|
} // namespace global
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
constexpr auto DEFAULT_REFRESH_INTERVAL = std::chrono::seconds(1);
|
||||||
|
} // namespace
|
||||||
|
|
||||||
DownloadEngine::DownloadEngine(std::unique_ptr<EventPoll> eventPoll)
|
DownloadEngine::DownloadEngine(std::unique_ptr<EventPoll> eventPoll)
|
||||||
: eventPoll_(std::move(eventPoll)),
|
: eventPoll_(std::move(eventPoll)),
|
||||||
haltRequested_(0),
|
haltRequested_(0),
|
||||||
noWait_(true),
|
noWait_(true),
|
||||||
refreshInterval_(DEFAULT_REFRESH_INTERVAL),
|
refreshInterval_(DEFAULT_REFRESH_INTERVAL),
|
||||||
lastRefresh_(0),
|
lastRefresh_(Timer::zero()),
|
||||||
cookieStorage_(make_unique<CookieStorage>()),
|
cookieStorage_(make_unique<CookieStorage>()),
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
btRegistry_(make_unique<BtRegistry>()),
|
btRegistry_(make_unique<BtRegistry>()),
|
||||||
|
@ -164,7 +168,7 @@ int DownloadEngine::run(bool oneshot)
|
||||||
noWait_ = false;
|
noWait_ = false;
|
||||||
global::wallclock().reset();
|
global::wallclock().reset();
|
||||||
calculateStatistics();
|
calculateStatistics();
|
||||||
if(lastRefresh_.differenceInMillis(global::wallclock())+A2_DELTA_MILLIS >=
|
if(lastRefresh_.difference(global::wallclock())+A2_DELTA_MILLIS >=
|
||||||
refreshInterval_) {
|
refreshInterval_) {
|
||||||
refreshInterval_ = DEFAULT_REFRESH_INTERVAL;
|
refreshInterval_ = DEFAULT_REFRESH_INTERVAL;
|
||||||
lastRefresh_ = global::wallclock();
|
lastRefresh_ = global::wallclock();
|
||||||
|
@ -188,9 +192,10 @@ void DownloadEngine::waitData()
|
||||||
if(noWait_) {
|
if(noWait_) {
|
||||||
tv.tv_sec = tv.tv_usec = 0;
|
tv.tv_sec = tv.tv_usec = 0;
|
||||||
} else {
|
} else {
|
||||||
lldiv_t qr = lldiv(refreshInterval_*1000, 1000000);
|
auto t =
|
||||||
tv.tv_sec = qr.quot;
|
std::chrono::duration_cast<std::chrono::microseconds>(refreshInterval_);
|
||||||
tv.tv_usec = qr.rem;
|
tv.tv_sec = t.count() / 1000000;
|
||||||
|
tv.tv_usec = t.count() % 1000000;
|
||||||
}
|
}
|
||||||
eventPoll_->poll(tv);
|
eventPoll_->poll(tv);
|
||||||
}
|
}
|
||||||
|
@ -245,7 +250,7 @@ void DownloadEngine::afterEachIteration()
|
||||||
requestHalt();
|
requestHalt();
|
||||||
global::globalHaltRequested = 2;
|
global::globalHaltRequested = 2;
|
||||||
setNoWait(true);
|
setNoWait(true);
|
||||||
setRefreshInterval(0);
|
setRefreshInterval(std::chrono::milliseconds(0));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,7 +259,7 @@ void DownloadEngine::afterEachIteration()
|
||||||
requestForceHalt();
|
requestForceHalt();
|
||||||
global::globalHaltRequested = 4;
|
global::globalHaltRequested = 4;
|
||||||
setNoWait(true);
|
setNoWait(true);
|
||||||
setRefreshInterval(0);
|
setRefreshInterval(std::chrono::milliseconds(0));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -307,7 +312,8 @@ void DownloadEngine::poolSocket(const std::string& key,
|
||||||
std::multimap<std::string, SocketPoolEntry>::value_type p(key, entry);
|
std::multimap<std::string, SocketPoolEntry>::value_type p(key, entry);
|
||||||
socketPool_.insert(p);
|
socketPool_.insert(p);
|
||||||
|
|
||||||
if(lastSocketPoolScan_.difference(global::wallclock()) < 60) {
|
if(lastSocketPoolScan_.difference(global::wallclock()) <
|
||||||
|
std::chrono::minutes(1)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::multimap<std::string, SocketPoolEntry> newPool;
|
std::multimap<std::string, SocketPoolEntry> newPool;
|
||||||
|
@ -351,9 +357,9 @@ void DownloadEngine::poolSocket
|
||||||
uint16_t proxyport,
|
uint16_t proxyport,
|
||||||
const std::shared_ptr<SocketCore>& sock,
|
const std::shared_ptr<SocketCore>& sock,
|
||||||
const std::string& options,
|
const std::string& options,
|
||||||
time_t timeout)
|
std::chrono::seconds timeout)
|
||||||
{
|
{
|
||||||
SocketPoolEntry e(sock, options, timeout);
|
SocketPoolEntry e(sock, options, std::move(timeout));
|
||||||
poolSocket(createSockPoolKey(ipaddr, port, username, proxyhost, proxyport),e);
|
poolSocket(createSockPoolKey(ipaddr, port, username, proxyhost, proxyport),e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,9 +369,9 @@ void DownloadEngine::poolSocket
|
||||||
const std::string& proxyhost,
|
const std::string& proxyhost,
|
||||||
uint16_t proxyport,
|
uint16_t proxyport,
|
||||||
const std::shared_ptr<SocketCore>& sock,
|
const std::shared_ptr<SocketCore>& sock,
|
||||||
time_t timeout)
|
std::chrono::seconds timeout)
|
||||||
{
|
{
|
||||||
SocketPoolEntry e(sock, timeout);
|
SocketPoolEntry e(sock, std::move(timeout));
|
||||||
poolSocket(createSockPoolKey(ipaddr, port, A2STR::NIL,proxyhost,proxyport),e);
|
poolSocket(createSockPoolKey(ipaddr, port, A2STR::NIL,proxyhost,proxyport),e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -388,20 +394,20 @@ bool getPeerInfo(std::pair<std::string, uint16_t>& res,
|
||||||
void DownloadEngine::poolSocket(const std::shared_ptr<Request>& request,
|
void DownloadEngine::poolSocket(const std::shared_ptr<Request>& request,
|
||||||
const std::shared_ptr<Request>& proxyRequest,
|
const std::shared_ptr<Request>& proxyRequest,
|
||||||
const std::shared_ptr<SocketCore>& socket,
|
const std::shared_ptr<SocketCore>& socket,
|
||||||
time_t timeout)
|
std::chrono::seconds timeout)
|
||||||
{
|
{
|
||||||
if(proxyRequest) {
|
if(proxyRequest) {
|
||||||
// If proxy is defined, then pool socket with its hostname.
|
// If proxy is defined, then pool socket with its hostname.
|
||||||
poolSocket(request->getHost(), request->getPort(),
|
poolSocket(request->getHost(), request->getPort(),
|
||||||
proxyRequest->getHost(), proxyRequest->getPort(),
|
proxyRequest->getHost(), proxyRequest->getPort(),
|
||||||
socket, timeout);
|
socket, std::move(timeout));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<std::string, uint16_t> peerInfo;
|
std::pair<std::string, uint16_t> peerInfo;
|
||||||
if(getPeerInfo(peerInfo, socket)) {
|
if(getPeerInfo(peerInfo, socket)) {
|
||||||
poolSocket(peerInfo.first, peerInfo.second,
|
poolSocket(peerInfo.first, peerInfo.second,
|
||||||
A2STR::NIL, 0, socket, timeout);
|
A2STR::NIL, 0, socket, std::move(timeout));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -411,20 +417,20 @@ void DownloadEngine::poolSocket
|
||||||
const std::shared_ptr<Request>& proxyRequest,
|
const std::shared_ptr<Request>& proxyRequest,
|
||||||
const std::shared_ptr<SocketCore>& socket,
|
const std::shared_ptr<SocketCore>& socket,
|
||||||
const std::string& options,
|
const std::string& options,
|
||||||
time_t timeout)
|
std::chrono::seconds timeout)
|
||||||
{
|
{
|
||||||
if(proxyRequest) {
|
if(proxyRequest) {
|
||||||
// If proxy is defined, then pool socket with its hostname.
|
// If proxy is defined, then pool socket with its hostname.
|
||||||
poolSocket(request->getHost(), request->getPort(), username,
|
poolSocket(request->getHost(), request->getPort(), username,
|
||||||
proxyRequest->getHost(), proxyRequest->getPort(),
|
proxyRequest->getHost(), proxyRequest->getPort(),
|
||||||
socket, options, timeout);
|
socket, options, std::move(timeout));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<std::string, uint16_t> peerInfo;
|
std::pair<std::string, uint16_t> peerInfo;
|
||||||
if(getPeerInfo(peerInfo, socket)) {
|
if(getPeerInfo(peerInfo, socket)) {
|
||||||
poolSocket(peerInfo.first, peerInfo.second, username,
|
poolSocket(peerInfo.first, peerInfo.second, username,
|
||||||
A2STR::NIL, 0, socket, options, timeout);
|
A2STR::NIL, 0, socket, options, std::move(timeout));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -512,16 +518,16 @@ DownloadEngine::popPooledSocket
|
||||||
DownloadEngine::SocketPoolEntry::SocketPoolEntry
|
DownloadEngine::SocketPoolEntry::SocketPoolEntry
|
||||||
(const std::shared_ptr<SocketCore>& socket,
|
(const std::shared_ptr<SocketCore>& socket,
|
||||||
const std::string& options,
|
const std::string& options,
|
||||||
time_t timeout)
|
std::chrono::seconds timeout)
|
||||||
: socket_(socket),
|
: socket_(socket),
|
||||||
options_(options),
|
options_(options),
|
||||||
timeout_(timeout)
|
timeout_(std::move(timeout))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
DownloadEngine::SocketPoolEntry::SocketPoolEntry
|
DownloadEngine::SocketPoolEntry::SocketPoolEntry
|
||||||
(const std::shared_ptr<SocketCore>& socket, time_t timeout)
|
(const std::shared_ptr<SocketCore>& socket, std::chrono::seconds timeout)
|
||||||
: socket_(socket),
|
: socket_(socket),
|
||||||
timeout_(timeout)
|
timeout_(std::move(timeout))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
DownloadEngine::SocketPoolEntry::~SocketPoolEntry() {}
|
DownloadEngine::SocketPoolEntry::~SocketPoolEntry() {}
|
||||||
|
@ -577,9 +583,9 @@ const std::unique_ptr<CookieStorage>& DownloadEngine::getCookieStorage() const
|
||||||
return cookieStorage_;
|
return cookieStorage_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadEngine::setRefreshInterval(int64_t interval)
|
void DownloadEngine::setRefreshInterval(std::chrono::milliseconds interval)
|
||||||
{
|
{
|
||||||
refreshInterval_ = std::min(static_cast<int64_t>(999), interval);
|
refreshInterval_ = std::move(interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadEngine::addCommand
|
void DownloadEngine::addCommand
|
||||||
|
|
|
@ -99,16 +99,16 @@ private:
|
||||||
// protocol specific option string
|
// protocol specific option string
|
||||||
std::string options_;
|
std::string options_;
|
||||||
|
|
||||||
time_t timeout_;
|
std::chrono::seconds timeout_;
|
||||||
|
|
||||||
Timer registeredTime_;
|
Timer registeredTime_;
|
||||||
public:
|
public:
|
||||||
SocketPoolEntry(const std::shared_ptr<SocketCore>& socket,
|
SocketPoolEntry(const std::shared_ptr<SocketCore>& socket,
|
||||||
const std::string& option,
|
const std::string& option,
|
||||||
time_t timeout);
|
std::chrono::seconds timeout);
|
||||||
|
|
||||||
SocketPoolEntry(const std::shared_ptr<SocketCore>& socket,
|
SocketPoolEntry(const std::shared_ptr<SocketCore>& socket,
|
||||||
time_t timeout);
|
std::chrono::seconds timeout);
|
||||||
|
|
||||||
~SocketPoolEntry();
|
~SocketPoolEntry();
|
||||||
|
|
||||||
|
@ -132,10 +132,7 @@ private:
|
||||||
|
|
||||||
bool noWait_;
|
bool noWait_;
|
||||||
|
|
||||||
static const int64_t DEFAULT_REFRESH_INTERVAL = 1000;
|
std::chrono::milliseconds refreshInterval_;
|
||||||
|
|
||||||
// Milliseconds
|
|
||||||
int64_t refreshInterval_;
|
|
||||||
Timer lastRefresh_;
|
Timer lastRefresh_;
|
||||||
|
|
||||||
std::unique_ptr<CookieStorage> cookieStorage_;
|
std::unique_ptr<CookieStorage> cookieStorage_;
|
||||||
|
@ -272,24 +269,24 @@ public:
|
||||||
const std::string& proxyhost, uint16_t proxyport,
|
const std::string& proxyhost, uint16_t proxyport,
|
||||||
const std::shared_ptr<SocketCore>& sock,
|
const std::shared_ptr<SocketCore>& sock,
|
||||||
const std::string& options,
|
const std::string& options,
|
||||||
time_t timeout = 15);
|
std::chrono::seconds timeout = std::chrono::seconds(15));
|
||||||
|
|
||||||
void poolSocket(const std::shared_ptr<Request>& request,
|
void poolSocket(const std::shared_ptr<Request>& request,
|
||||||
const std::string& username,
|
const std::string& username,
|
||||||
const std::shared_ptr<Request>& proxyRequest,
|
const std::shared_ptr<Request>& proxyRequest,
|
||||||
const std::shared_ptr<SocketCore>& socket,
|
const std::shared_ptr<SocketCore>& socket,
|
||||||
const std::string& options,
|
const std::string& options,
|
||||||
time_t timeout = 15);
|
std::chrono::seconds timeout = std::chrono::seconds(15));
|
||||||
|
|
||||||
void poolSocket(const std::string& ipaddr, uint16_t port,
|
void poolSocket(const std::string& ipaddr, uint16_t port,
|
||||||
const std::string& proxyhost, uint16_t proxyport,
|
const std::string& proxyhost, uint16_t proxyport,
|
||||||
const std::shared_ptr<SocketCore>& sock,
|
const std::shared_ptr<SocketCore>& sock,
|
||||||
time_t timeout = 15);
|
std::chrono::seconds timeout = std::chrono::seconds(15));
|
||||||
|
|
||||||
void poolSocket(const std::shared_ptr<Request>& request,
|
void poolSocket(const std::shared_ptr<Request>& request,
|
||||||
const std::shared_ptr<Request>& proxyRequest,
|
const std::shared_ptr<Request>& proxyRequest,
|
||||||
const std::shared_ptr<SocketCore>& socket,
|
const std::shared_ptr<SocketCore>& socket,
|
||||||
time_t timeout = 15);
|
std::chrono::seconds timeout = std::chrono::seconds(15));
|
||||||
|
|
||||||
std::shared_ptr<SocketCore> popPooledSocket
|
std::shared_ptr<SocketCore> popPooledSocket
|
||||||
(const std::string& ipaddr,
|
(const std::string& ipaddr,
|
||||||
|
@ -347,7 +344,7 @@ public:
|
||||||
|
|
||||||
const std::unique_ptr<AuthConfigFactory>& getAuthConfigFactory() const;
|
const std::unique_ptr<AuthConfigFactory>& getAuthConfigFactory() const;
|
||||||
|
|
||||||
void setRefreshInterval(int64_t interval);
|
void setRefreshInterval(std::chrono::milliseconds interval);
|
||||||
|
|
||||||
const std::string getSessionId() const
|
const std::string getSessionId() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -166,22 +166,22 @@ DownloadEngineFactory::newDownloadEngine
|
||||||
e.get()));
|
e.get()));
|
||||||
|
|
||||||
if(op->getAsInt(PREF_AUTO_SAVE_INTERVAL) > 0) {
|
if(op->getAsInt(PREF_AUTO_SAVE_INTERVAL) > 0) {
|
||||||
e->addRoutineCommand
|
e->addRoutineCommand(make_unique<AutoSaveCommand>(
|
||||||
(make_unique<AutoSaveCommand>(e->newCUID(), e.get(),
|
e->newCUID(), e.get(),
|
||||||
op->getAsInt(PREF_AUTO_SAVE_INTERVAL)));
|
std::chrono::seconds(op->getAsInt(PREF_AUTO_SAVE_INTERVAL))));
|
||||||
}
|
}
|
||||||
if(op->getAsInt(PREF_SAVE_SESSION_INTERVAL) > 0) {
|
if(op->getAsInt(PREF_SAVE_SESSION_INTERVAL) > 0) {
|
||||||
e->addRoutineCommand(make_unique<SaveSessionCommand>
|
e->addRoutineCommand(make_unique<SaveSessionCommand>(
|
||||||
(e->newCUID(), e.get(),
|
e->newCUID(), e.get(),
|
||||||
op->getAsInt(PREF_SAVE_SESSION_INTERVAL)));
|
std::chrono::seconds(op->getAsInt(PREF_SAVE_SESSION_INTERVAL))));
|
||||||
}
|
}
|
||||||
e->addRoutineCommand(make_unique<HaveEraseCommand>
|
e->addRoutineCommand(make_unique<HaveEraseCommand>
|
||||||
(e->newCUID(), e.get(), 10));
|
(e->newCUID(), e.get(), std::chrono::seconds(10)));
|
||||||
{
|
{
|
||||||
time_t stopSec = op->getAsInt(PREF_STOP);
|
auto stopSec = op->getAsInt(PREF_STOP);
|
||||||
if(stopSec > 0) {
|
if(stopSec > 0) {
|
||||||
e->addRoutineCommand(make_unique<TimedHaltCommand>(e->newCUID(), e.get(),
|
e->addRoutineCommand(make_unique<TimedHaltCommand>(
|
||||||
stopSec));
|
e->newCUID(), e.get(), std::chrono::seconds(stopSec)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(op->defined(PREF_STOP_WITH_PROCESS)) {
|
if(op->defined(PREF_STOP_WITH_PROCESS)) {
|
||||||
|
|
|
@ -60,8 +60,7 @@ struct DownloadResult
|
||||||
|
|
||||||
uint64_t sessionDownloadLength;
|
uint64_t sessionDownloadLength;
|
||||||
|
|
||||||
// milliseconds
|
std::chrono::milliseconds sessionTime;
|
||||||
int64_t sessionTime;
|
|
||||||
|
|
||||||
int64_t totalLength;
|
int64_t totalLength;
|
||||||
|
|
||||||
|
|
|
@ -71,10 +71,11 @@ bool FileAllocationCommand::executeInternal()
|
||||||
}
|
}
|
||||||
fileAllocationEntry_->allocateChunk();
|
fileAllocationEntry_->allocateChunk();
|
||||||
if(fileAllocationEntry_->finished()) {
|
if(fileAllocationEntry_->finished()) {
|
||||||
A2_LOG_DEBUG
|
A2_LOG_DEBUG(fmt(MSG_ALLOCATION_COMPLETED,
|
||||||
(fmt(MSG_ALLOCATION_COMPLETED,
|
static_cast<long int>(
|
||||||
static_cast<long int>(timer_.difference(global::wallclock())),
|
std::chrono::duration_cast<std::chrono::seconds>(
|
||||||
getRequestGroup()->getTotalLength()));
|
timer_.difference(global::wallclock())).count()),
|
||||||
|
getRequestGroup()->getTotalLength()));
|
||||||
std::vector<std::unique_ptr<Command>> commands;
|
std::vector<std::unique_ptr<Command>> commands;
|
||||||
fileAllocationEntry_->prepareForNextAction(commands, getDownloadEngine());
|
fileAllocationEntry_->prepareForNextAction(commands, getDownloadEngine());
|
||||||
getDownloadEngine()->addCommand(std::move(commands));
|
getDownloadEngine()->addCommand(std::move(commands));
|
||||||
|
|
|
@ -72,7 +72,7 @@ FileEntry::FileEntry(std::string path, int64_t length, int64_t offset,
|
||||||
offset_(offset),
|
offset_(offset),
|
||||||
uris_(uris.begin(), uris.end()),
|
uris_(uris.begin(), uris.end()),
|
||||||
path_(std::move(path)),
|
path_(std::move(path)),
|
||||||
lastFasterReplace_(0),
|
lastFasterReplace_(Timer::zero()),
|
||||||
maxConnectionPerServer_(1),
|
maxConnectionPerServer_(1),
|
||||||
requested_(true),
|
requested_(true),
|
||||||
uniqueProtocol_(false)
|
uniqueProtocol_(false)
|
||||||
|
@ -213,10 +213,13 @@ FileEntry::getRequest
|
||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
constexpr auto startupIdleTime = std::chrono::seconds(10);
|
||||||
|
} // namespace
|
||||||
|
|
||||||
std::shared_ptr<Request>
|
std::shared_ptr<Request>
|
||||||
FileEntry::findFasterRequest(const std::shared_ptr<Request>& base)
|
FileEntry::findFasterRequest(const std::shared_ptr<Request>& base)
|
||||||
{
|
{
|
||||||
const int startupIdleTime = 10;
|
|
||||||
if(requestPool_.empty() ||
|
if(requestPool_.empty() ||
|
||||||
lastFasterReplace_.difference(global::wallclock()) < startupIdleTime) {
|
lastFasterReplace_.difference(global::wallclock()) < startupIdleTime) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -248,7 +251,6 @@ FileEntry::findFasterRequest
|
||||||
const std::vector<std::pair<size_t, std::string> >& usedHosts,
|
const std::vector<std::pair<size_t, std::string> >& usedHosts,
|
||||||
const std::shared_ptr<ServerStatMan>& serverStatMan)
|
const std::shared_ptr<ServerStatMan>& serverStatMan)
|
||||||
{
|
{
|
||||||
const int startupIdleTime = 10;
|
|
||||||
const int SPEED_THRESHOLD = 20*1024;
|
const int SPEED_THRESHOLD = 20*1024;
|
||||||
if(lastFasterReplace_.difference(global::wallclock()) < startupIdleTime) {
|
if(lastFasterReplace_.difference(global::wallclock()) < startupIdleTime) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -99,7 +99,8 @@ FtpNegotiationCommand::FtpNegotiationCommand
|
||||||
{
|
{
|
||||||
ftp_->setBaseWorkingDir(baseWorkingDir);
|
ftp_->setBaseWorkingDir(baseWorkingDir);
|
||||||
if(seq == SEQ_RECV_GREETING) {
|
if(seq == SEQ_RECV_GREETING) {
|
||||||
setTimeout(getOption()->getAsInt(PREF_CONNECT_TIMEOUT));
|
setTimeout(
|
||||||
|
std::chrono::seconds(getOption()->getAsInt(PREF_CONNECT_TIMEOUT)));
|
||||||
}
|
}
|
||||||
setWriteCheckSocket(getSocket());
|
setWriteCheckSocket(getSocket());
|
||||||
}
|
}
|
||||||
|
@ -116,7 +117,8 @@ bool FtpNegotiationCommand::executeInternal() {
|
||||||
auto command = make_unique<FtpDownloadCommand>
|
auto command = make_unique<FtpDownloadCommand>
|
||||||
(getCuid(), getRequest(), getFileEntry(), getRequestGroup(), ftp_,
|
(getCuid(), getRequest(), getFileEntry(), getRequestGroup(), ftp_,
|
||||||
getDownloadEngine(), dataSocket_, getSocket());
|
getDownloadEngine(), dataSocket_, getSocket());
|
||||||
command->setStartupIdleTime(getOption()->getAsInt(PREF_STARTUP_IDLE_TIME));
|
command->setStartupIdleTime(
|
||||||
|
std::chrono::seconds(getOption()->getAsInt(PREF_STARTUP_IDLE_TIME)));
|
||||||
command->setLowestDownloadSpeedLimit
|
command->setLowestDownloadSpeedLimit
|
||||||
(getOption()->getAsInt(PREF_LOWEST_SPEED_LIMIT));
|
(getOption()->getAsInt(PREF_LOWEST_SPEED_LIMIT));
|
||||||
if(getFileEntry()->isUniqueProtocol()) {
|
if(getFileEntry()->isUniqueProtocol()) {
|
||||||
|
|
|
@ -40,8 +40,11 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
HaveEraseCommand::HaveEraseCommand(cuid_t cuid, DownloadEngine* e, time_t interval)
|
HaveEraseCommand::HaveEraseCommand(cuid_t cuid, DownloadEngine* e,
|
||||||
:TimeBasedCommand(cuid, e, interval, true) {}
|
std::chrono::seconds interval)
|
||||||
|
: TimeBasedCommand(cuid, e, std::move(interval), true)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
HaveEraseCommand::~HaveEraseCommand() {}
|
HaveEraseCommand::~HaveEraseCommand() {}
|
||||||
|
|
||||||
|
@ -60,7 +63,7 @@ void HaveEraseCommand::process()
|
||||||
for(auto & group : groups) {
|
for(auto & group : groups) {
|
||||||
const auto& ps = group->getPieceStorage();
|
const auto& ps = group->getPieceStorage();
|
||||||
if(ps) {
|
if(ps) {
|
||||||
ps->removeAdvertisedPiece(5);
|
ps->removeAdvertisedPiece(std::chrono::seconds(5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,8 @@ namespace aria2 {
|
||||||
class HaveEraseCommand : public TimeBasedCommand
|
class HaveEraseCommand : public TimeBasedCommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
HaveEraseCommand(cuid_t cuid, DownloadEngine* e, time_t interval);
|
HaveEraseCommand(cuid_t cuid, DownloadEngine* e,
|
||||||
|
std::chrono::seconds interval);
|
||||||
|
|
||||||
virtual ~HaveEraseCommand();
|
virtual ~HaveEraseCommand();
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ HttpRequestCommand::HttpRequestCommand
|
||||||
httpConnection->getSocketRecvBuffer()),
|
httpConnection->getSocketRecvBuffer()),
|
||||||
httpConnection_(httpConnection)
|
httpConnection_(httpConnection)
|
||||||
{
|
{
|
||||||
setTimeout(getOption()->getAsInt(PREF_CONNECT_TIMEOUT));
|
setTimeout(std::chrono::seconds(getOption()->getAsInt(PREF_CONNECT_TIMEOUT)));
|
||||||
disableReadCheckSocket();
|
disableReadCheckSocket();
|
||||||
setWriteCheckSocket(getSocket());
|
setWriteCheckSocket(getSocket());
|
||||||
}
|
}
|
||||||
|
|
|
@ -536,7 +536,8 @@ HttpResponseCommand::createHttpDownloadCommand
|
||||||
(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(
|
||||||
|
std::chrono::seconds(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() &&
|
||||||
|
|
|
@ -148,8 +148,8 @@ void HttpServerBodyCommand::addHttpServerResponseCommand(bool delayed)
|
||||||
auto resp =
|
auto resp =
|
||||||
make_unique<HttpServerResponseCommand>(getCuid(), httpServer_, e_, socket_);
|
make_unique<HttpServerResponseCommand>(getCuid(), httpServer_, e_, socket_);
|
||||||
if (delayed) {
|
if (delayed) {
|
||||||
e_->addCommand(
|
e_->addCommand(make_unique<DelayedCommand>(
|
||||||
make_unique<DelayedCommand>(getCuid(), e_, 1, std::move(resp), true));
|
getCuid(), e_, std::chrono::seconds(1), std::move(resp), true));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -320,7 +320,8 @@ bool HttpServerBodyCommand::execute()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(timeoutTimer_.difference(global::wallclock()) >= 30) {
|
if(timeoutTimer_.difference(global::wallclock()) >=
|
||||||
|
std::chrono::seconds(30)) {
|
||||||
A2_LOG_INFO("HTTP request body timeout.");
|
A2_LOG_INFO("HTTP request body timeout.");
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -253,7 +253,8 @@ bool HttpServerCommand::execute()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(timeoutTimer_.difference(global::wallclock()) >= 30) {
|
if(timeoutTimer_.difference(global::wallclock()) >=
|
||||||
|
std::chrono::seconds(30)) {
|
||||||
A2_LOG_INFO("HTTP request timeout.");
|
A2_LOG_INFO("HTTP request timeout.");
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -64,7 +64,7 @@ InitiateConnectionCommand::InitiateConnectionCommand
|
||||||
DownloadEngine* e)
|
DownloadEngine* e)
|
||||||
: AbstractCommand(cuid, req, fileEntry, requestGroup, e)
|
: AbstractCommand(cuid, req, fileEntry, requestGroup, e)
|
||||||
{
|
{
|
||||||
setTimeout(getOption()->getAsInt(PREF_DNS_TIMEOUT));
|
setTimeout(std::chrono::seconds(getOption()->getAsInt(PREF_DNS_TIMEOUT)));
|
||||||
// give a chance to be executed in the next loop in DownloadEngine
|
// give a chance to be executed in the next loop in DownloadEngine
|
||||||
setStatus(Command::STATUS_ONESHOT_REALTIME);
|
setStatus(Command::STATUS_ONESHOT_REALTIME);
|
||||||
disableReadCheckSocket();
|
disableReadCheckSocket();
|
||||||
|
|
|
@ -74,7 +74,8 @@ InitiatorMSEHandshakeCommand::InitiatorMSEHandshakeCommand
|
||||||
{
|
{
|
||||||
disableReadCheckSocket();
|
disableReadCheckSocket();
|
||||||
setWriteCheckSocket(getSocket());
|
setWriteCheckSocket(getSocket());
|
||||||
setTimeout(getOption()->getAsInt(PREF_PEER_CONNECTION_TIMEOUT));
|
setTimeout(std::chrono::seconds(
|
||||||
|
getOption()->getAsInt(PREF_PEER_CONNECTION_TIMEOUT)));
|
||||||
|
|
||||||
btRuntime_->increaseConnections();
|
btRuntime_->increaseConnections();
|
||||||
requestGroup_->increaseNumCommand();
|
requestGroup_->increaseNumCommand();
|
||||||
|
@ -98,7 +99,7 @@ bool InitiatorMSEHandshakeCommand::executeInternal() {
|
||||||
addCommandSelf();
|
addCommandSelf();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
setTimeout(getOption()->getAsInt(PREF_BT_TIMEOUT));
|
setTimeout(std::chrono::seconds(getOption()->getAsInt(PREF_BT_TIMEOUT)));
|
||||||
mseHandshake_->initEncryptionFacility(true);
|
mseHandshake_->initEncryptionFacility(true);
|
||||||
mseHandshake_->sendPublicKey();
|
mseHandshake_->sendPublicKey();
|
||||||
sequence_ = INITIATOR_SEND_KEY_PENDING;
|
sequence_ = INITIATOR_SEND_KEY_PENDING;
|
||||||
|
|
|
@ -48,13 +48,13 @@ LpdMessageDispatcher::LpdMessageDispatcher
|
||||||
uint16_t port,
|
uint16_t port,
|
||||||
const std::string& multicastAddress,
|
const std::string& multicastAddress,
|
||||||
uint16_t multicastPort,
|
uint16_t multicastPort,
|
||||||
time_t interval)
|
std::chrono::seconds interval)
|
||||||
: infoHash_(infoHash),
|
: infoHash_(infoHash),
|
||||||
port_(port),
|
port_(port),
|
||||||
multicastAddress_(multicastAddress),
|
multicastAddress_(multicastAddress),
|
||||||
multicastPort_(multicastPort),
|
multicastPort_(multicastPort),
|
||||||
timer_(0),
|
timer_(Timer::zero()),
|
||||||
interval_(interval),
|
interval_(std::move(interval)),
|
||||||
request_(bittorrent::createLpdRequest(multicastAddress_, multicastPort_,
|
request_(bittorrent::createLpdRequest(multicastAddress_, multicastPort_,
|
||||||
infoHash_, port_))
|
infoHash_, port_))
|
||||||
{}
|
{}
|
||||||
|
|
|
@ -52,13 +52,13 @@ private:
|
||||||
std::string multicastAddress_;
|
std::string multicastAddress_;
|
||||||
uint16_t multicastPort_;
|
uint16_t multicastPort_;
|
||||||
Timer timer_;
|
Timer timer_;
|
||||||
time_t interval_;
|
std::chrono::seconds interval_;
|
||||||
std::string request_;
|
std::string request_;
|
||||||
public:
|
public:
|
||||||
LpdMessageDispatcher
|
LpdMessageDispatcher(
|
||||||
(const std::string& infoHash, uint16_t port,
|
const std::string& infoHash, uint16_t port,
|
||||||
const std::string& multicastAddr, uint16_t multicastPort,
|
const std::string& multicastAddr, uint16_t multicastPort,
|
||||||
time_t interval = 5*60);
|
std::chrono::seconds interval = std::chrono::minutes(5));
|
||||||
|
|
||||||
~LpdMessageDispatcher();
|
~LpdMessageDispatcher();
|
||||||
|
|
||||||
|
|
|
@ -135,9 +135,9 @@ std::unique_ptr<StatCalc> getStatCalc(const std::shared_ptr<Option>& op)
|
||||||
if(op->getAsBool(PREF_QUIET)) {
|
if(op->getAsBool(PREF_QUIET)) {
|
||||||
return make_unique<NullStatCalc>();
|
return make_unique<NullStatCalc>();
|
||||||
}
|
}
|
||||||
auto impl = make_unique<ConsoleStatCalc>(op->getAsInt(PREF_SUMMARY_INTERVAL),
|
auto impl = make_unique<ConsoleStatCalc>(
|
||||||
op->getAsBool(PREF_ENABLE_COLOR),
|
std::chrono::seconds(op->getAsInt(PREF_SUMMARY_INTERVAL)),
|
||||||
op->getAsBool(PREF_HUMAN_READABLE));
|
op->getAsBool(PREF_ENABLE_COLOR), op->getAsBool(PREF_HUMAN_READABLE));
|
||||||
impl->setReadoutVisibility(op->getAsBool(PREF_SHOW_CONSOLE_READOUT));
|
impl->setReadoutVisibility(op->getAsBool(PREF_SHOW_CONSOLE_READOUT));
|
||||||
impl->setTruncate(op->getAsBool(PREF_TRUNCATE_CONSOLE_READOUT));
|
impl->setTruncate(op->getAsBool(PREF_TRUNCATE_CONSOLE_READOUT));
|
||||||
return std::move(impl);
|
return std::move(impl);
|
||||||
|
@ -273,10 +273,6 @@ int MultiUrlRequestInfo::prepare()
|
||||||
parseAsyncDNSServers(option_->get(PREF_ASYNC_DNS_SERVER));
|
parseAsyncDNSServers(option_->get(PREF_ASYNC_DNS_SERVER));
|
||||||
e_->setAsyncDNSServers(asyncDNSServers);
|
e_->setAsyncDNSServers(asyncDNSServers);
|
||||||
#endif // HAVE_ARES_ADDR_NODE
|
#endif // HAVE_ARES_ADDR_NODE
|
||||||
if(!Timer::monotonicClock()) {
|
|
||||||
A2_LOG_WARN("Don't change system time while aria2c is running."
|
|
||||||
" Doing this may make aria2c hang for long time.");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string serverStatIf = option_->get(PREF_SERVER_STAT_IF);
|
std::string serverStatIf = option_->get(PREF_SERVER_STAT_IF);
|
||||||
if(!serverStatIf.empty()) {
|
if(!serverStatIf.empty()) {
|
||||||
|
|
|
@ -51,7 +51,7 @@ Peer::Peer(std::string ipaddr, uint16_t port, bool incoming):
|
||||||
origPort_(port),
|
origPort_(port),
|
||||||
cuid_(0),
|
cuid_(0),
|
||||||
firstContactTime_(global::wallclock()),
|
firstContactTime_(global::wallclock()),
|
||||||
dropStartTime_(0),
|
dropStartTime_(Timer::zero()),
|
||||||
seeder_(false),
|
seeder_(false),
|
||||||
incoming_(incoming),
|
incoming_(incoming),
|
||||||
localPeer_(false),
|
localPeer_(false),
|
||||||
|
|
|
@ -57,7 +57,7 @@ PeerAbstractCommand::PeerAbstractCommand
|
||||||
: Command(cuid),
|
: Command(cuid),
|
||||||
checkPoint_(global::wallclock()),
|
checkPoint_(global::wallclock()),
|
||||||
// TODO referring global option
|
// TODO referring global option
|
||||||
timeout_(e->getOption()->getAsInt(PREF_BT_TIMEOUT)),
|
timeout_(std::chrono::seconds(e->getOption()->getAsInt(PREF_BT_TIMEOUT))),
|
||||||
e_(e),
|
e_(e),
|
||||||
socket_(s),
|
socket_(s),
|
||||||
peer_(peer),
|
peer_(peer),
|
||||||
|
|
|
@ -51,7 +51,7 @@ class SocketCore;
|
||||||
class PeerAbstractCommand : public Command {
|
class PeerAbstractCommand : public Command {
|
||||||
private:
|
private:
|
||||||
Timer checkPoint_;
|
Timer checkPoint_;
|
||||||
time_t timeout_;
|
std::chrono::seconds timeout_;
|
||||||
DownloadEngine* e_;
|
DownloadEngine* e_;
|
||||||
std::shared_ptr<SocketCore> socket_;
|
std::shared_ptr<SocketCore> socket_;
|
||||||
std::shared_ptr<Peer> peer_;
|
std::shared_ptr<Peer> peer_;
|
||||||
|
@ -79,7 +79,11 @@ protected:
|
||||||
return peer_;
|
return peer_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTimeout(time_t timeout) { timeout_ = timeout; }
|
void setTimeout(std::chrono::seconds timeout)
|
||||||
|
{
|
||||||
|
timeout_ = std::move(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool prepareForNextPeer(time_t wait);
|
virtual bool prepareForNextPeer(time_t wait);
|
||||||
virtual void onAbort() {};
|
virtual void onAbort() {};
|
||||||
// This function is called when DownloadFailureException is caught right after
|
// This function is called when DownloadFailureException is caught right after
|
||||||
|
|
|
@ -102,7 +102,8 @@ PeerInteractionCommand::PeerInteractionCommand
|
||||||
if(sequence_ == INITIATOR_SEND_HANDSHAKE) {
|
if(sequence_ == INITIATOR_SEND_HANDSHAKE) {
|
||||||
disableReadCheckSocket();
|
disableReadCheckSocket();
|
||||||
setWriteCheckSocket(getSocket());
|
setWriteCheckSocket(getSocket());
|
||||||
setTimeout(getOption()->getAsInt(PREF_PEER_CONNECTION_TIMEOUT));
|
setTimeout(std::chrono::seconds(
|
||||||
|
getOption()->getAsInt(PREF_PEER_CONNECTION_TIMEOUT)));
|
||||||
}
|
}
|
||||||
|
|
||||||
int family;
|
int family;
|
||||||
|
@ -180,8 +181,8 @@ PeerInteractionCommand::PeerInteractionCommand
|
||||||
dispatcher->setCuid(cuid);
|
dispatcher->setCuid(cuid);
|
||||||
dispatcher->setPeer(getPeer());
|
dispatcher->setPeer(getPeer());
|
||||||
dispatcher->setDownloadContext(requestGroup_->getDownloadContext().get());
|
dispatcher->setDownloadContext(requestGroup_->getDownloadContext().get());
|
||||||
dispatcher->setRequestTimeout(getOption()->
|
dispatcher->setRequestTimeout(
|
||||||
getAsInt(PREF_BT_REQUEST_TIMEOUT));
|
std::chrono::seconds(getOption()->getAsInt(PREF_BT_REQUEST_TIMEOUT)));
|
||||||
dispatcher->setBtMessageFactory(factory.get());
|
dispatcher->setBtMessageFactory(factory.get());
|
||||||
dispatcher->setRequestGroupMan
|
dispatcher->setRequestGroupMan
|
||||||
(getDownloadEngine()->getRequestGroupMan().get());
|
(getDownloadEngine()->getRequestGroupMan().get());
|
||||||
|
@ -227,7 +228,7 @@ PeerInteractionCommand::PeerInteractionCommand
|
||||||
(std::move(extensionMessageFactory));
|
(std::move(extensionMessageFactory));
|
||||||
btInteractive->setExtensionMessageRegistry(std::move(exMsgRegistry));
|
btInteractive->setExtensionMessageRegistry(std::move(exMsgRegistry));
|
||||||
btInteractive->setKeepAliveInterval
|
btInteractive->setKeepAliveInterval
|
||||||
(getOption()->getAsInt(PREF_BT_KEEP_ALIVE_INTERVAL));
|
(std::chrono::seconds(getOption()->getAsInt(PREF_BT_KEEP_ALIVE_INTERVAL)));
|
||||||
btInteractive->setRequestGroupMan
|
btInteractive->setRequestGroupMan
|
||||||
(getDownloadEngine()->getRequestGroupMan().get());
|
(getDownloadEngine()->getRequestGroupMan().get());
|
||||||
btInteractive->setBtMessageFactory(std::move(factory));
|
btInteractive->setBtMessageFactory(std::move(factory));
|
||||||
|
@ -307,7 +308,7 @@ bool PeerInteractionCommand::executeInternal() {
|
||||||
disableWriteCheckSocket();
|
disableWriteCheckSocket();
|
||||||
setReadCheckSocket(getSocket());
|
setReadCheckSocket(getSocket());
|
||||||
//socket->setBlockingMode();
|
//socket->setBlockingMode();
|
||||||
setTimeout(getOption()->getAsInt(PREF_BT_TIMEOUT));
|
setTimeout(std::chrono::seconds(getOption()->getAsInt(PREF_BT_TIMEOUT)));
|
||||||
btInteractive_->initiateHandshake();
|
btInteractive_->initiateHandshake();
|
||||||
sequence_ = INITIATOR_WAIT_HANDSHAKE;
|
sequence_ = INITIATOR_WAIT_HANDSHAKE;
|
||||||
break;
|
break;
|
||||||
|
@ -403,7 +404,7 @@ void PeerInteractionCommand::onFailure(const Exception& err)
|
||||||
{
|
{
|
||||||
requestGroup_->setLastErrorCode(err.getErrorCode());
|
requestGroup_->setLastErrorCode(err.getErrorCode());
|
||||||
requestGroup_->setHaltRequested(true);
|
requestGroup_->setHaltRequested(true);
|
||||||
getDownloadEngine()->setRefreshInterval(0);
|
getDownloadEngine()->setRefreshInterval(std::chrono::milliseconds(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PeerInteractionCommand::exitBeforeExecute()
|
bool PeerInteractionCommand::exitBeforeExecute()
|
||||||
|
|
|
@ -48,8 +48,8 @@ namespace aria2 {
|
||||||
PeerSessionResource::PeerSessionResource(int32_t pieceLength, int64_t totalLength)
|
PeerSessionResource::PeerSessionResource(int32_t pieceLength, int64_t totalLength)
|
||||||
:
|
:
|
||||||
bitfieldMan_(make_unique<BitfieldMan>(pieceLength, totalLength)),
|
bitfieldMan_(make_unique<BitfieldMan>(pieceLength, totalLength)),
|
||||||
lastDownloadUpdate_(0),
|
lastDownloadUpdate_(Timer::zero()),
|
||||||
lastAmUnchoking_(0),
|
lastAmUnchoking_(Timer::zero()),
|
||||||
dispatcher_(nullptr),
|
dispatcher_(nullptr),
|
||||||
amChoking_(true),
|
amChoking_(true),
|
||||||
amInterested_(false),
|
amInterested_(false),
|
||||||
|
|
|
@ -254,7 +254,7 @@ public:
|
||||||
* Removes have entry if specified seconds have elapsed since its
|
* Removes have entry if specified seconds have elapsed since its
|
||||||
* registration.
|
* registration.
|
||||||
*/
|
*/
|
||||||
virtual void removeAdvertisedPiece(time_t elapsed) = 0;
|
virtual void removeAdvertisedPiece(const std::chrono::seconds& elapsed) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets all bits in bitfield to 1.
|
* Sets all bits in bitfield to 1.
|
||||||
|
|
|
@ -63,7 +63,8 @@ ReceiverMSEHandshakeCommand::ReceiverMSEHandshakeCommand
|
||||||
sequence_(RECEIVER_IDENTIFY_HANDSHAKE),
|
sequence_(RECEIVER_IDENTIFY_HANDSHAKE),
|
||||||
mseHandshake_(make_unique<MSEHandshake>(cuid, s, e->getOption()))
|
mseHandshake_(make_unique<MSEHandshake>(cuid, s, e->getOption()))
|
||||||
{
|
{
|
||||||
setTimeout(e->getOption()->getAsInt(PREF_PEER_CONNECTION_TIMEOUT));
|
setTimeout(std::chrono::seconds(
|
||||||
|
e->getOption()->getAsInt(PREF_PEER_CONNECTION_TIMEOUT)));
|
||||||
mseHandshake_->setWantRead(true);
|
mseHandshake_->setWantRead(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -337,7 +337,7 @@ void RequestGroup::createInitialCommand
|
||||||
btAnnounce->setPieceStorage(pieceStorage_);
|
btAnnounce->setPieceStorage(pieceStorage_);
|
||||||
btAnnounce->setPeerStorage(peerStorage);
|
btAnnounce->setPeerStorage(peerStorage);
|
||||||
btAnnounce->setUserDefinedInterval
|
btAnnounce->setUserDefinedInterval
|
||||||
(option_->getAsInt(PREF_BT_TRACKER_INTERVAL));
|
(std::chrono::seconds(option_->getAsInt(PREF_BT_TRACKER_INTERVAL)));
|
||||||
btAnnounce->shuffleAnnounce();
|
btAnnounce->shuffleAnnounce();
|
||||||
|
|
||||||
assert(!btRegistry->get(gid_->getNumericId()));
|
assert(!btRegistry->get(gid_->getNumericId()));
|
||||||
|
@ -978,7 +978,7 @@ void RequestGroup::releaseRuntimeResource(DownloadEngine* e)
|
||||||
peerStorage_ = nullptr;
|
peerStorage_ = nullptr;
|
||||||
#endif // ENABLE_BITTORRENT
|
#endif // ENABLE_BITTORRENT
|
||||||
if(pieceStorage_) {
|
if(pieceStorage_) {
|
||||||
pieceStorage_->removeAdvertisedPiece(0);
|
pieceStorage_->removeAdvertisedPiece(std::chrono::seconds(0));
|
||||||
}
|
}
|
||||||
// Don't reset segmentMan_ and pieceStorage_ here to provide
|
// Don't reset segmentMan_ and pieceStorage_ here to provide
|
||||||
// progress information via RPC
|
// progress information via RPC
|
||||||
|
@ -1129,7 +1129,8 @@ std::shared_ptr<DownloadResult> RequestGroup::createDownloadResult() const
|
||||||
res->fileEntries = downloadContext_->getFileEntries();
|
res->fileEntries = downloadContext_->getFileEntries();
|
||||||
res->inMemoryDownload = inMemoryDownload_;
|
res->inMemoryDownload = inMemoryDownload_;
|
||||||
res->sessionDownloadLength = st.sessionDownloadLength;
|
res->sessionDownloadLength = st.sessionDownloadLength;
|
||||||
res->sessionTime = downloadContext_->calculateSessionTime();
|
res->sessionTime = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
|
downloadContext_->calculateSessionTime());
|
||||||
res->result = downloadResult();
|
res->result = downloadResult();
|
||||||
res->followedBy = followedByGIDs_;
|
res->followedBy = followedByGIDs_;
|
||||||
res->belongsTo = belongsToGID_;
|
res->belongsTo = belongsToGID_;
|
||||||
|
@ -1219,9 +1220,9 @@ void RequestGroup::markInMemoryDownload()
|
||||||
inMemoryDownload_ = true;
|
inMemoryDownload_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RequestGroup::setTimeout(time_t timeout)
|
void RequestGroup::setTimeout(std::chrono::seconds timeout)
|
||||||
{
|
{
|
||||||
timeout_ = timeout;
|
timeout_ = std::move(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RequestGroup::doesDownloadSpeedExceed()
|
bool RequestGroup::doesDownloadSpeedExceed()
|
||||||
|
|
|
@ -136,7 +136,7 @@ private:
|
||||||
Time lastModifiedTime_;
|
Time lastModifiedTime_;
|
||||||
|
|
||||||
// Timeout used for HTTP/FTP downloads.
|
// Timeout used for HTTP/FTP downloads.
|
||||||
time_t timeout_;
|
std::chrono::seconds timeout_;
|
||||||
|
|
||||||
int state_;
|
int state_;
|
||||||
|
|
||||||
|
@ -444,12 +444,9 @@ public:
|
||||||
return inMemoryDownload_;
|
return inMemoryDownload_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTimeout(time_t timeout);
|
void setTimeout(std::chrono::seconds timeout);
|
||||||
|
|
||||||
time_t getTimeout() const
|
const std::chrono::seconds& getTimeout() const { return timeout_; }
|
||||||
{
|
|
||||||
return timeout_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns true if current download speed exceeds
|
// Returns true if current download speed exceeds
|
||||||
// maxDownloadSpeedLimit_. Always returns false if
|
// maxDownloadSpeedLimit_. Always returns false if
|
||||||
|
|
|
@ -524,7 +524,7 @@ void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e)
|
||||||
}
|
}
|
||||||
if(count > 0) {
|
if(count > 0) {
|
||||||
e->setNoWait(true);
|
e->setNoWait(true);
|
||||||
e->setRefreshInterval(0);
|
e->setRefreshInterval(std::chrono::milliseconds(0));
|
||||||
A2_LOG_DEBUG(fmt("%d RequestGroup(s) added.", count));
|
A2_LOG_DEBUG(fmt("%d RequestGroup(s) added.", count));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -704,10 +704,9 @@ void formatDownloadResultCommon
|
||||||
o << std::setw(3) << downloadResult->gid->toAbbrevHex() << "|"
|
o << std::setw(3) << downloadResult->gid->toAbbrevHex() << "|"
|
||||||
<< std::setw(4) << status << "|"
|
<< std::setw(4) << status << "|"
|
||||||
<< std::setw(11);
|
<< std::setw(11);
|
||||||
if(downloadResult->sessionTime > 0) {
|
if(downloadResult->sessionTime.count() > 0) {
|
||||||
o << util::abbrevSize
|
o << util::abbrevSize(downloadResult->sessionDownloadLength * 1000 /
|
||||||
(downloadResult->sessionDownloadLength*1000/downloadResult->sessionTime)+
|
downloadResult->sessionTime.count()) << "B/s";
|
||||||
"B/s";
|
|
||||||
} else {
|
} else {
|
||||||
o << "n/a";
|
o << "n/a";
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,12 +36,9 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
void RequestSlot::setDispatchedTime(time_t sec) {
|
bool RequestSlot::isTimeout(const std::chrono::seconds& t) const
|
||||||
dispatchedTime_.reset(sec);
|
{
|
||||||
}
|
return dispatchedTime_.difference(global::wallclock()) >= t;
|
||||||
|
|
||||||
bool RequestSlot::isTimeout(time_t timeoutSec) const {
|
|
||||||
return dispatchedTime_.difference(global::wallclock()) >= timeoutSec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -51,8 +51,12 @@ public:
|
||||||
piece_(std::move(piece))
|
piece_(std::move(piece))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
RequestSlot():dispatchedTime_(0), index_(0), begin_(0), length_(0),
|
RequestSlot()
|
||||||
blockIndex_(0)
|
: dispatchedTime_(Timer::zero()),
|
||||||
|
index_(0),
|
||||||
|
begin_(0),
|
||||||
|
length_(0),
|
||||||
|
blockIndex_(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool operator==(const RequestSlot& requestSlot) const
|
bool operator==(const RequestSlot& requestSlot) const
|
||||||
|
@ -75,9 +79,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDispatchedTime(time_t secFromEpoch);
|
bool isTimeout(const std::chrono::seconds& t) const;
|
||||||
|
|
||||||
bool isTimeout(time_t timeoutSec) const;
|
|
||||||
|
|
||||||
size_t getIndex() const { return index_; }
|
size_t getIndex() const { return index_; }
|
||||||
void setIndex(size_t index) { index_ = index; }
|
void setIndex(size_t index) { index_ = index; }
|
||||||
|
@ -95,6 +97,10 @@ public:
|
||||||
{
|
{
|
||||||
return piece_;
|
return piece_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For unit test
|
||||||
|
void setDispatchedTime(Timer t) { dispatchedTime_ = std::move(t); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Timer dispatchedTime_;
|
Timer dispatchedTime_;
|
||||||
size_t index_;
|
size_t index_;
|
||||||
|
|
|
@ -391,7 +391,7 @@ std::unique_ptr<ValueBase> removeDownload
|
||||||
} else {
|
} else {
|
||||||
group->setHaltRequested(true, RequestGroup::USER_REQUEST);
|
group->setHaltRequested(true, RequestGroup::USER_REQUEST);
|
||||||
}
|
}
|
||||||
e->setRefreshInterval(0);
|
e->setRefreshInterval(std::chrono::milliseconds(0));
|
||||||
} else {
|
} else {
|
||||||
if(group->isDependencyResolved()) {
|
if(group->isDependencyResolved()) {
|
||||||
e->getRequestGroupMan()->removeReservedGroup(gid);
|
e->getRequestGroupMan()->removeReservedGroup(gid);
|
||||||
|
@ -431,7 +431,7 @@ std::unique_ptr<ValueBase> pauseDownload
|
||||||
if(group) {
|
if(group) {
|
||||||
bool reserved = group->getState() == RequestGroup::STATE_WAITING;
|
bool reserved = group->getState() == RequestGroup::STATE_WAITING;
|
||||||
if(pauseRequestGroup(group, reserved, forcePause)) {
|
if(pauseRequestGroup(group, reserved, forcePause)) {
|
||||||
e->setRefreshInterval(0);
|
e->setRefreshInterval(std::chrono::milliseconds(0));
|
||||||
return createGIDResponse(gid);
|
return createGIDResponse(gid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1306,8 +1306,8 @@ std::unique_ptr<ValueBase> goingShutdown
|
||||||
{
|
{
|
||||||
// Schedule shutdown after 3seconds to give time to client to
|
// Schedule shutdown after 3seconds to give time to client to
|
||||||
// receive RPC response.
|
// receive RPC response.
|
||||||
e->addRoutineCommand(make_unique<TimedHaltCommand>
|
e->addRoutineCommand(make_unique<TimedHaltCommand>(
|
||||||
(e->newCUID(), e, 3, forceHalt));
|
e->newCUID(), e, std::chrono::seconds(3), forceHalt));
|
||||||
A2_LOG_INFO("Scheduled shutdown in 3 seconds.");
|
A2_LOG_INFO("Scheduled shutdown in 3 seconds.");
|
||||||
return createOKResponse();
|
return createOKResponse();
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,8 +44,8 @@
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
SaveSessionCommand::SaveSessionCommand
|
SaveSessionCommand::SaveSessionCommand
|
||||||
(cuid_t cuid, DownloadEngine* e, time_t interval)
|
(cuid_t cuid, DownloadEngine* e, std::chrono::seconds interval)
|
||||||
: TimeBasedCommand(cuid, e, interval, true)
|
: TimeBasedCommand(cuid, e, std::move(interval), true)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
SaveSessionCommand::~SaveSessionCommand() {}
|
SaveSessionCommand::~SaveSessionCommand() {}
|
||||||
|
|
|
@ -42,7 +42,8 @@ namespace aria2 {
|
||||||
class SaveSessionCommand : public TimeBasedCommand
|
class SaveSessionCommand : public TimeBasedCommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SaveSessionCommand(cuid_t cuid, DownloadEngine* e, time_t interval);
|
SaveSessionCommand(cuid_t cuid, DownloadEngine* e,
|
||||||
|
std::chrono::seconds interval);
|
||||||
|
|
||||||
virtual ~SaveSessionCommand();
|
virtual ~SaveSessionCommand();
|
||||||
|
|
||||||
|
|
|
@ -168,7 +168,7 @@ bool SftpNegotiationCommand::executeInternal() {
|
||||||
(getCuid(), getRequest(), getFileEntry(), getRequestGroup(),
|
(getCuid(), getRequest(), getFileEntry(), getRequestGroup(),
|
||||||
getDownloadEngine(), getSocket(), std::move(authConfig_));
|
getDownloadEngine(), getSocket(), std::move(authConfig_));
|
||||||
command->setStartupIdleTime
|
command->setStartupIdleTime
|
||||||
(getOption()->getAsInt(PREF_STARTUP_IDLE_TIME));
|
(std::chrono::seconds(getOption()->getAsInt(PREF_STARTUP_IDLE_TIME)));
|
||||||
command->setLowestDownloadSpeedLimit
|
command->setLowestDownloadSpeedLimit
|
||||||
(getOption()->getAsInt(PREF_LOWEST_SPEED_LIMIT));
|
(getOption()->getAsInt(PREF_LOWEST_SPEED_LIMIT));
|
||||||
command->setStatus(Command::STATUS_ONESHOT_REALTIME);
|
command->setStatus(Command::STATUS_ONESHOT_REALTIME);
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue