dat-ecosystem-archive / datproject-discussions

a repo for discussions and other non-code organizing stuff [ DEPRECATED - More info on active projects and modules at https://dat-ecosystem.org/ ]
65 stars 6 forks source link

Plausibility of simple Chrome or Firefox plugins #84

Open aaronshaf opened 6 years ago

aaronshaf commented 6 years ago

It seems any Dat plugins so far require manually running a process in the background. Is it plausible to have a major browser plugin for Dat that doesn't require that?

RangerMauve commented 6 years ago

I think the easiest way forward for that is to use a public gateway kinda like http://gateway.mauve.moe:3000 and have that bundled in the extensions by default.

I'm planning on supporting plugin-less Dat interaction by relying on the gateway to inject the DatArchive API into the HTML of a page.

RangerMauve commented 6 years ago

The biggest limitation is that discovery-swarm won't work in a browser plugin due to the environment differences (no TCP/UDP/MDNS).

soyuka commented 6 years ago

It seems any Dat plugins so far require manually running a process in the background. Is it plausible to have a major browser plugin for Dat that doesn't require that?

Mhh I think you could do that by mapping fs access to some kind of browser-only storage (I think that @pfrazee did some experiments on storing blobs in indexedDB). As long as there is no reliable way to store data inside browsers it's hard but non impossible :).

I've choose to add a websocket-backed gateway that should give full dat-power in the browser. I'm successfully reading files managed by dat from the browser. Didn't published the full documentation yet but the code is available here if you want to take a peak!

Recently @sammacbeth built https://github.com/sammacbeth/dat-fox which has a dat protocol handler. This handler simply uses an http gateway to render dat pages in the browser. It's also a good place to look !

sammacbeth commented 6 years ago

As mentioned, there are several limitations in the browser extension APIs and environment preventing this:

  1. The protocol_handlers API only allows a protocol to be registered as a redirect to another url. As you also cannot register a function as a protocol handler, nor run a HTTP server inside an extension, this prevents the extension from serving the protocol itself. With the old Firefox Bootstrap extensions all of this was possible, however these can no longer be used with Firefox. The Firefox Addons team are generally receptive to new API proposals though.

  2. No socket API. Extensions are limited to http(s), websockets and WebRTC, and so would not be able to communicate with nodes running node dat.

  3. No file API, though IndexedDB could provide a file-like abstraction. This storage is, however, potentially volatile, as the browser may impose storage constraints, and it is very easy to accidentally delete.

Given these limitations, for the near future a secondary process is required. On the dat-fox I am proposing limiting the technical overhead of this, by installing a Native manifest for the gateway executable in the browser, such that, once installed, the user does not have to launch this process themselves. The browser automatically launches the process when the extension is started (this is part of the Native messaging API and also available in Chrome).

Public gateways are another option, but they introduce a significant privacy issue as the operator can observe all of the dat browsing of users. There are also many cases where it is required that dat urls should be kept secret to prevent unauthorised access to the content, and a public gateway would not be safe for these use-cases.

soyuka commented 6 years ago

Nice input! Tyvm about the Native messaging API thing, wasn't aware of that possibility!

Public gateways are another option

Like https://hashbase.io/ I guess. Although they kinda break the p2p utopia in which they are centralized?

RangerMauve commented 6 years ago

I see public gateways as a temporary solution to just bring the technology to people with as little effort as possible.

If you can make something using dat and share it to people that might not know about it yet, you could create network effects and get people more interested in installing extensions to get better support (performance, privacy).

Getting people to check out new web apps is hard enough, it's even harder if they need to install and configure some sort of software first. A gateway can get your Dat-based applications in front of people now and spread general usage of these apps and give incentives for browsers to support the APIs and protocols.

joehand commented 6 years ago

If y'all haven't seen it, some good work going on here: https://github.com/goonism/hyperproxy/ to support out of the box Dat browsing via a gateway + webrtc

https://hyperproxy.network/

RangerMauve commented 6 years ago

I like the idea behind hyperproxy, but IPFS has tried to use WebRTC for P2P stuff and the performance was crappy which made me kinda skeptical of using WebRTC for anything large scale (say more than 10 peers).

Signaling servers are a point of centralization which discovery-swarm eliminates by using the DHT and MDNS, and you can't have WebRTC without them.

If all of dat switched to WebRTC and WS for transports, and non-browser clients had signaling servers built into them, then this approach would be a lot more scalable. Otherwise I think that getting first-class browser support though the existing dat network is going to be more important.

Of course using WebRTC and signaling servers is a hell of a lot more decentralized than dat-gateway. :P

RangerMauve commented 6 years ago

I'm gonna be working on enabling the Bunsen browser folks to have a more complete solution and working on features to make a PWA that uses dat-gateway to allow people to use dat:// urls without installing anything and using a web app instead (to enable casual users to be exposed to the concept). I'll have the web app try to persuade people to install any extensions or browsers that would be better suited for their platform.

rjcorwin commented 6 years ago

I'm helping out with the Bunsen efforts and believe all these directions are worth exploring. Currently Bunsen UI looks for a local dat gateway first localhost:3000, if it doesn't find one, then it falls back to @RangerMauve's gateway. We also published the Bunsen UI as a Dat so the Android App which is bundled with a local gateway can serve the UI through the gateway. That means in any browser we can also see the Bunsen UI by hitting an online gateway -> http://gateway.mauve.moe:3000/bunsen.hashbase.io/

That puts us two steps away from having a Bunsen PWA. To get browsers to prompt users to install PWA we'll need to add the necessary manifest file to Bunsen UI and also get the gateway on https. We're close and very excited about the potential of getting DatArchive API working!

RangerMauve commented 6 years ago

I've added my initial implementation of redirecting Dats to use subdomains

https://github.com/RangerMauve/dat-gateway/tree/subdomain-redirect

Run it using node bin.js -r and navigate to http://lvh.me:3000/40a7f6b6147ae695bcbcff432f684c7bb5291ea339c28c1755896cdeb80bd2f9 to get redirected to http://82kzddgmfbk9bf5wzx1jyu2cfeujj7n37718r5unh5pdxe0bubwg.lvh.me:3000/

RangerMauve commented 6 years ago

@rjsteinert Have you looked into using the registerProtocolHandler API to register a webpage as a protocol handler? Maybe that paired with an iframe loading gateway content could be enough to make a web app that loads dat:// URLs through the gateway.

soyuka commented 6 years ago

Maybe that paired with an iframe loading gateway content could be enough to make a web app that loads dat:// URLs through the gateway.

I had a successful experiment with this.

RangerMauve commented 6 years ago

@soyuka That's awesome! Do you think you'd be interested in setting something up that works with my public gateway http://gateway.mauve.moe:3000/

RangerMauve commented 6 years ago

I've updated my public gateway to support the redirect to subdomains, but I've got a bug that means DatDNS doesn't work any more.

RangerMauve commented 6 years ago

Disregard the DatDNS thing, got it working. :D

RangerMauve commented 6 years ago

I think there should be a different default port for the gateway since 3000 is pretty generic and can clash with other services. I suggest port 3495 which is 0xDA7 in hex, which kinda looks like DAT.

rjcorwin commented 6 years ago

@RangerMauve Looks like decent support for navigator.registerProtocolHandler. That's very similar to how we handle dat:// links in Android using Intents API. I wonder if Chrome will allow handling of dat protocol, probably not right? Firefox though :). GIving it a try.

Awesome job on the gateway! Not only does that increase security immensely, it fixed a bunch of sites that wanted to live at the root of a domain.

RangerMauve commented 6 years ago

@rjsteinert I also updated the gateway and dat-archive-web To support DatArchive.resolveName and improved detection of HTTPS. Check out this branch.

Version doesn't work at the moment due to url parsing shenanigans.

Next gonna work on getting fork to work.

DNS URLs in the constructor don't work yet, so I might address that before fork.

Not sure what to do about commit/diff/etc.

Eventually I'll need to set up an SSL certificate. Might be a pain since I need a wildcard.

rjcorwin commented 6 years ago

As expected, Chrome doesn't play well with apps registering as protocol handlers for dat://.

screen shot 2018-04-19 at 10 23 55 pm

Firefox I bet works, but now I'm realizing our Web Components based Bunsen UI is having trouble in Firefox. Time to work on that :).

For SSL, I've had luck with some Lets Encrypt tooling that makes setting up a proxy with SSL support with Docker pretty easy. Recently I remember reading they added support for wildcards. An example -> https://github.com/rjsteinert/serve-a-static-site-with-ssl-example

soyuka commented 6 years ago

In the mean time use web+dat or ext+dat!

Interesting topic also: https://news.ycombinator.com/item?id=16242336

rjcorwin commented 6 years ago

Thanks @soyuka for the interesting read. We got Bunsen working for Firefox and see that registering to protocol handler is working.

screen shot 2018-04-20 at 7 07 15 pm

You can try it out on the gateway I just started http://104.236.57.117:3000/bunsen.hashbase.io/

Bunsen it not compatible with @RangerMauve's recent update to his gateway but we're looking forward to being compatible ASAP!

RangerMauve commented 6 years ago

@rjsteinert oh no, did I break something?

rjcorwin commented 6 years ago

Probably me! I've been working on Bunsen in the past hour trying to figure out a URL issue I'm starting to think is related to version of dat-gateway we're running for Bunsen. Btw, I love this "bug" I found.

woof

Shall we continue our discussion on dat-gateway in your repo's issue queue? (The issue queue is currently disabled)

RangerMauve commented 6 years ago

Oh snap I thought I fixed that. Enabled issues. I'm about to fall asleep though so you may need to wait 11 hours for me to get back on it. :P

rjcorwin commented 6 years ago

LOL yes it's fixed! That was gif from earlier today. Time flies! Have a good rest.

RangerMauve commented 6 years ago

I've released version 1.0.0 of dat-archive-web to NPM.

Everything is supported now except for archive.diff(), archive.commit(), and archive.revert(). DatArchive.selectArchive doesn't work for the default version, but it's easy to add behavior to support it.

Next step is going to make a dat-polyfill which will do link renaming (for images/iframes/anchors linking to dat://) and provide the DatArchive global which will attempt to either connect to the local gateway or the public one, and will coordinate with an iframe to do a rudamentary selectArchive dealio.

@rjsteinert Do you have time to talk about this polyfill stuff? I think this is basically what bunsen-ui is trying to do. I'm going to do the initial work for the polyfill, but I'll want to talk about persisting data between pages and how selectArchive should work.

rjcorwin commented 6 years ago

Bunsen handles URLs in three scenarios... 1) You are in the Android Bunsen App, using Intents API the app is registered on the system level as a handler of dat:// links. 2) You are in a browser that supports navigator.registerProtocolHandler https://github.com/bunsenbrowser/bunsen-ui/blob/master/src/bunsen-app/bunsen-app.html#L140 3) You are not in any of those so start the anchor link rewrite party! https://github.com/bunsenbrowser/bunsen-ui/blob/master/src/bunsen-app/bunsen-app.html#L145

How about 9pm ET tonight at https://talky.io/dat-polyfills ? All are welcome to join.

RangerMauve commented 6 years ago

21:00 ET works for me. :D

RangerMauve commented 6 years ago

Also, regarding option 3, I suggest using a MutationObserver which filters for nodes with the src and href attributes paired with an initial change instead of polling twice a second. I think that would be more efficient and eat less CPU

RangerMauve commented 6 years ago

I did some work on dat-polyfill

The idea is that it uses RPC over window.postMessage to talk to either a parent frame (with fallback to gateway).

The RPC API is there to emulate random-access-storage to deduplicate storage between everything, as well as addArchive which helps the parent track newly created iframes, and selectArchive that lets the parent prompt the user with some sort of UI to choose an archive from the ones that got tracked via addArchive.

An idea I have is to make the homepage of dat-gateway redirect to the bunsen UI and to inject this polyfill into HTML pages served from the archive.

Another idea I had is that the parent frame can explicitly specify what the gateway URL should be in the querystring (or we could auto-detect from window.location, I guess)

I'm not sure if the parent frame would be able to just inject JS content if it's got the same parent domain, though, which would be a lot easier.

sammacbeth commented 6 years ago

An update on dat-fox.

  1. The installation of the gateway is now reduced to a one-liner command (for Mac and Linux). Once this installation is done, the launching and management of the gateway process is done by the browser and extension, so no manual action is required on the user's part after installation.
  2. A full implementation of DatArchive is provided. That means fork, create and write too. Therefore many of the use-cases provided in beaker can now also be achieved in Firefox. For example, I forked and edited an orkl blog in Firefox, and published to hashbase. Note that not all apps are working, the next step will be to find out where the incompatibilities lie.

dat-create

pfrazee commented 6 years ago

@sammacbeth Nice!! Looking forward to seeing more

RangerMauve commented 6 years ago

@sammacbeth You mentioned in IRC about getting it to work on Android, what are your plans for that? A companion application?

sammacbeth commented 6 years ago

@RangerMauve most of the existing extension should be compatible with Firefox on Android, it would just require a substitute for the native messaging between extension and gateway. One method would be a companion app, and communicate between the apps over HTTP.