Skip to content

Commit

Permalink
Remove reachability from iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
fortuna committed Jul 11, 2023
1 parent d013d71 commit d344d65
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public class OutlineVpn: NSObject {
static let restart = "restart"
static let stop = "stop"
static let getTunnelId = "getTunnelId"
static let isServerReachable = "isServerReachable"
}

private enum MessageKey {
Expand Down Expand Up @@ -109,30 +108,6 @@ public class OutlineVpn: NSObject {
stopVpn()
}

// Determines whether a server is reachable via TCP.
public func isServerReachable(host: String, port: UInt16, _ completion: @escaping Callback) {
if isVpnConnected() {
// All the device's traffic, including the Outline app, go through the VpnExtension process.
// Performing a reachability test, opening a TCP socket to a host/port, will succeed
// unconditionally as the request will not leave the device. Send a message to the
// VpnExtension process to perform the reachability test.
let message = [MessageKey.action: Action.isServerReachable, MessageKey.host: host,
MessageKey.port: port] as [String : Any]
sendVpnExtensionMessage(message) { response in
guard response != nil else {
return completion(ErrorCode.serverUnreachable)
}
let rawCode = response?[MessageKey.errorCode] as? Int ?? ErrorCode.serverUnreachable.rawValue
completion(ErrorCode(rawValue: rawCode) ?? ErrorCode.serverUnreachable)
}
} else {
DispatchQueue.global(qos: .background).async {
let isReachable = ShadowsocksCheckServerReachable(host, Int(port), nil)
completion(isReachable ? ErrorCode.noError : ErrorCode.serverUnreachable)
}
}
}

// Calls |observer| when the VPN's status changes.
public func onVpnStatusChange(_ observer: @escaping(VpnStatusObserver)) {
vpnStatusObserver = observer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
NSString *const kActionRestart = @"restart";
NSString *const kActionStop = @"stop";
NSString *const kActionGetTunnelId = @"getTunnelId";
NSString *const kActionIsServerReachable = @"isServerReachable";
NSString *const kMessageKeyAction = @"action";
NSString *const kMessageKeyTunnelId = @"tunnelId";
NSString *const kMessageKeyConfig = @"config";
Expand Down Expand Up @@ -226,19 +225,6 @@ - (void)handleAppMessage:(NSData *)messageData completionHandler:(void (^)(NSDat
error:nil];
}
completionHandler(response);
} else if ([kActionIsServerReachable isEqualToString:action]) {
NSString *host = message[kMessageKeyHost];
NSNumber *port = message[kMessageKeyPort];
if (!host || !port) {
completionHandler(nil);
return;
}
ErrorCode errorCode = noError;
if (!ShadowsocksCheckServerReachable(host, [port intValue], nil)) {
errorCode = serverUnreachable;
}
NSDictionary *response = @{kMessageKeyErrorCode : [NSNumber numberWithLong:errorCode]};
completionHandler([NSJSONSerialization dataWithJSONObject:response options:kNilOptions error:nil]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,4 @@ final class OutlineTunnelTest: XCTestCase {

XCTAssertEqual(["1.1.1.1", "9.9.9.9", "208.67.222.222", "208.67.220.220"], settings.dnsSettings?.servers)
}

func testReachability() {
// TODO(fortuna): run a local server instead.
XCTAssertTrue(ShadowsocksCheckServerReachable("8.8.8.8", 853, nil))
XCTAssertTrue(ShadowsocksCheckServerReachable("google.com", 443, nil))
XCTAssertFalse(ShadowsocksCheckServerReachable("nonexistent.getoutline.org", 443, nil))
}
}
13 changes: 0 additions & 13 deletions src/cordova/plugin/apple/src/OutlinePlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,6 @@ class OutlinePlugin: CDVPlugin {
sendSuccess(OutlineVpn.shared.isActive(tunnelId), callbackId: command.callbackId)
}

func isServerReachable(_ command: CDVInvokedUrlCommand) {
DDLogInfo("isServerReachable")
guard let host = command.argument(at: 0) as? String else {
return sendError("Missing host address" , callbackId: command.callbackId)
}
guard let port = command.argument(at: 1) as? UInt16 else {
return sendError("Missing host port", callbackId: command.callbackId)
}
OutlineVpn.shared.isServerReachable(host: host, port: port) { errorCode in
self.sendSuccess(errorCode == OutlineVpn.ErrorCode.noError, callbackId: command.callbackId)
}
}

func onStatusChange(_ command: CDVInvokedUrlCommand) {
guard let tunnelId = command.argument(at: 0) as? String else {
return sendError("Missing tunnel ID", callbackId: command.callbackId)
Expand Down

0 comments on commit d344d65

Please sign in to comment.