diff options
Diffstat (limited to 'src/contrib/service/rps/rps.h')
-rw-r--r-- | src/contrib/service/rps/rps.h | 336 |
1 files changed, 336 insertions, 0 deletions
diff --git a/src/contrib/service/rps/rps.h b/src/contrib/service/rps/rps.h new file mode 100644 index 000000000..202f881c9 --- /dev/null +++ b/src/contrib/service/rps/rps.h | |||
@@ -0,0 +1,336 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2012-2013 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /** | ||
21 | * @file rps/rps.h | ||
22 | * @brief example IPC messages between RPS API and GNS service | ||
23 | * @author Julius Bünger | ||
24 | */ | ||
25 | |||
26 | #include "gnunet_rps_service.h" | ||
27 | |||
28 | /** | ||
29 | * Mesh port used by RPS. | ||
30 | */ | ||
31 | #define GNUNET_RPS_CADET_PORT 31337 | ||
32 | |||
33 | |||
34 | GNUNET_NETWORK_STRUCT_BEGIN | ||
35 | |||
36 | /*********************************************************************** | ||
37 | * P2P Messages | ||
38 | ***********************************************************************/ | ||
39 | |||
40 | /** | ||
41 | * P2P Message to send PeerIDs to other peer. | ||
42 | */ | ||
43 | struct GNUNET_RPS_P2P_PullReplyMessage | ||
44 | { | ||
45 | /** | ||
46 | * Header including size and type in NBO | ||
47 | */ | ||
48 | struct GNUNET_MessageHeader header; | ||
49 | |||
50 | /** | ||
51 | * Number of PeerIDs sent | ||
52 | */ | ||
53 | uint32_t num_peers GNUNET_PACKED; | ||
54 | |||
55 | /* Followed by num_peers * GNUNET_PeerIdentity */ | ||
56 | }; | ||
57 | |||
58 | |||
59 | /*********************************************************************** | ||
60 | * Client-Service Messages | ||
61 | ***********************************************************************/ | ||
62 | |||
63 | /** | ||
64 | * Message from client to service with seed of peers. | ||
65 | */ | ||
66 | struct GNUNET_RPS_CS_SeedMessage | ||
67 | { | ||
68 | /** | ||
69 | * Header including size and type in NBO | ||
70 | */ | ||
71 | struct GNUNET_MessageHeader header; | ||
72 | |||
73 | /** | ||
74 | * Number of peers | ||
75 | */ | ||
76 | uint32_t num_peers GNUNET_PACKED; | ||
77 | |||
78 | /* Followed by num_peers * GNUNET_PeerIdentity */ | ||
79 | }; | ||
80 | |||
81 | #if ENABLE_MALICIOUS | ||
82 | /** | ||
83 | * Message from client to service to turn service malicious. | ||
84 | */ | ||
85 | struct GNUNET_RPS_CS_ActMaliciousMessage | ||
86 | { | ||
87 | /** | ||
88 | * Header including size and type in NBO | ||
89 | */ | ||
90 | struct GNUNET_MessageHeader header; | ||
91 | |||
92 | /** | ||
93 | * If the type is 2 this is the attacked peer, | ||
94 | * empty otherwise. | ||
95 | */ | ||
96 | struct GNUNET_PeerIdentity attacked_peer; | ||
97 | |||
98 | /** | ||
99 | * Type of malicious behaviour. | ||
100 | * | ||
101 | * 0 No malicious behaviour at all | ||
102 | * 1 Try to maximise representation | ||
103 | * 2 Try to partition the network | ||
104 | */ | ||
105 | uint32_t type GNUNET_PACKED; | ||
106 | |||
107 | /** | ||
108 | * Number of peers | ||
109 | */ | ||
110 | uint32_t num_peers GNUNET_PACKED; | ||
111 | |||
112 | /* Followed by num_peers * GNUNET_PeerIdentity when the type of malicious | ||
113 | behaviour is 1 */ | ||
114 | }; | ||
115 | #endif /* ENABLE_MALICIOUS */ | ||
116 | |||
117 | |||
118 | /** | ||
119 | * Message from client to service telling it to start a new sub | ||
120 | */ | ||
121 | struct GNUNET_RPS_CS_SubStartMessage | ||
122 | { | ||
123 | /** | ||
124 | * Header including size and type in NBO | ||
125 | */ | ||
126 | struct GNUNET_MessageHeader header; | ||
127 | |||
128 | /** | ||
129 | * For alignment. | ||
130 | */ | ||
131 | uint32_t reserved GNUNET_PACKED; | ||
132 | |||
133 | /** | ||
134 | * Mean interval between two rounds | ||
135 | */ | ||
136 | struct GNUNET_TIME_RelativeNBO round_interval; | ||
137 | |||
138 | /** | ||
139 | * Length of the shared value represented as string. | ||
140 | */ | ||
141 | struct GNUNET_HashCode hash GNUNET_PACKED; | ||
142 | }; | ||
143 | |||
144 | |||
145 | /** | ||
146 | * Message from client to service telling it to stop a new sub | ||
147 | */ | ||
148 | struct GNUNET_RPS_CS_SubStopMessage | ||
149 | { | ||
150 | /** | ||
151 | * Header including size and type in NBO | ||
152 | */ | ||
153 | struct GNUNET_MessageHeader header; | ||
154 | |||
155 | /** | ||
156 | * Length of the shared value represented as string. | ||
157 | */ | ||
158 | struct GNUNET_HashCode hash GNUNET_PACKED; | ||
159 | }; | ||
160 | |||
161 | |||
162 | /* Debug messages */ | ||
163 | |||
164 | /** | ||
165 | * Message from client to service indicating that | ||
166 | * clients wants to get updates of the view | ||
167 | */ | ||
168 | struct GNUNET_RPS_CS_DEBUG_ViewRequest | ||
169 | { | ||
170 | /** | ||
171 | * Header including size and type in NBO | ||
172 | */ | ||
173 | struct GNUNET_MessageHeader header; | ||
174 | |||
175 | /** | ||
176 | * Number of updates | ||
177 | * 0 for sending updates until cancellation | ||
178 | */ | ||
179 | uint32_t num_updates GNUNET_PACKED; | ||
180 | }; | ||
181 | |||
182 | /** | ||
183 | * Message from service to client containing current update of view | ||
184 | */ | ||
185 | struct GNUNET_RPS_CS_DEBUG_ViewReply | ||
186 | { | ||
187 | /** | ||
188 | * Header including size and type in NBO | ||
189 | */ | ||
190 | struct GNUNET_MessageHeader header; | ||
191 | |||
192 | /** | ||
193 | * Identifyer of the message. | ||
194 | */ | ||
195 | uint32_t id GNUNET_PACKED; | ||
196 | |||
197 | /** | ||
198 | * Number of peers in the view | ||
199 | */ | ||
200 | uint64_t num_peers GNUNET_PACKED; | ||
201 | }; | ||
202 | /* Followed by num_peers * GNUNET_PeerIdentity */ | ||
203 | |||
204 | /** | ||
205 | * Message from client to service indicating that | ||
206 | * clients wants to get stream of biased peers | ||
207 | */ | ||
208 | struct GNUNET_RPS_CS_DEBUG_StreamRequest | ||
209 | { | ||
210 | /** | ||
211 | * Header including size and type in NBO | ||
212 | */ | ||
213 | struct GNUNET_MessageHeader header; | ||
214 | }; | ||
215 | |||
216 | /** | ||
217 | * Message from service to client containing peer from biased stream | ||
218 | */ | ||
219 | struct GNUNET_RPS_CS_DEBUG_StreamReply | ||
220 | { | ||
221 | /** | ||
222 | * Header including size and type in NBO | ||
223 | */ | ||
224 | struct GNUNET_MessageHeader header; | ||
225 | |||
226 | /** | ||
227 | * Number of peers | ||
228 | */ | ||
229 | uint64_t num_peers GNUNET_PACKED; | ||
230 | |||
231 | // TODO maybe source of peer (pull/push list, peerinfo, ...) | ||
232 | |||
233 | /* Followed by num_peers * GNUNET_PeerIdentity */ | ||
234 | }; | ||
235 | |||
236 | GNUNET_NETWORK_STRUCT_END | ||
237 | |||
238 | /*********************************************************************** | ||
239 | * Defines from old gnunet-service-rps_peers.h | ||
240 | ***********************************************************************/ | ||
241 | |||
242 | /** | ||
243 | * Different flags indicating the status of another peer. | ||
244 | */ | ||
245 | enum Peers_PeerFlags | ||
246 | { | ||
247 | /** | ||
248 | * If we are waiting for a reply from that peer (sent a pull request). | ||
249 | */ | ||
250 | Peers_PULL_REPLY_PENDING = 0x01, | ||
251 | |||
252 | /* IN_OTHER_GOSSIP_LIST = 0x02, unneeded? */ | ||
253 | /* IN_OWN_SAMPLER_LIST = 0x04, unneeded? */ | ||
254 | /* IN_OWN_GOSSIP_LIST = 0x08, unneeded? */ | ||
255 | |||
256 | /** | ||
257 | * We set this bit when we know the peer is online. | ||
258 | */ | ||
259 | Peers_ONLINE = 0x20, | ||
260 | |||
261 | /** | ||
262 | * We set this bit when we are going to destroy the channel to this peer. | ||
263 | * When cleanup_channel is called, we know that we wanted to destroy it. | ||
264 | * Otherwise the channel to the other peer was destroyed. | ||
265 | */ | ||
266 | Peers_TO_DESTROY = 0x40, | ||
267 | }; | ||
268 | |||
269 | /** | ||
270 | * Keep track of the status of a channel. | ||
271 | * | ||
272 | * This is needed in order to know what to do with a channel when it's | ||
273 | * destroyed. | ||
274 | */ | ||
275 | enum Peers_ChannelFlags | ||
276 | { | ||
277 | /** | ||
278 | * We destroyed the channel because the other peer established a second one. | ||
279 | */ | ||
280 | Peers_CHANNEL_ESTABLISHED_TWICE = 0x1, | ||
281 | |||
282 | /** | ||
283 | * The channel was removed because it was not needed any more. This should be | ||
284 | * the sending channel. | ||
285 | */ | ||
286 | Peers_CHANNEL_CLEAN = 0x2, | ||
287 | |||
288 | /** | ||
289 | * We destroyed the channel because the other peer established a second one. | ||
290 | */ | ||
291 | Peers_CHANNEL_DESTROING = 0x4, | ||
292 | }; | ||
293 | |||
294 | |||
295 | /** | ||
296 | * @brief The role of a channel. Sending or receiving. | ||
297 | */ | ||
298 | enum Peers_ChannelRole | ||
299 | { | ||
300 | /** | ||
301 | * Channel is used for sending | ||
302 | */ | ||
303 | Peers_CHANNEL_ROLE_SENDING = 0x01, | ||
304 | |||
305 | /** | ||
306 | * Channel is used for receiving | ||
307 | */ | ||
308 | Peers_CHANNEL_ROLE_RECEIVING = 0x02, | ||
309 | }; | ||
310 | |||
311 | /** | ||
312 | * @brief Functions of this type can be used to be stored at a peer for later execution. | ||
313 | * | ||
314 | * @param cls closure | ||
315 | * @param peer peer to execute function on | ||
316 | */ | ||
317 | typedef void (*PeerOp) (void *cls, const struct GNUNET_PeerIdentity *peer); | ||
318 | |||
319 | /** | ||
320 | * @brief Iterator over valid peers. | ||
321 | * | ||
322 | * @param cls closure | ||
323 | * @param peer current public peer id | ||
324 | * @return #GNUNET_YES if we should continue to | ||
325 | * iterate, | ||
326 | * #GNUNET_NO if not. | ||
327 | */ | ||
328 | typedef int | ||
329 | (*PeersIterator) (void *cls, | ||
330 | const struct GNUNET_PeerIdentity *peer); | ||
331 | |||
332 | |||
333 | /** | ||
334 | * Handle to the statistics service. | ||
335 | */ | ||
336 | extern struct GNUNET_STATISTICS_Handle *stats; | ||