Description
Rationale
Currently IPFS doesn't expose any way to know if a gateway is running and what it's URL is. One could opt to use the IPFS API to figure this out but that's quickly rather complicated to implement properly. Providing a file indicating that a gateway is running where the content of the file is the gateway URL would be a simple portable way for applications to detect a running IPFS gateway.
Potential usecases
- In my project to support IPFS in FFMpeg i need to know the gateway otherwise the user must always provide it manually. Reading a file would make this one step more user friendly in this case.
- Another potential user for this could be Brave (the browser). It would allow them to detect a running gateway.
- IPFS Companion also could benefit from this approach.
- There's likely many more potential usecases that could benefit from this too.
Implementation
- When the gateway part of the IPFS daemon starts, a file named
gateway
is created. This file is created in$IPFS_PATH
. The resulting file will be$IPFS_PATH/gateway
- The content of this file is the full URL to the gateway without a trailing forward slash. In a default setup scenario the content of the
gateway
file will behttp://localhost:8080
. The port section of this URL will follow whatever is provided in the IPFS config file underAddresses.Gateway
- When IPFS stops (assumption, the general graceful shutdown, not a crash) the
gateway
file is removed. - If the
Addresses.Gateway
setting is empty or missing from the config file then nogateway
file is created because no gateway should be started. This and only creating the file when the gateway starts should - more or less - guarantee that the file only exists if there is a gateway running.
How other applications can use this
Assumption, they do need to assume where the IPFS folder is.
- They should check for
SIPFS_PATH
and use that if it exists. Otherwise they should assume~/.ipfs
. They can expect the gateway file to be in that folder. If the gateway file is there it means a local gateway is running. - If the path exists but no gateway file does then it's safe to assume no gateway is running from that IPFS data folder.
- If they need to know the gateway address they can rely on the full content of the file being a single URL.
Open and unresolved issues
- Ideally it should be able to detect a running IPFS instance when it's running as a service under it's own username. This spec does not handle that. mDNS could potentially be used for that though it might not be ideal for all potential uses.
- In browser IPFS nodes (like what's possible in Brave). How to even figure out where it's gateway runs?
- More?...
Code and testcases
Right now there is no code nor testcases. I am planning to make both and will post a message in this issue when i'm actually working on this. You can assume i'm not working on this as long as i haven't explicitly said so in this issue.
Thank you and mentions
Thanx goes out to @Stebalien and @TheDiscordian for the fruitful discussion we had about this!