@@ -136,7 +136,7 @@ public enum RelaySelector {
136
136
}
137
137
138
138
/// Produce a list of `RelayWithLocation` items satisfying the given constraints
139
- private static func applyConstraints< T: AnyRelay > (
139
+ static func applyConstraints< T: AnyRelay > (
140
140
_ constraints: RelayConstraints ,
141
141
relays: [ RelayWithLocation < T > ]
142
142
) -> [ RelayWithLocation < T > ] {
@@ -154,24 +154,10 @@ public enum RelaySelector {
154
154
case . any:
155
155
return true
156
156
case let . only( relayConstraint) :
157
- for location in relayConstraint. locations {
158
- switch location {
159
- case let . country( countryCode) :
160
- return relayWithLocation. serverLocation. countryCode == countryCode &&
161
- relayWithLocation. relay. includeInCountry
162
-
163
- case let . city( countryCode, cityCode) :
164
- return relayWithLocation. serverLocation. countryCode == countryCode &&
165
- relayWithLocation. serverLocation. cityCode == cityCode
166
-
167
- case let . hostname( countryCode, cityCode, hostname) :
168
- return relayWithLocation. serverLocation. countryCode == countryCode &&
169
- relayWithLocation. serverLocation. cityCode == cityCode &&
170
- relayWithLocation. relay. hostname == hostname
171
- }
157
+ // At least one location must match the relay under test.
158
+ return relayConstraint. locations. contains { location in
159
+ relayWithLocation. matches ( location: location)
172
160
}
173
-
174
- return false
175
161
}
176
162
} . filter { relayWithLocation -> Bool in
177
163
relayWithLocation. relay. active
@@ -310,9 +296,26 @@ public struct RelaySelectorResult: Codable, Equatable {
310
296
public var location : Location
311
297
}
312
298
313
- private struct RelayWithLocation < T: AnyRelay > {
299
+ struct RelayWithLocation < T: AnyRelay > {
314
300
let relay : T
315
301
let serverLocation : Location
302
+
303
+ func matches( location: RelayLocation ) -> Bool {
304
+ switch location {
305
+ case let . country( countryCode) :
306
+ serverLocation. countryCode == countryCode &&
307
+ relay. includeInCountry
308
+
309
+ case let . city( countryCode, cityCode) :
310
+ serverLocation. countryCode == countryCode &&
311
+ serverLocation. cityCode == cityCode
312
+
313
+ case let . hostname( countryCode, cityCode, hostname) :
314
+ serverLocation. countryCode == countryCode &&
315
+ serverLocation. cityCode == cityCode &&
316
+ relay. hostname == hostname
317
+ }
318
+ }
316
319
}
317
320
318
321
private struct RelayWithDistance < T: AnyRelay > {
0 commit comments