@mark1russell7/netdiag 0.0.0-stage → 0.1.1

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.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +244 -2
  3. package/build/address.d.ts +56 -0
  4. package/build/address.d.ts.map +1 -0
  5. package/build/address.js +172 -0
  6. package/build/address.js.map +1 -0
  7. package/build/diagnosis-a4hRzFxp.js +922 -0
  8. package/build/diagnosis-a4hRzFxp.js.map +1 -0
  9. package/build/diagnosis.d.ts +8 -0
  10. package/build/diagnosis.js +1 -0
  11. package/build/index-K2dGiYxW.d.ts +259 -0
  12. package/build/index-K2dGiYxW.d.ts.map +1 -0
  13. package/build/index.d.ts +392 -0
  14. package/build/index.d.ts.map +1 -0
  15. package/build/index.js +1359 -0
  16. package/build/index.js.map +1 -0
  17. package/build/kinds-CQv769lK.js +341 -0
  18. package/build/kinds-CQv769lK.js.map +1 -0
  19. package/build/kinds-_NShfZpU.d.ts +377 -0
  20. package/build/kinds-_NShfZpU.d.ts.map +1 -0
  21. package/build/layer-BNg0VYuK.d.ts +22 -0
  22. package/build/layer-BNg0VYuK.d.ts.map +1 -0
  23. package/build/tools.d.ts +206 -0
  24. package/build/tools.d.ts.map +1 -0
  25. package/build/tools.js +896 -0
  26. package/build/tools.js.map +1 -0
  27. package/package.json +81 -3
  28. package/src/address/index.ts +155 -0
  29. package/src/diagnosis/catalog.ts +357 -0
  30. package/src/diagnosis/index.ts +47 -0
  31. package/src/diagnosis/model.ts +322 -0
  32. package/src/diagnosis/score.ts +160 -0
  33. package/src/fact.ts +87 -0
  34. package/src/index.ts +68 -0
  35. package/src/kinds.ts +460 -0
  36. package/src/layer.ts +31 -0
  37. package/src/probe.ts +61 -0
  38. package/src/probes/native.ts +354 -0
  39. package/src/probes/socket.ts +520 -0
  40. package/src/readers.ts +367 -0
  41. package/src/run.ts +163 -0
  42. package/src/scope.ts +152 -0
  43. package/src/target.ts +116 -0
  44. package/src/tools/common.ts +47 -0
  45. package/src/tools/host.ts +91 -0
  46. package/src/tools/index.ts +38 -0
  47. package/src/tools/licenses.ts +37 -0
  48. package/src/tools/mtr.ts +156 -0
  49. package/src/tools/ping.ts +231 -0
  50. package/src/tools/traceroute.ts +313 -0
