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

add multiAddrs for directCommand #796

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 8 additions & 7 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 14 additions & 3 deletions src/components/P2P/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -608,7 +608,8 @@ export class OceanP2P extends EventEmitter {
async sendTo(
peerName: string,
message: string,
sink: any
sink: any,
multiAddrs?: string[]
): Promise<P2PCommandResponse> {
P2P_LOGGER.logMessage('SendTo() node ' + peerName + ' task: ' + message, true)

Expand All @@ -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}`
Expand Down
7 changes: 6 additions & 1 deletion src/components/httpRoutes/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading