Skip to content

Commit b8b39f4

Browse files
Update set description and test CI
Signed-off-by: Matheus Sampaio Queiroga <[email protected]>
1 parent a21535b commit b8b39f4

File tree

10 files changed

+202
-69
lines changed

10 files changed

+202
-69
lines changed

.devcontainer/Dockerfile

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
FROM ubuntu:latest
2+
ARG DEBIAN_FRONTEND="noninteractive"
3+
ARG GOVERSION="1.22.0"
4+
ARG ZIGVERSION="0.11.0"
5+
6+
RUN apt update && apt list --upgradable -a && apt upgrade -y
7+
RUN apt update && apt install -y xz-utils software-properties-common cmake make build-essential git curl wget jq sudo procps zsh tar screen ca-certificates procps lsb-release gnupg gnupg2 gpg apt-transport-https python3-pip apt-file attr bash-completion bc bison clang command-not-found dialog dos2unix ed flex gawk gperf htop libresolv-wrapper lld llvm lsof man neofetch neovim rhash tree tshark unbound unzip xxhash openssh-server openssh-client
8+
STOPSIGNAL SIGSTOP
9+
CMD [ "zsh" ]
10+
WORKDIR /root
11+
12+
# Nodejs
13+
RUN curl https://deb.nodesource.com/setup_lts.x | bash && apt install nodejs -y
14+
15+
# Go (golang)
16+
RUN wget -qO- "https://go.dev/dl/go${GOVERSION}.linux-$(dpkg --print-architecture).tar.gz" | tar -C /usr/local -xzv && ln -s /usr/local/go/bin/go /usr/bin/go && ln -s /usr/local/go/bin/gofmt /usr/bin/gofmt
17+
18+
# Install Github CLI (gh)
19+
RUN (wget -q "$(wget -qO- https://api.github.com/repos/cli/cli/releases/latest | grep 'browser_download_url' | grep '.deb' | cut -d \" -f 4 | grep $(dpkg --print-architecture))" -O /tmp/gh.deb && dpkg -i /tmp/gh.deb && rm /tmp/gh.deb) || echo "Fail Install gh"
20+
21+
# Zig
22+
RUN wget -qO- "https://ziglang.org/download/${ZIGVERSION}/zig-linux-$(uname -m)-${ZIGVERSION}.tar.xz" | tar -xvJ -C /usr/local/ && \
23+
mv -v /usr/local/zig* /usr/local/zig && \
24+
ln -s /usr/local/zig/zig /usr/bin/zig
25+
26+
ARG USERNAME="devcontainer"
27+
ARG USER_UID="1000"
28+
ARG USER_GID=$USER_UID
29+
30+
# Add non root user and Install oh my zsh
31+
RUN addgroup --gid "${USER_GID}" "${USERNAME}"; useradd --uid "${USER_UID}" --gid "${USER_GID}" --groups sudo -m --shell /usr/bib/zsh "${USERNAME}" -p test
32+
USER $USERNAME
33+
WORKDIR /home/$USERNAME
34+
RUN git clone https://github.com/Sirherobrine23/dotfiles.git dotfiles && cd dotfiles && ./install; cd /home/$USERNAME; rm -rf dotfiles

.devcontainer/devcontainer.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "rebory linux devcontainer",
3+
"updateRemoteUserUID": false,
4+
"containerUser": "develop",
5+
"remoteUser": "develop",
6+
"build": {
7+
"dockerfile": "Dockerfile",
8+
"args": {
9+
"USERNAME": "develop",
10+
"USER_UID": "1000"
11+
}
12+
}
13+
}

.github/workflows/test.yml

+14-14
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: "Setup zig"
1919
uses: korandoru/setup-zig@v1
2020
with:
21-
zig-version: "master"
21+
zig-version: "0.11.0"
2222

