aboutsummaryrefslogtreecommitdiff
path: root/lib/net
diff options
context:
space:
mode:
Diffstat (limited to 'lib/net')
-rw-r--r--lib/net/tcpconn.ex28
1 files changed, 5 insertions, 23 deletions
diff --git a/lib/net/tcpconn.ex b/lib/net/tcpconn.ex
index 7d82601..6fc4b1a 100644
--- a/lib/net/tcpconn.ex
+++ b/lib/net/tcpconn.ex
@@ -56,19 +56,14 @@ defmodule SNet.TCPConn do
}
GenServer.cast(Shard.Manager, {:peer_up, cli_pkey, self(), addr, his_port})
Logger.info "New peer: #{print_id state} at #{inspect addr}:#{port}"
- GenServer.cast(self(), :init_pull)
{:noreply, state}
end
def handle_cast({:send_msg, msg}, state) do
- send_msg(state, msg)
- {:noreply, state}
- end
-
- def handle_cast(:init_pull, state) do
- id_list = (for {id, _, _} <- :ets.tab2list(:shard_db), do: id)
- send_msg(state, {:interested, id_list})
+ msgbin = :erlang.term_to_binary msg
+ enc = encode_pkt(msgbin, state.conn_his_pkey, state.conn_my_skey)
+ :gen_tcp.send(state.socket, enc)
{:noreply, state}
end
@@ -85,15 +80,10 @@ defmodule SNet.TCPConn do
msg
end
- defp send_msg(state, msg) do
- msgbin = :erlang.term_to_binary msg
- enc = encode_pkt(msgbin, state.conn_his_pkey, state.conn_my_skey)
- :gen_tcp.send(state.socket, enc)
- end
-
def handle_info({:tcp, _socket, raw_data}, state) do
msg = decode_pkt(raw_data, state.conn_his_pkey, state.conn_my_skey)
- handle_packet(:erlang.binary_to_term(msg, [:safe]), state)
+ msg_data = :erlang.binary_to_term(msg, [:safe])
+ Shard.Manager.dispatch(state.his_pkey, msg_data)
{:noreply, state}
end
@@ -103,14 +93,6 @@ defmodule SNet.TCPConn do
exit(:normal)
end
- defp handle_packet({:interested, shards}, state) do
- GenServer.cast(Shard.Manager, {:interested, state.his_pkey, shards})
- end
-
- defp handle_packet({shard, msg}, state) do
- Shard.Manager.dispatch(state.his_pkey, shard, msg)
- end
-
defp print_id(state) do
state.his_pkey
|> binary_part(0, 8)