Skip to content

Commit 218c472

Browse files
committed
fetchnodelogs p2p method
1 parent b8a24d9 commit 218c472

4 files changed

Lines changed: 60 additions & 6 deletions

File tree

src/@types/Provider.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,21 @@ export const PROTOCOL_COMMANDS = {
127127
GET_LOGS: 'getLogs',
128128
JOBS: 'jobs'
129129
}
130+
131+
export interface NodeLogsParams {
132+
logId?: string
133+
startTime?: string
134+
endTime?: string
135+
maxLogs?: number
136+
moduleName?: string
137+
level?: string
138+
page?: number
139+
}
140+
141+
export interface NodeLogEntry {
142+
timestamp: string
143+
level: string
144+
moduleName: string
145+
message: string
146+
meta?: Record<string, any>
147+
}

src/services/providers/BaseProvider.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import {
2121
dockerRegistryAuth,
2222
DownloadResponse,
2323
NodeStatus,
24-
NodeComputeJob
24+
NodeComputeJob,
25+
NodeLogsParams,
26+
NodeLogEntry
2527
} from '../../@types/index.js'
2628
import { type DDO, type ValidateMetadata } from '@oceanprotocol/ddo-js'
2729
import { decodeJwt } from '../../utils/Jwt.js'
@@ -439,7 +441,7 @@ export class BaseProvider {
439441
level?: string,
440442
page?: number,
441443
signal?: AbortSignal
442-
): Promise<any> {
444+
): Promise<NodeLogEntry[]> {
443445
return this.getImpl(nodeUri).downloadNodeLogs(
444446
nodeUri,
445447
signer,
@@ -486,6 +488,20 @@ export class BaseProvider {
486488
return this.p2pProvider.getMultiaddrFromPeerId(peerId)
487489
}
488490

491+
/**
492+
* Fetch node logs via P2P with a pre-signed payload.
493+
* For auto-signed log fetching (HTTP or P2P), use downloadNodeLogs().
494+
*/
495+
public async fetchNodeLogs(
496+
nodeUri: string | Multiaddr[],
497+
address: string,
498+
signature: string,
499+
nonce: string,
500+
logParams?: NodeLogsParams
501+
): Promise<NodeLogEntry[]> {
502+
return this.p2pProvider.fetchNodeLogs(nodeUri, address, signature, nonce, logParams)
503+
}
504+
489505
public async fetchConfig(
490506
nodeUri: string | Multiaddr[],
491507
payload: Record<string, any>

src/services/providers/HttpProvider.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import {
2020
dockerRegistryAuth,
2121
ComputeResultStream,
2222
NodeStatus,
23-
NodeComputeJob
23+
NodeComputeJob,
24+
NodeLogEntry
2425
} from '../../@types/index.js'
2526
import { PROTOCOL_COMMANDS } from '../../@types/Provider.js'
2627
import { type DDO, type ValidateMetadata } from '@oceanprotocol/ddo-js'
@@ -1439,7 +1440,7 @@ export class HttpProvider {
14391440
level?: string,
14401441
page?: number,
14411442
signal?: AbortSignal
1442-
): Promise<any> {
1443+
): Promise<NodeLogEntry[]> {
14431444
const providerEndpoints = await this.getEndpoints(nodeUri)
14441445
const serviceEndpoints = await this.getServiceEndpoints(nodeUri, providerEndpoints)
14451446

src/services/providers/P2pProvider.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import {
3636
NodeStatus,
3737
NodeComputeJob
3838
} from '../../@types/index.js'
39-
import { PROTOCOL_COMMANDS } from '../../@types/Provider.js'
39+
import { PROTOCOL_COMMANDS, NodeLogsParams, NodeLogEntry } from '../../@types/Provider.js'
4040
import { type DDO, type ValidateMetadata } from '@oceanprotocol/ddo-js'
4141
import { signRequest } from '../../utils/SignatureUtils.js'
4242
import { getConsumerAddress, getSignature, getAuthorization } from './BaseProvider.js'
@@ -1404,7 +1404,7 @@ export class P2pProvider {
14041404
level?: string,
14051405
page?: number,
14061406
signal?: AbortSignal
1407-
): Promise<any> {
1407+
): Promise<NodeLogEntry[]> {
14081408
const consumerAddress = await signer.getAddress()
14091409
const nonce = ((await this.getNonce(nodeUri, consumerAddress, signal)) + 1).toString()
14101410
const signature = await this.getSignature(signer, nonce, PROTOCOL_COMMANDS.GET_LOGS)
@@ -1424,6 +1424,25 @@ export class P2pProvider {
14241424
return this.sendP2pCommand(nodeUri, PROTOCOL_COMMANDS.GET_LOGS, body, signer, signal)
14251425
}
14261426

1427+
/**
1428+
* Fetch node logs via P2P with a pre-signed payload.
1429+
* P2P only — use downloadNodeLogs() for the auto-signed variant.
1430+
*/
1431+
public async fetchNodeLogs(
1432+
nodeUri: string | Multiaddr[],
1433+
address: string,
1434+
signature: string,
1435+
nonce: string,
1436+
logParams?: NodeLogsParams
1437+
): Promise<NodeLogEntry[]> {
1438+
return this.sendP2pCommand(nodeUri, PROTOCOL_COMMANDS.GET_LOGS, {
1439+
address,
1440+
signature,
1441+
nonce,
1442+
...logParams
1443+
})
1444+
}
1445+
14271446
/**
14281447
* Fetch node configuration via P2P. Accepts a pre-signed payload —
14291448
* the caller is responsible for nonce retrieval and signing.

0 commit comments

Comments
 (0)