mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2026-02-11 00:00:08 +08:00
Light refactoring of the packetFlow assignment
This commit is contained in:
@@ -96,6 +96,11 @@ NS_SWIFT_NAME(openVPNAdapter(_:handleEvent:message:));
|
||||
*/
|
||||
@property (nonatomic, class, readonly) NSString *platform;
|
||||
|
||||
/**
|
||||
|
||||
*/
|
||||
@property (nonatomic, weak) id<OpenVPNAdapterPacketFlow> packetFlow;
|
||||
|
||||
/**
|
||||
The object that acts as the delegate of the adapter.
|
||||
*/
|
||||
@@ -126,11 +131,6 @@ NS_SWIFT_NAME(openVPNAdapter(_:handleEvent:message:));
|
||||
*/
|
||||
@property (nonatomic, readonly) OpenVPNTransportStats *transportStatistics;
|
||||
|
||||
/**
|
||||
|
||||
*/
|
||||
- (instancetype)initWithPacketFlow:(id<OpenVPNAdapterPacketFlow>)packetFlow;
|
||||
|
||||
/**
|
||||
Applies the given configuration object.
|
||||
Call this method prior to connecting, this method has no effect after calling connect.
|
||||
@@ -181,8 +181,6 @@ NS_SWIFT_NAME(apply(configuration:));
|
||||
*/
|
||||
- (void)disconnect;
|
||||
|
||||
- (instancetype) init NS_UNAVAILABLE;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
@@ -40,10 +40,10 @@
|
||||
|
||||
@implementation OpenVPNAdapter
|
||||
|
||||
- (instancetype)initWithPacketFlow:(id<OpenVPNAdapterPacketFlow>)packetFlow {
|
||||
- (instancetype)init {
|
||||
if (self = [super init]) {
|
||||
_vpnClient = new OpenVPNClient(self);
|
||||
_packetFlowBridge = [[OpenVPNPacketFlowBridge alloc] initWithPacketFlow:packetFlow];
|
||||
_packetFlowBridge = [[OpenVPNPacketFlowBridge alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -87,6 +87,8 @@
|
||||
}
|
||||
|
||||
- (void)connect {
|
||||
NSAssert(self.packetFlow != nil, @"packetFlow property shouldn't be nil, set it before trying to establish connection.");
|
||||
|
||||
dispatch_queue_attr_t attributes = dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_UTILITY, 0);
|
||||
dispatch_queue_t connectQueue = dispatch_queue_create("me.ss-abramchuk.openvpn-adapter.connection.", attributes);
|
||||
dispatch_async(connectQueue, ^{
|
||||
@@ -166,6 +168,14 @@
|
||||
return _networkSettingsBuilder;
|
||||
}
|
||||
|
||||
- (id<OpenVPNAdapterPacketFlow>)packetFlow {
|
||||
return self.packetFlowBridge.packetFlow;
|
||||
}
|
||||
|
||||
- (void)setPacketFlow:(id<OpenVPNAdapterPacketFlow>)packetFlow {
|
||||
self.packetFlowBridge.packetFlow = packetFlow;
|
||||
}
|
||||
|
||||
#pragma mark - OpenVPNClientDelegate
|
||||
|
||||
- (BOOL)setRemoteAddress:(NSString *)address {
|
||||
|
||||
@@ -14,12 +14,11 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface OpenVPNPacketFlowBridge: NSObject
|
||||
|
||||
@property (nonatomic, weak) id<OpenVPNAdapterPacketFlow> packetFlow;
|
||||
|
||||
@property (nonatomic, readonly) CFSocketRef openVPNSocket;
|
||||
@property (nonatomic, readonly) CFSocketRef packetFlowSocket;
|
||||
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
- (instancetype)initWithPacketFlow:(id<OpenVPNAdapterPacketFlow>)packetFlow NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
- (BOOL)configureSocketsWithError:(NSError **)error;
|
||||
- (void)invalidateSocketsIfNeeded;
|
||||
|
||||
|
||||
@@ -15,21 +15,8 @@
|
||||
#import "OpenVPNPacket.h"
|
||||
#import "OpenVPNAdapterPacketFlow.h"
|
||||
|
||||
@interface OpenVPNPacketFlowBridge ()
|
||||
|
||||
@property (nonatomic) id<OpenVPNAdapterPacketFlow> packetFlow;
|
||||
|
||||
@end
|
||||
|
||||
@implementation OpenVPNPacketFlowBridge
|
||||
|
||||
- (instancetype)initWithPacketFlow:(id<OpenVPNAdapterPacketFlow>)packetFlow {
|
||||
if (self = [super init]) {
|
||||
_packetFlow = packetFlow;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - Sockets Configuration
|
||||
|
||||
static void SocketCallback(CFSocketRef socket, CFSocketCallBackType type, CFDataRef address, const void *data, void *obj) {
|
||||
|
||||
@@ -32,7 +32,7 @@ class OpenVPNAdapterTests: XCTestCase {
|
||||
func testApplyConfiguration() {
|
||||
guard let vpnConfiguration = VPNProfile.configuration.data(using: .utf8) else { fatalError() }
|
||||
|
||||
let adapter = OpenVPNAdapter(packetFlow: customFlow)
|
||||
let adapter = OpenVPNAdapter()
|
||||
|
||||
let configuration = OpenVPNConfiguration()
|
||||
configuration.fileContent = vpnConfiguration
|
||||
@@ -52,7 +52,7 @@ class OpenVPNAdapterTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testProvideCredentials() {
|
||||
let adapter = OpenVPNAdapter(packetFlow: customFlow)
|
||||
let adapter = OpenVPNAdapter()
|
||||
|
||||
let credentials = OpenVPNCredentials()
|
||||
credentials.username = "username"
|
||||
@@ -71,7 +71,7 @@ class OpenVPNAdapterTests: XCTestCase {
|
||||
func testConnection() {
|
||||
guard let vpnConfiguration = VPNProfile.configuration.data(using: .utf8) else { fatalError() }
|
||||
|
||||
let adapter = OpenVPNAdapter(packetFlow: customFlow)
|
||||
let adapter = OpenVPNAdapter()
|
||||
|
||||
let configuration = OpenVPNConfiguration()
|
||||
configuration.fileContent = vpnConfiguration
|
||||
@@ -99,6 +99,7 @@ class OpenVPNAdapterTests: XCTestCase {
|
||||
|
||||
expectations[.connection] = expectation(description: "me.ss-abramchuk.openvpn-adapter.connection")
|
||||
|
||||
adapter.packetFlow = customFlow
|
||||
adapter.delegate = self
|
||||
adapter.connect()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user