redux-cluster 1.10.0 → 2.0.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 (57) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +345 -471
  3. package/dist/cjs/core/backup.d.ts +10 -0
  4. package/dist/cjs/core/backup.d.ts.map +1 -0
  5. package/dist/cjs/core/backup.js +166 -0
  6. package/dist/cjs/core/redux-cluster.d.ts +47 -0
  7. package/dist/cjs/core/redux-cluster.d.ts.map +1 -0
  8. package/dist/cjs/core/redux-cluster.js +370 -0
  9. package/dist/cjs/index.d.ts +22 -0
  10. package/dist/cjs/index.d.ts.map +1 -0
  11. package/dist/cjs/index.js +43 -0
  12. package/dist/cjs/network/client.d.ts +23 -0
  13. package/dist/cjs/network/client.d.ts.map +1 -0
  14. package/dist/cjs/network/client.js +251 -0
  15. package/dist/cjs/network/server.d.ts +39 -0
  16. package/dist/cjs/network/server.d.ts.map +1 -0
  17. package/dist/cjs/network/server.js +440 -0
  18. package/dist/cjs/package.json +1 -0
  19. package/dist/cjs/types/index.d.ts +125 -0
  20. package/dist/cjs/types/index.d.ts.map +1 -0
  21. package/dist/cjs/types/index.js +20 -0
  22. package/dist/cjs/utils/crypto.d.ts +22 -0
  23. package/dist/cjs/utils/crypto.d.ts.map +1 -0
  24. package/dist/cjs/utils/crypto.js +404 -0
  25. package/dist/esm/core/backup.d.ts +10 -0
  26. package/dist/esm/core/backup.d.ts.map +1 -0
  27. package/dist/esm/core/backup.js +129 -0
  28. package/dist/esm/core/redux-cluster.d.ts +47 -0
  29. package/dist/esm/core/redux-cluster.d.ts.map +1 -0
  30. package/dist/esm/core/redux-cluster.js +363 -0
  31. package/dist/esm/index.d.ts +22 -0
  32. package/dist/esm/index.d.ts.map +1 -0
  33. package/dist/esm/index.js +25 -0
  34. package/dist/esm/network/client.d.ts +23 -0
  35. package/dist/esm/network/client.d.ts.map +1 -0
  36. package/dist/esm/network/client.js +214 -0
  37. package/dist/esm/network/server.d.ts +39 -0
  38. package/dist/esm/network/server.d.ts.map +1 -0
  39. package/dist/esm/network/server.js +403 -0
  40. package/dist/esm/package.json +1 -0
  41. package/dist/esm/types/index.d.ts +125 -0
  42. package/dist/esm/types/index.d.ts.map +1 -0
  43. package/dist/esm/types/index.js +17 -0
  44. package/dist/esm/utils/crypto.d.ts +22 -0
  45. package/dist/esm/utils/crypto.d.ts.map +1 -0
  46. package/dist/esm/utils/crypto.js +351 -0
  47. package/package.json +115 -34
  48. package/index.js +0 -678
  49. package/test.auto.js +0 -94
  50. package/test.auto.proc1.js +0 -97
  51. package/test.auto.proc2.js +0 -85
  52. package/test.visual.client.highload.js +0 -102
  53. package/test.visual.client.js +0 -103
  54. package/test.visual.error.js +0 -45
  55. package/test.visual.js +0 -97
  56. package/test.visual.server.highload.js +0 -102
  57. package/test.visual.server.js +0 -103
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/network/server.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,cAAc,EAEd,aAAa,EACd,MAAM,UAAU,CAAC;AAGlB,qBAAa,aAAa;IAatB,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,QAAQ;IAblB,SAAgB,GAAG,EAAE,MAAM,CAAC;IAC5B,SAAgB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAM;IAC5D,SAAgB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM;IACtD,SAAgB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAM;IAE7E,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAY;IAC1C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAiB;IAC1C,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,WAAW,CAAC,CAAa;IACjC,OAAO,CAAC,iBAAiB,CAAiB;gBAGhC,KAAK,EAAE,iBAAiB,EACxB,QAAQ,GAAE,cAAmB;IAavC,OAAO,CAAC,aAAa;IAcrB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,gBAAgB;IASxB,OAAO,CAAC,WAAW;IA8CnB,OAAO,CAAC,gBAAgB;IAuBxB,OAAO,CAAC,cAAc;IAmBtB,OAAO,CAAC,mBAAmB;IAiB3B,OAAO,CAAC,UAAU;IASlB,OAAO,CAAC,gBAAgB;IAyBxB,OAAO,CAAC,WAAW;IAyBnB,OAAO,CAAC,mBAAmB;IA2D3B,OAAO,CAAC,mBAAmB;IA8C3B,OAAO,CAAC,oBAAoB;IAyD5B,OAAO,CAAC,iBAAiB;IAazB,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,qBAAqB;IActB,SAAS,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,IAAI;IAgBzC,YAAY,IAAI,IAAI;IAI3B,OAAO,CAAC,OAAO;IAQR,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAiD9B"}
@@ -0,0 +1,403 @@
1
+ import * as net from "net";
2
+ import * as os from "os";
3
+ import * as path from "path";
4
+ import * as fs from "fs";
5
+ import * as zlib from "zlib";
6
+ import * as stream from "stream";
7
+ import * as crypto from "crypto";
8
+ import { MessageType, } from "../types";
9
+ import { hasher } from "../utils/crypto";
10
+ export class ClusterServer {
11
+ constructor(store, settings = {}) {
12
+ this.store = store;
13
+ this.settings = settings;
14
+ this.sockets = {};
15
+ this.database = {};
16
+ this.ip2ban = {};
17
+ this.ip2banTimeout = 10800000; // 3 hours
18
+ this.shouldAutoRestart = true;
19
+ this.uid = crypto.randomUUID();
20
+ this.setupDatabase();
21
+ this.setupBanSystem();
22
+ this.setupServer();
23
+ this.setupStoreIntegration();
24
+ this.ip2banGC = setInterval(() => {
25
+ this.cleanupBannedIPs();
26
+ }, 60000);
27
+ }
28
+ setupDatabase() {
29
+ if (this.settings.logins) {
30
+ for (const login in this.settings.logins) {
31
+ const hashedLogin = hasher(`REDUX_CLUSTER${login}`);
32
+ const hashedPassword = hasher(`REDUX_CLUSTER${this.settings.logins[login]}`);
33
+ if (hashedLogin && hashedPassword) {
34
+ this.database[hashedLogin] = hashedPassword;
35
+ }
36
+ }
37
+ }
38
+ }
39
+ setupBanSystem() {
40
+ // IP ban system is initialized in constructor
41
+ }
42
+ cleanupBannedIPs() {
43
+ const now = Date.now();
44
+ for (const key in this.ip2ban) {
45
+ if (this.ip2ban[key].time + this.ip2banTimeout < now) {
46
+ delete this.ip2ban[key];
47
+ }
48
+ }
49
+ }
50
+ setupServer() {
51
+ const listenOptions = this.getListenOptions();
52
+ this.server = net.createServer((socket) => {
53
+ this.handleNewConnection(socket);
54
+ });
55
+ this.server.on("listening", () => {
56
+ this.store.connected = true;
57
+ this.store.sendtoall({
58
+ _msg: MessageType.CONN_STATUS,
59
+ _hash: this.store.RCHash,
60
+ _connected: true,
61
+ });
62
+ });
63
+ this.server.on("close", () => {
64
+ this.store.connected = false;
65
+ this.store.sendtoall({
66
+ _msg: MessageType.CONN_STATUS,
67
+ _hash: this.store.RCHash,
68
+ _connected: false,
69
+ });
70
+ this.cleanup();
71
+ // Auto-restart server after 10 seconds
72
+ if (this.shouldAutoRestart) {
73
+ setTimeout(() => {
74
+ new ClusterServer(this.store, this.settings);
75
+ }, 10000);
76
+ }
77
+ });
78
+ this.server.on("error", (err) => {
79
+ this.store.stderr(`ReduxCluster.createServer socket error: ${err.message}`);
80
+ if (typeof this.server.close === "function") {
81
+ this.server.close();
82
+ }
83
+ });
84
+ this.startListening(listenOptions);
85
+ }
86
+ getListenOptions() {
87
+ const defaultOptions = { port: 10001 };
88
+ if (typeof this.settings.path === "string") {
89
+ switch (os.platform()) {
90
+ case "win32":
91
+ return { path: path.join("\\\\?\\pipe", this.settings.path) };
92
+ default:
93
+ return { path: path.join(this.settings.path) };
94
+ }
95
+ }
96
+ const options = { ...defaultOptions };
97
+ if (typeof this.settings.host === "string") {
98
+ options.host = this.settings.host;
99
+ }
100
+ if (typeof this.settings.port === "number") {
101
+ options.port = this.settings.port;
102
+ }
103
+ return options;
104
+ }
105
+ startListening(options) {
106
+ if (typeof options.path === "string") {
107
+ // Remove existing socket file
108
+ fs.unlink(options.path, (err) => {
109
+ if (err &&
110
+ !err.message.toLowerCase().includes("no such file or directory")) {
111
+ this.store.stderr(`ReduxCluster.createServer socket error: ${err.message}`);
112
+ }
113
+ this.server.listen(options);
114
+ });
115
+ }
116
+ else {
117
+ this.server.listen(options);
118
+ }
119
+ }
120
+ handleNewConnection(socket) {
121
+ // Hash IP address for security using hasher function
122
+ const clientIP = socket.remoteAddress ? hasher(socket.remoteAddress) : "";
123
+ const uid = crypto.randomUUID();
124
+ const clusterSocket = socket;
125
+ clusterSocket.uid = uid;
126
+ // Check if IP is banned
127
+ if (this.isIPBanned(clientIP)) {
128
+ this.rejectConnection(clusterSocket, true);
129
+ return;
130
+ }
131
+ this.setupSocket(clusterSocket, clientIP);
132
+ }
133
+ isIPBanned(ip) {
134
+ if (!ip || !this.ip2ban[ip])
135
+ return false;
136
+ const banInfo = this.ip2ban[ip];
137
+ const now = Date.now();
138
+ return banInfo.count >= 5 && banInfo.time + this.ip2banTimeout > now;
139
+ }
140
+ rejectConnection(socket, banned = false) {
141
+ // Create rejection message
142
+ const rejectionMessage = {
143
+ _msg: MessageType.SOCKET_AUTH_STATE,
144
+ _hash: this.store.RCHash,
145
+ _value: false,
146
+ ...(banned && { _banned: true }),
147
+ };
148
+ // Manually serialize and compress since custom write is not set up yet
149
+ try {
150
+ const compressed = zlib.gzipSync(Buffer.from(JSON.stringify(rejectionMessage)));
151
+ // Use the native write method directly, not the overridden one
152
+ const originalWrite = socket.writeNEW || socket.write.bind(socket);
153
+ originalWrite(compressed);
154
+ }
155
+ catch (err) {
156
+ this.store.stderr(`ReduxCluster.rejectConnection error: ${err.message}`);
157
+ }
158
+ this.closeSocket(socket);
159
+ }
160
+ setupSocket(socket, clientIP) {
161
+ // Override write method for object mode + compression
162
+ socket.writeNEW = socket.write;
163
+ socket.write = (data) => {
164
+ try {
165
+ const compressed = zlib.gzipSync(Buffer.from(JSON.stringify(data)));
166
+ return socket.writeNEW(compressed);
167
+ }
168
+ catch (err) {
169
+ this.store.stderr(`ReduxCluster.createServer write error: ${err.message}`);
170
+ return false;
171
+ }
172
+ };
173
+ socket.on("error", (err) => {
174
+ this.store.stderr(`ReduxCluster.createServer client error: ${err.message}`);
175
+ this.closeSocket(socket);
176
+ });
177
+ this.setupSocketPipeline(socket, clientIP);
178
+ }
179
+ setupSocketPipeline(socket, clientIP) {
180
+ // Create processing pipeline
181
+ const mbstring = new stream.Transform({
182
+ transform(buffer, encoding, callback) {
183
+ this.push(buffer);
184
+ callback();
185
+ },
186
+ });
187
+ mbstring.setEncoding("utf8");
188
+ const gunzipper = zlib.createGunzip();
189
+ // For now, we'll create a simple parser instead of using external library
190
+ const parser = new stream.Transform({
191
+ transform(chunk, encoding, callback) {
192
+ try {
193
+ const data = JSON.parse(chunk.toString());
194
+ this.push(data);
195
+ }
196
+ catch {
197
+ // Invalid JSON, ignore
198
+ }
199
+ callback();
200
+ },
201
+ objectMode: true,
202
+ });
203
+ const eventHandler = new stream.Writable({
204
+ write: (data, encoding, callback) => {
205
+ this.handleSocketMessage(data, socket, clientIP);
206
+ callback();
207
+ },
208
+ objectMode: true,
209
+ });
210
+ // Setup error handlers
211
+ [gunzipper, mbstring, parser, eventHandler].forEach((stream) => {
212
+ stream.on("error", (err) => {
213
+ this.store.stderr(`ReduxCluster.createServer stream error: ${err.message}`);
214
+ });
215
+ });
216
+ // Connect pipeline
217
+ socket.pipe(gunzipper).pipe(mbstring).pipe(parser).pipe(eventHandler);
218
+ }
219
+ handleSocketMessage(data, socket, clientIP) {
220
+ if (data._hash !== this.store.RCHash)
221
+ return;
222
+ switch (data._msg) {
223
+ case MessageType.MSG_TO_MASTER:
224
+ if (this.sockets[socket.uid]) {
225
+ if (data._action.type === MessageType.SYNC &&
226
+ !data._action._internal) {
227
+ throw new Error("Please don't use REDUX_CLUSTER_SYNC action type!");
228
+ }
229
+ // Apply action to server state
230
+ // This will automatically trigger sendActionsToNodes via reducer
231
+ this.store.dispatch(data._action);
232
+ }
233
+ break;
234
+ case MessageType.START:
235
+ if (this.sockets[socket.uid]) {
236
+ socket.write({
237
+ _msg: MessageType.MSG_TO_WORKER,
238
+ _hash: this.store.RCHash,
239
+ _action: {
240
+ type: MessageType.SYNC,
241
+ payload: this.store.getState(),
242
+ _internal: true,
243
+ },
244
+ });
245
+ }
246
+ break;
247
+ case MessageType.SOCKET_AUTH:
248
+ this.handleAuthentication(data, socket, clientIP);
249
+ break;
250
+ default:
251
+ // Ignore unknown message types
252
+ break;
253
+ }
254
+ }
255
+ handleAuthentication(data, socket, clientIP) {
256
+ const { _login, _password } = data;
257
+ // If no authentication is configured (empty database), allow all connections
258
+ if (Object.keys(this.database).length === 0) {
259
+ // No authentication required
260
+ this.sockets[socket.uid] = socket;
261
+ socket.write({
262
+ _msg: MessageType.SOCKET_AUTH_STATE,
263
+ _hash: this.store.RCHash,
264
+ _value: true,
265
+ });
266
+ return;
267
+ }
268
+ if (typeof _login !== "undefined" &&
269
+ typeof _password !== "undefined" &&
270
+ typeof this.database[_login] !== "undefined" &&
271
+ this.database[_login] === _password) {
272
+ // Successful authentication
273
+ this.sockets[socket.uid] = socket;
274
+ // Clear ban if exists
275
+ if (clientIP && this.ip2ban[clientIP]) {
276
+ delete this.ip2ban[clientIP];
277
+ }
278
+ // Use the custom write method that should be set up by now
279
+ socket.write({
280
+ _msg: MessageType.SOCKET_AUTH_STATE,
281
+ _hash: this.store.RCHash,
282
+ _value: true,
283
+ });
284
+ }
285
+ else {
286
+ // Failed authentication
287
+ if (clientIP) {
288
+ this.recordFailedLogin(clientIP);
289
+ }
290
+ // Use the custom write method that should be set up by now
291
+ socket.write({
292
+ _msg: MessageType.SOCKET_AUTH_STATE,
293
+ _hash: this.store.RCHash,
294
+ _value: false,
295
+ });
296
+ this.closeSocket(socket);
297
+ }
298
+ }
299
+ recordFailedLogin(ip) {
300
+ let count = 0;
301
+ if (this.ip2ban[ip]) {
302
+ count = this.ip2ban[ip].count;
303
+ if (count >= 5)
304
+ count = 0; // Reset on timeout
305
+ }
306
+ this.ip2ban[ip] = {
307
+ time: Date.now(),
308
+ count: count + 1,
309
+ };
310
+ }
311
+ closeSocket(socket) {
312
+ if (typeof socket.end === "function") {
313
+ socket.end();
314
+ }
315
+ if (socket.uid && this.sockets[socket.uid]) {
316
+ delete this.sockets[socket.uid];
317
+ }
318
+ }
319
+ setupStoreIntegration() {
320
+ // Register with store if in action mode
321
+ if (this.store.mode === "action") {
322
+ this.store.allsock[this.uid] = this;
323
+ }
324
+ // Subscribe to store changes in snapshot mode
325
+ this.unsubscribe = this.store.subscribe(() => {
326
+ if (this.store.mode === "snapshot") {
327
+ this.sendtoall();
328
+ }
329
+ });
330
+ }
331
+ sendtoall(message) {
332
+ const msg = message || {
333
+ _msg: MessageType.MSG_TO_WORKER,
334
+ _hash: this.store.RCHash,
335
+ _action: {
336
+ type: MessageType.SYNC,
337
+ payload: this.store.getState(),
338
+ _internal: true,
339
+ },
340
+ };
341
+ for (const uid in this.sockets) {
342
+ this.sockets[uid].write(msg);
343
+ }
344
+ }
345
+ ip2banGCStop() {
346
+ clearInterval(this.ip2banGC);
347
+ }
348
+ cleanup() {
349
+ if (this.unsubscribe) {
350
+ this.unsubscribe();
351
+ }
352
+ this.ip2banGCStop();
353
+ delete this.store.allsock[this.uid];
354
+ }
355
+ close() {
356
+ return new Promise((resolve) => {
357
+ // Prevent the automatic restart handler from creating a new server
358
+ this.shouldAutoRestart = false;
359
+ // Close all connected sockets first
360
+ Object.values(this.sockets).forEach((socket) => {
361
+ if (socket) {
362
+ try {
363
+ this.closeSocket(socket);
364
+ }
365
+ catch {
366
+ // ignore
367
+ }
368
+ }
369
+ });
370
+ // Clear sockets registry
371
+ Object.keys(this.sockets).forEach((key) => {
372
+ delete this.sockets[key];
373
+ });
374
+ // Stop IP ban garbage collector
375
+ if (this.ip2banGC) {
376
+ clearInterval(this.ip2banGC);
377
+ }
378
+ // Unsubscribe from store updates
379
+ if (this.unsubscribe) {
380
+ try {
381
+ this.unsubscribe();
382
+ }
383
+ catch {
384
+ // ignore
385
+ }
386
+ this.unsubscribe = undefined;
387
+ }
388
+ // Finally close the server and resolve when closed
389
+ if (this.server && typeof this.server.close === "function") {
390
+ try {
391
+ this.server.close(() => resolve());
392
+ }
393
+ catch {
394
+ // fallback resolve
395
+ resolve();
396
+ }
397
+ }
398
+ else {
399
+ resolve();
400
+ }
401
+ });
402
+ }
403
+ }
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,125 @@
1
+ import { Store, Action } from "redux";
2
+ export declare enum SerializationMode {
3
+ JSON = "json",
4
+ PROTOOBJECT = "protoobject"
5
+ }
6
+ export interface ReduxClusterConfig {
7
+ serializationMode?: SerializationMode;
8
+ debug?: boolean;
9
+ mode?: SyncMode;
10
+ syncMode?: "ipc" | "tcp";
11
+ role?: Role[];
12
+ server?: ServerSettings;
13
+ client?: ClientSettings;
14
+ backup?: BackupSettings;
15
+ stderr?: ErrorHandler;
16
+ resync?: number;
17
+ }
18
+ export type ProtoObjectState = any;
19
+ export declare enum MessageType {
20
+ CONN_STATUS = "REDUX_CLUSTER_CONNSTATUS",
21
+ MSG_TO_WORKER = "REDUX_CLUSTER_MSGTOWORKER",
22
+ MSG_TO_MASTER = "REDUX_CLUSTER_MSGTOMASTER",
23
+ SOCKET_AUTH = "REDUX_CLUSTER_SOCKET_AUTH",
24
+ SOCKET_AUTH_STATE = "REDUX_CLUSTER_SOCKET_AUTHSTATE",
25
+ START = "REDUX_CLUSTER_START",
26
+ SYNC = "REDUX_CLUSTER_SYNC"
27
+ }
28
+ export interface BaseMessage {
29
+ _msg: MessageType;
30
+ _hash: string;
31
+ }
32
+ export interface ConnectionStatusMessage extends BaseMessage {
33
+ _msg: MessageType.CONN_STATUS;
34
+ _connected: boolean;
35
+ }
36
+ export interface ActionToWorkerMessage extends BaseMessage {
37
+ _msg: MessageType.MSG_TO_WORKER;
38
+ _action: Action;
39
+ }
40
+ export interface ActionToMasterMessage extends BaseMessage {
41
+ _msg: MessageType.MSG_TO_MASTER;
42
+ _action: Action;
43
+ }
44
+ export interface SocketAuthMessage extends BaseMessage {
45
+ _msg: MessageType.SOCKET_AUTH;
46
+ _login: string;
47
+ _password: string;
48
+ }
49
+ export interface SocketAuthStateMessage extends BaseMessage {
50
+ _msg: MessageType.SOCKET_AUTH_STATE;
51
+ _value: boolean;
52
+ _banned?: boolean;
53
+ }
54
+ export interface StartMessage extends BaseMessage {
55
+ _msg: MessageType.START;
56
+ }
57
+ export type ClusterMessage = ConnectionStatusMessage | ActionToWorkerMessage | ActionToMasterMessage | SocketAuthMessage | SocketAuthStateMessage | StartMessage;
58
+ export type SyncMode = "action" | "snapshot";
59
+ export type Role = "master" | "worker" | "server" | "client";
60
+ export interface ServerSettings {
61
+ host?: string;
62
+ port?: number;
63
+ path?: string;
64
+ logins?: Record<string, string>;
65
+ }
66
+ export interface ClientSettings {
67
+ host?: string;
68
+ port?: number;
69
+ path?: string;
70
+ login?: string;
71
+ password?: string;
72
+ }
73
+ export interface BackupSettings {
74
+ path: string;
75
+ key?: string;
76
+ timeout?: number;
77
+ count?: number;
78
+ }
79
+ export interface ReduxClusterStore<S = any, A extends Action = Action> extends Store<S, A> {
80
+ readonly RCHash: string;
81
+ readonly version: string;
82
+ readonly homepage: string;
83
+ readonly role: Role[];
84
+ connected: boolean;
85
+ mode: SyncMode;
86
+ resync: number;
87
+ stderr: (message: string) => void;
88
+ readonly config: ReduxClusterConfig;
89
+ createServer(settings?: ServerSettings): ClusterServer;
90
+ createClient(settings?: ClientSettings): ClusterClient;
91
+ backup(settings: BackupSettings): Promise<boolean>;
92
+ sendtoall(message?: ClusterMessage): void;
93
+ sendtoallsock(message?: ClusterMessage): void;
94
+ registerClass?(name: string, classConstructor: any): void;
95
+ getRegisteredClasses?(): string[];
96
+ }
97
+ export interface ClusterServer {
98
+ readonly uid: string;
99
+ readonly sockets: Record<string, any>;
100
+ readonly database: Record<string, string>;
101
+ readonly ip2ban: Record<string, {
102
+ time: number;
103
+ count: number;
104
+ }>;
105
+ sendtoall(message?: ClusterMessage): void;
106
+ ip2banGCStop(): void;
107
+ }
108
+ export interface ClusterClient {
109
+ login?: string;
110
+ password?: string;
111
+ }
112
+ export interface ClusterSocket {
113
+ uid: string;
114
+ writeNEW: (data: any) => boolean;
115
+ write(data: any): boolean;
116
+ on(event: string, listener: (...args: any[]) => void): any;
117
+ pipe(...args: any[]): any;
118
+ end(): void;
119
+ remoteAddress?: string;
120
+ }
121
+ export type HasherFunction = (data: string, algorithm?: string) => string | undefined;
122
+ export type EncrypterFunction = (data: string, pass: string) => string;
123
+ export type DecrypterFunction = (data: string, pass: string) => string;
124
+ export type ErrorHandler = (message: string) => void;
125
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAGtC,oBAAY,iBAAiB;IAC3B,IAAI,SAAS;IACb,WAAW,gBAAgB;CAC5B;AAGD,MAAM,WAAW,kBAAkB;IAEjC,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IAEtC,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB,IAAI,CAAC,EAAE,QAAQ,CAAC;IAEhB,QAAQ,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IAEzB,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC;IAEd,MAAM,CAAC,EAAE,cAAc,CAAC;IAExB,MAAM,CAAC,EAAE,cAAc,CAAC;IAExB,MAAM,CAAC,EAAE,cAAc,CAAC;IAExB,MAAM,CAAC,EAAE,YAAY,CAAC;IAEtB,MAA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AAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,GAAG,CAAC;IAC3D,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC;IAC1B,GAAG,IAAI,IAAI,CAAC;IACZ,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAGD,MAAM,MAAM,cAAc,GAAG,CAC3B,IAAI,EAAE,MAAM,EACZ,SAAS,CAAC,EAAE,MAAM,KACf,MAAM,GAAG,SAAS,CAAC;AACxB,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;AACvE,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;AAGvE,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC"}
@@ -0,0 +1,17 @@
1
+ // Serialization modes
2
+ export var SerializationMode;
3
+ (function (SerializationMode) {
4
+ SerializationMode["JSON"] = "json";
5
+ SerializationMode["PROTOOBJECT"] = "protoobject";
6
+ })(SerializationMode || (SerializationMode = {}));
7
+ // Message types for IPC communication
8
+ export var MessageType;
9
+ (function (MessageType) {
10
+ MessageType["CONN_STATUS"] = "REDUX_CLUSTER_CONNSTATUS";
11
+ MessageType["MSG_TO_WORKER"] = "REDUX_CLUSTER_MSGTOWORKER";
12
+ MessageType["MSG_TO_MASTER"] = "REDUX_CLUSTER_MSGTOMASTER";
13
+ MessageType["SOCKET_AUTH"] = "REDUX_CLUSTER_SOCKET_AUTH";
14
+ MessageType["SOCKET_AUTH_STATE"] = "REDUX_CLUSTER_SOCKET_AUTHSTATE";
15
+ MessageType["START"] = "REDUX_CLUSTER_START";
16
+ MessageType["SYNC"] = "REDUX_CLUSTER_SYNC";
17
+ })(MessageType || (MessageType = {}));
@@ -0,0 +1,22 @@
1
+ import * as crypto from "crypto";
2
+ import { Transform } from "stream";
3
+ import { SerializationMode } from "../types";
4
+ export declare function hasher(input: string): string;
5
+ export declare function createCipher(key: string): crypto.Cipher;
6
+ export declare function createDecipher(key: string, iv: Buffer): crypto.Decipher;
7
+ export declare function encrypter(data: string, password: string): string;
8
+ export declare function decrypter(encryptedData: string, password: string): string;
9
+ export declare function deepClone(obj: any): any;
10
+ export declare function universalClone(obj: any, mode: SerializationMode, _classRegistry?: Map<string, any>): any;
11
+ export declare function protoObjectClone(obj: any): any;
12
+ export declare function universalSerialize(obj: any, mode: SerializationMode, classRegistry?: Map<string, any>): string;
13
+ export declare function universalDeserialize(str: string, mode: SerializationMode, classRegistry?: Map<string, any>): any;
14
+ export declare function serializeProtoObject(obj: any, classRegistry?: Map<string, any>): string;
15
+ export declare function deserializeProtoObject(str: string, classRegistry?: Map<string, any>): any;
16
+ export declare function createClassRegistry(): Map<string, any>;
17
+ export declare function createObjectStreamParser(): Transform | null;
18
+ export declare function createObjectStreamStringifier(): Transform | null;
19
+ export declare function createObjectStream(): Transform | null;
20
+ export declare function createDeserializationStream(mode: SerializationMode, classRegistry?: Map<string, any>): Transform;
21
+ export declare function createSerializationStream(mode: SerializationMode, classRegistry?: Map<string, any>): Transform;
22
+ //# sourceMappingURL=crypto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../../src/utils/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAoD7C,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE5C;AAGD,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAGvD;AAGD,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAA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