| … | … | @@ -55,6 +55,7 @@ export async function attachReplication (overlay, conn, { strategy = 'newest-win |
| 55 | 55 | const r = await overlay.fetchFile(remote.hash, { destPath: disk }) |
| 56 | 56 | if (!r) throw new Error('attachReplication: content fetch failed for ' + remote.hash) |
| 57 | 57 | await overlay.registerFile(overlayPath, disk, { contentHash: remote.hash, size: remote.size, rev: remote.rev }) |
| 58 | try { console.log(JSON.stringify({ msg: 'overlay-repl pull', path: overlayPath, hash: String(remote.hash).slice(0, 12) })) } catch {} |
| 58 | 59 | } |
| 59 | 60 | const remove = async (overlayPath) => { |
| 60 | 61 | try { fs.unlinkSync(diskFor(overlayPath)) } catch {} |
| … | … | @@ -68,7 +69,7 @@ export async function attachReplication (overlay, conn, { strategy = 'newest-win |
| 68 | 69 | if (!peerKey) return |
| 69 | 70 | if (running) { again = true; return } // coalesce concurrent triggers; re-run once if one arrived mid-flight |
| 70 | 71 | running = true |
| 71 | | try { const s = await reconcile(engine, peerKey, { strategy, pull, remove }); if (onConverge) onConverge(s) } catch {} |
| 72 | try { const s = await reconcile(engine, peerKey, { strategy, pull, remove }); try { console.log(JSON.stringify({ msg: 'overlay-repl reconcile', peer: String(peerKey).slice(0, 12), pulled: s && s.pulled, removed: s && s.removed, pushed: s && s.pushed, skipped: s && s.skipped, conflicts: s && s.conflicts, failed: s && s.failed && s.failed.length })) } catch {}; if (onConverge) onConverge(s) } catch (e) { try { console.log(JSON.stringify({ msg: 'overlay-repl reconcile ERR', error: e && e.message })) } catch {} } |
| 72 | 73 | finally { running = false; if (again) { again = false; runReconcile() } } |
| 73 | 74 | } |
| 74 | 75 | |
| … | … | @@ -79,6 +80,7 @@ export async function attachReplication (overlay, conn, { strategy = 'newest-win |
| 79 | 80 | onmessage: async (data) => { |
| 80 | 81 | if (!data || !Array.isArray(data.entries)) return |
| 81 | 82 | if (!peerKey && data.feedKey) { peerKey = String(data.feedKey); engine._peerFeeds.set(peerKey, peer) } |
| 83 | try { console.log(JSON.stringify({ msg: 'overlay-repl recv', peer: String(peerKey).slice(0, 12), entries: data.entries.length })) } catch {} |
| 82 | 84 | for (const e of data.entries) peer.add(e) |
| 83 | 85 | await runReconcile() |
| 84 | 86 | } |
| … | … | @@ -94,7 +96,7 @@ export async function attachReplication (overlay, conn, { strategy = 'newest-win |
| 94 | 96 | const entries = [] |
| 95 | 97 | for (let i = sentLen; i < end; i++) entries.push(await engine.feed.get(i)) |
| 96 | 98 | sentLen = end |
| 97 | | try { msg.send({ feedKey: engine.feedKey, entries }) } catch {} |
| 99 | try { msg.send({ feedKey: engine.feedKey, entries }); console.log(JSON.stringify({ msg: 'overlay-repl send', entries: entries.length, feedKey: String(engine.feedKey).slice(0, 12) })) } catch (e) { try { console.log(JSON.stringify({ msg: 'overlay-repl send ERR', error: e && e.message })) } catch {} } |
| 98 | 100 | } |
| 99 | 101 | await sendDelta() |
| 100 | 102 | const onAppend = () => { sendDelta().catch(() => {}) } |