socket-function 0.54.0 → 0.56.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 +1 -1
- package/src/webSocketServer.ts +8 -5
package/package.json
CHANGED
package/src/webSocketServer.ts
CHANGED
|
@@ -75,7 +75,6 @@ export async function startSocketServer(
|
|
|
75
75
|
ca: getTrustedCertificates(),
|
|
76
76
|
// Attempt to disable sessions, because they make SNI significantly harder to parse.
|
|
77
77
|
secureOptions: require("node:constants").SSL_OP_NO_TICKET,
|
|
78
|
-
keepAlive: false,
|
|
79
78
|
};
|
|
80
79
|
if (!httpsServerLast) {
|
|
81
80
|
httpsServerLast = https.createServer(lastOptions);
|
|
@@ -158,6 +157,10 @@ export async function startSocketServer(
|
|
|
158
157
|
// so it is easy to read, and consistent.
|
|
159
158
|
let options: https.ServerOptions = {
|
|
160
159
|
...config,
|
|
160
|
+
// Keep alive causes problems with our HTTP requests. AND... almost all of our data uses
|
|
161
|
+
// our websockets, so... we really don't need to keep alive our HTTP requests
|
|
162
|
+
// (and our images go through cloudflare, so we don't even need keep alive for that)
|
|
163
|
+
keepAlive: false,
|
|
161
164
|
};
|
|
162
165
|
if (!config.cert) {
|
|
163
166
|
throw new Error("No cert specified");
|
|
@@ -186,10 +189,10 @@ export async function startSocketServer(
|
|
|
186
189
|
|
|
187
190
|
let realServer = net.createServer(socket => {
|
|
188
191
|
//console.log("Received TCP connection from " + socket.remoteAddress);
|
|
189
|
-
const
|
|
192
|
+
const debug = socket.remoteAddress + ":" + socket.remotePort;
|
|
190
193
|
function handleTLSHello(buffer: Buffer, packetCount: number): void | "more" {
|
|
191
194
|
if (!SocketFunction.silent) {
|
|
192
|
-
console.log(`Received TCP header packet from ${
|
|
195
|
+
console.log(`Received TCP header packet from ${debug}, have ${buffer.length} bytes so far, ${packetCount} packets`);
|
|
193
196
|
}
|
|
194
197
|
// All HTTPS requests start with 22, and no HTTP requests start with 22,
|
|
195
198
|
// so we just need to read the first byte.
|
|
@@ -206,7 +209,7 @@ export async function startSocketServer(
|
|
|
206
209
|
console.log(`Received TCP connection with SNI ${JSON.stringify(sni)}`);
|
|
207
210
|
}
|
|
208
211
|
if (!sni) {
|
|
209
|
-
console.warn(`No SNI found in TLS hello from ${
|
|
212
|
+
console.warn(`No SNI found in TLS hello from ${debug}, using main server. Packets ${packetCount}`);
|
|
210
213
|
console.log(buffer.toString("base64"));
|
|
211
214
|
}
|
|
212
215
|
server = sniServers.get(sni) || mainHTTPSServer;
|
|
@@ -231,7 +234,7 @@ export async function startSocketServer(
|
|
|
231
234
|
}
|
|
232
235
|
getNextData();
|
|
233
236
|
socket.on("error", (e) => {
|
|
234
|
-
console.error(`Socket error for ${
|
|
237
|
+
console.error(`Socket error for ${debug}, ${e.stack}`);
|
|
235
238
|
});
|
|
236
239
|
});
|
|
237
240
|
|