Returned bool is not if the TryToConnect is successful or not.. false means the client was deleted! true means the client was not deleted!
| 1390 | //false means the client was deleted! |
| 1391 | //true means the client was not deleted! |
| 1392 | bool CUpDownClient::TryToConnect(bool bIgnoreMaxCon) |
| 1393 | { |
| 1394 | // Kad reviewed |
| 1395 | if (theApp->listensocket->TooManySockets() && !bIgnoreMaxCon ) { |
| 1396 | if (!(m_socket && m_socket->IsConnected())) { |
| 1397 | if(Disconnected("Too many connections")) { |
| 1398 | Safe_Delete(); |
| 1399 | return false; |
| 1400 | } |
| 1401 | return true; |
| 1402 | } |
| 1403 | } |
| 1404 | |
| 1405 | // Do not try to connect to source which are incompatible with our encryption setting (one requires it, and the other one doesn't supports it) |
| 1406 | if ( (RequiresCryptLayer() && !thePrefs::IsClientCryptLayerSupported()) || (thePrefs::IsClientCryptLayerRequired() && !SupportsCryptLayer()) ){ |
| 1407 | if(Disconnected("CryptLayer-Settings (Obfuscation) incompatible")){ |
| 1408 | Safe_Delete(); |
| 1409 | return false; |
| 1410 | } else { |
| 1411 | return true; |
| 1412 | } |
| 1413 | } |
| 1414 | |
| 1415 | // Ipfilter check |
| 1416 | uint32 uClientIP = GetIP(); |
| 1417 | if (uClientIP == 0 && !HasLowID()) { |
| 1418 | uClientIP = wxUINT32_SWAP_ALWAYS(m_nUserIDHybrid); |
| 1419 | } |
| 1420 | |
| 1421 | if (uClientIP) { |
| 1422 | // Although we filter all received IPs (server sources, source exchange) and all incoming connection attempts, |
| 1423 | // we do have to filter outgoing connection attempts here too, because we may have updated the ip filter list |
| 1424 | if (theApp->ipfilter->IsFiltered(uClientIP)) { |
| 1425 | AddDebugLogLineN(logIPFilter, CFormat("Filtered ip %u (%s) on TryToConnect\n") % uClientIP % Uint32toStringIP(uClientIP)); |
| 1426 | if (Disconnected("IPFilter")) { |
| 1427 | Safe_Delete(); |
| 1428 | return false; |
| 1429 | } |
| 1430 | return true; |
| 1431 | } |
| 1432 | |
| 1433 | // for safety: check again whether that IP is banned |
| 1434 | if (theApp->clientlist->IsBannedClient(uClientIP)) { |
| 1435 | AddDebugLogLineN(logClient, "Refused to connect to banned client " + Uint32toStringIP(uClientIP)); |
| 1436 | if (Disconnected("Banned IP")) { |
| 1437 | Safe_Delete(); |
| 1438 | return false; |
| 1439 | } |
| 1440 | return true; |
| 1441 | } |
| 1442 | } |
| 1443 | |
| 1444 | if (GetKadState() == KS_QUEUED_FWCHECK) { |
| 1445 | SetKadState(KS_CONNECTING_FWCHECK); |
| 1446 | } else if (GetKadState() == KS_QUEUED_FWCHECK_UDP) { |
| 1447 | SetKadState(KS_CONNECTING_FWCHECK_UDP); |
| 1448 | } |
| 1449 |
no test coverage detected