ipfs / js-ipfs

IPFS implementation in JavaScript
https://js.ipfs.tech
Other
7.43k stars 1.25k forks source link

API sugar: start, listen, and connect #1084

Closed pgte closed 1 year ago

pgte commented 6 years ago

Doing user-land apps and modules on top of IPFS, there are some oddities that I would love to see addressed to make life easier to developers.

One of them is starting a node, also related to offline support:

Creating a node and starting it should be easy to achieve even if offline. Starting a node should not mean initialising the network stack. It just means that you have a node you can read and write DAG nodes to and from. Also, it should mean that all the APIs are available. For instance, after starting, the pubsub API should be ready, even if subscriptions are only effective if the node is connected.

I would like to be able to do:

const node = IPFS()
await node.start() // initialises repo, makes all the APIs ready for commands

// pubsub is available
await node.pubsub.subscribe('topic', handler)

// can listen on a protocol (like webrtc) or an address (like a websockets server)
await node.listen(address, options) // listens on an address / protocol

// try to connect to a specific node
try {
  const duplexStream = await node.connect(peerAddress, protocol)
} catch (err) {
  if (err.code === 'ECONNECT') {
    console.log('could not connect to ' + peerAddress)
  }
}

// stops node and all network activity
await node.stop()
whizzzkid commented 1 year ago

js-ipfs is being deprecated in favor of Helia. You can follow the migration plan here https://github.com/ipfs/js-ipfs/issues/4336 and read the migration guide.

This issue has been resolved in Helia! if this does not address your concern please let us know by reopening this issue before 2023-06-05!