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

Method CheckAndAddKnownSource

src/DownloadQueue.cpp:720–773  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

718
719
720void CDownloadQueue::CheckAndAddKnownSource(CPartFile* sender,CUpDownClient* source)
721{
722 // Kad reviewed
723
724 if (sender->IsStopped()) {
725 return;
726 }
727
728 // Filter sources which are known to be dead/useless
729 if ( sender->IsDeadSource(source) ) {
730 return;
731 }
732
733 // "Filter LAN IPs" -- this may be needed here in case we are connected to the internet and are also connected
734 // to a LAN and some client from within the LAN connected to us. Though this situation may be supported in future
735 // by adding that client to the source list and filtering that client's LAN IP when sending sources to
736 // a client within the internet.
737 //
738 // "IPfilter" is not needed here, because that "known" client was already IPfiltered when receiving OP_HELLO.
739 if (!source->HasLowID()) {
740 uint32 nClientIP = wxUINT32_SWAP_ALWAYS(source->GetUserIDHybrid());
741 if (!IsGoodIP(nClientIP, thePrefs::FilterLanIPs())) { // check for 0-IP, localhost and LAN addresses
742 AddDebugLogLineN(logIPFilter, "Ignored already known source with IP=%s" + Uint32toStringIP(nClientIP));
743 return;
744 }
745 }
746
747 // Filter sources which are incompatible with our encryption setting (one requires it, and the other one doesn't supports it)
748 if ( (source->RequiresCryptLayer() && (!thePrefs::IsClientCryptLayerSupported() || !source->HasValidHash()))
749 || (thePrefs::IsClientCryptLayerRequired() && (!source->SupportsCryptLayer() || !source->HasValidHash()))) {
750 return;
751 }
752
753 CPartFile* file = source->GetRequestFile();
754
755 // Check if the file is already queued for something else
756 if ( file ) {
757 if ( file != sender ) {
758 if ( source->AddRequestForAnotherFile( sender ) ) {
759 Notify_SourceCtrlAddSource( sender, CCLIENTREF(source, "CDownloadQueue::CheckAndAddKnownSource Notify_SourceCtrlAddSource 1"), A4AF_SOURCE );
760 }
761 }
762 } else {
763 source->SetRequestFile( sender );
764
765 if ( source->GetFileRating() || !source->GetFileComment().IsEmpty() ) {
766 sender->UpdateFileRatingCommentAvail();
767 }
768
769 source->SetSourceFrom(SF_PASSIVE);
770 sender->AddSource( source );
771 Notify_SourceCtrlAddSource( sender, CCLIENTREF(source, "CDownloadQueue::CheckAndAddKnownSource Notify_SourceCtrlAddSource 2"), UNAVAILABLE_SOURCE);
772 }
773}
774
775
776bool CDownloadQueue::RemoveSource(CUpDownClient* toremove, bool WXUNUSED(updatewindow), bool bDoStatsUpdate)

Callers 2

ProcessPacketMethod · 0.80
ProcessExtPacketMethod · 0.80

Calls 15

IsGoodIPFunction · 0.85
Uint32toStringIPFunction · 0.85
IsStoppedMethod · 0.80
RequiresCryptLayerMethod · 0.80
HasValidHashMethod · 0.80
SupportsCryptLayerMethod · 0.80
SetRequestFileMethod · 0.80
SetSourceFromMethod · 0.80
IsDeadSourceMethod · 0.45
HasLowIDMethod · 0.45
GetUserIDHybridMethod · 0.45

Tested by

no test coverage detected