mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-04-25 14:32:18 +00:00
Address PR comment
This commit is contained in:
parent
52195afe18
commit
6ee5c70af9
@ -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",
|
||||
|
@ -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<bytes, bytes32>();
|
||||
|
||||
constructor() {
|
||||
this.mutex = new Mutex();
|
||||
}
|
||||
|
||||
public async store(peerId: PeerId, key: bytes32): Promise<void> {
|
||||
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<bytes32|null> {
|
||||
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 {
|
||||
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user