Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(electron): 🩹 fix connection issue of domain name keys #1763

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/electron/connectivity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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 {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<string> {
return timeoutPromise(
new Promise<string>((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'
);
}
7 changes: 7 additions & 0 deletions src/electron/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {GoVpnTunnel} from './go_vpn_tunnel';
import {installRoutingServices, RoutingDaemon} from './routing_service';
import {TunnelStore, SerializableTunnel} from './tunnel_store';
import {VpnTunnel} from './vpn_tunnel';
import {lookupIp} from './connectivity';

// TODO: can we define these macros in other .d.ts files with default values?
// Build-time macros injected by webpack's DefinePlugin:
Expand Down Expand Up @@ -466,6 +467,12 @@ function main() {
console.log(`connecting to ${args.id}...`);

try {
// We must convert the host from a potential "hostname" to an "IP" address
// because startVpn will add a routing table entry that prefixed with this
// host (e.g. "<host>/32"), therefore <host> must be an IP address.
// TODO: make sure we resolve it in the native code
args.config.host = await lookupIp(args.config.host || '');

await startVpn(args.config, args.id);
console.log(`connected to ${args.id}`);
await setupAutoLaunch(args);
Expand Down
Loading