aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-05-04 11:44:08 +0000
committerChristian Grothoff <christian@grothoff.org>2012-05-04 11:44:08 +0000
commit78fb72223d74c89a7fa72c01caab1e21133fd58a (patch)
tree83c9070fd50b29cc7a1bc1cb595ebdb00168d52c /src/core
parentb9ffb70e297418c8b264da8864e4bf3a75fb3adf (diff)
downloadgnunet-78fb72223d74c89a7fa72c01caab1e21133fd58a.tar.gz
gnunet-78fb72223d74c89a7fa72c01caab1e21133fd58a.zip
-extra debugging code
Diffstat (limited to 'src/core')
-rw-r--r--src/core/gnunet-service-core.c2
-rw-r--r--src/core/gnunet-service-core_kx.c52
2 files changed, 50 insertions, 4 deletions
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c
index 2eb71c257..59d938364 100644
--- a/src/core/gnunet-service-core.c
+++ b/src/core/gnunet-service-core.c
@@ -56,9 +56,7 @@ struct GNUNET_STATISTICS_Handle *GSC_stats;
56static void 56static void
57cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 57cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
58{ 58{
59#if DEBUG_CORE
60 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service shutting down.\n"); 59 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service shutting down.\n");
61#endif
62 GSC_CLIENTS_done (); 60 GSC_CLIENTS_done ();
63 GSC_NEIGHBOURS_done (); 61 GSC_NEIGHBOURS_done ();
64 GSC_SESSIONS_done (); 62 GSC_SESSIONS_done ();
diff --git a/src/core/gnunet-service-core_kx.c b/src/core/gnunet-service-core_kx.c
index 798c114a4..708a6f657 100644
--- a/src/core/gnunet-service-core_kx.c
+++ b/src/core/gnunet-service-core_kx.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors) 3 (C) 2009, 2010, 2011, 2012 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -39,6 +39,12 @@
39 39
40 40
41/** 41/**
42 * Set to GNUNET_YES to perform some slightly expensive internal invariant checks.
43 */
44#define EXTRA_CHECKS GNUNET_NO
45
46
47/**
42 * How long do we wait for SET_KEY confirmation initially? 48 * How long do we wait for SET_KEY confirmation initially?
43 */ 49 */
44#define INITIAL_SET_KEY_RETRY_FREQUENCY GNUNET_TIME_relative_multiply (MAX_SET_KEY_DELAY, 1) 50#define INITIAL_SET_KEY_RETRY_FREQUENCY GNUNET_TIME_relative_multiply (MAX_SET_KEY_DELAY, 1)
@@ -433,6 +439,38 @@ static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key;
433static struct GNUNET_SERVER_MessageStreamTokenizer *mst; 439static struct GNUNET_SERVER_MessageStreamTokenizer *mst;
434 440
435 441
442#if EXTRA_CHECKS
443/**
444 * Check internal invariants of the given KX record.
445 *
446 * @param kx record to check
447 * @param file filename for error reporting
448 * @param line line number for error reporting
449 */
450static void
451check_kx_record (struct GSC_KeyExchangeInfo *kx,
452 const char *file,
453 int line)
454{
455 struct GNUNET_HashCode hc;
456
457 if (NULL == kx->public_key)
458 return;
459 GNUNET_CRYPTO_hash (kx->public_key, sizeof (*kx->public_key), &hc);
460 GNUNET_assert_at (0 == memcmp (&hc, &kx->peer, sizeof (struct GNUNET_HashCode)), file, line);
461}
462
463
464/**
465 * Check internal invariants of the given KX record.
466 *
467 * @param kx record to check
468 */
469#define CHECK_KX(kx) check_kx_record(kx, __FILE__, __LINE__)
470#else
471#define CHECK_KX(kx)
472#endif
473
436/** 474/**
437 * Derive an authentication key from "set key" information 475 * Derive an authentication key from "set key" information
438 * 476 *
@@ -637,6 +675,7 @@ process_hello (void *cls, const struct GNUNET_PeerIdentity *peer,
637 struct GSC_KeyExchangeInfo *kx = cls; 675 struct GSC_KeyExchangeInfo *kx = cls;
638 struct SetKeyMessage *skm; 676 struct SetKeyMessage *skm;
639 677
678 CHECK_KX (kx);
640 if (err_msg != NULL) 679 if (err_msg != NULL)
641 { 680 {
642 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 681 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -668,6 +707,7 @@ process_hello (void *cls, const struct GNUNET_PeerIdentity *peer,
668 &set_key_retry_task, kx); 707 &set_key_retry_task, kx);
669 return; 708 return;
670 } 709 }
710 GNUNET_break (0 == memcmp (peer, &kx->peer, sizeof (struct GNUNET_PeerIdentity)));
671 if (kx->public_key != NULL) 711 if (kx->public_key != NULL)
672 { 712 {
673 /* already have public key, why are we here? */ 713 /* already have public key, why are we here? */
@@ -682,8 +722,10 @@ process_hello (void *cls, const struct GNUNET_PeerIdentity *peer,
682 GNUNET_break (0); 722 GNUNET_break (0);
683 GNUNET_free (kx->public_key); 723 GNUNET_free (kx->public_key);
684 kx->public_key = NULL; 724 kx->public_key = NULL;
725 CHECK_KX (kx);
685 return; 726 return;
686 } 727 }
728 CHECK_KX (kx);
687 send_key (kx); 729 send_key (kx);
688 if (NULL != kx->skm_received) 730 if (NULL != kx->skm_received)
689 { 731 {
@@ -718,6 +760,7 @@ GSC_KX_start (const struct GNUNET_PeerIdentity *pid)
718 GNUNET_PEERINFO_iterate (peerinfo, pid, 760 GNUNET_PEERINFO_iterate (peerinfo, pid,
719 GNUNET_TIME_UNIT_FOREVER_REL /* timeout? */ , 761 GNUNET_TIME_UNIT_FOREVER_REL /* timeout? */ ,
720 &process_hello, kx); 762 &process_hello, kx);
763 CHECK_KX (kx);
721 return kx; 764 return kx;
722} 765}
723 766
@@ -774,7 +817,8 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx,
774 struct PongMessage *pong; 817 struct PongMessage *pong;
775 enum KxStateMachine sender_status; 818 enum KxStateMachine sender_status;
776 uint16_t size; 819 uint16_t size;
777 820
821 CHECK_KX (kx);
778 size = ntohs (msg->size); 822 size = ntohs (msg->size);
779 if (size != sizeof (struct SetKeyMessage)) 823 if (size != sizeof (struct SetKeyMessage))
780 { 824 {
@@ -813,6 +857,7 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx,
813 &m->signature, kx->public_key))) 857 &m->signature, kx->public_key)))
814 { 858 {
815 /* invalid signature */ 859 /* invalid signature */
860 CHECK_KX (kx);
816 GNUNET_break_op (0); 861 GNUNET_break_op (0);
817 return; 862 return;
818 } 863 }
@@ -1007,6 +1052,7 @@ setup_fresh_setkey (struct GSC_KeyExchangeInfo *kx)
1007 skm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_SET_KEY); 1052 skm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_SET_KEY);
1008 skm->creation_time = GNUNET_TIME_absolute_hton (kx->encrypt_key_created); 1053 skm->creation_time = GNUNET_TIME_absolute_hton (kx->encrypt_key_created);
1009 skm->target = kx->peer; 1054 skm->target = kx->peer;
1055 CHECK_KX (kx);
1010 GNUNET_assert (GNUNET_OK == 1056 GNUNET_assert (GNUNET_OK ==
1011 GNUNET_CRYPTO_rsa_encrypt (&kx->encrypt_key, 1057 GNUNET_CRYPTO_rsa_encrypt (&kx->encrypt_key,
1012 sizeof (struct 1058 sizeof (struct
@@ -1244,6 +1290,7 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx,
1244 GNUNET_NO); 1290 GNUNET_NO);
1245 kx->status = KX_STATE_UP; 1291 kx->status = KX_STATE_UP;
1246 GSC_SESSIONS_create (&kx->peer, kx); 1292 GSC_SESSIONS_create (&kx->peer, kx);
1293 CHECK_KX (kx);
1247 schedule_rekey (kx); 1294 schedule_rekey (kx);
1248 GNUNET_assert (kx->keep_alive_task == GNUNET_SCHEDULER_NO_TASK); 1295 GNUNET_assert (kx->keep_alive_task == GNUNET_SCHEDULER_NO_TASK);
1249 if (kx->emsg_received != NULL) 1296 if (kx->emsg_received != NULL)
@@ -1286,6 +1333,7 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx,
1286static void 1333static void
1287send_key (struct GSC_KeyExchangeInfo *kx) 1334send_key (struct GSC_KeyExchangeInfo *kx)
1288{ 1335{
1336 CHECK_KX (kx);
1289 if (kx->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK) 1337 if (kx->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK)
1290 { 1338 {
1291 GNUNET_SCHEDULER_cancel (kx->retry_set_key_task); 1339 GNUNET_SCHEDULER_cancel (kx->retry_set_key_task);