@steve02081504/fount-p2p 0.0.10 → 0.0.12

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 (60) hide show
  1. package/README.md +25 -7
  2. package/core/bytes_codec.mjs +65 -10
  3. package/core/tcp_port.mjs +1 -1
  4. package/crypto/checkpoint_sign.mjs +2 -2
  5. package/dag/canonicalize_row.mjs +3 -3
  6. package/dag/index.mjs +2 -3
  7. package/discovery/bt/index.mjs +5 -5
  8. package/discovery/bt/probe_child.mjs +20 -0
  9. package/discovery/bt/runtime.mjs +59 -15
  10. package/discovery/index.mjs +45 -48
  11. package/discovery/mdns.mjs +72 -17
  12. package/discovery/nostr.mjs +165 -129
  13. package/federation/chunk_fetch_pending.mjs +4 -5
  14. package/federation/dag_order_cache.mjs +1 -1
  15. package/federation/entity_key_chain.mjs +3 -4
  16. package/federation/topo_order_memo.mjs +11 -4
  17. package/files/chunk_fetch.mjs +2 -2
  18. package/files/evfs.mjs +2 -2
  19. package/link/channel_mux.mjs +10 -10
  20. package/link/frame.mjs +76 -124
  21. package/link/handshake.mjs +5 -5
  22. package/link/pipe.mjs +49 -75
  23. package/link/providers/ble_gatt.mjs +15 -27
  24. package/link/providers/index.mjs +7 -9
  25. package/link/providers/lan_tcp.mjs +18 -33
  26. package/link/providers/link_id_pipe.mjs +46 -0
  27. package/link/providers/webrtc.mjs +43 -52
  28. package/link/rtc.mjs +21 -9
  29. package/mailbox/deliver_or_store.mjs +1 -1
  30. package/node/identity.mjs +4 -4
  31. package/node/network.mjs +9 -9
  32. package/overlay/index.mjs +13 -13
  33. package/package.json +3 -2
  34. package/rooms/scoped_link.mjs +22 -38
  35. package/schemas/discovery.mjs +1 -2
  36. package/schemas/federation_pull.mjs +2 -2
  37. package/schemas/part_query.mjs +1 -1
  38. package/schemas/remote_event.mjs +1 -1
  39. package/transport/advert_ingest.mjs +20 -0
  40. package/transport/group_link_set.mjs +26 -45
  41. package/transport/ice_servers.mjs +12 -3
  42. package/transport/link_registry.mjs +181 -523
  43. package/transport/offer_answer.mjs +194 -0
  44. package/transport/peer_pool.mjs +53 -64
  45. package/transport/remote_user_room.mjs +13 -15
  46. package/transport/rtc_connection_budget.mjs +18 -4
  47. package/transport/runtime_bootstrap.mjs +369 -0
  48. package/transport/signal_crypto.mjs +104 -0
  49. package/transport/user_room.mjs +22 -15
  50. package/trust_graph/send.mjs +1 -1
  51. package/utils/emit_safe.mjs +11 -0
  52. package/utils/shuffle.mjs +13 -0
  53. package/utils/ttl_map.mjs +29 -4
  54. package/wire/ingress.mjs +1 -1
  55. package/wire/part_ingress.mjs +6 -8
  56. package/wire/part_invoke.mjs +4 -4
  57. package/wire/part_query.mjs +2 -3
  58. package/wire/part_query.tunables.json +6 -1
  59. package/wire/part_query_cache.mjs +1 -1
  60. package/wire/volatile_signature.mjs +1 -1
