mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-20 23:58:06 +01:00
Decommission the old directory cache.
This commit is contained in:
committed by
Jon Chambers
parent
9cd121c8f6
commit
71510a8199
@@ -4,92 +4,28 @@
|
||||
*/
|
||||
package org.whispersystems.textsecuregcm.controllers;
|
||||
|
||||
import com.codahale.metrics.Histogram;
|
||||
import com.codahale.metrics.Meter;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import com.codahale.metrics.SharedMetricRegistries;
|
||||
import com.codahale.metrics.annotation.Timed;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.dropwizard.auth.Auth;
|
||||
import org.whispersystems.textsecuregcm.auth.ExternalServiceCredentialGenerator;
|
||||
import org.whispersystems.textsecuregcm.entities.ClientContact;
|
||||
import org.whispersystems.textsecuregcm.entities.ClientContactTokens;
|
||||
import org.whispersystems.textsecuregcm.entities.ClientContacts;
|
||||
import org.whispersystems.textsecuregcm.entities.DirectoryFeedbackRequest;
|
||||
import org.whispersystems.textsecuregcm.limits.RateLimiters;
|
||||
import org.whispersystems.textsecuregcm.storage.Account;
|
||||
import org.whispersystems.textsecuregcm.storage.Device;
|
||||
import org.whispersystems.textsecuregcm.storage.DirectoryManager;
|
||||
import org.whispersystems.textsecuregcm.util.Base64;
|
||||
import org.whispersystems.textsecuregcm.util.Constants;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.HeaderParam;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static com.codahale.metrics.MetricRegistry.name;
|
||||
import io.dropwizard.auth.Auth;
|
||||
|
||||
@Path("/v1/directory")
|
||||
public class DirectoryController {
|
||||
|
||||
private static final String[] FEEDBACK_STATUSES = {
|
||||
"ok",
|
||||
"mismatch",
|
||||
"attestation-error",
|
||||
"unexpected-error",
|
||||
};
|
||||
|
||||
private static final String[] FRONTED_REGIONS = {"+20", "+971", "+968", "+974"};
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(DirectoryController.class);
|
||||
private final MetricRegistry metricRegistry = SharedMetricRegistries.getOrCreate(Constants.METRICS_NAME);
|
||||
private final Histogram contactsHistogram = metricRegistry.histogram(name(getClass(), "contacts"));
|
||||
private final Meter contactsMeter = metricRegistry.meter(name(getClass(), "contactRate"));
|
||||
|
||||
private final Map<String, Meter> iosFeedbackMeters = new HashMap<String, Meter>() {{
|
||||
for (String status : FEEDBACK_STATUSES) {
|
||||
put(status, metricRegistry.meter(name(DirectoryController.class, "feedback-v2", "ios", status)));
|
||||
}
|
||||
}};
|
||||
private final Map<String, Meter> androidFeedbackMeters = new HashMap<String, Meter>() {{
|
||||
for (String status : FEEDBACK_STATUSES) {
|
||||
put(status, metricRegistry.meter(name(DirectoryController.class, "feedback-v2", "android", status)));
|
||||
}
|
||||
}};
|
||||
private final Map<String, Meter> unknownFeedbackMeters = new HashMap<String, Meter>() {{
|
||||
for (String status : FEEDBACK_STATUSES) {
|
||||
put(status, metricRegistry.meter(name(DirectoryController.class, "feedback-v2", "unknown", status)));
|
||||
}
|
||||
}};
|
||||
|
||||
private final RateLimiters rateLimiters;
|
||||
private final DirectoryManager directory;
|
||||
private final ExternalServiceCredentialGenerator directoryServiceTokenGenerator;
|
||||
|
||||
public DirectoryController(RateLimiters rateLimiters,
|
||||
DirectoryManager directory,
|
||||
ExternalServiceCredentialGenerator userTokenGenerator)
|
||||
{
|
||||
this.directory = directory;
|
||||
this.rateLimiters = rateLimiters;
|
||||
public DirectoryController(ExternalServiceCredentialGenerator userTokenGenerator) {
|
||||
this.directoryServiceTokenGenerator = userTokenGenerator;
|
||||
}
|
||||
|
||||
@@ -105,29 +41,8 @@ public class DirectoryController {
|
||||
@Path("/feedback-v3/{status}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response setFeedback(@Auth Account account,
|
||||
@PathParam("status") String status,
|
||||
@Valid DirectoryFeedbackRequest request)
|
||||
{
|
||||
Map<String, Meter> platformFeedbackMeters = unknownFeedbackMeters;
|
||||
|
||||
Optional<Device> masterDevice = account.getMasterDevice();
|
||||
if (masterDevice.isPresent()) {
|
||||
if (masterDevice.get().getApnId() != null) {
|
||||
platformFeedbackMeters = iosFeedbackMeters;
|
||||
} else if (masterDevice.get().getGcmId() != null) {
|
||||
platformFeedbackMeters = androidFeedbackMeters;
|
||||
}
|
||||
}
|
||||
|
||||
Optional<Meter> meter = Optional.ofNullable(platformFeedbackMeters.get(status));
|
||||
if (meter.isPresent()) {
|
||||
meter.get().mark();
|
||||
|
||||
return Response.ok().build();
|
||||
} else {
|
||||
return Response.status(Status.NOT_FOUND).build();
|
||||
}
|
||||
public Response setFeedback(@Auth Account account) {
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
|
||||
@@ -135,9 +50,7 @@ public class DirectoryController {
|
||||
@GET
|
||||
@Path("/{token}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getTokenPresence(@Auth Account account, @PathParam("token") String token)
|
||||
throws RateLimitExceededException
|
||||
{
|
||||
public Response getTokenPresence(@Auth Account account) {
|
||||
return Response.status(429).build();
|
||||
}
|
||||
|
||||
@@ -146,15 +59,7 @@ public class DirectoryController {
|
||||
@Path("/tokens")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Response getContactIntersection(@Auth Account account,
|
||||
@HeaderParam("X-Forwarded-For") String forwardedFor,
|
||||
@Valid ClientContactTokens contacts)
|
||||
throws RateLimitExceededException
|
||||
{
|
||||
public Response getContactIntersection(@Auth Account account) {
|
||||
return Response.status(429).build();
|
||||
}
|
||||
|
||||
private byte[] decodeToken(String encoded) throws IOException {
|
||||
return Base64.decodeWithoutPadding(encoded.replace('-', '+').replace('_', '/'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user