aboutsummaryrefslogtreecommitdiff
path: root/shard/lib/net/manager.ex
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2018-10-11 17:52:25 +0200
committerAlex Auvolat <alex@adnab.me>2018-10-11 17:52:25 +0200
commit28c9cac2e92011e2f7e6f23e93e8a5d9480a0922 (patch)
treead81473619ba5b9c18e925323264f58982311662 /shard/lib/net/manager.ex
parente5a7330d0526efb592e200ab96c3f33585ae8d02 (diff)
downloadshard-28c9cac2e92011e2f7e6f23e93e8a5d9480a0922.tar.gz
shard-28c9cac2e92011e2f7e6f23e93e8a5d9480a0922.zip
Fix initiation issues
Diffstat (limited to 'shard/lib/net/manager.ex')
-rw-r--r--shard/lib/net/manager.ex10
1 files changed, 7 insertions, 3 deletions
diff --git a/shard/lib/net/manager.ex b/shard/lib/net/manager.ex
index 75307ee..624d7e6 100644
--- a/shard/lib/net/manager.ex
+++ b/shard/lib/net/manager.ex
@@ -22,8 +22,11 @@ defmodule SNet.Manager do
{:ok, nil}
end
- def handle_call({:add_peer, peer_info, auth}, _from, state) do
+ def handle_call({:add_peer, peer_info, auth, callback}, _from, state) do
pid = add_peer_internal(peer_info, auth)
+ if callback != nil do
+ GenServer.cast(pid, {:callback, callback})
+ end
{:reply, pid, state}
end
@@ -38,6 +41,7 @@ defmodule SNet.Manager do
[[pid2]|_] when pid2 != pid ->
{:reply, :redundant, state}
_ ->
+ :ets.match_delete(:connections, {peer_info, pid, :_})
:ets.insert(:connections, {peer_info, pid, auth})
# Send interested message for all our shards
@@ -81,8 +85,8 @@ defmodule SNet.Manager do
@doc"""
Connect to a peer specified by ip address and port
"""
- def add_peer(peer_info, auth \\ nil) do
- GenServer.call(__MODULE__, {:add_peer, peer_info, auth})
+ def add_peer(peer_info, opts \\ []) do
+ GenServer.call(__MODULE__, {:add_peer, peer_info, opts[:auth], opts[:callback]})
end
@doc"""