querysub 0.84.0 → 0.86.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "querysub",
3
- "version": "0.84.0",
3
+ "version": "0.86.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "note1": "note on node-forge fork, see https://github.com/digitalbazaar/forge/issues/744 for details",
@@ -2,6 +2,8 @@ import debugbreak from "debugbreak";
2
2
  import * as net from "net";
3
3
  import ws from "ws";
4
4
  import child_process from "child_process";
5
+ import fs from "fs";
6
+ import path from "path";
5
7
 
6
8
  // Expose the internal port, via a tcp connection that we forward to internal port, for the first time
7
9
  // externalIP connects to us.
@@ -19,8 +21,19 @@ export async function hackDevtoolsWebsocketForward(config: {
19
21
  }> {
20
22
  const forwardCode = ((configInner: typeof config) => {
21
23
  const net = require("net");
24
+ const fs = require("fs");
25
+ const path = require("path");
22
26
  const server = net.createServer();
23
27
 
28
+ const debugFile = path.join(process.env.USERPROFILE || process.env.HOME, "debug.temp");
29
+ const logPacket = (direction: "RECEIVED" | "SENT", data: Buffer) => {
30
+ const timestamp = new Date().toISOString();
31
+ fs.appendFileSync(
32
+ debugFile,
33
+ `${timestamp} ${direction} ${data.length}\n`
34
+ );
35
+ };
36
+
24
37
  // Start listening on a random available port, binding to all interfaces (0.0.0.0)
25
38
  server.listen(0, "0.0.0.0");
26
39
 
@@ -46,6 +59,7 @@ export async function hackDevtoolsWebsocketForward(config: {
46
59
  port: configInner.internalPort,
47
60
  });
48
61
  internalConnection.on("data", (data: Buffer) => {
62
+ logPacket("SENT", data);
49
63
  socket.write(data);
50
64
  });
51
65
  let first = true;
@@ -57,6 +71,7 @@ export async function hackDevtoolsWebsocketForward(config: {
57
71
  lines[1] = `Host: 127.0.0.1:${configInner.internalPort}`;
58
72
  data = Buffer.from(lines.join("\r\n"));
59
73
  }
74
+ logPacket("RECEIVED", data);
60
75
  internalConnection.write(data);
61
76
  });
62
77
 
@@ -89,10 +104,10 @@ export async function hackDevtoolsWebsocketForward(config: {
89
104
  });
90
105
  });
91
106
 
107
+ console.log(`Forwarding to 127.0.0.1:${config.internalPort} for ${config.externalIP}`);
92
108
  const child = child_process.spawn("node", [
93
109
  "-e",
94
110
  `(${forwardCode.toString()})(${JSON.stringify(config)})`,
95
-
96
111
  ]);
97
112
 
98
113
  let externalPort: number | undefined;
@@ -126,6 +141,8 @@ export async function hackDevtoolsWebsocketForward(config: {
126
141
  // Wait for the port to be available
127
142
  externalPort = await portPromise;
128
143
 
144
+ console.log(`Forwarded external port ${externalPort} => ${config.internalPort} for ${config.externalIP}`);
145
+
129
146
  return {
130
147
  externalPort,
131
148
  cancel: () => {