Przeglądaj źródła

book/ dchat: explicit todos and add files

lunar-mining 4 lat temu
rodzic
commit
bfaedc8492

+ 45 - 0
doc/src/learn/dchat/creating-dchat/message.md

@@ -0,0 +1,45 @@
+# Creating a Message type
+
+We'll start by creating a custom Message type called Dchatmsg. This is the
+data structure that we'll use to send messages between dchat instances.
+
+Messages on the p2p network must implement the Message trait. Message is a
+generic type that standardizes all messages on DarkFi's p2p network.
+
+We define a custom type called Dchatmsg that implements the Message
+trait. We also add serde's SerialEncodable and SerialDecodable to our
+struct definition so our messages can be parsed by the network.
+
+The Message trait requires that we implement a method called name(),
+which returns a str of the struct's name.
+
+```
+use darkfi::{
+    net,
+    util::serial::{SerialDecodable, SerialEncodable},
+};
+
+impl net::Message for Dchatmsg {
+    fn name() -> &'static str {
+        "Dchatmsg"
+    }
+}
+
+#[derive(Debug, Clone, SerialEncodable, SerialDecodable)]
+pub struct Dchatmsg {
+    pub msg: String,
+}
+```
+
+For the purposes of our chat program, we will also define a buffer where
+we can write messages upon receiving them on the p2p network. We'll wrap
+this in a Mutex to ensure thread safety and an Arc pointer so we can
+pass it around.
+
+```
+use async_std::sync::{Arc, Mutex};
+
+pub type DchatmsgsBuffer = Arc<Mutex<Vec<Dchatmsg>>>;
+```
+
+

+ 1 - 0
doc/src/learn/dchat/creating-dchat/protocol-dchat.md

@@ -0,0 +1 @@
+# ProtocolDchat

+ 54 - 0
doc/src/learn/dchat/creating-dchat/protocols.md

@@ -0,0 +1,54 @@
+# Understanding protocols
+
+We now need to implement a custom protocol which defines how our chat
+program interacts with the p2p network.
+
+We've already interacted with several protocols already. Protocols
+are automatically activated when nodes connect to eachother on the
+p2p network. Here are examples of two protocols that every node runs
+continuously in the background:
+
+[ProtocolPing](../../../src/net/protocol/protocol_ping.rs): sends ping,
+receives pong
+[ProtocolAddress](../../../src/net/protocol/protocol_address.rs): receives
+a get_address message, sends an address message
+
+Under the hood, these protocols have a few similarities:
+
+1. They create a subscription to a message type, such as Ping and Pong.
+2. They implement [ProtocolBase](../../../src/net/protocol/protocol_base.rs),
+DarkFi's generic protocol trait.
+3. They run asynchronously using the
+[ProtocolJobsManager](../../../src/net/protocol/protocol_jobs_manager.rs).
+4. They hold a pointer to [Channel](../../../src/net/channel.rs) which
+invokes the [MessageSubsystem](../../../src/net/message_subscriber).
+
+This introduces several generic interfaces that we must use to build
+our custom protocol. In particular:
+
+1. The Message Subsystem
+
+MessageSubsystem is a generic publish/subscribe class that can
+dispatch any kind of message to a list of dispatchers. This is how we
+can send and receive custom messages on the p2p network.
+
+2. Message Subscription
+
+A subscription to a message type. 
+
+3. The Protocol Registry 
+
+ProtocolRegistry takes any kind of generic protocol and initializes it. We
+use it through the method register() which passes a protocol constructor
+and a session bitflag which determines which sessions (outbound, inbound,
+or seed) will run our protocol.
+
+4. ProtocolJobsManager
+
+An asynchronous job manager that spawns and stops tasks created by
+protocols across the network.
+
+5. ProtocolBase
+
+A generic protocol trait that all protocols must implement.
+

+ 9 - 0
doc/src/learn/dchat/local-deployment/local-deployment.md

@@ -0,0 +1,9 @@
+# Part 1: Deploying the network
+
+We'll start by deploying a local version of the p2p network. This will
+introduce a number of key concepts:
+
+* p2p daemons
+* Inbound, outbound, manual and seed nodes
+* Understanding Sessions
+* p2p.start() and p2p.run()

+ 1 - 1
doc/src/learn/dchat/network-tools/darkfi-rpc.md

@@ -1 +1 @@
-<!---TODO--->
+# TODO

+ 1 - 1
doc/src/learn/dchat/network-tools/dnetview.md

@@ -1,2 +1,2 @@
-<!---TODO--->
+# TODO
 

+ 2 - 0
doc/src/learn/dchat/network-tools/network-tools.md

@@ -0,0 +1,2 @@
+# TODO
+