Add comments

This commit is contained in:
Belma Gutlic
2020-01-13 16:40:42 +01:00
parent 7d22967197
commit 52195afe18
2 changed files with 10 additions and 3 deletions

View File

@ -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<bytes, bytes32>();
@ -32,6 +34,10 @@ class Keycache {
return key;
}
public resetStorage(): void {
this.storage.clear();
}
}
const KeyCache = new Keycache();

View File

@ -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);
}
}