blob: d7070055e72cb8864fdb5202e01cc6ced497fc91 (
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
//
// RelaySelectorProtocol.swift
// PacketTunnel
//
// Created by pronebird on 08/08/2023.
// Copyright © 2023 Mullvad VPN AB. All rights reserved.
//
import Foundation
import MullvadSettings
import MullvadTypes
/// Protocol describing a type that can select a relay.
public protocol RelaySelectorProtocol {
func selectRelays(
tunnelSettings: LatestTunnelSettings,
connectionAttemptCount: UInt
) throws -> SelectedRelays
}
/// Struct describing the selected relay.
public struct SelectedRelay: Equatable, Codable, Sendable {
/// Selected relay endpoint.
public let endpoint: MullvadEndpoint
/// Relay hostname.
public let hostname: String
/// Relay geo location.
public let location: Location
/// Designated initializer.
public init(endpoint: MullvadEndpoint, hostname: String, location: Location) {
self.endpoint = endpoint
self.hostname = hostname
self.location = location
}
}
extension SelectedRelay: CustomDebugStringConvertible {
public var debugDescription: String {
"\(hostname) -> \(endpoint.ipv4Relay.description)"
}
}
public struct SelectedRelays: Equatable, Codable, Sendable {
public let entry: SelectedRelay?
public let exit: SelectedRelay
public let retryAttempt: UInt
public init(entry: SelectedRelay?, exit: SelectedRelay, retryAttempt: UInt) {
self.entry = entry
self.exit = exit
self.retryAttempt = retryAttempt
}
}
extension SelectedRelays: CustomDebugStringConvertible {
public var debugDescription: String {
"Entry: \(entry?.hostname ?? "-") -> \(entry?.endpoint.ipv4Relay.description ?? "-"), " +
"Exit: \(exit.hostname) -> \(exit.endpoint.ipv4Relay.description)"
}
}
|