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: add back controller.api.gatewayHost and controller.api.gatewayPort or similar #831

Closed
SgtPooki opened this issue May 3, 2024 · 2 comments · Fixed by #850
Closed
Assignees
Labels
effort/hours Estimated to take one or several hours exp/intermediate Prior experience is likely helpful help wanted Seeking public contribution on this issue kind/enhancement A net-new feature or improvement to an existing feature P1 High: Likely tackled by core team if no one steps up status/in-progress In progress topic/devexp Developer Experience

Comments

@SgtPooki
Copy link
Member

SgtPooki commented May 3, 2024

With the latest update from #823 we no longer have the ability to get the listening ipfs gateway host and port from the instantiated kubo node.

this forces consumers to do handle passing around port/host config passed to createNode or parsing config options from the created KuboNode using https://github.com/multiformats/js-multiaddr-to-uri

We shouldn't need to do this on the consumer side because ipfsd-ctl and kubo-rpc-client should both have the gateway URL readily accessible.

We should expose this on the await node.info() result.

Note: this used to be done by reading stdout:

const gwMatch = output.trim().match(/Gateway .*listening on:? (.*)/)

@SgtPooki
Copy link
Member Author

we should call .id and it should return the listening multiaddrs

@SgtPooki
Copy link
Member Author

it doesn't seem like controller.api.id returns the same gateway endpoint we used to get with controller.api.gatewayHost/port

create code:

import { createNode, type KuboNode } from 'ipfsd-ctl'
import { path as kuboPath } from 'kubo'
import { create } from 'kubo-rpc-client'

export async function createKuboNode (listenPort?: number, repoPath?: string): Promise<{node: KuboNode, gatewayUrl: string}> {
  console.log('listening on port:', listenPort)
  const controller = await createNode({
    type: 'kubo',
    rpc: create,
    bin: kuboPath(),
    test: true,
    repo: repoPath,
    init: {
      config: {
        Addresses: {
          Swarm: [
            '/ip4/0.0.0.0/tcp/4001',
            '/ip4/0.0.0.0/tcp/4002/ws'
          ],
          Gateway: `/ip4/0.0.0.0/tcp/${listenPort ?? 0}`
        },
        Gateway: {
          NoFetch: true,
          ExposeRoutingAPI: true,
          HTTPHeaders: {
            'Access-Control-Allow-Origin': ['*'],
            'Access-Control-Allow-Methods': ['GET', 'POST', 'PUT', 'OPTIONS']
          }
        }
      }
    },
    args: ['--enable-pubsub-experiment', '--enable-namesys-pubsub']
  })

  console.log('id output: ', await controller.api.id())

  return {
    node: controller,
    gatewayUrl: `http://localhost:${listenPort ?? 0}`
  }
}

and the output:

listening on port: 3440
id output:  {
  id: PeerId(12D3KooWJTyULQ6sHpQuQMPbm3Bu2fAwoB2k6DC5JxGPKn5WPzeU),
  publicKey: 'CAESIIB/5yS1MRszt7rKlJLmo7ulFBVdmonJotEXrw2GJxyB',
  addresses: [
    Multiaddr(/ip4/127.0.0.1/tcp/4001/p2p/12D3KooWJTyULQ6sHpQuQMPbm3Bu2fAwoB2k6DC5JxGPKn5WPzeU),
    Multiaddr(/ip4/127.0.0.1/udp/4001/quic-v1/p2p/12D3KooWJTyULQ6sHpQuQMPbm3Bu2fAwoB2k6DC5JxGPKn5WPzeU),
    Multiaddr(/ip4/127.0.0.1/udp/4001/quic-v1/webtransport/certhash/uEiBGXKLzwcwO4htzNfqPCXkUAr6EwfNcwxO6kQSI23ysYw/certhash/uEiBgrXo_HUamK5EdTepvz4UPm1SOcOF4NSpaedG-qrryXA/p2p/12D3KooWJTyULQ6sHpQuQMPbm3Bu2fAwoB2k6DC5JxGPKn5WPzeU),
    Multiaddr(/ip4/192.168.1.227/tcp/4001/p2p/12D3KooWJTyULQ6sHpQuQMPbm3Bu2fAwoB2k6DC5JxGPKn5WPzeU),
    Multiaddr(/ip4/192.168.1.227/udp/4001/quic-v1/p2p/12D3KooWJTyULQ6sHpQuQMPbm3Bu2fAwoB2k6DC5JxGPKn5WPzeU),
    Multiaddr(/ip4/192.168.1.227/udp/4001/quic-v1/webtransport/certhash/uEiBGXKLzwcwO4htzNfqPCXkUAr6EwfNcwxO6kQSI23ysYw/certhash/uEiBgrXo_HUamK5EdTepvz4UPm1SOcOF4NSpaedG-qrryXA/p2p/12D3KooWJTyULQ6sHpQuQMPbm3Bu2fAwoB2k6DC5JxGPKn5WPzeU),
    Multiaddr(/ip4/97.126.29.103/udp/4001/quic-v1/p2p/12D3KooWJTyULQ6sHpQuQMPbm3Bu2fAwoB2k6DC5JxGPKn5WPzeU),
    Multiaddr(/ip4/97.126.29.103/udp/4001/quic-v1/webtransport/certhash/uEiBGXKLzwcwO4htzNfqPCXkUAr6EwfNcwxO6kQSI23ysYw/certhash/uEiBgrXo_HUamK5EdTepvz4UPm1SOcOF4NSpaedG-qrryXA/p2p/12D3KooWJTyULQ6sHpQuQMPbm3Bu2fAwoB2k6DC5JxGPKn5WPzeU),
    Multiaddr(/ip6/::1/tcp/4001/p2p/12D3KooWJTyULQ6sHpQuQMPbm3Bu2fAwoB2k6DC5JxGPKn5WPzeU),
    Multiaddr(/ip6/::1/udp/4001/quic-v1/p2p/12D3KooWJTyULQ6sHpQuQMPbm3Bu2fAwoB2k6DC5JxGPKn5WPzeU),
    Multiaddr(/ip6/::1/udp/4001/quic-v1/webtransport/certhash/uEiBGXKLzwcwO4htzNfqPCXkUAr6EwfNcwxO6kQSI23ysYw/certhash/uEiBgrXo_HUamK5EdTepvz4UPm1SOcOF4NSpaedG-qrryXA/p2p/12D3KooWJTyULQ6sHpQuQMPbm3Bu2fAwoB2k6DC5JxGPKn5WPzeU)
  ],
  agentVersion: 'kubo/0.27.0/',
  protocols: [
    '/ipfs/bitswap',
    '/ipfs/bitswap/1.0.0',
    '/ipfs/bitswap/1.1.0',
    '/ipfs/bitswap/1.2.0',
    '/ipfs/id/1.0.0',
    '/ipfs/id/push/1.0.0',
    '/ipfs/kad/1.0.0',
    '/ipfs/lan/kad/1.0.0',
    '/ipfs/ping/1.0.0',
    '/libp2p/autonat/1.0.0',
    '/libp2p/circuit/relay/0.2.0/hop',
    '/libp2p/circuit/relay/0.2.0/stop',
    '/libp2p/dcutr',
    '/x/'
  ]
}
http://localhost:3440

@SgtPooki SgtPooki self-assigned this Nov 14, 2024
@SgtPooki SgtPooki added kind/enhancement A net-new feature or improvement to an existing feature help wanted Seeking public contribution on this issue status/in-progress In progress P1 High: Likely tackled by core team if no one steps up exp/intermediate Prior experience is likely helpful effort/hours Estimated to take one or several hours topic/devexp Developer Experience and removed need/triage Needs initial labeling and prioritization labels Nov 14, 2024
@SgtPooki SgtPooki linked a pull request Nov 14, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/hours Estimated to take one or several hours exp/intermediate Prior experience is likely helpful help wanted Seeking public contribution on this issue kind/enhancement A net-new feature or improvement to an existing feature P1 High: Likely tackled by core team if no one steps up status/in-progress In progress topic/devexp Developer Experience
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant