gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated (49663768 -> 7cc3b108)


From: gnunet
Subject: [taler-wallet-core] branch master updated (49663768 -> 7cc3b108)
Date: Sun, 15 Dec 2019 17:49:16 +0100

This is an automated email from the git hooks/post-receive script.

dold pushed a change to branch master
in repository wallet-core.

    from 49663768 group refresh sessions into groups for nicer history
     new 985c90e0 Christian's thresholds for throttling
     new 7cc3b108 don't throttle the integration test

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/android/index.ts             |   2 +-
 src/headless/NodeHttpLib.ts      | 102 +++++++++++++++++++++++++++++++++++++++
 src/headless/helpers.ts          |  81 ++-----------------------------
 src/headless/integrationtest.ts  |  14 ++++--
 src/headless/taler-wallet-cli.ts |   2 +-
 src/util/RequestThrottler.ts     |   4 +-
 tsconfig.json                    |   1 +
 7 files changed, 122 insertions(+), 84 deletions(-)
 create mode 100644 src/headless/NodeHttpLib.ts

diff --git a/src/android/index.ts b/src/android/index.ts
index 6d7f92cd..003f7f4e 100644
--- a/src/android/index.ts
+++ b/src/android/index.ts
@@ -22,7 +22,6 @@ import {
   getDefaultNodeWallet,
   withdrawTestBalance,
   DefaultNodeWalletArgs,
-  NodeHttpLib,
 } from "../headless/helpers";
 import { openPromise, OpenedPromise } from "../util/promiseUtils";
 import fs = require("fs");
@@ -32,6 +31,7 @@ import {
   HttpRequestOptions,
   Headers,
 } from "../util/http";
+import { NodeHttpLib } from "../headless/NodeHttpLib";
 
 // @ts-ignore: special built-in module
 //import akono = require("akono");
