x 3 лет назад
Родитель
Сommit
723adfd01d

+ 2 - 1
doc/src/SUMMARY.md

@@ -29,6 +29,7 @@
   - [Smart Contracts](architecture/smart_contracts.md)
   - [Bridge](architecture/bridge.md)
   - [Tooling](architecture/tooling.md)
+  - [P2P Network](architecture/p2p-network.md)
 - [Smart Contracts](architecture/sc/sc.md)
   - [Transaction lifetime](architecture/sc/tx-lifetime.md)
 - [zkas](zkas/index.md)
@@ -61,7 +62,7 @@
     - [Deploy](learn/dchat/deployment/deploy.md)
   - [Creating dchat](learn/dchat/creating-dchat/part-2.md)
     - [Message](learn/dchat/creating-dchat/message.md)
-    - [Protocols](learn/dchat/creating-dchat/protocols.md)
+    - [Understanding Protocols](learn/dchat/creating-dchat/protocols.md)
     - [ProtocolDchat](learn/dchat/creating-dchat/protocol-dchat.md)
     - [Register protocol](learn/dchat/creating-dchat/register-protocol.md)
     - [Sending messages](learn/dchat/creating-dchat/sending-messages.md)

+ 42 - 0
doc/src/architecture/p2p-network.md

@@ -0,0 +1,42 @@
+# P2P Network
+
+We instantiate a `p2p` network and call `start()`. This will begin running a single
+p2p network until `stop()` is called.
+
+There are 3 session types:
+
+* `InboundSession`, concerned with incoming connections
+* `OutboundSession`, concerned with outgoing connections
+* `SeedSession` is a special session type which connects to seed nodes to populate
+  the hosts pool, then finishes once synced.
+
+Connections are made by either `Acceptor` or `Connector` for incoming or outgoing
+respectively. They have multiple transport types; see `src/net/transport/` for the
+full list.
+
+Connections are then wrapped in a `Channel` abstraction which allows
+protocols to be attached. See `src/net/protocol/` and run `fd protocol` for custom
+application specific network protocols. Also see the follow tutorial:
+
+* [Understanding Protocols](learn/dchat/creating-dchat/protocols.md)
+
+## Outbound Session
+
+The outbound session is responsible to ensure the hosts pool is populated, either
+through currently connected nodes or using the seed session.
+It performs this algorithm:
+
+1. Start $N$ slots, with each with `status = ACTIVE`
+2. If no addresses matching our filters are in the hosts pool then:
+    1. Check the other slots are all `ACTIVE`, otherwise `status = SLEEP` and
+       wait for a wakeup signal.
+    2. If we have connections available in `p2p` then `status = DISCOVERY`
+       otherwise `status = SEED`.
+    3. If `status = DISCOVERY` and the hosts pool is still empty then
+       `status = SEED`.
+    4. If the hosts pool is still empty, then `status = SLEEP` and set a wakeup timer.
+    4. Once finished, send the wakeup signal to the other slots and repeat the process.
+
+The slots are able to communicate to each other through pipes to signal status changes
+such as wakeup requests.
+

+ 1 - 1
doc/src/learn/dchat/creating-dchat/protocols.md

@@ -1,4 +1,4 @@
-# Understanding protocols
+# Understanding Protocols
 
 We now need to implement a custom protocol which defines how our chat
 program interacts with the p2p network.