socket-function 0.9.3 → 0.9.5
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/.eslintrc.js +50 -50
- package/SocketFunction.ts +280 -280
- package/SocketFunctionTypes.ts +90 -90
- package/hot/HotReloadController.ts +105 -105
- package/mobx/UrlParam.ts +39 -39
- package/mobx/observer.tsx +49 -49
- package/mobx/promiseToObservable.tsx +41 -41
- package/package.json +1 -1
- package/require/CSSShim.ts +19 -19
- package/require/RequireController.ts +252 -252
- package/require/buffer.js +2368 -2368
- package/require/compileFlags.ts +44 -44
- package/require/require.html +13 -13
- package/require/require.js +464 -462
- package/spec.txt +115 -115
- package/src/CallFactory.ts +389 -389
- package/src/JSONLACKS/JSONLACKS.generated.js +17 -17
- package/src/JSONLACKS/JSONLACKS.pegjs +247 -247
- package/src/JSONLACKS/JSONLACKS.ts +441 -429
- package/src/args.ts +21 -21
- package/src/batching.ts +177 -170
- package/src/caching.ts +359 -318
- package/src/callHTTPHandler.ts +203 -203
- package/src/callManager.ts +134 -134
- package/src/certStore.ts +29 -29
- package/src/fixLargeNetworkCalls.ts +8 -8
- package/src/formatting/colors.ts +78 -78
- package/src/formatting/format.ts +160 -160
- package/src/formatting/logColors.ts +17 -17
- package/src/misc.ts +315 -302
- package/src/nodeCache.ts +92 -92
- package/src/nodeProxy.ts +54 -54
- package/src/profiling/getOwnTime.ts +107 -142
- package/src/profiling/measure.ts +289 -273
- package/src/profiling/stats.ts +212 -212
- package/src/profiling/tcpLagProxy.ts +63 -63
- package/src/storagePath.ts +10 -10
- package/src/tlsParsing.ts +96 -96
- package/src/types.ts +8 -8
- package/src/webSocketServer.ts +254 -250
- package/test/client.css +2 -2
- package/test/client.ts +46 -46
- package/test/server.ts +43 -43
- package/test/shared.ts +52 -52
- package/tsconfig.json +26 -26
package/src/webSocketServer.ts
CHANGED
|
@@ -1,251 +1,255 @@
|
|
|
1
|
-
import https from "https";
|
|
2
|
-
import http from "http";
|
|
3
|
-
import net from "net";
|
|
4
|
-
import tls from "tls";
|
|
5
|
-
import * as ws from "ws";
|
|
6
|
-
import { getNodeIdsFromRequest, httpCallHandler } from "./callHTTPHandler";
|
|
7
|
-
import { SocketFunction } from "../SocketFunction";
|
|
8
|
-
import { getTrustedCertificates, watchTrustedCertificates } from "./certStore";
|
|
9
|
-
import { createCallFactory } from "./CallFactory";
|
|
10
|
-
import { parseSNIExtension, parseTLSHello, SNIType } from "./tlsParsing";
|
|
11
|
-
import debugbreak from "debugbreak";
|
|
12
|
-
import { getNodeId } from "./nodeCache";
|
|
13
|
-
import crypto from "crypto";
|
|
14
|
-
import { Watchable } from "./misc";
|
|
15
|
-
import { delay, runInfinitePoll } from "./batching";
|
|
16
|
-
import { magenta } from "./formatting/logColors";
|
|
17
|
-
import { yellow } from "./formatting/logColors";
|
|
18
|
-
import { green } from "./formatting/logColors";
|
|
19
|
-
|
|
20
|
-
export type SocketServerConfig = (
|
|
21
|
-
https.ServerOptions & {
|
|
22
|
-
key: string | Buffer;
|
|
23
|
-
cert: string | Buffer;
|
|
24
|
-
|
|
25
|
-
port: number;
|
|
26
|
-
/** You can also set `port: 0` if you don't care what port you want at all. */
|
|
27
|
-
useAvailablePortIfPortInUse?: boolean;
|
|
28
|
-
|
|
29
|
-
// public sets ip to "0.0.0.0", otherwise it defaults to "127.0.0.1", which
|
|
30
|
-
// causes the server to only accept local connections.
|
|
31
|
-
public?: boolean;
|
|
32
|
-
ip?: string;
|
|
33
|
-
|
|
34
|
-
// NOTE: Any same origin accesses are allowed (header.origin === header.host)
|
|
35
|
-
// For example, to allow "letx.ca" to access the server (when the hosted domain
|
|
36
|
-
// may be, "querysub.com", for example), use ["letx.ca"]
|
|
37
|
-
allowHostnames?: string[];
|
|
38
|
-
|
|
39
|
-
/** If the SNI matches this domain, we use a different key/cert. */
|
|
40
|
-
SNICerts?: {
|
|
41
|
-
[domain: string]: Watchable<https.ServerOptions>;
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
export async function startSocketServer(
|
|
47
|
-
config: SocketServerConfig
|
|
48
|
-
): Promise<string> {
|
|
49
|
-
|
|
50
|
-
const webSocketServer = new ws.Server({
|
|
51
|
-
noServer: true,
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
async function setupHTTPSServer(watchOptions: Watchable<https.ServerOptions>) {
|
|
55
|
-
let httpsServerLast: https.Server | undefined;
|
|
56
|
-
let onHttpServer: (server: https.Server) => void;
|
|
57
|
-
let httpServerPromise = new Promise<https.Server>(r => onHttpServer = r);
|
|
58
|
-
let lastOptions!: https.ServerOptions;
|
|
59
|
-
await watchOptions(value => {
|
|
60
|
-
lastOptions = { ...value, ca: getTrustedCertificates() };
|
|
61
|
-
if (!httpsServerLast) {
|
|
62
|
-
httpsServerLast = https.createServer(lastOptions);
|
|
63
|
-
} else {
|
|
64
|
-
httpsServerLast.setSecureContext(lastOptions);
|
|
65
|
-
}
|
|
66
|
-
onHttpServer(httpsServerLast);
|
|
67
|
-
});
|
|
68
|
-
let httpsServer = await httpServerPromise;
|
|
69
|
-
|
|
70
|
-
let allowedHostnames = new Set<string>();
|
|
71
|
-
for (let hostname of config.allowHostnames || []) {
|
|
72
|
-
allowedHostnames.add(hostname);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
watchTrustedCertificates(() => {
|
|
76
|
-
lastOptions.ca = getTrustedCertificates();
|
|
77
|
-
httpsServer.setSecureContext(lastOptions);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
httpsServer.on("connection", socket => {
|
|
81
|
-
if (!SocketFunction.silent) {
|
|
82
|
-
console.log("Client connection established");
|
|
83
|
-
}
|
|
84
|
-
socket.on("error", e => {
|
|
85
|
-
if (!SocketFunction.silent) {
|
|
86
|
-
console.log(`Client socket error ${e.message}`);
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
socket.on("close", () => {
|
|
90
|
-
if (!SocketFunction.silent) {
|
|
91
|
-
console.log("Client socket closed");
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
httpsServer.on("error", e => {
|
|
96
|
-
console.error(`Connection attempt error ${e.message}`);
|
|
97
|
-
});
|
|
98
|
-
httpsServer.on("tlsClientError", e => {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
let
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
resolve(
|
|
221
|
-
})
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
1
|
+
import https from "https";
|
|
2
|
+
import http from "http";
|
|
3
|
+
import net from "net";
|
|
4
|
+
import tls from "tls";
|
|
5
|
+
import * as ws from "ws";
|
|
6
|
+
import { getNodeIdsFromRequest, httpCallHandler } from "./callHTTPHandler";
|
|
7
|
+
import { SocketFunction } from "../SocketFunction";
|
|
8
|
+
import { getTrustedCertificates, watchTrustedCertificates } from "./certStore";
|
|
9
|
+
import { createCallFactory } from "./CallFactory";
|
|
10
|
+
import { parseSNIExtension, parseTLSHello, SNIType } from "./tlsParsing";
|
|
11
|
+
import debugbreak from "debugbreak";
|
|
12
|
+
import { getNodeId } from "./nodeCache";
|
|
13
|
+
import crypto from "crypto";
|
|
14
|
+
import { Watchable } from "./misc";
|
|
15
|
+
import { delay, runInfinitePoll } from "./batching";
|
|
16
|
+
import { magenta } from "./formatting/logColors";
|
|
17
|
+
import { yellow } from "./formatting/logColors";
|
|
18
|
+
import { green } from "./formatting/logColors";
|
|
19
|
+
|
|
20
|
+
export type SocketServerConfig = (
|
|
21
|
+
https.ServerOptions & {
|
|
22
|
+
key: string | Buffer;
|
|
23
|
+
cert: string | Buffer;
|
|
24
|
+
|
|
25
|
+
port: number;
|
|
26
|
+
/** You can also set `port: 0` if you don't care what port you want at all. */
|
|
27
|
+
useAvailablePortIfPortInUse?: boolean;
|
|
28
|
+
|
|
29
|
+
// public sets ip to "0.0.0.0", otherwise it defaults to "127.0.0.1", which
|
|
30
|
+
// causes the server to only accept local connections.
|
|
31
|
+
public?: boolean;
|
|
32
|
+
ip?: string;
|
|
33
|
+
|
|
34
|
+
// NOTE: Any same origin accesses are allowed (header.origin === header.host)
|
|
35
|
+
// For example, to allow "letx.ca" to access the server (when the hosted domain
|
|
36
|
+
// may be, "querysub.com", for example), use ["letx.ca"]
|
|
37
|
+
allowHostnames?: string[];
|
|
38
|
+
|
|
39
|
+
/** If the SNI matches this domain, we use a different key/cert. */
|
|
40
|
+
SNICerts?: {
|
|
41
|
+
[domain: string]: Watchable<https.ServerOptions>;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
export async function startSocketServer(
|
|
47
|
+
config: SocketServerConfig
|
|
48
|
+
): Promise<string> {
|
|
49
|
+
|
|
50
|
+
const webSocketServer = new ws.Server({
|
|
51
|
+
noServer: true,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
async function setupHTTPSServer(watchOptions: Watchable<https.ServerOptions>) {
|
|
55
|
+
let httpsServerLast: https.Server | undefined;
|
|
56
|
+
let onHttpServer: (server: https.Server) => void;
|
|
57
|
+
let httpServerPromise = new Promise<https.Server>(r => onHttpServer = r);
|
|
58
|
+
let lastOptions!: https.ServerOptions;
|
|
59
|
+
await watchOptions(value => {
|
|
60
|
+
lastOptions = { ...value, ca: getTrustedCertificates() };
|
|
61
|
+
if (!httpsServerLast) {
|
|
62
|
+
httpsServerLast = https.createServer(lastOptions);
|
|
63
|
+
} else {
|
|
64
|
+
httpsServerLast.setSecureContext(lastOptions);
|
|
65
|
+
}
|
|
66
|
+
onHttpServer(httpsServerLast);
|
|
67
|
+
});
|
|
68
|
+
let httpsServer = await httpServerPromise;
|
|
69
|
+
|
|
70
|
+
let allowedHostnames = new Set<string>();
|
|
71
|
+
for (let hostname of config.allowHostnames || []) {
|
|
72
|
+
allowedHostnames.add(hostname);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
watchTrustedCertificates(() => {
|
|
76
|
+
lastOptions.ca = getTrustedCertificates();
|
|
77
|
+
httpsServer.setSecureContext(lastOptions);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
httpsServer.on("connection", socket => {
|
|
81
|
+
if (!SocketFunction.silent) {
|
|
82
|
+
console.log("Client connection established");
|
|
83
|
+
}
|
|
84
|
+
socket.on("error", e => {
|
|
85
|
+
if (!SocketFunction.silent) {
|
|
86
|
+
console.log(`Client socket error ${e.message}`);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
socket.on("close", () => {
|
|
90
|
+
if (!SocketFunction.silent) {
|
|
91
|
+
console.log("Client socket closed");
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
httpsServer.on("error", e => {
|
|
96
|
+
console.error(`Connection attempt error ${e.message}`);
|
|
97
|
+
});
|
|
98
|
+
httpsServer.on("tlsClientError", e => {
|
|
99
|
+
// NOTE: This happens a lot when we have tabs open that connected to an old
|
|
100
|
+
// server (with old certs, that the browser will reject?)
|
|
101
|
+
if (!SocketFunction.silent) {
|
|
102
|
+
console.error(`TLS client error ${e.message}`);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
httpsServer.on("request", httpCallHandler);
|
|
107
|
+
|
|
108
|
+
httpsServer.on("upgrade", (request, socket, upgradeHead) => {
|
|
109
|
+
socket.on("error", e => {
|
|
110
|
+
if (!SocketFunction.silent) {
|
|
111
|
+
console.log(`Client socket error ${e.message}`);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
let originHeader = request.headers["origin"];
|
|
116
|
+
if (originHeader) {
|
|
117
|
+
try {
|
|
118
|
+
let host = new URL("ws://" + request.headers["host"]).hostname;
|
|
119
|
+
let origin = new URL(originHeader).hostname;
|
|
120
|
+
if (host !== origin && !allowedHostnames.has(origin)) {
|
|
121
|
+
throw new Error(`Invalid cross domain request, ${JSON.stringify(host)} !== ${JSON.stringify(origin)} (also not config.allowedHostnames ${JSON.stringify(config.allowHostnames)})`);
|
|
122
|
+
}
|
|
123
|
+
} catch (e) {
|
|
124
|
+
console.error(e);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
webSocketServer.handleUpgrade(request, socket, upgradeHead, (ws) => {
|
|
129
|
+
const { nodeId, localNodeId } = getNodeIdsFromRequest(request);
|
|
130
|
+
createCallFactory(ws, nodeId, localNodeId).catch(e => {
|
|
131
|
+
console.error(`Error in creating call factory, ${e.stack}`);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
return httpsServer;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// TODO: Only allow unauthorized for ip certificates, and then for domains use the domain as the nodeId,
|
|
139
|
+
// so it is easy to read, and consistent.
|
|
140
|
+
let options: https.ServerOptions = {
|
|
141
|
+
...config,
|
|
142
|
+
};
|
|
143
|
+
if (!config.cert) {
|
|
144
|
+
throw new Error("No cert specified");
|
|
145
|
+
}
|
|
146
|
+
if (!config.key) {
|
|
147
|
+
throw new Error("No key specified");
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const mainHTTPSServer = await setupHTTPSServer(callback => callback(options));
|
|
151
|
+
let sniServers = new Map<string, https.Server>();
|
|
152
|
+
for (let [domain, obj] of Object.entries(config.SNICerts || {})) {
|
|
153
|
+
sniServers.set(domain, await setupHTTPSServer(obj));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
let httpServer = http.createServer({}, async function (req, res) {
|
|
157
|
+
let url = new URL("http://" + req.headers.host + req.url);
|
|
158
|
+
url.protocol = "https:";
|
|
159
|
+
//url.hostname = opts.hostname;
|
|
160
|
+
url.hostname = req.headers.host || "";
|
|
161
|
+
res.writeHead(301, { Location: url + "" });
|
|
162
|
+
res.end();
|
|
163
|
+
});
|
|
164
|
+
httpServer.on("error", e => {
|
|
165
|
+
console.error(`HTTP error ${e.stack}`);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
let realServer = net.createServer(socket => {
|
|
169
|
+
// NOTE: ONCE is used, so we only look at the first buffer, and then after that
|
|
170
|
+
// we pipe. This should be very efficient, as pipe has insane throughput
|
|
171
|
+
// (100s of MB/s, easily, even on a terrible machine).
|
|
172
|
+
socket.once("data", buffer => {
|
|
173
|
+
// All HTTPS requests start with 22, and no HTTP requests start with 22,
|
|
174
|
+
// so we just need to read the first byte.
|
|
175
|
+
|
|
176
|
+
let server: https.Server | http.Server;
|
|
177
|
+
if (buffer[0] !== 22) {
|
|
178
|
+
server = httpServer;
|
|
179
|
+
} else {
|
|
180
|
+
let data = parseTLSHello(buffer);
|
|
181
|
+
let sni = data.extensions.filter(x => x.type === SNIType).flatMap(x => parseSNIExtension(x.data))[0];
|
|
182
|
+
if (!SocketFunction.silent) {
|
|
183
|
+
console.log(`Received TCP connection with SNI ${JSON.stringify(sni)}`);
|
|
184
|
+
}
|
|
185
|
+
server = sniServers.get(sni) || mainHTTPSServer;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// NOTE: Messages aren't dequeued until the current handler finishes, so we don't need to pause the socket or anything.
|
|
189
|
+
server.emit("connection", socket);
|
|
190
|
+
socket.unshift(buffer);
|
|
191
|
+
});
|
|
192
|
+
socket.on("error", (e) => {
|
|
193
|
+
console.error(`Exposed socket error, ${e.stack}`);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
let listenPromise = new Promise<void>((resolve, error) => {
|
|
199
|
+
realServer.on("listening", () => {
|
|
200
|
+
resolve();
|
|
201
|
+
});
|
|
202
|
+
realServer.on("error", e => {
|
|
203
|
+
error(e);
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
let host = config.public ? "0.0.0.0" : "127.0.0.1";
|
|
208
|
+
if (config.ip) {
|
|
209
|
+
host = config.ip;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
let port = config.port;
|
|
213
|
+
if (config.useAvailablePortIfPortInUse && port) {
|
|
214
|
+
async function isPortInUse(port: number): Promise<boolean> {
|
|
215
|
+
return new Promise<boolean>((resolve, reject) => {
|
|
216
|
+
let server = net.createServer();
|
|
217
|
+
server.listen(port, host)
|
|
218
|
+
.on("listening", function () {
|
|
219
|
+
server.close();
|
|
220
|
+
resolve(false);
|
|
221
|
+
}).on("close", function () {
|
|
222
|
+
resolve(true);
|
|
223
|
+
}).on("error", function (e) {
|
|
224
|
+
resolve(true);
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
if (await isPortInUse(port)) {
|
|
229
|
+
port = 0;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (!SocketFunction.silent) {
|
|
234
|
+
console.log(yellow(`Trying to listening on ${host}:${port}`));
|
|
235
|
+
}
|
|
236
|
+
realServer.listen(port, host);
|
|
237
|
+
|
|
238
|
+
await listenPromise;
|
|
239
|
+
|
|
240
|
+
port = (realServer.address() as net.AddressInfo).port;
|
|
241
|
+
let nodeId = getNodeId(getCommonName(config.cert), port);
|
|
242
|
+
if (!SocketFunction.silent) {
|
|
243
|
+
console.log(green(`Started Listening on ${nodeId}`));
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return nodeId;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function getCommonName(cert: Buffer | string) {
|
|
250
|
+
let subject = new crypto.X509Certificate(cert).subject;
|
|
251
|
+
let subjectKVPs = new Map(subject.split(",").map(x => x.trim().split("=")).map(x => [x[0], x.slice(1).join("=")]));
|
|
252
|
+
let commonName = subjectKVPs.get("CN");
|
|
253
|
+
if (!commonName) throw new Error(`No common name in subject: ${subject}`);
|
|
254
|
+
return commonName;
|
|
251
255
|
}
|
package/test/client.css
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
body {
|
|
2
|
-
background: orange;
|
|
1
|
+
body {
|
|
2
|
+
background: orange;
|
|
3
3
|
}
|
package/test/client.ts
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
/// <reference path="../require/RequireController.ts" />
|
|
2
|
-
|
|
3
|
-
// https://letx.ca:2542/?classGuid=RequireController-e2f811f3-14b8-4759-b0d6-73f14516cf1d&functionName=requireHTML&args=[%22./test/test%22]
|
|
4
|
-
|
|
5
|
-
//import typescript from "typescript";
|
|
6
|
-
|
|
7
|
-
import debugbreak from "debugbreak";
|
|
8
|
-
import { setFlag } from "../require/compileFlags";
|
|
9
|
-
import { SocketFunction } from "../SocketFunction";
|
|
10
|
-
import { Test } from "./shared";
|
|
11
|
-
|
|
12
|
-
import "../require/CSSShim";
|
|
13
|
-
import "./client.css";
|
|
14
|
-
import { isNode } from "../src/misc";
|
|
15
|
-
import { getCallObj } from "../src/nodeProxy";
|
|
16
|
-
|
|
17
|
-
module.allowclient = true;
|
|
18
|
-
|
|
19
|
-
//console.log(typeof typescript);
|
|
20
|
-
|
|
21
|
-
//setFlag(require, "typescript", "allowclient", true);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
void main();
|
|
25
|
-
|
|
26
|
-
async function main() {
|
|
27
|
-
if (isNode()) return;
|
|
28
|
-
|
|
29
|
-
SocketFunction.expose(Test);
|
|
30
|
-
|
|
31
|
-
console.log("cool");
|
|
32
|
-
|
|
33
|
-
const port = 2542;
|
|
34
|
-
|
|
35
|
-
let serverId = await SocketFunction.connect({ port, address: "localhost" });
|
|
36
|
-
let test = await Test.nodes[serverId].add(1, 2);
|
|
37
|
-
console.log(`${test}=${1 + 2}`);
|
|
38
|
-
|
|
39
|
-
// while (true) {
|
|
40
|
-
// let test = await TestClass.nodes[serverId].add(1, 2);
|
|
41
|
-
// console.log(`${test}=${1 + 2}`);
|
|
42
|
-
// await new Promise(resolve => setTimeout(resolve, 1000));
|
|
43
|
-
// }
|
|
44
|
-
|
|
45
|
-
await Test.nodes[serverId].callMe();
|
|
46
|
-
}
|
|
1
|
+
/// <reference path="../require/RequireController.ts" />
|
|
2
|
+
|
|
3
|
+
// https://letx.ca:2542/?classGuid=RequireController-e2f811f3-14b8-4759-b0d6-73f14516cf1d&functionName=requireHTML&args=[%22./test/test%22]
|
|
4
|
+
|
|
5
|
+
//import typescript from "typescript";
|
|
6
|
+
|
|
7
|
+
import debugbreak from "debugbreak";
|
|
8
|
+
import { setFlag } from "../require/compileFlags";
|
|
9
|
+
import { SocketFunction } from "../SocketFunction";
|
|
10
|
+
import { Test } from "./shared";
|
|
11
|
+
|
|
12
|
+
import "../require/CSSShim";
|
|
13
|
+
import "./client.css";
|
|
14
|
+
import { isNode } from "../src/misc";
|
|
15
|
+
import { getCallObj } from "../src/nodeProxy";
|
|
16
|
+
|
|
17
|
+
module.allowclient = true;
|
|
18
|
+
|
|
19
|
+
//console.log(typeof typescript);
|
|
20
|
+
|
|
21
|
+
//setFlag(require, "typescript", "allowclient", true);
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
void main();
|
|
25
|
+
|
|
26
|
+
async function main() {
|
|
27
|
+
if (isNode()) return;
|
|
28
|
+
|
|
29
|
+
SocketFunction.expose(Test);
|
|
30
|
+
|
|
31
|
+
console.log("cool");
|
|
32
|
+
|
|
33
|
+
const port = 2542;
|
|
34
|
+
|
|
35
|
+
let serverId = await SocketFunction.connect({ port, address: "localhost" });
|
|
36
|
+
let test = await Test.nodes[serverId].add(1, 2);
|
|
37
|
+
console.log(`${test}=${1 + 2}`);
|
|
38
|
+
|
|
39
|
+
// while (true) {
|
|
40
|
+
// let test = await TestClass.nodes[serverId].add(1, 2);
|
|
41
|
+
// console.log(`${test}=${1 + 2}`);
|
|
42
|
+
// await new Promise(resolve => setTimeout(resolve, 1000));
|
|
43
|
+
// }
|
|
44
|
+
|
|
45
|
+
await Test.nodes[serverId].callMe();
|
|
46
|
+
}
|