@peerbit/shared-log 11.0.4-e280087 → 11.0.5-61266e7

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/src/ranges.ts CHANGED
@@ -1372,6 +1372,9 @@ export const calculateCoverage = async <R extends "u32" | "u64">(properties: {
1372
1372
  start?: NumberFromType<R>;
1373
1373
  /** Optional: end of the content range (exclusive) */
1374
1374
  end?: NumberFromType<R>;
1375
+
1376
+ /** Optional: role age limit in milliseconds */
1377
+ roleAge?: number;
1375
1378
  }): Promise<number> => {
1376
1379
  // Use the provided content range if given; otherwise use the default full range.
1377
1380
  const contentStart = properties.start ?? properties.numbers.zero;
@@ -1385,12 +1388,14 @@ export const calculateCoverage = async <R extends "u32" | "u64">(properties: {
1385
1388
  numbers: properties.numbers,
1386
1389
  start: contentStart,
1387
1390
  end: properties.numbers.maxValue,
1391
+ roleAge: properties.roleAge,
1388
1392
  });
1389
1393
  const coverage2 = await calculateCoverage({
1390
1394
  peers: properties.peers,
1391
1395
  numbers: properties.numbers,
1392
1396
  start: properties.numbers.zero,
1393
1397
  end: contentEnd,
1398
+ roleAge: properties.roleAge,
1394
1399
  });
1395
1400
 
1396
1401
  return Math.min(coverage1, coverage2);
@@ -1399,7 +1404,21 @@ export const calculateCoverage = async <R extends "u32" | "u64">(properties: {
1399
1404
  const endpoints: { point: NumberFromType<R>; delta: -1 | 1 }[] = [];
1400
1405
 
1401
1406
  // For each range, record its start and end as events.
1402
- for (const r of await properties.peers.iterate().all()) {
1407
+ const timeThresholdQuery =
1408
+ properties?.roleAge != null
1409
+ ? [
1410
+ new IntegerCompare({
1411
+ key: "timestamp",
1412
+ compare: Compare.LessOrEqual,
1413
+ value: BigInt(Date.now() - properties.roleAge),
1414
+ }),
1415
+ ]
1416
+ : undefined;
1417
+ for (const r of await properties.peers
1418
+ .iterate({
1419
+ query: timeThresholdQuery,
1420
+ })
1421
+ .all()) {
1403
1422
  endpoints.push({ point: r.value.start1, delta: +1 });
1404
1423
  endpoints.push({ point: r.value.end1, delta: -1 });
1405
1424
 
@@ -541,7 +541,7 @@ export class RatelessIBLTSynchronizer<D extends "u32" | "u64">
541
541
  if (outProcess === true) {
542
542
  return true;
543
543
  } else if (outProcess === undefined) {
544
- return false; // we don't have enough information, or received information that is redundant
544
+ return true; // we don't have enough information, or received information that is redundant
545
545
  }
546
546
 
547
547
  // we are not done