@lat-murmeldjur/weeb_3 0.0.332001 → 0.0.333001

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
@@ -2,7 +2,7 @@
2
2
  "name": "@lat-murmeldjur/weeb_3",
3
3
  "type": "module",
4
4
  "description": "A Swarm client for browsers",
5
- "version": "0.0.332001",
5
+ "version": "0.0.333001",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
package/service.js CHANGED
@@ -10,10 +10,11 @@ const RAW_ROUTE_KINDS = [
10
10
  ];
11
11
  const FETCH_TIMEOUT_MS = 240000;
12
12
  const SERVICE_WORKER_MARKER = "forwarder-default20";
13
- const SERVICE_WORKER_PROTOCOL = 5;
13
+ const SERVICE_WORKER_PROTOCOL = 7;
14
14
  const MIB_BYTES = 1024 * 1024;
15
15
  const STREAM_STORAGE_WINDOW_BYTES = MIB_BYTES / 2;
16
16
  const STREAM_LOOKAHEAD_CHUNKS = 8;
17
+ const HLS_STREAM_LOOKAHEAD_CHUNKS = 4;
17
18
  const HLS_REQUEST_FLIGHTS = new Map();
18
19
  const CLIENT_RUNTIME_PROBES = new Map();
19
20
  const CLIENT_RUNTIME_PROBE_TIMEOUT_MS = 1_500;
@@ -604,13 +605,14 @@ function responseHeaders(headerRows) {
604
605
  return headers;
605
606
  }
606
607
 
