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 2d9ec52
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/peridio/rat.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,25 @@ defmodule Peridio.RAT do
GenServer.cast(pid, {:extend, expires_at})
end
end

def list_tunnels() do
tunnel_pids =
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 2d9ec52

Please sign in to comment.