mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-12-02 13:26:53 +00:00
Gate based on destination rather than random.
This commit is contained in:
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
-1
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user