Skip to content

Commit 042ba38

Browse files
authored
Merge pull request #26 from Bilb/fix-thread-safety-log
fix: make logging thread safe
2 parents 4e95c55 + 0196c21 commit 042ba38

21 files changed

+106
-57
lines changed

.vscode/c_cpp_properties.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Linux",
5+
"includePath": [
6+
"${workspaceFolder}/**",
7+
"${workspaceFolder}/include/**",
8+
"${workspaceFolder}/libsession-util/include/**",
9+
"${workspaceFolder}/node_modules/node-addon-api/",
10+
"${workspaceFolder}/node_modules/node-api-headers/include/"
11+
],
12+
"defines": [],
13+
"compilerPath": "/usr/bin/clang",
14+
"cStandard": "c17",
15+
"cppStandard": "c++20",
16+
"intelliSenseMode": "linux-clang-x64"
17+
},
18+
{
19+
"name": "Mac",
20+
"includePath": [
21+
"${workspaceFolder}/**",
22+
"${workspaceFolder}/include/**",
23+
"${workspaceFolder}/libsession-util/include/**",
24+
"${workspaceFolder}/node_modules/node-addon-api/",
25+
"${workspaceFolder}/node_modules/node-api-headers/include/"
26+
],
27+
"defines": [],
28+
"compilerPath": "/usr/bin/clang",
29+
"cStandard": "c17",
30+
"cppStandard": "c++20",
31+
"intelliSenseMode": "macos-clang-arm64"
32+
}
33+
],
34+
"version": 4
35+
}

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ if(MSVC)
4848
endif()
4949

5050
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC})
51-
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_JS_INC} "node_modules/node-addon-api" "../../node_modules/node-addon-api" "node_modules/node-api-headers/include" "../../node_modules/node-api-headers/include")
51+
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_JS_INC} "include/" "node_modules/node-addon-api" "../../node_modules/node-addon-api" "node_modules/node-api-headers/include" "../../node_modules/node-api-headers/include")
5252

5353
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
5454
target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_JS_LIB} ${LIBSESSION_STATIC_BUNDLE_LIBS})
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/meta/meta_base_wrapper.hpp renamed to include/meta/meta_base_wrapper.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
#include <napi.h>
44

5+
#include <optional>
56
#include <span>
67
#include <vector>
78

