@decentnetwork/peer 0.1.120 → 0.1.122
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 +31 -4
- package/package.json +1 -1
package/dist/peer.js
CHANGED
|
@@ -60,7 +60,10 @@ const DHT_MAINTENANCE_INTERVAL_MS = readEnvInt("DECENT_DHT_MAINTENANCE_INTERVAL_
|
|
|
60
60
|
// distance-sort it feeds) without limit — which starved CCTV forwarding over time.
|
|
61
61
|
const MAX_KNOWN_NODES = readEnvInt("DECENT_MAX_KNOWN_NODES", 400);
|
|
62
62
|
const MAX_SELF_ANNOUNCE_TARGETS = readEnvInt("DECENT_SELF_ANNOUNCE_TARGETS", 16);
|
|
63
|
-
|
|
63
|
+
// 1 (was 3): a dead node cost attempts×ANNOUNCE_WAIT = 12s — one wave of
|
|
64
|
+
// dead nodes ate the entire per-cycle deadline, so the walk never got past
|
|
65
|
+
// wave 1 and stored on ~1 node per DAY. The 12s cycle itself is the retry.
|
|
66
|
+
const SELF_ANNOUNCE_ATTEMPTS = readEnvInt("DECENT_SELF_ANNOUNCE_ATTEMPTS", 1);
|
|
64
67
|
// Self-announce batch size — number of step1 / step2 requests to fan out
|
|
65
68
|
// at once. Toxcore's onion_client.c::do_announce keeps up to
|
|
66
69
|
// MAX_ONION_CLIENTS_ANNOUNCE (12) in flight. Configurable via env.
|
|
@@ -5213,7 +5216,11 @@ export class Peer {
|
|
|
5213
5216
|
// Prefer DHT key learned from DHTPK updates; fallback to real key.
|
|
5214
5217
|
const friendDhtPk = session?.friendDhtPublicKey ?? friendRealPk;
|
|
5215
5218
|
const connectCandidates = this.#collectSessionEndpointCandidates(friendId, friend, session);
|
|
5216
|
-
|
|
5219
|
+
// Natives are known to the relay by their DHT key, not their identity
|
|
5220
|
+
// key — check both, else tcpAvailable stays false for every native.
|
|
5221
|
+
const dhtKeyForTcp = session?.friendDhtPublicKey ?? this.#friendDhtKeys.get(friendId);
|
|
5222
|
+
const tcpAvailable = !!this.#tcpRelays?.isFriendOnline(friendRealPk) ||
|
|
5223
|
+
(!!dhtKeyForTcp && !!this.#tcpRelays?.isFriendOnline(dhtKeyForTcp));
|
|
5217
5224
|
if (connectCandidates.length === 0 && !tcpAvailable) {
|
|
5218
5225
|
this.#debugLog(`initiate session: no known endpoint for ${friendId} yet`);
|
|
5219
5226
|
return false;
|
|
@@ -5354,8 +5361,28 @@ export class Peer {
|
|
|
5354
5361
|
}
|
|
5355
5362
|
// Also send via TCP relay if available, in parallel. Whichever
|
|
5356
5363
|
// arrives at the friend first triggers their cookie response.
|
|
5357
|
-
|
|
5358
|
-
|
|
5364
|
+
// Route/notify state at the relay is keyed by the key the FRIEND
|
|
5365
|
+
// handshook the relay with — for natives that's their (rotated) DHT
|
|
5366
|
+
// key, NOT their identity key. The old real-pk-only calls meant
|
|
5367
|
+
// tcpAvailable was never true for a native and the routed send would
|
|
5368
|
+
// have gone to a key the relay didn't know (tcp=0 forever while both
|
|
5369
|
+
// ends sat on the same relay).
|
|
5370
|
+
if (this.#tcpRelays) {
|
|
5371
|
+
const tcpKey = session.friendDhtPublicKey ?? friendRealPk;
|
|
5372
|
+
if (this.#tcpRelays.isFriendOnline(tcpKey) || this.#tcpRelays.isFriendOnline(friendRealPk)) {
|
|
5373
|
+
tcpSent = this.#tcpRelays.sendToFriend(tcpKey, packet);
|
|
5374
|
+
if (tcpSent === 0 && tcpKey !== friendRealPk) {
|
|
5375
|
+
tcpSent = this.#tcpRelays.sendToFriend(friendRealPk, packet);
|
|
5376
|
+
}
|
|
5377
|
+
}
|
|
5378
|
+
// OOB fallback: needs no route/cid — the relay forwards to any
|
|
5379
|
+
// connected client by key, and toxcore's oob handler accepts cookie
|
|
5380
|
+
// requests (0x18). This is exactly how the iOS side reaches US when
|
|
5381
|
+
// only a shared relay exists; without the mirror-image our own
|
|
5382
|
+
// initiation had no TCP path until a route linked.
|
|
5383
|
+
if (tcpSent === 0) {
|
|
5384
|
+
tcpSent = this.#tcpRelays.sendOobToFriend(tcpKey, packet);
|
|
5385
|
+
}
|
|
5359
5386
|
}
|
|
5360
5387
|
if (sent === 0 && tcpSent === 0 && selfSent === 0) {
|
|
5361
5388
|
throw new Error("no cookie request packet was sent");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decentnetwork/peer",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.122",
|
|
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",
|