bdy 1.9.32-dev → 1.9.33-dev

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,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.9.32-dev",
4
+ "version": "1.9.33-dev",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "scripts": {
@@ -36,7 +36,10 @@ class ServerHttp2 extends events_1.default {
36
36
  const address = this.server.address();
37
37
  if (!address || !address.port)
38
38
  return;
39
- let client = http2_1.default.connect(`http://localhost:${address.port}`);
39
+ let client = http2_1.default.connect(`http://localhost:${address.port}`, {
40
+ maxSessionMemory: 100,
41
+ noDelay: true
42
+ });
40
43
  let req = client.request(logRequest.headers);
41
44
  if (logRequest.requestBody.data.length > 0)
42
45
  req.write(logRequest.requestBody.data);
@@ -39,7 +39,7 @@ class SshClient extends events_1.default {
39
39
  hmac: ['hmac-sha2-256-etm@openssh.com'],
40
40
  kex: ['ecdh-sha2-nistp256'],
41
41
  },
42
- keepaliveInterval: 60000,
42
+ keepaliveInterval: 30000,
43
43
  host: this.ip,
44
44
  port: this.port,
45
45
  username: this.username,
@@ -69,6 +69,7 @@ class SshClient extends events_1.default {
69
69
  return Buffer.concat([data, newData]);
70
70
  }
71
71
  async processStream(stream, info) {
72
+ stream.allowHalfOpen = false;
72
73
  if (stream.readableFlowing)
73
74
  stream.pause();
74
75
  stream.on('error', () => {
@@ -9,14 +9,14 @@ const http2_1 = __importDefault(require("http2"));
9
9
  const uuid_1 = require("uuid");
10
10
  const texts_js_1 = require("../texts.js");
11
11
  const CONNECTION_TIMEOUT = 5000;
12
- const STREAM_LIMIT = 100;
12
+ const STREAM_LIMIT = 10;
13
13
  class TunnelAgent {
14
14
  static getHttp1() {
15
15
  if (!this.httpAgent1) {
16
16
  this.httpAgent1 = new http_1.default.Agent({
17
17
  noDelay: true,
18
18
  keepAlive: true,
19
- maxSockets: 200,
19
+ maxSockets: 20,
20
20
  });
21
21
  }
22
22
  return this.httpAgent1;
@@ -26,7 +26,7 @@ class TunnelAgent {
26
26
  this.httpsAgent1 = new https_1.default.Agent({
27
27
  noDelay: true,
28
28
  keepAlive: true,
29
- maxSockets: 200,
29
+ maxSockets: 20,
30
30
  });
31
31
  }
32
32
  return this.httpsAgent1;
@@ -39,6 +39,7 @@ class TunnelAgent {
39
39
  }, CONNECTION_TIMEOUT);
40
40
  const client = http2_1.default.connect(authority, {
41
41
  rejectUnauthorized: verify,
42
+ maxSessionMemory: 100,
42
43
  noDelay: true,
43
44
  servername,
44
45
  });
@@ -195,24 +195,7 @@ class TunnelHttp extends events_1.default {
195
195
  headers,
196
196
  });
197
197
  this.logRequest = this.httpLog.newRequest(method, headers, path, utils_1.TUNNEL_IDENTIFIED_HTTP1, this.req);
198
- r.on('upgrade', (proxyRes, socket) => {
199
- const headers = this.getClearedHeaders(proxyRes.headers, null, true);
200
- let msg = 'HTTP/1.1 101 Web Socket Protocol Handshake\r\n';
201
- Object.keys(headers).forEach((k) => {
202
- const v = headers[k];
203
- if (Array.isArray(v)) {
204
- v.forEach((vv) => {
205
- msg += `${k}: ${vv}\r\n`;
206
- });
207
- }
208
- else {
209
- msg += `${k}: ${v}\r\n`;
210
- }
211
- });
212
- msg += '\r\n';
213
- this.req.socket.write(msg);
214
- this.req.socket.pipe(socket).pipe(this.req.socket);
215
- });
198
+ r.on('upgrade', (proxyRes, socket, head) => this.upgrade(proxyRes, socket, head));
216
199
  r.on('response', (proxyRes) => {
217
200
  this.proxyRes = proxyRes;
218
201
  const statusCode = this.proxyRes.statusCode;
@@ -255,24 +238,7 @@ class TunnelHttp extends events_1.default {
255
238
  headers,
256
239
  });
257
240
  this.logRequest = this.httpLog.newRequest(method, headers, path, utils_1.TUNNEL_IDENTIFIED_HTTP1, this.req);
258
- r.on('upgrade', (proxyRes, socket) => {
259
- const headers = this.getClearedHeaders(proxyRes.headers, null, true);
260
- let msg = 'HTTP/1.1 101 Web Socket Protocol Handshake\r\n';
261
- Object.keys(headers).forEach((k) => {
262
- const v = headers[k];
263
- if (Array.isArray(v)) {
264
- v.forEach((vv) => {
265
- msg += `${k}: ${vv}\r\n`;
266
- });
267
- }
268
- else {
269
- msg += `${k}: ${v}\r\n`;
270
- }
271
- });
272
- msg += '\r\n';
273
- this.req.socket.write(msg);
274
- this.req.socket.pipe(socket).pipe(this.req.socket);
275
- });
241
+ r.on('upgrade', (proxyRes, socket, head) => this.upgrade(proxyRes, socket, head));
276
242
  r.on('response', (proxyRes) => {
277
243
  this.proxyRes = proxyRes;
278
244
  const statusCode = this.proxyRes.statusCode;
@@ -386,6 +352,47 @@ class TunnelHttp extends events_1.default {
386
352
  this.logRequest = null;
387
353
  }
388
354
  }
355
+ upgrade(proxyRes, socket, head) {
356
+ const resHeaders = proxyRes.headers;
357
+ const reqSocket = this.req.socket;
358
+ this.httpLog.newResponse(this.req, 101, resHeaders, this.logRequest);
359
+ this.clear();
360
+ socket.setTimeout(0);
361
+ const headers = this.getClearedHeaders(resHeaders, null, true);
362
+ let msg = 'HTTP/1.1 101 Web Socket Protocol Handshake\r\n';
363
+ Object.keys(headers).forEach((k) => {
364
+ const v = headers[k];
365
+ if (Array.isArray(v)) {
366
+ v.forEach((vv) => {
367
+ msg += `${k}: ${vv}\r\n`;
368
+ });
369
+ }
370
+ else {
371
+ msg += `${k}: ${v}\r\n`;
372
+ }
373
+ });
374
+ msg += '\r\n';
375
+ reqSocket.removeAllListeners();
376
+ socket.removeAllListeners();
377
+ reqSocket.on('close', () => {
378
+ reqSocket.removeAllListeners();
379
+ this.emit(utils_1.HTTP1_SOCKET_CLOSED, reqSocket);
380
+ });
381
+ socket.on('close', () => {
382
+ socket.removeAllListeners();
383
+ try {
384
+ reqSocket.destroy();
385
+ }
386
+ catch {
387
+ // do nothing
388
+ }
389
+ });
390
+ if (head && head.length) {
391
+ socket.unshift(head);
392
+ }
393
+ reqSocket.write(msg);
394
+ reqSocket.pipe(socket).pipe(reqSocket);
395
+ }
389
396
  async pipe() {
390
397
  if (this.serve) {
391
398
  try {
@@ -426,6 +426,7 @@ class Tunnel extends events_1.default {
426
426
  httpIdentify: this.identify.type,
427
427
  httpLog: this.httpLog,
428
428
  });
429
+ http.once(utils_js_1.HTTP1_SOCKET_CLOSED, (socket) => this.httpConnectionClosed(socket));
429
430
  http.pipe().then();
430
431
  }
431
432
  tlsSocket(tlsSocket) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.9.32-dev",
4
+ "version": "1.9.33-dev",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "scripts": {