607
- function requestRustRange(clients, url, start, end, networkId) {
608
+ function requestRustRange(clients, url, start, end, networkId, streamToken = "") {
608
609
  return messageFirstClient(clients, {
609
610
  type: "WEEB3_FETCH_REQUEST",
610
611
  url,
611
612
  method: "GET",
612
613
  range: `bytes=${start}-${end}`,
613
- networkId
614
+ networkId,
615
+ streamToken
614
616
  }).then((response) => {
615
617
  if (!response || !response.ok) {
616
618
  return response || { ok: false, status: 503, error: "empty weeb-3 range response" };
@@ -630,22 +632,45 @@ function requestRustRange(clients, url, start, end, networkId) {
630
632
  });
631
633
  }
632
634
 
633
- function createRustRangeStream(clients, url, size, networkId, stagedStart) {
635
+ function createRustRangeStream(clients, url, size, networkId, stagedStart, streamToken = "") {
634
636
  let position = 0;
635
637
  let schedulePosition = 0;
636
- let stagedWindows = stagedStart ? 4 : 0;
638
+ const lookahead = stagedStart ? HLS_STREAM_LOOKAHEAD_CHUNKS : STREAM_LOOKAHEAD_CHUNKS;
639
+ let schedulingAdmissionOpen = true;
640
+ let lookaheadAdmitted = !stagedStart;
637
641
  const scheduled = new Map();
638
642
 
643
+ const admitNextRange = () => {
644
+ if (!schedulingAdmissionOpen || schedulePosition >= size) {
645
+ return null;
646
+ }
647
+
648
+ const start = schedulePosition;
649
+ const end = Math.min(start + STREAM_STORAGE_WINDOW_BYTES - 1, size - 1);
650
+ const request = requestRustRange(clients, url, start, end, networkId, streamToken);
651
+ scheduled.set(start, request);
652
+ schedulePosition = end + 1;
653
+ return { start, request };
654
+ };
655
+
639
656
  const scheduleMore = () => {
640
- const lookahead = stagedWindows > 0 ? 4 : STREAM_LOOKAHEAD_CHUNKS;
657
+ if (!schedulingAdmissionOpen || !lookaheadAdmitted) {
658
+ return;
659
+ }
641
660
  while (schedulePosition < size && scheduled.size < lookahead) {
642
- const start = schedulePosition;
643
- const end = Math.min(start + STREAM_STORAGE_WINDOW_BYTES - 1, size - 1);
644
- scheduled.set(start, requestRustRange(clients, url, start, end, networkId));
645
- schedulePosition = end + 1;
661
+ if (!admitNextRange()) {
662
+ break;
663
+ }
646
664
  }
647
665
  };
648
666
 
667
+ const drainScheduledRanges = () => {
668
+ const dispatched = Array.from(scheduled.values());
669
+ return Promise.allSettled(dispatched).then(() => {
670
+ scheduled.clear();
671
+ });
672
+ };
673
+
649
674
  return new ReadableStream({
650
675
  async pull(controller) {
651
676
  try {
@@ -654,16 +679,25 @@ function createRustRangeStream(clients, url, size, networkId, stagedStart) {
654
679
  return;
655
680
  }
656
681
 
657
- scheduleMore();
682
+ if (lookaheadAdmitted) {
683
+ scheduleMore();
684
+ }
658
685
  const start = Math.floor(position / STREAM_STORAGE_WINDOW_BYTES) * STREAM_STORAGE_WINDOW_BYTES;
659
- const request = scheduled.get(start);
686
+ let request = scheduled.get(start);
660
687
  if (!request) {
661
- controller.error(new Error("weeb-3 stream window was not scheduled"));
662
- return;
688
+ const foreground = admitNextRange();
689
+ if (!foreground || foreground.start !== start) {
690
+ controller.error(new Error("weeb-3 foreground stream window was not admitted"));
691
+ return;
692
+ }
693
+ request = foreground.request;
663
694
  }
664
695
 
665
696
  const response = await request;
666
697
  scheduled.delete(start);
698
+ if (!schedulingAdmissionOpen) {
699
+ return;
700
+ }
667
701
  if (!response || !response.ok) {
668
702
  controller.error(new Error(response && response.error ? response.error : "weeb-3 range request failed"));
669
703
  return;
@@ -672,14 +706,18 @@ function createRustRangeStream(clients, url, size, networkId, stagedStart) {
672
706
  const body = toUint8Array(response.body);
673
707
  position = start + body.byteLength;
674
708
  controller.enqueue(body);
675
- stagedWindows = Math.max(0, stagedWindows - 1);
709
+ lookaheadAdmitted = true;
676
710
  scheduleMore();
677
711
  } catch (error) {
678
- controller.error(error);
712
+ if (schedulingAdmissionOpen) {
713
+ controller.error(error);
714
+ }
679
715
  }
680
716
  },
681
717
  cancel() {
682
- scheduled.clear();
718
+ schedulingAdmissionOpen = false;
719
+ lookaheadAdmitted = false;
720
+ return drainScheduledRanges();
683
721
  }
684
722
  });
685
723
  }
@@ -715,7 +753,15 @@ async function forwardRequestToRust(request, event) {
715
753
  if (response.stream && request.method !== "HEAD") {
716
754
  const size = Number(headers.get("Content-Length") || "0");
717
755
  const stagedStart = headers.get("X-Weeb3-Stream-Start") === "1";
718
- return new Response(createRustRangeStream(clients, request.url, size, networkId, stagedStart), {
756
+ const streamToken = headers.get("X-Weeb3-Stream-Token") || "";
757
+ return new Response(createRustRangeStream(
758
+ clients,
759
+ request.url,
760
+ size,
761
+ networkId,
762
+ stagedStart,
763
+ streamToken
764
+ ), {
719
765
  status,
720
766
  headers
721
767
  });
package/weeb_3.d.ts CHANGED
@@ -84,11 +84,11 @@ export interface InitOutput {
84
84
  readonly __wbg_requestarguments_free: (a: number, b: number) => void;
85
85
  readonly requestarguments_method: (a: number, b: number) => void;
86
86
  readonly requestarguments_params: (a: number) => number;
87
- readonly __wasm_bindgen_func_elem_591: (a: number, b: number) => void;
88
- readonly __wasm_bindgen_func_elem_1589: (a: number, b: number, c: number, d: number) => void;
89
- readonly __wasm_bindgen_func_elem_1591: (a: number, b: number, c: number, d: number) => void;
90
- readonly __wasm_bindgen_func_elem_3752: (a: number, b: number, c: number) => void;
91
- readonly __wasm_bindgen_func_elem_3678: (a: number, b: number) => void;
87
+ readonly __wasm_bindgen_func_elem_628: (a: number, b: number) => void;
88
+ readonly __wasm_bindgen_func_elem_1685: (a: number, b: number, c: number, d: number) => void;
89
+ readonly __wasm_bindgen_func_elem_1687: (a: number, b: number, c: number, d: number) => void;
90
+ readonly __wasm_bindgen_func_elem_3888: (a: number, b: number, c: number) => void;
91
+ readonly __wasm_bindgen_func_elem_3814: (a: number, b: number) => void;
92
92
  readonly __wbindgen_export: (a: number, b: number) => number;
93
93
  readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
94
94
  readonly __wbindgen_export3: (a: number) => void;
package/weeb_3.js CHANGED
@@ -634,6 +634,10 @@ function __wbg_get_imports() {
634
634
  const ret = getObject(arg0).done;
635
635
  return ret;
636
636
  },
637
+ __wbg_duration_56d63063c1dcc6d7: function(arg0) {
638
+ const ret = getObject(arg0).duration;
639
+ return ret;
640
+ },
637
641
  __wbg_encodeURIComponent_46e9eafddd38cb39: function(arg0, arg1) {
638
642
  const ret = encodeURIComponent(getStringFromWasm0(arg0, arg1));
639
643
  return addHeapObject(ret);
@@ -1182,7 +1186,7 @@ function __wbg_get_imports() {
1182
1186
  const a = state0.a;
1183
1187
  state0.a = 0;
1184
1188
  try {
1185
- return __wasm_bindgen_func_elem_1589(a, state0.b, arg0, arg1);
1189
+ return __wasm_bindgen_func_elem_1685(a, state0.b, arg0, arg1);
1186
1190
  } finally {
1187
1191
  state0.a = a;
1188
1192
  }
@@ -1506,6 +1510,9 @@ function __wbg_get_imports() {
1506
1510
  __wbg_set_auto_increment_5ef604f4f193fa58: function(arg0, arg1) {
1507
1511
  getObject(arg0).autoIncrement = arg1 !== 0;
1508
1512
  },
1513
+ __wbg_set_autoplay_a63d23ab32fd1826: function(arg0, arg1) {
1514
+ getObject(arg0).autoplay = arg1 !== 0;
1515
+ },
1509
1516
  __wbg_set_binaryType_5bbf62e9f705dc1a: function(arg0, arg1) {
1510
1517
  getObject(arg0).binaryType = __wbindgen_enum_BinaryType[arg1];
1511
1518
  },
@@ -1593,6 +1600,9 @@ function __wbg_get_imports() {
1593
1600
  __wbg_set_onupgradeneeded_c887b74722b6ce77: function(arg0, arg1) {
1594
1601
  getObject(arg0).onupgradeneeded = getObject(arg1);
1595
1602
  },
1603
+ __wbg_set_preload_8046ead18b4d246a: function(arg0, arg1, arg2) {
1604
+ getObject(arg0).preload = getStringFromWasm0(arg1, arg2);
1605
+ },
1596
1606
  __wbg_set_scope_c18e6f8045aa3843: function(arg0, arg1, arg2) {
1597
1607
  getObject(arg0).scope = getStringFromWasm0(arg1, arg2);
1598
1608
  },
@@ -1762,38 +1772,38 @@ function __wbg_get_imports() {
1762
1772
  console.warn(getObject(arg0));
1763
1773
  },
1764
1774
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
1765
- // Cast intrinsic for `Closure(Closure { dtor_idx: 3, function: Function { arguments: [Externref, Externref], shim_idx: 21, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1766
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_591, __wasm_bindgen_func_elem_1589);
1775
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 3, function: Function { arguments: [Externref, Externref], shim_idx: 23, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1776
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_628, __wasm_bindgen_func_elem_1685);
1767
1777
  return addHeapObject(ret);
1768
1778
  },
1769
1779
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
1770
1780
  // Cast intrinsic for `Closure(Closure { dtor_idx: 3, function: Function { arguments: [Externref], shim_idx: 4, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1771
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_591, __wasm_bindgen_func_elem_3752);
1781
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_628, __wasm_bindgen_func_elem_3888);
1772
1782
  return addHeapObject(ret);
1773
1783
  },
1774
1784
  __wbindgen_cast_0000000000000003: function(arg0, arg1) {
1775
1785
  // Cast intrinsic for `Closure(Closure { dtor_idx: 3, function: Function { arguments: [NamedExternref("CloseEvent")], shim_idx: 4, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1776
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_591, __wasm_bindgen_func_elem_3752);
1786
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_628, __wasm_bindgen_func_elem_3888);
1777
1787
  return addHeapObject(ret);
1778
1788
  },
1779
1789
  __wbindgen_cast_0000000000000004: function(arg0, arg1) {
1780
1790
  // Cast intrinsic for `Closure(Closure { dtor_idx: 3, function: Function { arguments: [NamedExternref("Event")], shim_idx: 4, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1781
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_591, __wasm_bindgen_func_elem_3752);
1791
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_628, __wasm_bindgen_func_elem_3888);
1782
1792
  return addHeapObject(ret);
1783
1793
  },
1784
1794
  __wbindgen_cast_0000000000000005: function(arg0, arg1) {
1785
- // Cast intrinsic for `Closure(Closure { dtor_idx: 3, function: Function { arguments: [NamedExternref("IDBVersionChangeEvent")], shim_idx: 23, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1786
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_591, __wasm_bindgen_func_elem_1591);
1795
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 3, function: Function { arguments: [NamedExternref("IDBVersionChangeEvent")], shim_idx: 25, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1796
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_628, __wasm_bindgen_func_elem_1687);
1787
1797
  return addHeapObject(ret);
1788
1798
  },
1789
1799
  __wbindgen_cast_0000000000000006: function(arg0, arg1) {
1790
1800
  // Cast intrinsic for `Closure(Closure { dtor_idx: 3, function: Function { arguments: [NamedExternref("MessageEvent")], shim_idx: 4, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1791
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_591, __wasm_bindgen_func_elem_3752);
1801
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_628, __wasm_bindgen_func_elem_3888);
1792
1802
  return addHeapObject(ret);
1793
1803
  },
1794
1804
  __wbindgen_cast_0000000000000007: function(arg0, arg1) {
1795
1805
  // Cast intrinsic for `Closure(Closure { dtor_idx: 3, function: Function { arguments: [], shim_idx: 99, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1796
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_591, __wasm_bindgen_func_elem_3678);
1806
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_628, __wasm_bindgen_func_elem_3814);
1797
1807
  return addHeapObject(ret);
1798
1808
  },
1799
1809
  __wbindgen_cast_0000000000000008: function(arg0) {
@@ -1846,22 +1856,22 @@ function __wbg_get_imports() {
1846
1856
  };
1847
1857
  }
1848
1858
 
1849
- function __wasm_bindgen_func_elem_3678(arg0, arg1) {
1850
- wasm.__wasm_bindgen_func_elem_3678(arg0, arg1);
1859
+ function __wasm_bindgen_func_elem_3814(arg0, arg1) {
1860
+ wasm.__wasm_bindgen_func_elem_3814(arg0, arg1);
1851
1861
  }
1852
1862
 
1853
- function __wasm_bindgen_func_elem_3752(arg0, arg1, arg2) {
1854
- wasm.__wasm_bindgen_func_elem_3752(arg0, arg1, addHeapObject(arg2));
1863
+ function __wasm_bindgen_func_elem_3888(arg0, arg1, arg2) {
1864
+ wasm.__wasm_bindgen_func_elem_3888(arg0, arg1, addHeapObject(arg2));
1855
1865
  }
1856
1866
 
1857
- function __wasm_bindgen_func_elem_1589(arg0, arg1, arg2, arg3) {
1858
- wasm.__wasm_bindgen_func_elem_1589(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
1867
+ function __wasm_bindgen_func_elem_1685(arg0, arg1, arg2, arg3) {
1868
+ wasm.__wasm_bindgen_func_elem_1685(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
1859
1869
  }
1860
1870
 
1861
- function __wasm_bindgen_func_elem_1591(arg0, arg1, arg2) {
1871
+ function __wasm_bindgen_func_elem_1687(arg0, arg1, arg2) {
1862
1872
  try {
1863
1873
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1864
- wasm.__wasm_bindgen_func_elem_1591(retptr, arg0, arg1, addHeapObject(arg2));
1874
+ wasm.__wasm_bindgen_func_elem_1687(retptr, arg0, arg1, addHeapObject(arg2));
1865
1875
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1866
1876
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1867
1877
  if (r1) {
package/weeb_3_bg.wasm CHANGED
Binary file
@@ -32,11 +32,11 @@ export const weeb3no103_uploadWithRedundancy: (a: number, b: number, c: number,
32
32
  export const __wbg_requestarguments_free: (a: number, b: number) => void;
33
33
  export const requestarguments_method: (a: number, b: number) => void;
34
34
  export const requestarguments_params: (a: number) => number;
35
- export const __wasm_bindgen_func_elem_591: (a: number, b: number) => void;
36
- export const __wasm_bindgen_func_elem_1589: (a: number, b: number, c: number, d: number) => void;
37
- export const __wasm_bindgen_func_elem_1591: (a: number, b: number, c: number, d: number) => void;
38
- export const __wasm_bindgen_func_elem_3752: (a: number, b: number, c: number) => void;
39
- export const __wasm_bindgen_func_elem_3678: (a: number, b: number) => void;
35
+ export const __wasm_bindgen_func_elem_628: (a: number, b: number) => void;
36
+ export const __wasm_bindgen_func_elem_1685: (a: number, b: number, c: number, d: number) => void;
37
+ export const __wasm_bindgen_func_elem_1687: (a: number, b: number, c: number, d: number) => void;
38
+ export const __wasm_bindgen_func_elem_3888: (a: number, b: number, c: number) => void;
39
+ export const __wasm_bindgen_func_elem_3814: (a: number, b: number) => void;
40
40
  export const __wbindgen_export: (a: number, b: number) => number;
41
41
  export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
42
42
  export const __wbindgen_export3: (a: number) => void;