@steve02081504/fount-p2p 0.0.23 → 0.0.25

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.
Files changed (67) hide show
  1. package/README.md +8 -6
  2. package/core/object.mjs +9 -0
  3. package/core/partpath.mjs +10 -0
  4. package/dag/storage.mjs +0 -5
  5. package/dag/strip_extensions.mjs +1 -3
  6. package/{wire/part_query_cache.mjs → federation/part_query/cache.mjs} +7 -7
  7. package/{wire/part_query.mjs → federation/part_query/runtime.mjs} +36 -77
  8. package/files/assemble.mjs +5 -5
  9. package/files/assemble_stream.mjs +2 -2
  10. package/files/chunk/fetch.mjs +101 -0
  11. package/files/chunk/pending.mjs +59 -0
  12. package/files/{chunk_provider_registry.mjs → chunk/provider_registry.mjs} +4 -5
  13. package/files/chunk/responder.mjs +104 -0
  14. package/files/{chunk_store.mjs → chunk/store.mjs} +2 -2
  15. package/files/{chunk_fetch_verify.mjs → chunk/verify.mjs} +2 -2
  16. package/files/evfs.mjs +18 -19
  17. package/files/fed/fetch_shared.mjs +39 -0
  18. package/files/fed/responder.mjs +47 -0
  19. package/files/{acl.mjs → manifest/acl.mjs} +4 -4
  20. package/files/{manifest_acl_registry.mjs → manifest/acl_registry.mjs} +14 -17
  21. package/files/{manifest_fetch.mjs → manifest/fetch.mjs} +47 -52
  22. package/files/{manifest.mjs → manifest/normalize.mjs} +2 -2
  23. package/files/manifest/pending.mjs +53 -0
  24. package/files/{public_manifest.mjs → manifest/public.mjs} +12 -12
  25. package/files/transfer_key.mjs +2 -2
  26. package/files/transfer_key_registry.mjs +7 -7
  27. package/index.mjs +4 -4
  28. package/infra/service.mjs +1 -1
  29. package/link/handshake.mjs +0 -3
  30. package/mailbox/deliver_or_store.mjs +0 -2
  31. package/mailbox/parse.mjs +1 -1
  32. package/mailbox/store.mjs +0 -9
  33. package/mailbox/wire.mjs +24 -16
  34. package/node/reputation_sync.mjs +33 -29
  35. package/package.json +10 -10
  36. package/registries/inbound.mjs +19 -9
  37. package/registries/part_path.mjs +3 -8
  38. package/schemas/discovery.mjs +1 -1
  39. package/schemas/federation_pull.mjs +1 -1
  40. package/schemas/part_query.mjs +6 -5
  41. package/transport/group_link_set.mjs +2 -2
  42. package/transport/link_registry.mjs +2 -2
  43. package/transport/node_scope/features.mjs +166 -0
  44. package/transport/node_scope/wire.mjs +143 -0
  45. package/transport/remote_user_room.mjs +0 -1
  46. package/{rooms → transport}/scoped_link.mjs +1 -1
  47. package/transport/user_room.mjs +15 -28
  48. package/utils/fetch_wait.mjs +98 -0
  49. package/wire/adapter.mjs +13 -0
  50. package/wire/ingress.mjs +1 -8
  51. package/wire/part/fanout.mjs +99 -0
  52. package/wire/part/group.mjs +45 -0
  53. package/wire/{part_ingress.mjs → part/ingress.mjs} +58 -67
  54. package/wire/{part_invoke.mjs → part/invoke.mjs} +1 -22
  55. package/wire/part/pending.mjs +32 -0
  56. package/wire/part/query.mjs +91 -0
  57. package/wire/subscribe.mjs +13 -0
  58. package/federation/chunk_fetch_pending.mjs +0 -124
  59. package/federation/manifest_fetch_pending.mjs +0 -88
  60. package/files/chunk_fetch.mjs +0 -99
  61. package/files/chunk_responder.mjs +0 -142
  62. package/transport/advert_ingest.mjs +0 -17
  63. package/transport/node_scope.mjs +0 -289
  64. package/wire/group_part.mjs +0 -43
  65. package/wire/part_common.mjs +0 -55
  66. package/wire/part_fanout.mjs +0 -52
  67. /package/{wire → schemas}/part_query.tunables.json +0 -0
@@ -1,13 +1,13 @@
1
1
  import { Buffer } from 'node:buffer'
2
2
 
3
- import { canonicalStringify } from '../core/canonical_json.mjs'
4
- import { hashFromPubKeyHex, parseEntityHash } from '../core/entity_id.mjs'
5
- import { assertSafeEvfsLogicalPath } from '../core/evfs_logical_path.mjs'
6
- import { isHex64, normalizeHex64 } from '../core/hexIds.mjs'
7
- import { sign, verify } from '../crypto/crypto.mjs'
3
+ import { canonicalStringify } from '../../core/canonical_json.mjs'
4
+ import { hashFromPubKeyHex, parseEntityHash } from '../../core/entity_id.mjs'
5
+ import { assertSafeEvfsLogicalPath } from '../../core/evfs_logical_path.mjs'
6
+ import { isHex64, normalizeHex64 } from '../../core/hexIds.mjs'
7
+ import { sign, verify } from '../../crypto/crypto.mjs'
8
+ import { putFileManifest, saveFileManifest } from '../evfs.mjs'
8
9
 
