diff options
Diffstat (limited to 'shard/lib/manager.ex')
-rw-r--r-- | shard/lib/manager.ex | 103 |
1 files changed, 1 insertions, 102 deletions
diff --git a/shard/lib/manager.ex b/shard/lib/manager.ex index 1e089ba..9def229 100644 --- a/shard/lib/manager.ex +++ b/shard/lib/manager.ex @@ -40,23 +40,6 @@ defmodule Shard.Manager do List of { {id, path}, pid } - - - :connections (not persistent) - - List of - { peer_info, pid, nil | {my_pk, his_pk} } - - And an internal table : - - - :outbox (not persistent) - - Multi-list of - { dest_peer_info, message, time_inserted } - - dest := peer_info - - No support for messages on authenticated channels - """ use GenServer @@ -82,10 +65,8 @@ defmodule Shard.Manager do :dets.open_file(@peer_db, [type: :bag]) :ets.new(:shard_procs, [:set, :protected, :named_table]) - :ets.new(:connections, [:bag, :protected, :named_table]) - outbox = :ets.new(:outbox, [:bag, :private]) - {:ok, %{outbox: outbox} } + {:ok, nil} end def handle_call({:register, shard_id, manifest, pid}, _from, state) do @@ -131,41 +112,6 @@ defmodule Shard.Manager do {:noreply, state} end - def handle_cast({:peer_up, pid, peer_info, auth}, state) do - :ets.insert(:connections, {peer_info, pid, auth}) - - # Send interested message for all our shards - id_list = (for [{id, _, _}] <- :dets.match(@shard_db, :"$1"), do: id) - GenServer.cast(pid, {:send_msg, {:interested, id_list}}) - - # Send queued messages - for {_, msg, _} <- :ets.lookup(state.outbox, peer_info) do - GenServer.cast(pid, {:send_msg, msg}) - end - :ets.delete(state.outbox, peer_info) - - {:noreply, state} - end - - def handle_cast({:peer_down, peer_pid, peer_info, auth}, state) do - :ets.match_delete(:connections, {peer_info, peer_pid, auth}) - {:noreply, state} - end - - def handle_cast({:connect_and_send, peer_info, msg}, state) do - case :ets.lookup(:connections, peer_info) do - [{_, pid, _}|_] -> - GenServer.cast(pid, {:send_msg, msg}) - [] -> - add_peer(peer_info) - currtime = System.os_time :second - :ets.insert(state.outbox, {peer_info, msg, currtime}) - outbox_cleanup = [ {{:_, :_, :'$1'}, [{:<, :'$1', currtime - 60}], [true]} ] - :ets.select_delete(state.outbox, outbox_cleanup) - end - {:noreply, state} - end - def handle_info({:DOWN, _, :process, pid, _}, state) do :ets.match_delete(:shard_procs, {:_, pid}) {:noreply, state} @@ -212,26 +158,6 @@ defmodule Shard.Manager do # ================ @doc""" - Send message to a peer specified by peer id - """ - def send_pid(pid, msg) do - GenServer.cast(pid, {:send_msg, msg}) - end - - @doc""" - Send message to a peer specified by peer info. - Opens a connection if necessary. - """ - def send(peer_info, msg) do - case :ets.lookup(:connections, peer_info) do - [{^peer_info, pid, _auth}|_] -> - GenServer.cast(pid, {:send_msg, msg}) - [] -> - GenServer.cast(__MODULE__, {:connect_and_send, peer_info, msg}) - end - end - - @doc""" Register a process as the main process for a shard. Returns either :ok or :redundant, in which case the process must exit. @@ -277,22 +203,6 @@ defmodule Shard.Manager do # ================ @doc""" - Connect to a peer specified by ip address and port - """ - def add_peer({:inet, ip, port}) do - spawn fn -> - case :gen_tcp.connect(ip, port, [:binary, packet: 2, active: false]) do - {:ok, client} -> - my_port = Application.get_env(:shard, :port) - {:ok, pid} = DynamicSupervisor.start_child(Shard.DynamicSupervisor, {SNet.TCPConn, %{socket: client, my_port: my_port, is_client: true, auth: nil}}) - :ok = :gen_tcp.controlling_process(client, pid) - _ -> - Logger.info "Could not connect to #{inspect ip}:#{port}, some messages may be dropped" - end - end - end - - @doc""" Returns the pid for a shard if it exists """ def find_proc(shard_id) do @@ -308,15 +218,4 @@ defmodule Shard.Manager do def list_shards() do for [x] <- :dets.match(@shard_db, :"$1"), do: x end - - @doc""" - Return the list of all connected peers - """ - def list_connections() do - for [x] <- :ets.match(:connections, :"$1"), do: x - end - - def get_connections_to(peer_info) do - for {^peer_info, pid, auth} <- :ets.lookup(:connections, peer_info), do: {pid, auth} - end end |