@decentnetwork/peer 0.1.35 → 0.1.37
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 +26 -1
- package/package.json +1 -1
package/dist/peer.js
CHANGED
|
@@ -71,6 +71,15 @@ const FRIEND_PING_INTERVAL_MS = readEnvInt("DECENT_FRIEND_PING_INTERVAL_MS", 400
|
|
|
71
71
|
// slow enough not to burn CPU on idle peers. Tunable via env.
|
|
72
72
|
const FRIEND_CONNECTION_LOOP_MS = readEnvInt("DECENT_FRIEND_CONNECTION_LOOP_MS", 250);
|
|
73
73
|
const FRIEND_TIMEOUT_MS = readEnvInt("DECENT_FRIEND_TIMEOUT_MS", 32000);
|
|
74
|
+
// How long a relay path stays "confirmed" (carrying bulk data on its own, no
|
|
75
|
+
// tcp-relay fan-out) after the last packet received over it. The relay
|
|
76
|
+
// keepalive refreshes this every ~4s on a healthy path, so a generous window
|
|
77
|
+
// tolerates several missed keepalives on a high-RTT / lossy China<->abroad link
|
|
78
|
+
// instead of flapping back to fan-out — which delivered every IP packet twice
|
|
79
|
+
// (the lili DUP! storm). Still well under FRIEND_TIMEOUT_MS, so a relay that
|
|
80
|
+
// genuinely dies fails over (control packets always fan out, and the session
|
|
81
|
+
// times out + re-handshakes) within the friend-timeout regardless.
|
|
82
|
+
const RELAY_CONFIRM_WINDOW_MS = readEnvInt("DECENT_RELAY_CONFIRM_WINDOW_MS", 20000);
|
|
74
83
|
const LAN_DISCOVERY_INTERVAL_MS = readEnvInt("DECENT_LAN_DISCOVERY_INTERVAL_MS", 10000);
|
|
75
84
|
// When a same-LAN friend's actual address is unknown (it's not in their
|
|
76
85
|
// DHT-PK extras and their NAT-mapped public IP doesn't accept our UDP),
|
|
@@ -332,6 +341,14 @@ export class Peer {
|
|
|
332
341
|
session.friendRealPublicKey ??= new Uint8Array(friendKey);
|
|
333
342
|
this.#friendSessions.set(friendId, session);
|
|
334
343
|
if (!session.established) {
|
|
344
|
+
// A fresh relay-online signal means the peer just (re)connected —
|
|
345
|
+
// almost always a restart. Clear any accumulated cookie backoff so
|
|
346
|
+
// the connection loop retries the handshake at the 8s base cadence
|
|
347
|
+
// instead of the 120s cap it had grown to while the peer was gone.
|
|
348
|
+
// Without this, a peer that restarts after a long outage sits
|
|
349
|
+
// "online but not established" for up to 2 minutes before the next
|
|
350
|
+
// handshake attempt — the exact cn/callpass post-restart wedge.
|
|
351
|
+
this.#cookieRetryCount.delete(friendId);
|
|
335
352
|
void this.#initiateSession(friendId).catch(() => { });
|
|
336
353
|
}
|
|
337
354
|
});
|
|
@@ -1763,6 +1780,14 @@ export class Peer {
|
|
|
1763
1780
|
this.#cacheFriendRemote(senderId, knownMatch.host, knownMatch.port, senderPublicKey, friendDhtPublicKey);
|
|
1764
1781
|
this.#debugLog(`onion dhtpk matched known node for ${senderId} at ${knownMatch.host}:${knownMatch.port}`);
|
|
1765
1782
|
}
|
|
1783
|
+
// A dhtpk_update is proof the friend is announcing and reachable. If our
|
|
1784
|
+
// session to them isn't established, clear the accumulated cookie backoff
|
|
1785
|
+
// so the connection loop retries the handshake at the base cadence rather
|
|
1786
|
+
// than the up-to-120s cap (mirrors the relay friendOnline reset; covers the
|
|
1787
|
+
// UDP/onion reconnect path after a restart).
|
|
1788
|
+
if (!this.#friendSessions.get(senderId)?.established) {
|
|
1789
|
+
this.#cookieRetryCount.delete(senderId);
|
|
1790
|
+
}
|
|
1766
1791
|
this.#debugLog(`dhtpk_update friend=${senderId} noReplay=${noReplay.toString()} ` +
|
|
1767
1792
|
`dhtpk=${carrierIdFromPublicKey(friendDhtPublicKey)} extraLen=${extra.length} ` +
|
|
1768
1793
|
`extraNodes=${extraNodes.length} extraPreviewHex=${extraPreview}`);
|
|
@@ -2731,7 +2756,7 @@ export class Peer {
|
|
|
2731
2756
|
let relayOk = false;
|
|
2732
2757
|
if (s?.relayRemote && s.relayPermitted) {
|
|
2733
2758
|
relayOk = this.#sendViaRelay(packet, s.relayRemote);
|
|
2734
|
-
const relayConfirmed = s.lastRelayRecvMs !== undefined && Date.now() - s.lastRelayRecvMs <
|
|
2759
|
+
const relayConfirmed = s.lastRelayRecvMs !== undefined && Date.now() - s.lastRelayRecvMs < RELAY_CONFIRM_WINDOW_MS;
|
|
2735
2760
|
if (isBulkData && relayOk && relayConfirmed) {
|
|
2736
2761
|
return;
|
|
2737
2762
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decentnetwork/peer",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.37",
|
|
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",
|