Skip to content

Draft: Next version

Marcel Klehr edited this page Jun 2, 2014 · 5 revisions

Note: This is the draft of the next version of smokesignal. Feel free to leave comments along with your username


Model

smoke.createNode

  • config: myAddress
  • config: seeds #a known node, that's part of the network

Node

  • addPeer(address:port, cb(er, peer))
  • events: connect, disconnect, error, new peer
  • peers[]

Peer < DuplexStream

  • events: disconnect, error

Middleware? provide a Constructor of a DuplexStream (or rather a factory function?). Middleware streams are stacked on top of each other, above the DATA channel of the peer link. Perhaps send a list of applied middleware along with HANDSHAKE.

  • PGP? (mh. tls at a lower would prolly be better)
  • ...?

I don't know if middleware is at all useful.

Plugins can define and intercept custom messages and extend Node.prototype.

  • Broadcast
  • Ping/Autoping
  • Friendly (takes :desiredPeerCount)

Protocol (Peer -> Peer)

HANDSHAKE

  • read "would you like to be peers with me?"

SHAKEHAND

  • read "yep, I very much would like to be peers with you."

DATA

  • read "this is something I'd like you to know"

Scenario: HANDSHAKE/SHAKEHAND

  1. a and b are unconnected
  2. a connects to b
  3. a and b are connected
  4. a sends HANDSHAKE to b
  5. b end SHAKEHAND a
  6. a and b are peers

Scenario: DATA

  1. a and b are peers
  2. a sends DATA to b

Plugins

Plugin: Broadcast

BROADCAST

  • read "I want you and everyone else to know this."

Plugin: Ping

PING

  • read "Would you mind pass this around to everyone, until it reaches X? If you're X then please call me back."

PONG

  • read "Hey there, someone said I should call you?!"

Plugin: Friendly

NEEDFRIEND

  • read "Please tell everyone that they can shake my hand at X."

Plugin: Count

COUNT

  • read "Give this message to all your peers, unless you've got this already. If so, just return 1 to me with COUNTED. If not, sum the counts of your friends +1 and tell me the result with COUNTED."

COUNTED

  • read "I counted X."