mirror of
https://github.com/AsamK/signal-cli.git
synced 2026-11-29 08:55:48 +00:00
1 parent
29dc873535
commit
e65fee0efb
8 files changed
+101
-24
No files matched your search
@@ -116,7 +116,8 @@ public class RecipientHelper {
|
||||
}
|
||||
if (forceRefresh) {
|
||||
try {
|
||||
final var aci = handleResponseException(dependencies.getUsernameApi().getAciByUsername(finalUsername));
|
||||
final var aci = (ACI) handleResponseException(dependencies.getUsernameApi()
|
||||
.getAciByUsername(finalUsername));
|
||||
return account.getRecipientStore().resolveRecipientTrusted(aci, finalUsername.getUsername());
|
||||
} catch (NonSuccessfulResponseCodeException e) {
|
||||
if (e.code == 404) {
|
||||
@@ -131,7 +132,7 @@ public class RecipientHelper {
|
||||
}
|
||||
return account.getRecipientStore().resolveRecipientByUsername(finalUsername.getUsername(), () -> {
|
||||
try {
|
||||
return handleResponseException(dependencies.getUsernameApi().getAciByUsername(finalUsername));
|
||||
return (ACI) handleResponseException(dependencies.getUsernameApi().getAciByUsername(finalUsername));
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ import org.whispersystems.signalservice.api.util.CredentialsProvider;
|
||||
import org.whispersystems.signalservice.api.util.UptimeSleepTimer;
|
||||
import org.whispersystems.signalservice.api.websocket.SignalWebSocket;
|
||||
import org.whispersystems.signalservice.internal.push.PushServiceSocket;
|
||||
import org.whispersystems.signalservice.internal.websocket.OkHttpWebSocketConnection;
|
||||
import org.whispersystems.signalservice.internal.websocket.LibSignalChatConnection;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -284,13 +284,12 @@ public class SignalDependencies {
|
||||
final var timer = new UptimeSleepTimer();
|
||||
final var healthMonitor = new SignalWebSocketHealthMonitor(timer);
|
||||
|
||||
authenticatedSignalWebSocket = new SignalWebSocket.AuthenticatedWebSocket(() -> new OkHttpWebSocketConnection(
|
||||
authenticatedSignalWebSocket = new SignalWebSocket.AuthenticatedWebSocket(() -> new LibSignalChatConnection(
|
||||
"normal",
|
||||
serviceEnvironmentConfig.signalServiceConfiguration(),
|
||||
Optional.of(credentialsProvider),
|
||||
userAgent,
|
||||
healthMonitor,
|
||||
allowStories), () -> true, timer, TimeUnit.SECONDS.toMillis(10));
|
||||
getLibSignalNetwork(),
|
||||
credentialsProvider,
|
||||
allowStories,
|
||||
healthMonitor), () -> true, timer, TimeUnit.SECONDS.toMillis(10));
|
||||
healthMonitor.monitor(authenticatedSignalWebSocket);
|
||||
});
|
||||
}
|
||||
@@ -300,13 +299,12 @@ public class SignalDependencies {
|
||||
final var timer = new UptimeSleepTimer();
|
||||
final var healthMonitor = new SignalWebSocketHealthMonitor(timer);
|
||||
|
||||
unauthenticatedSignalWebSocket = new SignalWebSocket.UnauthenticatedWebSocket(() -> new OkHttpWebSocketConnection(
|
||||
unauthenticatedSignalWebSocket = new SignalWebSocket.UnauthenticatedWebSocket(() -> new LibSignalChatConnection(
|
||||
"unidentified",
|
||||
serviceEnvironmentConfig.signalServiceConfiguration(),
|
||||
Optional.empty(),
|
||||
userAgent,
|
||||
healthMonitor,
|
||||
allowStories), () -> true, timer, TimeUnit.SECONDS.toMillis(10));
|
||||
getLibSignalNetwork(),
|
||||
null,
|
||||
allowStories,
|
||||
healthMonitor), () -> true, timer, TimeUnit.SECONDS.toMillis(10));
|
||||
healthMonitor.monitor(unauthenticatedSignalWebSocket);
|
||||
});
|
||||
}
|
||||
@@ -328,8 +326,7 @@ public class SignalDependencies {
|
||||
executor,
|
||||
ServiceConfig.MAX_ENVELOPE_SIZE,
|
||||
() -> true,
|
||||
UsePqRatchet.NO,
|
||||
Optional.empty()));
|
||||
UsePqRatchet.NO));
|
||||
}
|
||||
|
||||
public List<SecureValueRecovery> getSecureValueRecovery() {
|
||||
|
||||
+1
-2
@@ -7,7 +7,6 @@ import org.whispersystems.signalservice.api.util.SleepTimer;
|
||||
import org.whispersystems.signalservice.api.websocket.HealthMonitor;
|
||||
import org.whispersystems.signalservice.api.websocket.SignalWebSocket;
|
||||
import org.whispersystems.signalservice.api.websocket.WebSocketConnectionState;
|
||||
import org.whispersystems.signalservice.internal.websocket.OkHttpWebSocketConnection;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
@@ -23,7 +22,7 @@ final class SignalWebSocketHealthMonitor implements HealthMonitor {
|
||||
/**
|
||||
* This is the amount of time in between sent keep alives. Must be greater than [KEEP_ALIVE_TIMEOUT]
|
||||
*/
|
||||
private static final long KEEP_ALIVE_SEND_CADENCE = TimeUnit.SECONDS.toMillis(OkHttpWebSocketConnection.KEEPALIVE_FREQUENCY_SECONDS);
|
||||
private static final long KEEP_ALIVE_SEND_CADENCE = TimeUnit.SECONDS.toMillis(30);
|
||||
|
||||
/**
|
||||
* This is the amount of time we will wait for a response to the keep alive before we consider the websockets dead.
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.asamk.signal.manager.util;
|
||||
|
||||
import org.asamk.signal.manager.api.Pair;
|
||||
import org.signal.libsignal.net.BadRequestError;
|
||||
import org.signal.libsignal.net.RequestResult;
|
||||
import org.signal.libsignal.protocol.IdentityKey;
|
||||
import org.signal.libsignal.protocol.fingerprint.Fingerprint;
|
||||
import org.signal.libsignal.protocol.fingerprint.NumericFingerprintGenerator;
|
||||
@@ -158,6 +160,24 @@ public class Utils {
|
||||
return NetworkResultUtil.toBasicLegacy(response);
|
||||
}
|
||||
|
||||
public static <T, E extends BadRequestError> T handleResponseException(final RequestResult<T, E> result) throws IOException {
|
||||
if (result instanceof RequestResult.Success) {
|
||||
return ((RequestResult.Success<T>) result).getResult();
|
||||
} else if (result instanceof RequestResult.ApplicationError e) {
|
||||
final var cause = e.getCause();
|
||||
switch (cause) {
|
||||
case IOException io -> throw io;
|
||||
case RuntimeException rt -> throw rt;
|
||||
default -> throw new RuntimeException(cause);
|
||||
}
|
||||
} else if (result instanceof RequestResult.RetryableNetworkError e) {
|
||||
throw e.getNetworkError();
|
||||
} else if (result instanceof RequestResult.NonSuccess) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
throw new IllegalStateException("Unexpected value: " + result);
|
||||
}
|
||||
|
||||
public static ByteString firstNonEmpty(ByteString... strings) {
|
||||
for (final var s : strings) {
|
||||
if (s.size() > 0) {
|
||||
|
||||
Reference in new issue
Block a user