@decentnetwork/peer 0.1.47 → 0.1.48
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 +22 -5
- package/package.json +1 -1
package/dist/peer.js
CHANGED
|
@@ -9,7 +9,7 @@ import { PACKET_TYPE_MESSAGE, PACKET_TYPE_FRIEND_REQUEST, PACKET_TYPE_USERINFO,
|
|
|
9
9
|
import { NET_PACKET_ONION_ANNOUNCE_RESPONSE, NET_PACKET_ONION_DATA_RESPONSE, ONION_FRIEND_REQUEST_ID, createOnionAnnounceRequest, createOnionDataPacket, createOnionDataRequest, createOnionRequest0, openOnionAnnounceResponse, openOnionDataPacket, openOnionDataResponse } from "./compat/tox-onion.js";
|
|
10
10
|
import { CRYPTO_PACKET_DHTPK, CRYPTO_PACKET_FRIEND_REQ, NET_PACKET_CRYPTO, createToxDhtCryptoRequest, openToxDhtCryptoRequest } from "./compat/tox-dht-crypto.js";
|
|
11
11
|
import { NET_PACKET_PING_REQUEST, NET_PACKET_PING_RESPONSE, NET_PACKET_GET_NODES, NET_PACKET_SEND_NODES, encodeDhtRpc, decodeDhtRpc, buildPingPlain, parsePingPlain, buildGetNodesPlain, parseGetNodesPlain, buildSendNodesPlain, parseSendNodesNodeBytes, packUdpNodeV4 } from "./compat/dht-rpc.js";
|
|
12
|
-
import { FileTransferManager } from "./compat/filetransfer.js";
|
|
12
|
+
import { FileTransferManager, PACKET_ID_FILE_SENDREQUEST, PACKET_ID_FILE_CONTROL, PACKET_ID_FILE_DATA } from "./compat/filetransfer.js";
|
|
13
13
|
import { NET_PACKET_CRYPTO_DATA, NET_PACKET_CRYPTO_HS, NET_PACKET_COOKIE_REQUEST, NET_PACKET_COOKIE_RESPONSE, createCookieRequest, createCookieResponse, createCryptoDataPacket, createCryptoHandshake, openCookieRequest, openCookieResponse, openCryptoDataPacket, openCryptoHandshake, incrementNonce } from "./compat/net-crypto.js";
|
|
14
14
|
import { LegacyExpressClient } from "./compat/express.js";
|
|
15
15
|
import { TcpRelayPool } from "./compat/tcp-relay-pool.js";
|
|
@@ -2785,8 +2785,23 @@ export class Peer {
|
|
|
2785
2785
|
// e.g. decentlan IP=163) stays bulk / single-transport to avoid the relay
|
|
2786
2786
|
// backlog + duplicate fan-out that high packet rates cause. Chat is sparse
|
|
2787
2787
|
// and net_crypto dedups by packet number, so dual-send is safe here.
|
|
2788
|
-
|
|
2789
|
-
|
|
2788
|
+
// File transfer (80 sendrequest / 81 control / 82 data) is ALSO treated as
|
|
2789
|
+
// bulk → single-transport. It is high-volume AND order-sensitive: the
|
|
2790
|
+
// receiver reassembles chunks SEQUENTIALLY (position is implicit) and there
|
|
2791
|
+
// is no retransmit queue. Dual-sending it over UDP + relay (two paths with
|
|
2792
|
+
// different latency) reorders the chunks, and the receive-side low-water
|
|
2793
|
+
// dedup then drops the late copies — so a large file (mp4) gets gaps /
|
|
2794
|
+
// wrong order and never completes, while a tiny one (png, 1-2 chunks)
|
|
2795
|
+
// happens to finish before reordering bites. Pinning file transfer to a
|
|
2796
|
+
// single transport keeps the chunks in send order. (Reliability across a
|
|
2797
|
+
// lossy path still wants a reorder buffer + retransmit — tracked separately.)
|
|
2798
|
+
const isFileTransfer = kind === PACKET_ID_FILE_SENDREQUEST || kind === PACKET_ID_FILE_CONTROL || kind === PACKET_ID_FILE_DATA;
|
|
2799
|
+
const isBulkData = (this.#opts.bulkDataPacketId !== undefined && kind === this.#opts.bulkDataPacketId) || isFileTransfer;
|
|
2800
|
+
// File transfer rides the relay RELIABLY (never dropped under backpressure):
|
|
2801
|
+
// a dropped IP/CCTV packet is fine (the stream moves on), but a dropped file
|
|
2802
|
+
// chunk corrupts the file (no retransmit). So bulk IP data stays droppable
|
|
2803
|
+
// while file transfer is queued.
|
|
2804
|
+
await this.#sendToFriend(friendId, encrypted, session, isBulkData, isFileTransfer);
|
|
2790
2805
|
}
|
|
2791
2806
|
/**
|
|
2792
2807
|
* Send `packet` to `friendId` over whichever transport(s) are
|
|
@@ -2796,7 +2811,7 @@ export class Peer {
|
|
|
2796
2811
|
* receiving end (toxcore does the same when both transports are up).
|
|
2797
2812
|
* Throws only if zero transports succeeded.
|
|
2798
2813
|
*/
|
|
2799
|
-
async #sendToFriend(friendId, packet, session, isBulkData = false) {
|
|
2814
|
+
async #sendToFriend(friendId, packet, session, isBulkData = false, reliableOnRelay = false) {
|
|
2800
2815
|
const s = session ?? this.#friendSessions.get(friendId);
|
|
2801
2816
|
let udpOk = false;
|
|
2802
2817
|
let tcpOk = false;
|
|
@@ -2876,7 +2891,9 @@ export class Peer {
|
|
|
2876
2891
|
// Bulk IP data is droppable over the relay: under backpressure the
|
|
2877
2892
|
// relay client drops it (bounded queue) rather than buffering seconds
|
|
2878
2893
|
// of packets. Control frames pass isBulkData=false and always queue.
|
|
2879
|
-
|
|
2894
|
+
// File transfer is bulk (single-transport routing) but must NOT be
|
|
2895
|
+
// dropped — a lost chunk corrupts the file — so it is queued reliably.
|
|
2896
|
+
const sent = this.#tcpRelays.sendToFriend(tcpKey, packet, isBulkData && !reliableOnRelay);
|
|
2880
2897
|
if (sent > 0) {
|
|
2881
2898
|
tcpOk = true;
|
|
2882
2899
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decentnetwork/peer",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.48",
|
|
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",
|