2008-03-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Type clarification
	* src/DefaultPeerStorage.{h, cc}
	* test/DefaultPeerStorageTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2008-03-08 10:44:25 +00:00
parent c64a191061
commit 2555098ecd
4 changed files with 26 additions and 22 deletions

View File

@ -1,3 +1,9 @@
2008-03-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Type clarification
* src/DefaultPeerStorage.{h, cc}
* test/DefaultPeerStorageTest.cc
2008-03-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> 2008-03-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Type clarification: size_t for length or size, uint64_t for file Type clarification: size_t for length or size, uint64_t for file

View File

@ -123,9 +123,9 @@ PeerHandle DefaultPeerStorage::getUnusedPeer() {
class FindPeer { class FindPeer {
private: private:
std::string ipaddr; std::string ipaddr;
int32_t port; uint16_t port;
public: public:
FindPeer(const std::string& ipaddr, int32_t port):ipaddr(ipaddr), port(port) {} FindPeer(const std::string& ipaddr, uint16_t port):ipaddr(ipaddr), port(port) {}
bool operator()(const PeerHandle& peer) const { bool operator()(const PeerHandle& peer) const {
return ipaddr == peer->ipaddr && port == peer->port; return ipaddr == peer->ipaddr && port == peer->port;
@ -133,7 +133,7 @@ public:
}; };
PeerHandle DefaultPeerStorage::getPeer(const std::string& ipaddr, PeerHandle DefaultPeerStorage::getPeer(const std::string& ipaddr,
int32_t port) const { uint16_t port) const {
Peers::const_iterator itr = std::find_if(peers.begin(), peers.end(), Peers::const_iterator itr = std::find_if(peers.begin(), peers.end(),
FindPeer(ipaddr, port)); FindPeer(ipaddr, port));
if(itr == peers.end()) { if(itr == peers.end()) {
@ -143,7 +143,7 @@ PeerHandle DefaultPeerStorage::getPeer(const std::string& ipaddr,
} }
} }
int32_t DefaultPeerStorage::countPeer() const { size_t DefaultPeerStorage::countPeer() const {
return peers.size(); return peers.size();
} }
@ -201,7 +201,7 @@ TransferStat DefaultPeerStorage::calculateStat() {
return stat; return stat;
} }
void DefaultPeerStorage::deleteUnusedPeer(int32_t delSize) { void DefaultPeerStorage::deleteUnusedPeer(size_t delSize) {
Peers temp; Peers temp;
for(Peers::reverse_iterator itr = peers.rbegin(); for(Peers::reverse_iterator itr = peers.rbegin();
itr != peers.rend(); ++itr) { itr != peers.rend(); ++itr) {

View File

@ -52,11 +52,11 @@ private:
SharedHandle<BtContext> btContext; SharedHandle<BtContext> btContext;
const Option* option; const Option* option;
std::deque<SharedHandle<Peer> > peers; std::deque<SharedHandle<Peer> > peers;
int32_t maxPeerListSize; size_t maxPeerListSize;
Logger* logger; Logger* logger;
SharedHandle<BtRuntime> btRuntime; SharedHandle<BtRuntime> btRuntime;
int64_t removedPeerSessionDownloadLength; uint64_t removedPeerSessionDownloadLength;
int64_t removedPeerSessionUploadLength; uint64_t removedPeerSessionUploadLength;
bool isPeerAlreadyAdded(const SharedHandle<Peer>& peer); bool isPeerAlreadyAdded(const SharedHandle<Peer>& peer);
public: public:
@ -73,11 +73,11 @@ public:
virtual bool addPeer(const SharedHandle<Peer>& peer); virtual bool addPeer(const SharedHandle<Peer>& peer);
int32_t countPeer() const; size_t countPeer() const;
virtual SharedHandle<Peer> getUnusedPeer(); virtual SharedHandle<Peer> getUnusedPeer();
SharedHandle<Peer> getPeer(const std::string& ipaddr, int32_t port) const; SharedHandle<Peer> getPeer(const std::string& ipaddr, uint16_t port) const;
virtual void addPeer(const std::deque<SharedHandle<Peer> >& peers); virtual void addPeer(const std::deque<SharedHandle<Peer> >& peers);
@ -91,11 +91,11 @@ public:
virtual void returnPeer(const SharedHandle<Peer>& peer); virtual void returnPeer(const SharedHandle<Peer>& peer);
void setMaxPeerListSize(int32_t size) { this->maxPeerListSize = size; } void setMaxPeerListSize(size_t size) { this->maxPeerListSize = size; }
int32_t getMaxPeerListSize() const { return maxPeerListSize; } size_t getMaxPeerListSize() const { return maxPeerListSize; }
void deleteUnusedPeer(int32_t delSize); void deleteUnusedPeer(size_t delSize);
void onErasingPeer(const SharedHandle<Peer>& peer); void onErasingPeer(const SharedHandle<Peer>& peer);

View File

@ -54,14 +54,12 @@ CPPUNIT_TEST_SUITE_REGISTRATION(DefaultPeerStorageTest);
void DefaultPeerStorageTest::testCountPeer() { void DefaultPeerStorageTest::testCountPeer() {
DefaultPeerStorage ps(btContext, option); DefaultPeerStorage ps(btContext, option);
CPPUNIT_ASSERT_EQUAL((int32_t)0, CPPUNIT_ASSERT_EQUAL((size_t)0, ps.countPeer());
ps.countPeer());
SharedHandle<Peer> peer(new Peer("192.168.0.1", 6889)); SharedHandle<Peer> peer(new Peer("192.168.0.1", 6889));
ps.addPeer(peer); ps.addPeer(peer);
CPPUNIT_ASSERT_EQUAL((int32_t)1, CPPUNIT_ASSERT_EQUAL((size_t)1, ps.countPeer());
ps.countPeer());
} }
void DefaultPeerStorageTest::testDeleteUnusedPeer() { void DefaultPeerStorageTest::testDeleteUnusedPeer() {
@ -77,7 +75,7 @@ void DefaultPeerStorageTest::testDeleteUnusedPeer() {
ps.deleteUnusedPeer(2); ps.deleteUnusedPeer(2);
CPPUNIT_ASSERT_EQUAL((int32_t)1, ps.countPeer()); CPPUNIT_ASSERT_EQUAL((size_t)1, ps.countPeer());
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.3"), CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.3"),
ps.getPeer("192.168.0.3", 6889)->ipaddr); ps.getPeer("192.168.0.3", 6889)->ipaddr);
@ -89,7 +87,7 @@ void DefaultPeerStorageTest::testDeleteUnusedPeer() {
ps.deleteUnusedPeer(3); ps.deleteUnusedPeer(3);
// peer2 has been in use, so it did't deleted. // peer2 has been in use, so it did't deleted.
CPPUNIT_ASSERT_EQUAL((int32_t)1, ps.countPeer()); CPPUNIT_ASSERT_EQUAL((size_t)1, ps.countPeer());
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.2"), CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.2"),
ps.getPeer("192.168.0.2", 6889)->ipaddr); ps.getPeer("192.168.0.2", 6889)->ipaddr);
@ -106,12 +104,12 @@ void DefaultPeerStorageTest::testAddPeer() {
ps.addPeer(peer2); ps.addPeer(peer2);
ps.addPeer(peer3); ps.addPeer(peer3);
CPPUNIT_ASSERT_EQUAL((int32_t)3, ps.countPeer()); CPPUNIT_ASSERT_EQUAL((size_t)3, ps.countPeer());
// this returns false, because peer1 is already in the container // this returns false, because peer1 is already in the container
CPPUNIT_ASSERT_EQUAL(false, ps.addPeer(peer1)); CPPUNIT_ASSERT_EQUAL(false, ps.addPeer(peer1));
// the number of peers doesn't change. // the number of peers doesn't change.
CPPUNIT_ASSERT_EQUAL((int32_t)3, ps.countPeer()); CPPUNIT_ASSERT_EQUAL((size_t)3, ps.countPeer());
ps.setMaxPeerListSize(3); ps.setMaxPeerListSize(3);
@ -120,7 +118,7 @@ void DefaultPeerStorageTest::testAddPeer() {
peer1->usedBy(1); peer1->usedBy(1);
CPPUNIT_ASSERT(ps.addPeer(peer4)); CPPUNIT_ASSERT(ps.addPeer(peer4));
// peer2 was deleted. While peer1 is oldest, its cuid is not 0. // peer2 was deleted. While peer1 is oldest, its cuid is not 0.
CPPUNIT_ASSERT_EQUAL((int32_t)3, ps.countPeer()); CPPUNIT_ASSERT_EQUAL((size_t)3, ps.countPeer());
CPPUNIT_ASSERT(std::find(ps.getPeers().begin(), ps.getPeers().end(), peer2) == ps.getPeers().end()); CPPUNIT_ASSERT(std::find(ps.getPeers().begin(), ps.getPeers().end(), peer2) == ps.getPeers().end());
SharedHandle<Peer> peer5(new Peer("192.168.0.4", 0)); SharedHandle<Peer> peer5(new Peer("192.168.0.4", 0));