From 036e9f9ab403ebc29e71e6a86c66b4eed7d75a5d Mon Sep 17 00:00:00 2001 From: Sergey Abramchuk Date: Mon, 1 May 2017 13:07:07 +0300 Subject: [PATCH] Call clock_tick method --- OpenVPN Adapter/OpenVPNAdapter+Internal.h | 1 + OpenVPN Adapter/OpenVPNAdapter+Public.h | 4 +- OpenVPN Adapter/OpenVPNAdapter.mm | 83 +++++++++++++---------- OpenVPN Adapter/OpenVPNClient.h | 2 + OpenVPN Adapter/OpenVPNClient.mm | 5 +- 5 files changed, 56 insertions(+), 39 deletions(-) diff --git a/OpenVPN Adapter/OpenVPNAdapter+Internal.h b/OpenVPN Adapter/OpenVPNAdapter+Internal.h index 454906c..bbc2593 100644 --- a/OpenVPN Adapter/OpenVPNAdapter+Internal.h +++ b/OpenVPN Adapter/OpenVPNAdapter+Internal.h @@ -16,5 +16,6 @@ using namespace openvpn; - (void)handleEvent:(const ClientAPI::Event *)event; - (void)handleLog:(const ClientAPI::LogInfo *)log; +- (void)tick; @end diff --git a/OpenVPN Adapter/OpenVPNAdapter+Public.h b/OpenVPN Adapter/OpenVPNAdapter+Public.h index c023a7c..7eb5831 100644 --- a/OpenVPN Adapter/OpenVPNAdapter+Public.h +++ b/OpenVPN Adapter/OpenVPNAdapter+Public.h @@ -99,12 +99,12 @@ NS_SWIFT_NAME(handle(logMessage:)); @interface OpenVPNAdapter (Public) /** - Returns core copyright + Return core copyright */ @property (class, nonnull, readonly, nonatomic) NSString *copyright; /** - Returns platform description + Return platform description */ @property (class, nonnull, readonly, nonatomic) NSString *platform; diff --git a/OpenVPN Adapter/OpenVPNAdapter.mm b/OpenVPN Adapter/OpenVPNAdapter.mm index 32809f1..50dc92e 100644 --- a/OpenVPN Adapter/OpenVPNAdapter.mm +++ b/OpenVPN Adapter/OpenVPNAdapter.mm @@ -41,6 +41,7 @@ NSString * const OpenVPNAdapterErrorEventKey = @"me.ss-abramchuk.openvpn-adapter @property (weak, nonatomic) id packetFlow; +- (OpenVPNEvent)getEventIdentifierByName:(NSString *)eventName; - (NSString *)getSubnetFromPrefixLength:(NSNumber *)prefixLength; @end @@ -85,43 +86,14 @@ NSString * const OpenVPNAdapterErrorEventKey = @"me.ss-abramchuk.openvpn-adapter } } -- (OpenVPNEvent)getEventIdentifierByName:(NSString *)eventName { - NSDictionary *events = @{ - @"DISCONNECTED": @(OpenVPNEventDisconnected), - @"CONNECTED": @(OpenVPNEventConnected), - @"RECONNECTING": @(OpenVPNEventReconnecting), - @"RESOLVE": @(OpenVPNEventResolve), - @"WAIT": @(OpenVPNEventWait), - @"WAIT_PROXY": @(OpenVPNEventWaitProxy), - @"CONNECTING": @(OpenVPNEventConnecting), - @"GET_CONFIG": @(OpenVPNEventGetConfig), - @"ASSIGN_IP": @(OpenVPNEventAssignIP), - @"ADD_ROUTES": @(OpenVPNEventAddRoutes), - @"ECHO": @(OpenVPNEventEcho), - @"INFO": @(OpenVPNEventInfo), - @"PAUSE": @(OpenVPNEventPause), - @"RESUME": @(OpenVPNEventResume), - @"TRANSPORT_ERROR": @(OpenVPNEventTransportError), - @"TUN_ERROR": @(OpenVPNEventTunError), - @"CLIENT_RESTART": @(OpenVPNEventClientRestart), - @"AUTH_FAILED": @(OpenVPNEventAuthFailed), - @"CERT_VERIFY_FAIL": @(OpenVPNEventCertVerifyFail), - @"TLS_VERSION_MIN": @(OpenVPNEventTLSVersionMin), - @"CLIENT_HALT": @(OpenVPNEventClientHalt), - @"CONNECTION_TIMEOUT": @(OpenVPNEventConnectionTimeout), - @"INACTIVE_TIMEOUT": @(OpenVPNEventInactiveTimeout), - @"DYNAMIC_CHALLENGE": @(OpenVPNEventDynamicChallenge), - @"PROXY_NEED_CREDS": @(OpenVPNEventProxyNeedCreds), - @"PROXY_ERROR": @(OpenVPNEventProxyError), - @"TUN_SETUP_FAILED": @(OpenVPNEventTunSetupFailed), - @"TUN_IFACE_CREATE": @(OpenVPNEventTunIfaceCreate), - @"TUN_IFACE_DISABLED": @(OpenVPNEventTunIfaceDisabled), - @"EPKI_ERROR": @(OpenVPNEventEPKIError), - @"EPKI_INVALID_ALIAS": @(OpenVPNEventEPKIInvalidAlias), - }; +#pragma mark Clock Tick + +- (void)tick { + NSAssert(self.delegate != nil, @"delegate property should not be nil"); - OpenVPNEvent event = events[eventName] != nil ? (OpenVPNEvent)[(NSNumber *)events[eventName] unsignedIntegerValue] : OpenVPNEventUnknown; - return event; + if ([self.delegate respondsToSelector:@selector(tick)]) { + [self.delegate tick]; + } } @end @@ -262,6 +234,45 @@ NSString * const OpenVPNAdapterErrorEventKey = @"me.ss-abramchuk.openvpn-adapter #pragma mark Utils +- (OpenVPNEvent)getEventIdentifierByName:(NSString *)eventName { + NSDictionary *events = @{ + @"DISCONNECTED": @(OpenVPNEventDisconnected), + @"CONNECTED": @(OpenVPNEventConnected), + @"RECONNECTING": @(OpenVPNEventReconnecting), + @"RESOLVE": @(OpenVPNEventResolve), + @"WAIT": @(OpenVPNEventWait), + @"WAIT_PROXY": @(OpenVPNEventWaitProxy), + @"CONNECTING": @(OpenVPNEventConnecting), + @"GET_CONFIG": @(OpenVPNEventGetConfig), + @"ASSIGN_IP": @(OpenVPNEventAssignIP), + @"ADD_ROUTES": @(OpenVPNEventAddRoutes), + @"ECHO": @(OpenVPNEventEcho), + @"INFO": @(OpenVPNEventInfo), + @"PAUSE": @(OpenVPNEventPause), + @"RESUME": @(OpenVPNEventResume), + @"TRANSPORT_ERROR": @(OpenVPNEventTransportError), + @"TUN_ERROR": @(OpenVPNEventTunError), + @"CLIENT_RESTART": @(OpenVPNEventClientRestart), + @"AUTH_FAILED": @(OpenVPNEventAuthFailed), + @"CERT_VERIFY_FAIL": @(OpenVPNEventCertVerifyFail), + @"TLS_VERSION_MIN": @(OpenVPNEventTLSVersionMin), + @"CLIENT_HALT": @(OpenVPNEventClientHalt), + @"CONNECTION_TIMEOUT": @(OpenVPNEventConnectionTimeout), + @"INACTIVE_TIMEOUT": @(OpenVPNEventInactiveTimeout), + @"DYNAMIC_CHALLENGE": @(OpenVPNEventDynamicChallenge), + @"PROXY_NEED_CREDS": @(OpenVPNEventProxyNeedCreds), + @"PROXY_ERROR": @(OpenVPNEventProxyError), + @"TUN_SETUP_FAILED": @(OpenVPNEventTunSetupFailed), + @"TUN_IFACE_CREATE": @(OpenVPNEventTunIfaceCreate), + @"TUN_IFACE_DISABLED": @(OpenVPNEventTunIfaceDisabled), + @"EPKI_ERROR": @(OpenVPNEventEPKIError), + @"EPKI_INVALID_ALIAS": @(OpenVPNEventEPKIInvalidAlias), + }; + + OpenVPNEvent event = events[eventName] != nil ? (OpenVPNEvent)[(NSNumber *)events[eventName] unsignedIntegerValue] : OpenVPNEventUnknown; + return event; +} + - (NSString *)getSubnetFromPrefixLength:(NSNumber *)prefixLength { uint32_t bitmask = UINT_MAX << (sizeof(uint32_t) * 8 - prefixLength.integerValue); diff --git a/OpenVPN Adapter/OpenVPNClient.h b/OpenVPN Adapter/OpenVPNClient.h index 9356baa..dac4247 100644 --- a/OpenVPN Adapter/OpenVPNClient.h +++ b/OpenVPN Adapter/OpenVPNClient.h @@ -28,6 +28,8 @@ public: virtual void event(const ClientAPI::Event& ev) override; virtual void log(const ClientAPI::LogInfo& log) override; + virtual void clock_tick() override; + private: void* adapter; }; diff --git a/OpenVPN Adapter/OpenVPNClient.mm b/OpenVPN Adapter/OpenVPNClient.mm index b37eb1d..f444e0c 100644 --- a/OpenVPN Adapter/OpenVPNClient.mm +++ b/OpenVPN Adapter/OpenVPNClient.mm @@ -33,7 +33,6 @@ bool OpenVPNClient::pause_on_connection_timeout() { return false; } -// TODO: Provide interfacing with an OS-layer Keychain void OpenVPNClient::external_pki_cert_request(ClientAPI::ExternalPKICertRequest& certreq) { } void OpenVPNClient::external_pki_sign_request(ClientAPI::ExternalPKISignRequest& signreq) { } @@ -44,3 +43,7 @@ void OpenVPNClient::event(const ClientAPI::Event& ev) { void OpenVPNClient::log(const ClientAPI::LogInfo& log) { [(__bridge OpenVPNAdapter* )adapter handleLog:&log]; } + +void OpenVPNClient::clock_tick() { + [(__bridge OpenVPNAdapter* )adapter tick]; +}