From 52195afe18ad9a4f1bd4570c108da972c02589a0 Mon Sep 17 00:00:00 2001 From: Belma Gutlic Date: Mon, 13 Jan 2020 16:40:42 +0100 Subject: [PATCH] Add comments --- src/keycache.ts | 8 +++++++- src/noise.ts | 5 +++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/keycache.ts b/src/keycache.ts index ea65a94..2d1028d 100644 --- a/src/keycache.ts +++ b/src/keycache.ts @@ -2,7 +2,9 @@ import {Mutex} from 'async-mutex'; import {PeerId} from "./@types/libp2p"; import {bytes, bytes32} from "./@types/basic"; - +/** + * Storage for static keys of previously connected peers. + */ class Keycache { private mutex: Mutex; private storage = new Map(); @@ -32,6 +34,10 @@ class Keycache { return key; } + public resetStorage(): void { + this.storage.clear(); + } + } const KeyCache = new Keycache(); diff --git a/src/noise.ts b/src/noise.ts index 0a2a7a0..cebdec9 100644 --- a/src/noise.ts +++ b/src/noise.ts @@ -99,7 +99,7 @@ export class Noise implements INoiseConnection { /** * If Noise pipes supported, tries IK handshake first with XX as fallback if it fails. - * If remote peer static key is unknown, use XX. + * If noise pipes disabled or remote peer static key is unknown, use XX. * @param connection * @param isInitiator * @param libp2pPublicKey @@ -122,11 +122,12 @@ export class Noise implements INoiseConnection { try { return await this.performIKHandshake(IKhandshake, payload); } catch (e) { - // XX fallback + // IK failed, go to XX fallback const ephemeralKeys = IKhandshake.getRemoteEphemeralKeys(); return await this.performXXFallbackHandshake(params, payload, ephemeralKeys, e.initialMsg); } } else { + // Noise pipes not supported, use XX return await this.performXXHandshake(params, payload); } }