socket-function 0.36.0 → 0.38.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "socket-function",
3
- "version": "0.36.0",
3
+ "version": "0.38.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "note1": "note on node-forge fork, see https://github.com/digitalbazaar/forge/issues/744 for details",
@@ -11,6 +11,9 @@ export async function forwardPort(config: {
11
11
  internalPort: number;
12
12
  duration?: number;
13
13
  }) {
14
+ // On linux, just return, the server probably doesn't require forwarding, and if it does,
15
+ // it probably this code probably won't work anyways.
16
+ if (os.platform() === "linux") return;
14
17
  try {
15
18
  const { externalPort, internalPort } = config;
16
19
  let duration = config.duration ?? timeInHour;
package/src/https.ts CHANGED
@@ -23,13 +23,15 @@ export function httpsRequest(
23
23
  if (urlObj.port) {
24
24
  port = +urlObj.port;
25
25
  }
26
-
27
26
  return new Promise<Buffer>((resolve, reject) => {
28
27
  let httpRequest = requestor.request(
29
28
  urlObj + "",
30
29
  {
31
30
  method,
32
31
  headers: config?.headers,
32
+ // NOTE: We get a lot of backblaze errors when we try to re-use connections. It might be faster,
33
+ // but... anything that cares about speed should use websockets anyways...
34
+ agent: new requestor.Agent({ keepAlive: false }),
33
35
  },
34
36
  async httpResponse => {
35
37
  let data: Buffer[] = [];
@@ -67,6 +67,9 @@ export async function startSocketServer(
67
67
  let httpServerPromise = new Promise<https.Server>(r => onHttpServer = r);
68
68
  let lastOptions!: https.ServerOptions;
69
69
  await watchOptions(value => {
70
+ // NOTE: If this is called a lot... STOP CALLING IT A LOT! Calling setSecureContext
71
+ // so frequently likely leaks memory!
72
+ console.log(`Updating websocket server options`);
70
73
  lastOptions = {
71
74
  ...value,
72
75
  ca: getTrustedCertificates(),
@@ -88,6 +91,9 @@ export async function startSocketServer(
88
91
  }
89
92
 
90
93
  watchTrustedCertificates(() => {
94
+ // NOTE: If this is called a lot... STOP CALLING IT A LOT! Calling setSecureContext
95
+ // so frequently likely leaks memory!
96
+ console.log(`Updating websocket server trusted certificates`);
91
97
  lastOptions.ca = getTrustedCertificates();
92
98
  httpsServer.setSecureContext(lastOptions);
93
99
  });
@@ -38,12 +38,6 @@ export function createWebsocketFactory(): (nodeId: string) => SenderInterface {
38
38
  }
39
39
  let webSocket = new ws.WebSocket(`wss://${address}:${port}`, undefined, {
40
40
  ca: getTrustedCertificates(),
41
- // createConnection(options, oncreate) {
42
- // // NOTE: If our latency is 500ms, with 10MB/s, then we need a high water
43
- // // mark of at least 5MB, otherwise our connection is slowed down.
44
- // //(options as any).writableHighWaterMark = 5 * 1024 * 1024;
45
- // return tls.connect(options as any, oncreate as any);
46
- // },
47
41
  });
48
42
 
49
43
  // NOTE: Little setup is done here, because Sometimes websockets are created here,