peer-pad icon indicating copy to clipboard operation
peer-pad copied to clipboard

connection/synchronization/pinning state machine

Open parkan opened this issue 6 years ago • 7 comments
trafficstars

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

parkan avatar Dec 11 '18 18:12 parkan

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

parkan avatar Dec 11 '18 18:12 parkan

This would be very useful for tests as well.

jimpick avatar Dec 12 '18 05:12 jimpick

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/

jimpick avatar Dec 12 '18 10:12 jimpick

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)

parkan avatar Dec 12 '18 15:12 parkan

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 avatar Dec 12 '18 18:12 jimpick

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

jimpick avatar Jan 05 '19 20:01 jimpick

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

marcooliveira avatar Jan 07 '19 02:01 marcooliveira