aboutsummaryrefslogtreecommitdiff
path: root/lib/net/manager.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/net/manager.ex')
-rw-r--r--lib/net/manager.ex9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/net/manager.ex b/lib/net/manager.ex
index e5eb12d..4b1ce94 100644
--- a/lib/net/manager.ex
+++ b/lib/net/manager.ex
@@ -40,7 +40,12 @@ defmodule SNet.Manager do
{:noreply, state}
end
- def handle_call({:get_connections, pk_list}, state) do
+ def handle_call(:get_all, _from, state) do
+ pid_list = (for {_, {pid, _, _}} <- state.peers, pid != nil, do: pid)
+ {:reply, pid_list, state}
+ end
+
+ def handle_call({:get_connections, pk_list}, _from, state) do
pid_list = (for pk <- pk_list, Map.has_key?(state.peers, pk), do: state.peers[pk])
|> Enum.map(fn {pid, _, _} -> pid end)
|> Enum.filter(&(&1 != nil))
@@ -53,7 +58,7 @@ defmodule SNet.Manager do
def add_peer(ip, port, my_port) do
{:ok, client} = :gen_tcp.connect(ip, port, [:binary, packet: 2, active: false])
- {:ok, pid} = DynamicSupervisor.start_child(SNet.ConnSupervisor, {SNet.TCPConn, %{socket: client, my_port: my_port}})
+ {:ok, pid} = DynamicSupervisor.start_child(Shard.DynamicSupervisor, {SNet.TCPConn, %{socket: client, my_port: my_port}})
:ok = :gen_tcp.controlling_process(client, pid)
pid
end