aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2018-10-02 15:34:18 +0200
committerAlex Auvolat <alex@adnab.me>2018-10-02 15:34:18 +0200
commit486344f87f1e4c9b0cc391f12ce6bbf939be06ab (patch)
tree410175a4f8d3a9126f310766e0ea48acffc90307
parentfec60e26c0fc4bdc34c05bb52b12970987470254 (diff)
downloadshard-486344f87f1e4c9b0cc391f12ce6bbf939be06ab.tar.gz
shard-486344f87f1e4c9b0cc391f12ce6bbf939be06ab.zip
WIP
-rw-r--r--TODO23
-rw-r--r--shard/lib/net/chan.ex66
2 files changed, 87 insertions, 2 deletions
diff --git a/TODO b/TODO
index 637f964..690ce62 100644
--- a/TODO
+++ b/TODO
@@ -10,8 +10,27 @@ achieves our goals.
TASK LIST
=========
-- Highest priority: sign
-- Medium priority: dht, ep, dep
+- Highest priority: comm, sign, ep
+- Medium priority: dht, dep
+
+
+Architecture for communication primitives (comm, MED)
+-----------------------------------------
+
+Find the right abstraction(s) for communiation channels.
+
+Here are some things to keep in mind that we want at some point:
+
+- Encrypted point to point communication (to communicate private info after ACL check)
+- Flooding, gossip, RPS
+- Congestion control, proper multiplexing of feeds
+- Proper management of open connections to peers
+
+RPS question: can we integrate a preference for connections to peers that share the same shards?
+All while preventing the network from being disconnected.
+Ex: keep 100 total open connections that are sampled by proximity on the set of requested shards (bloom filter)
+plus 2 or 5 full random for all shards.
+
DHT to find peers for a given shard (dht, EASY)
diff --git a/shard/lib/net/chan.ex b/shard/lib/net/chan.ex
new file mode 100644
index 0000000..aa5c186
--- /dev/null
+++ b/shard/lib/net/chan.ex
@@ -0,0 +1,66 @@
+defprotocol SNet.Chan do
+ @moduledoc"""
+ Abstract definition for a communication channel
+ """
+
+ @doc"""
+ Function to send a message to relevant peers.
+ """
+ def send(chan, msg)
+
+ @doc"""
+ Function to declare a handler for a channel
+ """
+ def handle(chan, func)
+end
+
+def SNet.PeerChan do
+ @moduledoc"""
+ Direct channel to a peer
+ """
+
+ defstruct [:peer_id, :shard_id, :path]
+
+ def new(peer_id, shard_id, path) do
+ %__MODULE__{peer_id: peer_id, shard_id: shard_id, path: path}
+ end
+
+ defimpl SNet.Chan do
+ def send(chan, msg) do
+ Shard.Manager.send(chan.peer_id, {chan.shard_id, chan.path, msg})
+ end
+
+ def handle(chan, func) do
+ # DO NOT USE THIS
+ assert false
+ end
+ end
+end
+
+def SNet.FloodChan do
+ @moduledoc"""
+ Channel that send a message to all know peers for shard (floods the network)
+ """
+
+ defstruct [:shard_id, :path]
+
+ def new(shard_id, path) do
+ %__MODULE__{shard_id: shard_id, path: path}
+ end
+
+ defimpl SNet.Chan do
+ def send(chan, msg) do
+ for x <- Shard.Manager.get_shard_peers(chan.shard_id) do
+ Shard.Manager.send(x, {chan.shard_id, chan.path, msg})
+ end
+ end
+
+ def handle(chan, func) do
+ # TODO
+ end
+ end
+end
+
+def SNet.CipherChan do
+ # TODO
+end