GithubHelp home page GithubHelp logo

losvedir / ephemeral2 Goto Github PK

View Code? Open in Web Editor NEW
821.0 23.0 49.0 369 KB

Ephemeral P2P over websockets, Phoenix/Elixir.

License: MIT License

JavaScript 16.80% Elixir 76.47% CSS 0.70% HTML 6.03%

ephemeral2's Introduction

Ephemeral P2P

See example implementation running here. Discussion on Hacker News here.

This app hosts "P2P" pages that are "ephemeral". We say "P2P" because the clients host the page; new visitors retrieve the page contents from other visitors on the same page. It's "ephemeral" in that the server does not store the contents of any page, so once the last visitor leaves a particular page, it is gone.

How it works

Ephemeral P2P is an Elixir/Phoenix app, taking advantage of Phoenix's excellent Channel functionality. All of the logic lies in two channels, the HaveChannel for clients who have a particular bit of content, and the WantChannel for visitors who want it. The content is addressed by its SHA256 (let us say abc123), and the two topics associated with that content are have:abc123 and want:abc123.

A new page is created from the homepage. A visitor fills in the textarea with whatever content they desire, and presses the "Submit" button (which is not a form submission). The client hashes the content (let's call the hash abc123) and uses the HTML5 history api to change the URL to /abc123 for easy copy/paste-ability. The client then joins the "have:abc123" topic and begins listening for "content_request" messages, ready to respond with a "content" message that includes the page content which it has in memory.

A subsequent visitor who loads /abc123 joins the want:abc123 topic and tries to obtain the content. First it listens for a "content" message that another visitor may have provoked. If the visitor does not receive it in 2 seconds, it will send a "content_request" message itself. The server will re-broadcast this message to all have:abc123 subscribers, except that a handle_out will allow the message with probability 1/subscriber_count and drop it otherwise. Any have:abc123 subscribers who receive the message will respond with the content and the server will broadcast it to all want:abc123 subscribers. The new visitor will send a "content_request" message every 2 seconds until it gets the content (for the case where the handle_out drops the message to everyone, or a have subscriber fails to respond for some reason.)

When a want:abc123 subscriber gets the content, it leaves the want:abc123 topic and joins the have:abc123 topic, ready to pass it along to newer visitors.

Lastly, whenever a subscriber joins or leaves have:abc123, the new visitor count is broadcast, so all clients know the "health" of the page and how close it is to going away.

Run it yourself

First you'll need to install Elixir. Once you have elixir set up, it should be as easy as:

$ git clone [email protected]:losvedir/ephemeral2.git
$ cd ephemeral2
$ mix deps.get
$ mix phoenix.server

That should serve a copy of the app locally at localhost:4000. If you would like to modify the CSS or Javascript, you'll need to install npm and then brunch with:

$ npm install -g brunch

ephemeral2's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ephemeral2's Issues

Use WebRTC when possible

WebRTC data channels let browsers pass data directly between themselves, without relying on the server. If this system could use data channels for actual content delivery, the server would only have to route contact information between browsers, rather than the actual data. This dramatically improves the scalability of the system. Sharefest does basically this using BitTorrent.

A python client exists

I wrote this back in 2016 and have been running it ever since. There's really no point to this, just wanted to let people know.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.