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: load static websites and paths #2

Merged
merged 24 commits into from
Apr 6, 2023

Conversation

SgtPooki
Copy link
Member

@SgtPooki SgtPooki commented Apr 5, 2023

  • chore: debugging fetch speed
  • fix(libp2p-patch): filter out bad peers
  • feat: load static websites

demo

Pre-reqs

You have to visit the preview site first, and make sure the SW is loaded. Once it is, the below links should work for you.

Note: You may need to refresh a few times.. i'm sure there is additional pre-fetching we need to do so we can ensure sites load properly.

Links

ipfs.tech/images directory listing page: https://bafybeigrqbyusjs5hh3e7upxhwm52hqocygezkvke3c6neobrhon4yt3v4.on.fleek.co/helia-sw/QmeUdoMyahuQUPHS2odrZEL6yk2HnNfBJ147BeLXsZuqLJ/images

ipfs.tech/images/images/ipfs-desktop-hex.png: https://bafybeigrqbyusjs5hh3e7upxhwm52hqocygezkvke3c6neobrhon4yt3v4.on.fleek.co/helia-sw/QmeUdoMyahuQUPHS2odrZEL6yk2HnNfBJ147BeLXsZuqLJ/images/ipfs-desktop-hex.png

ipfs.tech website: https://bafybeigrqbyusjs5hh3e7upxhwm52hqocygezkvke3c6neobrhon4yt3v4.on.fleek.co/helia-sw/QmeUdoMyahuQUPHS2odrZEL6yk2HnNfBJ147BeLXsZuqLJ

You can also test the loading of content from the main page, and link to the direct content by clicking the call-to-action button beneath

@SgtPooki SgtPooki requested a review from aschmahmann April 5, 2023 04:57
@SgtPooki
Copy link
Member Author

SgtPooki commented Apr 5, 2023

Some issues brought up via slack:

  1. If I click on ipfs-applications-diagram.png I see a directory listing for index.html and ipfs-applications-diagram.png. Clicking either entry give me a blank page with Not found

That .png file is actually a directory

╰─ ✔ ❯ ipfs ls QmeUdoMyahuQUPHS2odrZEL6yk2HnNfBJ147BeLXsZuqLJ/images
Qma5hgVwaYzQGXCvf3BXB5Y7J86Z8fDWQz5kYgV1hbVNCs 17878  command-line-hex.png
Qmeosk9pDjpmMZGbuRpPjaWdNnjMdTpxTthbB8seYfRAcB -      ipfs-applications-diagram.png/
QmQfoXavfiGLmUL4bRnvS6w8LAwRw4nWLSL9jF7qU1e2B3 9904   ipfs-cluster.png
QmXkkYJYye8tzqL19Fyt1oea73yPWp3LH6774nmF7i9tie 7839   ipfs-companion-hex.png
QmVmBnuqByeEqoLu1HkCn2zYeMZ2L3ooPDKyWV5pfaiydJ 6268   ipfs-desktop-hex.png
QmU58Dt54RbV6ccJNLWtrPmzxMy6u2ndpeBACGsKWFPdYa 20434  js-ipfs-logo.png
QmPGLQcMexuZvZ2jeX4UhWofD4JeVucet5Uw58tvAN7tsn 16255  kubo-hex-logo.png
QmeGaLaMx1bH1z57KS1qLkoTCLPAQZbDsnAavjhupkaUqx 909480 meet-builders-thumbnail-pinata.png
Qmcm32sVsMYhURY3gqH7vSQ76492t5Rfxb3vsWCb35gVme 231643 social-card.png

╰─ ✔ ❯ ipfs ls QmeUdoMyahuQUPHS2odrZEL6yk2HnNfBJ147BeLXsZuqLJ/images/ipfs-applications-diagram.png
QmaNPC2vHmMBTWtkhHmEGAojWMusidq63jFKvNczaSBim5 394    index.html
QmdmV2xUjRhhS2vAbtUPs837rKunfXZn8zHmTKu59bR649 937808 ipfs-applications-diagram.png

