http://ephemeralp2p.durazo.us/2bbbf21959178ef2f935e90fc60e5b6e368d27514fe305ca7dcecc32c0134838 <h1>This page exists only if someone is looking at it</h1> <p> Hi! Welcome to Ephemeral P2P. Thank you for loading this content. Your browser retrieved it from the browser of someone currently viewing this page. You're now a part of the network and someone who loads this page in the future may get it from you! </p> <p> The server does not store this content anywhere, so as soon as the last person closes their browser, it's gone. You can see a count of how "healthy" the page is (how many people are viewing the content) at the top. </p> <h2>How does it work?</h2> <p>At a high level, this is what happens:</p> <ol> <li>From <a href="/">the homepage</a> you enter the content you want to share.</li> <li>When you submit it, you register the SHA-256 hash of the content on the server.</li> <li>Your browser stands by with an open websocket to the server.</li> <li>When someone else visits a link "/[sha256hash]", the server tries to retrieve the content from anyone registered with that hash. The server double checks the hash of the content it gets and then passes it along to the new person.</li> <li>That new person now registers with the server as someone who knows the content for that hash.</li> </ol> <h2>But why?</h2> <p> Just a simple experiment to play with websockets and concurrency. </p> <p> The app is built in Elixir (compiles to erlang) with the Phoenix framework, since it supports websockets out of the box. It's very "railsy" and in addition to rails-style "controllers", it has "channels" which are like controllers for websockets. Made building this thing a snap. </p> <p> The app is hosted on a heroku 1X dyno and I'm hoping this hits the front page of HN to see how many concurrent connections I can squeeze out of it. Erlang is known for its concurrency, so I'd love to know how Elixir/Phoenix can serve as an alternative to my usual rails when highly concurrent solutions are needed. I plan to tweet my findings, so you can follow me (<a href="http://twitter.com/losvedir">@losvedir</a>) if you're interested in them. </p> <h2>Where do we go from here?</h2> <p> There are two aspects to this project that I've found quite interesting, that I hope people explore: </p> <h3>Peer-to-peer over browser websockets</h3> <p> Does something like this exist? I opted for P2P of HTML injected into a container div, since I didn't want to deal with the legalities of clients sharing binary files back and forth. But someone wanting to deal with DMCA and all that might have an interesting service here. </p> <p> I could see this being a great alternative to something like sendfile (I think that's a thing?), or DropBox, or what have you, when you just want to send a file to a friend and it's too big for email. Big files could even be broken up into individual SHA-256'ed pieces, and the list of SHA-256 hashes could be the thing sent. The other side would then fetch each piece in turn and re-assemble. </p> <p> But that's starting to sound kind of like BitTorrent... I wonder if someone could even make a web-based bittorrent client along these lines. </p> <h3>Content addressed web</h3> <p> The cool thing about the page content being represented by its SHA-256 hash is that it doesn't matter where the content comes from. If anyone sends you the content, you can verify that it's what you were looking for. This makes it well suited for peer-to-peer or otherwise distributed file serving. <p> <p> Imagine essentially an archival service where all kinds of content (web pages, mp3s, videos, etc) are indexed according to their SHA-256. Hopefully this content would be distributed around the world and backed up and all that good stuff. Then if someone tweets a "hey, checkout this video I made [a2b89..]", it can be retrieved from this "global store of all content" using that hash. It's already very common to mention the SHA-256 alongside a download. Just think if you could take that and download from this service. </p> <p> Wikipedia is an amazing collection of knowledge in terms of articles. It seems like it would be valuable to have a similar nonprofit service that was a repository of "notable" files. </p> <h2>A quick warning</h2> <p> I don't do any sanitization of the shared HTML content, so be wary of other links that folks may post. But I don't think it's too great of a security risk, since there's nothing private here (no https), and you shouldn't be trusting me any more than any other random internet person. </p> <h2>In closing...</h2> <p> Thanks for checking this out! Feel free to <a href="https://github.com/losvedir/ephemeral2">fork the repo on github</a> and play around with it yourself! </p> <p> And a big thanks to the friendly folks on the #elixir-lang IRC channel who have been very helpful in building this. </p> <p> A (more) permament version of this content <a href="https://github.com/losvedir/ephemeral2/wiki/This-page-exists-only-if-someone-is-looking-at-it">can be found here</a>. </p>