badmfck-api-server 2.4.4 → 2.4.5
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,12 @@
|
|
1
1
|
import { BaseService } from "./BaseService";
|
2
2
|
import { HUBConnection } from "./cluster/HUBConnection";
|
3
|
+
import Signal, { Req } from "badmfck-signal";
|
3
4
|
export interface ClusterServiceOptions {
|
4
5
|
id: string;
|
5
6
|
privateKey: string;
|
6
7
|
hubURL: string;
|
7
8
|
hubPublicKey: string;
|
8
|
-
nodes:
|
9
|
+
nodes: (Signal<any> | Req<any, any>)[];
|
9
10
|
}
|
10
11
|
export declare class ClusterService extends BaseService {
|
11
12
|
options: ClusterServiceOptions;
|
@@ -29,6 +29,7 @@ class ClusterService extends BaseService_1.BaseService {
|
|
29
29
|
ws: new ws_1.default(this.options.hubURL),
|
30
30
|
privateKey: this.options.privateKey,
|
31
31
|
hubID: this.options.id,
|
32
|
+
handlers: this.options.nodes,
|
32
33
|
onAuthorized: () => {
|
33
34
|
this.ws?.send({
|
34
35
|
method: "auth",
|
@@ -43,7 +44,6 @@ class ClusterService extends BaseService_1.BaseService {
|
|
43
44
|
console.log("ClusterService: connection to HUB closed");
|
44
45
|
this.connectToHUB();
|
45
46
|
},
|
46
|
-
handlers: []
|
47
47
|
});
|
48
48
|
}
|
49
49
|
}
|
@@ -4,13 +4,14 @@ import Signal, { Req } from "badmfck-signal";
|
|
4
4
|
import { IError } from "./structures/Interfaces";
|
5
5
|
export interface HUBServiceOptions {
|
6
6
|
url: string;
|
7
|
-
|
7
|
+
hubPrivateKey: string;
|
8
8
|
hubID: string;
|
9
9
|
}
|
10
10
|
export interface IClusterNode {
|
11
11
|
clusterID: string;
|
12
12
|
url: string;
|
13
13
|
publicKey: string;
|
14
|
+
privateKey: string;
|
14
15
|
ws: HUBConnection[];
|
15
16
|
}
|
16
17
|
export declare const REQ_CLUSTER_NODE: Req<string, IError | {
|
@@ -28,7 +28,7 @@ class HUBService extends BaseService_1.BaseService {
|
|
28
28
|
wss.on("connection", (ws) => {
|
29
29
|
const conn = new HUBConnection_1.HUBConnection({
|
30
30
|
ws: ws,
|
31
|
-
privateKey: this.options.
|
31
|
+
privateKey: this.options.hubPrivateKey,
|
32
32
|
hubID: this.options.hubID,
|
33
33
|
onAuthorized: () => this.onConnectionAuthorized(conn),
|
34
34
|
onClose: () => this.onConnectionClosed(conn),
|
@@ -48,6 +48,7 @@ class HUBService extends BaseService_1.BaseService {
|
|
48
48
|
clusterID: conn.clientID,
|
49
49
|
url: conn.url,
|
50
50
|
publicKey: conn.publicKey,
|
51
|
+
privateKey: "123",
|
51
52
|
ws: []
|
52
53
|
};
|
53
54
|
this.nodes.set(conn.clientID, clusterNode);
|
@@ -41,7 +41,7 @@ class HUBConnection {
|
|
41
41
|
onAuthorized;
|
42
42
|
intervalID = 0;
|
43
43
|
constructor(options) {
|
44
|
-
(0, LogService_1.logInfo)("HUBConnection: new connection");
|
44
|
+
(0, LogService_1.logInfo)("HUBConnection: new connection", options.ws.url);
|
45
45
|
this.privateKey = options.privateKey;
|
46
46
|
this.publicKey = null;
|
47
47
|
this.hubID = options.hubID;
|