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.h92
1 files changed, 51 insertions, 41 deletions
diff --git a/src/cadet/cadet.h b/src/cadet/cadet.h
index 049f3a85a..c16fb2917 100644
--- a/src/cadet/cadet.h
+++ b/src/cadet/cadet.h
@@ -57,6 +57,7 @@ extern "C"
57#include "gnunet_util_lib.h" 57#include "gnunet_util_lib.h"
58#include "gnunet_peer_lib.h" 58#include "gnunet_peer_lib.h"
59#include "gnunet_core_service.h" 59#include "gnunet_core_service.h"
60#include "gnunet_cadet_service.h"
60#include "gnunet_protocols.h" 61#include "gnunet_protocols.h"
61#include <gnunet_cadet_service.h> 62#include <gnunet_cadet_service.h>
62 63
@@ -64,13 +65,29 @@ extern "C"
64/************************** CONSTANTS ******************************/ 65/************************** CONSTANTS ******************************/
65/******************************************************************************/ 66/******************************************************************************/
66 67
68/**
69 * Minimum value for channel IDs of local clients.
70 */
67#define GNUNET_CADET_LOCAL_CHANNEL_ID_CLI 0x80000000 71#define GNUNET_CADET_LOCAL_CHANNEL_ID_CLI 0x80000000
68#define GNUNET_CADET_LOCAL_CHANNEL_ID_SERV 0xB0000000
69 72
70#define HIGH_PID 0xFFFF0000 73/**
71#define LOW_PID 0x0000FFFF 74 * FIXME.
75 */
76#define HIGH_PID 0xFF000000
77
78/**
79 * FIXME.
80 */
81#define LOW_PID 0x00FFFFFF
72 82
73#define PID_OVERFLOW(pid, max) (pid > HIGH_PID && max < LOW_PID) 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))
74 91
75/******************************************************************************/ 92/******************************************************************************/
76/************************** MESSAGES ******************************/ 93/************************** MESSAGES ******************************/
@@ -80,6 +97,22 @@ GNUNET_NETWORK_STRUCT_BEGIN
80 97
81 98
82/** 99/**
100 * Number uniquely identifying a channel of a client.
101 */
102struct GNUNET_CADET_ClientChannelNumber
103{
104 /**
105 * Values for channel numbering.
106 * Local channel numbers given by the service (incoming) are
107 * smaller than #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI.
108 * Local channel numbers given by the client (created) are
109 * larger than #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI.
110 */
111 uint32_t channel_of_client GNUNET_PACKED;
112};
113
114
115/**
83 * Message for a client to create and destroy channels. 116 * Message for a client to create and destroy channels.
84 */ 117 */
85struct GNUNET_CADET_PortMessage 118struct GNUNET_CADET_PortMessage
@@ -98,31 +131,23 @@ struct GNUNET_CADET_PortMessage
98 struct GNUNET_HashCode port GNUNET_PACKED; 131 struct GNUNET_HashCode port GNUNET_PACKED;
99}; 132};
100 133
101/**
102 * Type for channel numbering.
103 * - Local channel numbers given by the service (incoming) are >= 0xB0000000
104 * - Local channel numbers given by the client (created) are >= 0x80000000
105 * - Global channel numbers are < 0x80000000
106 */
107typedef uint32_t CADET_ChannelNumber;
108
109 134
110/** 135/**
111 * Message for a client to create channels. 136 * Message for a client to create channels.
112 */ 137 */
113struct GNUNET_CADET_ChannelCreateMessage 138struct GNUNET_CADET_ChannelOpenMessageMessage
114{ 139{
115 /** 140 /**
116 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_CREATE 141 * Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_TUNNEL_CREATE
117 * 142 *
118 * Size: sizeof(struct GNUNET_CADET_ChannelCreateMessage) 143 * Size: sizeof(struct GNUNET_CADET_ChannelOpenMessageMessage)
119 */ 144 */
120 struct GNUNET_MessageHeader header; 145 struct GNUNET_MessageHeader header;
121 146
122 /** 147 /**
123 * ID of a channel controlled by this client. 148 * ID of a channel controlled by this client.
124 */ 149 */
125 CADET_ChannelNumber channel_id GNUNET_PACKED; 150 struct GNUNET_CADET_ClientChannelNumber channel_id;
126 151
127 /** 152 /**
128 * Channel's peer 153 * Channel's peer
@@ -152,11 +177,11 @@ struct GNUNET_CADET_ChannelDestroyMessage
152 * Size: sizeof(struct GNUNET_CADET_ChannelDestroyMessage) 177 * Size: sizeof(struct GNUNET_CADET_ChannelDestroyMessage)
153 */ 178 */
154 struct GNUNET_MessageHeader header; 179 struct GNUNET_MessageHeader header;
155 180
156 /** 181 /**
157 * ID of a channel controlled by this client. 182 * ID of a channel controlled by this client.
158 */ 183 */
159 CADET_ChannelNumber channel_id GNUNET_PACKED; 184 struct GNUNET_CADET_ClientChannelNumber channel_id;
160}; 185};
161 186
162 187
@@ -173,7 +198,7 @@ struct GNUNET_CADET_LocalData
173 /** 198 /**
174 * ID of the channel 199 * ID of the channel
175 */ 200 */
176 uint32_t id GNUNET_PACKED; 201 struct GNUNET_CADET_ClientChannelNumber id;
177 202
178 /** 203 /**
179 * Payload follows 204 * Payload follows
@@ -195,7 +220,7 @@ struct GNUNET_CADET_LocalAck
195 /** 220 /**
196 * ID of the channel allowed to send more data. 221 * ID of the channel allowed to send more data.
197 */ 222 */
198 CADET_ChannelNumber channel_id GNUNET_PACKED; 223 struct GNUNET_CADET_ClientChannelNumber channel_id;
199 224
200}; 225};
201 226
@@ -214,7 +239,7 @@ struct GNUNET_CADET_LocalInfo
214 /** 239 /**
215 * ID of the channel allowed to send more data. 240 * ID of the channel allowed to send more data.
216 */ 241 */
217 CADET_ChannelNumber channel_id GNUNET_PACKED; 242 struct GNUNET_CADET_ClientChannelNumber channel_id;
218 243
219 /** 244 /**
220 * ID of the owner of the channel (can be local peer). 245 * ID of the owner of the channel (can be local peer).
@@ -258,6 +283,7 @@ struct GNUNET_CADET_LocalInfoPeer
258 * (each path ends in destination) */ 283 * (each path ends in destination) */
259}; 284};
260 285
286
261/** 287/**
262 * Message to inform the client about one of the tunnels in the service. 288 * Message to inform the client about one of the tunnels in the service.
263 */ 289 */
@@ -294,7 +320,7 @@ struct GNUNET_CADET_LocalInfoTunnel
294 */ 320 */
295 uint16_t cstate GNUNET_PACKED; 321 uint16_t cstate GNUNET_PACKED;
296 322
297 /* If TUNNEL (no 'S'): GNUNET_PeerIdentity connection_ids[connections] */ 323 /* If TUNNEL (no 'S'): struct GNUNET_CADET_ConnectionTunnelIdentifier connection_ids[connections] */
298 /* If TUNNEL (no 'S'): uint32_t channel_ids[channels] */ 324 /* If TUNNEL (no 'S'): uint32_t channel_ids[channels] */
299}; 325};
300 326
@@ -350,25 +376,6 @@ GC_min_pid (uint32_t a, uint32_t b);
350 376
351 377
352/** 378/**
353 * Convert a 256 bit CadetHash into a 512 HashCode to use in GNUNET_h2s,
354 * multihashmap, and other HashCode-based functions.
355 *
356 * @param id A 256 bit hash to expand.
357 *
358 * @return A HashCode containing the original 256 bit hash right-padded with 0.
359 */
360const struct GNUNET_HashCode *
361GC_h2hc (const struct GNUNET_CADET_Hash *id);
362
363/**
364 * Get a string from a Cadet Hash (256 bits).
365 * WARNING: Not reentrant (based on GNUNET_h2s).
366 */
367const char *
368GC_h2s (const struct GNUNET_CADET_Hash *id);
369
370
371/**
372 * Allocate a string with a hexdump of any binary data. 379 * Allocate a string with a hexdump of any binary data.
373 * 380 *
374 * @param bin Arbitrary binary data. 381 * @param bin Arbitrary binary data.
@@ -378,7 +385,10 @@ GC_h2s (const struct GNUNET_CADET_Hash *id);
378 * @return The size of the output. 385 * @return The size of the output.
379 */ 386 */
380size_t 387size_t
381GC_bin2s (void *bin, unsigned int len, char **output); 388GC_bin2s (void *bin,
389 unsigned int len,
390 char **output);
391
382 392
383/** 393/**
384 * Convert a message type into a string to help debug 394 * Convert a message type into a string to help debug