peer-pad
peer-pad copied to clipboard
connection/synchronization/pinning state machine
aggregating concerns from:
- https://github.com/ipfs-shipyard/peer-pad/issues/251
- https://github.com/ipfs-shipyard/peer-pad/issues/264
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:
- offline (no IPFS peers)
- online, no app peers
- online, some app peers, no collaboration peers
- no content received
- receiving state from peers
- state received from pinner
- sending state to pinner
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
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
This would be very useful for tests as well.
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/
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)
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!
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

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