/hypercore-playground

Primary LanguageJavaScriptOtherNOASSERTION

hypercore-playground

Build Status js-standard-style

Simple playground on the hyper stack

Motivation

I always found fascinating the tech behind some p2p technology. Lastly I've saw some pretty interesting things about beaker browser, this talk and, more deeply this post. However, this intersting distributed world seemed just to complicated to me, and even though the teams behind the tech I was watching (The hyper stack and Dat project before that) have done an amazing job on their documentation, I still haven't find any beginner friendly introduction.

So I decided to try already those libraries, by making some simple chat like examples, and share what I found, this isn't the beginner guide I was looking for, because I can't even assure I would come to something useful, but it's going to be at least something fun.

File structure

I have organized this repo in folders grouped by the main module that I'm testing in it, the organization is clear but very opinionated.

Discovers

hyperswarm

A high-level API for finding and connecting to peers who are interested in a "topic."

  • minimal: Here is what I have as a minimal hyperswarm implementation. It could be even more minimal by using nodes native crypto module instead of sodium. This one was surprisingly easy, but has some drawbacks. When a peer process is killed it kills all other peers, this seems to be because I'm connecting directly to the process stdio streams.
  • fancy: This one was a mess. I just tried to make it look like a chat by changing the log, but it seems to be quite difficult to change process.stdout as many sites suggest. So this is broken.
  • universal-chat: This is basically RangerMauve/hyperswarm-universal-chat. I've just added some code for deduplication.

hypercore

Hypercore is a secure, distributed append-only log.

  • minimal: I actually started trying with the chat folder, but had no result. So tried a bit simpler approach but have issues also. After a lot of old school debuggin (console.log every where) I found out that my error was because of this code pattern
feed = hypercore(ram, argv.key)
// ...
feed.append(data, (err, seq) => {
  if (err) {
    console.error(err)
    process.exit(1)
  }
})

that's because you can´t write data to a feed that you didn't create, you can see that from hypercore tests (the are very illustrative)

License

MIT