@decentnetwork/peer 0.1.151 → 0.1.152
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.d.ts +19 -1
- package/dist/peer.js +20 -2
- package/package.json +1 -1
package/dist/peer.d.ts
CHANGED
|
@@ -80,13 +80,31 @@ export declare class Peer {
|
|
|
80
80
|
};
|
|
81
81
|
addKnownNodes(nodes: NetworkNode[]): void;
|
|
82
82
|
knownNodes(): NetworkNode[];
|
|
83
|
-
|
|
83
|
+
/** @param opts.force Send even when this friend looks already-accepted.
|
|
84
|
+
*
|
|
85
|
+
* The idempotency guard below is right for automatic retries and wrong for
|
|
86
|
+
* a person clicking "add". If the other side REJECTED an earlier request,
|
|
87
|
+
* their app forgets it — but a net_crypto session may already have been
|
|
88
|
+
* established, so this side keeps acceptedAt and skips every later attempt.
|
|
89
|
+
* Neither peer is then in the other's friend list and nothing either user
|
|
90
|
+
* does can fix it: every add is silently dropped here. A deliberate add has
|
|
91
|
+
* to be able to say "I mean it". */
|
|
92
|
+
sendFriendRequest(pubkey: string, hello?: string, opts?: {
|
|
93
|
+
force?: boolean;
|
|
94
|
+
}): Promise<void>;
|
|
84
95
|
lastFriendRequestDispatch(): {
|
|
85
96
|
transport: "onion" | "direct";
|
|
86
97
|
routes: number;
|
|
87
98
|
targets: number;
|
|
88
99
|
} | undefined;
|
|
89
100
|
acceptFriendRequest(pubkey: string): Promise<void>;
|
|
101
|
+
/** Decline an inbound request.
|
|
102
|
+
*
|
|
103
|
+
* Also drops any friend record and session the request already created.
|
|
104
|
+
* Clearing only the pending list left the transport half-attached: the
|
|
105
|
+
* sender saw a session, marked us accepted, and its idempotency guard then
|
|
106
|
+
* skipped every later attempt — so a rejected peer could never ask again,
|
|
107
|
+
* and neither side could see why. */
|
|
90
108
|
rejectFriendRequest(pubkey: string): void;
|
|
91
109
|
/**
|
|
92
110
|
* Drop a friend entirely: tear down any active net_crypto session, forget
|
package/dist/peer.js
CHANGED
|
@@ -1040,7 +1040,16 @@ export class Peer {
|
|
|
1040
1040
|
knownNodes() {
|
|
1041
1041
|
return [...this.#knownNodes];
|
|
1042
1042
|
}
|
|
1043
|
-
|
|
1043
|
+
/** @param opts.force Send even when this friend looks already-accepted.
|
|
1044
|
+
*
|
|
1045
|
+
* The idempotency guard below is right for automatic retries and wrong for
|
|
1046
|
+
* a person clicking "add". If the other side REJECTED an earlier request,
|
|
1047
|
+
* their app forgets it — but a net_crypto session may already have been
|
|
1048
|
+
* established, so this side keeps acceptedAt and skips every later attempt.
|
|
1049
|
+
* Neither peer is then in the other's friend list and nothing either user
|
|
1050
|
+
* does can fix it: every add is silently dropped here. A deliberate add has
|
|
1051
|
+
* to be able to say "I mean it". */
|
|
1052
|
+
async sendFriendRequest(pubkey, hello, opts) {
|
|
1044
1053
|
if (!this.#keyPair || !this.#announceDataKey) {
|
|
1045
1054
|
throw new Error("Peer is not started");
|
|
1046
1055
|
}
|
|
@@ -1056,7 +1065,7 @@ export class Peer {
|
|
|
1056
1065
|
const friendAddress = parseCarrierAddress(pubkey);
|
|
1057
1066
|
const friendId = carrierIdFromPublicKey(friendAddress.publicKey);
|
|
1058
1067
|
const existing = this.#friends.get(friendId);
|
|
1059
|
-
if (existing?.acceptedAt) {
|
|
1068
|
+
if (existing?.acceptedAt && !opts?.force) {
|
|
1060
1069
|
this.#debugLog(`friend request skipped — ${friendId} already accepted at ${new Date(existing.acceptedAt).toISOString()}`);
|
|
1061
1070
|
this.#lastFriendRequestDispatch = {
|
|
1062
1071
|
transport: "onion",
|
|
@@ -1237,8 +1246,17 @@ export class Peer {
|
|
|
1237
1246
|
this.#debugLog(`accept friend: initiate session failed for ${pubkey}: ${error.message}`);
|
|
1238
1247
|
});
|
|
1239
1248
|
}
|
|
1249
|
+
/** Decline an inbound request.
|
|
1250
|
+
*
|
|
1251
|
+
* Also drops any friend record and session the request already created.
|
|
1252
|
+
* Clearing only the pending list left the transport half-attached: the
|
|
1253
|
+
* sender saw a session, marked us accepted, and its idempotency guard then
|
|
1254
|
+
* skipped every later attempt — so a rejected peer could never ask again,
|
|
1255
|
+
* and neither side could see why. */
|
|
1240
1256
|
rejectFriendRequest(pubkey) {
|
|
1241
1257
|
this.#pendingFriendRequests.delete(pubkey);
|
|
1258
|
+
if (this.#friends.has(pubkey))
|
|
1259
|
+
this.removeFriend(pubkey);
|
|
1242
1260
|
}
|
|
1243
1261
|
/**
|
|
1244
1262
|
* Drop a friend entirely: tear down any active net_crypto session, forget
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decentnetwork/peer",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.152",
|
|
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",
|