Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 15 additions & 0 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ namespace node {
using v8::Context;
using v8::FunctionTemplate;
using v8::HandleScope;
using v8::Integer;
using v8::Isolate;
using v8::Local;
using v8::Message;
using v8::Number;
using v8::Private;
using v8::StackFrame;
using v8::StackTrace;
using v8::String;
using v8::Value;

IsolateData::IsolateData(Isolate* isolate,
uv_loop_t* event_loop,
Expand Down Expand Up @@ -341,6 +344,18 @@ void Environment::ToggleImmediateRef(bool ref) {
}


Local<Value> Environment::GetNow() {
uv_update_time(event_loop());
uint64_t now = uv_now(event_loop());
CHECK(now >= timer_base());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CHECK_GE

(Sorry, probably forgot to mention that last time.)

now -= timer_base();
if (now <= 0xfffffff)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could go until at least 0x7fffffff here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that might actually be missing an extra f? I think it's supposed to be 2**32 - 1, no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apapirovski If you want that then yes, one more f than in the current code it is (0xffffffff)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, looks like that's been incorrect since it got first committed like 3-4 years ago :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! :)

return Integer::New(isolate(), static_cast<uint32_t>(now));
else
return Number::New(isolate(), static_cast<double>(now));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The this-> prefixes aren't necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Total brain fart there, haha.



void CollectExceptionInfo(Environment* env,
v8::Local<v8::Object> obj,
int errorno,
Expand Down
2 changes: 2 additions & 0 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,8 @@ class Environment {

static inline Environment* ForAsyncHooks(AsyncHooks* hooks);

v8::Local<v8::Value> GetNow();

private:
inline void CreateImmediate(native_immediate_callback cb,
void* data,
Expand Down
16 changes: 2 additions & 14 deletions src/timer_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ using v8::FunctionTemplate;
using v8::HandleScope;
using v8::Integer;
using v8::Local;
using v8::Number;
using v8::Object;
using v8::String;
using v8::Value;
Expand Down Expand Up @@ -142,7 +141,7 @@ class TimerWrap : public HandleWrap {
Local<Value> ret;
Local<Value> args[1];
do {
args[0] = GetNow(env);
args[0] = env->GetNow();
ret = wrap->MakeCallback(kOnTimeout, 1, args).ToLocalChecked();
} while (ret->IsUndefined() &&
!env->tick_info()->has_thrown() &&
Expand All @@ -153,18 +152,7 @@ class TimerWrap : public HandleWrap {

static void Now(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
args.GetReturnValue().Set(GetNow(env));
}

static Local<Value> GetNow(Environment* env) {
uv_update_time(env->event_loop());
uint64_t now = uv_now(env->event_loop());
CHECK(now >= env->timer_base());
now -= env->timer_base();
if (now <= 0xfffffff)
return Integer::New(env->isolate(), static_cast<uint32_t>(now));
else
return Number::New(env->isolate(), static_cast<double>(now));
args.GetReturnValue().Set(env->GetNow());
}

uv_timer_t handle_;
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