mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-09-14 18:21:52 -04:00
Add disableRateLimits option to daemon (#1803)
This commit is contained in:
parent
145f0c9cf6
commit
ab5f6c8191
2 changed files with 45 additions and 16 deletions
|
@ -119,6 +119,7 @@ public class Config {
|
|||
public static final String PASSWORD_REQUIRED = "passwordRequired";
|
||||
public static final String UPDATE_XMR_BINARIES = "updateXmrBinaries";
|
||||
public static final String XMR_BLOCKCHAIN_PATH = "xmrBlockchainPath";
|
||||
public static final String DISABLE_RATE_LIMITS = "disableRateLimits";
|
||||
|
||||
// Default values for certain options
|
||||
public static final int UNSPECIFIED_PORT = -1;
|
||||
|
@ -208,6 +209,7 @@ public class Config {
|
|||
public final boolean passwordRequired;
|
||||
public final boolean updateXmrBinaries;
|
||||
public final String xmrBlockchainPath;
|
||||
public final boolean disableRateLimits;
|
||||
|
||||
// Properties derived from options but not exposed as options themselves
|
||||
public final File torDir;
|
||||
|
@ -639,6 +641,13 @@ public class Config {
|
|||
.ofType(String.class)
|
||||
.defaultsTo("");
|
||||
|
||||
ArgumentAcceptingOptionSpec<Boolean> disableRateLimits =
|
||||
parser.accepts(DISABLE_RATE_LIMITS,
|
||||
"Disables all API rate limits")
|
||||
.withRequiredArg()
|
||||
.ofType(boolean.class)
|
||||
.defaultsTo(false);
|
||||
|
||||
try {
|
||||
CompositeOptionSet options = new CompositeOptionSet();
|
||||
|
||||
|
@ -753,6 +762,7 @@ public class Config {
|
|||
this.passwordRequired = options.valueOf(passwordRequiredOpt);
|
||||
this.updateXmrBinaries = options.valueOf(updateXmrBinariesOpt);
|
||||
this.xmrBlockchainPath = options.valueOf(xmrBlockchainPathOpt);
|
||||
this.disableRateLimits = options.valueOf(disableRateLimits);
|
||||
} catch (OptionException ex) {
|
||||
throw new ConfigException("problem parsing option '%s': %s",
|
||||
ex.options().get(0),
|
||||
|
|
|
@ -22,11 +22,15 @@ import com.google.inject.Singleton;
|
|||
import haveno.common.config.Config;
|
||||
import haveno.core.api.CoreContext;
|
||||
import haveno.daemon.grpc.interceptor.PasswordAuthInterceptor;
|
||||
import io.grpc.Server;
|
||||
import io.grpc.ServerBuilder;
|
||||
import static io.grpc.ServerInterceptors.interceptForward;
|
||||
import java.io.IOException;
|
||||
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;
|
||||
|
||||
@Singleton
|
||||
|
@ -55,26 +59,41 @@ public class GrpcServer {
|
|||
GrpcXmrConnectionService moneroConnectionsService,
|
||||
GrpcXmrNodeService moneroNodeService) {
|
||||
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(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)
|
||||
.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();
|
||||
|
||||
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() {
|
||||
try {
|
||||
server.start();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue