Changeset 3fb1afe4edce3fd7fcf12e4a975e612089a8aebd
- Timestamp:
- 02/04/12 22:46:40 (16 months ago)
- Author:
- mkvore-commit@…
- Branches:
- i2p.imule.v2
- Children:
- e44fc65862bdaea1e12d837635b4eef7910b9365
- Parents:
- 183e411556713f7079dabf1e90a640900e5fb455
- Message:
-
UploadClient? merged. Not compiled.
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r183e..
|
r3fb1..
|
|
| 24 | 24 | // |
| 25 | 25 | |
| | 26 | #include "updownclient.h" // Interface |
| | 27 | |
| | 28 | #include <protocol/Protocols.h> |
| | 29 | #include <protocol/ed2k/Client2Client/TCP.h> |
| | 30 | |
| 26 | 31 | #include <zlib.h> |
| 27 | | #include <cmath> // Needed for std::exp |
| 28 | | |
| 29 | | #include "OtherFunctions.h" // Needed for nstrdup |
| 30 | | |
| 31 | | #include "ClientUDPSocket.h" // Needed for CClientUDPSocket |
| | 32 | |
| 32 | 33 | #include "ClientCredits.h" // Needed for CClientCredits |
| 33 | 34 | #include "Packet.h" // Needed for CPacket |
| … |
… |
|
| 35 | 36 | #include "UploadQueue.h" // Needed for CUploadQueue |
| 36 | 37 | #include "DownloadQueue.h" // Needed for CDownloadQueue |
| 37 | | #include "Preferences.h" // Needed for CPreferences |
| 38 | | #include "OtherStructs.h" // Needed for Requested_Block_Struct |
| 39 | | #include "ServerConnect.h" // Needed for CServerConnect |
| 40 | 38 | #include "PartFile.h" // Needed for PR_POWERSHARE |
| 41 | | #include "KnownFile.h" // Needed for CKnownFile |
| 42 | | #include "KnownFileList.h" // Needed for CKnownFileLists |
| 43 | 39 | #include "ClientTCPSocket.h" // Needed for CClientTCPSocket |
| 44 | 40 | #include "SharedFileList.h" // Needed for CSharedFileList |
| 45 | 41 | #include "imule.h" // Needed for theApp |
| 46 | | #include "BarShader.h" // Needed for CBarShader |
| 47 | | #include "updownclient.h" // Needed for CUpDownClient |
| 48 | 42 | #include "ClientList.h" |
| 49 | 43 | #include "Statistics.h" // Needed for theStats |
| 50 | | #include "GuiEvents.h" // Needed for Nofify_... macros |
| 51 | 44 | #include "Logger.h" |
| 52 | 45 | #include <common/Format.h> |
| 53 | | #include "ScopedPtr.h" |
| 54 | | #include <protocol/ed2k/Constants.h> |
| 55 | | #include <protocol/ed2k/Client2Client/TCP.h> |
| | 46 | #include "ScopedPtr.h" // Needed for CScopedArray |
| | 47 | #include "GuiEvents.h" // Needed for Notify_* |
| | 48 | |
| 56 | 49 | |
| 57 | 50 | // members of CUpDownClient |
| … |
… |
|
| 81 | 74 | |
| 82 | 75 | #ifndef CLIENT_GUI |
| 83 | | uint32_t CUpDownClient::GetScore(bool sysvalue, bool isdownloading, bool onlybasevalue) const |
| 84 | | { |
| 85 | | //TODO: complete this (friends, uploadspeed, imuleuser etc etc) |
| | 76 | uint32 CUpDownClient::GetScore(bool sysvalue, bool isdownloading, bool onlybasevalue) const |
| | 77 | { |
| | 78 | //TODO: complete this (friends, uploadspeed, amuleuser etc etc) |
| 86 | 79 | if (m_Username.IsEmpty()) { |
| 87 | 80 | return 0; |
| … |
… |
|
| 168 | 161 | fBaseValue *= 0.5f; |
| 169 | 162 | } |
| 170 | | return (uint32_t)fBaseValue; |
| | 163 | return (uint32)fBaseValue; |
| 171 | 164 | } |
| 172 | 165 | #endif |
| … |
… |
|
| 182 | 175 | |
| 183 | 176 | // Check if we have good lists and proceed to check for different chunks |
| 184 | | if (!m_BlockRequests_queue.empty() && !m_DoneBlocks_list.empty()) |
| | 177 | if ((!m_BlockRequests_queue.empty()) && !m_DoneBlocks_list.empty()) |
| 185 | 178 | { |
| 186 | 179 | Requested_Block_Struct* last_done_block = NULL; |
| … |
… |
|
| 191 | 184 | |
| 192 | 185 | // Get last block and next pending |
| 193 | | last_done_block = (Requested_Block_Struct*)m_DoneBlocks_list.front(); |
| 194 | | next_requested_block = (Requested_Block_Struct*)m_BlockRequests_queue.front(); |
| | 186 | last_done_block = m_DoneBlocks_list.front(); |
| | 187 | next_requested_block = m_BlockRequests_queue.front(); |
| 195 | 188 | |
| 196 | 189 | // Calculate corresponding parts to blocks |
| … |
… |
|
| 201 | 194 | if ( last_done_part != next_requested_part) { |
| 202 | 195 | different_part = true; |
| 203 | | AddDebugLogLineM(false, logClient, CFormat(wxT("%x :Session ended due to new chunk.")) % (long) this); |
| | 196 | AddDebugLogLineM(false, logClient, wxT("Session ended due to new chunk.")); |
| 204 | 197 | } |
| 205 | 198 | |
| 206 | 199 | if (md4cmp(last_done_block->FileID, next_requested_block->FileID) != 0) { |
| 207 | 200 | different_part = true; |
| 208 | | AddDebugLogLineM(false, logClient, CFormat(wxT("%x :Session ended due to different file.")) % (long) this); |
| | 201 | AddDebugLogLineM(false, logClient, wxT("Session ended due to different file.")); |
| 209 | 202 | } |
| 210 | 203 | } |
| … |
… |
|
| 226 | 219 | try { |
| 227 | 220 | // Buffer new data if current buffer is less than 100 KBytes |
| 228 | | while (!m_BlockRequests_queue.empty() && |
| | 221 | while ((!m_BlockRequests_queue.empty()) && |
| 229 | 222 | (m_addedPayloadQueueSession <= GetQueueSessionPayloadUp() || m_addedPayloadQueueSession-GetQueueSessionPayloadUp() < 100*1024)) { |
| 230 | 223 | |
| … |
… |
|
| 237 | 230 | |
| 238 | 231 | if (srcfile->IsPartFile() && ((CPartFile*)srcfile)->GetStatus() != PS_COMPLETE) { |
| 239 | | //TODO #warning This seems a good idea from eMule. We must import this. |
| | 232 | //#warning This seems a good idea from eMule. We must import this. |
| 240 | 233 | #if 0 |
| 241 | 234 | // Do not access a part file, if it is currently moved into the incoming directory. |
| … |
… |
|
| 257 | 250 | } |
| 258 | 251 | |
| 259 | | size_t togo; |
| | 252 | uint64 togo; |
| 260 | 253 | // THIS EndOffset points BEHIND the last byte requested |
| 261 | 254 | // (other than the offsets used in the PartFile code) |
| … |
… |
|
| 265 | 258 | throw wxString(wxT("Asked for invalid block (start > end)")); |
| 266 | 259 | } else { |
| 267 | | if (currentblock->EndOffset - currentblock->StartOffset >= (1<<sizeof(size_t))) |
| 268 | | throw wxString(wxT("Asked for a huge block")); |
| 269 | | |
| 270 | | togo = (size_t) (currentblock->EndOffset - currentblock->StartOffset); |
| | 260 | togo = currentblock->EndOffset - currentblock->StartOffset; |
| 271 | 261 | |
| 272 | 262 | if (srcfile->IsPartFile() && !((CPartFile*)srcfile)->IsComplete(currentblock->StartOffset,currentblock->EndOffset-1)) { |
| … |
… |
|
| 275 | 265 | } |
| 276 | 266 | |
| 277 | | if (togo > (EMBLOCKSIZE * 3)) { |
| | 267 | if (togo > EMBLOCKSIZE * 3) { |
| 278 | 268 | throw wxString(wxT("Client requested too large of a block.")); |
| 279 | 269 | } |
| 280 | 270 | |
| 281 | | CScopedArray<uint8_t> filedata(NULL); |
| | 271 | CScopedArray<byte> filedata(NULL); |
| 282 | 272 | if (!srcfile->IsPartFile()){ |
| 283 | 273 | if ( !file.Open(fullname, CFile::read) ) { |
| … |
… |
|
| 292 | 282 | file.Seek(currentblock->StartOffset, wxFromStart); |
| 293 | 283 | |
| 294 | | filedata.reset(new uint8_t[togo + 500]); |
| | 284 | filedata.reset(new byte[togo + 500]); |
| 295 | 285 | file.Read(filedata.get(), togo); |
| 296 | 286 | file.Close(); |
| … |
… |
|
| 299 | 289 | partfile->m_hpartfile.Seek(currentblock->StartOffset); |
| 300 | 290 | |
| 301 | | filedata.reset(new uint8_t[togo + 500]); |
| | 291 | filedata.reset(new byte[togo + 500]); |
| 302 | 292 | partfile->m_hpartfile.Read(filedata.get(), togo); |
| 303 | 293 | // Partfile should NOT be closed!!! |
| 304 | 294 | } |
| 305 | 295 | |
| 306 | | |
| 307 | | //TODO #warning Part of the above import. |
| | 296 | //#warning Part of the above import. |
| 308 | 297 | #if 0 |
| 309 | 298 | if (lockFile.m_pObject){ |
| … |
… |
|
| 335 | 324 | return; |
| 336 | 325 | } catch (const wxString& error) { |
| 337 | | AddDebugLogLineM(false, logClient, CFormat(wxT("%x :Client '")) % (long) this + GetUserName() + wxT("' caused error while creating packet (") + error + wxT(") - disconnecting client")); |
| | 326 | AddDebugLogLineM(false, logClient, wxT("Client '") + GetUserName() + wxT("' caused error while creating packet (") + error + wxT(") - disconnecting client")); |
| 338 | 327 | } catch (const CIOFailureException& error) { |
| 339 | | AddDebugLogLineM(true, logClient, CFormat(wxT("%x :IO failure while reading requested file: ")) % (long) this + error.what()); |
| 340 | | } catch (const CEOFException& error) { |
| | 328 | AddDebugLogLineM(true, logClient, wxT("IO failure while reading requested file: ") + error.what()); |
| | 329 | } catch (const CEOFException& WXUNUSED(error)) { |
| 341 | 330 | AddDebugLogLineM(true, logClient, GetClientFullInfo() + wxT(" requested file-data at an invalid position - disconnecting")); |
| 342 | 331 | } |
| … |
… |
|
| 347 | 336 | |
| 348 | 337 | |
| 349 | | void CUpDownClient::CreateStandartPackets(const uint8_t* buffer, uint32_t togo, Requested_Block_Struct* currentblock) |
| 350 | | { |
| 351 | | uint32_t nPacketSize; |
| 352 | | |
| 353 | | CMemFile memfile((uint8_t*)buffer, togo); |
| | 338 | void CUpDownClient::CreateStandartPackets(const byte* buffer, uint32 togo, Requested_Block_Struct* currentblock) |
| | 339 | { |
| | 340 | uint32 nPacketSize; |
| | 341 | |
| | 342 | CMemFile memfile(buffer, togo); |
| 354 | 343 | if (togo > 10240) { |
| 355 | | nPacketSize = togo/(uint32_t)(togo/10240); |
| | 344 | nPacketSize = togo/(uint32)(togo/10240); |
| 356 | 345 | } else { |
| 357 | 346 | nPacketSize = togo; |
| … |
… |
|
| 366 | 355 | togo -= nPacketSize; |
| 367 | 356 | |
| 368 | | CMemFile data(nPacketSize+32); |
| | 357 | uint64 endpos = (currentblock->EndOffset - togo); |
| | 358 | uint64 startpos = endpos - nPacketSize; |
| | 359 | |
| | 360 | |
| | 361 | CMemFile data(nPacketSize + 16 + 2 * (bLargeBlocks ? 8 :4)); |
| 369 | 362 | data.WriteHash(GetUploadFileID()); |
| 370 | | data.WriteUInt64(((currentblock->EndOffset - togo) - nPacketSize)); |
| 371 | | data.WriteUInt64(((currentblock->EndOffset - togo))); |
| | 363 | if (bLargeBlocks) { |
| | 364 | data.WriteUInt64(startpos); |
| | 365 | data.WriteUInt64(endpos); |
| | 366 | } else { |
| | 367 | data.WriteUInt32(startpos); |
| | 368 | data.WriteUInt32(endpos); |
| | 369 | } |
| 372 | 370 | char *tempbuf = new char[nPacketSize]; |
| 373 | 371 | memfile.Read(tempbuf, nPacketSize); |
| 374 | 372 | data.Write(tempbuf, nPacketSize); |
| 375 | 373 | delete [] tempbuf; |
| 376 | | CPacket* packet = new CPacket(data,OP_EDONKEYPROT,OP_SENDINGPART); |
| 377 | | |
| 378 | | theStats::AddUpOverheadFileRequest(24); |
| | 374 | CPacket* packet = new CPacket(data, (bLargeBlocks ? OP_EMULEPROT : OP_EDONKEYPROT), (bLargeBlocks ? (uint8)OP_SENDINGPART_I64 : (uint8)OP_SENDINGPART)); |
| | 375 | theStats::AddUpOverheadFileRequest(16 + 2 * (bLargeBlocks ? 8 :4)); |
| 379 | 376 | theStats::AddUploadToSoft(GetClientSoft(), nPacketSize); |
| | 377 | AddDebugLogLineM( false, logLocalClient, wxString::Format(wxT("Local Client: %s to "),(bLargeBlocks ? wxT("OP_SENDINGPART_I64") : wxT("OP_SENDINGPART"))) + GetFullIP() ); |
| 380 | 378 | m_socket->SendPacket(packet,true,false, nPacketSize); |
| 381 | 379 | } |
| … |
… |
|
| 383 | 381 | |
| 384 | 382 | |
| 385 | | void CUpDownClient::CreatePackedPackets(const uint8_t* buffer, uint32_t togo, Requested_Block_Struct* currentblock) |
| 386 | | { |
| 387 | | uint8_t* output = new uint8_t[togo+300]; |
| | 383 | void CUpDownClient::CreatePackedPackets(const byte* buffer, uint32 togo, Requested_Block_Struct* currentblock) |
| | 384 | { |
| | 385 | byte* output = new byte[togo+300]; |
| 388 | 386 | uLongf newsize = togo+300; |
| 389 | | uint32_t result = compress2(output, &newsize, buffer, togo, 9); |
| 390 | | wxASSERT( result <= (uint16_t) -1 ); |
| | 387 | uint16 result = compress2(output, &newsize, buffer, togo,9); |
| 391 | 388 | if (result != Z_OK || togo <= newsize){ |
| 392 | 389 | delete[] output; |
| … |
… |
|
| 397 | 394 | CMemFile memfile(output,newsize); |
| 398 | 395 | |
| 399 | | uint32_t totalPayloadSize = 0; |
| 400 | | uint32_t oldSize = togo; |
| | 396 | uint32 totalPayloadSize = 0; |
| | 397 | uint32 oldSize = togo; |
| 401 | 398 | togo = newsize; |
| 402 | | uint32_t nPacketSize; |
| | 399 | uint32 nPacketSize; |
| 403 | 400 | if (togo > 10240) { |
| 404 | | nPacketSize = togo/(uint32_t)(togo/10240); |
| | 401 | nPacketSize = togo/(uint32)(togo/10240); |
| 405 | 402 | } else { |
| 406 | 403 | nPacketSize = togo; |
| … |
… |
|
| 413 | 410 | togo -= nPacketSize; |
| 414 | 411 | |
| 415 | | CMemFile data(nPacketSize+24); |
| | 412 | |
| | 413 | CMemFile data(nPacketSize + 16 + (isLargeBlock ? 12 : 8)); |
| 416 | 414 | data.WriteHash(GetUploadFileID()); |
| | 415 | if (isLargeBlock) { |
| 417 | 416 | data.WriteUInt64(currentblock->StartOffset); |
| | 417 | } else { |
| | 418 | data.WriteUInt32(currentblock->StartOffset); |
| | 419 | } |
| 418 | 420 | data.WriteUInt32(newsize); |
| 419 | 421 | char *tempbuf = new char[nPacketSize]; |
| … |
… |
|
| 421 | 423 | data.Write(tempbuf,nPacketSize); |
| 422 | 424 | delete [] tempbuf; |
| 423 | | CPacket* packet = new CPacket(data, OP_EMULEPROT, OP_COMPRESSEDPART); |
| | 425 | CPacket* packet = new CPacket(data, OP_EMULEPROT, (isLargeBlock ? OP_COMPRESSEDPART_I64 : OP_COMPRESSEDPART)); |
| 424 | 426 | |
| 425 | 427 | // approximate payload size |
| 426 | | uint32_t payloadSize = nPacketSize*oldSize/newsize; |
| | 428 | uint32 payloadSize = nPacketSize*oldSize/newsize; |
| 427 | 429 | |
| 428 | 430 | if (togo == 0 && totalPayloadSize+payloadSize < oldSize) { |
| … |
… |
|
| 435 | 437 | theStats::AddUpOverheadFileRequest(24); |
| 436 | 438 | theStats::AddUploadToSoft(GetClientSoft(), nPacketSize); |
| | 439 | AddDebugLogLineM( false, logLocalClient, wxString::Format(wxT("Local Client: %s to "), (isLargeBlock ? wxT("OP_COMPRESSEDPART_I64") : wxT("OP_COMPRESSEDPART"))) + GetFullIP() ); |
| 437 | 440 | m_socket->SendPacket(packet,true,false, payloadSize); |
| 438 | 441 | } |
| … |
… |
|
| 471 | 474 | |
| 472 | 475 | try { |
| 473 | | uint16_t done = 0; |
| | 476 | uint16 done = 0; |
| 474 | 477 | while (done != m_upPartStatus.size()) { |
| 475 | | uint8_t toread = data->ReadUInt8(); |
| 476 | | for (int32_t i = 0;i != 8;i++){ |
| | 478 | uint8 toread = data->ReadUInt8(); |
| | 479 | for (sint32 i = 0;i != 8;i++){ |
| 477 | 480 | m_upPartStatus[done] = (toread>>i)&1; |
| 478 | 481 | // We may want to use this for another feature.. |
| … |
… |
|
| 493 | 496 | |
| 494 | 497 | if (GetExtendedRequestsVersion() > 1) { |
| 495 | | uint16_t nCompleteCountLast = GetUpCompleteSourcesCount(); |
| 496 | | uint16_t nCompleteCountNew = data->ReadUInt16(); |
| | 498 | uint16 nCompleteCountLast = GetUpCompleteSourcesCount(); |
| | 499 | uint16 nCompleteCountNew = data->ReadUInt16(); |
| 497 | 500 | SetUpCompleteSourcesCount(nCompleteCountNew); |
| 498 | 501 | if (nCompleteCountLast != nCompleteCountNew) { |
| … |
… |
|
| 572 | 575 | } |
| 573 | 576 | |
| 574 | | uint32_t CUpDownClient::GetWaitStartTime() const |
| 575 | | { |
| 576 | | uint32_t dwResult = 0; |
| | 577 | |
| | 578 | uint32 CUpDownClient::GetWaitStartTime() const |
| | 579 | { |
| | 580 | uint32 dwResult = 0; |
| 577 | 581 | |
| 578 | 582 | if ( credits ) { |
| … |
… |
|
| 605 | 609 | |
| 606 | 610 | |
| 607 | | uint32_t CUpDownClient::SendBlockData() |
| 608 | | { |
| 609 | | uint32_t curTick = ::GetTickCount(); |
| 610 | | uint64_t sentBytesCompleteFile = 0; |
| 611 | | uint64_t sentBytesPartFile = 0; |
| 612 | | uint64_t sentBytesPayload = 0; |
| 613 | | |
| 614 | | if ( m_socket ) |
| 615 | | { |
| | 611 | uint32 CUpDownClient::SendBlockData() |
| | 612 | { |
| | 613 | uint32 curTick = ::GetTickCount(); |
| | 614 | uint64 sentBytesCompleteFile = 0; |
| | 615 | uint64 sentBytesPartFile = 0; |
| | 616 | uint64 sentBytesPayload = 0; |
| | 617 | |
| | 618 | if (m_socket) { |
| 616 | 619 | CEMSocket* s = m_socket; |
| 617 | | // uint32_t uUpStatsPort = GetUserPort(); |
| | 620 | // uint32 uUpStatsPort = GetUserPort(); |
| 618 | 621 | |
| 619 | 622 | // Extended statistics information based on which client software and which port we sent this data to... |
| … |
… |
|
| 631 | 634 | m_nCurQueueSessionPayloadUp += sentBytesPayload; |
| 632 | 635 | |
| 633 | | if ( theApp->uploadqueue->CheckForTimeOver ( this ) ) |
| 634 | | { |
| | 636 | if (theApp->uploadqueue->CheckForTimeOver(this)) { |
| 635 | 637 | theApp->uploadqueue->RemoveFromUploadQueue ( this, true ); |
| 636 | 638 | SendOutOfPartReqsAndAddToWaitingQueue(); |
| 637 | | } |
| 638 | | else |
| 639 | | { |
| | 639 | } else { |
| 640 | 640 | // read blocks from file and put on socket |
| 641 | 641 | CreateNextBlockPackage(); |
| … |
… |
|
| 644 | 644 | |
| 645 | 645 | if ( sentBytesCompleteFile + sentBytesPartFile > 0 || |
| 646 | | m_AvarageUDR_list.size() == 0 || ( curTick - m_AvarageUDR_list.back().timestamp ) > 1*1000 ) |
| 647 | | { |
| | 646 | m_AvarageUDR_list.empty() || (curTick - m_AvarageUDR_list.back().timestamp) > 1*1000) { |
| 648 | 647 | // Store how much data we've transferred this round, |
| 649 | 648 | // to be able to calculate average speed later |
| 650 | 649 | // keep sum of all values in list up to date |
| 651 | | TransferredData newitem = { (uint32_t) (sentBytesCompleteFile + sentBytesPartFile), curTick}; |
| | 650 | TransferredData newitem = {sentBytesCompleteFile + sentBytesPartFile, curTick}; |
| 652 | 651 | m_AvarageUDR_list.push_back ( newitem ); |
| 653 | 652 | m_nSumForAvgUpDataRate += sentBytesCompleteFile + sentBytesPartFile; |
| 654 | 653 | } |
| 655 | 654 | |
| 656 | | // remove too old values in list |
| | 655 | // remove to old values in list |
| 657 | 656 | while ( m_AvarageUDR_list.size() > 0 && ( curTick - m_AvarageUDR_list.front().timestamp ) > _average_period*1000 ) |
| 658 | 657 | { |
| … |
… |
|
| 663 | 662 | |
| 664 | 663 | // Calculate average speed for this slot |
| 665 | | if ( m_AvarageUDR_list.size() > 0 && ( curTick - m_AvarageUDR_list.front().timestamp ) > 0 && GetUpStartTimeDelay() > 2*1000 ) |
| 666 | | { |
| 667 | | m_nUpDatarate = (uint32_t) |
| 668 | | (( m_nSumForAvgUpDataRate * (uint64_t)1000 ) / |
| 669 | | (uint64_t) ( curTick-m_AvarageUDR_list.front().timestamp )); |
| 670 | | } |
| 671 | | else |
| 672 | | { |
| | 664 | if ((!m_AvarageUDR_list.empty()) && (curTick - m_AvarageUDR_list.front().timestamp) > 0 && GetUpStartTimeDelay() > 2*1000) { |
| | 665 | m_nUpDatarate = ((uint64)m_nSumForAvgUpDataRate*1000) / (curTick-m_AvarageUDR_list.front().timestamp); |
| | 666 | } else { |
| 673 | 667 | // not enough values to calculate trustworthy speed. Use -1 to tell this |
| 674 | 668 | m_nUpDatarate = 0; //-1; |
| … |
… |
|
| 677 | 671 | // Check if it's time to update the display. |
| 678 | 672 | m_cSendblock++; |
| 679 | | if ( m_cSendblock == 30 ) |
| 680 | | { |
| | 673 | if (m_cSendblock == 30){ |
| 681 | 674 | m_cSendblock = 0; |
| 682 | 675 | Notify_UploadCtrlRefreshClient ( this ); |
| 683 | 676 | } |
| 684 | 677 | |
| 685 | | return (uint32_t) (sentBytesCompleteFile + sentBytesPartFile); |
| | 678 | return sentBytesCompleteFile + sentBytesPartFile; |
| 686 | 679 | } |
| 687 | 680 | |
| … |
… |
|
| 698 | 691 | //I did some tests with eDonkey also and it seems to work well with them also.. |
| 699 | 692 | |
| 700 | | AddDebugLogLineM(false, logLocalClient, CFormat(wxT("%x (%s --> %s): Local client %x : Sending OP_OUTOFPARTREQS")) % (long) m_socket % m_socket->GetLocal().humanReadable() % m_socket->GetPeer().humanReadable() % (long) this); |
| 701 | | |
| 702 | 693 | // Send this inmediately, don't queue. |
| 703 | | CPacket* pPacket = new CPacket(OP_OUTOFPARTREQS, 0); |
| | 694 | CPacket* pPacket = new CPacket(OP_OUTOFPARTREQS, 0, OP_EDONKEYPROT); |
| 704 | 695 | theStats::AddUpOverheadFileRequest(pPacket->GetPacketSize()); |
| | 696 | AddDebugLogLineM( false, logLocalClient, wxT("Local Client: OP_OUTOFPARTREQS to ") + GetFullIP() ); |
| 705 | 697 | SendPacket(pPacket, true, true); |
| 706 | 698 | |
| … |
… |
|
| 754 | 746 | data.WriteHash(file->GetPartHash(i)); |
| 755 | 747 | } |
| 756 | | CPacket* packet = new CPacket(data); |
| 757 | | packet->SetOpCode(OP_HASHSETANSWER); |
| | 748 | CPacket* packet = new CPacket(data, OP_EDONKEYPROT, OP_HASHSETANSWER); |
| 758 | 749 | theStats::AddUpOverheadFileRequest(packet->GetPacketSize()); |
| | 750 | AddDebugLogLineM( false, logLocalClient, wxT("Local Client: OP_HASHSETANSWER to ") + GetFullIP()); |
| 759 | 751 | SendPacket(packet,true,true); |
| 760 | 752 | } |
| … |
… |
|
| 774 | 766 | } |
| 775 | 767 | |
| 776 | | uint16_t nRank = theApp->uploadqueue->GetWaitingPosition(this); |
| | 768 | uint16 nRank = theApp->uploadqueue->GetWaitingPosition(this); |
| 777 | 769 | if (!nRank) { |
| 778 | 770 | return; |
| … |
… |
|
| 783 | 775 | // Kry: what are these zero bytes for. are they really correct? |
| 784 | 776 | // Kry - Well, eMule does like that. I guess they're ok. |
| 785 | | data.WriteUInt32(0); |
| 786 | | data.WriteUInt32(0); |
| 787 | | data.WriteUInt16(0); |
| 788 | | |
| 789 | | AddDebugLogLineM(false, logLocalClient, CFormat(wxT("%x (%s --> %s): Local client %x : OP_QUEUERANKING ")) % (long) m_socket % m_socket->GetLocal().humanReadable() % m_socket->GetPeer().humanReadable() % (long) this); |
| 790 | | CPacket* packet = new CPacket(data,OP_EMULEPROT); |
| 791 | | packet->SetOpCode(OP_QUEUERANKING); |
| 792 | | |
| | 777 | data.WriteUInt32(0); data.WriteUInt32(0); data.WriteUInt16(0); |
| | 778 | CPacket* packet = new CPacket(data, OP_EMULEPROT, OP_QUEUERANKING); |
| 793 | 779 | theStats::AddUpOverheadOther(packet->GetPacketSize()); |
| | 780 | AddDebugLogLineM(false, logLocalClient, wxT("Local Client: OP_QUEUERANKING to ") + GetFullIP()); |
| 794 | 781 | SendPacket(packet,true,true); |
| 795 | 782 | } |
| … |
… |
|
| 803 | 790 | m_bCommentDirty = false; |
| 804 | 791 | |
| 805 | | // We used to limit the comment to 50 before, now we do not anymore. |
| 806 | | const wxString& desc = file->GetFileComment(); |
| 807 | | uint8_t rating = file->GetFileRating(); |
| | 792 | // Truncate to max len. |
| | 793 | wxString desc = file->GetFileComment().Left(MAXFILECOMMENTLEN); |
| | 794 | uint8 rating = file->GetFileRating(); |
| 808 | 795 | |
| 809 | 796 | if ( file->GetFileRating() == 0 && desc.IsEmpty() ) { |
| … |
… |
|
| 813 | 800 | CMemFile data(256); |
| 814 | 801 | data.WriteUInt8(rating); |
| 815 | | data.WriteString(desc, GetUnicodeSupport(), 4 /* size it's uint32_t */); |
| 816 | | |
| 817 | | AddDebugLogLineM(false, logLocalClient, CFormat(wxT("%x (%s --> %s): Local client %x : OP_FILEDESC")) % (long) m_socket % m_socket->GetLocal().humanReadable() % m_socket->GetPeer().humanReadable() % (long) this); |
| 818 | | CPacket* packet = new CPacket(data,OP_EMULEPROT); |
| 819 | | packet->SetOpCode(OP_FILEDESC); |
| | 802 | data.WriteString(desc, GetUnicodeSupport(), 4 /* size it's uint32 */); |
| | 803 | |
| | 804 | CPacket* packet = new CPacket(data, OP_EMULEPROT, OP_FILEDESC); |
| 820 | 805 | theStats::AddUpOverheadOther(packet->GetPacketSize()); |
| | 806 | AddDebugLogLineM(false, logLocalClient, wxT("Local Client: OP_FILEDESC to ") + GetFullIP()); |
| 821 | 807 | SendPacket(packet,true); |
| 822 | 808 | } |
| … |
… |
|
| 837 | 823 | theApp->clientlist->AddBannedClient( GetTCPDest/*IP*/() ); |
| 838 | 824 | |
| 839 | | AddDebugLogLineM( false, logClient, CFormat(wxT("%x :Client '")) % (long) this + GetUserName() + wxT("' seems to be an aggressive client and is banned from the uploadqueue")); |
| | 825 | AddDebugLogLineM( false, logClient, wxT("Client '") + GetUserName() + wxT("' seems to be an aggressive client and is banned from the uploadqueue")); |
| 840 | 826 | |
| 841 | 827 | SetUploadState(US_BANNED); |
| … |
… |
|
| 852 | 838 | void CUpDownClient::CheckForAggressive() |
| 853 | 839 | { |
| 854 | | uint32_t cur_time = ::GetTickCount(); |
| | 840 | uint32 cur_time = ::GetTickCount(); |
| 855 | 841 | |
| 856 | 842 | // First call, initalize |
| … |
… |
|
| 862 | 848 | // Is this an aggressive request? |
| 863 | 849 | if ( ( cur_time - m_LastFileRequest ) < MIN_REQUESTTIME ) { |
| 864 | | m_Aggressiveness = (uint16_t) (m_Aggressiveness + 3); |
| | 850 | m_Aggressiveness += 3; |
| 865 | 851 | |
| 866 | 852 | // Is the client EVIL? |