badmfck-api-server 2.4.4 → 2.4.6
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.
@@ -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 | {
|
@@ -26,9 +26,10 @@ class HUBService extends BaseService_1.BaseService {
|
|
26
26
|
path: "/hub"
|
27
27
|
});
|
28
28
|
wss.on("connection", (ws) => {
|
29
|
+
(0, LogService_1.logInfo)("HUBService: new connection on wss server");
|
29
30
|
const conn = new HUBConnection_1.HUBConnection({
|
30
31
|
ws: ws,
|
31
|
-
privateKey: this.options.
|
32
|
+
privateKey: this.options.hubPrivateKey,
|
32
33
|
hubID: this.options.hubID,
|
33
34
|
onAuthorized: () => this.onConnectionAuthorized(conn),
|
34
35
|
onClose: () => this.onConnectionClosed(conn),
|
@@ -48,6 +49,7 @@ class HUBService extends BaseService_1.BaseService {
|
|
48
49
|
clusterID: conn.clientID,
|
49
50
|
url: conn.url,
|
50
51
|
publicKey: conn.publicKey,
|
52
|
+
privateKey: "123",
|
51
53
|
ws: []
|
52
54
|
};
|
53
55
|
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;
|