diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-08-06 00:30:36 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-08-06 00:30:36 +0530 |
commit | 82a2437c0967871d6b942105c98c3382978cad29 (patch) | |
tree | da803c3d4a58d9c691f5908b379791c8ee55cc37 /packages/taler-wallet-core/src/crypto | |
parent | a8f03d3dd1ad04abf7f569cb44933b6dce6713e7 (diff) | |
download | wallet-core-82a2437c0967871d6b942105c98c3382978cad29.tar.xz |
towards integration tests with fault injection
Diffstat (limited to 'packages/taler-wallet-core/src/crypto')
-rw-r--r-- | packages/taler-wallet-core/src/crypto/workers/cryptoApi.ts | 12 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/crypto/workers/nodeThreadWorker.ts | 19 |
2 files changed, 24 insertions, 7 deletions
diff --git a/packages/taler-wallet-core/src/crypto/workers/cryptoApi.ts b/packages/taler-wallet-core/src/crypto/workers/cryptoApi.ts index a272d5724..20d13a3f2 100644 --- a/packages/taler-wallet-core/src/crypto/workers/cryptoApi.ts +++ b/packages/taler-wallet-core/src/crypto/workers/cryptoApi.ts @@ -1,17 +1,17 @@ /* - This file is part of TALER + This file is part of GNU Taler (C) 2016 GNUnet e.V. - TALER is free software; you can redistribute it and/or modify it under the + 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. - TALER is distributed in the hope that it will be useful, but WITHOUT ANY + 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 - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ /** @@ -46,6 +46,7 @@ import { import * as timer from "../../util/timer"; import { Logger } from "../../util/logging"; +import { walletCoreApi } from "../.."; const logger = new Logger("cryptoApi.ts"); @@ -182,7 +183,7 @@ export class CryptoApi { }; this.resetWorkerTimeout(ws); work.startTime = timer.performanceNow(); - setTimeout(() => worker.postMessage(msg), 0); + timer.after(0, () => worker.postMessage(msg)); } resetWorkerTimeout(ws: WorkerState): void { @@ -198,6 +199,7 @@ export class CryptoApi { } }; ws.terminationTimerHandle = timer.after(15 * 1000, destroy); + //ws.terminationTimerHandle.unref(); } handleWorkerError(ws: WorkerState, e: any): void { diff --git a/packages/taler-wallet-core/src/crypto/workers/nodeThreadWorker.ts b/packages/taler-wallet-core/src/crypto/workers/nodeThreadWorker.ts index 6c9dfc569..d4d858330 100644 --- a/packages/taler-wallet-core/src/crypto/workers/nodeThreadWorker.ts +++ b/packages/taler-wallet-core/src/crypto/workers/nodeThreadWorker.ts @@ -21,6 +21,9 @@ import { CryptoWorkerFactory } from "./cryptoApi"; import { CryptoWorker } from "./cryptoWorker"; import os from "os"; import { CryptoImplementation } from "./cryptoImplementation"; +import { Logger } from "../../util/logging"; + +const logger = new Logger("nodeThreadWorker.ts"); const f = __filename; @@ -37,16 +40,22 @@ const workerCode = ` try { tw = require("${f}"); } catch (e) { - console.log("could not load from ${f}"); + console.warn("could not load from ${f}"); } if (!tw) { try { tw = require("taler-wallet-android"); } catch (e) { - console.log("could not load taler-wallet-android either"); + console.warn("could not load taler-wallet-android either"); throw e; } } + if (typeof tw.handleWorkerMessage !== "function") { + throw Error("module loaded for crypto worker lacks handleWorkerMessage"); + } + if (typeof tw.handleWorkerError !== "function") { + throw Error("module loaded for crypto worker lacks handleWorkerError"); + } parentPort.on("message", tw.handleWorkerMessage); parentPort.on("error", tw.handleWorkerError); `; @@ -138,6 +147,9 @@ class NodeThreadCryptoWorker implements CryptoWorker { constructor() { // eslint-disable-next-line @typescript-eslint/no-var-requires const worker_threads = require("worker_threads"); + + logger.trace("starting node crypto worker"); + this.nodeWorker = new worker_threads.Worker(workerCode, { eval: true }); this.nodeWorker.on("error", (err: Error) => { console.error("error in node worker:", err); @@ -145,6 +157,9 @@ class NodeThreadCryptoWorker implements CryptoWorker { this.onerror(err); } }); + this.nodeWorker.on("exit", (err) => { + logger.trace(`worker exited with code ${err}`); + }); this.nodeWorker.on("message", (v: any) => { if (this.onmessage) { this.onmessage(v); |