@steve02081504/fount-p2p 0.0.51 → 0.0.53

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/AGENTS.md CHANGED
@@ -51,10 +51,12 @@ Deno / native / BT: [runtime.md](docs/runtime.md).
51
51
  - `npm run check:text_lf:fix` — rewrite line-ending violations (the suites themselves never write)
52
52
  - `node scripts/check-imports.mjs` — relative import check
53
53
  - `node scripts/find-unused-exports.mjs` — dead-export scan (`--fount <path>` optional)
54
+ - `node scripts/check-regression-guard.mjs --revert <fixed file> --tests <test file> [--base <commit>]` — proves a new test catches its bug by running it in a throwaway worktree with the fix reverted; it accepts only "every leaf case failed through its own assertion" (a load error or a mixed pass/fail run is rejected, with the TAP counts printed); see the root [AGENTS.md](../AGENTS.md), and `test/pure/regression_guard_tool.test.mjs` covers the guarding, still-passes and not-exclusively-assertions verdicts
54
55
  - Assertions: `test/helpers/assert.mjs`
55
56
  - Fixed-seed identity: `test/helpers/identity.mjs`
56
57
  - Mock discovery: `test/helpers/mock_discovery.mjs`
57
58
  - Transport fakes must mirror the backend's failure signalling: a fake `RTCPeerConnection` whose `close()` stays silent (no `connectionstatechange`) hides re-entrancy bugs where a replaced connection closes the live one (fount-p2p#39, `link/providers/webrtc.mjs`).
59
+ - **Tests stay off the public network.** A suite that lets the runtime dial the default relays measures the relay latency, not the code: `shutdown_exit.test.mjs` asserts its child's `shutdown→exit` budget, which drifted past it on a live network, so the child now pins its nostr channel to a fake relay started by the parent and the test asserts the child never touched another relay. Register `initTestP2pNode` (disables NIP-66 discovery and census) and pass `setSignalingRuntimeConfig({ channels: { nostr: { relay: [localRelayUrl] } } })` instead of relying on `DEFAULT_RELAY_URLS`.
58
60
 
59
61
  ## Static checks (`scripts/checks/`, ported from fount's check standard)
60
62
 
@@ -535,12 +535,13 @@ export function createNostrDiscoveryProvider(options = {}) {
535
535
  bytesToBase64(bytes),
536
536
  secretKey,
537
537
  )
538
- // 显式 relay 覆盖(测试/用户 pin)时直接全量发布;否则走握手路由。
539
- if (hasExplicitRelay) {
540
- await publishEvent(resolveRelayUrls(), event)
541
- return
542
- }
543
- await routePublishEvent(hash, event)
538
+ // 显式配置只描述本机中继集;对端订阅的是它自己的监听集,两者可以不相交,
539
+ // 故定向发送要并上对端广告的监听集,否则事件发出去也没人听。
540
+ if (hasExplicitRelay) return void await publishEvent(
541
+ [...new Set([...resolveRelayUrls(), ...getPeerRoute(hash)?.listenRelays || []])],
542
+ event,
543
+ )
544
+ if (!await routePublishEvent(hash, event)) throw new Error('nostr: no relay accepted directed signal')
544
545
  },
545
546
  /**
546
547
  * @param {string} localNodeHash 本机 nodeHash
@@ -480,6 +480,8 @@ function registerSharedRelaySub(session, subscriptionId, filter, onEvent) {
480
480
  function flushPendingPublishes(relayUrl, session, socket) {
481
481
  const pending = session.pendingPublishes
482
482
  session.pendingPublishes = []
483
+ // 每个请求各自挂一个 message 监听;一次性按本批实际在途数抬高上限,避免运行中超出建连时的快照。
484
+ socket.setMaxListeners(session.inflightPublishes.length + pending.length + 8)
483
485
  for (const publishRequest of pending) {
484
486
  publishRequest.removeAbort?.()
485
487
  publishRequest.onAbort = null
@@ -84,7 +84,7 @@ Lower is better. A dead entry (`failureCount > 0` and either no successes or a l
84
84
  - **Round ≥1**: backoff `min(2000 · 2^(attempt−1), 60000)`; base on `lastGoodNostrRelays` (expanded via `expandFromHistory` ≤ 16), or weighted-random sample of `workingRelays` (weight `1/score`); round-0 core always included; fanout capped at `MAX_ROUTING_FANOUT` (64).
85
85
  - Retries ≤ `MAX_ROUTING_ATTEMPTS` (4).
86
86
 
87
- `routePublishEvent(toNodeHash, event, signal)`: publishes to the current round's targets in parallel via shared sessions; any `OK` records `lastGoodNostrRelays` (last 16) + success; all-fail records failures and backs off. `sendNodeSignal` uses routing; an explicit relay override (test/user pin) publishes directly.
87
+ `routePublishEvent(toNodeHash, event, signal)`: publishes to the current round's targets in parallel via shared sessions; any `OK` records `lastGoodNostrRelays` (last 16) + success; all-fail records failures and backs off. `sendNodeSignal` rejects when routing finds no accepting relay. With an explicit relay override (including the runtime's `getRelayUrls` callback), directed signals publish to the union of local relays and the peer's advertised listen relays. Every destination still passes the public-address/configured-relay gate and uses the validated DNS target. Each receiver subscribes on its own set, so the two local sets need not intersect when both peers advertise their listen relays.
88
88
 
89
89
  ## Census (population estimate)
90
90
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steve02081504/fount-p2p",
3
- "version": "0.0.51",
3
+ "version": "0.0.53",
4
4
  "description": "fount federation P2P layer — link, trust graph, mailbox, DAG, EVFS.",
5
5
  "keywords": [
6
6
  "network",