@decentnetwork/peer 0.1.119 → 0.1.121
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 +38 -5
- package/package.json +1 -1
package/dist/peer.js
CHANGED
|
@@ -2566,7 +2566,13 @@ export class Peer {
|
|
|
2566
2566
|
dataSecretKey: this.#announceDataKey.secretKey
|
|
2567
2567
|
});
|
|
2568
2568
|
if (!routed) {
|
|
2569
|
-
|
|
2569
|
+
// Log enough to distinguish "sender used a stale data pk from an old
|
|
2570
|
+
// announce entry" from "packet framing we mis-parse" — the temp pk
|
|
2571
|
+
// the sender encrypted to sits at bytes [25..57) in toxcore layout.
|
|
2572
|
+
const pkPreview = Buffer.from(packet.slice(25, 57)).toString("hex").slice(0, 16);
|
|
2573
|
+
this.#debugLog(`onion data response decrypt failed from=${remote.address}:${remote.port} ` +
|
|
2574
|
+
`len=${packet.length} ourDataPk=${Buffer.from(this.#announceDataKey.publicKey).toString("hex").slice(0, 16)} ` +
|
|
2575
|
+
`pkAt25=${pkPreview}`);
|
|
2570
2576
|
return;
|
|
2571
2577
|
}
|
|
2572
2578
|
const onionData = openOnionDataPacket(routed.payload, {
|
|
@@ -3173,8 +3179,11 @@ export class Peer {
|
|
|
3173
3179
|
// fleet, so an announce stored there is universally findable.
|
|
3174
3180
|
const wave = [];
|
|
3175
3181
|
if (waves === 1) {
|
|
3182
|
+
// ALL bootstraps, not a distance-picked subset: only a minority of
|
|
3183
|
+
// the fleet still answers UDP DHT (observed: 1 of 9), and a subset
|
|
3184
|
+
// pick chose 4 dead ones while skipping the live one.
|
|
3176
3185
|
const bootstrapIdSet = new Set(this.#opts.bootstrapNodes.map((n) => `${n.host}:${n.port}`));
|
|
3177
|
-
for (let qi = 0; qi < queue.length && wave.length <
|
|
3186
|
+
for (let qi = 0; qi < queue.length && wave.length < bootstrapIdSet.size;) {
|
|
3178
3187
|
const c = queue[qi];
|
|
3179
3188
|
const id = `${c.node.host}:${c.node.port}`;
|
|
3180
3189
|
if (bootstrapIdSet.has(id) && !visited.has(id)) {
|
|
@@ -5204,7 +5213,11 @@ export class Peer {
|
|
|
5204
5213
|
// Prefer DHT key learned from DHTPK updates; fallback to real key.
|
|
5205
5214
|
const friendDhtPk = session?.friendDhtPublicKey ?? friendRealPk;
|
|
5206
5215
|
const connectCandidates = this.#collectSessionEndpointCandidates(friendId, friend, session);
|
|
5207
|
-
|
|
5216
|
+
// Natives are known to the relay by their DHT key, not their identity
|
|
5217
|
+
// key — check both, else tcpAvailable stays false for every native.
|
|
5218
|
+
const dhtKeyForTcp = session?.friendDhtPublicKey ?? this.#friendDhtKeys.get(friendId);
|
|
5219
|
+
const tcpAvailable = !!this.#tcpRelays?.isFriendOnline(friendRealPk) ||
|
|
5220
|
+
(!!dhtKeyForTcp && !!this.#tcpRelays?.isFriendOnline(dhtKeyForTcp));
|
|
5208
5221
|
if (connectCandidates.length === 0 && !tcpAvailable) {
|
|
5209
5222
|
this.#debugLog(`initiate session: no known endpoint for ${friendId} yet`);
|
|
5210
5223
|
return false;
|
|
@@ -5345,8 +5358,28 @@ export class Peer {
|
|
|
5345
5358
|
}
|
|
5346
5359
|
// Also send via TCP relay if available, in parallel. Whichever
|
|
5347
5360
|
// arrives at the friend first triggers their cookie response.
|
|
5348
|
-
|
|
5349
|
-
|
|
5361
|
+
// Route/notify state at the relay is keyed by the key the FRIEND
|
|
5362
|
+
// handshook the relay with — for natives that's their (rotated) DHT
|
|
5363
|
+
// key, NOT their identity key. The old real-pk-only calls meant
|
|
5364
|
+
// tcpAvailable was never true for a native and the routed send would
|
|
5365
|
+
// have gone to a key the relay didn't know (tcp=0 forever while both
|
|
5366
|
+
// ends sat on the same relay).
|
|
5367
|
+
if (this.#tcpRelays) {
|
|
5368
|
+
const tcpKey = session.friendDhtPublicKey ?? friendRealPk;
|
|
5369
|
+
if (this.#tcpRelays.isFriendOnline(tcpKey) || this.#tcpRelays.isFriendOnline(friendRealPk)) {
|
|
5370
|
+
tcpSent = this.#tcpRelays.sendToFriend(tcpKey, packet);
|
|
5371
|
+
if (tcpSent === 0 && tcpKey !== friendRealPk) {
|
|
5372
|
+
tcpSent = this.#tcpRelays.sendToFriend(friendRealPk, packet);
|
|
5373
|
+
}
|
|
5374
|
+
}
|
|
5375
|
+
// OOB fallback: needs no route/cid — the relay forwards to any
|
|
5376
|
+
// connected client by key, and toxcore's oob handler accepts cookie
|
|
5377
|
+
// requests (0x18). This is exactly how the iOS side reaches US when
|
|
5378
|
+
// only a shared relay exists; without the mirror-image our own
|
|
5379
|
+
// initiation had no TCP path until a route linked.
|
|
5380
|
+
if (tcpSent === 0) {
|
|
5381
|
+
tcpSent = this.#tcpRelays.sendOobToFriend(tcpKey, packet);
|
|
5382
|
+
}
|
|
5350
5383
|
}
|
|
5351
5384
|
if (sent === 0 && tcpSent === 0 && selfSent === 0) {
|
|
5352
5385
|
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.121",
|
|
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",
|