diff options
author | Alex Auvolat <alex@adnab.me> | 2018-11-06 15:03:22 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2018-11-06 15:03:22 +0100 |
commit | 2973cf99c5b677c71717d916f83212bc2e6b36dc (patch) | |
tree | 8651b326786c62fc4e0bc438a625a13bf5df1844 /shard/lib/net/manager.ex | |
parent | c4f6cbab20b0b1d08755073d93365e5bd00dc755 (diff) | |
download | shard-2973cf99c5b677c71717d916f83212bc2e6b36dc.tar.gz shard-2973cf99c5b677c71717d916f83212bc2e6b36dc.zip |
Document
Diffstat (limited to 'shard/lib/net/manager.ex')
-rw-r--r-- | shard/lib/net/manager.ex | 12 |
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]|_] -> |