diff --git a/docs/API.md b/docs/API.md index 89a054bf9..fafcb7ea6 100644 --- a/docs/API.md +++ b/docs/API.md @@ -501,13 +501,14 @@ returns an empty object if it is valid otherwise an array with error #### Parameters -| name | type | required | description | -| ---------- | ------ | -------- | ------------------------------------------------- | -| command | string | v | command name | -| node | string | | if not present it means current node | -| id | string | v | document id or did | -| chainId | number | v | chain id of network on which document is provided | -| nftAddress | string | v | address of nft token | +| name | type | required | description | +| ---------- | -------- | -------- | ------------------------------------------------- | +| command | string | v | command name | +| node | string | | if not present it means current node | +| multiAddrs | string[] | | if passed, use this instead of peerStore & DHT | +| id | string | v | document id or did | +| chainId | number | v | chain id of network on which document is provided | +| nftAddress | string | v | address of nft token | #### Request diff --git a/src/components/P2P/index.ts b/src/components/P2P/index.ts index a58b00d35..c9311b7f9 100644 --- a/src/components/P2P/index.ts +++ b/src/components/P2P/index.ts @@ -43,7 +43,7 @@ import { GENERIC_EMOJIS, LOG_LEVELS_STR } from '../../utils/logging/Logger.js' import { INDEXER_DDO_EVENT_EMITTER } from '../Indexer/index.js' import { P2P_LOGGER } from '../../utils/logging/common.js' import { CoreHandlersRegistry } from '../core/handler/coreHandlersRegistry' -import { type Multiaddr, multiaddr } from '@multiformats/multiaddr' +import { Multiaddr, multiaddr } from '@multiformats/multiaddr' // import { getIPv4, getIPv6 } from '../../utils/ip.js' const DEFAULT_OPTIONS = { @@ -608,7 +608,8 @@ export class OceanP2P extends EventEmitter { async sendTo( peerName: string, message: string, - sink: any + sink: any, + multiAddrs?: string[] ): Promise { P2P_LOGGER.logMessage('SendTo() node ' + peerName + ' task: ' + message, true) @@ -630,7 +631,17 @@ export class OceanP2P extends EventEmitter { response.status.error = 'Invalid peer' return response } - const multiaddrs: Multiaddr[] = await this.getPeerMultiaddrs(peerName) + let multiaddrs: Multiaddr[] = [] + + if (!multiAddrs || multiAddrs.length < 1) { + // if they are no forced multiaddrs, try to find node multiaddr from peerStore/dht + multiaddrs = await this.getPeerMultiaddrs(peerName) + } else { + // just used what we were instructed to use + for (const addr of multiAddrs) { + multiaddrs.push(new Multiaddr(addr)) + } + } if (multiaddrs.length < 1) { response.status.httpStatus = 404 response.status.error = `Cannot find any address to dial for peer: ${peerId}` diff --git a/src/components/httpRoutes/commands.ts b/src/components/httpRoutes/commands.ts index 5c26389fd..6256def36 100644 --- a/src/components/httpRoutes/commands.ts +++ b/src/components/httpRoutes/commands.ts @@ -99,7 +99,12 @@ directCommandRoute.post( // send to another peer (Only here we need P2P networking) response = await req.oceanNode .getP2PNode() - .sendTo(req.body.node as string, JSON.stringify(req.body), sink) + .sendTo( + req.body.node as string, + JSON.stringify(req.body), + sink, + req.body.multiAddrs + ) } else { response = { stream: null,