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.ex17
1 files changed, 9 insertions, 8 deletions
diff --git a/shard/lib/net/group.ex b/shard/lib/net/group.ex
index d2c2537..692438a 100644
--- a/shard/lib/net/group.ex
+++ b/shard/lib/net/group.ex
@@ -36,12 +36,12 @@ defmodule SNet.PubShardGroup 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, _} <- Shard.Manager.list_connections do
+ for {_, pid, _} <- SNet.Manager.list_connections do
GenServer.cast(pid, {:send_msg, {:interested, [id]}})
end
for peer_info <- Shard.Manager.get_shard_peers id do
- if Shard.Manager.get_connections_to peer_info == [] do
- Shard.Manager.add_peer(peer_info) # TODO callback when connected
+ if SNet.Manager.get_connections_to peer_info == [] do
+ SNet.Manager.add_peer(peer_info) # TODO callback when connected
end
end
end
@@ -49,9 +49,10 @@ defmodule SNet.PubShardGroup do
end
def get_connections(%SNet.PubShardGroup{id: id}) do
- for peer_info <- Shard.Manager.get_shard_peers(id),
- [{pid, _auth}|_] = Shard.Manager.get_connections_to(peer_info),
- do: pid
+ Shard.Manager.get_shard_peers(id)
+ |> Enum.map(&(SNet.Manager.get_connections_to(&1)))
+ |> Enum.filter(&(&1 != []))
+ |> Enum.map(fn [{pid, _auth}|_] -> pid end)
end
def broadcast(group, msg, nmax) do
@@ -63,10 +64,10 @@ defmodule SNet.PubShardGroup do
|> Enum.count
if nmax - nsent > 0 do
Shard.Manager.get_shard_peers(id)
- |> Enum.filter(&(Shard.Manager.get_connections_to(&1) == []))
+ |> Enum.filter(&(SNet.Manager.get_connections_to(&1) == []))
|> Enum.shuffle
|> Enum.take(nmax - nsent)
- |> Enum.map(&(Shard.Manager.send(&1, msg)))
+ |> Enum.map(&(SNet.Manager.send(&1, msg)))
end
end