diff --git a/src/headless/NodeHttpLib.ts b/src/headless/NodeHttpLib.ts
new file mode 100644
index 00000000..5cbb40cc
--- /dev/null
+++ b/src/headless/NodeHttpLib.ts
@@ -0,0 +1,102 @@
+/*
+ This file is part of GNU Taler
+ (C) 2019 Taler Systems S.A.
+
+ GNU Taler is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ GNU Taler 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+
+ SPDX-License-Identifier: AGPL3.0-or-later
+*/
+
+import { Headers, HttpRequestLibrary, HttpRequestOptions, HttpResponse } from 
"../util/http";
+import { RequestThrottler } from "../util/RequestThrottler";
+import Axios, { AxiosResponse } from "axios";
+
+/**
+ * Implementation of the HTTP request library interface for node.
+ */
+export class NodeHttpLib implements HttpRequestLibrary {
+  private throttle = new RequestThrottler();
+  private throttlingEnabled = true;
+
+  /**
+   * Set whether requests should be throttled.
+   */
+  setThrottling(enabled: boolean) {
+    this.throttlingEnabled = enabled;
+  }
+
+  private async req(
+    method: "post" | "get",
+    url: string,
+    body: any,
+    opt?: HttpRequestOptions,
+  ): Promise<HttpResponse> {
+    if (this.throttlingEnabled && this.throttle.applyThrottle(url)) {
+      throw Error("request throttled");
+    }
+    let resp: AxiosResponse;
+    try {
+      resp = await Axios({
+        method,
+        url: url,
+        responseType: "text",
+        headers: opt?.headers,
+        validateStatus: () => true,
+        transformResponse: (x) => x,
+        data: body,
+      });
+    } catch (e) {
+      throw e;
+    }
+    const respText = resp.data;
+    if (typeof respText !== "string") {
+      throw Error("unexpected response type");
+    }
+    const makeJson = async () => {
+      let responseJson;
+      try {
+        responseJson = JSON.parse(respText);
+      } catch (e) {
+        throw Error("Invalid JSON from HTTP response");
+      }
+      if (responseJson === null || typeof responseJson !== "object") {
+        throw Error("Invalid JSON from HTTP response");
+      }
+      return responseJson;
+    };
+    const headers = new Headers();
+    for (const hn of Object.keys(resp.headers)) {
+      headers.set(hn, resp.headers[hn]);
+    }
+    return {
+      headers,
+      status: resp.status,
+      text: async () => resp.data,
+      json: makeJson,
+    };
+  }
+
+  async get(
+    url: string,
+    opt?: HttpRequestOptions,
+  ): Promise<HttpResponse> {
+    return this.req("get", url, undefined, opt);
+  }
+
+  async postJson(
+    url: string,
+    body: any,
+    opt?: HttpRequestOptions,
+  ): Promise<HttpResponse> {
+    return this.req("post", url, body, opt);
+  }
+}
\ No newline at end of file
diff --git a/src/headless/helpers.ts b/src/headless/helpers.ts
index 33304cd0..e65914a0 100644
--- a/src/headless/helpers.ts
+++ b/src/headless/helpers.ts
@@ -1,6 +1,6 @@
 /*
  This file is part of GNU Taler
- (C) 2019 GNUnet e.V.
+ (C) 2019 Taler Systems S.A.
 
  GNU Taler is free software; you can redistribute it and/or modify it under the
  terms of the GNU General Public License as published by the Free Software
@@ -16,6 +16,7 @@
 
 /**
  * Helpers to create headless wallets.
+ * @author Florian Dold <address@hidden>
  */
 
 /**
@@ -24,94 +25,20 @@
 import { Wallet } from "../wallet";
 import { MemoryBackend, BridgeIDBFactory, shimIndexedDB } from "idb-bridge";
 import { openTalerDatabase } from "../db";
-import Axios, { AxiosPromise, AxiosResponse } from "axios";
 import {
   HttpRequestLibrary,
-  HttpRequestOptions,
-  Headers,
 } from "../util/http";
 import * as amounts from "../util/amounts";
 import { Bank } from "./bank";
-
 import fs = require("fs");
-import { Logger } from "../util/logging";
 import { NodeThreadCryptoWorkerFactory } from 
"../crypto/workers/nodeThreadWorker";
-import { SynchronousCryptoWorkerFactory } from 
"../crypto/workers/synchronousWorker";
-import { RequestThrottler } from "../util/RequestThrottler";
 import { WalletNotification, NotificationType } from "../types/notifications";
 import { Database } from "../util/query";
+import { NodeHttpLib } from "./NodeHttpLib";
+import { Logger } from "../util/logging";
 
 const logger = new Logger("helpers.ts");
 
-export class NodeHttpLib implements HttpRequestLibrary {
-  private throttle = new RequestThrottler();
-
-  private async req(
-    method: "post" | "get",
-    url: string,
-    body: any,
-    opt?: HttpRequestOptions,
-  ) {
-    if (this.throttle.applyThrottle(url)) {
-      throw Error("request throttled");
-    }
-    let resp: AxiosResponse;
-    try {
-      resp = await Axios({
-        method,
-        url: url,
-        responseType: "text",
-        headers: opt?.headers,
-        validateStatus: () => true,
-        transformResponse: (x) => x,
-        data: body,
-      });
-    } catch (e) {
-      throw e;
-    }
-    const respText = resp.data;
-    if (typeof respText !== "string") {
-      throw Error("unexpected response type");
-    }
-    const makeJson = async () => {
-      let responseJson;
-      try {
-        responseJson = JSON.parse(respText);
-      } catch (e) {
-        throw Error("Invalid JSON from HTTP response");
-      }
-      if (responseJson === null || typeof responseJson !== "object") {
-        throw Error("Invalid JSON from HTTP response");
-      }
-      return responseJson;
-    };
-    const headers = new Headers();
-    for (const hn of Object.keys(resp.headers)) {
-      headers.set(hn, resp.headers[hn]);
-    }
-    return {
-      headers,
-      status: resp.status,
-      text: async () => resp.data,
-      json: makeJson,
-    };
-  }
-
-  async get(
-    url: string,
-    opt?: HttpRequestOptions,
-  ): Promise<import("../util/http").HttpResponse> {
-    return this.req("get", url, undefined, opt);
-  }
-
-  async postJson(
-    url: string,
-    body: any,
-    opt?: HttpRequestOptions,
-  ): Promise<import("../util/http").HttpResponse> {
-    return this.req("post", url, body, opt);
-  }
-}
 
 export interface DefaultNodeWalletArgs {
   /**
diff --git a/src/headless/integrationtest.ts b/src/headless/integrationtest.ts
index 632ce8f6..7c513e70 100644
--- a/src/headless/integrationtest.ts
+++ b/src/headless/integrationtest.ts
@@ -20,8 +20,10 @@
 
 import { getDefaultNodeWallet, withdrawTestBalance } from "./helpers";
 import { MerchantBackendConnection } from "./merchant";
+import { Logger } from "../util/logging";
+import { NodeHttpLib } from "./NodeHttpLib";
 
-const enableTracing = false;
+const logger = new Logger("integrationtest.ts");
 
 export async function runIntegrationTest(args: {
   exchangeBaseUrl: string;
@@ -31,10 +33,16 @@ export async function runIntegrationTest(args: {
   amountToWithdraw: string;
   amountToSpend: string;
 }) {
-  console.log("running test with", args);
-  const myWallet = await getDefaultNodeWallet();
+  logger.info("running test with arguments", args);
 
+  const myHttpLib = new NodeHttpLib();
+  myHttpLib.setThrottling(false);
+
+  const myWallet = await getDefaultNodeWallet({ httpLib: myHttpLib });
+
+  logger.info("withdrawing test balance");
   await withdrawTestBalance(myWallet, args.amountToWithdraw, args.bankBaseUrl, 
args.exchangeBaseUrl);
+  logger.info("done withdrawing test balance");
 
   const balance = await myWallet.getBalances();
 
diff --git a/src/headless/taler-wallet-cli.ts b/src/headless/taler-wallet-cli.ts
index 8d434110..bc83bac2 100644
--- a/src/headless/taler-wallet-cli.ts
+++ b/src/headless/taler-wallet-cli.ts
@@ -423,7 +423,7 @@ testCli
         merchantApiKey: cmdObj.merchantApiKey,
         merchantBaseUrl: cmdObj.merchant,
       }).catch(err => {
-        console.error("Failed with exception:");
+        console.error("Integration test failed with exception:");
         console.error(err);
       });
 
diff --git a/src/util/RequestThrottler.ts b/src/util/RequestThrottler.ts
index c144cb15..01695ec3 100644
--- a/src/util/RequestThrottler.ts
+++ b/src/util/RequestThrottler.ts
@@ -26,7 +26,7 @@ import { getTimestampNow, Timestamp } from 
"../types/walletTypes";
 /**
  * Maximum request per second, per origin.
  */
-const MAX_PER_SECOND = 20;
+const MAX_PER_SECOND = 50;
 
 /**
  * Maximum request per minute, per origin.
@@ -36,7 +36,7 @@ const MAX_PER_MINUTE = 100;
 /**
  * Maximum request per hour, per origin.
  */
-const MAX_PER_HOUR = 5000;
+const MAX_PER_HOUR = 1000;
 
 
 /**
diff --git a/tsconfig.json b/tsconfig.json
index cb2985ae..43ccd7e2 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -37,6 +37,7 @@
     "src/crypto/workers/nodeThreadWorker.ts",
     "src/crypto/workers/synchronousWorker.ts",
     "src/db.ts",
+    "src/headless/NodeHttpLib.ts",
     "src/headless/bank.ts",
     "src/headless/clk.ts",
     "src/headless/helpers.ts",

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]