Exemplo n.º 1
0
wxString wxDownloadThread::GetRemainingTime() const
{
    wxASSERT(IsDownloading());
    wxLongLong sec = GetElapsedMSec()/1000;
    if (sec <= 0)
        return wxT("not available");        // avoid division by zero

    // remaining time is the number of bytes we still need to download
    // divided by our download speed...
    wxLongLong nBytesPerSec = wxLongLong(GetCurrDownloadedBytes()) / sec;
    if (nBytesPerSec <= 0)
        return wxT("not available");        // avoid division by zero

    long remsec = (wxLongLong(m_nFinalSize-GetCurrDownloadedBytes())/nBytesPerSec).ToLong();
    if (remsec < 0)
        return wxT("not available");

    if (remsec < 60)
        return wxString::Format(wxT("%li sec"), remsec);
    else if (remsec < 60*60)
        return wxString::Format(wxT("%li min, %li sec"), remsec/60, remsec%60);
    else if (remsec < 60*60*24)
        return wxString::Format(wxT("%li hours, %li min, %li sec"),
                    remsec/3600, (remsec/60)%60, (remsec/3600)%60);
    else
        return wxT("not available");
}
Exemplo n.º 2
0
void
ManagedFileListWidget::RefreshList()
{
  items.clear();

  bool download_active = false;
  for (auto i = repository.begin(), end = repository.end(); i != end; ++i) {
    const auto &remote_file = *i;
    DownloadStatus download_status;
    const bool is_downloading = IsDownloading(remote_file, download_status);

    TCHAR path[MAX_PATH];
    if (LocalPath(path, remote_file) &&
        (is_downloading || File::Exists(path))) {
      download_active |= is_downloading;
      items.append().Set(BaseName(path),
                         is_downloading ? &download_status : NULL,
                         HasFailed(remote_file));
    }
  }

  ListControl &list = GetList();
  list.SetLength(items.size());
  list.Invalidate();

#ifdef HAVE_DOWNLOAD_MANAGER
  if (download_active && !Timer::IsActive())
    Timer::Schedule(1000);
#endif
}
Exemplo n.º 3
0
void
ManagedFileListWidget::RefreshList()
{
  items.clear();

  bool download_active = false;
  for (auto i = repository.begin(), end = repository.end(); i != end; ++i) {
    const auto &remote_file = *i;
    DownloadStatus download_status;
    const bool is_downloading = IsDownloading(remote_file, download_status);

    const auto path = LocalPath(remote_file);
    if (!path.IsNull() &&
        (is_downloading || File::Exists(path))) {
      download_active |= is_downloading;

      const Path base = path.GetBase();
      if (base.IsNull())
        continue;

      items.append().Set(base.c_str(),
                         is_downloading ? &download_status : nullptr,
                         HasFailed(remote_file));
    }
  }

  ListControl &list = GetList();
  list.SetLength(items.size());
  list.Invalidate();

#ifdef HAVE_DOWNLOAD_MANAGER
  if (download_active && !Timer::IsActive())
    Timer::Schedule(1000);
#endif
}
Exemplo n.º 4
0
wxString wxDownloadThread::GetDownloadSpeed() const
{
    wxASSERT(IsDownloading());
    wxLongLong msec = GetElapsedMSec();
    if (msec <= 0)
        return wxT("0 KB/s");       // avoid division by zero

    wxLongLong nBytesPerMilliSec = wxLongLong(GetCurrDownloadedBytes()) / msec;

    // we don't like bytes per millisecond as measure unit !
    long nKBPerSec = (nBytesPerMilliSec * 1000/1024).ToLong();          // our conversion factor
    return wxString::Format(wxT("%li KB/s"), nKBPerSec);
}
Exemplo n.º 5
0
void
ManagedFileListWidget::Add()
{
#ifdef HAVE_DOWNLOAD_MANAGER
  assert(Net::DownloadManager::IsAvailable());

  std::vector<AvailableFile> list;
  for (auto i = repository.begin(), end = repository.end(); i != end; ++i) {
    const AvailableFile &remote_file = *i;

    if (IsDownloading(remote_file.GetName()))
      /* already downloading this file */
      continue;

    ACPToWideConverter name(remote_file.GetName());
    if (!name.IsValid())
      continue;

    if (FindItem(name) < 0)
      list.push_back(remote_file);
  }

  if (list.empty())
    return;

  add_list = &list;

  FunctionListItemRenderer item_renderer(OnPaintAddItem);
  int i = ListPicker(_("Select a file"),
                     list.size(), 0, Layout::FastScale(18),
                     item_renderer);
  add_list = NULL;
  if (i < 0)
    return;

  assert((unsigned)i < list.size());

  const AvailableFile &remote_file = list[i];
  ACPToWideConverter base(remote_file.GetName());
  if (!base.IsValid())
    return;

  Net::DownloadManager::Enqueue(remote_file.GetURI(), base);
#endif
}
Exemplo n.º 6
0
void
ManagedFileListWidget::Add()
{
#ifdef HAVE_DOWNLOAD_MANAGER
  assert(Net::DownloadManager::IsAvailable());

  std::vector<AvailableFile> list;
  for (const auto &remote_file : repository) {
    if (IsDownloading(remote_file.GetName()))
      /* already downloading this file */
      continue;

    const UTF8ToWideConverter name(remote_file.GetName());
    if (!name.IsValid())
      continue;

    if (FindItem(name) < 0)
      list.push_back(remote_file);
  }

  if (list.empty())
    return;

  AddFileListItemRenderer item_renderer(list);
  int i = ListPicker(_("Select a file"),
                     list.size(), 0,
                     item_renderer.CalculateLayout(UIGlobals::GetDialogLook()),
                     item_renderer);
  if (i < 0)
    return;

  assert((unsigned)i < list.size());

  const AvailableFile &remote_file = list[i];
  const UTF8ToWideConverter base(remote_file.GetName());
  if (!base.IsValid())
    return;

  Net::DownloadManager::Enqueue(remote_file.GetURI(), base);
#endif
}
Exemplo n.º 7
0
bool CUploadQueue::AddUpNextClient(LPCTSTR pszReason, CUpDownClient* directadd){
	CUpDownClient* newclient = NULL;
	// select next client or use given client
	if (!directadd)
	{
        newclient = FindBestClientInQueue();

        if(newclient)
		{
		    RemoveFromWaitingQueue(newclient, true);
		    theApp.emuledlg->transferwnd->ShowQueueCount(waitinglist.GetCount());
        }
	}
	else 
		newclient = directadd;

    if(newclient == NULL) 
        return false;

	if (!thePrefs.TransferFullChunks())
		UpdateMaxClientScore(); // refresh score caching, now that the highest score is removed

	if (IsDownloading(newclient))
		return false;

    if(pszReason && thePrefs.GetLogUlDlEvents())
        AddDebugLogLine(false, _T("Adding client to upload list: %s Client: %s"), pszReason, newclient->DbgGetClientInfo());

	if (newclient->HasCollectionUploadSlot() && directadd == NULL){
		ASSERT( false );
		newclient->SetCollectionUploadSlot(false);
	}

	// tell the client that we are now ready to upload
	if (!newclient->socket || !newclient->socket->IsConnected())
	{
		newclient->SetUploadState(US_CONNECTING);
		if (!newclient->TryToConnect(true))
			return false;
	}
	else
	{
		if (thePrefs.GetDebugClientTCPLevel() > 0)
			DebugSend("OP__AcceptUploadReq", newclient);
		Packet* packet = new Packet(OP_ACCEPTUPLOADREQ,0);
		theStats.AddUpDataOverheadFileRequest(packet->size);
		newclient->SendPacket(packet, true);
		newclient->SetUploadState(US_UPLOADING);
	}
	newclient->SetUpStartTime();
	newclient->ResetSessionUp();

    InsertInUploadingList(newclient);

    m_nLastStartUpload = ::GetTickCount();
	
	// statistic
	CKnownFile* reqfile = theApp.sharedfiles->GetFileByID((uchar*)newclient->GetUploadFileID());
	if (reqfile)
		reqfile->statistic.AddAccepted();
		
	theApp.emuledlg->transferwnd->uploadlistctrl.AddClient(newclient);

	return true;
}
Exemplo n.º 8
0
 gcc_pure
 bool IsDownloading(const AvailableFile &file,
                    DownloadStatus &status_r) const {
   return IsDownloading(file.GetName(), status_r);
 }
