Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
15744d3c4e | |||
8b2f541150 | |||
b52bb4b474 | |||
42f5d66fc4 | |||
54bb9549a1 | |||
95c3314400 | |||
695d047200 | |||
c308589d28 | |||
068177b09d | |||
4a299cf3cb |
@ -12,6 +12,9 @@ stages:
|
|||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- npm install -g @shipzone/npmci
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
# ====================
|
# ====================
|
||||||
@ -36,6 +39,7 @@ auditProductionDependencies:
|
|||||||
- npmci command npm audit --audit-level=high --only=prod --production
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
auditDevDependencies:
|
auditDevDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
4
.snyk
4
.snyk
@ -1,4 +0,0 @@
|
|||||||
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
|
|
||||||
version: v1.13.5
|
|
||||||
ignore: {}
|
|
||||||
patch: {}
|
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "current file",
|
"command": "npm test",
|
||||||
"type": "node",
|
"name": "Run npm test",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"args": [
|
"type": "node-terminal"
|
||||||
"${relativeFile}"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "test.ts",
|
|
||||||
"type": "node",
|
|
||||||
"request": "launch",
|
|
||||||
"args": [
|
|
||||||
"test/test.ts"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
"gitrepo": "smartnetwork",
|
"gitrepo": "smartnetwork",
|
||||||
"shortDescription": "network diagnostics",
|
"description": "network diagnostics",
|
||||||
"npmPackagename": "@pushrocks/smartnetwork",
|
"npmPackagename": "@pushrocks/smartnetwork",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
23610
package-lock.json
generated
23610
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
23
package.json
23
package.json
@ -1,30 +1,31 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartnetwork",
|
"name": "@pushrocks/smartnetwork",
|
||||||
"version": "2.0.10",
|
"version": "3.0.0",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "network diagnostics",
|
"description": "network diagnostics",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
"type": "module",
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild --web)"
|
"build": "(tsbuild --web --allowimplicitany)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@gitzone/tsbuild": "^2.1.61",
|
||||||
"@gitzone/tstest": "^1.0.52",
|
"@gitzone/tstest": "^1.0.69",
|
||||||
"@pushrocks/tapbundle": "^3.2.14",
|
"@pushrocks/smartenv": "^5.0.0",
|
||||||
"tslint": "^6.1.3",
|
"@pushrocks/tapbundle": "^5.0.3"
|
||||||
"tslint-config-prettier": "^1.18.0"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartpromise": "^3.1.3",
|
"@pushrocks/smartpromise": "^3.1.7",
|
||||||
"@pushrocks/smartstring": "^3.0.24",
|
"@pushrocks/smartstring": "^4.0.2",
|
||||||
"@types/default-gateway": "^3.0.1",
|
"@types/default-gateway": "^3.0.1",
|
||||||
|
"icmp": "^2.0.1",
|
||||||
"isopen": "^1.3.0",
|
"isopen": "^1.3.0",
|
||||||
"public-ip": "^4.0.3",
|
"public-ip": "^4.0.4",
|
||||||
"systeminformation": "^5.6.12"
|
"systeminformation": "^5.11.9"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
|
18
test/test.ping.ts
Normal file
18
test/test.ping.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { tap, expect, expectAsync } from '@pushrocks/tapbundle';
|
||||||
|
|
||||||
|
import * as smartnetwork from '../ts/index.js';
|
||||||
|
|
||||||
|
let testSmartnetwork: smartnetwork.SmartNetwork;
|
||||||
|
|
||||||
|
tap.test('should create a vlid instance of SmartNetwork', async () => {
|
||||||
|
testSmartnetwork = new smartnetwork.SmartNetwork();
|
||||||
|
expect(testSmartnetwork).toBeInstanceOf(smartnetwork.SmartNetwork);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should send a ping to Google', async () => {
|
||||||
|
expectAsync(testSmartnetwork.ping('https://lossless.com')).toBeTrue();
|
||||||
|
expectAsync(testSmartnetwork.ping('https://notthere.lossless.com')).toBeTrue();
|
||||||
|
expectAsync(testSmartnetwork.ping('192.168.186.999')).toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
14
test/test.ts
14
test/test.ts
@ -1,11 +1,11 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, expectAsync, tap } from '@pushrocks/tapbundle';
|
||||||
import * as smartnetwork from '../ts/index';
|
import * as smartnetwork from '../ts/index.js';
|
||||||
|
|
||||||
let testSmartNetwork: smartnetwork.SmartNetwork;
|
let testSmartNetwork: smartnetwork.SmartNetwork;
|
||||||
|
|
||||||
tap.test('should create a valid instance of SmartNetwork', async () => {
|
tap.test('should create a valid instance of SmartNetwork', async () => {
|
||||||
testSmartNetwork = new smartnetwork.SmartNetwork();
|
testSmartNetwork = new smartnetwork.SmartNetwork();
|
||||||
expect(testSmartNetwork).to.be.instanceOf(smartnetwork.SmartNetwork);
|
expect(testSmartNetwork).toBeInstanceOf(smartnetwork.SmartNetwork);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should perform a speedtest', async () => {
|
tap.test('should perform a speedtest', async () => {
|
||||||
@ -15,13 +15,13 @@ tap.test('should perform a speedtest', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should determine wether a port is free', async () => {
|
tap.test('should determine wether a port is free', async () => {
|
||||||
await expect(testSmartNetwork.isLocalPortUnused(8080)).to.eventually.be.true;
|
await expectAsync(testSmartNetwork.isLocalPortUnused(8080)).toBeTrue();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should scan a port', async () => {
|
tap.test('should scan a port', async () => {
|
||||||
await expect(testSmartNetwork.isRemotePortAvailable('lossless.com:443')).to.eventually.be.true;
|
await expectAsync(testSmartNetwork.isRemotePortAvailable('lossless.com:443')).toBeTrue();
|
||||||
await expect(testSmartNetwork.isRemotePortAvailable('lossless.com', 443)).to.be.eventually.true;
|
await expectAsync(testSmartNetwork.isRemotePortAvailable('lossless.com', 443)).toBeTrue();
|
||||||
// await expect(testSmartNetwork.isRemotePortAvailable('lossless.com:444')).to.eventually.be.false;
|
await expectAsync(testSmartNetwork.isRemotePortAvailable('lossless.com:444')).toBeFalse();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should get gateways', async () => {
|
tap.test('should get gateways', async () => {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export function average(values) {
|
export function average(values: number[]) {
|
||||||
let total = 0;
|
let total = 0;
|
||||||
|
|
||||||
for (let i = 0; i < values.length; i += 1) {
|
for (let i = 0; i < values.length; i += 1) {
|
||||||
@ -8,7 +8,7 @@ export function average(values) {
|
|||||||
return total / values.length;
|
return total / values.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function median(values) {
|
export function median(values: number[]) {
|
||||||
const half = Math.floor(values.length / 2);
|
const half = Math.floor(values.length / 2);
|
||||||
|
|
||||||
values.sort((a, b) => a - b);
|
values.sort((a, b) => a - b);
|
||||||
@ -18,7 +18,7 @@ export function median(values) {
|
|||||||
return (values[half - 1] + values[half]) / 2;
|
return (values[half - 1] + values[half]) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function quartile(values, percentile) {
|
export function quartile(values: number[], percentile: number) {
|
||||||
values.sort((a, b) => a - b);
|
values.sort((a, b) => a - b);
|
||||||
const pos = (values.length - 1) * percentile;
|
const pos = (values.length - 1) * percentile;
|
||||||
const base = Math.floor(pos);
|
const base = Math.floor(pos);
|
||||||
@ -31,7 +31,7 @@ export function quartile(values, percentile) {
|
|||||||
return values[base];
|
return values[base];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function jitter(values) {
|
export function jitter(values: number[]) {
|
||||||
// Average distance between consecutive latency measurements...
|
// Average distance between consecutive latency measurements...
|
||||||
let jitters = [];
|
let jitters = [];
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
export * from './smartnetwork.classes.smartnetwork';
|
export * from './smartnetwork.classes.smartnetwork.js';
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import * as plugins from './smartnetwork.plugins';
|
import * as plugins from './smartnetwork.plugins.js';
|
||||||
import * as stats from './helpers/stats';
|
import * as stats from './helpers/stats.js';
|
||||||
|
|
||||||
export class CloudflareSpeed {
|
export class CloudflareSpeed {
|
||||||
constructor() {}
|
constructor() {}
|
||||||
@ -64,7 +64,7 @@ export class CloudflareSpeed {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async measureDownload(bytes: number, iterations: number) {
|
public async measureDownload(bytes: number, iterations: number) {
|
||||||
const measurements = [];
|
const measurements: number[] = [];
|
||||||
|
|
||||||
for (let i = 0; i < iterations; i += 1) {
|
for (let i = 0; i < iterations; i += 1) {
|
||||||
await this.download(bytes).then(
|
await this.download(bytes).then(
|
||||||
@ -82,7 +82,7 @@ export class CloudflareSpeed {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async measureUpload(bytes: number, iterations: number) {
|
public async measureUpload(bytes: number, iterations: number) {
|
||||||
const measurements = [];
|
const measurements: number[] = [];
|
||||||
|
|
||||||
for (let i = 0; i < iterations; i += 1) {
|
for (let i = 0; i < iterations; i += 1) {
|
||||||
await this.upload(bytes).then(
|
await this.upload(bytes).then(
|
||||||
@ -106,11 +106,11 @@ export class CloudflareSpeed {
|
|||||||
public async fetchServerLocations(): Promise<{ [key: string]: string }> {
|
public async fetchServerLocations(): Promise<{ [key: string]: string }> {
|
||||||
const res = JSON.parse(await this.get('speed.cloudflare.com', '/locations'));
|
const res = JSON.parse(await this.get('speed.cloudflare.com', '/locations'));
|
||||||
|
|
||||||
return res.reduce((data, { iata, city }) => {
|
return res.reduce((data: any, optionsArg: { iata: string; city: string }) => {
|
||||||
// Bypass prettier "no-assign-param" rules
|
// Bypass prettier "no-assign-param" rules
|
||||||
const data1 = data;
|
const data1 = data;
|
||||||
|
|
||||||
data1[iata] = city;
|
data1[optionsArg.iata] = optionsArg.city;
|
||||||
return data1;
|
return data1;
|
||||||
}, {});
|
}, {});
|
||||||
}
|
}
|
||||||
@ -124,7 +124,7 @@ export class CloudflareSpeed {
|
|||||||
method: 'GET',
|
method: 'GET',
|
||||||
},
|
},
|
||||||
(res) => {
|
(res) => {
|
||||||
const body = [];
|
const body: Array<Buffer> = [];
|
||||||
res.on('data', (chunk) => {
|
res.on('data', (chunk) => {
|
||||||
body.push(chunk);
|
body.push(chunk);
|
||||||
});
|
});
|
||||||
@ -145,7 +145,7 @@ export class CloudflareSpeed {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async download(bytes) {
|
public async download(bytes: number) {
|
||||||
const options = {
|
const options = {
|
||||||
hostname: 'speed.cloudflare.com',
|
hostname: 'speed.cloudflare.com',
|
||||||
path: `/__down?bytes=${bytes}`,
|
path: `/__down?bytes=${bytes}`,
|
||||||
@ -169,13 +169,13 @@ export class CloudflareSpeed {
|
|||||||
return this.request(options, data);
|
return this.request(options, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async request(options, data = '') {
|
public async request(options: plugins.https.RequestOptions, data = ''): Promise<number[]> {
|
||||||
let started;
|
let started: number;
|
||||||
let dnsLookup;
|
let dnsLookup: number;
|
||||||
let tcpHandshake;
|
let tcpHandshake: number;
|
||||||
let sslHandshake;
|
let sslHandshake: number;
|
||||||
let ttfb;
|
let ttfb: number;
|
||||||
let ended;
|
let ended: number;
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
started = plugins.perfHooks.performance.now();
|
started = plugins.perfHooks.performance.now();
|
||||||
@ -234,7 +234,7 @@ export class CloudflareSpeed {
|
|||||||
warp: string;
|
warp: string;
|
||||||
gateway: string;
|
gateway: string;
|
||||||
}> {
|
}> {
|
||||||
const parseCfCdnCgiTrace = (text) =>
|
const parseCfCdnCgiTrace = (text: string) =>
|
||||||
text
|
text
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.map((i) => {
|
.map((i) => {
|
||||||
@ -242,7 +242,7 @@ export class CloudflareSpeed {
|
|||||||
|
|
||||||
return [j[0], j[1]];
|
return [j[0], j[1]];
|
||||||
})
|
})
|
||||||
.reduce((data, [k, v]) => {
|
.reduce((data: any, [k, v]) => {
|
||||||
if (v === undefined) return data;
|
if (v === undefined) return data;
|
||||||
|
|
||||||
// Bypass prettier "no-assign-param" rules
|
// Bypass prettier "no-assign-param" rules
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import * as plugins from './smartnetwork.plugins';
|
import * as plugins from './smartnetwork.plugins.js';
|
||||||
|
|
||||||
import { CloudflareSpeed } from './smartnetwork.classes.cloudflarespeed';
|
import { CloudflareSpeed } from './smartnetwork.classes.cloudflarespeed.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SmartNetwork simplifies actions within the network
|
* SmartNetwork simplifies actions within the network
|
||||||
@ -16,6 +16,19 @@ export class SmartNetwork {
|
|||||||
return test;
|
return test;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async ping(hostArg: string, timeoutArg: number = 500): Promise<boolean> {
|
||||||
|
if (process.getuid() !== 0) {
|
||||||
|
console.log('icmp not allowed for nonroot!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await plugins.icmp.ping(hostArg, timeoutArg).catch();
|
||||||
|
if (result) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns a promise with a boolean answer
|
* returns a promise with a boolean answer
|
||||||
* note: false also resolves with false as argument
|
* note: false also resolves with false as argument
|
||||||
@ -78,7 +91,7 @@ export class SmartNetwork {
|
|||||||
const domainPart = domainArg.split(':')[0];
|
const domainPart = domainArg.split(':')[0];
|
||||||
const port = portArg ? portArg : parseInt(domainArg.split(':')[1], 10);
|
const port = portArg ? portArg : parseInt(domainArg.split(':')[1], 10);
|
||||||
|
|
||||||
plugins.isopen(domainPart, port, (response) => {
|
plugins.isopen(domainPart, port, (response: any) => {
|
||||||
console.log(response);
|
console.log(response);
|
||||||
if (response[port.toString()].isOpen) {
|
if (response[port.toString()].isOpen) {
|
||||||
done.resolve(true);
|
done.resolve(true);
|
||||||
|
@ -12,8 +12,12 @@ import * as smartstring from '@pushrocks/smartstring';
|
|||||||
export { smartpromise, smartstring };
|
export { smartpromise, smartstring };
|
||||||
|
|
||||||
// @third party scope
|
// @third party scope
|
||||||
|
// @ts-ignore
|
||||||
import isopen from 'isopen';
|
import isopen from 'isopen';
|
||||||
|
// @ts-ignore
|
||||||
|
import icmp from 'icmp';
|
||||||
|
// @ts-ignore
|
||||||
import publicIp from 'public-ip';
|
import publicIp from 'public-ip';
|
||||||
import * as systeminformation from 'systeminformation';
|
import * as systeminformation from 'systeminformation';
|
||||||
|
|
||||||
export { isopen, publicIp, systeminformation };
|
export { isopen, icmp, publicIp, systeminformation };
|
||||||
|
5
ts/tsconfig.json
Normal file
5
ts/tsconfig.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"noImplicitAny": true
|
||||||
|
}
|
||||||
|
}
|
9
tsconfig.json
Normal file
9
tsconfig.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ES2022",
|
||||||
|
"moduleResolution": "nodenext"
|
||||||
|
}
|
||||||
|
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
|
||||||
"rules": {
|
|
||||||
"semicolon": [true, "always"],
|
|
||||||
"no-console": false,
|
|
||||||
"ordered-imports": false,
|
|
||||||
"object-literal-sort-keys": false,
|
|
||||||
"member-ordering": {
|
|
||||||
"options":{
|
|
||||||
"order": [
|
|
||||||
"static-method"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"defaultSeverity": "warning"
|
|
||||||
}
|
|
Reference in New Issue
Block a user