mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-20 05:38:04 +01:00
Convert AbusiveHostRule to a record
This commit is contained in:
@@ -92,7 +92,6 @@ import org.whispersystems.textsecuregcm.util.Hex;
|
||||
import org.whispersystems.textsecuregcm.util.ImpossiblePhoneNumberException;
|
||||
import org.whispersystems.textsecuregcm.util.NonNormalizedPhoneNumberException;
|
||||
import org.whispersystems.textsecuregcm.util.Username;
|
||||
import org.whispersystems.textsecuregcm.util.UsernameValidator;
|
||||
import org.whispersystems.textsecuregcm.util.Util;
|
||||
import org.whispersystems.textsecuregcm.util.VerificationCode;
|
||||
|
||||
@@ -728,14 +727,14 @@ public class AccountController {
|
||||
List<AbusiveHostRule> abuseRules = abusiveHostRules.getAbusiveHostRulesFor(sourceHost);
|
||||
|
||||
for (AbusiveHostRule abuseRule : abuseRules) {
|
||||
if (abuseRule.isBlocked()) {
|
||||
if (abuseRule.blocked()) {
|
||||
logger.info("Blocked host: {}, {}, {} ({})", transport, number, sourceHost, forwardedFor);
|
||||
blockedHostMeter.mark();
|
||||
return new CaptchaRequirement(true, false);
|
||||
}
|
||||
|
||||
if (!abuseRule.getRegions().isEmpty()) {
|
||||
if (abuseRule.getRegions().stream().noneMatch(number::startsWith)) {
|
||||
if (!abuseRule.regions().isEmpty()) {
|
||||
if (abuseRule.regions().stream().noneMatch(number::startsWith)) {
|
||||
logger.info("Restricted host: {}, {}, {} ({})", transport, number, sourceHost, forwardedFor);
|
||||
filteredHostMeter.mark();
|
||||
return new CaptchaRequirement(true, false);
|
||||
|
||||
@@ -7,27 +7,6 @@ package org.whispersystems.textsecuregcm.storage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AbusiveHostRule {
|
||||
public record AbusiveHostRule(String host, boolean blocked, List<String> regions) {
|
||||
|
||||
private final String host;
|
||||
private final boolean blocked;
|
||||
private final List<String> regions;
|
||||
|
||||
public AbusiveHostRule(String host, boolean blocked, List<String> regions) {
|
||||
this.host = host;
|
||||
this.blocked = blocked;
|
||||
this.regions = regions;
|
||||
}
|
||||
|
||||
public List<String> getRegions() {
|
||||
return regions;
|
||||
}
|
||||
|
||||
public boolean isBlocked() {
|
||||
return blocked;
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,10 +112,10 @@ public class AbusiveHostRules {
|
||||
try (Timer.Context timer = insertTimer.time()) {
|
||||
return handle.createUpdate(
|
||||
"INSERT INTO abusive_host_rules(host, blocked, notes, regions) VALUES(:host::inet, :blocked, :notes, :regions) ON CONFLICT DO NOTHING")
|
||||
.bind("host", rule.getHost())
|
||||
.bind("blocked", rule.isBlocked() ? 1 : 0)
|
||||
.bind("host", rule.host())
|
||||
.bind("blocked", rule.blocked() ? 1 : 0)
|
||||
.bind("notes", notes)
|
||||
.bind("regions", String.join(",", rule.getRegions()))
|
||||
.bind("regions", String.join(",", rule.regions()))
|
||||
.execute();
|
||||
}
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user