Skip to content

Commit

Permalink
feat: subdomain gateways and Origin isolation check (#78)
Browse files Browse the repository at this point in the history
This adds two known public gateways that support Origin isolation
and Origin flag next to each gateway

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
  • Loading branch information
lidel authored and jamiew committed Dec 18, 2019
1 parent ed5fc55 commit afcbffa
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# ipfs/public-gateway-checker

Checks which public IPFS gateways are online or not.

NOTE: All of these (except gateway.ipfs.io and ipfs.io) are hosted by third-parties and should be treated as such.
> Checks which public IPFS gateways are online or not.
You can view this website on GitHub Pages: https://ipfs.github.io/public-gateway-checker/

Here's a screenshot:
[![screenshot_2019-12-14.png](https://ipfs.io/ipfs/QmX53EdPJxH377WHfwH8wV3tu8Zzjq9ojgQS6U82JRM6bd?filename=screenshot_2019-12-14.png)](https://ipfs.github.io/public-gateway-checker/)

[![screenshot](https://ipfs.io/ipfs/QmY261PdTRv3eKgxqCfgAbKkCrSxdCerfjjPoc3Arq9C5q)](https://ipfs.github.io/public-gateway-checker/)
**NOTE:** All of these (except `ipfs.io` and `dweb.link`) are hosted by third-parties and should be treated as such.

A CLI version `ipfg` is available here: https://github.com/JayBrown/Tools/tree/master/ipfg

## Adding a new public gateway

If you'd like to add a new public gateway, please edit `gateways.json` and submit a pull request.


## Command line

A CLI version `ipfg` is available here: https://github.com/JayBrown/Tools/tree/master/ipfg
34 changes: 30 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const HASH_TO_TEST = 'Qmaisz6NMhDB51cCvNWa1GMS7LU1pAxdF4Ld6Ft9kZEP2a';
const SCRIPT_HASH = 'QmYHbXzTCbjavphzqrTe7zYYMW8HyeuMLNcLbqiUkj9TAH';
const HASH_TO_TEST = 'bafybeifx7yeb55armcsxwwitkymga5xf53dxiarykms3ygqic223w5sk3m';
const SCRIPT_HASH = 'bafybeietzsezxbgeeyrmwicylb5tpvf7yutrm3bxrfaoulaituhbi7q6yi';
const HASH_STRING = 'Hello from IPFS Gateway Checker';

// checker is the program root, it contains all involved objects
Expand Down Expand Up @@ -112,6 +112,29 @@ Cors.prototype.onerror = function() {
};
// ////////////////////////////////////////////////////////////////////////////////////

// ////////////////////////////////////////////////////////////////////////////////////
// ORIGIN
let Origin = function(parent) {
this.parent = parent;

this.tag = document.createElement("span");
this.tag.textContent = ' ORIGIN: 🕑 - ';
};

Origin.prototype.check = function() {
const cidInSubdomain = this.parent.gateway.startsWith('https://:hash.ipfs.');
if (cidInSubdomain) {
this.tag.textContent = ' ORIGIN: ✅ - ';
} else {
this.onerror();
}
};

Origin.prototype.onerror = function() {
this.tag.textContent = ' ORIGIN: ❌ - ';
};
// ////////////////////////////////////////////////////////////////////////////////////

// ////////////////////////////////////////////////////////////////////////////////////
// NODE
let Node = function(parent, gateway, index) {
Expand All @@ -125,6 +148,9 @@ let Node = function(parent, gateway, index) {
this.cors = new Cors(this);
this.tag.append(this.cors.tag);

this.origin = new Origin(this);
this.tag.append(this.origin.tag);

this.link = document.createElement("span");
this.link.textContent = gateway.replace(':hash', HASH_TO_TEST);
this.tag.append(this.link);
Expand All @@ -141,6 +167,7 @@ Node.prototype.check = function() {
this.checkingTime = performance.now();
this.status.check();
this.cors.check();
this.origin.check();
};

Node.prototype.checked = function() {
Expand All @@ -149,7 +176,7 @@ Node.prototype.checked = function() {

let gatewayTitle = this.gateway.split(":hash")[0];
let gatewayAndHash = this.gateway.replace(':hash', HASH_TO_TEST);
this.link.innerHTML = `<a title="${gatewayTitle}"href="${gatewayAndHash}"target="_blank">${gatewayAndHash}</a>`;
this.link.innerHTML = `<a title="${gatewayTitle}" href="${gatewayAndHash}#x-ipfs-companion-no-redirect" target="_blank">${gatewayAndHash}</a>`;

if (!this.tested) {
let ms = (performance.now() - this.checkingTime).toFixed(2);
Expand Down Expand Up @@ -178,4 +205,3 @@ function checkGateways (gateways) {
fetch('./gateways.json')
.then(res => res.json())
.then(gateways => checkGateways(gateways));

2 changes: 2 additions & 0 deletions gateways.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[
"https://ipfs.io/ipfs/:hash",
"https://:hash.ipfs.dweb.link",
"https://gateway.ipfs.io/ipfs/:hash",
"https://ipfs.infura.io/ipfs/:hash",
"https://rx14.co.uk/ipfs/:hash",
Expand All @@ -17,6 +18,7 @@
"https://gateway.blocksec.com/ipfs/:hash",
"https://ipfs.renehsz.com/ipfs/:hash",
"https://cloudflare-ipfs.com/ipfs/:hash",
"https://:hash.ipfs.cf-ipfs.com",
"https://ipns.co/:hash",
"https://ipfs.mrh.io/ipfs/:hash",
"https://gateway.originprotocol.com/ipfs/:hash",
Expand Down

0 comments on commit afcbffa

Please sign in to comment.