Skip to content

Commit

Permalink
Use readFromBoot to read VPN status
Browse files Browse the repository at this point in the history
This removes VPN status monitoring, which
would be too expensive to do with a container and is really not
necessary. The VPN status information will be available for requests via
the supervisor API.
  • Loading branch information
pipex committed Dec 20, 2022
1 parent 9f8b877 commit 45d678f
Showing 1 changed file with 4 additions and 25 deletions.
29 changes: 4 additions & 25 deletions src/network.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as Bluebird from 'bluebird';
import * as _ from 'lodash';
import { promises as fs, watch } from 'fs';
import { promises as fs } from 'fs';
import * as networkCheck from 'network-checker';
import * as os from 'os';
import * as url from 'url';

import * as constants from './lib/constants';
import { EEXIST } from './lib/errors';
import { checkFalsey } from './lib/validation';
import { readFromRoot } from './lib/host-utils';

import blink = require('./lib/blink');

Expand All @@ -18,17 +18,12 @@ const networkPattern = {
pause: 1000,
};

let isConnectivityCheckPaused = false;
let isConnectivityCheckEnabled = true;

function checkHost(
opts: networkCheck.ConnectOptions,
): boolean | PromiseLike<boolean> {
return (
!isConnectivityCheckEnabled ||
isConnectivityCheckPaused ||
networkCheck.checkHost(opts)
);
return !isConnectivityCheckEnabled || networkCheck.checkHost(opts);
}

function customMonitor(
Expand All @@ -45,18 +40,14 @@ export function enableCheck(enable: boolean) {
export async function isVPNActive(): Promise<boolean> {
let active: boolean = true;
try {
await fs.lstat(`${constants.vpnStatusPath}/active`);
await readFromRoot(`${constants.vpnStatusPath}/active`);
} catch {
active = false;
}
log.info(`VPN connection is ${active ? 'active' : 'not active'}.`);
return active;
}

async function vpnStatusInotifyCallback(): Promise<void> {
isConnectivityCheckPaused = await isVPNActive();
}

export const startConnectivityCheck = _.once(
async (
apiEndpoint: string,
Expand All @@ -69,18 +60,6 @@ export const startConnectivityCheck = _.once(
return;
}

await Bluebird.resolve(fs.mkdir(constants.vpnStatusPath))
.catch(EEXIST, () => {
log.debug('VPN status path exists.');
})
.then(() => {
watch(constants.vpnStatusPath, vpnStatusInotifyCallback);
});

if (enable) {
vpnStatusInotifyCallback();
}

const parsedUrl = url.parse(apiEndpoint);
const port = parseInt(parsedUrl.port!, 10);

Expand Down

0 comments on commit 45d678f

Please sign in to comment.