conclave-team / conclave

CRDT and WebRTC based real-time, peer-to-peer, collaborative text editor
http://conclave.tech
MIT License
710 stars 130 forks source link

create broadcastSpec and buffer #1

Closed sunny-b closed 7 years ago

sunny-b commented 7 years ago

Created tests for the Broadcast class as well as created a buffer in incoming remote operations.

Additional changes:

How the Buffer works:

  1. When a remote operation is detected, Broadcast sends it to Controller to be handled.
  2. Controller first checks to see if that operation has already been integrated. If it has, it returns early. If it's a new operation, it broadcasts it out to all of it's peers and it adds it to the end of the buffer. (Lines 40-44)
  3. The Controller then reviews the buffer to integrate all the operations that are ready to be integrated. (Lines 50-65)
  4. Reviewing the buffer involves iterating over all the operations in the buffer (99% of the time it will just be one operation). The first step is a secondary check to see if the operation has already been integrated into the CRDT. This is in case two duplicate operations somehow manage to sneak into the buffer before the VersionVector is updated. If it's a duplicate, it's spliced out. (Lines 56-58)
  5. If the operation is a new operation, it checks to see if that operation is ready to be integrated (inserts are always ready, but deletes have to make sure the char they are deleting already exist). (Lines 86-96).
  6. If the operation is ready to be integrated, it is inserted into the CRDT, the VersionVector is updated, and the editor is updated (the operation is spliced out of buffer after being integrated). (Lines 100-112).
  7. The buffer keeps iterating over all operations until no new operations have been integrated (this is in the case that operations are being received out of order and therefore aren't integrated on the first pass through).