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.c501
1 files changed, 195 insertions, 306 deletions
diff --git a/src/cadet/gnunet-service-cadet_core.c b/src/cadet/gnunet-service-cadet_core.c
index 220a2b3cd..ec70a968b 100644
--- a/src/cadet/gnunet-service-cadet_core.c
+++ b/src/cadet/gnunet-service-cadet_core.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -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.
@@ -138,7 +138,6 @@ struct RouteDirection
138 * Is @e mqm currently ready for transmission? 138 * Is @e mqm currently ready for transmission?
139 */ 139 */
140 int is_ready; 140 int is_ready;
141
142}; 141};
143 142
144 143
@@ -177,8 +176,6 @@ struct CadetRoute
177 * Position of this route in the #route_heap. 176 * Position of this route in the #route_heap.
178 */ 177 */
179 struct GNUNET_CONTAINER_HeapNode *hn; 178 struct GNUNET_CONTAINER_HeapNode *hn;
180
181
182}; 179};
183 180
184 181
@@ -258,24 +255,17 @@ lower_rung (struct RouteDirection *dir)
258 struct Rung *rung = dir->rung; 255 struct Rung *rung = dir->rung;
259 struct Rung *prev; 256 struct Rung *prev;
260 257
261 GNUNET_CONTAINER_DLL_remove (rung->rd_head, 258 GNUNET_CONTAINER_DLL_remove (rung->rd_head, rung->rd_tail, dir);
262 rung->rd_tail,
263 dir);
264 prev = rung->prev; 259 prev = rung->prev;
265 GNUNET_assert (NULL != prev); 260 GNUNET_assert (NULL != prev);
266 if (prev->rung_off != rung->rung_off - 1) 261 if (prev->rung_off != rung->rung_off - 1)
267 { 262 {
268 prev = GNUNET_new (struct Rung); 263 prev = GNUNET_new (struct Rung);
269 prev->rung_off = rung->rung_off - 1; 264 prev->rung_off = rung->rung_off - 1;
270 GNUNET_CONTAINER_DLL_insert_after (rung_head, 265 GNUNET_CONTAINER_DLL_insert_after (rung_head, rung_tail, rung->prev, prev);
271 rung_tail,
272 rung->prev,
273 prev);
274 } 266 }
275 GNUNET_assert (NULL != prev); 267 GNUNET_assert (NULL != prev);
276 GNUNET_CONTAINER_DLL_insert (prev->rd_head, 268 GNUNET_CONTAINER_DLL_insert (prev->rd_head, prev->rd_tail, dir);
277 prev->rd_tail,
278 dir);
279 dir->rung = prev; 269 dir->rung = prev;
280} 270}
281 271
@@ -288,19 +278,13 @@ lower_rung (struct RouteDirection *dir)
288 * @param env envelope to discard 278 * @param env envelope to discard
289 */ 279 */
290static void 280static void
291discard_buffer (struct RouteDirection *dir, 281discard_buffer (struct RouteDirection *dir, struct GNUNET_MQ_Envelope *env)
292 struct GNUNET_MQ_Envelope *env)
293{ 282{
294 GNUNET_MQ_dll_remove (&dir->env_head, 283 GNUNET_MQ_dll_remove (&dir->env_head, &dir->env_tail, env);
295 &dir->env_tail,
296 env);
297 cur_buffers--; 284 cur_buffers--;
298 GNUNET_MQ_discard (env); 285 GNUNET_MQ_discard (env);
299 lower_rung (dir); 286 lower_rung (dir);
300 GNUNET_STATISTICS_set (stats, 287 GNUNET_STATISTICS_set (stats, "# buffer use", cur_buffers, GNUNET_NO);
301 "# buffer use",
302 cur_buffers,
303 GNUNET_NO);
304} 288}
305 289
306 290
@@ -322,12 +306,9 @@ discard_all_from_rung_tail ()
322 "# messages dropped due to full buffer", 306 "# messages dropped due to full buffer",
323 1, 307 1,
324 GNUNET_NO); 308 GNUNET_NO);
325 discard_buffer (dir, 309 discard_buffer (dir, dir->env_head);
326 dir->env_head);
327 } 310 }
328 GNUNET_CONTAINER_DLL_remove (rung_head, 311 GNUNET_CONTAINER_DLL_remove (rung_head, rung_tail, tail);
329 rung_tail,
330 tail);
331 GNUNET_free (tail); 312 GNUNET_free (tail);
332} 313}
333 314
@@ -345,7 +326,7 @@ static void
345route_message (struct CadetPeer *prev, 326route_message (struct CadetPeer *prev,
346 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, 327 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
347 const struct GNUNET_MessageHeader *msg, 328 const struct GNUNET_MessageHeader *msg,
348 const enum GNUNET_MQ_PriorityPreferences priority) 329 const enum GNUNET_MQ_PriorityPreferences priority)
349{ 330{
350 struct CadetRoute *route; 331 struct CadetRoute *route;
351 struct RouteDirection *dir; 332 struct RouteDirection *dir;
@@ -371,17 +352,14 @@ route_message (struct CadetPeer *prev,
371 /* No need to respond to these! */ 352 /* No need to respond to these! */
372 return; 353 return;
373 } 354 }
374 env = GNUNET_MQ_msg (bm, 355 env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN);
375 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN);
376 bm->cid = *cid; 356 bm->cid = *cid;
377 bm->peer1 = my_full_id; 357 bm->peer1 = my_full_id;
378 GCP_send_ooo (prev, 358 GCP_send_ooo (prev, env);
379 env);
380 return; 359 return;
381 } 360 }
382 route->last_use = GNUNET_TIME_absolute_get (); 361 route->last_use = GNUNET_TIME_absolute_get ();
383 GNUNET_CONTAINER_heap_update_cost (route->hn, 362 GNUNET_CONTAINER_heap_update_cost (route->hn, route->last_use.abs_value_us);
384 route->last_use.abs_value_us);
385 dir = (prev == route->prev.hop) ? &route->next : &route->prev; 363 dir = (prev == route->prev.hop) ? &route->next : &route->prev;
386 if (GNUNET_YES == dir->is_ready) 364 if (GNUNET_YES == dir->is_ready)
387 { 365 {
@@ -392,27 +370,24 @@ route_message (struct CadetPeer *prev,
392 GNUNET_i2s (GCP_get_id (dir->hop)), 370 GNUNET_i2s (GCP_get_id (dir->hop)),
393 GNUNET_sh2s (&cid->connection_of_tunnel)); 371 GNUNET_sh2s (&cid->connection_of_tunnel));
394 dir->is_ready = GNUNET_NO; 372 dir->is_ready = GNUNET_NO;
395 GCP_send (dir->mqm, 373 GCP_send (dir->mqm, GNUNET_MQ_msg_copy (msg));
396 GNUNET_MQ_msg_copy (msg));
397 return; 374 return;
398 } 375 }
399 /* Check if buffering is disallowed, and if so, make sure we only queue 376 /* Check if low latency is required and if the previous message was
400 one message per direction. */ 377 unreliable; if so, make sure we only queue one message per
401 if ( (0 != (priority & GNUNET_MQ_PREF_NO_BUFFER)) && 378 direction (no buffering). */
402 (NULL != dir->env_head) ) 379 if ((0 != (priority & GNUNET_MQ_PREF_LOW_LATENCY)) &&
403 discard_buffer (dir, 380 (NULL != dir->env_head) &&
404 dir->env_head); 381 (0 ==
382 (GNUNET_MQ_env_get_options (dir->env_head) & GNUNET_MQ_PREF_UNRELIABLE)))
383 discard_buffer (dir, dir->env_head);
405 /* Check for duplicates */ 384 /* Check for duplicates */
406 for (const struct GNUNET_MQ_Envelope *env = dir->env_head; 385 for (const struct GNUNET_MQ_Envelope *env = dir->env_head; NULL != env;
407 NULL != env;
408 env = GNUNET_MQ_env_next (env)) 386 env = GNUNET_MQ_env_next (env))
409 { 387 {
410 const struct GNUNET_MessageHeader *hdr = GNUNET_MQ_env_get_msg (env); 388 const struct GNUNET_MessageHeader *hdr = GNUNET_MQ_env_get_msg (env);
411 389
412 if ( (hdr->size == msg->size) && 390 if ((hdr->size == msg->size) && (0 == memcmp (hdr, msg, ntohs (msg->size))))
413 (0 == memcmp (hdr,
414 msg,
415 ntohs (msg->size))) )
416 { 391 {
417 LOG (GNUNET_ERROR_TYPE_DEBUG, 392 LOG (GNUNET_ERROR_TYPE_DEBUG,
418 "Received duplicate of message already in buffer, dropping\n"); 393 "Received duplicate of message already in buffer, dropping\n");
@@ -443,31 +418,22 @@ route_message (struct CadetPeer *prev,
443 "# messages dropped due to full buffer", 418 "# messages dropped due to full buffer",
444 1, 419 1,
445 GNUNET_NO); 420 GNUNET_NO);
446 discard_buffer (dir, 421 discard_buffer (dir, dir->env_head);
447 dir->env_head);
448 rung = dir->rung; 422 rung = dir->rung;
449 } 423 }
450 } 424 }
451 /* remove 'dir' from current rung */ 425 /* remove 'dir' from current rung */
452 GNUNET_CONTAINER_DLL_remove (rung->rd_head, 426 GNUNET_CONTAINER_DLL_remove (rung->rd_head, rung->rd_tail, dir);
453 rung->rd_tail,
454 dir);
455 /* make 'nxt' point to the next higher rung, create if necessary */ 427 /* make 'nxt' point to the next higher rung, create if necessary */
456 nxt = rung->next; 428 nxt = rung->next;
457 if ( (NULL == nxt) || 429 if ((NULL == nxt) || (rung->rung_off + 1 != nxt->rung_off))
458 (rung->rung_off + 1 != nxt->rung_off) )
459 { 430 {
460 nxt = GNUNET_new (struct Rung); 431 nxt = GNUNET_new (struct Rung);
461 nxt->rung_off = rung->rung_off + 1; 432 nxt->rung_off = rung->rung_off + 1;
462 GNUNET_CONTAINER_DLL_insert_after (rung_head, 433 GNUNET_CONTAINER_DLL_insert_after (rung_head, rung_tail, rung, nxt);
463 rung_tail,
464 rung,
465 nxt);
466 } 434 }
467 /* insert 'dir' into next higher rung */ 435 /* insert 'dir' into next higher rung */
468 GNUNET_CONTAINER_DLL_insert (nxt->rd_head, 436 GNUNET_CONTAINER_DLL_insert (nxt->rd_head, nxt->rd_tail, dir);
469 nxt->rd_tail,
470 dir);
471 dir->rung = nxt; 437 dir->rung = nxt;
472 438
473 /* add message into 'dir' buffer */ 439 /* add message into 'dir' buffer */
@@ -478,21 +444,21 @@ route_message (struct CadetPeer *prev,
478 GNUNET_i2s (GCP_get_id (dir->hop)), 444 GNUNET_i2s (GCP_get_id (dir->hop)),
479 GNUNET_sh2s (&cid->connection_of_tunnel)); 445 GNUNET_sh2s (&cid->connection_of_tunnel));
480 env = GNUNET_MQ_msg_copy (msg); 446 env = GNUNET_MQ_msg_copy (msg);
481 GNUNET_MQ_dll_insert_tail (&dir->env_head, 447 GNUNET_MQ_env_set_options (env, priority);
482 &dir->env_tail, 448 if ((0 != (priority & GNUNET_MQ_PREF_LOW_LATENCY)) &&
483 env); 449 (0 != (priority & GNUNET_MQ_PREF_OUT_OF_ORDER)) &&
450 (NULL != dir->env_head) &&
451 (0 == (GNUNET_MQ_env_get_options (dir->env_head) &
452 GNUNET_MQ_PREF_LOW_LATENCY)))
453 GNUNET_MQ_dll_insert_head (&dir->env_head, &dir->env_tail, env);
454 else
455 GNUNET_MQ_dll_insert_tail (&dir->env_head, &dir->env_tail, env);
484 cur_buffers++; 456 cur_buffers++;
485 GNUNET_STATISTICS_set (stats, 457 GNUNET_STATISTICS_set (stats, "# buffer use", cur_buffers, GNUNET_NO);
486 "# buffer use",
487 cur_buffers,
488 GNUNET_NO);
489 /* Clean up 'rung' if now empty (and not head) */ 458 /* Clean up 'rung' if now empty (and not head) */
490 if ( (NULL == rung->rd_head) && 459 if ((NULL == rung->rd_head) && (rung != rung_head))
491 (rung != rung_head) )
492 { 460 {
493 GNUNET_CONTAINER_DLL_remove (rung_head, 461 GNUNET_CONTAINER_DLL_remove (rung_head, rung_tail, rung);
494 rung_tail,
495 rung);
496 GNUNET_free (rung); 462 GNUNET_free (rung);
497 } 463 }
498} 464}
@@ -537,18 +503,14 @@ destroy_direction (struct RouteDirection *dir)
537 "# messages dropped due to route destruction", 503 "# messages dropped due to route destruction",
538 1, 504 1,
539 GNUNET_NO); 505 GNUNET_NO);
540 discard_buffer (dir, 506 discard_buffer (dir, env);
541 env);
542 } 507 }
543 if (NULL != dir->mqm) 508 if (NULL != dir->mqm)
544 { 509 {
545 GCP_request_mq_cancel (dir->mqm, 510 GCP_request_mq_cancel (dir->mqm, NULL);
546 NULL);
547 dir->mqm = NULL; 511 dir->mqm = NULL;
548 } 512 }
549 GNUNET_CONTAINER_DLL_remove (rung_head->rd_head, 513 GNUNET_CONTAINER_DLL_remove (rung_head->rd_head, rung_head->rd_tail, dir);
550 rung_head->rd_tail,
551 dir);
552} 514}
553 515
554 516
@@ -562,15 +524,15 @@ destroy_route (struct CadetRoute *route)
562{ 524{
563 LOG (GNUNET_ERROR_TYPE_DEBUG, 525 LOG (GNUNET_ERROR_TYPE_DEBUG,
564 "Destroying route from %s to %s of connection %s\n", 526 "Destroying route from %s to %s of connection %s\n",
565 GNUNET_i2s (GCP_get_id (route->prev.hop)), 527 GNUNET_i2s (GCP_get_id (route->prev.hop)),
566 GNUNET_i2s2 (GCP_get_id (route->next.hop)), 528 GNUNET_i2s2 (GCP_get_id (route->next.hop)),
567 GNUNET_sh2s (&route->cid.connection_of_tunnel)); 529 GNUNET_sh2s (&route->cid.connection_of_tunnel));
568 GNUNET_assert (route == 530 GNUNET_assert (route == GNUNET_CONTAINER_heap_remove_node (route->hn));
569 GNUNET_CONTAINER_heap_remove_node (route->hn)); 531 GNUNET_assert (
570 GNUNET_assert (GNUNET_YES == 532 GNUNET_YES ==
571 GNUNET_CONTAINER_multishortmap_remove (routes, 533 GNUNET_CONTAINER_multishortmap_remove (routes,
572 &route->cid.connection_of_tunnel, 534 &route->cid.connection_of_tunnel,
573 route)); 535 route));
574 GNUNET_STATISTICS_set (stats, 536 GNUNET_STATISTICS_set (stats,
575 "# routes", 537 "# routes",
576 GNUNET_CONTAINER_multishortmap_size (routes), 538 GNUNET_CONTAINER_multishortmap_size (routes),
@@ -607,15 +569,13 @@ send_broken (struct RouteDirection *target,
607 GNUNET_i2s2 (peer2), 569 GNUNET_i2s2 (peer2),
608 GNUNET_sh2s (&cid->connection_of_tunnel)); 570 GNUNET_sh2s (&cid->connection_of_tunnel));
609 571
610 env = GNUNET_MQ_msg (bm, 572 env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN);
611 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN);
612 bm->cid = *cid; 573 bm->cid = *cid;
613 if (NULL != peer1) 574 if (NULL != peer1)
614 bm->peer1 = *peer1; 575 bm->peer1 = *peer1;
615 if (NULL != peer2) 576 if (NULL != peer2)
616 bm->peer2 = *peer2; 577 bm->peer2 = *peer2;
617 GCP_request_mq_cancel (target->mqm, 578 GCP_request_mq_cancel (target->mqm, env);
618 env);
619 target->mqm = NULL; 579 target->mqm = NULL;
620} 580}
621 581
@@ -635,33 +595,22 @@ timeout_cb (void *cls)
635 struct GNUNET_TIME_Absolute exp; 595 struct GNUNET_TIME_Absolute exp;
636 596
637 timeout_task = NULL; 597 timeout_task = NULL;
638 linger = GNUNET_TIME_relative_multiply (keepalive_period, 598 linger = GNUNET_TIME_relative_multiply (keepalive_period, 3);
639 3);
640 while (NULL != (r = GNUNET_CONTAINER_heap_peek (route_heap))) 599 while (NULL != (r = GNUNET_CONTAINER_heap_peek (route_heap)))
641 { 600 {
642 exp = GNUNET_TIME_absolute_add (r->last_use, 601 exp = GNUNET_TIME_absolute_add (r->last_use, linger);
643 linger);
644 if (0 != GNUNET_TIME_absolute_get_remaining (exp).rel_value_us) 602 if (0 != GNUNET_TIME_absolute_get_remaining (exp).rel_value_us)
645 { 603 {
646 /* Route not yet timed out, wait until it does. */ 604 /* Route not yet timed out, wait until it does. */
647 timeout_task = GNUNET_SCHEDULER_add_at (exp, 605 timeout_task = GNUNET_SCHEDULER_add_at (exp, &timeout_cb, NULL);
648 &timeout_cb,
649 NULL);
650 return; 606 return;
651 } 607 }
652 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 608 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
653 "Sending BROKEN due to timeout (%s was last use, %s linger)\n", 609 "Sending BROKEN due to timeout (%s was last use, %s linger)\n",
654 GNUNET_STRINGS_absolute_time_to_string (r->last_use), 610 GNUNET_STRINGS_absolute_time_to_string (r->last_use),
655 GNUNET_STRINGS_relative_time_to_string (linger, 611 GNUNET_STRINGS_relative_time_to_string (linger, GNUNET_YES));
656 GNUNET_YES)); 612 send_broken (&r->prev, &r->cid, NULL, NULL);
657 send_broken (&r->prev, 613 send_broken (&r->next, &r->cid, NULL, NULL);
658 &r->cid,
659 NULL,
660 NULL);
661 send_broken (&r->next,
662 &r->cid,
663 NULL,
664 NULL);
665 destroy_route (r); 614 destroy_route (r);
666 } 615 }
667 /* No more routes left, so no need for a #timeout_task */ 616 /* No more routes left, so no need for a #timeout_task */
@@ -681,8 +630,7 @@ timeout_cb (void *cls)
681 * and the last envelope was discarded 630 * and the last envelope was discarded
682 */ 631 */
683static void 632static void
684dir_ready_cb (void *cls, 633dir_ready_cb (void *cls, int ready)
685 int ready)
686{ 634{
687 struct RouteDirection *dir = cls; 635 struct RouteDirection *dir = cls;
688 struct CadetRoute *route = dir->my_route; 636 struct CadetRoute *route = dir->my_route;
@@ -695,28 +643,18 @@ dir_ready_cb (void *cls,
695 dir->is_ready = GNUNET_YES; 643 dir->is_ready = GNUNET_YES;
696 if (NULL != (env = dir->env_head)) 644 if (NULL != (env = dir->env_head))
697 { 645 {
698 GNUNET_MQ_dll_remove (&dir->env_head, 646 GNUNET_MQ_dll_remove (&dir->env_head, &dir->env_tail, env);
699 &dir->env_tail,
700 env);
701 cur_buffers--; 647 cur_buffers--;
702 GNUNET_STATISTICS_set (stats, 648 GNUNET_STATISTICS_set (stats, "# buffer use", cur_buffers, GNUNET_NO);
703 "# buffer use",
704 cur_buffers,
705 GNUNET_NO);
706 lower_rung (dir); 649 lower_rung (dir);
707 dir->is_ready = GNUNET_NO; 650 dir->is_ready = GNUNET_NO;
708 GCP_send (dir->mqm, 651 GCP_send (dir->mqm, env);
709 env);
710 } 652 }
711 return; 653 return;
712 } 654 }
713 odir = (dir == &route->next) ? &route->prev : &route->next; 655 odir = (dir == &route->next) ? &route->prev : &route->next;
714 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 656 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending BROKEN due to MQ going down\n");
715 "Sending BROKEN due to MQ going down\n"); 657 send_broken (&route->next, &route->cid, GCP_get_id (odir->hop), &my_full_id);
716 send_broken (&route->next,
717 &route->cid,
718 GCP_get_id (odir->hop),
719 &my_full_id);
720 destroy_route (route); 658 destroy_route (route);
721} 659}
722 660
@@ -735,12 +673,8 @@ dir_init (struct RouteDirection *dir,
735{ 673{
736 dir->hop = hop; 674 dir->hop = hop;
737 dir->my_route = route; 675 dir->my_route = route;
738 dir->mqm = GCP_request_mq (hop, 676 dir->mqm = GCP_request_mq (hop, &dir_ready_cb, dir);
739 &dir_ready_cb, 677 GNUNET_CONTAINER_DLL_insert (rung_head->rd_head, rung_head->rd_tail, dir);
740 dir);
741 GNUNET_CONTAINER_DLL_insert (rung_head->rd_head,
742 rung_head->rd_tail,
743 dir);
744 dir->rung = rung_head; 678 dir->rung = rung_head;
745 GNUNET_assert (GNUNET_YES == dir->is_ready); 679 GNUNET_assert (GNUNET_YES == dir->is_ready);
746} 680}
@@ -757,21 +691,20 @@ dir_init (struct RouteDirection *dir,
757 * or NULL. 691 * or NULL.
758 */ 692 */
759static void 693static void
760send_broken_without_mqm (struct CadetPeer *target, 694send_broken_without_mqm (
761 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, 695 struct CadetPeer *target,
762 const struct GNUNET_PeerIdentity *failure_at) 696 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
697 const struct GNUNET_PeerIdentity *failure_at)
763{ 698{
764 struct GNUNET_MQ_Envelope *env; 699 struct GNUNET_MQ_Envelope *env;
765 struct GNUNET_CADET_ConnectionBrokenMessage *bm; 700 struct GNUNET_CADET_ConnectionBrokenMessage *bm;
766 701
767 env = GNUNET_MQ_msg (bm, 702 env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN);
768 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN);
769 bm->cid = *cid; 703 bm->cid = *cid;
770 bm->peer1 = my_full_id; 704 bm->peer1 = my_full_id;
771 if (NULL != failure_at) 705 if (NULL != failure_at)
772 bm->peer2 = *failure_at; 706 bm->peer2 = *failure_at;
773 GCP_send_ooo (target, 707 GCP_send_ooo (target, env);
774 env);
775} 708}
776 709
777 710
@@ -782,12 +715,14 @@ send_broken_without_mqm (struct CadetPeer *target,
782 * @param msg Message itself. 715 * @param msg Message itself.
783 */ 716 */
784static void 717static void
785handle_connection_create (void *cls, 718handle_connection_create (
786 const struct GNUNET_CADET_ConnectionCreateMessage *msg) 719 void *cls,
720 const struct GNUNET_CADET_ConnectionCreateMessage *msg)
787{ 721{
788 struct CadetPeer *sender = cls; 722 struct CadetPeer *sender = cls;
789 struct CadetPeer *next; 723 struct CadetPeer *next;
790 const struct GNUNET_PeerIdentity *pids = (const struct GNUNET_PeerIdentity *) &msg[1]; 724 const struct GNUNET_PeerIdentity *pids =
725 (const struct GNUNET_PeerIdentity *) &msg[1];
791 struct CadetRoute *route; 726 struct CadetRoute *route;
792 uint16_t size = ntohs (msg->header.size) - sizeof (*msg); 727 uint16_t size = ntohs (msg->header.size) - sizeof (*msg);
793 unsigned int path_length; 728 unsigned int path_length;
@@ -810,20 +745,19 @@ handle_connection_create (void *cls,
810 { 745 {
811 struct GNUNET_CONTAINER_MultiPeerMap *map; 746 struct GNUNET_CONTAINER_MultiPeerMap *map;
812 747
813 map = GNUNET_CONTAINER_multipeermap_create (path_length * 2, 748 map = GNUNET_CONTAINER_multipeermap_create (path_length * 2, GNUNET_YES);
814 GNUNET_YES);
815 GNUNET_assert (NULL != map); 749 GNUNET_assert (NULL != map);
816 for (unsigned int i=0;i<path_length;i++) 750 for (unsigned int i = 0; i < path_length; i++)
817 { 751 {
818 LOG (GNUNET_ERROR_TYPE_DEBUG, 752 LOG (GNUNET_ERROR_TYPE_DEBUG,
819 "CADET_CONNECTION_CREATE has peer %s at offset %u\n", 753 "CADET_CONNECTION_CREATE has peer %s at offset %u\n",
820 GNUNET_i2s (&pids[i]), 754 GNUNET_i2s (&pids[i]),
821 i); 755 i);
822 if (GNUNET_SYSERR == 756 if (GNUNET_SYSERR == GNUNET_CONTAINER_multipeermap_put (
823 GNUNET_CONTAINER_multipeermap_put (map, 757 map,
824 &pids[i], 758 &pids[i],
825 NULL, 759 NULL,
826 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 760 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
827 { 761 {
828 /* bogus request */ 762 /* bogus request */
829 GNUNET_CONTAINER_multipeermap_destroy (map); 763 GNUNET_CONTAINER_multipeermap_destroy (map);
@@ -836,9 +770,8 @@ handle_connection_create (void *cls,
836 GNUNET_CONTAINER_multipeermap_destroy (map); 770 GNUNET_CONTAINER_multipeermap_destroy (map);
837 } 771 }
838 /* Initiator is at offset 0, find us */ 772 /* Initiator is at offset 0, find us */
839 for (off=1;off<path_length;off++) 773 for (off = 1; off < path_length; off++)
840 if (0 == GNUNET_memcmp (&my_full_id, 774 if (0 == GNUNET_memcmp (&my_full_id, &pids[off]))
841 &pids[off]))
842 break; 775 break;
843 if (off == path_length) 776 if (off == path_length)
844 { 777 {
@@ -848,16 +781,14 @@ handle_connection_create (void *cls,
848 return; 781 return;
849 } 782 }
850 /* Check previous hop */ 783 /* Check previous hop */
851 if (sender != GCP_get (&pids[off - 1], 784 if (sender != GCP_get (&pids[off - 1], GNUNET_NO))
852 GNUNET_NO))
853 { 785 {
854 LOG (GNUNET_ERROR_TYPE_DEBUG, 786 LOG (GNUNET_ERROR_TYPE_DEBUG,
855 "Dropping CADET_CONNECTION_CREATE without sender at previous hop in the path\n"); 787 "Dropping CADET_CONNECTION_CREATE without sender at previous hop in the path\n");
856 GNUNET_break_op (0); 788 GNUNET_break_op (0);
857 return; 789 return;
858 } 790 }
859 if (NULL != 791 if (NULL != (route = get_route (&msg->cid)))
860 (route = get_route (&msg->cid)))
861 { 792 {
862 /* Duplicate CREATE, pass it on, previous one might have been lost! */ 793 /* Duplicate CREATE, pass it on, previous one might have been lost! */
863 794
@@ -867,7 +798,8 @@ handle_connection_create (void *cls,
867 route_message (sender, 798 route_message (sender,
868 &msg->cid, 799 &msg->cid,
869 &msg->header, 800 &msg->header,
870 GNUNET_MQ_PRIO_CRITICAL_CONTROL); 801 GNUNET_MQ_PRIO_CRITICAL_CONTROL |
802 GNUNET_MQ_PREF_LOW_LATENCY);
871 return; 803 return;
872 } 804 }
873 if (off == path_length - 1) 805 if (off == path_length - 1)
@@ -887,17 +819,14 @@ handle_connection_create (void *cls,
887 return; 819 return;
888 } 820 }
889 821
890 origin = GCP_get (&pids[0], 822 origin = GCP_get (&pids[0], GNUNET_YES);
891 GNUNET_YES);
892 LOG (GNUNET_ERROR_TYPE_DEBUG, 823 LOG (GNUNET_ERROR_TYPE_DEBUG,
893 "I am destination for CADET_CONNECTION_CREATE message from %s for connection %s, building inverse path\n", 824 "I am destination for CADET_CONNECTION_CREATE message from %s for connection %s, building inverse path\n",
894 GCP_2s (origin), 825 GCP_2s (origin),
895 GNUNET_sh2s (&msg->cid.connection_of_tunnel)); 826 GNUNET_sh2s (&msg->cid.connection_of_tunnel));
896 path = GCPP_get_path_from_route (path_length - 1, 827 path = GCPP_get_path_from_route (path_length - 1, pids);
897 pids);
898 if (GNUNET_OK != 828 if (GNUNET_OK !=
899 GCT_add_inbound_connection (GCP_get_tunnel (origin, 829 GCT_add_inbound_connection (GCP_get_tunnel (origin, GNUNET_YES),
900 GNUNET_YES),
901 &msg->cid, 830 &msg->cid,
902 path)) 831 path))
903 { 832 {
@@ -908,18 +837,14 @@ handle_connection_create (void *cls,
908 GCP_2s (sender), 837 GCP_2s (sender),
909 GNUNET_sh2s (&msg->cid.connection_of_tunnel), 838 GNUNET_sh2s (&msg->cid.connection_of_tunnel),
910 GCPP_2s (path)); 839 GCPP_2s (path));
911 send_broken_without_mqm (sender, 840 send_broken_without_mqm (sender, &msg->cid, NULL);
912 &msg->cid,
913 NULL);
914 return; 841 return;
915 } 842 }
916 return; 843 return;
917 } 844 }
918 /* We are merely a hop on the way, check if we can support the route */ 845 /* We are merely a hop on the way, check if we can support the route */
919 next = GCP_get (&pids[off + 1], 846 next = GCP_get (&pids[off + 1], GNUNET_NO);
920 GNUNET_NO); 847 if ((NULL == next) || (GNUNET_NO == GCP_has_core_connection (next)))
921 if ( (NULL == next) ||
922 (GNUNET_NO == GCP_has_core_connection (next)) )
923 { 848 {
924 /* unworkable, send back BROKEN notification */ 849 /* unworkable, send back BROKEN notification */
925 LOG (GNUNET_ERROR_TYPE_DEBUG, 850 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -928,9 +853,7 @@ handle_connection_create (void *cls,
928 GNUNET_sh2s (&msg->cid.connection_of_tunnel), 853 GNUNET_sh2s (&msg->cid.connection_of_tunnel),
929 GNUNET_i2s (&pids[off + 1]), 854 GNUNET_i2s (&pids[off + 1]),
930 off + 1); 855 off + 1);
931 send_broken_without_mqm (sender, 856 send_broken_without_mqm (sender, &msg->cid, &pids[off + 1]);
932 &msg->cid,
933 &pids[off + 1]);
934 return; 857 return;
935 } 858 }
936 if (max_routes <= GNUNET_CONTAINER_multishortmap_size (routes)) 859 if (max_routes <= GNUNET_CONTAINER_multishortmap_size (routes))
@@ -939,9 +862,7 @@ handle_connection_create (void *cls,
939 "Received CADET_CONNECTION_CREATE from %s for %s. We have reached our route limit. Sending BROKEN\n", 862 "Received CADET_CONNECTION_CREATE from %s for %s. We have reached our route limit. Sending BROKEN\n",
940 GCP_2s (sender), 863 GCP_2s (sender),
941 GNUNET_sh2s (&msg->cid.connection_of_tunnel)); 864 GNUNET_sh2s (&msg->cid.connection_of_tunnel));
942 send_broken_without_mqm (sender, 865 send_broken_without_mqm (sender, &msg->cid, &pids[off - 1]);
943 &msg->cid,
944 &pids[off - 1]);
945 return; 866 return;
946 } 867 }
947 868
@@ -955,17 +876,14 @@ handle_connection_create (void *cls,
955 route = GNUNET_new (struct CadetRoute); 876 route = GNUNET_new (struct CadetRoute);
956 route->cid = msg->cid; 877 route->cid = msg->cid;
957 route->last_use = GNUNET_TIME_absolute_get (); 878 route->last_use = GNUNET_TIME_absolute_get ();
958 dir_init (&route->prev, 879 dir_init (&route->prev, route, sender);
959 route, 880 dir_init (&route->next, route, next);
960 sender);
961 dir_init (&route->next,
962 route,
963 next);
964 GNUNET_assert (GNUNET_OK == 881 GNUNET_assert (GNUNET_OK ==
965 GNUNET_CONTAINER_multishortmap_put (routes, 882 GNUNET_CONTAINER_multishortmap_put (
966 &route->cid.connection_of_tunnel, 883 routes,
967 route, 884 &route->cid.connection_of_tunnel,
968 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 885 route,
886 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
969 GNUNET_STATISTICS_set (stats, 887 GNUNET_STATISTICS_set (stats,
970 "# routes", 888 "# routes",
971 GNUNET_CONTAINER_multishortmap_size (routes), 889 GNUNET_CONTAINER_multishortmap_size (routes),
@@ -974,15 +892,16 @@ handle_connection_create (void *cls,
974 route, 892 route,
975 route->last_use.abs_value_us); 893 route->last_use.abs_value_us);
976 if (NULL == timeout_task) 894 if (NULL == timeout_task)
977 timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (keepalive_period, 895 timeout_task =
978 3), 896 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (keepalive_period,
979 &timeout_cb, 897 3),
980 NULL); 898 &timeout_cb,
899 NULL);
981 /* also pass CREATE message along to next hop */ 900 /* also pass CREATE message along to next hop */
982 route_message (sender, 901 route_message (sender,
983 &msg->cid, 902 &msg->cid,
984 &msg->header, 903 &msg->header,
985 GNUNET_MQ_PRIO_CRITICAL_CONTROL); 904 GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY);
986} 905}
987 906
988 907
@@ -993,8 +912,9 @@ handle_connection_create (void *cls,
993 * @param msg Message itself. 912 * @param msg Message itself.
994 */ 913 */
995static void 914static void
996handle_connection_create_ack (void *cls, 915handle_connection_create_ack (
997 const struct GNUNET_CADET_ConnectionCreateAckMessage *msg) 916 void *cls,
917 const struct GNUNET_CADET_ConnectionCreateAckMessage *msg)
998{ 918{
999 struct CadetPeer *peer = cls; 919 struct CadetPeer *peer = cls;
1000 struct CadetConnection *cc; 920 struct CadetConnection *cc;
@@ -1005,12 +925,9 @@ handle_connection_create_ack (void *cls,
1005 { 925 {
1006 /* verify ACK came from the right direction */ 926 /* verify ACK came from the right direction */
1007 unsigned int len; 927 unsigned int len;
1008 struct CadetPeerPath *path = GCC_get_path (cc, 928 struct CadetPeerPath *path = GCC_get_path (cc, &len);
1009 &len);
1010 929
1011 if (peer != 930 if (peer != GCPP_get_peer_at_offset (path, 0))
1012 GCPP_get_peer_at_offset (path,
1013 0))
1014 { 931 {
1015 /* received ACK from unexpected direction, ignore! */ 932 /* received ACK from unexpected direction, ignore! */
1016 GNUNET_break_op (0); 933 GNUNET_break_op (0);
@@ -1027,7 +944,7 @@ handle_connection_create_ack (void *cls,
1027 route_message (peer, 944 route_message (peer,
1028 &msg->cid, 945 &msg->cid,
1029 &msg->header, 946 &msg->header,
1030 GNUNET_MQ_PRIO_CRITICAL_CONTROL); 947 GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY);
1031} 948}
1032 949
1033 950
@@ -1039,8 +956,9 @@ handle_connection_create_ack (void *cls,
1039 * @deprecated duplicate logic with #handle_destroy(); dedup! 956 * @deprecated duplicate logic with #handle_destroy(); dedup!
1040 */ 957 */
1041static void 958static void
1042handle_connection_broken (void *cls, 959handle_connection_broken (
1043 const struct GNUNET_CADET_ConnectionBrokenMessage *msg) 960 void *cls,
961 const struct GNUNET_CADET_ConnectionBrokenMessage *msg)
1044{ 962{
1045 struct CadetPeer *peer = cls; 963 struct CadetPeer *peer = cls;
1046 struct CadetConnection *cc; 964 struct CadetConnection *cc;
@@ -1052,12 +970,9 @@ handle_connection_broken (void *cls,
1052 { 970 {
1053 /* verify message came from the right direction */ 971 /* verify message came from the right direction */
1054 unsigned int len; 972 unsigned int len;
1055 struct CadetPeerPath *path = GCC_get_path (cc, 973 struct CadetPeerPath *path = GCC_get_path (cc, &len);
1056 &len);
1057 974
1058 if (peer != 975 if (peer != GCPP_get_peer_at_offset (path, 0))
1059 GCPP_get_peer_at_offset (path,
1060 0))
1061 { 976 {
1062 /* received message from unexpected direction, ignore! */ 977 /* received message from unexpected direction, ignore! */
1063 GNUNET_break_op (0); 978 GNUNET_break_op (0);
@@ -1076,7 +991,7 @@ handle_connection_broken (void *cls,
1076 route_message (peer, 991 route_message (peer,
1077 &msg->cid, 992 &msg->cid,
1078 &msg->header, 993 &msg->header,
1079 GNUNET_MQ_PREF_NO_BUFFER); 994 GNUNET_MQ_PREF_LOW_LATENCY | GNUNET_MQ_PRIO_CRITICAL_CONTROL);
1080 route = get_route (&msg->cid); 995 route = get_route (&msg->cid);
1081 if (NULL != route) 996 if (NULL != route)
1082 destroy_route (route); 997 destroy_route (route);
@@ -1091,8 +1006,9 @@ handle_connection_broken (void *cls,
1091 * @param msg Message itself. 1006 * @param msg Message itself.
1092 */ 1007 */
1093static void 1008static void
1094handle_connection_destroy (void *cls, 1009handle_connection_destroy (
1095 const struct GNUNET_CADET_ConnectionDestroyMessage *msg) 1010 void *cls,
1011 const struct GNUNET_CADET_ConnectionDestroyMessage *msg)
1096{ 1012{
1097 struct CadetPeer *peer = cls; 1013 struct CadetPeer *peer = cls;
1098 struct CadetConnection *cc; 1014 struct CadetConnection *cc;
@@ -1104,12 +1020,9 @@ handle_connection_destroy (void *cls,
1104 { 1020 {
1105 /* verify message came from the right direction */ 1021 /* verify message came from the right direction */
1106 unsigned int len; 1022 unsigned int len;
1107 struct CadetPeerPath *path = GCC_get_path (cc, 1023 struct CadetPeerPath *path = GCC_get_path (cc, &len);
1108 &len);
1109 1024
1110 if (peer != 1025 if (peer != GCPP_get_peer_at_offset (path, 0))
1111 GCPP_get_peer_at_offset (path,
1112 0))
1113 { 1026 {
1114 /* received message from unexpected direction, ignore! */ 1027 /* received message from unexpected direction, ignore! */
1115 GNUNET_break_op (0); 1028 GNUNET_break_op (0);
@@ -1130,7 +1043,7 @@ handle_connection_destroy (void *cls,
1130 route_message (peer, 1043 route_message (peer,
1131 &msg->cid, 1044 &msg->cid,
1132 &msg->header, 1045 &msg->header,
1133 GNUNET_MQ_PREF_NO_BUFFER); 1046 GNUNET_MQ_PREF_LOW_LATENCY | GNUNET_MQ_PRIO_CRITICAL_CONTROL);
1134 route = get_route (&msg->cid); 1047 route = get_route (&msg->cid);
1135 if (NULL != route) 1048 if (NULL != route)
1136 destroy_route (route); 1049 destroy_route (route);
@@ -1162,19 +1075,15 @@ handle_tunnel_kx (void *cls,
1162 { 1075 {
1163 /* verify message came from the right direction */ 1076 /* verify message came from the right direction */
1164 unsigned int len; 1077 unsigned int len;
1165 struct CadetPeerPath *path = GCC_get_path (cc, 1078 struct CadetPeerPath *path = GCC_get_path (cc, &len);
1166 &len);
1167 1079
1168 if (peer != 1080 if (peer != GCPP_get_peer_at_offset (path, 0))
1169 GCPP_get_peer_at_offset (path,
1170 0))
1171 { 1081 {
1172 /* received message from unexpected direction, ignore! */ 1082 /* received message from unexpected direction, ignore! */
1173 GNUNET_break_op (0); 1083 GNUNET_break_op (0);
1174 return; 1084 return;
1175 } 1085 }
1176 GCC_handle_kx (cc, 1086 GCC_handle_kx (cc, msg);
1177 msg);
1178 return; 1087 return;
1179 } 1088 }
1180 1089
@@ -1182,7 +1091,7 @@ handle_tunnel_kx (void *cls,
1182 route_message (peer, 1091 route_message (peer,
1183 &msg->cid, 1092 &msg->cid,
1184 &msg->header, 1093 &msg->header,
1185 GNUNET_MQ_PRIO_CRITICAL_CONTROL); 1094 GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY);
1186} 1095}
1187 1096
1188 1097
@@ -1193,8 +1102,9 @@ handle_tunnel_kx (void *cls,
1193 * @param msg Message itself. 1102 * @param msg Message itself.
1194 */ 1103 */
1195static void 1104static void
1196handle_tunnel_kx_auth (void *cls, 1105handle_tunnel_kx_auth (
1197 const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg) 1106 void *cls,
1107 const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg)
1198{ 1108{
1199 struct CadetPeer *peer = cls; 1109 struct CadetPeer *peer = cls;
1200 struct CadetConnection *cc; 1110 struct CadetConnection *cc;
@@ -1205,19 +1115,15 @@ handle_tunnel_kx_auth (void *cls,
1205 { 1115 {
1206 /* verify message came from the right direction */ 1116 /* verify message came from the right direction */
1207 unsigned int len; 1117 unsigned int len;
1208 struct CadetPeerPath *path = GCC_get_path (cc, 1118 struct CadetPeerPath *path = GCC_get_path (cc, &len);
1209 &len);
1210 1119
1211 if (peer != 1120 if (peer != GCPP_get_peer_at_offset (path, 0))
1212 GCPP_get_peer_at_offset (path,
1213 0))
1214 { 1121 {
1215 /* received message from unexpected direction, ignore! */ 1122 /* received message from unexpected direction, ignore! */
1216 GNUNET_break_op (0); 1123 GNUNET_break_op (0);
1217 return; 1124 return;
1218 } 1125 }
1219 GCC_handle_kx_auth (cc, 1126 GCC_handle_kx_auth (cc, msg);
1220 msg);
1221 return; 1127 return;
1222 } 1128 }
1223 1129
@@ -1225,7 +1131,7 @@ handle_tunnel_kx_auth (void *cls,
1225 route_message (peer, 1131 route_message (peer,
1226 &msg->kx.cid, 1132 &msg->kx.cid,
1227 &msg->kx.header, 1133 &msg->kx.header,
1228 GNUNET_MQ_PRIO_CRITICAL_CONTROL); 1134 GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY);
1229} 1135}
1230 1136
1231 1137
@@ -1264,26 +1170,19 @@ handle_tunnel_encrypted (void *cls,
1264 { 1170 {
1265 /* verify message came from the right direction */ 1171 /* verify message came from the right direction */
1266 unsigned int len; 1172 unsigned int len;
1267 struct CadetPeerPath *path = GCC_get_path (cc, 1173 struct CadetPeerPath *path = GCC_get_path (cc, &len);
1268 &len);
1269 1174
1270 if (peer != 1175 if (peer != GCPP_get_peer_at_offset (path, 0))
1271 GCPP_get_peer_at_offset (path,
1272 0))
1273 { 1176 {
1274 /* received message from unexpected direction, ignore! */ 1177 /* received message from unexpected direction, ignore! */
1275 GNUNET_break_op (0); 1178 GNUNET_break_op (0);
1276 return; 1179 return;
1277 } 1180 }
1278 GCC_handle_encrypted (cc, 1181 GCC_handle_encrypted (cc, msg);
1279 msg);
1280 return; 1182 return;
1281 } 1183 }
1282 /* We're just an intermediary peer, route the message along its path */ 1184 /* We're just an intermediary peer, route the message along its path */
1283 route_message (peer, 1185 route_message (peer, &msg->cid, &msg->header, GNUNET_MQ_PRIO_BEST_EFFORT);
1284 &msg->cid,
1285 &msg->header,
1286 GNUNET_MQ_PRIO_CRITICAL_CONTROL);
1287} 1186}
1288 1187
1289 1188
@@ -1300,17 +1199,14 @@ handle_tunnel_encrypted (void *cls,
1300 * @param my_identity ID of this peer, NULL if we failed 1199 * @param my_identity ID of this peer, NULL if we failed
1301 */ 1200 */
1302static void 1201static void
1303core_init_cb (void *cls, 1202core_init_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity)
1304 const struct GNUNET_PeerIdentity *my_identity)
1305{ 1203{
1306 if (NULL == my_identity) 1204 if (NULL == my_identity)
1307 { 1205 {
1308 GNUNET_break (0); 1206 GNUNET_break (0);
1309 return; 1207 return;
1310 } 1208 }
1311 GNUNET_break (0 == 1209 GNUNET_break (0 == GNUNET_memcmp (my_identity, &my_full_id));
1312 GNUNET_memcmp (my_identity,
1313 &my_full_id));
1314} 1210}
1315 1211
1316 1212
@@ -1330,10 +1226,8 @@ core_connect_cb (void *cls,
1330 LOG (GNUNET_ERROR_TYPE_DEBUG, 1226 LOG (GNUNET_ERROR_TYPE_DEBUG,
1331 "CORE connection to peer %s was established.\n", 1227 "CORE connection to peer %s was established.\n",
1332 GNUNET_i2s (peer)); 1228 GNUNET_i2s (peer));
1333 cp = GCP_get (peer, 1229 cp = GCP_get (peer, GNUNET_YES);
1334 GNUNET_YES); 1230 GCP_set_mq (cp, mq);
1335 GCP_set_mq (cp,
1336 mq);
1337 return cp; 1231 return cp;
1338} 1232}
1339 1233
@@ -1354,8 +1248,7 @@ core_disconnect_cb (void *cls,
1354 LOG (GNUNET_ERROR_TYPE_DEBUG, 1248 LOG (GNUNET_ERROR_TYPE_DEBUG,
1355 "CORE connection to peer %s went down.\n", 1249 "CORE connection to peer %s went down.\n",
1356 GNUNET_i2s (peer)); 1250 GNUNET_i2s (peer));
1357 GCP_set_mq (cp, 1251 GCP_set_mq (cp, NULL);
1358 NULL);
1359} 1252}
1360 1253
1361 1254
@@ -1367,52 +1260,48 @@ core_disconnect_cb (void *cls,
1367void 1260void
1368GCO_init (const struct GNUNET_CONFIGURATION_Handle *c) 1261GCO_init (const struct GNUNET_CONFIGURATION_Handle *c)
1369{ 1262{
1370 struct GNUNET_MQ_MessageHandler handlers[] = { 1263 struct GNUNET_MQ_MessageHandler handlers[] =
1371 GNUNET_MQ_hd_var_size (connection_create, 1264 {GNUNET_MQ_hd_var_size (connection_create,
1372 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE, 1265 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE,
1373 struct GNUNET_CADET_ConnectionCreateMessage, 1266 struct GNUNET_CADET_ConnectionCreateMessage,
1374 NULL), 1267 NULL),
1375 GNUNET_MQ_hd_fixed_size (connection_create_ack, 1268 GNUNET_MQ_hd_fixed_size (connection_create_ack,
1376 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK, 1269 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK,
1377 struct GNUNET_CADET_ConnectionCreateAckMessage, 1270 struct GNUNET_CADET_ConnectionCreateAckMessage,
1378 NULL), 1271 NULL),
1379 GNUNET_MQ_hd_fixed_size (connection_broken, 1272 GNUNET_MQ_hd_fixed_size (connection_broken,
1380 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN, 1273 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN,
1381 struct GNUNET_CADET_ConnectionBrokenMessage, 1274 struct GNUNET_CADET_ConnectionBrokenMessage,
1382 NULL), 1275 NULL),
1383 GNUNET_MQ_hd_fixed_size (connection_destroy, 1276 GNUNET_MQ_hd_fixed_size (connection_destroy,
1384 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY, 1277 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY,
1385 struct GNUNET_CADET_ConnectionDestroyMessage, 1278 struct GNUNET_CADET_ConnectionDestroyMessage,
1386 NULL), 1279 NULL),
1387 GNUNET_MQ_hd_fixed_size (tunnel_kx, 1280 GNUNET_MQ_hd_fixed_size (tunnel_kx,
1388 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX, 1281 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX,
1389 struct GNUNET_CADET_TunnelKeyExchangeMessage, 1282 struct GNUNET_CADET_TunnelKeyExchangeMessage,
1390 NULL), 1283 NULL),
1391 GNUNET_MQ_hd_fixed_size (tunnel_kx_auth, 1284 GNUNET_MQ_hd_fixed_size (tunnel_kx_auth,
1392 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH, 1285 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH,
1393 struct GNUNET_CADET_TunnelKeyExchangeAuthMessage, 1286 struct GNUNET_CADET_TunnelKeyExchangeAuthMessage,
1394 NULL), 1287 NULL),
1395 GNUNET_MQ_hd_var_size (tunnel_encrypted, 1288 GNUNET_MQ_hd_var_size (tunnel_encrypted,
1396 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED, 1289 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED,
1397 struct GNUNET_CADET_TunnelEncryptedMessage, 1290 struct GNUNET_CADET_TunnelEncryptedMessage,
1398 NULL), 1291 NULL),
1399 GNUNET_MQ_handler_end () 1292 GNUNET_MQ_handler_end ()};
1400 }; 1293
1401 1294 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (c,
1402 if (GNUNET_OK != 1295 "CADET",
1403 GNUNET_CONFIGURATION_get_value_number (c, 1296 "MAX_ROUTES",
1404 "CADET", 1297 &max_routes))
1405 "MAX_ROUTES", 1298 max_routes = 5000;
1406 &max_routes)) 1299 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (c,
1407 max_routes = 5000; 1300 "CADET",
1408 if (GNUNET_OK != 1301 "MAX_MSGS_QUEUE",
1409 GNUNET_CONFIGURATION_get_value_number (c, 1302 &max_buffers))
1410 "CADET", 1303 max_buffers = 10000;
1411 "MAX_MSGS_QUEUE", 1304 routes = GNUNET_CONTAINER_multishortmap_create (1024, GNUNET_NO);
1412 &max_buffers))
1413 max_buffers = 10000;
1414 routes = GNUNET_CONTAINER_multishortmap_create (1024,
1415 GNUNET_NO);
1416 route_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 1305 route_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
1417 core = GNUNET_CORE_connect (c, 1306 core = GNUNET_CORE_connect (c,
1418 NULL, 1307 NULL,