| … | … | @@ -36,12 +36,25 @@ async function main () { |
| 36 | 36 | await sleep(LOCAL ? 1500 : 5000) |
| 37 | 37 | console.log('[p2pb] relays connected:', relayCount(client.getStatus && client.getStatus())) |
| 38 | 38 | |
| 39 | const DURABILITY = process.env.DURABILITY || 'archive' // AutoHeal: ≥7 replicas across ≥4 regions, independent of this process |
| 39 | 40 | const files = SITE_FILES.map((p) => ({ path: '/' + p, content: readFileSync(join(__dir, p)) })) |
| 40 | 41 | console.log('[p2pb] publishing site drive (' + files.length + ' files)…') |
| 41 | | const drive = await client.publish(files, { appId: 'p2pbuilders-web', seed: !LOCAL, replicas: 4, ttlDays: 365 }) |
| 42 | const drive = await client.publish(files, { appId: 'p2pbuilders-web', seed: !LOCAL, replicas: 4, ttlDays: 365, durability: DURABILITY }) |
| 42 | 43 | const driveKey = drive.key.toString('hex') |
| 43 | 44 | console.log('[p2pb] site drive key:', driveKey) |
| 44 | 45 | |
| 46 | // A Hyperdrive stores file bytes in a SEPARATE content/blobs core. seed(driveKey) |
| 47 | // only advertises the metadata core, so relays hold metadata but not the files — |
| 48 | // and the drive can't be reconstructed once the publisher leaves. Seed the blobs |
| 49 | // core too so the fleet durably holds the actual content. |
| 50 | let contentKey = null |
| 51 | try { |
| 52 | await drive.ready() |
| 53 | const blobs = drive.blobs || (typeof drive.getBlobs === 'function' ? await drive.getBlobs() : null) |
| 54 | if (blobs && blobs.core) { await blobs.core.ready(); contentKey = blobs.core.key.toString('hex') } |
| 55 | } catch (e) { console.log('[p2pb] blobs-core note:', e.message) } |
| 56 | console.log('[p2pb] content/blobs core key:', contentKey || '(none — empty drive?)') |
| 57 | |
| 45 | 58 | if (LOCAL) { |
| 46 | 59 | console.log('\n[p2pb] ── LOCAL TEST (not seeded to relays, not in catalog) ──') |
| 47 | 60 | console.log('[p2pb] Open this in PearBrowser:\n\n hyper://' + driveKey + '/\n') |
| … | … | @@ -60,13 +73,43 @@ async function main () { |
| 60 | 73 | await client.publish([{ path: '/manifest.json', content: JSON.stringify(manifest, null, 2) }], |
| 61 | 74 | { appId: 'p2pbuilders-web-manifest', seed: true, replicas: 4, ttlDays: 365 }) |
| 62 | 75 | try { |
| 63 | | const res = await client.seed(Buffer.from(driveKey, 'hex'), { replicas: 4, ttlDays: 365, timeout: 30000 }) |
| 64 | | console.log('[p2pb] seed acceptances:', (res || []).length) |
| 76 | const res = await client.seed(Buffer.from(driveKey, 'hex'), { replicas: 4, ttlDays: 365, timeout: 30000, durability: DURABILITY }) |
| 77 | console.log('[p2pb] metadata seed acceptances:', (res || []).length) |
| 65 | 78 | } catch (err) { console.log('[p2pb] seed note:', err.message) } |
| 79 | if (contentKey) { |
| 80 | try { |
| 81 | const res = await client.seed(Buffer.from(contentKey, 'hex'), { replicas: 4, ttlDays: 365, timeout: 30000, durability: DURABILITY }) |
| 82 | console.log('[p2pb] content seed acceptances:', (res || []).length) |
| 83 | } catch (err) { console.log('[p2pb] content seed note:', err.message) } |
| 84 | } |
| 85 | |
| 86 | // Wait for PROOF a relay actually replicated the bytes — so durability doesn't |
| 87 | // depend on this process staying alive (archive-tier AutoHeal maintains it). |
| 88 | if (typeof client.waitForDurable === 'function') { |
| 89 | console.log('[p2pb] waiting for relay byte-replication evidence…') |
| 90 | try { |
| 91 | const durable = await client.waitForDurable(drive.key, { timeoutMs: 120000, minPeers: 1 }) |
| 92 | console.log('[p2pb] durable status:', JSON.stringify(durable)) |
| 93 | if (!durable || !durable.durable) console.warn('[p2pb] WARNING: no relay proved full replication yet; rerun or keep alive longer.') |
| 94 | } catch (err) { console.warn('[p2pb] durability check note:', err.message) } |
| 95 | } |
| 66 | 96 | |
| 67 | 97 | console.log('\n[p2pb] Live at: hyper://' + driveKey + '/\n') |
| 68 | | if (process.env.KEEP === '1') { console.log('[p2pb] staying alive so relays anchor (Ctrl-C to stop)…'); setInterval(() => {}, 1 << 30); return } |
| 69 | | await sleep(20000) |
| 98 | if (process.env.KEEP === '1') { |
| 99 | console.log('[p2pb] staying alive; polling relay durability until a relay proves it caught up…') |
| 100 | let confirmed = false |
| 101 | for (;;) { |
| 102 | if (typeof client.waitForDurable === 'function') { |
| 103 | try { |
| 104 | const d = await client.waitForDurable(drive.key, { timeoutMs: 25000, minPeers: 1 }) |
| 105 | if (d && d.durable) { if (!confirmed) console.log('[p2pb] DURABLE ✓ ' + JSON.stringify(d)); confirmed = true } |
| 106 | else console.log('[p2pb] not-yet-durable ' + JSON.stringify(d)) |
| 107 | } catch (e) { console.log('[p2pb] durability-check-error ' + e.message) } |
| 108 | } |
| 109 | await sleep(30000) |
| 110 | } |
| 111 | } |
| 112 | await sleep(8000) |
| 70 | 113 | try { if (client.destroy) await client.destroy() } catch {} |
| 71 | 114 | process.exit(0) |
| 72 | 115 | } |