Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changes to make proxy gateway only start while VPN is ON, and quit wh… #171

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/engine/engine/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2186,13 +2186,13 @@ void Engine::checkForceDisconnectNode(const QStringList & /*forceDisconnectNodes

void Engine::startProxySharingImpl(PROXY_SHARING_TYPE proxySharingType, uint port)
{
vpnShareController_->startProxySharing(proxySharingType, port);
vpnShareController_->activateProxySharing(proxySharingType, port);
emit proxySharingStateChanged(true, proxySharingType, getProxySharingAddress(), 0);
}

void Engine::stopProxySharingImpl()
{
vpnShareController_->stopProxySharing();
vpnShareController_->deactivateProxySharing();
emit proxySharingStateChanged(false, PROXY_SHARING_HTTP, "", 0);
}

Expand Down
29 changes: 28 additions & 1 deletion client/engine/engine/vpnshare/vpnsharecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
VpnShareController::VpnShareController(QObject *parent, IHelper *helper) : QObject(parent),
helper_(helper),
httpProxyServer_(NULL),
socksProxyServer_(NULL)
socksProxyServer_(NULL),
bProxySharingActivated_(false)
#ifdef Q_OS_WIN
,wifiSharing_(NULL)
#endif
Expand All @@ -32,12 +33,27 @@ VpnShareController::~VpnShareController()
#endif
}

void VpnShareController::activateProxySharing(PROXY_SHARING_TYPE proxyType, uint port)
{
// don't actually start the service unless the VPN is on
// it will be considered activated but not started till VPN is turned on
bProxySharingActivated_ = true;
ActivatedProxySharingType_ = proxyType;
port_ = port;
}

void VpnShareController::startProxySharing(PROXY_SHARING_TYPE proxyType, uint port)
{
QMutexLocker locker(&mutex_);

SAFE_DELETE(httpProxyServer_);
SAFE_DELETE(socksProxyServer_);

if(!bProxySharingActivated_)
{
return;
}

if (proxyType == PROXY_SHARING_HTTP)
{
httpProxyServer_ = new HttpProxyServer::HttpProxyServer(this);
Expand Down Expand Up @@ -79,6 +95,12 @@ void VpnShareController::startProxySharing(PROXY_SHARING_TYPE proxyType, uint po
}
}

void VpnShareController::deactivateProxySharing()
{
bProxySharingActivated_ = false;
stopProxySharing();
}

void VpnShareController::stopProxySharing()
{
QMutexLocker locker(&mutex_);
Expand Down Expand Up @@ -244,6 +266,10 @@ void VpnShareController::onConnectedToVPNEvent(const QString &vpnAdapterName)
{
socksProxyServer_->closeActiveConnections();
}
if (bProxySharingActivated_)
{
startProxySharing(ActivatedProxySharingType_, port_);
}
}

void VpnShareController::onDisconnectedFromVPNEvent()
Expand All @@ -263,6 +289,7 @@ void VpnShareController::onDisconnectedFromVPNEvent()
{
socksProxyServer_->closeActiveConnections();
}
stopProxySharing();
}

bool VpnShareController::getLastSavedPort(uint &outPort)
Expand Down
6 changes: 6 additions & 0 deletions client/engine/engine/vpnshare/vpnsharecontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class VpnShareController : public QObject
void startProxySharing(PROXY_SHARING_TYPE proxyType, uint port);
void stopProxySharing();

void activateProxySharing(PROXY_SHARING_TYPE proxyType, uint port);
void deactivateProxySharing();

bool isWifiSharingSupported();
void startWifiSharing(const QString &ssid, const QString &password);
void stopWifiSharing();
Expand All @@ -46,6 +49,9 @@ private slots:
private:
QRecursiveMutex mutex_;
IHelper *helper_;
bool bProxySharingActivated_;
PROXY_SHARING_TYPE ActivatedProxySharingType_;
uint port_;
HttpProxyServer::HttpProxyServer *httpProxyServer_;
SocksProxyServer::SocksProxyServer *socksProxyServer_;
#ifdef Q_OS_WIN
Expand Down