Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent excessive api calls #4966

Merged
merged 54 commits into from Dec 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
dc6144d
Refactor BtcWalletService to let api override fee rates
ghubstan Dec 4, 2020
900d498
Merge branch 'master' into 02-refactor-completePreparedSendBsqTx
ghubstan Dec 4, 2020
159d4cc
Add optional txFeeRate parameter to api sendbsq
ghubstan Dec 4, 2020
2842070
Merge branch 'master' into 03-add-txFeeRate-param
ghubstan Dec 8, 2020
6c9f0c2
Add new api method 'sendbtc' and test
ghubstan Dec 9, 2020
144c5a8
Merge branch 'master' into 04-add-sendbtc-impl
ghubstan Dec 9, 2020
bd66008
Support tx memo field for btc withdrawals from api
ghubstan Dec 9, 2020
478c8f4
Remove unused imports
ghubstan Dec 9, 2020
259bad6
Merge branch 'master' into 05-use-memo-tx-field
ghubstan Dec 10, 2020
150e2f6
Use Bisq's UserThread.executor in gRPC server
ghubstan Dec 11, 2020
6aa385e
Append nullable withdrawalTxId field to Trade proto message
ghubstan Dec 12, 2020
5522d0c
Add new api method gettransaction
ghubstan Dec 14, 2020
a0f1c22
Merge branch 'master' into 08-scratch
ghubstan Dec 14, 2020
0384642
Adjust create TransferwiseAccount test
ghubstan Dec 14, 2020
4be87a6
Disable method test to avoid repetition
ghubstan Dec 14, 2020
a341173
Merge branch 'master' into 09-scratch
ghubstan Dec 15, 2020
e6c6d3b
Add new CoreApiExceptionHandler to gRPC services
ghubstan Dec 16, 2020
1cd47fd
Merge branch 'master' into 09-refactor-grpc-error-handling
ghubstan Dec 16, 2020
c60605f
Fix class level comment
ghubstan Dec 16, 2020
f7c1103
Rename gRPC exception handler class
ghubstan Dec 16, 2020
2572e86
Create grpc interceptor pkg, move auth interceptor into it
ghubstan Dec 16, 2020
fa9ffa1
Put arguments on separate lines
ghubstan Dec 16, 2020
2148a4d
Prevent excessive api calls
ghubstan Dec 17, 2020
89e2187
Change long to int, tidy up error msg
ghubstan Dec 17, 2020
a5ed17e
Add license comment, stop & toString methods, and make isRunning tran…
ghubstan Dec 19, 2020
b307593
Make CallRateMeteringInterceptor configurable via json
ghubstan Dec 19, 2020
5de910a
Add unit test dependencies to daemon subproject
ghubstan Dec 19, 2020
455ed67
Add GrpcServiceRateMeteringConfigTest
ghubstan Dec 19, 2020
830a5f0
Add license note
ghubstan Dec 19, 2020
9f679de
Add license note and toString method
ghubstan Dec 19, 2020
bb8d2ae
Inject Config into CoreApi
ghubstan Dec 19, 2020
ea97a80
Don't cancel gRPC call if an interceptor does not meter all methods
ghubstan Dec 19, 2020
87f75ee
Configure GrpcVersionService's rate metering interceptor
ghubstan Dec 19, 2020
56a5c79
Add ApiTestConfig option --callRateMeteringConfigPath
ghubstan Dec 19, 2020
d5657e9
Install call rate metering config file before startup
ghubstan Dec 19, 2020
fabd7c8
Refactor testcase superclasses to support rate metering configs
ghubstan Dec 19, 2020
abc3940
Test CallRateMeteringInterceptor
ghubstan Dec 19, 2020
a3eb4ed
Remove unused import
ghubstan Dec 19, 2020
672eb79
Revert "Append nullable withdrawalTxId field to Trade proto message"
ghubstan Dec 21, 2020
bdde24a
Ajust TradeInfo to reverting 6aa385e494eb8fa870257c76e078108607503d03
ghubstan Dec 21, 2020
64c2ac5
Adjust grpc.proto to reverting 6aa385e494eb8fa870257c76e078108607503d03
ghubstan Dec 21, 2020
97dcac2
Adjust TradeFormat to reverting 6aa385e494eb8fa870257c76e078108607503d03
ghubstan Dec 21, 2020
3a770f4
Adjust TakeSellBTCOfferTest to reverting 6aa385e494eb8fa870257c76e078…
ghubstan Dec 21, 2020
4aa4270
Adjust TradeTest to reverting 6aa385e494eb8fa870257c76e078108607503d03
ghubstan Dec 21, 2020
1507a2c
Resolve file conflict w/ master
ghubstan Dec 21, 2020
8ee3a15
Merge branch '08-gettransaction' into 09-refactor-grpc-error-handling
ghubstan Dec 21, 2020
27efc5f
Merge branch '09-refactor-grpc-error-handling' into 10-callrate-inter…
ghubstan Dec 21, 2020
01546ad
Use a simpler, time windowing call rate meter
ghubstan Dec 22, 2020
d615212
Remove unused local var
ghubstan Dec 22, 2020
0d4ed95
Remove redundant callCount field
ghubstan Dec 22, 2020
c8ef414
Fix comment
ghubstan Dec 22, 2020
6356476
Support more fine grained rate metering
ghubstan Dec 23, 2020
b8c5a29
Disable CallRateMeteringInterceptorTest and run it from test suite
ghubstan Dec 23, 2020
10727fc
Fix GrpcCallRateMeter method and variable name
ghubstan Dec 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion daemon/src/main/java/bisq/daemon/grpc/GrpcServer.java
Expand Up @@ -31,6 +31,8 @@

