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

Open
SgtPooki opened this issue May 3, 2024 · 2 comments
Labels
need/triage Needs initial labeling and prioritization

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.

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need/triage Needs initial labeling and prioritization
Projects
None yet
Development

No branches or pull requests

1 participant