Skip to content

Commit aedccce

Browse files
committed
feat: add Agent Version column to peers table
shows which IPFS implementation each peer is running (e.g., kubo/0.35.0) depends on ipfs/js-kubo-rpc-client#342
1 parent 0e00305 commit aedccce

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

public/locales/en/peers.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"localNetwork": "Local Network",
44
"nearby": "nearby",
55
"protocols": "Open streams",
6+
"agentVersion": "Agent Version",
67
"addConnection": "Add connection",
78
"insertPeerAddress": "Insert the peer address you want to connect to.",
89
"addPermanentPeer": "Add to the permanent peering configuration",

src/bundles/peer-locations.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ function createPeersLocations (opts) {
9090
)).sort()
9191
: []).join(', ')
9292

93+
// Truncate agent version as a defensive measure against excessively long strings
94+
const rawAgentVersion = peer.identify?.AgentVersion || ''
95+
const maxAgentVersionLength = 30
96+
const agentVersion = rawAgentVersion.length > maxAgentVersionLength
97+
? rawAgentVersion.substring(0, maxAgentVersionLength) + '…'
98+
: rawAgentVersion
99+
93100
return {
94101
peerId,
95102
location,
@@ -101,7 +108,8 @@ function createPeersLocations (opts) {
101108
direction,
102109
latency,
103110
isPrivate,
104-
isNearby
111+
isNearby,
112+
agentVersion
105113
}
106114
}))
107115
)

src/bundles/peers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const swarmPeersTTL = ms.seconds(10)
66
const bundle = createAsyncResourceBundle({
77
name: 'peers',
88
actionBaseType: 'PEERS',
9-
getPromise: ({ getIpfs }) => getIpfs().swarm.peers({ verbose: true, timeout: swarmPeersTTL }),
9+
getPromise: ({ getIpfs }) => getIpfs().swarm.peers({ verbose: true, identify: true, timeout: swarmPeersTTL }),
1010
staleAfter: swarmPeersTTL,
1111
persist: false,
1212
checkIfOnline: false

src/peers/PeersTable/PeersTable.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,22 @@ const protocolsCellRenderer = (t) => ({ rowData }) => {
7575
)
7676
}
7777

78+
const agentVersionCellRenderer = (t) => ({ rowData }) => {
79+
const ref = React.createRef()
80+
const { agentVersion } = rowData
81+
if (!agentVersion) return (<span className='dib o-40 no-select'>-</span>)
82+
return (
83+
<CopyToClipboard text={agentVersion} onCopy={() => copyFeedback(ref, t)}>
84+
<span
85+
ref={ref}
86+
className='copyable'
87+
title={agentVersion}>
88+
{ agentVersion }
89+
</span>
90+
</CopyToClipboard>
91+
)
92+
}
93+
7894
const connectionCellRenderer = (t) => ({ rowData }) => {
7995
const ref = React.createRef()
8096
const { address, direction, peerId } = rowData
@@ -140,7 +156,7 @@ export const PeersTable = ({ className, t, peerLocationsForSwarm, selectedPeers
140156
const filteredPeerList = useMemo(() => {
141157
const filterLower = filter.toLowerCase()
142158
if (filterLower === '') return awaitedPeerLocationsForSwarm
143-
return awaitedPeerLocationsForSwarm.filter(({ location, latency, peerId, connection, protocols }) => {
159+
return awaitedPeerLocationsForSwarm.filter(({ location, latency, peerId, connection, protocols, agentVersion }) => {
144160
if (location != null && location.toLowerCase().includes(filterLower)) {
145161
return true
146162
}
@@ -150,13 +166,15 @@ export const PeersTable = ({ className, t, peerLocationsForSwarm, selectedPeers
150166
if (peerId != null && peerId.toString().includes(filter)) {
151167
return true
152168
}
153-
console.log('connection: ', connection)
154169
if (connection != null && connection.toLowerCase().includes(filterLower)) {
155170
return true
156171
}
157172
if (protocols != null && protocols.toLowerCase().includes(filterLower)) {
158173
return true
159174
}
175+
if (agentVersion != null && agentVersion.toLowerCase().includes(filterLower)) {
176+
return true
177+
}
160178

161179
return false
162180
})
@@ -186,11 +204,12 @@ export const PeersTable = ({ className, t, peerLocationsForSwarm, selectedPeers
186204
sort={sort}
187205
sortBy={sortBy}
188206
sortDirection={sortDirection}>
189-
<Column label={t('app:terms.location')} cellRenderer={locationCellRenderer(t)} dataKey='location' width={450} className='f6 charcoal truncate pl2' />
190-
<Column label={t('app:terms.latency')} cellRenderer={latencyCellRenderer} dataKey='latency' width={200} className='f6 charcoal pl2' />
191-
<Column label={t('app:terms.peerId')} cellRenderer={peerIdCellRenderer(t)} dataKey='peerId' width={250} className='charcoal monospace truncate f6 pl2' />
192-
<Column label={t('app:terms.connection')} cellRenderer={connectionCellRenderer(t)} dataKey='connection' width={250} className='f6 charcoal truncate pl2' />
193-
<Column label={t('protocols')} cellRenderer={protocolsCellRenderer(t)} dataKey='protocols' width={520} className='charcoal monospace truncate f7 pl2' />
207+
<Column label={t('app:terms.location')} cellRenderer={locationCellRenderer(t)} dataKey='location' width={350} className='f6 charcoal truncate pl2' />
208+
<Column label={t('app:terms.latency')} cellRenderer={latencyCellRenderer} dataKey='latency' width={100} className='f6 charcoal pl2' />
209+
<Column label={t('app:terms.peerId')} cellRenderer={peerIdCellRenderer(t)} dataKey='peerId' width={200} className='charcoal monospace truncate f6 pl2' />
210+
<Column label={t('app:terms.connection')} cellRenderer={connectionCellRenderer(t)} dataKey='connection' width={200} className='f6 charcoal truncate pl2' />
211+
<Column label={t('agentVersion')} cellRenderer={agentVersionCellRenderer(t)} dataKey='agentVersion' width={250} className='charcoal monospace truncate f7 pl2' />
212+
<Column label={t('protocols')} cellRenderer={protocolsCellRenderer(t)} dataKey='protocols' width={420} className='charcoal monospace truncate f7 pl2' />
194213
</Table>
195214
</>
196215
)}

0 commit comments

Comments
 (0)