aboutsummaryrefslogtreecommitdiff
path: root/shard/lib/net/manager.ex
diff options
context:
space:
mode:
Diffstat (limited to 'shard/lib/net/manager.ex')
-rw-r--r--shard/lib/net/manager.ex12
1 files changed, 8 insertions, 4 deletions
diff --git a/shard/lib/net/manager.ex b/shard/lib/net/manager.ex
index fb92f13..e4d8ad9 100644
--- a/shard/lib/net/manager.ex
+++ b/shard/lib/net/manager.ex
@@ -1,9 +1,8 @@
defmodule SNet.Manager do
@moduledoc"""
- - :connections (not persistent)
+ Maintains a table `:connections` of currently connected peers, which is a list of:
- List of
- { peer_info, pid, nil | {my_pk, his_pk} }
+ { peer_info, pid, nil | %SNet.Auth{my_pk: my_pk, his_pk: his_pk} }
"""
use GenServer
@@ -91,7 +90,7 @@ defmodule SNet.Manager do
@doc"""
Connect to a peer specified by ip address and port
- peer_info := {:inet, ip, port}
+ peer_info := {:inet, ip, port}
"""
def add_peer(peer_info, opts \\ []) do
GenServer.call(__MODULE__, {:add_peer, peer_info, opts[:auth], opts[:callback]})
@@ -134,6 +133,11 @@ defmodule SNet.Manager do
end
end
+ @doc"""
+ Send message to a peer specified by peer info over authenticated channel.
+ `auth` is a `SNet.Auth` struct describing the required authentication.
+ Opens a connection if necessary.
+ """
def send_auth(peer_info, auth, msg) do
case :ets.match(:connections, {peer_info, :'$1', auth, :_}) do
[[pid]|_] ->