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

Method SwapToAnotherFile

src/DownloadClient.cpp:1431–1540  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1429// toFile = Try to swap to this partfile only
1430
1431bool CUpDownClient::SwapToAnotherFile(bool bIgnoreNoNeeded, bool ignoreSuspensions, bool bRemoveCompletely, CPartFile* toFile)
1432{
1433 // Fail if m_reqfile is invalid
1434 if ( m_reqfile == NULL ) {
1435 return false;
1436 }
1437
1438 // It would be stupid to swap away a downloading source
1439 if (GetDownloadState() == DS_DOWNLOADING) {
1440 return false;
1441 }
1442
1443 // The iterator of the final target
1444 A4AFList::iterator target = m_A4AF_list.end();
1445
1446 // Do we want to swap to a specific file?
1447 if ( toFile != NULL ) {
1448 A4AFList::iterator it = m_A4AF_list.find( toFile );
1449 if ( it != m_A4AF_list.end() ) {
1450
1451 // We force ignoring of timestamps
1452 if ( IsValidSwapTarget( it, bIgnoreNoNeeded, true ) ) {
1453 // Set the target
1454 target = it;
1455 }
1456 }
1457 } else {
1458 // We want highest priority possible, but need to start with
1459 // a value less than any other priority
1460 char priority = -1;
1461
1462 A4AFList::iterator it = m_A4AF_list.begin();
1463 for ( ; it != m_A4AF_list.end(); ++it ) {
1464 if ( IsValidSwapTarget( it, bIgnoreNoNeeded, ignoreSuspensions ) ) {
1465 char cur_priority = it->first->GetDownPriority();
1466
1467 // We would prefer to get files with needed parts, thus rate them higher.
1468 // However, this really only matters if bIgnoreNoNeeded is true.
1469 if ( it->second.NeededParts )
1470 cur_priority += 10;
1471
1472 // Change target if the current file has a higher rate than the previous
1473 if ( cur_priority > priority ) {
1474 priority = cur_priority;
1475
1476 // Set the new target
1477 target = it;
1478
1479 // Break on the first High-priority file with needed parts
1480 if ( priority == PR_HIGH + 10 ) {
1481 break;
1482 }
1483 }
1484 }
1485 }
1486 }
1487
1488 // Try to swap if we found a valid target

Callers 8

OnSwapSourceMethod · 0.45
ProcessPacketMethod · 0.45
ProcessRequest2Method · 0.45
ClientRef.cppFile · 0.45
PartFile_Swap_A4AFFunction · 0.45
ProcessMethod · 0.45
RemoveAllSourcesMethod · 0.45

Calls 11

GetTickCount64Function · 0.85
GetDownPriorityMethod · 0.80
DelSourceMethod · 0.80
RemoveA4AFSourceMethod · 0.80
AddA4AFSourceMethod · 0.80
eraseMethod · 0.80
endMethod · 0.45
beginMethod · 0.45
UpdatePartsInfoMethod · 0.45
AddSourceMethod · 0.45

Tested by

no test coverage detected