fix(swarmtop): expose and render full peer identity/details from proc surfaces
This commit is contained in:
@@ -297,10 +297,37 @@ async function bareP2pReadSwarmSnapshot(ctx) {
|
||||
if (typeof snap.peerCount === 'number') out.peerCount = snap.peerCount
|
||||
if (typeof snap.topicCount === 'number') out.topicCount = snap.topicCount
|
||||
const peers = Array.isArray(snap.peers) ? snap.peers : []
|
||||
out.peers = peers.slice(0, 128)
|
||||
const detailsRaw = await bareP2pReadJson(ctx, '/proc/bare_os/peer_details.json')
|
||||
const details =
|
||||
detailsRaw && typeof detailsRaw === 'object' && Array.isArray(detailsRaw.peers)
|
||||
? detailsRaw.peers
|
||||
: []
|
||||
/** @type {Map<string, Record<string, unknown>>} */
|
||||
const byKey = new Map()
|
||||
for (const d of details) {
|
||||
if (!d || typeof d !== 'object') continue
|
||||
const rk = typeof d.remotePublicKey === 'string' ? d.remotePublicKey : ''
|
||||
const pid = typeof d.peerId === 'string' ? d.peerId : ''
|
||||
if (rk) byKey.set('k:' + rk, d)
|
||||
if (pid) byKey.set('p:' + pid, d)
|
||||
}
|
||||
const merged = []
|
||||
for (const p of peers) {
|
||||
if (!p || typeof p !== 'object') continue
|
||||
const rk = typeof p.remotePublicKey === 'string' ? p.remotePublicKey : ''
|
||||
const pid = typeof p.peerId === 'string' ? p.peerId : ''
|
||||
const d = (rk && byKey.get('k:' + rk)) || (pid && byKey.get('p:' + pid)) || null
|
||||
merged.push(d && typeof d === 'object' ? { ...p, ...d } : p)
|
||||
}
|
||||
out.peers = merged.slice(0, 128)
|
||||
return out
|
||||
}
|
||||
|
||||
async function bareP2pReadProcJson(ctx, path) {
|
||||
const v = await bareP2pReadJson(ctx, path)
|
||||
return v && typeof v === 'object' ? v : {}
|
||||
}
|
||||
|
||||
async function run(ctx, argv) {
|
||||
const argv0 = argv[0] || 'hypershell-board'
|
||||
const args = argv.slice(1)
|
||||
|
||||
Reference in New Issue
Block a user