aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-01-17 11:54:31 +0100
committerChristian Grothoff <christian@grothoff.org>2017-01-17 11:54:31 +0100
commit500842f42c4e51c4c5fc3c1cdfc1c1f7166b2d0d (patch)
tree9a80967af02b49319d0ab406b0ec9fa3d31e13fd /src
parentd0bb14e2a958f4f816c6c006dd8b7a979e6de289 (diff)
downloadgnunet-500842f42c4e51c4c5fc3c1cdfc1c1f7166b2d0d.tar.gz
gnunet-500842f42c4e51c4c5fc3c1cdfc1c1f7166b2d0d.zip
more work on new CADET
Diffstat (limited to 'src')
-rw-r--r--src/cadet/cadet_protocol.h16
-rw-r--r--src/cadet/gnunet-service-cadet-new.c12
-rw-r--r--src/cadet/gnunet-service-cadet-new.h5
-rw-r--r--src/cadet/gnunet-service-cadet-new_connection.c327
-rw-r--r--src/cadet/gnunet-service-cadet-new_connection.h19
-rw-r--r--src/cadet/gnunet-service-cadet-new_peer.c154
-rw-r--r--src/cadet/gnunet-service-cadet-new_peer.h74
-rw-r--r--src/cadet/gnunet-service-cadet-new_tunnels.c17
-rw-r--r--src/cadet/gnunet-service-cadet_connection.c18
-rw-r--r--src/cadet/gnunet-service-cadet_connection.h4
-rw-r--r--src/cadet/gnunet-service-cadet_local.c3
-rw-r--r--src/cadet/gnunet-service-cadet_tunnel.c4
12 files changed, 605 insertions, 48 deletions
diff --git a/src/cadet/cadet_protocol.h b/src/cadet/cadet_protocol.h
index c555d6155..ba2044b0d 100644
--- a/src/cadet/cadet_protocol.h
+++ b/src/cadet/cadet_protocol.h
@@ -74,7 +74,7 @@ struct GNUNET_CADET_ConnectionCreate
74 /** 74 /**
75 * ID of the connection 75 * ID of the connection
76 */ 76 */
77 struct GNUNET_CADET_Hash cid; 77 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
78 78
79 /** 79 /**
80 * path_length structs defining the *whole* path from the origin [0] to the 80 * path_length structs defining the *whole* path from the origin [0] to the
@@ -102,7 +102,7 @@ struct GNUNET_CADET_ConnectionACK
102 /** 102 /**
103 * ID of the connection. 103 * ID of the connection.
104 */ 104 */
105 struct GNUNET_CADET_Hash cid; 105 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
106 106
107}; 107};
108 108
@@ -125,7 +125,7 @@ struct GNUNET_CADET_ConnectionBroken
125 /** 125 /**
126 * ID of the connection. 126 * ID of the connection.
127 */ 127 */
128 struct GNUNET_CADET_Hash cid; 128 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
129 129
130 /** 130 /**
131 * ID of the endpoint 131 * ID of the endpoint
@@ -157,7 +157,7 @@ struct GNUNET_CADET_ConnectionDestroy
157 /** 157 /**
158 * ID of the connection. 158 * ID of the connection.
159 */ 159 */
160 struct GNUNET_CADET_Hash cid; 160 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
161}; 161};
162 162
163 163
@@ -179,7 +179,7 @@ struct GNUNET_CADET_ACK
179 /** 179 /**
180 * ID of the connection. 180 * ID of the connection.
181 */ 181 */
182 struct GNUNET_CADET_Hash cid; 182 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
183}; 183};
184 184
185 185
@@ -201,7 +201,7 @@ struct GNUNET_CADET_Poll
201 /** 201 /**
202 * ID of the connection. 202 * ID of the connection.
203 */ 203 */
204 struct GNUNET_CADET_Hash cid; 204 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
205 205
206}; 206};
207 207
@@ -247,7 +247,7 @@ struct GNUNET_CADET_KX
247 /** 247 /**
248 * ID of the connection. 248 * ID of the connection.
249 */ 249 */
250 struct GNUNET_CADET_Hash cid; 250 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
251 251
252 /** 252 /**
253 * Sender's ephemeral public ECC key encoded in a 253 * Sender's ephemeral public ECC key encoded in a
@@ -283,7 +283,7 @@ struct GNUNET_CADET_Encrypted
283 /** 283 /**
284 * ID of the connection. 284 * ID of the connection.
285 */ 285 */
286 struct GNUNET_CADET_Hash cid; 286 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
287 287
288 /** 288 /**
289 * MAC of the encrypted message, used to verify message integrity. 289 * MAC of the encrypted message, used to verify message integrity.
diff --git a/src/cadet/gnunet-service-cadet-new.c b/src/cadet/gnunet-service-cadet-new.c
index 74296a27e..b2f39b3cd 100644
--- a/src/cadet/gnunet-service-cadet-new.c
+++ b/src/cadet/gnunet-service-cadet-new.c
@@ -170,6 +170,11 @@ struct GNUNET_CONTAINER_MultiHashMap *loose_channels;
170 */ 170 */
171struct GNUNET_CONTAINER_MultiPeerMap *peers; 171struct GNUNET_CONTAINER_MultiPeerMap *peers;
172 172
173/**
174 * Map from expanded connection hash codes to `struct CadetConnection` objects.
175 */
176struct GNUNET_CONTAINER_MultiHashMap *connections;
177
173 178
174 179
175/** 180/**
@@ -317,6 +322,11 @@ shutdown_task (void *cls)
317 GNUNET_CONTAINER_multipeermap_destroy (peers); 322 GNUNET_CONTAINER_multipeermap_destroy (peers);
318 peers = NULL; 323 peers = NULL;
319 } 324 }
325 if (NULL != connections)
326 {
327 GNUNET_CONTAINER_multihashmap_destroy (connections);
328 connections = NULL;
329 }
320 if (NULL != ats_ch) 330 if (NULL != ats_ch)
321 { 331 {
322 GNUNET_ATS_connectivity_done (ats_ch); 332 GNUNET_ATS_connectivity_done (ats_ch);
@@ -1232,6 +1242,8 @@ run (void *cls,
1232 GNUNET_NO); 1242 GNUNET_NO);
1233 peers = GNUNET_CONTAINER_multipeermap_create (16, 1243 peers = GNUNET_CONTAINER_multipeermap_create (16,
1234 GNUNET_YES); 1244 GNUNET_YES);
1245 connections = GNUNET_CONTAINER_multihashmap_create (256,
1246 GNUNET_YES);
1235 GCH_init (c); 1247 GCH_init (c);
1236 GCD_init (c); 1248 GCD_init (c);
1237 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1249 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
diff --git a/src/cadet/gnunet-service-cadet-new.h b/src/cadet/gnunet-service-cadet-new.h
index 9521b6363..416c9d13a 100644
--- a/src/cadet/gnunet-service-cadet-new.h
+++ b/src/cadet/gnunet-service-cadet-new.h
@@ -140,6 +140,11 @@ extern struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
140extern struct GNUNET_CONTAINER_MultiHashMap *open_ports; 140extern struct GNUNET_CONTAINER_MultiHashMap *open_ports;
141 141
142/** 142/**
143 * Map from expanded connection hash codes to `struct CadetConnection` objects.
144 */
145extern struct GNUNET_CONTAINER_MultiHashMap *connections;
146
147/**
143 * Map from ports to channels where the ports were closed at the 148 * Map from ports to channels where the ports were closed at the
144 * time we got the inbound connection. 149 * time we got the inbound connection.
145 * Indexed by port, contains `struct CadetChannel`. 150 * Indexed by port, contains `struct CadetChannel`.
diff --git a/src/cadet/gnunet-service-cadet-new_connection.c b/src/cadet/gnunet-service-cadet-new_connection.c
index ea0b2c6e5..1f31331a5 100644
--- a/src/cadet/gnunet-service-cadet-new_connection.c
+++ b/src/cadet/gnunet-service-cadet-new_connection.c
@@ -30,6 +30,45 @@
30#include "gnunet-service-cadet-new_paths.h" 30#include "gnunet-service-cadet-new_paths.h"
31#include "gnunet-service-cadet-new_peer.h" 31#include "gnunet-service-cadet-new_peer.h"
32#include "gnunet-service-cadet-new_connection.h" 32#include "gnunet-service-cadet-new_connection.h"
33#include "gnunet_cadet_service.h"
34#include "cadet_protocol.h"
35
36
37/**
38 * All the states a connection can be in.
39 */
40enum CadetConnectionState
41{
42 /**
43 * Uninitialized status, we have not yet even gotten the message queue.
44 */
45 CADET_CONNECTION_NEW,
46
47 /**
48 * Connection create message in queue, awaiting transmission by CORE.
49 */
50 CADET_CONNECTION_SENDING_CREATE,
51
52 /**
53 * Connection create message sent, waiting for ACK.
54 */
55 CADET_CONNECTION_SENT,
56
57 /**
58 * Connection confirmed, ready to carry traffic.
59 */
60 CADET_CONNECTION_READY,
61
62 /**
63 * Connection to be destroyed, just waiting to empty queues.
64 */
65 CADET_CONNECTION_DESTROYED,
66
67 /**
68 * Connection to be destroyed because of a distant peer, same as DESTROYED.
69 */
70 CADET_CONNECTION_BROKEN
71};
33 72
34 73
35/** 74/**
@@ -37,6 +76,12 @@
37 */ 76 */
38struct CadetConnection 77struct CadetConnection
39{ 78{
79
80 /**
81 * ID of the connection.
82 */
83 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
84
40 /** 85 /**
41 * To which peer does this connection go? 86 * To which peer does this connection go?
42 */ 87 */
@@ -48,6 +93,26 @@ struct CadetConnection
48 struct CadetPeerPath *path; 93 struct CadetPeerPath *path;
49 94
50 /** 95 /**
96 * Pending message, NULL if we are ready to transmit.
97 */
98 struct GNUNET_MQ_Envelope *env;
99
100 /**
101 * Message queue to the first hop, or NULL if we have no connection yet.
102 */
103 struct GNUNET_MQ_Handle *mq;
104
105 /**
106 * Handle for calling #GCP_request_mq_cancel() once we are finished.
107 */
108 struct GCP_MessageQueueManager *mq_man;
109
110 /**
111 * Task for connection maintenance.
112 */
113 struct GNUNET_SCHEDULER_Task *task;
114
115 /**
51 * Function to call once we are ready to transmit. 116 * Function to call once we are ready to transmit.
52 */ 117 */
53 GNUNET_SCHEDULER_TaskCallback ready_cb; 118 GNUNET_SCHEDULER_TaskCallback ready_cb;
@@ -58,6 +123,16 @@ struct CadetConnection
58 void *ready_cb_cls; 123 void *ready_cb_cls;
59 124
60 /** 125 /**
126 * How long do we wait before we try again with a CREATE message?
127 */
128 struct GNUNET_TIME_Relative retry_delay;
129
130 /**
131 * State of the connection.
132 */
133 enum CadetConnectionState state;
134
135 /**
61 * Offset of our @e destination in @e path. 136 * Offset of our @e destination in @e path.
62 */ 137 */
63 unsigned int off; 138 unsigned int off;
@@ -74,8 +149,9 @@ struct CadetConnection
74int 149int
75GCC_is_ready (struct CadetConnection *cc) 150GCC_is_ready (struct CadetConnection *cc)
76{ 151{
77 GNUNET_break (0); 152 return ( (NULL != cc->mq) &&
78 return GNUNET_NO; 153 (CADET_CONNECTION_READY == cc->state) &&
154 (NULL == cc->env) ) ? GNUNET_YES : GNUNET_NO;
79} 155}
80 156
81 157
@@ -87,15 +163,193 @@ GCC_is_ready (struct CadetConnection *cc)
87void 163void
88GCC_destroy (struct CadetConnection *cc) 164GCC_destroy (struct CadetConnection *cc)
89{ 165{
166 if (NULL != cc->env)
167 {
168 if (NULL != cc->mq)
169 GNUNET_MQ_send_cancel (cc->env);
170 else
171 GNUNET_MQ_discard (cc->env);
172 cc->env = NULL;
173 }
174 if ( (NULL != cc->mq) &&
175 (CADET_CONNECTION_SENDING_CREATE != cc->state) )
176 {
177 /* Need to notify next hop that we are down. */
178 struct GNUNET_MQ_Envelope *env;
179 struct GNUNET_CADET_ConnectionDestroy *destroy_msg;
180
181 env = GNUNET_MQ_msg (destroy_msg,
182 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY);
183 destroy_msg->cid = cc->cid;
184 GNUNET_MQ_send (cc->mq,
185 env);
186 }
187 cc->mq = NULL;
188 GCP_request_mq_cancel (cc->mq_man);
189 cc->mq_man = NULL;
90 GCPP_del_connection (cc->path, 190 GCPP_del_connection (cc->path,
91 cc->off, 191 cc->off,
92 cc); 192 cc);
93 GNUNET_assert (0); // FIXME: incomplete implementation!
94 GNUNET_free (cc); 193 GNUNET_free (cc);
95} 194}
96 195
97 196
98/** 197/**
198 * Expand the shorter CADET hash to a full GNUnet hash.
199 *
200 * @param id hash to expand
201 * @return expanded hash
202 */
203static const struct GNUNET_HashCode *
204h2hc (const struct GNUNET_CADET_Hash *id)
205{
206 static struct GNUNET_HashCode hc;
207 char *ptr = (char *) &hc;
208
209 GNUNET_assert (sizeof (hc) == 2 * sizeof (*id));
210 GNUNET_memcpy (ptr,
211 id,
212 sizeof (*id));
213 GNUNET_memcpy (&ptr[sizeof (*id)],
214 id,
215 sizeof (*id));
216 return &hc;
217}
218
219
220/**
221 * Get the connection ID as a full hash.
222 *
223 * @param cc Connection to get the ID from.
224 * @return full hash ID of the connection.
225 */
226const struct GNUNET_HashCode *
227GCC_get_h (const struct CadetConnection *cc)
228{
229 return h2hc (&cc->cid.connection_of_tunnel);
230}
231
232
233/**
234 * An ACK was received for this connection, process it.
235 *
236 * @param cc the connection that got the ACK.
237 */
238void
239GCC_handle_ack (struct CadetConnection *cc)
240{
241 GNUNET_SCHEDULER_cancel (cc->task);
242#if FIXME
243 cc->task = GNUNET_SCHEDULER_add_delayed (cc->keepalive_period,
244 &send_keepalive,
245 cc);
246#endif
247 cc->state = CADET_CONNECTION_READY;
248 cc->ready_cb (cc->ready_cb_cls);
249}
250
251
252/**
253 * Send a CREATE message to the first hop.
254 *
255 * @param cls the `struct CadetConnection` to initiate
256 */
257static void
258send_create (void *cls);
259
260
261/**
262 * We finished transmission of the create message, now wait for
263 * ACK or retransmit.
264 *
265 * @param cls the `struct CadetConnection` that sent the create message
266 */
267static void
268transmit_create_done_cb (void *cls)
269{
270 struct CadetConnection *cc = cls;
271
272 cc->state = CADET_CONNECTION_SENT;
273 cc->env = NULL;
274 /* FIXME: at some point, we need to reset the delay back to 0! */
275 cc->retry_delay = GNUNET_TIME_STD_BACKOFF (cc->retry_delay);
276 cc->task = GNUNET_SCHEDULER_add_delayed (cc->retry_delay,
277 &send_create,
278 cc);
279}
280
281
282/**
283 * Send a CREATE message to the first hop.
284 *
285 * @param cls the `struct CadetConnection` to initiate
286 */
287static void
288send_create (void *cls)
289{
290 struct CadetConnection *cc = cls;
291 struct GNUNET_CADET_ConnectionCreate *create_msg;
292 struct GNUNET_PeerIdentity *pids;
293 struct GNUNET_MQ_Envelope *env;
294 unsigned int path_length;
295
296 cc->task = NULL;
297 GNUNET_assert (NULL != cc->mq);
298 path_length = GCPP_get_length (cc->path);
299 env = GNUNET_MQ_msg_extra (create_msg,
300 path_length * sizeof (struct GNUNET_PeerIdentity),
301 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE);
302 create_msg->cid = cc->cid;
303 pids = (struct GNUNET_PeerIdentity *) &create_msg[1];
304 for (unsigned int i=0;i<path_length;i++)
305 pids[i] = *GCP_get_id (GCPP_get_peer_at_offset (cc->path,
306 i));
307 cc->env = env;
308 GNUNET_MQ_notify_sent (env,
309 &transmit_create_done_cb,
310 cc);
311 GNUNET_MQ_send (cc->mq,
312 env);
313}
314
315
316/**
317 * There has been a change in the message queue existence for our
318 * peer at the first hop. Adjust accordingly.
319 *
320 * @param cls the `struct CadetConnection`
321 * @param mq NULL if the CORE connection was lost, non-NULL if
322 * it became available
323 */
324static void
325manage_first_hop_mq (void *cls,
326 struct GNUNET_MQ_Handle *mq)
327{
328 struct CadetConnection *cc = cls;
329
330 if (NULL == mq)
331 {
332 /* Connection is down, for now... */
333 cc->mq = NULL;
334 if (NULL != cc->task)
335 {
336 GNUNET_SCHEDULER_cancel (cc->task);
337 cc->task = NULL;
338 }
339 return;
340 }
341
342 cc->mq = mq;
343 cc->state = CADET_CONNECTION_SENDING_CREATE;
344
345 /* Now repeat sending connection creation messages
346 down the path, until we get an ACK! */
347 cc->task = GNUNET_SCHEDULER_add_now (&send_create,
348 cc);
349}
350
351
352/**
99 * Create a connection to @a destination via @a path and 353 * Create a connection to @a destination via @a path and
100 * notify @a cb whenever we are ready for more data. 354 * notify @a cb whenever we are ready for more data.
101 * 355 *
@@ -103,6 +357,7 @@ GCC_destroy (struct CadetConnection *cc)
103 * @param path which path to take (may not be the full path) 357 * @param path which path to take (may not be the full path)
104 * @param ready_cb function to call when ready to transmit 358 * @param ready_cb function to call when ready to transmit
105 * @param ready_cb_cls closure for @a cb 359 * @param ready_cb_cls closure for @a cb
360 * @return handle to the connection
106 */ 361 */
107struct CadetConnection * 362struct CadetConnection *
108GCC_create (struct CadetPeer *destination, 363GCC_create (struct CadetPeer *destination,
@@ -111,44 +366,82 @@ GCC_create (struct CadetPeer *destination,
111 void *ready_cb_cls) 366 void *ready_cb_cls)
112{ 367{
113 struct CadetConnection *cc; 368 struct CadetConnection *cc;
369 struct CadetPeer *first_hop;
114 unsigned int off; 370 unsigned int off;
115 371
116 off = GCPP_find_peer (path, 372 off = GCPP_find_peer (path,
117 destination); 373 destination);
118 GNUNET_assert (UINT_MAX > off); 374 GNUNET_assert (UINT_MAX > off);
119
120 GNUNET_assert (0); // fIXME: unfinished
121
122 cc = GNUNET_new (struct CadetConnection); 375 cc = GNUNET_new (struct CadetConnection);
376 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
377 &cc->cid,
378 sizeof (cc->cid));
379 GNUNET_assert (GNUNET_OK ==
380 GNUNET_CONTAINER_multihashmap_put (connections,
381 GCC_get_h (cc),
382 cc,
383 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
384 cc->ready_cb = ready_cb;
385 cc->ready_cb_cls = ready_cb_cls;
123 cc->path = path; 386 cc->path = path;
124 cc->off = off; 387 cc->off = off;
125 GCPP_add_connection (path, 388 GCPP_add_connection (path,
126 off, 389 off,
127 cc); 390 cc);
128 for (unsigned int i=0;i<off;i++) 391 for (unsigned int i=0;i<off;i++)
129 { 392 GCP_add_connection (GCPP_get_peer_at_offset (path,
130 // FIXME: remember existence of this connection with 393 off),
131 // ALL peers on the path! 394 cc);
132 // (and remove on destruction of connection!) 395
133 } 396 first_hop = GCPP_get_peer_at_offset (path,
397 0);
398 cc->mq_man = GCP_request_mq (first_hop,
399 &manage_first_hop_mq,
400 cc);
134 return cc; 401 return cc;
135} 402}
136 403
137 404
138/** 405/**
406 * We finished transmission of a message, if we are still ready, tell
407 * the tunnel!
408 *
409 * @param cls our `struct CadetConnection`
410 */
411static void
412transmit_done_cb (void *cls)
413{
414 struct CadetConnection *cc = cls;
415
416 cc->env = NULL;
417 if ( (NULL != cc->mq) &&
418 (CADET_CONNECTION_READY == cc->state) )
419 cc->ready_cb (cc->ready_cb_cls);
420}
421
422
423/**
139 * Transmit message @a msg via connection @a cc. Must only be called 424 * Transmit message @a msg via connection @a cc. Must only be called
140 * (once) after the connection has signalled that it is ready via the 425 * (once) after the connection has signalled that it is ready via the
141 * `ready_cb`. Clients can also use #GCC_is_ready() to check if the 426 * `ready_cb`. Clients can also use #GCC_is_ready() to check if the
142 * connection is right now ready for transmission. 427 * connection is right now ready for transmission.
143 * 428 *
144 * @param cc connection identification 429 * @param cc connection identification
145 * @param msg message to transmit 430 * @param env envelope with message to transmit
146 */ 431 */
147void 432void
148GCC_transmit (struct CadetConnection *cc, 433GCC_transmit (struct CadetConnection *cc,
149 const struct GNUNET_MessageHeader *msg) 434 struct GNUNET_MQ_Envelope *env)
150{ 435{
151 GNUNET_assert (0); // FIXME 436 GNUNET_assert (NULL == cc->env);
437 cc->env = env;
438 GNUNET_MQ_notify_sent (env,
439 &transmit_done_cb,
440 cc);
441 if ( (NULL != cc->mq) &&
442 (CADET_CONNECTION_READY == cc->state) )
443 GNUNET_MQ_send (cc->mq,
444 env);
152} 445}
153 446
154 447
@@ -174,8 +467,7 @@ GCC_get_path (struct CadetConnection *cc)
174const struct GNUNET_CADET_ConnectionTunnelIdentifier * 467const struct GNUNET_CADET_ConnectionTunnelIdentifier *
175GCC_get_id (struct CadetConnection *cc) 468GCC_get_id (struct CadetConnection *cc)
176{ 469{
177 GNUNET_assert (0); // FIXME 470 return &cc->cid;
178 return NULL;
179} 471}
180 472
181 473
@@ -189,4 +481,7 @@ void
189GCC_debug (struct CadetConnection *cc, 481GCC_debug (struct CadetConnection *cc,
190 enum GNUNET_ErrorType level) 482 enum GNUNET_ErrorType level)
191{ 483{
484 GNUNET_break (0); // FIXME: implement...
192} 485}
486
487/* end of gnunet-service-cadet-new_connection.c */
diff --git a/src/cadet/gnunet-service-cadet-new_connection.h b/src/cadet/gnunet-service-cadet-new_connection.h
index c11e34024..c9738d86e 100644
--- a/src/cadet/gnunet-service-cadet-new_connection.h
+++ b/src/cadet/gnunet-service-cadet-new_connection.h
@@ -60,6 +60,7 @@ GCC_destroy (struct CadetConnection *cc);
60 * @param path which path to take (may not be the full path) 60 * @param path which path to take (may not be the full path)
61 * @param ready_cb function to call when ready to transmit 61 * @param ready_cb function to call when ready to transmit
62 * @param ready_cb_cls closure for @a cb 62 * @param ready_cb_cls closure for @a cb
63 * @return handle to the connection
63 */ 64 */
64struct CadetConnection * 65struct CadetConnection *
65GCC_create (struct CadetPeer *destination, 66GCC_create (struct CadetPeer *destination,
@@ -75,11 +76,14 @@ GCC_create (struct CadetPeer *destination,
75 * connection is right now ready for transmission. 76 * connection is right now ready for transmission.
76 * 77 *
77 * @param cc connection identification 78 * @param cc connection identification
78 * @param msg message to transmit 79 * @param env envelope with message to transmit;
80 * the #GNUNET_MQ_notify_send() must not have yet been used
81 * for the envelope. Also, the message better match the
82 * connection identifier of this connection...
79 */ 83 */
80void 84void
81GCC_transmit (struct CadetConnection *cc, 85GCC_transmit (struct CadetConnection *cc,
82 const struct GNUNET_MessageHeader *msg); 86 struct GNUNET_MQ_Envelope *env);
83 87
84 88
85/** 89/**
@@ -103,6 +107,17 @@ GCC_get_id (struct CadetConnection *cc);
103 107
104 108
105/** 109/**
110 * Get the connection ID as a full hash.
111 *
112 * @param cc Connection to get the ID from.
113 * @return full hash ID of the connection.
114 * @deprecated try to replace use of full hash codes eventually...
115 */
116const struct GNUNET_HashCode *
117GCC_get_h (const struct CadetConnection *cc);
118
119
120/**
106 * Log connection info. 121 * Log connection info.
107 * 122 *
108 * @param cc connection 123 * @param cc connection
diff --git a/src/cadet/gnunet-service-cadet-new_peer.c b/src/cadet/gnunet-service-cadet-new_peer.c
index 9878c540e..ed3b24641 100644
--- a/src/cadet/gnunet-service-cadet-new_peer.c
+++ b/src/cadet/gnunet-service-cadet-new_peer.c
@@ -35,6 +35,7 @@
35#include "cadet_protocol.h" 35#include "cadet_protocol.h"
36#include "cadet_path.h" 36#include "cadet_path.h"
37#include "gnunet-service-cadet-new.h" 37#include "gnunet-service-cadet-new.h"
38#include "gnunet-service-cadet-new_connection.h"
38#include "gnunet-service-cadet-new_dht.h" 39#include "gnunet-service-cadet-new_dht.h"
39#include "gnunet-service-cadet-new_peer.h" 40#include "gnunet-service-cadet-new_peer.h"
40#include "gnunet-service-cadet-new_paths.h" 41#include "gnunet-service-cadet-new_paths.h"
@@ -51,6 +52,43 @@
51#define IDLE_PATH_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2) 52#define IDLE_PATH_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2)
52 53
53 54
55
56
57/**
58 * Data structure used to track whom we have to notify about changes
59 * to our message queue.
60 */
61struct GCP_MessageQueueManager
62{
63
64 /**
65 * Kept in a DLL.
66 */
67 struct GCP_MessageQueueManager *next;
68
69 /**
70 * Kept in a DLL.
71 */
72 struct GCP_MessageQueueManager *prev;
73
74 /**
75 * Function to call with updated message queue object.
76 */
77 GCP_MessageQueueNotificationCallback cb;
78
79 /**
80 * Closure for @e cb.
81 */
82 void *cb_cls;
83
84 /**
85 * The peer this is for.
86 */
87 struct CadetPeer *cp;
88
89};
90
91
54/** 92/**
55 * Struct containing all information regarding a given peer 93 * Struct containing all information regarding a given peer
56 */ 94 */
@@ -79,6 +117,16 @@ struct CadetPeer
79 struct CadetPeerPathEntry **path_tails; 117 struct CadetPeerPathEntry **path_tails;
80 118
81 /** 119 /**
120 * Notifications to call when @e core_mq changes.
121 */
122 struct GCP_MessageQueueManager *mqm_head;
123
124 /**
125 * Notifications to call when @e core_mq changes.
126 */
127 struct GCP_MessageQueueManager *mqm_tail;
128
129 /**
82 * MIN-heap of paths owned by this peer (they also end at this 130 * MIN-heap of paths owned by this peer (they also end at this
83 * peer). Ordered by desirability. 131 * peer). Ordered by desirability.
84 */ 132 */
@@ -207,11 +255,35 @@ destroy_peer (void *cls)
207 GNUNET_CONTAINER_multihashmap_destroy (cp->connections); 255 GNUNET_CONTAINER_multihashmap_destroy (cp->connections);
208 GNUNET_CONTAINER_heap_destroy (cp->path_heap); 256 GNUNET_CONTAINER_heap_destroy (cp->path_heap);
209 GNUNET_free_non_null (cp->hello); 257 GNUNET_free_non_null (cp->hello);
258 /* Peer should not be freed if paths exist; if there are no paths,
259 there ought to be no connections, and without connections, no
260 notifications. Thus we can assert that mqm_head is empty at this
261 point. */
262 GNUNET_assert (NULL == cp->mqm_head);
210 GNUNET_free (cp); 263 GNUNET_free (cp);
211} 264}
212 265
213 266
214/** 267/**
268 * Set the message queue to @a mq for peer @a cp and notify watchers.
269 *
270 * @param cp peer to modify
271 * @param mq message queue to set (can be NULL)
272 */
273void
274GCP_set_mq (struct CadetPeer *cp,
275 struct GNUNET_MQ_Handle *mq)
276{
277 cp->core_mq = mq;
278 for (struct GCP_MessageQueueManager *mqm = cp->mqm_head;
279 NULL != mqm;
280 mqm = mqm->next)
281 mqm->cb (mqm->cb_cls,
282 mq);
283}
284
285
286/**
215 * Function called to destroy a peer now. 287 * Function called to destroy a peer now.
216 * 288 *
217 * @param cls NULL 289 * @param cls NULL
@@ -465,6 +537,41 @@ GCP_detach_path (struct CadetPeer *cp,
465 537
466 538
467/** 539/**
540 * Add a @a connection to this @a cp.
541 *
542 * @param cp peer via which the @a connection goes
543 * @param cc the connection to add
544 */
545void
546GCP_add_connection (struct CadetPeer *cp,
547 struct CadetConnection *cc)
548{
549 GNUNET_assert (GNUNET_OK ==
550 GNUNET_CONTAINER_multihashmap_put (cp->connections,
551 GCC_get_h (cc),
552 cc,
553 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
554}
555
556
557/**
558 * Remove a @a connection that went via this @a cp.
559 *
560 * @param cp peer via which the @a connection went
561 * @param cc the connection to remove
562 */
563void
564GCP_remove_connection (struct CadetPeer *cp,
565 struct CadetConnection *cc)
566{
567 GNUNET_assert (GNUNET_YES ==
568 GNUNET_CONTAINER_multihashmap_remove (cp->connections,
569 GCC_get_h (cc),
570 cc));
571}
572
573
574/**
468 * This peer is now on more "active" duty, activate processes related to it. 575 * This peer is now on more "active" duty, activate processes related to it.
469 * 576 *
470 * @param cp the more-active peer 577 * @param cp the more-active peer
@@ -728,4 +835,51 @@ GCP_drop_tunnel (struct CadetPeer *peer,
728} 835}
729 836
730 837
838/**
839 * Start message queue change notifications.
840 *
841 * @param cp peer to notify for
842 * @param cb function to call if mq becomes available or unavailable
843 * @param cb_cls closure for @a cb
844 * @return handle to cancel request
845 */
846struct GCP_MessageQueueManager *
847GCP_request_mq (struct CadetPeer *cp,
848 GCP_MessageQueueNotificationCallback cb,
849 void *cb_cls)
850{
851 struct GCP_MessageQueueManager *mqm;
852
853 mqm = GNUNET_new (struct GCP_MessageQueueManager);
854 mqm->cb = cb;
855 mqm->cb_cls = cb_cls;
856 mqm->cp = cp;
857 GNUNET_CONTAINER_DLL_insert (cp->mqm_head,
858 cp->mqm_tail,
859 mqm);
860 if (NULL != cp->core_mq)
861 cb (cb_cls,
862 cp->core_mq);
863 return mqm;
864}
865
866
867/**
868 * Stops message queue change notifications.
869 *
870 * @param mqm handle matching request to cancel
871 */
872void
873GCP_request_mq_cancel (struct GCP_MessageQueueManager *mqm)
874{
875 struct CadetPeer *cp = mqm->cp;
876
877 GNUNET_CONTAINER_DLL_remove (cp->mqm_head,
878 cp->mqm_tail,
879 mqm);
880 GNUNET_free (mqm);
881}
882
883
884
731/* end of gnunet-service-cadet-new_peer.c */ 885/* end of gnunet-service-cadet-new_peer.c */
diff --git a/src/cadet/gnunet-service-cadet-new_peer.h b/src/cadet/gnunet-service-cadet-new_peer.h
index 780640674..74988981f 100644
--- a/src/cadet/gnunet-service-cadet-new_peer.h
+++ b/src/cadet/gnunet-service-cadet-new_peer.h
@@ -218,6 +218,28 @@ GCP_detach_path (struct CadetPeer *cp,
218 218
219 219
220/** 220/**
221 * Add a @a connection to this @a cp.
222 *
223 * @param cp peer via which the @a connection goes
224 * @param cc the connection to add
225 */
226void
227GCP_add_connection (struct CadetPeer *cp,
228 struct CadetConnection *cc);
229
230
231/**
232 * Remove a @a connection that went via this @a cp.
233 *
234 * @param cp peer via which the @a connection went
235 * @param cc the connection to remove
236 */
237void
238GCP_remove_connection (struct CadetPeer *cp,
239 struct CadetConnection *cc);
240
241
242/**
221 * We got a HELLO for a @a cp, remember it, and possibly 243 * We got a HELLO for a @a cp, remember it, and possibly
222 * trigger adequate actions (like trying to connect). 244 * trigger adequate actions (like trying to connect).
223 * 245 *
@@ -238,4 +260,56 @@ void
238GCP_destroy_all_peers (void); 260GCP_destroy_all_peers (void);
239 261
240 262
263/**
264 * Data structure used to track whom we have to notify about changes
265 * to our message queue.
266 */
267struct GCP_MessageQueueManager;
268
269
270/**
271 * Function to call with updated message queue object.
272 *
273 * @param cls closure
274 * @param mq NULL if MQ is gone, otherwise an active message queue
275 */
276typedef void
277(*GCP_MessageQueueNotificationCallback)(void *cls,
278 struct GNUNET_MQ_Handle *mq);
279
280
281/**
282 * Start message queue change notifications.
283 *
284 * @param cp peer to notify for
285 * @param cb function to call if mq becomes available or unavailable
286 * @param cb_cls closure for @a cb
287 * @return handle to cancel request
288 */
289struct GCP_MessageQueueManager *
290GCP_request_mq (struct CadetPeer *cp,
291 GCP_MessageQueueNotificationCallback cb,
292 void *cb_cls);
293
294
295/**
296 * Stops message queue change notifications.
297 *
298 * @param mqm handle matching request to cancel
299 */
300void
301GCP_request_mq_cancel (struct GCP_MessageQueueManager *mqm);
302
303
304/**
305 * Set the message queue to @a mq for peer @a cp and notify watchers.
306 *
307 * @param cp peer to modify
308 * @param mq message queue to set (can be NULL)
309 */
310void
311GCP_set_mq (struct CadetPeer *cp,
312 struct GNUNET_MQ_Handle *mq);
313
314
241#endif 315#endif
diff --git a/src/cadet/gnunet-service-cadet-new_tunnels.c b/src/cadet/gnunet-service-cadet-new_tunnels.c
index 1a07140f2..18c469b67 100644
--- a/src/cadet/gnunet-service-cadet-new_tunnels.c
+++ b/src/cadet/gnunet-service-cadet-new_tunnels.c
@@ -268,9 +268,9 @@ struct CadetTunnelQueueEntry
268 void *cont_cls; 268 void *cont_cls;
269 269
270 /** 270 /**
271 * (Encrypted) message to send follows. 271 * Envelope of message to send follows.
272 */ 272 */
273 /* struct GNUNET_MessageHeader *msg; */ 273 struct GNUNET_MQ_Envelope *env;
274}; 274};
275 275
276 276
@@ -533,7 +533,7 @@ destroy_tunnel (void *cls)
533 GNUNET_CONTAINER_DLL_remove (t->tq_head, 533 GNUNET_CONTAINER_DLL_remove (t->tq_head,
534 t->tq_tail, 534 t->tq_tail,
535 tqe); 535 tqe);
536 // FIXME: implement! 536 GNUNET_MQ_discard (tqe->env);
537 GNUNET_free (tqe); 537 GNUNET_free (tqe);
538 } 538 }
539 GCP_drop_tunnel (t->destination, 539 GCP_drop_tunnel (t->destination,
@@ -570,7 +570,7 @@ connection_ready_cb (void *cls)
570 t->tq_tail, 570 t->tq_tail,
571 tq); 571 tq);
572 GCC_transmit (ct->cc, 572 GCC_transmit (ct->cc,
573 (const struct GNUNET_MessageHeader *) &tq[1]); 573 tq->env);
574 tq->cont (tq->cont_cls); 574 tq->cont (tq->cont_cls);
575 GNUNET_free (tq); 575 GNUNET_free (tq);
576} 576}
@@ -693,12 +693,13 @@ consider_path_cb (void *cls,
693 ct->created = GNUNET_TIME_absolute_get (); 693 ct->created = GNUNET_TIME_absolute_get ();
694 ct->t = t; 694 ct->t = t;
695 ct->cc = GCC_create (t->destination, 695 ct->cc = GCC_create (t->destination,
696 path, 696 path,
697 &connection_ready_cb, 697 &connection_ready_cb,
698 t); 698 t);
699 /* FIXME: schedule job to kill connection (and path?) if it takes 699 /* FIXME: schedule job to kill connection (and path?) if it takes
700 too long to get ready! (And track performance data on how long 700 too long to get ready! (And track performance data on how long
701 other connections took with the tunnel!) */ 701 other connections took with the tunnel!)
702 => Note: to be done within 'connection'-logic! */
702 GNUNET_CONTAINER_DLL_insert (t->connection_head, 703 GNUNET_CONTAINER_DLL_insert (t->connection_head,
703 t->connection_tail, 704 t->connection_tail,
704 ct); 705 ct);
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c
index e727ef199..ffd98bf34 100644
--- a/src/cadet/gnunet-service-cadet_connection.c
+++ b/src/cadet/gnunet-service-cadet_connection.c
@@ -218,7 +218,7 @@ struct CadetConnection
218 /** 218 /**
219 * ID of the connection. 219 * ID of the connection.
220 */ 220 */
221 struct GNUNET_CADET_Hash id; 221 struct GNUNET_CADET_ConnectionTunnelIdentifier id;
222 222
223 /** 223 /**
224 * Path being used for the tunnel. At the origin of the connection 224 * Path being used for the tunnel. At the origin of the connection
@@ -1100,7 +1100,7 @@ send_broken (struct CadetConnection *c,
1100 * @param neighbor Peer to notify (neighbor who sent the connection). 1100 * @param neighbor Peer to notify (neighbor who sent the connection).
1101 */ 1101 */
1102static void 1102static void
1103send_broken_unknown (const struct GNUNET_CADET_Hash *connection_id, 1103send_broken_unknown (const struct GNUNET_CADET_ConnectionTunnelIdentifier *connection_id,
1104 const struct GNUNET_PeerIdentity *id1, 1104 const struct GNUNET_PeerIdentity *id1,
1105 const struct GNUNET_PeerIdentity *id2, 1105 const struct GNUNET_PeerIdentity *id2,
1106 struct CadetPeer *neighbor) 1106 struct CadetPeer *neighbor)
@@ -1836,7 +1836,7 @@ add_to_peer (struct CadetConnection *c,
1836static void 1836static void
1837log_message (const struct GNUNET_MessageHeader *message, 1837log_message (const struct GNUNET_MessageHeader *message,
1838 const struct CadetPeer *peer, 1838 const struct CadetPeer *peer,
1839 const struct GNUNET_CADET_Hash *conn_id) 1839 const struct GNUNET_CADET_ConnectionTunnelIdentifier *conn_id)
1840{ 1840{
1841 uint16_t size; 1841 uint16_t size;
1842 uint16_t type; 1842 uint16_t type;
@@ -1874,7 +1874,7 @@ void
1874GCC_handle_create (struct CadetPeer *peer, 1874GCC_handle_create (struct CadetPeer *peer,
1875 const struct GNUNET_CADET_ConnectionCreate *msg) 1875 const struct GNUNET_CADET_ConnectionCreate *msg)
1876{ 1876{
1877 const struct GNUNET_CADET_Hash *cid; 1877 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid;
1878 struct GNUNET_PeerIdentity *id; 1878 struct GNUNET_PeerIdentity *id;
1879 struct CadetPeerPath *path; 1879 struct CadetPeerPath *path;
1880 struct CadetPeer *dest_peer; 1880 struct CadetPeer *dest_peer;
@@ -2409,7 +2409,7 @@ GCC_handle_poll (struct CadetPeer *peer,
2409 */ 2409 */
2410static int 2410static int
2411check_message (const struct GNUNET_MessageHeader *message, 2411check_message (const struct GNUNET_MessageHeader *message,
2412 const struct GNUNET_CADET_Hash* cid, 2412 const struct GNUNET_CADET_ConnectionTunnelIdentifier* cid,
2413 struct CadetConnection *c, 2413 struct CadetConnection *c,
2414 struct CadetPeer *sender, 2414 struct CadetPeer *sender,
2415 uint32_t pid) 2415 uint32_t pid)
@@ -2534,7 +2534,7 @@ void
2534GCC_handle_kx (struct CadetPeer *peer, 2534GCC_handle_kx (struct CadetPeer *peer,
2535 const struct GNUNET_CADET_KX *msg) 2535 const struct GNUNET_CADET_KX *msg)
2536{ 2536{
2537 const struct GNUNET_CADET_Hash* cid; 2537 const struct GNUNET_CADET_ConnectionTunnelIdentifier* cid;
2538 struct CadetConnection *c; 2538 struct CadetConnection *c;
2539 int fwd; 2539 int fwd;
2540 2540
@@ -2591,7 +2591,7 @@ void
2591GCC_handle_encrypted (struct CadetPeer *peer, 2591GCC_handle_encrypted (struct CadetPeer *peer,
2592 const struct GNUNET_CADET_Encrypted *msg) 2592 const struct GNUNET_CADET_Encrypted *msg)
2593{ 2593{
2594 const struct GNUNET_CADET_Hash* cid; 2594 const struct GNUNET_CADET_ConnectionTunnelIdentifier* cid;
2595 struct CadetConnection *c; 2595 struct CadetConnection *c;
2596 uint32_t pid; 2596 uint32_t pid;
2597 int fwd; 2597 int fwd;
@@ -2734,7 +2734,7 @@ GCC_shutdown (void)
2734 * NULL in case of error: own id not in path, wrong neighbors, ... 2734 * NULL in case of error: own id not in path, wrong neighbors, ...
2735*/ 2735*/
2736struct CadetConnection * 2736struct CadetConnection *
2737GCC_new (const struct GNUNET_CADET_Hash *cid, 2737GCC_new (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
2738 struct CadetTunnel *t, 2738 struct CadetTunnel *t,
2739 struct CadetPeerPath *path, 2739 struct CadetPeerPath *path,
2740 unsigned int own_pos) 2740 unsigned int own_pos)
@@ -2871,7 +2871,7 @@ GCC_destroy (struct CadetConnection *c)
2871 * 2871 *
2872 * @return ID of the connection. 2872 * @return ID of the connection.
2873 */ 2873 */
2874const struct GNUNET_CADET_Hash * 2874const struct GNUNET_CADET_ConnectionTunnelIdentifier *
2875GCC_get_id (const struct CadetConnection *c) 2875GCC_get_id (const struct CadetConnection *c)
2876{ 2876{
2877 return &c->id; 2877 return &c->id;
diff --git a/src/cadet/gnunet-service-cadet_connection.h b/src/cadet/gnunet-service-cadet_connection.h
index 18f33ce7c..f1eb4d59c 100644
--- a/src/cadet/gnunet-service-cadet_connection.h
+++ b/src/cadet/gnunet-service-cadet_connection.h
@@ -277,7 +277,7 @@ GCC_shutdown (void);
277 * NULL in case of error: own id not in path, wrong neighbors, ... 277 * NULL in case of error: own id not in path, wrong neighbors, ...
278 */ 278 */
279struct CadetConnection * 279struct CadetConnection *
280GCC_new (const struct GNUNET_CADET_Hash *cid, 280GCC_new (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
281 struct CadetTunnel *t, 281 struct CadetTunnel *t,
282 struct CadetPeerPath *path, 282 struct CadetPeerPath *path,
283 unsigned int own_pos); 283 unsigned int own_pos);
@@ -300,7 +300,7 @@ GCC_destroy (struct CadetConnection *c);
300 * 300 *
301 * @return ID of the connection. 301 * @return ID of the connection.
302 */ 302 */
303const struct GNUNET_CADET_Hash * 303const struct GNUNET_CADET_ConnectionTunnelIdentifier *
304GCC_get_id (const struct CadetConnection *c); 304GCC_get_id (const struct CadetConnection *c);
305 305
306 306
diff --git a/src/cadet/gnunet-service-cadet_local.c b/src/cadet/gnunet-service-cadet_local.c
index 743fbf054..6e6313902 100644
--- a/src/cadet/gnunet-service-cadet_local.c
+++ b/src/cadet/gnunet-service-cadet_local.c
@@ -965,8 +965,9 @@ static void
965iter_connection (void *cls, struct CadetConnection *c) 965iter_connection (void *cls, struct CadetConnection *c)
966{ 966{
967 struct GNUNET_CADET_LocalInfoTunnel *msg = cls; 967 struct GNUNET_CADET_LocalInfoTunnel *msg = cls;
968 struct GNUNET_CADET_Hash *h = (struct GNUNET_CADET_Hash *) &msg[1]; 968 struct GNUNET_CADET_ConnectionTunnelIdentifier *h;
969 969
970 h = (struct GNUNET_CADET_ConnectionTunnelIdentifier *) &msg[1];
970 h[msg->connections] = *(GCC_get_id (c)); 971 h[msg->connections] = *(GCC_get_id (c));
971 msg->connections++; 972 msg->connections++;
972} 973}
diff --git a/src/cadet/gnunet-service-cadet_tunnel.c b/src/cadet/gnunet-service-cadet_tunnel.c
index 2e17774d4..29087dba4 100644
--- a/src/cadet/gnunet-service-cadet_tunnel.c
+++ b/src/cadet/gnunet-service-cadet_tunnel.c
@@ -1406,7 +1406,7 @@ send_prebuilt_message (const struct GNUNET_MessageHeader *message,
1406 "Sending message of type %s with PID %u and CID %s\n", 1406 "Sending message of type %s with PID %u and CID %s\n",
1407 GC_m2s (type), 1407 GC_m2s (type),
1408 htonl (ax_msg->pid), 1408 htonl (ax_msg->pid),
1409 GC_h2s (&ax_msg->cid)); 1409 GC_h2s (&ax_msg->cid.connection_of_tunnel));
1410 1410
1411 if (NULL == cont) 1411 if (NULL == cont)
1412 { 1412 {
@@ -2744,7 +2744,7 @@ struct CadetConnection *
2744GCT_use_path (struct CadetTunnel *t, struct CadetPeerPath *path) 2744GCT_use_path (struct CadetTunnel *t, struct CadetPeerPath *path)
2745{ 2745{
2746 struct CadetConnection *c; 2746 struct CadetConnection *c;
2747 struct GNUNET_CADET_Hash cid; 2747 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
2748 unsigned int own_pos; 2748 unsigned int own_pos;
2749 2749
2750 if (NULL == t || NULL == path) 2750 if (NULL == t || NULL == path)