Skip to content

cpalescan/safety_net

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SafetyNet

Running the code on one terminaò

First start the Mix project in iex:

iex -S mix

You can now initialise a demo with:

Demo.init()

This should initialise a demo with several ships. To simulate a failure, run:

Demo.stop(:A)

You can also 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})

This is the expected output from the Lighthouse:

[%Ship{id: 3, coords: {3, 3}, status: :PIRATES}, %Ship{id: 2, coords: {2, 2}, status: :alive}, %Ship{id: 1, coords: {1, 1}, status: :alive}]

You can verify the PIDs with:

GenServer.whereis({:global, 1}) # <- for ships
#PID<0.200.0>

GenServer.whereis(:lighthouse) # <- for the lighthouse
#PID<0.199.0>

Running on different nodes

To create a node

iex --sname <node_name> --cookie secret  -S mix

To connect nodes

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])

To spawn the Lighthouse (FRONTEND)

LighthouseServer.start_link

Installation

If available in Hex, the package can be installed by adding safety_net to your list of dependencies in mix.exs:

def deps do
  [
    {:safety_net, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/safety_net.

About

Elixir project 2025

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages