Skip to content

Latest commit

 

History

History
86 lines (60 loc) · 2.38 KB

README.md

File metadata and controls

86 lines (60 loc) · 2.38 KB

/pkg/pubsub

cd /

Note

asyncmachine-go is a declarative control flow library implementing AOP and Actor Model through a clock-based state machine.

/pkg/pubsub is a trustful decentralized synchronization network for asyncmachine-go. Each peer exposes several state machines, then starts gossiping about them and other ones known to him. Remote state machines are then visible to other peers as /pkg/rpc.LocalWorker. PubSub can be used to match Clients with Workers from /pkg/node.

Under the hood it's based on libp2p gossipsub, which is a mesh-based PubSub, also based on gossipping, but for the purpose of network topology. libp2p gossips are separate from gossips of this package.

Support

  • state checking YES
  • state mutations NO
  • state waiting YES

Features

  • gossip-based discovery
  • gossip-based clock updates
  • gossip-based checksums via machine time
  • rate limitting
  • no leaders, no elections

Screenshot

am-dbg view of a PubSub with 6 peers, with p1-p5 exposing a single state machine each.

Schema

State schema from /pkg/pubsub/states/.

worker schena

TODO

  • more rate limitting
  • confirmed handler timeouts
  • faster discovery
  • load test
  • mDNS & DHT & auth
  • optimizations
  • documentation
    • discovery protocol
    • sequence diagrams

Usage

import (
    ma "github.com/multiformats/go-multiaddr"
    ampubsub "github.com/pancsta/asyncmachine-go/pkg/pubsub"
)

// ...

// init a pubsub peer
ps, _ := ampubsub.NewTopic(ctx, t.Name(), name, machs, nil)
// prep a libp2p multi address
a, _ := ma.NewMultiaddr("/ip4/127.0.0.1/udp/75343/quic-v1")
addrs := []ma.Multiaddr{a}
ps.ConnAddrs = addrs
ps.Start()
<-ps.Mach.When1(ss.Connected, ctx)
ps.Mach.Add1()

Status

Alpha, work in progress, not semantically versioned.

Credits

monorepo

Go back to the monorepo root to continue reading.