mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-06-11 01:41:33 +00:00
Add comments
This commit is contained in:
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user