diff options
-rw-r--r-- | configure.ac | 8 | ||||
-rw-r--r-- | src/dht/gnunet-dht-driver.c | 88 |
2 files changed, 50 insertions, 46 deletions
diff --git a/configure.ac b/configure.ac index b958efc7e..2e2b90321 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -726,15 +726,15 @@ AC_MSG_RESULT($enable_experimental) | |||
726 | AM_CONDITIONAL([HAVE_EXPERIMENTAL], [test "x$enable_experimental" = "xyes"]) | 726 | AM_CONDITIONAL([HAVE_EXPERIMENTAL], [test "x$enable_experimental" = "xyes"]) |
727 | 727 | ||
728 | # should malicious code be compiled (code used for testing with malicious peers) | 728 | # should malicious code be compiled (code used for testing with malicious peers) |
729 | disable_malicious=yes | 729 | enable_malicious=0 |
730 | AC_MSG_CHECKING(whether to compile malicious code) | 730 | AC_MSG_CHECKING(whether to compile malicious code) |
731 | AC_ARG_ENABLE(malicious, | 731 | AC_ARG_ENABLE(malicious, |
732 | [AS_HELP_STRING([--enable-malicious], | 732 | [AS_HELP_STRING([--enable-malicious], |
733 | [enable compiling malicious code (only for developers for testing)])], | 733 | [enable compiling malicious code (only for developers for testing)])], |
734 | [enable_malicious=$enableval], | 734 | [enable_malicious=1], |
735 | [enable_malicious="no"]) | 735 | [enable_malicious=0]) |
736 | AC_MSG_RESULT($enable_malicious) | 736 | AC_MSG_RESULT($enable_malicious) |
737 | AM_CONDITIONAL([HAVE_MALICIOUS], [test "x$enable_malicious" = "xyes"]) | 737 | AM_CONDITIONAL([HAVE_MALICIOUS], [test "x$enable_malicious" = "x1"]) |
738 | AC_DEFINE_UNQUOTED([HAVE_MALICIOUS], $enable_malicious, [Compile malicious code]) | 738 | AC_DEFINE_UNQUOTED([HAVE_MALICIOUS], $enable_malicious, [Compile malicious code]) |
739 | 739 | ||
740 | # gcov compilation | 740 | # gcov compilation |
diff --git a/src/dht/gnunet-dht-driver.c b/src/dht/gnunet-dht-driver.c index 983ac9e74..62af2f21e 100644 --- a/src/dht/gnunet-dht-driver.c +++ b/src/dht/gnunet-dht-driver.c | |||
@@ -27,6 +27,9 @@ | |||
27 | * FIXME: Do churn! | 27 | * FIXME: Do churn! |
28 | */ | 28 | */ |
29 | #include "platform.h" | 29 | #include "platform.h" |
30 | #ifndef HAVE_MALICIOUS | ||
31 | #error foo | ||
32 | #endif | ||
30 | #include "gnunet_testing_lib.h" | 33 | #include "gnunet_testing_lib.h" |
31 | #include "gnunet_core_service.h" | 34 | #include "gnunet_core_service.h" |
32 | #include "gnunet_dht_service.h" | 35 | #include "gnunet_dht_service.h" |
@@ -87,12 +90,12 @@ | |||
87 | /* | 90 | /* |
88 | * Default frequency for sending malicious get messages | 91 | * Default frequency for sending malicious get messages |
89 | */ | 92 | */ |
90 | #define DEFAULT_MALICIOUS_GET_FREQUENCY 1000 /* Number of milliseconds */ | 93 | #define DEFAULT_MALICIOUS_GET_FREQUENCY GNUNET_TIME_UNIT_SECONDS |
91 | 94 | ||
92 | /* | 95 | /* |
93 | * Default frequency for sending malicious put messages | 96 | * Default frequency for sending malicious put messages |
94 | */ | 97 | */ |
95 | #define DEFAULT_MALICIOUS_PUT_FREQUENCY 1000 /* Default is in milliseconds */ | 98 | #define DEFAULT_MALICIOUS_PUT_FREQUENCY GNUNET_TIME_UNIT_SECONDS |
96 | 99 | ||
97 | /* Structs */ | 100 | /* Structs */ |
98 | 101 | ||
@@ -406,9 +409,9 @@ static unsigned long long round_delay; | |||
406 | 409 | ||
407 | static unsigned long long malicious_droppers; | 410 | static unsigned long long malicious_droppers; |
408 | 411 | ||
409 | static unsigned long long malicious_get_frequency; | 412 | static struct GNUNET_TIME_Relative malicious_get_frequency; |
410 | 413 | ||
411 | static unsigned long long malicious_put_frequency; | 414 | static struct GNUNET_TIME_Relative malicious_put_frequency; |
412 | 415 | ||
413 | static unsigned long long settle_time; | 416 | static unsigned long long settle_time; |
414 | 417 | ||
@@ -744,7 +747,7 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
744 | if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK) | 747 | if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK) |
745 | GNUNET_SCHEDULER_cancel(sched, test_get->disconnect_task); | 748 | GNUNET_SCHEDULER_cancel(sched, test_get->disconnect_task); |
746 | if (test_get->get_handle != NULL) | 749 | if (test_get->get_handle != NULL) |
747 | GNUNET_DHT_get_stop(test_get->get_handle, NULL, NULL); | 750 | GNUNET_DHT_get_stop(test_get->get_handle); |
748 | if (test_get->dht_handle != NULL) | 751 | if (test_get->dht_handle != NULL) |
749 | GNUNET_DHT_disconnect(test_get->dht_handle); | 752 | GNUNET_DHT_disconnect(test_get->dht_handle); |
750 | test_get = test_get->next; | 753 | test_get = test_get->next; |
@@ -968,7 +971,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
968 | if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK) | 971 | if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK) |
969 | GNUNET_SCHEDULER_cancel(sched, test_get->disconnect_task); | 972 | GNUNET_SCHEDULER_cancel(sched, test_get->disconnect_task); |
970 | if (test_get->get_handle != NULL) | 973 | if (test_get->get_handle != NULL) |
971 | GNUNET_DHT_get_stop(test_get->get_handle, NULL, NULL); | 974 | GNUNET_DHT_get_stop(test_get->get_handle); |
972 | if (test_get->dht_handle != NULL) | 975 | if (test_get->dht_handle != NULL) |
973 | GNUNET_DHT_disconnect(test_get->dht_handle); | 976 | GNUNET_DHT_disconnect(test_get->dht_handle); |
974 | test_get = test_get->next; | 977 | test_get = test_get->next; |
@@ -1621,9 +1624,10 @@ get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
1621 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) | 1624 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) |
1622 | gets_failed++; | 1625 | gets_failed++; |
1623 | GNUNET_assert(test_get->get_handle != NULL); | 1626 | GNUNET_assert(test_get->get_handle != NULL); |
1624 | GNUNET_DHT_get_stop(test_get->get_handle, &get_stop_finished, test_get); | 1627 | GNUNET_DHT_get_stop(test_get->get_handle); |
1625 | test_get->get_handle = NULL; | 1628 | test_get->get_handle = NULL; |
1626 | test_get->disconnect_task = GNUNET_SCHEDULER_NO_TASK; | 1629 | test_get->disconnect_task = GNUNET_SCHEDULER_NO_TASK; |
1630 | GNUNET_SCHEDULER_add_now (sched, &get_stop_finished, test_get); | ||
1627 | } | 1631 | } |
1628 | 1632 | ||
1629 | /** | 1633 | /** |
@@ -1632,6 +1636,10 @@ get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
1632 | * @param cls closure | 1636 | * @param cls closure |
1633 | * @param exp when will this value expire | 1637 | * @param exp when will this value expire |
1634 | * @param key key of the result | 1638 | * @param key key of the result |
1639 | * @param get_path NULL-terminated array of pointers | ||
1640 | * to the peers on reverse GET path (or NULL if not recorded) | ||
1641 | * @param put_path NULL-terminated array of pointers | ||
1642 | * to the peers on the PUT path (or NULL if not recorded) | ||
1635 | * @param type type of the result | 1643 | * @param type type of the result |
1636 | * @param size number of bytes in data | 1644 | * @param size number of bytes in data |
1637 | * @param data pointer to the result data | 1645 | * @param data pointer to the result data |
@@ -1639,7 +1647,9 @@ get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
1639 | void get_result_iterator (void *cls, | 1647 | void get_result_iterator (void *cls, |
1640 | struct GNUNET_TIME_Absolute exp, | 1648 | struct GNUNET_TIME_Absolute exp, |
1641 | const GNUNET_HashCode * key, | 1649 | const GNUNET_HashCode * key, |
1642 | uint32_t type, | 1650 | const struct GNUNET_PeerIdentity * const *get_path, |
1651 | const struct GNUNET_PeerIdentity * const *put_path, | ||
1652 | enum GNUNET_BLOCK_Type type, | ||
1643 | uint32_t size, | 1653 | uint32_t size, |
1644 | const void *data) | 1654 | const void *data) |
1645 | { | 1655 | { |
@@ -1665,16 +1675,7 @@ void get_result_iterator (void *cls, | |||
1665 | GNUNET_SCHEDULER_add_continuation(sched, &get_stop_task, test_get, GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 1675 | GNUNET_SCHEDULER_add_continuation(sched, &get_stop_task, test_get, GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
1666 | } | 1676 | } |
1667 | 1677 | ||
1668 | /** | 1678 | |
1669 | * Continuation telling us GET request was sent. | ||
1670 | */ | ||
1671 | static void | ||
1672 | get_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | ||
1673 | { | ||
1674 | // Is there something to be done here? | ||
1675 | if (tc->reason != GNUNET_SCHEDULER_REASON_PREREQ_DONE) | ||
1676 | return; | ||
1677 | } | ||
1678 | 1679 | ||
1679 | /** | 1680 | /** |
1680 | * Set up some data, and call API PUT function | 1681 | * Set up some data, and call API PUT function |
@@ -1720,12 +1721,14 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
1720 | /* Insert the data at the first peer */ | 1721 | /* Insert the data at the first peer */ |
1721 | test_get->get_handle = GNUNET_DHT_get_start(test_get->dht_handle, | 1722 | test_get->get_handle = GNUNET_DHT_get_start(test_get->dht_handle, |
1722 | get_delay, | 1723 | get_delay, |
1723 | 1, | 1724 | 1 /* FIXME: use real type */, |
1724 | &known_keys[test_get->uid], | 1725 | &known_keys[test_get->uid], |
1726 | GNUNET_DHT_RO_NONE, | ||
1727 | NULL, 0, | ||
1728 | NULL, 0, | ||
1725 | &get_result_iterator, | 1729 | &get_result_iterator, |
1726 | test_get, | ||
1727 | &get_continuation, | ||
1728 | test_get); | 1730 | test_get); |
1731 | |||
1729 | #if VERBOSE > 1 | 1732 | #if VERBOSE > 1 |
1730 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting get for uid %u from peer %s\n", | 1733 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting get for uid %u from peer %s\n", |
1731 | test_get->uid, | 1734 | test_get->uid, |
@@ -1828,9 +1831,10 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
1828 | outstanding_puts++; | 1831 | outstanding_puts++; |
1829 | GNUNET_DHT_put(test_put->dht_handle, | 1832 | GNUNET_DHT_put(test_put->dht_handle, |
1830 | &known_keys[test_put->uid], | 1833 | &known_keys[test_put->uid], |
1831 | 1, | 1834 | GNUNET_DHT_RO_NONE, |
1835 | 1 /* FIXME: use real type */, | ||
1832 | sizeof(data), data, | 1836 | sizeof(data), data, |
1833 | GNUNET_TIME_absolute_get_forever(), | 1837 | GNUNET_TIME_UNIT_FOREVER_ABS, |
1834 | put_delay, | 1838 | put_delay, |
1835 | &put_finished, test_put); | 1839 | &put_finished, test_put); |
1836 | test_put->disconnect_task = GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_get_forever(), &put_disconnect_task, test_put); | 1840 | test_put->disconnect_task = GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_get_forever(), &put_disconnect_task, test_put); |
@@ -2141,7 +2145,6 @@ static void | |||
2141 | set_malicious (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | 2145 | set_malicious (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) |
2142 | { | 2146 | { |
2143 | struct MaliciousContext *ctx = cls; | 2147 | struct MaliciousContext *ctx = cls; |
2144 | int ret; | ||
2145 | 2148 | ||
2146 | if (outstanding_malicious > DEFAULT_MAX_OUTSTANDING_GETS) | 2149 | if (outstanding_malicious > DEFAULT_MAX_OUTSTANDING_GETS) |
2147 | { | 2150 | { |
@@ -2163,28 +2166,29 @@ set_malicious (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
2163 | ctx->daemon->shortname, ctx->malicious_type); | 2166 | ctx->daemon->shortname, ctx->malicious_type); |
2164 | #endif | 2167 | #endif |
2165 | 2168 | ||
2166 | ret = GNUNET_YES; | ||
2167 | switch (ctx->malicious_type) | 2169 | switch (ctx->malicious_type) |
2168 | { | 2170 | { |
2169 | case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET: | 2171 | case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET: |
2170 | ret = GNUNET_DHT_set_malicious_getter(ctx->dht_handle, malicious_get_frequency, &malicious_done_task, ctx); | 2172 | GNUNET_DHT_set_malicious_getter(ctx->dht_handle, malicious_get_frequency); |
2173 | GNUNET_SCHEDULER_add_now (sched, | ||
2174 | &malicious_done_task, ctx); | ||
2171 | break; | 2175 | break; |
2172 | case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT: | 2176 | case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT: |
2173 | ret = GNUNET_DHT_set_malicious_putter(ctx->dht_handle, malicious_put_frequency, &malicious_done_task, ctx); | 2177 | GNUNET_DHT_set_malicious_putter(ctx->dht_handle, malicious_put_frequency); |
2178 | GNUNET_SCHEDULER_add_now (sched, | ||
2179 | &malicious_done_task, ctx); | ||
2174 | break; | 2180 | break; |
2175 | case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP: | 2181 | case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP: |
2176 | ret = GNUNET_DHT_set_malicious_dropper(ctx->dht_handle, &malicious_done_task, ctx); | 2182 | GNUNET_DHT_set_malicious_dropper(ctx->dht_handle); |
2183 | GNUNET_SCHEDULER_add_now (sched, &malicious_done_task, ctx); | ||
2177 | break; | 2184 | break; |
2178 | default: | 2185 | default: |
2179 | break; | 2186 | break; |
2180 | } | 2187 | } |
2181 | 2188 | ||
2182 | if (ret == GNUNET_NO) | 2189 | ctx->disconnect_task = GNUNET_SCHEDULER_add_delayed(sched, |
2183 | { | 2190 | GNUNET_TIME_UNIT_FOREVER_REL, |
2184 | GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100), &set_malicious, ctx); | 2191 | &malicious_disconnect_task, ctx); |
2185 | } | ||
2186 | else | ||
2187 | ctx->disconnect_task = GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_get_forever(), &malicious_disconnect_task, ctx); | ||
2188 | } | 2192 | } |
2189 | 2193 | ||
2190 | /** | 2194 | /** |
@@ -2800,15 +2804,15 @@ run (void *cls, | |||
2800 | replicate_same = GNUNET_YES; | 2804 | replicate_same = GNUNET_YES; |
2801 | } | 2805 | } |
2802 | 2806 | ||
2803 | if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT_TESTING", | 2807 | if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_time (cfg, "DHT_TESTING", |
2804 | "MALICIOUS_GET_FREQUENCY", | 2808 | "MALICIOUS_GET_FREQUENCY", |
2805 | &malicious_get_frequency)) | 2809 | &malicious_get_frequency)) |
2806 | malicious_get_frequency = DEFAULT_MALICIOUS_GET_FREQUENCY; | 2810 | malicious_get_frequency = DEFAULT_MALICIOUS_GET_FREQUENCY; |
2807 | 2811 | ||
2808 | 2812 | ||
2809 | if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT_TESTING", | 2813 | if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_time (cfg, "DHT_TESTING", |
2810 | "MALICIOUS_PUT_FREQUENCY", | 2814 | "MALICIOUS_PUT_FREQUENCY", |
2811 | &malicious_put_frequency)) | 2815 | &malicious_put_frequency)) |
2812 | malicious_put_frequency = DEFAULT_MALICIOUS_PUT_FREQUENCY; | 2816 | malicious_put_frequency = DEFAULT_MALICIOUS_PUT_FREQUENCY; |
2813 | 2817 | ||
2814 | 2818 | ||
@@ -2985,8 +2989,8 @@ run (void *cls, | |||
2985 | trial_info.malicious_getters = malicious_getters; | 2989 | trial_info.malicious_getters = malicious_getters; |
2986 | trial_info.malicious_putters = malicious_putters; | 2990 | trial_info.malicious_putters = malicious_putters; |
2987 | trial_info.malicious_droppers = malicious_droppers; | 2991 | trial_info.malicious_droppers = malicious_droppers; |
2988 | trial_info.malicious_get_frequency = malicious_get_frequency; | 2992 | trial_info.malicious_get_frequency = malicious_get_frequency.value; |
2989 | trial_info.malicious_put_frequency = malicious_put_frequency; | 2993 | trial_info.malicious_put_frequency = malicious_put_frequency.value; |
2990 | trial_info.stop_closest = stop_closest; | 2994 | trial_info.stop_closest = stop_closest; |
2991 | trial_info.stop_found = stop_found; | 2995 | trial_info.stop_found = stop_found; |
2992 | trial_info.strict_kademlia = strict_kademlia; | 2996 | trial_info.strict_kademlia = strict_kademlia; |