From 864105d5765a500ed5be014b14e0d177f28579f3 Mon Sep 17 00:00:00 2001 From: Abnessor aka Findoff Date: Tue, 13 Oct 2020 13:46:40 +0000 Subject: [PATCH 1/6] fix to node v12 compatibility --- src/module.cc | 2 +- src/tuntap.cc | 49 ++++++++++++++++++++++++++++--------------------- src/tuntap.hh | 6 +++--- 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/src/module.cc b/src/module.cc index 33a1c40..be11cab 100644 --- a/src/module.cc +++ b/src/module.cc @@ -23,7 +23,7 @@ using namespace v8; -void InitAll(Handle exports, Handle module) { +void InitAll(Local exports, Local module) { Tuntap::Init(module); } diff --git a/src/tuntap.cc b/src/tuntap.cc index 8c108db..6cada03 100644 --- a/src/tuntap.cc +++ b/src/tuntap.cc @@ -41,8 +41,9 @@ Tuntap::~Tuntap() { delete[] this->read_buff; } -void Tuntap::Init(Handle module) { +void Tuntap::Init(Local module) { Isolate* isolate = module->GetIsolate(); + Local context = isolate->GetCurrentContext(); // Prepare constructor template Local tpl = FunctionTemplate::New(isolate, New); @@ -62,14 +63,15 @@ void Tuntap::Init(Handle module) { #undef SETFUNC - constructor.Reset(isolate, tpl->GetFunction()); + constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked()); - module->Set(String::NewFromUtf8(isolate, "exports"), tpl->GetFunction()); + module->Set(String::NewFromUtf8(isolate, "exports"), tpl->GetFunction(context).ToLocalChecked()); } void Tuntap::New(const FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); HandleScope scope(isolate); + Local context = isolate->GetCurrentContext(); bool ret; std::string err_str; Local main_obj; @@ -80,7 +82,7 @@ void Tuntap::New(const FunctionCallbackInfo& args) { obj = new Tuntap(); obj->Wrap(args.This()); if(args[0]->IsObject()) { - main_obj = args[0]->ToObject(); + main_obj = args[0]->ToObject(context).ToLocalChecked(); ret = obj->construct(main_obj, err_str); if(ret == false) { obj->fd = -1; @@ -100,7 +102,7 @@ void Tuntap::New(const FunctionCallbackInfo& args) { } } -bool Tuntap::construct(Handle main_obj, std::string &error) { +bool Tuntap::construct(Local main_obj, std::string &error) { Isolate* isolate = main_obj->GetIsolate(); HandleScope scope(isolate); Local keys_arr; @@ -195,6 +197,7 @@ void Tuntap::writeBuffer(const FunctionCallbackInfo& args) { } void Tuntap::open(const FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); + Local context = isolate->GetCurrentContext(); HandleScope scope(isolate); Local main_obj = Object::New(isolate); std::string err_str; @@ -212,7 +215,7 @@ void Tuntap::open(const FunctionCallbackInfo& args) { return; } - main_obj = args[0]->ToObject(); + main_obj = args[0]->ToObject(context).ToLocalChecked(); } ret = obj->construct(main_obj, err_str); @@ -246,6 +249,7 @@ void Tuntap::close(const FunctionCallbackInfo& args) { void Tuntap::set(const FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); + Local context = isolate->GetCurrentContext(); HandleScope scope(isolate); Tuntap *obj = ObjectWrap::Unwrap(args.This()); std::vector options; @@ -260,20 +264,20 @@ void Tuntap::set(const FunctionCallbackInfo& args) { return; } - main_obj = args[0]->ToObject(); + main_obj = args[0]->ToObject(context).ToLocalChecked(); - if(main_obj->Has(String::NewFromUtf8(isolate, "type")) || main_obj->Has(String::NewFromUtf8(isolate, "name"))) { + if(main_obj->Has(context, String::NewFromUtf8(isolate, "type")).ToChecked() || main_obj->Has(context, String::NewFromUtf8(isolate, "name")).ToChecked()) { TT_THROW_TYPE("Cannot set name and type from this function!"); return; } obj->objset(main_obj); - keys_arr = main_obj->GetPropertyNames(); + keys_arr = main_obj->GetPropertyNames(context).ToLocalChecked(); for (unsigned int i = 0, limiti = keys_arr->Length(); i < limiti; i++) { key = keys_arr->Get(i); val = main_obj->Get(key); - String::Utf8Value key_str(key->ToString()); + String::Utf8Value key_str(isolate, key); if(strcmp(*key_str, "addr") == 0) { if(obj->fd) @@ -304,7 +308,7 @@ void Tuntap::set(const FunctionCallbackInfo& args) { options.push_back(tuntap_itf_opts_t::OPT_RUNNING); } else if(strcmp(*key_str, "ethtype_comp") == 0) { - String::Utf8Value val_str(val->ToString()); + String::Utf8Value val_str(isolate, val); if(strcmp(*val_str, "none") == 0) obj->itf_opts.ethtype_comp = TUNTAP_ETCOMP_NONE; @@ -341,7 +345,7 @@ void Tuntap::unset(const FunctionCallbackInfo& args) { for (unsigned int i = 0, limiti = keys_arr->Length(); i < limiti; i++) { val = keys_arr->Get(i); - String::Utf8Value val_str(val->ToString()); + String::Utf8Value val_str(isolate, val); if(strcmp(*val_str, "addr") == 0) { obj->itf_opts.addr = ""; @@ -401,17 +405,20 @@ void Tuntap::startRead(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(args.This()); } -void Tuntap::objset(Handle obj) { +void Tuntap::objset(Local obj) { + Isolate* isolate = obj->GetIsolate(); + Local context = isolate->GetCurrentContext(); + Local keys_arr; Local key; Local val; - keys_arr = obj->GetPropertyNames(); + keys_arr = obj->GetPropertyNames(context).ToLocalChecked(); for (unsigned int i = 0, limiti = keys_arr->Length(); i < limiti; i++) { key = keys_arr->Get(i); val = obj->Get(key); - String::Utf8Value key_str(key->ToString()); - String::Utf8Value val_str(val->ToString()); + String::Utf8Value key_str(isolate, key); + String::Utf8Value val_str(isolate, val); if(strcmp(*key_str, "type") == 0) { if(strcmp(*val_str, "tun") == 0) { @@ -434,21 +441,21 @@ void Tuntap::objset(Handle obj) { this->itf_opts.dest = *val_str; } else if(strcmp(*key_str, "mtu") == 0) { - this->itf_opts.mtu = val->ToInteger()->Value(); + this->itf_opts.mtu = val->ToInteger(context).ToLocalChecked()->Value(); if(this->itf_opts.mtu <= 50) this->itf_opts.mtu = 50; } else if(strcmp(*key_str, "persist") == 0) { - this->itf_opts.is_persistant = val->ToBoolean()->Value(); + this->itf_opts.is_persistant = val->ToBoolean(context).ToLocalChecked()->Value(); } else if(strcmp(*key_str, "up") == 0) { - this->itf_opts.is_up = val->ToBoolean()->Value(); + this->itf_opts.is_up = val->ToBoolean(context).ToLocalChecked()->Value(); } else if(strcmp(*key_str, "running") == 0) { - this->itf_opts.is_running = val->ToBoolean()->Value(); + this->itf_opts.is_running = val->ToBoolean(context).ToLocalChecked()->Value(); } else if(strcmp(*key_str, "ethtype_comp") == 0) { - String::Utf8Value val_str(val->ToString()); + String::Utf8Value val_str(isolate, val); if(strcmp(*val_str, "none") == 0) this->itf_opts.ethtype_comp = TUNTAP_ETCOMP_NONE; diff --git a/src/tuntap.hh b/src/tuntap.hh index 9f2e397..69ed5e8 100644 --- a/src/tuntap.hh +++ b/src/tuntap.hh @@ -26,7 +26,7 @@ class Tuntap : public node::ObjectWrap { public: - static void Init(v8::Handle module); + static void Init(v8::Local module); private: Tuntap(); @@ -62,8 +62,8 @@ class Tuntap : public node::ObjectWrap { int size; }; - bool construct(v8::Handle main_obj, std::string &error); - void objset(v8::Handle obj); + bool construct(v8::Local main_obj, std::string &error); + void objset(v8::Local obj); static void writeBuffer(const v8::FunctionCallbackInfo& args); static void open(const v8::FunctionCallbackInfo& args); static void close(const v8::FunctionCallbackInfo& args); From 8620d00c27181a7e1fc35e1c80b7ea7c0a71270b Mon Sep 17 00:00:00 2001 From: Abnessor aka Findoff Date: Tue, 13 Oct 2020 13:49:43 +0000 Subject: [PATCH 2/6] fill fork info --- README.md | 3 +++ package.json | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7a1d302..6683248 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ node-tuntap =========== +Forked for node v12 compatibility +--------------------------------- + Node-tuntap is a node module that allows creating and using [`tun` and `tap` interfaces](https://en.wikipedia.org/wiki/TUN/TAP) in javascript. diff --git a/package.json b/package.json index 9af99d0..f0b25f8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "node-tuntap", - "version": "1.0.6", + "name": "@findoff/node-tuntap", + "version": "2.0.0", "description": "Tunnel interface management in node", "author": "Maxime Ferrino", "repository": { @@ -20,9 +20,9 @@ }, "gypfile": true, "bugs": { - "url": "https://github.com/binarysec/node-tuntap/issues" + "url": "https://github.com/findoff/node-tuntap/issues" }, - "homepage": "https://github.com/binarysec/node-tuntap", + "homepage": "https://github.com/findoff/node-tuntap", "license": "GPLv3", "os" : [ "!win32" ] } From 9c46d089e5dd722782fa9326d18a7af896c9a412 Mon Sep 17 00:00:00 2001 From: gtnoble Date: Fri, 26 Aug 2022 12:48:52 -0500 Subject: [PATCH 3/6] Fixes compilation errors with Node v16 Filled fork info --- .gitignore | 4 +++- README.md | 2 +- package.json | 16 +++++++++------- src/module.hh | 4 ++-- src/tuntap.cc | 23 ++++++++++++----------- 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 42afabf..e6f8fe3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -/build \ No newline at end of file +/build +/node_modules +package-lock.json \ No newline at end of file diff --git a/README.md b/README.md index 6683248..968bc8a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ node-tuntap =========== -Forked for node v12 compatibility +Forked for node v16 compatibility --------------------------------- Node-tuntap is a node module that allows creating and using [`tun` and `tap` diff --git a/package.json b/package.json index f0b25f8..39d5011 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { - "name": "@findoff/node-tuntap", - "version": "2.0.0", + "name": "@gtnoble/node-tuntap", + "version": "3.0.0", "description": "Tunnel interface management in node", - "author": "Maxime Ferrino", + "author": "Garret Noble", "repository": { "type": "git", - "url": "https://github.com/binarysec/node-tuntap.git" + "url": "https://github.com/gtnoble/node-tuntap.git" }, "keywords": [ "tunnel", @@ -20,9 +20,11 @@ }, "gypfile": true, "bugs": { - "url": "https://github.com/findoff/node-tuntap/issues" + "url": "https://github.com/gtnoble/node-tuntap/issues" }, - "homepage": "https://github.com/findoff/node-tuntap", + "homepage": "https://github.com/gtnoble/node-tuntap", "license": "GPLv3", - "os" : [ "!win32" ] + "os": [ + "!win32" + ] } diff --git a/src/module.hh b/src/module.hh index 21ea379..2ac2a73 100644 --- a/src/module.hh +++ b/src/module.hh @@ -43,10 +43,10 @@ #include "tuntap.hh" #define TT_THROW(str) \ - isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, str))) + isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, str).ToLocalChecked())) #define TT_THROW_TYPE(str) \ - isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, str))) + isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, str).ToLocalChecked())) #define NVM_NEW_INSTANCE(target, isolate, argc, argv) ( \ (target) \ diff --git a/src/tuntap.cc b/src/tuntap.cc index 6cada03..459a58d 100644 --- a/src/tuntap.cc +++ b/src/tuntap.cc @@ -47,7 +47,7 @@ void Tuntap::Init(Local module) { // Prepare constructor template Local tpl = FunctionTemplate::New(isolate, New); - tpl->SetClassName(String::NewFromUtf8(isolate, "tuntap")); + tpl->SetClassName(String::NewFromUtf8(isolate, "tuntap").ToLocalChecked()); tpl->InstanceTemplate()->SetInternalFieldCount(1); // Prototype @@ -65,7 +65,7 @@ void Tuntap::Init(Local module) { constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked()); - module->Set(String::NewFromUtf8(isolate, "exports"), tpl->GetFunction(context).ToLocalChecked()); + module->Set(context, String::NewFromUtf8(isolate, "exports").ToLocalChecked(), tpl->GetFunction(context).ToLocalChecked()); } void Tuntap::New(const FunctionCallbackInfo& args) { @@ -266,7 +266,7 @@ void Tuntap::set(const FunctionCallbackInfo& args) { main_obj = args[0]->ToObject(context).ToLocalChecked(); - if(main_obj->Has(context, String::NewFromUtf8(isolate, "type")).ToChecked() || main_obj->Has(context, String::NewFromUtf8(isolate, "name")).ToChecked()) { + if(main_obj->Has(context, String::NewFromUtf8(isolate, "type").ToLocalChecked()).ToChecked() || main_obj->Has(context, String::NewFromUtf8(isolate, "name").ToLocalChecked()).ToChecked()) { TT_THROW_TYPE("Cannot set name and type from this function!"); return; } @@ -275,8 +275,8 @@ void Tuntap::set(const FunctionCallbackInfo& args) { keys_arr = main_obj->GetPropertyNames(context).ToLocalChecked(); for (unsigned int i = 0, limiti = keys_arr->Length(); i < limiti; i++) { - key = keys_arr->Get(i); - val = main_obj->Get(key); + key = keys_arr->Get(context, i).ToLocalChecked(); + val = main_obj->Get(context, key).ToLocalChecked(); String::Utf8Value key_str(isolate, key); if(strcmp(*key_str, "addr") == 0) { @@ -329,6 +329,7 @@ void Tuntap::set(const FunctionCallbackInfo& args) { void Tuntap::unset(const FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); + Local context = isolate->GetCurrentContext(); HandleScope scope(isolate); Tuntap *obj = ObjectWrap::Unwrap(args.This()); std::vector options; @@ -344,7 +345,7 @@ void Tuntap::unset(const FunctionCallbackInfo& args) { keys_arr = args[0].As(); for (unsigned int i = 0, limiti = keys_arr->Length(); i < limiti; i++) { - val = keys_arr->Get(i); + val = keys_arr->Get(context, i).ToLocalChecked(); String::Utf8Value val_str(isolate, val); if(strcmp(*val_str, "addr") == 0) { @@ -415,8 +416,8 @@ void Tuntap::objset(Local obj) { keys_arr = obj->GetPropertyNames(context).ToLocalChecked(); for (unsigned int i = 0, limiti = keys_arr->Length(); i < limiti; i++) { - key = keys_arr->Get(i); - val = obj->Get(key); + key = keys_arr->Get(context, i).ToLocalChecked(); + val = obj->Get(context, key).ToLocalChecked(); String::Utf8Value key_str(isolate, key); String::Utf8Value val_str(isolate, val); @@ -446,13 +447,13 @@ void Tuntap::objset(Local obj) { this->itf_opts.mtu = 50; } else if(strcmp(*key_str, "persist") == 0) { - this->itf_opts.is_persistant = val->ToBoolean(context).ToLocalChecked()->Value(); + this->itf_opts.is_persistant = val->ToBoolean(isolate)->Value(); } else if(strcmp(*key_str, "up") == 0) { - this->itf_opts.is_up = val->ToBoolean(context).ToLocalChecked()->Value(); + this->itf_opts.is_up = val->ToBoolean(isolate)->Value(); } else if(strcmp(*key_str, "running") == 0) { - this->itf_opts.is_running = val->ToBoolean(context).ToLocalChecked()->Value(); + this->itf_opts.is_running = val->ToBoolean(isolate)->Value(); } else if(strcmp(*key_str, "ethtype_comp") == 0) { String::Utf8Value val_str(isolate, val); From 530165e908b89c344353095e60f486177e11716e Mon Sep 17 00:00:00 2001 From: gtnoble Date: Sun, 28 Aug 2022 18:24:22 -0500 Subject: [PATCH 4/6] Update project files --- .npmignore | 1 + package.json | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 .npmignore diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..c795b05 --- /dev/null +++ b/.npmignore @@ -0,0 +1 @@ +build \ No newline at end of file diff --git a/package.json b/package.json index 39d5011..ff34d38 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gtnoble/node-tuntap", - "version": "3.0.0", + "version": "2.1.0", "description": "Tunnel interface management in node", "author": "Garret Noble", "repository": { @@ -14,10 +14,13 @@ "tuntap", "interface" ], - "main": "./index.js", - "scripts": { - "install": "node-gyp rebuild" + "dependencies": { + "node-gyp": ">=9.1.0" + }, + "devDependencies": { + "node-gyp": ">=9.1.0" }, + "main": "./index.js", "gypfile": true, "bugs": { "url": "https://github.com/gtnoble/node-tuntap/issues" From 13a64671d9eba2a6e3433ace56b0a152cd34faa4 Mon Sep 17 00:00:00 2001 From: gtnoble Date: Sun, 28 Aug 2022 20:45:17 -0500 Subject: [PATCH 5/6] Removed unnecessary makefile --- Makefile | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 Makefile diff --git a/Makefile b/Makefile deleted file mode 100644 index ea3ecb4..0000000 --- a/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -all: build - -build: build/Release/tuntap.node - -build/Release/tuntap.node: src/*.cc src/*.hh src/tuntap-itf/*.cc src/tuntap-itf/*.hh - node-gyp build - -config: configure - -configure: - node-gyp configure - -clean: - node-gyp clean - -rebuild: - node-gyp clean configure build From d33633a3cfaef02ac3a5e455810fc3e345938db0 Mon Sep 17 00:00:00 2001 From: gtnoble Date: Sun, 28 Aug 2022 21:01:11 -0500 Subject: [PATCH 6/6] Include updated installation instructions --- README.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/README.md b/README.md index 968bc8a..ed0b236 100644 --- a/README.md +++ b/README.md @@ -37,11 +37,7 @@ Simple sample : Building/installing ------------------- - -To build the module, just run `make`. *node-gyp* is required to build it. - -There is currently no way to install it. You will have to copy the files in -the right places by hand. +`npm install @gtnoble/node-tuntap` Available options -----------------