summaryrefslogtreecommitdiffhomepage
path: root/ios/PacketTunnel/PacketTunnelProvider/RelaySelectorWrapper.swift
blob: 5127e0a55b3226feda1e48313963e139713ff1a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//
//  RelaySelectorWrapper.swift
//  PacketTunnel
//
//  Created by pronebird on 08/08/2023.
//  Copyright © 2023 Mullvad VPN AB. All rights reserved.
//

import Foundation
import MullvadREST
import MullvadTypes
import PacketTunnelCore

struct RelaySelectorWrapper: RelaySelectorProtocol {
    let relayCache: RelayCache

    func selectRelay(
        with constraints: RelayConstraints,
        connectionAttemptFailureCount: UInt
    ) throws -> SelectedRelay {
        let selectorResult = try RelaySelector.evaluate(
            relays: relayCache.read().relays,
            constraints: constraints,
            numberOfFailedAttempts: connectionAttemptFailureCount
        )

        return SelectedRelay(
            endpoint: selectorResult.endpoint,
            hostname: selectorResult.relay.hostname,
            location: selectorResult.location,
            retryAttempts: connectionAttemptFailureCount
        )
    }
}