aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cadet/Makefile.am36
-rw-r--r--src/cadet/cadet.h53
-rw-r--r--src/cadet/cadet_api.c404
-rw-r--r--src/cadet/cadet_protocol.h11
-rw-r--r--src/cadet/gnunet-cadet.c13
-rw-r--r--src/cadet/gnunet-service-cadet_channel.c81
-rw-r--r--src/cadet/gnunet-service-cadet_channel.h4
-rw-r--r--src/cadet/gnunet-service-cadet_connection.c2
-rw-r--r--src/cadet/gnunet-service-cadet_dht.c16
-rw-r--r--src/cadet/gnunet-service-cadet_hello.h5
-rw-r--r--src/cadet/gnunet-service-cadet_local.c182
-rw-r--r--src/cadet/gnunet-service-cadet_local.h30
-rw-r--r--src/cadet/gnunet-service-cadet_peer.c4
-rw-r--r--src/cadet/gnunet-service-cadet_peer.h5
-rw-r--r--src/cadet/gnunet-service-cadet_tunnel.c96
-rw-r--r--src/cadet/gnunet-service-cadet_tunnel.h4
-rw-r--r--src/cadet/test_cadet_local.c5
-rw-r--r--src/include/gnunet_cadet_service.h29
-rw-r--r--src/include/gnunet_protocols.h5
19 files changed, 586 insertions, 399 deletions
diff --git a/src/cadet/Makefile.am b/src/cadet/Makefile.am
index d823b4872..ba93bee18 100644
--- a/src/cadet/Makefile.am
+++ b/src/cadet/Makefile.am
@@ -22,7 +22,9 @@ plugindir = $(libdir)/gnunet
22AM_CLFAGS = -g 22AM_CLFAGS = -g
23 23
24libexec_PROGRAMS = \ 24libexec_PROGRAMS = \
25 gnunet-service-cadet $(EXP_LIBEXEC) 25 gnunet-service-cadet \
26 gnunet-service-cadet-new \
27 $(EXP_LIBEXEC)
26 28
27bin_PROGRAMS = \ 29bin_PROGRAMS = \
28 gnunet-cadet 30 gnunet-cadet
@@ -46,6 +48,26 @@ gnunet_cadet_LDADD = \
46 libgnunetcadet.la \ 48 libgnunetcadet.la \
47 $(top_builddir)/src/util/libgnunetutil.la 49 $(top_builddir)/src/util/libgnunetutil.la
48 50
51gnunet_service_cadet_new_SOURCES = \
52 gnunet-service-cadet-new.c gnunet-service-cadet-new.h \
53 gnunet-service-cadet-new_channel.c gnunet-service-cadet-new_channel.h \
54 gnunet-service-cadet-new_connection.c gnunet-service-cadet-new_connection.h \
55 gnunet-service-cadet-new_dht.c gnunet-service-cadet-new_dht.h \
56 gnunet-service-cadet-new_hello.c gnunet-service-cadet-new_hello.h \
57 gnunet-service-cadet-new_tunnels.c gnunet-service-cadet-new_tunnels.h \
58 gnunet-service-cadet-new_paths.c gnunet-service-cadet-new_paths.h \
59 gnunet-service-cadet-new_peer.c gnunet-service-cadet-new_peer.h
60gnunet_service_cadet_new_LDADD = \
61 $(top_builddir)/src/util/libgnunetutil.la \
62 $(top_builddir)/src/ats/libgnunetats.la \
63 $(top_builddir)/src/core/libgnunetcore.la \
64 $(top_builddir)/src/dht/libgnunetdht.la \
65 $(top_builddir)/src/statistics/libgnunetstatistics.la \
66 $(top_builddir)/src/transport/libgnunettransport.la \
67 $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \
68 $(top_builddir)/src/hello/libgnunethello.la \
69 $(top_builddir)/src/block/libgnunetblock.la
70
49gnunet_service_cadet_SOURCES = \ 71gnunet_service_cadet_SOURCES = \
50 gnunet-service-cadet_tunnel.c gnunet-service-cadet_tunnel.h \ 72 gnunet-service-cadet_tunnel.c gnunet-service-cadet_tunnel.h \
51 gnunet-service-cadet_connection.c gnunet-service-cadet_connection.h \ 73 gnunet-service-cadet_connection.c gnunet-service-cadet_connection.h \
@@ -87,6 +109,11 @@ libgnunetcadettest_a_LIBADD = \
87 109
88if HAVE_TESTING 110if HAVE_TESTING
89check_PROGRAMS = \ 111check_PROGRAMS = \
112 test_cadet_2_speed_reliable_backwards \
113 test_cadet_5_speed \
114 test_cadet_5_speed_ack \
115 test_cadet_5_speed_reliable \
116 test_cadet_5_speed_reliable_backwards \
90 test_cadet_single \ 117 test_cadet_single \
91 test_cadet_local \ 118 test_cadet_local \
92 test_cadet_2_forward \ 119 test_cadet_2_forward \
@@ -96,15 +123,10 @@ check_PROGRAMS = \
96 test_cadet_2_speed_ack \ 123 test_cadet_2_speed_ack \
97 test_cadet_2_speed_backwards \ 124 test_cadet_2_speed_backwards \
98 test_cadet_2_speed_reliable \ 125 test_cadet_2_speed_reliable \
99 test_cadet_2_speed_reliable_backwards \
100 test_cadet_5_forward \ 126 test_cadet_5_forward \
101 test_cadet_5_signal \ 127 test_cadet_5_signal \
102 test_cadet_5_keepalive \ 128 test_cadet_5_keepalive \
103 test_cadet_5_speed \ 129 test_cadet_5_speed_backwards
104 test_cadet_5_speed_ack \
105 test_cadet_5_speed_backwards \
106 test_cadet_5_speed_reliable \
107 test_cadet_5_speed_reliable_backwards
108endif 130endif
109 131
110ld_cadet_test_lib = \ 132ld_cadet_test_lib = \
diff --git a/src/cadet/cadet.h b/src/cadet/cadet.h
index f3f6fb6b4..163734c06 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,12 +65,22 @@ 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
73/**
74 * FIXME.
75 */
70#define HIGH_PID 0xFF000000 76#define HIGH_PID 0xFF000000
77
78/**
79 * FIXME.
80 */
71#define LOW_PID 0x00FFFFFF 81#define LOW_PID 0x00FFFFFF
72 82
83
73/** 84/**
74 * Test if the two PIDs (of type `uint32_t`) are in the range where we 85 * Test if the two PIDs (of type `uint32_t`) are in the range where we
75 * have to worry about overflows. This is the case when @a pid is 86 * have to worry about overflows. This is the case when @a pid is
@@ -86,6 +97,22 @@ GNUNET_NETWORK_STRUCT_BEGIN
86 97
87 98
88/** 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/**
89 * Message for a client to create and destroy channels. 116 * Message for a client to create and destroy channels.
90 */ 117 */
91struct GNUNET_CADET_PortMessage 118struct GNUNET_CADET_PortMessage
@@ -104,14 +131,6 @@ struct GNUNET_CADET_PortMessage
104 struct GNUNET_HashCode port GNUNET_PACKED; 131 struct GNUNET_HashCode port GNUNET_PACKED;
105}; 132};
106 133
107/**
108 * Type for channel numbering.
109 * - Local channel numbers given by the service (incoming) are >= 0xB0000000
110 * - Local channel numbers given by the client (created) are >= 0x80000000
111 * - Global channel numbers are < 0x80000000
112 */
113typedef uint32_t CADET_ChannelNumber;
114
115 134
116/** 135/**
117 * Message for a client to create channels. 136 * Message for a client to create channels.
@@ -128,7 +147,7 @@ struct GNUNET_CADET_ChannelCreateMessage
128 /** 147 /**
129 * ID of a channel controlled by this client. 148 * ID of a channel controlled by this client.
130 */ 149 */
131 CADET_ChannelNumber channel_id GNUNET_PACKED; 150 struct GNUNET_CADET_ClientChannelNumber channel_id;
132 151
133 /** 152 /**
134 * Channel's peer 153 * Channel's peer
@@ -158,11 +177,11 @@ struct GNUNET_CADET_ChannelDestroyMessage
158 * Size: sizeof(struct GNUNET_CADET_ChannelDestroyMessage) 177 * Size: sizeof(struct GNUNET_CADET_ChannelDestroyMessage)
159 */ 178 */
160 struct GNUNET_MessageHeader header; 179 struct GNUNET_MessageHeader header;
161 180
162 /** 181 /**
163 * ID of a channel controlled by this client. 182 * ID of a channel controlled by this client.
164 */ 183 */
165 CADET_ChannelNumber channel_id GNUNET_PACKED; 184 struct GNUNET_CADET_ClientChannelNumber channel_id;
166}; 185};
167 186
168 187
@@ -179,7 +198,7 @@ struct GNUNET_CADET_LocalData
179 /** 198 /**
180 * ID of the channel 199 * ID of the channel
181 */ 200 */
182 uint32_t id GNUNET_PACKED; 201 struct GNUNET_CADET_ClientChannelNumber id;
183 202
184 /** 203 /**
185 * Payload follows 204 * Payload follows
@@ -201,7 +220,7 @@ struct GNUNET_CADET_LocalAck
201 /** 220 /**
202 * ID of the channel allowed to send more data. 221 * ID of the channel allowed to send more data.
203 */ 222 */
204 CADET_ChannelNumber channel_id GNUNET_PACKED; 223 struct GNUNET_CADET_ClientChannelNumber channel_id;
205 224
206}; 225};
207 226
@@ -220,7 +239,7 @@ struct GNUNET_CADET_LocalInfo
220 /** 239 /**
221 * ID of the channel allowed to send more data. 240 * ID of the channel allowed to send more data.
222 */ 241 */
223 CADET_ChannelNumber channel_id GNUNET_PACKED; 242 struct GNUNET_CADET_ClientChannelNumber channel_id;
224 243
225 /** 244 /**
226 * ID of the owner of the channel (can be local peer). 245 * ID of the owner of the channel (can be local peer).
@@ -264,6 +283,7 @@ struct GNUNET_CADET_LocalInfoPeer
264 * (each path ends in destination) */ 283 * (each path ends in destination) */
265}; 284};
266 285
286
267/** 287/**
268 * 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.
269 */ 289 */
@@ -300,7 +320,7 @@ struct GNUNET_CADET_LocalInfoTunnel
300 */ 320 */
301 uint16_t cstate GNUNET_PACKED; 321 uint16_t cstate GNUNET_PACKED;
302 322
303 /* If TUNNEL (no 'S'): GNUNET_PeerIdentity connection_ids[connections] */ 323 /* If TUNNEL (no 'S'): struct GNUNET_CADET_ConnectionTunnelIdentifier connection_ids[connections] */
304 /* If TUNNEL (no 'S'): uint32_t channel_ids[channels] */ 324 /* If TUNNEL (no 'S'): uint32_t channel_ids[channels] */
305}; 325};
306 326
@@ -366,6 +386,7 @@ GC_min_pid (uint32_t a, uint32_t b);
366const struct GNUNET_HashCode * 386const struct GNUNET_HashCode *
367GC_h2hc (const struct GNUNET_CADET_Hash *id); 387GC_h2hc (const struct GNUNET_CADET_Hash *id);
368 388
389
369/** 390/**
370 * Get a string from a Cadet Hash (256 bits). 391 * Get a string from a Cadet Hash (256 bits).
371 * WARNING: Not reentrant (based on GNUNET_h2s). 392 * WARNING: Not reentrant (based on GNUNET_h2s).
diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c
index 23305d8a9..57a14639d 100644
--- a/src/cadet/cadet_api.c
+++ b/src/cadet/cadet_api.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2011 GNUnet e.V. 3 Copyright (C) 2011, 2017 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -19,7 +19,7 @@
19*/ 19*/
20/** 20/**
21 * @file cadet/cadet_api.c 21 * @file cadet/cadet_api.c
22 * @brief cadet api: client implementation of new cadet service 22 * @brief cadet api: client implementation of cadet service
23 * @author Bartlomiej Polot 23 * @author Bartlomiej Polot
24 */ 24 */
25 25
@@ -41,46 +41,48 @@
41 */ 41 */
42struct GNUNET_CADET_TransmitHandle 42struct GNUNET_CADET_TransmitHandle
43{ 43{
44 /** 44 /**
45 * Double Linked list 45 * Double Linked list
46 */ 46 */
47 struct GNUNET_CADET_TransmitHandle *next; 47 struct GNUNET_CADET_TransmitHandle *next;
48 48
49 /** 49 /**
50 * Double Linked list 50 * Double Linked list
51 */ 51 */
52 struct GNUNET_CADET_TransmitHandle *prev; 52 struct GNUNET_CADET_TransmitHandle *prev;
53 53
54 /** 54 /**
55 * Channel this message is sent on / for (may be NULL for control messages). 55 * Channel this message is sent on / for (may be NULL for control messages).
56 */ 56 */
57 struct GNUNET_CADET_Channel *channel; 57 struct GNUNET_CADET_Channel *channel;
58 58
59 /** 59 /**
60 * Request data task. 60 * Request data task.
61 */ 61 */
62 struct GNUNET_SCHEDULER_Task *request_data_task; 62 struct GNUNET_SCHEDULER_Task *request_data_task;
63 63
64 /** 64 /**
65 * Callback to obtain the message to transmit, or NULL if we 65 * Callback to obtain the message to transmit, or NULL if we
66 * got the message in 'data'. Notice that messages built 66 * got the message in 'data'. Notice that messages built
67 * by 'notify' need to be encapsulated with information about 67 * by 'notify' need to be encapsulated with information about
68 * the 'target'. 68 * the 'target'.
69 */ 69 */
70 GNUNET_CONNECTION_TransmitReadyNotify notify; 70 GNUNET_CONNECTION_TransmitReadyNotify notify;
71 71
72 /** 72 /**
73 * Closure for 'notify' 73 * Closure for 'notify'
74 */ 74 */
75 void *notify_cls; 75 void *notify_cls;
76 76
77 /** 77 /**
78 * Size of the payload. 78 * Size of the payload.
79 */ 79 */
80 size_t size; 80 size_t size;
81}; 81};
82 82
83union CadetInfoCB { 83
84union CadetInfoCB
85{
84 86
85 /** 87 /**
86 * Channel callback. 88 * Channel callback.
@@ -114,14 +116,14 @@ union CadetInfoCB {
114 */ 116 */
115struct GNUNET_CADET_Handle 117struct GNUNET_CADET_Handle
116{ 118{
117 /** 119 /**
118 * Message queue (if available). 120 * Message queue (if available).
119 */ 121 */
120 struct GNUNET_MQ_Handle *mq; 122 struct GNUNET_MQ_Handle *mq;
121 123
122 /** 124 /**
123 * Set of handlers used for processing incoming messages in the channels 125 * Set of handlers used for processing incoming messages in the channels
124 */ 126 */
125 const struct GNUNET_CADET_MessageHandler *message_handlers; 127 const struct GNUNET_CADET_MessageHandler *message_handlers;
126 128
127 /** 129 /**
@@ -134,40 +136,40 @@ struct GNUNET_CADET_Handle
134 */ 136 */
135 struct GNUNET_CONTAINER_MultiHashMap *ports; 137 struct GNUNET_CONTAINER_MultiHashMap *ports;
136 138
137 /** 139 /**
138 * Double linked list of the channels this client is connected to, head. 140 * Double linked list of the channels this client is connected to, head.
139 */ 141 */
140 struct GNUNET_CADET_Channel *channels_head; 142 struct GNUNET_CADET_Channel *channels_head;
141 143
142 /** 144 /**
143 * Double linked list of the channels this client is connected to, tail. 145 * Double linked list of the channels this client is connected to, tail.
144 */ 146 */
145 struct GNUNET_CADET_Channel *channels_tail; 147 struct GNUNET_CADET_Channel *channels_tail;
146 148
147 /** 149 /**
148 * Callback for inbound channel disconnection 150 * Callback for inbound channel disconnection
149 */ 151 */
150 GNUNET_CADET_ChannelEndHandler *cleaner; 152 GNUNET_CADET_ChannelEndHandler *cleaner;
151 153
152 /** 154 /**
153 * Closure for all the handlers given by the client 155 * Closure for all the handlers given by the client
154 */ 156 */
155 void *cls; 157 void *cls;
156 158
157 /** 159 /**
158 * Messages to send to the service, head. 160 * Messages to send to the service, head.
159 */ 161 */
160 struct GNUNET_CADET_TransmitHandle *th_head; 162 struct GNUNET_CADET_TransmitHandle *th_head;
161 163
162 /** 164 /**
163 * Messages to send to the service, tail. 165 * Messages to send to the service, tail.
164 */ 166 */
165 struct GNUNET_CADET_TransmitHandle *th_tail; 167 struct GNUNET_CADET_TransmitHandle *th_tail;
166 168
167 /** 169 /**
168 * chid of the next channel to create (to avoid reusing IDs often) 170 * child of the next channel to create (to avoid reusing IDs often)
169 */ 171 */
170 CADET_ChannelNumber next_chid; 172 struct GNUNET_CADET_ClientChannelNumber next_chid;
171 173
172 /** 174 /**
173 * Configuration given by the client, in case of reconnection 175 * Configuration given by the client, in case of reconnection
@@ -201,9 +203,9 @@ struct GNUNET_CADET_Handle
201 */ 203 */
202struct GNUNET_CADET_Peer 204struct GNUNET_CADET_Peer
203{ 205{
204 /** 206 /**
205 * ID of the peer in short form 207 * ID of the peer in short form
206 */ 208 */
207 GNUNET_PEER_Id id; 209 GNUNET_PEER_Id id;
208 210
209 /** 211 /**
@@ -218,34 +220,34 @@ struct GNUNET_CADET_Peer
218 */ 220 */
219struct GNUNET_CADET_Channel 221struct GNUNET_CADET_Channel
220{ 222{
221 /** 223 /**
222 * DLL next 224 * DLL next
223 */ 225 */
224 struct GNUNET_CADET_Channel *next; 226 struct GNUNET_CADET_Channel *next;
225 227
226 /** 228 /**
227 * DLL prev 229 * DLL prev
228 */ 230 */
229 struct GNUNET_CADET_Channel *prev; 231 struct GNUNET_CADET_Channel *prev;
230 232
231 /** 233 /**
232 * Handle to the cadet this channel belongs to 234 * Handle to the cadet this channel belongs to
233 */ 235 */
234 struct GNUNET_CADET_Handle *cadet; 236 struct GNUNET_CADET_Handle *cadet;
235 237
236 /** 238 /**
237 * Local ID of the channel 239 * Local ID of the channel
238 */ 240 */
239 CADET_ChannelNumber chid; 241 struct GNUNET_CADET_ClientChannelNumber chid;
240 242
241 /** 243 /**
242 * Channel's port, if any. 244 * Channel's port, if any.
243 */ 245 */
244 struct GNUNET_CADET_Port *port; 246 struct GNUNET_CADET_Port *port;
245 247
246 /** 248 /**
247 * Other end of the channel. 249 * Other end of the channel.
248 */ 250 */
249 GNUNET_PEER_Id peer; 251 GNUNET_PEER_Id peer;
250 252
251 /** 253 /**
@@ -253,46 +255,47 @@ struct GNUNET_CADET_Channel
253 */ 255 */
254 void *ctx; 256 void *ctx;
255 257
256 /** 258 /**
257 * Size of packet queued in this channel 259 * Size of packet queued in this channel
258 */ 260 */
259 unsigned int packet_size; 261 unsigned int packet_size;
260 262
261 /** 263 /**
262 * Channel options: reliability, etc. 264 * Channel options: reliability, etc.
263 */ 265 */
264 enum GNUNET_CADET_ChannelOption options; 266 enum GNUNET_CADET_ChannelOption options;
265 267
266 /** 268 /**
267 * Are we allowed to send to the service? 269 * Are we allowed to send to the service?
268 */ 270 */
269 int allow_send; 271 int allow_send;
270 272
271}; 273};
272 274
275
273/** 276/**
274 * Opaque handle to a port. 277 * Opaque handle to a port.
275 */ 278 */
276struct GNUNET_CADET_Port 279struct GNUNET_CADET_Port
277{ 280{
278 /** 281 /**
279 * Handle to the CADET session this port belongs to. 282 * Handle to the CADET session this port belongs to.
280 */ 283 */
281 struct GNUNET_CADET_Handle *cadet; 284 struct GNUNET_CADET_Handle *cadet;
282 285
283 /** 286 /**
284 * Port ID. 287 * Port ID.
285 */ 288 */
286 struct GNUNET_HashCode *hash; 289 struct GNUNET_HashCode *hash;
287 290
288 /** 291 /**
289 * Callback handler for incoming channels on this port. 292 * Callback handler for incoming channels on this port.
290 */ 293 */
291 GNUNET_CADET_InboundChannelNotificationHandler *handler; 294 GNUNET_CADET_InboundChannelNotificationHandler *handler;
292 295
293 /** 296 /**
294 * Closure for @a handler. 297 * Closure for @a handler.
295 */ 298 */
296 void *cls; 299 void *cls;
297}; 300};
298 301
@@ -356,22 +359,20 @@ find_port (const struct GNUNET_CADET_Handle *h,
356 359
357/** 360/**
358 * Get the channel handler for the channel specified by id from the given handle 361 * Get the channel handler for the channel specified by id from the given handle
362 *
359 * @param h Cadet handle 363 * @param h Cadet handle
360 * @param chid ID of the wanted channel 364 * @param chid ID of the wanted channel
361 * @return handle to the required channel or NULL if not found 365 * @return handle to the required channel or NULL if not found
362 */ 366 */
363static struct GNUNET_CADET_Channel * 367static struct GNUNET_CADET_Channel *
364retrieve_channel (struct GNUNET_CADET_Handle *h, CADET_ChannelNumber chid) 368retrieve_channel (struct GNUNET_CADET_Handle *h,
369 struct GNUNET_CADET_ClientChannelNumber chid)
365{ 370{
366 struct GNUNET_CADET_Channel *ch; 371 struct GNUNET_CADET_Channel *ch;
367 372
368 ch = h->channels_head; 373 for (ch = h->channels_head; NULL != ch; ch = ch->next)
369 while (ch != NULL) 374 if (ch->chid.channel_of_client == chid.channel_of_client)
370 {
371 if (ch->chid == chid)
372 return ch; 375 return ch;
373 ch = ch->next;
374 }
375 return NULL; 376 return NULL;
376} 377}
377 378
@@ -385,21 +386,27 @@ retrieve_channel (struct GNUNET_CADET_Handle *h, CADET_ChannelNumber chid)
385 * @return Handle to the created channel. 386 * @return Handle to the created channel.
386 */ 387 */
387static struct GNUNET_CADET_Channel * 388static struct GNUNET_CADET_Channel *
388create_channel (struct GNUNET_CADET_Handle *h, CADET_ChannelNumber chid) 389create_channel (struct GNUNET_CADET_Handle *h,
390 struct GNUNET_CADET_ClientChannelNumber chid)
389{ 391{
390 struct GNUNET_CADET_Channel *ch; 392 struct GNUNET_CADET_Channel *ch;
391 393
392 ch = GNUNET_new (struct GNUNET_CADET_Channel); 394 ch = GNUNET_new (struct GNUNET_CADET_Channel);
393 GNUNET_CONTAINER_DLL_insert (h->channels_head, h->channels_tail, ch); 395 GNUNET_CONTAINER_DLL_insert (h->channels_head,
396 h->channels_tail,
397 ch);
394 ch->cadet = h; 398 ch->cadet = h;
395 if (0 == chid) 399 if (0 == chid.channel_of_client)
396 { 400 {
397 ch->chid = h->next_chid; 401 ch->chid = h->next_chid;
398 while (NULL != retrieve_channel (h, h->next_chid)) 402 while (NULL != retrieve_channel (h,
403 h->next_chid))
399 { 404 {
400 h->next_chid++; 405 h->next_chid.channel_of_client
401 h->next_chid &= ~GNUNET_CADET_LOCAL_CHANNEL_ID_SERV; 406 = htonl (1 + ntohl (h->next_chid.channel_of_client));
402 h->next_chid |= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI; 407 if (0 == ntohl (h->next_chid.channel_of_client))
408 h->next_chid.channel_of_client
409 = htonl (GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
403 } 410 }
404 } 411 }
405 else 412 else
@@ -440,7 +447,9 @@ destroy_channel (struct GNUNET_CADET_Channel *ch, int call_cleaner)
440 } 447 }
441 h = ch->cadet; 448 h = ch->cadet;
442 449
443 GNUNET_CONTAINER_DLL_remove (h->channels_head, h->channels_tail, ch); 450 GNUNET_CONTAINER_DLL_remove (h->channels_head,
451 h->channels_tail,
452 ch);
444 453
445 /* signal channel destruction */ 454 /* signal channel destruction */
446 if ( (NULL != h->cleaner) && (0 != ch->peer) && (GNUNET_YES == call_cleaner) ) 455 if ( (NULL != h->cleaner) && (0 != ch->peer) && (GNUNET_YES == call_cleaner) )
@@ -466,7 +475,7 @@ destroy_channel (struct GNUNET_CADET_Channel *ch, int call_cleaner)
466 if (0 != ch->peer) 475 if (0 != ch->peer)
467 GNUNET_PEER_change_rc (ch->peer, -1); 476 GNUNET_PEER_change_rc (ch->peer, -1);
468 GNUNET_free (ch); 477 GNUNET_free (ch);
469 return; 478
470} 479}
471 480
472 481
@@ -516,13 +525,15 @@ send_ack (struct GNUNET_CADET_Channel *ch)
516 struct GNUNET_CADET_LocalAck *msg; 525 struct GNUNET_CADET_LocalAck *msg;
517 struct GNUNET_MQ_Envelope *env; 526 struct GNUNET_MQ_Envelope *env;
518 527
519 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); 528 env = GNUNET_MQ_msg (msg,
520 529 GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK);
521 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ACK on channel %X\n", ch->chid);
522 msg->channel_id = htonl (ch->chid);
523 GNUNET_MQ_send (ch->cadet->mq, env);
524 530
525 return; 531 LOG (GNUNET_ERROR_TYPE_DEBUG,
532 "Sending ACK on channel %X\n",
533 ch->chid.channel_of_client);
534 msg->channel_id = ch->chid;
535 GNUNET_MQ_send (ch->cadet->mq,
536 env);
526} 537}
527 538
528 539
@@ -555,13 +566,16 @@ request_data (void *cls)
555 th->channel->packet_size = 0; 566 th->channel->packet_size = 0;
556 remove_from_queue (th); 567 remove_from_queue (th);
557 568
558 env = GNUNET_MQ_msg_extra (msg, th->size, 569 env = GNUNET_MQ_msg_extra (msg,
570 th->size,
559 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); 571 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA);
560 msg->id = htonl (th->channel->chid); 572 msg->id = th->channel->chid;
561 osize = th->notify (th->notify_cls, th->size, &msg[1]); 573 osize = th->notify (th->notify_cls,
574 th->size,
575 &msg[1]);
562 GNUNET_assert (osize == th->size); 576 GNUNET_assert (osize == th->size);
563 GNUNET_MQ_send (th->channel->cadet->mq, env); 577 GNUNET_MQ_send (th->channel->cadet->mq,
564 578 env);
565 GNUNET_free (th); 579 GNUNET_free (th);
566} 580}
567 581
@@ -580,13 +594,15 @@ handle_channel_created (void *cls,
580 struct GNUNET_CADET_Channel *ch; 594 struct GNUNET_CADET_Channel *ch;
581 struct GNUNET_CADET_Port *port; 595 struct GNUNET_CADET_Port *port;
582 const struct GNUNET_HashCode *port_number; 596 const struct GNUNET_HashCode *port_number;
583 CADET_ChannelNumber chid; 597 struct GNUNET_CADET_ClientChannelNumber chid;
584 598
585 chid = ntohl (msg->channel_id); 599 chid = msg->channel_id;
586 port_number = &msg->port; 600 port_number = &msg->port;
587 LOG (GNUNET_ERROR_TYPE_DEBUG, "Creating incoming channel %X [%s]\n", 601 LOG (GNUNET_ERROR_TYPE_DEBUG,
588 chid, GNUNET_h2s (port_number)); 602 "Creating incoming channel %X [%s]\n",
589 if (chid < GNUNET_CADET_LOCAL_CHANNEL_ID_SERV) 603 ntohl (chid.channel_of_client),
604 GNUNET_h2s (port_number));
605 if (ntohl (chid.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
590 { 606 {
591 GNUNET_break (0); 607 GNUNET_break (0);
592 return; 608 return;
@@ -636,18 +652,24 @@ handle_channel_destroy (void *cls,
636{ 652{
637 struct GNUNET_CADET_Handle *h = cls; 653 struct GNUNET_CADET_Handle *h = cls;
638 struct GNUNET_CADET_Channel *ch; 654 struct GNUNET_CADET_Channel *ch;
639 CADET_ChannelNumber chid; 655 struct GNUNET_CADET_ClientChannelNumber chid;
640 656
641 chid = ntohl (msg->channel_id); 657 chid = msg->channel_id;
642 LOG (GNUNET_ERROR_TYPE_DEBUG, "Channel %X Destroy from service\n", chid); 658 LOG (GNUNET_ERROR_TYPE_DEBUG,
643 ch = retrieve_channel (h, chid); 659 "Channel %X Destroy from service\n",
660 ntohl (chid.channel_of_client));
661 ch = retrieve_channel (h,
662 chid);
644 663
645 if (NULL == ch) 664 if (NULL == ch)
646 { 665 {
647 LOG (GNUNET_ERROR_TYPE_DEBUG, "channel %X unknown\n", chid); 666 LOG (GNUNET_ERROR_TYPE_DEBUG,
667 "channel %X unknown\n",
668 ntohl (chid.channel_of_client));
648 return; 669 return;
649 } 670 }
650 destroy_channel (ch, GNUNET_YES); 671 destroy_channel (ch,
672 GNUNET_YES);
651} 673}
652 674
653 675
@@ -674,7 +696,8 @@ check_local_data (void *cls,
674 return GNUNET_SYSERR; 696 return GNUNET_SYSERR;
675 } 697 }
676 698
677 ch = retrieve_channel (h, ntohl (message->id)); 699 ch = retrieve_channel (h,
700 message->id);
678 if (NULL == ch) 701 if (NULL == ch)
679 { 702 {
680 GNUNET_break_op (0); 703 GNUNET_break_op (0);
@@ -702,14 +725,17 @@ handle_local_data (void *cls,
702 unsigned int i; 725 unsigned int i;
703 uint16_t type; 726 uint16_t type;
704 727
705 LOG (GNUNET_ERROR_TYPE_DEBUG, "Got a data message!\n"); 728 LOG (GNUNET_ERROR_TYPE_DEBUG,
706 ch = retrieve_channel (h, ntohl (message->id)); 729 "Got a data message!\n");
730 ch = retrieve_channel (h, message->id);
707 GNUNET_assert (NULL != ch); 731 GNUNET_assert (NULL != ch);
708 732
709 payload = (struct GNUNET_MessageHeader *) &message[1]; 733 payload = (struct GNUNET_MessageHeader *) &message[1];
710 LOG (GNUNET_ERROR_TYPE_DEBUG, " %s data on channel %s [%X]\n", 734 LOG (GNUNET_ERROR_TYPE_DEBUG, " %s data on channel %s [%X]\n",
711 GC_f2s (ch->chid >= GNUNET_CADET_LOCAL_CHANNEL_ID_SERV), 735 GC_f2s (ntohl (ch->chid.channel_of_client) >=
712 GNUNET_i2s (GNUNET_PEER_resolve2 (ch->peer)), ntohl (message->id)); 736 GNUNET_CADET_LOCAL_CHANNEL_ID_CLI),
737 GNUNET_i2s (GNUNET_PEER_resolve2 (ch->peer)),
738 ntohl (message->id.channel_of_client));
713 739
714 type = ntohs (payload->type); 740 type = ntohs (payload->type);
715 LOG (GNUNET_ERROR_TYPE_DEBUG, " payload type %s\n", GC_m2s (type)); 741 LOG (GNUNET_ERROR_TYPE_DEBUG, " payload type %s\n", GC_m2s (type));
@@ -751,17 +777,21 @@ handle_local_ack (void *cls,
751{ 777{
752 struct GNUNET_CADET_Handle *h = cls; 778 struct GNUNET_CADET_Handle *h = cls;
753 struct GNUNET_CADET_Channel *ch; 779 struct GNUNET_CADET_Channel *ch;
754 CADET_ChannelNumber chid; 780 struct GNUNET_CADET_ClientChannelNumber chid;
755 781
756 LOG (GNUNET_ERROR_TYPE_DEBUG, "Got an ACK!\n"); 782 LOG (GNUNET_ERROR_TYPE_DEBUG, "Got an ACK!\n");
757 chid = ntohl (message->channel_id); 783 chid = message->channel_id;
758 ch = retrieve_channel (h, chid); 784 ch = retrieve_channel (h, chid);
759 if (NULL == ch) 785 if (NULL == ch)
760 { 786 {
761 LOG (GNUNET_ERROR_TYPE_DEBUG, "ACK on unknown channel %X\n", chid); 787 LOG (GNUNET_ERROR_TYPE_DEBUG,
788 "ACK on unknown channel %X\n",
789 ntohl (chid.channel_of_client));
762 return; 790 return;
763 } 791 }
764 LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X!\n", ch->chid); 792 LOG (GNUNET_ERROR_TYPE_DEBUG,
793 " on channel %X!\n",
794 ntohl (ch->chid.channel_of_client));
765 ch->allow_send = GNUNET_YES; 795 ch->allow_send = GNUNET_YES;
766 if (0 < ch->packet_size) 796 if (0 < ch->packet_size)
767 { 797 {
@@ -1132,9 +1162,12 @@ handle_get_tunnels (void *cls,
1132{ 1162{
1133 struct GNUNET_CADET_Handle *h = cls; 1163 struct GNUNET_CADET_Handle *h = cls;
1134 1164
1135 h->info_cb.tunnels_cb (h->info_cls, &msg->destination, 1165 h->info_cb.tunnels_cb (h->info_cls,
1136 ntohl (msg->channels), ntohl (msg->connections), 1166 &msg->destination,
1137 ntohs (msg->estate), ntohs (msg->cstate)); 1167 ntohl (msg->channels),
1168 ntohl (msg->connections),
1169 ntohs (msg->estate),
1170 ntohs (msg->cstate));
1138 1171
1139} 1172}
1140 1173
@@ -1170,13 +1203,14 @@ check_get_tunnel (void *cls,
1170 if (esize > msize) 1203 if (esize > msize)
1171 { 1204 {
1172 GNUNET_break_op (0); 1205 GNUNET_break_op (0);
1173 h->info_cb.tunnel_cb (h->info_cls, NULL, 0, 0, NULL, NULL, 0, 0); 1206 h->info_cb.tunnel_cb (h->info_cls,
1207 NULL, 0, 0, NULL, NULL, 0, 0);
1174 goto clean_cls; 1208 goto clean_cls;
1175 } 1209 }
1176 ch_n = ntohl (msg->channels); 1210 ch_n = ntohl (msg->channels);
1177 c_n = ntohl (msg->connections); 1211 c_n = ntohl (msg->connections);
1178 esize += ch_n * sizeof (CADET_ChannelNumber); 1212 esize += ch_n * sizeof (struct GNUNET_CADET_ChannelNumber);
1179 esize += c_n * sizeof (struct GNUNET_CADET_Hash); 1213 esize += c_n * sizeof (struct GNUNET_CADET_ConnectionTunnelIdentifier);
1180 if (msize != esize) 1214 if (msize != esize)
1181 { 1215 {
1182 GNUNET_break_op (0); 1216 GNUNET_break_op (0);
@@ -1186,7 +1220,8 @@ check_get_tunnel (void *cls,
1186 (unsigned int) esize, 1220 (unsigned int) esize,
1187 ch_n, 1221 ch_n,
1188 c_n); 1222 c_n);
1189 h->info_cb.tunnel_cb (h->info_cls, NULL, 0, 0, NULL, NULL, 0, 0); 1223 h->info_cb.tunnel_cb (h->info_cls,
1224 NULL, 0, 0, NULL, NULL, 0, 0);
1190 goto clean_cls; 1225 goto clean_cls;
1191 } 1226 }
1192 1227
@@ -1212,18 +1247,23 @@ handle_get_tunnel (void *cls,
1212 struct GNUNET_CADET_Handle *h = cls; 1247 struct GNUNET_CADET_Handle *h = cls;
1213 unsigned int ch_n; 1248 unsigned int ch_n;
1214 unsigned int c_n; 1249 unsigned int c_n;
1215 struct GNUNET_CADET_Hash *conns; 1250 const struct GNUNET_CADET_ConnectionTunnelIdentifier *conns;
1216 CADET_ChannelNumber *chns; 1251 const struct GNUNET_CADET_ChannelNumber *chns;
1217 1252
1218 ch_n = ntohl (msg->channels); 1253 ch_n = ntohl (msg->channels);
1219 c_n = ntohl (msg->connections); 1254 c_n = ntohl (msg->connections);
1220 1255
1221 /* Call Callback with tunnel info. */ 1256 /* Call Callback with tunnel info. */
1222 conns = (struct GNUNET_CADET_Hash *) &msg[1]; 1257 conns = (const struct GNUNET_CADET_ConnectionTunnelIdentifier *) &msg[1];
1223 chns = (CADET_ChannelNumber *) &conns[c_n]; 1258 chns = (const struct GNUNET_CADET_ChannelNumber *) &conns[c_n];
1224 h->info_cb.tunnel_cb (h->info_cls, &msg->destination, 1259 h->info_cb.tunnel_cb (h->info_cls,
1225 ch_n, c_n, chns, conns, 1260 &msg->destination,
1226 ntohs (msg->estate), ntohs (msg->cstate)); 1261 ch_n,
1262 c_n,
1263 chns,
1264 conns,
1265 ntohs (msg->estate),
1266 ntohs (msg->cstate));
1227} 1267}
1228 1268
1229 1269
@@ -1343,9 +1383,10 @@ reconnect (struct GNUNET_CADET_Handle *h)
1343/******************************************************************************/ 1383/******************************************************************************/
1344 1384
1345struct GNUNET_CADET_Handle * 1385struct GNUNET_CADET_Handle *
1346GNUNET_CADET_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, 1386GNUNET_CADET_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
1347 GNUNET_CADET_ChannelEndHandler cleaner, 1387 void *cls,
1348 const struct GNUNET_CADET_MessageHandler *handlers) 1388 GNUNET_CADET_ChannelEndHandler cleaner,
1389 const struct GNUNET_CADET_MessageHandler *handlers)
1349{ 1390{
1350 struct GNUNET_CADET_Handle *h; 1391 struct GNUNET_CADET_Handle *h;
1351 1392
@@ -1364,7 +1405,7 @@ GNUNET_CADET_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls,
1364 } 1405 }
1365 h->cls = cls; 1406 h->cls = cls;
1366 h->message_handlers = handlers; 1407 h->message_handlers = handlers;
1367 h->next_chid = GNUNET_CADET_LOCAL_CHANNEL_ID_CLI; 1408 h->next_chid.channel_of_client = htonl (GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
1368 h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS; 1409 h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS;
1369 h->reconnect_task = NULL; 1410 h->reconnect_task = NULL;
1370 1411
@@ -1384,21 +1425,24 @@ GNUNET_CADET_disconnect (struct GNUNET_CADET_Handle *handle)
1384 struct GNUNET_CADET_Channel *aux; 1425 struct GNUNET_CADET_Channel *aux;
1385 struct GNUNET_CADET_TransmitHandle *th; 1426 struct GNUNET_CADET_TransmitHandle *th;
1386 1427
1387 LOG (GNUNET_ERROR_TYPE_DEBUG, "CADET DISCONNECT\n"); 1428 LOG (GNUNET_ERROR_TYPE_DEBUG,
1388 1429 "CADET DISCONNECT\n");
1389 ch = handle->channels_head; 1430 ch = handle->channels_head;
1390 while (NULL != ch) 1431 while (NULL != ch)
1391 { 1432 {
1392 aux = ch->next; 1433 aux = ch->next;
1393 if (ch->chid < GNUNET_CADET_LOCAL_CHANNEL_ID_SERV) 1434 if (ntohl (ch->chid.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
1394 { 1435 {
1395 GNUNET_break (0); 1436 GNUNET_break (0);
1396 LOG (GNUNET_ERROR_TYPE_DEBUG, "channel %X not destroyed\n", ch->chid); 1437 LOG (GNUNET_ERROR_TYPE_DEBUG,
1438 "channel %X not destroyed\n",
1439 ntohl (ch->chid.channel_of_client));
1397 } 1440 }
1398 destroy_channel (ch, GNUNET_YES); 1441 destroy_channel (ch,
1442 GNUNET_YES);
1399 ch = aux; 1443 ch = aux;
1400 } 1444 }
1401 while ( (th = handle->th_head) != NULL) 1445 while (NULL != (th = handle->th_head))
1402 { 1446 {
1403 struct GNUNET_MessageHeader *msg; 1447 struct GNUNET_MessageHeader *msg;
1404 1448
@@ -1534,24 +1578,27 @@ GNUNET_CADET_channel_create (struct GNUNET_CADET_Handle *h,
1534 struct GNUNET_CADET_ChannelCreateMessage *msg; 1578 struct GNUNET_CADET_ChannelCreateMessage *msg;
1535 struct GNUNET_MQ_Envelope *env; 1579 struct GNUNET_MQ_Envelope *env;
1536 struct GNUNET_CADET_Channel *ch; 1580 struct GNUNET_CADET_Channel *ch;
1581 struct GNUNET_CADET_ClientChannelNumber chid;
1537 1582
1538 LOG (GNUNET_ERROR_TYPE_DEBUG, 1583 LOG (GNUNET_ERROR_TYPE_DEBUG,
1539 "Creating new channel to %s:%u\n", 1584 "Creating new channel to %s:%u\n",
1540 GNUNET_i2s (peer), port); 1585 GNUNET_i2s (peer), port);
1541 ch = create_channel (h, 0); 1586 chid.channel_of_client = htonl (0);
1587 ch = create_channel (h, chid);
1542 LOG (GNUNET_ERROR_TYPE_DEBUG, " at %p\n", ch); 1588 LOG (GNUNET_ERROR_TYPE_DEBUG, " at %p\n", ch);
1543 LOG (GNUNET_ERROR_TYPE_DEBUG, " number %X\n", ch->chid); 1589 LOG (GNUNET_ERROR_TYPE_DEBUG, " number %X\n",
1590 ntohl (ch->chid.channel_of_client));
1544 ch->ctx = channel_ctx; 1591 ch->ctx = channel_ctx;
1545 ch->peer = GNUNET_PEER_intern (peer); 1592 ch->peer = GNUNET_PEER_intern (peer);
1546 1593
1547 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE); 1594 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE);
1548 msg->channel_id = htonl (ch->chid); 1595 msg->channel_id = ch->chid;
1549 msg->port = *port; 1596 msg->port = *port;
1550 msg->peer = *peer; 1597 msg->peer = *peer;
1551 msg->opt = htonl (options); 1598 msg->opt = htonl (options);
1552 ch->allow_send = GNUNET_NO; 1599 ch->allow_send = GNUNET_NO;
1553 GNUNET_MQ_send (h->mq, env); 1600 GNUNET_MQ_send (h->mq,
1554 1601 env);
1555 return ch; 1602 return ch;
1556} 1603}
1557 1604
@@ -1590,7 +1637,7 @@ GNUNET_CADET_channel_destroy (struct GNUNET_CADET_Channel *channel)
1590 } 1637 }
1591 1638
1592 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY); 1639 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY);
1593 msg->channel_id = htonl (channel->chid); 1640 msg->channel_id = channel->chid;
1594 GNUNET_MQ_send (h->mq, env); 1641 GNUNET_MQ_send (h->mq, env);
1595 1642
1596 destroy_channel (channel, GNUNET_YES); 1643 destroy_channel (channel, GNUNET_YES);
@@ -1617,7 +1664,7 @@ GNUNET_CADET_channel_get_info (struct GNUNET_CADET_Channel *channel,
1617 { 1664 {
1618 case GNUNET_CADET_OPTION_NOBUFFER: 1665 case GNUNET_CADET_OPTION_NOBUFFER:
1619 case GNUNET_CADET_OPTION_RELIABLE: 1666 case GNUNET_CADET_OPTION_RELIABLE:
1620 case GNUNET_CADET_OPTION_OOORDER: 1667 case GNUNET_CADET_OPTION_OUT_OF_ORDER:
1621 if (0 != (option & channel->options)) 1668 if (0 != (option & channel->options))
1622 bool_flag = GNUNET_YES; 1669 bool_flag = GNUNET_YES;
1623 else 1670 else
@@ -1651,7 +1698,8 @@ GNUNET_CADET_notify_transmit_ready (struct GNUNET_CADET_Channel *channel,
1651 LOG (GNUNET_ERROR_TYPE_DEBUG, "CADET NOTIFY TRANSMIT READY\n"); 1698 LOG (GNUNET_ERROR_TYPE_DEBUG, "CADET NOTIFY TRANSMIT READY\n");
1652 LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X\n", channel->chid); 1699 LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X\n", channel->chid);
1653 LOG (GNUNET_ERROR_TYPE_DEBUG, " allow_send %d\n", channel->allow_send); 1700 LOG (GNUNET_ERROR_TYPE_DEBUG, " allow_send %d\n", channel->allow_send);
1654 if (channel->chid >= GNUNET_CADET_LOCAL_CHANNEL_ID_SERV) 1701 if (ntohl (channel->chid.channel_of_client) >=
1702 GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
1655 LOG (GNUNET_ERROR_TYPE_DEBUG, " to origin\n"); 1703 LOG (GNUNET_ERROR_TYPE_DEBUG, " to origin\n");
1656 else 1704 else
1657 LOG (GNUNET_ERROR_TYPE_DEBUG, " to destination\n"); 1705 LOG (GNUNET_ERROR_TYPE_DEBUG, " to destination\n");
@@ -1946,7 +1994,7 @@ GNUNET_CADET_show_channel (struct GNUNET_CADET_Handle *h,
1946 1994
1947 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL); 1995 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL);
1948 msg->peer = *initiator; 1996 msg->peer = *initiator;
1949 msg->channel_id = htonl (channel_number); 1997 msg->channel_id.channel_of_client = htonl (channel_number);
1950 GNUNET_MQ_send (h->mq, env); 1998 GNUNET_MQ_send (h->mq, env);
1951 1999
1952 h->info_cb.channel_cb = callback; 2000 h->info_cb.channel_cb = callback;
diff --git a/src/cadet/cadet_protocol.h b/src/cadet/cadet_protocol.h
index d034c63b0..c555d6155 100644
--- a/src/cadet/cadet_protocol.h
+++ b/src/cadet/cadet_protocol.h
@@ -70,7 +70,7 @@ struct GNUNET_CADET_ConnectionCreate
70 * For alignment. 70 * For alignment.
71 */ 71 */
72 uint32_t reserved GNUNET_PACKED; 72 uint32_t reserved GNUNET_PACKED;
73 73
74 /** 74 /**
75 * ID of the connection 75 * ID of the connection
76 */ 76 */
@@ -322,6 +322,7 @@ struct GNUNET_CADET_Encrypted
322/******************************* CHANNEL ***********************************/ 322/******************************* CHANNEL ***********************************/
323/******************************************************************************/ 323/******************************************************************************/
324 324
325
325/** 326/**
326 * Message to create a Channel. 327 * Message to create a Channel.
327 */ 328 */
@@ -345,7 +346,7 @@ struct GNUNET_CADET_ChannelCreate
345 /** 346 /**
346 * ID of the channel 347 * ID of the channel
347 */ 348 */
348 CADET_ChannelNumber chid GNUNET_PACKED; 349 struct GNUNET_CADET_ChannelNumber chid;
349}; 350};
350 351
351 352
@@ -362,7 +363,7 @@ struct GNUNET_CADET_ChannelManage
362 /** 363 /**
363 * ID of the channel 364 * ID of the channel
364 */ 365 */
365 CADET_ChannelNumber chid GNUNET_PACKED; 366 struct GNUNET_CADET_ChannelNumber chid;
366}; 367};
367 368
368 369
@@ -385,7 +386,7 @@ struct GNUNET_CADET_Data
385 /** 386 /**
386 * ID of the channel 387 * ID of the channel
387 */ 388 */
388 CADET_ChannelNumber chid GNUNET_PACKED; 389 struct GNUNET_CADET_ChannelNumber chid;
389 390
390 /** 391 /**
391 * Payload follows 392 * Payload follows
@@ -406,7 +407,7 @@ struct GNUNET_CADET_DataACK
406 /** 407 /**
407 * ID of the channel 408 * ID of the channel
408 */ 409 */
409 CADET_ChannelNumber chid GNUNET_PACKED; 410 struct GNUNET_CADET_ChannelNumber chid;
410 411
411 /** 412 /**
412 * Bitfield of already-received newer messages 413 * Bitfield of already-received newer messages
diff --git a/src/cadet/gnunet-cadet.c b/src/cadet/gnunet-cadet.c
index 5afb64e24..eeef2ff89 100644
--- a/src/cadet/gnunet-cadet.c
+++ b/src/cadet/gnunet-cadet.c
@@ -727,8 +727,8 @@ tunnel_callback (void *cls,
727 const struct GNUNET_PeerIdentity *peer, 727 const struct GNUNET_PeerIdentity *peer,
728 unsigned int n_channels, 728 unsigned int n_channels,
729 unsigned int n_connections, 729 unsigned int n_connections,
730 uint32_t *channels, 730 const struct GNUNET_CADET_ChannelNumber *channels,
731 struct GNUNET_CADET_Hash *connections, 731 const struct GNUNET_CADET_ConnectionTunnelIdentifier *connections,
732 unsigned int estate, 732 unsigned int estate,
733 unsigned int cstate) 733 unsigned int cstate)
734{ 734{
@@ -739,10 +739,10 @@ tunnel_callback (void *cls,
739 FPRINTF (stdout, "Tunnel %s\n", GNUNET_i2s_full (peer)); 739 FPRINTF (stdout, "Tunnel %s\n", GNUNET_i2s_full (peer));
740 FPRINTF (stdout, "\t%u channels\n", n_channels); 740 FPRINTF (stdout, "\t%u channels\n", n_channels);
741 for (i = 0; i < n_channels; i++) 741 for (i = 0; i < n_channels; i++)
742 FPRINTF (stdout, "\t\t%X\n", ntohl (channels[i])); 742 FPRINTF (stdout, "\t\t%X\n", ntohl (channels[i].cn));
743 FPRINTF (stdout, "\t%u connections\n", n_connections); 743 FPRINTF (stdout, "\t%u connections\n", n_connections);
744 for (i = 0; i < n_connections; i++) 744 for (i = 0; i < n_connections; i++)
745 FPRINTF (stdout, "\t\t%s\n", GC_h2s (&connections[i])); 745 FPRINTF (stdout, "\t\t%s\n", GC_h2s (&connections[i].connection_of_tunnel));
746 FPRINTF (stdout, "\tencryption state: %s\n", enc_2s (estate)); 746 FPRINTF (stdout, "\tencryption state: %s\n", enc_2s (estate));
747 FPRINTF (stdout, "\tconnection state: %s\n", conn_2s (cstate)); 747 FPRINTF (stdout, "\tconnection state: %s\n", conn_2s (cstate));
748 } 748 }
@@ -827,7 +827,10 @@ show_tunnel (void *cls)
827 GNUNET_SCHEDULER_shutdown (); 827 GNUNET_SCHEDULER_shutdown ();
828 return; 828 return;
829 } 829 }
830 GNUNET_CADET_get_tunnel (mh, &pid, tunnel_callback, NULL); 830 GNUNET_CADET_get_tunnel (mh,
831 &pid,
832 &tunnel_callback,
833 NULL);
831} 834}
832 835
833 836
diff --git a/src/cadet/gnunet-service-cadet_channel.c b/src/cadet/gnunet-service-cadet_channel.c
index d2d176e83..6bc3dc590 100644
--- a/src/cadet/gnunet-service-cadet_channel.c
+++ b/src/cadet/gnunet-service-cadet_channel.c
@@ -58,7 +58,7 @@ enum CadetChannelState
58 /** 58 /**
59 * Connection confirmed, ready to carry traffic. 59 * Connection confirmed, ready to carry traffic.
60 */ 60 */
61 CADET_CHANNEL_READY, 61 CADET_CHANNEL_READY
62}; 62};
63 63
64 64
@@ -216,19 +216,19 @@ struct CadetChannel
216 /** 216 /**
217 * Global channel number ( < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) 217 * Global channel number ( < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
218 */ 218 */
219 CADET_ChannelNumber gid; 219 struct GNUNET_CADET_ChannelNumber gid;
220 220
221 /** 221 /**
222 * Local tunnel number for root (owner) client. 222 * Local tunnel number for root (owner) client.
223 * ( >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI or 0 ) 223 * ( >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI or 0 )
224 */ 224 */
225 CADET_ChannelNumber lid_root; 225 struct GNUNET_CADET_ClientChannelNumber lid_root;
226 226
227 /** 227 /**
228 * Local tunnel number for local destination clients (incoming number) 228 * Local tunnel number for local destination clients (incoming number)
229 * ( >= GNUNET_CADET_LOCAL_CHANNEL_ID_SERV or 0). 229 * ( >= GNUNET_CADET_LOCAL_CHANNEL_ID_SERV or 0).
230 */ 230 */
231 CADET_ChannelNumber lid_dest; 231 struct GNUNET_CADET_ClientChannelNumber lid_dest;
232 232
233 /** 233 /**
234 * Channel state. 234 * Channel state.
@@ -517,7 +517,7 @@ send_destroy (struct CadetChannel *ch, int local_only)
517 517
518 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY); 518 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY);
519 msg.header.size = htons (sizeof (msg)); 519 msg.header.size = htons (sizeof (msg));
520 msg.chid = htonl (ch->gid); 520 msg.chid = ch->gid;
521 521
522 /* If root is not NULL, notify. 522 /* If root is not NULL, notify.
523 * If it's NULL, check lid_root. When a local destroy comes in, root 523 * If it's NULL, check lid_root. When a local destroy comes in, root
@@ -526,12 +526,12 @@ send_destroy (struct CadetChannel *ch, int local_only)
526 */ 526 */
527 if (NULL != ch->root) 527 if (NULL != ch->root)
528 GML_send_channel_destroy (ch->root, ch->lid_root); 528 GML_send_channel_destroy (ch->root, ch->lid_root);
529 else if (0 == ch->lid_root && GNUNET_NO == local_only) 529 else if (0 == ch->lid_root.channel_of_client && GNUNET_NO == local_only)
530 GCCH_send_prebuilt_message (&msg.header, ch, GNUNET_NO, NULL); 530 GCCH_send_prebuilt_message (&msg.header, ch, GNUNET_NO, NULL);
531 531
532 if (NULL != ch->dest) 532 if (NULL != ch->dest)
533 GML_send_channel_destroy (ch->dest, ch->lid_dest); 533 GML_send_channel_destroy (ch->dest, ch->lid_dest);
534 else if (0 == ch->lid_dest && GNUNET_NO == local_only) 534 else if (0 == ch->lid_dest.channel_of_client && GNUNET_NO == local_only)
535 GCCH_send_prebuilt_message (&msg.header, ch, GNUNET_YES, NULL); 535 GCCH_send_prebuilt_message (&msg.header, ch, GNUNET_YES, NULL);
536} 536}
537 537
@@ -552,7 +552,10 @@ send_client_create (struct CadetChannel *ch)
552 opt = 0; 552 opt = 0;
553 opt |= GNUNET_YES == ch->reliable ? GNUNET_CADET_OPTION_RELIABLE : 0; 553 opt |= GNUNET_YES == ch->reliable ? GNUNET_CADET_OPTION_RELIABLE : 0;
554 opt |= GNUNET_YES == ch->nobuffer ? GNUNET_CADET_OPTION_NOBUFFER : 0; 554 opt |= GNUNET_YES == ch->nobuffer ? GNUNET_CADET_OPTION_NOBUFFER : 0;
555 GML_send_channel_create (ch->dest, ch->lid_dest, &ch->port, opt, 555 GML_send_channel_create (ch->dest,
556 ch->lid_dest,
557 &ch->port,
558 opt,
556 GCT_get_destination (ch->t)); 559 GCT_get_destination (ch->t));
557 560
558} 561}
@@ -883,7 +886,7 @@ send_create (struct CadetChannel *ch)
883 886
884 msgcc.header.size = htons (sizeof (msgcc)); 887 msgcc.header.size = htons (sizeof (msgcc));
885 msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE); 888 msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE);
886 msgcc.chid = htonl (ch->gid); 889 msgcc.chid = ch->gid;
887 msgcc.port = ch->port; 890 msgcc.port = ch->port;
888 msgcc.opt = htonl (channel_get_options (ch)); 891 msgcc.opt = htonl (channel_get_options (ch));
889 892
@@ -904,10 +907,11 @@ send_ack (struct CadetChannel *ch, int fwd)
904 907
905 msg.header.size = htons (sizeof (msg)); 908 msg.header.size = htons (sizeof (msg));
906 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_ACK); 909 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_ACK);
907 LOG (GNUNET_ERROR_TYPE_DEBUG, " sending channel %s ack for channel %s\n", 910 LOG (GNUNET_ERROR_TYPE_DEBUG,
911 " sending channel %s ack for channel %s\n",
908 GC_f2s (fwd), GCCH_2s (ch)); 912 GC_f2s (fwd), GCCH_2s (ch));
909 913
910 msg.chid = htonl (ch->gid); 914 msg.chid =ch->gid;
911 GCCH_send_prebuilt_message (&msg.header, ch, !fwd, NULL); 915 GCCH_send_prebuilt_message (&msg.header, ch, !fwd, NULL);
912} 916}
913 917
@@ -925,8 +929,9 @@ fire_and_forget (const struct GNUNET_MessageHeader *msg,
925 struct CadetChannel *ch, 929 struct CadetChannel *ch,
926 int force) 930 int force)
927{ 931{
928 GNUNET_break (NULL == GCT_send_prebuilt_message (msg, ch->t, NULL, 932 GNUNET_break (NULL ==
929 force, NULL, NULL)); 933 GCT_send_prebuilt_message (msg, ch->t, NULL,
934 force, NULL, NULL));
930} 935}
931 936
932 937
@@ -946,7 +951,7 @@ send_nack (struct CadetChannel *ch)
946 " sending channel NACK for channel %s\n", 951 " sending channel NACK for channel %s\n",
947 GCCH_2s (ch)); 952 GCCH_2s (ch));
948 953
949 msg.chid = htonl (ch->gid); 954 msg.chid = ch->gid;
950 GCCH_send_prebuilt_message (&msg.header, ch, GNUNET_NO, NULL); 955 GCCH_send_prebuilt_message (&msg.header, ch, GNUNET_NO, NULL);
951} 956}
952 957
@@ -1252,7 +1257,7 @@ channel_save_copy (struct CadetChannel *ch,
1252static struct CadetChannel * 1257static struct CadetChannel *
1253channel_new (struct CadetTunnel *t, 1258channel_new (struct CadetTunnel *t,
1254 struct CadetClient *owner, 1259 struct CadetClient *owner,
1255 CADET_ChannelNumber lid_root) 1260 struct GNUNET_CADET_ClientChannelNumber lid_root)
1256{ 1261{
1257 struct CadetChannel *ch; 1262 struct CadetChannel *ch;
1258 1263
@@ -1393,7 +1398,7 @@ GCCH_destroy (struct CadetChannel *ch)
1393 * 1398 *
1394 * @return ID used to identify the channel with the remote peer. 1399 * @return ID used to identify the channel with the remote peer.
1395 */ 1400 */
1396CADET_ChannelNumber 1401struct GNUNET_CADET_ChannelNumber
1397GCCH_get_id (const struct CadetChannel *ch) 1402GCCH_get_id (const struct CadetChannel *ch)
1398{ 1403{
1399 return ch->gid; 1404 return ch->gid;
@@ -1533,7 +1538,7 @@ GCCH_send_data_ack (struct CadetChannel *ch, int fwd)
1533 1538
1534 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_DATA_ACK); 1539 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_DATA_ACK);
1535 msg.header.size = htons (sizeof (msg)); 1540 msg.header.size = htons (sizeof (msg));
1536 msg.chid = htonl (ch->gid); 1541 msg.chid = ch->gid;
1537 msg.mid = htonl (ack); 1542 msg.mid = htonl (ack);
1538 1543
1539 msg.futures = 0LL; 1544 msg.futures = 0LL;
@@ -1657,7 +1662,7 @@ GCCH_debug (struct CadetChannel *ch, enum GNUNET_ErrorType level)
1657 { 1662 {
1658 LOG2 (level, "CHN cli %s\n", GML_2s (ch->root)); 1663 LOG2 (level, "CHN cli %s\n", GML_2s (ch->root));
1659 LOG2 (level, "CHN ready %s\n", ch->root_rel->client_ready ? "YES" : "NO"); 1664 LOG2 (level, "CHN ready %s\n", ch->root_rel->client_ready ? "YES" : "NO");
1660 LOG2 (level, "CHN id %X\n", ch->lid_root); 1665 LOG2 (level, "CHN id %X\n", ch->lid_root.channel_of_client);
1661 LOG2 (level, "CHN recv %d\n", ch->root_rel->n_recv); 1666 LOG2 (level, "CHN recv %d\n", ch->root_rel->n_recv);
1662 LOG2 (level, "CHN MID r: %d, s: %d\n", 1667 LOG2 (level, "CHN MID r: %d, s: %d\n",
1663 ch->root_rel->mid_recv, ch->root_rel->mid_send); 1668 ch->root_rel->mid_recv, ch->root_rel->mid_send);
@@ -1733,11 +1738,12 @@ GCCH_handle_local_ack (struct CadetChannel *ch, int fwd)
1733 * @param message Data message. 1738 * @param message Data message.
1734 * @param size Size of data. 1739 * @param size Size of data.
1735 * 1740 *
1736 * @return GNUNET_OK if everything goes well, GNUNET_SYSERR in case of en error. 1741 * @return #GNUNET_OK if everything goes well, #GNUNET_SYSERR in case of en error.
1737 */ 1742 */
1738int 1743int
1739GCCH_handle_local_data (struct CadetChannel *ch, 1744GCCH_handle_local_data (struct CadetChannel *ch,
1740 struct CadetClient *c, int fwd, 1745 struct CadetClient *c,
1746 int fwd,
1741 const struct GNUNET_MessageHeader *message, 1747 const struct GNUNET_MessageHeader *message,
1742 size_t size) 1748 size_t size)
1743{ 1749{
@@ -1775,7 +1781,7 @@ GCCH_handle_local_data (struct CadetChannel *ch,
1775 GNUNET_memcpy (&payload[1], message, size); 1781 GNUNET_memcpy (&payload[1], message, size);
1776 payload->header.size = htons (p2p_size); 1782 payload->header.size = htons (p2p_size);
1777 payload->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_DATA); 1783 payload->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_DATA);
1778 payload->chid = htonl (ch->gid); 1784 payload->chid = ch->gid;
1779 LOG (GNUNET_ERROR_TYPE_DEBUG, " sending on channel...\n"); 1785 LOG (GNUNET_ERROR_TYPE_DEBUG, " sending on channel...\n");
1780 GCCH_send_prebuilt_message (&payload->header, ch, fwd, NULL); 1786 GCCH_send_prebuilt_message (&payload->header, ch, fwd, NULL);
1781 1787
@@ -1845,11 +1851,11 @@ GCCH_handle_local_create (struct CadetClient *c,
1845 struct CadetChannel *ch; 1851 struct CadetChannel *ch;
1846 struct CadetTunnel *t; 1852 struct CadetTunnel *t;
1847 struct CadetPeer *peer; 1853 struct CadetPeer *peer;
1848 CADET_ChannelNumber chid; 1854 struct GNUNET_CADET_ClientChannelNumber chid;
1849 1855
1850 LOG (GNUNET_ERROR_TYPE_DEBUG, " towards %s:%u\n", 1856 LOG (GNUNET_ERROR_TYPE_DEBUG, " towards %s:%u\n",
1851 GNUNET_i2s (&msg->peer), GNUNET_h2s (&msg->port)); 1857 GNUNET_i2s (&msg->peer), GNUNET_h2s (&msg->port));
1852 chid = ntohl (msg->channel_id); 1858 chid = msg->channel_id;
1853 1859
1854 /* Sanity check for duplicate channel IDs */ 1860 /* Sanity check for duplicate channel IDs */
1855 if (NULL != GML_channel_get (c, chid)) 1861 if (NULL != GML_channel_get (c, chid))
@@ -2147,20 +2153,21 @@ struct CadetChannel *
2147GCCH_handle_create (struct CadetTunnel *t, 2153GCCH_handle_create (struct CadetTunnel *t,
2148 const struct GNUNET_CADET_ChannelCreate *msg) 2154 const struct GNUNET_CADET_ChannelCreate *msg)
2149{ 2155{
2150 CADET_ChannelNumber chid; 2156 struct GNUNET_CADET_ClientChannelNumber chid;
2157 struct GNUNET_CADET_ChannelNumber gid;
2151 struct CadetChannel *ch; 2158 struct CadetChannel *ch;
2152 struct CadetClient *c; 2159 struct CadetClient *c;
2153 int new_channel; 2160 int new_channel;
2154 const struct GNUNET_HashCode *port; 2161 const struct GNUNET_HashCode *port;
2155 2162
2156 chid = ntohl (msg->chid); 2163 gid = msg->chid;
2157 2164 ch = GCT_get_channel (t, gid);
2158 ch = GCT_get_channel (t, chid);
2159 if (NULL == ch) 2165 if (NULL == ch)
2160 { 2166 {
2161 /* Create channel */ 2167 /* Create channel */
2162 ch = channel_new (t, NULL, 0); 2168 chid.channel_of_client = htonl (0);
2163 ch->gid = chid; 2169 ch = channel_new (t, NULL, chid);
2170 ch->gid = gid;
2164 channel_set_options (ch, ntohl (msg->opt)); 2171 channel_set_options (ch, ntohl (msg->opt));
2165 new_channel = GNUNET_YES; 2172 new_channel = GNUNET_YES;
2166 } 2173 }
@@ -2403,7 +2410,7 @@ GCCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
2403 { 2410 {
2404 struct GNUNET_CADET_ChannelCreate *cc_msg; 2411 struct GNUNET_CADET_ChannelCreate *cc_msg;
2405 cc_msg = (struct GNUNET_CADET_ChannelCreate *) message; 2412 cc_msg = (struct GNUNET_CADET_ChannelCreate *) message;
2406 SPRINTF (info, " 0x%08X", ntohl (cc_msg->chid)); 2413 SPRINTF (info, " 0x%08X", ntohl (cc_msg->chid.cn));
2407 break; 2414 break;
2408 } 2415 }
2409 case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_ACK: 2416 case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_ACK:
@@ -2412,7 +2419,7 @@ GCCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
2412 { 2419 {
2413 struct GNUNET_CADET_ChannelManage *m_msg; 2420 struct GNUNET_CADET_ChannelManage *m_msg;
2414 m_msg = (struct GNUNET_CADET_ChannelManage *) message; 2421 m_msg = (struct GNUNET_CADET_ChannelManage *) message;
2415 SPRINTF (info, " 0x%08X", ntohl (m_msg->chid)); 2422 SPRINTF (info, " 0x%08X", ntohl (m_msg->chid.cn));
2416 break; 2423 break;
2417 } 2424 }
2418 default: 2425 default:
@@ -2542,9 +2549,13 @@ GCCH_2s (const struct CadetChannel *ch)
2542 if (NULL == ch) 2549 if (NULL == ch)
2543 return "(NULL Channel)"; 2550 return "(NULL Channel)";
2544 2551
2545 SPRINTF (buf, "%s:%s gid:%X (%X / %X)", 2552 SPRINTF (buf,
2546 GCT_2s (ch->t), GNUNET_h2s (&ch->port), 2553 "%s:%s gid:%X (%X / %X)",
2547 ch->gid, ch->lid_root, ch->lid_dest); 2554 GCT_2s (ch->t),
2555 GNUNET_h2s (&ch->port),
2556 ntohl (ch->gid.cn),
2557 ntohl (ch->lid_root.channel_of_client),
2558 ntohl (ch->lid_dest.channel_of_client));
2548 2559
2549 return buf; 2560 return buf;
2550} 2561}
diff --git a/src/cadet/gnunet-service-cadet_channel.h b/src/cadet/gnunet-service-cadet_channel.h
index eeea02712..8faad2e86 100644
--- a/src/cadet/gnunet-service-cadet_channel.h
+++ b/src/cadet/gnunet-service-cadet_channel.h
@@ -69,7 +69,7 @@ GCCH_destroy (struct CadetChannel *ch);
69 * 69 *
70 * @return ID used to identify the channel with the remote peer. 70 * @return ID used to identify the channel with the remote peer.
71 */ 71 */
72CADET_ChannelNumber 72struct GNUNET_CADET_ChannelNumber
73GCCH_get_id (const struct CadetChannel *ch); 73GCCH_get_id (const struct CadetChannel *ch);
74 74
75/** 75/**
@@ -347,6 +347,8 @@ const char *
347GCCH_2s (const struct CadetChannel *ch); 347GCCH_2s (const struct CadetChannel *ch);
348 348
349 349
350
351
350#if 0 /* keep Emacsens' auto-indent happy */ 352#if 0 /* keep Emacsens' auto-indent happy */
351{ 353{
352#endif 354#endif
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c
index 343e372b2..e727ef199 100644
--- a/src/cadet/gnunet-service-cadet_connection.c
+++ b/src/cadet/gnunet-service-cadet_connection.c
@@ -2464,7 +2464,7 @@ check_message (const struct GNUNET_MessageHeader *message,
2464 if (GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED == type) 2464 if (GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED == type)
2465 { 2465 {
2466 fc = fwd ? &c->bck_fc : &c->fwd_fc; 2466 fc = fwd ? &c->bck_fc : &c->fwd_fc;
2467 LOG (GNUNET_ERROR_TYPE_DEBUG, " PID %u (expected %u - %u)\n", 2467 LOG (GNUNET_ERROR_TYPE_DEBUG, " PID %u (expected in interval [%u,%u])\n",
2468 pid, 2468 pid,
2469 fc->last_pid_recv + 1, 2469 fc->last_pid_recv + 1,
2470 fc->last_ack_sent); 2470 fc->last_ack_sent);
diff --git a/src/cadet/gnunet-service-cadet_dht.c b/src/cadet/gnunet-service-cadet_dht.c
index 43b1c8252..22673b167 100644
--- a/src/cadet/gnunet-service-cadet_dht.c
+++ b/src/cadet/gnunet-service-cadet_dht.c
@@ -42,16 +42,24 @@
42 */ 42 */
43struct GCD_search_handle 43struct GCD_search_handle
44{ 44{
45 /** DHT_GET handle. */ 45 /**
46 * DHT_GET handle.
47 */
46 struct GNUNET_DHT_GetHandle *dhtget; 48 struct GNUNET_DHT_GetHandle *dhtget;
47 49
48 /** Provided callback to call when a path is found. */ 50 /**
51 * Provided callback to call when a path is found.
52 */
49 GCD_search_callback callback; 53 GCD_search_callback callback;
50 54
51 /** Provided closure. */ 55 /**
56 * Provided closure.
57 */
52 void *cls; 58 void *cls;
53 59
54 /** Peer ID searched for */ 60 /**
61 * Peer ID searched for
62 */
55 GNUNET_PEER_Id peer_id; 63 GNUNET_PEER_Id peer_id;
56}; 64};
57 65
diff --git a/src/cadet/gnunet-service-cadet_hello.h b/src/cadet/gnunet-service-cadet_hello.h
index 5f535b496..34121e1e0 100644
--- a/src/cadet/gnunet-service-cadet_hello.h
+++ b/src/cadet/gnunet-service-cadet_hello.h
@@ -50,11 +50,13 @@ extern "C"
50void 50void
51GCH_init (const struct GNUNET_CONFIGURATION_Handle *c); 51GCH_init (const struct GNUNET_CONFIGURATION_Handle *c);
52 52
53
53/** 54/**
54 * Shut down the hello subsystem. 55 * Shut down the hello subsystem.
55 */ 56 */
56void 57void
57GCH_shutdown (); 58GCH_shutdown (void);
59
58 60
59/** 61/**
60 * Get own hello message. 62 * Get own hello message.
@@ -64,6 +66,7 @@ GCH_shutdown ();
64const struct GNUNET_HELLO_Message * 66const struct GNUNET_HELLO_Message *
65GCH_get_mine (void); 67GCH_get_mine (void);
66 68
69
67#if 0 /* keep Emacsens' auto-indent happy */ 70#if 0 /* keep Emacsens' auto-indent happy */
68{ 71{
69#endif 72#endif
diff --git a/src/cadet/gnunet-service-cadet_local.c b/src/cadet/gnunet-service-cadet_local.c
index 9be1224c1..743fbf054 100644
--- a/src/cadet/gnunet-service-cadet_local.c
+++ b/src/cadet/gnunet-service-cadet_local.c
@@ -61,7 +61,7 @@ struct CadetClient
61 * Tunnels that belong to this client, indexed by local id 61 * Tunnels that belong to this client, indexed by local id
62 */ 62 */
63 struct GNUNET_CONTAINER_MultiHashMap32 *own_channels; 63 struct GNUNET_CONTAINER_MultiHashMap32 *own_channels;
64 64
65 /** 65 /**
66 * Tunnels this client has accepted, indexed by incoming local id 66 * Tunnels this client has accepted, indexed by incoming local id
67 */ 67 */
@@ -70,7 +70,7 @@ struct CadetClient
70 /** 70 /**
71 * Channel ID for the next incoming channel. 71 * Channel ID for the next incoming channel.
72 */ 72 */
73 CADET_ChannelNumber next_chid; 73 struct GNUNET_CADET_ClientChannelNumber next_chid;
74 74
75 /** 75 /**
76 * Handle to communicate with the client 76 * Handle to communicate with the client
@@ -188,7 +188,9 @@ channel_destroy_iterator (void *cls,
188 " Channel %s destroy, due to client %s shutdown.\n", 188 " Channel %s destroy, due to client %s shutdown.\n",
189 GCCH_2s (ch), GML_2s (c)); 189 GCCH_2s (ch), GML_2s (c));
190 190
191 GCCH_handle_local_destroy (ch, c, key < GNUNET_CADET_LOCAL_CHANNEL_ID_SERV); 191 GCCH_handle_local_destroy (ch,
192 c,
193 key < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
192 return GNUNET_OK; 194 return GNUNET_OK;
193} 195}
194 196
@@ -247,7 +249,6 @@ client_new (struct GNUNET_SERVER_Client *client)
247 c = GNUNET_new (struct CadetClient); 249 c = GNUNET_new (struct CadetClient);
248 c->handle = client; 250 c->handle = client;
249 c->id = next_client_id++; /* overflow not important: just for debug */ 251 c->id = next_client_id++; /* overflow not important: just for debug */
250 c->next_chid = GNUNET_CADET_LOCAL_CHANNEL_ID_SERV;
251 252
252 c->own_channels = GNUNET_CONTAINER_multihashmap32_create (32); 253 c->own_channels = GNUNET_CONTAINER_multihashmap32_create (32);
253 c->incoming_channels = GNUNET_CONTAINER_multihashmap32_create (32); 254 c->incoming_channels = GNUNET_CONTAINER_multihashmap32_create (32);
@@ -474,7 +475,7 @@ handle_channel_destroy (void *cls, struct GNUNET_SERVER_Client *client,
474 struct GNUNET_CADET_ChannelDestroyMessage *msg; 475 struct GNUNET_CADET_ChannelDestroyMessage *msg;
475 struct CadetClient *c; 476 struct CadetClient *c;
476 struct CadetChannel *ch; 477 struct CadetChannel *ch;
477 CADET_ChannelNumber chid; 478 struct GNUNET_CADET_ClientChannelNumber chid;
478 479
479 LOG (GNUNET_ERROR_TYPE_DEBUG, "Got a DESTROY CHANNEL from client!\n"); 480 LOG (GNUNET_ERROR_TYPE_DEBUG, "Got a DESTROY CHANNEL from client!\n");
480 481
@@ -499,7 +500,7 @@ handle_channel_destroy (void *cls, struct GNUNET_SERVER_Client *client,
499 msg = (struct GNUNET_CADET_ChannelDestroyMessage *) message; 500 msg = (struct GNUNET_CADET_ChannelDestroyMessage *) message;
500 501
501 /* Retrieve tunnel */ 502 /* Retrieve tunnel */
502 chid = ntohl (msg->channel_id); 503 chid = msg->channel_id;
503 ch = GML_channel_get (c, chid); 504 ch = GML_channel_get (c, chid);
504 505
505 LOG (GNUNET_ERROR_TYPE_INFO, "Client %u is destroying channel %X\n", 506 LOG (GNUNET_ERROR_TYPE_INFO, "Client %u is destroying channel %X\n",
@@ -515,7 +516,9 @@ handle_channel_destroy (void *cls, struct GNUNET_SERVER_Client *client,
515 return; 516 return;
516 } 517 }
517 518
518 GCCH_handle_local_destroy (ch, c, chid < GNUNET_CADET_LOCAL_CHANNEL_ID_SERV); 519 GCCH_handle_local_destroy (ch,
520 c,
521 ntohl (chid.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
519 522
520 GNUNET_SERVER_receive_done (client, GNUNET_OK); 523 GNUNET_SERVER_receive_done (client, GNUNET_OK);
521 return; 524 return;
@@ -537,7 +540,7 @@ handle_data (void *cls, struct GNUNET_SERVER_Client *client,
537 struct GNUNET_CADET_LocalData *msg; 540 struct GNUNET_CADET_LocalData *msg;
538 struct CadetClient *c; 541 struct CadetClient *c;
539 struct CadetChannel *ch; 542 struct CadetChannel *ch;
540 CADET_ChannelNumber chid; 543 struct GNUNET_CADET_ClientChannelNumber chid;
541 size_t message_size; 544 size_t message_size;
542 size_t payload_size; 545 size_t payload_size;
543 size_t payload_claimed_size; 546 size_t payload_claimed_size;
@@ -583,12 +586,12 @@ handle_data (void *cls, struct GNUNET_SERVER_Client *client,
583 return; 586 return;
584 } 587 }
585 588
586 chid = ntohl (msg->id); 589 chid = msg->id;
587 LOG (GNUNET_ERROR_TYPE_DEBUG, " %u bytes (%u payload) by client %u\n", 590 LOG (GNUNET_ERROR_TYPE_DEBUG, " %u bytes (%u payload) by client %u\n",
588 payload_size, payload_claimed_size, c->id); 591 payload_size, payload_claimed_size, c->id);
589 592
590 /* Channel exists? */ 593 /* Channel exists? */
591 fwd = chid < GNUNET_CADET_LOCAL_CHANNEL_ID_SERV; 594 fwd = ntohl (chid.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI;
592 ch = GML_channel_get (c, chid); 595 ch = GML_channel_get (c, chid);
593 if (NULL == ch) 596 if (NULL == ch)
594 { 597 {
@@ -626,7 +629,7 @@ handle_ack (void *cls, struct GNUNET_SERVER_Client *client,
626 struct GNUNET_CADET_LocalAck *msg; 629 struct GNUNET_CADET_LocalAck *msg;
627 struct CadetChannel *ch; 630 struct CadetChannel *ch;
628 struct CadetClient *c; 631 struct CadetClient *c;
629 CADET_ChannelNumber chid; 632 struct GNUNET_CADET_ClientChannelNumber chid;
630 int fwd; 633 int fwd;
631 634
632 LOG (GNUNET_ERROR_TYPE_DEBUG, "\n"); 635 LOG (GNUNET_ERROR_TYPE_DEBUG, "\n");
@@ -644,13 +647,16 @@ handle_ack (void *cls, struct GNUNET_SERVER_Client *client,
644 msg = (struct GNUNET_CADET_LocalAck *) message; 647 msg = (struct GNUNET_CADET_LocalAck *) message;
645 648
646 /* Channel exists? */ 649 /* Channel exists? */
647 chid = ntohl (msg->channel_id); 650 chid = msg->channel_id;
648 LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X\n", chid); 651 LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X\n",
652 ntohl (chid.channel_of_client));
649 ch = GML_channel_get (c, chid); 653 ch = GML_channel_get (c, chid);
650 LOG (GNUNET_ERROR_TYPE_DEBUG, " -- ch %p\n", ch); 654 LOG (GNUNET_ERROR_TYPE_DEBUG, " -- ch %p\n", ch);
651 if (NULL == ch) 655 if (NULL == ch)
652 { 656 {
653 LOG (GNUNET_ERROR_TYPE_DEBUG, "Channel %X unknown.\n", chid); 657 LOG (GNUNET_ERROR_TYPE_DEBUG,
658 "Channel %X unknown.\n",
659 ntohl (chid.channel_of_client));
654 LOG (GNUNET_ERROR_TYPE_DEBUG, " for client %u.\n", c->id); 660 LOG (GNUNET_ERROR_TYPE_DEBUG, " for client %u.\n", c->id);
655 GNUNET_STATISTICS_update (stats, 661 GNUNET_STATISTICS_update (stats,
656 "# client ack messages on unknown channel", 662 "# client ack messages on unknown channel",
@@ -661,12 +667,10 @@ handle_ack (void *cls, struct GNUNET_SERVER_Client *client,
661 667
662 /* If client is root, the ACK is going FWD, therefore this is "BCK ACK". */ 668 /* If client is root, the ACK is going FWD, therefore this is "BCK ACK". */
663 /* If client is dest, the ACK is going BCK, therefore this is "FWD ACK" */ 669 /* If client is dest, the ACK is going BCK, therefore this is "FWD ACK" */
664 fwd = chid >= GNUNET_CADET_LOCAL_CHANNEL_ID_SERV; 670 fwd = ntohl (chid.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI;
665 671
666 GCCH_handle_local_ack (ch, fwd); 672 GCCH_handle_local_ack (ch, fwd);
667 GNUNET_SERVER_receive_done (client, GNUNET_OK); 673 GNUNET_SERVER_receive_done (client, GNUNET_OK);
668
669 return;
670} 674}
671 675
672 676
@@ -972,9 +976,9 @@ iter_channel (void *cls, struct CadetChannel *ch)
972{ 976{
973 struct GNUNET_CADET_LocalInfoTunnel *msg = cls; 977 struct GNUNET_CADET_LocalInfoTunnel *msg = cls;
974 struct GNUNET_CADET_Hash *h = (struct GNUNET_CADET_Hash *) &msg[1]; 978 struct GNUNET_CADET_Hash *h = (struct GNUNET_CADET_Hash *) &msg[1];
975 CADET_ChannelNumber *chn = (CADET_ChannelNumber *) &h[msg->connections]; 979 struct GNUNET_CADET_ChannelNumber *chn = (struct GNUNET_CADET_ChannelNumber *) &h[msg->connections];
976 980
977 chn[msg->channels] = htonl (GCCH_get_id (ch)); 981 chn[msg->channels] = GCCH_get_id (ch);
978 msg->channels++; 982 msg->channels++;
979} 983}
980 984
@@ -1040,7 +1044,7 @@ handle_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client,
1040 1044
1041 size = sizeof (struct GNUNET_CADET_LocalInfoTunnel); 1045 size = sizeof (struct GNUNET_CADET_LocalInfoTunnel);
1042 size += c_n * sizeof (struct GNUNET_CADET_Hash); 1046 size += c_n * sizeof (struct GNUNET_CADET_Hash);
1043 size += ch_n * sizeof (CADET_ChannelNumber); 1047 size += ch_n * sizeof (struct GNUNET_CADET_ChannelNumber);
1044 1048
1045 resp = GNUNET_malloc (size); 1049 resp = GNUNET_malloc (size);
1046 resp->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL); 1050 resp->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL);
@@ -1214,26 +1218,16 @@ GML_shutdown (void)
1214 * @return non-NULL if channel exists in the clients lists 1218 * @return non-NULL if channel exists in the clients lists
1215 */ 1219 */
1216struct CadetChannel * 1220struct CadetChannel *
1217GML_channel_get (struct CadetClient *c, CADET_ChannelNumber chid) 1221GML_channel_get (struct CadetClient *c,
1222 struct GNUNET_CADET_ClientChannelNumber chid)
1218{ 1223{
1219 struct GNUNET_CONTAINER_MultiHashMap32 *map; 1224 struct GNUNET_CONTAINER_MultiHashMap32 *map;
1220 1225
1221 if (0 == (chid & GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)) 1226 if (ntohl (chid.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
1222 {
1223 GNUNET_break_op (0);
1224 LOG (GNUNET_ERROR_TYPE_DEBUG, "CHID %X not a local chid\n", chid);
1225 return NULL;
1226 }
1227
1228 if (chid >= GNUNET_CADET_LOCAL_CHANNEL_ID_SERV)
1229 map = c->incoming_channels;
1230 else if (chid >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
1231 map = c->own_channels; 1227 map = c->own_channels;
1232 else 1228 else
1233 { 1229 map = c->incoming_channels;
1234 GNUNET_break (0); 1230
1235 map = NULL;
1236 }
1237 if (NULL == map) 1231 if (NULL == map)
1238 { 1232 {
1239 GNUNET_break (0); 1233 GNUNET_break (0);
@@ -1242,7 +1236,8 @@ GML_channel_get (struct CadetClient *c, CADET_ChannelNumber chid)
1242 GML_2s (c), chid); 1236 GML_2s (c), chid);
1243 return NULL; 1237 return NULL;
1244 } 1238 }
1245 return GNUNET_CONTAINER_multihashmap32_get (map, chid); 1239 return GNUNET_CONTAINER_multihashmap32_get (map,
1240 chid.channel_of_client);
1246} 1241}
1247 1242
1248 1243
@@ -1255,17 +1250,19 @@ GML_channel_get (struct CadetClient *c, CADET_ChannelNumber chid)
1255 */ 1250 */
1256void 1251void
1257GML_channel_add (struct CadetClient *client, 1252GML_channel_add (struct CadetClient *client,
1258 uint32_t chid, 1253 struct GNUNET_CADET_ClientChannelNumber chid,
1259 struct CadetChannel *ch) 1254 struct CadetChannel *ch)
1260{ 1255{
1261 if (chid >= GNUNET_CADET_LOCAL_CHANNEL_ID_SERV) 1256 if (ntohl (chid.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
1262 GNUNET_CONTAINER_multihashmap32_put (client->incoming_channels, chid, ch, 1257 GNUNET_CONTAINER_multihashmap32_put (client->own_channels,
1263 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 1258 chid.channel_of_client,
1264 else if (chid >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) 1259 ch,
1265 GNUNET_CONTAINER_multihashmap32_put (client->own_channels, chid, ch,
1266 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 1260 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1267 else 1261 else
1268 GNUNET_break (0); 1262 GNUNET_CONTAINER_multihashmap32_put (client->incoming_channels,
1263 chid.channel_of_client,
1264 ch,
1265 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1269} 1266}
1270 1267
1271 1268
@@ -1278,19 +1275,17 @@ GML_channel_add (struct CadetClient *client,
1278 */ 1275 */
1279void 1276void
1280GML_channel_remove (struct CadetClient *client, 1277GML_channel_remove (struct CadetClient *client,
1281 uint32_t chid, 1278 struct GNUNET_CADET_ClientChannelNumber chid,
1282 struct CadetChannel *ch) 1279 struct CadetChannel *ch)
1283{ 1280{
1284 if (GNUNET_CADET_LOCAL_CHANNEL_ID_SERV <= chid) 1281 if (ntohl (chid.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
1285 GNUNET_break (GNUNET_YES == 1282 GNUNET_CONTAINER_multihashmap32_remove (client->own_channels,
1286 GNUNET_CONTAINER_multihashmap32_remove (client->incoming_channels, 1283 chid.channel_of_client,
1287 chid, ch)); 1284 ch);
1288 else if (GNUNET_CADET_LOCAL_CHANNEL_ID_CLI <= chid)
1289 GNUNET_break (GNUNET_YES ==
1290 GNUNET_CONTAINER_multihashmap32_remove (client->own_channels,
1291 chid, ch));
1292 else 1285 else
1293 GNUNET_break (0); 1286 GNUNET_CONTAINER_multihashmap32_remove (client->incoming_channels,
1287 chid.channel_of_client,
1288 ch);
1294} 1289}
1295 1290
1296 1291
@@ -1301,18 +1296,26 @@ GML_channel_remove (struct CadetClient *client,
1301 * 1296 *
1302 * @return LID of a channel free to use. 1297 * @return LID of a channel free to use.
1303 */ 1298 */
1304CADET_ChannelNumber 1299struct GNUNET_CADET_ClientChannelNumber
1305GML_get_next_chid (struct CadetClient *c) 1300GML_get_next_chid (struct CadetClient *c)
1306{ 1301{
1307 CADET_ChannelNumber chid; 1302 struct GNUNET_CADET_ClientChannelNumber chid;
1308 1303
1309 while (NULL != GML_channel_get (c, c->next_chid)) 1304 while (NULL != GML_channel_get (c,
1305 c->next_chid))
1310 { 1306 {
1311 LOG (GNUNET_ERROR_TYPE_DEBUG, "Channel %u exists...\n", c->next_chid); 1307 LOG (GNUNET_ERROR_TYPE_DEBUG,
1312 c->next_chid = (c->next_chid + 1) | GNUNET_CADET_LOCAL_CHANNEL_ID_SERV; 1308 "Channel %u exists...\n",
1309 c->next_chid);
1310 c->next_chid.channel_of_client
1311 = htonl (1 + (ntohl (c->next_chid.channel_of_client)));
1312 if (ntohl (c->next_chid.channel_of_client) >=
1313 GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
1314 c->next_chid.channel_of_client = htonl (0);
1313 } 1315 }
1314 chid = c->next_chid; 1316 chid = c->next_chid;
1315 c->next_chid = (c->next_chid + 1) | GNUNET_CADET_LOCAL_CHANNEL_ID_SERV; 1317 c->next_chid.channel_of_client
1318 = htonl (1 + (ntohl (c->next_chid.channel_of_client)));
1316 1319
1317 return chid; 1320 return chid;
1318} 1321}
@@ -1330,9 +1333,11 @@ GML_client_get (struct GNUNET_SERVER_Client *client)
1330{ 1333{
1331 if (NULL == client) 1334 if (NULL == client)
1332 return NULL; 1335 return NULL;
1333 return GNUNET_SERVER_client_get_user_context (client, struct CadetClient); 1336 return GNUNET_SERVER_client_get_user_context (client,
1337 struct CadetClient);
1334} 1338}
1335 1339
1340
1336/** 1341/**
1337 * Find a client that has opened a port 1342 * Find a client that has opened a port
1338 * 1343 *
@@ -1357,27 +1362,25 @@ GML_client_get_by_port (const struct GNUNET_HashCode *port)
1357void 1362void
1358GML_client_delete_channel (struct CadetClient *c, 1363GML_client_delete_channel (struct CadetClient *c,
1359 struct CadetChannel *ch, 1364 struct CadetChannel *ch,
1360 CADET_ChannelNumber id) 1365 struct GNUNET_CADET_ClientChannelNumber id)
1361{ 1366{
1362 int res; 1367 int res;
1363 1368
1364 if (GNUNET_CADET_LOCAL_CHANNEL_ID_SERV <= id) 1369 if (ntohl (id.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
1365 {
1366 res = GNUNET_CONTAINER_multihashmap32_remove (c->incoming_channels,
1367 id, ch);
1368 if (GNUNET_YES != res)
1369 LOG (GNUNET_ERROR_TYPE_DEBUG, "client_delete_channel dest KO\n");
1370 }
1371 else if (GNUNET_CADET_LOCAL_CHANNEL_ID_CLI <= id)
1372 { 1370 {
1373 res = GNUNET_CONTAINER_multihashmap32_remove (c->own_channels, 1371 res = GNUNET_CONTAINER_multihashmap32_remove (c->own_channels,
1374 id, ch); 1372 id.channel_of_client,
1373 ch);
1375 if (GNUNET_YES != res) 1374 if (GNUNET_YES != res)
1376 LOG (GNUNET_ERROR_TYPE_DEBUG, "client_delete_tunnel root KO\n"); 1375 LOG (GNUNET_ERROR_TYPE_DEBUG, "client_delete_tunnel root KO\n");
1377 } 1376 }
1378 else 1377 else
1379 { 1378 {
1380 GNUNET_break (0); 1379 res = GNUNET_CONTAINER_multihashmap32_remove (c->incoming_channels,
1380 id.channel_of_client,
1381 ch);
1382 if (GNUNET_YES != res)
1383 LOG (GNUNET_ERROR_TYPE_DEBUG, "client_delete_channel dest KO\n");
1381 } 1384 }
1382} 1385}
1383 1386
@@ -1390,17 +1393,21 @@ GML_client_delete_channel (struct CadetClient *c,
1390 * @param id Channel ID to use 1393 * @param id Channel ID to use
1391 */ 1394 */
1392void 1395void
1393GML_send_ack (struct CadetClient *c, CADET_ChannelNumber id) 1396GML_send_ack (struct CadetClient *c,
1397 struct GNUNET_CADET_ClientChannelNumber id)
1394{ 1398{
1395 struct GNUNET_CADET_LocalAck msg; 1399 struct GNUNET_CADET_LocalAck msg;
1396 1400
1397 LOG (GNUNET_ERROR_TYPE_DEBUG, 1401 LOG (GNUNET_ERROR_TYPE_DEBUG,
1398 "send local %s ack on %X towards %p\n", 1402 "send local %s ack on %X towards %p\n",
1399 id < GNUNET_CADET_LOCAL_CHANNEL_ID_SERV ? "FWD" : "BCK", id, c); 1403 ntohl (id.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI
1404 ? "FWD" : "BCK",
1405 ntohl (id.channel_of_client),
1406 c);
1400 1407
1401 msg.header.size = htons (sizeof (msg)); 1408 msg.header.size = htons (sizeof (msg));
1402 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); 1409 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK);
1403 msg.channel_id = htonl (id); 1410 msg.channel_id = id;
1404 GNUNET_SERVER_notification_context_unicast (nc, 1411 GNUNET_SERVER_notification_context_unicast (nc,
1405 c->handle, 1412 c->handle,
1406 &msg.header, 1413 &msg.header,
@@ -1421,14 +1428,16 @@ GML_send_ack (struct CadetClient *c, CADET_ChannelNumber id)
1421 */ 1428 */
1422void 1429void
1423GML_send_channel_create (struct CadetClient *c, 1430GML_send_channel_create (struct CadetClient *c,
1424 uint32_t id, struct GNUNET_HashCode *port, 1431 struct GNUNET_CADET_ClientChannelNumber id,
1425 uint32_t opt, const struct GNUNET_PeerIdentity *peer) 1432 const struct GNUNET_HashCode *port,
1433 uint32_t opt,
1434 const struct GNUNET_PeerIdentity *peer)
1426{ 1435{
1427 struct GNUNET_CADET_ChannelCreateMessage msg; 1436 struct GNUNET_CADET_ChannelCreateMessage msg;
1428 1437
1429 msg.header.size = htons (sizeof (msg)); 1438 msg.header.size = htons (sizeof (msg));
1430 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE); 1439 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE);
1431 msg.channel_id = htonl (id); 1440 msg.channel_id = id;
1432 msg.port = *port; 1441 msg.port = *port;
1433 msg.opt = htonl (opt); 1442 msg.opt = htonl (opt);
1434 msg.peer = *peer; 1443 msg.peer = *peer;
@@ -1444,17 +1453,19 @@ GML_send_channel_create (struct CadetClient *c,
1444 * @param id Channel ID to use 1453 * @param id Channel ID to use
1445 */ 1454 */
1446void 1455void
1447GML_send_channel_nack (struct CadetClient *c, CADET_ChannelNumber id) 1456GML_send_channel_nack (struct CadetClient *c,
1457 struct GNUNET_CADET_ClientChannelNumber id)
1448{ 1458{
1449 struct GNUNET_CADET_LocalAck msg; 1459 struct GNUNET_CADET_LocalAck msg;
1450 1460
1451 LOG (GNUNET_ERROR_TYPE_DEBUG, 1461 LOG (GNUNET_ERROR_TYPE_DEBUG,
1452 "send local nack on %X towards %p\n", 1462 "send local nack on %X towards %p\n",
1453 id, c); 1463 ntohl (id.channel_of_client),
1464 c);
1454 1465
1455 msg.header.size = htons (sizeof (msg)); 1466 msg.header.size = htons (sizeof (msg));
1456 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_NACK); 1467 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_NACK);
1457 msg.channel_id = htonl (id); 1468 msg.channel_id = id;
1458 GNUNET_SERVER_notification_context_unicast (nc, 1469 GNUNET_SERVER_notification_context_unicast (nc,
1459 c->handle, 1470 c->handle,
1460 &msg.header, 1471 &msg.header,
@@ -1469,7 +1480,8 @@ GML_send_channel_nack (struct CadetClient *c, CADET_ChannelNumber id)
1469 * @param id ID of the channel that is destroyed. 1480 * @param id ID of the channel that is destroyed.
1470 */ 1481 */
1471void 1482void
1472GML_send_channel_destroy (struct CadetClient *c, uint32_t id) 1483GML_send_channel_destroy (struct CadetClient *c,
1484 struct GNUNET_CADET_ClientChannelNumber id)
1473{ 1485{
1474 struct GNUNET_CADET_ChannelDestroyMessage msg; 1486 struct GNUNET_CADET_ChannelDestroyMessage msg;
1475 1487
@@ -1482,7 +1494,7 @@ GML_send_channel_destroy (struct CadetClient *c, uint32_t id)
1482 return; 1494 return;
1483 msg.header.size = htons (sizeof (msg)); 1495 msg.header.size = htons (sizeof (msg));
1484 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY); 1496 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY);
1485 msg.channel_id = htonl (id); 1497 msg.channel_id = id;
1486 GNUNET_SERVER_notification_context_unicast (nc, c->handle, 1498 GNUNET_SERVER_notification_context_unicast (nc, c->handle,
1487 &msg.header, GNUNET_NO); 1499 &msg.header, GNUNET_NO);
1488} 1500}
@@ -1498,7 +1510,7 @@ GML_send_channel_destroy (struct CadetClient *c, uint32_t id)
1498void 1510void
1499GML_send_data (struct CadetClient *c, 1511GML_send_data (struct CadetClient *c,
1500 const struct GNUNET_CADET_Data *msg, 1512 const struct GNUNET_CADET_Data *msg,
1501 CADET_ChannelNumber id) 1513 struct GNUNET_CADET_ClientChannelNumber id)
1502{ 1514{
1503 struct GNUNET_CADET_LocalData *copy; 1515 struct GNUNET_CADET_LocalData *copy;
1504 uint16_t size = ntohs (msg->header.size) - sizeof (struct GNUNET_CADET_Data); 1516 uint16_t size = ntohs (msg->header.size) - sizeof (struct GNUNET_CADET_Data);
@@ -1518,7 +1530,7 @@ GML_send_data (struct CadetClient *c,
1518 GNUNET_memcpy (&copy[1], &msg[1], size); 1530 GNUNET_memcpy (&copy[1], &msg[1], size);
1519 copy->header.size = htons (sizeof (struct GNUNET_CADET_LocalData) + size); 1531 copy->header.size = htons (sizeof (struct GNUNET_CADET_LocalData) + size);
1520 copy->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); 1532 copy->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA);
1521 copy->id = htonl (id); 1533 copy->id = id;
1522 GNUNET_SERVER_notification_context_unicast (nc, c->handle, 1534 GNUNET_SERVER_notification_context_unicast (nc, c->handle,
1523 &copy->header, GNUNET_NO); 1535 &copy->header, GNUNET_NO);
1524} 1536}
diff --git a/src/cadet/gnunet-service-cadet_local.h b/src/cadet/gnunet-service-cadet_local.h
index f89745092..9b6e5bf05 100644
--- a/src/cadet/gnunet-service-cadet_local.h
+++ b/src/cadet/gnunet-service-cadet_local.h
@@ -80,7 +80,8 @@ GML_shutdown (void);
80 * @return non-NULL if channel exists in the clients lists 80 * @return non-NULL if channel exists in the clients lists
81 */ 81 */
82struct CadetChannel * 82struct CadetChannel *
83GML_channel_get (struct CadetClient *c, uint32_t chid); 83GML_channel_get (struct CadetClient *c,
84 struct GNUNET_CADET_ClientChannelNumber chid);
84 85
85/** 86/**
86 * Add a channel to a client 87 * Add a channel to a client
@@ -91,7 +92,7 @@ GML_channel_get (struct CadetClient *c, uint32_t chid);
91 */ 92 */
92void 93void
93GML_channel_add (struct CadetClient *client, 94GML_channel_add (struct CadetClient *client,
94 uint32_t chid, 95 struct GNUNET_CADET_ClientChannelNumber chid,
95 struct CadetChannel *ch); 96 struct CadetChannel *ch);
96 97
97/** 98/**
@@ -103,7 +104,7 @@ GML_channel_add (struct CadetClient *client,
103 */ 104 */
104void 105void
105GML_channel_remove (struct CadetClient *client, 106GML_channel_remove (struct CadetClient *client,
106 uint32_t chid, 107 struct GNUNET_CADET_ClientChannelNumber chid,
107 struct CadetChannel *ch); 108 struct CadetChannel *ch);
108 109
109/** 110/**
@@ -113,7 +114,7 @@ GML_channel_remove (struct CadetClient *client,
113 * 114 *
114 * @return LID of a channel free to use. 115 * @return LID of a channel free to use.
115 */ 116 */
116CADET_ChannelNumber 117struct GNUNET_CADET_ClientChannelNumber
117GML_get_next_chid (struct CadetClient *c); 118GML_get_next_chid (struct CadetClient *c);
118 119
119/** 120/**
@@ -146,7 +147,7 @@ GML_client_get_by_port (const struct GNUNET_HashCode *port);
146void 147void
147GML_client_delete_channel (struct CadetClient *c, 148GML_client_delete_channel (struct CadetClient *c,
148 struct CadetChannel *ch, 149 struct CadetChannel *ch,
149 CADET_ChannelNumber id); 150 struct GNUNET_CADET_ClientChannelNumber id);
150 151
151/** 152/**
152 * Build a local ACK message and send it to a local client, if needed. 153 * Build a local ACK message and send it to a local client, if needed.
@@ -157,7 +158,8 @@ GML_client_delete_channel (struct CadetClient *c,
157 * @param id Channel ID to use 158 * @param id Channel ID to use
158 */ 159 */
159void 160void
160GML_send_ack (struct CadetClient *c, CADET_ChannelNumber id); 161GML_send_ack (struct CadetClient *c,
162 struct GNUNET_CADET_ClientChannelNumber id);
161 163
162/** 164/**
163 * Notify the appropriate client that a new incoming channel was created. 165 * Notify the appropriate client that a new incoming channel was created.
@@ -170,8 +172,10 @@ GML_send_ack (struct CadetClient *c, CADET_ChannelNumber id);
170 */ 172 */
171void 173void
172GML_send_channel_create (struct CadetClient *c, 174GML_send_channel_create (struct CadetClient *c,
173 uint32_t id, struct GNUNET_HashCode *port, 175 struct GNUNET_CADET_ClientChannelNumber id,
174 uint32_t opt, const struct GNUNET_PeerIdentity *peer); 176 const struct GNUNET_HashCode *port,
177 uint32_t opt,
178 const struct GNUNET_PeerIdentity *peer);
175 179
176/** 180/**
177 * Build a local channel NACK message and send it to a local client. 181 * Build a local channel NACK message and send it to a local client.
@@ -180,7 +184,9 @@ GML_send_channel_create (struct CadetClient *c,
180 * @param id Channel ID to use 184 * @param id Channel ID to use
181 */ 185 */
182void 186void
183GML_send_channel_nack (struct CadetClient *c, CADET_ChannelNumber id); 187GML_send_channel_nack (struct CadetClient *c,
188 struct GNUNET_CADET_ClientChannelNumber id);
189
184 190
185/** 191/**
186 * Notify a client that a channel is no longer valid. 192 * Notify a client that a channel is no longer valid.
@@ -189,7 +195,9 @@ GML_send_channel_nack (struct CadetClient *c, CADET_ChannelNumber id);
189 * @param id ID of the channel that is destroyed. 195 * @param id ID of the channel that is destroyed.
190 */ 196 */
191void 197void
192GML_send_channel_destroy (struct CadetClient *c, uint32_t id); 198GML_send_channel_destroy (struct CadetClient *c,
199 struct GNUNET_CADET_ClientChannelNumber id);
200
193 201
194/** 202/**
195 * Modify the cadet message ID from global to local and send to client. 203 * Modify the cadet message ID from global to local and send to client.
@@ -201,7 +209,7 @@ GML_send_channel_destroy (struct CadetClient *c, uint32_t id);
201void 209void
202GML_send_data (struct CadetClient *c, 210GML_send_data (struct CadetClient *c,
203 const struct GNUNET_CADET_Data *msg, 211 const struct GNUNET_CADET_Data *msg,
204 CADET_ChannelNumber id); 212 struct GNUNET_CADET_ClientChannelNumber id);
205 213
206/** 214/**
207 * Get the static string to represent a client. 215 * Get the static string to represent a client.
diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c
index c1e2d3224..b2ad1124c 100644
--- a/src/cadet/gnunet-service-cadet_peer.c
+++ b/src/cadet/gnunet-service-cadet_peer.c
@@ -76,7 +76,7 @@ struct CadetPeerQueue {
76 * Task to asynchronously run the drop continuation. 76 * Task to asynchronously run the drop continuation.
77 */ 77 */
78 struct GNUNET_SCHEDULER_Task *drop_task; 78 struct GNUNET_SCHEDULER_Task *drop_task;
79 79
80 /** 80 /**
81 * Time when message was queued for sending. 81 * Time when message was queued for sending.
82 */ 82 */
@@ -1145,7 +1145,7 @@ static void
1145drop_cb (void *cls) 1145drop_cb (void *cls)
1146{ 1146{
1147 struct CadetPeerQueue *q = cls; 1147 struct CadetPeerQueue *q = cls;
1148 1148
1149 GNUNET_MQ_discard (q->env); 1149 GNUNET_MQ_discard (q->env);
1150 call_peer_cont (q, GNUNET_YES); 1150 call_peer_cont (q, GNUNET_YES);
1151 GNUNET_free (q); 1151 GNUNET_free (q);
diff --git a/src/cadet/gnunet-service-cadet_peer.h b/src/cadet/gnunet-service-cadet_peer.h
index 093cfa21a..37d735bf5 100644
--- a/src/cadet/gnunet-service-cadet_peer.h
+++ b/src/cadet/gnunet-service-cadet_peer.h
@@ -122,6 +122,7 @@ GCP_shutdown (void);
122struct CadetPeer * 122struct CadetPeer *
123GCP_get (const struct GNUNET_PeerIdentity *peer_id, int create); 123GCP_get (const struct GNUNET_PeerIdentity *peer_id, int create);
124 124
125
125/** 126/**
126 * Retrieve the CadetPeer stucture associated with the peer. Optionally create 127 * Retrieve the CadetPeer stucture associated with the peer. Optionally create
127 * one and insert it in the appropriate structures if the peer is not known yet. 128 * one and insert it in the appropriate structures if the peer is not known yet.
@@ -136,6 +137,7 @@ GCP_get (const struct GNUNET_PeerIdentity *peer_id, int create);
136struct CadetPeer * 137struct CadetPeer *
137GCP_get_short (const GNUNET_PEER_Id peer, int create); 138GCP_get_short (const GNUNET_PEER_Id peer, int create);
138 139
140
139/** 141/**
140 * Try to establish a new connection to this peer (in its tunnel). 142 * Try to establish a new connection to this peer (in its tunnel).
141 * If the peer doesn't have any path to it yet, try to get one. 143 * If the peer doesn't have any path to it yet, try to get one.
@@ -440,7 +442,8 @@ GCP_iterate_paths (struct CadetPeer *peer,
440 * @param cls Closure for @c iter. 442 * @param cls Closure for @c iter.
441 */ 443 */
442void 444void
443GCP_iterate_all (GNUNET_CONTAINER_PeerMapIterator iter, void *cls); 445GCP_iterate_all (GNUNET_CONTAINER_PeerMapIterator iter,
446 void *cls);
444 447
445 448
446/** 449/**
diff --git a/src/cadet/gnunet-service-cadet_tunnel.c b/src/cadet/gnunet-service-cadet_tunnel.c
index 6ddcf6598..2e17774d4 100644
--- a/src/cadet/gnunet-service-cadet_tunnel.c
+++ b/src/cadet/gnunet-service-cadet_tunnel.c
@@ -63,7 +63,7 @@ struct CadetTChannel
63 63
64 64
65/** 65/**
66 * Connection list and metadata. 66 * Entry in list of connections used by tunnel, with metadata.
67 */ 67 */
68struct CadetTConnection 68struct CadetTConnection
69{ 69{
@@ -243,6 +243,7 @@ struct CadetTunnelAxolotl
243 struct GNUNET_TIME_Absolute ratchet_expiration; 243 struct GNUNET_TIME_Absolute ratchet_expiration;
244}; 244};
245 245
246
246/** 247/**
247 * Struct containing all information regarding a tunnel to a peer. 248 * Struct containing all information regarding a tunnel to a peer.
248 */ 249 */
@@ -309,7 +310,7 @@ struct CadetTunnel
309 /** 310 /**
310 * Channel ID for the next created channel. 311 * Channel ID for the next created channel.
311 */ 312 */
312 CADET_ChannelNumber next_chid; 313 struct GNUNET_CADET_ChannelNumber next_chid;
313 314
314 /** 315 /**
315 * Destroy flag: if true, destroy on last message. 316 * Destroy flag: if true, destroy on last message.
@@ -1401,7 +1402,11 @@ send_prebuilt_message (const struct GNUNET_MessageHeader *message,
1401 GNUNET_break (0); 1402 GNUNET_break (0);
1402 LOG (GNUNET_ERROR_TYPE_ERROR, "type %s not valid\n", GC_m2s (type)); 1403 LOG (GNUNET_ERROR_TYPE_ERROR, "type %s not valid\n", GC_m2s (type));
1403 } 1404 }
1404 LOG (GNUNET_ERROR_TYPE_DEBUG, "type %s\n", GC_m2s (type)); 1405 LOG (GNUNET_ERROR_TYPE_DEBUG,
1406 "Sending message of type %s with PID %u and CID %s\n",
1407 GC_m2s (type),
1408 htonl (ax_msg->pid),
1409 GC_h2s (&ax_msg->cid));
1405 1410
1406 if (NULL == cont) 1411 if (NULL == cont)
1407 { 1412 {
@@ -1562,17 +1567,19 @@ destroy_iterator (void *cls,
1562 * @param gid ID of the channel. 1567 * @param gid ID of the channel.
1563 */ 1568 */
1564static void 1569static void
1565send_channel_destroy (struct CadetTunnel *t, unsigned int gid) 1570send_channel_destroy (struct CadetTunnel *t,
1571 struct GNUNET_CADET_ChannelNumber gid)
1566{ 1572{
1567 struct GNUNET_CADET_ChannelManage msg; 1573 struct GNUNET_CADET_ChannelManage msg;
1568 1574
1569 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY); 1575 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY);
1570 msg.header.size = htons (sizeof (msg)); 1576 msg.header.size = htons (sizeof (msg));
1571 msg.chid = htonl (gid); 1577 msg.chid = gid;
1572 1578
1573 LOG (GNUNET_ERROR_TYPE_DEBUG, 1579 LOG (GNUNET_ERROR_TYPE_DEBUG,
1574 "WARNING destroying unknown channel %u on tunnel %s\n", 1580 "WARNING destroying unknown channel %u on tunnel %s\n",
1575 gid, GCT_2s (t)); 1581 ntohl (gid.cn),
1582 GCT_2s (t));
1576 send_prebuilt_message (&msg.header, t, NULL, GNUNET_YES, NULL, NULL, NULL); 1583 send_prebuilt_message (&msg.header, t, NULL, GNUNET_YES, NULL, NULL, NULL);
1577} 1584}
1578 1585
@@ -1613,13 +1620,17 @@ handle_data (struct CadetTunnel *t,
1613 1620
1614 1621
1615 /* Check channel */ 1622 /* Check channel */
1616 ch = GCT_get_channel (t, ntohl (msg->chid)); 1623 ch = GCT_get_channel (t, msg->chid);
1617 if (NULL == ch) 1624 if (NULL == ch)
1618 { 1625 {
1619 GNUNET_STATISTICS_update (stats, "# data on unknown channel", 1626 GNUNET_STATISTICS_update (stats,
1620 1, GNUNET_NO); 1627 "# data on unknown channel",
1621 LOG (GNUNET_ERROR_TYPE_DEBUG, "channel 0x%X unknown\n", ntohl (msg->chid)); 1628 1,
1622 send_channel_destroy (t, ntohl (msg->chid)); 1629 GNUNET_NO);
1630 LOG (GNUNET_ERROR_TYPE_DEBUG,
1631 "channel 0x%X unknown\n",
1632 ntohl (msg->chid.cn));
1633 send_channel_destroy (t, msg->chid);
1623 return; 1634 return;
1624 } 1635 }
1625 1636
@@ -1654,13 +1665,13 @@ handle_data_ack (struct CadetTunnel *t,
1654 } 1665 }
1655 1666
1656 /* Check channel */ 1667 /* Check channel */
1657 ch = GCT_get_channel (t, ntohl (msg->chid)); 1668 ch = GCT_get_channel (t, msg->chid);
1658 if (NULL == ch) 1669 if (NULL == ch)
1659 { 1670 {
1660 GNUNET_STATISTICS_update (stats, "# data ack on unknown channel", 1671 GNUNET_STATISTICS_update (stats, "# data ack on unknown channel",
1661 1, GNUNET_NO); 1672 1, GNUNET_NO);
1662 LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING channel %u unknown\n", 1673 LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING channel %u unknown\n",
1663 ntohl (msg->chid)); 1674 ntohl (msg->chid.cn));
1664 return; 1675 return;
1665 } 1676 }
1666 1677
@@ -1690,7 +1701,7 @@ handle_ch_create (struct CadetTunnel *t,
1690 } 1701 }
1691 1702
1692 /* Check channel */ 1703 /* Check channel */
1693 ch = GCT_get_channel (t, ntohl (msg->chid)); 1704 ch = GCT_get_channel (t, msg->chid);
1694 if (NULL != ch && ! GCT_is_loopback (t)) 1705 if (NULL != ch && ! GCT_is_loopback (t))
1695 { 1706 {
1696 /* Probably a retransmission, safe to ignore */ 1707 /* Probably a retransmission, safe to ignore */
@@ -1725,13 +1736,14 @@ handle_ch_nack (struct CadetTunnel *t,
1725 } 1736 }
1726 1737
1727 /* Check channel */ 1738 /* Check channel */
1728 ch = GCT_get_channel (t, ntohl (msg->chid)); 1739 ch = GCT_get_channel (t, msg->chid);
1729 if (NULL == ch) 1740 if (NULL == ch)
1730 { 1741 {
1731 GNUNET_STATISTICS_update (stats, "# channel NACK on unknown channel", 1742 GNUNET_STATISTICS_update (stats, "# channel NACK on unknown channel",
1732 1, GNUNET_NO); 1743 1, GNUNET_NO);
1733 LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING channel %u unknown\n", 1744 LOG (GNUNET_ERROR_TYPE_DEBUG,
1734 ntohl (msg->chid)); 1745 "WARNING channel %u unknown\n",
1746 ntohl (msg->chid.cn));
1735 return; 1747 return;
1736 } 1748 }
1737 1749
@@ -1766,13 +1778,16 @@ handle_ch_ack (struct CadetTunnel *t,
1766 } 1778 }
1767 1779
1768 /* Check channel */ 1780 /* Check channel */
1769 ch = GCT_get_channel (t, ntohl (msg->chid)); 1781 ch = GCT_get_channel (t, msg->chid);
1770 if (NULL == ch) 1782 if (NULL == ch)
1771 { 1783 {
1772 GNUNET_STATISTICS_update (stats, "# channel ack on unknown channel", 1784 GNUNET_STATISTICS_update (stats,
1773 1, GNUNET_NO); 1785 "# channel ack on unknown channel",
1774 LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING channel %u unknown\n", 1786 1,
1775 ntohl (msg->chid)); 1787 GNUNET_NO);
1788 LOG (GNUNET_ERROR_TYPE_DEBUG,
1789 "WARNING channel %u unknown\n",
1790 ntohl (msg->chid.cn));
1776 return; 1791 return;
1777 } 1792 }
1778 1793
@@ -1807,7 +1822,7 @@ handle_ch_destroy (struct CadetTunnel *t,
1807 } 1822 }
1808 1823
1809 /* Check channel */ 1824 /* Check channel */
1810 ch = GCT_get_channel (t, ntohl (msg->chid)); 1825 ch = GCT_get_channel (t, msg->chid);
1811 if (NULL == ch) 1826 if (NULL == ch)
1812 { 1827 {
1813 /* Probably a retransmission, safe to ignore */ 1828 /* Probably a retransmission, safe to ignore */
@@ -2200,7 +2215,7 @@ GCT_new (struct CadetPeer *destination)
2200 struct CadetTunnel *t; 2215 struct CadetTunnel *t;
2201 2216
2202 t = GNUNET_new (struct CadetTunnel); 2217 t = GNUNET_new (struct CadetTunnel);
2203 t->next_chid = 0; 2218 t->next_chid.cn = 0;
2204 t->peer = destination; 2219 t->peer = destination;
2205 2220
2206 if (GNUNET_OK != 2221 if (GNUNET_OK !=
@@ -2442,7 +2457,8 @@ GCT_remove_connection (struct CadetTunnel *t,
2442 * @param ch Channel. 2457 * @param ch Channel.
2443 */ 2458 */
2444void 2459void
2445GCT_add_channel (struct CadetTunnel *t, struct CadetChannel *ch) 2460GCT_add_channel (struct CadetTunnel *t,
2461 struct CadetChannel *ch)
2446{ 2462{
2447 struct CadetTChannel *aux; 2463 struct CadetTChannel *aux;
2448 2464
@@ -2510,7 +2526,8 @@ GCT_remove_channel (struct CadetTunnel *t, struct CadetChannel *ch)
2510 * @return channel handler, NULL if doesn't exist 2526 * @return channel handler, NULL if doesn't exist
2511 */ 2527 */
2512struct CadetChannel * 2528struct CadetChannel *
2513GCT_get_channel (struct CadetTunnel *t, CADET_ChannelNumber chid) 2529GCT_get_channel (struct CadetTunnel *t,
2530 struct GNUNET_CADET_ChannelNumber chid)
2514{ 2531{
2515 struct CadetTChannel *iter; 2532 struct CadetTChannel *iter;
2516 2533
@@ -2519,7 +2536,7 @@ GCT_get_channel (struct CadetTunnel *t, CADET_ChannelNumber chid)
2519 2536
2520 for (iter = t->channel_head; NULL != iter; iter = iter->next) 2537 for (iter = t->channel_head; NULL != iter; iter = iter->next)
2521 { 2538 {
2522 if (GCCH_get_id (iter->ch) == chid) 2539 if (GCCH_get_id (iter->ch).cn == chid.cn)
2523 break; 2540 break;
2524 } 2541 }
2525 2542
@@ -2966,11 +2983,11 @@ GCT_get_destination (struct CadetTunnel *t)
2966 * 2983 *
2967 * @return GID of a channel free to use. 2984 * @return GID of a channel free to use.
2968 */ 2985 */
2969CADET_ChannelNumber 2986struct GNUNET_CADET_ChannelNumber
2970GCT_get_next_chid (struct CadetTunnel *t) 2987GCT_get_next_chid (struct CadetTunnel *t)
2971{ 2988{
2972 CADET_ChannelNumber chid; 2989 struct GNUNET_CADET_ChannelNumber chid;
2973 CADET_ChannelNumber mask; 2990 struct GNUNET_CADET_ChannelNumber mask;
2974 int result; 2991 int result;
2975 2992
2976 /* Set bit 30 depending on the ID relationship. Bit 31 is always 0 for GID. 2993 /* Set bit 30 depending on the ID relationship. Bit 31 is always 0 for GID.
@@ -2979,20 +2996,22 @@ GCT_get_next_chid (struct CadetTunnel *t)
2979 */ 2996 */
2980 result = GNUNET_CRYPTO_cmp_peer_identity (&my_full_id, GCP_get_id (t->peer)); 2997 result = GNUNET_CRYPTO_cmp_peer_identity (&my_full_id, GCP_get_id (t->peer));
2981 if (0 > result) 2998 if (0 > result)
2982 mask = 0x40000000; 2999 mask.cn = htonl (0x40000000);
2983 else 3000 else
2984 mask = 0x0; 3001 mask.cn = 0x0;
2985 t->next_chid |= mask; 3002 t->next_chid.cn |= mask.cn;
2986 3003
2987 while (NULL != GCT_get_channel (t, t->next_chid)) 3004 while (NULL != GCT_get_channel (t, t->next_chid))
2988 { 3005 {
2989 LOG (GNUNET_ERROR_TYPE_DEBUG, "Channel %u exists...\n", t->next_chid); 3006 LOG (GNUNET_ERROR_TYPE_DEBUG,
2990 t->next_chid = (t->next_chid + 1) & ~GNUNET_CADET_LOCAL_CHANNEL_ID_CLI; 3007 "Channel %u exists...\n",
2991 t->next_chid |= mask; 3008 t->next_chid.cn);
3009 t->next_chid.cn = htonl ((ntohl (t->next_chid.cn) + 1) & ~GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
3010 t->next_chid.cn |= mask.cn;
2992 } 3011 }
2993 chid = t->next_chid; 3012 chid = t->next_chid;
2994 t->next_chid = (t->next_chid + 1) & ~GNUNET_CADET_LOCAL_CHANNEL_ID_CLI; 3013 t->next_chid.cn = (t->next_chid.cn + 1) & ~GNUNET_CADET_LOCAL_CHANNEL_ID_CLI;
2995 t->next_chid |= mask; 3014 t->next_chid.cn |= mask.cn;
2996 3015
2997 return chid; 3016 return chid;
2998} 3017}
@@ -3486,4 +3505,3 @@ GCT_iterate_channels (struct CadetTunnel *t, GCT_chan_iter iter, void *cls)
3486 for (cht = t->channel_head; NULL != cht; cht = cht->next) 3505 for (cht = t->channel_head; NULL != cht; cht = cht->next)
3487 iter (cls, cht->ch); 3506 iter (cls, cht->ch);
3488} 3507}
3489
diff --git a/src/cadet/gnunet-service-cadet_tunnel.h b/src/cadet/gnunet-service-cadet_tunnel.h
index e3ca57e9c..2d9a2b528 100644
--- a/src/cadet/gnunet-service-cadet_tunnel.h
+++ b/src/cadet/gnunet-service-cadet_tunnel.h
@@ -291,7 +291,7 @@ GCT_remove_channel (struct CadetTunnel *t, struct CadetChannel *ch);
291 * @return channel handler, NULL if doesn't exist 291 * @return channel handler, NULL if doesn't exist
292 */ 292 */
293struct CadetChannel * 293struct CadetChannel *
294GCT_get_channel (struct CadetTunnel *t, CADET_ChannelNumber chid); 294GCT_get_channel (struct CadetTunnel *t, struct GNUNET_CADET_ChannelNumber chid);
295 295
296 296
297/** 297/**
@@ -427,7 +427,7 @@ GCT_get_destination (struct CadetTunnel *t);
427 * 427 *
428 * @return ID of a channel free to use. 428 * @return ID of a channel free to use.
429 */ 429 */
430CADET_ChannelNumber 430struct GNUNET_CADET_ChannelNumber
431GCT_get_next_chid (struct CadetTunnel *t); 431GCT_get_next_chid (struct CadetTunnel *t);
432 432
433 433
diff --git a/src/cadet/test_cadet_local.c b/src/cadet/test_cadet_local.c
index c226563d5..d15785cb0 100644
--- a/src/cadet/test_cadet_local.c
+++ b/src/cadet/test_cadet_local.c
@@ -178,7 +178,8 @@ inbound_channel (void *cls,
178 * with the channel is stored 178 * with the channel is stored
179 */ 179 */
180static void 180static void
181channel_end (void *cls, const struct GNUNET_CADET_Channel *channel, 181channel_end (void *cls,
182 const struct GNUNET_CADET_Channel *channel,
182 void *channel_ctx) 183 void *channel_ctx)
183{ 184{
184 long id = (long) cls; 185 long id = (long) cls;
@@ -191,6 +192,8 @@ channel_end (void *cls, const struct GNUNET_CADET_Channel *channel,
191 GNUNET_CADET_notify_transmit_ready_cancel (mth); 192 GNUNET_CADET_notify_transmit_ready_cancel (mth);
192 mth = NULL; 193 mth = NULL;
193 } 194 }
195 if (channel == ch)
196 ch = NULL;
194 if (GNUNET_NO == got_data) 197 if (GNUNET_NO == got_data)
195 { 198 {
196 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply ( 199 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (
diff --git a/src/include/gnunet_cadet_service.h b/src/include/gnunet_cadet_service.h
index c32311643..c6b683370 100644
--- a/src/include/gnunet_cadet_service.h
+++ b/src/include/gnunet_cadet_service.h
@@ -102,9 +102,9 @@ enum GNUNET_CADET_ChannelOption
102 102
103 /** 103 /**
104 * Enable out of order delivery of messages. 104 * Enable out of order delivery of messages.
105 * Yes/No. 105 * Set bit for out-of-order delivery.
106 */ 106 */
107 GNUNET_CADET_OPTION_OOORDER = 0x4, 107 GNUNET_CADET_OPTION_OUT_OF_ORDER = 0x4,
108 108
109 /** 109 /**
110 * Who is the peer at the other end of the channel. 110 * Who is the peer at the other end of the channel.
@@ -332,7 +332,8 @@ union GNUNET_CADET_ChannelInfo
332 */ 332 */
333const union GNUNET_CADET_ChannelInfo * 333const union GNUNET_CADET_ChannelInfo *
334GNUNET_CADET_channel_get_info (struct GNUNET_CADET_Channel *channel, 334GNUNET_CADET_channel_get_info (struct GNUNET_CADET_Channel *channel,
335 enum GNUNET_CADET_ChannelOption option, ...); 335 enum GNUNET_CADET_ChannelOption option,
336 ...);
336 337
337 338
338/** 339/**
@@ -491,6 +492,24 @@ typedef void
491 492
492 493
493/** 494/**
495 * Hash uniquely identifying a connection below a tunnel.
496 */
497struct GNUNET_CADET_ConnectionTunnelIdentifier
498{
499 struct GNUNET_CADET_Hash connection_of_tunnel;
500};
501
502
503/**
504 * Number identifying a CADET channel.
505 */
506struct GNUNET_CADET_ChannelNumber
507{
508 uint32_t cn GNUNET_PACKED;
509};
510
511
512/**
494 * Method called to retrieve information about a specific tunnel the cadet peer 513 * Method called to retrieve information about a specific tunnel the cadet peer
495 * has established, o`r is trying to establish. 514 * has established, o`r is trying to establish.
496 * 515 *
@@ -508,8 +527,8 @@ typedef void
508 const struct GNUNET_PeerIdentity *peer, 527 const struct GNUNET_PeerIdentity *peer,
509 unsigned int n_channels, 528 unsigned int n_channels,
510 unsigned int n_connections, 529 unsigned int n_connections,
511 uint32_t *channels, 530 const struct GNUNET_CADET_ChannelNumber *channels,
512 struct GNUNET_CADET_Hash *connections, 531 const struct GNUNET_CADET_ConnectionTunnelIdentifier *connections,
513 unsigned int estate, 532 unsigned int estate,
514 unsigned int cstate); 533 unsigned int cstate);
515 534
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index 6c56315a6..9e91a958c 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -2776,6 +2776,11 @@ extern "C"
2776 */ 2776 */
2777#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_DUMP 1038 2777#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_DUMP 1038
2778 2778
2779/**
2780 * End of local information about all peers known to the service.
2781 */
2782#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER_END 1039
2783
2779/******************************** Application *******************************/ 2784/******************************** Application *******************************/
2780 2785
2781/** 2786/**