Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show full rpc backend version #1294

Merged
merged 4 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions add-on/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,9 @@
"message": "The URL of your local Kubo RPC",
"description": "A label in Node status section of Browser Action pop-up (panel_statusApiAddressTitle)"
},
"panel_statusGatewayVersion": {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ this was not used anywhere

"message": "version",
"description": "A label in Node status section of Browser Action pop-up (panel_statusGatewayVersion)"
},
"panel_statusGatewayVersionTitle": {
"message": "The version of IPFS your local node is using",
"description": "A label in Node status section of Browser Action pop-up (panel_statusGatewayVersionTitle)"
"panel_kuboRpcBackendVersionTitle": {
"message": "The version of IPFS backend this extension talks to over Kubo RPC API",
"description": "A label in Node status section of Browser Action pop-up (panel_kuboRpcBackendVersionTitle)"
},
"panel_statusSwarmPeers": {
"message": "Peers",
Expand Down
30 changes: 22 additions & 8 deletions add-on/src/lib/ipfs-companion.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,25 @@ export default async function init (inQuickImport = false) {
handler(message)
}

async function fetchKuboRpcBackendVersion () {
// prefer AgentVersion string from 'ipfs id' , but if that fails, use 'ipfs version'
try {
const id = await ipfs.id()
if (id) {
return id.agentVersion
}
} catch (_) {
try {
const v = await ipfs.version()
if (v) {
return v.commit ? v.version + '/' + v.commit : v.version
}
} catch (_) {
}
}
return null
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❗ woah

Suggested change
try {
const id = await ipfs.id()
if (id) {
return id.agentVersion
}
} catch (_) {
try {
const v = await ipfs.version()
if (v) {
return v.commit ? v.version + '/' + v.commit : v.version
}
} catch (_) {
}
}
return null
}
try {
const { agentVersion } = await ipfs.id()
if (agentVersion) {
return agentVersion
}
const {version, commit} = await ipfs.version()
return [version, commit].filter(Boolean).join('/')
} catch (_) {}
return null
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, applied in 90f32c8


async function sendStatusUpdateToBrowserAction () {
if (!browserActionPort) return
const currentTab = await browser.tabs.query({ active: true, currentWindow: true }).then(tabs => tabs[0])
Expand All @@ -250,14 +269,9 @@ export default async function init (inQuickImport = false) {
newVersion: state.dismissedUpdate !== version ? version : null,
currentTab
}
try {
const v = await ipfs.version()
if (v) {
info.gatewayVersion = v.commit ? v.version + '/' + v.commit : v.version
}
} catch (error) {
info.gatewayVersion = null
}

info.kuboRpcBackendVersion = await fetchKuboRpcBackendVersion()

if (state.active && info.currentTab) {
const url = info.currentTab.url
info.isIpfsContext = ipfsPathValidator.isIpfsPageActionsContext(url)
Expand Down
4 changes: 2 additions & 2 deletions add-on/src/popup/browser-action/gateway-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function statusEntry ({ label, labelLegend, value, check, itemClass = '', valueC

export default function gatewayStatus ({
gatewayAddress,
gatewayVersion,
kuboRpcBackendVersion,
ipfsApiUrl,
swarmPeers
}) {
Expand All @@ -42,7 +42,7 @@ export default function gatewayStatus ({
label: 'panel_statusApiAddress',
labelLegend: 'panel_statusApiAddressTitle',
value: api,
check: gatewayVersion
check: kuboRpcBackendVersion
})}
</ul>
`
Expand Down
11 changes: 5 additions & 6 deletions add-on/src/popup/browser-action/ipfs-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@ function statusEntry ({ label, labelLegend, title, value, check, valueClass = ''
value = value || value === 0 ? value : offline
return html`
<div title="${labelLegend}" class="ma0 pa0" style="line-height: 0.25">
<span class="f7 tr monospace force-select-all ${valueClass}" title="${title}">${value.substring(0, 13)}</span>
<span class="f7 tr monospace force-select-all ${valueClass}" title="${title}">${value.substring(0, 18)}</span>
lidel marked this conversation as resolved.
Show resolved Hide resolved
</div>
`
}

export default function ipfsVersion ({
gatewayVersion
kuboRpcBackendVersion
}) {
return html`
${statusEntry({
label: 'panel_statusGatewayVersion',
title: browser.i18n.getMessage('panel_statusGatewayVersionTitle'),
value: gatewayVersion,
check: gatewayVersion
title: browser.i18n.getMessage('panel_kuboRpcBackendVersionTitle'),
value: kuboRpcBackendVersion,
check: kuboRpcBackendVersion
})}
`
}
8 changes: 4 additions & 4 deletions add-on/src/popup/browser-action/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default (state, emitter) => {
publicSubdomainGatewayUrl: null,
gatewayAddress: null,
swarmPeers: null,
gatewayVersion: null,
kuboRpcBackendVersion: null,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ renamed to make it clear this is version of RPC backend, and not gateway.
(if we want versioned gateways, we should expose gateway-conformance version, but this is future work)

isApiAvailable: false,
// isRedirectContext
currentTab: null,
Expand Down Expand Up @@ -215,7 +215,7 @@ export default (state, emitter) => {
if (!state.active) {
state.gatewayAddress = state.pubGwURLString
state.ipfsApiUrl = null
state.gatewayVersion = null
state.kuboRpcBackendVersion = null
state.swarmPeers = null
state.isIpfsOnline = false
}
Expand All @@ -241,13 +241,13 @@ export default (state, emitter) => {
state.isApiAvailable = state.active && !browser.extension.inIncognitoContext // https://github.com/ipfs-shipyard/ipfs-companion/issues/243
state.swarmPeers = !state.active || status.peerCount === -1 ? null : status.peerCount
state.isIpfsOnline = state.active && status.peerCount > -1
state.gatewayVersion = state.active && status.gatewayVersion ? status.gatewayVersion : null
state.kuboRpcBackendVersion = state.active && status.kuboRpcBackendVersion ? status.kuboRpcBackendVersion : null
state.ipfsApiUrl = state.active ? status.apiURLString : null
} else {
state.ipfsNodeType = 'external'
state.swarmPeers = null
state.isIpfsOnline = false
state.gatewayVersion = null
state.kuboRpcBackendVersion = null
state.isIpfsContext = false
state.isRedirectContext = false
}
Expand Down