2009-06-07 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Added countSeeder() function which counts seeder in the given
	iterator range. Use it in ConsoleStatCalc and XmlRpcMethodImpl.
	* src/ConsoleStatCalc.cc
	* src/Peer.h
	* src/XmlRpcMethodImpl.cc
	* test/PeerTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2009-06-07 05:34:10 +00:00
parent 4dc9217bb6
commit b922020985
5 changed files with 40 additions and 4 deletions

View File

@ -1,3 +1,12 @@
2009-06-07 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added countSeeder() function which counts seeder in the given
iterator range. Use it in ConsoleStatCalc and XmlRpcMethodImpl.
* src/ConsoleStatCalc.cc
* src/Peer.h
* src/XmlRpcMethodImpl.cc
* test/PeerTest.cc
2009-06-06 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2009-06-06 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Documented missing seeder in getPeers xml-rpc method. Documented missing seeder in getPeers xml-rpc method.

View File

@ -120,7 +120,7 @@ static void printProgress
std::deque<SharedHandle<Peer> > peers; std::deque<SharedHandle<Peer> > peers;
ps->getActivePeers(peers); ps->getActivePeers(peers);
o << " " << "SEED:" o << " " << "SEED:"
<< std::count_if(peers.begin(), peers.end(), mem_fun_sh(&Peer::isSeeder)); << countSeeder(peers.begin(), peers.end());
} }
#endif // ENABLE_BITTORRENT #endif // ENABLE_BITTORRENT

View File

@ -40,11 +40,13 @@
#include <cassert> #include <cassert>
#include <string> #include <string>
#include <deque> #include <deque>
#include <algorithm>
#include "SharedHandle.h" #include "SharedHandle.h"
#include "TimeA2.h" #include "TimeA2.h"
#include "BtConstants.h" #include "BtConstants.h"
#include "PeerStat.h" #include "PeerStat.h"
#include "a2functional.h"
namespace aria2 { namespace aria2 {
@ -289,6 +291,12 @@ public:
size_t countOutstandingUpload() const; size_t countOutstandingUpload() const;
}; };
template<typename InputIterator>
size_t countSeeder(InputIterator first, InputIterator last)
{
return std::count_if(first, last, mem_fun_sh(&Peer::isSeeder));
}
typedef SharedHandle<Peer> PeerHandle; typedef SharedHandle<Peer> PeerHandle;
typedef std::deque<PeerHandle> Peers; typedef std::deque<PeerHandle> Peers;

View File

@ -293,9 +293,7 @@ static void gatherProgressBitTorrent
std::deque<SharedHandle<Peer> > peers; std::deque<SharedHandle<Peer> > peers;
peerStorage->getActivePeers(peers); peerStorage->getActivePeers(peers);
entryDict["numSeeders"] = entryDict["numSeeders"] = countSeeder(peers.begin(), peers.end());
Util::uitos(std::count_if(peers.begin(), peers.end(),
mem_fun_sh(&Peer::isSeeder)));
} }
static void gatherPeer(BDE& peers, const SharedHandle<PeerStorage>& ps) static void gatherPeer(BDE& peers, const SharedHandle<PeerStorage>& ps)

View File

@ -10,6 +10,7 @@ class PeerTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testAmAllowedIndexSet); CPPUNIT_TEST(testAmAllowedIndexSet);
CPPUNIT_TEST(testGetId); CPPUNIT_TEST(testGetId);
CPPUNIT_TEST(testOperatorEqual); CPPUNIT_TEST(testOperatorEqual);
CPPUNIT_TEST(testCountSeeder);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
private: private:
SharedHandle<Peer> peer; SharedHandle<Peer> peer;
@ -23,6 +24,7 @@ public:
void testAmAllowedIndexSet(); void testAmAllowedIndexSet();
void testGetId(); void testGetId();
void testOperatorEqual(); void testOperatorEqual();
void testCountSeeder();
}; };
@ -57,4 +59,23 @@ void PeerTest::testOperatorEqual()
} }
} }
void PeerTest::testCountSeeder()
{
std::vector<SharedHandle<Peer> > peers(5);
peers[0].reset(new Peer("192.168.0.1", 7000));
peers[1].reset(new Peer("192.168.0.2", 7000));
peers[2].reset(new Peer("192.168.0.3", 7000));
peers[3].reset(new Peer("192.168.0.4", 7000));
peers[4].reset(new Peer("192.168.0.5", 7000));
for(std::vector<SharedHandle<Peer> >::iterator i = peers.begin();
i != peers.end(); ++i) {
(*i)->allocateSessionResource(1024, 1024*8);
}
unsigned char bitfield[] = { 0xff };
peers[1]->setBitfield(bitfield, 1);
peers[3]->setBitfield(bitfield, 1);
peers[4]->setBitfield(bitfield, 1);
CPPUNIT_ASSERT_EQUAL((size_t)3, countSeeder(peers.begin(), peers.end()));
}
} // namespace aria2 } // namespace aria2