easily create a duplex protocol that starts with a handshake
Make a duplex protocol that starts with a handshake.
Writing duplex protocols are difficult. (don't get me started on "callback hell", that is nothing) This module implements the boiler plate for a duplex protocol where a handshake is exchanged (and calculating the handshake can be async)
The basic outline for the sort of protocol you can build with pull-handshake is as follows:
- two entities (databases, etc) connect via a stream.
- each retrives some meta information (asyncly) and sends that to the other side.
- when each node has both retrived it's own metadata, and recieved the remote data, that is compared - and the node determins what data must be sent, and what to do with the data that is expected to be received.
handshake//callback with your metadatagetMyMetadatacb//compare my header with your header and decide what to send.var missing = findDifferenceme you//return a duplex pull-stream, that handles both reading and writing.returnsource: createReadStreammissingsink: createWriteStream
see pull-2step-replicate for a working example.