@aj-shadow/z-abs-corelayer-server 0.0.0-aj-beta.221
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/.gitattributes +26 -0
- package/LICENSE.txt +96 -0
- package/README.md +5 -0
- package/npm-shrinkwrap.json +13 -0
- package/package.json +10 -0
- package/project/server/_build/Server-CoreLayer-server.bld +12 -0
- package/project/server/_build/z-abs-corelayer-server.prj +12 -0
- package/project/server/communication/core-protocol/decoder.js +404 -0
- package/project/server/communication/core-protocol/encoder.js +503 -0
- package/project/server/communication/messages/messages-s-to-c/message-persistent-init-response.js +14 -0
- package/project/server/communication/messages/messages-s-to-c/message-persistent-publish.js +16 -0
- package/project/server/communication/messages/messages-s-to-c/message-ws-init.js +14 -0
- package/project/server/communication/messages/messages-s-to-s/service-init-request.js +17 -0
- package/project/server/communication/messages/messages-s-to-s/service-init-response.js +18 -0
- package/project/server/communication/messages/messages-s-to-s/service-offer-off.js +15 -0
- package/project/server/communication/messages/messages-s-to-s/service-offer-on.js +15 -0
- package/project/server/communication/messages/messages-s-to-s/worker-init-request.js +15 -0
- package/project/server/data-response.js +588 -0
- package/project/server/high-resolution-timestamp.js +36 -0
- package/project/server/log/log-config.js +107 -0
- package/project/server/log/log-types.js +14 -0
- package/project/server/log/logger-console.js +36 -0
- package/project/server/log/logger.js +114 -0
- package/project/server/node/channel-input.js +65 -0
- package/project/server/node/channel-output.js +39 -0
- package/project/server/node/clients.js +80 -0
- package/project/server/node/connection-address.js +24 -0
- package/project/server/node/connection-data-ip.js +82 -0
- package/project/server/node/connection-data.js +25 -0
- package/project/server/node/const.js +44 -0
- package/project/server/node/external-services.js +209 -0
- package/project/server/node/http-cache.js +109 -0
- package/project/server/node/http-proxy.js +97 -0
- package/project/server/node/http-request-handler.js +219 -0
- package/project/server/node/http-server.js +36 -0
- package/project/server/node/http2-server.js +67 -0
- package/project/server/node/https-server.js +63 -0
- package/project/server/node/ip-client.js +98 -0
- package/project/server/node/ip-server.js +63 -0
- package/project/server/node/ip-subscription.js +46 -0
- package/project/server/node/message-channel.js +98 -0
- package/project/server/node/node-admin.js +513 -0
- package/project/server/node/node-data.js +25 -0
- package/project/server/node/node-settings.js +352 -0
- package/project/server/node/node-worker.js +76 -0
- package/project/server/node/node.js +156 -0
- package/project/server/node/servers.js +168 -0
- package/project/server/node/ws-client.js +12 -0
- package/project/server/node/ws-server.js +20 -0
- package/project/server/node/ws-web-server.js +52 -0
- package/project/server/node/wss-server.js +20 -0
- package/project/server/node/wss-web-server.js +82 -0
- package/project/server/path/actor-path-build.js +29 -0
- package/project/server/path/actor-path-content.js +51 -0
- package/project/server/path/actor-path-creator.js +90 -0
- package/project/server/path/actor-path-data.js +487 -0
- package/project/server/path/actor-path-dist.js +132 -0
- package/project/server/path/actor-path-generated.js +202 -0
- package/project/server/path/actor-path-project.js +181 -0
- package/project/server/path/actor-path.js +57 -0
- package/project/server/path/paths/actor-content-paths.js +34 -0
- package/project/server/path/paths/actor-data-paths.js +302 -0
- package/project/server/path/paths/actor-generated-paths.js +99 -0
- package/project/server/path/paths/actor-paths.js +22 -0
- package/project/server/plugin-base-multi.js +484 -0
- package/project/server/plugin-base.js +233 -0
- package/project/server/plugin-component.js +92 -0
- package/project/server/plugin-data/client/plugin_data_ClientGet.js +18 -0
- package/project/server/plugin-data/dialog-file/plugin_data_DialogFileGet.js +197 -0
- package/project/server/plugin-data/platform/plugin_data_PlatformPing.js +19 -0
- package/project/server/plugin-factor-protocol.js +35 -0
- package/project/server/plugin-factory.js +127 -0
- package/project/server/plugin-lock.js +164 -0
- package/project/server/response-queue.js +46 -0
- package/project/server/responses.js +20 -0
- package/project/server/service/plugin-service.js +264 -0
- package/project/server/service/service-export.js +47 -0
- package/project/server/service/service-manager.js +270 -0
- package/project/server/service/service-requests.js +49 -0
- package/project/server/session-cache.js +39 -0
- package/project/server/session.js +23 -0
- package/project/server/worker/worker-channel.js +175 -0
- package/project/server/worker/worker-core.js +58 -0
- package/project/server/worker/worker-main.js +165 -0
- package/project/server/worker/worker-pool.js +94 -0
- package/project/server/worker/worker-thread.js +128 -0
- package/project/z-abs-corelayer-server.tree +99 -0
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const Const = require('./const');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class NodeSettings {
|
|
8
|
+
static CONFIG_DEFUALT = 'default';
|
|
9
|
+
|
|
10
|
+
constructor(releaseData, dynamicConfig, originalSettings) {
|
|
11
|
+
this.releaseData = releaseData;
|
|
12
|
+
this.dynamicConfig = dynamicConfig;
|
|
13
|
+
this.originalSettings = originalSettings;
|
|
14
|
+
this.settings = {
|
|
15
|
+
httpServers: [],
|
|
16
|
+
http2Servers: [],
|
|
17
|
+
httpsServers: [],
|
|
18
|
+
tcpServers: [],
|
|
19
|
+
tlsServers: [],
|
|
20
|
+
wsServers: [],
|
|
21
|
+
wssServers: [],
|
|
22
|
+
tcpClients: [],
|
|
23
|
+
tlsClients: [],
|
|
24
|
+
wsClients: [],
|
|
25
|
+
wssClients: [],
|
|
26
|
+
ipProxyServers: [],
|
|
27
|
+
httpProxyServers: [],
|
|
28
|
+
wsWebServers: []
|
|
29
|
+
};
|
|
30
|
+
let config = NodeSettings.CONFIG_DEFUALT;
|
|
31
|
+
for(let i = 0; i < originalSettings.configurations.length; ++i) {
|
|
32
|
+
const hasConfig = this._hasConfig(originalSettings.configurations[i]);
|
|
33
|
+
if(hasConfig) {
|
|
34
|
+
config = originalSettings.configurations[i];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
this._parse(config);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
_parse(config) {
|
|
41
|
+
const settings = this.originalSettings;
|
|
42
|
+
if(settings.httpServers) {
|
|
43
|
+
settings.httpServers.forEach((httpServer, index) => {
|
|
44
|
+
const setting = {name:httpServer.name, type:httpServer.type, host:this._getHost(config, index, httpServer), port:this._getPort(config, index, httpServer), directories: httpServer.directories};
|
|
45
|
+
this.settings.httpServers.push(setting);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
if(settings.http2Servers) {
|
|
49
|
+
settings.http2Servers.forEach((http2Server, index) => {
|
|
50
|
+
const setting = {name:http2Server.name, type:http2Server.type, host:this._getHost(config, index, http2Server), port:this._getPort(config, index, http2Server), directories: http2Server.directories, keyFile:http2Server.keyFile, certFile:http2Server.certFile};
|
|
51
|
+
this.settings.http2Servers.push(setting);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
if(settings.httpsServers) {
|
|
55
|
+
settings.httpsServers.forEach((httpsServer, index) => {
|
|
56
|
+
const setting = {name:httpsServer.name, type:httpsServer.type, host:this._getHost(config, index, httpsServer), port:this._getPort(config, index, httpsServer), directories: httpsServer.directories, keyFile:httpsServer.keyFile, certFile:httpsServer.certFile};
|
|
57
|
+
this.settings.httpsServers.push(setting);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if(settings.tcpServers) {
|
|
61
|
+
settings.tcpServers.forEach((tcpServer, index) => {
|
|
62
|
+
const setting = {name:tcpServer.name, type:tcpServer.type, host:this._getHost(config, index, tcpServer), port:this._getPort(config, index, tcpServer), protocols:tcpServer.protocols};
|
|
63
|
+
this.settings.tcpServers.push(setting);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if(settings.tlsServers) {
|
|
67
|
+
settings.tlsServers.forEach((tlsServer, index) => {
|
|
68
|
+
const setting = {name:tlsServer.name, type:tlsServer.type, host:this._getHost(config, index, tlsServer), port:this._getPort(config, index, tlsServer), protocols:tlsServer.protocols, keyFile:tlsServer.keyFile, certFile:tlsServer.certFile};
|
|
69
|
+
this.settings.tlsServers.push(setting);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if(settings.wsServers) {
|
|
73
|
+
settings.wsServers.forEach((wsServer, index) => {
|
|
74
|
+
const setting = {name:wsServer.name, type:wsServer.type, host:this._getHost(config, index, wsServer), port:this._getPort(config, index, wsServer), protocols:wsServer.protocols};
|
|
75
|
+
this.settings.wsServers.push(setting);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
if(settings.wssServers) {
|
|
79
|
+
settings.wssServers.forEach((wssServer, index) => {
|
|
80
|
+
const setting = {name:wssServer.name, type:wssServer.type, host:this._getHost(config, index, wssServer), port:this._getPort(config, index, wssServer), protocols:wsServer.protocols, keyFile:wssServer.keyFile, certFile:wssServer.certFile};
|
|
81
|
+
this.settings.wssServers.push(setting);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
if(settings.tcpClients) {
|
|
85
|
+
settings.tcpClients.forEach((tcpClient) => {
|
|
86
|
+
const setting = {name:tcpClient.name, type:tcpClient.type, host:this._getHost(config, -1, tcpClient), port:this._getPort(config, -1, tcpClient), dependency:tcpClient.dependency, protocols:tcpClient.protocols};
|
|
87
|
+
this.settings.tcpClients.push(setting);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
if(settings.tlsClients) {
|
|
91
|
+
settings.tlsClients.forEach((tlsClient) => {
|
|
92
|
+
const setting = {name:tlsClient.name, type:tlsClient.type, host:this._getHost(config, -1, tlsClient), port:this._getPort(config, -1, tlsClient), dependency:tlsClient.dependency, protocols:tlsClient.protocols, keyFile:tlsClient.keyFile, certFile:tlsClient.certFile};
|
|
93
|
+
this.settings.tlsClients.push(setting);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
if(settings.wsClients) {
|
|
97
|
+
settings.wsClients.forEach((wsClient) => {
|
|
98
|
+
const setting = {name:wsClient.name, type:wsClient.type, host:this._getHosts(config, -1, wsClient), port:this._getPort(config, -1, wsClient), dependency:wsClient.dependency, protocols:wsClient.protocols};
|
|
99
|
+
this.settings.wsClients.push(setting);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
if(settings.wssClients) {
|
|
103
|
+
settings.wssClients.forEach((wssClient) => {
|
|
104
|
+
const setting = {name:wssClient.name, type:wssClient.type, host:this._getHost(config, -1, wssClient), port:this._getPort(config, -1, wssClient), dependency:wssClient.dependency, protocols:wssClient.protocols, keyFile:wssClient.keyFile, certFile:wssClient.certFile};
|
|
105
|
+
this.settings.wssClients.push(setting);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
if(settings.ipProxyServers) {
|
|
109
|
+
settings.ipProxyServers.forEach((ipProxyServer) => {
|
|
110
|
+
let frontendType = null;
|
|
111
|
+
const setting = {
|
|
112
|
+
frontend: {
|
|
113
|
+
type: 0,
|
|
114
|
+
settings: null
|
|
115
|
+
},
|
|
116
|
+
backend: {
|
|
117
|
+
type: 0,
|
|
118
|
+
settings: null
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
this.settings.ipProxyServers.push(setting);
|
|
122
|
+
this._getIpProxyType(ipProxyServer.frontend, setting.frontend, config, -1);
|
|
123
|
+
this._getIpProxyType(ipProxyServer.backend, setting.backend, config, -1);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
if(settings.httpProxyServers) {
|
|
127
|
+
settings.httpProxyServers.forEach((httpProxyServer) => {
|
|
128
|
+
let frontendType = null;
|
|
129
|
+
const setting = {
|
|
130
|
+
frontend: {
|
|
131
|
+
type: 0,
|
|
132
|
+
settings: null
|
|
133
|
+
},
|
|
134
|
+
backends: []
|
|
135
|
+
};
|
|
136
|
+
this.settings.httpProxyServers.push(setting);
|
|
137
|
+
this._getHttpProxyServerType(httpProxyServer.frontend, setting.frontend, config, -1);
|
|
138
|
+
this._getHttpProxyClientType(httpProxyServer.backends, setting.backends, config, -1);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
if(settings.wsWebServers) {
|
|
142
|
+
settings.wsWebServers.forEach((wsWebServer, index) => {
|
|
143
|
+
const setting = {name:wsWebServer.name, type:wsWebServer.type, host:this._getHost(config, index, wsWebServer), port:this._getPort(config, index, wsWebServer), protocols:wsWebServer.protocols};
|
|
144
|
+
this.settings.wsWebServers.push(setting);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
_getHttpProxyServerType(frontendOriginalSettings, frontendParsedSettings, config, index) {
|
|
150
|
+
let endInstance = null;
|
|
151
|
+
if(frontendOriginalSettings.httpProxyServer) {
|
|
152
|
+
endInstance = frontendOriginalSettings.httpProxyServer;
|
|
153
|
+
frontendParsedSettings.type = Const.TRANSPORT_HTTP;
|
|
154
|
+
frontendParsedSettings.settings = {name:endInstance.name, type:endInstance.type, host:this._getHost(config, index, endInstance), port:this._getPort(config, index, endInstance), protocols:endInstance.protocols};
|
|
155
|
+
}
|
|
156
|
+
else if(frontendOriginalSettings.httpsProxyServer) {
|
|
157
|
+
endInstance = frontendOriginalSettings.tlsServer;
|
|
158
|
+
frontendParsedSettings.type = Const.TRANSPORT_HTTPS;
|
|
159
|
+
frontendParsedSettings.settings = {name:endInstance.name, type:endInstance.type, host:this._getHost(config, index, endInstance), port:this._getPort(config, index, endInstance), protocols:endInstance.protocols, keyFile:endInstance.keyFile, certFile:endInstance.certFile};
|
|
160
|
+
}
|
|
161
|
+
else if(frontendOriginalSettings.wsServer) {
|
|
162
|
+
endInstance = frontendOriginalSettings.wsServer;
|
|
163
|
+
frontendParsedSettings.type = Const.TRANSPORT_HTTP2;
|
|
164
|
+
frontendParsedSettings.settings = {name:endInstance.name, type:endInstance.type, host:this._getHost(config, index, endInstance), port:this._getPort(config, index, endInstance), protocols:endInstance.protocols, keyFile:endInstance.keyFile, certFile:endInstance.certFile};
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if(endInstance.protocols) {
|
|
170
|
+
if(endInstance.protocols.client) {
|
|
171
|
+
frontendParsedSettings.settings.protocols.client = endInstance.protocols.client;
|
|
172
|
+
}
|
|
173
|
+
if(endInstance.protocols.server) {
|
|
174
|
+
frontendParsedSettings.settings.protocols.server = endInstance.protocols.server;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
_getHttpProxyClientType(backendOriginalSettings, backendParsedSettings, config, index) {
|
|
180
|
+
backendOriginalSettings.forEach((backendOriginalSetting) => {
|
|
181
|
+
const backend = {
|
|
182
|
+
type: 0,
|
|
183
|
+
urls: null,
|
|
184
|
+
settings: null
|
|
185
|
+
};
|
|
186
|
+
let endInstance = null;
|
|
187
|
+
backendParsedSettings.push(backend);
|
|
188
|
+
if(backendOriginalSetting.tcpClient) {
|
|
189
|
+
endInstance = backendOriginalSetting.tcpClient;
|
|
190
|
+
backend.type = Const.TRANSPORT_TCP;
|
|
191
|
+
backend.settings = {name:endInstance.name, type:endInstance.type, host:this._getHost(config, index, endInstance), port:this._getPort(config, index, endInstance), protocols:endInstance.protocols};
|
|
192
|
+
}
|
|
193
|
+
else if(backendOriginalSetting.tlsClient) {
|
|
194
|
+
endInstance = backendOriginalSetting.tlsClient;
|
|
195
|
+
backend.type = Const.TRANSPORT_TLS;
|
|
196
|
+
backend.settings = {name:endInstance.name, type:endInstance.type, host:this._getHost(config, index, endInstance), port:this._getPort(config, index, endInstance), protocols:endInstance.protocols, keyFile:endInstance.keyFile, certFile:endInstance.certFile};
|
|
197
|
+
}
|
|
198
|
+
else if(backendOriginalSetting.wsClient) {
|
|
199
|
+
endInstance = backendOriginalSetting.wsClient;
|
|
200
|
+
backend.type = Const.TRANSPORT_WS;
|
|
201
|
+
backend.settings = {name:endInstance.name, type:endInstance.type, host:this._getHost(config, index, endInstance), port:this._getPort(config, index, endInstance), protocols:endInstance.protocols};
|
|
202
|
+
}
|
|
203
|
+
else if(backendOriginalSetting.wssClient) {
|
|
204
|
+
endInstance = backendOriginalSetting.wssClient;
|
|
205
|
+
backend.type = Const.TRANSPORT_WSS;
|
|
206
|
+
backend.settings = {name:endInstance.name, type:endInstance.type, host:this._getHost(config, index, endInstance), port:this._getPort(config, index, endInstance), protocols:endInstance.protocols, keyFile:endInstance.keyFile, certFile:endInstance.certFile};
|
|
207
|
+
}
|
|
208
|
+
backend.urls = endInstance.urls;
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
_getIpProxyType(endPart, settingsEnd, config, index) {
|
|
213
|
+
let endInstance = null;
|
|
214
|
+
if(endPart.tcpServer) {
|
|
215
|
+
endInstance = endPart.tcpServer;
|
|
216
|
+
settingsEnd.type = Const.TRANSPORT_TCP;
|
|
217
|
+
settingsEnd.settings = {name:endInstance.name, type:endInstance.type, host:this._getHost(config, index, endInstance), port:this._getPort(config, index, endInstance), protocols:endInstance.protocols};
|
|
218
|
+
}
|
|
219
|
+
else if(endPart.tlsServer) {
|
|
220
|
+
endInstance = endPart.tlsServer;
|
|
221
|
+
settingsEnd.type = Const.TRANSPORT_TLS;
|
|
222
|
+
settingsEnd.settings = {name:endInstance.name, type:endInstance.type, host:this._getHost(config, index, endInstance), port:this._getPort(config, index, endInstance), protocols:endInstance.protocols, keyFile:endInstance.keyFile, certFile:endInstance.certFile};
|
|
223
|
+
}
|
|
224
|
+
else if(endPart.wsServer) {
|
|
225
|
+
endInstance = endPart.wsServer;
|
|
226
|
+
settingsEnd.type = Const.TRANSPORT_WS;
|
|
227
|
+
settingsEnd.settings = {name:endInstance.name, type:endInstance.type, host:this._getHost(config, index, endInstance), port:this._getPort(config, index, endInstance), protocols:endInstance.protocols};
|
|
228
|
+
}
|
|
229
|
+
else if(endPart.wssServer) {
|
|
230
|
+
endInstance = endPart.wssServer;
|
|
231
|
+
settingsEnd.type = Const.TRANSPORT_WSS;
|
|
232
|
+
settingsEnd.settings = {name:endInstance.name, type:endInstance.type, host:this._getHost(config, index, endInstance), port:this._getPort(config, index, endInstance), protocols:endInstance.protocols, keyFile:endInstance.keyFile, certFile:endInstance.certFile};
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if(endInstance.protocols) {
|
|
238
|
+
if(endInstance.protocols.client) {
|
|
239
|
+
settingsEnd.settings.protocols.client = endInstance.protocols.client;
|
|
240
|
+
}
|
|
241
|
+
if(endInstance.protocols.server) {
|
|
242
|
+
settingsEnd.settings.protocols.server = endInstance.protocols.server;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
_hasConfig(name, index) {
|
|
248
|
+
let value = '';
|
|
249
|
+
if(!index) {
|
|
250
|
+
value = this.dynamicConfig.parameters.has(name);
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
value = this.dynamicConfig.parameters.has(`${name}${index + 1}`);
|
|
254
|
+
}
|
|
255
|
+
return value;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
_getConfig(name, index) {
|
|
259
|
+
let value = '';
|
|
260
|
+
if(!index) {
|
|
261
|
+
value = this.dynamicConfig.parameters.get(name);
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
value = this.dynamicConfig.parameters.get(`${name}${index + 1}`);
|
|
265
|
+
}
|
|
266
|
+
return value;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
_getHost(config, index, parameters) {
|
|
270
|
+
if(-1 !== index) {
|
|
271
|
+
let host = '';
|
|
272
|
+
if('http-server' === parameters.name) {
|
|
273
|
+
host = this._getConfig('httph', index);
|
|
274
|
+
}
|
|
275
|
+
else if('https-server' === parameters.name) {
|
|
276
|
+
host = this._getConfig('httpsh', index);
|
|
277
|
+
}
|
|
278
|
+
else if('http2-server' === parameters.name) {
|
|
279
|
+
host = this._getConfig('http2h', index);
|
|
280
|
+
}
|
|
281
|
+
else if('tcp-server' === parameters.name) {
|
|
282
|
+
host = this._getConfig('tcph', index);
|
|
283
|
+
}
|
|
284
|
+
else if('tls-server' === parameters.name) {
|
|
285
|
+
host = this._getConfig('tlsh', index);
|
|
286
|
+
}
|
|
287
|
+
else if('ws-server' === parameters.name) {
|
|
288
|
+
host = this._getConfig('wsh', index);
|
|
289
|
+
}
|
|
290
|
+
else if('wss-server' === parameters.name) {
|
|
291
|
+
host = this._getConfig('wssh', index);
|
|
292
|
+
}
|
|
293
|
+
else if('ws-web-server' === parameters.name) {
|
|
294
|
+
host = this._getConfig('wswebh', index);
|
|
295
|
+
}
|
|
296
|
+
if(host) {
|
|
297
|
+
return host;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if(NodeSettings.CONFIG_DEFUALT === config) {
|
|
301
|
+
return parameters.host;
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
return Reflect.get(parameters, `${config}Host`);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
_getPort(config, index, parameters) {
|
|
309
|
+
if(-1 !== index) {
|
|
310
|
+
let port = '';
|
|
311
|
+
if('http-server' === parameters.name) {
|
|
312
|
+
port = this._getConfig('httpp', index);
|
|
313
|
+
}
|
|
314
|
+
else if('https-server' === parameters.name) {
|
|
315
|
+
port = this._getConfig('httpsp', index);
|
|
316
|
+
}
|
|
317
|
+
else if('http2-server' === parameters.name) {
|
|
318
|
+
port = this._getConfig('http2p', index);
|
|
319
|
+
}
|
|
320
|
+
else if('tcp-server' === parameters.name) {
|
|
321
|
+
port = this._getConfig('tcpp', index);
|
|
322
|
+
}
|
|
323
|
+
else if('tls-server' === parameters.name) {
|
|
324
|
+
port = this._getConfig('tlsp', index);
|
|
325
|
+
}
|
|
326
|
+
else if('ws-server' === parameters.name) {
|
|
327
|
+
port = this._getConfig('wsp', index);
|
|
328
|
+
}
|
|
329
|
+
else if('wss-server' === parameters.name) {
|
|
330
|
+
port = this._getConfig('wssp', index);
|
|
331
|
+
}
|
|
332
|
+
else if('ws-web-server' === parameters.name) {
|
|
333
|
+
port = this._getConfig('wswebp', index);
|
|
334
|
+
}
|
|
335
|
+
else if('wss-web-server' === parameters.name) {
|
|
336
|
+
port = this._getConfig('wsswebp', index);
|
|
337
|
+
}
|
|
338
|
+
if(port) {
|
|
339
|
+
return Number.parseInt(port);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
if(NodeSettings.CONFIG_DEFUALT === config) {
|
|
343
|
+
return parameters.port;
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
return Reflect.get(parameters, `${config}Port`);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
module.exports = NodeSettings;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const Const = require('./const');
|
|
5
|
+
const WorkerInitRequest = require('../communication/messages/messages-s-to-s/worker-init-request');
|
|
6
|
+
const DataResponse = require('../data-response');
|
|
7
|
+
const ConnectionData = require('./connection-data');
|
|
8
|
+
const PluginFactoryProtocol = require('../plugin-factor-protocol');
|
|
9
|
+
const CoreProtocolConst = require('z-abs-corelayer-cs/clientServer/communication/core-protocol/core-protocol-const');
|
|
10
|
+
const GuidGenerator = require('z-abs-corelayer-cs/clientServer/guid-generator');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class NodeWorker {
|
|
14
|
+
static id = -1;
|
|
15
|
+
|
|
16
|
+
constructor() {
|
|
17
|
+
this.nodeName = `WORKER-${++NodeWorker.id}-NODE`
|
|
18
|
+
this.nodeId = GuidGenerator.create();
|
|
19
|
+
this.dataResponse = new DataResponse(this.nodeName, this.nodeId, Const.NODE_TYPE_WORKER, this, null);
|
|
20
|
+
this.channelOutput = null;
|
|
21
|
+
this.channelInput = null;
|
|
22
|
+
this.connectionData = null;
|
|
23
|
+
this.pluginFactoryProtocol = new PluginFactoryProtocol();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
init(sessionData, pluginPath, protocols) {
|
|
27
|
+
this.connectionData = new ConnectionData(`WORKER-${NodeWorker.id}-NODE-IN`, `WORKER-${NodeWorker.id}-NODE-OUT`, process.send.bind(process));
|
|
28
|
+
let pendings = 2;
|
|
29
|
+
this.dataResponse.pluginDataFactory.load(() => {
|
|
30
|
+
if(0 === --pendings) {
|
|
31
|
+
this._init(sessionData);
|
|
32
|
+
}
|
|
33
|
+
}, pluginPath);
|
|
34
|
+
this.pluginFactoryProtocol.load(protocols, () => {
|
|
35
|
+
this.pluginFactoryProtocol.register(null, this.connectionData.channelOutput);
|
|
36
|
+
if(0 === --pendings) {
|
|
37
|
+
this._init(sessionData);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
_init(sessionData) {
|
|
43
|
+
const channelInput = this.connectionData.channelInput;
|
|
44
|
+
process.on('message', (msg) => {
|
|
45
|
+
channelInput.onNewMessage(Buffer.from(msg.data), true, (coreMessage) => {
|
|
46
|
+
if(CoreProtocolConst.REQUEST === coreMessage.msgId) {
|
|
47
|
+
this.dataResponse.handleRequests(coreMessage.msg, null, null, (response, dataBuffers, debug, token) => {
|
|
48
|
+
this.send(response, dataBuffers, debug, coreMessage.envelope);
|
|
49
|
+
}, (message, dataBuffers, debug, sessionId) => {
|
|
50
|
+
this.send(message, dataBuffers, debug, coreMessage.envelope);
|
|
51
|
+
}, this.connectionData);
|
|
52
|
+
}
|
|
53
|
+
else if(999 <= coreMessage.msgId) {
|
|
54
|
+
const session = this.dataResponse.sessionCache.getSession(coreMessage.msg.sessionId);
|
|
55
|
+
if(session) {
|
|
56
|
+
session.dataPluginsInternal.forEach((dataPlugin) => {
|
|
57
|
+
dataPlugin.handleMessageFromClient(coreMessage.msg);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
// TODO: log
|
|
63
|
+
console.log('*************************');
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
this.send(new WorkerInitRequest(sessionData), null, false, null);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
send(msg, dataBuffers, debug, envelope) {
|
|
71
|
+
this.connectionData.channelOutput.send(msg, dataBuffers, debug, envelope);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
module.exports = NodeWorker;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const DebugDashboard = require('z-abs-corelayer-cs/clientServer/debug-dashboard/log');
|
|
5
|
+
const ExternalServices = require('./external-services');
|
|
6
|
+
const Const = require('./const');
|
|
7
|
+
const Clients = require('./clients');
|
|
8
|
+
const Servers = require('./servers');
|
|
9
|
+
const NodeSettings = require('./node-settings');
|
|
10
|
+
const DataResponse = require('../data-response');
|
|
11
|
+
const PluginFactoryProtocol = require('../plugin-factor-protocol');
|
|
12
|
+
const GuidGenerator = require('z-abs-corelayer-cs/clientServer/guid-generator');
|
|
13
|
+
const Net = require('net');
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Node {
|
|
17
|
+
static TYPE_PRODUCTION = 0;
|
|
18
|
+
static TYPE_DEVELOPMENT = 1;
|
|
19
|
+
static TYPE_TEST = 2;
|
|
20
|
+
static TYPE_NPM = 3;
|
|
21
|
+
|
|
22
|
+
static NODE_OK = ddb.green('Node: ');
|
|
23
|
+
static NODE_STOP = ddb.yellow('Node: ');
|
|
24
|
+
static NODE_NOK = ddb.red('Node: ');
|
|
25
|
+
|
|
26
|
+
constructor(releaseData, dynamicConfig, settings, build) {
|
|
27
|
+
this.settings = settings;
|
|
28
|
+
this.build = build;
|
|
29
|
+
this.NodeSettings = new NodeSettings(releaseData, dynamicConfig, settings);
|
|
30
|
+
this.nodeName = settings.type ? `${settings.type}-${settings.name}` : settings.name;
|
|
31
|
+
this.nodeId = GuidGenerator.create();
|
|
32
|
+
this.nodeType = this._setNodeType();
|
|
33
|
+
this.pluginDatas = settings.pluginDatas;
|
|
34
|
+
this.pluginServices = settings.pluginServices;
|
|
35
|
+
this.pluginComponents = settings.pluginComponents;
|
|
36
|
+
this.externalServices = new ExternalServices();
|
|
37
|
+
this.dataResponse = new DataResponse(this.nodeName, this.nodeId, this.nodeType, this, this.externalServices);
|
|
38
|
+
this.servers = new Servers(this.nodeName, this.nodeId, this.NodeSettings.settings, this.settings.defaultSite, this.dataResponse);
|
|
39
|
+
this.clients = new Clients(this.nodeName, this.nodeId, this.NodeSettings.settings, this.dataResponse);
|
|
40
|
+
this.initialized = false;
|
|
41
|
+
this.hasCaughtException = false;
|
|
42
|
+
this.workers = new Map();
|
|
43
|
+
if(settings.workers) {
|
|
44
|
+
settings.workers.forEach((worker) => {
|
|
45
|
+
const pluginFactoryProtocol = new PluginFactoryProtocol();
|
|
46
|
+
const protocols = worker.protocols?.server ? worker.protocols.server : '[]';
|
|
47
|
+
pluginFactoryProtocol.load(protocols, () => {});
|
|
48
|
+
this.workers.set(worker.name, {
|
|
49
|
+
worker,
|
|
50
|
+
pluginFactoryProtocol
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
this.nodeStartedSubscriptions = [];
|
|
55
|
+
//console.log('pid:', process.pid, 'ppid:', process.ppid);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
run(cb) {
|
|
59
|
+
if(this.build) {
|
|
60
|
+
return cb();
|
|
61
|
+
}
|
|
62
|
+
this.subscribeOnNodeStarted(() => {
|
|
63
|
+
ddb.writelnTime(Node.NODE_OK, this.nodeName, ddb.yellow('::'), this.nodeId, ddb.green(' started.'));
|
|
64
|
+
});
|
|
65
|
+
this.servers.create();
|
|
66
|
+
this.clients.create();
|
|
67
|
+
this.dataResponse.init(this.pluginDatas, this.pluginServices, this.pluginComponents, this.NodeSettings.settings, this.workers, () => {
|
|
68
|
+
process.on('uncaughtException', this._uncaughtException.bind(this));
|
|
69
|
+
process.on('exit', this._onExit.bind(this));
|
|
70
|
+
process.on('SIGINT', this._onSigint.bind(this));
|
|
71
|
+
this.dataResponse.startServices(() => {
|
|
72
|
+
this.servers.start(() => {
|
|
73
|
+
this.clients.start(() => {
|
|
74
|
+
cb();
|
|
75
|
+
this._publishNodeStarted();
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
subscribeOnConnectionEvents(guid, eventType, name, cb) {
|
|
83
|
+
if(Const.EVENT_TYPE_CONNECTION === eventType) {
|
|
84
|
+
this.servers.subscribeOnConnectionEvents(guid, eventType, name, cb);
|
|
85
|
+
this.clients.subscribeOnConnectionEvents(guid, eventType, name, cb);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
unsubscribeOnConnectionEvents(guid, eventType, name) {
|
|
90
|
+
if(Const.EVENT_TYPE_CONNECTION === eventType) {
|
|
91
|
+
this.servers.unsubscribeOnConnectionEvents(guid, eventType, name);
|
|
92
|
+
this.clients.unsubscribeOnConnectionEvents(guid, eventType, name);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
subscribeOnNodeStarted(cb) {
|
|
97
|
+
this.nodeStartedSubscriptions.push(cb);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
_setNodeType() {
|
|
101
|
+
if(undefined === this.settings.nodeType) {
|
|
102
|
+
return Const.NODE_TYPE_FRONTEND;
|
|
103
|
+
}
|
|
104
|
+
else if('backend' === this.settings.nodeType) {
|
|
105
|
+
return Const.NODE_TYPE_BACKEND;
|
|
106
|
+
}
|
|
107
|
+
else if('proxy' === this.settings.nodeType) {
|
|
108
|
+
return Const.NODE_TYPE_PROXY;
|
|
109
|
+
}
|
|
110
|
+
else if('surveillance' === this.settings.nodeType) {
|
|
111
|
+
return Const.NODE_TYPE_SURVEILLANCE;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
_publishNodeStarted() {
|
|
116
|
+
const cb = this.nodeStartedSubscriptions.shift();
|
|
117
|
+
if(cb) {
|
|
118
|
+
cb();
|
|
119
|
+
process.nextTick(this._publishNodeStarted.bind(this));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
_uncaughtException(err, origin) {
|
|
124
|
+
// TODO: Add timoutes.
|
|
125
|
+
ddb.writelnTime(ddb.redBright(' uncaught exception: '), err.message);
|
|
126
|
+
console.log(err);
|
|
127
|
+
this.hasCaughtException = true;
|
|
128
|
+
this.dataResponse.stopServices(true, () => {
|
|
129
|
+
ddb.writelnTime(Node.NODE_STOP, this.nodeName, ddb.yellow('::'), this.nodeId, ddb.green(' stopped in an orderly manner.'));
|
|
130
|
+
process.exit(0xBAD);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
_onExit(code) {
|
|
135
|
+
if(this.hasCaughtException && 0xBAD !== code) {
|
|
136
|
+
ddb.writelnTime(Node.NODE_NOK, this.nodeName, ddb.yellow('::'), this.nodeId, ddb.red(' stopped in an unordered manner.'));
|
|
137
|
+
}
|
|
138
|
+
// TODO: Add timoutes.
|
|
139
|
+
/*this.dataResponse.stopServices(true, () => {
|
|
140
|
+
ddb.writelnTime(ddb.green('****** Node '), this.nodeName, ddb.yellow('::'), this.nodeId, ddb.green(' stopped in an orderly manner. ******'));
|
|
141
|
+
ddb.writelnTime(ddb.redBright(' uncaught exception: '));
|
|
142
|
+
process.exit(code);
|
|
143
|
+
});*/
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
_onSigint(code) {
|
|
147
|
+
// TODO: Add timoutes.
|
|
148
|
+
this.dataResponse.stopServices(false, () => {
|
|
149
|
+
ddb.writelnTime(Node.NODE_STOP, this.nodeName, ddb.yellow('::'), this.nodeId, ddb.redBright(' received SIGINT'), ddb.green(' stopped in an orderly manner.'));
|
|
150
|
+
process.exit(0xDEAD);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
module.exports = Node;
|