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