socket-function 0.57.0 → 0.59.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": "socket-function",
3
- "version": "0.57.0",
3
+ "version": "0.59.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",
@@ -188,54 +188,57 @@ export async function startSocketServer(
188
188
  });
189
189
 
190
190
  let realServer = net.createServer(socket => {
191
- //console.log("Received TCP connection from " + socket.remoteAddress);
192
- const debug = socket.remoteAddress + ":" + socket.remotePort;
193
- function handleTLSHello(buffer: Buffer, packetCount: number): void | "more" {
194
- if (!SocketFunction.silent) {
195
- console.log(`Received TCP header packet from ${debug}, have ${buffer.length} bytes so far, ${packetCount} packets`);
196
- }
197
- // All HTTPS requests start with 22, and no HTTP requests start with 22,
198
- // so we just need to read the first byte.
199
- let server: https.Server | http.Server;
200
- if (buffer[0] !== 22) {
201
- server = httpServer;
202
- } else {
203
- let data = parseTLSHello(buffer);
204
- if (data.missingBytes > 0) {
205
- return "more";
206
- }
207
- let sni = data.extensions.filter(x => x.type === SNIType).flatMap(x => parseSNIExtension(x.data))[0];
208
- if (!SocketFunction.silent) {
209
- console.log(`Received TCP connection with SNI ${JSON.stringify(sni)}`);
210
- }
211
- if (!sni) {
212
- console.warn(`No SNI found in TLS hello from ${debug}, using main server. Packets ${packetCount}`);
213
- console.log(buffer.toString("base64"));
214
- }
215
- server = sniServers.get(sni) || mainHTTPSServer;
216
- }
191
+ let server = sniServers.get("querysub.com") || mainHTTPSServer;
192
+ server.emit("connection", socket);
217
193
 
218
- // NOTE: Messages aren't dequeued until the current handler finishes, so we don't need to pause the socket or anything.
219
- server.emit("connection", socket);
220
- socket.unshift(buffer);
221
- }
222
- let buffers: Buffer[] = [];
223
- function getNextData() {
224
- // NOTE: ONCE is used, so we only look at the first buffer, and then after that
225
- // we pipe. This should be very efficient, as pipe has insane throughput
226
- // (100s of MB/s, easily, even on a terrible machine).
227
- socket.once("data", buffer => {
228
- buffers.push(buffer);
229
- let result = handleTLSHello(Buffer.concat(buffers), buffers.length);
230
- if (result === "more") {
231
- getNextData();
232
- }
233
- });
234
- }
235
- getNextData();
236
- socket.on("error", (e) => {
237
- console.error(`Socket error for ${debug}, ${e.stack}`);
238
- });
194
+ // //console.log("Received TCP connection from " + socket.remoteAddress);
195
+ // const debug = socket.remoteAddress + ":" + socket.remotePort;
196
+ // function handleTLSHello(buffer: Buffer, packetCount: number): void | "more" {
197
+ // if (!SocketFunction.silent) {
198
+ // console.log(`Received TCP header packet from ${debug}, have ${buffer.length} bytes so far, ${packetCount} packets`);
199
+ // }
200
+ // // All HTTPS requests start with 22, and no HTTP requests start with 22,
201
+ // // so we just need to read the first byte.
202
+ // let server: https.Server | http.Server;
203
+ // if (buffer[0] !== 22) {
204
+ // server = httpServer;
205
+ // } else {
206
+ // let data = parseTLSHello(buffer);
207
+ // if (data.missingBytes > 0) {
208
+ // return "more";
209
+ // }
210
+ // let sni = data.extensions.filter(x => x.type === SNIType).flatMap(x => parseSNIExtension(x.data))[0];
211
+ // if (!SocketFunction.silent) {
212
+ // console.log(`Received TCP connection with SNI ${JSON.stringify(sni)}`);
213
+ // }
214
+ // if (!sni) {
215
+ // console.warn(`No SNI found in TLS hello from ${debug}, using main server. Packets ${packetCount}`);
216
+ // console.log(buffer.toString("base64"));
217
+ // }
218
+ // server = sniServers.get(sni) || mainHTTPSServer;
219
+ // }
220
+
221
+ // // NOTE: Messages aren't dequeued until the current handler finishes, so we don't need to pause the socket or anything.
222
+ // server.emit("connection", socket);
223
+ // socket.unshift(buffer);
224
+ // }
225
+ // let buffers: Buffer[] = [];
226
+ // function getNextData() {
227
+ // // NOTE: ONCE is used, so we only look at the first buffer, and then after that
228
+ // // we pipe. This should be very efficient, as pipe has insane throughput
229
+ // // (100s of MB/s, easily, even on a terrible machine).
230
+ // socket.once("data", buffer => {
231
+ // buffers.push(buffer);
232
+ // let result = handleTLSHello(Buffer.concat(buffers), buffers.length);
233
+ // if (result === "more") {
234
+ // getNextData();
235
+ // }
236
+ // });
237
+ // }
238
+ // getNextData();
239
+ // socket.on("error", (e) => {
240
+ // console.error(`Socket error for ${debug}, ${e.stack}`);
241
+ // });
239
242
  });
240
243
 
241
244