mirror of https://github.com/aria2/aria2
2008-03-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Type clarification * src/DefaultPeerStorage.{h, cc} * test/DefaultPeerStorageTest.ccpull/1/head
parent
c64a191061
commit
2555098ecd
|
@ -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>
|
||||
|
||||
Type clarification: size_t for length or size, uint64_t for file
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -52,11 +52,11 @@ private:
|
|||
SharedHandle<BtContext> btContext;
|
||||
const Option* option;
|
||||
std::deque<SharedHandle<Peer> > peers;
|
||||
int32_t maxPeerListSize;
|
||||
size_t maxPeerListSize;
|
||||
Logger* logger;
|
||||
SharedHandle<BtRuntime> btRuntime;
|
||||
int64_t removedPeerSessionDownloadLength;
|
||||
int64_t removedPeerSessionUploadLength;
|
||||
uint64_t removedPeerSessionDownloadLength;
|
||||
uint64_t removedPeerSessionUploadLength;
|
||||
|
||||
bool isPeerAlreadyAdded(const SharedHandle<Peer>& peer);
|
||||
public:
|
||||
|
@ -73,11 +73,11 @@ public:
|
|||
|
||||
virtual bool addPeer(const SharedHandle<Peer>& peer);
|
||||
|
||||
int32_t countPeer() const;
|
||||
size_t countPeer() const;
|
||||
|
||||
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);
|
||||
|
||||
|
@ -91,11 +91,11 @@ public:
|
|||
|
||||
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);
|
||||
|
||||
|
|
|
@ -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> 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<Peer> peer5(new Peer("192.168.0.4", 0));
|
||||
|
|
Loading…
Reference in New Issue