@decentnetwork/peer 0.1.2 → 0.1.3
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 +18 -10
- package/package.json +1 -1
package/dist/peer.js
CHANGED
|
@@ -2080,13 +2080,20 @@ export class Peer {
|
|
|
2080
2080
|
void this.#sendOnionDhtPk(friendRealPk).catch((error) => {
|
|
2081
2081
|
this.#debugLog(`UDP retry: dhtpk_send for ${friendId} failed: ${error.message}`);
|
|
2082
2082
|
});
|
|
2083
|
-
// 2. Try to discover the peer's UDP endpoint and kick a
|
|
2084
|
-
// cookie request via UDP.
|
|
2085
|
-
//
|
|
2086
|
-
//
|
|
2083
|
+
// 2. Try to discover the peer's UDP endpoint and kick a
|
|
2084
|
+
// fresh cookie request via UDP. discoverAndCacheFriend
|
|
2085
|
+
// Endpoint accepts EITHER the DHT-PK (preferred —
|
|
2086
|
+
// direct DHT lookup) OR the friend's real identity
|
|
2087
|
+
// public key (onion-routed lookup). When the session
|
|
2088
|
+
// came up via TCP-relay only, neither side has
|
|
2089
|
+
// received an onion DHT-PK from the other yet, so
|
|
2090
|
+
// session.friendDhtPublicKey is null. Falling back
|
|
2091
|
+
// to friendRealPk keeps the retry from being a no-op
|
|
2092
|
+
// in exactly the case it was designed to fix.
|
|
2087
2093
|
const dhtPk = session.friendDhtPublicKey;
|
|
2088
|
-
|
|
2089
|
-
|
|
2094
|
+
const searchKey = dhtPk ?? friendRealPk;
|
|
2095
|
+
if (searchKey && searchKey.length === 32) {
|
|
2096
|
+
void this.#discoverAndCacheFriendEndpoint(friendId, searchKey)
|
|
2090
2097
|
.then((found) => {
|
|
2091
2098
|
if (found) {
|
|
2092
2099
|
return this.#initiateSession(friendId).catch(() => undefined);
|
|
@@ -2094,12 +2101,13 @@ export class Peer {
|
|
|
2094
2101
|
})
|
|
2095
2102
|
.catch(() => undefined);
|
|
2096
2103
|
}
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2104
|
+
// Always also retry initiate if we have a cached real
|
|
2105
|
+
// UDP endpoint — covers the case where discovery
|
|
2106
|
+
// succeeded earlier but the cookie request was lost.
|
|
2107
|
+
if (friend.remoteHost && friend.remotePort) {
|
|
2100
2108
|
void this.#initiateSession(friendId).catch(() => undefined);
|
|
2101
2109
|
}
|
|
2102
|
-
this.#debugLog(`UDP retry attempt for ${friendId} (currently on TCP relay)`);
|
|
2110
|
+
this.#debugLog(`UDP retry attempt for ${friendId} (currently on TCP relay, search=${dhtPk ? "dht-pk" : "real-pk"})`);
|
|
2103
2111
|
}
|
|
2104
2112
|
}
|
|
2105
2113
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decentnetwork/peer",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
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",
|