Retry DHT get_peers task if the number of peers in PeerStorage is less

than max peers.

Added virtual size_t countPeer() const to PeerStorage.
pull/1/head
Tatsuhiro Tsujikawa 2011-07-29 23:49:25 +09:00
parent aa13ff5f51
commit 70eeebfae9
4 changed files with 19 additions and 3 deletions

View File

@ -110,9 +110,14 @@ bool DHTGetPeersCommand::execute()
} else if(task_ && task_->finished()) {
A2_LOG_DEBUG("task finished detected");
lastGetPeerTime_ = global::wallclock;
if(numRetry_ < MAX_RETRIES && btRuntime_->lessThanMinPeers()) {
if(numRetry_ < MAX_RETRIES &&
(btRuntime_->getMaxPeers() == 0 ||
btRuntime_->getMaxPeers() > peerStorage_->countPeer())) {
++numRetry_;
A2_LOG_DEBUG(fmt("Too few peers. Try again(%lu)",
A2_LOG_DEBUG(fmt("Too few peers. peers=%lu, max_peers=%lu."
" Try again(%lu)",
static_cast<unsigned long>(peerStorage_->countPeer()),
static_cast<unsigned long>(btRuntime_->getMaxPeers()),
static_cast<unsigned long>(numRetry_)));
} else {
numRetry_ = 0;

View File

@ -78,7 +78,7 @@ public:
virtual bool addPeer(const SharedHandle<Peer>& peer);
size_t countPeer() const;
virtual size_t countPeer() const;
virtual SharedHandle<Peer> getUnusedPeer();

View File

@ -67,6 +67,12 @@ public:
*/
virtual const std::deque<SharedHandle<Peer> >& getPeers() = 0;
/**
* Returns the number of peers.
*/
virtual size_t countPeer() const = 0;
/**
* Returns internal dropped peer list.
*/

View File

@ -33,6 +33,11 @@ public:
return peers;
}
virtual size_t countPeer() const
{
return peers.size();
}
virtual const std::deque<SharedHandle<Peer> >& getDroppedPeers() {
return droppedPeers;
}