Exemplo n.º 9
0
 gcc_pure
 bool IsDownloading(const AvailableFile &file) const {
   return IsDownloading(file.GetName());
 }
Exemplo n.º 10
0
CString CDownload::GetDownloadStatus() const
{
	CString strText;

	if ( m_bClearing )	// Briefly marked for removal
	{
		LoadString( strText, IDS_STATUS_CLEARING );
	}
	else if ( IsPaused() )
	{
		if ( GetFileError() == ERROR_SUCCESS || IsSeeding() )
			LoadString( strText, IDS_STATUS_PAUSED );
		else
			LoadString( strText, IsMoving() ? IDS_STATUS_CANTMOVE : IDS_STATUS_FILEERROR );
	}
	else if ( IsCompleted() )
	{
		if ( IsSeeding() )
			LoadString( strText, m_bTorrentTrackerError ? IDS_STATUS_TRACKERDOWN : IDS_STATUS_SEEDING );
		else
			LoadString( strText, IDS_STATUS_COMPLETED );
	}
	else if ( IsMoving() )
	{
		LoadString( strText, IDS_STATUS_MOVING );
	}
	else if ( IsStarted() && GetProgress() == 100.0f )
	{
		LoadString( strText, IDS_STATUS_VERIFYING );
	}
	else if ( ! IsTrying() )
	{
		LoadString( strText, IDS_STATUS_QUEUED );
	}
	else if ( IsDownloading() )
	{
		const DWORD nTime = GetTimeRemaining();

		if ( nTime == 0xFFFFFFFF )
			LoadString( strText, IDS_STATUS_ACTIVE );	// IDS_STATUS_DOWNLOADING
		else if ( nTime == 0 )
			LoadString( strText, IDS_STATUS_DOWNLOADING );
		else if ( nTime > 86400 )
			strText.Format( L"%u:%.2u:%.2u:%.2u", nTime / 86400, ( nTime / 3600 ) % 24, ( nTime / 60 ) % 60, nTime % 60 );
		else
			strText.Format( L"%u:%.2u:%.2u", nTime / 3600, ( nTime / 60 ) % 60, nTime % 60 );
	}
	else if ( GetEffectiveSourceCount() > 0 )
	{
		LoadString( strText, IDS_STATUS_PENDING );
	}
	else if ( IsTorrent() )
	{
		if ( GetTaskType() == dtaskAllocate )
			LoadString( strText, IDS_STATUS_CREATING );
		else if ( m_bTorrentTrackerError )
			LoadString( strText, IDS_STATUS_TRACKERDOWN );
		else
			LoadString( strText, IDS_STATUS_TORRENT );
	}
	else // Inactive
	{
		LoadString( strText, IDS_STATUS_QUEUED );
	}

	return strText;
}
Exemplo n.º 11
0
void CUploadQueue::AddClientToUploadQueue(CUpDownClient *pClient)
{
	EMULE_TRY

	CUpDownClient	*pNewSource;

// Select next client or use given client
	if (!pClient)
	{
		POSITION		toadd = 0, pos1, pos2;
		CUpDownClient	*pSource, *pLowIdClient = NULL;
		uint32			dwScore, dwBestScore = 0, dwBestLowIdScore = 0, dwCurTick = ::GetTickCount();

		for (pos1 = waitinglist.GetHeadPosition(); (pos2 = pos1) != NULL;)
		{
			pSource = waitinglist.GetNext(pos1);

		// Clear dead clients
			ASSERT(pSource->GetLastUpRequest());

		// Remove "?" from queue
			if ( (dwCurTick - pSource->GetLastUpRequest() > MAX_PURGEQUEUETIME)
				|| !g_App.m_pSharedFilesList->GetFileByID(pSource->m_reqFileHash) )
			{
				RemoveFromWaitingQueue(pos2, true);
#ifdef OLD_SOCKETS_ENABLED
				if (!pSource->m_pRequestSocket)
				{
					if (pSource->Disconnected())
						pSource = NULL;
				}
#endif //OLD_SOCKETS_ENABLED
				continue;
			}
			if ((dwScore = pSource->GetScore()) > dwBestScore)
			{
				if (!pSource->HasLowID()
#ifdef OLD_SOCKETS_ENABLED
					|| (pSource->m_pRequestSocket && pSource->m_pRequestSocket->IsConnected())
#endif //OLD_SOCKETS_ENABLED
				)
				{
				//	Client is a HighID or a currently connected to us LowID client
					dwBestScore = dwScore;
					toadd = pos2;
				}
				else if (!pSource->IsAddNextConnect())
				{
				//	Client is a LowID client that is not ready to go (not connected),
				//	compare it with the best not ready client
					if (dwScore > dwBestLowIdScore)
					{
						dwBestLowIdScore = dwScore;
						pLowIdClient = waitinglist.GetAt(pos2);
					}
				}
			}
		}
	//	The best not ready client may be better than the best ready client,
	//	so we need to check against that client
		if ((dwBestLowIdScore > dwBestScore) && (pLowIdClient != NULL))
			pLowIdClient->SetAddNextConnect(true);

		if (!toadd)
			return;

		pNewSource = waitinglist.GetAt(toadd);
		RemoveFromWaitingQueue(toadd, true);
		g_App.m_pMDlg->m_wndTransfer.UpdateUploadHeader();
	}
	else
		pNewSource = pClient;

	if (!g_App.m_pClientList->IsValidClient(pNewSource))
		return;

// Never upload to already downloading client
	if (IsDownloading(pNewSource))
		return;

// Tell the client that we are now ready to upload
#ifdef OLD_SOCKETS_ENABLED
	if (!pNewSource->IsHandshakeFinished())
	{
		pNewSource->SetUploadState(US_CONNECTING);
	//	Exceeding number of open TCP connections (TooManySockets) here
	//	by one is fine, as we don't invite to upload queue too often
		if (!pNewSource->TryToConnect(true))
			return;
	}
	else
	{
		Packet* packet = new Packet(OP_ACCEPTUPLOADREQ, 0);
		g_App.m_pUploadQueue->AddUpDataOverheadFileRequest(packet->m_dwSize);
		pNewSource->m_pRequestSocket->SendPacket(packet, true);
		pNewSource->SetUploadState(US_UPLOADING);
		pNewSource->SetLastGotULData();
	}
#endif //OLD_SOCKETS_ENABLED

	pNewSource->SetUpStartTime();
	pNewSource->ResetSessionUp();
	pNewSource->ResetCompressionGain();
	pNewSource->SetAddNextConnect(false);
	EnterCriticalSection(&m_csUploadQueueList);
	m_UploadingList.push_back(pNewSource);
	LeaveCriticalSection(&m_csUploadQueueList);
// clear the information about active clients, if their number in upload queue was changed
	m_activeClientsDeque.clear();
	m_activeClientsSortedVector.clear();

// Statistic
	CKnownFile	*pReqPartFile = g_App.m_pSharedFilesList->GetFileByID((uchar*)pNewSource->m_reqFileHash);

	if (pReqPartFile)
		pReqPartFile->statistic.AddAccepted();

	g_App.m_pMDlg->m_wndTransfer.m_ctlUploadList.AddClient(pNewSource);

	EMULE_CATCH
}
Exemplo n.º 12
0
void CUploadQueue::AddUpNextClient(CUpDownClient* directadd)
{
	CClientPtrList::iterator toadd = m_waitinglist.end();
	CClientPtrList::iterator toaddlow = m_waitinglist.end();
	
	uint32_t bestscore = 0;
	uint32_t bestlowscore = 0;

	CUpDownClient* newclient;
	// select next client or use given client
	if (!directadd) {
		// Track if we purged any clients from the queue, as to only send one notify in total
		bool purged = false;
		
		CClientPtrList::iterator it = m_waitinglist.begin();
		for (; it != m_waitinglist.end(); ) {
			CClientPtrList::iterator tmp_it = it++;
			CUpDownClient* cur_client = *tmp_it;

			// clear dead clients
			if ( (::GetTickCount() - cur_client->GetLastUpRequest() > MAX_PURGEQUEUETIME) || !theApp->sharedfiles->GetFileByID(cur_client->GetUploadFileID()) ) {
				purged = true;
				cur_client->ClearWaitStartTime();
				RemoveFromWaitingQueue(tmp_it);
				if (!cur_client->GetSocket()) {
					if(cur_client->Disconnected(wxT("AddUpNextClient - purged"))) {
						cur_client->Safe_Delete();
						cur_client = NULL;
					}
				}
				continue;
			} 

			suspendlist::iterator it2 = std::find( suspended_uploads_list.begin(),
			                                      suspended_uploads_list.end(),
			                                      cur_client->GetUploadFileID() );
			if (cur_client->IsBanned() || it2 != suspended_uploads_list.end() ) { // Banned client or suspended upload ?
			        continue;
			}
			// finished clearing
			
			uint32_t cur_score = cur_client->GetScore(true);
			if (cur_score > bestscore) {
				bestscore = cur_score;
				toadd = tmp_it;
			} else {
				cur_score = cur_client->GetScore(false);
				if ((cur_score > bestlowscore) && !cur_client->m_bAddNextConnect){
					bestlowscore = cur_score;
					toaddlow = tmp_it;
				}
			}
		}

		// Update the count on GUI if any clients were purged
		if (purged) {
			Notify_ShowQueueCount(m_waitinglist.size());
		}

		if (bestlowscore > bestscore){
			newclient = *toaddlow;
			newclient->m_bAddNextConnect = true;
		}

		if (toadd == m_waitinglist.end()) {
			return;
		}
		
		newclient = *toadd;
		lastupslotHighID = true; // VQB LowID alternate
		RemoveFromWaitingQueue(toadd);
		Notify_ShowQueueCount(m_waitinglist.size());
	} else {
		//prevent another potential access of a suspended upload

		suspendlist::iterator it = std::find( suspended_uploads_list.begin(),
		                                      suspended_uploads_list.end(),
		                                      directadd->GetUploadFileID() );
		if ( it != suspended_uploads_list.end() ) {
			return;
		} else {
			newclient = directadd;
		}
	}

	if (IsDownloading(newclient)) {
		return;
	}
	// tell the client that we are now ready to upload
	if (!newclient->IsConnected()) {
		newclient->SetUploadState(US_CONNECTING);
		if (!newclient->TryToConnect(true)) {
			return;
		}
	} else {
		CPacket* packet = new CPacket(OP_ACCEPTUPLOADREQ, 0, OP_EDONKEYPROT);
		theStats::AddUpOverheadFileRequest(packet->GetPacketSize());
		AddDebugLogLineM( false, logLocalClient, wxT("Local Client: OP_ACCEPTUPLOADREQ to ") + newclient->GetFullIP() );
		newclient->SendPacket(packet,true);
		newclient->SetUploadState(US_UPLOADING);
	}
	newclient->SetUpStartTime();
	newclient->ResetSessionUp();

	theApp->uploadBandwidthThrottler->AddToStandardList(m_uploadinglist.size(), newclient->GetSocket());
	m_uploadinglist.push_back(newclient);
	theStats::AddUploadingClient();

	// Statistic
	CKnownFile* reqfile = (CKnownFile*) newclient->GetUploadFile();
	if (reqfile) {
		reqfile->statistic.AddAccepted();
	}
	Notify_UploadCtrlAddClient(newclient);
}