@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.
- package/README.md +25 -7
- package/core/bytes_codec.mjs +65 -10
- package/core/tcp_port.mjs +1 -1
- package/crypto/checkpoint_sign.mjs +2 -2
- package/dag/canonicalize_row.mjs +3 -3
- package/dag/index.mjs +2 -3
- package/discovery/bt/index.mjs +5 -5
- package/discovery/bt/probe_child.mjs +20 -0
- package/discovery/bt/runtime.mjs +59 -15
- package/discovery/index.mjs +45 -48
- package/discovery/mdns.mjs +72 -17
- package/discovery/nostr.mjs +165 -129
- package/federation/chunk_fetch_pending.mjs +4 -5
- package/federation/dag_order_cache.mjs +1 -1
- package/federation/entity_key_chain.mjs +3 -4
- package/federation/topo_order_memo.mjs +11 -4
- package/files/chunk_fetch.mjs +2 -2
- package/files/evfs.mjs +2 -2
- package/link/channel_mux.mjs +10 -10
- package/link/frame.mjs +76 -124
- package/link/handshake.mjs +5 -5
- package/link/pipe.mjs +49 -75
- package/link/providers/ble_gatt.mjs +15 -27
- package/link/providers/index.mjs +7 -9
- package/link/providers/lan_tcp.mjs +18 -33
- package/link/providers/link_id_pipe.mjs +46 -0
- package/link/providers/webrtc.mjs +43 -52
- package/link/rtc.mjs +21 -9
- package/mailbox/deliver_or_store.mjs +1 -1
- package/node/identity.mjs +4 -4
- package/node/network.mjs +9 -9
- package/overlay/index.mjs +13 -13
- package/package.json +3 -2
- package/rooms/scoped_link.mjs +22 -38
- package/schemas/discovery.mjs +1 -2
- package/schemas/federation_pull.mjs +2 -2
- package/schemas/part_query.mjs +1 -1
- package/schemas/remote_event.mjs +1 -1
- package/transport/advert_ingest.mjs +20 -0
- package/transport/group_link_set.mjs +26 -45
- package/transport/ice_servers.mjs +12 -3
- package/transport/link_registry.mjs +181 -523
- package/transport/offer_answer.mjs +194 -0
- package/transport/peer_pool.mjs +53 -64
- package/transport/remote_user_room.mjs +13 -15
- package/transport/rtc_connection_budget.mjs +18 -4
- package/transport/runtime_bootstrap.mjs +369 -0
- package/transport/signal_crypto.mjs +104 -0
- package/transport/user_room.mjs +22 -15
- package/trust_graph/send.mjs +1 -1
- package/utils/emit_safe.mjs +11 -0
- package/utils/shuffle.mjs +13 -0
- package/utils/ttl_map.mjs +29 -4
- package/wire/ingress.mjs +1 -1
- package/wire/part_ingress.mjs +6 -8
- package/wire/part_invoke.mjs +4 -4
- package/wire/part_query.mjs +2 -3
- package/wire/part_query.tunables.json +6 -1
- package/wire/part_query_cache.mjs +1 -1
- package/wire/volatile_signature.mjs +1 -1
package/wire/part_ingress.mjs
CHANGED
|
@@ -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 (
|
|
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(
|
|
163
|
-
if (!pending || payload
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
}
|
package/wire/part_invoke.mjs
CHANGED
|
@@ -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.
|
|
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 (!
|
|
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
|
|
80
|
+
return typeof kind === 'string' && kind.length
|
|
81
81
|
}
|
package/wire/part_query.mjs
CHANGED
|
@@ -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 =
|
|
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
|
-
|
|
180
|
-
return Array.isArray(rows) ? rows : []
|
|
179
|
+
return await handler(queryContext, query) || []
|
|
181
180
|
}
|
|
182
181
|
|
|
183
182
|
/**
|
|
@@ -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 || !
|
|
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 (!
|
|
20
|
+
if (!slices?.length || slices.length > MAX_STREAM_VOLATILE_SLICES) return null
|
|
21
21
|
return slices
|
|
22
22
|
}
|
|
23
23
|
|