aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/cadet.h
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2023-10-18 20:02:10 +0200
committerMartin Schanzenbach <schanzen@gnunet.org>2023-10-18 20:02:10 +0200
commit11949e419fd7230431646703ac0cf8e34f615673 (patch)
tree94892053dd1734a41effa1fd2a5b7e9f650b0f31 /src/cadet/cadet.h
parent2d76608872f25220ef85c56af403392f6842dc19 (diff)
downloadgnunet-11949e419fd7230431646703ac0cf8e34f615673.tar.gz
gnunet-11949e419fd7230431646703ac0cf8e34f615673.zip
BUILD: Move cadet to service/cli
Diffstat (limited to 'src/cadet/cadet.h')
-rw-r--r--src/cadet/cadet.h578
1 files changed, 0 insertions, 578 deletions
diff --git a/src/cadet/cadet.h b/src/cadet/cadet.h
deleted file mode 100644
index e8caa7d35..000000000
--- a/src/cadet/cadet.h
+++ /dev/null
@@ -1,578 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2001 - 2011 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/**
22 * @author Bartlomiej Polot
23 * @file cadet/cadet.h
24 */
25
26#ifndef CADET_H_
27#define CADET_H_
28
29#ifdef __cplusplus
30extern "C" {
31#if 0 /* keep Emacsens' auto-indent happy */
32}
33#endif
34#endif
35
36#include <stdint.h>
37
38#if ! defined(GNUNET_CULL_LOGGING)
39#define CADET_TIMING_START \
40 struct GNUNET_TIME_Absolute __timestamp; \
41 __timestamp = GNUNET_TIME_absolute_get ()
42
43#define CADET_TIMING_END \
44 struct GNUNET_TIME_Relative __duration; \
45 __duration = GNUNET_TIME_absolute_get_duration (__timestamp); \
46 LOG (GNUNET_ERROR_TYPE_INFO, \
47 " %s duration %s\n", \
48 __FUNCTION__, \
49 GNUNET_STRINGS_relative_time_to_string (__duration, GNUNET_YES));
50#else
51#define CADET_TIMING_START
52#define CADET_TIMING_END
53#endif
54
55
56#include "platform.h"
57#include "gnunet_util_lib.h"
58#include "gnunet_core_service.h"
59#include "gnunet_cadet_service.h"
60#include "gnunet_protocols.h"
61#include "gnunet_cadet_service.h"
62
63/******************************************************************************/
64/************************** CONSTANTS ******************************/
65/******************************************************************************/
66
67/**
68 * Minimum value for channel IDs of local clients.
69 */
70#define GNUNET_CADET_LOCAL_CHANNEL_ID_CLI 0x80000000U
71
72/**
73 * FIXME.
74 */
75#define HIGH_PID 0xFF000000
76
77/**
78 * FIXME.
79 */
80#define LOW_PID 0x00FFFFFF
81
82
83/**
84 * Test if the two PIDs (of type `uint32_t`) are in the range where we
85 * have to worry about overflows. This is the case when @a pid is
86 * large and @a max is small, useful when comparing @a pid smaller
87 * than @a max.
88 */
89#define PID_OVERFLOW(pid, max) (((pid) > HIGH_PID) && ((max) < LOW_PID))
90
91/******************************************************************************/
92/************************** MESSAGES ******************************/
93/******************************************************************************/
94
95GNUNET_NETWORK_STRUCT_BEGIN
96
97/**
98 * Number uniquely identifying a channel of a client.
99 */
100struct GNUNET_CADET_ClientChannelNumber
101{
102 /**
103 * Values for channel numbering.
104 * Local channel numbers given by the service (incoming) are
105 * smaller than #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI.
106 * Local channel numbers given by the client (created) are
107 * larger than #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI.
108 */
109 uint32_t channel_of_client GNUNET_PACKED;
110};
111
112/**
113 * Opaque handle to a channel.
114 */
115struct GNUNET_CADET_Channel
116{
117
118 /**
119 * Other end of the channel.
120 */
121 struct GNUNET_PeerIdentity peer;
122
123 /**
124 * Handle to the cadet this channel belongs to
125 */
126 struct GNUNET_CADET_Handle *cadet;
127
128 /**
129 * Channel's port, if incoming.
130 */
131 struct GNUNET_CADET_Port *incoming_port;
132
133 /**
134 * Any data the caller wants to put in here, used for the
135 * various callbacks (@e disconnects, @e window_changes, handlers).
136 */
137 void *ctx;
138
139 /**
140 * Message Queue for the channel (which we are implementing).
141 */
142 struct GNUNET_MQ_Handle *mq;
143
144 /**
145 * Task to allow mq to send more traffic.
146 */
147 struct GNUNET_SCHEDULER_Task *mq_cont;
148
149 /**
150 * Pending envelope with a message to be transmitted to the
151 * service as soon as we are allowed to. Should only be
152 * non-NULL if @e allow_send is 0.
153 */
154 struct GNUNET_MQ_Envelope *pending_env;
155
156 /**
157 * Window change handler.
158 */
159 GNUNET_CADET_WindowSizeEventHandler window_changes;
160
161 /**
162 * Disconnect handler.
163 */
164 GNUNET_CADET_DisconnectEventHandler disconnects;
165
166 /**
167 * Local ID of the channel, #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI bit is set if outbound.
168 */
169 struct GNUNET_CADET_ClientChannelNumber ccn;
170
171 /**
172 * How many messages are we allowed to send to the service right now?
173 */
174 unsigned int allow_send;
175};
176
177/**
178 * Message for a client to create and destroy channels.
179 */
180struct GNUNET_CADET_PortMessage
181{
182 /**
183 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN
184 * or #GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE
185 *
186 * Size: sizeof(struct GNUNET_CADET_ChannelMessage)
187 */
188 struct GNUNET_MessageHeader header;
189
190 /**
191 * Port to open/close.
192 */
193 struct GNUNET_HashCode port GNUNET_PACKED;
194};
195
196
197/**
198 * Message for a client to create channels.
199 */
200struct GNUNET_CADET_LocalChannelCreateMessage
201{
202 /**
203 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE
204 *
205 * Size: sizeof(struct GNUNET_CADET_ChannelOpenMessageMessage)
206 */
207 struct GNUNET_MessageHeader header;
208
209 /**
210 * ID of a channel controlled by this client.
211 */
212 struct GNUNET_CADET_ClientChannelNumber ccn;
213
214 /**
215 * Channel's peer
216 */
217 struct GNUNET_PeerIdentity peer;
218
219 /**
220 * Port of the channel.
221 */
222 struct GNUNET_HashCode port;
223
224 /**
225 * Options.
226 */
227 uint32_t opt GNUNET_PACKED;
228};
229
230
231/**
232 * Message for or to a client to destroy tunnel.
233 */
234struct GNUNET_CADET_LocalChannelDestroyMessage
235{
236 /**
237 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY
238 */
239 struct GNUNET_MessageHeader header;
240
241 /**
242 * ID of a channel controlled by this client.
243 */
244 struct GNUNET_CADET_ClientChannelNumber ccn;
245};
246
247
248/**
249 * Message for cadet data traffic.
250 */
251struct GNUNET_CADET_LocalData
252{
253 /**
254 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA
255 */
256 struct GNUNET_MessageHeader header;
257
258 /**
259 * ID of the channel
260 */
261 struct GNUNET_CADET_ClientChannelNumber ccn;
262
263 /**
264 * Priority and preferences (an enum GNUNET_MQ_PriorityPreferences)
265 * of the message in NBO.
266 */
267 uint32_t pp GNUNET_PACKED;
268
269 /**
270 * Payload follows
271 */
272};
273
274
275/**
276 * Message to allow the client send more data to the service
277 * (always service -> client).
278 */
279struct GNUNET_CADET_LocalAck
280{
281 /**
282 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK
283 */
284 struct GNUNET_MessageHeader header;
285
286 /**
287 * ID of the channel allowed to send more data.
288 */
289 struct GNUNET_CADET_ClientChannelNumber ccn;
290};
291
292
293/**
294 * Message to inform the client about channels in the service.
295 *
296 * TODO: split into two messages!
297 */
298struct GNUNET_CADET_LocalInfo
299{
300 /**
301 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL or
302 * #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER
303 */
304 struct GNUNET_MessageHeader header;
305
306 /**
307 * ID of the channel allowed to send more data.
308 */
309 struct GNUNET_CADET_ClientChannelNumber ccn;
310
311 /**
312 * ID of the destination of the channel (can be local peer).
313 */
314 struct GNUNET_PeerIdentity peer;
315};
316
317/**
318 * Message to drop another message of specific type. Used in test context
319 */
320struct GNUNET_CADET_RequestDropCadetMessage
321{
322
323 /**
324 * Type: #GNUNET_MESSAGE_TYPE_CADET_DROP_CADET_MESSAGE
325 */
326 struct GNUNET_MessageHeader header;
327
328 /**
329 * Type of the message this handler covers, in host byte order.
330 */
331 uint16_t type;
332
333 /**
334 * ID of the channel we want to drop a message for.
335 */
336 struct GNUNET_CADET_ClientChannelNumber ccn;
337
338};
339
340/**
341 * Message to inform the client about channels in the service.
342 */
343struct GNUNET_CADET_RequestPathInfoMessage
344{
345 /**
346 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH
347 */
348 struct GNUNET_MessageHeader header;
349
350 /**
351 * Always zero.
352 */
353 uint32_t resered GNUNET_PACKED;
354
355 /**
356 * ID of the destination of the channel (can be local peer).
357 */
358 struct GNUNET_PeerIdentity peer;
359};
360
361
362/**
363 * Message to inform the client about channels in the service.
364 */
365struct GNUNET_CADET_ChannelInfoMessage
366{
367 /**
368 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL.
369 */
370 struct GNUNET_MessageHeader header;
371
372 /**
373 * Root of the channel
374 */
375 struct GNUNET_PeerIdentity root;
376
377 /**
378 * Destination of the channel
379 */
380 struct GNUNET_PeerIdentity dest;
381
382 /* FIXME: expand! */
383};
384
385
386/**
387 * Message to as the service about information on a channel.
388 */
389struct GNUNET_CADET_RequestChannelInfoMessage
390{
391 /**
392 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_CHANNEL.
393 */
394 struct GNUNET_MessageHeader header;
395
396 /**
397 * Target of the channel.
398 */
399 struct GNUNET_PeerIdentity target;
400};
401
402
403/**
404 * Message to inform the client about one of the paths known to the service.
405 */
406struct GNUNET_CADET_LocalInfoPath
407{
408 /**
409 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH.
410 */
411 struct GNUNET_MessageHeader header;
412
413 /**
414 * Offset of the peer that was requested.
415 */
416 uint32_t off GNUNET_PACKED;
417};
418
419
420/**
421 * Message to inform the client about one of the peers in the service.
422 */
423struct GNUNET_CADET_LocalInfoPeers
424{
425 /**
426 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS
427 */
428 struct GNUNET_MessageHeader header;
429
430 /**
431 * Number of paths.
432 */
433 uint16_t paths GNUNET_PACKED;
434
435 /**
436 * Do we have a tunnel toward this peer?
437 */
438 int16_t tunnel GNUNET_PACKED;
439
440 /**
441 * Shortest known path.
442 */
443 uint32_t best_path_length GNUNET_PACKED;
444
445 /**
446 * ID of the peer (can be local peer).
447 */
448 struct GNUNET_PeerIdentity destination;
449};
450
451
452/**
453 * Message to inform the client about one of the tunnels in the service.
454 *
455 * TODO: split into two messages!
456 */
457struct GNUNET_CADET_LocalInfoTunnel
458{
459 /**
460 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL
461 * or #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS
462 */
463 struct GNUNET_MessageHeader header;
464
465 /**
466 * Number of channels.
467 */
468 uint32_t channels GNUNET_PACKED;
469
470 /**
471 * ID of the destination of the tunnel (can be local peer).
472 */
473 struct GNUNET_PeerIdentity destination;
474
475 /**
476 * Number of connections.
477 */
478 uint32_t connections GNUNET_PACKED;
479
480 /**
481 * Encryption state.
482 */
483 uint16_t estate GNUNET_PACKED;
484
485 /**
486 * Connection state.
487 */
488 uint16_t cstate GNUNET_PACKED;
489
490 /* If TUNNEL (no 'S'): struct GNUNET_CADET_ConnectionTunnelIdentifier connection_ids[connections] */
491 /* If TUNNEL (no 'S'): uint32_t channel_ids[channels] */
492};
493
494
495GNUNET_NETWORK_STRUCT_END
496
497
498/**
499 * @brief Translate a fwd variable into a string representation, for logging.
500 *
501 * @param fwd Is FWD? (#GNUNET_YES or #GNUNET_NO)
502 *
503 * @return String representing FWD or BCK.
504 */
505char *
506GC_f2s (int fwd);
507
508
509/**
510 * Check if one pid is bigger than other, accounting for overflow.
511 *
512 * @param bigger Argument that should be bigger.
513 * @param smaller Argument that should be smaller.
514 *
515 * @return True if bigger (arg1) has a higher value than smaller (arg 2).
516 */
517int
518GC_is_pid_bigger (uint32_t bigger, uint32_t smaller);
519
520
521/**
522 * Get the higher ACK value out of two values, taking in account overflow.
523 *
524 * @param a First ACK value.
525 * @param b Second ACK value.
526 *
527 * @return Highest ACK value from the two.
528 */
529uint32_t
530GC_max_pid (uint32_t a, uint32_t b);
531
532
533/**
534 * Get the lower ACK value out of two values, taking in account overflow.
535 *
536 * @param a First ACK value.
537 * @param b Second ACK value.
538 *
539 * @return Lowest ACK value from the two.
540 */
541uint32_t
542GC_min_pid (uint32_t a, uint32_t b);
543
544
545/**
546 * Allocate a string with a hexdump of any binary data.
547 *
548 * @param bin Arbitrary binary data.
549 * @param len Length of @a bin in bytes.
550 * @param output Where to write the output (if *output be NULL it's allocated).
551 *
552 * @return The size of the output.
553 */
554size_t
555GC_bin2s (void *bin, unsigned int len, char **output);
556
557
558/**
559 * Convert a message type into a string to help debug
560 * Generated with:
561 * FIND: "#define ([^ ]+)[ ]*([0-9]+)"
562 * REPLACE: " case \2: return "\1"; break;"
563 *
564 * @param m Message type.
565 *
566 * @return Human readable string description.
567 */
568const char *
569GC_m2s (uint16_t m);
570
571#if 0 /* keep Emacsens' auto-indent happy */
572{
573#endif
574#ifdef __cplusplus
575}
576#endif
577
578#endif