ipfs / js-ipfs

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

Support relay and hop as "config" options like Go #2667

Closed hugomrdias closed 1 year ago

hugomrdias commented 4 years ago

Type: Enhancement

Severity: High

Description:

Correctly we dont support enabling relay and hop using the config like go https://github.com/ipfs/go-ipfs/blob/master/docs/config.md#swarm so we when using the CLI there’s no way to run a js daemon as a relay.

Steps to reproduce the error:

ggarri commented 4 years ago

I have started a little research and I have realized that js-ipfs already support relay and hops in config as we can see from the description at the example circuit-relaying about to how to setup the ipfs node.

Just as we did with go-ipfs, go ahead and edit js-ipfs config file located under ~/.jsipfs/config. Let's add the following config:

  "relay": {
    "enabled": true,
    "hop": {
      "enabled": true
    }
  }

And I got same conclusion after reading this code in core->component->libp2p

      relay: {
        enabled: get(options, 'relay.enabled',
          get(config, 'relay.enabled', true)),
        hop: {
          enabled: get(options, 'relay.hop.enabled',
            get(config, 'relay.hop.enabled', false)),
          active: get(options, 'relay.hop.active',
            get(config, 'relay.hop.active', false))
        }
      },

Aiming the best compatibility across both projects, js-ipfs and go-ipfs I am incline to tackle this issue by providing the same config map than go-ipfs, which looks like the one below:

  "Swarm": {
    "DisableRelay": false,
    "EnableRelayHop": true,
    "EnableAutoRelay": false,
...
    }

And therefore this issue will also involve an update of the circuit-relaying example as it was mentioned above or provide a backward compatible solution which bring some technical debt but it might be worthy to no affect people using it.

Please, I would appreciate some feedback in case I am heading in the wrong direction @hugomrdias

hugomrdias commented 4 years ago

@ggarri first thank you for tackling this!! Yes this is the right direction, the js-ipfs top level relay options are artefacts from times when the libp2p was lacking support for it. So we should remove those options, add support for it in the repo config just like Go has and make sure that manually passing libp2p config overrides the repo config (@alanshaw @achingbrain do you agree with this last part about constructor config having higher precedence than repo config?)

achingbrain commented 4 years ago

Sounds good. I think if someone's gone to the trouble of passing constructor args in, they should override passively detected settings.

SgtPooki commented 1 year ago

js-ipfs is being deprecated in favor of Helia. You can learn more about this deprecation and read the migration guide.

Please feel to reopen with any comments by 2023-06-02. We will do a final pass on reopened issues afterwards (see https://github.com/ipfs/js-ipfs/issues/4336).