Skip to main content

goxoy_p2p/
structs.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
4pub struct NodeP2PAcceptanceToGroup {
5    pub sender: NodeP2PBasicInfo,
6    pub proxy_node: NodeP2PBasicInfo,
7    pub joiner_node: NodeP2PBasicInfo,
8    pub sign: String,
9}
10
11#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord)]
12pub struct NodeP2PPingData {
13    pub exact_time: u128,
14    pub public_key: String,
15    pub group_hash: String,
16    pub list_hash: String,
17    pub waiting_room: NodeP2PWaitingRoomList,
18    pub sign: String,
19}
20
21#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord)]
22pub struct NodeP2PConsensusList {
23    pub addr: String,
24    pub status: NodeGroupStatus,
25    pub public_key: String,
26    pub vote_power: usize,
27    pub list_hash: String,
28    pub ping_data: NodeP2PPingData,
29    pub time: u64,
30    pub next_port: usize,
31    pub next_addr: String,
32}
33
34#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord)]
35pub struct NodeP2PWaitingRoomList {
36    pub addr: String,
37    pub public_key: String,
38    pub request_time: u64,
39}
40
41#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord)]
42pub struct NodeP2PBasicList {
43    pub addr: String,
44    pub public_key: String,
45    pub vote_power: usize,
46    pub status: NodeStatus,
47    pub group_time: u64,
48    pub list_hash: String,    // bu listelerin hashini tutan degisken
49    pub details_hash: String, // bu liste detaylarini tutan degisken
50    pub time: u64,
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
54pub struct NodePropose {
55    pub proposer: String, // node public_key
56    pub sign: String,     // node public_key
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
60pub struct NodeGroupList {
61    pub group_time: u64,
62    pub details_hash: String,
63    pub list: Vec<String>,
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
67pub struct NodeGroup {
68    pub id: String,
69    pub list: Vec<NodeP2PConsensusList>,
70    pub neighbor: NodeP2PNeighbor,
71    pub active: bool,
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
75pub struct NodeConfig {
76    pub public_key: String,
77    pub addr: String,
78    pub next: usize,
79    pub my_time: u64,
80    pub vote_power: usize,
81    pub group_time: u64,
82    pub list_hash: String,
83    pub details_hash: String,
84    pub sign: String,
85}
86
87#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
88pub struct NodeMessagePacket {
89    pub time:u64,
90    pub public_key:String,
91    pub network_id: String,
92    pub msg_type: NodeMessageType,
93    pub sign: String, // sender will sign the message
94    pub data: String,
95}
96
97#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
98pub struct NodeMessageDistribution {
99    pub id: String,
100    pub origin: String,
101    pub sender: String,
102    pub count: u128,
103    pub level: usize,     // increase the number for every node
104    pub receiver: String, // if its empty send to all,
105    pub network_id: String,
106    pub group_id: String,
107    pub msg_type: NodeMessageType,
108    pub sign: String,
109    pub data: String,
110}
111
112#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
113pub struct NodeSocketPorts {
114    pub common: String,
115    pub next: usize,
116}
117
118#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
119pub struct NodeSocketList {
120    pub status: NodeStatus,
121    pub common: String,
122    pub time: u64,
123    pub next: usize,
124}
125
126#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
127pub struct NodeP2PNeighbor {
128    pub addr: String,
129    pub next_port: usize,
130    pub public_key: String,
131}
132
133#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
134pub struct NodeP2PJoinNodeInfo {
135    pub active: bool,
136    pub my_node: NodeP2PBasicInfo,
137    pub observer_node: NodeP2PBasicInfo, // bu ağa katılacak node'u gözlemleyen node
138    pub observers_neighbor: NodeP2PBasicInfo,
139    pub selected_node: NodeP2PBasicInfo,
140    pub neighbor_next_port: usize,
141}
142
143#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
144pub struct NodeP2PBasicInfo {
145    pub addr: String,
146    pub public_key: String,
147}
148
149#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
150pub struct NodeP2PNewMemberDefinition {
151    pub active: bool,
152    pub time: u64,
153    pub addr: String,
154    pub public_key: String,
155    pub next_port: usize,
156}
157
158#[derive(Debug, Copy, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord)]
159pub enum NodeMessageType {
160    Successs,
161    WrongNetworkId,
162    Unknown,
163    NodeId,
164    NextPort,
165    GroupList,
166    GroupData,
167    Error,
168    NodeList,
169    NodeListHash,
170    JoinRequest,
171    AcceptanceGroup,
172    NewMembersNextPort,
173    Ping,
174    Gossip,
175}
176
177#[derive(Debug, Copy, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord)]
178pub enum NodeType {
179    Unknown,
180    Starter,
181    Node,
182}
183
184#[derive(Debug, Copy, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord)]
185pub enum NodeStatus {
186    Unknown = 0,
187    Online = 1,
188    Offline = 2,
189}
190
191#[derive(Debug, Copy, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord)]
192pub enum SocketType {
193    Common = 1,
194    Next = 2,
195}
196
197#[derive(Debug, Copy, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord)]
198pub enum LibraryStatus {
199    Idle,
200    Starting,
201    ThereAreEnoughNode,
202    WaitingForEnoughNode,
203    WaitingForTheGroupsAcceptance,
204    AcceptedByGroup,
205    GroupAcceptanceCompleted,
206    Error,
207    Running,
208    Shutdown,
209}
210
211#[derive(Debug, Copy, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord)]
212pub enum NodeGroupStatus {
213    Member,
214    Candidate,
215}