Skip to content

Commit 0cd79e1

Browse files
authored
Hardcode UniqueID in streams keys (#308)
Now that Foundation is ubiquitous, we can use UniqueID/UUID directly. Fixes a weird runtime crash in a missing Hashable witness table (OID → RandomlyInitialized → Hashable).
1 parent cb0f34d commit 0cd79e1

File tree

18 files changed

+36
-36
lines changed

18 files changed

+36
-36
lines changed

Sources/MiniFoundation/Streams/CurrentValueStream.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
import Dispatch
66

77
/// Replacement for `CurrentValueSubject`.
8-
public final class CurrentValueStream<OID, T>: @unchecked Sendable where OID: RandomlyInitialized, T: Sendable {
8+
public final class CurrentValueStream<T>: @unchecked Sendable where T: Sendable {
99
let queue = DispatchQueue(label: "CurrentValueStream")
1010

11-
var observers: [OID: AsyncStream<T>.Continuation] = [:]
11+
var observers: [UniqueID: AsyncStream<T>.Continuation] = [:]
1212

13-
var throwingObservers: [OID: AsyncThrowingStream<T, Error>.Continuation] = [:]
13+
var throwingObservers: [UniqueID: AsyncThrowingStream<T, Error>.Continuation] = [:]
1414

1515
var isFinished = false
1616

@@ -30,7 +30,7 @@ public final class CurrentValueStream<OID, T>: @unchecked Sendable where OID: Ra
3030
}
3131

3232
public func subscribe() -> AsyncStream<T> {
33-
let id = OID() // best-effort, assume nonexistent observer id
33+
let id = UniqueID() // Best-effort, assume nonexistent observer id
3434
return AsyncStream { [weak self] continuation in
3535
guard let self else {
3636
return
@@ -48,7 +48,7 @@ public final class CurrentValueStream<OID, T>: @unchecked Sendable where OID: Ra
4848
}
4949

5050
public func subscribeThrowing() -> AsyncThrowingStream<T, Error> {
51-
let id = OID() // Best-effort, assume nonexistent observer id
51+
let id = UniqueID() // Best-effort, assume nonexistent observer id
5252
return AsyncThrowingStream { [weak self] continuation in
5353
guard let self else {
5454
return

Sources/MiniFoundation/Streams/PassthroughStream.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
import Dispatch
66

77
/// Replacement for `PassthroughSubject`.
8-
public final class PassthroughStream<OID, T>: @unchecked Sendable where OID: RandomlyInitialized, T: Sendable {
8+
public final class PassthroughStream<T>: @unchecked Sendable where T: Sendable {
99
let queue = DispatchQueue(label: "PassthroughStream")
1010

11-
var observers: [OID: AsyncStream<T>.Continuation] = [:]
11+
var observers: [UniqueID: AsyncStream<T>.Continuation] = [:]
1212

13-
var throwingObservers: [OID: AsyncThrowingStream<T, Error>.Continuation] = [:]
13+
var throwingObservers: [UniqueID: AsyncThrowingStream<T, Error>.Continuation] = [:]
1414

1515
var isFinished = false
1616

@@ -27,7 +27,7 @@ public final class PassthroughStream<OID, T>: @unchecked Sendable where OID: Ran
2727
}
2828

2929
public func subscribe() -> AsyncStream<T> {
30-
let id = OID() // Best-effort, assume nonexistent observer id
30+
let id = UniqueID() // Best-effort, assume nonexistent observer id
3131
return AsyncStream { [weak self] continuation in
3232
guard let self else {
3333
return
@@ -44,7 +44,7 @@ public final class PassthroughStream<OID, T>: @unchecked Sendable where OID: Ran
4444
}
4545

4646
public func subscribeThrowing() -> AsyncThrowingStream<T, Error> {
47-
let id = OID() // Best-effort, assume nonexistent observer id
47+
let id = UniqueID() // Best-effort, assume nonexistent observer id
4848
return AsyncThrowingStream { [weak self] continuation in
4949
guard let self else {
5050
return

Sources/PartoutCore/Connection/AutoUpgradingLink.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public final class AutoUpgradingLink: LinkInterface {
1414

1515
private let io: SocketIOInterface
1616

17-
private let betterPathStream: PassthroughStream<UniqueID, Void>
17+
private let betterPathStream: PassthroughStream<Void>
1818

1919
public init(
2020
endpoint: ExtendedEndpoint,

Sources/PartoutCore/Connection/BetterPathBlock.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
// SPDX-License-Identifier: GPL-3.0
44

55
/// Returns a stream to observe events about better network paths.
6-
public typealias BetterPathBlock = @Sendable () throws -> PassthroughStream<UniqueID, Void>
6+
public typealias BetterPathBlock = @Sendable () throws -> PassthroughStream<Void>

Sources/PartoutCore/Connection/CyclingConnection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public actor CyclingConnection {
6666

6767
private let endpoints: [ExtendedEndpoint]
6868

69-
private nonisolated let statusSubject: CurrentValueStream<UniqueID, ConnectionStatus>
69+
private nonisolated let statusSubject: CurrentValueStream<ConnectionStatus>
7070

7171
private var hooks: Hooks
7272

Sources/PartoutCore/Connection/NetworkObserver.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ public final class NetworkObserver: @unchecked Sendable {
88

99
private let state: AtomicState
1010

11-
private let signalSubject: CurrentValueStream<UniqueID, Bool>
11+
private let signalSubject: CurrentValueStream<Bool>
1212

1313
private let isStatusReady: (ConnectionStatus) -> Bool
1414

1515
/// Publishes when the network state is ready for reconnection.
16-
public let onReady: PassthroughStream<UniqueID, Void>
16+
public let onReady: PassthroughStream<Void>
1717

1818
private var subscriptions: [Task<Void, Never>]
1919

Sources/PartoutCore/Tunnel/FakeTunnelStrategy.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
/// Implementation of ``TunnelObservableStrategy`` to fake VPN operation on simulators.
66
public actor FakeTunnelStrategy: TunnelObservableStrategy, Sendable {
7-
private nonisolated let activeProfileSubject: CurrentValueStream<UniqueID, TunnelActiveProfile?>
7+
private nonisolated let activeProfileSubject: CurrentValueStream<TunnelActiveProfile?>
88

99
private var status: TunnelStatus {
1010
get {

Sources/PartoutCore/Tunnel/Tunnel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public final class Tunnel {
1616

1717
private let strategy: TunnelObservableStrategy
1818

19-
private let activeProfilesSubject: CurrentValueStream<UniqueID, [Profile.ID: TunnelActiveProfile]>
19+
private let activeProfilesSubject: CurrentValueStream<[Profile.ID: TunnelActiveProfile]>
2020

2121
private let environmentFactory: (Profile.ID) -> TunnelEnvironmentReader
2222

Sources/PartoutOS/AppleNE/App/NETunnelStrategy.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public actor NETunnelStrategy {
1818

1919
private let options: Set<Option>
2020

21-
private nonisolated let managersSubject: CurrentValueStream<UniqueID, [Profile.ID: NETunnelProviderManager]>
21+
private nonisolated let managersSubject: CurrentValueStream<[Profile.ID: NETunnelProviderManager]>
2222

2323
private var allManagers: [Profile.ID: NETunnelProviderManager] {
2424
didSet {

Sources/PartoutOS/AppleNE/AppExtension/NEObservablePath.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public final class NEObservablePath: ReachabilityObserver {
1010

1111
private let monitor: NWPathMonitor
1212

13-
private nonisolated let subject: CurrentValueStream<UniqueID, NWPath>
13+
private nonisolated let subject: CurrentValueStream<NWPath>
1414

1515
public init(_ ctx: PartoutLoggerContext) {
1616
self.ctx = ctx

0 commit comments

Comments
 (0)