Skip to content

Commit

Permalink
v2.11.6
Browse files Browse the repository at this point in the history
  • Loading branch information
bernerdad committed Aug 9, 2024
1 parent bca1850 commit dda3af6
Show file tree
Hide file tree
Showing 215 changed files with 3,493 additions and 1,912 deletions.
4 changes: 4 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,9 @@ build:artifact:links:
- echo ${NEXUS_PATH_BRANCH_UPLOAD}/windows-arm64/Windscribe_${VERSION}_arm64.exe
- echo ${NEXUS_PATH_BRANCH_UPLOAD}/macos/Windscribe_$VERSION.dmg
- echo ${NEXUS_PATH_BRANCH_UPLOAD}/linux/windscribe_${VERSION}_amd64.deb
- echo ${NEXUS_PATH_BRANCH_UPLOAD}/linux-arm64/windscribe_${VERSION}_arm64.deb
- echo ${NEXUS_PATH_BRANCH_UPLOAD}/linux/windscribe-cli_${VERSION}_amd64.deb
- echo ${NEXUS_PATH_BRANCH_UPLOAD}/linux-arm64/windscribe-cli_${VERSION}_arm64.deb
- echo ${NEXUS_PATH_BRANCH_UPLOAD}/linux/windscribe_${VERSION}_x86_64_fedora.rpm
- echo ${NEXUS_PATH_BRANCH_UPLOAD}/linux/windscribe-cli_${VERSION}_x86_64_fedora.rpm
- echo ${NEXUS_PATH_BRANCH_UPLOAD}/linux/windscribe_${VERSION}_x86_64_opensuse.rpm
Expand All @@ -846,7 +848,9 @@ build:artifact:links:tagged:
- echo ${NEXUS_PATH_TAGGED_UPLOAD}/${TAG}/Windscribe_${VERSION}_arm64.exe
- echo ${NEXUS_PATH_TAGGED_UPLOAD}/${TAG}/Windscribe_$VERSION.dmg
- echo ${NEXUS_PATH_TAGGED_UPLOAD}/${TAG}/windscribe_${VERSION}_amd64.deb
- echo ${NEXUS_PATH_TAGGED_UPLOAD}/${TAG}/windscribe_${VERSION}_arm64.deb
- echo ${NEXUS_PATH_TAGGED_UPLOAD}/${TAG}/windscribe-cli_${VERSION}_amd64.deb
- echo ${NEXUS_PATH_TAGGED_UPLOAD}/${TAG}/windscribe-cli_${VERSION}_arm64.deb
- echo ${NEXUS_PATH_TAGGED_UPLOAD}/${TAG}/windscribe_${VERSION}_x86_64_fedora.rpm
- echo ${NEXUS_PATH_TAGGED_UPLOAD}/${TAG}/windscribe-cli_${VERSION}_x86_64_fedora.rpm
- echo ${NEXUS_PATH_TAGGED_UPLOAD}/${TAG}/windscribe_${VERSION}_x86_64_opensuse.rpm
Expand Down
2 changes: 1 addition & 1 deletion backend/mac/helper/helper-info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<key>CFBundleName</key>
<string>WindscribeHelper</string>
<key>CFBundleVersion</key>
<string>73</string>
<string>76</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2024 Windscribe Limited. All rights reserved.</string>
<key>LSMinimumSystemVersion</key>
Expand Down
9 changes: 7 additions & 2 deletions backend/mac/helper/installer/files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ int Files::executeStep()

