sendy-ws
v1.5.2
Published
The clients in these modules are broken up into two types, reliable and unreliable
Downloads
7
Keywords
Readme
Messenger pipeline
The clients in these modules are broken up into two types, reliable and unreliable
Unreliable clients can fail to deliver messages, get disconnected, etc. When you say unreliable.send(msg)
, you will never know if it was delivered. These clients talk directly over an unreliable network: websockets, udp, etc.
Reliable clients have no concept of a network, but guarantee in-order delivery if plugged into an unreliable client. At the core of the reliable client pipeline is a delivery-mechanism-agnostic implementation of the UTP protocol.
In certain situations, you need to wrap each packet that travels across the network in a special envelope, in which case you have the design below.
Because the UTP protocol will break things up into messages,
The basic design:
top level (application layer)
var reliable = {} // one per sender/recipient pair
// these can vary var unreliable = new Client({ url: '/some/websocket/url' }) (knows nothing of recipients)
// these guys don't know about unreliable // just a msg pipeline reliable[to].send(msg) // e.g. @tradle/otr-client -> sendy.send(msg) // length-prefix (@tradle/sendy) ('send', piece) // utp (break up into pieces) <- // bubble <- // bubble ('send', msg, to)
// we know who it's for because all those intermediates // are per-recipient
msg = wrap(msg) // wrap in to/from envelope u.send(msg)
u.on 'message' msg = unpack(msg) // unwrap envelope -> clients[msg.from].receive(msg.data) // bubble -> sendy.receive(msg) // bubble ('receive', msg) // piece-together, emit <- // length-prefix <- // otr client msg