Define OpenVPNAdapterPacketFlow and use it instead of NEPacketTunnelFlow object to simplify testing

This commit is contained in:
Sergey Abramchuk
2017-03-09 19:08:24 +03:00
parent 3c840cd0f8
commit 1e886eaca7
4 changed files with 24 additions and 7 deletions
+7 -3
View File
@@ -10,14 +10,19 @@
#import "OpenVPNAdapter.h"
@class NEPacketTunnelFlow;
@class NEPacketTunnelNetworkSettings;
@protocol OpenVPNAdapterPacketFlow <NSObject>
- (void)readPacketsWithCompletionHandler:(nonnull void (^)(NSArray<NSData *> * _Nonnull packets, NSArray<NSNumber *> * _Nonnull protocols))completionHandler;
- (BOOL)writePackets:(nonnull NSArray<NSData *> *)packets withProtocols:(nonnull NSArray<NSNumber *> *)protocols;
@end
@protocol OpenVPNAdapterDelegate <NSObject>
- (void)configureTunnelWithSettings:(nonnull NEPacketTunnelNetworkSettings *)settings
callback:(nonnull void (^)(NEPacketTunnelFlow * __nullable flow))callback
callback:(nonnull void (^)(id<OpenVPNAdapterPacketFlow> _Nullable flow))callback
NS_SWIFT_NAME(configureTunnel(settings:callback:));
- (void)handleEvent:(OpenVPNEvent)event
@@ -29,7 +34,6 @@ NS_SWIFT_NAME(handle(error:));
@end
@interface OpenVPNAdapter (Provider)
@property (strong, nonatomic, nullable) NSString *username;
+2 -2
View File
@@ -43,7 +43,7 @@ NSString * const OpenVPNAdapterErrorEventKey = @"me.ss-abramchuk.openvpn-adapter
@property CFSocketRef vpnSocket;
@property CFSocketRef tunSocket;
@property (weak, nonatomic) NEPacketTunnelFlow *packetFlow;
@property (weak, nonatomic) id<OpenVPNAdapterPacketFlow> packetFlow;
- (void)readTUNPackets;
- (void)readVPNData:(NSData *)data;
@@ -199,7 +199,7 @@ static void socketCallback(CFSocketRef socket, CFSocketCallBackType type, CFData
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
[self.delegate configureTunnelWithSettings:networkSettings callback:^(NEPacketTunnelFlow * _Nullable flow) {
[self.delegate configureTunnelWithSettings:networkSettings callback:^(id<OpenVPNAdapterPacketFlow> _Nullable flow) {
self.packetFlow = flow;
dispatch_semaphore_signal(sema);
}];