2323
- uses: actions/setup-node@v4
2424
name: Setup Node.js
@@ -28,8 +28,7 @@ jobs:
2828
- name: Install dependencies
2929
run: |
3030
export DEBIAN_FRONTEND=noninteractive
31-
sudo apt update
32-
sudo apt install -y "binutils-multiarch" "build-essential"
31+
sudo apt update && sudo apt install -y "build-essential"
3332
npm install --no-save --ignore-scripts
3433
3534
- name: Build addon
@@ -44,19 +43,15 @@ jobs:
4443
runs-on: ubuntu-latest
4544
strategy:
4645
matrix:
47-
node_version: [ 16.x, 18.x, 19.x, 20.x, 21.x ]
48-
target_arch: [ "x86_64", "aarch64" ]
49-
target_os:
50-
- "linux"
51-
# - "macos"
46+
node_version: [ 16.x, 17.x, 18.x, 19.x, 20.x, 21.x ]
5247
steps:
5348
- uses: actions/checkout@v4
5449
name: Checkout
5550

5651
- name: "Setup zig"
5752
uses: korandoru/setup-zig@v1
5853
with:
59-
zig-version: "master"
54+
zig-version: "0.11.0"
6055

6156
- uses: actions/setup-node@v4
6257
name: Setup Node.js
@@ -66,16 +61,21 @@ jobs:
6661
- name: Install dependencies
6762
run: |
6863
export DEBIAN_FRONTEND=noninteractive
69-
sudo apt update
70-
sudo apt install -y "binutils-multiarch" "build-essential"
64+
sudo apt update && sudo apt install -y "build-essential"
7165
npm install --no-save --ignore-scripts
7266
73-
- name: Build addon
74-
run: npm run dev -- --target ${{ matrix.target_arch }}-${{ matrix.target_os }}
67+
- name: Build addon linux
68+
run: npm run dev -- --target x86_64-linux --target aarch64-linux
69+
70+
- name: Build addon macos
71+
run: npm run dev -- --target x86_64-macos --target aarch64-macos
72+
73+
- name: Build addon windows
74+
run: npm run dev -- --target x86_64-windows --target aarch64-windows
7575

7676
- name: Upload prebuilds interface
7777
uses: actions/upload-artifact@v3
7878
with:
7979
retention-days: 7
80-
name: prebuilds_${{ matrix.target_arch }}-${{ matrix.target_os }}_${{ matrix.node_version }}
80+
name: build-${{ matrix.node_version }}
8181
path: "build/*"

addons/tools/wginterface-linux.cpp

+78-26
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,79 @@ extern "C" {
2828
#include "linux/wireguard.h"
2929
}
3030

