-
Notifications
You must be signed in to change notification settings - Fork 363
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: Implementing Trustless Server Checks #310
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import fetchPonyfill from 'fetch-ponyfill' | ||
|
||
import { CheckBase } from './CheckBase' | ||
import { HASH_TO_TEST, TRUSTLESS_RESPONSE_TYPES } from './constants' | ||
import type { GatewayNode } from './GatewayNode' | ||
|
||
import { Log } from './Log' | ||
|
||
const { fetch } = fetchPonyfill() | ||
|
||
const log = new Log('Trustless') | ||
|
||
class Trustless extends CheckBase implements Checkable { | ||
_className = 'Trustless' | ||
_tagName = 'div' | ||
constructor (protected parent: GatewayNode) { | ||
super(parent, 'div', 'Trustless') | ||
} | ||
|
||
async check (): Promise<void> { | ||
const now = Date.now() | ||
const gatewayAndHash = this.parent.gateway.replace(':hash', HASH_TO_TEST) | ||
this.parent.tag.classList.add('trustless') | ||
try { | ||
const trustlessResponseTypesTests = await Promise.all(TRUSTLESS_RESPONSE_TYPES.map( | ||
async (trustlessTypes): Promise<boolean> => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
const testUrl = `${gatewayAndHash}?format=${trustlessTypes}&now=${now}#x-ipfs-companion-no-redirect` | ||
const response = await fetch(testUrl) | ||
return Boolean(response.headers.get('Content-Type')?.includes(`application/vnd.ipld.${trustlessTypes}`)) | ||
} | ||
)) | ||
|
||
if (!trustlessResponseTypesTests.includes(false)) { | ||
this.tag.win() | ||
} else { | ||
log.debug('The response type did not match the expected type') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For better troubleshooting, we should understand what the expected type was in the error message. i.e. If a gateway owner fails a test and wants to figure out how they failed, do they need to support car, raw, or both? probably worth addressing in another issue. |
||
this.onerror() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: we could remove this one since we're throwing an error in the line below, and catching on line 40 with another call to |
||
throw new Error(`URL '${gatewayAndHash} does not support Trustless`) | ||
} | ||
} catch (err) { | ||
log.error(err) | ||
this.onerror() | ||
throw err | ||
} | ||
} | ||
|
||
checked (): void { | ||
log.warn('Not implemented yet') | ||
} | ||
|
||
onerror (): void { | ||
this.tag.err() | ||
} | ||
} | ||
|
||
export { Trustless } |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,8 +70,9 @@ div.Node a, div#origin-warning a { | |
div.Node div.Status, | ||
div.Node div.Cors, | ||
div.Node div.Origin, | ||
div.Node div.Trustless, | ||
div.Node div.Flag { | ||
width: 5em; | ||
width: 6em; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. distributes more evently. |
||
text-align: center; | ||
margin: 0 0.5em; | ||
user-select: none; | ||
|
@@ -93,6 +94,10 @@ div.Node div.Took { | |
font-style: italic; | ||
} | ||
|
||
div.Node.trustless div.Trustless { | ||
margin: 0 1.3em; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. accounting for wider column |
||
} | ||
|
||
div.Node.origin div.Link::after { | ||
content: " 💚" | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel this can be refactored, but will revisit this in a future PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you file an issue for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#311