// The installer should have removed any existing Windscribe app instance by this point,
// but we'll doublecheck just to be sure.
if (std::filesystem::exists(installPath)) {
std::error_code ec;
if (std::filesystem::exists(installPath, ec)) {
LOG("Files: install path already exists");
std::filesystem::remove_all(installPath);
std::filesystem::remove_all(installPath, ec);
if (ec) {
LOG("Files: filesystem::remove_all failed: %s", ec.message().c_str());
return -1;
}
}

auto status = Utils::executeCommand("mkdir", {installPath.c_str()}, &lastError_);
Expand Down
14 changes: 7 additions & 7 deletions backend/mac/helper/ip_hostnames/ares_library_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ AresLibraryInit::~AresLibraryInit()
void AresLibraryInit::init()
{
if (!init_ && !failedInit_) {
int status = ares_library_init(ARES_LIB_INIT_ALL);
if (status != ARES_SUCCESS) {
Logger::instance().out("ares_library_init failed: %s", ares_strerror(status));
failedInit_ = true;
} else {
init_ = true;
}
int status = ares_library_init(ARES_LIB_INIT_ALL);
if (status != ARES_SUCCESS) {
Logger::instance().out("ares_library_init failed: %s", ares_strerror(status));
failedInit_ = true;
} else {
init_ = true;
}
}
}
172 changes: 115 additions & 57 deletions backend/mac/helper/ip_hostnames/dns_resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@

DnsResolver *DnsResolver::this_ = NULL;

DnsResolver::DnsResolver() : channel_(NULL)
DnsResolver::DnsResolver()
: bStopCalled_(false)
, bNeedFinish_(false)
, channel_(NULL)
{
assert(this_ == NULL);
this_ = this;
aresLibraryInit_.init();

thread_ = std::thread(threadFunc, this);
}

DnsResolver::~DnsResolver()
{
cancelAll();
assert(bStopCalled_);
this_ = NULL;
}

Expand All @@ -31,106 +36,159 @@ void DnsResolver::setResolveDomainsCallbackHandler(std::function<void(std::map<s
void DnsResolver::stop()
{
cancelAll();

// kick thread
this_->mutex_.lock();
bNeedFinish_ = true;
waitCondition_.notify_all();
this_->mutex_.unlock();

// wait for thread to finish
thread_.join();
bStopCalled_ = true;
}

void DnsResolver::resolveDomains(const std::vector<std::string> &hostnames)
{
std::lock_guard<std::mutex> lock(mutex_);

// cancel any lookups currently in channel
if (!hostnamesInProgress_.empty()) {
ares_cancel(channel_);
ares_destroy(channel_);
ares_queue_wait_empty(channel_, -1);
this_->channel_ = NULL;
} else {
assert(channel_ == NULL);
}
hostnamesInProgress_.clear();
hostinfoResults_.clear();

struct ares_options options;
int optmask = 0;
memset(&options, 0, sizeof(options));
optmask |= ARES_OPT_TRIES;
options.tries = 3;
optmask |= ARES_OPT_EVENT_THREAD;
options.evsys = ARES_EVSYS_DEFAULT;
optmask |= ARES_OPT_MAXTIMEOUTMS;
options.maxtimeout = 5 * 1000;

int status = ares_init_options(&channel_, &options, optmask);
if (status != ARES_SUCCESS) {
Logger::instance().out("ares_init_options failed: %s", ares_strerror(status));
return;
}
{
// cancel any lookups currently in channel
if (!hostnamesInProgress_.empty())
{
ares_cancel(channel_);
ares_destroy(channel_);
this_->channel_ = NULL;
}
else
{
assert(channel_ == NULL);
}
hostnamesInProgress_.clear();
hostinfoResults_.clear();

struct ares_options options;
int optmask = 0;
memset(&options, 0, sizeof(options));
optmask |= ARES_OPT_TRIES;
options.tries = 3;

int status = ares_init_options(&channel_, &options, optmask);
if (status != ARES_SUCCESS)
{
Logger::instance().out("ares_init_options failed: %s", ares_strerror(status));
return;
}

for (auto &hostname : hostnames) {
hostnamesInProgress_.insert(hostname);
}
for (auto &hostname : hostnames)
{
hostnamesInProgress_.insert(hostname);
}

// filter for unique hostnames and execute request
for (auto &hostname : hostnames) {
USER_ARG *userArg = new USER_ARG();
userArg->hostname = hostname;
struct ares_addrinfo_hints hints;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET;
ares_getaddrinfo(channel_, hostname.c_str(), NULL, &hints, aresLookupFinishedCallback, userArg);
// filter for unique hostnames and execute request
for (auto &hostname : hostnames)
{
USER_ARG *userArg = new USER_ARG();
userArg->hostname = hostname;
ares_gethostbyname(channel_, hostname.c_str(), AF_INET, aresLookupFinishedCallback, userArg);
}
}

// kick thread
waitCondition_.notify_all();
}

void DnsResolver::cancelAll()
{
std::lock_guard<std::mutex> lock(mutex_);

if (channel_) {
if (channel_)
{
ares_cancel(channel_);
hostnamesInProgress_.clear();
ares_destroy(channel_);
ares_queue_wait_empty(channel_, -1);
}
channel_ = NULL;
}

void DnsResolver::aresLookupFinishedCallback(void * arg, int status, int /*timeouts*/, struct ares_addrinfo *result)
{
if (this_ == nullptr) {
assert(false);
return;
};

std::lock_guard<std::mutex> lock(this_->mutex_);

void DnsResolver::aresLookupFinishedCallback(void * arg, int status, int /*timeouts*/, struct hostent * host)
{
USER_ARG *userArg = static_cast<USER_ARG *>(arg);

// cancel and fail cases
if (status == ARES_ECANCELLED) {
if (status == ARES_ECANCELLED)
{
delete userArg;
return;
}

HostInfo hostInfo;
hostInfo.hostname = userArg->hostname;

if (status != ARES_SUCCESS) {
if (status != ARES_SUCCESS)
{
hostInfo.error = true;
} else {
}
else
{
// add ips
for (struct ares_addrinfo_node *node = result->nodes; node != NULL; node = node->ai_next) {
for (char **p = host->h_addr_list; *p; p++)
{
char addr_buf[46] = "??";
ares_inet_ntop(node->ai_family, &((const struct sockaddr_in *)((void *)node->ai_addr))->sin_addr, addr_buf, sizeof(addr_buf));
ares_inet_ntop(host->h_addrtype, *p, addr_buf, sizeof(addr_buf));
hostInfo.addresses.push_back(std::string(addr_buf));
}
}

this_->hostinfoResults_[hostInfo.hostname] = hostInfo;
this_->hostnamesInProgress_.erase(userArg->hostname);

if (this_->hostnamesInProgress_.empty()) {
if (this_->hostnamesInProgress_.empty())
{
this_->resolveDomainsCallback_(this_->hostinfoResults_);
}

delete userArg;
}

void DnsResolver::threadFunc(void *arg)
{
//BIND_CRASH_HANDLER_FOR_THREAD();
DnsResolver *resolver = static_cast<DnsResolver *>(arg);

while (true)
{
{
std::unique_lock<std::mutex> lockWait(resolver->mutex_);
if (resolver->bNeedFinish_)
{
break;
}

if (resolver->channel_ != NULL && !resolver->processChannel(resolver->channel_))
{
resolver->waitCondition_.wait(lockWait);
}
}
sleep(1);
}
}

bool DnsResolver::processChannel(ares_channel channel)
{
fd_set read_fds, write_fds;
int res;
int nfds;

FD_ZERO(&read_fds);
FD_ZERO(&write_fds);
nfds = ares_fds(channel, &read_fds, &write_fds);
if (nfds == 0) {
return false;
}
timeval tv;
timeval *tvp = ares_timeout(channel, NULL, &tv);
res = select(nfds, &read_fds, &write_fds, NULL, tvp);
ares_process(channel, &read_fds, &write_fds);
return true;
}
18 changes: 15 additions & 3 deletions backend/mac/helper/ip_hostnames/dns_resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
#include <condition_variable>
#include <functional>
#include <map>
#include <mutex>
#include <set>
#include <string>
#include <thread>
#include <vector>

#include "ares_library_init.h"
Expand Down Expand Up @@ -36,18 +38,28 @@ class DnsResolver
private:
std::function<void(std::map<std::string, HostInfo>)> resolveDomainsCallback_;

struct USER_ARG {
struct USER_ARG
{
std::string hostname;
};

bool bStopCalled_;
std::mutex mutex_;
std::condition_variable waitCondition_;
bool bNeedFinish_;

AresLibraryInit aresLibraryInit_;
ares_channel channel_;
std::mutex mutex_;

static DnsResolver *this_;

std::map<std::string, HostInfo> hostinfoResults_;
std::set<std::string> hostnamesInProgress_;

static void aresLookupFinishedCallback(void *arg, int status, int timeouts, struct ares_addrinfo *result);
// thread specific
std::thread thread_;
static void threadFunc(void *arg);
static void aresLookupFinishedCallback(void *arg, int status, int timeouts, struct hostent *host);

bool processChannel(ares_channel channel);
};
Loading

0 comments on commit dda3af6

Please sign in to comment.