| 69 | } |
| 70 | |
| 71 | NetworkPathCandidate NetworkPathResolver::resolveExplicitSelection(const QString& interfaceId, |
| 72 | const QString& interfaceName, |
| 73 | const QHostAddress& lastSuccessfulAddress) |
| 74 | { |
| 75 | const auto candidates = enumerateIpv4Candidates(); |
| 76 | |
| 77 | auto findMatch = [&](auto&& predicate) -> NetworkPathCandidate { |
| 78 | for (const auto& candidate : candidates) { |
| 79 | if (predicate(candidate)) |
| 80 | return candidate; |
| 81 | } |
| 82 | return {}; |
| 83 | }; |
| 84 | |
| 85 | if (!interfaceId.trimmed().isEmpty()) { |
| 86 | auto match = findMatch([&](const NetworkPathCandidate& candidate) { |
| 87 | return candidate.interfaceId == interfaceId; |
| 88 | }); |
| 89 | if (match.isValid()) |
| 90 | return match; |
| 91 | } |
| 92 | |
| 93 | if (!interfaceName.trimmed().isEmpty()) { |
| 94 | auto match = findMatch([&](const NetworkPathCandidate& candidate) { |
| 95 | return candidate.interfaceName == interfaceName; |
| 96 | }); |
| 97 | if (match.isValid()) |
| 98 | return match; |
| 99 | } |
| 100 | |
| 101 | if (isUsableIpv4(lastSuccessfulAddress)) { |
| 102 | auto match = findMatch([&](const NetworkPathCandidate& candidate) { |
| 103 | return candidate.address == lastSuccessfulAddress; |
| 104 | }); |
| 105 | if (match.isValid()) |
| 106 | return match; |
| 107 | } |
| 108 | |
| 109 | return {}; |
| 110 | } |
| 111 | |
| 112 | NetworkPathCandidate NetworkPathResolver::autoCandidate() |
| 113 | { |