socket-function 0.74.0 → 0.76.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/SocketFunction.ts CHANGED
@@ -419,8 +419,9 @@ export class SocketFunction {
419
419
  if (isNode()) {
420
420
  throw new Error("Cannot get browser nodeId on server");
421
421
  }
422
- if (globalThis.BOOTED_EDGE_NODE) {
423
- return globalThis.BOOTED_EDGE_NODE.host;
422
+ let edgeNode = getBootedEdgeNode();
423
+ if (edgeNode) {
424
+ return edgeNode.host;
424
425
  }
425
426
  return SocketFunction.connect({ address: location.hostname, port: +location.port || 443 });
426
427
  }
@@ -433,14 +434,9 @@ export class SocketFunction {
433
434
  }
434
435
  }
435
436
 
436
-
437
- declare global {
438
- var BOOTED_EDGE_NODE: EdgeNodeConfig | undefined;
437
+ function getBootedEdgeNode() {
438
+ return (globalThis as any).BOOTED_EDGE_NODE as { host: string } | undefined;
439
439
  }
440
- type EdgeNodeConfig = {
441
- // EX: 127-0-0-1.example.com:3334
442
- host: string;
443
- };
444
440
 
445
441
 
446
442
  let socketContextSeqNum = 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "socket-function",
3
- "version": "0.74.0",
3
+ "version": "0.76.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
@@ -148,7 +148,7 @@ export const runClientHooks = measureWrap(async function runClientHooks(
148
148
  let time = Date.now();
149
149
  await hook(context);
150
150
  time = Date.now() - time;
151
- if (time > 100) {
151
+ if (time > 500) {
152
152
  console.warn(`Slow (${formatTime(time)}) client hook: ${JSON.stringify(hook.name || hook.toString().slice(0, 100))} for ${callType.classGuid}.${callType.functionName}(...)`);
153
153
  }
154
154
  // NOTE: See ClientHookContext.overrideResult for why we break here
@@ -170,7 +170,7 @@ export const runServerHooks = measureWrap(async function runServerHooks(
170
170
  let time = Date.now();
171
171
  await _setSocketContext(caller, () => hook(hookContext));
172
172
  time = Date.now() - time;
173
- if (time > 100) {
173
+ if (time > 500) {
174
174
  console.warn(`Slow (${formatTime(time)}) server hook: ${JSON.stringify(hook.name || hook.toString().slice(0, 100))} for ${callType.classGuid}.${callType.functionName}(...)`);
175
175
  }
176
176
  // NOTE: See HookContext.overrideResult for why we don't break here
@@ -46,7 +46,9 @@ export type SocketServerConfig = (
46
46
  // may be, "querysub.com", for example), use ["letx.ca"]
47
47
  allowHostnames?: string[];
48
48
 
49
- /** If the SNI matches this domain, we use a different key/cert. */
49
+ /** If the SNI matches this domain, we use a different key/cert.
50
+ * We remove subdomains until we find a match
51
+ */
50
52
  SNICerts?: {
51
53
  [domain: string]: Watchable<https.ServerOptions>;
52
54
  };
@@ -208,20 +210,22 @@ export async function startSocketServer(
208
210
  }
209
211
  let sni = data.extensions.filter(x => x.type === SNIType).flatMap(x => parseSNIExtension(x.data))[0];
210
212
  if (!SocketFunction.silent) {
211
- console.log(`Received TCP connection with SNI ${JSON.stringify(sni)}`);
213
+ console.log(`Received TCP connection with SNI ${JSON.stringify(sni)}. Have handlers for: ${Array.from(sniServers.keys()).join(", ")}`);
212
214
  }
213
215
  if (!sni) {
214
216
  console.warn(`No SNI found in TLS hello from ${debug}, using main server. Packets ${packetCount}`);
215
217
  console.log(buffer.toString("base64"));
216
218
  }
219
+ let originalSNI = sni;
220
+ // Remove subdomains until we can find a domain
221
+ while (!sniServers.has(sni)) {
222
+ let parts = sni.split(".");
223
+ if (parts.length <= 2) break;
224
+ sni = parts.slice(1).join(".");
225
+ }
217
226
 
218
227
  if (!sniServers.has(sni)) {
219
- if (sni) {
220
- sni = sni.split(".").slice(-2).join(".");
221
- }
222
- if (!sniServers.has(sni)) {
223
- console.warn(`No SNI server found for ${sni}, using main server.`);
224
- }
228
+ console.warn(`No SNI server found for ${originalSNI}, using main server. SNI candidates ${Array.from(sniServers.keys()).join(", ")}`);
225
229
  }
226
230
  server = sniServers.get(sni) || mainHTTPSServer;
227
231
  }