diff --git a/src/cordova/apple/OutlineAppleLib/Sources/OutlineTunnelSources/OutlineVpn.swift b/src/cordova/apple/OutlineAppleLib/Sources/OutlineTunnelSources/OutlineVpn.swift index 04f3825179..9418fb1a16 100644 --- a/src/cordova/apple/OutlineAppleLib/Sources/OutlineTunnelSources/OutlineVpn.swift +++ b/src/cordova/apple/OutlineAppleLib/Sources/OutlineTunnelSources/OutlineVpn.swift @@ -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 { @@ -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 diff --git a/src/cordova/apple/OutlineAppleLib/Sources/PacketTunnelProviderSources/PacketTunnelProvider.m b/src/cordova/apple/OutlineAppleLib/Sources/PacketTunnelProviderSources/PacketTunnelProvider.m index 00ded12b74..46c42ff608 100644 --- a/src/cordova/apple/OutlineAppleLib/Sources/PacketTunnelProviderSources/PacketTunnelProvider.m +++ b/src/cordova/apple/OutlineAppleLib/Sources/PacketTunnelProviderSources/PacketTunnelProvider.m @@ -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"; @@ -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]); } } diff --git a/src/cordova/apple/OutlineAppleLib/Tests/OutlineTunnelTest/OutlineTunnelTest.swift b/src/cordova/apple/OutlineAppleLib/Tests/OutlineTunnelTest/OutlineTunnelTest.swift index 344b277553..f9ffd22b09 100644 --- a/src/cordova/apple/OutlineAppleLib/Tests/OutlineTunnelTest/OutlineTunnelTest.swift +++ b/src/cordova/apple/OutlineAppleLib/Tests/OutlineTunnelTest/OutlineTunnelTest.swift @@ -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)) - } } diff --git a/src/cordova/plugin/apple/src/OutlinePlugin.swift b/src/cordova/plugin/apple/src/OutlinePlugin.swift index 4b8ea2df53..7a6cc21f60 100644 --- a/src/cordova/plugin/apple/src/OutlinePlugin.swift +++ b/src/cordova/plugin/apple/src/OutlinePlugin.swift @@ -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) diff --git a/src/electron/connectivity.ts b/src/electron/connectivity.ts deleted file mode 100644 index 28fa722095..0000000000 --- a/src/electron/connectivity.ts +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2019 The Outline Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import * as dns from 'dns'; -import * as net from 'net'; - -import {timeoutPromise} from '../infrastructure/timeout_promise'; -import * as errors from '../www/model/errors'; - -const DNS_LOOKUP_TIMEOUT_MS = 10000; - -// Uses the OS' built-in functions, i.e. /etc/hosts, et al.: -// https://nodejs.org/dist/latest-v10.x/docs/api/dns.html#dns_dns -// -// Effectively a no-op if hostname is already an IP. -export function lookupIp(hostname: string): Promise { - return timeoutPromise( - new Promise((fulfill, reject) => { - dns.lookup(hostname, 4, (e, address) => { - if (e) { - return reject(new errors.ServerUnreachable('could not resolve proxy server hostname')); - } - fulfill(address); - }); - }), - DNS_LOOKUP_TIMEOUT_MS, - 'DNS lookup' - ); -} - -// Resolves iff a (TCP) connection can be established with the specified destination within the -// specified timeout (zero means "no timeout"), optionally retrying with a delay. -export function isServerReachable( - host: string, - port: number, - timeout = 0, - maxAttempts = 1, - retryIntervalMs = 0 -): Promise { - let attempt = 0; - return new Promise((fulfill, reject) => { - const connect = () => { - attempt++; - - const socket = new net.Socket(); - socket.once('error', () => { - if (attempt < maxAttempts) { - setTimeout(connect, retryIntervalMs); - } else { - reject(new errors.ServerUnreachable()); - } - }); - - if (timeout > 0) { - socket.setTimeout(timeout); - } - - socket.connect({host, port}, () => { - socket.end(); - fulfill(); - }); - }; - connect(); - }); -} diff --git a/src/electron/index.ts b/src/electron/index.ts index c253cf28a3..e7b16afaed 100644 --- a/src/electron/index.ts +++ b/src/electron/index.ts @@ -23,7 +23,6 @@ import * as process from 'process'; import * as url from 'url'; import autoLaunch = require('auto-launch'); // tslint:disable-line -import * as connectivity from './connectivity'; import * as errors from '../www/model/errors'; import {ShadowsocksSessionConfig} from '../www/app/tunnel'; @@ -72,8 +71,6 @@ const enum Options { AUTOSTART = '--autostart', } -const REACHABILITY_TIMEOUT_MS = 10000; - let currentTunnel: VpnTunnel | undefined; /** @@ -452,17 +449,7 @@ function main() { mainWindow?.webContents.send('outline-ipc-push-clipboard'); }); - // TODO: refactor channel name and namespace to a constant - ipcMain.handle('outline-ipc-is-server-reachable', async (_, args: {hostname: string; port: number}) => { - try { - await connectivity.isServerReachable(args.hostname || '', args.port || 0, REACHABILITY_TIMEOUT_MS); - return true; - } catch { - return false; - } - }); - - // Connects to the specified server, if that server is reachable and the credentials are valid. + // Connects to the specified server. // TODO: refactor channel name and namespace to a constant ipcMain.handle( 'outline-ipc-start-proxying', @@ -479,12 +466,6 @@ function main() { console.log(`connecting to ${args.id}...`); try { - // Rather than repeadedly resolving a hostname in what may be a fingerprint-able way, - // resolve it just once, upfront. - args.config.host = await connectivity.lookupIp(args.config.host || ''); - - await connectivity.isServerReachable(args.config.host || '', args.config.port || 0, REACHABILITY_TIMEOUT_MS); - await startVpn(args.config, args.id); console.log(`connected to ${args.id}`); await setupAutoLaunch(args); diff --git a/src/www/app/app.ts b/src/www/app/app.ts index 5c0d363405..6c44e5c739 100644 --- a/src/www/app/app.ts +++ b/src/www/app/app.ts @@ -622,17 +622,8 @@ export class App { private async syncServerConnectivityState(server: Server) { try { const isRunning = await server.checkRunning(); - if (!isRunning) { - this.updateServerListItem(server.id, {connectionState: ServerConnectionState.DISCONNECTED}); - return; - } - const isReachable = await server.checkReachable(); - if (isReachable) { - this.updateServerListItem(server.id, {connectionState: ServerConnectionState.CONNECTED}); - } else { - console.log(`Server ${server.id} reconnecting`); - this.updateServerListItem(server.id, {connectionState: ServerConnectionState.RECONNECTING}); - } + const connectionState = isRunning ? ServerConnectionState.CONNECTED : ServerConnectionState.DISCONNECTED; + this.updateServerListItem(server.id, {connectionState}); } catch (e) { console.error('Failed to sync server connectivity state', e); } diff --git a/src/www/app/cordova_main.ts b/src/www/app/cordova_main.ts index e5551ad87f..b3f6e40427 100644 --- a/src/www/app/cordova_main.ts +++ b/src/www/app/cordova_main.ts @@ -27,10 +27,8 @@ import * as Sentry from '@sentry/browser'; import {AbstractClipboard} from './clipboard'; import {EnvironmentVariables} from './environment'; import {SentryErrorReporter} from './error_reporter'; -import {FakeNativeNetworking} from './fake_net'; import {main} from './main'; import * as errors from '../model/errors'; -import {NativeNetworking} from './net'; import {OutlinePlatform} from './platform'; import {Tunnel, TunnelStatus} from './tunnel'; import {AbstractUpdater} from './updater'; @@ -88,12 +86,6 @@ class CordovaErrorReporter extends SentryErrorReporter { } } -class CordovaNativeNetworking implements NativeNetworking { - async isServerReachable(hostname: string, port: number) { - return await pluginExecWithErrorCode('isServerReachable', hostname, port); - } -} - class CordovaTunnel implements Tunnel { constructor(public id: string) {} @@ -131,10 +123,6 @@ class CordovaPlatform implements OutlinePlatform { return !CordovaPlatform.isBrowser(); } - getNativeNetworking() { - return this.hasDeviceSupport() ? new CordovaNativeNetworking() : new FakeNativeNetworking(); - } - getTunnelFactory() { return (id: string) => { return this.hasDeviceSupport() ? new CordovaTunnel(id) : new FakeOutlineTunnel(id); diff --git a/src/www/app/electron_main.ts b/src/www/app/electron_main.ts index 9b51e47bec..e6583669a9 100644 --- a/src/www/app/electron_main.ts +++ b/src/www/app/electron_main.ts @@ -24,10 +24,8 @@ import {ErrorCode, OutlinePluginError} from '../model/errors'; import {AbstractClipboard} from './clipboard'; import {ElectronOutlineTunnel} from './electron_outline_tunnel'; import {getSentryBrowserIntegrations, OutlineErrorReporter} from './error_reporter'; -import {FakeNativeNetworking} from './fake_net'; import {FakeOutlineTunnel} from './fake_tunnel'; import {getLocalizationFunction, main} from './main'; -import {NativeNetworking} from './net'; import {AbstractUpdater} from './updater'; import {UrlInterceptor} from './url_interceptor'; import {VpnInstaller} from './vpn_installer'; @@ -102,17 +100,8 @@ class ElectronErrorReporter implements OutlineErrorReporter { } } -class ElectronNativeNetworking implements NativeNetworking { - isServerReachable(hostname: string, port: number): Promise { - return window.electron.methodChannel.invoke('is-server-reachable', {hostname, port}); - } -} - main({ hasDeviceSupport: () => isOsSupported, - getNativeNetworking: () => { - return isOsSupported ? new ElectronNativeNetworking() : new FakeNativeNetworking(); - }, getTunnelFactory: () => { return (id: string) => { return isOsSupported ? new ElectronOutlineTunnel(id) : new FakeOutlineTunnel(id); diff --git a/src/www/app/fake_net.ts b/src/www/app/fake_net.ts deleted file mode 100644 index 26e0e6e015..0000000000 --- a/src/www/app/fake_net.ts +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2021 The Outline Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import {NativeNetworking} from './net'; - -export class FakeNativeNetworking implements NativeNetworking { - async isServerReachable(hostname: string, _port: number) { - return !hostname.includes('unreachable'); - } -} diff --git a/src/www/app/main.ts b/src/www/app/main.ts index e1f9fb1811..18ec3d8308 100644 --- a/src/www/app/main.ts +++ b/src/www/app/main.ts @@ -18,7 +18,6 @@ import {EventQueue} from '../model/events'; import {App} from './app'; import {onceEnvVars} from './environment'; -import {NativeNetworking} from './net'; import {OutlineServerRepository} from './outline_server_repository'; import {makeConfig, SIP002_URI} from 'ShadowsocksConfig'; import {OutlinePlatform} from './platform'; @@ -52,10 +51,9 @@ function createServerRepo( eventQueue: EventQueue, storage: Storage, deviceSupport: boolean, - net: NativeNetworking, createTunnel: TunnelFactory ) { - const repo = new OutlineServerRepository(net, createTunnel, eventQueue, storage); + const repo = new OutlineServerRepository(createTunnel, eventQueue, storage); if (!deviceSupport) { console.debug('Detected development environment, using fake servers.'); if (repo.getAll().length === 0) { @@ -107,7 +105,6 @@ export function main(platform: OutlinePlatform) { eventQueue, window.localStorage, platform.hasDeviceSupport(), - platform.getNativeNetworking(), platform.getTunnelFactory() ); const settings = new Settings(); diff --git a/src/www/app/net.ts b/src/www/app/net.ts deleted file mode 100644 index 4ddc9fc69d..0000000000 --- a/src/www/app/net.ts +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2021 The Outline Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Exposes native networking capabilities to the web app. -export interface NativeNetworking { - // Returns whether a server is reachable via TCP at address `${hostname}:${port}`. - isServerReachable(hostname: string, port: number): Promise; -} diff --git a/src/www/app/outline_server_repository/index.ts b/src/www/app/outline_server_repository/index.ts index dc72f7a9da..3885e8f278 100644 --- a/src/www/app/outline_server_repository/index.ts +++ b/src/www/app/outline_server_repository/index.ts @@ -19,7 +19,6 @@ import * as errors from '../../model/errors'; import * as events from '../../model/events'; import {ServerRepository, ServerType} from '../../model/server'; -import {NativeNetworking} from '../net'; import {TunnelFactory} from '../tunnel'; import {OutlineServer} from './server'; @@ -109,7 +108,6 @@ export class OutlineServerRepository implements ServerRepository { private lastForgottenServer: OutlineServer | null = null; constructor( - private readonly net: NativeNetworking, private readonly createTunnel: TunnelFactory, private eventQueue: events.EventQueue, private storage: Storage @@ -312,7 +310,6 @@ export class OutlineServerRepository implements ServerRepository { isDynamicAccessKey(accessKey) ? ServerType.DYNAMIC_CONNECTION : ServerType.STATIC_CONNECTION, name, this.createTunnel(id), - this.net, this.eventQueue ); diff --git a/src/www/app/outline_server_repository/outline_server_repository.spec.ts b/src/www/app/outline_server_repository/outline_server_repository.spec.ts index a99287247d..9a424cb8ba 100644 --- a/src/www/app/outline_server_repository/outline_server_repository.spec.ts +++ b/src/www/app/outline_server_repository/outline_server_repository.spec.ts @@ -16,7 +16,6 @@ import {InMemoryStorage} from '../../../infrastructure/memory_storage'; import {ServerIncompatible, ServerUrlInvalid, ShadowsocksUnsupportedCipher} from '../../model/errors'; import {EventQueue, ServerAdded, ServerForgetUndone, ServerForgotten, ServerRenamed} from '../../model/events'; -import {FakeNativeNetworking} from '../fake_net'; import {FakeOutlineTunnel} from '../fake_tunnel'; import {OutlineServerRepository, ServersStorageV0, ServersStorageV1, serversStorageV0ConfigToAccessKey} from '.'; @@ -50,12 +49,7 @@ describe('OutlineServerRepository', () => { const storage = new InMemoryStorage( new Map([[OutlineServerRepository.SERVERS_STORAGE_KEY_V0, JSON.stringify(storageV0)]]) ); - const repo = new OutlineServerRepository( - new FakeNativeNetworking(), - getFakeTunnelFactory(), - new EventQueue(), - storage - ); + const repo = new OutlineServerRepository(getFakeTunnelFactory(), new EventQueue(), storage); const server0 = repo.getById('server-0'); expect(server0?.accessKey).toEqual(serversStorageV0ConfigToAccessKey(CONFIG_0_V0)); expect(server0?.name).toEqual(CONFIG_0_V0.name); @@ -77,12 +71,7 @@ describe('OutlineServerRepository', () => { [OutlineServerRepository.SERVERS_STORAGE_KEY, JSON.stringify(storageV1)], ]) ); - const repo = new OutlineServerRepository( - new FakeNativeNetworking(), - getFakeTunnelFactory(), - new EventQueue(), - storage - ); + const repo = new OutlineServerRepository(getFakeTunnelFactory(), new EventQueue(), storage); const server0 = repo.getById('server-0'); expect(server0?.accessKey).toEqual(serversStorageV0ConfigToAccessKey(CONFIG_0_V0)); expect(server0?.name).toEqual(CONFIG_0_V0.name); @@ -99,12 +88,7 @@ describe('OutlineServerRepository', () => { const storage = new InMemoryStorage( new Map([[OutlineServerRepository.SERVERS_STORAGE_KEY_V0, JSON.stringify(storageV0)]]) ); - const repo = new OutlineServerRepository( - new FakeNativeNetworking(), - getFakeTunnelFactory(), - new EventQueue(), - storage - ); + const repo = new OutlineServerRepository(getFakeTunnelFactory(), new EventQueue(), storage); // Trigger storage change. repo.forget('server-1'); repo.undoForget('server-1'); @@ -124,12 +108,7 @@ describe('OutlineServerRepository', () => { it('add stores servers', () => { const storage = new InMemoryStorage(); - const repo = new OutlineServerRepository( - new FakeNativeNetworking(), - getFakeTunnelFactory(), - new EventQueue(), - storage - ); + const repo = new OutlineServerRepository(getFakeTunnelFactory(), new EventQueue(), storage); const accessKey0 = serversStorageV0ConfigToAccessKey(CONFIG_0_V0); const accessKey1 = serversStorageV0ConfigToAccessKey(CONFIG_1_V0); repo.add(accessKey0); @@ -144,12 +123,7 @@ describe('OutlineServerRepository', () => { it('add emits ServerAdded event', () => { const eventQueue = new EventQueue(); - const repo = new OutlineServerRepository( - new FakeNativeNetworking(), - getFakeTunnelFactory(), - eventQueue, - new InMemoryStorage() - ); + const repo = new OutlineServerRepository(getFakeTunnelFactory(), eventQueue, new InMemoryStorage()); const accessKey = serversStorageV0ConfigToAccessKey(CONFIG_0_V0); repo.add(accessKey); let didEmitServerAddedEvent = false; @@ -164,23 +138,13 @@ describe('OutlineServerRepository', () => { }); it('add throws on invalid access keys', () => { - const repo = new OutlineServerRepository( - new FakeNativeNetworking(), - getFakeTunnelFactory(), - new EventQueue(), - new InMemoryStorage() - ); + const repo = new OutlineServerRepository(getFakeTunnelFactory(), new EventQueue(), new InMemoryStorage()); expect(() => repo.add('ss://invalid')).toThrowError(ServerUrlInvalid); expect(() => repo.add('')).toThrowError(ServerUrlInvalid); }); it('getAll returns added servers', () => { - const repo = new OutlineServerRepository( - new FakeNativeNetworking(), - getFakeTunnelFactory(), - new EventQueue(), - new InMemoryStorage() - ); + const repo = new OutlineServerRepository(getFakeTunnelFactory(), new EventQueue(), new InMemoryStorage()); expect(repo.getAll()).toEqual([]); const accessKey0 = serversStorageV0ConfigToAccessKey(CONFIG_0_V0); const accessKey1 = serversStorageV0ConfigToAccessKey(CONFIG_1_V0); @@ -197,12 +161,7 @@ describe('OutlineServerRepository', () => { }); it('getById retrieves added servers', () => { - const repo = new OutlineServerRepository( - new FakeNativeNetworking(), - getFakeTunnelFactory(), - new EventQueue(), - new InMemoryStorage() - ); + const repo = new OutlineServerRepository(getFakeTunnelFactory(), new EventQueue(), new InMemoryStorage()); const accessKey = serversStorageV0ConfigToAccessKey(CONFIG_0_V0); repo.add(accessKey); const serverId = repo.getAll()[0].id; @@ -213,12 +172,7 @@ describe('OutlineServerRepository', () => { }); it('getById returns undefined for nonexistent servers', () => { - const repo = new OutlineServerRepository( - new FakeNativeNetworking(), - getFakeTunnelFactory(), - new EventQueue(), - new InMemoryStorage() - ); + const repo = new OutlineServerRepository(getFakeTunnelFactory(), new EventQueue(), new InMemoryStorage()); expect(repo.getById('server-does-not-exist')).toBeUndefined(); expect(repo.getById('')).toBeUndefined(); }); @@ -226,12 +180,7 @@ describe('OutlineServerRepository', () => { it('renames servers', () => { const NEW_SERVER_NAME = 'new server name'; const storage = new InMemoryStorage(); - const repo = new OutlineServerRepository( - new FakeNativeNetworking(), - getFakeTunnelFactory(), - new EventQueue(), - storage - ); + const repo = new OutlineServerRepository(getFakeTunnelFactory(), new EventQueue(), storage); repo.add(serversStorageV0ConfigToAccessKey(CONFIG_0_V0)); const server = repo.getAll()[0]; repo.rename(server.id, NEW_SERVER_NAME); @@ -245,12 +194,7 @@ describe('OutlineServerRepository', () => { const NEW_SERVER_NAME = 'new server name'; const eventQueue = new EventQueue(); eventQueue.subscribe(ServerAdded, () => {}); // Silence dropped event warnings. - const repo = new OutlineServerRepository( - new FakeNativeNetworking(), - getFakeTunnelFactory(), - eventQueue, - new InMemoryStorage() - ); + const repo = new OutlineServerRepository(getFakeTunnelFactory(), eventQueue, new InMemoryStorage()); const accessKey = serversStorageV0ConfigToAccessKey(CONFIG_0_V0); repo.add(accessKey); const server = repo.getAll()[0]; @@ -266,12 +210,7 @@ describe('OutlineServerRepository', () => { it('forgets servers', () => { const storage = new InMemoryStorage(); - const repo = new OutlineServerRepository( - new FakeNativeNetworking(), - getFakeTunnelFactory(), - new EventQueue(), - storage - ); + const repo = new OutlineServerRepository(getFakeTunnelFactory(), new EventQueue(), storage); repo.add(serversStorageV0ConfigToAccessKey(CONFIG_0_V0)); repo.add(serversStorageV0ConfigToAccessKey(CONFIG_1_V0)); const forgottenServerId = repo.getAll()[0].id; @@ -288,12 +227,7 @@ describe('OutlineServerRepository', () => { it('forget emits ServerForgotten events', () => { const eventQueue = new EventQueue(); eventQueue.subscribe(ServerAdded, () => {}); // Silence dropped event warnings. - const repo = new OutlineServerRepository( - new FakeNativeNetworking(), - getFakeTunnelFactory(), - eventQueue, - new InMemoryStorage() - ); + const repo = new OutlineServerRepository(getFakeTunnelFactory(), eventQueue, new InMemoryStorage()); repo.add(serversStorageV0ConfigToAccessKey(CONFIG_0_V0)); repo.add(serversStorageV0ConfigToAccessKey(CONFIG_1_V0)); const forgottenServerId = repo.getAll()[0].id; @@ -309,12 +243,7 @@ describe('OutlineServerRepository', () => { it('undoes forgetting servers', () => { const storage = new InMemoryStorage(); - const repo = new OutlineServerRepository( - new FakeNativeNetworking(), - getFakeTunnelFactory(), - new EventQueue(), - storage - ); + const repo = new OutlineServerRepository(getFakeTunnelFactory(), new EventQueue(), storage); repo.add(serversStorageV0ConfigToAccessKey(CONFIG_0_V0)); repo.add(serversStorageV0ConfigToAccessKey(CONFIG_1_V0)); const forgottenServerId = repo.getAll()[0].id; @@ -335,12 +264,7 @@ describe('OutlineServerRepository', () => { // Silence dropped event warnings. eventQueue.subscribe(ServerAdded, () => {}); eventQueue.subscribe(ServerForgotten, () => {}); - const repo = new OutlineServerRepository( - new FakeNativeNetworking(), - getFakeTunnelFactory(), - eventQueue, - new InMemoryStorage() - ); + const repo = new OutlineServerRepository(getFakeTunnelFactory(), eventQueue, new InMemoryStorage()); repo.add(serversStorageV0ConfigToAccessKey(CONFIG_0_V0)); repo.add(serversStorageV0ConfigToAccessKey(CONFIG_1_V0)); const forgottenServerId = repo.getAll()[0].id; @@ -356,12 +280,7 @@ describe('OutlineServerRepository', () => { }); it('validates static access keys', () => { - const repo = new OutlineServerRepository( - new FakeNativeNetworking(), - getFakeTunnelFactory(), - new EventQueue(), - new InMemoryStorage() - ); + const repo = new OutlineServerRepository(getFakeTunnelFactory(), new EventQueue(), new InMemoryStorage()); // Invalid access keys. expect(() => repo.validateAccessKey('')).toThrowError(ServerUrlInvalid); expect(() => repo.validateAccessKey('ss://invalid')).toThrowError(ServerUrlInvalid); diff --git a/src/www/app/outline_server_repository/server.ts b/src/www/app/outline_server_repository/server.ts index 6ddf1016bc..ed94aa24ee 100644 --- a/src/www/app/outline_server_repository/server.ts +++ b/src/www/app/outline_server_repository/server.ts @@ -16,7 +16,6 @@ import * as errors from '../../model/errors'; import * as events from '../../model/events'; import {Server, ServerType} from '../../model/server'; -import {NativeNetworking} from '../net'; import {Tunnel, TunnelStatus, ShadowsocksSessionConfig} from '../tunnel'; import {fetchShadowsocksSessionConfig, staticKeyToShadowsocksSessionConfig} from './access_key_serialization'; @@ -37,7 +36,6 @@ export class OutlineServer implements Server { public readonly type: ServerType, private _name: string, private tunnel: Tunnel, - private net: NativeNetworking, private eventQueue: events.EventQueue ) { switch (this.type) { @@ -131,15 +129,6 @@ export class OutlineServer implements Server { return this.tunnel.isRunning(); } - // NOTE: you should only be calling this method on running servers - checkReachable(): Promise { - if (!this.sessionConfig) { - return Promise.resolve(false); - } - - return this.net.isServerReachable(this.sessionConfig.host, this.sessionConfig.port); - } - static isServerCipherSupported(cipher?: string) { return cipher !== undefined && OutlineServer.SUPPORTED_CIPHERS.includes(cipher); } diff --git a/src/www/app/platform.ts b/src/www/app/platform.ts index 4ae2eef2e0..b9746dc2a3 100644 --- a/src/www/app/platform.ts +++ b/src/www/app/platform.ts @@ -15,7 +15,6 @@ import {Clipboard} from './clipboard'; import {EnvironmentVariables} from './environment'; import {OutlineErrorReporter} from './error_reporter'; -import {NativeNetworking} from './net'; import {TunnelFactory} from './tunnel'; import {Updater} from './updater'; import {UrlInterceptor} from './url_interceptor'; @@ -30,8 +29,6 @@ export interface OutlinePlatform { // assume it's running in demo mode, e.g. Electron on macOS. hasDeviceSupport(): boolean; - getNativeNetworking(): NativeNetworking; - getTunnelFactory(): TunnelFactory; getUrlInterceptor(): UrlInterceptor | undefined; diff --git a/src/www/model/server.ts b/src/www/model/server.ts index 635df60044..f789f78331 100644 --- a/src/www/model/server.ts +++ b/src/www/model/server.ts @@ -56,9 +56,6 @@ export interface Server { // Checks whether the server is already active and in use. checkRunning(): Promise; - - // Checks whether the server is reachable. - checkReachable(): Promise; } export interface ServerRepository {