Skip to content

Commit

Permalink
Remove reachability from www
Browse files Browse the repository at this point in the history
  • Loading branch information
fortuna committed Jul 11, 2023
1 parent 6e5bfef commit d013d71
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 295 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ final class OutlineTunnelTest: XCTestCase {
}

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))
// 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))
}
}
76 changes: 0 additions & 76 deletions src/electron/connectivity.ts

This file was deleted.

21 changes: 1 addition & 20 deletions src/electron/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -72,8 +71,6 @@ const enum Options {
AUTOSTART = '--autostart',
}

const REACHABILITY_TIMEOUT_MS = 10000;

let currentTunnel: VpnTunnel | undefined;

/**
Expand Down Expand Up @@ -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',
Expand All @@ -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);
Expand Down
13 changes: 2 additions & 11 deletions src/www/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
12 changes: 0 additions & 12 deletions src/www/app/cordova_main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -88,12 +86,6 @@ class CordovaErrorReporter extends SentryErrorReporter {
}
}

class CordovaNativeNetworking implements NativeNetworking {
async isServerReachable(hostname: string, port: number) {
return await pluginExecWithErrorCode<boolean>('isServerReachable', hostname, port);
}
}

class CordovaTunnel implements Tunnel {
constructor(public id: string) {}

Expand Down Expand Up @@ -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);
Expand Down
11 changes: 0 additions & 11 deletions src/www/app/electron_main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -102,17 +100,8 @@ class ElectronErrorReporter implements OutlineErrorReporter {
}
}

class ElectronNativeNetworking implements NativeNetworking {
isServerReachable(hostname: string, port: number): Promise<boolean> {
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);
Expand Down
21 changes: 0 additions & 21 deletions src/www/app/fake_net.ts

This file was deleted.

5 changes: 1 addition & 4 deletions src/www/app/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -107,7 +105,6 @@ export function main(platform: OutlinePlatform) {
eventQueue,
window.localStorage,
platform.hasDeviceSupport(),
platform.getNativeNetworking(),
platform.getTunnelFactory()
);
const settings = new Settings();
Expand Down
19 changes: 0 additions & 19 deletions src/www/app/net.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/www/app/outline_server_repository/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
);

Expand Down
Loading

0 comments on commit d013d71

Please sign in to comment.