Remove libsignal shadow/bridge websocket infra.

This commit is contained in:
Cody Henthorne
2025-03-05 15:49:23 -05:00
committed by Michelle Tang
parent 83611414cc
commit da5c8ff6ea
5 changed files with 13 additions and 374 deletions

View File

@@ -47,7 +47,6 @@ import org.thoughtcrime.securesms.jobs.TypingSendJob;
import org.thoughtcrime.securesms.keyvalue.SignalStore;
import org.thoughtcrime.securesms.megaphone.MegaphoneRepository;
import org.thoughtcrime.securesms.messages.IncomingMessageObserver;
import org.thoughtcrime.securesms.net.DefaultWebSocketShadowingBridge;
import org.thoughtcrime.securesms.net.SignalWebSocketHealthMonitor;
import org.thoughtcrime.securesms.net.StandardUserAgentInterceptor;
import org.thoughtcrime.securesms.notifications.MessageNotifier;
@@ -105,9 +104,7 @@ import org.whispersystems.signalservice.internal.push.PushServiceSocket;
import org.whispersystems.signalservice.internal.websocket.LibSignalChatConnection;
import org.whispersystems.signalservice.internal.websocket.LibSignalNetworkExtensions;
import org.whispersystems.signalservice.internal.websocket.OkHttpWebSocketConnection;
import org.whispersystems.signalservice.internal.websocket.ShadowingWebSocketConnection;
import org.whispersystems.signalservice.internal.websocket.WebSocketConnection;
import org.whispersystems.signalservice.internal.websocket.WebSocketShadowingBridge;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
@@ -302,8 +299,7 @@ public class ApplicationDependencyProvider implements AppDependencies.Provider {
public @NonNull SignalWebSocket.AuthenticatedWebSocket provideAuthWebSocket(@NonNull Supplier<SignalServiceConfiguration> signalServiceConfigurationSupplier, @NonNull Supplier<Network> libSignalNetworkSupplier) {
SleepTimer sleepTimer = !SignalStore.account().isFcmEnabled() || SignalStore.internal().isWebsocketModeForced() ? new AlarmSleepTimer(context) : new UptimeSleepTimer();
SignalWebSocketHealthMonitor healthMonitor = new SignalWebSocketHealthMonitor(sleepTimer);
WebSocketShadowingBridge bridge = new DefaultWebSocketShadowingBridge(context);
WebSocketFactory webSocketFactory = provideWebSocketFactory(signalServiceConfigurationSupplier, healthMonitor, libSignalNetworkSupplier, bridge);
WebSocketFactory webSocketFactory = provideWebSocketFactory(signalServiceConfigurationSupplier, healthMonitor, libSignalNetworkSupplier);
SignalWebSocket.AuthenticatedWebSocket webSocket = new SignalWebSocket.AuthenticatedWebSocket(webSocketFactory::createWebSocket);
healthMonitor.monitor(webSocket);
@@ -315,8 +311,7 @@ public class ApplicationDependencyProvider implements AppDependencies.Provider {
public @NonNull SignalWebSocket.UnauthenticatedWebSocket provideUnauthWebSocket(@NonNull Supplier<SignalServiceConfiguration> signalServiceConfigurationSupplier, @NonNull Supplier<Network> libSignalNetworkSupplier) {
SleepTimer sleepTimer = !SignalStore.account().isFcmEnabled() || SignalStore.internal().isWebsocketModeForced() ? new AlarmSleepTimer(context) : new UptimeSleepTimer();
SignalWebSocketHealthMonitor healthMonitor = new SignalWebSocketHealthMonitor(sleepTimer);
WebSocketShadowingBridge bridge = new DefaultWebSocketShadowingBridge(context);
WebSocketFactory webSocketFactory = provideWebSocketFactory(signalServiceConfigurationSupplier, healthMonitor, libSignalNetworkSupplier, bridge);
WebSocketFactory webSocketFactory = provideWebSocketFactory(signalServiceConfigurationSupplier, healthMonitor, libSignalNetworkSupplier);
SignalWebSocket.UnauthenticatedWebSocket webSocket = new SignalWebSocket.UnauthenticatedWebSocket(webSocketFactory::createUnidentifiedWebSocket);
healthMonitor.monitor(webSocket);
@@ -419,21 +414,18 @@ public class ApplicationDependencyProvider implements AppDependencies.Provider {
@NonNull WebSocketFactory provideWebSocketFactory(@NonNull Supplier<SignalServiceConfiguration> signalServiceConfigurationSupplier,
@NonNull HealthMonitor healthMonitor,
@NonNull Supplier<Network> libSignalNetworkSupplier,
@NonNull WebSocketShadowingBridge bridge)
@NonNull Supplier<Network> libSignalNetworkSupplier)
{
return new WebSocketFactory() {
@Override
public WebSocketConnection createWebSocket() {
if (RemoteConfig.libSignalWebSocketEnabled()) {
Network network = libSignalNetworkSupplier.get();
return new LibSignalChatConnection(
"libsignal-auth",
network,
new DynamicCredentialsProvider(),
Stories.isFeatureEnabled(),
healthMonitor
);
return new LibSignalChatConnection("libsignal-auth",
network,
new DynamicCredentialsProvider(),
Stories.isFeatureEnabled(),
healthMonitor);
} else {
return new OkHttpWebSocketConnection("normal",
signalServiceConfigurationSupplier.get(),
@@ -446,28 +438,13 @@ public class ApplicationDependencyProvider implements AppDependencies.Provider {
@Override
public WebSocketConnection createUnidentifiedWebSocket() {
int shadowPercentage = RemoteConfig.libSignalWebSocketShadowingPercentage();
if (shadowPercentage > 0) {
return new ShadowingWebSocketConnection(
"unauth-shadow",
signalServiceConfigurationSupplier.get(),
Optional.empty(),
BuildConfig.SIGNAL_AGENT,
healthMonitor,
Stories.isFeatureEnabled(),
libSignalNetworkSupplier.get(),
shadowPercentage,
bridge
);
}
if (RemoteConfig.libSignalWebSocketEnabled()) {
Network network = libSignalNetworkSupplier.get();
return new LibSignalChatConnection(
"libsignal-unauth",
network,
null,
Stories.isFeatureEnabled(),
healthMonitor);
return new LibSignalChatConnection("libsignal-unauth",
network,
null,
Stories.isFeatureEnabled(),
healthMonitor);
} else {
return new OkHttpWebSocketConnection("unidentified",
signalServiceConfigurationSupplier.get(),

View File

@@ -1,59 +0,0 @@
/*
* Copyright 2024 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.thoughtcrime.securesms.net
import android.app.Application
import android.app.Notification
import android.app.PendingIntent
import android.content.Intent
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import org.signal.core.util.PendingIntentFlags
import org.thoughtcrime.securesms.R
import org.thoughtcrime.securesms.keyvalue.InternalValues
import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.logsubmit.SubmitDebugLogActivity
import org.thoughtcrime.securesms.notifications.NotificationChannels
import org.thoughtcrime.securesms.notifications.NotificationIds
import org.thoughtcrime.securesms.util.RemoteConfig
import org.whispersystems.signalservice.internal.websocket.WebSocketShadowingBridge
/**
* Implements a [WebSocketShadowingBridge] to provide shadowing-specific functionality to
* [org.whispersystems.signalservice.internal.websocket.ShadowingWebSocketConnection]
*/
class DefaultWebSocketShadowingBridge(private val context: Application) : WebSocketShadowingBridge {
private val store: InternalValues = SignalStore.internal
override fun writeStatsSnapshot(bytes: ByteArray) {
store.webSocketShadowingStats = bytes
}
override fun readStatsSnapshot(): ByteArray? {
return store.webSocketShadowingStats
}
override fun triggerFailureNotification(message: String) {
if (!RemoteConfig.internalUser) {
return
}
val notification: Notification = NotificationCompat.Builder(context, NotificationChannels.getInstance().FAILURES)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle("[Internal-only] $message")
.setContentText("Tap to send a debug log")
.setContentIntent(
PendingIntent.getActivity(
context,
0,
Intent(context, SubmitDebugLogActivity::class.java),
PendingIntentFlags.mutable()
)
)
.build()
NotificationManagerCompat.from(context).notify(NotificationIds.INTERNAL_ERROR, notification)
}
}

View File

@@ -1036,20 +1036,6 @@ object RemoteConfig {
BuildConfig.MESSAGE_BACKUP_RESTORE_ENABLED || value.asBoolean(false)
}
/**
* Percentage [0, 100] of web socket requests that will be "shadowed" by sending
* an unauthenticated keep-alive via libsignal-net. Default: 0
*/
@JvmStatic
@get:JvmName("libSignalWebSocketShadowingPercentage")
val libSignalWebSocketShadowingPercentage: Int by remoteValue(
key = "android.libsignalWebSocketShadowingPercentage",
hotSwappable = false
) { value ->
val remote = value.asInteger(0)
remote.coerceIn(0, 100)
}
@JvmStatic
val backgroundMessageProcessInterval: Long by remoteValue(
key = "android.messageProcessor.alarmIntervalMins",