@decentnetwork/peer 0.1.87 → 0.1.88
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/dist/peer.js +15 -41
- package/package.json +1 -1
package/dist/peer.js
CHANGED
|
@@ -174,7 +174,7 @@ const AGENTNET_PROTO_VERSION = 1;
|
|
|
174
174
|
// Peer package version, advertised as the default appVersion when the embedder
|
|
175
175
|
// doesn't override it. Read lazily so a bundler that inlines this file doesn't
|
|
176
176
|
// need the package.json at runtime.
|
|
177
|
-
const PEER_PKG_VERSION = "0.1.
|
|
177
|
+
const PEER_PKG_VERSION = "0.1.88";
|
|
178
178
|
// Toxcore Messenger.h packet IDs (live inside encrypted 0x1b crypto data plain payload)
|
|
179
179
|
const PACKET_ID_PADDING = 0;
|
|
180
180
|
const PACKET_ID_REQUEST = 1; // request retransmission of unreceived packets
|
|
@@ -2057,50 +2057,24 @@ export class Peer {
|
|
|
2057
2057
|
// deliver immediately (a reorder buffer would only add latency and
|
|
2058
2058
|
// would wait forever for retransmits that arrive at fresh numbers);
|
|
2059
2059
|
// they still advance the ack point eagerly, exactly as before.
|
|
2060
|
-
// - Everything else is
|
|
2061
|
-
//
|
|
2062
|
-
//
|
|
2063
|
-
//
|
|
2064
|
-
//
|
|
2065
|
-
//
|
|
2066
|
-
//
|
|
2067
|
-
//
|
|
2060
|
+
// - Everything else is a reliable message (chat 64, bulkmsg, invites,
|
|
2061
|
+
// profile, control): deliver immediately and advance the ack point.
|
|
2062
|
+
//
|
|
2063
|
+
// NOTE: a strict in-order recv_array (buffer-ahead + retransmit-request)
|
|
2064
|
+
// was tried here to fix reordered multi-fragment inline files, but it
|
|
2065
|
+
// STALLED the whole reliable stream against native peers whose retransmit
|
|
2066
|
+
// didn't recover our gaps — breaking chat + files in BOTH directions
|
|
2067
|
+
// (the stalled ack point starved the peer's send window). Reverted to the
|
|
2068
|
+
// forgiving skip-the-gap behavior: a lost fragment corrupts one message
|
|
2069
|
+
// (rare) instead of wedging the session. Large files should use the
|
|
2070
|
+
// toxcore file-transfer channel (sendFile), which has its own reliability.
|
|
2068
2071
|
const consumesReliableNumber = kind !== PACKET_ID_REQUEST &&
|
|
2069
2072
|
kind < 192 &&
|
|
2070
2073
|
kind !== this.#opts.bulkDataPacketId;
|
|
2071
|
-
if (
|
|
2072
|
-
|
|
2073
|
-
state.receiveBufferStart = Math.max(state.receiveBufferStart ?? 0, (opened.packetNumber + 1) >>> 0);
|
|
2074
|
-
}
|
|
2075
|
-
this.#deliverLosslessPayload(friendId, state, kind, inner, remote);
|
|
2076
|
-
return;
|
|
2077
|
-
}
|
|
2078
|
-
const expected = state.receiveBufferStart ?? 0;
|
|
2079
|
-
const ahead = (opened.packetNumber - expected) >>> 0;
|
|
2080
|
-
if (ahead >= 0x80000000) {
|
|
2081
|
-
// Below the low-water mark — already delivered. Duplicate; drop.
|
|
2082
|
-
return;
|
|
2083
|
-
}
|
|
2084
|
-
if (ahead === 0) {
|
|
2085
|
-
// In order: deliver, advance, then drain any now-contiguous buffered.
|
|
2086
|
-
state.receiveBufferStart = (expected + 1) >>> 0;
|
|
2087
|
-
this.#deliverLosslessPayload(friendId, state, kind, inner, remote);
|
|
2088
|
-
this.#drainRecvBufferContiguous(friendId, state, remote);
|
|
2089
|
-
return;
|
|
2090
|
-
}
|
|
2091
|
-
// A gap sits below this packet. Hold it and drive recovery: ask the
|
|
2092
|
-
// sender to retransmit the missing number(s). If the buffer outgrows the
|
|
2093
|
-
// reorder window the gap is a genuine loss that won't come back — force
|
|
2094
|
-
// the stream forward rather than wedge every later packet forever.
|
|
2095
|
-
const buf = (state.recvBuffer ??= new Map());
|
|
2096
|
-
if (!buf.has(opened.packetNumber))
|
|
2097
|
-
buf.set(opened.packetNumber, { kind, inner });
|
|
2098
|
-
if (buf.size > RECV_REORDER_WINDOW) {
|
|
2099
|
-
this.#forceAdvanceRecvBuffer(friendId, state, remote);
|
|
2100
|
-
}
|
|
2101
|
-
else {
|
|
2102
|
-
this.#requestMissingReliablePackets(friendId, state);
|
|
2074
|
+
if (consumesReliableNumber) {
|
|
2075
|
+
state.receiveBufferStart = Math.max(state.receiveBufferStart ?? 0, (opened.packetNumber + 1) >>> 0);
|
|
2103
2076
|
}
|
|
2077
|
+
this.#deliverLosslessPayload(friendId, state, kind, inner, remote);
|
|
2104
2078
|
return;
|
|
2105
2079
|
}
|
|
2106
2080
|
// Reverted: we used to DELETE a "desynced" session here to force a clean
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decentnetwork/peer",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.88",
|
|
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",
|