socket-function 0.8.36 → 0.8.38
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/SocketFunction.ts +65 -26
- package/SocketFunctionTypes.ts +14 -22
- package/package.json +4 -2
- package/require/require.js +8 -2
- package/src/CallFactory.ts +90 -19
- package/src/JSONLACKS/JSONLACKS.generated.js +2202 -0
- package/src/JSONLACKS/JSONLACKS.generated.js.d.ts +1 -0
- package/src/JSONLACKS/JSONLACKS.pegjs +248 -0
- package/src/JSONLACKS/JSONLACKS.ts +376 -0
- package/src/batching.ts +94 -0
- package/src/caching.ts +7 -1
- package/src/callManager.ts +14 -12
- package/src/certStore.ts +2 -0
- package/src/formatting/colors.ts +79 -0
- package/src/formatting/format.ts +157 -0
- package/src/formatting/logColors.ts +18 -0
- package/src/misc.ts +74 -2
- package/src/nodeCache.ts +10 -4
- package/src/profiling/getOwnTime.ts +143 -0
- package/src/profiling/measure.ts +241 -0
- package/src/profiling/stats.ts +213 -0
- package/src/profiling/tcpLagProxy.ts +64 -0
- package/src/types.ts +1 -1
- package/src/webSocketServer.ts +24 -11
- package/src/websocketFactory.ts +7 -2
package/src/webSocketServer.ts
CHANGED
|
@@ -64,12 +64,18 @@ export async function startSocketServer(
|
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
httpsServer.on("connection", socket => {
|
|
67
|
-
|
|
67
|
+
if (!SocketFunction.silent) {
|
|
68
|
+
console.log("Client connection established");
|
|
69
|
+
}
|
|
68
70
|
socket.on("error", e => {
|
|
69
|
-
|
|
71
|
+
if (!SocketFunction.silent) {
|
|
72
|
+
console.log(`Client socket error ${e.message}`);
|
|
73
|
+
}
|
|
70
74
|
});
|
|
71
75
|
socket.on("close", () => {
|
|
72
|
-
|
|
76
|
+
if (!SocketFunction.silent) {
|
|
77
|
+
console.log("Client socket closed");
|
|
78
|
+
}
|
|
73
79
|
});
|
|
74
80
|
});
|
|
75
81
|
httpsServer.on("error", e => {
|
|
@@ -83,7 +89,9 @@ export async function startSocketServer(
|
|
|
83
89
|
|
|
84
90
|
httpsServer.on("upgrade", (request, socket, upgradeHead) => {
|
|
85
91
|
socket.on("error", e => {
|
|
86
|
-
|
|
92
|
+
if (!SocketFunction.silent) {
|
|
93
|
+
console.log(`Client socket error ${e.message}`);
|
|
94
|
+
}
|
|
87
95
|
});
|
|
88
96
|
|
|
89
97
|
let originHeader = request.headers["origin"];
|
|
@@ -153,7 +161,9 @@ export async function startSocketServer(
|
|
|
153
161
|
} else {
|
|
154
162
|
let data = parseTLSHello(buffer);
|
|
155
163
|
let sni = data.extensions.filter(x => x.type === SNIType).flatMap(x => parseSNIExtension(x.data))[0];
|
|
156
|
-
|
|
164
|
+
if (!SocketFunction.silent) {
|
|
165
|
+
console.log(`Received TCP connection with SNI ${JSON.stringify(sni)}`);
|
|
166
|
+
}
|
|
157
167
|
server = sniServers.get(sni) || mainHTTPSServer;
|
|
158
168
|
}
|
|
159
169
|
|
|
@@ -176,10 +186,9 @@ export async function startSocketServer(
|
|
|
176
186
|
});
|
|
177
187
|
});
|
|
178
188
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
host = "0.0.0.0";
|
|
189
|
+
let host = config.public ? "0.0.0.0" : "127.0.0.1";
|
|
190
|
+
if (config.ip) {
|
|
191
|
+
host = config.ip;
|
|
183
192
|
}
|
|
184
193
|
|
|
185
194
|
let port = config.port;
|
|
@@ -203,14 +212,18 @@ export async function startSocketServer(
|
|
|
203
212
|
}
|
|
204
213
|
}
|
|
205
214
|
|
|
206
|
-
|
|
215
|
+
if (!SocketFunction.silent) {
|
|
216
|
+
console.log(`Trying to listening on ${host}:${port}`);
|
|
217
|
+
}
|
|
207
218
|
realServer.listen(port, host);
|
|
208
219
|
|
|
209
220
|
await listenPromise;
|
|
210
221
|
|
|
211
222
|
port = (realServer.address() as net.AddressInfo).port;
|
|
212
223
|
let nodeId = getNodeId(getCommonName(config.cert), port);
|
|
213
|
-
|
|
224
|
+
if (!SocketFunction.silent) {
|
|
225
|
+
console.log(`Started Listening on ${nodeId}`);
|
|
226
|
+
}
|
|
214
227
|
|
|
215
228
|
return nodeId;
|
|
216
229
|
}
|
package/src/websocketFactory.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { SenderInterface } from "./CallFactory";
|
|
|
5
5
|
import { getTrustedCertificates } from "./certStore";
|
|
6
6
|
import { getNodeIdLocation } from "./nodeCache";
|
|
7
7
|
import debugbreak from "debugbreak";
|
|
8
|
+
import { SocketFunction } from "../SocketFunction";
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
export function getTLSSocket(webSocket: ws.WebSocket) {
|
|
@@ -22,7 +23,9 @@ export function createWebsocketFactory(): (nodeId: string) => SenderInterface {
|
|
|
22
23
|
if (!location) throw new Error(`Cannot connect to ${nodeId}, no address known`);
|
|
23
24
|
let { address, port } = location;
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
if (!SocketFunction.silent) {
|
|
27
|
+
console.log(`Connecting to ${address}:${port}`);
|
|
28
|
+
}
|
|
26
29
|
return new WebSocket(`wss://${address}:${port}`);
|
|
27
30
|
};
|
|
28
31
|
} else {
|
|
@@ -31,7 +34,9 @@ export function createWebsocketFactory(): (nodeId: string) => SenderInterface {
|
|
|
31
34
|
if (!location) throw new Error(`Cannot connect to ${nodeId}, no address known`);
|
|
32
35
|
let { address, port } = location;
|
|
33
36
|
|
|
34
|
-
|
|
37
|
+
if (!SocketFunction.silent) {
|
|
38
|
+
console.log(`Connecting to ${address}:${port}`);
|
|
39
|
+
}
|
|
35
40
|
let webSocket = new ws.WebSocket(`wss://${address}:${port}`, {
|
|
36
41
|
ca: tls.rootCertificates.concat(getTrustedCertificates()),
|
|
37
42
|
});
|