MCPcopy Create free account
hub / github.com/amule-project/amule / SortGetBestClient

Method SortGetBestClient

src/UploadQueue.cpp:76–166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74
75
76void CUploadQueue::SortGetBestClient(CClientRef * bestClient)
77{
78 uint64 tick = GetTickCount64();
79 m_lastSort = tick;
80 CClientRefList::iterator it = m_waitinglist.begin();
81 for (; it != m_waitinglist.end(); ) {
82 CClientRefList::iterator it2 = it++;
83 CUpDownClient* cur_client = it2->GetClient();
84
85 // clear dead clients
86 if (tick - cur_client->GetLastUpRequest() > MAX_PURGEQUEUETIME
87 || !theApp->sharedfiles->GetFileByID(cur_client->GetUploadFileID())) {
88 cur_client->ClearWaitStartTime();
89 RemoveFromWaitingQueue(it2);
90 if (!cur_client->GetSocket()) {
91 if (cur_client->Disconnected("AddUpNextClient - purged")) {
92 cur_client->Safe_Delete();
93 cur_client = NULL;
94 }
95 }
96 continue;
97 }
98
99 if (cur_client->IsBanned() || IsSuspended(cur_client->GetUploadFileID())) { // Banned client or suspended upload ?
100 cur_client->ClearScore();
101 continue;
102 }
103 // finished clearing
104
105 // Calculate score of current client
106 uint32 cur_score = cur_client->CalculateScore();
107 // Check if it's better than that of a previous one, and move it up then.
108 CClientRefList::iterator it1 = it2;
109 while (it1 != m_waitinglist.begin()) {
110 --it1;
111 if (cur_score > it1->GetClient()->GetScore()) {
112 // swap them
113 std::swap(*it2, *it1);
114 --it2;
115 } else {
116 // no need to check further since list is already sorted
117 break;
118 }
119 }
120 }
121
122 // Second Pass:
123 // - calculate queue rank
124 // - find best high id client
125 // - mark all better low id clients as enabled for upload
126 uint16 rank = 1;
127 bool bestClientFound = false;
128 for (it = m_waitinglist.begin(); it != m_waitinglist.end(); ) {
129 CClientRefList::iterator it2 = it++;
130 CUpDownClient* cur_client = it2->GetClient();
131 cur_client->SetUploadQueueWaitingPosition(rank++);
132 if (bestClientFound) {
133 // There's a better high id client

Callers

nothing calls this directly

Calls 15

GetTickCount64Function · 0.85
CFormatClass · 0.85
GetLastUpRequestMethod · 0.80
GetSocketMethod · 0.80
DisconnectedMethod · 0.80
IsBannedMethod · 0.80
ClearScoreMethod · 0.80
CalculateScoreMethod · 0.80
ECIDMethod · 0.80
swapFunction · 0.70
beginMethod · 0.45

Tested by

no test coverage detected