Add device diagnostics and P2P access controls
This commit is contained in:
@@ -47,7 +47,7 @@ export function createP2pHub({ getDevice, authorizeProfile = async () => '', ena
|
||||
const deviceId = String(m.device || '');
|
||||
const secret = String(m.secret || '');
|
||||
const d = /^dev_[0-9a-f]{16}$/.test(deviceId) ? await getDevice(deviceId).catch(() => null) : null;
|
||||
if (!d || !same(d.secret_hash, sha(secret))) { try { ws.close(4401, 'unknown device'); } catch { /* gone */ } return; }
|
||||
if (!d || d.banned_at || !same(d.secret_hash, sha(secret))) { try { ws.close(d?.banned_at ? 4403 : 4401, d?.banned_at ? 'device banned' : 'unknown device'); } catch { /* gone */ } return; }
|
||||
ws.data.profile = await authorizeProfile(m.profile, m.profileSecret, deviceId).catch(() => '');
|
||||
ws.data.inventory = [];
|
||||
ws.data.authed = true;
|
||||
@@ -107,6 +107,8 @@ export function createP2pHub({ getDevice, authorizeProfile = async () => '', ena
|
||||
websocket: { open, message, close },
|
||||
isOnline: (deviceId) => online.has(deviceId),
|
||||
send: (deviceId, msg) => { const ws = online.get(deviceId); if (!ws) return false; send(ws, msg); return true; },
|
||||
disconnect: (deviceId) => { const ws = online.get(deviceId); if (!ws) return false; try { ws.close(4403, 'device banned'); } catch { /* gone */ } return true; },
|
||||
onlineDevices: () => [...online.keys()],
|
||||
onlineCount: () => online.size,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user