@push.rocks/smartnetwork 4.4.0 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{npmextra.json → .smartconfig.json} +17 -5
- package/dist_rust/rustnetwork_linux_amd64 +0 -0
- package/dist_rust/rustnetwork_linux_arm64 +0 -0
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/helpers/stats.js +1 -1
- package/dist_ts/index.d.ts +3 -0
- package/dist_ts/index.js +3 -1
- package/dist_ts/smartnetwork.classes.cloudflarespeed.js +32 -11
- package/dist_ts/smartnetwork.classes.ipintelligence.d.ts +101 -0
- package/dist_ts/smartnetwork.classes.ipintelligence.js +442 -0
- package/dist_ts/smartnetwork.classes.publicip.js +1 -1
- package/dist_ts/smartnetwork.classes.rustbridge.d.ts +100 -0
- package/dist_ts/smartnetwork.classes.rustbridge.js +98 -0
- package/dist_ts/smartnetwork.classes.smartnetwork.d.ts +38 -32
- package/dist_ts/smartnetwork.classes.smartnetwork.js +129 -159
- package/dist_ts/smartnetwork.plugins.d.ts +7 -10
- package/dist_ts/smartnetwork.plugins.js +9 -13
- package/package.json +19 -18
- package/readme.hints.md +60 -34
- package/readme.md +8 -0
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/helpers/stats.ts +1 -1
- package/ts/index.ts +3 -0
- package/ts/smartnetwork.classes.cloudflarespeed.ts +32 -16
- package/ts/smartnetwork.classes.ipintelligence.ts +542 -0
- package/ts/smartnetwork.classes.publicip.ts +2 -2
- package/ts/smartnetwork.classes.rustbridge.ts +181 -0
- package/ts/smartnetwork.classes.smartnetwork.ts +152 -175
- package/ts/smartnetwork.plugins.ts +8 -12
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import * as plugins from './smartnetwork.plugins.js';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Command map for the rustnetwork IPC binary.
|
|
7
|
+
* Each key maps to { params, result } defining the typed IPC protocol.
|
|
8
|
+
*/
|
|
9
|
+
type TNetworkCommands = {
|
|
10
|
+
healthPing: {
|
|
11
|
+
params: Record<string, never>;
|
|
12
|
+
result: { pong: boolean };
|
|
13
|
+
};
|
|
14
|
+
ping: {
|
|
15
|
+
params: { host: string; count?: number; timeoutMs?: number };
|
|
16
|
+
result: {
|
|
17
|
+
alive: boolean;
|
|
18
|
+
times: (number | null)[];
|
|
19
|
+
min: number | null;
|
|
20
|
+
max: number | null;
|
|
21
|
+
avg: number | null;
|
|
22
|
+
stddev: number | null;
|
|
23
|
+
packetLoss: number;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
traceroute: {
|
|
27
|
+
params: { host: string; maxHops?: number; timeoutMs?: number };
|
|
28
|
+
result: {
|
|
29
|
+
hops: Array<{ ttl: number; ip: string; rtt: number | null }>;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
tcpPortCheck: {
|
|
33
|
+
params: { host: string; port: number; timeoutMs?: number };
|
|
34
|
+
result: { isOpen: boolean; latencyMs: number | null };
|
|
35
|
+
};
|
|
36
|
+
isLocalPortFree: {
|
|
37
|
+
params: { port: number };
|
|
38
|
+
result: { free: boolean };
|
|
39
|
+
};
|
|
40
|
+
defaultGateway: {
|
|
41
|
+
params: Record<string, never>;
|
|
42
|
+
result: {
|
|
43
|
+
interfaceName: string;
|
|
44
|
+
addresses: Array<{ family: string; address: string }>;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
function getPlatformSuffix(): string | null {
|
|
50
|
+
const platform = process.platform;
|
|
51
|
+
const arch = process.arch;
|
|
52
|
+
|
|
53
|
+
const platformMap: Record<string, string> = {
|
|
54
|
+
linux: 'linux',
|
|
55
|
+
darwin: 'macos',
|
|
56
|
+
win32: 'windows',
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const archMap: Record<string, string> = {
|
|
60
|
+
x64: 'amd64',
|
|
61
|
+
arm64: 'arm64',
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const p = platformMap[platform];
|
|
65
|
+
const a = archMap[arch];
|
|
66
|
+
|
|
67
|
+
if (p && a) {
|
|
68
|
+
return `${p}_${a}`;
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Singleton bridge to the rustnetwork binary.
|
|
75
|
+
* Manages the IPC lifecycle for network diagnostics operations.
|
|
76
|
+
*/
|
|
77
|
+
export class RustNetworkBridge {
|
|
78
|
+
private static instance: RustNetworkBridge | null = null;
|
|
79
|
+
|
|
80
|
+
public static getInstance(): RustNetworkBridge {
|
|
81
|
+
if (!RustNetworkBridge.instance) {
|
|
82
|
+
RustNetworkBridge.instance = new RustNetworkBridge();
|
|
83
|
+
}
|
|
84
|
+
return RustNetworkBridge.instance;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private bridge: InstanceType<typeof plugins.smartrust.RustBridge<TNetworkCommands>>;
|
|
88
|
+
|
|
89
|
+
private constructor() {
|
|
90
|
+
const packageDir = path.resolve(
|
|
91
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
92
|
+
'..',
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const platformSuffix = getPlatformSuffix();
|
|
96
|
+
const localPaths: string[] = [];
|
|
97
|
+
|
|
98
|
+
// Platform-specific cross-compiled binary
|
|
99
|
+
if (platformSuffix) {
|
|
100
|
+
localPaths.push(path.join(packageDir, 'dist_rust', `rustnetwork_${platformSuffix}`));
|
|
101
|
+
}
|
|
102
|
+
// Native build without suffix
|
|
103
|
+
localPaths.push(path.join(packageDir, 'dist_rust', 'rustnetwork'));
|
|
104
|
+
// Local dev paths
|
|
105
|
+
localPaths.push(path.join(packageDir, 'rust', 'target', 'release', 'rustnetwork'));
|
|
106
|
+
localPaths.push(path.join(packageDir, 'rust', 'target', 'debug', 'rustnetwork'));
|
|
107
|
+
|
|
108
|
+
this.bridge = new plugins.smartrust.RustBridge<TNetworkCommands>({
|
|
109
|
+
binaryName: 'rustnetwork',
|
|
110
|
+
cliArgs: ['--management'],
|
|
111
|
+
requestTimeoutMs: 30_000,
|
|
112
|
+
readyTimeoutMs: 10_000,
|
|
113
|
+
localPaths,
|
|
114
|
+
searchSystemPath: false,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Spawn the Rust binary and wait for it to be ready.
|
|
120
|
+
*/
|
|
121
|
+
public async start(): Promise<void> {
|
|
122
|
+
const ok = await this.bridge.spawn();
|
|
123
|
+
if (!ok) {
|
|
124
|
+
throw new Error('Failed to spawn rustnetwork binary');
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Kill the Rust binary.
|
|
130
|
+
*/
|
|
131
|
+
public async stop(): Promise<void> {
|
|
132
|
+
this.bridge.kill();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Ensure the bridge is running before sending a command.
|
|
137
|
+
*/
|
|
138
|
+
private async ensureRunning(): Promise<void> {
|
|
139
|
+
// The bridge will throw if not spawned — we just call start() if not yet running
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// ===== Command wrappers =====
|
|
143
|
+
|
|
144
|
+
public async ping(
|
|
145
|
+
host: string,
|
|
146
|
+
count?: number,
|
|
147
|
+
timeoutMs?: number,
|
|
148
|
+
): Promise<TNetworkCommands['ping']['result']> {
|
|
149
|
+
return this.bridge.sendCommand('ping', { host, count, timeoutMs });
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
public async traceroute(
|
|
153
|
+
host: string,
|
|
154
|
+
maxHops?: number,
|
|
155
|
+
timeoutMs?: number,
|
|
156
|
+
): Promise<TNetworkCommands['traceroute']['result']> {
|
|
157
|
+
return this.bridge.sendCommand('traceroute', { host, maxHops, timeoutMs });
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
public async tcpPortCheck(
|
|
161
|
+
host: string,
|
|
162
|
+
port: number,
|
|
163
|
+
timeoutMs?: number,
|
|
164
|
+
): Promise<TNetworkCommands['tcpPortCheck']['result']> {
|
|
165
|
+
return this.bridge.sendCommand('tcpPortCheck', { host, port, timeoutMs });
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
public async isLocalPortFree(
|
|
169
|
+
port: number,
|
|
170
|
+
): Promise<TNetworkCommands['isLocalPortFree']['result']> {
|
|
171
|
+
return this.bridge.sendCommand('isLocalPortFree', { port });
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
public async defaultGateway(): Promise<TNetworkCommands['defaultGateway']['result']> {
|
|
175
|
+
return this.bridge.sendCommand('defaultGateway', {} as Record<string, never>);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
public async healthPing(): Promise<TNetworkCommands['healthPing']['result']> {
|
|
179
|
+
return this.bridge.sendCommand('healthPing', {} as Record<string, never>);
|
|
180
|
+
}
|
|
181
|
+
}
|