Add device diagnostics and P2P access controls

This commit is contained in:
Jonathan Sykes
2026-10-14 02:45:33 +08:00
parent e9a597c415
commit 5177a4d441
11 changed files with 147 additions and 8 deletions

View File

@@ -41,10 +41,12 @@ export function registerP2pRoutes(app, deps) {
if (!m) return null;
const d = await p2pDb.getDevice(m[1]);
if (!d || !same(d.secret_hash, sha(m[2]))) return null;
if (d.banned_at) return { ...d, _banned: true };
return d;
}
const requireDevice = async (c, next) => {
const d = await deviceOf(c);
if (d?._banned) return c.json({ ok: false, error: 'device access revoked' }, 403);
if (!d) return c.json({ ok: false, error: 'unknown device' }, 401);
c.set('device', d);
await next();
@@ -67,6 +69,7 @@ export function registerP2pRoutes(app, deps) {
deviceId, secretHash: sha(secret),
fingerprint: String(body.fingerprint || '').slice(0, 128) || null,
profile: String(body.profile || '').slice(0, 64) || null,
userAgent: String(c.req.header('user-agent') || '').slice(0, 500),
now: t,
});
return c.json({ ok: true, deviceId, secret });