-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
30 lines (23 loc) · 722 Bytes
/
index.js
File metadata and controls
30 lines (23 loc) · 722 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// store tls session tickets for session resumption
// TODO: add redis
const QuickLRU = require('quick-lru');
module.exports = (server, options) => {
if (!server) {
throw new Error('Missing server argument - [https,tls].createServer()');
}
if (!server._sharedCreds) {
throw new Error('Server is not TLS');
}
options = options || {};
if (!options.hasOwnProperty('maxCachedSessions')) {
options.maxCachedSessions = 100;
}
const lru = new QuickLRU({maxSize: options.maxCachedSessions});
server.on('newSession', (id, data, cb) => {
lru.set(id.toString('hex'),data);
cb();
});
server.on('resumeSession', (id, cb) => {
cb(null, lru.get(id.toString('hex')) || null);
});
};