@steve02081504/fount-p2p 0.0.7 → 0.0.8

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.
@@ -330,6 +330,14 @@ export function createBluetoothDiscoveryProvider() {
330
330
  id: 'bt',
331
331
  priority: 20,
332
332
  caps: { canDiscover: true, canSignal: true, canRelay: false },
333
+ /**
334
+ * 是否具备对该 peer 的 GATT 信令能力(需未过期 BT peer hint)。
335
+ * @param {string} to 目标 nodeHash
336
+ * @returns {boolean} 有 hint 则可尝试
337
+ */
338
+ canSignalTo(to) {
339
+ return !!getBtPeerHint(to)
340
+ },
333
341
  /**
334
342
  * 广播指定 topic 的 advert。
335
343
  * @param {string} topic advert 主题
@@ -1,4 +1,4 @@
1
- /** @typedef {{ id: string, priority: number, caps: { canDiscover?: boolean, canSignal?: boolean, canRelay?: boolean }, advertise?: (topic: string, bytes: Uint8Array) => (() => void) | Promise<() => void>, subscribe?: (topic: string, onAdvert: (bytes: Uint8Array, meta?: object) => void) => (() => void) | Promise<() => void>, sendSignal?: (topic: string, to: string, bytes: Uint8Array) => void | Promise<void>, onSignal?: (topic: string, onSignal: (bytes: Uint8Array, meta?: object) => void) => (() => void) | Promise<() => void> }} DiscoveryProvider */
1
+ /** @typedef {{ id: string, priority: number, caps: { canDiscover?: boolean, canSignal?: boolean, canRelay?: boolean }, advertise?: (topic: string, bytes: Uint8Array) => (() => void) | Promise<() => void>, subscribe?: (topic: string, onAdvert: (bytes: Uint8Array, meta?: object) => void) => (() => void) | Promise<() => void>, canSignalTo?: (to: string) => boolean, sendSignal?: (topic: string, to: string, bytes: Uint8Array) => void | Promise<void>, onSignal?: (topic: string, onSignal: (bytes: Uint8Array, meta?: object) => void) => (() => void) | Promise<() => void> }} DiscoveryProvider */
2
2
 
3
3
  /** @type {Map<string, DiscoveryProvider>} */
4
4
  const providers = new Map()
@@ -95,15 +95,14 @@ export async function sendSignal(topic, to, bytes) {
95
95
  if (!capable.length) throw new Error('p2p: no discovery provider can signal')
96
96
  let sent = false
97
97
  let lastError = null
98
- for (const provider of capable)
99
- try {
100
- await Promise.resolve(provider.sendSignal(topic, to, bytes))
101
- sent = true
102
- }
103
- catch (error) {
104
- lastError = error
105
- console.warn(`p2p: discovery signal failed for ${provider.id}`, error)
106
- }
98
+ for (const provider of capable) if (provider?.canSignalTo?.(to)) try {
99
+ await Promise.resolve(provider.sendSignal(topic, to, bytes))
100
+ sent = true
101
+ }
102
+ catch (error) {
103
+ lastError = error
104
+ console.warn(`p2p: discovery signal failed for ${provider.id}`, error)
105
+ }
107
106
  if (!sent) throw lastError || new Error('p2p: no discovery provider delivered signal')
108
107
  }
109
108
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steve02081504/fount-p2p",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "fount federation P2P layer — link, trust graph, mailbox, DAG, EVFS.",
5
5
  "keywords": [
6
6
  "network",