From 6ee5c70af9cdba34814f5de2224e71e721da6c8e Mon Sep 17 00:00:00 2001 From: Belma Gutlic Date: Mon, 13 Jan 2020 18:25:28 +0100 Subject: [PATCH] Address PR comment --- package.json | 1 - src/keycache.ts | 23 ++--------------------- yarn.lock | 5 ----- 3 files changed, 2 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index da6919f..2babf57 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,6 @@ "typescript": "^3.6.4" }, "dependencies": { - "async-mutex": "^0.1.4", "bcrypto": "^4.2.3", "bn.js": "^5.0.0", "buffer": "^5.4.3", diff --git a/src/keycache.ts b/src/keycache.ts index 2d1028d..bf96f5e 100644 --- a/src/keycache.ts +++ b/src/keycache.ts @@ -1,4 +1,3 @@ -import {Mutex} from 'async-mutex'; import {PeerId} from "./@types/libp2p"; import {bytes, bytes32} from "./@types/basic"; @@ -6,32 +5,14 @@ import {bytes, bytes32} from "./@types/basic"; * Storage for static keys of previously connected peers. */ class Keycache { - private mutex: Mutex; private storage = new Map(); - constructor() { - this.mutex = new Mutex(); - } - public async store(peerId: PeerId, key: bytes32): Promise { - const release = await this.mutex.acquire(); - try { - this.storage.set(peerId.id, key); - } finally { - release(); - } + this.storage.set(peerId.id, key); } public async load(peerId: PeerId): Promise { - const release = await this.mutex.acquire(); - let key; - try { - key = this.storage.get(peerId.id) || null; - } finally { - release(); - } - - return key; + return this.storage.get(peerId.id) || null; } public resetStorage(): void { diff --git a/yarn.lock b/yarn.lock index ed561c7..63ec7c9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1086,11 +1086,6 @@ async-each@^1.0.1: resolved "https://registry.yarnpkg.com/async-each/-/async-each-1.0.3.tgz#b727dbf87d7651602f06f4d4ac387f47d91b0cbf" integrity sha512-z/WhQ5FPySLdvREByI2vZiTWwCnF0moMJ1hK9YQwDTHKh6I7/uSckMetoRGb5UBZPC1z0jlw+n/XCgjeH7y1AQ== -async-mutex@^0.1.4: - version "0.1.4" - resolved "https://registry.yarnpkg.com/async-mutex/-/async-mutex-0.1.4.tgz#a47d1eebf584f7dcdd760e3642dc2c58613bef5c" - integrity sha512-zVWTmAnxxHaeB2B1te84oecI8zTDJ/8G49aVBblRX6be0oq6pAybNcUSxwfgVOmOjSCvN4aYZAqwtyNI8e1YGw== - atob@^2.1.1: version "2.1.2" resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9"