mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-19 16:19:33 +01:00
Convert rate limit apis to WebSocket.
This commit is contained in:
committed by
Greyson Parrelli
parent
86b2fe9742
commit
61a8636217
@@ -16,11 +16,11 @@ import org.thoughtcrime.securesms.database.model.ParentStoryId
|
||||
import org.thoughtcrime.securesms.dependencies.AppDependencies
|
||||
import org.thoughtcrime.securesms.jobs.SubmitRateLimitPushChallengeJob.SuccessEvent
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.net.SignalNetwork
|
||||
import org.thoughtcrime.securesms.notifications.v2.ConversationId
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException
|
||||
import org.whispersystems.signalservice.api.NetworkResult
|
||||
import org.whispersystems.signalservice.api.push.exceptions.ProofRequiredException
|
||||
import java.io.IOException
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.time.Duration
|
||||
@@ -42,25 +42,26 @@ object ProofRequiredExceptionHandler {
|
||||
fun handle(context: Context, proofRequired: ProofRequiredException, recipient: Recipient?, threadId: Long, messageId: Long): Result {
|
||||
Log.w(TAG, "[Proof Required] Options: ${proofRequired.options}")
|
||||
|
||||
try {
|
||||
if (ProofRequiredException.Option.PUSH_CHALLENGE in proofRequired.options) {
|
||||
AppDependencies.signalServiceAccountManager.requestRateLimitPushChallenge()
|
||||
Log.i(TAG, "[Proof Required] Successfully requested a challenge. Waiting up to $PUSH_CHALLENGE_TIMEOUT ms.")
|
||||
if (ProofRequiredException.Option.PUSH_CHALLENGE in proofRequired.options) {
|
||||
when (val result = SignalNetwork.rateLimitChallenge.requestPushChallenge()) {
|
||||
is NetworkResult.Success -> {
|
||||
Log.i(TAG, "[Proof Required] Successfully requested a challenge. Waiting up to $PUSH_CHALLENGE_TIMEOUT ms.")
|
||||
val success = PushChallengeRequest(PUSH_CHALLENGE_TIMEOUT).blockUntilSuccess()
|
||||
|
||||
val success = PushChallengeRequest(PUSH_CHALLENGE_TIMEOUT).blockUntilSuccess()
|
||||
|
||||
if (success) {
|
||||
Log.i(TAG, "Successfully responded to a push challenge. Retrying message send.")
|
||||
return Result.RETRY_NOW
|
||||
} else {
|
||||
Log.w(TAG, "Failed to respond to the push challeng in time. Falling back.")
|
||||
if (success) {
|
||||
Log.i(TAG, "Successfully responded to a push challenge. Retrying message send.")
|
||||
return Result.RETRY_NOW
|
||||
} else {
|
||||
Log.w(TAG, "Failed to respond to the push challeng in time. Falling back.")
|
||||
}
|
||||
}
|
||||
is NetworkResult.StatusCodeError -> Log.w(TAG, "[Proof Required] Could not request a push challenge (${result.code}). Falling back.", result.exception)
|
||||
is NetworkResult.NetworkError -> {
|
||||
Log.w(TAG, "[Proof Required] Network error when requesting push challenge. Retrying later.")
|
||||
return Result.RETRY_LATER
|
||||
}
|
||||
is NetworkResult.ApplicationError -> throw result.throwable
|
||||
}
|
||||
} catch (e: NonSuccessfulResponseCodeException) {
|
||||
Log.w(TAG, "[Proof Required] Could not request a push challenge (${e.code}). Falling back.", e)
|
||||
} catch (e: IOException) {
|
||||
Log.w(TAG, "[Proof Required] Network error when requesting push challenge. Retrying later.")
|
||||
return Result.RETRY_LATER
|
||||
}
|
||||
|
||||
if (messageId > 0) {
|
||||
|
||||
@@ -19,12 +19,13 @@ import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.BuildConfig;
|
||||
import org.thoughtcrime.securesms.PassphraseRequiredActivity;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.dependencies.AppDependencies;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.net.SignalNetwork;
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||
import org.thoughtcrime.securesms.util.ExceptionHelper;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.thoughtcrime.securesms.util.views.SimpleProgressDialog;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException;
|
||||
import org.whispersystems.signalservice.api.NetworkResultUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -98,12 +99,16 @@ public class RecaptchaProofActivity extends PassphraseRequiredActivity {
|
||||
try {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
try {
|
||||
AppDependencies.getSignalServiceAccountManager().submitRateLimitRecaptchaChallenge(challenge, token);
|
||||
NetworkResultUtil.toBasicLegacy(SignalNetwork.rateLimitChallenge().submitCaptchaChallenge(challenge, token));
|
||||
RateLimitUtil.retryAllRateLimitedMessages(this);
|
||||
Log.i(TAG, "Successfully completed reCAPTCHA.");
|
||||
return new TokenResult(true, true);
|
||||
} catch (PushNetworkException e) {
|
||||
Log.w(TAG, "Network error during submission. Retrying.", e);
|
||||
} catch (IOException e) {
|
||||
if (ExceptionHelper.isRetryableIOException(e)) {
|
||||
Log.w(TAG, "Network error during submission. Retrying.", e);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
||||
Reference in New Issue
Block a user