peer-base / peer-pad

📝 Online editor providing collaborative editing in really real-time using CRDTs and IPFS.
https://peerpad.net
MIT License
678 stars 57 forks source link

connection/synchronization/pinning state machine #266

Open parkan opened 5 years ago

parkan commented 5 years ago

aggregating concerns from:

The Problem

peer-pad can be in a variety of states, depending on interactions between your peer, other peers in the collaboration, other peers in the app (but not in your collaboration), and pinners:

etc

this results in confusing feedback for users, difficulty in debugging, and erratic behavior

FSM Solution

intuitively, these state can be represented by a finite state machine, describing valid states and transitions between them. It might be convenient to represent the state as tuples of (app state, collaboration state, pinner state) like (online, synchronized, sending)

this can get pretty complicated as the number of possible states is large, but it's worth trying to sketch out to see just how hairy it gets

libp2p has recently implemented the dialFSM Connection State Machine, which can form the basis and example for our effort

parkan commented 5 years ago

this is probably generalizable to peer-star-app, but it's easier to think about in terms of a concrete application so I'm opening this here for now

jimpick commented 5 years ago

This would be very useful for tests as well.

jimpick commented 5 years ago

Here are some fun FSM links:

This looks like a nifty library I haven’t tried yet:

https://github.com/davidkpiano/xstate

Here’s a simple lib for UIs from the Choo project:

https://github.com/choojs/nanostate/

The really interesting stuff is “Finite State Transducers”, which are used for things like speech recognition... the Kaldi project uses OpenFST (C++):

http://www.openfst.org/

parkan commented 5 years ago

FSTs look like a cool extension of FSMs but I really hope we don't have to use probabilistic state transitions anytime soon 😅

nanostate reminds me of the first real website I worked on, which badly needed a state machine because it played music (hypem.com)

jimpick commented 5 years ago

Some of the heavier-duty computer science-y stuff is probably going to be necessary if we go in the direction of trying to model the state of peer-to-peer swarms ... there's a lot of state in something like that!

jimpick commented 5 years ago

I was playing around with XState, and I made a little prototype of using it to drive a simulation using peer-base...

https://github.com/jimpick/peer-base-xstate-playground

Demo

marcooliveira commented 5 years ago

For reference, this relates to: https://github.com/peer-base/peer-base/issues/227