Restore an evicted server copy from an online holder

This commit is contained in:
Claude
2026-09-30 07:58:42 +00:00
parent 6d3cefa874
commit 60a28fc593
8 changed files with 112 additions and 7 deletions

View File

@@ -85,3 +85,21 @@ test('holders payload: persistent rows, online flag, stale marker, share-off hid
]);
expect(JSON.stringify(p)).not.toContain('dev_'); // never leak device ids
});
test('rehydrator asks one online sharing holder, once per 10 min, only when the server has no copy', async () => {
const { createRehydrator } = await import('./p2p-hub.js');
const sent = [];
let t = NOW;
let serverHas = false;
const hub = { isOnline: (d) => d === 'dev_000000000000000a' || d === 'dev_000000000000000c', send: (d, m) => { sent.push([d, m]); return true; } };
const rehydrate = createRehydrator({ p2pDb, hub, hasServerCopy: async () => serverHas, now: () => t });
expect(await rehydrate('dQw4w9WgXcQ')).toBe(true);
// c is online but has sharing off; a is online and shares.
expect(sent).toEqual([['dev_000000000000000a', { type: 'upload-request', videoId: 'dQw4w9WgXcQ', cid: CID }]]);
expect(await rehydrate('dQw4w9WgXcQ')).toBe(true); // recently asked — no second message
expect(sent.length).toBe(1);
t += 11 * 60_000;
serverHas = true;
expect(await rehydrate('dQw4w9WgXcQ')).toBe(false); // server copy is back
expect(await rehydrate('unknownVid1')).toBe(false); // nobody holds it
});