@netkitty/analysis 1.0.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/CHANGELOG.md +12 -0
- package/LICENSE +21 -0
- package/README.md +150 -0
- package/README.zh-CN.md +146 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +27 -0
- package/dist/lib/streaming/Analysis.d.ts +54 -0
- package/dist/lib/streaming/Analysis.js +159 -0
- package/dist/lib/streaming/backends/BrowserFileReadBackend.d.ts +14 -0
- package/dist/lib/streaming/backends/BrowserFileReadBackend.js +36 -0
- package/dist/lib/streaming/backends/NodeFileReadBackend.d.ts +15 -0
- package/dist/lib/streaming/backends/NodeFileReadBackend.js +62 -0
- package/dist/lib/streaming/filter/FilterExpression.d.ts +35 -0
- package/dist/lib/streaming/filter/FilterExpression.js +166 -0
- package/dist/lib/streaming/indexer/ConversationKey.d.ts +18 -0
- package/dist/lib/streaming/indexer/ConversationKey.js +54 -0
- package/dist/lib/streaming/indexer/FrameIndexer.d.ts +16 -0
- package/dist/lib/streaming/indexer/FrameIndexer.js +58 -0
- package/dist/lib/streaming/indexer/PcapIndexBuilder.d.ts +20 -0
- package/dist/lib/streaming/indexer/PcapIndexBuilder.js +52 -0
- package/dist/lib/streaming/interfaces/IAnalysisReducer.d.ts +14 -0
- package/dist/lib/streaming/interfaces/IAnalysisReducer.js +2 -0
- package/dist/lib/streaming/interfaces/IIndexStore.d.ts +16 -0
- package/dist/lib/streaming/interfaces/IIndexStore.js +2 -0
- package/dist/lib/streaming/interfaces/IReadBackend.d.ts +11 -0
- package/dist/lib/streaming/interfaces/IReadBackend.js +2 -0
- package/dist/lib/streaming/interfaces/IWorkerChannel.d.ts +12 -0
- package/dist/lib/streaming/interfaces/IWorkerChannel.js +2 -0
- package/dist/lib/streaming/reducers/ConversationsReducer.d.ts +34 -0
- package/dist/lib/streaming/reducers/ConversationsReducer.js +66 -0
- package/dist/lib/streaming/reducers/EndpointsReducer.d.ts +25 -0
- package/dist/lib/streaming/reducers/EndpointsReducer.js +49 -0
- package/dist/lib/streaming/reducers/ReducerFactories.d.ts +13 -0
- package/dist/lib/streaming/reducers/ReducerFactories.js +42 -0
- package/dist/lib/streaming/reducers/TcpStreamReducer.d.ts +35 -0
- package/dist/lib/streaming/reducers/TcpStreamReducer.js +153 -0
- package/dist/lib/streaming/stores/ColumnarIndexStore.d.ts +21 -0
- package/dist/lib/streaming/stores/ColumnarIndexStore.js +134 -0
- package/dist/lib/streaming/types/AnalysisEvents.d.ts +8 -0
- package/dist/lib/streaming/types/AnalysisEvents.js +2 -0
- package/dist/lib/streaming/types/AnalysisOptions.d.ts +5 -0
- package/dist/lib/streaming/types/AnalysisOptions.js +2 -0
- package/dist/lib/streaming/types/AnalysisPhase.d.ts +2 -0
- package/dist/lib/streaming/types/AnalysisPhase.js +2 -0
- package/dist/lib/streaming/types/AnalysisSource.d.ts +2 -0
- package/dist/lib/streaming/types/AnalysisSource.js +2 -0
- package/dist/lib/streaming/types/Frame.d.ts +7 -0
- package/dist/lib/streaming/types/Frame.js +2 -0
- package/dist/lib/streaming/types/FrameIndexRecord.d.ts +14 -0
- package/dist/lib/streaming/types/FrameIndexRecord.js +2 -0
- package/dist/lib/streaming/types/FrameRow.d.ts +12 -0
- package/dist/lib/streaming/types/FrameRow.js +2 -0
- package/dist/lib/streaming/types/UpdateContext.d.ts +7 -0
- package/dist/lib/streaming/types/UpdateContext.js +2 -0
- package/dist/lib/streaming/worker/AnalysisWorkerCore.d.ts +10 -0
- package/dist/lib/streaming/worker/AnalysisWorkerCore.js +192 -0
- package/dist/lib/streaming/worker/BuiltinScans.d.ts +23 -0
- package/dist/lib/streaming/worker/BuiltinScans.js +121 -0
- package/dist/lib/streaming/worker/IWorkerEndpoint.d.ts +9 -0
- package/dist/lib/streaming/worker/IWorkerEndpoint.js +2 -0
- package/dist/lib/streaming/worker/NodeWorkerChannel.d.ts +16 -0
- package/dist/lib/streaming/worker/NodeWorkerChannel.js +60 -0
- package/dist/lib/streaming/worker/SyntheticFrame.d.ts +8 -0
- package/dist/lib/streaming/worker/SyntheticFrame.js +38 -0
- package/dist/lib/streaming/worker/WebWorkerChannel.d.ts +23 -0
- package/dist/lib/streaming/worker/WebWorkerChannel.js +59 -0
- package/dist/lib/streaming/worker/WebWorkerEndpoint.d.ts +19 -0
- package/dist/lib/streaming/worker/WebWorkerEndpoint.js +44 -0
- package/dist/lib/streaming/worker/WorkerEndpoint.d.ts +13 -0
- package/dist/lib/streaming/worker/WorkerEndpoint.js +45 -0
- package/dist/lib/streaming/worker/WorkerMessage.d.ts +24 -0
- package/dist/lib/streaming/worker/WorkerMessage.js +2 -0
- package/dist/lib/streaming/worker/analysisWorker.d.ts +1 -0
- package/dist/lib/streaming/worker/analysisWorker.js +11 -0
- package/dist/lib/streaming/worker/analysisWorkerBrowser.d.ts +1 -0
- package/dist/lib/streaming/worker/analysisWorkerBrowser.js +12 -0
- package/dist/lib/streaming/worker/spawnNodeAnalysisChannel.d.ts +7 -0
- package/dist/lib/streaming/worker/spawnNodeAnalysisChannel.js +18 -0
- package/package.json +65 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WorkerEndpoint = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Worker side of the channel: registers request handlers (their return value, awaited, becomes the
|
|
6
|
+
* response) and can push notify messages back to the main thread. Shared by the real analysis worker
|
|
7
|
+
* and test workers, so the request/response wiring lives in one place. A thrown/rejected handler is
|
|
8
|
+
* reported as an error response rather than crashing the worker.
|
|
9
|
+
*/
|
|
10
|
+
class WorkerEndpoint {
|
|
11
|
+
#port;
|
|
12
|
+
#handlers = new Map();
|
|
13
|
+
constructor(port) {
|
|
14
|
+
this.#port = port;
|
|
15
|
+
this.#port.on('message', (message) => { void this.#onMessage(message); });
|
|
16
|
+
}
|
|
17
|
+
handle(method, handler) {
|
|
18
|
+
this.#handlers.set(method, handler);
|
|
19
|
+
}
|
|
20
|
+
notify(method, payload, transfer) {
|
|
21
|
+
this.#port.postMessage({ kind: 'notify', method: method, payload: payload }, transfer ? transfer : []);
|
|
22
|
+
}
|
|
23
|
+
async #onMessage(message) {
|
|
24
|
+
if (message.kind === 'request') {
|
|
25
|
+
const handler = this.#handlers.get(message.method);
|
|
26
|
+
if (!handler) {
|
|
27
|
+
this.#port.postMessage({ kind: 'response', id: message.id, ok: false, error: `no handler for method: ${message.method}` });
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const result = await handler(message.payload);
|
|
32
|
+
this.#port.postMessage({ kind: 'response', id: message.id, ok: true, payload: result });
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
this.#port.postMessage({ kind: 'response', id: message.id, ok: false, error: error instanceof Error ? error.message : String(error) });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else if (message.kind === 'notify') {
|
|
39
|
+
const handler = this.#handlers.get(message.method);
|
|
40
|
+
if (handler)
|
|
41
|
+
void handler(message.payload);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.WorkerEndpoint = WorkerEndpoint;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire protocol between the Analysis facade (main thread) and the analysis worker. Only the
|
|
3
|
+
* invoke/notify semantics are borrowed from capture's pipe layer; the transport is plain
|
|
4
|
+
* worker_threads / Web Worker postMessage, and ArrayBuffers ride the transfer list without copying.
|
|
5
|
+
*/
|
|
6
|
+
export type WorkerRequest = {
|
|
7
|
+
kind: 'request';
|
|
8
|
+
id: number;
|
|
9
|
+
method: string;
|
|
10
|
+
payload: unknown;
|
|
11
|
+
};
|
|
12
|
+
export type WorkerResponse = {
|
|
13
|
+
kind: 'response';
|
|
14
|
+
id: number;
|
|
15
|
+
ok: boolean;
|
|
16
|
+
payload?: unknown;
|
|
17
|
+
error?: string;
|
|
18
|
+
};
|
|
19
|
+
export type WorkerNotify = {
|
|
20
|
+
kind: 'notify';
|
|
21
|
+
method: string;
|
|
22
|
+
payload: unknown;
|
|
23
|
+
};
|
|
24
|
+
export type WorkerMessage = WorkerRequest | WorkerResponse | WorkerNotify;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const node_worker_threads_1 = require("node:worker_threads");
|
|
4
|
+
const WorkerEndpoint_1 = require("./WorkerEndpoint");
|
|
5
|
+
const NodeFileReadBackend_1 = require("../backends/NodeFileReadBackend");
|
|
6
|
+
const AnalysisWorkerCore_1 = require("./AnalysisWorkerCore");
|
|
7
|
+
/**
|
|
8
|
+
* node analysis worker entrypoint: a WorkerEndpoint over the worker_threads parent port, and a backend
|
|
9
|
+
* factory that treats the source as a filesystem path. All handler logic lives in AnalysisWorkerCore.
|
|
10
|
+
*/
|
|
11
|
+
(0, AnalysisWorkerCore_1.installAnalysisHandlers)(new WorkerEndpoint_1.WorkerEndpoint(node_worker_threads_1.parentPort), (source) => new NodeFileReadBackend_1.NodeFileReadBackend(source));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const WebWorkerEndpoint_1 = require("./WebWorkerEndpoint");
|
|
4
|
+
const BrowserFileReadBackend_1 = require("../backends/BrowserFileReadBackend");
|
|
5
|
+
const AnalysisWorkerCore_1 = require("./AnalysisWorkerCore");
|
|
6
|
+
(0, AnalysisWorkerCore_1.installAnalysisHandlers)(new WebWorkerEndpoint_1.WebWorkerEndpoint(self), (source) => {
|
|
7
|
+
if (source instanceof ArrayBuffer)
|
|
8
|
+
return new BrowserFileReadBackend_1.BrowserFileReadBackend(new Blob([source]));
|
|
9
|
+
if (source instanceof Uint8Array)
|
|
10
|
+
return new BrowserFileReadBackend_1.BrowserFileReadBackend(new Blob([source]));
|
|
11
|
+
return new BrowserFileReadBackend_1.BrowserFileReadBackend(source);
|
|
12
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IWorkerChannel } from '../interfaces/IWorkerChannel';
|
|
2
|
+
/**
|
|
3
|
+
* node channel factory: spawns the analysis worker (sibling compiled .js) and wraps it in a
|
|
4
|
+
* NodeWorkerChannel. Loaded lazily by the Analysis facade so the facade itself never statically
|
|
5
|
+
* imports worker_threads and stays environment-agnostic.
|
|
6
|
+
*/
|
|
7
|
+
export declare function spawnNodeAnalysisChannel(): IWorkerChannel;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.spawnNodeAnalysisChannel = spawnNodeAnalysisChannel;
|
|
7
|
+
const node_worker_threads_1 = require("node:worker_threads");
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const NodeWorkerChannel_1 = require("./NodeWorkerChannel");
|
|
10
|
+
/**
|
|
11
|
+
* node channel factory: spawns the analysis worker (sibling compiled .js) and wraps it in a
|
|
12
|
+
* NodeWorkerChannel. Loaded lazily by the Analysis facade so the facade itself never statically
|
|
13
|
+
* imports worker_threads and stays environment-agnostic.
|
|
14
|
+
*/
|
|
15
|
+
function spawnNodeAnalysisChannel() {
|
|
16
|
+
const worker = new node_worker_threads_1.Worker(node_path_1.default.resolve(__dirname, 'analysisWorker.js'));
|
|
17
|
+
return new NodeWorkerChannel_1.NodeWorkerChannel(worker);
|
|
18
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@netkitty/analysis",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Streaming cross-packet network analysis over the netkitty codec: TCP stream reassembly, flow tracking and Wireshark-style follow-stream, off a worker.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"require": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"README.md",
|
|
16
|
+
"README.zh-CN.md",
|
|
17
|
+
"CHANGELOG.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"clean": "shx rm -rf ./dist ./dist-test",
|
|
21
|
+
"build": "npm run clean && tsc -p tsconfig.json",
|
|
22
|
+
"build:test": "tsc -p tsconfig.test.json",
|
|
23
|
+
"test": "npm run build:test && node --test \"dist-test/**/*.spec.js\"",
|
|
24
|
+
"test:only": "node --test \"dist-test/**/*.spec.js\""
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"netkitty",
|
|
28
|
+
"network-analysis",
|
|
29
|
+
"packet-analysis",
|
|
30
|
+
"flow",
|
|
31
|
+
"flow-analysis",
|
|
32
|
+
"tcp-stream",
|
|
33
|
+
"stream-reassembly",
|
|
34
|
+
"follow-tcp-stream",
|
|
35
|
+
"tcp",
|
|
36
|
+
"wireshark",
|
|
37
|
+
"deep-packet-inspection",
|
|
38
|
+
"dpi",
|
|
39
|
+
"pcap",
|
|
40
|
+
"network"
|
|
41
|
+
],
|
|
42
|
+
"author": "alex.ma",
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public",
|
|
46
|
+
"registry": "https://registry.npmjs.org/"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/node": "^22.13.10",
|
|
50
|
+
"shx": "^0.3.4",
|
|
51
|
+
"typescript": "^5.8.2"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@netkitty/codec": "^1.0.0",
|
|
55
|
+
"@netkitty/pcap-core": "^1.0.0"
|
|
56
|
+
},
|
|
57
|
+
"repository": {
|
|
58
|
+
"type": "git",
|
|
59
|
+
"url": "git+https://github.com/myq1991/netkitty.git",
|
|
60
|
+
"directory": "packages/analysis"
|
|
61
|
+
},
|
|
62
|
+
"homepage": "https://github.com/myq1991/netkitty/tree/main/packages/analysis#readme",
|
|
63
|
+
"bugs": "https://github.com/myq1991/netkitty/issues",
|
|
64
|
+
"gitHead": "d71e793d2017c0f207f7b829adfcce11b56fe7ee"
|
|
65
|
+
}
|