wire-mesh 3.6.5 → 3.6.7

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/dist/server.cjs CHANGED
@@ -242,10 +242,12 @@ async function advanceCertificateSchedule(storage, now, options = {}) {
242
242
  const stillValid = (await readStored(storage)).filter((certificate) => certificate.notAfter.getTime() > now.getTime());
243
243
  const startedIndex = stillValid.findLastIndex((certificate) => certificate.notBefore.getTime() <= now.getTime());
244
244
  const certificates = startedIndex === -1 ? [await mintPinnedCertificate(now, lifetimeMs)] : stillValid.slice(startedIndex);
245
- while (certificates.length < 4) {
245
+ const missing = 4 - certificates.length;
246
+ if (missing > 0) {
246
247
  const last = certificates[certificates.length - 1];
247
248
  if (last === void 0) throw new Error("the certificate schedule is empty");
248
- certificates.push(await mintPinnedCertificate(new Date(last.notBefore.getTime() + servingMs), lifetimeMs));
249
+ const successors = await Promise.all(Array.from({ length: missing }, async (_, index) => mintPinnedCertificate(new Date(last.notBefore.getTime() + servingMs * (index + 1)), lifetimeMs)));
250
+ certificates.push(...successors);
249
251
  }
250
252
  await writeStored(storage, certificates);
251
253
  const [serving, next] = certificates;
@@ -327,7 +329,6 @@ function createWebTransportTransport(options = {}) {
327
329
  await started.ready;
328
330
  const bound = started.address();
329
331
  if (bound === null) throw new Error("the WebTransport server bound no address");
330
- port = bound.port;
331
332
  const liveSessions = /* @__PURE__ */ new Set();
332
333
  const drainState = { draining: false };
333
334
  const endSession = (session) => {
@@ -361,6 +362,7 @@ function createWebTransportTransport(options = {}) {
361
362
  })().catch(reportError);
362
363
  return {
363
364
  server: started,
365
+ port: bound.port,
364
366
  drain: async () => {
365
367
  drainState.draining = true;
366
368
  const open = [...liveSessions];
@@ -370,6 +372,7 @@ function createWebTransportTransport(options = {}) {
370
372
  };
371
373
  };
372
374
  let running = await startServer();
375
+ port = running.port;
373
376
  const advertise = () => reachableHosts(host).map((reachable) => (0, wire_mesh_core_domain_pinned_address.formatPinnedAddress)(`${reachable}:${String(port)}`, schedule.advertised.map((certificate) => certificate.sha256Hex)));
374
377
  /** Drains and stops the running server, if there is one: cleared first, so a rotation that failed after this point is retried by starting a server rather than by retiring one that is already gone. */
375
378
  const retire = async () => {
@@ -390,6 +393,7 @@ function createWebTransportTransport(options = {}) {
390
393
  await retire();
391
394
  if (closed) return;
392
395
  running = await startServer();
396
+ port = running.port;
393
397
  options.onCertificateRenewed?.(advertise());
394
398
  })().then(() => {
395
399
  if (!closed) armRotation(untilRotation());
package/dist/server.mjs CHANGED
@@ -241,10 +241,12 @@ async function advanceCertificateSchedule(storage, now, options = {}) {
241
241
  const stillValid = (await readStored(storage)).filter((certificate) => certificate.notAfter.getTime() > now.getTime());
242
242
  const startedIndex = stillValid.findLastIndex((certificate) => certificate.notBefore.getTime() <= now.getTime());
243
243
  const certificates = startedIndex === -1 ? [await mintPinnedCertificate(now, lifetimeMs)] : stillValid.slice(startedIndex);
244
- while (certificates.length < 4) {
244
+ const missing = 4 - certificates.length;
245
+ if (missing > 0) {
245
246
  const last = certificates[certificates.length - 1];
246
247
  if (last === void 0) throw new Error("the certificate schedule is empty");
247
- certificates.push(await mintPinnedCertificate(new Date(last.notBefore.getTime() + servingMs), lifetimeMs));
248
+ const successors = await Promise.all(Array.from({ length: missing }, async (_, index) => mintPinnedCertificate(new Date(last.notBefore.getTime() + servingMs * (index + 1)), lifetimeMs)));
249
+ certificates.push(...successors);
248
250
  }
249
251
  await writeStored(storage, certificates);
250
252
  const [serving, next] = certificates;
@@ -326,7 +328,6 @@ function createWebTransportTransport(options = {}) {
326
328
  await started.ready;
327
329
  const bound = started.address();
328
330
  if (bound === null) throw new Error("the WebTransport server bound no address");
329
- port = bound.port;
330
331
  const liveSessions = /* @__PURE__ */ new Set();
331
332
  const drainState = { draining: false };
332
333
  const endSession = (session) => {
@@ -360,6 +361,7 @@ function createWebTransportTransport(options = {}) {
360
361
  })().catch(reportError);
361
362
  return {
362
363
  server: started,
364
+ port: bound.port,
363
365
  drain: async () => {
364
366
  drainState.draining = true;
365
367
  const open = [...liveSessions];
@@ -369,6 +371,7 @@ function createWebTransportTransport(options = {}) {
369
371
  };
370
372
  };
371
373
  let running = await startServer();
374
+ port = running.port;
372
375
  const advertise = () => reachableHosts(host).map((reachable) => formatPinnedAddress(`${reachable}:${String(port)}`, schedule.advertised.map((certificate) => certificate.sha256Hex)));
373
376
  /** Drains and stops the running server, if there is one: cleared first, so a rotation that failed after this point is retried by starting a server rather than by retiring one that is already gone. */
374
377
  const retire = async () => {
@@ -389,6 +392,7 @@ function createWebTransportTransport(options = {}) {
389
392
  await retire();
390
393
  if (closed) return;
391
394
  running = await startServer();
395
+ port = running.port;
392
396
  options.onCertificateRenewed?.(advertise());
393
397
  })().then(() => {
394
398
  if (!closed) armRotation(untilRotation());