diff options
| author | Jon Petersson <jon.petersson@kvadrat.se> | 2023-05-04 14:10:11 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2023-06-06 10:09:00 +0200 |
| commit | 3453eee5db8b569bf4e3c8b069bb35e87701a65d (patch) | |
| tree | 23a299326fdcd625f70351c7b81fc3f365bc7157 /ios/RelaySelector | |
| parent | 4f60f2368fba733c1aaa968c34d0a33d43e4e90b (diff) | |
| download | mullvadvpn-3453eee5db8b569bf4e3c8b069bb35e87701a65d.tar.xz mullvadvpn-3453eee5db8b569bf4e3c8b069bb35e87701a65d.zip | |
Add custom port selection to settings
Diffstat (limited to 'ios/RelaySelector')
| -rw-r--r-- | ios/RelaySelector/RelaySelector.swift | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/ios/RelaySelector/RelaySelector.swift b/ios/RelaySelector/RelaySelector.swift index 38a1c4d3ab..956461751b 100644 --- a/ios/RelaySelector/RelaySelector.swift +++ b/ios/RelaySelector/RelaySelector.swift @@ -101,12 +101,18 @@ public enum RelaySelector { rawPortRanges: [[UInt16]], numberOfFailedAttempts: UInt ) -> UInt16? { - // 1. First two attempts should pick a random port. - // 2. The next two should pick port 53. - // 3. Repeat steps 1 and 2. - let useDefaultPort = (numberOfFailedAttempts % 4 == 2) || (numberOfFailedAttempts % 4 == 3) + switch constraints.port { + case let .only(port): + return port - return useDefaultPort ? defaultPort : pickRandomPort(rawPortRanges: rawPortRanges) + case .any: + // 1. First two attempts should pick a random port. + // 2. The next two should pick port 53. + // 3. Repeat steps 1 and 2. + let useDefaultPort = (numberOfFailedAttempts % 4 == 2) || (numberOfFailedAttempts % 4 == 3) + + return useDefaultPort ? defaultPort : pickRandomPort(rawPortRanges: rawPortRanges) + } } private static func pickRandomRelay(relays: [RelayWithLocation]) -> RelayWithLocation? { |
