@decentnetwork/peer 0.1.145 → 0.1.147

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.
@@ -12,6 +12,7 @@ export declare class LegacyExpressClient {
12
12
  selfUserId: string;
13
13
  selfAddress: string;
14
14
  callbacks: PullCallbacks;
15
+ debug?: boolean;
15
16
  });
16
17
  hasNodes(): boolean;
17
18
  sendOfflineFriendRequest(address: string, hello: Uint8Array): Promise<void>;
@@ -12,8 +12,13 @@ export class LegacyExpressClient {
12
12
  #selfAddress;
13
13
  #currNode = 0;
14
14
  #callbacks;
15
+ // Own gate, and env-only until now — so in a browser this client was mute
16
+ // whatever the peer's debug setting was. That is why a stalled pull looked
17
+ // identical to a pull that never ran.
15
18
  #debug = process.env.DECENT_DEBUG === "1";
16
19
  constructor(opts) {
20
+ if (opts.debug)
21
+ this.#debug = true;
17
22
  this.#selfKeyPair = opts.selfKeyPair;
18
23
  this.#selfUserId = opts.selfUserId;
19
24
  this.#selfAddress = opts.selfAddress;
@@ -63,8 +68,12 @@ export class LegacyExpressClient {
63
68
  try {
64
69
  body = await this.#http(node, "GET", encodeURIComponent(this.#selfUserId));
65
70
  }
66
- catch {
67
- continue; // relay unreachable right now try the next
71
+ catch (error) {
72
+ // Say so. Swallowing this made an unreachable relay indistinguishable
73
+ // from an empty inbox, and offline mail piled up on the server with
74
+ // nothing anywhere reporting why.
75
+ this.#debugLog(`pull from ${node.host}:${node.port} failed: ${error?.message ?? error}`);
76
+ continue;
68
77
  }
69
78
  const messages = parseExpressResponseFrames(body);
70
79
  if (messages.length === 0) {
package/dist/peer.js CHANGED
@@ -598,6 +598,7 @@ export class Peer {
598
598
  selfKeyPair: this.#keyPair,
599
599
  selfUserId: this.userid(),
600
600
  selfAddress: this.address(),
601
+ debug: this.#debug,
601
602
  callbacks: {
602
603
  onOfflineFriendRequest: (fromUserId, packet) => {
603
604
  this.#emitOfflineFriendRequest(fromUserId, packet);
@@ -3738,8 +3739,14 @@ export class Peer {
3738
3739
  }
3739
3740
  #ensureExpressPullLoop() {
3740
3741
  if (!this.#express?.hasNodes() || this.#expressPollTimer || EXPRESS_PULL_INTERVAL_MS <= 0) {
3742
+ // Three ways to silently do nothing, and no way to tell them apart from
3743
+ // outside — which cost a long evening of guessing why offline mail was
3744
+ // never collected in a browser.
3745
+ this.#debugLog(`express pull loop NOT started: hasClient=${!!this.#express} hasNodes=${!!this.#express?.hasNodes()} ` +
3746
+ `alreadyRunning=${!!this.#expressPollTimer} interval=${EXPRESS_PULL_INTERVAL_MS}`);
3741
3747
  return;
3742
3748
  }
3749
+ this.#debugLog(`express pull loop started, every ${EXPRESS_PULL_INTERVAL_MS}ms`);
3743
3750
  const pull = () => {
3744
3751
  void this.#express?.pullOnce().catch((error) => {
3745
3752
  this.#debugLog(`express pull failed: ${error.message}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/peer",
3
- "version": "0.1.145",
3
+ "version": "0.1.147",
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",