9
- import { putFileManifest, saveFileManifest } from './evfs.mjs'
10
- import { normalizeFileManifest, publicTransferKeyDescriptor } from './manifest.mjs'
10
+ import { normalizeFileManifest, publicTransferKeyDescriptor } from './normalize.mjs'
11
11
 
12
12
  /** 实体公开 manifest 签名域 */
13
13
  export const ENTITY_PUBLIC_MANIFEST_DOMAIN = 'fount-entity-public-manifest'
@@ -32,11 +32,11 @@ export function publicManifestSignBytes(fields) {
32
32
  }
33
33
 
34
34
  /**
35
- * @param {import('./manifest.mjs').FileManifest} manifest 清单
35
+ * @param {import('./normalize.mjs').FileManifest} manifest 清单
36
36
  * @param {number} publishedAt 发布时间
37
37
  * @param {Uint8Array | Buffer} entitySecretKey recovery 私钥种子
38
38
  * @param {string} entityPubKeyHex recovery 公钥 hex
39
- * @returns {Promise<import('./manifest.mjs').FileManifest>} 带 publicSig 的清单
39
+ * @returns {Promise<import('./normalize.mjs').FileManifest>} 带 publicSig 的清单
40
40
  */
41
41
  export async function attachPublicManifestSig(manifest, publishedAt, entitySecretKey, entityPubKeyHex) {
42
42
  const pubKeyHex = normalizeHex64(entityPubKeyHex)
@@ -63,7 +63,7 @@ export async function attachPublicManifestSig(manifest, publishedAt, entitySecre
63
63
 
64
64
  /**
65
65
  * @param {unknown} input 原始 manifest
66
- * @returns {Promise<import('./manifest.mjs').FileManifest | null>} 验签通过的清单;非法为 null
66
+ * @returns {Promise<import('./normalize.mjs').FileManifest | null>} 验签通过的清单;非法为 null
67
67
  */
68
68
  export async function verifySignedPublicManifest(input) {
69
69
  const manifest = normalizeFileManifest(input)
@@ -105,7 +105,7 @@ export async function verifySignedPublicManifest(input) {
105
105
 
106
106
  /**
107
107
  * @param {object | null | undefined} localManifest 本地已有清单
108
- * @param {import('./manifest.mjs').FileManifest} incoming 入站已验签清单
108
+ * @param {import('./normalize.mjs').FileManifest} incoming 入站已验签清单
109
109
  * @returns {boolean} 是否应以 incoming 覆盖本地缓存
110
110
  */
111
111
  export function shouldPreferIncomingPublicManifest(localManifest, incoming) {
@@ -125,7 +125,7 @@ export function shouldPreferIncomingPublicManifest(localManifest, incoming) {
125
125
  * @param {Uint8Array | Buffer} parameters.entitySecretKey recovery 私钥种子
126
126
  * @param {string} parameters.entityPubKeyHex recovery 公钥 hex
127
127
  * @param {number} [parameters.publishedAt] 发布时间(默认 Date.now)
128
- * @returns {Promise<import('./manifest.mjs').FileManifest>} 已签名并落盘的公开清单
128
+ * @returns {Promise<import('./normalize.mjs').FileManifest>} 已签名并落盘的公开清单
129
129
  */
130
130
  export async function publishPublicFile(parameters) {
131
131
  const {
@@ -8,8 +8,8 @@ import {
8
8
  } from '../crypto/key.mjs'
9
9
 
10
10
  /**
11
- * @typedef {import('./manifest.mjs').FileManifest} FileManifest
12
- * @typedef {import('./manifest.mjs').TransferKeyDescriptor} TransferKeyDescriptor
11
+ * @typedef {import('./manifest/normalize.mjs').FileManifest} FileManifest
12
+ * @typedef {import('./manifest/normalize.mjs').TransferKeyDescriptor} TransferKeyDescriptor
13
13
  */
14
14
 
15
15
  /**
@@ -1,7 +1,7 @@
1
1
  /** @type {Map<string, { getGroupFileMasterKey?: (replicaUsername: string, groupId: string, keyGeneration?: number) => Promise<Buffer | string | null>, getVaultMasterKey?: (replicaUsername: string, entityHash: string) => Promise<Buffer | string | null> }>} */
2
2
  const transferDependenciesByOwner = new Map()
3
3
 
4
- /** @type {Map<string, (replicaUsername: string, manifest: import('./manifest.mjs').FileManifest) => Promise<Buffer | null>>} */
4
+ /** @type {Map<string, (replicaUsername: string, manifest: import('./manifest/normalize.mjs').FileManifest) => Promise<Buffer | null>>} */
5
5
  const dagPlaintextReadersByOwner = new Map()
6
6
 
7
7
  /**
@@ -17,19 +17,19 @@ export function registerTransferKeyDependencies(ownerId, dependencies) {
17
17
 
18
18
  /**
19
19
  * @param {string} ownerId 注册方
20
- * @param {(replicaUsername: string, manifest: import('./manifest.mjs').FileManifest) => Promise<Buffer | null>} reader dagParts 明文读取
20
+ * @param {(replicaUsername: string, manifest: import('./manifest/normalize.mjs').FileManifest) => Promise<Buffer | null>} reader dagParts 明文读取
21
21
  * @returns {void}
22
22
  */
23
23
  export function registerDagManifestPlaintextReader(ownerId, reader) {
24
24
  dagPlaintextReadersByOwner.set(String(ownerId), reader)
25
25
  }
26
26
 
27
- /** @type {Array<{ ownerId: string, match: (manifest: import('./manifest.mjs').FileManifest) => boolean }>} */
27
+ /** @type {Array<{ ownerId: string, match: (manifest: import('./manifest/normalize.mjs').FileManifest) => boolean }>} */
28
28
  const manifestOwnerMatchers = []
29
29
 
30
30
  /**
31
31
  * @param {string} ownerId 注册方
32
- * @param {(manifest: import('./manifest.mjs').FileManifest) => boolean} match manifest 匹配谓词
32
+ * @param {(manifest: import('./manifest/normalize.mjs').FileManifest) => boolean} match manifest 匹配谓词
33
33
  * @returns {void}
34
34
  */
35
35
  export function registerManifestOwnerMatcher(ownerId, match) {
@@ -59,7 +59,7 @@ export function unregisterTransferKeyDependencies(ownerId) {
59
59
 
60
60
  /**
61
61
  * 从 manifest 推断 transfer key 注册方 id(按 registerManifestOwnerMatcher 注册顺序匹配)。
62
- * @param {import('./manifest.mjs').FileManifest} manifest 清单
62
+ * @param {import('./manifest/normalize.mjs').FileManifest} manifest 清单
63
63
  * @returns {string | null} 所有者 id
64
64
  */
65
65
  export function resolveManifestTransferOwnerId(manifest) {
@@ -70,7 +70,7 @@ export function resolveManifestTransferOwnerId(manifest) {
70
70
 
71
71
  /**
72
72
  * @param {string} [ownerId] 显式注册方;省略时按 manifest 推断
73
- * @param {import('./manifest.mjs').FileManifest} [manifest] 用于推断 ownerId
73
+ * @param {import('./manifest/normalize.mjs').FileManifest} [manifest] 用于推断 ownerId
74
74
  * @returns {{ getGroupFileMasterKey?: (replicaUsername: string, groupId: string, keyGeneration?: number) => Promise<Buffer | string | null>, getVaultMasterKey?: (replicaUsername: string, entityHash: string) => Promise<Buffer | string | null> }} 依赖
75
75
  */
76
76
  export function resolveTransferKeyDependencies(ownerId, manifest) {
@@ -81,7 +81,7 @@ export function resolveTransferKeyDependencies(ownerId, manifest) {
81
81
 
82
82
  /**
83
83
  * @param {string} replicaUsername 副本用户名
84
- * @param {import('./manifest.mjs').FileManifest} manifest 清单
84
+ * @param {import('./manifest/normalize.mjs').FileManifest} manifest 清单
85
85
  * @returns {Promise<Buffer | null>} 明文;无 reader 或未命中为 null
86
86
  */
87
87
  export async function readDagManifestPlaintext(replicaUsername, manifest) {
package/index.mjs CHANGED
@@ -32,7 +32,6 @@ import {
32
32
  unlockReputationMax,
33
33
  } from './node/reputation_sync.mjs'
34
34
  import { getRoutingProfile, setRoutingProfile } from './node/routing_profile.mjs'
35
- import { createScopedLinkRoom } from './rooms/scoped_link.mjs'
36
35
  import { createGroupLinkSet } from './transport/group_link_set.mjs'
37
36
  import {
38
37
  configureLinkRegistry,
@@ -42,9 +41,10 @@ import {
42
41
  reloadDiscoveryRelays,
43
42
  sendToNodeLink,
44
43
  } from './transport/link_registry.mjs'
44
+ import { attachNodeScopeDefaultFeatures } from './transport/node_scope/features.mjs'
45
+ import { ensureNodeScope } from './transport/node_scope/wire.mjs'
46
+ import { createScopedLinkRoom } from './transport/scoped_link.mjs'
45
47
  import {
46
- attachUserRoomDefaultWires,
47
- ensureNodeScope,
48
48
  ensureUserRoom,
49
49
  getUserRoomSlot,
50
50
  } from './transport/user_room.mjs'
@@ -54,7 +54,7 @@ import {
54
54
  */
55
55
  export {
56
56
  attachReputationSyncWire,
57
- attachUserRoomDefaultWires,
57
+ attachNodeScopeDefaultFeatures,
58
58
  configureLinkRegistry,
59
59
  createGroupLinkSet,
60
60
  createScopedLinkRoom,
package/infra/service.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  import { isNodeInitialized } from '../node/instance.mjs'
3
3
  import { setOverlayRateGate, clearOverlayRateGate } from '../overlay/index.mjs'
4
4
  import { getLinkRegistry } from '../transport/link_registry.mjs'
5
- import { attachNodeScopeMailbox } from '../transport/node_scope.mjs'
5
+ import { attachNodeScopeMailbox } from '../transport/node_scope/features.mjs'
6
6
 
7
7
  import { attachInfraDebugLog, detachInfraDebugLog } from './debug_log.mjs'
8
8
  import {
@@ -9,9 +9,6 @@ import { ensureNodeSeed, getNodeHash } from '../node/identity.mjs'
9
9
 
10
10
  import { normalizeDtlsFingerprint } from './sdp_fingerprint.mjs'
11
11
 
12
- /** advert / peer-hint 端口规范化(re-export,调用方可直接从 core/tcp_port 导入) */
13
- export const normalizeAdvertTcpPort = normalizeTcpPort
14
-
15
12
  /**
16
13
  * Link 握手签名域标识符。
17
14
  */
@@ -23,7 +23,6 @@ import {
23
23
  * @returns {Promise<string | null>} 已验证的 remote nodeHash
24
24
  */
25
25
  async function resolveRemoteNodeHashForPeer(username, peerId) {
26
- void username
27
26
  if (!peerId) return null
28
27
  const entry = activeLinkRoster().find(row => row.peerId === peerId)
29
28
  const remote = entry?.remoteNodeHash?.trim().toLowerCase()
@@ -51,7 +50,6 @@ async function resolveRelayHopForIngress(record) {
51
50
  * @returns {Promise<{ maxHop: number, relayFanoutTrusted: number, relayFanoutNormal: number, wantFanout: number, batterySaver: boolean }>} 按在线 peer 数缩放的路由
52
51
  */
53
52
  async function resolveRouting(username) {
54
- void username
55
53
  const { batterySaver, mailbox } = getNodeTransportSettings()
56
54
  const peerCount = activeLinkRoster().length
57
55
  return resolveMailboxRoutingForPeerCount(peerCount, mailbox, batterySaver)
package/mailbox/parse.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  import { assertHex64 } from '../core/hexIds.mjs'
2
+ import { isPlainObject } from '../core/object.mjs'
2
3
  import {
3
4
  assertMailboxPubKeyHash,
4
5
  assertMailboxRecordShape,
5
6
  } from '../schemas/mailbox.mjs'
6
- import { isPlainObject } from '../wire/ingress.mjs'
7
7
 
8
8
  /**
9
9
  * @typedef {import('../schemas/mailbox.mjs').MailboxWireErr} MailboxParseErr
package/mailbox/store.mjs CHANGED
@@ -11,19 +11,10 @@ import {
11
11
  sortMailboxForRetention,
12
12
  } from './importance.mjs'
13
13
  import {
14
- MAX_BUCKET_BYTES,
15
- MAX_BUCKET_ENTRIES,
16
- mailboxBucketKey,
17
- mailboxRecordBytes,
18
14
  pruneMailboxBuckets,
19
15
  pruneMailboxGlobalFair,
20
16
  } from './prune.mjs'
21
17
 
22
- /**
23
- * mailbox 桶裁剪与计量辅助(re-export)。
24
- */
25
- export { MAX_BUCKET_BYTES, MAX_BUCKET_ENTRIES, mailboxBucketKey, mailboxRecordBytes }
26
-
27
18
  /** 单条 mailbox envelope JSON 字节上限 */
28
19
  export const MAX_ENTRY_BYTES = 256 * 1024
29
20
 
package/mailbox/wire.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ import { subscribeWire } from '../wire/subscribe.mjs'
2
+
1
3
  import {
2
4
  ingestMailboxGive,
3
5
  ingestMailboxPut,
@@ -5,23 +7,30 @@ import {
5
7
  } from './deliver_or_store.mjs'
6
8
  import { parseMailboxGive, parseMailboxPut, parseMailboxWant } from './parse.mjs'
7
9
 
8
- /**
9
- * @typedef {{ replicaUsername?: string }} MailboxWireContext
10
- */
10
+ /** @typedef {import('../wire/adapter.mjs').WireContext} MailboxWireContext */
11
+ /** @typedef {import('../wire/adapter.mjs').WireAdapter} WireAdapter */
11
12
 
12
13
  /**
13
14
  * @param {MailboxWireContext} wireContext 入站上下文
14
- * @param {{ on: (name: string, handler: (payload: unknown, peerId: string) => void) => (() => void) | void, send: (name: string, payload: unknown, peerId: string | null) => void }} wire Trystero 适配器
15
+ * @param {WireAdapter} wire action 表
15
16
  * @returns {() => void} 取消挂载的 dispose
16
17
  */
17
18
  export function attachMailboxWire(wireContext, wire) {
18
- const offs = [
19
- wire.on('mailbox_put', (payload, peerId) => {
19
+ return subscribeWire(wire, {
20
+ /**
21
+ * @param {unknown} payload mailbox_put 载荷
22
+ * @param {string} peerId 对端 nodeHash
23
+ */
24
+ mailbox_put(payload, peerId) {
20
25
  const put = parseMailboxPut(payload)
21
26
  if (!put.ok) return
22
27
  void ingestMailboxPut(wireContext, put.value, peerId).catch(error => console.error('mailbox: put ingest failed', error))
23
- }),
24
- wire.on('mailbox_want', (payload, peerId) => {
28
+ },
29
+ /**
30
+ * @param {unknown} payload mailbox_want 载荷
31
+ * @param {string} peerId 对端 nodeHash
32
+ */
33
+ mailbox_want(payload, peerId) {
25
34
  const want = parseMailboxWant(payload)
26
35
  if (!want.ok) return
27
36
  void respondMailboxWant(want.value, (giveWire, targetPeerId) => {
@@ -30,15 +39,14 @@ export function attachMailboxWire(wireContext, wire) {
30
39
  }
31
40
  catch { /* disconnected */ }
32
41
  }, peerId).catch(error => console.error('mailbox: want failed', error))
33
- }),
34
- wire.on('mailbox_give', payload => {
42
+ },
43
+ /**
44
+ * @param {unknown} payload mailbox_give 载荷
45
+ */
46
+ mailbox_give(payload) {
35
47
  const give = parseMailboxGive(payload)
36
48
  if (!give.ok) return
37
49
  void ingestMailboxGive(wireContext, give.value).catch(error => console.error('mailbox: give ingest failed', error))
38
- }),
39
- ]
40
- return () => {
41
- for (const off of offs)
42
- try { off?.() } catch { /* ignore */ }
43
- }
50
+ },
51
+ })
44
52
  }
@@ -2,7 +2,9 @@ import { randomUUID } from 'node:crypto'
2
2
 
3
3
  import { isHex64, normalizeHex64 } from '../core/hexIds.mjs'
4
4
  import { sendToNodeLink } from '../transport/link_registry.mjs'
5
- import { attachNodeScopeFeature, ensureNodeScope, getNodeScopeWire } from '../transport/node_scope.mjs'
5
+ import { attachNodeScopeFeature } from '../transport/node_scope/features.mjs'
6
+ import { ensureNodeScope, getNodeScopeWire } from '../transport/node_scope/wire.mjs'
7
+ import { subscribeWire } from '../wire/subscribe.mjs'
6
8
 
7
9
  import {
8
10
  loadReputation,
@@ -226,34 +228,36 @@ function exportScoreTable() {
226
228
  export function attachReputationSyncWire() {
227
229
  ensureNodeScope()
228
230
  if (!getNodeScopeWire()) throw new Error('p2p: attachReputationSyncWire requires node scope wire')
229
- const dispose = attachNodeScopeFeature('rep_sync', wire => {
230
- const offs = [
231
- wire.on('rep_sync_req', (payload, peerId) => {
232
- const requester = normalizeHex64(peerId)
233
- if (!requester || !getReputationExportAllowlist().includes(requester)) return
234
- try {
235
- wire.send('rep_sync_res', {
236
- requestId: payload?.requestId,
237
- ...exportScoreTable(),
238
- }, peerId)
239
- }
240
- catch { /* disconnected */ }
241
- }),
242
- wire.on('rep_sync_res', (payload, peerId) => {
243
- const requestId = String(payload?.requestId || '')
244
- const pending = pendingPulls.get(requestId)
245
- if (!pending) return
246
- if (normalizeHex64(peerId) !== pending.donor) return
247
- clearTimeout(pending.timer)
248
- pendingPulls.delete(requestId)
249
- pending.resolve(payload)
250
- }),
251
- ]
252
- return () => {
253
- for (const off of offs)
254
- try { off?.() } catch { /* ignore */ }
255
- }
256
- })
231
+ const dispose = attachNodeScopeFeature('rep_sync', wire => subscribeWire(wire, {
232
+ /**
233
+ * @param {unknown} payload rep_sync_req 载荷
234
+ * @param {string} peerId 对端 nodeHash
235
+ */
236
+ rep_sync_req(payload, peerId) {
237
+ const requester = normalizeHex64(peerId)
238
+ if (!requester || !getReputationExportAllowlist().includes(requester)) return
239
+ try {
240
+ wire.send('rep_sync_res', {
241
+ requestId: payload?.requestId,
242
+ ...exportScoreTable(),
243
+ }, peerId)
244
+ }
245
+ catch { /* disconnected */ }
246
+ },
247
+ /**
248
+ * @param {unknown} payload rep_sync_res 载荷
249
+ * @param {string} peerId 对端 nodeHash
250
+ */
251
+ rep_sync_res(payload, peerId) {
252
+ const requestId = String(payload?.requestId || '')
253
+ const pending = pendingPulls.get(requestId)
254
+ if (!pending) return
255
+ if (normalizeHex64(peerId) !== pending.donor) return
256
+ clearTimeout(pending.timer)
257
+ pendingPulls.delete(requestId)
258
+ pending.resolve(payload)
259
+ },
260
+ }))
257
261
  syncWireDisposers.add(dispose)
258
262
  return () => {
259
263
  if (!syncWireDisposers.delete(dispose)) return
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steve02081504/fount-p2p",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "description": "fount federation P2P layer — link, trust graph, mailbox, DAG, EVFS.",
5
5
  "keywords": [
6
6
  "network",
@@ -11,7 +11,7 @@
11
11
  "type": "module",
12
12
  "repository": {
13
13
  "type": "git",
14
- "url": "https://github.com/steve02081504/fount-p2p.git",
14
+ "url": "git+https://github.com/steve02081504/fount-p2p.git",
15
15
  "directory": "."
16
16
  },
17
17
  "engines": {
@@ -31,7 +31,7 @@
31
31
  "!scripts/**"
32
32
  ],
33
33
  "bin": {
34
- "fount-p2p": "./infra/cli.mjs"
34
+ "fount-p2p": "infra/cli.mjs"
35
35
  },
36
36
  "exports": {
37
37
  ".": "./index.mjs",
@@ -41,19 +41,15 @@
41
41
  "./crypto": "./crypto/crypto.mjs",
42
42
  "./crypto/*": "./crypto/*.mjs",
43
43
  "./wire/*": "./wire/*.mjs",
44
+ "./wire/part/*": "./wire/part/*.mjs",
44
45
  "./schemas/*": "./schemas/*.mjs",
45
46
  "./node/*": "./node/*.mjs",
46
47
  "./discovery": "./discovery/index.mjs",
47
48
  "./discovery/bt": "./discovery/bt/index.mjs",
48
49
  "./discovery/bt/*": "./discovery/bt/*.mjs",
49
50
  "./discovery/*": "./discovery/*.mjs",
50
- "./transport/link_registry": "./transport/link_registry.mjs",
51
- "./transport/user_room": "./transport/user_room.mjs",
52
- "./transport/group_link_set": "./transport/group_link_set.mjs",
53
- "./transport/node_scope": "./transport/node_scope.mjs",
54
- "./transport/room_scopes": "./transport/room_scopes.mjs",
55
- "./transport/remote_user_room": "./transport/remote_user_room.mjs",
56
- "./rooms/*": "./rooms/*.mjs",
51
+ "./transport/node_scope/*": "./transport/node_scope/*.mjs",
52
+ "./transport/*": "./transport/*.mjs",
57
53
  "./overlay": "./overlay/index.mjs",
58
54
  "./overlay/*": "./overlay/*.mjs",
59
55
  "./trust_graph/*": "./trust_graph/*.mjs",
@@ -62,7 +58,11 @@
62
58
  "./dag/*": "./dag/*.mjs",
63
59
  "./timeline/*": "./timeline/*.mjs",
64
60
  "./files/*": "./files/*.mjs",
61
+ "./files/chunk/*": "./files/chunk/*.mjs",
62
+ "./files/manifest/*": "./files/manifest/*.mjs",
63
+ "./files/fed/*": "./files/fed/*.mjs",
65
64
  "./federation/*": "./federation/*.mjs",
65
+ "./federation/part_query/*": "./federation/part_query/*.mjs",
66
66
  "./governance/*": "./governance/*.mjs",
67
67
  "./registries/*": "./registries/*.mjs",
68
68
  "./permissions": "./permissions/index.mjs",
@@ -1,4 +1,18 @@
1
- /** @typedef {import('../wire/part_invoke.mjs').PartInvokeResponse} PartInvokeResponse */
1
+ /**
2
+ * @typedef {{ message: string, code: string }} PartInvokeError
3
+ */
4
+
5
+ /**
6
+ * @typedef {object} PartInvokeResultResponse
7
+ * @property {unknown} result
8
+ */
9
+
10
+ /**
11
+ * @typedef {object} PartInvokeErrorResponse
12
+ * @property {PartInvokeError} error
13
+ */
14
+
15
+ /** @typedef {PartInvokeResultResponse | PartInvokeErrorResponse} PartInvokeResponse */
2
16
 
3
17
  /**
4
18
  * @typedef {{
@@ -29,7 +43,7 @@ const deliveryHandlers = new Map()
29
43
  * @returns {void}
30
44
  */
31
45
  export function registerRpcInboundHandler(type, handler) {
32
- rpcHandlers.set(String(type || '').trim(), handler)
46
+ rpcHandlers.set(type, handler)
33
47
  }
34
48
 
35
49
  /**
@@ -38,7 +52,7 @@ export function registerRpcInboundHandler(type, handler) {
38
52
  * @returns {void}
39
53
  */
40
54
  export function registerDeliveryInboundHandler(type, handler) {
41
- deliveryHandlers.set(String(type || '').trim(), handler)
55
+ deliveryHandlers.set(type, handler)
42
56
  }
43
57
 
44
58
  /**
@@ -47,9 +61,7 @@ export function registerDeliveryInboundHandler(type, handler) {
47
61
  * @returns {Promise<PartInvokeResponse | null>} 处理器返回值
48
62
  */
49
63
  export async function dispatchRpcInbound(inboundContext, message) {
50
- const type = String(message?.type || '').trim()
51
- if (!type) return null
52
- const handler = rpcHandlers.get(type)
64
+ const handler = rpcHandlers.get(message.type)
53
65
  if (!handler) return null
54
66
  return handler(inboundContext, message)
55
67
  }
@@ -60,9 +72,7 @@ export async function dispatchRpcInbound(inboundContext, message) {
60
72
  * @returns {Promise<void>}
61
73
  */
62
74
  export async function dispatchDeliveryInbound(inboundContext, message) {
63
- const type = String(message?.type || '').trim()
64
- if (!type) return
65
- const handler = deliveryHandlers.get(type)
75
+ const handler = deliveryHandlers.get(message.type)
66
76
  if (!handler) return
67
77
  await handler(inboundContext, message)
68
78
  }
@@ -1,5 +1,3 @@
1
- import { normalizePartpath } from '../wire/part_invoke.mjs'
2
-
3
1
  /** @type {Map<string, string>} shell 逻辑名 → partpath */
4
2
  const shellPartpaths = new Map()
5
3
 
@@ -10,10 +8,7 @@ const shellPartpaths = new Map()
10
8
  * @returns {void}
11
9
  */
12
10
  export function registerShellPartpath(shellKey, partpath) {
13
- const key = String(shellKey || '').trim()
14
- const path = normalizePartpath(partpath)
15
- if (!key || !path) throw new Error('invalid_shell_partpath_registration')
16
- shellPartpaths.set(key, path)
11
+ shellPartpaths.set(shellKey, partpath)
17
12
  }
18
13
 
19
14
  /**
@@ -21,7 +16,7 @@ export function registerShellPartpath(shellKey, partpath) {
21
16
  * @returns {void}
22
17
  */
23
18
  export function unregisterShellPartpath(shellKey) {
24
- shellPartpaths.delete(String(shellKey || '').trim())
19
+ shellPartpaths.delete(shellKey)
25
20
  }
26
21
 
27
22
  /**
@@ -29,7 +24,7 @@ export function unregisterShellPartpath(shellKey) {
29
24
  * @returns {string} 已注册的 partpath
30
25
  */
31
26
  export function getShellPartpath(shellKey) {
32
- const path = shellPartpaths.get(String(shellKey || '').trim())
27
+ const path = shellPartpaths.get(shellKey)
33
28
  if (!path) throw new Error(`shell partpath not registered: ${shellKey}`)
34
29
  return path
35
30
  }
@@ -1,5 +1,5 @@
1
1
  import { assertHex64, isHex64, isSignatureHex128, normalizeHex64 } from '../core/hexIds.mjs'
2
- import { isPlainObject } from '../wire/ingress.mjs'
2
+ import { isPlainObject } from '../core/object.mjs'
3
3
 
4
4
  const MAX_DISCOVERY_ADS = 64
5
5
 
@@ -2,8 +2,8 @@
2
2
  * 联邦补拉 attestation / HPKE 响应 wire 解析(无 attestation/envelope 即丢弃)。
3
3
  */
4
4
  import { isHex64, isSignatureHex128, normalizeHex64 } from '../core/hexIds.mjs'
5
+ import { isPlainObject } from '../core/object.mjs'
5
6
  import { EVENT_ID_HEX } from '../dag/index.mjs'
6
- import { isPlainObject } from '../wire/ingress.mjs'
7
7
 
8
8
  /** @typedef {{ requesterPubKeyHash: string, groupId: string, requestId: string, timestamp: number, wantIds?: string[], signature: string }} PullAttestation */
9
9
 
@@ -2,9 +2,10 @@ import { Buffer } from 'node:buffer'
2
2
 
3
3
  import { canonicalStringify } from '../core/canonical_json.mjs'
4
4
  import { isHex64, normalizeHex64 } from '../core/hexIds.mjs'
5
- import { isPlainObject } from '../wire/ingress.mjs'
6
- import { normalizePartpath } from '../wire/part_invoke.mjs'
7
- import partQueryTunables from '../wire/part_query.tunables.json' with { type: 'json' }
5
+ import { isPlainObject } from '../core/object.mjs'
6
+ import { parsePartpath } from '../core/partpath.mjs'
7
+
8
+ import partQueryTunables from './part_query.tunables.json' with { type: 'json' }
8
9
 
9
10
  /**
10
11
  * @typedef {{
@@ -100,7 +101,7 @@ export function parsePartQueryReq(value, tunables = partQueryTunables) {
100
101
  if (!requestId) return null
101
102
  const originNodeHash = normalizeHex64(value.originNodeHash)
102
103
  if (!isHex64(originNodeHash)) return null
103
- const partpath = normalizePartpath(value.partpath)
104
+ const partpath = parsePartpath(value.partpath)
104
105
  if (!partpath) return null
105
106
  const kind = String(value.kind || '').trim()
106
107
  if (!kind) return null
@@ -143,7 +144,7 @@ export function parsePartQueryRes(value, tunables = partQueryTunables) {
143
144
  * @returns {string | null} 规范化三元组的缓存材料;非法 null
144
145
  */
145
146
  export function normalizePartQueryCacheMaterial(partpath, kind, query) {
146
- const path = normalizePartpath(partpath)
147
+ const path = parsePartpath(partpath)
147
148
  const k = String(kind || '').trim()
148
149
  if (!path || !k) return null
149
150
  if (measureJsonBytes(query) > partQueryTunables.maxQueryBytes) return null
@@ -1,9 +1,9 @@
1
+ import { noteAdvertPeerHints } from '../discovery/advert_peer_hints.mjs'
1
2
  import { listVisibleNodeHashes, startGroupPresence, watchVerifiedGroupAdverts } from '../discovery/index.mjs'
2
3
  import { loadPeerPoolView } from '../node/network.mjs'
3
4
  import { loadReputation } from '../node/reputation_store.mjs'
4
5
  import { emitSafe } from '../utils/emit_safe.mjs'
5
6
 
6
- import { applyAdvertPeerHints } from './advert_ingest.mjs'
7
7
  import { getLinkRegistry } from './link_registry.mjs'
8
8
  import { resolveFederationPoolLimits, selectLinkTargetsFromMembers } from './peer_pool.mjs'
9
9
  import { loadTransportTunables } from './tunables.mjs'
@@ -208,7 +208,7 @@ export function createGroupLinkSet(options) {
208
208
  registerCleanup(await watchVerifiedGroupAdverts(roomSecret, async (verifiedNodeHash, body, meta) => {
209
209
  if (verifiedNodeHash === selfNodeHash) return
210
210
  if (!allowNode(verifiedNodeHash)) return
211
- applyAdvertPeerHints(verifiedNodeHash, body, meta)
211
+ noteAdvertPeerHints(verifiedNodeHash, body, meta)
212
212
  notePeerCandidate(verifiedNodeHash)
213
213
  }))
214
214
 
@@ -2,6 +2,7 @@ import { Buffer } from 'node:buffer'
2
2
 
3
3
  import { compareHex64Asc, normalizeHex64 } from '../core/hexIds.mjs'
4
4
  import { keyPairFromSeed } from '../crypto/crypto.mjs'
5
+ import { noteAdvertPeerHints } from '../discovery/advert_peer_hints.mjs'
5
6
  import { watchVerifiedNodeAdvert, setDiscoveryLinkDialer, prepareConnectToNode } from '../discovery/index.mjs'
6
7
  import { setDiscoveryPeerClueListener } from '../discovery/peer_clue.mjs'
7
8
  import { listLinkProviders } from '../link/providers/index.mjs'
@@ -13,7 +14,6 @@ import { ms } from '../utils/duration.mjs'
13
14
  import { emitSafe } from '../utils/emit_safe.mjs'
14
15
  import { createLruMap } from '../utils/lru.mjs'
15
16
 
16
- import { applyAdvertPeerHints } from './advert_ingest.mjs'
17
17
  import { DEFAULT_ICE_SERVERS } from './ice_servers.mjs'
18
18
  import { createMeshKeepalive } from './mesh_keepalive.mjs'
19
19
  import { createOfferAnswerDial } from './offer_answer.mjs'
@@ -650,7 +650,7 @@ export function createLinkRegistry(options = {}) {
650
650
  async watchNodeAdvert(nodeHash, onAdvert) {
651
651
  const hash = normalizeHex64(nodeHash)
652
652
  return await watchVerifiedNodeAdvert(hash, async (verifiedNodeHash, body, meta) => {
653
- applyAdvertPeerHints(verifiedNodeHash, body, meta)
653
+ noteAdvertPeerHints(verifiedNodeHash, body, meta)
654
654
  recentAdverts.touch(verifiedNodeHash, Date.now())
655
655
  dialCooldown.delete(verifiedNodeHash)
656
656
  await Promise.resolve(onAdvert(verifiedNodeHash, body))