bdy 1.22.66-master → 1.22.68-master

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.22.66-master",
4
+ "version": "1.22.68-master",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "scripts": {
@@ -33,6 +33,7 @@ class ServerSsh extends events_1.default {
33
33
  login;
34
34
  password;
35
35
  server;
36
+ injected = 0;
36
37
  constructor(agent, login, password, hostKey) {
37
38
  super();
38
39
  this.agent = agent;
@@ -82,8 +83,25 @@ class ServerSsh extends events_1.default {
82
83
  this.server = null;
83
84
  }
84
85
  handleSshTunnel(stream) {
85
- if (this.server)
86
+ if (this.server) {
87
+ this.injected += 1;
88
+ logger_1.default.debug(`injectSocket: ${this.injected} concurrent injected connection(s)`);
89
+ // Count inbound channel bytes the nested SSH server actually receives.
90
+ // CHANNEL_DATA pushes into the readable via .push(), so wrapping it is a
91
+ // read-only observation that does not change flow/backpressure.
92
+ let inBytes = 0;
93
+ const origPush = stream.push.bind(stream);
94
+ stream.push = (chunk, enc) => {
95
+ if (chunk)
96
+ inBytes += chunk.length;
97
+ return origPush(chunk, enc);
98
+ };
99
+ stream.once('close', () => {
100
+ this.injected -= 1;
101
+ logger_1.default.debug(`injectSocket received ${inBytes} inbound nested-SSH bytes (handshake already consumed)`);
102
+ });
86
103
  this.server.injectSocket(stream);
104
+ }
87
105
  }
88
106
  checkValueSafe(input, allowed) {
89
107
  const autoReject = input.length !== allowed.length;
@@ -73,16 +73,19 @@ class SshClient extends events_1.default {
73
73
  s.once('readable', resolve);
74
74
  });
75
75
  }
76
- async readStreamBytes(s, toRead) {
76
+ async readStreamBytes(s, toRead, reads = 0) {
77
77
  await this.waitForStreamReadable(s);
78
78
  const data = s.read(toRead) ?? s.read();
79
79
  if (data === null) {
80
- return this.readStreamBytes(s, toRead);
80
+ return this.readStreamBytes(s, toRead, reads + 1);
81
81
  }
82
82
  const newToRead = toRead - data.length;
83
- if (newToRead <= 0)
83
+ if (newToRead <= 0) {
84
+ if (reads > 0)
85
+ logger_1.default.debug(`handshake read took ${reads + 1} reads`);
84
86
  return data;
85
- const newData = await this.readStreamBytes(s, newToRead);
87
+ }
88
+ const newData = await this.readStreamBytes(s, newToRead, reads + 1);
86
89
  return Buffer.concat([data, newData]);
87
90
  }
88
91
  async processStream(stream, info) {
@@ -150,6 +153,7 @@ class SshClient extends events_1.default {
150
153
  }
151
154
  if (type === tunnel_1.TUNNEL_SOCKET_TYPE.SSH) {
152
155
  logger_1.default.debug((0, texts_1.LOG_DETECTED_STREAM)('SSH'));
156
+ logger_1.default.debug(`SSH handoff: ${stream.readableLength} leftover bytes buffered at injectSocket`);
153
157
  triggerStream(tunnel_1.TUNNEL_SSH_EVENT.STREAM_SSH, ip);
154
158
  return;
155
159
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.22.66-master",
4
+ "version": "1.22.68-master",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "scripts": {