@@ -116,7 +116,7 @@ export async function handleIncomingPartInvokeRequest(wireContext, payload, wire
116
116
  if (!partpath || !payload.requestId) return
117
117
 
118
118
  const response = await dispatchPartInvoke(wireContext, { ...payload, peerId })
119
- if (response == null || !isPartInvokeResponse(response)) return
119
+ if (!isPartInvokeResponse(response)) return
120
120
 
121
121
  try {
122
122
  wire.send('part_invoke_response', {
@@ -159,14 +159,12 @@ export async function handleIncomingPartInvokeFireAndForget(wireContext, payload
159
159
  * @returns {void}
160
160
  */
161
161
  export function handleIncomingPartInvokeResponse(payload, peerId = '') {
162
- const pending = pendingPartInvoke.get(String(payload?.requestId || ''))
163
- if (!pending || payload?.response == null) return
164
- const peerKey = String(peerId || payload?.nodeHash || '').trim()
165
- if (peerKey) {
166
- if (pending.respondedPeers.has(peerKey)) return
167
- pending.respondedPeers.add(peerKey)
162
+ const pending = pendingPartInvoke.get(payload.requestId)
163
+ if (!pending || !isPartInvokeResponse(payload.response)) return
164
+ if (peerId) {
165
+ if (pending.respondedPeers.has(peerId)) return
166
+ pending.respondedPeers.add(peerId)
168
167
  }
169
- if (!isPartInvokeResponse(payload.response)) return
170
168
  pending.responses.push(payload.response)
171
169
  if (pending.responses.length >= pending.maxResponses) pending.finish()
172
170
  }
@@ -45,9 +45,9 @@ export function isPartInvokeResponse(value) {
45
45
  const err = value.error
46
46
  return isPlainObject(err)
47
47
  && typeof err.message === 'string'
48
- && err.message.length > 0
49
48
  && typeof err.code === 'string'
50
- && err.code.length > 0
49
+ && err.message.length
50
+ && err.code.length
51
51
  }
52
52
  return true
53
53
  }
@@ -57,7 +57,7 @@ export function isPartInvokeResponse(value) {
57
57
  * @returns {unknown | null} 成功 `result`;失败或空为 null
58
58
  */
59
59
  export function unwrapPartInvokeResult(response) {
60
- if (!response || !isPartInvokeResponse(response) || 'error' in response) return null
60
+ if (!isPartInvokeResponse(response) || 'error' in response) return null
61
61
  return response.result ?? null
62
62
  }
63
63
 
@@ -77,5 +77,5 @@ export function normalizePartpath(value) {
77
77
  export function isPartInvoke(value) {
78
78
  if (!isPlainObject(value)) return false
79
79
  const { kind } = value
80
- return typeof kind === 'string' && kind.length > 0
80
+ return typeof kind === 'string' && kind.length
81
81
  }
@@ -132,7 +132,7 @@ export function registerQueryInboundHandler(partpath, kind, handler, state = def
132
132
  * @returns {number} 等待下游超时
133
133
  */
134
134
  export function resolvePartQueryHopTimeoutMs(ttl, tunables = partQueryTunables) {
135
- const table = Array.isArray(tunables.hopTimeoutMs) ? tunables.hopTimeoutMs : [1000, 2500, 4000, 6000]
135
+ const table = tunables.hopTimeoutMs || [1000, 2500, 4000, 6000]
136
136
  const index = Math.max(0, Math.min(table.length - 1, Math.floor(ttl) - 1))
137
137
  return Math.max(1, Math.floor(Number(table[index]) || tunables.defaultTimeoutMs || 4000))
138
138
  }
@@ -176,8 +176,7 @@ export function mergeQueryRows(lists, maxHits, rowKey) {
176
176
  async function runLocalHandler(state, queryContext, partpath, kind, query) {
177
177
  const handler = state.handlers.get(handlerKey(partpath, kind))
178
178
  if (!handler) return []
179
- const rows = await handler(queryContext, query)
180
- return Array.isArray(rows) ? rows : []
179
+ return await handler(queryContext, query) || []
181
180
  }
182
181
 
183
182
  /**
@@ -9,6 +9,11 @@
9
9
  "dedupeMaxSize": 4000,
10
10
  "cacheTtlMs": 300000,
11
11
  "cacheMaxKeys": 256,
12
- "hopTimeoutMs": [1000, 2500, 4000, 6000],
12
+ "hopTimeoutMs": [
13
+ 1000,
14
+ 2500,
15
+ 4000,
16
+ 6000
17
+ ],
13
18
  "defaultTimeoutMs": 4000
14
19
  }
@@ -77,7 +77,7 @@ export function createPartQueryCache(options = {}) {
77
77
  */
78
78
  set(partpath, kind, query, rows, now = Date.now()) {
79
79
  const key = partQueryCacheKey(partpath, kind, query)
80
- if (!key || !Array.isArray(rows)) return
80
+ if (!key || !rows) return
81
81
  sweep(now)
82
82
  map.touch(key, {
83
83
  rows: rows.slice(0, maxHits),
@@ -17,7 +17,7 @@ export const MAX_STREAM_VOLATILE_SLICES = 256
17
17
  * @returns {object[] | null} 合法切片或 null
18
18
  */
19
19
  export function boundStreamSlices(slices) {
20
- if (!Array.isArray(slices) || slices.length > MAX_STREAM_VOLATILE_SLICES) return null
20
+ if (!slices?.length || slices.length > MAX_STREAM_VOLATILE_SLICES) return null
21
21
  return slices
22
22
  }
23
23