示例#1
0
/**
  * Get the fastest free peer, may remove dead peers.
  */
PM::IPeer* ChunkDownloader::getTheFastestFreePeer()
{
   QMutexLocker locker(&this->mutex);

   PM::IPeer* current = nullptr;
   bool isTheNmberOfPeersHasChanged = false;
   for (QMutableListIterator<PM::IPeer*> i(this->peers); i.hasNext();)
   {
      PM::IPeer* peer = i.next();
      if (!peer->isAvailable())
      {
         i.remove();
         this->linkedPeers.rmLink(peer);
         isTheNmberOfPeersHasChanged = true;
      }
      else if (this->occupiedPeersDownloadingChunk.isPeerFree(peer) && (!current || peer->getSpeed() > current->getSpeed()))
         current = peer;
   }

   if (isTheNmberOfPeersHasChanged)
      emit numberOfPeersChanged();

   return current;
}
示例#2
0
int ChunkDownloader::getNumberOfFreePeer()
{
   QMutexLocker locker(&this->mutex);

   int n = 0;
   bool isTheNmberOfPeersHasChanged = false;
   for (QMutableListIterator<PM::IPeer*> i(this->peers); i.hasNext();)
   {
      PM::IPeer* peer = i.next();
      if (!peer->isAvailable())
      {
         i.remove();
         this->linkedPeers.rmLink(peer);
         isTheNmberOfPeersHasChanged = true;
      }
      else if (this->occupiedPeersDownloadingChunk.isPeerFree(peer))
         n++;
   }

   if (isTheNmberOfPeersHasChanged)
      emit numberOfPeersChanged();

   return n;
}
示例#3
0
/**
  * @remarks This method may remove dead peers from the list.
  */
QList<PM::IPeer*> ChunkDownloader::getPeers()
{
   QMutexLocker locker(&this->mutex);

   QList<PM::IPeer*> peers;
   peers.reserve(this->peers.size());

   bool isTheNmberOfPeersHasChanged = false;
   for (QMutableListIterator<PM::IPeer*> i(this->peers); i.hasNext();)
   {
      PM::IPeer* peer = i.next();
      if (peer->isAvailable())
         peers << peer;
      else
      {
         i.remove();
         this->linkedPeers.rmLink(peer);
         isTheNmberOfPeersHasChanged = true;
      }
   }
   if (isTheNmberOfPeersHasChanged)
      emit numberOfPeersChanged();
   return peers;
}