diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/dht/Makefile.am | 19 | ||||
-rw-r--r-- | src/dht/test_dht_line.conf | 1 | ||||
-rw-r--r-- | src/dht/test_dht_monitor.c | 423 | ||||
-rw-r--r-- | src/dht/test_dht_monitor.conf | 57 | ||||
-rw-r--r-- | src/dht/test_dht_multipeer.conf | 1 |
5 files changed, 246 insertions, 255 deletions
diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am index 0baf6b00e..2270d094b 100644 --- a/src/dht/Makefile.am +++ b/src/dht/Makefile.am | |||
@@ -125,21 +125,21 @@ check_PROGRAMS = \ | |||
125 | test_dht_twopeer \ | 125 | test_dht_twopeer \ |
126 | test_dht_multipeer \ | 126 | test_dht_multipeer \ |
127 | test_dht_line \ | 127 | test_dht_line \ |
128 | test_dht_2dtorus | 128 | test_dht_2dtorus \ |
129 | # test_dht_monitor | 129 | test_dht_monitor |
130 | 130 | ||
131 | if HAVE_EXPERIMENTAL | 131 | if HAVE_EXPERIMENTAL |
132 | # These tests still do not work as testbed does | 132 | # These tests still do not work as testbed does |
133 | # not support the respective topology op | 133 | # not support the respective topology op |
134 | NEW_TESTS = test_dht_2dtorus test_dht_multipeer | 134 | NEW_TESTS = test_dht_2dtorus test_dht_multipeer |
135 | endif | 135 | endif |
136 | 136 | ||
137 | if ENABLE_TEST_RUN | 137 | if ENABLE_TEST_RUN |
138 | TESTS = test_dht_api $(check_SCRIPTS) \ | 138 | TESTS = test_dht_api $(check_SCRIPTS) \ |
139 | test_dht_twopeer \ | 139 | test_dht_twopeer \ |
140 | test_dht_line \ | 140 | test_dht_line \ |
141 | test_dht_monitor \ | ||
141 | $(NEW_TESTS) | 142 | $(NEW_TESTS) |
142 | # test_dht_monitor | ||
143 | endif | 143 | endif |
144 | 144 | ||
145 | test_dht_api_SOURCES = \ | 145 | test_dht_api_SOURCES = \ |
@@ -184,18 +184,20 @@ test_dht_line_DEPENDENCIES = \ | |||
184 | test_dht_multipeer_SOURCES = \ | 184 | test_dht_multipeer_SOURCES = \ |
185 | test_dht_topo.c | 185 | test_dht_topo.c |
186 | test_dht_multipeer_LDADD = \ | 186 | test_dht_multipeer_LDADD = \ |
187 | $(top_builddir)/src/dht/libgnunetdhttest.a \ | ||
187 | $(top_builddir)/src/util/libgnunetutil.la \ | 188 | $(top_builddir)/src/util/libgnunetutil.la \ |
188 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 189 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
189 | $(top_builddir)/src/testing_old/libgnunettesting_old.la \ | 190 | $(top_builddir)/src/testbed/libgnunettestbed.la \ |
190 | $(top_builddir)/src/dht/libgnunetdht.la | 191 | $(top_builddir)/src/dht/libgnunetdht.la |
191 | test_dht_multipeer_DEPENDENCIES = \ | 192 | test_dht_multipeer_DEPENDENCIES = \ |
192 | libgnunetdht.la | 193 | libgnunetdht.la |
193 | 194 | ||
194 | # fixme, rewrite based on test_dht_topo.c! | 195 | test_dht_monitor_SOURCES = \ |
195 | test_dht_monitor_SOURCES = test_dht_monitor.c | 196 | test_dht_monitor.c |
196 | test_dht_monitor_LDADD = \ | 197 | test_dht_monitor_LDADD = \ |
198 | $(top_builddir)/src/dht/libgnunetdhttest.a \ | ||
197 | $(top_builddir)/src/util/libgnunetutil.la \ | 199 | $(top_builddir)/src/util/libgnunetutil.la \ |
198 | $(top_builddir)/src/testing_old/libgnunettesting_old.la \ | 200 | $(top_builddir)/src/testbed/libgnunettestbed.la \ |
199 | $(top_builddir)/src/dht/libgnunetdht.la | 201 | $(top_builddir)/src/dht/libgnunetdht.la |
200 | test_dht_monitor_DEPENDENCIES = \ | 202 | test_dht_monitor_DEPENDENCIES = \ |
201 | libgnunetdht.la | 203 | libgnunetdht.la |
@@ -205,6 +207,7 @@ EXTRA_DIST = \ | |||
205 | test_dht_api_data.conf \ | 207 | test_dht_api_data.conf \ |
206 | test_dht_api_peer1.conf \ | 208 | test_dht_api_peer1.conf \ |
207 | test_dht_twopeer_data.conf \ | 209 | test_dht_twopeer_data.conf \ |
210 | test_dht_monitor.conf \ | ||
208 | test_dht_multipeer.conf \ | 211 | test_dht_multipeer.conf \ |
209 | test_dht_2dtorus.conf \ | 212 | test_dht_2dtorus.conf \ |
210 | test_dht_line.conf \ | 213 | test_dht_line.conf \ |
diff --git a/src/dht/test_dht_line.conf b/src/dht/test_dht_line.conf index e2bb54f1b..0c790aaa1 100644 --- a/src/dht/test_dht_line.conf +++ b/src/dht/test_dht_line.conf | |||
@@ -10,6 +10,7 @@ AUTOSTART = NO | |||
10 | [nat] | 10 | [nat] |
11 | DISABLEV6 = YES | 11 | DISABLEV6 = YES |
12 | RETURN_LOCAL_ADDRESSES = YES | 12 | RETURN_LOCAL_ADDRESSES = YES |
13 | USE_LOCALADDR = YES | ||
13 | ENABLE_UPNP = NO | 14 | ENABLE_UPNP = NO |
14 | BEHIND_NAT = NO | 15 | BEHIND_NAT = NO |
15 | ALLOW_NAT = NO | 16 | ALLOW_NAT = NO |
diff --git a/src/dht/test_dht_monitor.c b/src/dht/test_dht_monitor.c index e8be7e49c..74024edf2 100644 --- a/src/dht/test_dht_monitor.c +++ b/src/dht/test_dht_monitor.c | |||
@@ -19,277 +19,212 @@ | |||
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file dht/test_dht_monitor.c | 21 | * @file dht/test_dht_monitor.c |
22 | * | 22 | * @brief Test for the dht monitoring API; checks that we receive "some" monitor events |
23 | * @brief Test for the dht service: store, retrieve and monitor in a line. | 23 | * @author Christian Grothoff |
24 | * TODO: update this description | ||
25 | * Each peer stores it own ID in the DHT and then a different peer tries to | ||
26 | * retrieve that key from it. The GET starts after a first round of PUTS has | ||
27 | * been made. Periodically, each peer stores its ID into the DHT. If after | ||
28 | * a timeout no result has been returned, the test fails. | ||
29 | */ | 24 | */ |
30 | #include "platform.h" | 25 | #include "platform.h" |
31 | #include "gnunet_testing_lib.h" | 26 | #include "gnunet_testbed_service.h" |
32 | #include "gnunet_dht_service.h" | 27 | #include "gnunet_dht_service.h" |
33 | 28 | #include "dht_test_lib.h" | |
34 | #define REMOVE_DIR GNUNET_YES | ||
35 | 29 | ||
36 | 30 | ||
37 | /** | 31 | /** |
38 | * How long until we give up on connecting the peers? | 32 | * How long do we run the test at most? |
39 | */ | 33 | */ |
40 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1500) | 34 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) |
41 | |||
42 | #define GET_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) | ||
43 | 35 | ||
36 | /** | ||
37 | * How often do we run the PUTs? | ||
38 | */ | ||
44 | #define PUT_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 39 | #define PUT_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
45 | 40 | ||
46 | static int ok; | ||
47 | 41 | ||
48 | /** | 42 | /** |
49 | * Be verbose | 43 | * Information we keep for each GET operation. |
50 | */ | 44 | */ |
51 | static int verbose; | 45 | struct GetOperation |
46 | { | ||
47 | /** | ||
48 | * DLL. | ||
49 | */ | ||
50 | struct GetOperation *next; | ||
52 | 51 | ||
53 | /** | 52 | /** |
54 | * Total number of peers in the test. | 53 | * DLL. |
55 | */ | 54 | */ |
56 | static unsigned long long num_peers; | 55 | struct GetOperation *prev; |
57 | 56 | ||
58 | /** | 57 | /** |
59 | * Global configuration file | 58 | * Handle for the operation. |
60 | */ | 59 | */ |
61 | static struct GNUNET_CONFIGURATION_Handle *testing_cfg; | 60 | struct GNUNET_DHT_GetHandle *get; |
61 | |||
62 | }; | ||
62 | 63 | ||
63 | /** | ||
64 | * Total number of currently running peers. | ||
65 | */ | ||
66 | static unsigned long long peers_running; | ||
67 | 64 | ||
68 | /** | 65 | /** |
69 | * Total number of connections in the whole network. | 66 | * Return value from 'main'. |
70 | */ | 67 | */ |
71 | static unsigned int total_connections; | 68 | static int ok; |
72 | 69 | ||
73 | /** | 70 | /** |
74 | * The currently running peer group. | 71 | * Head of list of active GET operations. |
75 | */ | 72 | */ |
76 | static struct GNUNET_TESTING_PeerGroup *pg; | 73 | static struct GetOperation *get_head; |
77 | 74 | ||
78 | /** | 75 | /** |
79 | * File to report results to. | 76 | * Tail of list of active GET operations. |
80 | */ | 77 | */ |
81 | static struct GNUNET_DISK_FileHandle *output_file; | 78 | static struct GetOperation *get_tail; |
82 | 79 | ||
83 | /** | 80 | /** |
84 | * File to log connection info, statistics to. | 81 | * Array of the testbed's peers. |
85 | */ | 82 | */ |
86 | static struct GNUNET_DISK_FileHandle *data_file; | 83 | static struct GNUNET_TESTBED_Peer **my_peers; |
87 | 84 | ||
88 | /** | 85 | /** |
89 | * Task called to disconnect peers. | 86 | * Number of peers to run. |
90 | */ | 87 | */ |
91 | static GNUNET_SCHEDULER_TaskIdentifier disconnect_task; | 88 | static unsigned int NUM_PEERS = 3; |
92 | 89 | ||
93 | /** | 90 | /** |
94 | * Task To perform tests | 91 | * Task called to disconnect peers. |
95 | */ | 92 | */ |
96 | static GNUNET_SCHEDULER_TaskIdentifier test_task; | 93 | static GNUNET_SCHEDULER_TaskIdentifier timeout_task; |
97 | 94 | ||
98 | /** | 95 | /** |
99 | * Task to do DHT_puts | 96 | * Task to do DHT_puts |
100 | */ | 97 | */ |
101 | static GNUNET_SCHEDULER_TaskIdentifier put_task; | 98 | static GNUNET_SCHEDULER_TaskIdentifier put_task; |
102 | 99 | ||
103 | /** | 100 | static struct GNUNET_DHT_MonitorHandle **monitors; |
104 | * Task called to shutdown test. | ||
105 | */ | ||
106 | static GNUNET_SCHEDULER_TaskIdentifier shutdown_handle; | ||
107 | |||
108 | static char *topology_file; | ||
109 | |||
110 | static struct GNUNET_DHT_Handle **hs; | ||
111 | |||
112 | static struct GNUNET_DHT_MonitorHandle **mhs; | ||
113 | |||
114 | static struct GNUNET_DHT_GetHandle *get_h_far; | ||
115 | |||
116 | static const char *id_far = "2UVH"; | ||
117 | |||
118 | static struct GNUNET_TESTING_Daemon *d_far; | ||
119 | |||
120 | static struct GNUNET_TESTING_Daemon *o; | ||
121 | 101 | ||
122 | static unsigned int monitor_counter; | 102 | static unsigned int monitor_counter; |
123 | 103 | ||
124 | static unsigned int monitor_expect = UINT_MAX; | ||
125 | |||
126 | static int in_test; | ||
127 | |||
128 | 104 | ||
129 | /** | 105 | /** |
130 | * Check whether peers successfully shut down. | 106 | * Task run on success or timeout to clean up. |
131 | */ | 107 | * Terminates active get operations and shuts down |
132 | static void | 108 | * the testbed. |
133 | shutdown_callback (void *cls, const char *emsg) | 109 | * |
134 | { | 110 | * @param cls the 'struct GNUNET_DHT_TestContext' |
135 | if (emsg != NULL) | 111 | * @param tc scheduler context |
136 | { | 112 | */ |
137 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "test: Shutdown of peers failed: %s\n", | ||
138 | emsg); | ||
139 | ok++; | ||
140 | } | ||
141 | else | ||
142 | { | ||
143 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
144 | "test: All peers successfully shut down!\n"); | ||
145 | } | ||
146 | GNUNET_CONFIGURATION_destroy (testing_cfg); | ||
147 | } | ||
148 | |||
149 | |||
150 | static void | ||
151 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
152 | { | ||
153 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Ending test.\n"); | ||
154 | if (disconnect_task != GNUNET_SCHEDULER_NO_TASK) | ||
155 | { | ||
156 | GNUNET_SCHEDULER_cancel (disconnect_task); | ||
157 | disconnect_task = GNUNET_SCHEDULER_NO_TASK; | ||
158 | } | ||
159 | if (data_file != NULL) | ||
160 | GNUNET_DISK_file_close (data_file); | ||
161 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | ||
162 | } | ||
163 | |||
164 | |||
165 | static void | 113 | static void |
166 | disconnect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 114 | shutdown_task (void *cls, |
115 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
167 | { | 116 | { |
117 | struct GNUNET_DHT_TEST_Context *ctx = cls; | ||
168 | unsigned int i; | 118 | unsigned int i; |
119 | struct GetOperation *get_op; | ||
169 | 120 | ||
170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: disconnecting peers\n"); | 121 | ok = (monitor_counter > NUM_PEERS) ? 0 : 2; |
171 | disconnect_task = GNUNET_SCHEDULER_NO_TASK; | 122 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
172 | GNUNET_SCHEDULER_cancel (put_task); | 123 | "Received %u monitor events\n", |
173 | if (NULL != get_h_far) | 124 | monitor_counter); |
174 | GNUNET_DHT_get_stop (get_h_far); | 125 | while (NULL != (get_op = get_tail)) |
175 | for (i = 0; i < num_peers; i++) | ||
176 | { | 126 | { |
177 | GNUNET_DHT_monitor_stop(mhs[i]); | 127 | GNUNET_DHT_get_stop (get_op->get); |
178 | GNUNET_DHT_disconnect (hs[i]); | 128 | GNUNET_CONTAINER_DLL_remove (get_head, |
129 | get_tail, | ||
130 | get_op); | ||
131 | GNUNET_free (get_op); | ||
179 | } | 132 | } |
180 | GNUNET_SCHEDULER_cancel (shutdown_handle); | 133 | for (i=0;i<NUM_PEERS;i++) |
181 | shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | 134 | GNUNET_DHT_monitor_stop (monitors[i]); |
135 | GNUNET_free (monitors); | ||
136 | GNUNET_SCHEDULER_cancel (put_task); | ||
137 | GNUNET_DHT_TEST_cleanup (ctx); | ||
182 | } | 138 | } |
183 | 139 | ||
184 | 140 | ||
141 | /** | ||
142 | * Iterator called on each result obtained for a DHT | ||
143 | * operation that expects a reply | ||
144 | * | ||
145 | * @param cls closure with our 'struct GetOperation' | ||
146 | * @param exp when will this value expire | ||
147 | * @param key key of the result | ||
148 | * @param get_path peers on reply path (or NULL if not recorded) | ||
149 | * @param get_path_length number of entries in get_path | ||
150 | * @param put_path peers on the PUT path (or NULL if not recorded) | ||
151 | * @param put_path_length number of entries in get_path | ||
152 | * @param type type of the result | ||
153 | * @param size number of bytes in data | ||
154 | * @param data pointer to the result data | ||
155 | */ | ||
185 | static void | 156 | static void |
186 | dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, | 157 | dht_get_handler (void *cls, struct GNUNET_TIME_Absolute exp, |
187 | const struct GNUNET_HashCode * key, | 158 | const struct GNUNET_HashCode * key, |
188 | const struct GNUNET_PeerIdentity *get_path, | 159 | const struct GNUNET_PeerIdentity *get_path, |
189 | unsigned int get_path_length, | 160 | unsigned int get_path_length, |
190 | const struct GNUNET_PeerIdentity *put_path, | 161 | const struct GNUNET_PeerIdentity *put_path, |
191 | unsigned int put_path_length, enum GNUNET_BLOCK_Type type, | 162 | unsigned int put_path_length, enum GNUNET_BLOCK_Type type, |
192 | size_t size, const void *data) | 163 | size_t size, const void *data) |
193 | { | 164 | { |
194 | int i; | 165 | struct GetOperation *get_op = cls; |
166 | struct GNUNET_HashCode want; | ||
167 | struct GNUNET_DHT_TestContext *ctx; | ||
195 | 168 | ||
196 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 169 | if (sizeof (struct GNUNET_HashCode) != size) |
197 | "test: ************* FOUND!!! ***********\n"); | ||
198 | if (sizeof (struct GNUNET_HashCode) == size) | ||
199 | { | 170 | { |
200 | const struct GNUNET_HashCode *h = data; | 171 | GNUNET_break (0); |
201 | 172 | return; | |
202 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Contents: %s\n", | ||
203 | GNUNET_h2s_full (h)); | ||
204 | |||
205 | } | ||
206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: PATH: (get %u, put %u)\n", | ||
207 | get_path_length, put_path_length); | ||
208 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: LOCAL\n"); | ||
209 | for (i = get_path_length - 1; i >= 0; i--) | ||
210 | { | ||
211 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: %s\n", | ||
212 | GNUNET_i2s (&get_path[i])); | ||
213 | } | ||
214 | for (i = put_path_length - 1; i >= 0; i--) | ||
215 | { | ||
216 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: %s\n", | ||
217 | GNUNET_i2s (&put_path[i])); | ||
218 | } | ||
219 | monitor_expect = get_path_length + put_path_length; | ||
220 | if (monitor_counter >= monitor_expect) | ||
221 | { | ||
222 | ok = 0; | ||
223 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "expected at least %u hops, got %u\n", | ||
224 | get_path_length + put_path_length, monitor_counter); | ||
225 | GNUNET_SCHEDULER_cancel (disconnect_task); | ||
226 | disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL); | ||
227 | } | 173 | } |
228 | } | 174 | GNUNET_CRYPTO_hash (key, sizeof (*key), &want); |
229 | 175 | if (0 != memcmp (&want, data, sizeof (want))) | |
230 | |||
231 | /** | ||
232 | * Start test: start GET request from the first node in the line looking for | ||
233 | * the ID of the last node in the line. | ||
234 | * | ||
235 | * @param cls Closure (not used). | ||
236 | * @param tc Task context. | ||
237 | */ | ||
238 | static void | ||
239 | do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
240 | { | ||
241 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | ||
242 | { | 176 | { |
177 | GNUNET_break (0); | ||
243 | return; | 178 | return; |
244 | } | 179 | } |
245 | 180 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | |
246 | in_test = GNUNET_YES; | 181 | "Get successful\n"); |
247 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n"); | 182 | GNUNET_DHT_get_stop (get_op->get); |
248 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n", | 183 | GNUNET_CONTAINER_DLL_remove (get_head, |
249 | GNUNET_h2s_full (&d_far->id.hashPubKey)); | 184 | get_tail, |
250 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: from %s\n", | 185 | get_op); |
251 | GNUNET_h2s_full (&o->id.hashPubKey)); | 186 | GNUNET_free (get_op); |
252 | get_h_far = GNUNET_DHT_get_start (hs[0], | 187 | if (NULL != get_head) |
253 | GNUNET_BLOCK_TYPE_TEST, /* type */ | 188 | return; |
254 | &d_far->id.hashPubKey, /*key to search */ | 189 | /* all DHT GET operations successful; terminate! */ |
255 | 4U, /* replication level */ | 190 | ok = 0; |
256 | GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ | 191 | ctx = GNUNET_SCHEDULER_cancel (timeout_task); |
257 | 0, /* xquery bits */ | 192 | timeout_task = GNUNET_SCHEDULER_add_now (&shutdown_task, ctx); |
258 | &dht_get_id_handler, NULL); | ||
259 | GNUNET_SCHEDULER_cancel (disconnect_task); | ||
260 | disconnect_task = | ||
261 | GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &disconnect_peers, NULL); | ||
262 | } | 193 | } |
263 | 194 | ||
264 | 195 | ||
265 | /** | 196 | /** |
266 | * Periodic function used to put the ID of the far peer in the DHT. | 197 | * Task to put the id of each peer into the DHT. |
267 | * | 198 | * |
268 | * @param cls Closure (not used). | 199 | * @param cls array with NUM_PEERS DHT handles |
269 | * @param tc Task context. | 200 | * @param tc Task context |
270 | */ | 201 | */ |
271 | static void | 202 | static void |
272 | put_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 203 | do_puts (void *cls, |
204 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
273 | { | 205 | { |
274 | struct GNUNET_TESTING_Daemon *d; | 206 | struct GNUNET_DHT_Handle **hs = cls; |
207 | struct GNUNET_HashCode key; | ||
208 | struct GNUNET_HashCode value; | ||
209 | unsigned int i; | ||
275 | 210 | ||
276 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 211 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
212 | "Putting values into DHT\n"); | ||
213 | for (i = 0; i < NUM_PEERS; i++) | ||
277 | { | 214 | { |
278 | put_task = GNUNET_SCHEDULER_NO_TASK; | 215 | GNUNET_CRYPTO_hash (&i, sizeof (i), &key); |
279 | return; | 216 | GNUNET_CRYPTO_hash (&key, sizeof (key), &value); |
217 | GNUNET_DHT_put (hs[i], &key, 10U, | ||
218 | GNUNET_DHT_RO_RECORD_ROUTE | | ||
219 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | ||
220 | GNUNET_BLOCK_TYPE_TEST, | ||
221 | sizeof (value), &value, | ||
222 | GNUNET_TIME_UNIT_FOREVER_ABS, | ||
223 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
224 | NULL, NULL); | ||
280 | } | 225 | } |
281 | 226 | put_task = GNUNET_SCHEDULER_add_delayed (PUT_FREQUENCY, | |
282 | d = GNUNET_TESTING_daemon_get (pg, 4); | 227 | &do_puts, hs); |
283 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: putting into DHT: %s\n", | ||
284 | GNUNET_h2s_full (&d->id.hashPubKey)); | ||
285 | GNUNET_DHT_put (hs[4], &d->id.hashPubKey, 10U, | ||
286 | GNUNET_DHT_RO_RECORD_ROUTE | | ||
287 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | ||
288 | GNUNET_BLOCK_TYPE_TEST, sizeof (struct GNUNET_PeerIdentity), | ||
289 | (const char *) &d->id, GNUNET_TIME_UNIT_FOREVER_ABS, | ||
290 | GNUNET_TIME_UNIT_FOREVER_REL, NULL, NULL); | ||
291 | |||
292 | put_task = GNUNET_SCHEDULER_add_delayed (PUT_FREQUENCY, &put_id, NULL); | ||
293 | } | 228 | } |
294 | 229 | ||
295 | 230 | ||
@@ -316,27 +251,14 @@ monitor_get_cb (void *cls, | |||
316 | const struct GNUNET_PeerIdentity *path, | 251 | const struct GNUNET_PeerIdentity *path, |
317 | const struct GNUNET_HashCode * key) | 252 | const struct GNUNET_HashCode * key) |
318 | { | 253 | { |
319 | const char *s_key; | ||
320 | unsigned int i; | 254 | unsigned int i; |
321 | 255 | ||
322 | i = (unsigned int) (long) cls; | 256 | i = (unsigned int) (long) cls; |
323 | s_key = GNUNET_h2s(key); | ||
324 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 257 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
325 | "%u got a GET message for key %s\n", | 258 | "%u got a GET message for key %s\n", |
326 | i, s_key); | 259 | i, |
327 | 260 | GNUNET_h2s (key)); | |
328 | if (strncmp (s_key, id_far, 4) == 0 && in_test == GNUNET_YES) | 261 | monitor_counter++; |
329 | { | ||
330 | monitor_counter++; | ||
331 | if (monitor_counter >= monitor_expect) | ||
332 | { | ||
333 | ok = 0; | ||
334 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "expected at least %u hops, got %u\n", | ||
335 | monitor_expect, monitor_counter); | ||
336 | GNUNET_SCHEDULER_cancel (disconnect_task); | ||
337 | disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL); | ||
338 | } | ||
339 | } | ||
340 | } | 262 | } |
341 | 263 | ||
342 | 264 | ||
@@ -369,18 +291,14 @@ monitor_put_cb (void *cls, | |||
369 | const void *data, | 291 | const void *data, |
370 | size_t size) | 292 | size_t size) |
371 | { | 293 | { |
372 | const char *s_key; | ||
373 | unsigned int i; | 294 | unsigned int i; |
374 | 295 | ||
375 | i = (unsigned int) (long) cls; | 296 | i = (unsigned int) (long) cls; |
376 | s_key = GNUNET_h2s(key); | ||
377 | |||
378 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 297 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
379 | "%u got a PUT message for key %s with %u bytes\n", | 298 | "%u got a PUT message for key %s with %u bytes\n", |
380 | i, s_key, size); | 299 | i, |
381 | 300 | GNUNET_h2s (key), size); | |
382 | if (strncmp (s_key, id_far, 4) == 0 && in_test == GNUNET_YES) | 301 | monitor_counter++; |
383 | monitor_counter++; | ||
384 | } | 302 | } |
385 | 303 | ||
386 | 304 | ||
@@ -411,17 +329,14 @@ monitor_res_cb (void *cls, | |||
411 | const void *data, | 329 | const void *data, |
412 | size_t size) | 330 | size_t size) |
413 | { | 331 | { |
414 | const char *s_key; | ||
415 | unsigned int i; | 332 | unsigned int i; |
416 | 333 | ||
417 | i = (unsigned int) (long) cls; | 334 | i = (unsigned int) (long) cls; |
418 | s_key = GNUNET_h2s(key); | ||
419 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 335 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
420 | "%u got a REPLY message for key %s with %u bytes\n", | 336 | "%u got a REPLY message for key %s with %u bytes\n", |
421 | i, s_key, size); | 337 | i, |
422 | 338 | GNUNET_h2s (key), size); | |
423 | if (strncmp (s_key, id_far, 4) == 0 && in_test == GNUNET_YES) | 339 | monitor_counter++; |
424 | monitor_counter++; | ||
425 | } | 340 | } |
426 | 341 | ||
427 | 342 | ||
@@ -442,31 +357,45 @@ run (void *cls, | |||
442 | struct GNUNET_DHT_Handle **dhts) | 357 | struct GNUNET_DHT_Handle **dhts) |
443 | { | 358 | { |
444 | unsigned int i; | 359 | unsigned int i; |
360 | unsigned int j; | ||
361 | struct GNUNET_HashCode key; | ||
362 | struct GetOperation *get_op; | ||
445 | 363 | ||
446 | GNUNET_assert (NUM_PEERS == num_peers); | 364 | GNUNET_assert (NUM_PEERS == num_peers); |
447 | my_peers = peers; | 365 | my_peers = peers; |
448 | mhs = GNUNET_malloc (num_peers * sizeof (struct GNUNET_DHT_MonitorHandle *)); | 366 | monitors = GNUNET_malloc (num_peers * sizeof (struct GNUNET_DHT_MonitorHandle *)); |
449 | for (i = 0; i < num_peers; i++) | 367 | for (i = 0; i < num_peers; i++) |
368 | monitors[i] = GNUNET_DHT_monitor_start (dhts[i], | ||
369 | GNUNET_BLOCK_TYPE_ANY, | ||
370 | NULL, | ||
371 | &monitor_get_cb, | ||
372 | &monitor_res_cb, | ||
373 | &monitor_put_cb, | ||
374 | (void *)(long)i); | ||
375 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
376 | "Peers setup, starting test\n"); | ||
377 | put_task = GNUNET_SCHEDULER_add_now (&do_puts, dhts); | ||
378 | for (i=0;i<num_peers;i++) | ||
450 | { | 379 | { |
451 | d = GNUNET_TESTING_daemon_get (pg, i); | 380 | GNUNET_CRYPTO_hash (&i, sizeof (i), &key); |
452 | hs[i] = GNUNET_DHT_connect (d->cfg, 32); | 381 | for (j=0;j<num_peers;j++) |
453 | mhs[i] = GNUNET_DHT_monitor_start (hs[i], | 382 | { |
454 | GNUNET_BLOCK_TYPE_ANY, | 383 | get_op = GNUNET_malloc (sizeof (struct GetOperation)); |
455 | NULL, | 384 | GNUNET_CONTAINER_DLL_insert (get_head, |
456 | &monitor_get_cb, | 385 | get_tail, |
457 | &monitor_res_cb, | 386 | get_op); |
458 | &monitor_put_cb, | 387 | get_op->get = GNUNET_DHT_get_start (dhts[j], |
459 | (void *)(long)i); | 388 | GNUNET_BLOCK_TYPE_TEST, /* type */ |
389 | &key, /*key to search */ | ||
390 | 4U, /* replication level */ | ||
391 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | ||
392 | NULL, /* xquery */ | ||
393 | 0, /* xquery bits */ | ||
394 | &dht_get_handler, get_op); | ||
395 | } | ||
460 | } | 396 | } |
461 | put_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 397 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
462 | (GNUNET_TIME_UNIT_SECONDS, 3), | 398 | &shutdown_task, ctx); |
463 | &put_id, NULL); | ||
464 | test_task = | ||
465 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
466 | (GNUNET_TIME_UNIT_SECONDS, 6), &do_test, | ||
467 | NULL); | ||
468 | disconnect_task = | ||
469 | GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &disconnect_peers, NULL); | ||
470 | } | 399 | } |
471 | 400 | ||
472 | 401 | ||
diff --git a/src/dht/test_dht_monitor.conf b/src/dht/test_dht_monitor.conf new file mode 100644 index 000000000..ebefcca38 --- /dev/null +++ b/src/dht/test_dht_monitor.conf | |||
@@ -0,0 +1,57 @@ | |||
1 | [fs] | ||
2 | AUTOSTART = NO | ||
3 | |||
4 | [resolver] | ||
5 | AUTOSTART = NO | ||
6 | |||
7 | [block] | ||
8 | plugins = test dht | ||
9 | |||
10 | [dhtcache] | ||
11 | QUOTA = 1 MB | ||
12 | DATABASE = sqlite | ||
13 | |||
14 | [transport] | ||
15 | PLUGINS = tcp | ||
16 | |||
17 | [ats] | ||
18 | WAN_QUOTA_IN = 1 GB | ||
19 | WAN_QUOTA_OUT = 1 GB | ||
20 | |||
21 | [arm] | ||
22 | DEFAULTSERVICES = dht core | ||
23 | |||
24 | [TESTING] | ||
25 | WEAKRANDOM = YES | ||
26 | |||
27 | [testbed] | ||
28 | OVERLAY_TOPOLOGY = LINE | ||
29 | |||
30 | [gnunetd] | ||
31 | HOSTKEY = $SERVICEHOME/.hostkey | ||
32 | |||
33 | [PATHS] | ||
34 | SERVICEHOME = /tmp/test-dht-multipeer/ | ||
35 | |||
36 | [nat] | ||
37 | DISABLEV6 = YES | ||
38 | ENABLE_UPNP = NO | ||
39 | BEHIND_NAT = NO | ||
40 | ALLOW_NAT = NO | ||
41 | INTERNAL_ADDRESS = 127.0.0.1 | ||
42 | EXTERNAL_ADDRESS = 127.0.0.1 | ||
43 | USE_LOCALADDR = YES | ||
44 | RETURN_LOCAL_ADDRESSES = YES | ||
45 | |||
46 | [dns] | ||
47 | AUTOSTART = NO | ||
48 | |||
49 | [namestore] | ||
50 | AUTOSTART = NO | ||
51 | |||
52 | [nse] | ||
53 | AUTOSTART = NO | ||
54 | |||
55 | [vpn] | ||
56 | AUTOSTART=NO | ||
57 | |||
diff --git a/src/dht/test_dht_multipeer.conf b/src/dht/test_dht_multipeer.conf index 497510ce5..1408f05b9 100644 --- a/src/dht/test_dht_multipeer.conf +++ b/src/dht/test_dht_multipeer.conf | |||
@@ -36,6 +36,7 @@ SERVICEHOME = /tmp/test-dht-multipeer/ | |||
36 | 36 | ||
37 | [nat] | 37 | [nat] |
38 | DISABLEV6 = YES | 38 | DISABLEV6 = YES |
39 | RETURN_LOCAL_ADDRESSES = YES | ||
39 | ENABLE_UPNP = NO | 40 | ENABLE_UPNP = NO |
40 | BEHIND_NAT = NO | 41 | BEHIND_NAT = NO |
41 | ALLOW_NAT = NO | 42 | ALLOW_NAT = NO |