connectionStates
The per-connection latest lifecycle state: each connection's NwConnectionId mapped to its current NwConnState — NwConnState.Viable (path up), NwConnState.PathLost (path unsatisfied), or NwConnState.Closed (terminally torn, carrying the raw close reason). This ONE drop-tolerant STATE signal unifies the two former parallel maps — connectionViability (#1509) and closedConnections (#1522) — into a single total sum type (#1539). A connection absent from the map has never established.
It is state, not an event stream, and it drives two NwSeam reconciliations at once:
Path loss / recovery (#1478). Network.framework moves a connection that loses its route from
readytowaiting(NOTfailed), so no NwConnectionClosed ever fires — the peer is silently unreachable. The seam arms a bounded grace timer while a connection is NwConnState.PathLost and cancels it on recovery to NwConnState.Viable; if the path never recovers the peer is torn.Terminal teardown (#1522). NwConnState.Closed is the drop-tolerant backstop for the lossy connectionClosed event: a
failed/cancelledclose dropped under buffer pressure would otherwise strand a zombie peer. The seam tears any still-tracked connection whose state is NwConnState.Closed, IMMEDIATELY and with no grace timer.
Modelling it as a StateFlow of the latest value per connection (rather than a lossy tryEmit event flow) makes it drop-tolerant: intermediate transitions may coalesce under backpressure, but the LATEST value per connection is never lost. NwConnState.Closed is furthermore terminal, monotone and dominant — producers latch it so a late NwConnState.Viable/NwConnState.PathLost for a closed id can never overwrite it (so a closure can never be conflated away the way a boolean live-set's presence-then-absence would be under the same starvation that drops the event).
Absence means NOTHING. A connection absent from this map may be live, dialling, or never-having-existed — never infer a closure from a key being absent. The ONLY positive signal is a key's presence with a NwConnState.Closed value.
Defaults to a never-updated empty map so a binding that has not yet wired the underlying transitions inherits "every connection's state is unknown" rather than being forced to implement it before the ABI lands. RealNwApi (appleMain), BridgeNwApi (JVM), and the test fakes override it.