Skip to content

Commit

Permalink
Added list and get_by_interface_id for tunnels
Browse files Browse the repository at this point in the history
  • Loading branch information
mobileoverlord committed Jul 12, 2024
1 parent d92e5bf commit 6ed7b06
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: '1.17.0'
elixir-version: '1.17.2'
otp-version: '27.0'
- name: Restore dependencies cache
uses: actions/cache@v4
Expand Down
20 changes: 20 additions & 0 deletions lib/peridio/rat.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,24 @@ defmodule Peridio.RAT do
GenServer.cast(pid, {:extend, expires_at})
end
end

def list_tunnels() do
Peridio.RAT.DynamicSupervisor
|> DynamicSupervisor.which_children()
|> Enum.map(&elem(&1, 1))
|> Enum.map(&{&1, Tunnel.get_state(&1)})
|> Enum.map(fn {pid, %Tunnel.State{id: id, interface: interface}} ->
{pid, id, interface}
end)
end

def get_tunnel_by_interface_id(interface_id) do
case Registry.select(:tunnels, [
{{:"$2", :"$1", :"$3"}, [{:==, {:map_get, :id, :"$3"}, interface_id}],
[{{:"$1", :"$2", :"$3"}}]}
]) do
[] -> nil
[tunnel] -> tunnel
end
end
end

0 comments on commit 6ed7b06

Please sign in to comment.