Gate based on destination rather than random.

This commit is contained in:
Jon Chambers authored and Jon Chambers committed 2021-01-15 18:05:18 -05:00
1 parent affb219d72
commit 59eb6d10c1
2 files changed
+15 -1

No files matched your search

@@ -37,4 +37,12 @@ public class AmbiguousIdentifier {
public boolean hasNumber() {
return number != null;
}
public int sendingGateHash() {
if (uuid != null) {
return (int)(uuid.getLeastSignificantBits() & 0xff);
} else {
return number.hashCode() & 0xff;
}
}
}
@@ -124,7 +124,7 @@ public class MessageController {
@Valid IncomingMessageList messages)
throws RateLimitExceededException
{
if (random.nextDouble() <= getSuccessPercentage()) {
if (shouldSend(destinationName)) {
if (!source.isPresent() && !accessKey.isPresent()) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
@@ -199,6 +199,12 @@ public class MessageController {
}
}
private boolean shouldSend(final AmbiguousIdentifier destination) {
final double hash = destination.sendingGateHash();
return (hash / 255.0) <= getSuccessPercentage();
}
private double getSuccessPercentage() {
if (featureFlagsManager.isFeatureFlagActive("SEND_MESSAGE_1_PERCENT")) {
return 0.01;