1*6236dae4SAndroid Build Coastguard Worker<!-- 2*6236dae4SAndroid Build Coastguard WorkerCopyright (C) Daniel Stenberg, <[email protected]>, et al. 3*6236dae4SAndroid Build Coastguard Worker 4*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl 5*6236dae4SAndroid Build Coastguard Worker--> 6*6236dae4SAndroid Build Coastguard Worker 7*6236dae4SAndroid Build Coastguard Worker# IPFS 8*6236dae4SAndroid Build Coastguard WorkerFor an overview about IPFS, visit the [IPFS project site](https://ipfs.tech/). 9*6236dae4SAndroid Build Coastguard Worker 10*6236dae4SAndroid Build Coastguard WorkerIn IPFS there are two protocols. IPFS and IPNS (their workings are explained in detail [here](https://docs.ipfs.tech/concepts/)). The ideal way to access data on the IPFS network is through those protocols. For example to access the Big Buck Bunny video the ideal way to access it is like: `ipfs://bafybeigagd5nmnn2iys2f3doro7ydrevyr2mzarwidgadawmamiteydbzi` 11*6236dae4SAndroid Build Coastguard Worker 12*6236dae4SAndroid Build Coastguard Worker## IPFS Gateways 13*6236dae4SAndroid Build Coastguard Worker 14*6236dae4SAndroid Build Coastguard WorkerIPFS Gateway acts as a bridge between traditional HTTP clients and IPFS. 15*6236dae4SAndroid Build Coastguard WorkerIPFS Gateway specifications of HTTP semantics can be found [here](https://specs.ipfs.tech/http-gateways/). 16*6236dae4SAndroid Build Coastguard Worker 17*6236dae4SAndroid Build Coastguard Worker### Deserialized responses 18*6236dae4SAndroid Build Coastguard Worker 19*6236dae4SAndroid Build Coastguard WorkerBy default, a gateway acts as a bridge between traditional HTTP clients and IPFS and performs necessary hash verification and deserialization. Through such gateway, users can download files, directories, and other content-addressed data stored with IPFS or IPNS as if they were stored in a traditional web server. 20*6236dae4SAndroid Build Coastguard Worker 21*6236dae4SAndroid Build Coastguard Worker### Verifiable responses 22*6236dae4SAndroid Build Coastguard Worker 23*6236dae4SAndroid Build Coastguard WorkerBy explicitly requesting [application/vnd.ipld.raw](https://www.iana.org/assignments/media-types/application/vnd.ipld.raw) or [application/vnd.ipld.car](https://www.iana.org/assignments/media-types/application/vnd.ipld.car) responses, by means defined in [Trustless Gateway Specification](https://specs.ipfs.tech/http-gateways/trustless-gateway/), the user is able to fetch raw content-addressed data and [perform hash verification themselves](https://docs.ipfs.tech/reference/http/gateway/#trustless-verifiable-retrieval). 24*6236dae4SAndroid Build Coastguard Worker 25*6236dae4SAndroid Build Coastguard WorkerThis enables users to use untrusted, public gateways without worrying they might return invalid/malicious bytes. 26*6236dae4SAndroid Build Coastguard Worker 27*6236dae4SAndroid Build Coastguard Worker## IPFS and IPNS protocol handling 28*6236dae4SAndroid Build Coastguard Worker 29*6236dae4SAndroid Build Coastguard WorkerThere are various ways to access data from the IPFS network. One such way is 30*6236dae4SAndroid Build Coastguard Workerthrough the concept of public 31*6236dae4SAndroid Build Coastguard Worker"[gateways](https://docs.ipfs.tech/concepts/ipfs-gateway/#overview)". The 32*6236dae4SAndroid Build Coastguard Workershort version is that entities can offer gateway services. An example here 33*6236dae4SAndroid Build Coastguard Workerthat is hosted by Protocol Labs (who also makes IPFS) is `dweb.link` and 34*6236dae4SAndroid Build Coastguard Worker`ipfs.io`. Both sites expose gateway functionality. Getting a file through 35*6236dae4SAndroid Build Coastguard Worker`ipfs.io` looks like this: 36*6236dae4SAndroid Build Coastguard Worker`https://ipfs.io/ipfs/bafybeigagd5nmnn2iys2f3doro7ydrevyr2mzarwidgadawmamiteydbzi` 37*6236dae4SAndroid Build Coastguard Worker 38*6236dae4SAndroid Build Coastguard WorkerIf you were to be [running your own IPFS 39*6236dae4SAndroid Build Coastguard Workernode](https://docs.ipfs.tech/how-to/command-line-quick-start/) then you, by 40*6236dae4SAndroid Build Coastguard Workerdefault, also have a [local gateway](https://specs.ipfs.tech/http-gateways/) 41*6236dae4SAndroid Build Coastguard Workerrunning. In its default configuration the earlier example would then also work 42*6236dae4SAndroid Build Coastguard Workerin this link: 43*6236dae4SAndroid Build Coastguard Worker 44*6236dae4SAndroid Build Coastguard Worker`http://127.0.0.1:8080/ipfs/bafybeigagd5nmnn2iys2f3doro7ydrevyr2mzarwidgadawmamiteydbzi` 45*6236dae4SAndroid Build Coastguard Worker 46*6236dae4SAndroid Build Coastguard Worker## cURL handling of the IPFS protocols 47*6236dae4SAndroid Build Coastguard Worker 48*6236dae4SAndroid Build Coastguard WorkerThe IPFS integration in cURL hides this gateway logic for you. Instead of 49*6236dae4SAndroid Build Coastguard Workerproviding a full URL to a file on IPFS like this: 50*6236dae4SAndroid Build Coastguard Worker 51*6236dae4SAndroid Build Coastguard Worker``` 52*6236dae4SAndroid Build Coastguard Workercurl http://127.0.0.1:8080/ipfs/bafybeigagd5nmnn2iys2f3doro7ydrevyr2mzarwidgadawmamiteydbzi 53*6236dae4SAndroid Build Coastguard Worker``` 54*6236dae4SAndroid Build Coastguard Worker 55*6236dae4SAndroid Build Coastguard WorkerYou can provide it with the IPFS protocol instead: 56*6236dae4SAndroid Build Coastguard Worker``` 57*6236dae4SAndroid Build Coastguard Workercurl ipfs://bafybeigagd5nmnn2iys2f3doro7ydrevyr2mzarwidgadawmamiteydbzi 58*6236dae4SAndroid Build Coastguard Worker``` 59*6236dae4SAndroid Build Coastguard Worker 60*6236dae4SAndroid Build Coastguard WorkerWith the IPFS protocol way of asking a file, cURL still needs to know the 61*6236dae4SAndroid Build Coastguard Workergateway. curl essentially just rewrites the IPFS based URL to a gateway URL. 62*6236dae4SAndroid Build Coastguard Worker 63*6236dae4SAndroid Build Coastguard Worker### IPFS_GATEWAY environment variable 64*6236dae4SAndroid Build Coastguard Worker 65*6236dae4SAndroid Build Coastguard WorkerIf the `IPFS_GATEWAY` environment variable is found, its value is used as 66*6236dae4SAndroid Build Coastguard Workergateway. 67*6236dae4SAndroid Build Coastguard Worker 68*6236dae4SAndroid Build Coastguard Worker### Automatic gateway detection 69*6236dae4SAndroid Build Coastguard Worker 70*6236dae4SAndroid Build Coastguard WorkerWhen you provide no additional details to cURL then it: 71*6236dae4SAndroid Build Coastguard Worker 72*6236dae4SAndroid Build Coastguard Worker1. First looks for the `IPFS_GATEWAY` environment variable and use that if it 73*6236dae4SAndroid Build Coastguard Worker is set. 74*6236dae4SAndroid Build Coastguard Worker2. Looks for the file: `~/.ipfs/gateway`. If it can find that file then it 75*6236dae4SAndroid Build Coastguard Worker means that you have a local gateway running and that file contains the URL 76*6236dae4SAndroid Build Coastguard Worker to your local gateway. 77*6236dae4SAndroid Build Coastguard Worker 78*6236dae4SAndroid Build Coastguard WorkerIf cURL fails, you are presented with an error message and a link to this page 79*6236dae4SAndroid Build Coastguard Workerto the option most applicable to solving the issue. 80*6236dae4SAndroid Build Coastguard Worker 81*6236dae4SAndroid Build Coastguard Worker### `--ipfs-gateway` argument 82*6236dae4SAndroid Build Coastguard Worker 83*6236dae4SAndroid Build Coastguard WorkerYou can also provide a `--ipfs-gateway` argument to cURL. This overrules any 84*6236dae4SAndroid Build Coastguard Workerother gateway setting. curl does not fallback to the other options if the 85*6236dae4SAndroid Build Coastguard Workerprovided gateway did not work. 86*6236dae4SAndroid Build Coastguard Worker 87*6236dae4SAndroid Build Coastguard Worker## Gateway redirects 88*6236dae4SAndroid Build Coastguard Worker 89*6236dae4SAndroid Build Coastguard WorkerA gateway could redirect to another place. For example, `dweb.link` redirects 90*6236dae4SAndroid Build Coastguard Worker[path based](https://docs.ipfs.tech/how-to/address-ipfs-on-web/#path-gateway) 91*6236dae4SAndroid Build Coastguard Workerrequests to [subdomain 92*6236dae4SAndroid Build Coastguard Workerbased](https://docs.ipfs.tech/how-to/address-ipfs-on-web/#subdomain-gateway) 93*6236dae4SAndroid Build Coastguard Workerones. A request using: 94*6236dae4SAndroid Build Coastguard Worker 95*6236dae4SAndroid Build Coastguard Worker curl ipfs://bafybeigagd5nmnn2iys2f3doro7ydrevyr2mzarwidgadawmamiteydbzi --ipfs-gateway https://dweb.link 96*6236dae4SAndroid Build Coastguard Worker 97*6236dae4SAndroid Build Coastguard WorkerWhich would be translated to: 98*6236dae4SAndroid Build Coastguard Worker 99*6236dae4SAndroid Build Coastguard Worker https://dweb.link/ipfs/bafybeigagd5nmnn2iys2f3doro7ydrevyr2mzarwidgadawmamiteydbzi 100*6236dae4SAndroid Build Coastguard Worker 101*6236dae4SAndroid Build Coastguard Workerredirects to: 102*6236dae4SAndroid Build Coastguard Worker 103*6236dae4SAndroid Build Coastguard Worker https://bafybeigagd5nmnn2iys2f3doro7ydrevyr2mzarwidgadawmamiteydbzi.ipfs.dweb.link 104*6236dae4SAndroid Build Coastguard Worker 105*6236dae4SAndroid Build Coastguard WorkerIf you trust this behavior from your gateway of choice then passing the `-L` 106*6236dae4SAndroid Build Coastguard Workeroption follows the redirect. 107*6236dae4SAndroid Build Coastguard Worker 108*6236dae4SAndroid Build Coastguard Worker## Error messages and hints 109*6236dae4SAndroid Build Coastguard Worker 110*6236dae4SAndroid Build Coastguard WorkerDepending on the arguments, cURL could present the user with an error. 111*6236dae4SAndroid Build Coastguard Worker 112*6236dae4SAndroid Build Coastguard Worker### Gateway file and environment variable 113*6236dae4SAndroid Build Coastguard Worker 114*6236dae4SAndroid Build Coastguard WorkercURL tried to look for the file: `~/.ipfs/gateway` but could not find it. It 115*6236dae4SAndroid Build Coastguard Workeralso tried to look for the `IPFS_GATEWAY` environment variable but could not 116*6236dae4SAndroid Build Coastguard Workerfind that either. This happens when no extra arguments are passed to cURL and 117*6236dae4SAndroid Build Coastguard Workerletting it try to figure it out [automatically](#automatic-gateway-detection). 118*6236dae4SAndroid Build Coastguard Worker 119*6236dae4SAndroid Build Coastguard WorkerAny IPFS implementation that has gateway support should expose its URL in 120*6236dae4SAndroid Build Coastguard Worker`~/.ipfs/gateway`. If you are already running a gateway, make sure it exposes 121*6236dae4SAndroid Build Coastguard Workerthe file where cURL expects to find it. 122*6236dae4SAndroid Build Coastguard Worker 123*6236dae4SAndroid Build Coastguard WorkerAlternatively you could set the `IPFS_GATEWAY` environment variable or pass 124*6236dae4SAndroid Build Coastguard Workerthe `--ipfs-gateway` flag to the cURL command. 125*6236dae4SAndroid Build Coastguard Worker 126*6236dae4SAndroid Build Coastguard Worker### Malformed gateway URL 127*6236dae4SAndroid Build Coastguard Worker 128*6236dae4SAndroid Build Coastguard WorkerThe command executed evaluates in an invalid URL. This could be anywhere in 129*6236dae4SAndroid Build Coastguard Workerthe URL, but a likely point is a wrong gateway URL. 130*6236dae4SAndroid Build Coastguard Worker 131*6236dae4SAndroid Build Coastguard WorkerInspect the URL set via the `IPFS_GATEWAY` environment variable or passed with 132*6236dae4SAndroid Build Coastguard Workerthe `--ipfs-gateway` flag. Alternatively opt to go for the 133*6236dae4SAndroid Build Coastguard Worker[automatic](#automatic-gateway-detection) gateway detection. 134