@decentnetwork/peer 0.1.142 → 0.1.143

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 CHANGED
@@ -898,6 +898,41 @@ export class Peer {
898
898
  if (!this.#bootstrap) {
899
899
  throw new Error("Peer is not started");
900
900
  }
901
+ // A browser has no UDP and never will. The DHT bootstrap is a getnodes
902
+ // datagram waiting for a sendnodes reply, so there it can only ever time
903
+ // out — 30 seconds, then an error that reads like a network fault.
904
+ //
905
+ // That cost far more than a slow start. Everything after the await lives
906
+ // downstream of it: the self-announce (without which nobody can FIND this
907
+ // peer), the announce loop, and the express pull loop (without which
908
+ // offline messages are never collected). start() launches only the
909
+ // friend-connection loop, so a browser could talk to a friend who was
910
+ // already online and whose endpoint it had cached — and nothing else.
911
+ // That is exactly the half-working shape this looked like from outside.
912
+ //
913
+ // With tcpOnlyBootstrap we skip the datagram round trip and seed the node
914
+ // list from the configured bootstrap nodes, which is what the TCP relay
915
+ // path uses anyway. Announce and both loops then run normally.
916
+ if (this.#opts.tcpOnlyBootstrap) {
917
+ const seed = this.#opts.bootstrapNodes ?? [];
918
+ if (seed.length === 0) {
919
+ throw new Error("tcpOnlyBootstrap needs at least one bootstrap node to seed from");
920
+ }
921
+ this.#knownNodes = dedupeNodes([...seed]);
922
+ await this.#runSelfAnnounce(false, Date.now() + JOIN_ANNOUNCE_TIMEOUT_MS);
923
+ this.#ensureSelfAnnounceLoop();
924
+ this.#ensureDhtMaintenanceLoop();
925
+ this.#ensureFriendConnectionLoop();
926
+ this.#ensureExpressPullLoop();
927
+ void this.#doFriendConnections().catch((error) => {
928
+ this.#debugLog(`initial friend connection cycle failed: ${error.message}`);
929
+ });
930
+ const first = seed[0];
931
+ return {
932
+ respondingNode: first,
933
+ discoveredNodes: []
934
+ };
935
+ }
901
936
  const result = await this.#bootstrap.join();
902
937
  this.#recordNodeSuccess(`${result.respondingNode.host}:${result.respondingNode.port}`);
903
938
  const discovered = result.discoveredNodes.map((node) => ({
@@ -93,6 +93,13 @@ export type PeerOptions = {
93
93
  * and the field is omitted entirely (never sent as ""), so a friend keeps
94
94
  * whatever picture they already have for us. */
95
95
  punkId?: number;
96
+ /** Skip the UDP DHT bootstrap and seed the node list from bootstrapNodes.
97
+ *
98
+ * For hosts with no UDP — a browser above all. Without it joinNetwork()
99
+ * waits 30s for a datagram that cannot arrive, and everything downstream
100
+ * of it never runs: self-announce (so nobody can find this peer) and the
101
+ * express pull loop (so offline messages are never collected). */
102
+ tcpOnlyBootstrap?: boolean;
96
103
  compatibilityMode?: CompatibilityMode;
97
104
  debugLabel?: string;
98
105
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/peer",
3
- "version": "0.1.142",
3
+ "version": "0.1.143",
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",