31-
#define SETCONFIG 1
32-
#define GETCONFIG 1
33-
#define LISTDEV 1
34-
#define DELIFACE 1
31+
#define EPERM 1 /* Operation not permitted */
32+
#define ENOENT 2 /* No such file or directory */
33+
#define ESRCH 3 /* No such process */
34+
#define EINTR 4 /* Interrupted system call */
35+
#define EIO 5 /* I/O error */
36+
#define ENXIO 6 /* No such device or address */
37+
#define E2BIG 7 /* Argument list too long */
38+
#define ENOEXEC 8 /* Exec format error */
39+
#define EBADF 9 /* Bad file number */
40+
#define ECHILD 10 /* No child processes */
41+
#define EAGAIN 11 /* Try again */
42+
#define ENOMEM 12 /* Out of memory */
43+
#define EACCES 13 /* Permission denied */
44+
#define EFAULT 14 /* Bad address */
45+
#define ENOTBLK 15 /* Block device required */
46+
#define EBUSY 16 /* Device or resource busy */
47+
#define EEXIST 17 /* File exists */
48+
#define EXDEV 18 /* Cross-device link */
49+
#define ENODEV 19 /* No such device */
50+
#define ENOTDIR 20 /* Not a directory */
51+
#define EISDIR 21 /* Is a directory */
52+
#define EINVAL 22 /* Invalid argument */
53+
#define ENFILE 23 /* File table overflow */
54+
#define EMFILE 24 /* Too many open files */
55+
#define ENOTTY 25 /* Not a typewriter */
56+
#define ETXTBSY 26 /* Text file busy */
57+
#define EFBIG 27 /* File too large */
58+
#define ENOSPC 28 /* No space left on device */
59+
#define ESPIPE 29 /* Illegal seek */
60+
#define EROFS 30 /* Read-only file system */
61+
#define EMLINK 31 /* Too many links */
62+
#define EPIPE 32 /* Broken pipe */
63+
#define EDOM 33 /* Math argument out of domain of func */
64+
#define ERANGE 34 /* Math result not representable */
65+
66+
std::string getKernelMesage(int errStatus) {
67+
std::string message = std::string("Error code: ").append(std::to_string(errStatus));
68+
if (errStatus == -EPERM) message = std::string("Operation not permitted, code: ").append(std::to_string(errStatus));
69+
else if (errStatus == -ENOENT) message = std::string("No such file or directory, code: ").append(std::to_string(errStatus));
70+
else if (errStatus == -ESRCH) message = std::string("No such process, code: ").append(std::to_string(errStatus));
71+
else if (errStatus == -EINTR) message = std::string("Interrupted system call, code: ").append(std::to_string(errStatus));
72+
else if (errStatus == -EIO) message = std::string("I/O error, code: ").append(std::to_string(errStatus));
73+
else if (errStatus == -ENXIO) message = std::string("No such device or address, code: ").append(std::to_string(errStatus));
74+
else if (errStatus == -E2BIG) message = std::string("Argument list too long, code: ").append(std::to_string(errStatus));
75+
else if (errStatus == -ENOEXEC) message = std::string("Exec format error, code: ").append(std::to_string(errStatus));
76+
else if (errStatus == -EBADF) message = std::string("Bad file number, code: ").append(std::to_string(errStatus));
77+
else if (errStatus == -ECHILD) message = std::string("No child processes, code: ").append(std::to_string(errStatus));
78+
else if (errStatus == -EAGAIN) message = std::string("Try again, code: ").append(std::to_string(errStatus));
79+
else if (errStatus == -ENOMEM) message = std::string("Out of memory, code: ").append(std::to_string(errStatus));
80+
else if (errStatus == -EACCES) message = std::string("Permission denied, code: ").append(std::to_string(errStatus));
81+
else if (errStatus == -EFAULT) message = std::string("Bad address, code: ").append(std::to_string(errStatus));
82+
else if (errStatus == -ENOTBLK) message = std::string("Block device required, code: ").append(std::to_string(errStatus));
83+
else if (errStatus == -EBUSY) message = std::string("Device or resource busy, code: ").append(std::to_string(errStatus));
84+
else if (errStatus == -EEXIST) message = std::string("File exists, code: ").append(std::to_string(errStatus));
85+
else if (errStatus == -EXDEV) message = std::string("Cross-device link, code: ").append(std::to_string(errStatus));
86+
else if (errStatus == -ENODEV) message = std::string("No such device, code: ").append(std::to_string(errStatus));
87+
else if (errStatus == -ENOTDIR) message = std::string("Not a directory, code: ").append(std::to_string(errStatus));
88+
else if (errStatus == -EISDIR) message = std::string("Is a directory, code: ").append(std::to_string(errStatus));
89+
else if (errStatus == -EINVAL) message = std::string("Invalid argument, code: ").append(std::to_string(errStatus));
90+
else if (errStatus == -ENFILE) message = std::string("File table overflow, code: ").append(std::to_string(errStatus));
91+
else if (errStatus == -EMFILE) message = std::string("Too many open files, code: ").append(std::to_string(errStatus));
92+
else if (errStatus == -ENOTTY) message = std::string("Not a typewriter, code: ").append(std::to_string(errStatus));
93+
else if (errStatus == -ETXTBSY) message = std::string("Text file busy, code: ").append(std::to_string(errStatus));
94+
else if (errStatus == -EFBIG) message = std::string("File too large, code: ").append(std::to_string(errStatus));
95+
else if (errStatus == -ENOSPC) message = std::string("No space left on device, code: ").append(std::to_string(errStatus));
96+
else if (errStatus == -ESPIPE) message = std::string("Illegal seek, code: ").append(std::to_string(errStatus));
97+
else if (errStatus == -EROFS) message = std::string("Read-only file system, code: ").append(std::to_string(errStatus));
98+
else if (errStatus == -EMLINK) message = std::string("Too many links, code: ").append(std::to_string(errStatus));
99+
else if (errStatus == -EPIPE) message = std::string("Broken pipe, code: ").append(std::to_string(errStatus));
100+
else if (errStatus == -EDOM) message = std::string("Math argument out of domain of func, code: ").append(std::to_string(errStatus));
101+
else if (errStatus == -ERANGE) message = std::string("Math result not representable, code: ").append(std::to_string(errStatus));
102+
return message;
103+
}
35104

36105
unsigned long maxName() {
37106
return IFNAMSIZ;
@@ -78,13 +147,7 @@ void deleteInterface::Execute() {
78147
if (!!devicesList) {
79148
for ((device_name) = (devicesList), (len) = 0; ((len) = strlen(device_name)); (device_name) += (len) + 1) {
80149
if (device_name == wgName.c_str()) {
81-
if ((len = wg_add_device(wgName.c_str())) < 0) {
82-
std::string err = "Error code: ";
83-
err = err.append(std::to_string(len));
84-
if (len == -ENOMEM) err = "Out of memory";
85-
else if (len == -errno) err = ((std::string)"Cannot add device, code: ").append(std::to_string(len));
86-
SetError(err);
87-
}
150+
if ((len = wg_add_device(wgName.c_str())) < 0) SetError(getKernelMesage(len));
88151
break;
89152
}
90153
}
@@ -94,12 +157,8 @@ void deleteInterface::Execute() {
94157

95158
void setConfig::Execute() {
96159
int res = setInterface(wgName);
97-
if (res < 0) {
98-
std::string err = "Error code: ";
99-
err = err.append(std::to_string(res));
100-
if (res == -ENOMEM) err = "Out of memory";
101-
else if (res == -errno) err = ((std::string)"Cannot add device, code: ").append(std::to_string(res));
102-
SetError(err);
160+
if (res < 0 && res != EEXIST) {
161+
SetError(getKernelMesage(res));
103162
return;
104163
}
105164

@@ -270,12 +329,7 @@ void setConfig::Execute() {
270329

271330
// Set interface config
272331
if ((res = wg_set_device(deviceStruct)) < 0) {
273-
std::string err = "Set wireguard config Error code: ";
274-
err = err.append(std::to_string(res));
275-
if (res == -ENODEV) err = "No such device";
276-
else if (res == -EINVAL) err = "Invalid argument";
277-
else if (res == -ENOSPC) err = "No space left on device";
278-
SetError(err);
332+
SetError(getKernelMesage(res));
279333
}
280334

281335
if (res >= 0) {
@@ -313,9 +367,7 @@ std::string keyTo64(const uint8_t *key) {
313367
void getConfig::Execute() {
314368
int res; wg_device *device;
315369
if ((res = wg_get_device(&device, strdup(wgName.c_str()))) < 0) {
316-
std::string err = "Cannot get wireguard device, Error code ";
317-
err = err.append(std::to_string(res));
318-
SetError(err);
370+
SetError(getKernelMesage(res));
319371
return;
320372
}
321373

addons/tools/wginterface-win.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ std::string getErrorString(DWORD errorMessageID) {
6262

6363
std::string startAddon(const Napi::Env env, Napi::Object exports) {
6464
if (!IsRunAsAdmin()) return "Run nodejs with administrator privilegies";
65-
auto DLLPATH = exports.Get("WIREGUARD_DLL_PATH");
65+
auto DLLPATH = exports.Get("WIN32DLLPATH");
6666
if (!(DLLPATH.IsString())) return "Require WIREGUARD_DLL_PATH in addon load!";
6767
LPCWSTR dllPath = toLpcwstr(DLLPATH.ToString());
6868

addons/tools/wginterface.cpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,26 @@ Napi::Object Init(Napi::Env initEnv, Napi::Object exports) {
1414

1515
// Wireguard constants set
1616
const Napi::Object constants = Napi::Object::New(initEnv);
17-
constants.Set("WG_B64_LENGTH", B64_WG_KEY_LENGTH);
18-
constants.Set("WG_LENGTH", WG_KEY_LENGTH);
19-
constants.Set("MAX_NAME_LENGTH", maxName());
17+
// Set wireguard version if present
2018
constants.Set("driveVersion", versionDrive());
2119

22-
// Constants
20+
// Wireguard max name length
21+
constants.Set("nameLength", maxName());
22+
23+
constants.Set("base64Length", B64_WG_KEY_LENGTH);
24+
constants.Set("keyLength", WG_KEY_LENGTH);
25+
26+
// Set addon constants
2327
exports.Set("constants", constants);
2428

2529
// Function's
30+
#ifdef USERSPACE_GO
31+
exports.Set("createTun", Napi::Function::New(initEnv, [&](const Napi::CallbackInfo &info) -> Napi::Value { return info.Env().Undefined(); }));
32+
exports.Set("deleteTun", Napi::Function::New(initEnv, [&](const Napi::CallbackInfo &info) -> Napi::Value { return info.Env().Undefined(); }));
33+
exports.Set("checkTun", Napi::Function::New(initEnv, [&](const Napi::CallbackInfo &info) -> Napi::Value { return info.Env().Undefined(); }));
34+
exports.Set("getTun", Napi::Function::New(initEnv, [&](const Napi::CallbackInfo &info) -> Napi::Value { return info.Env().Undefined(); }));
35+
#endif
36+
2637
#ifdef SETCONFIG
2738
exports.Set("setConfig", Napi::Function::New(initEnv, [&](const Napi::CallbackInfo &info) -> Napi::Value {
2839
const Napi::Env env = info.Env();

addons/tools/wginterface.hh

+6-6
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,17 @@ class setConfig : public Napi::AsyncWorker {
186186
if (sfw.IsNumber() && (sfw.ToNumber().Uint32Value() >= 0)) fwmark = sfw.ToNumber().Uint32Value();
187187
else fwmark = -1;
188188

189-
const auto saddr = config.Get("Address");
190-
if (saddr.IsArray()) {
191-
const Napi::Array addrs = saddr.As<Napi::Array>();
189+
const auto setAddress = config.Get("address");
190+
if (setAddress.IsArray()) {
191+
const Napi::Array addrs = setAddress.As<Napi::Array>();
192192
for (unsigned int i = 0; i < addrs.Length(); i++) {
193193
if (addrs.Get(i).IsString()) Address.push_back(addrs.Get(i).ToString().Utf8Value());
194194
}
195195
}
196196

197197
// Replace peers
198-
const auto srpee = config.Get("replacePeers");
199-
if (srpee.IsBoolean()) replacePeers = srpee.ToBoolean().Value();
198+
const auto setReplace = config.Get("replacePeers");
199+
if (setReplace.IsBoolean()) replacePeers = setReplace.ToBoolean().Value();
200200

201201
// Peers
202202
const auto speers = config.Get("peers");
@@ -298,7 +298,7 @@ class getConfig : public Napi::AsyncWorker {
298298
if (Address.size() > 0) {
299299
const auto Addrs = Napi::Array::New(env);
300300
for (auto &addr : Address) Addrs.Set(Addrs.Length(), addr);
301-
config.Set("Address", Addrs);
301+
config.Set("address", Addrs);
302302
}
303303

304304
// Peer object

binding.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ sources:
2323
- "addons/tools/wginterface.cpp"
2424
- "addons/tools/wginterface-dummy.cpp"
2525
target:
26+
macos:
27+
defines:
28+
- USERSPACE_GO
2629
linux:
2730
sources:
2831
- "addons/tools/linux/wireguard.c"
@@ -47,6 +50,9 @@ target:
4750
flagsCC:
4851
- "-fPIC"
4952
windows:
53+
flags:
54+
- "-undefined"
55+
- "dynamic_lookup"
5056
target:
5157
x86_64:
5258
release: true

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@
4646
},
4747
"dependencies": {
4848
"node-addon-api": "^7.1.0",
49-
"rebory": "^0.1.11-2"
49+
"rebory": "^0.1.12"
5050
}
5151
}

0 commit comments

Comments
 (0)