Reset tunnel depending on tunPersist settings

This commit is contained in:
Sergey Abramchuk
2019-09-26 13:01:20 +03:00
parent d1f794ae57
commit 8d167952b1
3 changed files with 29 additions and 3 deletions
+5 -2
View File
@@ -48,7 +48,8 @@
#pragma mark - OpenVPNClient Lifecycle
- (OpenVPNProperties *)applyConfiguration:(OpenVPNConfiguration *)configuration error:(NSError * __autoreleasing *)error {
ClientAPI::EvalConfig eval = self.vpnClient->eval_config(configuration.config);
ClientAPI::Config *config = new ClientAPI::Config(configuration.config);
ClientAPI::EvalConfig eval = self.vpnClient->apply_config(config);
if (eval.error) {
if (error) {
@@ -398,7 +399,9 @@
_sessionName = nil;
_packetFlowBridge = nil;
_networkSettingsBuilder = nil;
}
- (void)resetTun {
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
void (^completionHandler)(id<OpenVPNAdapterPacketFlow> _Nullable) = ^(id<OpenVPNAdapterPacketFlow> flow) {
+5
View File
@@ -51,6 +51,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)tick;
- (void)resetSettings;
- (void)resetTun;
@end
NS_ASSUME_NONNULL_END
@@ -60,6 +61,9 @@ using namespace openvpn;
class OpenVPNClient : public ClientAPI::OpenVPNClient {
public:
OpenVPNClient(id<OpenVPNClientDelegate> _Nonnull delegate);
~OpenVPNClient();
ClientAPI::EvalConfig apply_config(ClientAPI::Config* _Nonnull config);
bool tun_builder_new() override;
@@ -99,6 +103,7 @@ public:
private:
__weak id<OpenVPNClientDelegate> _Nonnull delegate;
ClientAPI::Config * _Nullable config;
};
+19 -1
View File
@@ -17,10 +17,24 @@ using ::IPv4::Addr;
OpenVPNClient::OpenVPNClient(id<OpenVPNClientDelegate> delegate): ClientAPI::OpenVPNClient() {
this->delegate = delegate;
this->config = nullptr;
}
OpenVPNClient::~OpenVPNClient() {
if (this->config != nullptr) { delete this->config; }
}
ClientAPI::EvalConfig OpenVPNClient::apply_config(ClientAPI::Config* _Nonnull config) {
if (this->config != nullptr) { delete this->config; }
this->config = config;
return eval_config(*config);
}
bool OpenVPNClient::tun_builder_new() {
[this->delegate resetSettings];
[this->delegate resetTun];
return true;
}
@@ -134,11 +148,15 @@ int OpenVPNClient::tun_builder_establish() {
}
bool OpenVPNClient::tun_builder_persist() {
return true;
return config->tunPersist;
}
void OpenVPNClient::tun_builder_teardown(bool disconnect) {
[this->delegate resetSettings];
if (disconnect || !this->tun_builder_persist()) {
[this->delegate resetTun];
}
}
bool OpenVPNClient::socket_protect(int socket, std::string remote, bool ipv6) {