Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: /ipns/ check #313

Merged
merged 7 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/GatewayNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import { UiComponent } from './UiComponent'
import { Log } from './Log'
import { gatewayHostname } from './gatewayHostname'
import { HASH_TO_TEST } from './constants'
import { IPNSCheck } from './Ipns'

const log = new Log('GatewayNode')

class GatewayNode extends UiComponent /* implements Checkable */ {
// tag: Tag
status: Status
cors: Cors
ipns: IPNSCheck
origin: Origin
trustless: Trustless
link: HTMLDivElement & { url?: URL }
Expand All @@ -42,6 +44,9 @@ class GatewayNode extends UiComponent /* implements Checkable */ {
this.cors = new Cors(this)
this.tag.append(this.cors.tag)

this.ipns = new IPNSCheck(this)
this.tag.append(this.ipns.tag)

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

Expand Down Expand Up @@ -77,6 +82,7 @@ class GatewayNode extends UiComponent /* implements Checkable */ {
// this.flag.check().then(() => log.debug(this.gateway, 'Flag success')),
this.status.check().then(() => log.debug(this.gateway, 'Status success')).then(this.onSuccessfulCheck.bind(this)),
this.cors.check().then(() => log.debug(this.gateway, 'CORS success')).then(this.onSuccessfulCheck.bind(this)),
this.ipns.check().then(() => log.debug(this.gateway, 'IPNS success')).then(this.onSuccessfulCheck.bind(this)),
this.origin.check().then(() => log.debug(this.gateway, 'Origin success')).then(this.onSuccessfulCheck.bind(this)),
this.trustless.check().then(
() => log.debug(this.gateway, 'Trustless success')).then(this.onSuccessfulCheck.bind(this))
Expand Down
50 changes: 50 additions & 0 deletions src/Ipns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import fetchPonyfill from 'fetch-ponyfill'

import { CheckBase } from './CheckBase'
import { IPNS_PATH_TO_TEST } from './constants'
import type { GatewayNode } from './GatewayNode'

import { Log } from './Log'

const { fetch } = fetchPonyfill()

const log = new Log('Ipns')

class IPNSCheck extends CheckBase implements Checkable {
_className = 'Ipns'
_tagName = 'div'
constructor (protected parent: GatewayNode) {
super(parent, 'div', 'Ipns')
}

async check (): Promise<void> {
const now = Date.now()
// Since gateway URLs are hard coded with /ipfs/, we need to parse URLs and override the path to /ipns/.
const gatewayUrl = new URL(this.parent.gateway)
gatewayUrl.pathname = IPNS_PATH_TO_TEST
const testUrl = `${gatewayUrl.href}?now=${now}`
whizzzkid marked this conversation as resolved.
Show resolved Hide resolved
try {
const response = await fetch(testUrl)
if (response.status === 200) {
this.tag.win()
} else {
log.debug(`${this.parent.gateway} does not support IPNS`)
throw new Error(`URL '${testUrl} is not reachable`)
}
} catch (err) {
log.error(err)
this.onerror()
throw err
}
}
SgtPooki marked this conversation as resolved.
Show resolved Hide resolved

checked (): void {
log.warn('Not implemented yet')
}

onerror (): void {
this.tag.err()
}
}

export { IPNSCheck }
2 changes: 1 addition & 1 deletion src/Tag.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TagStatus } from './TagStatus'

type TagClasses = 'Status' | 'Node' | 'Cors' | 'Origin' | 'Flag' | 'Trustless'
type TagClasses = 'Cors' | 'Flag' | 'Ipns' | 'Node' | 'Origin' | 'Status' | 'Trustless'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just reordered alphabetically.


type TagContent = TagStatus

Expand Down
4 changes: 3 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

const HASH_STRING = 'Hello from IPFS Gateway Checker'
const HASH_TO_TEST = 'bafybeifx7yeb55armcsxwwitkymga5xf53dxiarykms3ygqic223w5sk3m'
const IMG_HASH = 'bafybeibwzifw52ttrkqlikfzext5akxu7lz4xiwjgwzmqcpdzmp3n5vnbe' // 1x1.png
// const IFRAME_HASH = 'bafkreifx3g6bkkwl7b4v43lvcqfo5vshbiehuvmpky2zayhfpg5qj7y3ca'
const HASH_STRING = 'Hello from IPFS Gateway Checker'
const IPNS_PATH_TO_TEST = '/ipns/en.wikipedia-on-ipfs.org/favicon.ico'
const TRUSTLESS_RESPONSE_TYPES = ['raw', 'car']
const DEFAULT_IPFS_GATEWAY = 'https://ipfs.io'

Expand All @@ -12,5 +13,6 @@ export {
HASH_TO_TEST,
// IFRAME_HASH,
IMG_HASH,
IPNS_PATH_TO_TEST,
TRUSTLESS_RESPONSE_TYPES
}
1 change: 1 addition & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ <h1 class='f3 fw2 montserrat aqua ttu ma0'>Public Gateways</h1>
<div class="Node Header">
<div class="Status" title="Online status: is it possible to read data?" style="cursor: help">Online</div>
<div class="Cors" title="Allows Cross-Origin Resource Sharing (CORS fetch)"><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#The_HTTP_response_headers" target="_blank">CORS</a></div>
<div class="Ipns" title="Allows IPNS Resolution to IPFS Content Addresses"><a href="https://docs.ipfs.tech/concepts/ipns" target="_blank">IPNS</a></div>
<div class="Origin" title="Provides Origin Isolation (Subdomain Gateway)"><a href="https://docs.ipfs.io/how-to/address-ipfs-on-web/#subdomain-gateway" target="_blank">Origin</a></div>
<div class="Trustless" title="Supports Trustless Gateway Specification"><a href="https://docs.ipfs.tech/reference/http/gateway/#trustless-verifiable-retrieval" target="_blank">Block/CAR</a></div>
<div class="Flag">Country</div>
Expand Down
3 changes: 2 additions & 1 deletion src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ div.Node div.Status,
div.Node div.Cors,
div.Node div.Origin,
div.Node div.Trustless,
div.Node div.Ipns,
div.Node div.Flag {
width: 6em;
width: 7.2em;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird way these divs are structured. I'll create an issue to have a better table replacement here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, we will be able to clean up the table with a more responsive and user friendly view by implementing the mocks from #93

text-align: center;
margin: 0 0.5em;
user-select: none;
Expand Down