mirror of
https://github.com/mollyim/mollyim-android.git
synced 2025-05-12 21:30:39 +01:00
Clean up code after upstream changes to UWS keepalive
This commit is contained in:
parent
9d0b1883ae
commit
94a2ecf429
7 changed files with 13 additions and 33 deletions
|
@ -95,7 +95,7 @@ class SignalWebSocketHealthMonitor(
|
|||
}
|
||||
}
|
||||
|
||||
override fun onKeepAliveResponse(sentTimestamp: Long, isIdentifiedWebSocket: Boolean, keepMonitoring: Boolean) {
|
||||
override fun onKeepAliveResponse(sentTimestamp: Long, isIdentifiedWebSocket: Boolean) {
|
||||
val keepAliveTime = System.currentTimeMillis().milliseconds
|
||||
executor.execute {
|
||||
lastKeepAliveReceived = keepAliveTime
|
||||
|
|
|
@ -4,7 +4,7 @@ package org.whispersystems.signalservice.api.websocket
|
|||
* Callbacks to provide WebSocket health information to a monitor.
|
||||
*/
|
||||
interface HealthMonitor {
|
||||
fun onKeepAliveResponse(sentTimestamp: Long, isIdentifiedWebSocket: Boolean, keepMonitoring: Boolean)
|
||||
fun onKeepAliveResponse(sentTimestamp: Long, isIdentifiedWebSocket: Boolean)
|
||||
|
||||
fun onMessageError(status: Int, isIdentifiedWebSocket: Boolean)
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ public class ProvisioningSocket {
|
|||
userAgent,
|
||||
new HealthMonitor() {
|
||||
@Override
|
||||
public void onKeepAliveResponse(long sentTimestamp, boolean isIdentifiedWebSocket, boolean keepMonitoring) {
|
||||
public void onKeepAliveResponse(long sentTimestamp, boolean isIdentifiedWebSocket) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -126,8 +126,6 @@ class LibSignalChatConnection(
|
|||
|
||||
override val name = "[$name:${System.identityHashCode(this)}]"
|
||||
|
||||
override var keepAlive = true
|
||||
|
||||
val state = BehaviorSubject.createDefault(WebSocketConnectionState.DISCONNECTED)
|
||||
|
||||
val stateMonitor = state
|
||||
|
@ -386,9 +384,8 @@ class LibSignalChatConnection(
|
|||
in 200..299 -> {
|
||||
healthMonitor.onKeepAliveResponse(
|
||||
sentTimestamp = Instant.now().toEpochMilli(), // ignored. can be any value
|
||||
isIdentifiedWebSocket = chatConnection is AuthenticatedChatConnection,
|
||||
keepMonitoring = keepAlive,
|
||||
)
|
||||
isIdentifiedWebSocket = chatConnection is AuthenticatedChatConnection
|
||||
)
|
||||
}
|
||||
|
||||
in 400..599 -> {
|
||||
|
|
|
@ -79,8 +79,6 @@ public class OkHttpWebSocketConnection extends WebSocketListener implements WebS
|
|||
|
||||
private WebSocket client;
|
||||
|
||||
private boolean keepAlive;
|
||||
|
||||
public OkHttpWebSocketConnection(String name,
|
||||
SignalServiceConfiguration serviceConfiguration,
|
||||
Optional<CredentialsProvider> credentialsProvider,
|
||||
|
@ -107,7 +105,6 @@ public class OkHttpWebSocketConnection extends WebSocketListener implements WebS
|
|||
this.socketFactory = serviceConfiguration.getSocketFactory();
|
||||
this.proxySelector = serviceConfiguration.getProxySelector();
|
||||
this.healthMonitor = healthMonitor;
|
||||
this.keepAlive = true;
|
||||
this.webSocketState = BehaviorSubject.createDefault(WebSocketConnectionState.DISCONNECTED);
|
||||
this.allowStories = allowStories;
|
||||
this.serviceUrls = serviceConfiguration.getSignalServiceUrls();
|
||||
|
@ -120,16 +117,6 @@ public class OkHttpWebSocketConnection extends WebSocketListener implements WebS
|
|||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getKeepAlive() {
|
||||
return keepAlive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setKeepAlive(boolean keepAlive) {
|
||||
this.keepAlive = keepAlive;
|
||||
}
|
||||
|
||||
private Pair<SignalServiceUrl, String> getConnectionInfo() {
|
||||
SignalServiceUrl serviceUrl = serviceUrls[random.nextInt(serviceUrls.length)];
|
||||
String uri = serviceUrl.getUrl().replace("https://", "wss://").replace("http://", "ws://");
|
||||
|
@ -283,7 +270,7 @@ public class OkHttpWebSocketConnection extends WebSocketListener implements WebS
|
|||
|
||||
@Override
|
||||
public synchronized void sendKeepAlive() throws IOException {
|
||||
if (client != null && keepAlive) {
|
||||
if (client != null) {
|
||||
log("Sending keep alive...");
|
||||
long id = System.currentTimeMillis();
|
||||
byte[] message = new WebSocketMessage.Builder()
|
||||
|
@ -328,7 +315,7 @@ public class OkHttpWebSocketConnection extends WebSocketListener implements WebS
|
|||
healthMonitor.onMessageError(message.response.status, credentialsProvider.isPresent());
|
||||
}
|
||||
} else if (keepAlives.remove(message.response.id)) {
|
||||
healthMonitor.onKeepAliveResponse(message.response.id, credentialsProvider.isPresent(), keepAlive);
|
||||
healthMonitor.onKeepAliveResponse(message.response.id, credentialsProvider.isPresent());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -350,9 +337,7 @@ public class OkHttpWebSocketConnection extends WebSocketListener implements WebS
|
|||
|
||||
@Override
|
||||
public synchronized void onFailure(WebSocket webSocket, Throwable t, Response response) {
|
||||
if (keepAlive || response != null) {
|
||||
warn("onFailure()", t);
|
||||
}
|
||||
warn("onFailure()", t);
|
||||
|
||||
if (response != null && (response.code() == 401 || response.code() == 403)) {
|
||||
webSocketState.onNext(WebSocketConnectionState.AUTHENTICATION_FAILED);
|
||||
|
|
|
@ -22,8 +22,6 @@ interface WebSocketConnection {
|
|||
|
||||
val name: String
|
||||
|
||||
var keepAlive: Boolean
|
||||
|
||||
fun connect(): Observable<WebSocketConnectionState>
|
||||
|
||||
fun isDead(): Boolean
|
||||
|
|
|
@ -53,7 +53,7 @@ class LibSignalChatConnectionTest {
|
|||
fun before() {
|
||||
clearAllMocks()
|
||||
every { healthMonitor.onMessageError(any(), any()) }
|
||||
every { healthMonitor.onKeepAliveResponse(any(), any(), any()) }
|
||||
every { healthMonitor.onKeepAliveResponse(any(), any()) }
|
||||
|
||||
// NB: We provide default success behavior mocks here to cut down on boilerplate later, but it is
|
||||
// expected that some tests will override some of these to test failures.
|
||||
|
@ -222,7 +222,7 @@ class LibSignalChatConnectionTest {
|
|||
sendLatch!!.await(100, TimeUnit.MILLISECONDS)
|
||||
|
||||
verify(exactly = 1) {
|
||||
healthMonitor.onKeepAliveResponse(any(), false, any())
|
||||
healthMonitor.onKeepAliveResponse(any(), false)
|
||||
}
|
||||
verify(exactly = 0) {
|
||||
healthMonitor.onMessageError(any(), any())
|
||||
|
@ -253,7 +253,7 @@ class LibSignalChatConnectionTest {
|
|||
healthMonitor.onMessageError(response.status, false)
|
||||
}
|
||||
verify(exactly = 0) {
|
||||
healthMonitor.onKeepAliveResponse(any(), any(), any())
|
||||
healthMonitor.onKeepAliveResponse(any(), any())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ class LibSignalChatConnectionTest {
|
|||
)
|
||||
observer.assertNoConsecutiveDuplicates()
|
||||
verify(exactly = 0) {
|
||||
healthMonitor.onKeepAliveResponse(any(), any(), any())
|
||||
healthMonitor.onKeepAliveResponse(any(), any())
|
||||
healthMonitor.onMessageError(any(), any())
|
||||
}
|
||||
}
|
||||
|
@ -317,7 +317,7 @@ class LibSignalChatConnectionTest {
|
|||
)
|
||||
observer.assertNoConsecutiveDuplicates()
|
||||
verify(exactly = 0) {
|
||||
healthMonitor.onKeepAliveResponse(any(), any(), any())
|
||||
healthMonitor.onKeepAliveResponse(any(), any())
|
||||
healthMonitor.onMessageError(any(), any())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue