diff --git a/ChangeLog b/ChangeLog index 5b6e4670..c229fd24 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-03-08 Tatsuhiro Tsujikawa + + Type clarification + * src/DefaultPeerStorage.{h, cc} + * test/DefaultPeerStorageTest.cc + 2008-03-08 Tatsuhiro Tsujikawa Type clarification: size_t for length or size, uint64_t for file diff --git a/src/DefaultPeerStorage.cc b/src/DefaultPeerStorage.cc index c79a4dca..b9102ef7 100644 --- a/src/DefaultPeerStorage.cc +++ b/src/DefaultPeerStorage.cc @@ -123,9 +123,9 @@ PeerHandle DefaultPeerStorage::getUnusedPeer() { class FindPeer { private: std::string ipaddr; - int32_t port; + uint16_t port; 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 { return ipaddr == peer->ipaddr && port == peer->port; @@ -133,7 +133,7 @@ public: }; 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(), FindPeer(ipaddr, port)); 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(); } @@ -201,7 +201,7 @@ TransferStat DefaultPeerStorage::calculateStat() { return stat; } -void DefaultPeerStorage::deleteUnusedPeer(int32_t delSize) { +void DefaultPeerStorage::deleteUnusedPeer(size_t delSize) { Peers temp; for(Peers::reverse_iterator itr = peers.rbegin(); itr != peers.rend(); ++itr) { diff --git a/src/DefaultPeerStorage.h b/src/DefaultPeerStorage.h index 40148cec..b81f825a 100644 --- a/src/DefaultPeerStorage.h +++ b/src/DefaultPeerStorage.h @@ -52,11 +52,11 @@ private: SharedHandle btContext; const Option* option; std::deque > peers; - int32_t maxPeerListSize; + size_t maxPeerListSize; Logger* logger; SharedHandle btRuntime; - int64_t removedPeerSessionDownloadLength; - int64_t removedPeerSessionUploadLength; + uint64_t removedPeerSessionDownloadLength; + uint64_t removedPeerSessionUploadLength; bool isPeerAlreadyAdded(const SharedHandle& peer); public: @@ -73,11 +73,11 @@ public: virtual bool addPeer(const SharedHandle& peer); - int32_t countPeer() const; + size_t countPeer() const; virtual SharedHandle getUnusedPeer(); - SharedHandle getPeer(const std::string& ipaddr, int32_t port) const; + SharedHandle getPeer(const std::string& ipaddr, uint16_t port) const; virtual void addPeer(const std::deque >& peers); @@ -91,11 +91,11 @@ public: virtual void returnPeer(const SharedHandle& 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); diff --git a/test/DefaultPeerStorageTest.cc b/test/DefaultPeerStorageTest.cc index d1c5209e..719d81b9 100644 --- a/test/DefaultPeerStorageTest.cc +++ b/test/DefaultPeerStorageTest.cc @@ -54,14 +54,12 @@ CPPUNIT_TEST_SUITE_REGISTRATION(DefaultPeerStorageTest); void DefaultPeerStorageTest::testCountPeer() { DefaultPeerStorage ps(btContext, option); - CPPUNIT_ASSERT_EQUAL((int32_t)0, - ps.countPeer()); + CPPUNIT_ASSERT_EQUAL((size_t)0, ps.countPeer()); SharedHandle peer(new Peer("192.168.0.1", 6889)); ps.addPeer(peer); - CPPUNIT_ASSERT_EQUAL((int32_t)1, - ps.countPeer()); + CPPUNIT_ASSERT_EQUAL((size_t)1, ps.countPeer()); } void DefaultPeerStorageTest::testDeleteUnusedPeer() { @@ -77,7 +75,7 @@ void DefaultPeerStorageTest::testDeleteUnusedPeer() { 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"), ps.getPeer("192.168.0.3", 6889)->ipaddr); @@ -89,7 +87,7 @@ void DefaultPeerStorageTest::testDeleteUnusedPeer() { ps.deleteUnusedPeer(3); // 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"), ps.getPeer("192.168.0.2", 6889)->ipaddr); @@ -106,12 +104,12 @@ void DefaultPeerStorageTest::testAddPeer() { ps.addPeer(peer2); 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 CPPUNIT_ASSERT_EQUAL(false, ps.addPeer(peer1)); // 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); @@ -120,7 +118,7 @@ void DefaultPeerStorageTest::testAddPeer() { peer1->usedBy(1); CPPUNIT_ASSERT(ps.addPeer(peer4)); // 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()); SharedHandle peer5(new Peer("192.168.0.4", 0));