@@ -0,0 +1,206 @@
1
+ import { B as ProbeContext, C as PathTrace, R as Availability, S as PathReport, v as IcmpEcho, z as Probe } from "./kinds-_NShfZpU.js";
2
+ /**
3
+ * The output of one command of an outside tool.
4
+ *
5
+ * The function `runCommand` of `@procedures/shell` gives this shape, so it is a host with no change (refer to the README).
6
+ */
7
+ interface ToolOutput {
8
+ /** The exit code of the program. */
9
+ readonly exitCode: number;
10
+ readonly stdout: string;
11
+ readonly stderr: string;
12
+ /** This field is true when the time limit stopped the program. */
13
+ readonly timedOut?: boolean | undefined;
14
+ /** The error that kept the program from its start, for example `spawn ping ENOENT`. */
15
+ readonly error?: string | undefined;
16
+ }
17
+ /** The options of one command. */
18
+ interface ToolRunOptions {
19
+ /** The time limit of the command, in milliseconds. After the limit, the host stops the program. */
20
+ readonly timeoutMs: number;
21
+ readonly signal: AbortSignal;
22
+ /** The environment variables to add to the environment of the program, for example `LC_ALL=C` for English output. */
23
+ readonly env?: Readonly<Record<string, string>> | undefined;
24
+ }
25
+ /**
26
+ * The host of the outside tools: the operating system, and the function that starts a program.
27
+ *
28
+ * - `platform` has the values of `process.platform`, for example `linux`, `darwin` or `win32`.
29
+ * - `run` starts a program with a list of arguments and no shell. It does not throw. A failure is in the output.
30
+ */
31
+ interface ToolHost {
32
+ readonly platform: string;
33
+ run(command: string, args: readonly string[], options: ToolRunOptions): Promise<ToolOutput>;
34
+ }
35
+ /** The raw output of a probe of an outside tool: the command, its output, and the times on the clock of the runner. */
36
+ interface ToolRaw extends ToolOutput {
37
+ readonly platform: string;
38
+ readonly command: string;
39
+ readonly args: readonly string[];
40
+ readonly start: number;
41
+ readonly end: number;
42
+ }
43
+ /** The time limit of the command that examines if a tool is available, in milliseconds. */
44
+ export declare const AVAILABILITY_TIMEOUT_MS = 5e3;
45
+ /** The time that an adapter adds to the time limit of a command, in milliseconds. In this time, a tool writes its last lines. */
46
+ export declare const TOOL_MARGIN_MS = 3e3;
47
+ /**
48
+ * This function gives the availability of a tool from the output of a harmless command. A tool is available when its
49
+ * program starts. The first group of `version` gives the version of the tool.
50
+ */
51
+ export declare function availabilityOf(tool: string, output: ToolOutput, version?: RegExp): Availability;
52
+ /** A command of an outside tool: the program, its arguments, its time limit and the environment variables to add. */
53
+ interface ToolCommand {
54
+ readonly command: string;
55
+ readonly args: readonly string[];
56
+ readonly timeoutMs: number;
57
+ readonly env?: Readonly<Record<string, string>> | undefined;
58
+ }
59
+ /** This function starts a command on the host, and gives its raw output with the times of the clock of the runner. */
60
+ export declare function runTool(host: ToolHost, tool: ToolCommand, context: ProbeContext): Promise<ToolRaw>;
61
+ /**
62
+ * The use of an outside tool in netdiag.
63
+ *
64
+ * - `adapter`: netdiag has an optional adapter. The user installs the tool, and netdiag starts it when it is available.
65
+ * - `not-bundled`: netdiag does not start the tool, because its license is restrictive.
66
+ */
67
+ type ToolUse = "adapter" | "not-bundled";
68
+ /** A row of the table of the licenses of the outside tools. */
69
+ interface ToolLicense {
70
+ /** The name of the program, for example `ping`. */
71
+ readonly tool: string;
72
+ readonly license: string;
73
+ readonly use: ToolUse;
74
+ /** The id of the probe of the adapter. A planned adapter has no probe yet. */
75
+ readonly probe?: string | undefined;
76
+ }
77
+ /**
78
+ * The licenses of the outside tools, as data. netdiag bundles no tool. A test makes sure that the probe of each adapter
79
+ * has a row with the use `adapter`.
80
+ */
81
+ export declare const TOOL_LICENSES: readonly ToolLicense[];
82
+ /** This function gives the row of a tool, or `undefined` for a tool that is not in the table. */
83
+ export declare function toolLicense(tool: string): ToolLicense | undefined;
84
+ /** The input of the ping probe: echo requests to one IP address. */
85
+ interface PingInput {
86
+ readonly address: string;
87
+ /** The number of echo requests. The default is `DEFAULT_PING_COUNT`. */
88
+ readonly count?: number | undefined;
89
+ /** The time to wait for each reply, in milliseconds. The default is `DEFAULT_PING_WAIT_MS`. */
90
+ readonly waitMs?: number | undefined;
91
+ }
92
+ /** The default number of echo requests. The feature `path.loss` needs `LOSS_MIN_SENT` requests or more. */
93
+ export declare const DEFAULT_PING_COUNT = 4;
94
+ /** The default time to wait for each reply, in milliseconds. */
95
+ export declare const DEFAULT_PING_WAIT_MS = 1e3;
96
+ /** The largest number of echo requests in one input. */
97
+ export declare const MAX_PING_COUNT = 100;
98
+ /** The time between two echo requests on Linux and macOS, in milliseconds. A user without privileges can set it. */
99
+ export declare const PING_INTERVAL_MS = 200;
100
+ /**
101
+ * The time that the `ping6` of macOS waits after its last request when a reply is missing, in milliseconds. The tool
102
+ * has no option for it.
103
+ */
104
+ export declare const PING6_LAST_WAIT_MS = 1e4;
105
+ /**
106
+ * This function gives the command of ping for an operating system and an input. For an operating system that the adapter
107
+ * does not know, it gives `undefined`. It throws for an input that is not valid.
108
+ *
109
+ * - Linux: iputils `ping`, with a deadline (`-w`) in seconds, so that ping writes its statistics.
110
+ * - macOS: `ping` with a deadline (`-t`), and `ping6` for an IPv6 address.
111
+ * - Windows: `ping.exe`. It sends one request each second.
112
+ */
113
+ export declare function pingCommand(platform: string, input: PingInput): ToolCommand | undefined;
114
+ /** This function tells if ping is available on the host. On Linux, netdiag reads only the ping of iputils. */
115
+ export declare function pingAvailability(host: ToolHost, context: ProbeContext): Promise<Availability>;
116
+ /**
117
+ * This function reads the raw output of the ping probe into the value of a fact `icmp.echo`.
118
+ *
119
+ * - The replies are the lines of echo replies. A message of an unreachable address and a duplicate are not replies.
120
+ * - Output with no statistics gives the outcome `error`, also when it has replies. The time limit stopped such a ping.
121
+ */
122
+ export declare function readPing(raw: ToolRaw, address: string): IcmpEcho;
123
+ /**
124
+ * This function makes the probe `icmp.ping`: the echo requests of the tool ping to one IP address. The host starts
125
+ * the tool. Give `runCommand` of `@procedures/shell`, or a fake host in a test.
126
+ */
127
+ export declare function pingProbe(host: ToolHost): Probe<PingInput, ToolRaw>;
128
+ /** The input of the traceroute probe: the path to one IP address. */
129
+ interface TraceInput {
130
+ readonly address: string;
131
+ /** The largest TTL. The default is `DEFAULT_TRACE_HOPS`. */
132
+ readonly maxHops?: number | undefined;
133
+ /** The time to wait for each answer, in milliseconds. On Linux and macOS, the tool rounds it up to full seconds. */
134
+ readonly waitMs?: number | undefined;
135
+ }
136
+ /** The default largest TTL. */
137
+ export declare const DEFAULT_TRACE_HOPS = 30;
138
+ /** The largest TTL of one input. */
139
+ export declare const MAX_TRACE_HOPS = 64;
140
+ /** The default time to wait for each answer, in milliseconds. */
141
+ export declare const DEFAULT_TRACE_WAIT_MS = 1e3;
142
+ /** The number of probes for each TTL. `tracert` on Windows always sends 3 probes. */
143
+ export declare const TRACE_QUERIES = 3;
144
+ /**
145
+ * This function gives the command of traceroute for an operating system and an input. For an operating system that the
146
+ * adapter does not know, it gives `undefined`. It throws for an input that is not valid.
147
+ *
148
+ * - Linux: `traceroute`, with UDP probes. A user without privileges can send them.
149
+ * - macOS: `traceroute`, and `traceroute6` for an IPv6 address.
150
+ * - Windows: `tracert.exe`, with ICMP echo requests.
151
+ *
152
+ * The time limit is the time of a trace that waits for each probe of each hop.
153
+ */
154
+ export declare function tracerouteCommand(platform: string, input: TraceInput): ToolCommand | undefined;
155
+ /** This function tells if traceroute is available on the host. On Linux, netdiag reads only the Modern traceroute for Linux. */
156
+ export declare function tracerouteAvailability(host: ToolHost, context: ProbeContext): Promise<Availability>;
157
+ /**
158
+ * This function reads the raw output of the traceroute probe into the value of a fact `path.trace`.
159
+ *
160
+ * - The outcome is `reached` when the address answered at the last hop.
161
+ * - Output that netdiag cannot read gives the outcome `error`. An `error` keeps the hops that netdiag read.
162
+ */
163
+ export declare function readTraceroute(raw: ToolRaw, input: {
164
+ readonly address: string;
165
+ readonly maxHops?: number | undefined;
166
+ }): PathTrace;
167
+ /**
168
+ * This function makes the probe `path.traceroute`: the trace of the path to one IP address with the tool traceroute,
169
+ * or `tracert` on Windows. The host starts the tool.
170
+ */
171
+ export declare function tracerouteProbe(host: ToolHost): Probe<TraceInput, ToolRaw>;
172
+ /** The input of the mtr probe: many cycles of probes on the path to one IP address. */
173
+ interface MtrInput {
174
+ readonly address: string;
175
+ /** The number of cycles. The default is `DEFAULT_MTR_CYCLES`. */
176
+ readonly cycles?: number | undefined;
177
+ /** The largest TTL. The default is `DEFAULT_TRACE_HOPS`. */
178
+ readonly maxHops?: number | undefined;
179
+ }
180
+ /** The default number of cycles. It is `LOSS_MIN_SENT` of the readers, so a report gives the feature `path.loss`. */
181
+ export declare const DEFAULT_MTR_CYCLES = 20;
182
+ /** The largest number of cycles of one input. */
183
+ export declare const MAX_MTR_CYCLES = 100;
184
+ /** The time that mtr waits for the last answers after the last cycle, in milliseconds (its option `--gracetime`). */
185
+ export declare const MTR_GRACE_MS = 5e3;
186
+ /**
187
+ * This function gives the command of mtr for an operating system and an input. On Windows and on an operating system
188
+ * that the adapter does not know, it gives `undefined`. It throws for an input that is not valid.
189
+ */
190
+ export declare function mtrCommand(platform: string, input: MtrInput): ToolCommand | undefined;
191
+ /** This function tells if mtr is available on the host. The adapter knows Linux and macOS. */
192
+ export declare function mtrAvailability(host: ToolHost, context: ProbeContext): Promise<Availability>;
193
+ /**
194
+ * This function reads the raw output of the mtr probe into the value of a fact `path.report`.
195
+ *
196
+ * - The number of answers of a hop comes from its loss and its number of probes.
197
+ * - Output that netdiag cannot read gives the outcome `error`.
198
+ */
199
+ export declare function readMtr(raw: ToolRaw, input: {
200
+ readonly address: string;
201
+ readonly cycles?: number | undefined;
202
+ }): PathReport;
203
+ /** This function makes the probe `path.mtr`: many cycles of probes on the path to one IP address with the tool mtr. */
204
+ export declare function mtrProbe(host: ToolHost): Probe<MtrInput, ToolRaw>;
205
+ export type { MtrInput, PingInput, ToolCommand, ToolHost, ToolLicense, ToolOutput, ToolRaw, ToolRunOptions, ToolUse, TraceInput };
206
+ //# sourceMappingURL=tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.d.ts","names":[],"sources":["../src/tools/host.ts","../src/tools/licenses.ts","../src/tools/ping.ts","../src/tools/traceroute.ts","../src/tools/mtr.ts"],"mappings":";;;;;;UAOiB;;WAEN;WACA;WACA;;WAEA;;WAEA;;;UAIM;;WAEN;WACA,QAAQ;;WAER,MAAM,SAAS;;;;;;;;UAST;WACN;EACT,IAAI,iBAAiB,yBAAyB,SAAS,iBAAiB,QAAQ;;;UAIjE,gBAAgB;WACtB;WACA;WACA;WACA;WACA;;;qBAIE;;qBAGA;;;;;wBAMG,eAAe,cAAc,QAAQ,YAAY,UAAU,SAAS;;UAOnE;WACN;WACA;WACA;WACA,MAAM,SAAS;;;wBAIJ,QAAQ,MAAM,UAAU,MAAM,aAAa,SAAS,eAAe,QAAQ;;;;;;;KClErF;;UAGK;;WAEN;WACA;WACA,KAAK;;WAEL;;;;;;qBAOE,wBAAwB;;wBAYrB,YAAY,eAAe;;UCrB1B;WACN;;WAEA;;WAEA;;;qBAIE;;qBAGA;;qBAGA;;qBAGA;;;;;qBAMA;;;;;;;;;wBAuBG,YAAY,kBAAkB,OAAO,YAAY;;wBAqC3C,iBAAiB,MAAM,UAAU,SAAS,eAAe,QAAQ;;;;;;;wBA0FvE,SAAS,KAAK,SAAS,kBAAkB;;;;;wBAyBzC,UAAU,MAAM,WAAW,MAAM,WAAW;;UCxM3C;WACN;;WAEA;;WAEA;;;qBAIE;;qBAGA;;qBAGA;;qBAGA;;;;;;;;;;;wBAyBG,kBAAkB,kBAAkB,OAAO,aAAa;;wBAyBlD,uBAAuB,MAAM,UAAU,SAAS,eAAe,QAAQ;;;;;;;wBA4L7E,eAAe,KAAK,SAAS;WAAkB;WAA0B;IAAiC;;;;;wBA0B1G,gBAAgB,MAAM,WAAW,MAAM,YAAY;;UC1RlD;WACN;;WAEA;;WAEA;;;qBAIE;;qBAGA;;qBAGA;;;;;wBAmBG,WAAW,kBAAkB,OAAO,WAAW;;wBAYzC,gBAAgB,MAAM,UAAU,SAAS,eAAe,QAAQ;;;;;;;wBAyDtE,QAAQ,KAAK,SAAS;WAAkB;WAA0B;IAAgC;;wBAsBlG,SAAS,MAAM,WAAW,MAAM,UAAU"}