First install dependencies and start the Mix project in iex:
mix deps.get
iex -S mixYou can now initialise a demo with:
Demo.init()This should initialise a demo with several ships. You will see log messages in the terminal. To simulate a failure, run:
Demo.stop(:A)You can add a new ship with:
Demo.add_ship(:ship_id, [:ship_2, :ship_3])By default the new ship's coordinates will be {0,0} but you can also specify them if you like by passing them as a third argument:
Demo.add_ship(:ship_id, [:ship_2, :ship_3], {10,10})You can also add multiple ships at once, for example:
Demo.add_ships(10, [:ship_2, :ship_3])The Lighthouse is a Phoenix app that uses PubSub to receive broadcasts about the ships and display them.
Start the Lighthouse with a cookie and a node name, e.g.:
iex --name lighthouse@localhost --cookie secret -S mix phx.serverNow when you start the SafetyNet app, use the same cookie:
iex --name <node_name> --cookie secret -S mixThen connect SafetyNet to the Lighthouse by running:
Node.connect(:lighthouse@localhost)Now the nodes should be connected. You can start the demo and the ships will broadcast updates to the Lighthouse automatically.
To create a node:
iex --sname <node_name> --cookie secret -S mixNow at this point if you have the Lighthouse running, you can simply connect each extra node running SafetyNet to the Lighthouse. They will join the network and be able to communicate with ships on other nodes.
If you aren't running the Lighthouse, simply connect nodes to each other:
Node.connect(:"node_name@user")To run a distributed demo, run Demo.init() in one terminal and in the other add some ships:
Demo.add_ship(:F, [:B, :C], {1, 1})
Demo.add_ship(:G, [:A])There are a few tests, you can run them with the following command:
mix test