mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-20 06:38:05 +01:00
Update gcm-sender-async to use jdk11 httpclient
This commit is contained in:
@@ -86,7 +86,6 @@ import javax.servlet.DispatcherType;
|
||||
import javax.servlet.FilterRegistration;
|
||||
import javax.servlet.ServletRegistration;
|
||||
import java.security.Security;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -188,7 +187,7 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
|
||||
DispatchManager dispatchManager = new DispatchManager(cacheClientFactory, Optional.of(deadLetterHandler));
|
||||
PubSubManager pubSubManager = new PubSubManager(cacheClient, dispatchManager);
|
||||
APNSender apnSender = new APNSender(accountsManager, config.getApnConfiguration());
|
||||
GCMSender gcmSender = new GCMSender(accountsManager, config.getGcmConfiguration().getApiKey(), directoryQueue);
|
||||
GCMSender gcmSender = new GCMSender(accountsManager, config.getGcmConfiguration().getApiKey());
|
||||
WebsocketSender websocketSender = new WebsocketSender(messagesManager, pubSubManager);
|
||||
RateLimiters rateLimiters = new RateLimiters(config.getLimitsConfiguration(), cacheClient);
|
||||
|
||||
|
||||
@@ -4,25 +4,22 @@ import com.codahale.metrics.Meter;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import com.codahale.metrics.SharedMetricRegistries;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.gcm.server.Message;
|
||||
import org.whispersystems.gcm.server.Result;
|
||||
import org.whispersystems.gcm.server.Sender;
|
||||
import org.whispersystems.textsecuregcm.sqs.DirectoryQueue;
|
||||
import org.whispersystems.textsecuregcm.storage.Account;
|
||||
import org.whispersystems.textsecuregcm.storage.AccountsManager;
|
||||
import org.whispersystems.textsecuregcm.storage.Device;
|
||||
import org.whispersystems.textsecuregcm.util.Constants;
|
||||
import org.whispersystems.textsecuregcm.util.SystemMapper;
|
||||
import org.whispersystems.textsecuregcm.util.Util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -45,23 +42,19 @@ public class GCMSender implements Managed {
|
||||
put("notification", metricRegistry.meter(name(getClass(), "outbound", "notification")));
|
||||
}};
|
||||
|
||||
|
||||
private final AccountsManager accountsManager;
|
||||
private final Sender signalSender;
|
||||
private final DirectoryQueue directoryQueue;
|
||||
private ExecutorService executor;
|
||||
|
||||
public GCMSender(AccountsManager accountsManager, String signalKey, DirectoryQueue directoryQueue) {
|
||||
public GCMSender(AccountsManager accountsManager, String signalKey) {
|
||||
this.accountsManager = accountsManager;
|
||||
this.signalSender = new Sender(signalKey, 50);
|
||||
this.directoryQueue = directoryQueue;
|
||||
this.signalSender = new Sender(signalKey, SystemMapper.getMapper(), 6);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public GCMSender(AccountsManager accountsManager, Sender sender, DirectoryQueue directoryQueue, ExecutorService executor) {
|
||||
public GCMSender(AccountsManager accountsManager, Sender sender, ExecutorService executor) {
|
||||
this.accountsManager = accountsManager;
|
||||
this.signalSender = sender;
|
||||
this.directoryQueue = directoryQueue;
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
@@ -73,28 +66,26 @@ public class GCMSender implements Managed {
|
||||
String key = message.isReceipt() ? "receipt" : "notification";
|
||||
Message request = builder.withDataPart(key, "").build();
|
||||
|
||||
ListenableFuture<Result> future = signalSender.send(request, message);
|
||||
CompletableFuture<Result> future = signalSender.send(request);
|
||||
markOutboundMeter(key);
|
||||
|
||||
Futures.addCallback(future, new FutureCallback<Result>() {
|
||||
@Override
|
||||
public void onSuccess(Result result) {
|
||||
future.handle((result, throwable) -> {
|
||||
if (result != null) {
|
||||
if (result.isUnregistered() || result.isInvalidRegistrationId()) {
|
||||
handleBadRegistration(result);
|
||||
executor.submit(() -> handleBadRegistration(message));
|
||||
} else if (result.hasCanonicalRegistrationId()) {
|
||||
handleCanonicalRegistrationId(result);
|
||||
executor.submit(() -> handleCanonicalRegistrationId(message, result));
|
||||
} else if (!result.isSuccess()) {
|
||||
handleGenericError(result);
|
||||
executor.submit(() -> handleGenericError(message, result));
|
||||
} else {
|
||||
success.mark();
|
||||
}
|
||||
} else {
|
||||
logger.warn("FCM Failed: " + throwable + ", " + throwable.getCause());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable throwable) {
|
||||
logger.warn("GCM Failed: " + throwable);
|
||||
}
|
||||
}, executor);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,16 +94,15 @@ public class GCMSender implements Managed {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() throws IOException {
|
||||
this.signalSender.stop();
|
||||
public void stop() {
|
||||
this.executor.shutdown();
|
||||
}
|
||||
|
||||
private void handleBadRegistration(Result result) {
|
||||
GcmMessage message = (GcmMessage) result.getContext();
|
||||
private void handleBadRegistration(GcmMessage message) {
|
||||
Optional<Account> account = getAccountForEvent(message);
|
||||
|
||||
if (account.isPresent()) {
|
||||
//noinspection OptionalGetWithoutIsPresent
|
||||
Device device = account.get().getDevice(message.getDeviceId()).get();
|
||||
|
||||
if (device.getUninstalledFeedbackTimestamp() == 0) {
|
||||
@@ -124,14 +114,14 @@ public class GCMSender implements Managed {
|
||||
unregistered.mark();
|
||||
}
|
||||
|
||||
private void handleCanonicalRegistrationId(Result result) {
|
||||
GcmMessage message = (GcmMessage)result.getContext();
|
||||
private void handleCanonicalRegistrationId(GcmMessage message, Result result) {
|
||||
logger.warn(String.format("Actually received 'CanonicalRegistrationId' ::: (canonical=%s), (original=%s)",
|
||||
result.getCanonicalRegistrationId(), message.getGcmId()));
|
||||
|
||||
Optional<Account> account = getAccountForEvent(message);
|
||||
|
||||
if (account.isPresent()) {
|
||||
//noinspection OptionalGetWithoutIsPresent
|
||||
Device device = account.get().getDevice(message.getDeviceId()).get();
|
||||
device.setGcmId(result.getCanonicalRegistrationId());
|
||||
|
||||
@@ -141,8 +131,7 @@ public class GCMSender implements Managed {
|
||||
canonical.mark();
|
||||
}
|
||||
|
||||
private void handleGenericError(Result result) {
|
||||
GcmMessage message = (GcmMessage)result.getContext();
|
||||
private void handleGenericError(GcmMessage message, Result result) {
|
||||
logger.warn(String.format("Unrecoverable Error ::: (error=%s), (gcm_id=%s), " +
|
||||
"(destination=%s), (device_id=%d)",
|
||||
result.getError(), message.getGcmId(), message.getNumber(),
|
||||
|
||||
Reference in New Issue
Block a user