89
#include "../base_config.hpp"
910
#include "../groups/meta_group.hpp"
10-
1111
namespace session::nodeapi {
1212

1313
class MetaBaseWrapper {
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"main": "index.js",
33
"name": "libsession_util_nodejs",
44
"description": "Wrappers for the Session Util Library",
5-
"version": "0.5.0",
5+
"version": "0.5.1",
66
"license": "GPL-3.0",
77
"author": {
88
"name": "Oxen Project",
@@ -11,16 +11,18 @@
1111
"scripts": {
1212
"update_version": "sh update_version.sh",
1313
"clean": "rimraf .cache build",
14+
"lint:cpp": "cppcheck --std=c++20 -j8 --quiet src libsession-util/src",
1415
"install": "cmake-js build --runtime=electron --runtime-version=34.2.0 --CDSUBMODULE_CHECK=OFF --CDLOCAL_MIRROR=https://oxen.rocks/deps --CDENABLE_ONIONREQ=OFF --CDWITH_TESTS=OFF",
15-
"prepare_release": "sh prepare_release.sh"
16+
"prepare_release": "sh prepare_release.sh",
17+
"dedup": "npx --yes yarn-deduplicate yarn.lock"
1618
},
1719
"devDependencies": {
1820
"clang-format": "^1.8.0",
1921
"rimraf": "2.6.2"
2022
},
2123
"dependencies": {
22-
"cmake-js": "7.2.1",
23-
"node-addon-api": "^6.1.0"
24+
"cmake-js": "7.3.1",
25+
"node-addon-api": "^8.3.1"
2426
},
2527
"typings": "index.d.ts",
2628
"packageManager": "[email protected]"

src/addon.cpp

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <napi.h>
22

3+
#include <oxen/log.hpp>
4+
35
#include "blinding/blinding.hpp"
46
#include "constants.hpp"
57
#include "contacts_config.hpp"
@@ -9,18 +11,34 @@
911
#include "user_config.hpp"
1012
#include "user_groups_config.hpp"
1113

14+
Napi::ThreadSafeFunction tsfn;
15+
1216
Napi::Object InitAll(Napi::Env env, Napi::Object exports) {
1317
using namespace session::nodeapi;
1418

15-
session::add_logger([env](std::string_view msg) {
16-
std::string toLog = std::string("libsession-util: ") + std::string(msg) + "\n";
17-
18-
Napi::Function consoleLog =
19-
env.Global().Get("console").As<Napi::Object>().Get("log").As<Napi::Function>();
20-
consoleLog.Call({Napi::String::New(env, toLog)});
19+
tsfn = Napi::ThreadSafeFunction::New(
20+
env,
21+
Napi::Function::New(env, [](const Napi::CallbackInfo& info) {}),
22+
"LoggerCallback",
23+
0,
24+
1);
25+
26+
session::add_logger([](std::string_view msg) {
27+
tsfn.BlockingCall(
28+
new std::string(msg),
29+
[](Napi::Env env, Napi::Function jsCallback, std::string* msg) {
30+
Napi::HandleScope scope(env);
31+
Napi::Function consoleLog = env.Global()
32+
.Get("console")
33+
.As<Napi::Object>()
34+
.Get("log")
35+
.As<Napi::Function>();
36+
Napi::String jsStr = Napi::String::New(env, "libsession-util: " + *msg);
37+
consoleLog.Call({jsStr});
38+
delete msg;
39+
});
2140
});
22-
23-
// session::logger_set_level_default(session::LogLevel::debug);
41+
oxen::log::set_level_default(oxen::log::Level::info);
2442

2543
ConstantsWrapper::Init(env, exports);
2644

src/convo_info_volatile_config.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "community.hpp"
77
#include "session/config/convo_info_volatile.hpp"
88
#include "session/types.hpp"
9+
#include "utilities.hpp"
910

1011
namespace session::nodeapi {
1112

src/groups/meta_group_wrapper.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
#include "meta_group_wrapper.hpp"
1+
#include "groups/meta_group_wrapper.hpp"
22

33
#include <napi.h>
4+
#include <oxenc/bt_producer.h>
45

56
#include <memory>
7+
#include <session/types.hpp>
8+
#include <session/util.hpp>
69
#include <span>
710
#include <vector>
811

9-
#include "oxenc/bt_producer.h"
10-
#include "session/types.hpp"
11-
1212
namespace session::nodeapi {
1313

1414
Napi::Object member_to_js(const Napi::Env& env, const member& info, const member::Status& status) {
@@ -275,7 +275,6 @@ Napi::Value MetaGroupWrapper::metaMerge(const Napi::CallbackInfo& info) {
275275

276276
auto count_merged = 0;
277277

278-
279278
// Note: we need to process keys first as they might allow us the incoming info+members
280279
// details
281280
if (!groupKeys.IsNull() && !groupKeys.IsUndefined()) {

yarn.lock

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ asynckit@^0.4.0:
3737
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
3838
integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==
3939

40-
axios@^1.3.2:
41-
version "1.7.7"
42-
resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.7.tgz#2f554296f9892a72ac8d8e4c5b79c14a91d0a47f"
43-
integrity sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==
40+
axios@^1.6.5:
41+
version "1.8.4"
42+
resolved "https://registry.yarnpkg.com/axios/-/axios-1.8.4.tgz#78990bb4bc63d2cae072952d374835950a82f447"
43+
integrity sha512-eBSYY4Y68NNlHbHBMdeDmKNtDgXWhQsJcGqzO3iLUM0GraQFSS9cVgPX5I9b3lbdFKyYoAEGAZF1DwhTaljNAw==
4444
dependencies:
4545
follow-redirects "^1.15.6"
4646
form-data "^4.0.0"
@@ -82,24 +82,23 @@ cliui@^8.0.1:
8282
strip-ansi "^6.0.1"
8383
wrap-ansi "^7.0.0"
8484

85-
cmake-js@7.2.1:
86-
version "7.2.1"
87-
resolved "https://registry.yarnpkg.com/cmake-js/-/cmake-js-7.2.1.tgz#757c0d39994121b084bab96290baf115ee7712cd"
88-
integrity sha512-AdPSz9cSIJWdKvm0aJgVu3X8i0U3mNTswJkSHzZISqmYVjZk7Td4oDFg0mCBA383wO+9pG5Ix7pEP1CZH9x2BA==
85+
cmake-js@7.3.1:
86+
version "7.3.1"
87+
resolved "https://registry.yarnpkg.com/cmake-js/-/cmake-js-7.3.1.tgz#ed661eebd22a56d4743d7d2106a56fe50aa4355c"
88+
integrity sha512-aJtHDrTFl8qovjSSqXT9aC2jdGfmP8JQsPtjdLAXFfH1BF4/ImZ27Jx0R61TFg8Apc3pl6e2yBKMveAeRXx2Rw==
8989
dependencies:
90-
axios "^1.3.2"
90+
axios "^1.6.5"
9191
debug "^4"
92-
fs-extra "^10.1.0"
93-
lodash.isplainobject "^4.0.6"
92+
fs-extra "^11.2.0"
9493
memory-stream "^1.0.0"
95-
node-api-headers "^0.0.2"
94+
node-api-headers "^1.1.0"
9695
npmlog "^6.0.2"
9796
rc "^1.2.7"
98-
semver "^7.3.8"
99-
tar "^6.1.11"
97+
semver "^7.5.4"
98+
tar "^6.2.0"
10099
url-join "^4.0.1"
101100
which "^2.0.2"
102-
yargs "^17.6.0"
101+
yargs "^17.7.2"
103102

104103
color-convert@^2.0.1:
105104
version "2.0.1"
@@ -181,10 +180,10 @@ form-data@^4.0.0:
181180
combined-stream "^1.0.8"
182181
mime-types "^2.1.12"
183182

184-
fs-extra@^10.1.0:
185-
version "10.1.0"
186-
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.1.0.tgz#02873cfbc4084dde127eaa5f9905eef2325d1abf"
187-
integrity sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==
183+
fs-extra@^11.2.0:
184+
version "11.3.0"
185+
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-11.3.0.tgz#0daced136bbaf65a555a326719af931adc7a314d"
186+
integrity sha512-Z4XaCL6dUDHfP/jT25jJKMmtxvuwbkrD1vNSMFlo9lNLY2c5FHYSQgHPRZUjAB26TpDEoW9HCOgplrdbaPV/ew==
188187
dependencies:
189188
graceful-fs "^4.2.0"
190189
jsonfile "^6.0.1"
@@ -299,11 +298,6 @@ jsonfile@^6.0.1:
299298
optionalDependencies:
300299
graceful-fs "^4.1.6"
301300

302-
lodash.isplainobject@^4.0.6:
303-
version "4.0.6"
304-
resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb"
305-
integrity sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==
306-
307301
memory-stream@^1.0.0:
308302
version "1.0.0"
309303
resolved "https://registry.yarnpkg.com/memory-stream/-/memory-stream-1.0.0.tgz#481dfd259ccdf57b03ec2c9632960044180e73c2"
@@ -365,15 +359,15 @@ ms@^2.1.3:
365359
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
366360
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==
367361

368-
node-addon-api@^6.1.0:
369-
version "6.1.0"
370-
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-6.1.0.tgz#ac8470034e58e67d0c6f1204a18ae6995d9c0d76"
371-
integrity sha512-+eawOlIgy680F0kBzPUNFhMZGtJ1YmqM6l4+Crf4IkImjYrO/mqPwRMh352g23uIaQKFItcQ64I7KMaJxHgAVA==
362+
node-addon-api@^8.3.1:
363+
version "8.3.1"
364+
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-8.3.1.tgz#53bc8a4f8dbde3de787b9828059da94ba9fd4eed"
365+
integrity sha512-lytcDEdxKjGJPTLEfW4mYMigRezMlyJY8W4wxJK8zE533Jlb8L8dRuObJFWg2P+AuOIxoCgKF+2Oq4d4Zd0OUA==
372366

373-
node-api-headers@^0.0.2:
374-
version "0.0.2"
375-
resolved "https://registry.yarnpkg.com/node-api-headers/-/node-api-headers-0.0.2.tgz#31f4c6c2750b63e598128e76a60aefca6d76ac5d"
376-
integrity sha512-YsjmaKGPDkmhoNKIpkChtCsPVaRE0a274IdERKnuc/E8K1UJdBZ4/mvI006OijlQZHCfpRNOH3dfHQs92se8gg==
367+
node-api-headers@^1.1.0:
368+
version "1.5.0"
369+
resolved "https://registry.yarnpkg.com/node-api-headers/-/node-api-headers-1.5.0.tgz#73a0bab642c77e39b815b6d24ad4c6b56f695912"
370+
integrity sha512-Yi/FgnN8IU/Cd6KeLxyHkylBUvDTsSScT0Tna2zTrz8klmc8qF2ppj6Q1LHsmOueJWhigQwR4cO2p0XBGW5IaQ==
377371

378372
npmlog@^6.0.2:
379373
version "6.0.2"
@@ -452,10 +446,10 @@ safe-buffer@~5.2.0:
452446
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6"
453447
integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==
454448

455-
semver@^7.3.8:
456-
version "7.6.3"
457-
resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.3.tgz#980f7b5550bc175fb4dc09403085627f9eb33143"
458-
integrity sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==
449+
semver@^7.5.4:
450+
version "7.7.1"
451+
resolved "https://registry.yarnpkg.com/semver/-/semver-7.7.1.tgz#abd5098d82b18c6c81f6074ff2647fd3e7220c9f"
452+
integrity sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==
459453

460454
set-blocking@^2.0.0:
461455
version "2.0.0"
@@ -500,7 +494,7 @@ supports-preserve-symlinks-flag@^1.0.0:
500494
resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09"
501495
integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==
502496

503-
tar@^6.1.11:
497+
tar@^6.2.0:
504498
version "6.2.1"
505499
resolved "https://registry.yarnpkg.com/tar/-/tar-6.2.1.tgz#717549c541bc3c2af15751bea94b1dd068d4b03a"
506500
integrity sha512-DZ4yORTwrbTj/7MZYq2w+/ZFdI6OZ/f9SFHR+71gIVUZhOQPHzVCLpvRnPgyaMpfWxxk/4ONva3GQSyNIKRv6A==
@@ -570,7 +564,7 @@ yargs-parser@^21.1.1:
570564
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.1.1.tgz#9096bceebf990d21bb31fa9516e0ede294a77d35"
571565
integrity sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==
572566

573-
yargs@^17.6.0:
567+
yargs@^17.7.2:
574568
version "17.7.2"
575569
resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.7.2.tgz#991df39aca675a192b816e1e0363f9d75d2aa269"
576570
integrity sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==

0 commit comments

Comments
 (0)