|
| 1 | +import Foundation |
| 2 | + |
| 3 | +// This file declares the frozen, presentation-neutral value for one selected |
| 4 | +// session's retained connection and TLS evidence. Like the tables it reads, it is |
| 5 | +// observation-only: it carries the exact retained ``ConnectionSummary`` and |
| 6 | +// ``TLSEvidenceSummary`` values a fold already produced, plus the relevant |
| 7 | +// capture-level coverage counters — never a rendered label, severity, policy, raw |
| 8 | +// bytes, URL, path, SNI or certificate. It adds no analysis; it is a filtered, |
| 9 | +// deterministic projection of one immutable ``InvestigationSnapshot``. |
| 10 | + |
| 11 | +// MARK: - ConnectionSelectionCoverage |
| 12 | + |
| 13 | +/// The capture-level connection-table coverage a selected session's presentation |
| 14 | +/// needs, carried verbatim from ``ConnectionTable/Snapshot``. These are *global* |
| 15 | +/// facts: `omittedSummaryCount` and the counts describe the whole capture, never |
| 16 | +/// this one session, so a caller must label them as capture-level and never claim |
| 17 | +/// they prove this selected session was omitted. |
| 18 | +nonisolated struct ConnectionSelectionCoverage: Hashable, Sendable { |
| 19 | + static let empty = ConnectionSelectionCoverage( |
| 20 | + omittedSummaryCount: 0, |
| 21 | + activeConnectionCount: 0, |
| 22 | + publishedSummaryCount: 0, |
| 23 | + retainedEventCount: 0, |
| 24 | + countersOverflowed: false |
| 25 | + ) |
| 26 | + |
| 27 | + let omittedSummaryCount: UInt64 |
| 28 | + let activeConnectionCount: Int |
| 29 | + let publishedSummaryCount: Int |
| 30 | + let retainedEventCount: Int |
| 31 | + let countersOverflowed: Bool |
| 32 | +} |
| 33 | + |
| 34 | +// MARK: - TLSSelectionCoverage |
| 35 | + |
| 36 | +/// The capture-level TLS-evidence coverage a selected session's presentation needs, |
| 37 | +/// carried verbatim from ``TLSEvidenceTable/Snapshot``. As with the connection |
| 38 | +/// coverage these are global capture facts; absence of a retained summary for this |
| 39 | +/// session is unknown coverage, never evidence of absence. |
| 40 | +nonisolated struct TLSSelectionCoverage: Hashable, Sendable { |
| 41 | + static let empty = TLSSelectionCoverage( |
| 42 | + omittedObservationCount: 0, |
| 43 | + retainedObservationCount: 0, |
| 44 | + excludedReassembledRecordCount: 0, |
| 45 | + recoveredTruncationIndicatorCount: 0, |
| 46 | + decoderTruncatedFrameCount: 0, |
| 47 | + capacityReached: false, |
| 48 | + countersOverflowed: false |
| 49 | + ) |
| 50 | + |
| 51 | + let omittedObservationCount: UInt64 |
| 52 | + let retainedObservationCount: Int |
| 53 | + let excludedReassembledRecordCount: UInt64 |
| 54 | + let recoveredTruncationIndicatorCount: UInt64 |
| 55 | + let decoderTruncatedFrameCount: UInt64 |
| 56 | + let capacityReached: Bool |
| 57 | + let countersOverflowed: Bool |
| 58 | +} |
| 59 | + |
| 60 | +// MARK: - SessionEvidenceSelection |
| 61 | + |
| 62 | +/// The immutable, presentation-neutral view of one selected session's retained |
| 63 | +/// connection and TLS evidence. |
| 64 | +/// |
| 65 | +/// A session is tuple-derived, so one session can hold multiple sequential TCP |
| 66 | +/// connection incarnations when its tuple is reused. `connections` lists *every* |
| 67 | +/// retained incarnation whose tuple-derived session id matches, in the snapshot's |
| 68 | +/// existing deterministic (first-observed) order — this value never chooses one as |
| 69 | +/// "the connection." `tls` is the zero-or-one retained tuple/session-scoped TLS |
| 70 | +/// summary; because current evidence cannot prove which incarnation a tuple-scoped |
| 71 | +/// TLS record belongs to, it is shared at session scope and never paired to a |
| 72 | +/// specific connection. |
| 73 | +/// |
| 74 | +/// Every per-summary omission, exclusion, truncation, loss, limitation and overflow |
| 75 | +/// fact needed by a presentation layer already lives inside the retained |
| 76 | +/// ``ConnectionSummary``/``TLSEvidenceSummary`` values carried here; the two |
| 77 | +/// coverage members add only the capture-level (global) counters. |
| 78 | +nonisolated struct SessionEvidenceSelection: Hashable, Sendable { |
| 79 | + /// The tuple-derived session id this selection was projected for. |
| 80 | + let sessionID: UUID |
| 81 | + /// Every retained connection incarnation for this session in first-observed |
| 82 | + /// order. Bounded by the connection table's published-summary bound. |
| 83 | + let connections: [ConnectionSummary] |
| 84 | + /// The zero-or-one retained tuple/session-scoped TLS summary. Never paired to a |
| 85 | + /// connection incarnation. |
| 86 | + let tls: TLSEvidenceSummary? |
| 87 | + /// Capture-level connection coverage, carried verbatim. |
| 88 | + let connectionCoverage: ConnectionSelectionCoverage |
| 89 | + /// Capture-level TLS coverage, carried verbatim. |
| 90 | + let tlsCoverage: TLSSelectionCoverage |
| 91 | + |
| 92 | + /// Whether nothing was retained for this session. Capture-level coverage is |
| 93 | + /// still carried so a caller can present it as global unknown coverage. |
| 94 | + var isEmpty: Bool { |
| 95 | + connections.isEmpty && tls == nil |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +// MARK: - InvestigationSnapshot selection |
| 100 | + |
| 101 | +extension InvestigationSnapshot { |
| 102 | + /// Project the retained connection/TLS evidence for one tuple-derived session id. |
| 103 | + /// |
| 104 | + /// Pure and off-main-ready: it filters the wrapped fold's already-produced |
| 105 | + /// connection and TLS summaries — no decode, no re-assessment, no copy of the |
| 106 | + /// snapshot arrays beyond the bounded matches. The connection incarnations keep |
| 107 | + /// the snapshot's deterministic order, and the single tuple-scoped TLS summary is |
| 108 | + /// matched by session id, never re-attributed to an incarnation. |
| 109 | + nonisolated func selectingSession(_ sessionID: UUID) -> SessionEvidenceSelection { |
| 110 | + let connectionSnapshot = connections |
| 111 | + let matchedConnections = connectionSnapshot.summaries.filter { |
| 112 | + SessionBuilder.sessionID(for: $0.tuple) == sessionID |
| 113 | + } |
| 114 | + let tlsSnapshot = tlsEvidence |
| 115 | + let matchedTLS = tlsSnapshot.summaries.first { $0.sessionID == sessionID } |
| 116 | + |
| 117 | + return SessionEvidenceSelection( |
| 118 | + sessionID: sessionID, |
| 119 | + connections: matchedConnections, |
| 120 | + tls: matchedTLS, |
| 121 | + connectionCoverage: ConnectionSelectionCoverage( |
| 122 | + omittedSummaryCount: connectionSnapshot.omittedSummaryCount, |
| 123 | + activeConnectionCount: connectionSnapshot.activeConnectionCount, |
| 124 | + publishedSummaryCount: connectionSnapshot.publishedSummaryCount, |
| 125 | + retainedEventCount: connectionSnapshot.retainedEventCount, |
| 126 | + countersOverflowed: connectionSnapshot.countersOverflowed |
| 127 | + ), |
| 128 | + tlsCoverage: TLSSelectionCoverage( |
| 129 | + omittedObservationCount: tlsSnapshot.omittedObservationCount, |
| 130 | + retainedObservationCount: tlsSnapshot.retainedObservationCount, |
| 131 | + excludedReassembledRecordCount: tlsSnapshot.excludedReassembledRecordCount, |
| 132 | + recoveredTruncationIndicatorCount: tlsSnapshot.recoveredTruncationIndicatorCount, |
| 133 | + decoderTruncatedFrameCount: tlsSnapshot.decoderTruncatedFrameCount, |
| 134 | + capacityReached: tlsSnapshot.capacityReached, |
| 135 | + countersOverflowed: tlsSnapshot.countersOverflowed |
| 136 | + ) |
| 137 | + ) |
| 138 | + } |
| 139 | +} |
0 commit comments