fix(swarmtop): expose and render full peer identity/details from proc surfaces
This commit is contained in:
+46
-4
@@ -768,10 +768,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 : {}
|
||||
}
|
||||
|
||||
function bareP2pFmtClock(ms) {
|
||||
const d = new Date(typeof ms === 'number' ? ms : Date.now())
|
||||
const z = (n) => (n < 10 ? '0' : '') + n
|
||||
@@ -978,16 +1005,31 @@ async function run(ctx, argv) {
|
||||
lines.push('Peers:')
|
||||
const peers = Array.isArray(snap.peers) ? snap.peers : []
|
||||
if (!peers.length) lines.push(' (no peers reported)')
|
||||
for (const p of peers.slice(0, 24)) {
|
||||
for (const p of peers.slice(0, 12)) {
|
||||
const key =
|
||||
p && typeof p === 'object' && typeof p.remotePublicKey === 'string'
|
||||
? p.remotePublicKey.slice(0, 16)
|
||||
? p.remotePublicKey
|
||||
: '?'
|
||||
const state =
|
||||
p && typeof p === 'object' && typeof p.state === 'string'
|
||||
? p.state
|
||||
: 'connected'
|
||||
lines.push(' ' + key + ' ' + state)
|
||||
const addr =
|
||||
p && typeof p === 'object' && p.endpoint && typeof p.endpoint === 'object'
|
||||
? String(p.endpoint.address || p.remoteAddress || '?') +
|
||||
':' +
|
||||
String(p.endpoint.port || p.remotePort || '?')
|
||||
: String(p?.remoteAddress || '?') + ':' + String(p?.remotePort || '?')
|
||||
const osHint =
|
||||
p &&
|
||||
typeof p === 'object' &&
|
||||
p.peerOs &&
|
||||
typeof p.peerOs === 'object' &&
|
||||
p.peerOs.osHint
|
||||
? String(p.peerOs.osHint)
|
||||
: 'unknown'
|
||||
lines.push(' pubkey: ' + key)
|
||||
lines.push(' state=' + state + ' endpoint=' + addr + ' os=' + osHint)
|
||||
}
|
||||
lines.push('')
|
||||
lines.push('Recent events:')
|
||||
|
||||
Reference in New Issue
Block a user