aboutsummaryrefslogtreecommitdiff
path: root/shard/lib/net/group.ex
diff options
context:
space:
mode:
Diffstat (limited to 'shard/lib/net/group.ex')
-rw-r--r--shard/lib/net/group.ex16
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