📄 uploadqueue.cpp
字号:
}
// done
// Add clients server to list.
if (theApp.glob_prefs->AddServersFromClient()){
in_addr host;
host.S_un.S_addr = client->GetServerIP();
CServer* srv = new CServer(client->GetServerPort(), inet_ntoa(host));
srv->SetListName(srv->GetAddress());
if (!theApp.emuledlg->serverwnd.serverlistctrl.AddServer(srv, true))
delete srv;
/*else
theApp.emuledlg->AddLogLine(false,"Added new server: %s:%d", srv->GetFullIP(), srv->GetPort());*/
}
// statistic values
CKnownFile* reqfile = theApp.sharedfiles->GetFileByID((uchar*)client->GetUploadFileID());
if (reqfile)
reqfile->statistic.AddRequest();
// TODO find better ways to cap the list
if ((uint32)waitinglist.GetCount() > (theApp.glob_prefs->GetQueueSize()+bannedcount))
return;
if (client->IsDownloading()){
// he's already downloading and wants probably only another file
Packet* packet = new Packet(OP_ACCEPTUPLOADREQ,0);
theApp.uploadqueue->AddUpDataOverheadFileRequest(packet->size);
client->socket->SendPacket(packet,true);
return;
}
if (waitinglist.IsEmpty() && AcceptNewClient()){
AddUpNextClient(client);
m_nLastStartUpload = ::GetTickCount();
}
else{
waitinglist.AddTail(client);
client->SetUploadState(US_ONUPLOADQUEUE);
client->SendRankingInfo();
theApp.emuledlg->transferwnd.queuelistctrl.AddClient(client);
theApp.emuledlg->transferwnd.ShowQueueCount(waitinglist.GetCount());
}
}
bool CUploadQueue::RemoveFromUploadQueue(CUpDownClient* client, bool updatewindow){
for (POSITION pos = uploadinglist.GetHeadPosition();pos != 0;uploadinglist.GetNext(pos)){
if (client == uploadinglist.GetAt(pos)){
if (updatewindow)
theApp.emuledlg->transferwnd.uploadlistctrl.RemoveClient(uploadinglist.GetAt(pos));
uploadinglist.RemoveAt(pos);
if( client->GetTransferedUp() ){
successfullupcount++;
totaluploadtime += client->GetUpStartTimeDelay()/1000;
}
else
failedupcount++;
client->SetUploadState(US_NONE);
client->ClearUploadBlockRequests();
CKnownFile* reqfile = theApp.sharedfiles->GetFileByID(client->GetUploadFileID());
// if( reqfile )
// reqfile->SubQueuedCount();
// client->SetUploadFileID(NULL);
return true;
}
}
return false;
}
uint32 CUploadQueue::GetAverageUpTime(){
if( successfullupcount ){
return totaluploadtime/successfullupcount;
}
return 0;
}
bool CUploadQueue::RemoveFromWaitingQueue(CUpDownClient* client, bool updatewindow){
POSITION pos = waitinglist.Find(client);
if (pos){
RemoveFromWaitingQueue(pos,updatewindow);
if (updatewindow)
theApp.emuledlg->transferwnd.ShowQueueCount(waitinglist.GetCount());
return true;
}
else
return false;
}
void CUploadQueue::RemoveFromWaitingQueue(POSITION pos, bool updatewindow){
CUpDownClient* todelete = waitinglist.GetAt(pos);
waitinglist.RemoveAt(pos);
if( todelete->IsBanned() )
todelete->UnBan();
if (updatewindow)
theApp.emuledlg->transferwnd.queuelistctrl.RemoveClient(todelete);
todelete->SetUploadState(US_NONE);
}
bool CUploadQueue::CheckForTimeOver(CUpDownClient* client){
if (theApp.glob_prefs->TransferFullChunks())
{
if( client->GetUpStartTimeDelay() > 3600000 ){ // Try to keep the clients from downloading for ever.
theApp.emuledlg->AddDebugLogLine(false, "%s: Upload session ended due to excessive time.", client->GetUserName());
return true;
}
// For some reason, some clients can continue to download after a chunk size.
// Are they redownloading the same chunk over and over????
if( client->GetSessionUp() > 10485760 ){
theApp.emuledlg->AddDebugLogLine(false, "%s: Upload session ended due to excessive transfered amount.", client->GetUserName());
return true;
}
}
else
{
// Cache current client score
const uint32 score = client->GetScore(true, true);
// Check if another client has a bigger score
for(POSITION pos = waitinglist.GetHeadPosition(); pos != 0; )
if(score < waitinglist.GetNext(pos)->GetScore(true, false)){
theApp.emuledlg->AddDebugLogLine(false, "%s: Upload session ended due to score.", client->GetUserName());
return true;
}
}
return false;
}
void CUploadQueue::DeleteAll(){
waitinglist.RemoveAll();
uploadinglist.RemoveAll();
}
uint16 CUploadQueue::GetWaitingPosition(CUpDownClient* client){
if (!IsOnUploadQueue(client))
return 0;
uint16 rank = 1;
uint32 myscore = client->GetScore(false);
for (POSITION pos = waitinglist.GetHeadPosition();pos != 0;waitinglist.GetNext(pos)){
if (waitinglist.GetAt(pos)->GetScore(false) > myscore)
rank++;
}
return rank;
}
void CUploadQueue::CompUpDatarateOverhead(){
this->m_AvarageUDRO_list.AddTail(m_nUpDataRateMSOverhead);
if (m_AvarageUDRO_list.GetCount() > 150)
m_AvarageUDRO_list.RemoveAt(m_AvarageUDRO_list.GetHeadPosition());
m_nUpDatarateOverhead = 0;
m_nUpDataRateMSOverhead = 0;
for (POSITION pos = m_AvarageUDRO_list.GetHeadPosition();pos != 0;m_AvarageUDRO_list.GetNext(pos))
m_nUpDatarateOverhead += m_AvarageUDRO_list.GetAt(pos);
if(m_AvarageUDRO_list.GetCount() > 10)
m_nUpDatarateOverhead = 10*m_nUpDatarateOverhead/m_AvarageUDRO_list.GetCount();
else
m_nUpDatarateOverhead = 0;
return;
}
VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg,UINT_PTR idEvent,DWORD dwTime){
// Barry - Don't do anything if the app is shutting down - can cause unhandled exceptions
if (!theApp.emuledlg->IsRunning())
return;
theApp.uploadqueue->Process();
theApp.downloadqueue->Process();
theApp.uploadqueue->CompUpDatarateOverhead();
theApp.downloadqueue->CompDownDatarateOverhead();
counter++;
// one second
if (counter >= 10){
counter=0;
theApp.clientcredits->Process();
theApp.serverlist->Process();
theApp.friendlist->Process();
if( theApp.serverconnect->IsConnecting() && !theApp.serverconnect->IsSingleConnect() )
theApp.serverconnect->TryAnotherConnectionrequest();
theApp.emuledlg->statisticswnd.UpdateConnectionsStatus();
if (theApp.glob_prefs->WatchClipboard4ED2KLinks()) theApp.emuledlg->searchwnd.SearchClipBoard();
if (theApp.serverconnect->IsConnecting()) theApp.serverconnect->CheckForTimeout();
// display graphs
if (theApp.glob_prefs->GetTrafficOMeterInterval()>0) {
igraph++;
if (igraph >= (uint32)(theApp.glob_prefs->GetTrafficOMeterInterval()) ) {
igraph=0;
theApp.emuledlg->statisticswnd.SetCurrentRate((float)theApp.uploadqueue->GetDatarate()/1024,(float)theApp.downloadqueue->GetDatarate()/1024);
}
}
if (theApp.emuledlg->activewnd == &theApp.emuledlg->statisticswnd && theApp.emuledlg->IsWindowVisible() ) {
// display stats
if (theApp.glob_prefs->GetStatsInterval()>0) {
istats++;
if (istats >= (uint32)(theApp.glob_prefs->GetStatsInterval()) ) {
istats=0;
theApp.emuledlg->ShowStatistics();
}
}
}
//save rates every second
theApp.emuledlg->statisticswnd.RecordRate();
sec++;
// 5 seconds
if (sec>=5) {
#ifdef _DEBUG
if (!AfxCheckMemory()) AfxDebugBreak();
#endif
sec = 0;
theApp.listensocket->Process();
theApp.OnlineSig(); // Added By Bouc7
theApp.emuledlg->ShowTransferRate();
}
statsave++;
if (statsave>=60) {
statsave=0;
CString buffer;
char* fullpath = new char[strlen(theApp.glob_prefs->GetAppDir())+16];
sprintf(fullpath,"%spreferences.ini",theApp.glob_prefs->GetAppDir());
CIni ini( fullpath, "eMule" );
delete[] fullpath;
fullpath=NULL;
buffer.Format("%I64Lu",theApp.stat_sessionReceivedBytes+theApp.glob_prefs->GetTotalDownloaded());
ini.WriteString("TotalDownloadedBytes",buffer ,"Statistics");
buffer.Format("%I64Lu",theApp.stat_sessionSentBytes+theApp.glob_prefs->GetTotalUploaded());
ini.WriteString("TotalUploadedBytes",buffer ,"Statistics");
//theApp.scheduler->Check();
}
}
}
CUpDownClient* CUploadQueue::GetNextClient(CUpDownClient* lastclient){
if (waitinglist.IsEmpty())
return 0;
if (!lastclient)
return waitinglist.GetHead();
POSITION pos = waitinglist.Find(lastclient);
if (!pos){
TRACE("Error: CServerList::GetNextClient");
return waitinglist.GetHead();
}
waitinglist.GetNext(pos);
if (!pos)
return NULL;
else
return waitinglist.GetAt(pos);
}
void CUploadQueue::FindSourcesForFileById(CTypedPtrList<CPtrList, CUpDownClient*>* srclist, uchar* filehash) {
POSITION pos;
pos = uploadinglist.GetHeadPosition();
while(pos) {
CUpDownClient *potential = uploadinglist.GetNext(pos);
if(memcmp(potential->GetUploadFileID(), filehash, 16) == 0)
srclist->AddTail(potential);
}
pos = waitinglist.GetHeadPosition();
while(pos) {
CUpDownClient *potential = waitinglist.GetNext(pos);
if(memcmp(potential->GetUploadFileID(), filehash, 16) == 0)
srclist->AddTail(potential);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -