diff --git a/.zed/settings.json b/.zed/settings.json index dbfdc19..7fa4b35 100644 --- a/.zed/settings.json +++ b/.zed/settings.json @@ -8,30 +8,25 @@ "formatter": "auto", "format_on_save": "off", "tab_size": 2, - "file_scan_exclusions": [ - "/*-lock", - "/node_modules", - "/build" - ], "languages": { "TypeScript": { - "hard_tabs": false - "format_on_save": true, + "hard_tabs": false, + "format_on_save": "on", "code_actions_on_format": { "source.organizeImports": true, "source.removeUnusedImports": true } }, "JavaScript": { - "hard_tabs": false - "format_on_save": true, + "hard_tabs": false, + "format_on_save": "on", "code_actions_on_format": { "source.organizeImports": true, "source.removeUnusedImports": true } }, "Go": { - "format_on_save": true + "format_on_save": "on" }, "C++": { "hard_tabs": false diff --git a/addon/genKey/wgkeys.cpp b/addon/genKey/wgkeys.cpp index fbb3e15..11fac53 100644 --- a/addon/genKey/wgkeys.cpp +++ b/addon/genKey/wgkeys.cpp @@ -1,4 +1,5 @@ #include "wgkeys.hh" +#include #include #include #include @@ -330,15 +331,16 @@ std::string wgKeys::toHex(const std::string &keyBase64) { wg_key key; wgKeys::stringToKey(key, keyBase64); char hex[65]; - for (int i = 0; i < 32; ++i) sprintf(hex + i * 2, "%02x", key[i]); + // for (int i = 0; i < 32; ++i) sprintf(hex + i * 2, "%02x", key[i]); + for (int i = 0; i < 32; ++i) snprintf(hex + i * 2, 3, "%02x", key[i]); hex[64] = '\0'; return std::string(hex); } std::string wgKeys::HextoBase64(const std::string &s_hex) { wg_key key; - for(unsigned i = 0, uchr ; i < s_hex.length() ; i += 2) { - sscanf( s_hex.c_str()+ i, "%2x", &uchr); // conversion + for(unsigned i = 0, uchr; i < s_hex.length(); i += 2) { + sscanf(s_hex.c_str() + i, "%2x", &uchr); // conversion key[i/2] = uchr; // save as char } return wgKeys::toString(key); diff --git a/addon/userspace/go/main.go b/addon/userspace/go/main.go index 66ad85a..e8abf51 100644 --- a/addon/userspace/go/main.go +++ b/addon/userspace/go/main.go @@ -14,9 +14,6 @@ import ( func main() {} -// Default log level to print in terminal -const levelLog = device.LogLevelSilent - func getCharErr(err error) *C.char { if err == nil { return C.CString("") @@ -63,10 +60,12 @@ func stopWg(wgName *C.char) (bool, *C.char) { tunName := C.GoString(wgName) if dev, ok := Devices[tunName]; ok { dev.Close() + delete(Devices, tunName) if tun, ok := Tuns[tunName]; ok { if err := tun.Close(); err != nil { return false, getCharErr(err) } + delete(Tuns, tunName) } return true, nil } @@ -76,7 +75,7 @@ func stopWg(wgName *C.char) (bool, *C.char) { // Set config in tun, if not exist create and add to Tuns // //export setWg -func setWg(wgName, wgConfig *C.char) *C.char { +func setWg(levelLog int, wgName, wgConfig *C.char) *C.char { tunName, configString := C.GoString(wgName), C.GoString(wgConfig) _, okTuns := Tuns[tunName] _, okDev := Devices[tunName] diff --git a/addon/userspace/wginterface.cpp b/addon/userspace/wginterface.cpp index ce3a19c..1564c0a 100644 --- a/addon/userspace/wginterface.cpp +++ b/addon/userspace/wginterface.cpp @@ -26,7 +26,7 @@ void IpManeger::GetInInterface(std::string interfaceName) {} std::string driveLoad(std::map load) { return ""; } std::string getWireguardVersion() { - return std::string(wgVersion()); + return std::string("wireguard-go ").append(wgVersion()); } void WireguardDevices::getInterfaces() { @@ -68,7 +68,7 @@ void WireguardConfig::setWireguardConfig() { } } - std::string err = setWg((char*)this->name.c_str(), (char*)userspaceConfig.append("\n").c_str()); + std::string err = setWg(0, (char*)this->name.c_str(), (char*)userspaceConfig.append("\n").c_str()); if (!err.empty()) throw err; } diff --git a/addon/wginterface.hh b/addon/wginterface.hh index d4611a2..bb37104 100644 --- a/addon/wginterface.hh +++ b/addon/wginterface.hh @@ -215,23 +215,4 @@ class WireguardConfig { void getWireguardConfig(); }; -namespace WireguardUserspace { - // Get Wireguard-go version - std::string getWireguardVersion(); - - // Close all wireguard tunels - void closeAllWireguardTunnels(); - - // Create tunel and return path to tunel - std::string createWireguardTunnel(std::string wgName); - - // Delete tunel by name and return true if success - void deleteWireguardTunnel(std::string wgName); - - // List all tunels - std::vector listTunnels(); - - // Check if tunel exist - bool checkIfExistTunnel(std::string wgName); -}; #endif diff --git a/compile_flags.txt b/compile_flags.txt index cae68be..0ec1c61 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -1,5 +1,6 @@ +-std=c++17 -Iaddon/ -Iaddon/genKey -Inode_modules/node-addon-api -I/usr/local/include/node --std=c++17 \ No newline at end of file +-I/opt/local/include/node \ No newline at end of file