diff options
author | Alex Auvolat <alex@adnab.me> | 2018-10-11 17:52:25 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2018-10-11 17:52:25 +0200 |
commit | 28c9cac2e92011e2f7e6f23e93e8a5d9480a0922 (patch) | |
tree | ad81473619ba5b9c18e925323264f58982311662 /shard/lib/net/group.ex | |
parent | e5a7330d0526efb592e200ab96c3f33585ae8d02 (diff) | |
download | shard-28c9cac2e92011e2f7e6f23e93e8a5d9480a0922.tar.gz shard-28c9cac2e92011e2f7e6f23e93e8a5d9480a0922.zip |
Fix initiation issues
Diffstat (limited to 'shard/lib/net/group.ex')
-rw-r--r-- | shard/lib/net/group.ex | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/shard/lib/net/group.ex b/shard/lib/net/group.ex index f09d174..7086c2d 100644 --- a/shard/lib/net/group.ex +++ b/shard/lib/net/group.ex @@ -33,15 +33,18 @@ defmodule SNet.PubShardGroup do defstruct [:id] defimpl SNet.Group do - def init_lookup(%SNet.PubShardGroup{id: id}, _notify_to) do + def init_lookup(%SNet.PubShardGroup{id: id}, notify_to) do # For now: ask all currently connected peers and connect to new peers we know of spawn fn -> for {_, pid, _} <- SNet.Manager.list_connections do - GenServer.cast(pid, {:send_msg, {:interested, [id]}}) + GenServer.cast(notify_to, {:peer_connected, pid}) end for peer_info <- Shard.Manager.get_shard_peers id do if SNet.Manager.get_connections_to peer_info == [] do - SNet.Manager.add_peer(peer_info) # TODO callback when connected + SNet.Manager.add_peer(peer_info, + callback: fn pid -> + GenServer.cast(notify_to, {:peer_connected, pid}) + end) end end end @@ -96,8 +99,11 @@ defmodule SNet.PrivGroup do info = GenServer.call(pid, :get_info) if Map.has_key?(info, :peer_info) do for pi <- info.peer_info do - SNet.Manager.add_peer(pi, %SNet.Auth{my_pk: my_pk, his_pk: pk}) - # no callback here, we don't know if connect was successful + SNet.Manager.add_peer(pi, + auth: %SNet.Auth{my_pk: my_pk, his_pk: pk}, + callback: fn pid -> + GenServer.cast(notify_to, {:peer_connected, pid}) + end) end end end |