Skip to content

Commit

Permalink
tls: provide now value from C++
Browse files Browse the repository at this point in the history
Instead of separately calling into C++ from JS to retrieve
the Timer.now() value, pass it in as an argument.
  • Loading branch information
apapirovski committed Feb 4, 2018
1 parent 28fbd73 commit f24c570
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
8 changes: 3 additions & 5 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const common = require('_tls_common');
const { StreamWrap } = require('_stream_wrap');
const { Buffer } = require('buffer');
const debug = util.debuglog('tls');
const { Timer } = process.binding('timer_wrap');
const tls_wrap = process.binding('tls_wrap');
const { TCP, constants: TCPConstants } = process.binding('tcp_wrap');
const { Pipe, constants: PipeConstants } = process.binding('pipe_wrap');
Expand All @@ -49,14 +48,13 @@ const kSNICallback = Symbol('snicallback');

const noop = () => {};

function onhandshakestart() {
function onhandshakestart(now) {
debug('onhandshakestart');

const owner = this.owner;
const now = Timer.now();

assert(now >= this.lastHandshakeTime);

const owner = this.owner;

if ((now - this.lastHandshakeTime) >= tls.CLIENT_RENEG_WINDOW * 1000) {
this.handshakes = 0;
}
Expand Down
3 changes: 2 additions & 1 deletion src/tls_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ void TLSWrap::SSLInfoCallback(const SSL* ssl_, int where, int ret) {
if (where & SSL_CB_HANDSHAKE_START) {
Local<Value> callback = object->Get(env->onhandshakestart_string());
if (callback->IsFunction()) {
c->MakeCallback(callback.As<Function>(), 0, nullptr);
Local<Value> argv[] = { env->GetNow() };
c->MakeCallback(callback.As<Function>(), arraysize(argv), argv);
}
}

Expand Down

0 comments on commit f24c570

Please sign in to comment.