aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/gnunet-service-cadet_core.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cadet/gnunet-service-cadet_core.c')
-rw-r--r--src/cadet/gnunet-service-cadet_core.c1164
1 files changed, 579 insertions, 585 deletions
diff --git a/src/cadet/gnunet-service-cadet_core.c b/src/cadet/gnunet-service-cadet_core.c
index ec70a968b..a08c80aae 100644
--- a/src/cadet/gnunet-service-cadet_core.c
+++ b/src/cadet/gnunet-service-cadet_core.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file cadet/gnunet-service-cadet_core.c 22 * @file cadet/gnunet-service-cadet_core.c
@@ -39,7 +39,7 @@
39#include "gnunet_statistics_service.h" 39#include "gnunet_statistics_service.h"
40#include "cadet_protocol.h" 40#include "cadet_protocol.h"
41 41
42#define LOG(level, ...) GNUNET_log_from (level, "cadet-cor", __VA_ARGS__) 42#define LOG(level, ...) GNUNET_log_from(level, "cadet-cor", __VA_ARGS__)
43 43
44/** 44/**
45 * Information we keep per direction for a route. 45 * Information we keep per direction for a route.
@@ -52,9 +52,7 @@ struct RouteDirection;
52 * routes that have the current maximum of messages in the buffer (in 52 * routes that have the current maximum of messages in the buffer (in
53 * case we have to purge). 53 * case we have to purge).
54 */ 54 */
55struct Rung 55struct Rung {
56{
57
58 /** 56 /**
59 * Rung of RouteDirections with one more buffer entry each. 57 * Rung of RouteDirections with one more buffer entry each.
60 */ 58 */
@@ -91,9 +89,7 @@ struct Rung
91/** 89/**
92 * Information we keep per direction for a route. 90 * Information we keep per direction for a route.
93 */ 91 */
94struct RouteDirection 92struct RouteDirection {
95{
96
97 /** 93 /**
98 * DLL of other route directions within the same `struct Rung`. 94 * DLL of other route directions within the same `struct Rung`.
99 */ 95 */
@@ -149,9 +145,7 @@ struct RouteDirection
149 * the complete `struct CadetPath` that is formed by the individual 145 * the complete `struct CadetPath` that is formed by the individual
150 * routes. 146 * routes.
151 */ 147 */
152struct CadetRoute 148struct CadetRoute {
153{
154
155 /** 149 /**
156 * Information about the next hop on this route. 150 * Information about the next hop on this route.
157 */ 151 */
@@ -237,10 +231,10 @@ static struct GNUNET_SCHEDULER_Task *timeout_task;
237 * @param cid hash generated from the connection identifier 231 * @param cid hash generated from the connection identifier
238 */ 232 */
239static struct CadetRoute * 233static struct CadetRoute *
240get_route (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) 234get_route(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
241{ 235{
242 return GNUNET_CONTAINER_multishortmap_get (routes, 236 return GNUNET_CONTAINER_multishortmap_get(routes,
243 &cid->connection_of_tunnel); 237 &cid->connection_of_tunnel);
244} 238}
245 239
246 240
@@ -250,22 +244,22 @@ get_route (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
250 * @param dir direction to lower in rung. 244 * @param dir direction to lower in rung.
251 */ 245 */
252static void 246static void
253lower_rung (struct RouteDirection *dir) 247lower_rung(struct RouteDirection *dir)
254{ 248{
255 struct Rung *rung = dir->rung; 249 struct Rung *rung = dir->rung;
256 struct Rung *prev; 250 struct Rung *prev;
257 251
258 GNUNET_CONTAINER_DLL_remove (rung->rd_head, rung->rd_tail, dir); 252 GNUNET_CONTAINER_DLL_remove(rung->rd_head, rung->rd_tail, dir);
259 prev = rung->prev; 253 prev = rung->prev;
260 GNUNET_assert (NULL != prev); 254 GNUNET_assert(NULL != prev);
261 if (prev->rung_off != rung->rung_off - 1) 255 if (prev->rung_off != rung->rung_off - 1)
262 { 256 {
263 prev = GNUNET_new (struct Rung); 257 prev = GNUNET_new(struct Rung);
264 prev->rung_off = rung->rung_off - 1; 258 prev->rung_off = rung->rung_off - 1;
265 GNUNET_CONTAINER_DLL_insert_after (rung_head, rung_tail, rung->prev, prev); 259 GNUNET_CONTAINER_DLL_insert_after(rung_head, rung_tail, rung->prev, prev);
266 } 260 }
267 GNUNET_assert (NULL != prev); 261 GNUNET_assert(NULL != prev);
268 GNUNET_CONTAINER_DLL_insert (prev->rd_head, prev->rd_tail, dir); 262 GNUNET_CONTAINER_DLL_insert(prev->rd_head, prev->rd_tail, dir);
269 dir->rung = prev; 263 dir->rung = prev;
270} 264}
271 265
@@ -278,13 +272,13 @@ lower_rung (struct RouteDirection *dir)
278 * @param env envelope to discard 272 * @param env envelope to discard
279 */ 273 */
280static void 274static void
281discard_buffer (struct RouteDirection *dir, struct GNUNET_MQ_Envelope *env) 275discard_buffer(struct RouteDirection *dir, struct GNUNET_MQ_Envelope *env)
282{ 276{
283 GNUNET_MQ_dll_remove (&dir->env_head, &dir->env_tail, env); 277 GNUNET_MQ_dll_remove(&dir->env_head, &dir->env_tail, env);
284 cur_buffers--; 278 cur_buffers--;
285 GNUNET_MQ_discard (env); 279 GNUNET_MQ_discard(env);
286 lower_rung (dir); 280 lower_rung(dir);
287 GNUNET_STATISTICS_set (stats, "# buffer use", cur_buffers, GNUNET_NO); 281 GNUNET_STATISTICS_set(stats, "# buffer use", cur_buffers, GNUNET_NO);
288} 282}
289 283
290 284
@@ -292,24 +286,24 @@ discard_buffer (struct RouteDirection *dir, struct GNUNET_MQ_Envelope *env)
292 * Discard all messages from the highest rung, to make space. 286 * Discard all messages from the highest rung, to make space.
293 */ 287 */
294static void 288static void
295discard_all_from_rung_tail () 289discard_all_from_rung_tail()
296{ 290{
297 struct Rung *tail = rung_tail; 291 struct Rung *tail = rung_tail;
298 struct RouteDirection *dir; 292 struct RouteDirection *dir;
299 293
300 while (NULL != (dir = tail->rd_head)) 294 while (NULL != (dir = tail->rd_head))
301 { 295 {
302 LOG (GNUNET_ERROR_TYPE_DEBUG, 296 LOG(GNUNET_ERROR_TYPE_DEBUG,
303 "Queue full due new message %s on connection %s, dropping old message\n", 297 "Queue full due new message %s on connection %s, dropping old message\n",
304 GNUNET_sh2s (&dir->my_route->cid.connection_of_tunnel)); 298 GNUNET_sh2s(&dir->my_route->cid.connection_of_tunnel));
305 GNUNET_STATISTICS_update (stats, 299 GNUNET_STATISTICS_update(stats,
306 "# messages dropped due to full buffer", 300 "# messages dropped due to full buffer",
307 1, 301 1,
308 GNUNET_NO); 302 GNUNET_NO);
309 discard_buffer (dir, dir->env_head); 303 discard_buffer(dir, dir->env_head);
310 } 304 }
311 GNUNET_CONTAINER_DLL_remove (rung_head, rung_tail, tail); 305 GNUNET_CONTAINER_DLL_remove(rung_head, rung_tail, tail);
312 GNUNET_free (tail); 306 GNUNET_free(tail);
313} 307}
314 308
315 309
@@ -323,10 +317,10 @@ discard_all_from_rung_tail ()
323 * @param msg the message to forward 317 * @param msg the message to forward
324 */ 318 */
325static void 319static void
326route_message (struct CadetPeer *prev, 320route_message(struct CadetPeer *prev,
327 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, 321 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
328 const struct GNUNET_MessageHeader *msg, 322 const struct GNUNET_MessageHeader *msg,
329 const enum GNUNET_MQ_PriorityPreferences priority) 323 const enum GNUNET_MQ_PriorityPreferences priority)
330{ 324{
331 struct CadetRoute *route; 325 struct CadetRoute *route;
332 struct RouteDirection *dir; 326 struct RouteDirection *dir;
@@ -334,133 +328,133 @@ route_message (struct CadetPeer *prev,
334 struct Rung *nxt; 328 struct Rung *nxt;
335 struct GNUNET_MQ_Envelope *env; 329 struct GNUNET_MQ_Envelope *env;
336 330
337 route = get_route (cid); 331 route = get_route(cid);
338 if (NULL == route) 332 if (NULL == route)
339 {
340 struct GNUNET_MQ_Envelope *env;
341 struct GNUNET_CADET_ConnectionBrokenMessage *bm;
342
343 LOG (GNUNET_ERROR_TYPE_DEBUG,
344 "Failed to route message of type %u from %s on connection %s: no route\n",
345 ntohs (msg->type),
346 GCP_2s (prev),
347 GNUNET_sh2s (&cid->connection_of_tunnel));
348 switch (ntohs (msg->type))
349 { 333 {
350 case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY: 334 struct GNUNET_MQ_Envelope *env;
351 case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN: 335 struct GNUNET_CADET_ConnectionBrokenMessage *bm;
352 /* No need to respond to these! */ 336
337 LOG(GNUNET_ERROR_TYPE_DEBUG,
338 "Failed to route message of type %u from %s on connection %s: no route\n",
339 ntohs(msg->type),
340 GCP_2s(prev),
341 GNUNET_sh2s(&cid->connection_of_tunnel));
342 switch (ntohs(msg->type))
343 {
344 case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY:
345 case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN:
346 /* No need to respond to these! */
347 return;
348 }
349 env = GNUNET_MQ_msg(bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN);
350 bm->cid = *cid;
351 bm->peer1 = my_full_id;
352 GCP_send_ooo(prev, env);
353 return; 353 return;
354 } 354 }
355 env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); 355 route->last_use = GNUNET_TIME_absolute_get();
356 bm->cid = *cid; 356 GNUNET_CONTAINER_heap_update_cost(route->hn, route->last_use.abs_value_us);
357 bm->peer1 = my_full_id;
358 GCP_send_ooo (prev, env);
359 return;
360 }
361 route->last_use = GNUNET_TIME_absolute_get ();
362 GNUNET_CONTAINER_heap_update_cost (route->hn, route->last_use.abs_value_us);
363 dir = (prev == route->prev.hop) ? &route->next : &route->prev; 357 dir = (prev == route->prev.hop) ? &route->next : &route->prev;
364 if (GNUNET_YES == dir->is_ready) 358 if (GNUNET_YES == dir->is_ready)
365 { 359 {
366 LOG (GNUNET_ERROR_TYPE_DEBUG, 360 LOG(GNUNET_ERROR_TYPE_DEBUG,
367 "Routing message of type %u from %s to %s on connection %s\n", 361 "Routing message of type %u from %s to %s on connection %s\n",
368 ntohs (msg->type), 362 ntohs(msg->type),
369 GCP_2s (prev), 363 GCP_2s(prev),
370 GNUNET_i2s (GCP_get_id (dir->hop)), 364 GNUNET_i2s(GCP_get_id(dir->hop)),
371 GNUNET_sh2s (&cid->connection_of_tunnel)); 365 GNUNET_sh2s(&cid->connection_of_tunnel));
372 dir->is_ready = GNUNET_NO; 366 dir->is_ready = GNUNET_NO;
373 GCP_send (dir->mqm, GNUNET_MQ_msg_copy (msg)); 367 GCP_send(dir->mqm, GNUNET_MQ_msg_copy(msg));
374 return; 368 return;
375 } 369 }
376 /* Check if low latency is required and if the previous message was 370 /* Check if low latency is required and if the previous message was
377 unreliable; if so, make sure we only queue one message per 371 unreliable; if so, make sure we only queue one message per
378 direction (no buffering). */ 372 direction (no buffering). */
379 if ((0 != (priority & GNUNET_MQ_PREF_LOW_LATENCY)) && 373 if ((0 != (priority & GNUNET_MQ_PREF_LOW_LATENCY)) &&
380 (NULL != dir->env_head) && 374 (NULL != dir->env_head) &&
381 (0 == 375 (0 ==
382 (GNUNET_MQ_env_get_options (dir->env_head) & GNUNET_MQ_PREF_UNRELIABLE))) 376 (GNUNET_MQ_env_get_options(dir->env_head) & GNUNET_MQ_PREF_UNRELIABLE)))
383 discard_buffer (dir, dir->env_head); 377 discard_buffer(dir, dir->env_head);
384 /* Check for duplicates */ 378 /* Check for duplicates */
385 for (const struct GNUNET_MQ_Envelope *env = dir->env_head; NULL != env; 379 for (const struct GNUNET_MQ_Envelope *env = dir->env_head; NULL != env;
386 env = GNUNET_MQ_env_next (env)) 380 env = GNUNET_MQ_env_next(env))
387 {
388 const struct GNUNET_MessageHeader *hdr = GNUNET_MQ_env_get_msg (env);
389
390 if ((hdr->size == msg->size) && (0 == memcmp (hdr, msg, ntohs (msg->size))))
391 { 381 {
392 LOG (GNUNET_ERROR_TYPE_DEBUG, 382 const struct GNUNET_MessageHeader *hdr = GNUNET_MQ_env_get_msg(env);
393 "Received duplicate of message already in buffer, dropping\n"); 383
394 GNUNET_STATISTICS_update (stats, 384 if ((hdr->size == msg->size) && (0 == memcmp(hdr, msg, ntohs(msg->size))))
395 "# messages dropped due to duplicate in buffer", 385 {
396 1, 386 LOG(GNUNET_ERROR_TYPE_DEBUG,
397 GNUNET_NO); 387 "Received duplicate of message already in buffer, dropping\n");
398 return; 388 GNUNET_STATISTICS_update(stats,
389 "# messages dropped due to duplicate in buffer",
390 1,
391 GNUNET_NO);
392 return;
393 }
399 } 394 }
400 }
401 395
402 rung = dir->rung; 396 rung = dir->rung;
403 if (cur_buffers == max_buffers) 397 if (cur_buffers == max_buffers)
404 {
405 /* Need to make room. */
406 if (NULL != rung->next)
407 {
408 /* Easy case, drop messages from route directions in highest rung */
409 discard_all_from_rung_tail ();
410 }
411 else
412 { 398 {
413 /* We are in the highest rung, drop our own! */ 399 /* Need to make room. */
414 LOG (GNUNET_ERROR_TYPE_DEBUG, 400 if (NULL != rung->next)
415 "Queue full due new message %s on connection %s, dropping old message\n", 401 {
416 GNUNET_sh2s (&dir->my_route->cid.connection_of_tunnel)); 402 /* Easy case, drop messages from route directions in highest rung */
417 GNUNET_STATISTICS_update (stats, 403 discard_all_from_rung_tail();
418 "# messages dropped due to full buffer", 404 }
419 1, 405 else
420 GNUNET_NO); 406 {
421 discard_buffer (dir, dir->env_head); 407 /* We are in the highest rung, drop our own! */
422 rung = dir->rung; 408 LOG(GNUNET_ERROR_TYPE_DEBUG,
409 "Queue full due new message %s on connection %s, dropping old message\n",
410 GNUNET_sh2s(&dir->my_route->cid.connection_of_tunnel));
411 GNUNET_STATISTICS_update(stats,
412 "# messages dropped due to full buffer",
413 1,
414 GNUNET_NO);
415 discard_buffer(dir, dir->env_head);
416 rung = dir->rung;
417 }
423 } 418 }
424 }
425 /* remove 'dir' from current rung */ 419 /* remove 'dir' from current rung */
426 GNUNET_CONTAINER_DLL_remove (rung->rd_head, rung->rd_tail, dir); 420 GNUNET_CONTAINER_DLL_remove(rung->rd_head, rung->rd_tail, dir);
427 /* make 'nxt' point to the next higher rung, create if necessary */ 421 /* make 'nxt' point to the next higher rung, create if necessary */
428 nxt = rung->next; 422 nxt = rung->next;
429 if ((NULL == nxt) || (rung->rung_off + 1 != nxt->rung_off)) 423 if ((NULL == nxt) || (rung->rung_off + 1 != nxt->rung_off))
430 { 424 {
431 nxt = GNUNET_new (struct Rung); 425 nxt = GNUNET_new(struct Rung);
432 nxt->rung_off = rung->rung_off + 1; 426 nxt->rung_off = rung->rung_off + 1;
433 GNUNET_CONTAINER_DLL_insert_after (rung_head, rung_tail, rung, nxt); 427 GNUNET_CONTAINER_DLL_insert_after(rung_head, rung_tail, rung, nxt);
434 } 428 }
435 /* insert 'dir' into next higher rung */ 429 /* insert 'dir' into next higher rung */
436 GNUNET_CONTAINER_DLL_insert (nxt->rd_head, nxt->rd_tail, dir); 430 GNUNET_CONTAINER_DLL_insert(nxt->rd_head, nxt->rd_tail, dir);
437 dir->rung = nxt; 431 dir->rung = nxt;
438 432
439 /* add message into 'dir' buffer */ 433 /* add message into 'dir' buffer */
440 LOG (GNUNET_ERROR_TYPE_DEBUG, 434 LOG(GNUNET_ERROR_TYPE_DEBUG,
441 "Queueing new message of type %u from %s to %s on connection %s\n", 435 "Queueing new message of type %u from %s to %s on connection %s\n",
442 ntohs (msg->type), 436 ntohs(msg->type),
443 GCP_2s (prev), 437 GCP_2s(prev),
444 GNUNET_i2s (GCP_get_id (dir->hop)), 438 GNUNET_i2s(GCP_get_id(dir->hop)),
445 GNUNET_sh2s (&cid->connection_of_tunnel)); 439 GNUNET_sh2s(&cid->connection_of_tunnel));
446 env = GNUNET_MQ_msg_copy (msg); 440 env = GNUNET_MQ_msg_copy(msg);
447 GNUNET_MQ_env_set_options (env, priority); 441 GNUNET_MQ_env_set_options(env, priority);
448 if ((0 != (priority & GNUNET_MQ_PREF_LOW_LATENCY)) && 442 if ((0 != (priority & GNUNET_MQ_PREF_LOW_LATENCY)) &&
449 (0 != (priority & GNUNET_MQ_PREF_OUT_OF_ORDER)) && 443 (0 != (priority & GNUNET_MQ_PREF_OUT_OF_ORDER)) &&
450 (NULL != dir->env_head) && 444 (NULL != dir->env_head) &&
451 (0 == (GNUNET_MQ_env_get_options (dir->env_head) & 445 (0 == (GNUNET_MQ_env_get_options(dir->env_head) &
452 GNUNET_MQ_PREF_LOW_LATENCY))) 446 GNUNET_MQ_PREF_LOW_LATENCY)))
453 GNUNET_MQ_dll_insert_head (&dir->env_head, &dir->env_tail, env); 447 GNUNET_MQ_dll_insert_head(&dir->env_head, &dir->env_tail, env);
454 else 448 else
455 GNUNET_MQ_dll_insert_tail (&dir->env_head, &dir->env_tail, env); 449 GNUNET_MQ_dll_insert_tail(&dir->env_head, &dir->env_tail, env);
456 cur_buffers++; 450 cur_buffers++;
457 GNUNET_STATISTICS_set (stats, "# buffer use", cur_buffers, GNUNET_NO); 451 GNUNET_STATISTICS_set(stats, "# buffer use", cur_buffers, GNUNET_NO);
458 /* Clean up 'rung' if now empty (and not head) */ 452 /* Clean up 'rung' if now empty (and not head) */
459 if ((NULL == rung->rd_head) && (rung != rung_head)) 453 if ((NULL == rung->rd_head) && (rung != rung_head))
460 { 454 {
461 GNUNET_CONTAINER_DLL_remove (rung_head, rung_tail, rung); 455 GNUNET_CONTAINER_DLL_remove(rung_head, rung_tail, rung);
462 GNUNET_free (rung); 456 GNUNET_free(rung);
463 } 457 }
464} 458}
465 459
466 460
@@ -473,16 +467,16 @@ route_message (struct CadetPeer *prev,
473 * @return #GNUNET_YES if size is correct, #GNUNET_NO otherwise. 467 * @return #GNUNET_YES if size is correct, #GNUNET_NO otherwise.
474 */ 468 */
475static int 469static int
476check_connection_create (void *cls, 470check_connection_create(void *cls,
477 const struct GNUNET_CADET_ConnectionCreateMessage *msg) 471 const struct GNUNET_CADET_ConnectionCreateMessage *msg)
478{ 472{
479 uint16_t size = ntohs (msg->header.size) - sizeof (*msg); 473 uint16_t size = ntohs(msg->header.size) - sizeof(*msg);
480 474
481 if (0 != (size % sizeof (struct GNUNET_PeerIdentity))) 475 if (0 != (size % sizeof(struct GNUNET_PeerIdentity)))
482 { 476 {
483 GNUNET_break_op (0); 477 GNUNET_break_op(0);
484 return GNUNET_NO; 478 return GNUNET_NO;
485 } 479 }
486 return GNUNET_YES; 480 return GNUNET_YES;
487} 481}
488 482
@@ -493,24 +487,24 @@ check_connection_create (void *cls,
493 * @param dir direction to destroy (do NOT free memory of 'dir' itself) 487 * @param dir direction to destroy (do NOT free memory of 'dir' itself)
494 */ 488 */
495static void 489static void
496destroy_direction (struct RouteDirection *dir) 490destroy_direction(struct RouteDirection *dir)
497{ 491{
498 struct GNUNET_MQ_Envelope *env; 492 struct GNUNET_MQ_Envelope *env;
499 493
500 while (NULL != (env = dir->env_head)) 494 while (NULL != (env = dir->env_head))
501 { 495 {
502 GNUNET_STATISTICS_update (stats, 496 GNUNET_STATISTICS_update(stats,
503 "# messages dropped due to route destruction", 497 "# messages dropped due to route destruction",
504 1, 498 1,
505 GNUNET_NO); 499 GNUNET_NO);
506 discard_buffer (dir, env); 500 discard_buffer(dir, env);
507 } 501 }
508 if (NULL != dir->mqm) 502 if (NULL != dir->mqm)
509 { 503 {
510 GCP_request_mq_cancel (dir->mqm, NULL); 504 GCP_request_mq_cancel(dir->mqm, NULL);
511 dir->mqm = NULL; 505 dir->mqm = NULL;
512 } 506 }
513 GNUNET_CONTAINER_DLL_remove (rung_head->rd_head, rung_head->rd_tail, dir); 507 GNUNET_CONTAINER_DLL_remove(rung_head->rd_head, rung_head->rd_tail, dir);
514} 508}
515 509
516 510
@@ -520,26 +514,26 @@ destroy_direction (struct RouteDirection *dir)
520 * @param route route to destroy 514 * @param route route to destroy
521 */ 515 */
522static void 516static void
523destroy_route (struct CadetRoute *route) 517destroy_route(struct CadetRoute *route)
524{ 518{
525 LOG (GNUNET_ERROR_TYPE_DEBUG, 519 LOG(GNUNET_ERROR_TYPE_DEBUG,
526 "Destroying route from %s to %s of connection %s\n", 520 "Destroying route from %s to %s of connection %s\n",
527 GNUNET_i2s (GCP_get_id (route->prev.hop)), 521 GNUNET_i2s(GCP_get_id(route->prev.hop)),
528 GNUNET_i2s2 (GCP_get_id (route->next.hop)), 522 GNUNET_i2s2(GCP_get_id(route->next.hop)),
529 GNUNET_sh2s (&route->cid.connection_of_tunnel)); 523 GNUNET_sh2s(&route->cid.connection_of_tunnel));
530 GNUNET_assert (route == GNUNET_CONTAINER_heap_remove_node (route->hn)); 524 GNUNET_assert(route == GNUNET_CONTAINER_heap_remove_node(route->hn));
531 GNUNET_assert ( 525 GNUNET_assert(
532 GNUNET_YES == 526 GNUNET_YES ==
533 GNUNET_CONTAINER_multishortmap_remove (routes, 527 GNUNET_CONTAINER_multishortmap_remove(routes,
534 &route->cid.connection_of_tunnel, 528 &route->cid.connection_of_tunnel,
535 route)); 529 route));
536 GNUNET_STATISTICS_set (stats, 530 GNUNET_STATISTICS_set(stats,
537 "# routes", 531 "# routes",
538 GNUNET_CONTAINER_multishortmap_size (routes), 532 GNUNET_CONTAINER_multishortmap_size(routes),
539 GNUNET_NO); 533 GNUNET_NO);
540 destroy_direction (&route->prev); 534 destroy_direction(&route->prev);
541 destroy_direction (&route->next); 535 destroy_direction(&route->next);
542 GNUNET_free (route); 536 GNUNET_free(route);
543} 537}
544 538
545 539
@@ -552,30 +546,30 @@ destroy_route (struct CadetRoute *route)
552 * @param peer2 another one of the peers where a link is broken 546 * @param peer2 another one of the peers where a link is broken
553 */ 547 */
554static void 548static void
555send_broken (struct RouteDirection *target, 549send_broken(struct RouteDirection *target,
556 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, 550 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
557 const struct GNUNET_PeerIdentity *peer1, 551 const struct GNUNET_PeerIdentity *peer1,
558 const struct GNUNET_PeerIdentity *peer2) 552 const struct GNUNET_PeerIdentity *peer2)
559{ 553{
560 struct GNUNET_MQ_Envelope *env; 554 struct GNUNET_MQ_Envelope *env;
561 struct GNUNET_CADET_ConnectionBrokenMessage *bm; 555 struct GNUNET_CADET_ConnectionBrokenMessage *bm;
562 556
563 if (NULL == target->mqm) 557 if (NULL == target->mqm)
564 return; /* Can't send notification, connection is down! */ 558 return; /* Can't send notification, connection is down! */
565 LOG (GNUNET_ERROR_TYPE_DEBUG, 559 LOG(GNUNET_ERROR_TYPE_DEBUG,
566 "Notifying %s about BROKEN route at %s-%s of connection %s\n", 560 "Notifying %s about BROKEN route at %s-%s of connection %s\n",
567 GCP_2s (target->hop), 561 GCP_2s(target->hop),
568 GNUNET_i2s (peer1), 562 GNUNET_i2s(peer1),
569 GNUNET_i2s2 (peer2), 563 GNUNET_i2s2(peer2),
570 GNUNET_sh2s (&cid->connection_of_tunnel)); 564 GNUNET_sh2s(&cid->connection_of_tunnel));
571 565
572 env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); 566 env = GNUNET_MQ_msg(bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN);
573 bm->cid = *cid; 567 bm->cid = *cid;
574 if (NULL != peer1) 568 if (NULL != peer1)
575 bm->peer1 = *peer1; 569 bm->peer1 = *peer1;
576 if (NULL != peer2) 570 if (NULL != peer2)
577 bm->peer2 = *peer2; 571 bm->peer2 = *peer2;
578 GCP_request_mq_cancel (target->mqm, env); 572 GCP_request_mq_cancel(target->mqm, env);
579 target->mqm = NULL; 573 target->mqm = NULL;
580} 574}
581 575
@@ -588,31 +582,31 @@ send_broken (struct RouteDirection *target,
588 * @param cls NULL 582 * @param cls NULL
589 */ 583 */
590static void 584static void
591timeout_cb (void *cls) 585timeout_cb(void *cls)
592{ 586{
593 struct CadetRoute *r; 587 struct CadetRoute *r;
594 struct GNUNET_TIME_Relative linger; 588 struct GNUNET_TIME_Relative linger;
595 struct GNUNET_TIME_Absolute exp; 589 struct GNUNET_TIME_Absolute exp;
596 590
597 timeout_task = NULL; 591 timeout_task = NULL;
598 linger = GNUNET_TIME_relative_multiply (keepalive_period, 3); 592 linger = GNUNET_TIME_relative_multiply(keepalive_period, 3);
599 while (NULL != (r = GNUNET_CONTAINER_heap_peek (route_heap))) 593 while (NULL != (r = GNUNET_CONTAINER_heap_peek(route_heap)))
600 {
601 exp = GNUNET_TIME_absolute_add (r->last_use, linger);
602 if (0 != GNUNET_TIME_absolute_get_remaining (exp).rel_value_us)
603 { 594 {
604 /* Route not yet timed out, wait until it does. */ 595 exp = GNUNET_TIME_absolute_add(r->last_use, linger);
605 timeout_task = GNUNET_SCHEDULER_add_at (exp, &timeout_cb, NULL); 596 if (0 != GNUNET_TIME_absolute_get_remaining(exp).rel_value_us)
606 return; 597 {
598 /* Route not yet timed out, wait until it does. */
599 timeout_task = GNUNET_SCHEDULER_add_at(exp, &timeout_cb, NULL);
600 return;
601 }
602 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
603 "Sending BROKEN due to timeout (%s was last use, %s linger)\n",
604 GNUNET_STRINGS_absolute_time_to_string(r->last_use),
605 GNUNET_STRINGS_relative_time_to_string(linger, GNUNET_YES));
606 send_broken(&r->prev, &r->cid, NULL, NULL);
607 send_broken(&r->next, &r->cid, NULL, NULL);
608 destroy_route(r);
607 } 609 }
608 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
609 "Sending BROKEN due to timeout (%s was last use, %s linger)\n",
610 GNUNET_STRINGS_absolute_time_to_string (r->last_use),
611 GNUNET_STRINGS_relative_time_to_string (linger, GNUNET_YES));
612 send_broken (&r->prev, &r->cid, NULL, NULL);
613 send_broken (&r->next, &r->cid, NULL, NULL);
614 destroy_route (r);
615 }
616 /* No more routes left, so no need for a #timeout_task */ 610 /* No more routes left, so no need for a #timeout_task */
617} 611}
618 612
@@ -630,32 +624,32 @@ timeout_cb (void *cls)
630 * and the last envelope was discarded 624 * and the last envelope was discarded
631 */ 625 */
632static void 626static void
633dir_ready_cb (void *cls, int ready) 627dir_ready_cb(void *cls, int ready)
634{ 628{
635 struct RouteDirection *dir = cls; 629 struct RouteDirection *dir = cls;
636 struct CadetRoute *route = dir->my_route; 630 struct CadetRoute *route = dir->my_route;
637 struct RouteDirection *odir; 631 struct RouteDirection *odir;
638 632
639 if (GNUNET_YES == ready) 633 if (GNUNET_YES == ready)
640 {
641 struct GNUNET_MQ_Envelope *env;
642
643 dir->is_ready = GNUNET_YES;
644 if (NULL != (env = dir->env_head))
645 { 634 {
646 GNUNET_MQ_dll_remove (&dir->env_head, &dir->env_tail, env); 635 struct GNUNET_MQ_Envelope *env;
647 cur_buffers--; 636
648 GNUNET_STATISTICS_set (stats, "# buffer use", cur_buffers, GNUNET_NO); 637 dir->is_ready = GNUNET_YES;
649 lower_rung (dir); 638 if (NULL != (env = dir->env_head))
650 dir->is_ready = GNUNET_NO; 639 {
651 GCP_send (dir->mqm, env); 640 GNUNET_MQ_dll_remove(&dir->env_head, &dir->env_tail, env);
641 cur_buffers--;
642 GNUNET_STATISTICS_set(stats, "# buffer use", cur_buffers, GNUNET_NO);
643 lower_rung(dir);
644 dir->is_ready = GNUNET_NO;
645 GCP_send(dir->mqm, env);
646 }
647 return;
652 } 648 }
653 return;
654 }
655 odir = (dir == &route->next) ? &route->prev : &route->next; 649 odir = (dir == &route->next) ? &route->prev : &route->next;
656 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending BROKEN due to MQ going down\n"); 650 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending BROKEN due to MQ going down\n");
657 send_broken (&route->next, &route->cid, GCP_get_id (odir->hop), &my_full_id); 651 send_broken(&route->next, &route->cid, GCP_get_id(odir->hop), &my_full_id);
658 destroy_route (route); 652 destroy_route(route);
659} 653}
660 654
661 655
@@ -667,16 +661,16 @@ dir_ready_cb (void *cls, int ready)
667 * @param hop next hop on in the @a dir 661 * @param hop next hop on in the @a dir
668 */ 662 */
669static void 663static void
670dir_init (struct RouteDirection *dir, 664dir_init(struct RouteDirection *dir,
671 struct CadetRoute *route, 665 struct CadetRoute *route,
672 struct CadetPeer *hop) 666 struct CadetPeer *hop)
673{ 667{
674 dir->hop = hop; 668 dir->hop = hop;
675 dir->my_route = route; 669 dir->my_route = route;
676 dir->mqm = GCP_request_mq (hop, &dir_ready_cb, dir); 670 dir->mqm = GCP_request_mq(hop, &dir_ready_cb, dir);
677 GNUNET_CONTAINER_DLL_insert (rung_head->rd_head, rung_head->rd_tail, dir); 671 GNUNET_CONTAINER_DLL_insert(rung_head->rd_head, rung_head->rd_tail, dir);
678 dir->rung = rung_head; 672 dir->rung = rung_head;
679 GNUNET_assert (GNUNET_YES == dir->is_ready); 673 GNUNET_assert(GNUNET_YES == dir->is_ready);
680} 674}
681 675
682 676
@@ -691,7 +685,7 @@ dir_init (struct RouteDirection *dir,
691 * or NULL. 685 * or NULL.
692 */ 686 */
693static void 687static void
694send_broken_without_mqm ( 688send_broken_without_mqm(
695 struct CadetPeer *target, 689 struct CadetPeer *target,
696 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, 690 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
697 const struct GNUNET_PeerIdentity *failure_at) 691 const struct GNUNET_PeerIdentity *failure_at)
@@ -699,12 +693,12 @@ send_broken_without_mqm (
699 struct GNUNET_MQ_Envelope *env; 693 struct GNUNET_MQ_Envelope *env;
700 struct GNUNET_CADET_ConnectionBrokenMessage *bm; 694 struct GNUNET_CADET_ConnectionBrokenMessage *bm;
701 695
702 env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); 696 env = GNUNET_MQ_msg(bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN);
703 bm->cid = *cid; 697 bm->cid = *cid;
704 bm->peer1 = my_full_id; 698 bm->peer1 = my_full_id;
705 if (NULL != failure_at) 699 if (NULL != failure_at)
706 bm->peer2 = *failure_at; 700 bm->peer2 = *failure_at;
707 GCP_send_ooo (target, env); 701 GCP_send_ooo(target, env);
708} 702}
709 703
710 704
@@ -715,193 +709,193 @@ send_broken_without_mqm (
715 * @param msg Message itself. 709 * @param msg Message itself.
716 */ 710 */
717static void 711static void
718handle_connection_create ( 712handle_connection_create(
719 void *cls, 713 void *cls,
720 const struct GNUNET_CADET_ConnectionCreateMessage *msg) 714 const struct GNUNET_CADET_ConnectionCreateMessage *msg)
721{ 715{
722 struct CadetPeer *sender = cls; 716 struct CadetPeer *sender = cls;
723 struct CadetPeer *next; 717 struct CadetPeer *next;
724 const struct GNUNET_PeerIdentity *pids = 718 const struct GNUNET_PeerIdentity *pids =
725 (const struct GNUNET_PeerIdentity *) &msg[1]; 719 (const struct GNUNET_PeerIdentity *)&msg[1];
726 struct CadetRoute *route; 720 struct CadetRoute *route;
727 uint16_t size = ntohs (msg->header.size) - sizeof (*msg); 721 uint16_t size = ntohs(msg->header.size) - sizeof(*msg);
728 unsigned int path_length; 722 unsigned int path_length;
729 unsigned int off; 723 unsigned int off;
730 724
731 path_length = size / sizeof (struct GNUNET_PeerIdentity); 725 path_length = size / sizeof(struct GNUNET_PeerIdentity);
732 if (0 == path_length) 726 if (0 == path_length)
733 { 727 {
734 LOG (GNUNET_ERROR_TYPE_DEBUG, 728 LOG(GNUNET_ERROR_TYPE_DEBUG,
735 "Dropping CADET_CONNECTION_CREATE with empty path\n"); 729 "Dropping CADET_CONNECTION_CREATE with empty path\n");
736 GNUNET_break_op (0); 730 GNUNET_break_op(0);
737 return; 731 return;
738 } 732 }
739 LOG (GNUNET_ERROR_TYPE_DEBUG, 733 LOG(GNUNET_ERROR_TYPE_DEBUG,
740 "Handling CADET_CONNECTION_CREATE from %s for CID %s with %u hops\n", 734 "Handling CADET_CONNECTION_CREATE from %s for CID %s with %u hops\n",
741 GCP_2s (sender), 735 GCP_2s(sender),
742 GNUNET_sh2s (&msg->cid.connection_of_tunnel), 736 GNUNET_sh2s(&msg->cid.connection_of_tunnel),
743 path_length); 737 path_length);
744 /* Check for loops */ 738 /* Check for loops */
745 { 739 {
746 struct GNUNET_CONTAINER_MultiPeerMap *map; 740 struct GNUNET_CONTAINER_MultiPeerMap *map;
747 741
748 map = GNUNET_CONTAINER_multipeermap_create (path_length * 2, GNUNET_YES); 742 map = GNUNET_CONTAINER_multipeermap_create(path_length * 2, GNUNET_YES);
749 GNUNET_assert (NULL != map); 743 GNUNET_assert(NULL != map);
750 for (unsigned int i = 0; i < path_length; i++) 744 for (unsigned int i = 0; i < path_length; i++)
751 {
752 LOG (GNUNET_ERROR_TYPE_DEBUG,
753 "CADET_CONNECTION_CREATE has peer %s at offset %u\n",
754 GNUNET_i2s (&pids[i]),
755 i);
756 if (GNUNET_SYSERR == GNUNET_CONTAINER_multipeermap_put (
757 map,
758 &pids[i],
759 NULL,
760 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
761 { 745 {
762 /* bogus request */ 746 LOG(GNUNET_ERROR_TYPE_DEBUG,
763 GNUNET_CONTAINER_multipeermap_destroy (map); 747 "CADET_CONNECTION_CREATE has peer %s at offset %u\n",
764 LOG (GNUNET_ERROR_TYPE_DEBUG, 748 GNUNET_i2s(&pids[i]),
765 "Dropping CADET_CONNECTION_CREATE with cyclic path\n"); 749 i);
766 GNUNET_break_op (0); 750 if (GNUNET_SYSERR == GNUNET_CONTAINER_multipeermap_put(
767 return; 751 map,
752 &pids[i],
753 NULL,
754 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
755 {
756 /* bogus request */
757 GNUNET_CONTAINER_multipeermap_destroy(map);
758 LOG(GNUNET_ERROR_TYPE_DEBUG,
759 "Dropping CADET_CONNECTION_CREATE with cyclic path\n");
760 GNUNET_break_op(0);
761 return;
762 }
768 } 763 }
769 } 764 GNUNET_CONTAINER_multipeermap_destroy(map);
770 GNUNET_CONTAINER_multipeermap_destroy (map);
771 } 765 }
772 /* Initiator is at offset 0, find us */ 766 /* Initiator is at offset 0, find us */
773 for (off = 1; off < path_length; off++) 767 for (off = 1; off < path_length; off++)
774 if (0 == GNUNET_memcmp (&my_full_id, &pids[off])) 768 if (0 == GNUNET_memcmp(&my_full_id, &pids[off]))
775 break; 769 break;
776 if (off == path_length) 770 if (off == path_length)
777 { 771 {
778 LOG (GNUNET_ERROR_TYPE_DEBUG, 772 LOG(GNUNET_ERROR_TYPE_DEBUG,
779 "Dropping CADET_CONNECTION_CREATE without us in the path\n"); 773 "Dropping CADET_CONNECTION_CREATE without us in the path\n");
780 GNUNET_break_op (0); 774 GNUNET_break_op(0);
781 return; 775 return;
782 } 776 }
783 /* Check previous hop */ 777 /* Check previous hop */
784 if (sender != GCP_get (&pids[off - 1], GNUNET_NO)) 778 if (sender != GCP_get(&pids[off - 1], GNUNET_NO))
785 {
786 LOG (GNUNET_ERROR_TYPE_DEBUG,
787 "Dropping CADET_CONNECTION_CREATE without sender at previous hop in the path\n");
788 GNUNET_break_op (0);
789 return;
790 }
791 if (NULL != (route = get_route (&msg->cid)))
792 {
793 /* Duplicate CREATE, pass it on, previous one might have been lost! */
794
795 LOG (GNUNET_ERROR_TYPE_DEBUG,
796 "Passing on duplicate CADET_CONNECTION_CREATE message on connection %s\n",
797 GNUNET_sh2s (&msg->cid.connection_of_tunnel));
798 route_message (sender,
799 &msg->cid,
800 &msg->header,
801 GNUNET_MQ_PRIO_CRITICAL_CONTROL |
802 GNUNET_MQ_PREF_LOW_LATENCY);
803 return;
804 }
805 if (off == path_length - 1)
806 {
807 /* We are the destination, create connection */
808 struct CadetConnection *cc;
809 struct CadetPeerPath *path;
810 struct CadetPeer *origin;
811
812 cc = GCC_lookup (&msg->cid);
813 if (NULL != cc)
814 { 779 {
815 LOG (GNUNET_ERROR_TYPE_DEBUG, 780 LOG(GNUNET_ERROR_TYPE_DEBUG,
816 "Received duplicate CADET_CONNECTION_CREATE message on connection %s\n", 781 "Dropping CADET_CONNECTION_CREATE without sender at previous hop in the path\n");
817 GNUNET_sh2s (&msg->cid.connection_of_tunnel)); 782 GNUNET_break_op(0);
818 GCC_handle_duplicate_create (cc);
819 return; 783 return;
820 } 784 }
821 785 if (NULL != (route = get_route(&msg->cid)))
822 origin = GCP_get (&pids[0], GNUNET_YES);
823 LOG (GNUNET_ERROR_TYPE_DEBUG,
824 "I am destination for CADET_CONNECTION_CREATE message from %s for connection %s, building inverse path\n",
825 GCP_2s (origin),
826 GNUNET_sh2s (&msg->cid.connection_of_tunnel));
827 path = GCPP_get_path_from_route (path_length - 1, pids);
828 if (GNUNET_OK !=
829 GCT_add_inbound_connection (GCP_get_tunnel (origin, GNUNET_YES),
830 &msg->cid,
831 path))
832 { 786 {
833 /* Send back BROKEN: duplicate connection on the same path, 787 /* Duplicate CREATE, pass it on, previous one might have been lost! */
834 we will use the other one. */ 788
835 LOG (GNUNET_ERROR_TYPE_DEBUG, 789 LOG(GNUNET_ERROR_TYPE_DEBUG,
836 "Received CADET_CONNECTION_CREATE from %s for %s, but %s already has a connection. Sending BROKEN\n", 790 "Passing on duplicate CADET_CONNECTION_CREATE message on connection %s\n",
837 GCP_2s (sender), 791 GNUNET_sh2s(&msg->cid.connection_of_tunnel));
838 GNUNET_sh2s (&msg->cid.connection_of_tunnel), 792 route_message(sender,
839 GCPP_2s (path)); 793 &msg->cid,
840 send_broken_without_mqm (sender, &msg->cid, NULL); 794 &msg->header,
795 GNUNET_MQ_PRIO_CRITICAL_CONTROL |
796 GNUNET_MQ_PREF_LOW_LATENCY);
797 return;
798 }
799 if (off == path_length - 1)
800 {
801 /* We are the destination, create connection */
802 struct CadetConnection *cc;
803 struct CadetPeerPath *path;
804 struct CadetPeer *origin;
805
806 cc = GCC_lookup(&msg->cid);
807 if (NULL != cc)
808 {
809 LOG(GNUNET_ERROR_TYPE_DEBUG,
810 "Received duplicate CADET_CONNECTION_CREATE message on connection %s\n",
811 GNUNET_sh2s(&msg->cid.connection_of_tunnel));
812 GCC_handle_duplicate_create(cc);
813 return;
814 }
815
816 origin = GCP_get(&pids[0], GNUNET_YES);
817 LOG(GNUNET_ERROR_TYPE_DEBUG,
818 "I am destination for CADET_CONNECTION_CREATE message from %s for connection %s, building inverse path\n",
819 GCP_2s(origin),
820 GNUNET_sh2s(&msg->cid.connection_of_tunnel));
821 path = GCPP_get_path_from_route(path_length - 1, pids);
822 if (GNUNET_OK !=
823 GCT_add_inbound_connection(GCP_get_tunnel(origin, GNUNET_YES),
824 &msg->cid,
825 path))
826 {
827 /* Send back BROKEN: duplicate connection on the same path,
828 we will use the other one. */
829 LOG(GNUNET_ERROR_TYPE_DEBUG,
830 "Received CADET_CONNECTION_CREATE from %s for %s, but %s already has a connection. Sending BROKEN\n",
831 GCP_2s(sender),
832 GNUNET_sh2s(&msg->cid.connection_of_tunnel),
833 GCPP_2s(path));
834 send_broken_without_mqm(sender, &msg->cid, NULL);
835 return;
836 }
841 return; 837 return;
842 } 838 }
843 return;
844 }
845 /* We are merely a hop on the way, check if we can support the route */ 839 /* We are merely a hop on the way, check if we can support the route */
846 next = GCP_get (&pids[off + 1], GNUNET_NO); 840 next = GCP_get(&pids[off + 1], GNUNET_NO);
847 if ((NULL == next) || (GNUNET_NO == GCP_has_core_connection (next))) 841 if ((NULL == next) || (GNUNET_NO == GCP_has_core_connection(next)))
848 { 842 {
849 /* unworkable, send back BROKEN notification */ 843 /* unworkable, send back BROKEN notification */
850 LOG (GNUNET_ERROR_TYPE_DEBUG, 844 LOG(GNUNET_ERROR_TYPE_DEBUG,
851 "Received CADET_CONNECTION_CREATE from %s for %s. Next hop %s:%u is down. Sending BROKEN\n", 845 "Received CADET_CONNECTION_CREATE from %s for %s. Next hop %s:%u is down. Sending BROKEN\n",
852 GCP_2s (sender), 846 GCP_2s(sender),
853 GNUNET_sh2s (&msg->cid.connection_of_tunnel), 847 GNUNET_sh2s(&msg->cid.connection_of_tunnel),
854 GNUNET_i2s (&pids[off + 1]), 848 GNUNET_i2s(&pids[off + 1]),
855 off + 1); 849 off + 1);
856 send_broken_without_mqm (sender, &msg->cid, &pids[off + 1]); 850 send_broken_without_mqm(sender, &msg->cid, &pids[off + 1]);
857 return; 851 return;
858 } 852 }
859 if (max_routes <= GNUNET_CONTAINER_multishortmap_size (routes)) 853 if (max_routes <= GNUNET_CONTAINER_multishortmap_size(routes))
860 { 854 {
861 LOG (GNUNET_ERROR_TYPE_DEBUG, 855 LOG(GNUNET_ERROR_TYPE_DEBUG,
862 "Received CADET_CONNECTION_CREATE from %s for %s. We have reached our route limit. Sending BROKEN\n", 856 "Received CADET_CONNECTION_CREATE from %s for %s. We have reached our route limit. Sending BROKEN\n",
863 GCP_2s (sender), 857 GCP_2s(sender),
864 GNUNET_sh2s (&msg->cid.connection_of_tunnel)); 858 GNUNET_sh2s(&msg->cid.connection_of_tunnel));
865 send_broken_without_mqm (sender, &msg->cid, &pids[off - 1]); 859 send_broken_without_mqm(sender, &msg->cid, &pids[off - 1]);
866 return; 860 return;
867 } 861 }
868 862
869 /* Workable route, create routing entry */ 863 /* Workable route, create routing entry */
870 LOG (GNUNET_ERROR_TYPE_DEBUG, 864 LOG(GNUNET_ERROR_TYPE_DEBUG,
871 "Received CADET_CONNECTION_CREATE from %s for %s. Next hop %s:%u is up. Creating route\n", 865 "Received CADET_CONNECTION_CREATE from %s for %s. Next hop %s:%u is up. Creating route\n",
872 GCP_2s (sender), 866 GCP_2s(sender),
873 GNUNET_sh2s (&msg->cid.connection_of_tunnel), 867 GNUNET_sh2s(&msg->cid.connection_of_tunnel),
874 GNUNET_i2s (&pids[off + 1]), 868 GNUNET_i2s(&pids[off + 1]),
875 off + 1); 869 off + 1);
876 route = GNUNET_new (struct CadetRoute); 870 route = GNUNET_new(struct CadetRoute);
877 route->cid = msg->cid; 871 route->cid = msg->cid;
878 route->last_use = GNUNET_TIME_absolute_get (); 872 route->last_use = GNUNET_TIME_absolute_get();
879 dir_init (&route->prev, route, sender); 873 dir_init(&route->prev, route, sender);
880 dir_init (&route->next, route, next); 874 dir_init(&route->next, route, next);
881 GNUNET_assert (GNUNET_OK == 875 GNUNET_assert(GNUNET_OK ==
882 GNUNET_CONTAINER_multishortmap_put ( 876 GNUNET_CONTAINER_multishortmap_put(
883 routes, 877 routes,
884 &route->cid.connection_of_tunnel, 878 &route->cid.connection_of_tunnel,
885 route, 879 route,
886 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 880 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
887 GNUNET_STATISTICS_set (stats, 881 GNUNET_STATISTICS_set(stats,
888 "# routes", 882 "# routes",
889 GNUNET_CONTAINER_multishortmap_size (routes), 883 GNUNET_CONTAINER_multishortmap_size(routes),
890 GNUNET_NO); 884 GNUNET_NO);
891 route->hn = GNUNET_CONTAINER_heap_insert (route_heap, 885 route->hn = GNUNET_CONTAINER_heap_insert(route_heap,
892 route, 886 route,
893 route->last_use.abs_value_us); 887 route->last_use.abs_value_us);
894 if (NULL == timeout_task) 888 if (NULL == timeout_task)
895 timeout_task = 889 timeout_task =
896 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (keepalive_period, 890 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(keepalive_period,
897 3), 891 3),
898 &timeout_cb, 892 &timeout_cb,
899 NULL); 893 NULL);
900 /* also pass CREATE message along to next hop */ 894 /* also pass CREATE message along to next hop */
901 route_message (sender, 895 route_message(sender,
902 &msg->cid, 896 &msg->cid,
903 &msg->header, 897 &msg->header,
904 GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY); 898 GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY);
905} 899}
906 900
907 901
@@ -912,7 +906,7 @@ handle_connection_create (
912 * @param msg Message itself. 906 * @param msg Message itself.
913 */ 907 */
914static void 908static void
915handle_connection_create_ack ( 909handle_connection_create_ack(
916 void *cls, 910 void *cls,
917 const struct GNUNET_CADET_ConnectionCreateAckMessage *msg) 911 const struct GNUNET_CADET_ConnectionCreateAckMessage *msg)
918{ 912{
@@ -920,31 +914,31 @@ handle_connection_create_ack (
920 struct CadetConnection *cc; 914 struct CadetConnection *cc;
921 915
922 /* First, check if ACK belongs to a connection that ends here. */ 916 /* First, check if ACK belongs to a connection that ends here. */
923 cc = GCC_lookup (&msg->cid); 917 cc = GCC_lookup(&msg->cid);
924 if (NULL != cc) 918 if (NULL != cc)
925 {
926 /* verify ACK came from the right direction */
927 unsigned int len;
928 struct CadetPeerPath *path = GCC_get_path (cc, &len);
929
930 if (peer != GCPP_get_peer_at_offset (path, 0))
931 { 919 {
932 /* received ACK from unexpected direction, ignore! */ 920 /* verify ACK came from the right direction */
933 GNUNET_break_op (0); 921 unsigned int len;
922 struct CadetPeerPath *path = GCC_get_path(cc, &len);
923
924 if (peer != GCPP_get_peer_at_offset(path, 0))
925 {
926 /* received ACK from unexpected direction, ignore! */
927 GNUNET_break_op(0);
928 return;
929 }
930 LOG(GNUNET_ERROR_TYPE_DEBUG,
931 "Received CONNECTION_CREATE_ACK for connection %s.\n",
932 GNUNET_sh2s(&msg->cid.connection_of_tunnel));
933 GCC_handle_connection_create_ack(cc);
934 return; 934 return;
935 } 935 }
936 LOG (GNUNET_ERROR_TYPE_DEBUG,
937 "Received CONNECTION_CREATE_ACK for connection %s.\n",
938 GNUNET_sh2s (&msg->cid.connection_of_tunnel));
939 GCC_handle_connection_create_ack (cc);
940 return;
941 }
942 936
943 /* We're just an intermediary peer, route the message along its path */ 937 /* We're just an intermediary peer, route the message along its path */
944 route_message (peer, 938 route_message(peer,
945 &msg->cid, 939 &msg->cid,
946 &msg->header, 940 &msg->header,
947 GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY); 941 GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY);
948} 942}
949 943
950 944
@@ -956,7 +950,7 @@ handle_connection_create_ack (
956 * @deprecated duplicate logic with #handle_destroy(); dedup! 950 * @deprecated duplicate logic with #handle_destroy(); dedup!
957 */ 951 */
958static void 952static void
959handle_connection_broken ( 953handle_connection_broken(
960 void *cls, 954 void *cls,
961 const struct GNUNET_CADET_ConnectionBrokenMessage *msg) 955 const struct GNUNET_CADET_ConnectionBrokenMessage *msg)
962{ 956{
@@ -965,36 +959,36 @@ handle_connection_broken (
965 struct CadetRoute *route; 959 struct CadetRoute *route;
966 960
967 /* First, check if message belongs to a connection that ends here. */ 961 /* First, check if message belongs to a connection that ends here. */
968 cc = GCC_lookup (&msg->cid); 962 cc = GCC_lookup(&msg->cid);
969 if (NULL != cc) 963 if (NULL != cc)
970 {
971 /* verify message came from the right direction */
972 unsigned int len;
973 struct CadetPeerPath *path = GCC_get_path (cc, &len);
974
975 if (peer != GCPP_get_peer_at_offset (path, 0))
976 { 964 {
977 /* received message from unexpected direction, ignore! */ 965 /* verify message came from the right direction */
978 GNUNET_break_op (0); 966 unsigned int len;
967 struct CadetPeerPath *path = GCC_get_path(cc, &len);
968
969 if (peer != GCPP_get_peer_at_offset(path, 0))
970 {
971 /* received message from unexpected direction, ignore! */
972 GNUNET_break_op(0);
973 return;
974 }
975 LOG(GNUNET_ERROR_TYPE_DEBUG,
976 "Received CONNECTION_BROKEN for connection %s. Destroying it.\n",
977 GNUNET_sh2s(&msg->cid.connection_of_tunnel));
978 GCC_destroy_without_core(cc);
979
980 /* FIXME: also destroy the path up to the specified link! */
979 return; 981 return;
980 } 982 }
981 LOG (GNUNET_ERROR_TYPE_DEBUG,
982 "Received CONNECTION_BROKEN for connection %s. Destroying it.\n",
983 GNUNET_sh2s (&msg->cid.connection_of_tunnel));
984 GCC_destroy_without_core (cc);
985
986 /* FIXME: also destroy the path up to the specified link! */
987 return;
988 }
989 983
990 /* We're just an intermediary peer, route the message along its path */ 984 /* We're just an intermediary peer, route the message along its path */
991 route_message (peer, 985 route_message(peer,
992 &msg->cid, 986 &msg->cid,
993 &msg->header, 987 &msg->header,
994 GNUNET_MQ_PREF_LOW_LATENCY | GNUNET_MQ_PRIO_CRITICAL_CONTROL); 988 GNUNET_MQ_PREF_LOW_LATENCY | GNUNET_MQ_PRIO_CRITICAL_CONTROL);
995 route = get_route (&msg->cid); 989 route = get_route(&msg->cid);
996 if (NULL != route) 990 if (NULL != route)
997 destroy_route (route); 991 destroy_route(route);
998 /* FIXME: also destroy paths we MAY have up to the specified link! */ 992 /* FIXME: also destroy paths we MAY have up to the specified link! */
999} 993}
1000 994
@@ -1006,7 +1000,7 @@ handle_connection_broken (
1006 * @param msg Message itself. 1000 * @param msg Message itself.
1007 */ 1001 */
1008static void 1002static void
1009handle_connection_destroy ( 1003handle_connection_destroy(
1010 void *cls, 1004 void *cls,
1011 const struct GNUNET_CADET_ConnectionDestroyMessage *msg) 1005 const struct GNUNET_CADET_ConnectionDestroyMessage *msg)
1012{ 1006{
@@ -1015,38 +1009,38 @@ handle_connection_destroy (
1015 struct CadetRoute *route; 1009 struct CadetRoute *route;
1016 1010
1017 /* First, check if message belongs to a connection that ends here. */ 1011 /* First, check if message belongs to a connection that ends here. */
1018 cc = GCC_lookup (&msg->cid); 1012 cc = GCC_lookup(&msg->cid);
1019 if (NULL != cc) 1013 if (NULL != cc)
1020 {
1021 /* verify message came from the right direction */
1022 unsigned int len;
1023 struct CadetPeerPath *path = GCC_get_path (cc, &len);
1024
1025 if (peer != GCPP_get_peer_at_offset (path, 0))
1026 { 1014 {
1027 /* received message from unexpected direction, ignore! */ 1015 /* verify message came from the right direction */
1028 GNUNET_break_op (0); 1016 unsigned int len;
1017 struct CadetPeerPath *path = GCC_get_path(cc, &len);
1018
1019 if (peer != GCPP_get_peer_at_offset(path, 0))
1020 {
1021 /* received message from unexpected direction, ignore! */
1022 GNUNET_break_op(0);
1023 return;
1024 }
1025 LOG(GNUNET_ERROR_TYPE_DEBUG,
1026 "Received CONNECTION_DESTROY for connection %s. Destroying connection.\n",
1027 GNUNET_sh2s(&msg->cid.connection_of_tunnel));
1028
1029 GCC_destroy_without_core(cc);
1029 return; 1030 return;
1030 } 1031 }
1031 LOG (GNUNET_ERROR_TYPE_DEBUG,
1032 "Received CONNECTION_DESTROY for connection %s. Destroying connection.\n",
1033 GNUNET_sh2s (&msg->cid.connection_of_tunnel));
1034
1035 GCC_destroy_without_core (cc);
1036 return;
1037 }
1038 1032
1039 /* We're just an intermediary peer, route the message along its path */ 1033 /* We're just an intermediary peer, route the message along its path */
1040 LOG (GNUNET_ERROR_TYPE_DEBUG, 1034 LOG(GNUNET_ERROR_TYPE_DEBUG,
1041 "Received CONNECTION_DESTROY for connection %s. Destroying route.\n", 1035 "Received CONNECTION_DESTROY for connection %s. Destroying route.\n",
1042 GNUNET_sh2s (&msg->cid.connection_of_tunnel)); 1036 GNUNET_sh2s(&msg->cid.connection_of_tunnel));
1043 route_message (peer, 1037 route_message(peer,
1044 &msg->cid, 1038 &msg->cid,
1045 &msg->header, 1039 &msg->header,
1046 GNUNET_MQ_PREF_LOW_LATENCY | GNUNET_MQ_PRIO_CRITICAL_CONTROL); 1040 GNUNET_MQ_PREF_LOW_LATENCY | GNUNET_MQ_PRIO_CRITICAL_CONTROL);
1047 route = get_route (&msg->cid); 1041 route = get_route(&msg->cid);
1048 if (NULL != route) 1042 if (NULL != route)
1049 destroy_route (route); 1043 destroy_route(route);
1050} 1044}
1051 1045
1052 1046
@@ -1057,41 +1051,41 @@ handle_connection_destroy (
1057 * @param msg Message itself. 1051 * @param msg Message itself.
1058 */ 1052 */
1059static void 1053static void
1060handle_tunnel_kx (void *cls, 1054handle_tunnel_kx(void *cls,
1061 const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg) 1055 const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg)
1062{ 1056{
1063 struct CadetPeer *peer = cls; 1057 struct CadetPeer *peer = cls;
1064 struct CadetConnection *cc; 1058 struct CadetConnection *cc;
1065 1059
1066 /* First, check if message belongs to a connection that ends here. */ 1060 /* First, check if message belongs to a connection that ends here. */
1067 LOG (GNUNET_ERROR_TYPE_DEBUG, 1061 LOG(GNUNET_ERROR_TYPE_DEBUG,
1068 "Routing KX with ephemeral %s on CID %s\n", 1062 "Routing KX with ephemeral %s on CID %s\n",
1069 GNUNET_e2s (&msg->ephemeral_key), 1063 GNUNET_e2s(&msg->ephemeral_key),
1070 GNUNET_sh2s (&msg->cid.connection_of_tunnel)); 1064 GNUNET_sh2s(&msg->cid.connection_of_tunnel));
1071 1065
1072 1066
1073 cc = GCC_lookup (&msg->cid); 1067 cc = GCC_lookup(&msg->cid);
1074 if (NULL != cc) 1068 if (NULL != cc)
1075 {
1076 /* verify message came from the right direction */
1077 unsigned int len;
1078 struct CadetPeerPath *path = GCC_get_path (cc, &len);
1079
1080 if (peer != GCPP_get_peer_at_offset (path, 0))
1081 { 1069 {
1082 /* received message from unexpected direction, ignore! */ 1070 /* verify message came from the right direction */
1083 GNUNET_break_op (0); 1071 unsigned int len;
1072 struct CadetPeerPath *path = GCC_get_path(cc, &len);
1073
1074 if (peer != GCPP_get_peer_at_offset(path, 0))
1075 {
1076 /* received message from unexpected direction, ignore! */
1077 GNUNET_break_op(0);
1078 return;
1079 }
1080 GCC_handle_kx(cc, msg);
1084 return; 1081 return;
1085 } 1082 }
1086 GCC_handle_kx (cc, msg);
1087 return;
1088 }
1089 1083
1090 /* We're just an intermediary peer, route the message along its path */ 1084 /* We're just an intermediary peer, route the message along its path */
1091 route_message (peer, 1085 route_message(peer,
1092 &msg->cid, 1086 &msg->cid,
1093 &msg->header, 1087 &msg->header,
1094 GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY); 1088 GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY);
1095} 1089}
1096 1090
1097 1091
@@ -1102,7 +1096,7 @@ handle_tunnel_kx (void *cls,
1102 * @param msg Message itself. 1096 * @param msg Message itself.
1103 */ 1097 */
1104static void 1098static void
1105handle_tunnel_kx_auth ( 1099handle_tunnel_kx_auth(
1106 void *cls, 1100 void *cls,
1107 const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg) 1101 const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg)
1108{ 1102{
@@ -1110,28 +1104,28 @@ handle_tunnel_kx_auth (
1110 struct CadetConnection *cc; 1104 struct CadetConnection *cc;
1111 1105
1112 /* First, check if message belongs to a connection that ends here. */ 1106 /* First, check if message belongs to a connection that ends here. */
1113 cc = GCC_lookup (&msg->kx.cid); 1107 cc = GCC_lookup(&msg->kx.cid);
1114 if (NULL != cc) 1108 if (NULL != cc)
1115 {
1116 /* verify message came from the right direction */
1117 unsigned int len;
1118 struct CadetPeerPath *path = GCC_get_path (cc, &len);
1119
1120 if (peer != GCPP_get_peer_at_offset (path, 0))
1121 { 1109 {
1122 /* received message from unexpected direction, ignore! */ 1110 /* verify message came from the right direction */
1123 GNUNET_break_op (0); 1111 unsigned int len;
1112 struct CadetPeerPath *path = GCC_get_path(cc, &len);
1113
1114 if (peer != GCPP_get_peer_at_offset(path, 0))
1115 {
1116 /* received message from unexpected direction, ignore! */
1117 GNUNET_break_op(0);
1118 return;
1119 }
1120 GCC_handle_kx_auth(cc, msg);
1124 return; 1121 return;
1125 } 1122 }
1126 GCC_handle_kx_auth (cc, msg);
1127 return;
1128 }
1129 1123
1130 /* We're just an intermediary peer, route the message along its path */ 1124 /* We're just an intermediary peer, route the message along its path */
1131 route_message (peer, 1125 route_message(peer,
1132 &msg->kx.cid, 1126 &msg->kx.cid,
1133 &msg->kx.header, 1127 &msg->kx.header,
1134 GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY); 1128 GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY);
1135} 1129}
1136 1130
1137 1131
@@ -1144,8 +1138,8 @@ handle_tunnel_kx_auth (
1144 * @return #GNUNET_YES if size is correct, #GNUNET_NO otherwise. 1138 * @return #GNUNET_YES if size is correct, #GNUNET_NO otherwise.
1145 */ 1139 */
1146static int 1140static int
1147check_tunnel_encrypted (void *cls, 1141check_tunnel_encrypted(void *cls,
1148 const struct GNUNET_CADET_TunnelEncryptedMessage *msg) 1142 const struct GNUNET_CADET_TunnelEncryptedMessage *msg)
1149{ 1143{
1150 return GNUNET_YES; 1144 return GNUNET_YES;
1151} 1145}
@@ -1158,31 +1152,31 @@ check_tunnel_encrypted (void *cls,
1158 * @param msg Message itself. 1152 * @param msg Message itself.
1159 */ 1153 */
1160static void 1154static void
1161handle_tunnel_encrypted (void *cls, 1155handle_tunnel_encrypted(void *cls,
1162 const struct GNUNET_CADET_TunnelEncryptedMessage *msg) 1156 const struct GNUNET_CADET_TunnelEncryptedMessage *msg)
1163{ 1157{
1164 struct CadetPeer *peer = cls; 1158 struct CadetPeer *peer = cls;
1165 struct CadetConnection *cc; 1159 struct CadetConnection *cc;
1166 1160
1167 /* First, check if message belongs to a connection that ends here. */ 1161 /* First, check if message belongs to a connection that ends here. */
1168 cc = GCC_lookup (&msg->cid); 1162 cc = GCC_lookup(&msg->cid);
1169 if (NULL != cc) 1163 if (NULL != cc)
1170 {
1171 /* verify message came from the right direction */
1172 unsigned int len;
1173 struct CadetPeerPath *path = GCC_get_path (cc, &len);
1174
1175 if (peer != GCPP_get_peer_at_offset (path, 0))
1176 { 1164 {
1177 /* received message from unexpected direction, ignore! */ 1165 /* verify message came from the right direction */
1178 GNUNET_break_op (0); 1166 unsigned int len;
1167 struct CadetPeerPath *path = GCC_get_path(cc, &len);
1168
1169 if (peer != GCPP_get_peer_at_offset(path, 0))
1170 {
1171 /* received message from unexpected direction, ignore! */
1172 GNUNET_break_op(0);
1173 return;
1174 }
1175 GCC_handle_encrypted(cc, msg);
1179 return; 1176 return;
1180 } 1177 }
1181 GCC_handle_encrypted (cc, msg);
1182 return;
1183 }
1184 /* We're just an intermediary peer, route the message along its path */ 1178 /* We're just an intermediary peer, route the message along its path */
1185 route_message (peer, &msg->cid, &msg->header, GNUNET_MQ_PRIO_BEST_EFFORT); 1179 route_message(peer, &msg->cid, &msg->header, GNUNET_MQ_PRIO_BEST_EFFORT);
1186} 1180}
1187 1181
1188 1182
@@ -1199,14 +1193,14 @@ handle_tunnel_encrypted (void *cls,
1199 * @param my_identity ID of this peer, NULL if we failed 1193 * @param my_identity ID of this peer, NULL if we failed
1200 */ 1194 */
1201static void 1195static void
1202core_init_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity) 1196core_init_cb(void *cls, const struct GNUNET_PeerIdentity *my_identity)
1203{ 1197{
1204 if (NULL == my_identity) 1198 if (NULL == my_identity)
1205 { 1199 {
1206 GNUNET_break (0); 1200 GNUNET_break(0);
1207 return; 1201 return;
1208 } 1202 }
1209 GNUNET_break (0 == GNUNET_memcmp (my_identity, &my_full_id)); 1203 GNUNET_break(0 == GNUNET_memcmp(my_identity, &my_full_id));
1210} 1204}
1211 1205
1212 1206
@@ -1217,17 +1211,17 @@ core_init_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity)
1217 * @param peer peer identity this notification is about 1211 * @param peer peer identity this notification is about
1218 */ 1212 */
1219static void * 1213static void *
1220core_connect_cb (void *cls, 1214core_connect_cb(void *cls,
1221 const struct GNUNET_PeerIdentity *peer, 1215 const struct GNUNET_PeerIdentity *peer,
1222 struct GNUNET_MQ_Handle *mq) 1216 struct GNUNET_MQ_Handle *mq)
1223{ 1217{
1224 struct CadetPeer *cp; 1218 struct CadetPeer *cp;
1225 1219
1226 LOG (GNUNET_ERROR_TYPE_DEBUG, 1220 LOG(GNUNET_ERROR_TYPE_DEBUG,
1227 "CORE connection to peer %s was established.\n", 1221 "CORE connection to peer %s was established.\n",
1228 GNUNET_i2s (peer)); 1222 GNUNET_i2s(peer));
1229 cp = GCP_get (peer, GNUNET_YES); 1223 cp = GCP_get(peer, GNUNET_YES);
1230 GCP_set_mq (cp, mq); 1224 GCP_set_mq(cp, mq);
1231 return cp; 1225 return cp;
1232} 1226}
1233 1227
@@ -1239,16 +1233,16 @@ core_connect_cb (void *cls,
1239 * @param peer peer identity this notification is about 1233 * @param peer peer identity this notification is about
1240 */ 1234 */
1241static void 1235static void
1242core_disconnect_cb (void *cls, 1236core_disconnect_cb(void *cls,
1243 const struct GNUNET_PeerIdentity *peer, 1237 const struct GNUNET_PeerIdentity *peer,
1244 void *peer_cls) 1238 void *peer_cls)
1245{ 1239{
1246 struct CadetPeer *cp = peer_cls; 1240 struct CadetPeer *cp = peer_cls;
1247 1241
1248 LOG (GNUNET_ERROR_TYPE_DEBUG, 1242 LOG(GNUNET_ERROR_TYPE_DEBUG,
1249 "CORE connection to peer %s went down.\n", 1243 "CORE connection to peer %s went down.\n",
1250 GNUNET_i2s (peer)); 1244 GNUNET_i2s(peer));
1251 GCP_set_mq (cp, NULL); 1245 GCP_set_mq(cp, NULL);
1252} 1246}
1253 1247
1254 1248
@@ -1258,57 +1252,57 @@ core_disconnect_cb (void *cls,
1258 * @param c Configuration. 1252 * @param c Configuration.
1259 */ 1253 */
1260void 1254void
1261GCO_init (const struct GNUNET_CONFIGURATION_Handle *c) 1255GCO_init(const struct GNUNET_CONFIGURATION_Handle *c)
1262{ 1256{
1263 struct GNUNET_MQ_MessageHandler handlers[] = 1257 struct GNUNET_MQ_MessageHandler handlers[] =
1264 {GNUNET_MQ_hd_var_size (connection_create, 1258 { GNUNET_MQ_hd_var_size(connection_create,
1265 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE, 1259 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE,
1266 struct GNUNET_CADET_ConnectionCreateMessage, 1260 struct GNUNET_CADET_ConnectionCreateMessage,
1261 NULL),
1262 GNUNET_MQ_hd_fixed_size(connection_create_ack,
1263 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK,
1264 struct GNUNET_CADET_ConnectionCreateAckMessage,
1267 NULL), 1265 NULL),
1268 GNUNET_MQ_hd_fixed_size (connection_create_ack, 1266 GNUNET_MQ_hd_fixed_size(connection_broken,
1269 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK, 1267 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN,
1270 struct GNUNET_CADET_ConnectionCreateAckMessage, 1268 struct GNUNET_CADET_ConnectionBrokenMessage,
1271 NULL),
1272 GNUNET_MQ_hd_fixed_size (connection_broken,
1273 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN,
1274 struct GNUNET_CADET_ConnectionBrokenMessage,
1275 NULL),
1276 GNUNET_MQ_hd_fixed_size (connection_destroy,
1277 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY,
1278 struct GNUNET_CADET_ConnectionDestroyMessage,
1279 NULL),
1280 GNUNET_MQ_hd_fixed_size (tunnel_kx,
1281 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX,
1282 struct GNUNET_CADET_TunnelKeyExchangeMessage,
1283 NULL),
1284 GNUNET_MQ_hd_fixed_size (tunnel_kx_auth,
1285 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH,
1286 struct GNUNET_CADET_TunnelKeyExchangeAuthMessage,
1287 NULL),
1288 GNUNET_MQ_hd_var_size (tunnel_encrypted,
1289 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED,
1290 struct GNUNET_CADET_TunnelEncryptedMessage,
1291 NULL), 1269 NULL),
1292 GNUNET_MQ_handler_end ()}; 1270 GNUNET_MQ_hd_fixed_size(connection_destroy,
1293 1271 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY,
1294 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (c, 1272 struct GNUNET_CADET_ConnectionDestroyMessage,
1295 "CADET", 1273 NULL),
1296 "MAX_ROUTES", 1274 GNUNET_MQ_hd_fixed_size(tunnel_kx,
1297 &max_routes)) 1275 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX,
1276 struct GNUNET_CADET_TunnelKeyExchangeMessage,
1277 NULL),
1278 GNUNET_MQ_hd_fixed_size(tunnel_kx_auth,
1279 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH,
1280 struct GNUNET_CADET_TunnelKeyExchangeAuthMessage,
1281 NULL),
1282 GNUNET_MQ_hd_var_size(tunnel_encrypted,
1283 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED,
1284 struct GNUNET_CADET_TunnelEncryptedMessage,
1285 NULL),
1286 GNUNET_MQ_handler_end() };
1287
1288 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(c,
1289 "CADET",
1290 "MAX_ROUTES",
1291 &max_routes))
1298 max_routes = 5000; 1292 max_routes = 5000;
1299 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (c, 1293 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(c,
1300 "CADET", 1294 "CADET",
1301 "MAX_MSGS_QUEUE", 1295 "MAX_MSGS_QUEUE",
1302 &max_buffers)) 1296 &max_buffers))
1303 max_buffers = 10000; 1297 max_buffers = 10000;
1304 routes = GNUNET_CONTAINER_multishortmap_create (1024, GNUNET_NO); 1298 routes = GNUNET_CONTAINER_multishortmap_create(1024, GNUNET_NO);
1305 route_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 1299 route_heap = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN);
1306 core = GNUNET_CORE_connect (c, 1300 core = GNUNET_CORE_connect(c,
1307 NULL, 1301 NULL,
1308 &core_init_cb, 1302 &core_init_cb,
1309 &core_connect_cb, 1303 &core_connect_cb,
1310 &core_disconnect_cb, 1304 &core_disconnect_cb,
1311 handlers); 1305 handlers);
1312} 1306}
1313 1307
1314 1308
@@ -1316,23 +1310,23 @@ GCO_init (const struct GNUNET_CONFIGURATION_Handle *c)
1316 * Shut down the CORE subsystem. 1310 * Shut down the CORE subsystem.
1317 */ 1311 */
1318void 1312void
1319GCO_shutdown () 1313GCO_shutdown()
1320{ 1314{
1321 if (NULL != core) 1315 if (NULL != core)
1322 { 1316 {
1323 GNUNET_CORE_disconnect (core); 1317 GNUNET_CORE_disconnect(core);
1324 core = NULL; 1318 core = NULL;
1325 } 1319 }
1326 GNUNET_assert (0 == GNUNET_CONTAINER_multishortmap_size (routes)); 1320 GNUNET_assert(0 == GNUNET_CONTAINER_multishortmap_size(routes));
1327 GNUNET_CONTAINER_multishortmap_destroy (routes); 1321 GNUNET_CONTAINER_multishortmap_destroy(routes);
1328 routes = NULL; 1322 routes = NULL;
1329 GNUNET_CONTAINER_heap_destroy (route_heap); 1323 GNUNET_CONTAINER_heap_destroy(route_heap);
1330 route_heap = NULL; 1324 route_heap = NULL;
1331 if (NULL != timeout_task) 1325 if (NULL != timeout_task)
1332 { 1326 {
1333 GNUNET_SCHEDULER_cancel (timeout_task); 1327 GNUNET_SCHEDULER_cancel(timeout_task);
1334 timeout_task = NULL; 1328 timeout_task = NULL;
1335 } 1329 }
1336} 1330}
1337 1331
1338/* end of gnunet-cadet-service_core.c */ 1332/* end of gnunet-cadet-service_core.c */