@lat-murmeldjur/weeb_3 0.0.350001 → 0.0.351001
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 +1 -1
- package/service.js +29 -114
- package/weeb_3.d.ts +45 -40
- package/weeb_3.js +605 -610
- package/weeb_3_bg.wasm +0 -0
- package/weeb_3_bg.wasm.d.ts +45 -40
package/package.json
CHANGED
package/service.js
CHANGED
|
@@ -19,13 +19,9 @@ const FETCH_TIMEOUT_MS = 240000;
|
|
|
19
19
|
const SERVICE_WORKER_MARKER = "forwarder-default29";
|
|
20
20
|
const SERVICE_WORKER_PROTOCOL = 10;
|
|
21
21
|
const MIB_BYTES = 1024 * 1024;
|
|
22
|
-
const
|
|
22
|
+
const STREAM_WINDOW_BYTES = MIB_BYTES / 2;
|
|
23
23
|
const STREAM_LOOKAHEAD_CHUNKS = 8;
|
|
24
|
-
const HLS_STREAM_WINDOW_BYTES = MIB_BYTES / 2;
|
|
25
|
-
const HLS_STREAM_INITIAL_LOOKAHEAD_CHUNKS = 1;
|
|
26
24
|
const HLS_STREAM_LOOKAHEAD_CHUNKS = 4;
|
|
27
|
-
const HLS_LIVE_STREAM_WINDOW_BYTES = MIB_BYTES / 2;
|
|
28
|
-
const HLS_LIVE_STREAM_LOOKAHEAD_CHUNKS = 4;
|
|
29
25
|
const RANGE_REQUEST_FLIGHTS = new Map();
|
|
30
26
|
const SHARED_WORKER_PROTOCOL = 5;
|
|
31
27
|
const WINDOW_RELAY_TIMEOUT_MS = 1_500;
|
|
@@ -269,27 +265,16 @@ self.addEventListener("fetch", (event) => {
|
|
|
269
265
|
}
|
|
270
266
|
|
|
271
267
|
const bzzResource = canonicalBzzResource(url);
|
|
272
|
-
if (
|
|
273
|
-
|
|
268
|
+
if (
|
|
269
|
+
(request.method === "GET" || request.method === "HEAD") &&
|
|
270
|
+
(bzzResource || canonicalRawResource(url) || canonicalFeedResource(url))
|
|
271
|
+
) {
|
|
272
|
+
if (bzzResource && isAppShellNavigation(request)) {
|
|
274
273
|
event.respondWith(fetchOrError(appShellRequest(request)));
|
|
275
274
|
} else {
|
|
276
275
|
event.respondWith(forwardRequestToRust(request, event.clientId, event.resultingClientId));
|
|
277
276
|
}
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
const rawResource = canonicalRawResource(url);
|
|
282
|
-
if (rawResource && (request.method === "GET" || request.method === "HEAD")) {
|
|
283
|
-
event.respondWith(forwardRequestToRust(request, event.clientId, event.resultingClientId));
|
|
284
|
-
return;
|
|
285
277
|
}
|
|
286
|
-
|
|
287
|
-
const feedResource = canonicalFeedResource(url);
|
|
288
|
-
if (feedResource && (request.method === "GET" || request.method === "HEAD")) {
|
|
289
|
-
event.respondWith(forwardRequestToRust(request, event.clientId, event.resultingClientId));
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
278
|
});
|
|
294
279
|
|
|
295
280
|
function isStableWindowClient(client) {
|
|
@@ -634,16 +619,6 @@ function responseBodyStream(body) {
|
|
|
634
619
|
});
|
|
635
620
|
}
|
|
636
621
|
|
|
637
|
-
function responseHeaders(headerRows) {
|
|
638
|
-
const headers = new Headers();
|
|
639
|
-
for (const row of headerRows || []) {
|
|
640
|
-
if (row && row.length >= 2) {
|
|
641
|
-
headers.set(String(row[0]), String(row[1]));
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
return headers;
|
|
645
|
-
}
|
|
646
|
-
|
|
647
622
|
function requestRustRange(client, url, start, end, networkId) {
|
|
648
623
|
const key = `${client?.id || ""}|${networkId}|${url}|${start}|${end}`;
|
|
649
624
|
const existing = RANGE_REQUEST_FLIGHTS.get(key);
|
|
@@ -675,11 +650,7 @@ function requestRustRange(client, url, start, end, networkId) {
|
|
|
675
650
|
return { ok: true, body };
|
|
676
651
|
});
|
|
677
652
|
RANGE_REQUEST_FLIGHTS.set(key, request);
|
|
678
|
-
request.finally(() => {
|
|
679
|
-
if (RANGE_REQUEST_FLIGHTS.get(key) === request) {
|
|
680
|
-
RANGE_REQUEST_FLIGHTS.delete(key);
|
|
681
|
-
}
|
|
682
|
-
}).catch(() => {});
|
|
653
|
+
request.finally(() => RANGE_REQUEST_FLIGHTS.delete(key)).catch(() => {});
|
|
683
654
|
return request;
|
|
684
655
|
}
|
|
685
656
|
|
|
@@ -689,7 +660,6 @@ function createRustRangeStream(
|
|
|
689
660
|
size,
|
|
690
661
|
networkId,
|
|
691
662
|
windowBytes,
|
|
692
|
-
initialLookahead,
|
|
693
663
|
lookahead
|
|
694
664
|
) {
|
|
695
665
|
let position = 0;
|
|
@@ -697,34 +667,12 @@ function createRustRangeStream(
|
|
|
697
667
|
let admissionOpen = true;
|
|
698
668
|
const scheduled = new Map();
|
|
699
669
|
|
|
700
|
-
const nextRangeBounds = () => {
|
|
701
|
-
if (!admissionOpen || schedulePosition >= size) {
|
|
702
|
-
return null;
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
const start = schedulePosition;
|
|
706
|
-
const end = Math.min(start + windowBytes - 1, size - 1);
|
|
707
|
-
schedulePosition = end + 1;
|
|
708
|
-
return { start, end };
|
|
709
|
-
};
|
|
710
|
-
|
|
711
|
-
const admitRange = () => {
|
|
712
|
-
const range = nextRangeBounds();
|
|
713
|
-
if (!range) {
|
|
714
|
-
return null;
|
|
715
|
-
}
|
|
716
|
-
const { start, end } = range;
|
|
717
|
-
const request = requestRustRange(client, url, start, end, networkId);
|
|
718
|
-
scheduled.set(start, request);
|
|
719
|
-
return { start, request };
|
|
720
|
-
};
|
|
721
|
-
|
|
722
670
|
const scheduleMore = () => {
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
671
|
+
while (admissionOpen && schedulePosition < size && scheduled.size < lookahead) {
|
|
672
|
+
const start = schedulePosition;
|
|
673
|
+
const end = Math.min(start + windowBytes - 1, size - 1);
|
|
674
|
+
schedulePosition = end + 1;
|
|
675
|
+
scheduled.set(start, requestRustRange(client, url, start, end, networkId));
|
|
728
676
|
}
|
|
729
677
|
};
|
|
730
678
|
|
|
@@ -734,15 +682,11 @@ function createRustRangeStream(
|
|
|
734
682
|
});
|
|
735
683
|
};
|
|
736
684
|
|
|
737
|
-
const closeAdmission = () => {
|
|
738
|
-
admissionOpen = false;
|
|
739
|
-
};
|
|
740
|
-
|
|
741
685
|
const failStream = async (controller, error) => {
|
|
742
686
|
if (!admissionOpen) {
|
|
743
687
|
return;
|
|
744
688
|
}
|
|
745
|
-
|
|
689
|
+
admissionOpen = false;
|
|
746
690
|
controller.error(error);
|
|
747
691
|
await drainScheduledRanges();
|
|
748
692
|
};
|
|
@@ -751,27 +695,15 @@ function createRustRangeStream(
|
|
|
751
695
|
async pull(controller) {
|
|
752
696
|
try {
|
|
753
697
|
if (position >= size) {
|
|
754
|
-
|
|
698
|
+
admissionOpen = false;
|
|
755
699
|
controller.close();
|
|
756
700
|
await drainScheduledRanges();
|
|
757
701
|
return;
|
|
758
702
|
}
|
|
759
703
|
|
|
760
704
|
scheduleMore();
|
|
761
|
-
const start =
|
|
762
|
-
|
|
763
|
-
if (!pending) {
|
|
764
|
-
const foreground = admitRange();
|
|
765
|
-
if (!foreground || foreground.start !== start) {
|
|
766
|
-
await failStream(
|
|
767
|
-
controller,
|
|
768
|
-
new Error("weeb-3 foreground stream window was not admitted")
|
|
769
|
-
);
|
|
770
|
-
return;
|
|
771
|
-
}
|
|
772
|
-
pending = foreground.request;
|
|
773
|
-
}
|
|
774
|
-
const response = await pending;
|
|
705
|
+
const start = position;
|
|
706
|
+
const response = await scheduled.get(start);
|
|
775
707
|
scheduled.delete(start);
|
|
776
708
|
|
|
777
709
|
if (!admissionOpen) {
|
|
@@ -785,7 +717,7 @@ function createRustRangeStream(
|
|
|
785
717
|
return;
|
|
786
718
|
}
|
|
787
719
|
|
|
788
|
-
const body =
|
|
720
|
+
const body = response.body;
|
|
789
721
|
position = start + body.byteLength;
|
|
790
722
|
controller.enqueue(body);
|
|
791
723
|
scheduleMore();
|
|
@@ -796,7 +728,7 @@ function createRustRangeStream(
|
|
|
796
728
|
}
|
|
797
729
|
},
|
|
798
730
|
cancel() {
|
|
799
|
-
|
|
731
|
+
admissionOpen = false;
|
|
800
732
|
return drainScheduledRanges();
|
|
801
733
|
}
|
|
802
734
|
});
|
|
@@ -822,7 +754,7 @@ async function forwardRequestToRust(request, clientId, resultingClientId) {
|
|
|
822
754
|
);
|
|
823
755
|
|
|
824
756
|
const status = Number(response.status || (response.ok ? 200 : 404));
|
|
825
|
-
const headers =
|
|
757
|
+
const headers = new Headers(response.headers);
|
|
826
758
|
|
|
827
759
|
if (!response.ok) {
|
|
828
760
|
return new Response(response.error || "weeb-3 request failed", {
|
|
@@ -831,44 +763,27 @@ async function forwardRequestToRust(request, clientId, resultingClientId) {
|
|
|
831
763
|
});
|
|
832
764
|
}
|
|
833
765
|
|
|
766
|
+
let body;
|
|
834
767
|
if (response.stream && request.method !== "HEAD") {
|
|
835
768
|
const size = Number(headers.get("Content-Length") || "0");
|
|
836
769
|
if (!Number.isSafeInteger(size) || size <= 0) {
|
|
837
770
|
return new Response("weeb-3 stream response has an invalid length", { status: 502 });
|
|
838
771
|
}
|
|
839
|
-
const
|
|
840
|
-
|
|
841
|
-
? HLS_LIVE_STREAM_WINDOW_BYTES
|
|
842
|
-
: hlsResource ? HLS_STREAM_WINDOW_BYTES : STREAM_STORAGE_WINDOW_BYTES;
|
|
843
|
-
const lookahead = liveHlsResource
|
|
844
|
-
? HLS_LIVE_STREAM_LOOKAHEAD_CHUNKS
|
|
845
|
-
: hlsResource ? HLS_STREAM_LOOKAHEAD_CHUNKS : STREAM_LOOKAHEAD_CHUNKS;
|
|
846
|
-
const initialLookahead = hlsResource
|
|
847
|
-
? HLS_STREAM_INITIAL_LOOKAHEAD_CHUNKS
|
|
848
|
-
: lookahead;
|
|
849
|
-
return new Response(createRustRangeStream(
|
|
772
|
+
const lookahead = hlsResource ? HLS_STREAM_LOOKAHEAD_CHUNKS : STREAM_LOOKAHEAD_CHUNKS;
|
|
773
|
+
body = createRustRangeStream(
|
|
850
774
|
client,
|
|
851
775
|
request.url,
|
|
852
776
|
size,
|
|
853
777
|
networkId,
|
|
854
|
-
|
|
855
|
-
initialLookahead,
|
|
778
|
+
STREAM_WINDOW_BYTES,
|
|
856
779
|
lookahead
|
|
857
|
-
)
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
});
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
return new Response(
|
|
864
|
-
request.method === "HEAD" || status === 304
|
|
780
|
+
);
|
|
781
|
+
} else {
|
|
782
|
+
body = request.method === "HEAD" || status === 304
|
|
865
783
|
? null
|
|
866
|
-
: responseBodyStream(response.body)
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
headers
|
|
870
|
-
}
|
|
871
|
-
);
|
|
784
|
+
: responseBodyStream(response.body);
|
|
785
|
+
}
|
|
786
|
+
return new Response(body, { status, headers });
|
|
872
787
|
} catch (error) {
|
|
873
788
|
return new Response(error && error.message ? error.message : "weeb-3 forwarder error", {
|
|
874
789
|
status: 502
|
package/weeb_3.d.ts
CHANGED
|
@@ -70,50 +70,55 @@ export interface InitOutput {
|
|
|
70
70
|
readonly memory: WebAssembly.Memory;
|
|
71
71
|
readonly __wbg_weeb3no103_free: (a: number, b: number) => void;
|
|
72
72
|
readonly __wbg_weeb3workerruntime_free: (a: number, b: number) => void;
|
|
73
|
-
readonly interweeb: (a: number, b: number) =>
|
|
74
|
-
readonly weeb3no103_acquireFeedBytes: (a: number, b: number, c: number, d: number, e: number) =>
|
|
75
|
-
readonly weeb3no103_attachStream: (a: number, b:
|
|
76
|
-
readonly weeb3no103_batchState: (a: number, b: number, c: number) =>
|
|
77
|
-
readonly weeb3no103_buyBatch: (a: number, b: number, c: number) =>
|
|
78
|
-
readonly weeb3no103_deployChequebook: (a: number) =>
|
|
79
|
-
readonly weeb3no103_depositChequebook: (a: number, b: number, c: number) =>
|
|
80
|
-
readonly weeb3no103_logs: (a: number) =>
|
|
81
|
-
readonly weeb3no103_networkState: (a: number) =>
|
|
73
|
+
readonly interweeb: (a: number, b: number) => any;
|
|
74
|
+
readonly weeb3no103_acquireFeedBytes: (a: number, b: number, c: number, d: number, e: number) => any;
|
|
75
|
+
readonly weeb3no103_attachStream: (a: number, b: any, c: number, d: number, e: number, f: number, g: number, h: number) => any;
|
|
76
|
+
readonly weeb3no103_batchState: (a: number, b: number, c: number) => any;
|
|
77
|
+
readonly weeb3no103_buyBatch: (a: number, b: number, c: number) => any;
|
|
78
|
+
readonly weeb3no103_deployChequebook: (a: number) => any;
|
|
79
|
+
readonly weeb3no103_depositChequebook: (a: number, b: number, c: number) => any;
|
|
80
|
+
readonly weeb3no103_logs: (a: number) => any;
|
|
81
|
+
readonly weeb3no103_networkState: (a: number) => any;
|
|
82
82
|
readonly weeb3no103_new: (a: number, b: number) => number;
|
|
83
|
-
readonly weeb3no103_openSecureVault: (a: number) =>
|
|
84
|
-
readonly weeb3no103_postFeedBytes: (a: number, b: number, c: number, d:
|
|
85
|
-
readonly weeb3no103_postPushChunk: (a: number, b:
|
|
86
|
-
readonly weeb3no103_postUploadBytes: (a: number, b:
|
|
87
|
-
readonly weeb3no103_postUploadBytesWithRedundancy: (a: number, b:
|
|
88
|
-
readonly weeb3no103_progressSnapshot: (a: number, b: number) =>
|
|
89
|
-
readonly weeb3no103_ready: (a: number, b: number, c: number) =>
|
|
90
|
-
readonly weeb3no103_renderInterface: (a: number, b:
|
|
91
|
-
readonly weeb3no103_resetStamp: (a: number) =>
|
|
92
|
-
readonly weeb3no103_retrieve: (a: number, b: number, c: number) =>
|
|
93
|
-
readonly weeb3no103_retrieveBytes: (a: number, b: number, c: number) =>
|
|
94
|
-
readonly weeb3no103_retrieveChunk: (a: number, b: number, c: number) =>
|
|
83
|
+
readonly weeb3no103_openSecureVault: (a: number) => any;
|
|
84
|
+
readonly weeb3no103_postFeedBytes: (a: number, b: number, c: number, d: any, e: number, f: number, g: number, h: number, i: number, j: number, k: number) => any;
|
|
85
|
+
readonly weeb3no103_postPushChunk: (a: number, b: any, c: number, d: any, e: any) => any;
|
|
86
|
+
readonly weeb3no103_postUploadBytes: (a: number, b: any, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => any;
|
|
87
|
+
readonly weeb3no103_postUploadBytesWithRedundancy: (a: number, b: any, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number) => any;
|
|
88
|
+
readonly weeb3no103_progressSnapshot: (a: number, b: number) => any;
|
|
89
|
+
readonly weeb3no103_ready: (a: number, b: number, c: number) => any;
|
|
90
|
+
readonly weeb3no103_renderInterface: (a: number, b: any) => any;
|
|
91
|
+
readonly weeb3no103_resetStamp: (a: number) => any;
|
|
92
|
+
readonly weeb3no103_retrieve: (a: number, b: number, c: number) => any;
|
|
93
|
+
readonly weeb3no103_retrieveBytes: (a: number, b: number, c: number) => any;
|
|
94
|
+
readonly weeb3no103_retrieveChunk: (a: number, b: number, c: number) => any;
|
|
95
95
|
readonly weeb3no103_start: (a: number, b: number) => void;
|
|
96
|
-
readonly weeb3no103_switchNetwork: (a: number, b: number, c: number) =>
|
|
97
|
-
readonly weeb3no103_upload: (a: number, b:
|
|
98
|
-
readonly weeb3no103_uploadWithRedundancy: (a: number, b:
|
|
99
|
-
readonly weeb3workerruntime_handleMessage: (a: number, b:
|
|
96
|
+
readonly weeb3no103_switchNetwork: (a: number, b: number, c: number) => any;
|
|
97
|
+
readonly weeb3no103_upload: (a: number, b: any, c: number, d: number, e: number, f: number, g: number, h: number) => any;
|
|
98
|
+
readonly weeb3no103_uploadWithRedundancy: (a: number, b: any, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number) => any;
|
|
99
|
+
readonly weeb3workerruntime_handleMessage: (a: number, b: any) => any;
|
|
100
100
|
readonly weeb3workerruntime_new: () => number;
|
|
101
|
-
readonly weeb3workerruntime_start: (a: number, b:
|
|
101
|
+
readonly weeb3workerruntime_start: (a: number, b: any) => any;
|
|
102
102
|
readonly __wbg_requestarguments_free: (a: number, b: number) => void;
|
|
103
|
-
readonly requestarguments_method: (a: number
|
|
104
|
-
readonly requestarguments_params: (a: number) =>
|
|
105
|
-
readonly
|
|
106
|
-
readonly
|
|
107
|
-
readonly
|
|
108
|
-
readonly
|
|
109
|
-
readonly
|
|
110
|
-
readonly
|
|
111
|
-
readonly
|
|
112
|
-
readonly
|
|
113
|
-
readonly
|
|
114
|
-
readonly
|
|
115
|
-
readonly
|
|
116
|
-
readonly
|
|
103
|
+
readonly requestarguments_method: (a: number) => [number, number];
|
|
104
|
+
readonly requestarguments_params: (a: number) => any;
|
|
105
|
+
readonly wasm_bindgen_2fc1ddd1063c2c6b___closure__destroy___dyn_core_ed718c3d60ebd546___ops__function__FnMut_____Output_______: (a: number, b: number) => void;
|
|
106
|
+
readonly wasm_bindgen_2fc1ddd1063c2c6b___closure__destroy___dyn_core_ed718c3d60ebd546___ops__function__Fn__wasm_bindgen_2fc1ddd1063c2c6b___JsValue__wasm_bindgen_2fc1ddd1063c2c6b___JsValue___Output_______: (a: number, b: number) => void;
|
|
107
|
+
readonly wasm_bindgen_2fc1ddd1063c2c6b___closure__destroy___dyn_core_ed718c3d60ebd546___ops__function__FnMut__wasm_bindgen_2fc1ddd1063c2c6b___JsValue____Output_______: (a: number, b: number) => void;
|
|
108
|
+
readonly wasm_bindgen_2fc1ddd1063c2c6b___convert__closures_____invoke___wasm_bindgen_2fc1ddd1063c2c6b___JsValue__alloc_508e33bd5656020b___string__String__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_2fc1ddd1063c2c6b___JsValue__: (a: number, b: number, c: any, d: number, e: number) => [number, number];
|
|
109
|
+
readonly wasm_bindgen_2fc1ddd1063c2c6b___convert__closures_____invoke___wasm_bindgen_2fc1ddd1063c2c6b___JsValue__wasm_bindgen_2fc1ddd1063c2c6b___JsValue_____: (a: number, b: number, c: any, d: any) => void;
|
|
110
|
+
readonly wasm_bindgen_2fc1ddd1063c2c6b___convert__closures_____invoke___web_sys_2f642151e65e7b7b___features__gen_IdbVersionChangeEvent__IdbVersionChangeEvent__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_2fc1ddd1063c2c6b___JsValue__: (a: number, b: number, c: any) => [number, number];
|
|
111
|
+
readonly wasm_bindgen_2fc1ddd1063c2c6b___convert__closures_____invoke___wasm_bindgen_2fc1ddd1063c2c6b___JsValue__wasm_bindgen_2fc1ddd1063c2c6b___JsValue______1_: (a: number, b: number, c: any, d: any) => void;
|
|
112
|
+
readonly wasm_bindgen_2fc1ddd1063c2c6b___convert__closures_____invoke___wasm_bindgen_2fc1ddd1063c2c6b___JsValue_____: (a: number, b: number, c: any) => void;
|
|
113
|
+
readonly wasm_bindgen_2fc1ddd1063c2c6b___convert__closures_____invoke______: (a: number, b: number) => void;
|
|
114
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
115
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
116
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
117
|
+
readonly __externref_table_alloc: () => number;
|
|
118
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
119
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
120
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
121
|
+
readonly __wbindgen_start: () => void;
|
|
117
122
|
}
|
|
118
123
|
|
|
119
124
|
export type SyncInitInput = BufferSource | WebAssembly.Module;
|