| 621 | |
| 622 | |
| 623 | void CDownloadQueue::CheckAndAddSource(CPartFile* sender, CUpDownClient* source) |
| 624 | { |
| 625 | // if we block loopbacks at this point it should prevent us from connecting to ourself |
| 626 | if ( source->HasValidHash() ) { |
| 627 | if ( source->GetUserHash() == thePrefs::GetUserHash() ) { |
| 628 | AddDebugLogLineN( logDownloadQueue, "Tried to add source with matching hash to your own." ); |
| 629 | source->Safe_Delete(); |
| 630 | return; |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | if (sender->IsStopped()) { |
| 635 | source->Safe_Delete(); |
| 636 | return; |
| 637 | } |
| 638 | |
| 639 | // Filter sources which are known to be dead/useless |
| 640 | if ( theApp->clientlist->IsDeadSource( source ) || sender->IsDeadSource(source) ) { |
| 641 | source->Safe_Delete(); |
| 642 | return; |
| 643 | } |
| 644 | |
| 645 | // Filter sources which are incompatible with our encryption setting (one requires it, and the other one doesn't supports it) |
| 646 | if ( (source->RequiresCryptLayer() && (!thePrefs::IsClientCryptLayerSupported() || !source->HasValidHash())) || (thePrefs::IsClientCryptLayerRequired() && (!source->SupportsCryptLayer() || !source->HasValidHash()))) { |
| 647 | source->Safe_Delete(); |
| 648 | return; |
| 649 | } |
| 650 | |
| 651 | // Find all clients with the same hash |
| 652 | if ( source->HasValidHash() ) { |
| 653 | CClientList::SourceList found = theApp->clientlist->GetClientsByHash( source->GetUserHash() ); |
| 654 | |
| 655 | CClientList::SourceList::iterator it = found.begin(); |
| 656 | for ( ; it != found.end(); ++it ) { |
| 657 | CKnownFile* file = it->GetRequestFile(); |
| 658 | |
| 659 | // Only check files on the download-queue |
| 660 | if ( file ) { |
| 661 | // Is the found source queued for something else? |
| 662 | if ( file != sender ) { |
| 663 | // Try to add a request for the other file |
| 664 | if ( it->GetClient()->AddRequestForAnotherFile(sender)) { |
| 665 | // Add it to downloadlistctrl |
| 666 | Notify_SourceCtrlAddSource(sender, *it, A4AF_SOURCE); |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | source->Safe_Delete(); |
| 671 | return; |
| 672 | } |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | |
| 677 | |
| 678 | // Our new source is real new but maybe it is already uploading to us? |
| 679 | // If yes the known client will be attached to the var "source" and the old |
| 680 | // source-client will be deleted. However, if the request file of the known |
no test coverage detected