事件:'resumeSession'
【Event: 'resumeSession'】
当客户端请求恢复之前的 TLS 会话时,会触发 'resumeSession' 事件。调用监听器回调时会传入两个参数:
【The 'resumeSession' event is emitted when the client requests to resume a
previous TLS session. The listener callback is passed two arguments when
called:】
sessionId<Buffer> TLS 会话标识符callback<Function> 当先前的会话已恢复时要调用的回调函数:callback([err[, sessionData]])
事件监听器应使用给定的 sessionId 在外部存储中查找由 'newSession' 事件处理程序保存的 sessionData。如果找到,请调用 callback(null, sessionData) 以恢复会话。如果未找到,则无法恢复会话。必须调用 callback() 而不带 sessionData,以便握手可以继续并创建新会话。也可以调用 callback(err) 来终止传入连接并销毁套接字。
【The event listener should perform a lookup in external storage for the
sessionData saved by the 'newSession' event handler using the given
sessionId. If found, call callback(null, sessionData) to resume the session.
If not found, the session cannot be resumed. callback() must be called
without sessionData so that the handshake can continue and a new session can
be created. It is possible to call callback(err) to terminate the incoming
connection and destroy the socket.】
监听此事件只会对在添加事件监听器之后建立的连接产生影响。
【Listening for this event will have an effect only on connections established after the addition of the event listener.】
以下说明恢复 TLS 会话:
【The following illustrates resuming a TLS session:】
const tlsSessionStore = {};
server.on('newSession', (id, data, cb) => {
tlsSessionStore[id.toString('hex')] = data;
cb();
});
server.on('resumeSession', (id, cb) => {
cb(null, tlsSessionStore[id.toString('hex')] || null);
});