@peerbit/pubsub 5.4.11 → 5.4.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peerbit/pubsub",
3
- "version": "5.4.11",
3
+ "version": "5.4.13",
4
4
  "description": "Direct streaming for libp2p",
5
5
  "type": "module",
6
6
  "types": "./dist/src/index.d.ts",
@@ -87,8 +87,8 @@
87
87
  "uint8arrays": "^5.1.0",
88
88
  "@peerbit/any-store-interface": "1.1.4",
89
89
  "@peerbit/crypto": "3.1.6",
90
- "@peerbit/pubsub-interface": "5.2.2",
91
90
  "@peerbit/logger": "2.0.2",
91
+ "@peerbit/pubsub-interface": "5.2.2",
92
92
  "@peerbit/stream": "5.2.4",
93
93
  "@peerbit/stream-interface": "6.0.16",
94
94
  "@peerbit/time": "3.0.1"
@@ -1464,6 +1464,11 @@ export class FanoutTree extends DirectStream<FanoutTreeEvents> {
1464
1464
  this.topicRootControlPlane =
1465
1465
  topicRootControlPlane ?? new TopicRootControlPlane();
1466
1466
 
1467
+ this.registerUnderlayPeerDisconnectHandler();
1468
+ }
1469
+
1470
+ private registerUnderlayPeerDisconnectHandler() {
1471
+ if (this.underlayPeerDisconnectHandler) return;
1467
1472
  const onPeerDisconnect = (ev: any) => {
1468
1473
  const peerId = ev?.detail;
1469
1474
  if (!peerId) return;
@@ -1482,6 +1487,15 @@ export class FanoutTree extends DirectStream<FanoutTreeEvents> {
1482
1487
  );
1483
1488
  }
1484
1489
 
1490
+ public override async start() {
1491
+ await super.start();
1492
+ // stop() removes the listener, so a restarted instance must add it again
1493
+ // (but not while a stop that raced this start is still tearing down).
1494
+ if (this.started && !this.stopping) {
1495
+ this.registerUnderlayPeerDisconnectHandler();
1496
+ }
1497
+ }
1498
+
1485
1499
  private createLoopCloseController(): AbortController {
1486
1500
  const controller = new AbortController();
1487
1501
  const stopSignal = this.closeController.signal;
package/src/index.ts CHANGED
@@ -5181,6 +5181,18 @@ export class TopicControlPlane
5181
5181
 
5182
5182
  if (pubsubMessage instanceof PeerUnavailable) {
5183
5183
  const peerHash = pubsubMessage.publicKeyHash;
5184
+ // A relay reports loss of its own path, not the subscriber's departure.
5185
+ // Keep stronger local evidence; explicit signed Unsubscribe messages are
5186
+ // handled separately and still remove directly connected subscribers.
5187
+ const direct = this.peers.get(peerHash);
5188
+ if (
5189
+ direct &&
5190
+ !direct.isClosed &&
5191
+ direct.isReadable &&
5192
+ direct.isWritable
5193
+ ) {
5194
+ return;
5195
+ }
5184
5196
  // Relay-originated shard deltas are keyed only by shard membership, not by
5185
5197
  // per-topic subscription watermarks. They are emitted immediately when the
5186
5198
  // relay loses a child so downstream peers can shed stale membership without