@aj-shadow/z-abs-funclayer-engine-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.
Files changed (204) hide show
  1. package/.gitattributes +26 -0
  2. package/LICENSE.txt +96 -0
  3. package/README.md +5 -0
  4. package/npm-shrinkwrap.json +13 -0
  5. package/package.json +10 -0
  6. package/project/server/_build/Server-FuncLayer-Engine-server.bld +12 -0
  7. package/project/server/_build/z-abs-funclayer-engine-server.prj +12 -0
  8. package/project/server/address/address-calculator.js +377 -0
  9. package/project/server/address/address-data.js +364 -0
  10. package/project/server/address/address-manager.js +251 -0
  11. package/project/server/address/address.js +176 -0
  12. package/project/server/address/addresses.js +122 -0
  13. package/project/server/address/dns-url-cache.js +130 -0
  14. package/project/server/address/interfaces.js +100 -0
  15. package/project/server/address/local-dns.js +35 -0
  16. package/project/server/address/login-report.js +56 -0
  17. package/project/server/address/networks.js +598 -0
  18. package/project/server/address/real-networks.js +102 -0
  19. package/project/server/address/subnet.js +60 -0
  20. package/project/server/communication/messages/messages-s-to-c/message-execution-started.js +17 -0
  21. package/project/server/communication/messages/messages-s-to-c/message-execution-stopped.js +14 -0
  22. package/project/server/communication/messages/messages-s-to-c/message-test-case-debug-paused.js +18 -0
  23. package/project/server/communication/messages/messages-s-to-c/message-test-case-log.js +25 -0
  24. package/project/server/communication/messages/messages-s-to-c/message-test-case-started.js +21 -0
  25. package/project/server/communication/messages/messages-s-to-c/message-test-case-state.js +18 -0
  26. package/project/server/communication/messages/messages-s-to-c/message-test-case-stopped.js +22 -0
  27. package/project/server/communication/messages/messages-s-to-c/message-test-stage-started.js +19 -0
  28. package/project/server/communication/messages/messages-s-to-c/message-test-stage-stopped.js +19 -0
  29. package/project/server/communication/messages/messages-s-to-c/message-test-suite-started.js +16 -0
  30. package/project/server/communication/messages/messages-s-to-c/message-test-suite-stopped.js +19 -0
  31. package/project/server/communication/messages/messages-s-to-w/message-test-case-debug-actor-index-ok.js +15 -0
  32. package/project/server/communication/messages/messages-w-to-s/message-test-case-debug-actor-index.js +15 -0
  33. package/project/server/debug/debug-step-over.js +54 -0
  34. package/project/server/debug/debugger.js +102 -0
  35. package/project/server/debug-dashboard/debug-dashboard.js +14 -0
  36. package/project/server/debug-dashboard/gauge-manager.js +44 -0
  37. package/project/server/debug-dashboard/gauge.js +37 -0
  38. package/project/server/engine/actor/actor-condition.js +335 -0
  39. package/project/server/engine/actor/actor-intercepting.js +32 -0
  40. package/project/server/engine/actor/actor-local.js +24 -0
  41. package/project/server/engine/actor/actor-mixins/asynch-mixin.js +103 -0
  42. package/project/server/engine/actor/actor-mixins/content-mixin.js +22 -0
  43. package/project/server/engine/actor/actor-mixins/logger-mixin.js +603 -0
  44. package/project/server/engine/actor/actor-mixins/process-mixin.js +35 -0
  45. package/project/server/engine/actor/actor-mixins/shared-data-mixin.js +109 -0
  46. package/project/server/engine/actor/actor-mixins/shared-execution-data-mixin.js +57 -0
  47. package/project/server/engine/actor/actor-mixins/stack-mixin-client.js +157 -0
  48. package/project/server/engine/actor/actor-mixins/stack-mixin-server.js +123 -0
  49. package/project/server/engine/actor/actor-mixins/stack-mixin.js +128 -0
  50. package/project/server/engine/actor/actor-mixins/test-data-mixin.js +402 -0
  51. package/project/server/engine/actor/actor-mixins/timer-mixin.js +44 -0
  52. package/project/server/engine/actor/actor-mixins/verify-mixin-base.js +668 -0
  53. package/project/server/engine/actor/actor-mixins/verify-mixin-mandatory.js +46 -0
  54. package/project/server/engine/actor/actor-mixins/verify-mixin-optional.js +44 -0
  55. package/project/server/engine/actor/actor-mixins/verify-mixin-value.js +71 -0
  56. package/project/server/engine/actor/actor-originating.js +32 -0
  57. package/project/server/engine/actor/actor-part-mixins/part-asynch-mixin.js +24 -0
  58. package/project/server/engine/actor/actor-part-mixins/part-logger-mixin.js +39 -0
  59. package/project/server/engine/actor/actor-part-mixins/part-shared-runtime-data-mixin.js +33 -0
  60. package/project/server/engine/actor/actor-part-mixins/part-timer-mixin.js +12 -0
  61. package/project/server/engine/actor/actor-part-mixins/part-verify-mixin-mandatory.js +15 -0
  62. package/project/server/engine/actor/actor-part-mixins/part-verify-mixin-optional.js +15 -0
  63. package/project/server/engine/actor/actor-part-mixins/part-verify-mixin-value.js +15 -0
  64. package/project/server/engine/actor/actor-part-post.js +37 -0
  65. package/project/server/engine/actor/actor-part-pre.js +37 -0
  66. package/project/server/engine/actor/actor-pending.js +79 -0
  67. package/project/server/engine/actor/actor-proxy.js +38 -0
  68. package/project/server/engine/actor/actor-results.js +36 -0
  69. package/project/server/engine/actor/actor-state-timeout.js +35 -0
  70. package/project/server/engine/actor/actor-sut.js +38 -0
  71. package/project/server/engine/actor/actor-terminating.js +32 -0
  72. package/project/server/engine/actor/actor.js +553 -0
  73. package/project/server/engine/actor-phase.js +26 -0
  74. package/project/server/engine/actor-state-machine-base.js +298 -0
  75. package/project/server/engine/actor-state-machine-data.js +383 -0
  76. package/project/server/engine/actor-state-machine-exec.js +137 -0
  77. package/project/server/engine/actor-state-machine-post.js +177 -0
  78. package/project/server/engine/actor-state-machine-pre.js +142 -0
  79. package/project/server/engine/actor-state-machine-process.js +88 -0
  80. package/project/server/engine/actor-state-machine-state.js +52 -0
  81. package/project/server/engine/actor-state-machine.js +185 -0
  82. package/project/server/engine/actor-state.js +35 -0
  83. package/project/server/engine/actor-worker.js +68 -0
  84. package/project/server/engine/actors-phase.js +49 -0
  85. package/project/server/engine/actors.js +317 -0
  86. package/project/server/engine/data/content-audio.js +18 -0
  87. package/project/server/engine/data/content-base.js +91 -0
  88. package/project/server/engine/data/content-binary.js +15 -0
  89. package/project/server/engine/data/content-cache.js +67 -0
  90. package/project/server/engine/data/content-data.js +254 -0
  91. package/project/server/engine/data/content-documents.js +18 -0
  92. package/project/server/engine/data/content-image.js +20 -0
  93. package/project/server/engine/data/content-other.js +19 -0
  94. package/project/server/engine/data/content-text.js +19 -0
  95. package/project/server/engine/data/content-undefined.js +14 -0
  96. package/project/server/engine/data/content-video.js +20 -0
  97. package/project/server/engine/data/content.js +60 -0
  98. package/project/server/engine/data/runtime-data-shared.js +75 -0
  99. package/project/server/engine/data/test-data.js +239 -0
  100. package/project/server/engine/execution-context-test-case.js +48 -0
  101. package/project/server/engine/execution-context-test-suite.js +66 -0
  102. package/project/server/engine/execution-context.js +93 -0
  103. package/project/server/engine/stage-setter.js +132 -0
  104. package/project/server/engine/stage.js +83 -0
  105. package/project/server/engine/test-case-load.js +25 -0
  106. package/project/server/engine/test-case-loader.js +125 -0
  107. package/project/server/engine/test-case-not-found.js +29 -0
  108. package/project/server/engine/test-case-result-type.js +42 -0
  109. package/project/server/engine/test-case.js +417 -0
  110. package/project/server/engine/test-output.js +116 -0
  111. package/project/server/engine/test-statistics-test-case.js +59 -0
  112. package/project/server/engine/test-statistics-test-suite.js +63 -0
  113. package/project/server/engine/test-suite.js +276 -0
  114. package/project/server/stack/api/base-64.js +16 -0
  115. package/project/server/stack/api/const-commands-decoder.js +15 -0
  116. package/project/server/stack/api/const-commands-encoder.js +15 -0
  117. package/project/server/stack/api/hmacSha1.js +14 -0
  118. package/project/server/stack/api/json-web-token.js +38 -0
  119. package/project/server/stack/api/sdp/sdp-decoder.js +70 -0
  120. package/project/server/stack/api/sdp/sdp-encoder.js +40 -0
  121. package/project/server/stack/api/sdp/sdp-media-attribute.js +13 -0
  122. package/project/server/stack/api/sdp/sdp-media-session.js +16 -0
  123. package/project/server/stack/api/sdp/sdp-message.js +17 -0
  124. package/project/server/stack/api/sdp/sdp-origin.js +17 -0
  125. package/project/server/stack/api/sdp/sdp-session-attribute.js +13 -0
  126. package/project/server/stack/api/sdp/sdp-timing.js +15 -0
  127. package/project/server/stack/api/text-protocol-header.js +35 -0
  128. package/project/server/stack/factory/stack-components-helpers.js +22 -0
  129. package/project/server/stack/factory/stack-components-template-base-actors.js +124 -0
  130. package/project/server/stack/factory/stack-components-template-base-test-cases.js +22 -0
  131. package/project/server/stack/factory/stack-components-templates-actors.js +15 -0
  132. package/project/server/stack/factory/stack-components-templates-test-cases.js +20 -0
  133. package/project/server/stack/managers/client-manager/client-manager.js +193 -0
  134. package/project/server/stack/managers/connection-manager/connection-data.js +82 -0
  135. package/project/server/stack/managers/connection-manager/connection-manager.js +177 -0
  136. package/project/server/stack/managers/connection-manager/connection-object.js +148 -0
  137. package/project/server/stack/managers/connection-manager/shared-data.js +14 -0
  138. package/project/server/stack/managers/manager.js +95 -0
  139. package/project/server/stack/managers/server-manager/server-manager.js +76 -0
  140. package/project/server/stack/managers/server-manager/server.js +384 -0
  141. package/project/server/stack/managers/shared-manager.js +117 -0
  142. package/project/server/stack/network/buffer-manager.js +190 -0
  143. package/project/server/stack/network/mc/mc-connection-client-shared.js +51 -0
  144. package/project/server/stack/network/mc/mc-connection-client.js +117 -0
  145. package/project/server/stack/network/mc/mc-connection-server-shared.js +51 -0
  146. package/project/server/stack/network/mc/mc-connection-server.js +58 -0
  147. package/project/server/stack/network/mc/mc-connection-shared.js +26 -0
  148. package/project/server/stack/network/mc/mc-connection.js +33 -0
  149. package/project/server/stack/network/mc/mc-server.js +90 -0
  150. package/project/server/stack/network/network-connection-shared.js +177 -0
  151. package/project/server/stack/network/network-connection.js +134 -0
  152. package/project/server/stack/network/network-helper.js +12 -0
  153. package/project/server/stack/network/network-server.js +36 -0
  154. package/project/server/stack/network/network-type.js +46 -0
  155. package/project/server/stack/network/tcp/tcp-connection-client-shared.js +18 -0
  156. package/project/server/stack/network/tcp/tcp-connection-client.js +71 -0
  157. package/project/server/stack/network/tcp/tcp-connection-server-shared.js +14 -0
  158. package/project/server/stack/network/tcp/tcp-connection-server.js +16 -0
  159. package/project/server/stack/network/tcp/tcp-connection-shared.js +55 -0
  160. package/project/server/stack/network/tcp/tcp-connection.js +167 -0
  161. package/project/server/stack/network/tcp/tcp-server.js +35 -0
  162. package/project/server/stack/network/tls/tls-connection-client-shared.js +18 -0
  163. package/project/server/stack/network/tls/tls-connection-client.js +76 -0
  164. package/project/server/stack/network/tls/tls-connection-server-shared.js +14 -0
  165. package/project/server/stack/network/tls/tls-connection-server.js +16 -0
  166. package/project/server/stack/network/tls/tls-connection-shared.js +63 -0
  167. package/project/server/stack/network/tls/tls-connection.js +176 -0
  168. package/project/server/stack/network/tls/tls-server.js +45 -0
  169. package/project/server/stack/network/transport.js +19 -0
  170. package/project/server/stack/network/udp/udp-connection-client-shared.js +47 -0
  171. package/project/server/stack/network/udp/udp-connection-client.js +93 -0
  172. package/project/server/stack/network/udp/udp-connection-server-shared.js +51 -0
  173. package/project/server/stack/network/udp/udp-connection-server.js +58 -0
  174. package/project/server/stack/network/udp/udp-connection-shared.js +26 -0
  175. package/project/server/stack/network/udp/udp-connection.js +33 -0
  176. package/project/server/stack/network/udp/udp-server.js +74 -0
  177. package/project/server/stack/pending/pending-const.js +22 -0
  178. package/project/server/stack/pending/pending-context-receive.js +18 -0
  179. package/project/server/stack/pending/pending-context-send.js +18 -0
  180. package/project/server/stack/pending/pending-context.js +18 -0
  181. package/project/server/stack/pending/pending-inner.js +107 -0
  182. package/project/server/stack/pending/pending-switch.js +146 -0
  183. package/project/server/stack/stacks/ascii-dictionary.js +289 -0
  184. package/project/server/stack/stacks/binary-log.js +88 -0
  185. package/project/server/stack/stacks/bit-byte.js +51 -0
  186. package/project/server/stack/stacks/browser-data.js +25 -0
  187. package/project/server/stack/stacks/cancel-object.js +16 -0
  188. package/project/server/stack/stacks/connection-client.js +228 -0
  189. package/project/server/stack/stacks/connection-instance.js +69 -0
  190. package/project/server/stack/stacks/connection-ip.js +374 -0
  191. package/project/server/stack/stacks/connection-server.js +169 -0
  192. package/project/server/stack/stacks/connection-web.js +113 -0
  193. package/project/server/stack/stacks/connection-worker-client.js +29 -0
  194. package/project/server/stack/stacks/connection-worker-connection.js +41 -0
  195. package/project/server/stack/stacks/connection-worker-server.js +29 -0
  196. package/project/server/stack/stacks/connection-worker.js +99 -0
  197. package/project/server/stack/stacks/connection.js +132 -0
  198. package/project/server/stack/stacks/decoder.js +83 -0
  199. package/project/server/stack/stacks/encoder.js +82 -0
  200. package/project/server/stack/stacks/ip-log.js +24 -0
  201. package/project/server/stack/stacks/message-selector.js +22 -0
  202. package/project/server/stack/stacks/msg-ip.js +18 -0
  203. package/project/server/stack/stacks/stack-content-cache.js +27 -0
  204. package/project/z-abs-funclayer-engine-server.tree +230 -0
