| @@ -177,78 +177,118 @@ final class DomainViewModel { |
| 177 | var bulkInput: String = "" |
177 | var bulkInput: String = "" |
| 178 | var domainInputError: String? |
178 | var domainInputError: String? |
| 179 | |
179 | |
| 180 | var dnsSections: [DNSSection] = [] |
180 | // MARK: Section state |
| 181 | var dnsLoading = false |
181 | |
| 182 | var dnsError: String? |
182 | /// Each section's value, phase and error as one stored property, so the |
| 183 | var availabilityResult: DomainAvailabilityResult? |
183 | /// three are written together or not at all. There were 20 `*Loading` |
| 184 | var availabilityLoading = false |
184 | /// flags and 19 `*Error` strings before, independently assignable (A2). |
| 185 | var suggestions: [DomainSuggestionResult] = [] |
185 | /// |
| 186 | var suggestionsLoading = false |
186 | /// The accessors below keep the names every reader already uses. They are |
| 187 | |
187 | /// a staging layer: the next step is views reading the state directly, as |
| 188 | var sslInfo: SSLCertificateInfo? |
188 | /// the Web and Network slices already do. |
| 189 | var sslLoading = false |
189 | var dnsState = SectionState<[DNSSection]>() |
| 190 | var sslError: String? |
190 | var availabilityState = SectionState<DomainAvailabilityResult>() |
| 191 | var hstsPreloaded: Bool? |
191 | var suggestionsState = SectionState<[DomainSuggestionResult]>() |
| 192 | var hstsLoading = false |
192 | var sslState = SectionState<SSLCertificateInfo>() |
| 193 | |
193 | var hstsState = SectionState<Bool>() |
| 194 | var httpHeaders: [HTTPHeader] = [] |
194 | var httpHeadersState = SectionState<[HTTPHeader]>() |
| |
195 | var reachabilityState = SectionState<[PortReachability]>() |
| |
196 | var ipGeolocationState = SectionState<IPGeolocation>() |
| |
197 | var emailSecurityState = SectionState<EmailSecurityResult>() |
| |
198 | var ownershipState = SectionState<DomainOwnership>() |
| |
199 | var ownershipHistoryState = SectionState<[DomainOwnershipHistoryEvent]>() |
| |
200 | var ptrState = SectionState<String>() |
| |
201 | var redirectChainState = SectionState<[RedirectHop]>() |
| |
202 | var subdomainsState = SectionState<[DiscoveredSubdomain]>() |
| |
203 | var extendedSubdomainsState = SectionState<[DiscoveredSubdomain]>() |
| |
204 | var dnsHistoryState = SectionState<[DNSHistoryEvent]>() |
| |
205 | var domainPricingState = SectionState<DomainPricingInsight>() |
| |
206 | var reputationState = SectionState<DomainReputationResult>() |
| |
207 | var portScanState = SectionState<[PortScanResult]>() |
| |
208 | var customPortScanState = SectionState<[PortScanResult]>() |
| |
209 | |
| |
210 | var dnsSections: [DNSSection] { dnsState.items } |
| |
211 | var dnsLoading: Bool { dnsState.isLoading } |
| |
212 | var dnsError: String? { dnsState.error } |
| |
213 | |
| |
214 | var availabilityResult: DomainAvailabilityResult? { availabilityState.value } |
| |
215 | var availabilityLoading: Bool { availabilityState.isLoading } |
| |
216 | |
| |
217 | var suggestions: [DomainSuggestionResult] { suggestionsState.items } |
| |
218 | var suggestionsLoading: Bool { suggestionsState.isLoading } |
| |
219 | |
| |
220 | var sslInfo: SSLCertificateInfo? { sslState.value } |
| |
221 | var sslLoading: Bool { sslState.isLoading } |
| |
222 | var sslError: String? { sslState.error } |
| |
223 | |
| |
224 | var hstsPreloaded: Bool? { hstsState.value } |
| |
225 | var hstsLoading: Bool { hstsState.isLoading } |
| |
226 | |
| |
227 | var httpHeaders: [HTTPHeader] { httpHeadersState.items } |
| |
228 | var httpHeadersLoading: Bool { httpHeadersState.isLoading } |
| |
229 | var httpHeadersError: String? { httpHeadersState.error } |
| |
230 | |
| |
231 | var reachabilityResults: [PortReachability] { reachabilityState.items } |
| |
232 | var reachabilityLoading: Bool { reachabilityState.isLoading } |
| |
233 | var reachabilityError: String? { reachabilityState.error } |
| |
234 | |
| |
235 | var ipGeolocation: IPGeolocation? { ipGeolocationState.value } |
| |
236 | var ipGeolocationLoading: Bool { ipGeolocationState.isLoading } |
| |
237 | var ipGeolocationError: String? { ipGeolocationState.error } |
| |
238 | |
| |
239 | var emailSecurity: EmailSecurityResult? { emailSecurityState.value } |
| |
240 | var emailSecurityLoading: Bool { emailSecurityState.isLoading } |
| |
241 | var emailSecurityError: String? { emailSecurityState.error } |
| |
242 | |
| |
243 | var ownershipResult: DomainOwnership? { ownershipState.value } |
| |
244 | var ownershipLoading: Bool { ownershipState.isLoading } |
| |
245 | var ownershipError: String? { ownershipState.error } |
| |
246 | |
| |
247 | var ownershipHistory: [DomainOwnershipHistoryEvent] { ownershipHistoryState.items } |
| |
248 | var ownershipHistoryLoading: Bool { ownershipHistoryState.isLoading } |
| |
249 | var ownershipHistoryError: String? { ownershipHistoryState.error } |
| |
250 | |
| |
251 | var ptrRecord: String? { ptrState.value } |
| |
252 | var ptrLoading: Bool { ptrState.isLoading } |
| |
253 | var ptrError: String? { ptrState.error } |
| |
254 | |
| |
255 | var redirectChain: [RedirectHop] { redirectChainState.items } |
| |
256 | var redirectChainLoading: Bool { redirectChainState.isLoading } |
| |
257 | var redirectChainError: String? { redirectChainState.error } |
| |
258 | |
| |
259 | var subdomains: [DiscoveredSubdomain] { subdomainsState.items } |
| |
260 | var subdomainsLoading: Bool { subdomainsState.isLoading } |
| |
261 | var subdomainsError: String? { subdomainsState.error } |
| |
262 | |
| |
263 | var extendedSubdomains: [DiscoveredSubdomain] { extendedSubdomainsState.items } |
| |
264 | var extendedSubdomainsLoading: Bool { extendedSubdomainsState.isLoading } |
| |
265 | var extendedSubdomainsError: String? { extendedSubdomainsState.error } |
| |
266 | |
| |
267 | var dnsHistory: [DNSHistoryEvent] { dnsHistoryState.items } |
| |
268 | var dnsHistoryLoading: Bool { dnsHistoryState.isLoading } |
| |
269 | var dnsHistoryError: String? { dnsHistoryState.error } |
| |
270 | |
| |
271 | var domainPricing: DomainPricingInsight? { domainPricingState.value } |
| |
272 | var domainPricingLoading: Bool { domainPricingState.isLoading } |
| |
273 | var domainPricingError: String? { domainPricingState.error } |
| |
274 | |
| |
275 | var reputation: DomainReputationResult? { reputationState.value } |
| |
276 | var reputationLoading: Bool { reputationState.isLoading } |
| |
277 | var reputationError: String? { reputationState.error } |
| |
278 | |
| |
279 | var portScanResults: [PortScanResult] { portScanState.items } |
| |
280 | var portScanLoading: Bool { portScanState.isLoading } |
| |
281 | var portScanError: String? { portScanState.error } |
| |
282 | |
| |
283 | var customPortResults: [PortScanResult] { customPortScanState.items } |
| |
284 | var customPortScanLoading: Bool { customPortScanState.isLoading } |
| |
285 | var customPortScanError: String? { customPortScanState.error } |
| |
286 | |
| 195 | var httpSecurityGrade: String? |
287 | var httpSecurityGrade: String? |
| 196 | var httpStatusCode: Int? |
288 | var httpStatusCode: Int? |
| 197 | var httpResponseTimeMs: Int? |
289 | var httpResponseTimeMs: Int? |
| 198 | var httpProtocol: String? |
290 | var httpProtocol: String? |
| 199 | var http3Advertised = false |
291 | var http3Advertised = false |
| 200 | var httpHeadersLoading = false |
| |
| 201 | var httpHeadersError: String? |
| |
| 202 | |
| |
| 203 | var reachabilityResults: [PortReachability] = [] |
| |
| 204 | var reachabilityLoading = false |
| |
| 205 | var reachabilityError: String? |
| |
| 206 | |
| |
| 207 | var ipGeolocation: IPGeolocation? |
| |
| 208 | var ipGeolocationLoading = false |
| |
| 209 | var ipGeolocationError: String? |
| |
| 210 | |
| |
| 211 | var emailSecurity: EmailSecurityResult? |
| |
| 212 | var emailSecurityLoading = false |
| |
| 213 | var emailSecurityError: String? |
| |
| 214 | |
| |
| 215 | var ownershipResult: DomainOwnership? |
| |
| 216 | var ownershipLoading = false |
| |
| 217 | var ownershipError: String? |
| |
| 218 | var ownershipHistory: [DomainOwnershipHistoryEvent] = [] |
| |
| 219 | var ownershipHistoryLoading = false |
| |
| 220 | var ownershipHistoryError: String? |
| |
| 221 | |
| |
| 222 | var ptrRecord: String? |
| |
| 223 | var ptrLoading = false |
| |
| 224 | var ptrError: String? |
| |
| 225 | |
| |
| 226 | var redirectChain: [RedirectHop] = [] |
| |
| 227 | var redirectChainLoading = false |
| |
| 228 | var redirectChainError: String? |
| |
| 229 | |
| |
| 230 | var subdomains: [DiscoveredSubdomain] = [] |
| |
| 231 | var subdomainsLoading = false |
| |
| 232 | var subdomainsError: String? |
| |
| 233 | var extendedSubdomains: [DiscoveredSubdomain] = [] |
| |
| 234 | var extendedSubdomainsLoading = false |
| |
| 235 | var extendedSubdomainsError: String? |
| |
| 236 | var dnsHistory: [DNSHistoryEvent] = [] |
| |
| 237 | var dnsHistoryLoading = false |
| |
| 238 | var dnsHistoryError: String? |
| |
| 239 | var domainPricing: DomainPricingInsight? |
| |
| 240 | var domainPricingLoading = false |
| |
| 241 | var domainPricingError: String? |
| |
| 242 | var reputation: DomainReputationResult? |
| |
| 243 | var reputationLoading = false |
| |
| 244 | var reputationError: String? |
| |
| 245 | |
| |
| 246 | var portScanResults: [PortScanResult] = [] |
| |
| 247 | var portScanLoading = false |
| |
| 248 | var portScanError: String? |
| |
| 249 | var customPortResults: [PortScanResult] = [] |
| |
| 250 | var customPortScanLoading = false |
| |
| 251 | var customPortScanError: String? |
| |
| 252 | |
292 | |
| 253 | var hasRun = false |
293 | var hasRun = false |
| 254 | private(set) var searchedDomain: String = "" |
294 | private(set) var searchedDomain: String = "" |
| @@ -372,22 +412,24 @@ final class DomainViewModel { |
| 372 | } |
412 | } |
| 373 | |
413 | |
| 374 | var resultsLoaded: Bool { |
414 | var resultsLoaded: Bool { |
| 375 | hasRun && |
415 | guard hasRun else { return false } |
| 376 | !dnsLoading && |
416 | return [ |
| 377 | !availabilityLoading && |
417 | dnsState.isSettled, |
| 378 | !suggestionsLoading && |
418 | availabilityState.isSettled, |
| 379 | !sslLoading && |
419 | suggestionsState.isSettled, |
| 380 | !hstsLoading && |
420 | sslState.isSettled, |
| 381 | !httpHeadersLoading && |
421 | hstsState.isSettled, |
| 382 | !reachabilityLoading && |
422 | httpHeadersState.isSettled, |
| 383 | !ipGeolocationLoading && |
423 | reachabilityState.isSettled, |
| 384 | !emailSecurityLoading && |
424 | ipGeolocationState.isSettled, |
| 385 | !ownershipLoading && |
425 | emailSecurityState.isSettled, |
| 386 | !ptrLoading && |
426 | ownershipState.isSettled, |
| 387 | !redirectChainLoading && |
427 | ptrState.isSettled, |
| 388 | !subdomainsLoading && |
428 | redirectChainState.isSettled, |
| 389 | !portScanLoading && |
429 | subdomainsState.isSettled, |
| 390 | !customPortScanLoading |
430 | portScanState.isSettled, |
| |
431 | !customPortScanState.isLoading |
| |
432 | ].allSatisfy { $0 } |
| 391 | } |
433 | } |
| 392 | |
434 | |
| 393 | var activeLoadingLabels: [String] { |
435 | var activeLoadingLabels: [String] { |
| @@ -1327,13 +1369,12 @@ final class DomainViewModel { |
| 1327 | |
1369 | |
| 1328 | func runCustomPortScan(ports: [UInt16]) async { |
1370 | func runCustomPortScan(ports: [UInt16]) async { |
| 1329 | guard !searchedDomain.isEmpty else { |
1371 | guard !searchedDomain.isEmpty else { |
| 1330 | customPortScanError = "Run a domain lookup first" |
1372 | customPortScanState = .settled(value: [], error: "Run a domain lookup first") |
| 1331 | return |
1373 | return |
| 1332 | } |
1374 | } |
| 1333 | |
1375 | |
| 1334 | guard !ports.isEmpty else { |
1376 | guard !ports.isEmpty else { |
| 1335 | customPortScanError = "Enter at least one valid port" |
1377 | customPortScanState = .settled(value: [], error: "Enter at least one valid port") |
| 1336 | customPortResults = [] |
| |
| 1337 | return |
1378 | return |
| 1338 | } |
1379 | } |
| 1339 | |
1380 | |
| @@ -1341,9 +1382,7 @@ final class DomainViewModel { |
| 1341 | let domain = searchedDomain |
1382 | let domain = searchedDomain |
| 1342 | let lookupID = activeLookupID |
1383 | let lookupID = activeLookupID |
| 1343 | |
1384 | |
| 1344 | customPortScanLoading = true |
1385 | customPortScanState = .loading |
| 1345 | customPortScanError = nil |
| |
| 1346 | customPortResults = [] |
| |
| 1347 | |
1386 | |
| 1348 | customPortScanTask = Task { [weak self] in |
1387 | customPortScanTask = Task { [weak self] in |
| 1349 | guard let self else { return } |
1388 | guard let self else { return } |
| @@ -1407,8 +1446,7 @@ final class DomainViewModel { |
| 1407 | } |
1446 | } |
| 1408 | |
1447 | |
| 1409 | func loadOwnershipHistory() async { |
1448 | func loadOwnershipHistory() async { |
| 1410 | await loadLookup(into: \.ownershipHistory, loading: \.ownershipHistoryLoading, error: \.ownershipHistoryError, |
1449 | await loadLookup(into: \.ownershipHistoryState, fallback: "Ownership history unavailable") { |
| 1411 | fallback: "Ownership history unavailable") { |
| |
| 1412 | await ExternalDataService.shared.ownershipHistory( |
1450 | await ExternalDataService.shared.ownershipHistory( |
| 1413 | domain: searchedDomain, |
1451 | domain: searchedDomain, |
| 1414 | currentOwnership: ownershipResult, |
1452 | currentOwnership: ownershipResult, |
| @@ -1418,8 +1456,7 @@ final class DomainViewModel { |
| 1418 | } |
1456 | } |
| 1419 | |
1457 | |
| 1420 | func loadDNSHistory() async { |
1458 | func loadDNSHistory() async { |
| 1421 | await loadLookup(into: \.dnsHistory, loading: \.dnsHistoryLoading, error: \.dnsHistoryError, |
1459 | await loadLookup(into: \.dnsHistoryState, fallback: "DNS history unavailable") { |
| 1422 | fallback: "DNS history unavailable") { |
| |
| 1423 | await ExternalDataService.shared.dnsHistory( |
1460 | await ExternalDataService.shared.dnsHistory( |
| 1424 | domain: searchedDomain, |
1461 | domain: searchedDomain, |
| 1425 | dnsSections: dnsSections, |
1462 | dnsSections: dnsSections, |
| @@ -1429,8 +1466,11 @@ final class DomainViewModel { |
| 1429 | } |
1466 | } |
| 1430 | |
1467 | |
| 1431 | func loadExtendedSubdomains() async { |
1468 | func loadExtendedSubdomains() async { |
| 1432 | await loadLookup(.extendedSubdomains, into: \.extendedSubdomains, loading: \.extendedSubdomainsLoading, error: \.extendedSubdomainsError, |
1469 | await loadLookup( |
| 1433 | fallback: "Extended subdomains unavailable") { |
1470 | .extendedSubdomains, |
| |
1471 | into: \.extendedSubdomainsState, |
| |
1472 | fallback: "Extended subdomains unavailable" |
| |
1473 | ) { |
| 1434 | await ExternalDataService.shared.extendedSubdomains( |
1474 | await ExternalDataService.shared.extendedSubdomains( |
| 1435 | domain: searchedDomain, |
1475 | domain: searchedDomain, |
| 1436 | existing: subdomains |
1476 | existing: subdomains |
| @@ -1443,9 +1483,7 @@ final class DomainViewModel { |
| 1443 | /// doesn't include it; without one the lookup is open to every tier. |
1483 | /// doesn't include it; without one the lookup is open to every tier. |
| 1444 | private func loadLookup<Item>( |
1484 | private func loadLookup<Item>( |
| 1445 | _ capability: FeatureCapability? = nil, |
1485 | _ capability: FeatureCapability? = nil, |
| 1446 | into items: ReferenceWritableKeyPath<DomainViewModel, [Item]>, |
1486 | into state: ReferenceWritableKeyPath<DomainViewModel, SectionState<[Item]>>, |
| 1447 | loading: ReferenceWritableKeyPath<DomainViewModel, Bool>, |
| |
| 1448 | error: ReferenceWritableKeyPath<DomainViewModel, String?>, |
| |
| 1449 | fallback: String, |
1487 | fallback: String, |
| 1450 | fetch: () async -> ServiceResult<[Item]> |
1488 | fetch: () async -> ServiceResult<[Item]> |
| 1451 | ) async { |
1489 | ) async { |
| @@ -1454,14 +1492,11 @@ final class DomainViewModel { |
| 1454 | upgradePrompt = FeatureAccessService.upgradePrompt(for: capability) |
1492 | upgradePrompt = FeatureAccessService.upgradePrompt(for: capability) |
| 1455 | return |
1493 | return |
| 1456 | } |
1494 | } |
| 1457 | guard self[keyPath: items].isEmpty else { return } |
1495 | guard self[keyPath: state].items.isEmpty else { return } |
| 1458 | |
| |
| 1459 | self[keyPath: loading] = true |
| |
| 1460 | self[keyPath: error] = nil |
| |
| 1461 | |
| |
| 1462 | (self[keyPath: items], self[keyPath: error]) = found(await fetch(), fallback: fallback) |
| |
| 1463 | |
1496 | |
| 1464 | self[keyPath: loading] = false |
1497 | self[keyPath: state] = .loading |
| |
1498 | let (items, message) = found(await fetch(), fallback: fallback) |
| |
1499 | self[keyPath: state] = .settled(value: items, error: message) |
| 1465 | _ = saveHistoryEntry(replaceLatest: true) |
1500 | _ = saveHistoryEntry(replaceLatest: true) |
| 1466 | } |
1501 | } |
| 1467 | |
1502 | |
| @@ -1506,7 +1541,10 @@ final class DomainViewModel { |
| 1506 | return entry |
1541 | return entry |
| 1507 | } |
1542 | } |
| 1508 | |
1543 | |
| 1509 | private func applySnapshot(_ snapshot: LookupSnapshot) { |
1544 | /// The single place section state is written from an inspection result. |
| |
1545 | /// Internal so the tests that pin what each section ends up showing can |
| |
1546 | /// reach it without a live lookup. |
| |
1547 | func applySnapshot(_ snapshot: LookupSnapshot) { |
| 1510 | currentHistoryEntryID = snapshot.historyEntryID |
1548 | currentHistoryEntryID = snapshot.historyEntryID |
| 1511 | currentSnapshotTimestamp = snapshot.timestamp |
1549 | currentSnapshotTimestamp = snapshot.timestamp |
| 1512 | currentResultSource = snapshot.resultSource |
1550 | currentResultSource = snapshot.resultSource |
| @@ -1527,79 +1565,44 @@ final class DomainViewModel { |
| 1527 | DomainDebugLog.signpostEnd("DomainViewModel.reportBuilder.build", start: reportStartedAt, domain: snapshot.domain) |
1565 | DomainDebugLog.signpostEnd("DomainViewModel.reportBuilder.build", start: reportStartedAt, domain: snapshot.domain) |
| 1528 | currentChangeSummary = currentReport?.changeSummary ?? snapshot.changeSummary |
1566 | currentChangeSummary = currentReport?.changeSummary ?? snapshot.changeSummary |
| 1529 | |
1567 | |
| 1530 | dnsSections = snapshot.dnsSections |
1568 | dnsState = .settled(value: snapshot.dnsSections, error: snapshot.dnsError) |
| 1531 | dnsError = snapshot.dnsError |
1569 | availabilityState = .settled(value: snapshot.availabilityResult) |
| 1532 | availabilityResult = snapshot.availabilityResult |
1570 | suggestionsState = .settled(value: snapshot.suggestions) |
| 1533 | suggestions = snapshot.suggestions |
1571 | sslState = .settled(value: snapshot.sslInfo, error: snapshot.sslError) |
| 1534 | sslInfo = snapshot.sslInfo |
1572 | hstsState = .settled(value: snapshot.hstsPreloaded) |
| 1535 | sslError = snapshot.sslError |
1573 | httpHeadersState = .settled(value: snapshot.httpHeaders, error: snapshot.httpHeadersError) |
| 1536 | hstsPreloaded = snapshot.hstsPreloaded |
| |
| 1537 | httpHeaders = snapshot.httpHeaders |
| |
| 1538 | httpSecurityGrade = snapshot.httpSecurityGrade |
1574 | httpSecurityGrade = snapshot.httpSecurityGrade |
| 1539 | httpStatusCode = snapshot.httpStatusCode |
1575 | httpStatusCode = snapshot.httpStatusCode |
| 1540 | httpResponseTimeMs = snapshot.httpResponseTimeMs |
1576 | httpResponseTimeMs = snapshot.httpResponseTimeMs |
| 1541 | httpProtocol = snapshot.httpProtocol |
1577 | httpProtocol = snapshot.httpProtocol |
| 1542 | http3Advertised = snapshot.http3Advertised |
1578 | http3Advertised = snapshot.http3Advertised |
| 1543 | httpHeadersError = snapshot.httpHeadersError |
1579 | reachabilityState = .settled(value: snapshot.reachabilityResults, error: snapshot.reachabilityError) |
| 1544 | reachabilityResults = snapshot.reachabilityResults |
1580 | ipGeolocationState = .settled(value: snapshot.ipGeolocation, error: snapshot.ipGeolocationError) |
| 1545 | reachabilityError = snapshot.reachabilityError |
1581 | emailSecurityState = .settled(value: snapshot.emailSecurity, error: snapshot.emailSecurityError) |
| 1546 | ipGeolocation = snapshot.ipGeolocation |
1582 | ownershipState = .settled(value: snapshot.ownership, error: snapshot.ownershipError) |
| 1547 | ipGeolocationError = snapshot.ipGeolocationError |
1583 | ownershipHistoryState = .settled(value: snapshot.ownershipHistory, error: snapshot.ownershipHistoryError) |
| 1548 | emailSecurity = snapshot.emailSecurity |
1584 | ptrState = .settled(value: snapshot.ptrRecord, error: snapshot.ptrError) |
| 1549 | emailSecurityError = snapshot.emailSecurityError |
1585 | redirectChainState = .settled(value: snapshot.redirectChain, error: snapshot.redirectChainError) |
| 1550 | ownershipResult = snapshot.ownership |
1586 | subdomainsState = .settled(value: snapshot.subdomains, error: snapshot.subdomainsError) |
| 1551 | ownershipError = snapshot.ownershipError |
1587 | extendedSubdomainsState = .settled(value: snapshot.extendedSubdomains, error: snapshot.extendedSubdomainsError) |
| 1552 | ownershipHistory = snapshot.ownershipHistory |
1588 | dnsHistoryState = .settled(value: snapshot.dnsHistory, error: snapshot.dnsHistoryError) |
| 1553 | ownershipHistoryError = snapshot.ownershipHistoryError |
1589 | domainPricingState = .settled(value: snapshot.domainPricing, error: snapshot.domainPricingError) |
| 1554 | ptrRecord = snapshot.ptrRecord |
1590 | reputationState = .settled(value: snapshot.reputation, error: snapshot.reputationError) |
| 1555 | ptrError = snapshot.ptrError |
1591 | portScanState = .settled( |
| 1556 | redirectChain = snapshot.redirectChain |
1592 | value: snapshot.portScanResults.filter { $0.kind == .standard }, |
| 1557 | redirectChainError = snapshot.redirectChainError |
1593 | error: snapshot.portScanError |
| 1558 | subdomains = snapshot.subdomains |
1594 | ) |
| 1559 | subdomainsError = snapshot.subdomainsError |
1595 | customPortScanState = .settled(value: snapshot.portScanResults.filter { $0.kind == .custom }) |
| 1560 | extendedSubdomains = snapshot.extendedSubdomains |
| |
| 1561 | extendedSubdomainsError = snapshot.extendedSubdomainsError |
| |
| 1562 | dnsHistory = snapshot.dnsHistory |
| |
| 1563 | dnsHistoryError = snapshot.dnsHistoryError |
| |
| 1564 | domainPricing = snapshot.domainPricing |
| |
| 1565 | domainPricingError = snapshot.domainPricingError |
| |
| 1566 | portScanResults = snapshot.portScanResults.filter { $0.kind == .standard } |
| |
| 1567 | customPortResults = snapshot.portScanResults.filter { $0.kind == .custom } |
| |
| 1568 | portScanError = snapshot.portScanError |
| |
| 1569 | customPortScanError = nil |
| |
| 1570 | |
| |
| 1571 | dnsLoading = false |
| |
| 1572 | availabilityLoading = false |
| |
| 1573 | suggestionsLoading = false |
| |
| 1574 | sslLoading = false |
| |
| 1575 | hstsLoading = false |
| |
| 1576 | httpHeadersLoading = false |
| |
| 1577 | reachabilityLoading = false |
| |
| 1578 | ipGeolocationLoading = false |
| |
| 1579 | emailSecurityLoading = false |
| |
| 1580 | ownershipLoading = false |
| |
| 1581 | ownershipHistoryLoading = false |
| |
| 1582 | ptrLoading = false |
| |
| 1583 | redirectChainLoading = false |
| |
| 1584 | subdomainsLoading = false |
| |
| 1585 | extendedSubdomainsLoading = false |
| |
| 1586 | dnsHistoryLoading = false |
| |
| 1587 | domainPricingLoading = false |
| |
| 1588 | portScanLoading = false |
| |
| 1589 | customPortScanLoading = false |
| |
| 1590 | } |
1596 | } |
| 1591 | |
1597 | |
| 1592 | private func applyCustomPortResult(_ result: ServiceResult<[PortScanResult]>) { |
1598 | private func applyCustomPortResult(_ result: ServiceResult<[PortScanResult]>) { |
| 1593 | switch result { |
1599 | switch result { |
| 1594 | case let .success(results): |
1600 | case let .success(results): |
| 1595 | customPortResults = results |
1601 | customPortScanState = .settled(value: results) |
| 1596 | customPortScanError = nil |
| |
| 1597 | _ = saveHistoryEntry(replaceLatest: true) |
1602 | _ = saveHistoryEntry(replaceLatest: true) |
| 1598 | case let .empty(message), let .error(message): |
1603 | case let .empty(message), let .error(message): |
| 1599 | customPortResults = [] |
1604 | customPortScanState = .settled(value: [], error: message) |
| 1600 | customPortScanError = message |
| |
| 1601 | } |
1605 | } |
| 1602 | customPortScanLoading = false |
| |
| 1603 | } |
1606 | } |
| 1604 | |
1607 | |
| 1605 | private static func performBatchLookup(domain: String, previousSnapshot: LookupSnapshot?) async -> BatchLookupPayload? { |
1608 | private static func performBatchLookup(domain: String, previousSnapshot: LookupSnapshot?) async -> BatchLookupPayload? { |
| @@ -2111,7 +2114,6 @@ final class DomainViewModel { |
| 2111 | ownershipDiff = [] |
2114 | ownershipDiff = [] |
| 2112 | clearLookupState() |
2115 | clearLookupState() |
| 2113 | setAllLoadingStates(true) |
2116 | setAllLoadingStates(true) |
| 2114 | customPortScanLoading = false |
| |
| 2115 | return lookupID |
2117 | return lookupID |
| 2116 | } |
2118 | } |
| 2117 | |
2119 | |
| @@ -2382,93 +2384,62 @@ final class DomainViewModel { |
| 2382 | ) |
2384 | ) |
| 2383 | } |
2385 | } |
| 2384 | |
2386 | |
| |
2387 | /// Resets every section before a new lookup, so the previous domain's |
| |
2388 | /// results cannot be mistaken for this one's. One assignment per section |
| |
2389 | /// now; it used to be three. |
| 2385 | private func clearLookupState() { |
2390 | private func clearLookupState() { |
| 2386 | dnsSections = [] |
2391 | dnsState = .idle |
| 2387 | dnsError = nil |
2392 | availabilityState = .idle |
| 2388 | dnsLoading = false |
2393 | suggestionsState = .idle |
| 2389 | availabilityResult = nil |
2394 | sslState = .idle |
| 2390 | availabilityLoading = false |
2395 | hstsState = .idle |
| 2391 | suggestions = [] |
2396 | httpHeadersState = .idle |
| 2392 | suggestionsLoading = false |
| |
| 2393 | sslInfo = nil |
| |
| 2394 | sslError = nil |
| |
| 2395 | sslLoading = false |
| |
| 2396 | hstsPreloaded = nil |
| |
| 2397 | hstsLoading = false |
| |
| 2398 | httpHeaders = [] |
| |
| 2399 | httpSecurityGrade = nil |
2397 | httpSecurityGrade = nil |
| 2400 | httpStatusCode = nil |
2398 | httpStatusCode = nil |
| 2401 | httpResponseTimeMs = nil |
2399 | httpResponseTimeMs = nil |
| 2402 | httpProtocol = nil |
2400 | httpProtocol = nil |
| 2403 | http3Advertised = false |
2401 | http3Advertised = false |
| 2404 | httpHeadersError = nil |
2402 | reachabilityState = .idle |
| 2405 | httpHeadersLoading = false |
2403 | ipGeolocationState = .idle |
| 2406 | reachabilityResults = [] |
2404 | emailSecurityState = .idle |
| 2407 | reachabilityError = nil |
2405 | ownershipState = .idle |
| 2408 | reachabilityLoading = false |
2406 | ownershipHistoryState = .idle |
| 2409 | ipGeolocation = nil |
2407 | ptrState = .idle |
| 2410 | ipGeolocationError = nil |
2408 | redirectChainState = .idle |
| 2411 | ipGeolocationLoading = false |
2409 | subdomainsState = .idle |
| 2412 | emailSecurity = nil |
2410 | extendedSubdomainsState = .idle |
| 2413 | emailSecurityError = nil |
2411 | dnsHistoryState = .idle |
| 2414 | emailSecurityLoading = false |
2412 | domainPricingState = .idle |
| 2415 | ownershipResult = nil |
2413 | reputationState = .idle |
| 2416 | ownershipError = nil |
2414 | portScanState = .idle |
| 2417 | ownershipLoading = false |
2415 | customPortScanState = .idle |
| 2418 | ownershipHistory = [] |
2416 | } |
| 2419 | ownershipHistoryError = nil |
2417 | |
| 2420 | ownershipHistoryLoading = false |
2418 | /// Puts the sections a lookup drives into flight, and resets the |
| 2421 | ptrRecord = nil |
2419 | /// on-demand ones — ownership history, extended subdomains, DNS history |
| 2422 | ptrError = nil |
2420 | /// and pricing are fetched when the user opens them, not by the lookup, so |
| 2423 | ptrLoading = false |
2421 | /// they were never part of this either. |
| 2424 | redirectChain = [] |
| |
| 2425 | redirectChainError = nil |
| |
| 2426 | redirectChainLoading = false |
| |
| 2427 | subdomains = [] |
| |
| 2428 | subdomainsError = nil |
| |
| 2429 | subdomainsLoading = false |
| |
| 2430 | extendedSubdomains = [] |
| |
| 2431 | extendedSubdomainsError = nil |
| |
| 2432 | extendedSubdomainsLoading = false |
| |
| 2433 | dnsHistory = [] |
| |
| 2434 | dnsHistoryError = nil |
| |
| 2435 | dnsHistoryLoading = false |
| |
| 2436 | domainPricing = nil |
| |
| 2437 | domainPricingError = nil |
| |
| 2438 | domainPricingLoading = false |
| |
| 2439 | portScanResults = [] |
| |
| 2440 | portScanError = nil |
| |
| 2441 | portScanLoading = false |
| |
| 2442 | customPortResults = [] |
| |
| 2443 | customPortScanError = nil |
| |
| 2444 | customPortScanLoading = false |
| |
| 2445 | currentHistoryEntryID = nil |
| |
| 2446 | currentSnapshotTimestamp = Date() |
| |
| 2447 | currentResultSource = .live |
| |
| 2448 | currentCachedSections = [] |
| |
| 2449 | currentStatusMessage = nil |
| |
| 2450 | currentReport = nil |
| |
| 2451 | } |
| |
| 2452 | |
| |
| 2453 | private func setAllLoadingStates(_ loading: Bool) { |
2422 | private func setAllLoadingStates(_ loading: Bool) { |
| 2454 | dnsLoading = loading |
2423 | let phase: SectionPhase = loading ? .loading : .idle |
| 2455 | availabilityLoading = loading |
2424 | dnsState.phase = phase |
| 2456 | suggestionsLoading = loading |
2425 | availabilityState.phase = phase |
| 2457 | sslLoading = loading |
2426 | suggestionsState.phase = phase |
| 2458 | hstsLoading = loading |
2427 | sslState.phase = phase |
| 2459 | httpHeadersLoading = loading |
2428 | hstsState.phase = phase |
| 2460 | reachabilityLoading = loading |
2429 | httpHeadersState.phase = phase |
| 2461 | ipGeolocationLoading = loading |
2430 | reachabilityState.phase = phase |
| 2462 | emailSecurityLoading = loading |
2431 | ipGeolocationState.phase = phase |
| 2463 | ownershipLoading = loading |
2432 | emailSecurityState.phase = phase |
| 2464 | ownershipHistoryLoading = false |
2433 | ownershipState.phase = phase |
| 2465 | ptrLoading = loading |
2434 | ptrState.phase = phase |
| 2466 | redirectChainLoading = loading |
2435 | redirectChainState.phase = phase |
| 2467 | subdomainsLoading = loading |
2436 | subdomainsState.phase = phase |
| 2468 | extendedSubdomainsLoading = false |
2437 | portScanState.phase = phase |
| 2469 | dnsHistoryLoading = false |
2438 | |
| 2470 | domainPricingLoading = false |
2439 | ownershipHistoryState.phase = .idle |
| 2471 | portScanLoading = loading |
2440 | extendedSubdomainsState.phase = .idle |
| |
2441 | dnsHistoryState.phase = .idle |
| |
2442 | domainPricingState.phase = .idle |
| 2472 | } |
2443 | } |
| 2473 | |
2444 | |
| 2474 | private func primaryIPAddress(from sections: [DNSSection]) -> String? { |
2445 | private func primaryIPAddress(from sections: [DNSSection]) -> String? { |