void CClientList::AddClient( CUpDownClient* toadd ) { // Ensure that only new clients can be added to the list if ( toadd->GetClientState() == CS_NEW ) { // Update the client-state toadd->m_clientState = CS_LISTED; //Notify_ClientCtrlAddClient( toadd ); // We always add the ID/ptr pair, regardles of the actual ID value m_clientList.insert( IDMapPair( toadd->GetUserIDHybrid(), CCLIENTREF(toadd, wxT("CClientList::AddClient m_clientList.insert"))) ); // We only add the IP if it is valid if ( toadd->GetIP() ) { m_ipList.insert( IDMapPair( toadd->GetIP(), CCLIENTREF(toadd, wxT("CClientList::AddClient m_ipList.insert")) ) ); } // We only add the hash if it is valid if ( toadd->HasValidHash() ) { m_hashList.insert( HashMapPair( toadd->GetUserHash(), CCLIENTREF(toadd, wxT("CClientList::AddClient m_hashList.insert")) ) ); } toadd->UpdateStats(); } }
void CDownloadQueue::CheckAndAddKnownSource(CPartFile* sender,CUpDownClient* source) { // Kad reviewed if (sender->IsStopped()) { return; } // Filter sources which are known to be dead/useless if ( sender->IsDeadSource(source) ) { return; } // "Filter LAN IPs" -- this may be needed here in case we are connected to the internet and are also connected // to a LAN and some client from within the LAN connected to us. Though this situation may be supported in future // by adding that client to the source list and filtering that client's LAN IP when sending sources to // a client within the internet. // // "IPfilter" is not needed here, because that "known" client was already IPfiltered when receiving OP_HELLO. if (!source->HasLowID()) { uint32 nClientIP = wxUINT32_SWAP_ALWAYS(source->GetUserIDHybrid()); if (!IsGoodIP(nClientIP, thePrefs::FilterLanIPs())) { // check for 0-IP, localhost and LAN addresses AddDebugLogLineN(logIPFilter, wxT("Ignored already known source with IP=%s") + Uint32toStringIP(nClientIP)); return; } } // Filter sources which are incompatible with our encryption setting (one requires it, and the other one doesn't supports it) if ( (source->RequiresCryptLayer() && (!thePrefs::IsClientCryptLayerSupported() || !source->HasValidHash())) || (thePrefs::IsClientCryptLayerRequired() && (!source->SupportsCryptLayer() || !source->HasValidHash()))) { source->Safe_Delete(); return; } CPartFile* file = source->GetRequestFile(); // Check if the file is already queued for something else if ( file ) { if ( file != sender ) { if ( source->AddRequestForAnotherFile( sender ) ) { Notify_SourceCtrlAddSource( sender, CCLIENTREF(source, wxT("CDownloadQueue::CheckAndAddKnownSource Notify_SourceCtrlAddSource 1")), A4AF_SOURCE ); } } } else { source->SetRequestFile( sender ); if ( source->GetFileRating() || !source->GetFileComment().IsEmpty() ) { sender->UpdateFileRatingCommentAvail(); } source->SetSourceFrom(SF_PASSIVE); sender->AddSource( source ); Notify_SourceCtrlAddSource( sender, CCLIENTREF(source, wxT("CDownloadQueue::CheckAndAddKnownSource Notify_SourceCtrlAddSource 2")), UNAVAILABLE_SOURCE); } }
void CClientList::RemoveFromKadList(CUpDownClient* torem) { wxCHECK_RET(torem, wxT("NULL pointer in RemoveFromKadList")); if (m_KadSources.erase(CCLIENTREF(torem, wxEmptyString))) { if (torem == m_pBuddy.GetClient()) { m_pBuddy.Unlink(); m_nBuddyStatus = Disconnected; Notify_ServerUpdateED2KInfo(); } } }
void CClientList::UpdateClientID( CUpDownClient* client, uint32 newID ) { // Sanity check if ( ( client->GetClientState() != CS_LISTED ) || ( client->GetUserIDHybrid() == newID ) ) return; // First remove the ID entry RemoveIDFromList( client ); // Add the new entry m_clientList.insert( IDMapPair( newID, CCLIENTREF(client, wxT("CClientList::UpdateClientID")) ) ); }
void CFriendList::RequestSharedFileList(CFriend* cur_friend) { if (cur_friend) { CUpDownClient* client = cur_friend->GetLinkedClient().GetClient(); if (!client) { client = new CUpDownClient(cur_friend->GetPort(), cur_friend->GetIP(), 0, 0, 0, true, true); client->SetUserName(cur_friend->GetName()); theApp->clientlist->AddClient(client); cur_friend->LinkClient(CCLIENTREF(client, wxT("CFriendList::RequestSharedFileList"))); } client->RequestSharedFileList(); } }
void CClientList::UpdateClientIP( CUpDownClient* client, uint32 newIP ) { // Sanity check if ( ( client->GetClientState() != CS_LISTED ) || ( client->GetIP() == newIP ) ) return; // Remove the old IP entry RemoveIPFromList( client ); if ( newIP ) { m_ipList.insert( IDMapPair( newIP, CCLIENTREF(client, wxT("CClientList::UpdateClientIP")) ) ); } }
void CClientList::UpdateClientHash( CUpDownClient* client, const CMD4Hash& newHash ) { // Sanity check if ( ( client->GetClientState() != CS_LISTED ) || ( client->GetUserHash() == newHash ) ) return; // Remove the old entry RemoveHashFromList( client ); // And add the new one if valid if ( !newHash.IsEmpty() ) { m_hashList.insert( HashMapPair( newHash, CCLIENTREF(client, wxT("CClientList::UpdateClientHash")) ) ); } }
void CFriendList::StartChatSession(CFriend* Friend) { if (Friend) { CUpDownClient* client = Friend->GetLinkedClient().GetClient(); if (!client) { client = new CUpDownClient(Friend->GetPort(), Friend->GetIP(), 0, 0, 0, true, true); client->SetIP(Friend->GetIP()); client->SetUserName(Friend->GetName()); theApp->clientlist->AddClient(client); Friend->LinkClient(CCLIENTREF(client, wxT("CFriendList::StartChatSession"))); } } else { AddLogLineC(_("CRITICAL - no client on StartChatSession")); } }
void CDownloadQueue::CheckAndAddSource(CPartFile* sender, CUpDownClient* source) { // if we block loopbacks at this point it should prevent us from connecting to ourself if ( source->HasValidHash() ) { if ( source->GetUserHash() == thePrefs::GetUserHash() ) { AddDebugLogLineN( logDownloadQueue, wxT("Tried to add source with matching hash to your own.") ); source->Safe_Delete(); return; } } if (sender->IsStopped()) { source->Safe_Delete(); return; } //Dynamic Leecher Protect - Bill Lee if ( source->IsBanned() ){ source->Safe_Delete(); return; } //Bill Lee end // Filter sources which are known to be dead/useless if ( theApp->clientlist->IsDeadSource( source ) || sender->IsDeadSource(source) ) { source->Safe_Delete(); return; } // Filter sources which are incompatible with our encryption setting (one requires it, and the other one doesn't supports it) if ( (source->RequiresCryptLayer() && (!thePrefs::IsClientCryptLayerSupported() || !source->HasValidHash())) || (thePrefs::IsClientCryptLayerRequired() && (!source->SupportsCryptLayer() || !source->HasValidHash()))) { source->Safe_Delete(); return; } // Find all clients with the same hash if ( source->HasValidHash() ) { CClientList::SourceList found = theApp->clientlist->GetClientsByHash( source->GetUserHash() ); CClientList::SourceList::iterator it = found.begin(); for ( ; it != found.end(); it++ ) { CKnownFile* file = it->GetRequestFile(); // Only check files on the download-queue if ( file ) { // Is the found source queued for something else? if ( file != sender ) { // Try to add a request for the other file if ( it->GetClient()->AddRequestForAnotherFile(sender)) { // Add it to downloadlistctrl Notify_SourceCtrlAddSource(sender, *it, A4AF_SOURCE); } } source->Safe_Delete(); return; } } } // Our new source is real new but maybe it is already uploading to us? // If yes the known client will be attached to the var "source" and the old // source-client will be deleted. However, if the request file of the known // source is NULL, then we have to treat it almost like a new source and if // it isn't NULL and not "sender", then we shouldn't move it, but rather add // a request for the new file. ESourceFrom nSourceFrom = source->GetSourceFrom(); if ( theApp->clientlist->AttachToAlreadyKnown(&source, 0) ) { // Already queued for another file? if ( source->GetRequestFile() ) { // If we're already queued for the right file, then there's nothing to do if ( sender != source->GetRequestFile() ) { // Add the new file to the request list source->AddRequestForAnotherFile( sender ); } } else { // Source was known, but reqfile NULL. source->SetRequestFile( sender ); source->SetSourceFrom(nSourceFrom); sender->AddSource( source ); if ( source->GetFileRating() || !source->GetFileComment().IsEmpty() ) { sender->UpdateFileRatingCommentAvail(); } Notify_SourceCtrlAddSource(sender, CCLIENTREF(source, wxT("CDownloadQueue::CheckAndAddSource Notify_SourceCtrlAddSource 1")), UNAVAILABLE_SOURCE); } } else { // Unknown client, add it to the clients list source->SetRequestFile( sender ); theApp->clientlist->AddClient(source); sender->AddSource( source ); if ( source->GetFileRating() || !source->GetFileComment().IsEmpty() ) { sender->UpdateFileRatingCommentAvail(); } Notify_SourceCtrlAddSource(sender, CCLIENTREF(source, wxT("CDownloadQueue::CheckAndAddSource Notify_SourceCtrlAddSource 2")), UNAVAILABLE_SOURCE); } }
void CClientList::AddToKadList(CUpDownClient* toadd) { wxCHECK_RET(toadd, wxT("NULL pointer in AddToKadList")); m_KadSources.insert(CCLIENTREF(toadd, wxT("CClientList::AddToKadList"))); // This will take care of duplicates. }