socket-function 0.53.0 → 0.55.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 -13
package/package.json
CHANGED
package/src/webSocketServer.ts
CHANGED
|
@@ -100,17 +100,18 @@ export async function startSocketServer(
|
|
|
100
100
|
});
|
|
101
101
|
|
|
102
102
|
httpsServer.on("connection", socket => {
|
|
103
|
+
let debug = (socket as any).remoteAddress + ":" + (socket as any).remotePort;
|
|
103
104
|
if (!SocketFunction.silent) {
|
|
104
|
-
console.log(
|
|
105
|
+
console.log(`HTTP server connection established ${debug}`);
|
|
105
106
|
}
|
|
106
107
|
socket.on("error", e => {
|
|
107
108
|
if (!SocketFunction.silent) {
|
|
108
|
-
console.log(`
|
|
109
|
+
console.log(`HTTP server socket error for ${debug}, ${e.message}`);
|
|
109
110
|
}
|
|
110
111
|
});
|
|
111
112
|
socket.on("close", () => {
|
|
112
113
|
if (!SocketFunction.silent) {
|
|
113
|
-
console.log(
|
|
114
|
+
console.log(`HTTP server socket closed for ${debug}`);
|
|
114
115
|
}
|
|
115
116
|
});
|
|
116
117
|
});
|
|
@@ -128,12 +129,6 @@ export async function startSocketServer(
|
|
|
128
129
|
httpsServer.on("request", httpCallHandler);
|
|
129
130
|
|
|
130
131
|
httpsServer.on("upgrade", (request, socket, upgradeHead) => {
|
|
131
|
-
socket.on("error", e => {
|
|
132
|
-
if (!SocketFunction.silent) {
|
|
133
|
-
console.log(`Client socket error ${e.message}`);
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
|
|
137
132
|
let originHeader = request.headers["origin"];
|
|
138
133
|
if (originHeader) {
|
|
139
134
|
try {
|
|
@@ -191,10 +186,10 @@ export async function startSocketServer(
|
|
|
191
186
|
|
|
192
187
|
let realServer = net.createServer(socket => {
|
|
193
188
|
//console.log("Received TCP connection from " + socket.remoteAddress);
|
|
194
|
-
const
|
|
189
|
+
const debug = socket.remoteAddress + ":" + socket.remotePort;
|
|
195
190
|
function handleTLSHello(buffer: Buffer, packetCount: number): void | "more" {
|
|
196
191
|
if (!SocketFunction.silent) {
|
|
197
|
-
console.log(`Received TCP header packet from ${
|
|
192
|
+
console.log(`Received TCP header packet from ${debug}, have ${buffer.length} bytes so far, ${packetCount} packets`);
|
|
198
193
|
}
|
|
199
194
|
// All HTTPS requests start with 22, and no HTTP requests start with 22,
|
|
200
195
|
// so we just need to read the first byte.
|
|
@@ -211,7 +206,7 @@ export async function startSocketServer(
|
|
|
211
206
|
console.log(`Received TCP connection with SNI ${JSON.stringify(sni)}`);
|
|
212
207
|
}
|
|
213
208
|
if (!sni) {
|
|
214
|
-
console.warn(`No SNI found in TLS hello from ${
|
|
209
|
+
console.warn(`No SNI found in TLS hello from ${debug}, using main server. Packets ${packetCount}`);
|
|
215
210
|
console.log(buffer.toString("base64"));
|
|
216
211
|
}
|
|
217
212
|
server = sniServers.get(sni) || mainHTTPSServer;
|
|
@@ -236,7 +231,7 @@ export async function startSocketServer(
|
|
|
236
231
|
}
|
|
237
232
|
getNextData();
|
|
238
233
|
socket.on("error", (e) => {
|
|
239
|
-
console.error(`Socket error for ${
|
|
234
|
+
console.error(`Socket error for ${debug}, ${e.stack}`);
|
|
240
235
|
});
|
|
241
236
|
});
|
|
242
237
|
|