Gate based on destination rather than random.
This commit is contained in:
parent
affb219d72
commit
59eb6d10c1
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue