From 8d658a29a218cc629d333bd2648d030893d702f6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Jan 2024 12:07:46 +0000 Subject: [PATCH 1/2] Bump ref-napi from 1.4.3 to 3.0.3 Bumps [ref-napi](https://github.com/node-ffi-napi/ref-napi) from 1.4.3 to 3.0.3. - [Release notes](https://github.com/node-ffi-napi/ref-napi/releases) - [Changelog](https://github.com/node-ffi-napi/ref-napi/blob/latest/CHANGELOG.md) - [Commits](https://github.com/node-ffi-napi/ref-napi/compare/v1.4.3...v3.0.3) --- updated-dependencies: - dependency-name: ref-napi dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- package-lock.json | 67 +++++++++++++++++++++++++++++++---------------- package.json | 2 +- 2 files changed, 45 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index 18fe92c..478b3f3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -658,14 +658,6 @@ "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", "dev": true }, - "bindings": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", - "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", - "requires": { - "file-uri-to-path": "1.0.0" - } - }, "bluebird": { "version": "3.7.2", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", @@ -1118,11 +1110,6 @@ } } }, - "file-uri-to-path": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", - "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==" - }, "fill-range": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", @@ -3107,19 +3094,23 @@ } }, "ref-napi": { - "version": "1.4.3", - "resolved": "https://registry.npmjs.org/ref-napi/-/ref-napi-1.4.3.tgz", - "integrity": "sha512-yE98eVwjpeGSbHjahn+hNlheGgKdV3gCW1rSj7HZL4ITzBhRb0HlUapWamRcAjZebPr3yuhvxeKFmso8NbRv5g==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/ref-napi/-/ref-napi-3.0.3.tgz", + "integrity": "sha512-LiMq/XDGcgodTYOMppikEtJelWsKQERbLQsYm0IOOnzhwE9xYZC7x8txNnFC9wJNOkPferQI4vD4ZkC0mDyrOA==", "requires": { - "bindings": "^1.3.0", - "debug": "^3.1.0", - "node-addon-api": "^2.0.0" + "debug": "^4.1.1", + "get-symbol-from-current-process-h": "^1.0.2", + "node-addon-api": "^3.0.0", + "node-gyp-build": "^4.2.1" }, "dependencies": { - "node-addon-api": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.0.tgz", - "integrity": "sha512-ASCL5U13as7HhOExbT6OlWJJUV/lLzL2voOSP1UVehpRD8FbSrSDjfScK/KwAvVTI5AS6r4VwbOMlIqtvRidnA==" + "debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "requires": { + "ms": "2.1.2" + } } } }, @@ -3152,6 +3143,36 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + }, + "node-addon-api": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.2.tgz", + "integrity": "sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA==" + }, + "ref-napi": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/ref-napi/-/ref-napi-1.5.2.tgz", + "integrity": "sha512-hwyNmWpUkt1bDWDW4aiwCoC+SJfJO69UIdjqssNqdaS0sYJpgqzosGg/rLtk69UoQ8drZdI9yyQefM7eEMM3Gw==", + "requires": { + "debug": "^3.1.0", + "node-addon-api": "^2.0.0", + "node-gyp-build": "^4.2.1" + }, + "dependencies": { + "debug": { + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", + "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", + "requires": { + "ms": "^2.1.1" + } + }, + "ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + } + } } } }, diff --git a/package.json b/package.json index d2ac524..0bfaf8f 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "dependencies": { "ffi-napi": "^4.0.3", "ref-array-napi": "^1.2.0", - "ref-napi": "^1.4.3", + "ref-napi": "^3.0.3", "ref-struct-napi": "^1.1.0", "underscore": "^1.12.1" }, From f46bdf43b27feb00279f6c37cff829e910a7414a Mon Sep 17 00:00:00 2001 From: iphydf Date: Tue, 2 Jan 2024 11:27:00 +0000 Subject: [PATCH 2/2] fix: Make js-toxcore-c compatible with ref-napi 2 and higher. --- lib/tox.js | 41 ++++++++++++++++++++++++++--------------- test/tox.js | 2 +- tools/local-dev.sh | 5 +++++ 3 files changed, 32 insertions(+), 16 deletions(-) create mode 100755 tools/local-dev.sh diff --git a/lib/tox.js b/lib/tox.js index 9309d07..7440cb8 100644 --- a/lib/tox.js +++ b/lib/tox.js @@ -204,7 +204,9 @@ Tox.prototype.inspect = function () { Object.keys(this).forEach(function (k) { obj[k] = this[k]; // Hacky fix for StringSlice assert error: - // void node::Buffer::StringSlice(const v8::FunctionCallbackInfo&) [with node::encoding encoding = (node::encoding)5u]: Assertion `obj_data != __null' failed. + // void node::Buffer::StringSlice(const + // v8::FunctionCallbackInfo&) [with node::encoding encoding = + // (node::encoding)5u]: Assertion `obj_data != __null' failed. if (k === "_options") { // linting is weird and wants us to specifically `.toString()` this obj[k.toString()] = "[ToxOptions]"; @@ -2346,7 +2348,8 @@ Tox.prototype.getSecretKeyHexSync = function () { /** * Check if this Tox instance has a handle associated with it. * @private - * @param {Tox~errorCallback} callback - Callback to pass Error object to if no handle + * @param {Tox~errorCallback} callback - Callback to pass Error object to if no + * handle * @return {Boolean} true if has handle (no error), false if no handle (error) */ Tox.prototype._checkHandle = function (callback) { @@ -2516,20 +2519,22 @@ Tox.prototype._fixFileControl = function (control) { }; /** - * Fix a send lossless packet value. Adds magic byte(160) to the first byte of data + * Fix a send lossless packet value. Adds magic byte(160) to the first byte of + * data * @private * @param {Buffer} data * @return {Buffer} new data */ Tox.prototype._fixSendLosslessPacket = function (data) { - //160: magic byte + // 160: magic byte return Buffer.concat([Buffer.from([160]), data]); }; /** * Fix a lossless/lossy packet buffer by prepending an id byte. * @private - * @param {Number} id - Byte to prepend, according to tox.h it should be in the range + * @param {Number} id - Byte to prepend, according to tox.h it should be in the + * range * [160, 191] if lossless and [200, 254] if lossy. * @param {Buffer} data - Data buffer to prepend to * @return {Buffer} new data @@ -2613,6 +2618,9 @@ Tox.prototype._setProxyToToxOptions = function (opts, options) { // Store in "this' so it isn"t GC-d? this._proxyAddress = Buffer.from(proxy.address + "\0"); options.proxy_address = this._proxyAddress; + // TODO(iphydf): Weird hack here to make sure getOptions works. + // Remove this and see tests fail. + ref.reinterpretUntilZeros(this._proxyAddress, ref.types.char.size); } // Set port @@ -2624,7 +2632,8 @@ Tox.prototype._setProxyToToxOptions = function (opts, options) { }; /** - * Store an ffi.Callback. This is to prevent an annoying ffi garbage collection bug. + * Store an ffi.Callback. This is to prevent an annoying ffi garbage collection + * bug. * @private * @param {Object} key - Key * @param {ffi.Callback} callback - Callback @@ -2652,7 +2661,8 @@ Tox.prototype._toFFICallback = function (ffiFunc, callback) { ///////////////////// /** - * Used in: Tox#bootstrap(), Tox#bootstrapSync(), Tox#addTCPRelay(), Tox#addTCPRelaySync(). + * Used in: Tox#bootstrap(), Tox#bootstrapSync(), Tox#addTCPRelay(), + * Tox#addTCPRelaySync(). * @private */ Tox.prototype._performBootstrap = function (opts) { @@ -3274,8 +3284,8 @@ Tox.prototype._initFileRecvChunkCb = function () { cb: FileRecvChunkCallback, name: "FileRecvChunkCallback", wrapper: function (handle, friend, file, position, data, size, userdata) { - // Apparently data can sometimes be a NULL pointer, set data to undefined if so - // This should only happen on final chunk? + // Apparently data can sometimes be a NULL pointer, set data to undefined + // if so This should only happen on final chunk? if (ref.address(data) !== 0) { data = Buffer.from(ref.reinterpret(data, size)); // Copy to another Buffer } else { @@ -3297,12 +3307,13 @@ Tox.prototype._initFriendLosslessPacketCb = function () { cb: FriendLosslessPacketCallback, name: "FriendLosslessPacketCallback", wrapper: function (handle, friend, data, length, userdata) { - //if(ref.address(data) !== 0) { - // //first byte is magic byte(160) so ignore it - // data = Buffer.from(ref.reinterpret(data, (length - 1), 1)); // Copy to another Buffer - //} else { - // data = undefined; - //} + // if (ref.address(data) !== 0) { + // // first byte is magic byte(160) so ignore it + // // Copy to another Buffer + // data = Buffer.from(ref.reinterpret(data, (length - 1), 1)); + // } else { + // data = undefined; + // } if (ref.address(data) === 0) { throw new Error("NULL data packet"); } diff --git a/test/tox.js b/test/tox.js index 6afe289..e5763aa 100644 --- a/test/tox.js +++ b/test/tox.js @@ -35,7 +35,7 @@ describe("Tox", function () { toxNoUdp.start(); var customPort = 33510; - var toxCustomPort = new Tox({ startPort: customPort, endPort: customPort }); + var toxCustomPort = new Tox({ startPort: customPort, endPort: customPort + 100 }); toxCustomPort.start(); var toxDead = new Tox(); diff --git a/tools/local-dev.sh b/tools/local-dev.sh new file mode 100755 index 0000000..eca84e4 --- /dev/null +++ b/tools/local-dev.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +set -eux + +docker run --rm -v "$PWD:/work/js-toxcore-c" --tmpfs /work/js-toxcore-c/node_modules:exec -it toxchat/js-toxcore-c