2008-06-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Always remove a peer from cache in 
DefaultPeerStorage::returnPeer(),
	to make room more fleshy, recently found peers.
	Peer::_badConditionStartTime is not used anymore. Consider to 
remove
	it.
	* src/DefaultPeerStorage.cc
	* test/DefaultPeerStorageTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2008-06-10 11:29:10 +00:00
parent 811649149d
commit 7a74971caa
3 changed files with 17 additions and 14 deletions

View File

@ -1,3 +1,12 @@
2008-06-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Always remove a peer from cache in DefaultPeerStorage::returnPeer(),
to make room more fleshy, recently found peers.
Peer::_badConditionStartTime is not used anymore. Consider to remove
it.
* src/DefaultPeerStorage.cc
* test/DefaultPeerStorageTest.cc
2008-06-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Returns cached data only when the previous receiveHandshake() is called

View File

@ -244,15 +244,9 @@ void DefaultPeerStorage::returnPeer(const PeerHandle& peer)
logger->debug("Cannot find peer %s:%u in PeerStorage.", peer->ipaddr.c_str(), peer->port);
} else {
onReturningPeer(peer);
if((*itr)->port == 0) {
onErasingPeer(*itr);
peers.erase(itr);
} else {
peer->startBadCondition();
peer->resetStatus();
peers.erase(itr);
peers.push_back(peer);
}
}
}

View File

@ -219,13 +219,13 @@ void DefaultPeerStorageTest::testReturnPeer()
ps.addPeer(peer2);
ps.addPeer(peer3);
ps.returnPeer(peer2);
// peer2 is moved to the end of container
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.2"),
ps.getPeers().back()->ipaddr);
ps.returnPeer(peer2); // peer2 removed from the container
CPPUNIT_ASSERT_EQUAL((size_t)2, ps.getPeers().size());
CPPUNIT_ASSERT(std::find(ps.getPeers().begin(), ps.getPeers().end(), peer2)
== ps.getPeers().end());
ps.returnPeer(peer1); // peer1 is removed from the container
CPPUNIT_ASSERT_EQUAL((size_t)2, ps.getPeers().size());
CPPUNIT_ASSERT_EQUAL((size_t)1, ps.getPeers().size());
CPPUNIT_ASSERT(std::find(ps.getPeers().begin(), ps.getPeers().end(), peer1) == ps.getPeers().end());
}