@@ -0,0 +1,134 @@
1
+
2
+ 'use strict';
3
+
4
+ const BufferManager = require('./buffer-manager');
5
+ const Transport = require('./transport');
6
+
7
+
8
+ class NetworkConnection {
9
+ constructor(transportProperties, name, type, connection) {
10
+ this.transportProperties = transportProperties;
11
+ this.name = name;
12
+ this.type = type;
13
+ this.connection = connection;
14
+ this.prefixLength = name.length + 1;
15
+ this.bufferManager = new BufferManager();
16
+ this.askedForReceiveLine = false;
17
+ this.askedForReceiveSize = 0;
18
+ this.askedForReceive = false;
19
+ this.cbDone = null;
20
+ this.isCancel = false;
21
+ this.lockSend = false;
22
+ this.lockReceive = false;
23
+ }
24
+
25
+ halfClosed() {
26
+ return false;
27
+ }
28
+
29
+ setTransportProperties(options, allowedProperties) {
30
+ Transport.setTransportProperties(options, this.transportProperties, allowedProperties, this.prefixLength)
31
+ }
32
+
33
+ send(msg, done) {
34
+ this.isCancel = false;
35
+ this.sendMessage(msg, done);
36
+ }
37
+
38
+ receiveLine(done) {
39
+ this.isCancel = false;
40
+ if(this.bufferManager.findLine()) {
41
+ const line = this.bufferManager.getLine();
42
+ process.nextTick(done, line, null);
43
+ this.cbDone = null;
44
+ this.askedForReceiveLine = false;
45
+ }
46
+ else {
47
+ this.cbDone = done;
48
+ this.askedForReceiveLine = true;
49
+ }
50
+ }
51
+
52
+ receiveSize(size, done) {
53
+ this.isCancel = false;
54
+ const buffer = this.bufferManager.receiveSize(size);
55
+ if(buffer) {
56
+ process.nextTick(done, buffer, null);
57
+ this.cbDone = null;
58
+ this.askedForReceiveSize = 0;
59
+ }
60
+ else {
61
+ this.cbDone = done;
62
+ this.askedForReceiveSize = size;
63
+ }
64
+ }
65
+
66
+ receive(done) {
67
+ this.isCancel = false;
68
+ const buffers = this.bufferManager.receive();
69
+ if(buffers) {
70
+ process.nextTick(done, buffers, null);
71
+ this.cbDone = null;
72
+ this.askedForReceive = false;
73
+ }
74
+ else {
75
+ this.cbDone = done;
76
+ this.askedForReceive = true;
77
+ }
78
+ }
79
+
80
+ cancel() {
81
+ this.isCancel = true;
82
+ }
83
+
84
+ onBuffer(buffer) {
85
+ if(this.isCancel) {
86
+ // TODO: Log dropped buffer
87
+ return;
88
+ }
89
+ this.bufferManager.addBuffer(buffer);
90
+ if(this.askedForReceiveLine) {
91
+ this.receiveLine(this.cbDone);
92
+ }
93
+ else if(0 < this.askedForReceiveSize) {
94
+ this.receiveSize(this.askedForReceiveSize, this.cbDone);
95
+ }
96
+ else if(this.askedForReceive) {
97
+ this.receive(this.cbDone);
98
+ }
99
+ }
100
+
101
+ onEnd() {
102
+ const done = this.cbDone;
103
+ this.cbDone = null;
104
+ if(this.askedForReceiveLine || this.askedForReceive || 0 !== this.askedForReceiveSize) {
105
+ process.nextTick(done, null, new Error('internal_error_network_end'));
106
+ this.askedForReceiveLine = false;
107
+ this.askedForReceiveSize = 0;
108
+ this.askedForReceive = false;
109
+ }
110
+ }
111
+
112
+ onError() {
113
+
114
+ }
115
+
116
+ getSrvAddress() {
117
+ return this.srvAddress;
118
+ }
119
+
120
+ getDstAddress() {
121
+ return this.dstAddress;
122
+ }
123
+
124
+ getLocal() {
125
+ return this.localAddress;
126
+ }
127
+
128
+ getRemote() {
129
+ return this.remoteAddress;
130
+ }
131
+ }
132
+
133
+
134
+ module.exports = NetworkConnection;
@@ -0,0 +1,12 @@
1
+
2
+ 'use strict';
3
+
4
+
5
+ class NetworkHelper {
6
+ constructor() {
7
+
8
+ }
9
+ }
10
+
11
+
12
+ module.exports = NetworkHelper;
@@ -0,0 +1,36 @@
1
+
2
+ 'use strict';
3
+
4
+ const Transport = require('./transport');
5
+
6
+
7
+ class NetworkServer {
8
+ constructor(connection, cbConnection, name) {
9
+ this.connection = connection;
10
+ this.cbConnection = cbConnection;
11
+ this.name = name;
12
+ this.srvAddress = null;
13
+ this.dstAddress = null;
14
+ this.prefixLength = name.length + 1;
15
+ this.serverSocket = null;
16
+ }
17
+
18
+ close(cbClose) {
19
+ if(null !== this.serverSocket) {
20
+ this.serverSocket.close((err) => {
21
+ cbClose();
22
+ });
23
+ this.serverSocket = null;
24
+ }
25
+ else {
26
+ process.nextTick(cbClose);
27
+ }
28
+ }
29
+
30
+ setTransportProperties(options, transportProperties, allowedProperties) {
31
+ Transport.setTransportProperties(options, transportProperties, allowedProperties, this.prefixLength)
32
+ }
33
+ }
34
+
35
+
36
+ module.exports = NetworkServer;
@@ -0,0 +1,46 @@
1
+
2
+ 'use strict';
3
+
4
+ // TODO: Remove - equal as
5
+ class NetworkType {
6
+ static getNetworkName(networkId) {
7
+ if(networkId < NetworkType.NetworkNames.length && networkId >= 0) {
8
+ return NetworkType.NetworkNames[networkId];
9
+ }
10
+ else {
11
+ return NetworkType.NetworkNameUnknown;
12
+ }
13
+ }
14
+ static getNetworkType(networkName) {
15
+ return _NetworkTypeConst_NetworkTypeNames.get(networkName);
16
+ }
17
+ }
18
+
19
+ NetworkType.DEFAULT = -1;
20
+ NetworkType.TCP = 0;
21
+ NetworkType.UDP = 1;
22
+ NetworkType.MC = 2;
23
+ NetworkType.TLS = 3;
24
+ NetworkType.BC = 4;
25
+ NetworkType.SCTP = 5;
26
+ NetworkType.QUIC = 6;
27
+
28
+ NetworkType.NetworkNames = [
29
+ 'tcp',
30
+ 'udp',
31
+ 'mc',
32
+ 'tls',
33
+ 'bc',
34
+ 'sctp',
35
+ 'quic'
36
+ ];
37
+
38
+ NetworkType.NetworkNameUnknown = 'unknown';
39
+
40
+ const _NetworkTypeConst_NetworkTypeNames = new Map();
41
+ for(let i = 0; i < NetworkType.NetworkNames.length; ++i) {
42
+ _NetworkTypeConst_NetworkTypeNames.set(NetworkType.NetworkNames[i], i);
43
+ }
44
+
45
+
46
+ module.exports = NetworkType;
@@ -0,0 +1,18 @@
1
+
2
+ 'use strict';
3
+
4
+ const TcpConnectionShared = require('./tcp-connection-shared');
5
+
6
+
7
+ class TcpConnectionClientShared extends TcpConnectionShared {
8
+ constructor(networkConnection, connectionName) {
9
+ super(networkConnection, connectionName);
10
+ }
11
+
12
+ connect(done) {
13
+ this.networkConnection.connect(done);
14
+ }
15
+ }
16
+
17
+
18
+ module.exports = TcpConnectionClientShared;
@@ -0,0 +1,71 @@
1
+
2
+ 'use strict';
3
+
4
+ const TcpConnection = require('./tcp-connection');
5
+ const Net = require('net');
6
+
7
+
8
+ class TcpConnectionClient extends TcpConnection {
9
+ static TRANSPORT_PROPERTIES = new Set(['allowHalfOpen', 'noDelay', 'keepAlive', 'keepAliveInitialDelay']);
10
+
11
+ constructor(srcAddress, dstAddress, transportProperties, connection) {
12
+ super(transportProperties, 'client', connection);
13
+ this.srcAddress = srcAddress;
14
+ this.dstAddress = dstAddress;
15
+ this.err = null;
16
+ }
17
+
18
+ connect(done) {
19
+ let timeoutId = -1;
20
+ this.cbError = (err) => {
21
+ this.cbError = null;
22
+ if(-1 !== timeoutId) {
23
+ clearTimeout(timeoutId);
24
+ }
25
+ this.err = err;
26
+ };
27
+ const options = {
28
+ host: this.dstAddress.host,
29
+ port: this.dstAddress.port,
30
+ localAddress: this.srcAddress.host,
31
+ localPort: this.srcAddress.port
32
+ };
33
+ this.setTransportProperties(options, TcpConnectionClient.TRANSPORT_PROPERTIES);
34
+ const socket = Net.connect(options, () => {
35
+ if(this.cbError) {
36
+ this.cbError();
37
+ if(done) {
38
+ const doDone = done;
39
+ done = null;
40
+ doDone(this.err);
41
+ }
42
+ }
43
+ });
44
+ if(!this.connection.actor.debug) {
45
+ timeoutId = setTimeout(() => {
46
+ if(this.cbError) {
47
+ this.cbError(new Error('Timeout'));
48
+ socket.destroy();
49
+ }
50
+ }, 10);
51
+ }
52
+ socket.on('error', (err) => {
53
+ if(this.cbError) {
54
+ this.cbError(err);
55
+ }
56
+ });
57
+ socket.on('close', () => {
58
+ if(this.err) {
59
+ if(done) {
60
+ const doDone = done;
61
+ done = null;
62
+ doDone(this.err);
63
+ }
64
+ }
65
+ });
66
+ this.attach(socket);
67
+ }
68
+ }
69
+
70
+
71
+ module.exports = TcpConnectionClient;
@@ -0,0 +1,14 @@
1
+
2
+ 'use strict';
3
+
4
+ const TcpConnectionShared = require('./tcp-connection-shared');
5
+
6
+
7
+ class TcpConnectionServerShared extends TcpConnectionShared {
8
+ constructor(networkConnection, connectionName) {
9
+ super(networkConnection, connectionName);
10
+ }
11
+ }
12
+
13
+
14
+ module.exports = TcpConnectionServerShared;
@@ -0,0 +1,16 @@
1
+
2
+ 'use strict';
3
+
4
+ const TcpConnection = require('./tcp-connection');
5
+
6
+
7
+ class TcpConnectionServer extends TcpConnection {
8
+ constructor(srvAddress, dstAddress, transportProperties, connection) {
9
+ super(transportProperties, 'server', connection);
10
+ this.srvAddress = srvAddress;
11
+ this.dstAddress = dstAddress;
12
+ }
13
+ }
14
+
15
+
16
+ module.exports = TcpConnectionServer;
@@ -0,0 +1,55 @@
1
+
2
+ 'use strict';
3
+
4
+ const NetworkConnectionShared = require('../network-connection-shared');
5
+
6
+
7
+ class TcpConnectionShared extends NetworkConnectionShared {
8
+ constructor(networkConnection, connectionName) {
9
+ super(networkConnection, connectionName);
10
+ }
11
+
12
+ attach(socket) {
13
+ this.networkConnection.attach(socket);
14
+ }
15
+
16
+ close(done) {
17
+ if(0 === this.unref()) {
18
+ this.networkConnection.close(done);
19
+ }
20
+ else {
21
+ process.nextTick(done);
22
+ }
23
+ }
24
+
25
+ sendMessage(msg) {
26
+ this.networkConnection.sendMessage(msg);
27
+ }
28
+
29
+ getLocalAddress() {
30
+ return this.networkConnection.getLocalAddress();
31
+ }
32
+
33
+ getLocalPort() {
34
+ return this.networkConnection.getLocalPort();
35
+ }
36
+
37
+ getLocalFamily() {
38
+ return this.networkConnection.getLocalFamily();
39
+ }
40
+
41
+ getRemoteAddress() {
42
+ return this.networkConnection.getRemoteAddress();
43
+ }
44
+
45
+ getRemotePort() {
46
+ return this.networkConnection.getRemotePort();
47
+ }
48
+
49
+ getRemoteFamily() {
50
+ return this.networkConnection.getRemoteFamily();
51
+ }
52
+ }
53
+
54
+
55
+ module.exports = TcpConnectionShared;
@@ -0,0 +1,167 @@
1
+
2
+ 'use strict';
3
+
4
+ const NetworkConnection = require('../network-connection');
5
+
6
+
7
+ class TcpConnection extends NetworkConnection {
8
+ constructor(transportProperties, type, connection) {
9
+ super(transportProperties, 'tcp', type, connection);
10
+ this.socket = null;
11
+ this.cbError = null;
12
+ this.queue = [];
13
+ this.stall = false;
14
+ this.endDone = null;
15
+ this.closeDone = null;
16
+ }
17
+
18
+ attach(socket) {
19
+ this.socket = socket;
20
+ this.socket.on('data', (buffer) => {
21
+ this.onBuffer(buffer);
22
+ });
23
+ this.socket.on('end', () => {
24
+ this.onEnd();
25
+ });
26
+ this.socket.on('error', (err) => {
27
+ if(this.cbError) {
28
+ this.cbError(err);
29
+ }
30
+ else {
31
+ this.onError(err);
32
+ }
33
+ });
34
+ }
35
+
36
+ end(done) {
37
+ if(null !== this.socket) {
38
+ if(this.transportProperties?.has('allowHalfOpen')) {
39
+ if(this.queue.length > 0) {
40
+ this.endDone = done;
41
+ return;
42
+ }
43
+ this.socket.once('end', (hadError) => {
44
+ done();
45
+ });
46
+ this.socket.end();
47
+ return;
48
+ }
49
+ }
50
+ else {
51
+ process.nextTick(done);
52
+ }
53
+ }
54
+
55
+ close(done) {
56
+ if(null !== this.socket) {
57
+ if(this.queue.length > 0) {
58
+ this.closeDone = done;
59
+ return;
60
+ }
61
+ this.socket.once('close', (hadError) => {
62
+ done();
63
+ });
64
+ this.socket.destroy();
65
+ return;
66
+ }
67
+ else {
68
+ process.nextTick(done);
69
+ }
70
+ }
71
+
72
+ closed() {
73
+ return !this.socket || this.socket && this.socket.destroyed;
74
+ }
75
+
76
+ halfClosed() {
77
+ return !this.socket || this.socket && 'readOnly' === this.socket.readyState;
78
+ }
79
+
80
+ sendMessage(msg) {
81
+ if(this.stall) {
82
+ this.queue.push(msg);
83
+ return;
84
+ }
85
+ const ok = this.socket.write(msg);
86
+ if(!ok) {
87
+ this._enterStall();
88
+ }
89
+ }
90
+
91
+ _enterStall() {
92
+ if(this.stall) {
93
+ return;
94
+ }
95
+ this.stall = true;
96
+ this.socket.once('drain', () => {
97
+ this.stall = false;
98
+ this._flushQueue();
99
+ });
100
+ }
101
+
102
+ _flushQueue() {
103
+ while(!this.stall && this.queue.length > 0) {
104
+ const msg = this.queue.shift();
105
+ const ok = this.socket.write(msg);
106
+ if(!ok) {
107
+ this._enterStall();
108
+ return;
109
+ }
110
+ }
111
+ if(0 === this.queue.length) {
112
+ if(this.endDone) {
113
+ this.end(() => {
114
+ this.endDone();
115
+ this.endDone = null;
116
+ if(this.closeDone) {
117
+ this.close(this.closeDone);
118
+ this.closeDone = null;
119
+ }
120
+ });
121
+ }
122
+ else if(this.closeDone) {
123
+ this.close(this.closeDone);
124
+ this.closeDone = null;
125
+ }
126
+ }
127
+ }
128
+
129
+ getLocalAddress() {
130
+ if(null !== this.socket) {
131
+ return this.socket.localAddress;
132
+ }
133
+ }
134
+
135
+ getLocalPort() {
136
+ if(null !== this.socket) {
137
+ return this.socket.localPort;
138
+ }
139
+ }
140
+
141
+ getLocalFamily() {
142
+ if(null !== this.socket) {
143
+ return this.socket.localFamily;
144
+ }
145
+ }
146
+
147
+ getRemoteAddress() {
148
+ if(null !== this.socket) {
149
+ return this.socket.remoteAddress;
150
+ }
151
+ }
152
+
153
+ getRemotePort() {
154
+ if(null !== this.socket) {
155
+ return this.socket.remotePort;
156
+ }
157
+ }
158
+
159
+ getRemoteFamily() {
160
+ if(null !== this.socket) {
161
+ return this.socket.remoteFamily;
162
+ }
163
+ }
164
+ }
165
+
166
+
167
+ module.exports = TcpConnection;
@@ -0,0 +1,35 @@
1
+
2
+ 'use strict';
3
+
4
+ const NetworkServer = require('../network-server');
5
+ const Net = require('net');
6
+
7
+
8
+ class TcpServer extends NetworkServer {
9
+ static TRANSPORT_PROPERTIES = new Set(['allowHalfOpen', 'pauseOnConnect', 'noDelay', 'keepAlive', 'keepAliveInitialDelay']);
10
+
11
+ constructor(connection, cbConnection) {
12
+ super(connection, cbConnection, 'tcp');
13
+ }
14
+
15
+ init(srvAddress, dstAddress, transportProperties, cbListen) {
16
+ this.srvAddress = srvAddress;
17
+ const options = {};
18
+ this.setTransportProperties(options, transportProperties, TcpServer.TRANSPORT_PROPERTIES);
19
+ this.serverSocket = Net.createServer(options, (socket) => {
20
+ this.cbConnection(socket);
21
+ });
22
+ this.serverSocket.on('error', (err) => {
23
+ cbListen(err);
24
+ });
25
+ this.serverSocket.listen({
26
+ host: this.srvAddress.host,
27
+ port: this.srvAddress.port
28
+ }, () => {
29
+ cbListen();
30
+ });
31
+ }
32
+ }
33
+
34
+
35
+ module.exports = TcpServer;
@@ -0,0 +1,18 @@
1
+
2
+ 'use strict';
3
+
4
+ const TlsConnectionShared = require('./tls-connection-shared');
5
+
6
+
7
+ class TlsConnectionClientShared extends TlsConnectionShared {
8
+ constructor(networkConnection, connectionName) {
9
+ super(networkConnection, connectionName);
10
+ }
11
+
12
+ connect(done) {
13
+ this.networkConnection.connect(done);
14
+ }
15
+ }
16
+
17
+
18
+ module.exports = TlsConnectionClientShared;
@@ -0,0 +1,76 @@
1
+
2
+ 'use strict';
3
+
4
+ const StackComponentsCerts = require('z-abs-funclayer-stack-server/server/factory/stack-components-certs');
5
+ const TlsConnection = require('./tls-connection');
6
+ const Tls = require('tls');
7
+
8
+
9
+ class TlsConnectionClient extends TlsConnection {
10
+ static TRANSPORT_PROPERTIES = new Set(['allowHalfOpen', 'noDelay', 'rejectUnauthorized', 'keepAlive', 'keepAliveInitialDelay']);
11
+
12
+ constructor(srcAddress, dstAddress, transportProperties, connection) {
13
+ super(transportProperties, 'client', connection);
14
+ this.srcAddress = srcAddress;
15
+ this.dstAddress = dstAddress;
16
+ this.err = null;
17
+ }
18
+
19
+ connect(done) {
20
+ let timeoutId = -1;
21
+ this.cbError = (err) => {
22
+ this.cbError = null;
23
+ if(-1 !== timeoutId) {
24
+ clearTimeout(timeoutId);
25
+ }
26
+ this.err = err;
27
+ };
28
+ const options = {
29
+ host: this.dstAddress.host,
30
+ port: this.dstAddress.port,
31
+ localAddress: this.srcAddress.host,
32
+ localPort: this.srcAddress.port,
33
+ checkServerIdentity: (host, cert) => {
34
+ //ddb.writeln('checkServerIdentity', host, cert);
35
+ },
36
+ ca: StackComponentsCerts.ca
37
+ };
38
+ this.setTransportProperties(options, TlsConnectionClient.TRANSPORT_PROPERTIES);
39
+ const socket = Tls.connect(options, () => {
40
+ if(this.cbError) {
41
+ this.cbError();
42
+ if(done) {
43
+ const doDone = done;
44
+ done = null;
45
+ doDone(this.err);
46
+ }
47
+ }
48
+ });
49
+ if(!this.connection.actor.debug) {
50
+ timeoutId = setTimeout(() => {
51
+ if(this.cbError) {
52
+ this.cbError(new Error('Timeout'));
53
+ socket.destroy();
54
+ }
55
+ }, 10);
56
+ }
57
+ socket.on('error', (err) => {
58
+ if(this.cbError) {
59
+ this.cbError(err);
60
+ }
61
+ });
62
+ socket.on('close', () => {
63
+ if(this.err) {
64
+ if(done) {
65
+ const doDone = done;
66
+ done = null;
67
+ doDone(this.err);
68
+ }
69
+ }
70
+ });
71
+ this.attach(socket);
72
+ }
73
+ }
74
+
75
+
76
+ module.exports = TlsConnectionClient;