From 579457eae04317ab77788424e64f4bb334251d3c Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 19 May 2009 11:29:23 +0000 Subject: [PATCH] 2009-05-19 Tatsuhiro Tsujikawa Added SEED to console output, which represents the number of seeders currently the client is connecting to. * src/ConsoleStatCalc.cc * src/ConsoleStatCalc.h * src/DownloadEngine.cc * src/NullStatCalc.h * src/StatCalc.h --- ChangeLog | 10 ++++++ src/ConsoleStatCalc.cc | 75 +++++++++++++++++++++++++++--------------- src/ConsoleStatCalc.h | 5 +-- src/DownloadEngine.cc | 2 +- src/NullStatCalc.h | 5 +-- src/StatCalc.h | 9 ++--- 6 files changed, 64 insertions(+), 42 deletions(-) diff --git a/ChangeLog b/ChangeLog index 04c48a0f..c5290aae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2009-05-19 Tatsuhiro Tsujikawa + + Added SEED to console output, which represents the number of + seeders currently the client is connecting to. + * src/ConsoleStatCalc.cc + * src/ConsoleStatCalc.h + * src/DownloadEngine.cc + * src/NullStatCalc.h + * src/StatCalc.h + 2009-05-18 Tatsuhiro Tsujikawa Added source filename(__FILE__) and line number(__LINE__) to diff --git a/src/ConsoleStatCalc.cc b/src/ConsoleStatCalc.cc index cbd43984..7f2feda9 100644 --- a/src/ConsoleStatCalc.cc +++ b/src/ConsoleStatCalc.cc @@ -49,6 +49,7 @@ #include #include +#include "DownloadEngine.h" #include "RequestGroupMan.h" #include "RequestGroup.h" #include "FileAllocationMan.h" @@ -58,11 +59,19 @@ #include "Util.h" #ifdef ENABLE_BITTORRENT # include "BtContext.h" +# include "Peer.h" +# include "PeerStorage.h" +# include "BtRegistry.h" +# include "BtProgressInfoFile.h" +# include "BtRuntime.h" +# include "BtAnnounce.h" +# include "PieceStorage.h" #endif // ENABLE_BITTORRENT namespace aria2 { -static void printProgress(std::ostream& o, const SharedHandle& rg) +static void printProgress +(std::ostream& o, const SharedHandle& rg, const DownloadEngine* e) { TransferStat stat = rg->calculateStat(); unsigned int eta = 0; @@ -72,9 +81,12 @@ static void printProgress(std::ostream& o, const SharedHandle& rg) o << "[" << "#" << rg->getGID() << " "; + #ifdef ENABLE_BITTORRENT - if(rg->downloadFinished() && - !dynamic_pointer_cast(rg->getDownloadContext()).isNull()) { + SharedHandle btctx = + dynamic_pointer_cast(rg->getDownloadContext()); + + if(!btctx.isNull() && rg->downloadFinished()) { o << "SEEDING" << "(" << "ratio:"; if(rg->getCompletedLength() > 0) { o << std::fixed << std::setprecision(1) @@ -101,6 +113,17 @@ static void printProgress(std::ostream& o, const SharedHandle& rg) o << " " << "CN:" << rg->getNumConnection(); +#ifdef ENABLE_BITTORRENT + if(!btctx.isNull()) { + SharedHandle ps = + e->getBtRegistry()->getPeerStorage(btctx->getInfoHashAsString()); + std::deque > peers; + ps->getActivePeers(peers); + o << " " << "SEED:" + << std::count_if(peers.begin(), peers.end(), mem_fun_sh(&Peer::isSeeder)); + } +#endif // ENABLE_BITTORRENT + if(!rg->downloadFinished()) { o << " " << "SPD:" @@ -124,20 +147,23 @@ class PrintSummary { private: size_t _cols; + const DownloadEngine* _e; public: - PrintSummary(size_t cols):_cols(cols) {} + PrintSummary(size_t cols, const DownloadEngine* e):_cols(cols), _e(e) {} void operator()(const SharedHandle& rg) { const char SEP_CHAR = '-'; - printProgress(std::cout, rg); + printProgress(std::cout, rg, _e); std::cout << "\n" << "FILE: " << rg->getFilePath() << "\n" << std::setfill(SEP_CHAR) << std::setw(_cols) << SEP_CHAR << "\n"; } }; -static void printProgressSummary(const std::deque >& groups, size_t cols) +static void printProgressSummary +(const std::deque >& groups, size_t cols, + const DownloadEngine* e) { const char SEP_CHAR = '='; time_t now; @@ -158,7 +184,7 @@ static void printProgressSummary(const std::deque >& } std::cout << " *** " << "\n" << std::setfill(SEP_CHAR) << std::setw(cols) << SEP_CHAR << "\n"; - std::for_each(groups.begin(), groups.end(), PrintSummary(cols)); + std::for_each(groups.begin(), groups.end(), PrintSummary(cols, e)); } ConsoleStatCalc::ConsoleStatCalc(time_t summaryInterval): @@ -166,10 +192,7 @@ ConsoleStatCalc::ConsoleStatCalc(time_t summaryInterval): {} void -ConsoleStatCalc::calculateStat -(const RequestGroupManHandle& requestGroupMan, - const SharedHandle& fileAllocationMan, - const SharedHandle& checkIntegrityMan) +ConsoleStatCalc::calculateStat(const DownloadEngine* e) { if(!_cp.elapsed(1)) { return; @@ -188,35 +211,35 @@ ConsoleStatCalc::calculateStat std::cout << '\r' << std::setfill(' ') << std::setw(cols) << ' ' << '\r'; } std::ostringstream o; - if(requestGroupMan->countRequestGroup() > 0) { + if(e->_requestGroupMan->countRequestGroup() > 0) { if((_summaryInterval > 0) && _lastSummaryNotified.elapsed(_summaryInterval)) { _lastSummaryNotified.reset(); - printProgressSummary(requestGroupMan->getRequestGroups(), cols); + printProgressSummary(e->_requestGroupMan->getRequestGroups(), cols, e); std::cout << "\n"; } - RequestGroupHandle firstRequestGroup = requestGroupMan->getRequestGroup(0); + RequestGroupHandle firstRequestGroup = e->_requestGroupMan->getRequestGroup(0); - printProgress(o, firstRequestGroup); + printProgress(o, firstRequestGroup, e); - if(requestGroupMan->countRequestGroup() > 1) { + if(e->_requestGroupMan->countRequestGroup() > 1) { o << "(" - << requestGroupMan->countRequestGroup()-1 + << e->_requestGroupMan->countRequestGroup()-1 << "more...)"; } } - if(requestGroupMan->countRequestGroup() > 1 && - !requestGroupMan->downloadFinished()) { - TransferStat stat = requestGroupMan->calculateStat(); + if(e->_requestGroupMan->countRequestGroup() > 1 && + !e->_requestGroupMan->downloadFinished()) { + TransferStat stat = e->_requestGroupMan->calculateStat(); o << " " << "[TOTAL SPD:" << std::fixed << std::setprecision(2) << stat.getDownloadSpeed()/1024.0 << "KiB/s" << "]"; } { - SharedHandle entry=fileAllocationMan->getPickedEntry(); + SharedHandle entry=e->_fileAllocationMan->getPickedEntry(); if(!entry.isNull()) { o << " " << "[FileAlloc:" @@ -234,16 +257,16 @@ ConsoleStatCalc::calculateStat } o << "%)" << "]"; - if(fileAllocationMan->hasNext()) { + if(e->_fileAllocationMan->hasNext()) { o << "(" - << fileAllocationMan->countEntryInQueue() + << e->_fileAllocationMan->countEntryInQueue() << "waiting...)"; } } } #ifdef ENABLE_MESSAGE_DIGEST { - CheckIntegrityEntryHandle entry = checkIntegrityMan->getPickedEntry(); + CheckIntegrityEntryHandle entry = e->_checkIntegrityMan->getPickedEntry(); if(!entry.isNull()) { o << " " << "[Checksum:" @@ -257,9 +280,9 @@ ConsoleStatCalc::calculateStat << 100*entry->getCurrentLength()/entry->getTotalLength() << "%)" << "]"; - if(checkIntegrityMan->hasNext()) { + if(e->_checkIntegrityMan->hasNext()) { o << "(" - << checkIntegrityMan->countEntryInQueue() + << e->_checkIntegrityMan->countEntryInQueue() << "waiting...)"; } } diff --git a/src/ConsoleStatCalc.h b/src/ConsoleStatCalc.h index d290944d..a71149a7 100644 --- a/src/ConsoleStatCalc.h +++ b/src/ConsoleStatCalc.h @@ -53,10 +53,7 @@ public: virtual ~ConsoleStatCalc() {} - virtual void - calculateStat(const SharedHandle& requestGroupMan, - const SharedHandle& fileAllocationMan, - const SharedHandle& checkIntegrityMan); + virtual void calculateStat(const DownloadEngine* e); }; typedef SharedHandle ConsoleStatCalcHandle; diff --git a/src/DownloadEngine.cc b/src/DownloadEngine.cc index 8e98acf2..b65a37bb 100644 --- a/src/DownloadEngine.cc +++ b/src/DownloadEngine.cc @@ -191,7 +191,7 @@ bool DownloadEngine::deleteSocketForWriteCheck(const SocketHandle& socket, void DownloadEngine::calculateStatistics() { if(!_statCalc.isNull()) { - _statCalc->calculateStat(_requestGroupMan, _fileAllocationMan, _checkIntegrityMan); + _statCalc->calculateStat(this); } } diff --git a/src/NullStatCalc.h b/src/NullStatCalc.h index 375fe6bd..912d837e 100644 --- a/src/NullStatCalc.h +++ b/src/NullStatCalc.h @@ -43,10 +43,7 @@ class NullStatCalc:public StatCalc { public: virtual ~NullStatCalc() {} - virtual void - calculateStat(const SharedHandle& requestGroupMan, - const SharedHandle& fileAllocationMan, - const SharedHandle& checkIntegrityMan) {} + virtual void calculateStat(const DownloadEngine* e) {} }; } // namespace aria2 diff --git a/src/StatCalc.h b/src/StatCalc.h index 635366db..7aea53f6 100644 --- a/src/StatCalc.h +++ b/src/StatCalc.h @@ -37,21 +37,16 @@ #include "common.h" #include "SharedHandle.h" -#include "FileAllocationMan.h" -#include "CheckIntegrityMan.h" namespace aria2 { -class RequestGroupMan; +class DownloadEngine; class StatCalc { public: virtual ~StatCalc() {} - virtual void - calculateStat(const SharedHandle& requestGroupMan, - const SharedHandle& fileAllocationMan, - const SharedHandle& checkIntegrityMan) = 0; + virtual void calculateStat(const DownloadEngine* e) = 0; }; typedef SharedHandle StatCalcHandle;