Repository navigation
http root endpoint returns node status #1622
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
Open
alexcos20
wants to merge
6
commits into
feat/scoped-auth-tokens
Choose a base branch
from
feature/unify_status_endpoints
base: feat/scoped-auth-tokens
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b0046ea
http root endpoint returns node status
alexcos20 10b053d
Add 'feat/scoped-auth-tokens' based PRs to docker build
alexcos20 a0dae37
resolve comments
alexcos20 cc1613d
Merge branch 'feature/unify_status_endpoints' of https://github.com/o…
alexcos20 7e691ed
fix http decryptor
alexcos20 6c25eca
Update CI workflow to checkout specific branch
alexcos20 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,42 @@ | ||
| import express from 'express' | ||
| import { HTTP_LOGGER } from '../../utils/logging/common.js' | ||
| import express, { Request, Response } from 'express' | ||
| import { Readable } from 'stream' | ||
| import { StatusHandler } from '../core/handler/statusHandler.js' | ||
| import { PROTOCOL_COMMANDS } from '../../utils/constants.js' | ||
| import { StatusCommand } from '../../@types/commands.js' | ||
|
|
||
| export const rootEndpointRoutes = express.Router() | ||
|
|
||
| rootEndpointRoutes.get('/', (req, res) => { | ||
| const config = req.oceanNode.getConfig() | ||
| if (!config.supportedNetworks) { | ||
| HTTP_LOGGER.debug(`Supported networks not defined`) | ||
| // The root endpoint is the HTTP mirror of the `status` command (the same object returned over | ||
| // P2P / `/directCommand`). It defaults to the BASIC status to keep this frequently-hit path | ||
| // cheap for health checks; `?detailed=true` opts into the extended status (c2dClusters + | ||
| // supportedSchemas), mirroring the P2P `status` vs `detailedStatus` split. `?clientChallenge=...` | ||
| // (OJ-03) is forwarded so a client can prove the node controls the key its peerId commits to. | ||
| rootEndpointRoutes.get('/', async (req: Request, res: Response): Promise<void> => { | ||
| const detailed = String(req.query.detailed).toLowerCase() === 'true' | ||
| const clientChallenge = req.query.clientChallenge | ||
| ? String(req.query.clientChallenge) | ||
| : undefined | ||
| const command: StatusCommand = { | ||
| command: PROTOCOL_COMMANDS.STATUS, | ||
| node: req.oceanNode.getKeyManager().getPeerId().toString(), | ||
| detailed, | ||
| clientChallenge, | ||
| caller: req.caller | ||
| } | ||
| const result = await new StatusHandler(req.oceanNode).handle(command) | ||
| // Preserve the handler's HTTP status for BOTH streamed and non-streamed responses: a | ||
| // rate-limit / error response (e.g. buildRateLimitReachedResponse) carries a stream AND a | ||
| // non-200 httpStatus, so the status must be set before piping, not only on the error branch. | ||
| res.status(result.status.httpStatus) | ||
| if (result.stream) { | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| // The success path emits a formatted JSON string stream; pipe it straight through instead | ||
| // of buffering and re-serializing via res.json(). Non-200 stream bodies (e.g. the rate-limit | ||
| // text) are left as the default content type. | ||
| if (result.status.httpStatus === 200) { | ||
| res.type('application/json') | ||
| } | ||
| ;(result.stream as Readable).pipe(res) | ||
| } else { | ||
| res.send(result.status.error) | ||
| } | ||
| const keyManager = req.oceanNode.getKeyManager() | ||
| res.json({ | ||
| nodeId: keyManager.getPeerId().toString(), | ||
| chainIds: config.supportedNetworks ? Object.keys(config.supportedNetworks) : [], | ||
| providerAddress: keyManager.getEthAddress(), | ||
| nodePublicKey: keyManager.getPublicKey(), | ||
| software: 'Ocean-Node', | ||
| version: '0.0.1' | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not build the cached status identity from the caller-supplied
node.GET /returns the cachedidfromsrc/components/core/utils/statusHandler.ts. That cache is built once, and itsidcomes from thenodeIdargument (lines 140-142). The first status request sets this value, and later requests do not change it.On an HTTP-only node,
POST /directCommandrunsstatuslocally and does not comparenodewith the local peerId. A request such as{"command":"status","node":"<other peerId>"}can therefore set the cachedidto another node's identity. An unchallengedGET /then returns that identity until the process restarts. Theidoverride inhandle()applies only to challenged responses.Set the cached
idfrom this node's own key manager. Do not take it from the command target. KeepnodeIdout of the cached object so that unchallenged responses always report the serving node's identity.Build detailed cluster data per request in
status().In
src/components/core/utils/statusHandler.ts, the detailed branch writesc2dClustersto the shared module-levelnodeStatusobject (lines 215-216). It then awaits engine calls. A concurrent basic request can delete that property (line 300) during those awaits. The result depends on when the delete occurs:nodeStatus.c2dClusters.push(...)evaluates its receiver,pushthrows aTypeError. The catch block suppresses it and the remaining engines are skipped.pushargument list,pushwrites to an array that is no longer attached tonodeStatus. The clusters are lost without an error.In both cases, the detailed response omits
c2dClusters.Build the cluster list in a local variable before the awaits. Return a per-request response object that includes that list. Do not write per-request cluster data to the shared
nodeStatusobject. Themaintenanceblock already follows this pattern (lines 205-209 and 306). CopyingnodeStatusafterstatus()returns does not fix the problem, because the data is lost during the awaits insidestatus().There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see a0dae37