p2p_file_sharing_enum_commands/
lib.rs

1//!This library contains common command and response types for client and daemon for their communication.
2
3use serde::{Serialize, Deserialize};
4use std::net::IpAddr;
5use std::collections::HashMap;
6
7///Connection port for the daemon and the client
8pub const PORT: u16 = 3000; // now it connects to 3000
9///Pair of containers for response from ls command
10pub type LsResponseType = HashMap<IpAddr, Vec<String>>;
11///Pair of pair of containers for response from status command
12pub type StatusResponseType = (HashMap<String, Vec<IpAddr>>, HashMap<String, Vec<IpAddr>>);
13
14///Depending on which command the client enters into the console, its type will be determined, the command will be serialized and then sent to the daemon.
15#[derive(Serialize, Deserialize, Debug)]
16pub enum CommandType {
17    Share(String),
18    Scan,
19    Ls,
20    Download(String, String),
21    Status,
22}
23
24/* Client gets enum from a daemon what is below.
25   Any request from a client could end with access or failure.
26   In success a client gets enum with 1 or 2 or 3 field. Depends from what client was requested.
27   If error - enum with 4th field.*/
28
29///The response from the daemon comes in a serialized form and deserialize, it is reduced to the type of response to which the request was sent from the client.
30#[derive(Serialize, Deserialize, Debug)]
31pub enum ResponseType {
32    ShareScan,
33    Ls(String),
34    Download(bool),
35    Status(String),
36    Error(String),
37}