Add disableRateLimits option to daemon (#1803)

This commit is contained in:
atsamd21 2025-06-12 14:16:59 +02:00 committed by GitHub
parent 145f0c9cf6
commit ab5f6c8191
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 45 additions and 16 deletions

View file

@ -119,6 +119,7 @@ public class Config {
public static final String PASSWORD_REQUIRED = "passwordRequired"; public static final String PASSWORD_REQUIRED = "passwordRequired";
public static final String UPDATE_XMR_BINARIES = "updateXmrBinaries"; public static final String UPDATE_XMR_BINARIES = "updateXmrBinaries";
public static final String XMR_BLOCKCHAIN_PATH = "xmrBlockchainPath"; public static final String XMR_BLOCKCHAIN_PATH = "xmrBlockchainPath";
public static final String DISABLE_RATE_LIMITS = "disableRateLimits";
// Default values for certain options // Default values for certain options
public static final int UNSPECIFIED_PORT = -1; public static final int UNSPECIFIED_PORT = -1;
@ -208,6 +209,7 @@ public class Config {
public final boolean passwordRequired; public final boolean passwordRequired;
public final boolean updateXmrBinaries; public final boolean updateXmrBinaries;
public final String xmrBlockchainPath; public final String xmrBlockchainPath;
public final boolean disableRateLimits;
// Properties derived from options but not exposed as options themselves // Properties derived from options but not exposed as options themselves
public final File torDir; public final File torDir;
@ -639,6 +641,13 @@ public class Config {
.ofType(String.class) .ofType(String.class)
.defaultsTo(""); .defaultsTo("");
ArgumentAcceptingOptionSpec<Boolean> disableRateLimits =
parser.accepts(DISABLE_RATE_LIMITS,
"Disables all API rate limits")
.withRequiredArg()
.ofType(boolean.class)
.defaultsTo(false);
try { try {
CompositeOptionSet options = new CompositeOptionSet(); CompositeOptionSet options = new CompositeOptionSet();
@ -753,6 +762,7 @@ public class Config {
this.passwordRequired = options.valueOf(passwordRequiredOpt); this.passwordRequired = options.valueOf(passwordRequiredOpt);
this.updateXmrBinaries = options.valueOf(updateXmrBinariesOpt); this.updateXmrBinaries = options.valueOf(updateXmrBinariesOpt);
this.xmrBlockchainPath = options.valueOf(xmrBlockchainPathOpt); this.xmrBlockchainPath = options.valueOf(xmrBlockchainPathOpt);
this.disableRateLimits = options.valueOf(disableRateLimits);
} catch (OptionException ex) { } catch (OptionException ex) {
throw new ConfigException("problem parsing option '%s': %s", throw new ConfigException("problem parsing option '%s': %s",
ex.options().get(0), ex.options().get(0),

View file

@ -22,11 +22,15 @@ import com.google.inject.Singleton;
import haveno.common.config.Config; import haveno.common.config.Config;
import haveno.core.api.CoreContext; import haveno.core.api.CoreContext;
import haveno.daemon.grpc.interceptor.PasswordAuthInterceptor; import haveno.daemon.grpc.interceptor.PasswordAuthInterceptor;
import io.grpc.Server;
import io.grpc.ServerBuilder;
import static io.grpc.ServerInterceptors.interceptForward; import static io.grpc.ServerInterceptors.interceptForward;
import java.io.IOException; import java.io.IOException;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
import io.grpc.Metadata;
import io.grpc.ServerCall;
import io.grpc.ServerCallHandler;
import io.grpc.ServerInterceptor;
import io.grpc.Server;
import io.grpc.ServerBuilder;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@Singleton @Singleton
@ -55,26 +59,41 @@ public class GrpcServer {
GrpcXmrConnectionService moneroConnectionsService, GrpcXmrConnectionService moneroConnectionsService,
GrpcXmrNodeService moneroNodeService) { GrpcXmrNodeService moneroNodeService) {
this.server = ServerBuilder.forPort(config.apiPort) this.server = ServerBuilder.forPort(config.apiPort)
.addService(interceptForward(accountService, accountService.interceptors()))
.addService(interceptForward(disputeAgentsService, disputeAgentsService.interceptors()))
.addService(interceptForward(disputesService, disputesService.interceptors()))
.addService(interceptForward(helpService, helpService.interceptors()))
.addService(interceptForward(offersService, offersService.interceptors()))
.addService(interceptForward(paymentAccountsService, paymentAccountsService.interceptors()))
.addService(interceptForward(priceService, priceService.interceptors()))
.addService(shutdownService) .addService(shutdownService)
.addService(interceptForward(tradeStatisticsService, tradeStatisticsService.interceptors()))
.addService(interceptForward(tradesService, tradesService.interceptors()))
.addService(interceptForward(versionService, versionService.interceptors()))
.addService(interceptForward(walletsService, walletsService.interceptors()))
.addService(interceptForward(notificationsService, notificationsService.interceptors()))
.addService(interceptForward(moneroConnectionsService, moneroConnectionsService.interceptors()))
.addService(interceptForward(moneroNodeService, moneroNodeService.interceptors()))
.intercept(passwordAuthInterceptor) .intercept(passwordAuthInterceptor)
.addService(interceptForward(accountService, config.disableRateLimits ? interceptors() : accountService.interceptors()))
.addService(interceptForward(disputeAgentsService, config.disableRateLimits ? interceptors() : disputeAgentsService.interceptors()))
.addService(interceptForward(disputesService, config.disableRateLimits ? interceptors() : disputesService.interceptors()))
.addService(interceptForward(helpService, config.disableRateLimits ? interceptors() : helpService.interceptors()))
.addService(interceptForward(offersService, config.disableRateLimits ? interceptors() : offersService.interceptors()))
.addService(interceptForward(paymentAccountsService, config.disableRateLimits ? interceptors() : paymentAccountsService.interceptors()))
.addService(interceptForward(priceService, config.disableRateLimits ? interceptors() : priceService.interceptors()))
.addService(interceptForward(tradeStatisticsService, config.disableRateLimits ? interceptors() : tradeStatisticsService.interceptors()))
.addService(interceptForward(tradesService, config.disableRateLimits ? interceptors() : tradesService.interceptors()))
.addService(interceptForward(versionService, config.disableRateLimits ? interceptors() : versionService.interceptors()))
.addService(interceptForward(walletsService, config.disableRateLimits ? interceptors() : walletsService.interceptors()))
.addService(interceptForward(notificationsService, config.disableRateLimits ? interceptors() : notificationsService.interceptors()))
.addService(interceptForward(moneroConnectionsService, config.disableRateLimits ? interceptors() : moneroConnectionsService.interceptors()))
.addService(interceptForward(moneroNodeService, config.disableRateLimits ? interceptors() : moneroNodeService.interceptors()))
.build(); .build();
coreContext.setApiUser(true); coreContext.setApiUser(true);
} }
private ServerInterceptor[] interceptors() {
return new ServerInterceptor[]{callLoggingInterceptor()};
}
private ServerInterceptor callLoggingInterceptor() {
return new ServerInterceptor() {
@Override
public <RequestT, ResponseT> ServerCall.Listener<RequestT> interceptCall(ServerCall<RequestT, ResponseT> call, Metadata headers, ServerCallHandler<RequestT, ResponseT> next) {
log.debug("GRPC endpoint called: " + call.getMethodDescriptor().getFullMethodName());
return next.startCall(call, headers);
}
};
}
public void start() { public void start() {
try { try {
server.start(); server.start();