ipfs / ipfs-companion

Browser extension that simplifies access to IPFS resources on the web
https://docs.ipfs.tech/install/ipfs-companion/
Creative Commons Zero v1.0 Universal
2.05k stars 325 forks source link

Allow Web Pages to query companion for the best available node #1116

Open whizzzkid opened 1 year ago

whizzzkid commented 1 year ago

Is your feature request related to a problem? Please describe. companion right now redirects requests based on regex for a select few domain. ipfs.io e.g. has been throwing 429 for me. So if a developer embeds cloudflare-ipfs.com companion does not redirect this request to local-node.

Describe the solution you'd like There should be a mechanism where the page can request the best available local node and use that to make requests. Something like page <-> extension communication, metamask does something similar.

lidel commented 1 year ago

companion right now redirects requests based on regex for a select few domain. ipfs.io e.g. has been throwing 429 for me. So if a developer embeds cloudflare-ipfs.com companion does not redirect this request to local-node.

AFAIK this is incorrect: ipfs-companion uses https://www.npmjs.com/package/is-ipfs and will redirect every gateway URL that follows conventions described in https://docs.ipfs.tech/how-to/address-ipfs-on-web. No specific hostname is hardcoded, redirection will work for any compatible URL, as long as CID or valid DNSLink is present.

If this is no longer happening, then we have a bug.

There should be a mechanism where the page can request the best available local node and use that to make requests. Something like page <-> extension communication, metamask does something similar.

There is a lot prior art aorund this, happy to discuss in January when I am back, but for now quick brain-dump:

ipfs.io e.g. has been throwing 429 for me.

429 on a public gateway are something Companion can detect and recover from, but you need more than one Public Gateway to handle scenario when local gateway is absent and the default public gateway is down.

Changing Public Gateway setting from being a single URL to a list of public gateways sounds like a sensible step.

Long term, this problem will go away when we have native ipfs:// – abstracting backend away, allowing for seamless resume without changing Origin.

whizzzkid commented 1 year ago

Thanks for the context, for some reason redirection was spotty when I posted the issue, I need to get to the root of this.

Changing Public Gateway setting from being a single URL to a list of public gateways sounds like a sensible step.

Absolutely, in fact the gateway checker list and tests could be leveraged for this purpose, we can use the top-N public gateways closest to the user for this.

SgtPooki commented 1 year ago

@whizzzkid bifrost has some open issues around 429 issues. I believe they've nailed most of them down now, but we should ensure that companion works properly if a gateway is throwing errors. Based on the convo so far, it sounds like this task has turned into the following action items:

Do any of these tasks remain valid in the long-term scenario where ipfs:// is supported natively?

If not, do any of these tasks provide a decent QoL improvement with minimal dev-effort until then?

lidel commented 1 year ago

Allow users to add multiple different gateways Allow users to automatically select top-N public gateways closest to them (checkbox for: use public-gateways?

We need to be very careful what we suggest to users as default or fallback.

Public gateways are run by random people, and people who use public gateway for fetching already deserialized data delegate IPFS to a third-party that is other than Protocol Labs. (IPFS happens on remote server, and not your machine).

Unless we are able to guarantee user is fetching data as raw block or CAR and verify it matches expected CID, we should not assist user in delegating trust to some random person on the internet.

If not, do any of these tasks provide a decent QoL improvement with minimal dev-effort until then?

I'd say no. Only verifiable response types are relevant for native ipfs://, and Companion, given web and webextension APIs available today, does not have ability to serve verified bytes on its own (we delegate it to IPFS Desktop/Brave/Kubo). We should not make it easier for people to get MITM'd.

If we want to invest time towards native ipfs://, prioritize https://github.com/ipfs/ipfs-companion/issues/1128 to help Igalia with handler discussions (redirect handler today means it is easier to discuss native one tomorrow).

whizzzkid commented 1 year ago

@lidel we can defer this. This would require a portable version of the gateway checker. I'd say this is blocked till then.