The not-found at site/helia-sw/QmeUdoMyahuQUPHS2odrZEL6yk2HnNfBJ147BeLXsZuqLJ/images/images/ipfs-applications-diagram.png/index.html is definitely a bug, i will look into it.

  1. The CID of the UnixFS directory being traversed needs to be in the subdomain somehow - otherwise if I have two websites I’m rendering:
    https://bafyfoo.on.fleek.co/helia-sw/QmGood
    https://bafyfoo.on.fleek.co/helia-sw/QmEvil
    QmEvil can read any cookies set by QmGood which leads to all sorts of credential-stealing vulnerabilities

I don't think we can do subdomains without getting a server/dns involved somehow. Each subdomain/origin would be a different service-worker instance, but we could re-use the same service worker code.

@SgtPooki
Copy link
Member Author

SgtPooki commented Apr 5, 2023

Others via slack:

Is putting the path into the URL bar viable as compared to using URL fragments with some escaping for existing fragments? I've noticed that if I refresh a page I end up with an error (probably from Fleek trying to resolve it) like ipfs resolve -r /ipfs/bafybeigqtacsovumsjmo7xgiaydqlp4jaqtwpuvciyhfasb4q3jeus3fzq/ipfs/QmeUdoMyahuQUPHS2odrZEL6yk2HnNfBJ147BeLXsZuqLJ: no link named "ipfs" under bafybeigqtacsovumsjmo7xgiaydqlp4jaqtwpuvciyhfasb4q3jeus3fzq

Since I changed the intercept path to be helia-sw we shouldn't run into the resolve -r /ipfs/ blah errors from fleek anymore. maybe i'm missing something.

Do we need this approach with paths to deal with range-requests for fragments of data like video?

Range requests are currently not implemented.. I was going to tackle that next. I also need to make sure ETag and caching is working properly, because it doesn't seem to be working 100% right now

@SgtPooki
Copy link
Member Author

SgtPooki commented Apr 5, 2023

@achingbrain fixed dir listing, thanks for calling that out. See video

helia-sw-dir-list-mostly-fixed.mp4

Copy link
Contributor

@whizzzkid whizzzkid left a comment

Choose a reason for hiding this comment

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

That looks like one hell of an example.

Q:

  • My SW never connects to peers, what could be the issue?
  • This work needs cleanup.
  • More comments from examples POV.
  • How would this even be tested?
  • Concerns in comments.

src/sw.ts Outdated
Comment on lines 26 to 27
console.log('stopping existing helia instance now')
await helia.stop()
Copy link
Contributor

Choose a reason for hiding this comment

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

does this even work? since this is a new worker, it won't have access to the helia instance from the old install.

You might not need this, but if you still, a better way to do this would be in the registration.

Copy link
Member Author

Choose a reason for hiding this comment

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

yea, i need an onUnregister for the sw, but I may not need to, haven't dove into it fully, but i'm also wondering if we actually want a persistent helia instance, or if we want to boot one up on every request.

I imagine that keeping the same instance running, with a timeout to stop it when no work is done in X period, might be the best solution for now.

console.log('intercepting request to ', urlString)
console.log('referred from ', request.referrer)
if (isReferrerPreviouslyIntercepted(event)) {
const destinationParts = urlString.split('/')
Copy link
Contributor

Choose a reason for hiding this comment

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

this sounds super dangerous, wondering is an injection is feasible.

Copy link
Member Author

Choose a reason for hiding this comment

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

more than likely with this current code, yes.

Co-authored-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
@SgtPooki
Copy link
Member Author

SgtPooki commented Apr 6, 2023

That looks like one hell of an example.

Q:

  • My SW never connects to peers, what could be the issue?

Sometimes I have to use bootstrapOnly and add my own peerID, but ipni should be working properly for you, may need a live debugging session so i can observe directly.

  • This work needs cleanup.

yes 100%, it's pretty messy, but i'm just trying to get things to a working point and can polish easily later. PR is more for testing than for code review.

A lot of code here exists just to debug why things don't work when they aren't working. (like the setInterval)

  • How would this even be tested?

as in unit/e2e tests?

e2e: probably with local node and a bootStrapOnly config to that specific node

unit: should be fairly straightforward for most of the code.

@SgtPooki SgtPooki merged commit 3bad813 into feat/gateway-handling Apr 6, 2023
@SgtPooki SgtPooki deleted the feat/load-html branch April 6, 2023 23:19
@lidel lidel mentioned this pull request Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants