`srand` is not accessible in swift. Remove `srand` anyhow as anything
using `rand` for any actual randomness should be considered a bug in
need of fixing rather than viewing `srand` as an acceptable workaround.
Includes code changes for libsignal splitting ChatService into
AuthenticatedChatService and UnauthenticatedChatService, which is more
in line with how iOS does things anyway. Also now supports receiving
stories on the auth connection using libsignal.
This is a *subclass* of OWSChatConnectionUsingLibSignal, mainly
because the authenticated/identified connection really does have
capabilities the unauth/unidentified one does not, and splitting those
out makes it easier to see which are which.
For now each websocket connection, identified and unidentified, has
its own libsignal ChatService instance, even though ChatService is
designed to manage both connections together. Later on in the
migration it'll make sense to consolidate them, but under the existing
structure of OWSChatConnection this is the easiest way to manage their
lifecycles.
Controlled by new RemoteConfig flag
"ios.experimentalTransportEnabled.libsignalAuth" (and for local
testing, UserDefaults flag UseLibsignalForIdentifiedWebsocket).
Since this already affects more than just the chat connection, having
it in OWSChatConnection isn't really the best choice. This way we can
be sure the libsignal Net instance's proxy settings will be updated
before any notifications go out.
The choice of whether or not to use this is controlled by a
RemoteConfig flag, ios.experimentalTransportEnabled.libsignal, but
because ChatConnectionManager is set up before RemoteConfig has even
loaded its cached settings, the flag is cached in UserDefaults, like
the shadowing kill switch setting.
Most requests on good networks happen well under 2sec, but there have
been a few timeouts that seem spurious (distinct from a series of
timeouts all happening in a row on the libsignal websocket).