@@ -37,38 +37,60 @@ extension RelayPicking {
37
37
38
38
struct SinglehopPicker : RelayPicking {
39
39
let constraints : RelayConstraints
40
+ let daitaSettings : DAITASettings
40
41
let relays : REST . ServerRelaysResponse
41
42
let connectionAttemptCount : UInt
42
43
43
44
func pick( ) throws -> SelectedRelays {
44
- let candidates = try RelaySelector . WireGuard. findCandidates (
45
- by: constraints. exitLocations,
46
- in: relays,
47
- filterConstraint: constraints. filter
48
- )
45
+ var exitCandidates = [ RelayWithLocation < REST . ServerRelay > ] ( )
49
46
50
- let match = try findBestMatch ( from: candidates)
47
+ do {
48
+ exitCandidates = try RelaySelector . WireGuard. findCandidates (
49
+ by: constraints. exitLocations,
50
+ in: relays,
51
+ filterConstraint: constraints. filter,
52
+ daitaEnabled: daitaSettings. state. isEnabled
53
+ )
54
+ } catch let error as NoRelaysSatisfyingConstraintsError where error. reason == . noDaitaRelaysFound {
55
+ #if DEBUG
56
+ // If DAITA is enabled and no supported relays are found, we should try to find the nearest
57
+ // available relay that supports DAITA and use it as entry in a multihop selection.
58
+ var constraints = constraints
59
+ constraints. entryLocations = . any
60
+
61
+ return try MultihopPicker (
62
+ constraints: constraints,
63
+ daitaSettings: daitaSettings,
64
+ relays: relays,
65
+ connectionAttemptCount: connectionAttemptCount
66
+ ) . pick ( )
67
+ #endif
68
+ }
51
69
70
+ let match = try findBestMatch ( from: exitCandidates)
52
71
return SelectedRelays ( entry: nil , exit: match, retryAttempt: connectionAttemptCount)
53
72
}
54
73
}
55
74
56
75
struct MultihopPicker : RelayPicking {
57
76
let constraints : RelayConstraints
77
+ let daitaSettings : DAITASettings
58
78
let relays : REST . ServerRelaysResponse
59
79
let connectionAttemptCount : UInt
60
80
61
81
func pick( ) throws -> SelectedRelays {
62
82
let entryCandidates = try RelaySelector . WireGuard. findCandidates (
63
83
by: constraints. entryLocations,
64
84
in: relays,
65
- filterConstraint: constraints. filter
85
+ filterConstraint: constraints. filter,
86
+ daitaEnabled: daitaSettings. state. isEnabled
66
87
)
67
88
68
89
let exitCandidates = try RelaySelector . WireGuard. findCandidates (
69
90
by: constraints. exitLocations,
70
91
in: relays,
71
- filterConstraint: constraints. filter
92
+ filterConstraint: constraints. filter,
93
+ daitaEnabled: false
72
94
)
73
95
74
96
/*
0 commit comments