import lombok.extern.slf4j.Slf4j;

import static io.grpc.ServerInterceptors.interceptForward;



import bisq.daemon.grpc.interceptor.PasswordAuthInterceptor;
Expand Down Expand Up @@ -60,7 +62,7 @@ public GrpcServer(Config config,
.addService(priceService)
.addService(tradeStatisticsService)
.addService(tradesService)
.addService(versionService)
.addService(interceptForward(versionService, versionService.interceptors()))
.addService(walletsService)
.intercept(passwordAuthInterceptor)
.build();
Expand Down
54 changes: 53 additions & 1 deletion daemon/src/main/java/bisq/daemon/grpc/GrpcVersionService.java
@@ -1,3 +1,20 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.daemon.grpc;

import bisq.core.api.CoreApi;
Expand All @@ -6,11 +23,29 @@
import bisq.proto.grpc.GetVersionReply;
import bisq.proto.grpc.GetVersionRequest;

import io.grpc.ServerInterceptor;
import io.grpc.stub.StreamObserver;

import javax.inject.Inject;

class GrpcVersionService extends GetVersionGrpc.GetVersionImplBase {
import com.google.common.annotations.VisibleForTesting;

import java.util.HashMap;
import java.util.Optional;

import lombok.extern.slf4j.Slf4j;

import static bisq.daemon.grpc.interceptor.GrpcServiceRateMeteringConfig.getCustomRateMeteringInterceptor;
import static java.util.concurrent.TimeUnit.SECONDS;



import bisq.daemon.grpc.interceptor.CallRateMeteringInterceptor;
import bisq.daemon.grpc.interceptor.GrpcCallRateMeter;

@VisibleForTesting
@Slf4j
public class GrpcVersionService extends GetVersionGrpc.GetVersionImplBase {

private final CoreApi coreApi;
private final GrpcExceptionHandler exceptionHandler;
Expand All @@ -31,4 +66,21 @@ public void getVersion(GetVersionRequest req, StreamObserver<GetVersionReply> re
exceptionHandler.handleException(cause, responseObserver);
}
}

final ServerInterceptor[] interceptors() {
Optional<ServerInterceptor> rateMeteringInterceptor = rateMeteringInterceptor();
return rateMeteringInterceptor.map(serverInterceptor ->
new ServerInterceptor[]{serverInterceptor}).orElseGet(() -> new ServerInterceptor[0]);
}

final Optional<ServerInterceptor> rateMeteringInterceptor() {
@SuppressWarnings("unused") // Defined as a usage example.
CallRateMeteringInterceptor defaultCallRateMeteringInterceptor =
new CallRateMeteringInterceptor(new HashMap<>() {{
put("getVersion", new GrpcCallRateMeter(100, SECONDS));
}});

return getCustomRateMeteringInterceptor(coreApi.getConfig().appDataDir, this.getClass())
.or(Optional::empty /* Optional.of(defaultCallRateMeteringInterceptor) */);
}
}