fix(relay): keep bulk streaming from blocking client requests

Negotiate downstream delivery credit and schedule response streams fairly before encryption. Bound queued output, preserve deltas and WebSocket close ordering, and retain legacy peer compatibility.

Validated with 81 relay tests, workspace type-check and lint, web build and mobile assets, and slow-link tests through the production relay. Confirmed on LTE by the maintainer.
This commit is contained in:
Bohdan Triapitsyn
2026-09-09 17:41:14 +03:00
parent 4d8148587c
commit af84735388
13 changed files with 761 additions and 58 deletions
@@ -34,6 +34,7 @@ export const TunnelFrameType = {
WsClose: 10,
Ping: 11,
Pong: 12,
DeliveryAck: 13,
};
const TUNNEL_FRAME_TYPE_VALUES = new Set(Object.values(TunnelFrameType));
@@ -43,6 +44,14 @@ export const isTunnelFrameType = (value) => TUNNEL_FRAME_TYPE_VALUES.has(value);
const MAX_STREAM_ID = 0xffffffff;
/** Decode the client's cumulative raw tunnel-frame byte count. */
export const decodeDeliveryAck = (payload) => {
if (payload.length !== 8) throw new Error('invalid delivery acknowledgement');
const bytes = Number(new DataView(payload.buffer, payload.byteOffset, payload.byteLength).getBigUint64(0));
if (!Number.isSafeInteger(bytes)) throw new Error('invalid delivery acknowledgement');
return bytes;
};
export class TunnelCodecError extends Error {
constructor(message) {
super(message);