@decentnetwork/peer 0.1.72 → 0.1.73

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.
@@ -62,10 +62,14 @@ const CWND_MIN_CHUNKS = 8; // ~11 KB floor — keeps a slow/flaky path's buffer
62
62
  // link keeps a big window (it drains quickly, so a big window adds little
63
63
  // delay); a thin flaky one keeps a small window (a big window there would add
64
64
  // seconds). Growing whenever the added delay is low means no self-limiting.
65
- const MAX_QUEUE_MS = 150; // ceiling on added latency when exceeded, drain
66
- const QUEUE_LOW_MS = 60; // below this there's spare capacity grow
67
- const VEGAS_GROW = 1.3; // window ×this per RTT when under-filled
68
- const VEGAS_SHRINK = 0.85; // window ×this per RTT when the queue is too deep
65
+ // The budget is generous on purpose: for a bulk transfer to a flaky peer,
66
+ // ~0.5s of added latency keeps ping well under a second (fine — the peer stays
67
+ // usable), and buys far more throughput on a jittery path than a tight 150ms
68
+ // bound, which collapsed the window to the floor (~17 KB/s observed on lili).
69
+ const MAX_QUEUE_MS = 350; // raw-queue ceiling before draining (bulk transfer tolerates ~0.35s added latency)
70
+ const QUEUE_LOW_MS = 150; // grow while the smoothed (jitter-free) queue is under this
71
+ const VEGAS_GROW = 1.25; // window ×this per RTT when under-filled
72
+ const VEGAS_SHRINK = 0.8; // window ×this per RTT when the queue is too deep
69
73
  const WATCHDOG_MS = 150; // stall poll cadence / base no-progress patience
70
74
  const WATCHDOG_MAX_MS = 8000; // cap the RTT-adaptive stall patience (must exceed a slow path's RTT so acks aren't mistaken for a stall)
71
75
  const FAST_RT_MIN_MS = 40; // min gap between fast-retransmits of the same hole (≈1 RTT)
@@ -194,7 +198,7 @@ export class FileTransferManager {
194
198
  acked: 0, nextSend: 0, pumping: false, started: false, req, startMs: nowMs(),
195
199
  lastProgressAcked: 0, lastAckAdvanceMs: nowMs(), lastResendMs: 0,
196
200
  cwnd: CWND_INIT_CHUNKS, stalls: 0,
197
- minRttMs: Infinity, srttMs: 0, probeOffset: -1, probeSentMs: 0,
201
+ minRttMs: Infinity, minSrttMs: Infinity, srttMs: 0, probeOffset: -1, probeSentMs: 0,
198
202
  };
199
203
  this.#map(this.#sending, friendId).set(fileNumber, st);
200
204
  void this.send(friendId, PACKET_ID_FILE_SENDREQUEST, req).catch(() => undefined);
@@ -498,15 +502,23 @@ export class FileTransferManager {
498
502
  st.srttMs = st.srttMs === 0 ? rtt : 0.85 * st.srttMs + 0.15 * rtt;
499
503
  if (rtt < st.minRttMs)
500
504
  st.minRttMs = rtt;
501
- // Added latency this transfer is putting on the path = how deep the
502
- // queue is. Steer the window to keep it under MAX_QUEUE_MS.
503
- const queueDelayMs = st.minRttMs !== Infinity ? rtt - st.minRttMs : 0;
504
- if (queueDelayMs < QUEUE_LOW_MS) {
505
- st.cwnd = Math.min(WINDOW_CHUNKS, Math.ceil(st.cwnd * VEGAS_GROW)); // spare capacity grow
505
+ if (st.srttMs < st.minSrttMs)
506
+ st.minSrttMs = st.srttMs;
507
+ // Hybrid signal, so per-packet JITTER doesn't masquerade as a queue:
508
+ // • GROW on the SMOOTHED queue (srtt minSrtt): jitter averages out,
509
+ // so a flaky path that isn't really queuing keeps growing instead
510
+ // of collapsing to the floor (~17 KB/s observed on lili).
511
+ // • SHRINK on the RAW queue (rtt − minRtt) against a higher ceiling:
512
+ // fast reaction to genuine bufferbloat, but the ceiling sits above
513
+ // the jitter band so a lone jittery sample doesn't trigger it.
514
+ const smoothQueue = st.minSrttMs !== Infinity ? st.srttMs - st.minSrttMs : 0;
515
+ const rawQueue = st.minRttMs !== Infinity ? rtt - st.minRttMs : 0;
516
+ if (rawQueue > MAX_QUEUE_MS) {
517
+ st.cwnd = Math.max(CWND_MIN_CHUNKS, Math.floor(st.cwnd * VEGAS_SHRINK)); // real queue too deep → drain
506
518
  }
507
- else if (queueDelayMs > MAX_QUEUE_MS) {
508
- st.cwnd = Math.max(CWND_MIN_CHUNKS, Math.floor(st.cwnd * VEGAS_SHRINK)); // queue too deep drain
509
- } // else hold: pipe full, queue shallow
519
+ else if (smoothQueue < QUEUE_LOW_MS) {
520
+ st.cwnd = Math.min(WINDOW_CHUNKS, Math.ceil(st.cwnd * VEGAS_GROW)); // spare capacitygrow
521
+ } // else hold
510
522
  }
511
523
  }
512
524
  if (st.acked - st.lastProgressAcked >= 256 * 1024 || st.acked >= st.size) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/peer",
3
- "version": "0.1.72",
3
+ "version": "0.1.73",
4
4
  "description": "Pure TypeScript port of Elastos Carrier (toxcore-derived) P2P messaging. DHT, onion routing, TCP relay, FlatBuffers app payloads, Express offline relay. Wire-compatible with iOS Beagle and the Carrier C SDK.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",