Add some meters and reorder limits
This commit is contained in:
parent
df9bd21f55
commit
585bbf3987
1
pom.xml
1
pom.xml
|
@ -14,7 +14,6 @@
|
||||||
<properties>
|
<properties>
|
||||||
<dropwizard.version>1.3.7</dropwizard.version>
|
<dropwizard.version>1.3.7</dropwizard.version>
|
||||||
<jackson.api.version>2.9.6</jackson.api.version>
|
<jackson.api.version>2.9.6</jackson.api.version>
|
||||||
<hystrix.version>1.5.12</hystrix.version>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
|
|
@ -118,15 +118,15 @@ public class KeysController {
|
||||||
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
|
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (account.isPresent()) {
|
|
||||||
rateLimiters.getPreKeysLimiter().validate(account.get().getNumber() + "__" + number + "." + deviceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
Optional<Account> target = accounts.get(number);
|
Optional<Account> target = accounts.get(number);
|
||||||
OptionalAccess.verify(account, accessKey, target, deviceId);
|
OptionalAccess.verify(account, accessKey, target, deviceId);
|
||||||
|
|
||||||
assert(target.isPresent());
|
assert(target.isPresent());
|
||||||
|
|
||||||
|
if (account.isPresent()) {
|
||||||
|
rateLimiters.getPreKeysLimiter().validate(account.get().getNumber() + "__" + number + "." + deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
Optional<List<KeyRecord>> targetKeys = getLocalKeys(target.get(), deviceId);
|
Optional<List<KeyRecord>> targetKeys = getLocalKeys(target.get(), deviceId);
|
||||||
List<PreKeyResponseItem> devices = new LinkedList<>();
|
List<PreKeyResponseItem> devices = new LinkedList<>();
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,9 @@
|
||||||
*/
|
*/
|
||||||
package org.whispersystems.textsecuregcm.controllers;
|
package org.whispersystems.textsecuregcm.controllers;
|
||||||
|
|
||||||
|
import com.codahale.metrics.Meter;
|
||||||
|
import com.codahale.metrics.MetricRegistry;
|
||||||
|
import com.codahale.metrics.SharedMetricRegistries;
|
||||||
import com.codahale.metrics.annotation.Timed;
|
import com.codahale.metrics.annotation.Timed;
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -41,6 +44,7 @@ import org.whispersystems.textsecuregcm.storage.AccountsManager;
|
||||||
import org.whispersystems.textsecuregcm.storage.Device;
|
import org.whispersystems.textsecuregcm.storage.Device;
|
||||||
import org.whispersystems.textsecuregcm.storage.MessagesManager;
|
import org.whispersystems.textsecuregcm.storage.MessagesManager;
|
||||||
import org.whispersystems.textsecuregcm.util.Base64;
|
import org.whispersystems.textsecuregcm.util.Base64;
|
||||||
|
import org.whispersystems.textsecuregcm.util.Constants;
|
||||||
import org.whispersystems.textsecuregcm.util.Util;
|
import org.whispersystems.textsecuregcm.util.Util;
|
||||||
import org.whispersystems.textsecuregcm.websocket.WebSocketConnection;
|
import org.whispersystems.textsecuregcm.websocket.WebSocketConnection;
|
||||||
|
|
||||||
|
@ -64,13 +68,17 @@ import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static com.codahale.metrics.MetricRegistry.name;
|
||||||
import io.dropwizard.auth.Auth;
|
import io.dropwizard.auth.Auth;
|
||||||
|
|
||||||
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
|
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
|
||||||
@Path("/v1/messages")
|
@Path("/v1/messages")
|
||||||
public class MessageController {
|
public class MessageController {
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(MessageController.class);
|
private final Logger logger = LoggerFactory.getLogger(MessageController.class);
|
||||||
|
private final MetricRegistry metricRegistry = SharedMetricRegistries.getOrCreate(Constants.METRICS_NAME);
|
||||||
|
private final Meter unidentifiedMeter = metricRegistry.meter(name(getClass(), "delivery", "unidentified"));
|
||||||
|
private final Meter identifiedMeter = metricRegistry.meter(name(getClass(), "delivery", "identified" ));
|
||||||
|
|
||||||
private final RateLimiters rateLimiters;
|
private final RateLimiters rateLimiters;
|
||||||
private final PushSender pushSender;
|
private final PushSender pushSender;
|
||||||
|
@ -113,6 +121,12 @@ public class MessageController {
|
||||||
rateLimiters.getMessagesLimiter().validate(source.get().getNumber() + "__" + destinationName);
|
rateLimiters.getMessagesLimiter().validate(source.get().getNumber() + "__" + destinationName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (source.isPresent() && !source.get().getNumber().equals(destinationName)) {
|
||||||
|
identifiedMeter.mark();
|
||||||
|
} else {
|
||||||
|
unidentifiedMeter.mark();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
boolean isSyncMessage = source.isPresent() && source.get().getNumber().equals(destinationName);
|
boolean isSyncMessage = source.isPresent() && source.get().getNumber().equals(destinationName);
|
||||||
|
|
||||||
|
@ -122,6 +136,8 @@ public class MessageController {
|
||||||
else destination = source;
|
else destination = source;
|
||||||
|
|
||||||
OptionalAccess.verify(source, accessKey, destination);
|
OptionalAccess.verify(source, accessKey, destination);
|
||||||
|
assert(destination.isPresent());
|
||||||
|
|
||||||
validateCompleteDeviceList(destination.get(), messages.getMessages(), isSyncMessage);
|
validateCompleteDeviceList(destination.get(), messages.getMessages(), isSyncMessage);
|
||||||
validateRegistrationIds(destination.get(), messages.getMessages());
|
validateRegistrationIds(destination.get(), messages.getMessages());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue