mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-06-16 18:41:32 +00:00
Add comments
This commit is contained in:
@ -2,7 +2,9 @@ import {Mutex} from 'async-mutex';
|
|||||||
import {PeerId} from "./@types/libp2p";
|
import {PeerId} from "./@types/libp2p";
|
||||||
import {bytes, bytes32} from "./@types/basic";
|
import {bytes, bytes32} from "./@types/basic";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Storage for static keys of previously connected peers.
|
||||||
|
*/
|
||||||
class Keycache {
|
class Keycache {
|
||||||
private mutex: Mutex;
|
private mutex: Mutex;
|
||||||
private storage = new Map<bytes, bytes32>();
|
private storage = new Map<bytes, bytes32>();
|
||||||
@ -32,6 +34,10 @@ class Keycache {
|
|||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public resetStorage(): void {
|
||||||
|
this.storage.clear();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const KeyCache = new Keycache();
|
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 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 connection
|
||||||
* @param isInitiator
|
* @param isInitiator
|
||||||
* @param libp2pPublicKey
|
* @param libp2pPublicKey
|
||||||
@ -122,11 +122,12 @@ export class Noise implements INoiseConnection {
|
|||||||
try {
|
try {
|
||||||
return await this.performIKHandshake(IKhandshake, payload);
|
return await this.performIKHandshake(IKhandshake, payload);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// XX fallback
|
// IK failed, go to XX fallback
|
||||||
const ephemeralKeys = IKhandshake.getRemoteEphemeralKeys();
|
const ephemeralKeys = IKhandshake.getRemoteEphemeralKeys();
|
||||||
return await this.performXXFallbackHandshake(params, payload, ephemeralKeys, e.initialMsg);
|
return await this.performXXFallbackHandshake(params, payload, ephemeralKeys, e.initialMsg);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Noise pipes not supported, use XX
|
||||||
return await this.performXXHandshake(params, payload);
|
return await this.performXXHandshake(params, payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user