@decentnetwork/peer 0.1.98 → 0.1.99

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.
@@ -108,6 +108,8 @@ const LAN_SAMPLE_MAX_GAIN = 1.25;
108
108
  const LAN_STARTUP_MAX_GAIN = 1.15;
109
109
  const LAN_STARTUP_DELIVERY_GAIN = 1.5; // never probe above 1.5x recently delivered goodput
110
110
  const LAN_STARTUP_QUEUE_MS = 500; // unmistakable raw queue spike; smaller app-level RTT outliers are normal on Windows
111
+ const LAN_STARTUP_HARD_QUEUE_MS = 2000; // one multi-second queue sample is unsafe
112
+ const LAN_STARTUP_QUEUE_ROUNDS = 2; // tolerate one scheduler/session-handover outlier on LAN
111
113
  const LAN_STARTUP_KEEPUP = 0.70; // delivered goodput below 70% of pace means the receiver is no longer keeping up
112
114
  const LAN_STARTUP_SLOW_ROUNDS = 5; // require sustained saturation across Windows scheduler/ACK jitter
113
115
  // FILE ACKs are coalesced and handled by the remote JS event loop. On Windows
@@ -250,7 +252,7 @@ export class FileTransferManager {
250
252
  cwnd: CWND_INIT_CHUNKS, stalls: 0, parityHighBlock: -1, lastLossMs: 0, lossEwma: 0,
251
253
  minRttMs: Infinity, srttMs: 0, probeOffset: -1, probeSentMs: 0,
252
254
  paceRateBps: PACE_INIT_BPS, paceTokens: 0, lastPaceMs: nowMs(),
253
- btlBwBps: 0, bwSamples: [], fullBwRounds: 0, bbrPhase: 0, roundCount: 0,
255
+ btlBwBps: 0, bwSamples: [], fullBwRounds: 0, startupQueueRounds: 0, bbrPhase: 0, roundCount: 0,
254
256
  rateMarkMs: nowMs(), rateMarkAcked: 0, lowRttCount: 0, lowRttMinMs: Infinity, lastCcLogMs: 0,
255
257
  lanPath: this.isLanPath(friendId),
256
258
  };
@@ -787,6 +789,7 @@ export class FileTransferManager {
787
789
  // physical-LAN endpoint. Restart STARTUP from the measured rate.
788
790
  st.bbrPhase = 0;
789
791
  st.fullBwRounds = 0;
792
+ st.startupQueueRounds = 0;
790
793
  }
791
794
  st.lanPath = lanNow;
792
795
  if (!lanNow) {
@@ -817,7 +820,19 @@ export class FileTransferManager {
817
820
  st.fullBwRounds++;
818
821
  }
819
822
  const rawQueue = st.minRttMs !== Infinity ? acceptedRtt - st.minRttMs : 0;
820
- const startupOvershot = rawQueue > LAN_STARTUP_QUEUE_MS;
823
+ if (rawQueue > LAN_STARTUP_QUEUE_MS) {
824
+ st.startupQueueRounds++;
825
+ }
826
+ else {
827
+ st.startupQueueRounds = 0;
828
+ }
829
+ // File acceptance, an event-loop pause, or a relay-to-LAN
830
+ // handover can produce one 500-1000 ms ACK on Windows/macOS.
831
+ // One such sample is not evidence that a paced LAN is full.
832
+ // Require persistence, while retaining an immediate brake for
833
+ // a genuinely dangerous multi-second queue.
834
+ const startupOvershot = rawQueue > LAN_STARTUP_HARD_QUEUE_MS ||
835
+ st.startupQueueRounds >= LAN_STARTUP_QUEUE_ROUNDS;
821
836
  const startupUnderDelivering = st.fullBwRounds >= LAN_STARTUP_SLOW_ROUNDS;
822
837
  if (startupUnderDelivering || startupOvershot) {
823
838
  st.bbrPhase = 2;
@@ -828,6 +843,7 @@ export class FileTransferManager {
828
843
  // the sender continue flooding for ~2 s and collapse cwnd.
829
844
  st.bwSamples = measuredRate > 0 ? [measuredRate] : [];
830
845
  st.btlBwBps = measuredRate > 0 ? measuredRate : PACE_INIT_BPS;
846
+ st.startupQueueRounds = 0;
831
847
  st.paceRateBps = Math.max(PACE_INIT_BPS, Math.min(st.paceRateBps * 0.8, st.btlBwBps * 1.1));
832
848
  }
833
849
  else if (st.bbrPhase === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/peer",
3
- "version": "0.1.98",
3
+ "version": "0.1.99",
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",