GNUnet  0.11.x
cadet.h
Go to the documentation of this file.
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 
26 #ifndef CADET_H_
27 #define CADET_H_
28 
29 #ifdef __cplusplus
30 extern "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 
71 #define GNUNET_CADET_LOCAL_CHANNEL_ID_CLI 0x80000000U
72 
76 #define HIGH_PID 0xFF000000
77 
81 #define LOW_PID 0x00FFFFFF
82 
83 
90 #define PID_OVERFLOW(pid, max) (((pid) > HIGH_PID) && ((max) < LOW_PID))
91 
92 /******************************************************************************/
93 /************************** MESSAGES ******************************/
94 /******************************************************************************/
95 
97 
102 {
111 };
112 
117 {
118 
122  struct GNUNET_PeerIdentity peer;
123 
128 
133 
138  void *ctx;
139 
144 
149 
156 
161 
166 
171 
175  unsigned int allow_send;
176 };
177 
182 {
190 
195 };
196 
197 
202 {
209 
214 
218  struct GNUNET_PeerIdentity peer;
219 
223  struct GNUNET_HashCode port;
224 
228  uint32_t opt GNUNET_PACKED;
229 };
230 
231 
236 {
241 
246 };
247 
248 
253 {
258 
263 
268  uint32_t pp GNUNET_PACKED;
269 
273 };
274 
275 
281 {
286 
291 };
292 
293 
300 {
306 
311 
315  struct GNUNET_PeerIdentity peer;
316 };
317 
322 {
323 
328 
332  uint16_t type;
333 
338 
339 };
340 
345 {
350 
355 
359  struct GNUNET_PeerIdentity peer;
360 };
361 
362 
367 {
372 
376  struct GNUNET_PeerIdentity root;
377 
381  struct GNUNET_PeerIdentity dest;
382 
383  /* FIXME: expand! */
384 };
385 
386 
391 {
396 
401 };
402 
403 
408 {
413 
417  uint32_t off GNUNET_PACKED;
418 };
419 
420 
425 {
430 
435 
440 
445 
450 };
451 
452 
459 {
465 
470 
475 
480 
485 
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 
497 
498 
506 char *
507 GC_f2s (int fwd);
508 
509 
518 int
519 GC_is_pid_bigger (uint32_t bigger, uint32_t smaller);
520 
521 
530 uint32_t
531 GC_max_pid (uint32_t a, uint32_t b);
532 
533 
542 uint32_t
543 GC_min_pid (uint32_t a, uint32_t b);
544 
545 
555 size_t
556 GC_bin2s (void *bin, unsigned int len, char **output);
557 
558 
569 const char *
570 GC_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
size_t GC_bin2s(void *bin, unsigned int len, char **output)
Allocate a string with a hexdump of any binary data.
uint32_t GC_min_pid(uint32_t a, uint32_t b)
Get the lower ACK value out of two values, taking in account overflow.
uint32_t GC_max_pid(uint32_t a, uint32_t b)
Get the higher ACK value out of two values, taking in account overflow.
const char * GC_m2s(uint16_t m)
Convert a message type into a string to help debug Generated with: FIND: "#define ([^ ]+)[ ]*([0-9]+)...
int GC_is_pid_bigger(uint32_t bigger, uint32_t smaller)
Check if one pid is bigger than other, accounting for overflow.
GNUNET_NETWORK_STRUCT_END char * GC_f2s(int fwd)
Translate a fwd variable into a string representation, for logging.
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.
#define GNUNET_PACKED
gcc-ism to get packed structs.
void(* GNUNET_CADET_DisconnectEventHandler)(void *cls, const struct GNUNET_CADET_Channel *channel)
Function called whenever an MQ-channel is destroyed, unless the destruction was requested by GNUNET_C...
void(* GNUNET_CADET_WindowSizeEventHandler)(void *cls, const struct GNUNET_CADET_Channel *channel, int window_size)
Function called whenever an MQ-channel's transmission window size changes.
Message to inform the client about channels in the service.
Definition: cadet.h:367
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL.
Definition: cadet.h:371
struct GNUNET_PeerIdentity dest
Destination of the channel.
Definition: cadet.h:381
struct GNUNET_PeerIdentity root
Root of the channel.
Definition: cadet.h:376
Opaque handle to a channel.
Definition: cadet.h:117
void * ctx
Any data the caller wants to put in here, used for the various callbacks (disconnects,...
Definition: cadet.h:138
struct GNUNET_CADET_Handle * cadet
Handle to the cadet this channel belongs to.
Definition: cadet.h:127
unsigned int allow_send
How many messages are we allowed to send to the service right now?
Definition: cadet.h:175
struct GNUNET_SCHEDULER_Task * mq_cont
Task to allow mq to send more traffic.
Definition: cadet.h:148
struct GNUNET_PeerIdentity peer
Other end of the channel.
Definition: cadet.h:122
GNUNET_CADET_WindowSizeEventHandler window_changes
Window change handler.
Definition: cadet.h:160
struct GNUNET_CADET_ClientChannelNumber ccn
Local ID of the channel, GNUNET_CADET_LOCAL_CHANNEL_ID_CLI bit is set if outbound.
Definition: cadet.h:170
GNUNET_CADET_DisconnectEventHandler disconnects
Disconnect handler.
Definition: cadet.h:165
struct GNUNET_MQ_Handle * mq
Message Queue for the channel (which we are implementing).
Definition: cadet.h:143
struct GNUNET_MQ_Envelope * pending_env
Pending envelope with a message to be transmitted to the service as soon as we are allowed to.
Definition: cadet.h:155
struct GNUNET_CADET_Port * incoming_port
Channel's port, if incoming.
Definition: cadet.h:132
Number uniquely identifying a channel of a client.
Definition: cadet.h:102
uint32_t channel_of_client
Values for channel numbering.
Definition: cadet.h:110
Opaque handle to the service.
Definition: cadet_api.c:39
Message to allow the client send more data to the service (always service -> client).
Definition: cadet.h:281
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK.
Definition: cadet.h:285
struct GNUNET_CADET_ClientChannelNumber ccn
ID of the channel allowed to send more data.
Definition: cadet.h:290
Message for a client to create channels.
Definition: cadet.h:202
struct GNUNET_PeerIdentity peer
Channel's peer.
Definition: cadet.h:218
struct GNUNET_CADET_ClientChannelNumber ccn
ID of a channel controlled by this client.
Definition: cadet.h:213
struct GNUNET_HashCode port
Port of the channel.
Definition: cadet.h:223
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE.
Definition: cadet.h:208
Message for or to a client to destroy tunnel.
Definition: cadet.h:236
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY.
Definition: cadet.h:240
struct GNUNET_CADET_ClientChannelNumber ccn
ID of a channel controlled by this client.
Definition: cadet.h:245
Message for cadet data traffic.
Definition: cadet.h:253
struct GNUNET_CADET_ClientChannelNumber ccn
ID of the channel.
Definition: cadet.h:262
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA.
Definition: cadet.h:257
uint32_t pp
Priority and preferences (an enum GNUNET_MQ_PriorityPreferences) of the message in NBO.
Definition: cadet.h:268
Message to inform the client about one of the paths known to the service.
Definition: cadet.h:408
uint32_t off
Offset of the peer that was requested.
Definition: cadet.h:417
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH.
Definition: cadet.h:412
Message to inform the client about one of the peers in the service.
Definition: cadet.h:425
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS.
Definition: cadet.h:429
struct GNUNET_PeerIdentity destination
ID of the peer (can be local peer).
Definition: cadet.h:449
uint32_t best_path_length
Shortest known path.
Definition: cadet.h:444
int16_t tunnel
Do we have a tunnel toward this peer?
Definition: cadet.h:439
uint16_t paths
Number of paths.
Definition: cadet.h:434
Message to inform the client about one of the tunnels in the service.
Definition: cadet.h:459
struct GNUNET_MessageHeader header
Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL or GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS.
Definition: cadet.h:464
uint16_t cstate
Connection state.
Definition: cadet.h:489
uint16_t estate
Encryption state.
Definition: cadet.h:484
struct GNUNET_PeerIdentity destination
ID of the destination of the tunnel (can be local peer).
Definition: cadet.h:474
uint32_t connections
Number of connections.
Definition: cadet.h:479
uint32_t channels
Number of channels.
Definition: cadet.h:469
Message to inform the client about channels in the service.
Definition: cadet.h:300
struct GNUNET_PeerIdentity peer
ID of the destination of the channel (can be local peer).
Definition: cadet.h:315
struct GNUNET_CADET_ClientChannelNumber ccn
ID of the channel allowed to send more data.
Definition: cadet.h:310
struct GNUNET_MessageHeader header
Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL or #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER.
Definition: cadet.h:305
Message for a client to create and destroy channels.
Definition: cadet.h:182
struct GNUNET_HashCode port
Port to open/close.
Definition: cadet.h:194
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN or GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE.
Definition: cadet.h:189
Opaque handle to a port.
Definition: cadet_api.c:80
Message to as the service about information on a channel.
Definition: cadet.h:391
struct GNUNET_PeerIdentity target
Target of the channel.
Definition: cadet.h:400
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_CHANNEL.
Definition: cadet.h:395
Message to drop another message of specific type.
Definition: cadet.h:322
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_CADET_DROP_CADET_MESSAGE.
Definition: cadet.h:327
struct GNUNET_CADET_ClientChannelNumber ccn
ID of the channel we want to drop a message for.
Definition: cadet.h:337
uint16_t type
Type of the message this handler covers, in host byte order.
Definition: cadet.h:332
Message to inform the client about channels in the service.
Definition: cadet.h:345
uint32_t resered
Always zero.
Definition: cadet.h:354
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH.
Definition: cadet.h:349
struct GNUNET_PeerIdentity peer
ID of the destination of the channel (can be local peer).
Definition: cadet.h:359
A 512-bit hashcode.
Handle to a message queue.
Definition: mq.c:86
Header for all communications.
The identity of the host (wraps the signing key of the peer).
Entry in list of pending tasks.
Definition: scheduler.c:135