mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-20 17:58:03 +01:00
Return report spam token from spam check instead of separate call
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
package org.whispersystems.textsecuregcm.spam;
|
||||
|
||||
import org.whispersystems.textsecuregcm.auth.AccountAndAuthenticatedDeviceHolder;
|
||||
import org.whispersystems.textsecuregcm.storage.Account;
|
||||
import javax.ws.rs.container.ContainerRequestContext;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Generates ReportSpamTokens to be used for spam reports.
|
||||
*/
|
||||
public interface ReportSpamTokenProvider {
|
||||
|
||||
/**
|
||||
* Generate a new ReportSpamToken
|
||||
*
|
||||
* @param context the message request context
|
||||
* @param sender the account that sent the unsealed sender message
|
||||
* @param maybeDestination the intended recepient of the message if available
|
||||
* @return either a generated token or nothing
|
||||
*/
|
||||
Optional<byte[]> makeReportSpamToken(ContainerRequestContext context, final AccountAndAuthenticatedDeviceHolder sender,
|
||||
final Optional<Account> maybeDestination);
|
||||
|
||||
/**
|
||||
* Provider which generates nothing
|
||||
*
|
||||
* @return the provider
|
||||
*/
|
||||
static ReportSpamTokenProvider noop() {
|
||||
return (ignoredContext, ignoredSender, ignoredDest) -> Optional.empty();
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
package org.whispersystems.textsecuregcm.spam;
|
||||
|
||||
import org.whispersystems.textsecuregcm.auth.AccountAndAuthenticatedDeviceHolder;
|
||||
import org.whispersystems.textsecuregcm.storage.Account;
|
||||
import javax.ws.rs.container.ContainerRequestContext;
|
||||
import javax.ws.rs.core.Response;
|
||||
@@ -11,6 +12,25 @@ import java.util.Optional;
|
||||
|
||||
public interface SpamChecker {
|
||||
|
||||
/**
|
||||
* A result from the spam checker that is one of:
|
||||
* <ul>
|
||||
* <li>
|
||||
* Message is determined to be spam, and a response is returned
|
||||
* </li>
|
||||
* <li>
|
||||
* Message is not spam, and an optional spam token is returned
|
||||
* </li>
|
||||
* </ul>
|
||||
*/
|
||||
sealed interface SpamCheckResult {}
|
||||
|
||||
record Spam(Response response) implements SpamCheckResult {}
|
||||
|
||||
record NotSpam(Optional<byte[]> token) implements SpamCheckResult {
|
||||
public static final NotSpam EMPTY_TOKEN = new NotSpam(Optional.empty());
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a message may be spam
|
||||
*
|
||||
@@ -18,14 +38,14 @@ public interface SpamChecker {
|
||||
* @param maybeSource The sender of the message, could be empty if this as message sent with sealed sender
|
||||
* @param maybeDestination The destination of the message, could be empty if the destination does not exist or could
|
||||
* not be retrieved
|
||||
* @return A response to return if the request is determined to be spam, otherwise empty if the message should be sent
|
||||
* @return A {@link SpamCheckResult}
|
||||
*/
|
||||
Optional<Response> checkForSpam(
|
||||
SpamCheckResult checkForSpam(
|
||||
final ContainerRequestContext requestContext,
|
||||
final Optional<Account> maybeSource,
|
||||
final Optional<? extends AccountAndAuthenticatedDeviceHolder> maybeSource,
|
||||
final Optional<Account> maybeDestination);
|
||||
|
||||
static SpamChecker noop() {
|
||||
return (ignoredContext, ignoredSource, ignoredDestination) -> Optional.empty();
|
||||
return (ignoredContext, ignoredSource, ignoredDestination) -> NotSpam.EMPTY_TOKEN;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,13 +33,6 @@ public interface SpamFilter extends Managed {
|
||||
*/
|
||||
void configure(String environmentName, Validator validator) throws IOException, ConfigurationValidationException;
|
||||
|
||||
/**
|
||||
* Builds a spam report token provider. This will generate tokens used by the spam reporting system.
|
||||
*
|
||||
* @return the configured spam report token provider.
|
||||
*/
|
||||
ReportSpamTokenProvider getReportSpamTokenProvider();
|
||||
|
||||
/**
|
||||
* Return a reported message listener controlled by the spam filter. Listeners will be registered with the
|
||||
* {@link org.whispersystems.textsecuregcm.storage.ReportMessageManager}.
|
||||
|
||||
Reference in New Issue
Block a user