aboutsummaryrefslogtreecommitdiff
path: root/src/dht
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht')
-rw-r--r--src/dht/dht.h39
-rw-r--r--src/dht/dht_api.c964
-rw-r--r--src/dht/dht_test_lib.c135
-rw-r--r--src/dht/dht_test_lib.h24
-rw-r--r--src/dht/gnunet-dht-get.c226
-rw-r--r--src/dht/gnunet-dht-monitor.c276
-rw-r--r--src/dht/gnunet-dht-put.c173
-rw-r--r--src/dht/gnunet-service-dht.c120
-rw-r--r--src/dht/gnunet-service-dht.h74
-rw-r--r--src/dht/gnunet-service-dht_clients.c1395
-rw-r--r--src/dht/gnunet-service-dht_datacache.c387
-rw-r--r--src/dht/gnunet-service-dht_datacache.h44
-rw-r--r--src/dht/gnunet-service-dht_hello.c86
-rw-r--r--src/dht/gnunet-service-dht_hello.h10
-rw-r--r--src/dht/gnunet-service-dht_neighbours.c2652
-rw-r--r--src/dht/gnunet-service-dht_neighbours.h72
-rw-r--r--src/dht/gnunet-service-dht_nse.c58
-rw-r--r--src/dht/gnunet-service-dht_nse.h10
-rw-r--r--src/dht/gnunet-service-dht_routing.c396
-rw-r--r--src/dht/gnunet-service-dht_routing.h40
-rw-r--r--src/dht/gnunet_dht_profiler.c760
-rw-r--r--src/dht/plugin_block_dht.c196
-rw-r--r--src/dht/test_dht_api.c184
-rw-r--r--src/dht/test_dht_monitor.c324
-rw-r--r--src/dht/test_dht_topo.c495
25 files changed, 4548 insertions, 4592 deletions
diff --git a/src/dht/dht.h b/src/dht/dht.h
index 46fad3669..3d5fc0963 100644
--- a/src/dht/dht.h
+++ b/src/dht/dht.h
@@ -11,12 +11,12 @@
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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @author Christian Grothoff 22 * @author Christian Grothoff
@@ -40,8 +40,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
40 * Message which indicates the DHT should cancel outstanding 40 * Message which indicates the DHT should cancel outstanding
41 * requests and discard any state. 41 * requests and discard any state.
42 */ 42 */
43struct GNUNET_DHT_ClientGetStopMessage 43struct GNUNET_DHT_ClientGetStopMessage {
44{
45 /** 44 /**
46 * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP 45 * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP
47 */ 46 */
@@ -61,7 +60,6 @@ struct GNUNET_DHT_ClientGetStopMessage
61 * Key of this request 60 * Key of this request
62 */ 61 */
63 struct GNUNET_HashCode key; 62 struct GNUNET_HashCode key;
64
65}; 63};
66 64
67 65
@@ -69,8 +67,7 @@ struct GNUNET_DHT_ClientGetStopMessage
69 * DHT GET message sent from clients to service. Indicates that a GET 67 * DHT GET message sent from clients to service. Indicates that a GET
70 * request should be issued. 68 * request should be issued.
71 */ 69 */
72struct GNUNET_DHT_ClientGetMessage 70struct GNUNET_DHT_ClientGetMessage {
73{
74 /** 71 /**
75 * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET 72 * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET
76 */ 73 */
@@ -104,7 +101,6 @@ struct GNUNET_DHT_ClientGetMessage
104 uint64_t unique_id GNUNET_PACKED; 101 uint64_t unique_id GNUNET_PACKED;
105 102
106 /* Possibly followed by xquery, copied to end of this dealy do */ 103 /* Possibly followed by xquery, copied to end of this dealy do */
107
108}; 104};
109 105
110 106
@@ -112,8 +108,7 @@ struct GNUNET_DHT_ClientGetMessage
112 * DHT GET RESULTS KNOWN message sent from clients to service. Indicates that a GET 108 * DHT GET RESULTS KNOWN message sent from clients to service. Indicates that a GET
113 * request should exclude certain results which are already known. 109 * request should exclude certain results which are already known.
114 */ 110 */
115struct GNUNET_DHT_ClientGetResultSeenMessage 111struct GNUNET_DHT_ClientGetResultSeenMessage {
116{
117 /** 112 /**
118 * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN 113 * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN
119 */ 114 */
@@ -136,7 +131,6 @@ struct GNUNET_DHT_ClientGetResultSeenMessage
136 uint64_t unique_id GNUNET_PACKED; 131 uint64_t unique_id GNUNET_PACKED;
137 132
138 /* Followed by an array of the hash codes of known results */ 133 /* Followed by an array of the hash codes of known results */
139
140}; 134};
141 135
142 136
@@ -144,8 +138,7 @@ struct GNUNET_DHT_ClientGetResultSeenMessage
144/** 138/**
145 * Reply to a GET send from the service to a client. 139 * Reply to a GET send from the service to a client.
146 */ 140 */
147struct GNUNET_DHT_ClientResultMessage 141struct GNUNET_DHT_ClientResultMessage {
148{
149 /** 142 /**
150 * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT 143 * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT
151 */ 144 */
@@ -184,15 +177,13 @@ struct GNUNET_DHT_ClientResultMessage
184 struct GNUNET_HashCode key GNUNET_PACKED; 177 struct GNUNET_HashCode key GNUNET_PACKED;
185 178
186 /* put path, get path and actual data are copied to end of this dealy do */ 179 /* put path, get path and actual data are copied to end of this dealy do */
187
188}; 180};
189 181
190 182
191/** 183/**
192 * Message to insert data into the DHT, sent from clients to DHT service. 184 * Message to insert data into the DHT, sent from clients to DHT service.
193 */ 185 */
194struct GNUNET_DHT_ClientPutMessage 186struct GNUNET_DHT_ClientPutMessage {
195{
196 /** 187 /**
197 * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT 188 * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT
198 */ 189 */
@@ -224,15 +215,13 @@ struct GNUNET_DHT_ClientPutMessage
224 struct GNUNET_HashCode key GNUNET_PACKED; 215 struct GNUNET_HashCode key GNUNET_PACKED;
225 216
226 /* DATA copied to end of this message */ 217 /* DATA copied to end of this message */
227
228}; 218};
229 219
230 220
231/** 221/**
232 * Message to monitor put requests going through peer, DHT service -> clients. 222 * Message to monitor put requests going through peer, DHT service -> clients.
233 */ 223 */
234struct GNUNET_DHT_MonitorPutMessage 224struct GNUNET_DHT_MonitorPutMessage {
235{
236 /** 225 /**
237 * Type: #GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT 226 * Type: #GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT
238 */ 227 */
@@ -277,15 +266,13 @@ struct GNUNET_DHT_MonitorPutMessage
277 /* put path (if tracked) */ 266 /* put path (if tracked) */
278 267
279 /* Payload */ 268 /* Payload */
280
281}; 269};
282 270
283 271
284/** 272/**
285 * Message to request monitoring messages, clients -> DHT service. 273 * Message to request monitoring messages, clients -> DHT service.
286 */ 274 */
287struct GNUNET_DHT_MonitorStartStopMessage 275struct GNUNET_DHT_MonitorStartStopMessage {
288{
289 /** 276 /**
290 * Type: #GNUNET_MESSAGE_TYPE_DHT_MONITOR_START or 277 * Type: #GNUNET_MESSAGE_TYPE_DHT_MONITOR_START or
291 * #GNUNET_MESSAGE_TYPE_DHT_MONITOR_STOP 278 * #GNUNET_MESSAGE_TYPE_DHT_MONITOR_STOP
@@ -327,8 +314,7 @@ struct GNUNET_DHT_MonitorStartStopMessage
327/** 314/**
328 * Message to monitor get requests going through peer, DHT service -> clients. 315 * Message to monitor get requests going through peer, DHT service -> clients.
329 */ 316 */
330struct GNUNET_DHT_MonitorGetMessage 317struct GNUNET_DHT_MonitorGetMessage {
331{
332 /** 318 /**
333 * Type: #GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET 319 * Type: #GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET
334 */ 320 */
@@ -366,14 +352,12 @@ struct GNUNET_DHT_MonitorGetMessage
366 struct GNUNET_HashCode key GNUNET_PACKED; 352 struct GNUNET_HashCode key GNUNET_PACKED;
367 353
368 /* get path (if tracked) */ 354 /* get path (if tracked) */
369
370}; 355};
371 356
372/** 357/**
373 * Message to monitor get results going through peer, DHT service -> clients. 358 * Message to monitor get results going through peer, DHT service -> clients.
374 */ 359 */
375struct GNUNET_DHT_MonitorGetRespMessage 360struct GNUNET_DHT_MonitorGetRespMessage {
376{
377 /** 361 /**
378 * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT 362 * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT
379 */ 363 */
@@ -409,7 +393,6 @@ struct GNUNET_DHT_MonitorGetRespMessage
409 /* get path (if tracked) */ 393 /* get path (if tracked) */
410 394
411 /* Payload */ 395 /* Payload */
412
413}; 396};
414 397
415GNUNET_NETWORK_STRUCT_END 398GNUNET_NETWORK_STRUCT_END
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c
index 69ac041cc..516c96479 100644
--- a/src/dht/dht_api.c
+++ b/src/dht/dht_api.c
@@ -11,12 +11,12 @@
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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file dht/dht_api.c 22 * @file dht/dht_api.c
@@ -34,14 +34,13 @@
34#include "gnunet_dht_service.h" 34#include "gnunet_dht_service.h"
35#include "dht.h" 35#include "dht.h"
36 36
37#define LOG(kind,...) GNUNET_log_from (kind, "dht-api",__VA_ARGS__) 37#define LOG(kind, ...) GNUNET_log_from(kind, "dht-api", __VA_ARGS__)
38 38
39 39
40/** 40/**
41 * Handle to a PUT request. 41 * Handle to a PUT request.
42 */ 42 */
43struct GNUNET_DHT_PutHandle 43struct GNUNET_DHT_PutHandle {
44{
45 /** 44 /**
46 * Kept in a DLL. 45 * Kept in a DLL.
47 */ 46 */
@@ -71,15 +70,12 @@ struct GNUNET_DHT_PutHandle
71 * Envelope from the PUT operation. 70 * Envelope from the PUT operation.
72 */ 71 */
73 struct GNUNET_MQ_Envelope *env; 72 struct GNUNET_MQ_Envelope *env;
74
75}; 73};
76 74
77/** 75/**
78 * Handle to a GET request 76 * Handle to a GET request
79 */ 77 */
80struct GNUNET_DHT_GetHandle 78struct GNUNET_DHT_GetHandle {
81{
82
83 /** 79 /**
84 * Iterator to call on data receipt 80 * Iterator to call on data receipt
85 */ 81 */
@@ -142,15 +138,13 @@ struct GNUNET_DHT_GetHandle
142 * end of the positions that are actually used. 138 * end of the positions that are actually used.
143 */ 139 */
144 unsigned int seen_results_end; 140 unsigned int seen_results_end;
145
146}; 141};
147 142
148 143
149/** 144/**
150 * Handle to a monitoring request. 145 * Handle to a monitoring request.
151 */ 146 */
152struct GNUNET_DHT_MonitorHandle 147struct GNUNET_DHT_MonitorHandle {
153{
154 /** 148 /**
155 * DLL. 149 * DLL.
156 */ 150 */
@@ -195,16 +189,13 @@ struct GNUNET_DHT_MonitorHandle
195 * Closure for @e get_cb, @e put_cb and @e get_resp_cb. 189 * Closure for @e get_cb, @e put_cb and @e get_resp_cb.
196 */ 190 */
197 void *cb_cls; 191 void *cb_cls;
198
199}; 192};
200 193
201 194
202/** 195/**
203 * Connection to the DHT service. 196 * Connection to the DHT service.
204 */ 197 */
205struct GNUNET_DHT_Handle 198struct GNUNET_DHT_Handle {
206{
207
208 /** 199 /**
209 * Configuration to use. 200 * Configuration to use.
210 */ 201 */
@@ -256,8 +247,6 @@ struct GNUNET_DHT_Handle
256 * Generator for unique ids. 247 * Generator for unique ids.
257 */ 248 */
258 uint64_t uid_gen; 249 uint64_t uid_gen;
259
260
261}; 250};
262 251
263 252
@@ -268,7 +257,7 @@ struct GNUNET_DHT_Handle
268 * @return #GNUNET_YES on success, #GNUNET_NO on failure. 257 * @return #GNUNET_YES on success, #GNUNET_NO on failure.
269 */ 258 */
270static int 259static int
271try_connect (struct GNUNET_DHT_Handle *h); 260try_connect(struct GNUNET_DHT_Handle *h);
272 261
273 262
274/** 263/**
@@ -277,25 +266,25 @@ try_connect (struct GNUNET_DHT_Handle *h);
277 * @param gh GET to generate messages for. 266 * @param gh GET to generate messages for.
278 */ 267 */
279static void 268static void
280send_get (struct GNUNET_DHT_GetHandle *gh) 269send_get(struct GNUNET_DHT_GetHandle *gh)
281{ 270{
282 struct GNUNET_DHT_Handle *h = gh->dht_handle; 271 struct GNUNET_DHT_Handle *h = gh->dht_handle;
283 struct GNUNET_MQ_Envelope *env; 272 struct GNUNET_MQ_Envelope *env;
284 struct GNUNET_DHT_ClientGetMessage *get_msg; 273 struct GNUNET_DHT_ClientGetMessage *get_msg;
285 274
286 env = GNUNET_MQ_msg_extra (get_msg, 275 env = GNUNET_MQ_msg_extra(get_msg,
287 gh->xquery_size, 276 gh->xquery_size,
288 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET); 277 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET);
289 get_msg->options = htonl ((uint32_t) gh->options); 278 get_msg->options = htonl((uint32_t)gh->options);
290 get_msg->desired_replication_level = htonl (gh->desired_replication_level); 279 get_msg->desired_replication_level = htonl(gh->desired_replication_level);
291 get_msg->type = htonl (gh->type); 280 get_msg->type = htonl(gh->type);
292 get_msg->key = gh->key; 281 get_msg->key = gh->key;
293 get_msg->unique_id = gh->unique_id; 282 get_msg->unique_id = gh->unique_id;
294 GNUNET_memcpy (&get_msg[1], 283 GNUNET_memcpy(&get_msg[1],
295 &gh[1], 284 &gh[1],
296 gh->xquery_size); 285 gh->xquery_size);
297 GNUNET_MQ_send (h->mq, 286 GNUNET_MQ_send(h->mq,
298 env); 287 env);
299} 288}
300 289
301 290
@@ -309,8 +298,8 @@ send_get (struct GNUNET_DHT_GetHandle *gh)
309 * @param transmission_offset_start at which offset should we start? 298 * @param transmission_offset_start at which offset should we start?
310 */ 299 */
311static void 300static void
312send_get_known_results (struct GNUNET_DHT_GetHandle *gh, 301send_get_known_results(struct GNUNET_DHT_GetHandle *gh,
313 unsigned int transmission_offset_start) 302 unsigned int transmission_offset_start)
314{ 303{
315 struct GNUNET_DHT_Handle *h = gh->dht_handle; 304 struct GNUNET_DHT_Handle *h = gh->dht_handle;
316 struct GNUNET_MQ_Envelope *env; 305 struct GNUNET_MQ_Envelope *env;
@@ -319,26 +308,26 @@ send_get_known_results (struct GNUNET_DHT_GetHandle *gh,
319 unsigned int max; 308 unsigned int max;
320 unsigned int transmission_offset; 309 unsigned int transmission_offset;
321 310
322 max = (GNUNET_MAX_MESSAGE_SIZE - sizeof (*msg)) 311 max = (GNUNET_MAX_MESSAGE_SIZE - sizeof(*msg))
323 / sizeof (struct GNUNET_HashCode); 312 / sizeof(struct GNUNET_HashCode);
324 transmission_offset = transmission_offset_start; 313 transmission_offset = transmission_offset_start;
325 while (transmission_offset < gh->seen_results_end) 314 while (transmission_offset < gh->seen_results_end)
326 { 315 {
327 delta = gh->seen_results_end - transmission_offset; 316 delta = gh->seen_results_end - transmission_offset;
328 if (delta > max) 317 if (delta > max)
329 delta = max; 318 delta = max;
330 env = GNUNET_MQ_msg_extra (msg, 319 env = GNUNET_MQ_msg_extra(msg,
331 delta * sizeof (struct GNUNET_HashCode), 320 delta * sizeof(struct GNUNET_HashCode),
332 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN); 321 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN);
333 msg->key = gh->key; 322 msg->key = gh->key;
334 msg->unique_id = gh->unique_id; 323 msg->unique_id = gh->unique_id;
335 GNUNET_memcpy (&msg[1], 324 GNUNET_memcpy(&msg[1],
336 &gh->seen_results[transmission_offset], 325 &gh->seen_results[transmission_offset],
337 sizeof (struct GNUNET_HashCode) * delta); 326 sizeof(struct GNUNET_HashCode) * delta);
338 GNUNET_MQ_send (h->mq, 327 GNUNET_MQ_send(h->mq,
339 env); 328 env);
340 transmission_offset += delta; 329 transmission_offset += delta;
341 } 330 }
342} 331}
343 332
344 333
@@ -352,19 +341,19 @@ send_get_known_results (struct GNUNET_DHT_GetHandle *gh,
352 * @return #GNUNET_YES (always) 341 * @return #GNUNET_YES (always)
353 */ 342 */
354static int 343static int
355add_get_request_to_pending (void *cls, 344add_get_request_to_pending(void *cls,
356 const struct GNUNET_HashCode *key, 345 const struct GNUNET_HashCode *key,
357 void *value) 346 void *value)
358{ 347{
359 struct GNUNET_DHT_Handle *handle = cls; 348 struct GNUNET_DHT_Handle *handle = cls;
360 struct GNUNET_DHT_GetHandle *gh = value; 349 struct GNUNET_DHT_GetHandle *gh = value;
361 350
362 LOG (GNUNET_ERROR_TYPE_DEBUG, 351 LOG(GNUNET_ERROR_TYPE_DEBUG,
363 "Retransmitting request related to %s to DHT %p\n", 352 "Retransmitting request related to %s to DHT %p\n",
364 GNUNET_h2s (key), 353 GNUNET_h2s(key),
365 handle); 354 handle);
366 send_get (gh); 355 send_get(gh);
367 send_get_known_results (gh, 0); 356 send_get_known_results(gh, 0);
368 return GNUNET_YES; 357 return GNUNET_YES;
369} 358}
370 359
@@ -375,25 +364,25 @@ add_get_request_to_pending (void *cls,
375 * @param mh monitor handle to generate start message for 364 * @param mh monitor handle to generate start message for
376 */ 365 */
377static void 366static void
378send_monitor_start (struct GNUNET_DHT_MonitorHandle *mh) 367send_monitor_start(struct GNUNET_DHT_MonitorHandle *mh)
379{ 368{
380 struct GNUNET_DHT_Handle *h = mh->dht_handle; 369 struct GNUNET_DHT_Handle *h = mh->dht_handle;
381 struct GNUNET_MQ_Envelope *env; 370 struct GNUNET_MQ_Envelope *env;
382 struct GNUNET_DHT_MonitorStartStopMessage *m; 371 struct GNUNET_DHT_MonitorStartStopMessage *m;
383 372
384 env = GNUNET_MQ_msg (m, 373 env = GNUNET_MQ_msg(m,
385 GNUNET_MESSAGE_TYPE_DHT_MONITOR_START); 374 GNUNET_MESSAGE_TYPE_DHT_MONITOR_START);
386 m->type = htonl (mh->type); 375 m->type = htonl(mh->type);
387 m->get = htons (NULL != mh->get_cb); 376 m->get = htons(NULL != mh->get_cb);
388 m->get_resp = htons (NULL != mh->get_resp_cb); 377 m->get_resp = htons(NULL != mh->get_resp_cb);
389 m->put = htons (NULL != mh->put_cb); 378 m->put = htons(NULL != mh->put_cb);
390 if (NULL != mh->key) 379 if (NULL != mh->key)
391 { 380 {
392 m->filter_key = htons(1); 381 m->filter_key = htons(1);
393 m->key = *mh->key; 382 m->key = *mh->key;
394 } 383 }
395 GNUNET_MQ_send (h->mq, 384 GNUNET_MQ_send(h->mq,
396 env); 385 env);
397} 386}
398 387
399 388
@@ -403,31 +392,31 @@ send_monitor_start (struct GNUNET_DHT_MonitorHandle *mh)
403 * @param cls a `struct GNUNET_DHT_Handle` 392 * @param cls a `struct GNUNET_DHT_Handle`
404 */ 393 */
405static void 394static void
406try_reconnect (void *cls) 395try_reconnect(void *cls)
407{ 396{
408 struct GNUNET_DHT_Handle *h = cls; 397 struct GNUNET_DHT_Handle *h = cls;
409 struct GNUNET_DHT_MonitorHandle *mh; 398 struct GNUNET_DHT_MonitorHandle *mh;
410 399
411 LOG (GNUNET_ERROR_TYPE_DEBUG, 400 LOG(GNUNET_ERROR_TYPE_DEBUG,
412 "Reconnecting with DHT %p\n", 401 "Reconnecting with DHT %p\n",
413 h); 402 h);
414 h->retry_time = GNUNET_TIME_STD_BACKOFF (h->retry_time); 403 h->retry_time = GNUNET_TIME_STD_BACKOFF(h->retry_time);
415 h->reconnect_task = NULL; 404 h->reconnect_task = NULL;
416 if (GNUNET_YES != try_connect (h)) 405 if (GNUNET_YES != try_connect(h))
417 { 406 {
418 LOG (GNUNET_ERROR_TYPE_WARNING, 407 LOG(GNUNET_ERROR_TYPE_WARNING,
419 "DHT reconnect failed!\n"); 408 "DHT reconnect failed!\n");
420 h->reconnect_task 409 h->reconnect_task
421 = GNUNET_SCHEDULER_add_delayed (h->retry_time, 410 = GNUNET_SCHEDULER_add_delayed(h->retry_time,
422 &try_reconnect, 411 &try_reconnect,
423 h); 412 h);
424 return; 413 return;
425 } 414 }
426 GNUNET_CONTAINER_multihashmap_iterate (h->active_requests, 415 GNUNET_CONTAINER_multihashmap_iterate(h->active_requests,
427 &add_get_request_to_pending, 416 &add_get_request_to_pending,
428 h); 417 h);
429 for (mh = h->monitor_head; NULL != mh; mh = mh->next) 418 for (mh = h->monitor_head; NULL != mh; mh = mh->next)
430 send_monitor_start (mh); 419 send_monitor_start(mh);
431} 420}
432 421
433 422
@@ -437,7 +426,7 @@ try_reconnect (void *cls)
437 * @param h handle to dht to (possibly) disconnect and reconnect 426 * @param h handle to dht to (possibly) disconnect and reconnect
438 */ 427 */
439static void 428static void
440do_disconnect (struct GNUNET_DHT_Handle *h) 429do_disconnect(struct GNUNET_DHT_Handle *h)
441{ 430{
442 struct GNUNET_DHT_PutHandle *ph; 431 struct GNUNET_DHT_PutHandle *ph;
443 GNUNET_SCHEDULER_TaskCallback cont; 432 GNUNET_SCHEDULER_TaskCallback cont;
@@ -445,27 +434,27 @@ do_disconnect (struct GNUNET_DHT_Handle *h)
445 434
446 if (NULL == h->mq) 435 if (NULL == h->mq)
447 return; 436 return;
448 GNUNET_MQ_destroy (h->mq); 437 GNUNET_MQ_destroy(h->mq);
449 h->mq = NULL; 438 h->mq = NULL;
450 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 439 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
451 "Disconnecting from DHT service, will try to reconnect in %s\n", 440 "Disconnecting from DHT service, will try to reconnect in %s\n",
452 GNUNET_STRINGS_relative_time_to_string (h->retry_time, 441 GNUNET_STRINGS_relative_time_to_string(h->retry_time,
453 GNUNET_YES)); 442 GNUNET_YES));
454 /* notify client about all PUTs that (may) have failed due to disconnect */ 443 /* notify client about all PUTs that (may) have failed due to disconnect */
455 while (NULL != (ph = h->put_head)) 444 while (NULL != (ph = h->put_head))
456 { 445 {
457 cont = ph->cont; 446 cont = ph->cont;
458 cont_cls = ph->cont_cls; 447 cont_cls = ph->cont_cls;
459 ph->env = NULL; 448 ph->env = NULL;
460 GNUNET_DHT_put_cancel (ph); 449 GNUNET_DHT_put_cancel(ph);
461 if (NULL != cont) 450 if (NULL != cont)
462 cont (cont_cls); 451 cont(cont_cls);
463 } 452 }
464 GNUNET_assert (NULL == h->reconnect_task); 453 GNUNET_assert(NULL == h->reconnect_task);
465 h->reconnect_task 454 h->reconnect_task
466 = GNUNET_SCHEDULER_add_delayed (h->retry_time, 455 = GNUNET_SCHEDULER_add_delayed(h->retry_time,
467 &try_reconnect, 456 &try_reconnect,
468 h); 457 h);
469} 458}
470 459
471 460
@@ -478,12 +467,12 @@ do_disconnect (struct GNUNET_DHT_Handle *h)
478 * @param error error code 467 * @param error error code
479 */ 468 */
480static void 469static void
481mq_error_handler (void *cls, 470mq_error_handler(void *cls,
482 enum GNUNET_MQ_Error error) 471 enum GNUNET_MQ_Error error)
483{ 472{
484 struct GNUNET_DHT_Handle *h = cls; 473 struct GNUNET_DHT_Handle *h = cls;
485 474
486 do_disconnect (h); 475 do_disconnect(h);
487} 476}
488 477
489 478
@@ -496,18 +485,18 @@ mq_error_handler (void *cls,
496 * #GNUNET_SYSERR if the message is malformed. 485 * #GNUNET_SYSERR if the message is malformed.
497 */ 486 */
498static int 487static int
499check_monitor_get (void *cls, 488check_monitor_get(void *cls,
500 const struct GNUNET_DHT_MonitorGetMessage *msg) 489 const struct GNUNET_DHT_MonitorGetMessage *msg)
501{ 490{
502 uint32_t plen = ntohl (msg->get_path_length); 491 uint32_t plen = ntohl(msg->get_path_length);
503 uint16_t msize = ntohs (msg->header.size) - sizeof (*msg); 492 uint16_t msize = ntohs(msg->header.size) - sizeof(*msg);
504 493
505 if ( (plen > UINT16_MAX) || 494 if ((plen > UINT16_MAX) ||
506 (plen * sizeof (struct GNUNET_PeerIdentity) != msize) ) 495 (plen * sizeof(struct GNUNET_PeerIdentity) != msize))
507 { 496 {
508 GNUNET_break (0); 497 GNUNET_break(0);
509 return GNUNET_SYSERR; 498 return GNUNET_SYSERR;
510 } 499 }
511 return GNUNET_OK; 500 return GNUNET_OK;
512} 501}
513 502
@@ -519,31 +508,31 @@ check_monitor_get (void *cls,
519 * @param msg Monitor get message from the service. 508 * @param msg Monitor get message from the service.
520 */ 509 */
521static void 510static void
522handle_monitor_get (void *cls, 511handle_monitor_get(void *cls,
523 const struct GNUNET_DHT_MonitorGetMessage *msg) 512 const struct GNUNET_DHT_MonitorGetMessage *msg)
524{ 513{
525 struct GNUNET_DHT_Handle *handle = cls; 514 struct GNUNET_DHT_Handle *handle = cls;
526 struct GNUNET_DHT_MonitorHandle *mh; 515 struct GNUNET_DHT_MonitorHandle *mh;
527 516
528 for (mh = handle->monitor_head; NULL != mh; mh = mh->next) 517 for (mh = handle->monitor_head; NULL != mh; mh = mh->next)
529 { 518 {
530 if (NULL == mh->get_cb) 519 if (NULL == mh->get_cb)
531 continue; 520 continue;
532 if ( ( (GNUNET_BLOCK_TYPE_ANY == mh->type) || 521 if (((GNUNET_BLOCK_TYPE_ANY == mh->type) ||
533 (mh->type == ntohl (msg->type)) ) && 522 (mh->type == ntohl(msg->type))) &&
534 ( (NULL == mh->key) || 523 ((NULL == mh->key) ||
535 (0 == memcmp (mh->key, 524 (0 == memcmp(mh->key,
536 &msg->key, 525 &msg->key,
537 sizeof (struct GNUNET_HashCode))) ) ) 526 sizeof(struct GNUNET_HashCode)))))
538 mh->get_cb (mh->cb_cls, 527 mh->get_cb(mh->cb_cls,
539 ntohl (msg->options), 528 ntohl(msg->options),
540 (enum GNUNET_BLOCK_Type) ntohl(msg->type), 529 (enum GNUNET_BLOCK_Type)ntohl(msg->type),
541 ntohl (msg->hop_count), 530 ntohl(msg->hop_count),
542 ntohl (msg->desired_replication_level), 531 ntohl(msg->desired_replication_level),
543 ntohl (msg->get_path_length), 532 ntohl(msg->get_path_length),
544 (struct GNUNET_PeerIdentity *) &msg[1], 533 (struct GNUNET_PeerIdentity *)&msg[1],
545 &msg->key); 534 &msg->key);
546 } 535 }
547} 536}
548 537
549 538
@@ -556,19 +545,19 @@ handle_monitor_get (void *cls,
556 * #GNUNET_SYSERR if the message is malformed. 545 * #GNUNET_SYSERR if the message is malformed.
557 */ 546 */
558static int 547static int
559check_monitor_get_resp (void *cls, 548check_monitor_get_resp(void *cls,
560 const struct GNUNET_DHT_MonitorGetRespMessage *msg) 549 const struct GNUNET_DHT_MonitorGetRespMessage *msg)
561{ 550{
562 size_t msize = ntohs (msg->header.size) - sizeof (*msg); 551 size_t msize = ntohs(msg->header.size) - sizeof(*msg);
563 uint32_t getl = ntohl (msg->get_path_length); 552 uint32_t getl = ntohl(msg->get_path_length);
564 uint32_t putl = ntohl (msg->put_path_length); 553 uint32_t putl = ntohl(msg->put_path_length);
565 554
566 if ( (getl + putl < getl) || 555 if ((getl + putl < getl) ||
567 ( (msize / sizeof (struct GNUNET_PeerIdentity)) < getl + putl) ) 556 ((msize / sizeof(struct GNUNET_PeerIdentity)) < getl + putl))
568 { 557 {
569 GNUNET_break (0); 558 GNUNET_break(0);
570 return GNUNET_SYSERR; 559 return GNUNET_SYSERR;
571 } 560 }
572 return GNUNET_OK; 561 return GNUNET_OK;
573} 562}
574 563
@@ -580,38 +569,38 @@ check_monitor_get_resp (void *cls,
580 * @param msg monitor get response message from the service 569 * @param msg monitor get response message from the service
581 */ 570 */
582static void 571static void
583handle_monitor_get_resp (void *cls, 572handle_monitor_get_resp(void *cls,
584 const struct GNUNET_DHT_MonitorGetRespMessage *msg) 573 const struct GNUNET_DHT_MonitorGetRespMessage *msg)
585{ 574{
586 struct GNUNET_DHT_Handle *handle = cls; 575 struct GNUNET_DHT_Handle *handle = cls;
587 size_t msize = ntohs (msg->header.size) - sizeof (*msg); 576 size_t msize = ntohs(msg->header.size) - sizeof(*msg);
588 const struct GNUNET_PeerIdentity *path; 577 const struct GNUNET_PeerIdentity *path;
589 uint32_t getl = ntohl (msg->get_path_length); 578 uint32_t getl = ntohl(msg->get_path_length);
590 uint32_t putl = ntohl (msg->put_path_length); 579 uint32_t putl = ntohl(msg->put_path_length);
591 struct GNUNET_DHT_MonitorHandle *mh; 580 struct GNUNET_DHT_MonitorHandle *mh;
592 581
593 path = (const struct GNUNET_PeerIdentity *) &msg[1]; 582 path = (const struct GNUNET_PeerIdentity *)&msg[1];
594 for (mh = handle->monitor_head; NULL != mh; mh = mh->next) 583 for (mh = handle->monitor_head; NULL != mh; mh = mh->next)
595 { 584 {
596 if (NULL == mh->get_resp_cb) 585 if (NULL == mh->get_resp_cb)
597 continue; 586 continue;
598 if ( ( (GNUNET_BLOCK_TYPE_ANY == mh->type) || 587 if (((GNUNET_BLOCK_TYPE_ANY == mh->type) ||
599 (mh->type == ntohl(msg->type)) ) && 588 (mh->type == ntohl(msg->type))) &&
600 ( (NULL == mh->key) || 589 ((NULL == mh->key) ||
601 (0 == memcmp (mh->key, 590 (0 == memcmp(mh->key,
602 &msg->key, 591 &msg->key,
603 sizeof (struct GNUNET_HashCode))) ) ) 592 sizeof(struct GNUNET_HashCode)))))
604 mh->get_resp_cb (mh->cb_cls, 593 mh->get_resp_cb(mh->cb_cls,
605 (enum GNUNET_BLOCK_Type) ntohl (msg->type), 594 (enum GNUNET_BLOCK_Type)ntohl(msg->type),
606 path, 595 path,
607 getl, 596 getl,
608 &path[getl], 597 &path[getl],
609 putl, 598 putl,
610 GNUNET_TIME_absolute_ntoh(msg->expiration_time), 599 GNUNET_TIME_absolute_ntoh(msg->expiration_time),
611 &msg->key, 600 &msg->key,
612 (const void *) &path[getl + putl], 601 (const void *)&path[getl + putl],
613 msize - sizeof (struct GNUNET_PeerIdentity) * (putl + getl)); 602 msize - sizeof(struct GNUNET_PeerIdentity) * (putl + getl));
614 } 603 }
615} 604}
616 605
617 606
@@ -624,19 +613,19 @@ handle_monitor_get_resp (void *cls,
624 * #GNUNET_SYSERR if the message is malformed. 613 * #GNUNET_SYSERR if the message is malformed.
625 */ 614 */
626static int 615static int
627check_monitor_put (void *cls, 616check_monitor_put(void *cls,
628 const struct GNUNET_DHT_MonitorPutMessage *msg) 617 const struct GNUNET_DHT_MonitorPutMessage *msg)
629{ 618{
630 size_t msize; 619 size_t msize;
631 uint32_t putl; 620 uint32_t putl;
632 621
633 msize = ntohs (msg->header.size) - sizeof (*msg); 622 msize = ntohs(msg->header.size) - sizeof(*msg);
634 putl = ntohl (msg->put_path_length); 623 putl = ntohl(msg->put_path_length);
635 if ((msize / sizeof (struct GNUNET_PeerIdentity)) < putl) 624 if ((msize / sizeof(struct GNUNET_PeerIdentity)) < putl)
636 { 625 {
637 GNUNET_break (0); 626 GNUNET_break(0);
638 return GNUNET_SYSERR; 627 return GNUNET_SYSERR;
639 } 628 }
640 return GNUNET_OK; 629 return GNUNET_OK;
641} 630}
642 631
@@ -648,38 +637,38 @@ check_monitor_put (void *cls,
648 * @param msg Monitor put message from the service. 637 * @param msg Monitor put message from the service.
649 */ 638 */
650static void 639static void
651handle_monitor_put (void *cls, 640handle_monitor_put(void *cls,
652 const struct GNUNET_DHT_MonitorPutMessage *msg) 641 const struct GNUNET_DHT_MonitorPutMessage *msg)
653{ 642{
654 struct GNUNET_DHT_Handle *handle = cls; 643 struct GNUNET_DHT_Handle *handle = cls;
655 size_t msize = ntohs (msg->header.size) - sizeof (*msg); 644 size_t msize = ntohs(msg->header.size) - sizeof(*msg);
656 uint32_t putl = ntohl (msg->put_path_length); 645 uint32_t putl = ntohl(msg->put_path_length);
657 const struct GNUNET_PeerIdentity *path; 646 const struct GNUNET_PeerIdentity *path;
658 struct GNUNET_DHT_MonitorHandle *mh; 647 struct GNUNET_DHT_MonitorHandle *mh;
659 648
660 path = (const struct GNUNET_PeerIdentity *) &msg[1]; 649 path = (const struct GNUNET_PeerIdentity *)&msg[1];
661 for (mh = handle->monitor_head; NULL != mh; mh = mh->next) 650 for (mh = handle->monitor_head; NULL != mh; mh = mh->next)
662 { 651 {
663 if (NULL == mh->put_cb) 652 if (NULL == mh->put_cb)
664 continue; 653 continue;
665 if ( ( (GNUNET_BLOCK_TYPE_ANY == mh->type) || 654 if (((GNUNET_BLOCK_TYPE_ANY == mh->type) ||
666 (mh->type == ntohl(msg->type)) ) && 655 (mh->type == ntohl(msg->type))) &&
667 ( (NULL == mh->key) || 656 ((NULL == mh->key) ||
668 (0 == memcmp (mh->key, 657 (0 == memcmp(mh->key,
669 &msg->key, 658 &msg->key,
670 sizeof (struct GNUNET_HashCode))) ) ) 659 sizeof(struct GNUNET_HashCode)))))
671 mh->put_cb (mh->cb_cls, 660 mh->put_cb(mh->cb_cls,
672 ntohl (msg->options), 661 ntohl(msg->options),
673 (enum GNUNET_BLOCK_Type) ntohl(msg->type), 662 (enum GNUNET_BLOCK_Type)ntohl(msg->type),
674 ntohl (msg->hop_count), 663 ntohl(msg->hop_count),
675 ntohl (msg->desired_replication_level), 664 ntohl(msg->desired_replication_level),
676 putl, 665 putl,
677 path, 666 path,
678 GNUNET_TIME_absolute_ntoh(msg->expiration_time), 667 GNUNET_TIME_absolute_ntoh(msg->expiration_time),
679 &msg->key, 668 &msg->key,
680 (const void *) &path[putl], 669 (const void *)&path[putl],
681 msize - sizeof (struct GNUNET_PeerIdentity) * putl); 670 msize - sizeof(struct GNUNET_PeerIdentity) * putl);
682 } 671 }
683} 672}
684 673
685 674
@@ -692,25 +681,25 @@ handle_monitor_put (void *cls,
692 * #GNUNET_SYSERR if the message is malformed. 681 * #GNUNET_SYSERR if the message is malformed.
693 */ 682 */
694static int 683static int
695check_client_result (void *cls, 684check_client_result(void *cls,
696 const struct GNUNET_DHT_ClientResultMessage *msg) 685 const struct GNUNET_DHT_ClientResultMessage *msg)
697{ 686{
698 size_t msize = ntohs (msg->header.size) - sizeof (*msg); 687 size_t msize = ntohs(msg->header.size) - sizeof(*msg);
699 uint32_t put_path_length = ntohl (msg->put_path_length); 688 uint32_t put_path_length = ntohl(msg->put_path_length);
700 uint32_t get_path_length = ntohl (msg->get_path_length); 689 uint32_t get_path_length = ntohl(msg->get_path_length);
701 size_t meta_length; 690 size_t meta_length;
702 691
703 meta_length = 692 meta_length =
704 sizeof (struct GNUNET_PeerIdentity) * (get_path_length + put_path_length); 693 sizeof(struct GNUNET_PeerIdentity) * (get_path_length + put_path_length);
705 if ( (msize < meta_length) || 694 if ((msize < meta_length) ||
706 (get_path_length > 695 (get_path_length >
707 GNUNET_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || 696 GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) ||
708 (put_path_length > 697 (put_path_length >
709 GNUNET_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) ) 698 GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)))
710 { 699 {
711 GNUNET_break (0); 700 GNUNET_break(0);
712 return GNUNET_SYSERR; 701 return GNUNET_SYSERR;
713 } 702 }
714 return GNUNET_OK; 703 return GNUNET_OK;
715} 704}
716 705
@@ -724,15 +713,15 @@ check_client_result (void *cls,
724 * @return #GNUNET_YES to continue to iterate over all results 713 * @return #GNUNET_YES to continue to iterate over all results
725 */ 714 */
726static int 715static int
727process_client_result (void *cls, 716process_client_result(void *cls,
728 const struct GNUNET_HashCode *key, 717 const struct GNUNET_HashCode *key,
729 void *value) 718 void *value)
730{ 719{
731 const struct GNUNET_DHT_ClientResultMessage *crm = cls; 720 const struct GNUNET_DHT_ClientResultMessage *crm = cls;
732 struct GNUNET_DHT_GetHandle *get_handle = value; 721 struct GNUNET_DHT_GetHandle *get_handle = value;
733 size_t msize = ntohs (crm->header.size) - sizeof (*crm); 722 size_t msize = ntohs(crm->header.size) - sizeof(*crm);
734 uint32_t put_path_length = ntohl (crm->put_path_length); 723 uint32_t put_path_length = ntohl(crm->put_path_length);
735 uint32_t get_path_length = ntohl (crm->get_path_length); 724 uint32_t get_path_length = ntohl(crm->get_path_length);
736 const struct GNUNET_PeerIdentity *put_path; 725 const struct GNUNET_PeerIdentity *put_path;
737 const struct GNUNET_PeerIdentity *get_path; 726 const struct GNUNET_PeerIdentity *get_path;
738 struct GNUNET_HashCode hc; 727 struct GNUNET_HashCode hc;
@@ -741,59 +730,59 @@ process_client_result (void *cls,
741 const void *data; 730 const void *data;
742 731
743 if (crm->unique_id != get_handle->unique_id) 732 if (crm->unique_id != get_handle->unique_id)
744 { 733 {
745 /* UID mismatch */ 734 /* UID mismatch */
746 LOG (GNUNET_ERROR_TYPE_DEBUG, 735 LOG(GNUNET_ERROR_TYPE_DEBUG,
747 "Ignoring reply for %s: UID mismatch: %llu/%llu\n", 736 "Ignoring reply for %s: UID mismatch: %llu/%llu\n",
748 GNUNET_h2s (key), 737 GNUNET_h2s(key),
749 crm->unique_id, 738 crm->unique_id,
750 get_handle->unique_id); 739 get_handle->unique_id);
751 return GNUNET_YES; 740 return GNUNET_YES;
752 } 741 }
753 /* FIXME: might want to check that type matches */ 742 /* FIXME: might want to check that type matches */
754 meta_length = 743 meta_length =
755 sizeof (struct GNUNET_PeerIdentity) * (get_path_length + put_path_length); 744 sizeof(struct GNUNET_PeerIdentity) * (get_path_length + put_path_length);
756 data_length = msize - meta_length; 745 data_length = msize - meta_length;
757 put_path = (const struct GNUNET_PeerIdentity *) &crm[1]; 746 put_path = (const struct GNUNET_PeerIdentity *)&crm[1];
758 get_path = &put_path[put_path_length]; 747 get_path = &put_path[put_path_length];
759 { 748 {
760 char *pp; 749 char *pp;
761 char *gp; 750 char *gp;
762 751
763 gp = GNUNET_STRINGS_pp2s (get_path, 752 gp = GNUNET_STRINGS_pp2s(get_path,
764 get_path_length); 753 get_path_length);
765 pp = GNUNET_STRINGS_pp2s (put_path, 754 pp = GNUNET_STRINGS_pp2s(put_path,
766 put_path_length); 755 put_path_length);
767 LOG (GNUNET_ERROR_TYPE_DEBUG, 756 LOG(GNUNET_ERROR_TYPE_DEBUG,
768 "Giving %u byte reply for %s to application (GP: %s, PP: %s)\n", 757 "Giving %u byte reply for %s to application (GP: %s, PP: %s)\n",
769 (unsigned int) data_length, 758 (unsigned int)data_length,
770 GNUNET_h2s (key), 759 GNUNET_h2s(key),
771 gp, 760 gp,
772 pp); 761 pp);
773 GNUNET_free (gp); 762 GNUNET_free(gp);
774 GNUNET_free (pp); 763 GNUNET_free(pp);
775 } 764 }
776 data = &get_path[get_path_length]; 765 data = &get_path[get_path_length];
777 /* remember that we've seen this result */ 766 /* remember that we've seen this result */
778 GNUNET_CRYPTO_hash (data, 767 GNUNET_CRYPTO_hash(data,
779 data_length, 768 data_length,
780 &hc); 769 &hc);
781 if (get_handle->seen_results_size == get_handle->seen_results_end) 770 if (get_handle->seen_results_size == get_handle->seen_results_end)
782 GNUNET_array_grow (get_handle->seen_results, 771 GNUNET_array_grow(get_handle->seen_results,
783 get_handle->seen_results_size, 772 get_handle->seen_results_size,
784 get_handle->seen_results_size * 2 + 1); 773 get_handle->seen_results_size * 2 + 1);
785 get_handle->seen_results[get_handle->seen_results_end++] = hc; 774 get_handle->seen_results[get_handle->seen_results_end++] = hc;
786 /* no need to block it explicitly, service already knows about it! */ 775 /* no need to block it explicitly, service already knows about it! */
787 get_handle->iter (get_handle->iter_cls, 776 get_handle->iter(get_handle->iter_cls,
788 GNUNET_TIME_absolute_ntoh (crm->expiration), 777 GNUNET_TIME_absolute_ntoh(crm->expiration),
789 key, 778 key,
790 get_path, 779 get_path,
791 get_path_length, 780 get_path_length,
792 put_path, 781 put_path,
793 put_path_length, 782 put_path_length,
794 ntohl (crm->type), 783 ntohl(crm->type),
795 data_length, 784 data_length,
796 data); 785 data);
797 return GNUNET_YES; 786 return GNUNET_YES;
798} 787}
799 788
@@ -805,15 +794,15 @@ process_client_result (void *cls,
805 * @param msg Monitor put message from the service. 794 * @param msg Monitor put message from the service.
806 */ 795 */
807static void 796static void
808handle_client_result (void *cls, 797handle_client_result(void *cls,
809 const struct GNUNET_DHT_ClientResultMessage *msg) 798 const struct GNUNET_DHT_ClientResultMessage *msg)
810{ 799{
811 struct GNUNET_DHT_Handle *handle = cls; 800 struct GNUNET_DHT_Handle *handle = cls;
812 801
813 GNUNET_CONTAINER_multihashmap_get_multiple (handle->active_requests, 802 GNUNET_CONTAINER_multihashmap_get_multiple(handle->active_requests,
814 &msg->key, 803 &msg->key,
815 &process_client_result, 804 &process_client_result,
816 (void *) msg); 805 (void *)msg);
817} 806}
818 807
819 808
@@ -823,7 +812,7 @@ handle_client_result (void *cls,
823 * @param cls The DHT handle. 812 * @param cls The DHT handle.
824 */ 813 */
825static void 814static void
826handle_put_cont (void *cls) 815handle_put_cont(void *cls)
827{ 816{
828 struct GNUNET_DHT_PutHandle *ph = cls; 817 struct GNUNET_DHT_PutHandle *ph = cls;
829 GNUNET_SCHEDULER_TaskCallback cont; 818 GNUNET_SCHEDULER_TaskCallback cont;
@@ -832,9 +821,9 @@ handle_put_cont (void *cls)
832 cont = ph->cont; 821 cont = ph->cont;
833 cont_cls = ph->cont_cls; 822 cont_cls = ph->cont_cls;
834 ph->env = NULL; 823 ph->env = NULL;
835 GNUNET_DHT_put_cancel (ph); 824 GNUNET_DHT_put_cancel(ph);
836 if (NULL != cont) 825 if (NULL != cont)
837 cont (cont_cls); 826 cont(cont_cls);
838} 827}
839 828
840 829
@@ -845,40 +834,41 @@ handle_put_cont (void *cls)
845 * @return #GNUNET_YES on success, #GNUNET_NO on failure. 834 * @return #GNUNET_YES on success, #GNUNET_NO on failure.
846 */ 835 */
847static int 836static int
848try_connect (struct GNUNET_DHT_Handle *h) 837try_connect(struct GNUNET_DHT_Handle *h)
849{ 838{
850 struct GNUNET_MQ_MessageHandler handlers[] = { 839 struct GNUNET_MQ_MessageHandler handlers[] = {
851 GNUNET_MQ_hd_var_size (monitor_get, 840 GNUNET_MQ_hd_var_size(monitor_get,
852 GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET, 841 GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET,
853 struct GNUNET_DHT_MonitorGetMessage, 842 struct GNUNET_DHT_MonitorGetMessage,
854 h), 843 h),
855 GNUNET_MQ_hd_var_size (monitor_get_resp, 844 GNUNET_MQ_hd_var_size(monitor_get_resp,
856 GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET_RESP, 845 GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET_RESP,
857 struct GNUNET_DHT_MonitorGetRespMessage, 846 struct GNUNET_DHT_MonitorGetRespMessage,
858 h), 847 h),
859 GNUNET_MQ_hd_var_size (monitor_put, 848 GNUNET_MQ_hd_var_size(monitor_put,
860 GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT, 849 GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT,
861 struct GNUNET_DHT_MonitorPutMessage, 850 struct GNUNET_DHT_MonitorPutMessage,
862 h), 851 h),
863 GNUNET_MQ_hd_var_size (client_result, 852 GNUNET_MQ_hd_var_size(client_result,
864 GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT, 853 GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT,
865 struct GNUNET_DHT_ClientResultMessage, 854 struct GNUNET_DHT_ClientResultMessage,
866 h), 855 h),
867 GNUNET_MQ_handler_end () 856 GNUNET_MQ_handler_end()
868 }; 857 };
858
869 if (NULL != h->mq) 859 if (NULL != h->mq)
870 return GNUNET_OK; 860 return GNUNET_OK;
871 h->mq = GNUNET_CLIENT_connect (h->cfg, 861 h->mq = GNUNET_CLIENT_connect(h->cfg,
872 "dht", 862 "dht",
873 handlers, 863 handlers,
874 &mq_error_handler, 864 &mq_error_handler,
875 h); 865 h);
876 if (NULL == h->mq) 866 if (NULL == h->mq)
877 { 867 {
878 LOG (GNUNET_ERROR_TYPE_WARNING, 868 LOG(GNUNET_ERROR_TYPE_WARNING,
879 "Failed to connect to the DHT service!\n"); 869 "Failed to connect to the DHT service!\n");
880 return GNUNET_NO; 870 return GNUNET_NO;
881 } 871 }
882 return GNUNET_YES; 872 return GNUNET_YES;
883} 873}
884 874
@@ -892,24 +882,24 @@ try_connect (struct GNUNET_DHT_Handle *h)
892 * @return handle to the DHT service, or NULL on error 882 * @return handle to the DHT service, or NULL on error
893 */ 883 */
894struct GNUNET_DHT_Handle * 884struct GNUNET_DHT_Handle *
895GNUNET_DHT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 885GNUNET_DHT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg,
896 unsigned int ht_len) 886 unsigned int ht_len)
897{ 887{
898 struct GNUNET_DHT_Handle *handle; 888 struct GNUNET_DHT_Handle *handle;
899 889
900 handle = GNUNET_new (struct GNUNET_DHT_Handle); 890 handle = GNUNET_new(struct GNUNET_DHT_Handle);
901 handle->cfg = cfg; 891 handle->cfg = cfg;
902 handle->uid_gen 892 handle->uid_gen
903 = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 893 = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK,
904 UINT64_MAX); 894 UINT64_MAX);
905 handle->active_requests 895 handle->active_requests
906 = GNUNET_CONTAINER_multihashmap_create (ht_len, 896 = GNUNET_CONTAINER_multihashmap_create(ht_len,
907 GNUNET_YES); 897 GNUNET_YES);
908 if (GNUNET_NO == try_connect (handle)) 898 if (GNUNET_NO == try_connect(handle))
909 { 899 {
910 GNUNET_DHT_disconnect (handle); 900 GNUNET_DHT_disconnect(handle);
911 return NULL; 901 return NULL;
912 } 902 }
913 return handle; 903 return handle;
914} 904}
915 905
@@ -920,30 +910,30 @@ GNUNET_DHT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
920 * @param handle handle of the DHT connection to stop 910 * @param handle handle of the DHT connection to stop
921 */ 911 */
922void 912void
923GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle) 913GNUNET_DHT_disconnect(struct GNUNET_DHT_Handle *handle)
924{ 914{
925 struct GNUNET_DHT_PutHandle *ph; 915 struct GNUNET_DHT_PutHandle *ph;
926 916
927 GNUNET_assert (0 == 917 GNUNET_assert(0 ==
928 GNUNET_CONTAINER_multihashmap_size (handle->active_requests)); 918 GNUNET_CONTAINER_multihashmap_size(handle->active_requests));
929 while (NULL != (ph = handle->put_head)) 919 while (NULL != (ph = handle->put_head))
930 { 920 {
931 if (NULL != ph->cont) 921 if (NULL != ph->cont)
932 ph->cont (ph->cont_cls); 922 ph->cont(ph->cont_cls);
933 GNUNET_DHT_put_cancel (ph); 923 GNUNET_DHT_put_cancel(ph);
934 } 924 }
935 if (NULL != handle->mq) 925 if (NULL != handle->mq)
936 { 926 {
937 GNUNET_MQ_destroy (handle->mq); 927 GNUNET_MQ_destroy(handle->mq);
938 handle->mq = NULL; 928 handle->mq = NULL;
939 } 929 }
940 if (NULL != handle->reconnect_task) 930 if (NULL != handle->reconnect_task)
941 { 931 {
942 GNUNET_SCHEDULER_cancel (handle->reconnect_task); 932 GNUNET_SCHEDULER_cancel(handle->reconnect_task);
943 handle->reconnect_task = NULL; 933 handle->reconnect_task = NULL;
944 } 934 }
945 GNUNET_CONTAINER_multihashmap_destroy (handle->active_requests); 935 GNUNET_CONTAINER_multihashmap_destroy(handle->active_requests);
946 GNUNET_free (handle); 936 GNUNET_free(handle);
947} 937}
948 938
949 939
@@ -968,59 +958,59 @@ GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle)
968 * @param cont_cls closure for @a cont 958 * @param cont_cls closure for @a cont
969 */ 959 */
970struct GNUNET_DHT_PutHandle * 960struct GNUNET_DHT_PutHandle *
971GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, 961GNUNET_DHT_put(struct GNUNET_DHT_Handle *handle,
972 const struct GNUNET_HashCode *key, 962 const struct GNUNET_HashCode *key,
973 uint32_t desired_replication_level, 963 uint32_t desired_replication_level,
974 enum GNUNET_DHT_RouteOption options, 964 enum GNUNET_DHT_RouteOption options,
975 enum GNUNET_BLOCK_Type type, 965 enum GNUNET_BLOCK_Type type,
976 size_t size, 966 size_t size,
977 const void *data, 967 const void *data,
978 struct GNUNET_TIME_Absolute exp, 968 struct GNUNET_TIME_Absolute exp,
979 GNUNET_SCHEDULER_TaskCallback cont, 969 GNUNET_SCHEDULER_TaskCallback cont,
980 void *cont_cls) 970 void *cont_cls)
981{ 971{
982 struct GNUNET_MQ_Envelope *env; 972 struct GNUNET_MQ_Envelope *env;
983 struct GNUNET_DHT_ClientPutMessage *put_msg; 973 struct GNUNET_DHT_ClientPutMessage *put_msg;
984 size_t msize; 974 size_t msize;
985 struct GNUNET_DHT_PutHandle *ph; 975 struct GNUNET_DHT_PutHandle *ph;
986 976
987 msize = sizeof (struct GNUNET_DHT_ClientPutMessage) + size; 977 msize = sizeof(struct GNUNET_DHT_ClientPutMessage) + size;
988 if ((msize >= GNUNET_MAX_MESSAGE_SIZE) || 978 if ((msize >= GNUNET_MAX_MESSAGE_SIZE) ||
989 (size >= GNUNET_MAX_MESSAGE_SIZE)) 979 (size >= GNUNET_MAX_MESSAGE_SIZE))
990 { 980 {
991 GNUNET_break (0); 981 GNUNET_break(0);
992 return NULL; 982 return NULL;
993 } 983 }
994 if (NULL == handle->mq) 984 if (NULL == handle->mq)
995 return NULL; 985 return NULL;
996 LOG (GNUNET_ERROR_TYPE_DEBUG, 986 LOG(GNUNET_ERROR_TYPE_DEBUG,
997 "Sending PUT for %s to DHT via %p\n", 987 "Sending PUT for %s to DHT via %p\n",
998 GNUNET_h2s (key), 988 GNUNET_h2s(key),
999 handle); 989 handle);
1000 ph = GNUNET_new (struct GNUNET_DHT_PutHandle); 990 ph = GNUNET_new(struct GNUNET_DHT_PutHandle);
1001 ph->dht_handle = handle; 991 ph->dht_handle = handle;
1002 ph->cont = cont; 992 ph->cont = cont;
1003 ph->cont_cls = cont_cls; 993 ph->cont_cls = cont_cls;
1004 GNUNET_CONTAINER_DLL_insert_tail (handle->put_head, 994 GNUNET_CONTAINER_DLL_insert_tail(handle->put_head,
1005 handle->put_tail, 995 handle->put_tail,
1006 ph); 996 ph);
1007 env = GNUNET_MQ_msg_extra (put_msg, 997 env = GNUNET_MQ_msg_extra(put_msg,
1008 size, 998 size,
1009 GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT); 999 GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT);
1010 GNUNET_MQ_notify_sent (env, 1000 GNUNET_MQ_notify_sent(env,
1011 &handle_put_cont, 1001 &handle_put_cont,
1012 ph); 1002 ph);
1013 ph->env = env; 1003 ph->env = env;
1014 put_msg->type = htonl ((uint32_t) type); 1004 put_msg->type = htonl((uint32_t)type);
1015 put_msg->options = htonl ((uint32_t) options); 1005 put_msg->options = htonl((uint32_t)options);
1016 put_msg->desired_replication_level = htonl (desired_replication_level); 1006 put_msg->desired_replication_level = htonl(desired_replication_level);
1017 put_msg->expiration = GNUNET_TIME_absolute_hton (exp); 1007 put_msg->expiration = GNUNET_TIME_absolute_hton(exp);
1018 put_msg->key = *key; 1008 put_msg->key = *key;
1019 GNUNET_memcpy (&put_msg[1], 1009 GNUNET_memcpy(&put_msg[1],
1020 data, 1010 data,
1021 size); 1011 size);
1022 GNUNET_MQ_send (handle->mq, 1012 GNUNET_MQ_send(handle->mq,
1023 env); 1013 env);
1024 return ph; 1014 return ph;
1025} 1015}
1026 1016
@@ -1037,18 +1027,18 @@ GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
1037 * @param ph put operation to cancel ('cont' will no longer be called) 1027 * @param ph put operation to cancel ('cont' will no longer be called)
1038 */ 1028 */
1039void 1029void
1040GNUNET_DHT_put_cancel (struct GNUNET_DHT_PutHandle *ph) 1030GNUNET_DHT_put_cancel(struct GNUNET_DHT_PutHandle *ph)
1041{ 1031{
1042 struct GNUNET_DHT_Handle *handle = ph->dht_handle; 1032 struct GNUNET_DHT_Handle *handle = ph->dht_handle;
1043 1033
1044 if (NULL != ph->env) 1034 if (NULL != ph->env)
1045 GNUNET_MQ_notify_sent (ph->env, 1035 GNUNET_MQ_notify_sent(ph->env,
1046 NULL, 1036 NULL,
1047 NULL); 1037 NULL);
1048 GNUNET_CONTAINER_DLL_remove (handle->put_head, 1038 GNUNET_CONTAINER_DLL_remove(handle->put_head,
1049 handle->put_tail, 1039 handle->put_tail,
1050 ph); 1040 ph);
1051 GNUNET_free (ph); 1041 GNUNET_free(ph);
1052} 1042}
1053 1043
1054 1044
@@ -1069,32 +1059,32 @@ GNUNET_DHT_put_cancel (struct GNUNET_DHT_PutHandle *ph)
1069 * @return handle to stop the async get 1059 * @return handle to stop the async get
1070 */ 1060 */
1071struct GNUNET_DHT_GetHandle * 1061struct GNUNET_DHT_GetHandle *
1072GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, 1062GNUNET_DHT_get_start(struct GNUNET_DHT_Handle *handle,
1073 enum GNUNET_BLOCK_Type type, 1063 enum GNUNET_BLOCK_Type type,
1074 const struct GNUNET_HashCode *key, 1064 const struct GNUNET_HashCode *key,
1075 uint32_t desired_replication_level, 1065 uint32_t desired_replication_level,
1076 enum GNUNET_DHT_RouteOption options, 1066 enum GNUNET_DHT_RouteOption options,
1077 const void *xquery, 1067 const void *xquery,
1078 size_t xquery_size, 1068 size_t xquery_size,
1079 GNUNET_DHT_GetIterator iter, 1069 GNUNET_DHT_GetIterator iter,
1080 void *iter_cls) 1070 void *iter_cls)
1081{ 1071{
1082 struct GNUNET_DHT_GetHandle *gh; 1072 struct GNUNET_DHT_GetHandle *gh;
1083 size_t msize; 1073 size_t msize;
1084 1074
1085 msize = sizeof (struct GNUNET_DHT_ClientGetMessage) + xquery_size; 1075 msize = sizeof(struct GNUNET_DHT_ClientGetMessage) + xquery_size;
1086 if ((msize >= GNUNET_MAX_MESSAGE_SIZE) || 1076 if ((msize >= GNUNET_MAX_MESSAGE_SIZE) ||
1087 (xquery_size >= GNUNET_MAX_MESSAGE_SIZE)) 1077 (xquery_size >= GNUNET_MAX_MESSAGE_SIZE))
1088 { 1078 {
1089 GNUNET_break (0); 1079 GNUNET_break(0);
1090 return NULL; 1080 return NULL;
1091 } 1081 }
1092 LOG (GNUNET_ERROR_TYPE_DEBUG, 1082 LOG(GNUNET_ERROR_TYPE_DEBUG,
1093 "Sending query for %s to DHT %p\n", 1083 "Sending query for %s to DHT %p\n",
1094 GNUNET_h2s (key), 1084 GNUNET_h2s(key),
1095 handle); 1085 handle);
1096 gh = GNUNET_malloc (sizeof (struct GNUNET_DHT_GetHandle) + 1086 gh = GNUNET_malloc(sizeof(struct GNUNET_DHT_GetHandle) +
1097 xquery_size); 1087 xquery_size);
1098 gh->iter = iter; 1088 gh->iter = iter;
1099 gh->iter_cls = iter_cls; 1089 gh->iter_cls = iter_cls;
1100 gh->dht_handle = handle; 1090 gh->dht_handle = handle;
@@ -1104,15 +1094,15 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle,
1104 gh->desired_replication_level = desired_replication_level; 1094 gh->desired_replication_level = desired_replication_level;
1105 gh->type = type; 1095 gh->type = type;
1106 gh->options = options; 1096 gh->options = options;
1107 GNUNET_memcpy (&gh[1], 1097 GNUNET_memcpy(&gh[1],
1108 xquery, 1098 xquery,
1109 xquery_size); 1099 xquery_size);
1110 GNUNET_CONTAINER_multihashmap_put (handle->active_requests, 1100 GNUNET_CONTAINER_multihashmap_put(handle->active_requests,
1111 &gh->key, 1101 &gh->key,
1112 gh, 1102 gh,
1113 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1103 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1114 if (NULL != handle->mq) 1104 if (NULL != handle->mq)
1115 send_get (gh); 1105 send_get(gh);
1116 return gh; 1106 return gh;
1117} 1107}
1118 1108
@@ -1128,9 +1118,9 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle,
1128 * to be blocked 1118 * to be blocked
1129 */ 1119 */
1130void 1120void
1131GNUNET_DHT_get_filter_known_results (struct GNUNET_DHT_GetHandle *get_handle, 1121GNUNET_DHT_get_filter_known_results(struct GNUNET_DHT_GetHandle *get_handle,
1132 unsigned int num_results, 1122 unsigned int num_results,
1133 const struct GNUNET_HashCode *results) 1123 const struct GNUNET_HashCode *results)
1134{ 1124{
1135 unsigned int needed; 1125 unsigned int needed;
1136 unsigned int had; 1126 unsigned int had;
@@ -1138,16 +1128,16 @@ GNUNET_DHT_get_filter_known_results (struct GNUNET_DHT_GetHandle *get_handle,
1138 had = get_handle->seen_results_end; 1128 had = get_handle->seen_results_end;
1139 needed = had + num_results; 1129 needed = had + num_results;
1140 if (needed > get_handle->seen_results_size) 1130 if (needed > get_handle->seen_results_size)
1141 GNUNET_array_grow (get_handle->seen_results, 1131 GNUNET_array_grow(get_handle->seen_results,
1142 get_handle->seen_results_size, 1132 get_handle->seen_results_size,
1143 needed); 1133 needed);
1144 GNUNET_memcpy (&get_handle->seen_results[get_handle->seen_results_end], 1134 GNUNET_memcpy(&get_handle->seen_results[get_handle->seen_results_end],
1145 results, 1135 results,
1146 num_results * sizeof (struct GNUNET_HashCode)); 1136 num_results * sizeof(struct GNUNET_HashCode));
1147 get_handle->seen_results_end += num_results; 1137 get_handle->seen_results_end += num_results;
1148 if (NULL != get_handle->dht_handle->mq) 1138 if (NULL != get_handle->dht_handle->mq)
1149 send_get_known_results (get_handle, 1139 send_get_known_results(get_handle,
1150 had); 1140 had);
1151} 1141}
1152 1142
1153 1143
@@ -1157,35 +1147,35 @@ GNUNET_DHT_get_filter_known_results (struct GNUNET_DHT_GetHandle *get_handle,
1157 * @param get_handle handle to the GET operation to stop 1147 * @param get_handle handle to the GET operation to stop
1158 */ 1148 */
1159void 1149void
1160GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle) 1150GNUNET_DHT_get_stop(struct GNUNET_DHT_GetHandle *get_handle)
1161{ 1151{
1162 struct GNUNET_DHT_Handle *handle = get_handle->dht_handle; 1152 struct GNUNET_DHT_Handle *handle = get_handle->dht_handle;
1163 1153
1164 LOG (GNUNET_ERROR_TYPE_DEBUG, 1154 LOG(GNUNET_ERROR_TYPE_DEBUG,
1165 "Sending STOP for %s to DHT via %p\n", 1155 "Sending STOP for %s to DHT via %p\n",
1166 GNUNET_h2s (&get_handle->key), 1156 GNUNET_h2s(&get_handle->key),
1167 handle); 1157 handle);
1168 if (NULL != handle->mq) 1158 if (NULL != handle->mq)
1169 { 1159 {
1170 struct GNUNET_MQ_Envelope *env; 1160 struct GNUNET_MQ_Envelope *env;
1171 struct GNUNET_DHT_ClientGetStopMessage *stop_msg; 1161 struct GNUNET_DHT_ClientGetStopMessage *stop_msg;
1172 1162
1173 env = GNUNET_MQ_msg (stop_msg, 1163 env = GNUNET_MQ_msg(stop_msg,
1174 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP); 1164 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP);
1175 stop_msg->reserved = htonl (0); 1165 stop_msg->reserved = htonl(0);
1176 stop_msg->unique_id = get_handle->unique_id; 1166 stop_msg->unique_id = get_handle->unique_id;
1177 stop_msg->key = get_handle->key; 1167 stop_msg->key = get_handle->key;
1178 GNUNET_MQ_send (handle->mq, 1168 GNUNET_MQ_send(handle->mq,
1179 env); 1169 env);
1180 } 1170 }
1181 GNUNET_assert (GNUNET_YES == 1171 GNUNET_assert(GNUNET_YES ==
1182 GNUNET_CONTAINER_multihashmap_remove (handle->active_requests, 1172 GNUNET_CONTAINER_multihashmap_remove(handle->active_requests,
1183 &get_handle->key, 1173 &get_handle->key,
1184 get_handle)); 1174 get_handle));
1185 GNUNET_array_grow (get_handle->seen_results, 1175 GNUNET_array_grow(get_handle->seen_results,
1186 get_handle->seen_results_end, 1176 get_handle->seen_results_end,
1187 0); 1177 0);
1188 GNUNET_free (get_handle); 1178 GNUNET_free(get_handle);
1189} 1179}
1190 1180
1191 1181
@@ -1202,17 +1192,17 @@ GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle)
1202 * @return Handle to stop monitoring. 1192 * @return Handle to stop monitoring.
1203 */ 1193 */
1204struct GNUNET_DHT_MonitorHandle * 1194struct GNUNET_DHT_MonitorHandle *
1205GNUNET_DHT_monitor_start (struct GNUNET_DHT_Handle *handle, 1195GNUNET_DHT_monitor_start(struct GNUNET_DHT_Handle *handle,
1206 enum GNUNET_BLOCK_Type type, 1196 enum GNUNET_BLOCK_Type type,
1207 const struct GNUNET_HashCode *key, 1197 const struct GNUNET_HashCode *key,
1208 GNUNET_DHT_MonitorGetCB get_cb, 1198 GNUNET_DHT_MonitorGetCB get_cb,
1209 GNUNET_DHT_MonitorGetRespCB get_resp_cb, 1199 GNUNET_DHT_MonitorGetRespCB get_resp_cb,
1210 GNUNET_DHT_MonitorPutCB put_cb, 1200 GNUNET_DHT_MonitorPutCB put_cb,
1211 void *cb_cls) 1201 void *cb_cls)
1212{ 1202{
1213 struct GNUNET_DHT_MonitorHandle *mh; 1203 struct GNUNET_DHT_MonitorHandle *mh;
1214 1204
1215 mh = GNUNET_new (struct GNUNET_DHT_MonitorHandle); 1205 mh = GNUNET_new(struct GNUNET_DHT_MonitorHandle);
1216 mh->get_cb = get_cb; 1206 mh->get_cb = get_cb;
1217 mh->get_resp_cb = get_resp_cb; 1207 mh->get_resp_cb = get_resp_cb;
1218 mh->put_cb = put_cb; 1208 mh->put_cb = put_cb;
@@ -1220,15 +1210,15 @@ GNUNET_DHT_monitor_start (struct GNUNET_DHT_Handle *handle,
1220 mh->type = type; 1210 mh->type = type;
1221 mh->dht_handle = handle; 1211 mh->dht_handle = handle;
1222 if (NULL != key) 1212 if (NULL != key)
1223 { 1213 {
1224 mh->key = GNUNET_new (struct GNUNET_HashCode); 1214 mh->key = GNUNET_new(struct GNUNET_HashCode);
1225 *mh->key = *key; 1215 *mh->key = *key;
1226 } 1216 }
1227 GNUNET_CONTAINER_DLL_insert (handle->monitor_head, 1217 GNUNET_CONTAINER_DLL_insert(handle->monitor_head,
1228 handle->monitor_tail, 1218 handle->monitor_tail,
1229 mh); 1219 mh);
1230 if (NULL != handle->mq) 1220 if (NULL != handle->mq)
1231 send_monitor_start (mh); 1221 send_monitor_start(mh);
1232 return mh; 1222 return mh;
1233} 1223}
1234 1224
@@ -1241,30 +1231,30 @@ GNUNET_DHT_monitor_start (struct GNUNET_DHT_Handle *handle,
1241 * On return get_handle will no longer be valid, caller must not use again!!! 1231 * On return get_handle will no longer be valid, caller must not use again!!!
1242 */ 1232 */
1243void 1233void
1244GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *mh) 1234GNUNET_DHT_monitor_stop(struct GNUNET_DHT_MonitorHandle *mh)
1245{ 1235{
1246 struct GNUNET_DHT_Handle *handle = mh->dht_handle; 1236 struct GNUNET_DHT_Handle *handle = mh->dht_handle;
1247 struct GNUNET_DHT_MonitorStartStopMessage *m; 1237 struct GNUNET_DHT_MonitorStartStopMessage *m;
1248 struct GNUNET_MQ_Envelope *env; 1238 struct GNUNET_MQ_Envelope *env;
1249 1239
1250 GNUNET_CONTAINER_DLL_remove (handle->monitor_head, 1240 GNUNET_CONTAINER_DLL_remove(handle->monitor_head,
1251 handle->monitor_tail, 1241 handle->monitor_tail,
1252 mh); 1242 mh);
1253 env = GNUNET_MQ_msg (m, 1243 env = GNUNET_MQ_msg(m,
1254 GNUNET_MESSAGE_TYPE_DHT_MONITOR_STOP); 1244 GNUNET_MESSAGE_TYPE_DHT_MONITOR_STOP);
1255 m->type = htonl (mh->type); 1245 m->type = htonl(mh->type);
1256 m->get = htons (NULL != mh->get_cb); 1246 m->get = htons(NULL != mh->get_cb);
1257 m->get_resp = htons(NULL != mh->get_resp_cb); 1247 m->get_resp = htons(NULL != mh->get_resp_cb);
1258 m->put = htons (NULL != mh->put_cb); 1248 m->put = htons(NULL != mh->put_cb);
1259 if (NULL != mh->key) 1249 if (NULL != mh->key)
1260 { 1250 {
1261 m->filter_key = htons (1); 1251 m->filter_key = htons(1);
1262 m->key = *mh->key; 1252 m->key = *mh->key;
1263 } 1253 }
1264 GNUNET_MQ_send (handle->mq, 1254 GNUNET_MQ_send(handle->mq,
1265 env); 1255 env);
1266 GNUNET_free_non_null (mh->key); 1256 GNUNET_free_non_null(mh->key);
1267 GNUNET_free (mh); 1257 GNUNET_free(mh);
1268} 1258}
1269 1259
1270 1260
diff --git a/src/dht/dht_test_lib.c b/src/dht/dht_test_lib.c
index b4afa3516..8ce3e98ea 100644
--- a/src/dht/dht_test_lib.c
+++ b/src/dht/dht_test_lib.c
@@ -11,12 +11,12 @@
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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file dht/dht_test_lib.c 21 * @file dht/dht_test_lib.c
22 * @author Christian Grothoff 22 * @author Christian Grothoff
@@ -28,8 +28,7 @@
28/** 28/**
29 * Test context for a DHT Test. 29 * Test context for a DHT Test.
30 */ 30 */
31struct GNUNET_DHT_TEST_Context 31struct GNUNET_DHT_TEST_Context {
32{
33 /** 32 /**
34 * Array of running peers. 33 * Array of running peers.
35 */ 34 */
@@ -59,7 +58,6 @@ struct GNUNET_DHT_TEST_Context
59 * Number of peers running, size of the arrays above. 58 * Number of peers running, size of the arrays above.
60 */ 59 */
61 unsigned int num_peers; 60 unsigned int num_peers;
62
63}; 61};
64 62
65 63
@@ -74,10 +72,10 @@ struct GNUNET_DHT_TEST_Context
74 * @return service handle to return in 'op_result', NULL on error 72 * @return service handle to return in 'op_result', NULL on error
75 */ 73 */
76static void * 74static void *
77dht_connect_adapter (void *cls, 75dht_connect_adapter(void *cls,
78 const struct GNUNET_CONFIGURATION_Handle *cfg) 76 const struct GNUNET_CONFIGURATION_Handle *cfg)
79{ 77{
80 return GNUNET_DHT_connect (cfg, 16); 78 return GNUNET_DHT_connect(cfg, 16);
81} 79}
82 80
83 81
@@ -89,12 +87,12 @@ dht_connect_adapter (void *cls,
89 * @param op_result service handle returned from the connect adapter 87 * @param op_result service handle returned from the connect adapter
90 */ 88 */
91static void 89static void
92dht_disconnect_adapter (void *cls, 90dht_disconnect_adapter(void *cls,
93 void *op_result) 91 void *op_result)
94{ 92{
95 struct GNUNET_DHT_Handle *dht = op_result; 93 struct GNUNET_DHT_Handle *dht = op_result;
96 94
97 GNUNET_DHT_disconnect (dht); 95 GNUNET_DHT_disconnect(dht);
98} 96}
99 97
100 98
@@ -108,33 +106,34 @@ dht_disconnect_adapter (void *cls,
108 * operation has executed successfully. 106 * operation has executed successfully.
109 */ 107 */
110static void 108static void
111dht_connect_cb (void *cls, 109dht_connect_cb(void *cls,
112 struct GNUNET_TESTBED_Operation *op, 110 struct GNUNET_TESTBED_Operation *op,
113 void *ca_result, 111 void *ca_result,
114 const char *emsg) 112 const char *emsg)
115{ 113{
116 struct GNUNET_DHT_TEST_Context *ctx = cls; 114 struct GNUNET_DHT_TEST_Context *ctx = cls;
117 115
118 if (NULL != emsg) 116 if (NULL != emsg)
119 { 117 {
120 fprintf (stderr, 118 fprintf(stderr,
121 "Failed to connect to DHT service: %s\n", 119 "Failed to connect to DHT service: %s\n",
122 emsg); 120 emsg);
123 GNUNET_SCHEDULER_shutdown (); 121 GNUNET_SCHEDULER_shutdown();
124 return; 122 return;
125 } 123 }
126 for (unsigned int i=0;i<ctx->num_peers;i++) 124 for (unsigned int i = 0; i < ctx->num_peers; i++)
127 if (op == ctx->ops[i]) 125 if (op == ctx->ops[i])
128 ctx->dhts[i] = ca_result; 126 ctx->dhts[i] = ca_result;
129 for (unsigned int i=0;i<ctx->num_peers;i++) 127 for (unsigned int i = 0; i < ctx->num_peers; i++)
130 if (NULL == ctx->dhts[i]) 128 if (NULL == ctx->dhts[i])
131 return; /* still some DHT connections missing */ 129 return;
130 /* still some DHT connections missing */
132 /* all DHT connections ready! */ 131 /* all DHT connections ready! */
133 ctx->app_main (ctx->app_main_cls, 132 ctx->app_main(ctx->app_main_cls,
134 ctx, 133 ctx,
135 ctx->num_peers, 134 ctx->num_peers,
136 ctx->peers, 135 ctx->peers,
137 ctx->dhts); 136 ctx->dhts);
138} 137}
139 138
140 139
@@ -144,38 +143,38 @@ dht_connect_cb (void *cls,
144 * @param ctx handle for the testbed 143 * @param ctx handle for the testbed
145 */ 144 */
146void 145void
147GNUNET_DHT_TEST_cleanup (struct GNUNET_DHT_TEST_Context *ctx) 146GNUNET_DHT_TEST_cleanup(struct GNUNET_DHT_TEST_Context *ctx)
148{ 147{
149 for (unsigned int i=0;i<ctx->num_peers;i++) 148 for (unsigned int i = 0; i < ctx->num_peers; i++)
150 GNUNET_TESTBED_operation_done (ctx->ops[i]); 149 GNUNET_TESTBED_operation_done(ctx->ops[i]);
151 GNUNET_free (ctx->ops); 150 GNUNET_free(ctx->ops);
152 GNUNET_free (ctx->dhts); 151 GNUNET_free(ctx->dhts);
153 GNUNET_free (ctx); 152 GNUNET_free(ctx);
154 GNUNET_SCHEDULER_shutdown (); 153 GNUNET_SCHEDULER_shutdown();
155} 154}
156 155
157 156
158static void 157static void
159dht_test_run (void *cls, 158dht_test_run(void *cls,
160 struct GNUNET_TESTBED_RunHandle *h, 159 struct GNUNET_TESTBED_RunHandle *h,
161 unsigned int num_peers, 160 unsigned int num_peers,
162 struct GNUNET_TESTBED_Peer **peers, 161 struct GNUNET_TESTBED_Peer **peers,
163 unsigned int links_succeeded, 162 unsigned int links_succeeded,
164 unsigned int links_failed) 163 unsigned int links_failed)
165{ 164{
166 struct GNUNET_DHT_TEST_Context *ctx = cls; 165 struct GNUNET_DHT_TEST_Context *ctx = cls;
167 166
168 GNUNET_assert (num_peers == ctx->num_peers); 167 GNUNET_assert(num_peers == ctx->num_peers);
169 ctx->peers = peers; 168 ctx->peers = peers;
170 for (unsigned int i=0;i<num_peers;i++) 169 for (unsigned int i = 0; i < num_peers; i++)
171 ctx->ops[i] = GNUNET_TESTBED_service_connect (ctx, 170 ctx->ops[i] = GNUNET_TESTBED_service_connect(ctx,
172 peers[i], 171 peers[i],
173 "dht", 172 "dht",
174 &dht_connect_cb, 173 &dht_connect_cb,
175 ctx, 174 ctx,
176 &dht_connect_adapter, 175 &dht_connect_adapter,
177 &dht_disconnect_adapter, 176 &dht_disconnect_adapter,
178 ctx); 177 ctx);
179} 178}
180 179
181 180
@@ -190,27 +189,27 @@ dht_test_run (void *cls,
190 * @param tmain_cls closure for 'tmain' 189 * @param tmain_cls closure for 'tmain'
191 */ 190 */
192void 191void
193GNUNET_DHT_TEST_run (const char *testname, 192GNUNET_DHT_TEST_run(const char *testname,
194 const char *cfgname, 193 const char *cfgname,
195 unsigned int num_peers, 194 unsigned int num_peers,
196 GNUNET_DHT_TEST_AppMain tmain, 195 GNUNET_DHT_TEST_AppMain tmain,
197 void *tmain_cls) 196 void *tmain_cls)
198{ 197{
199 struct GNUNET_DHT_TEST_Context *ctx; 198 struct GNUNET_DHT_TEST_Context *ctx;
200 199
201 ctx = GNUNET_new (struct GNUNET_DHT_TEST_Context); 200 ctx = GNUNET_new(struct GNUNET_DHT_TEST_Context);
202 ctx->num_peers = num_peers; 201 ctx->num_peers = num_peers;
203 ctx->ops = GNUNET_new_array (num_peers, 202 ctx->ops = GNUNET_new_array(num_peers,
204 struct GNUNET_TESTBED_Operation *); 203 struct GNUNET_TESTBED_Operation *);
205 ctx->dhts = GNUNET_new_array (num_peers, 204 ctx->dhts = GNUNET_new_array(num_peers,
206 struct GNUNET_DHT_Handle *); 205 struct GNUNET_DHT_Handle *);
207 ctx->app_main = tmain; 206 ctx->app_main = tmain;
208 ctx->app_main_cls = tmain_cls; 207 ctx->app_main_cls = tmain_cls;
209 (void) GNUNET_TESTBED_test_run (testname, 208 (void)GNUNET_TESTBED_test_run(testname,
210 cfgname, 209 cfgname,
211 num_peers, 210 num_peers,
212 0LL, NULL, NULL, 211 0LL, NULL, NULL,
213 &dht_test_run, ctx); 212 &dht_test_run, ctx);
214} 213}
215 214
216/* end of dht_test_lib.c */ 215/* end of dht_test_lib.c */
diff --git a/src/dht/dht_test_lib.h b/src/dht/dht_test_lib.h
index c60cc7d1e..716daaacf 100644
--- a/src/dht/dht_test_lib.h
+++ b/src/dht/dht_test_lib.h
@@ -11,12 +11,12 @@
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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file dht/dht_test_lib.h 21 * @file dht/dht_test_lib.h
22 * @author Christian Grothoff 22 * @author Christian Grothoff
@@ -52,10 +52,10 @@ struct GNUNET_DHT_TEST_Context;
52 * @param dhts handle to each of the DHTs of the peers 52 * @param dhts handle to each of the DHTs of the peers
53 */ 53 */
54typedef void (*GNUNET_DHT_TEST_AppMain) (void *cls, 54typedef void (*GNUNET_DHT_TEST_AppMain) (void *cls,
55 struct GNUNET_DHT_TEST_Context *ctx, 55 struct GNUNET_DHT_TEST_Context *ctx,
56 unsigned int num_peers, 56 unsigned int num_peers,
57 struct GNUNET_TESTBED_Peer **peers, 57 struct GNUNET_TESTBED_Peer **peers,
58 struct GNUNET_DHT_Handle **dhts); 58 struct GNUNET_DHT_Handle **dhts);
59 59
60 60
61/** 61/**
@@ -69,11 +69,11 @@ typedef void (*GNUNET_DHT_TEST_AppMain) (void *cls,
69 * @param tmain_cls closure for 'tmain' 69 * @param tmain_cls closure for 'tmain'
70 */ 70 */
71void 71void
72GNUNET_DHT_TEST_run (const char *testname, 72GNUNET_DHT_TEST_run(const char *testname,
73 const char *cfgname, 73 const char *cfgname,
74 unsigned int num_peers, 74 unsigned int num_peers,
75 GNUNET_DHT_TEST_AppMain tmain, 75 GNUNET_DHT_TEST_AppMain tmain,
76 void *tmain_cls); 76 void *tmain_cls);
77 77
78 78
79/** 79/**
@@ -82,7 +82,7 @@ GNUNET_DHT_TEST_run (const char *testname,
82 * @param ctx handle for the testbed 82 * @param ctx handle for the testbed
83 */ 83 */
84void 84void
85GNUNET_DHT_TEST_cleanup (struct GNUNET_DHT_TEST_Context *ctx); 85GNUNET_DHT_TEST_cleanup(struct GNUNET_DHT_TEST_Context *ctx);
86 86
87#if 0 /* keep Emacsens' auto-indent happy */ 87#if 0 /* keep Emacsens' auto-indent happy */
88{ 88{
diff --git a/src/dht/gnunet-dht-get.c b/src/dht/gnunet-dht-get.c
index af667584b..901641660 100644
--- a/src/dht/gnunet-dht-get.c
+++ b/src/dht/gnunet-dht-get.c
@@ -11,12 +11,12 @@
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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file dht/gnunet-dht-get.c 21 * @file dht/gnunet-dht-get.c
22 * @brief search for data in DHT 22 * @brief search for data in DHT
@@ -26,7 +26,7 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_dht_service.h" 27#include "gnunet_dht_service.h"
28 28
29#define LOG(kind, ...) GNUNET_log_from (kind, "dht-clients", __VA_ARGS__) 29#define LOG(kind, ...) GNUNET_log_from(kind, "dht-clients", __VA_ARGS__)
30/** 30/**
31 * The type of the query 31 * The type of the query
32 */ 32 */
@@ -45,7 +45,7 @@ static char *query_key;
45/** 45/**
46 * User supplied timeout value 46 * User supplied timeout value
47 */ 47 */
48static struct GNUNET_TIME_Relative timeout_request = {60000}; 48static struct GNUNET_TIME_Relative timeout_request = { 60000 };
49 49
50/** 50/**
51 * Be verbose 51 * Be verbose
@@ -94,23 +94,23 @@ static struct GNUNET_SCHEDULER_Task *tt;
94 * @param cls unused 94 * @param cls unused
95 */ 95 */
96static void 96static void
97cleanup_task (void *cls) 97cleanup_task(void *cls)
98{ 98{
99 if (NULL != get_handle) 99 if (NULL != get_handle)
100 { 100 {
101 GNUNET_DHT_get_stop (get_handle); 101 GNUNET_DHT_get_stop(get_handle);
102 get_handle = NULL; 102 get_handle = NULL;
103 } 103 }
104 if (NULL != dht_handle) 104 if (NULL != dht_handle)
105 { 105 {
106 GNUNET_DHT_disconnect (dht_handle); 106 GNUNET_DHT_disconnect(dht_handle);
107 dht_handle = NULL; 107 dht_handle = NULL;
108 } 108 }
109 if (NULL != tt) 109 if (NULL != tt)
110 { 110 {
111 GNUNET_SCHEDULER_cancel (tt); 111 GNUNET_SCHEDULER_cancel(tt);
112 tt = NULL; 112 tt = NULL;
113 } 113 }
114} 114}
115 115
116 116
@@ -120,10 +120,10 @@ cleanup_task (void *cls)
120 * @param cls unused 120 * @param cls unused
121 */ 121 */
122static void 122static void
123timeout_task (void *cls) 123timeout_task(void *cls)
124{ 124{
125 tt = NULL; 125 tt = NULL;
126 GNUNET_SCHEDULER_shutdown (); 126 GNUNET_SCHEDULER_shutdown();
127} 127}
128 128
129 129
@@ -143,34 +143,34 @@ timeout_task (void *cls)
143 * @param data pointer to the result data 143 * @param data pointer to the result data
144 */ 144 */
145static void 145static void
146get_result_iterator (void *cls, 146get_result_iterator(void *cls,
147 struct GNUNET_TIME_Absolute exp, 147 struct GNUNET_TIME_Absolute exp,
148 const struct GNUNET_HashCode *key, 148 const struct GNUNET_HashCode *key,
149 const struct GNUNET_PeerIdentity *get_path, 149 const struct GNUNET_PeerIdentity *get_path,
150 unsigned int get_path_length, 150 unsigned int get_path_length,
151 const struct GNUNET_PeerIdentity *put_path, 151 const struct GNUNET_PeerIdentity *put_path,
152 unsigned int put_path_length, 152 unsigned int put_path_length,
153 enum GNUNET_BLOCK_Type type, 153 enum GNUNET_BLOCK_Type type,
154 size_t size, 154 size_t size,
155 const void *data) 155 const void *data)
156{ 156{
157 fprintf (stdout, 157 fprintf(stdout,
158 (GNUNET_BLOCK_TYPE_TEST == type) ? _ ("Result %d, type %d:\n%.*s\n") 158 (GNUNET_BLOCK_TYPE_TEST == type) ? _("Result %d, type %d:\n%.*s\n")
159 : _ ("Result %d, type %d:\n"), 159 : _("Result %d, type %d:\n"),
160 result_count, 160 result_count,
161 type, 161 type,
162 (unsigned int) size, 162 (unsigned int)size,
163 (char *) data); 163 (char *)data);
164 if (verbose) 164 if (verbose)
165 { 165 {
166 fprintf (stdout, " GET path: "); 166 fprintf(stdout, " GET path: ");
167 for (unsigned int i = 0; i < get_path_length; i++) 167 for (unsigned int i = 0; i < get_path_length; i++)
168 fprintf (stdout, "%s%s", (0 == i) ? "" : "-", GNUNET_i2s (&get_path[i])); 168 fprintf(stdout, "%s%s", (0 == i) ? "" : "-", GNUNET_i2s(&get_path[i]));
169 fprintf (stdout, "\n PUT path: "); 169 fprintf(stdout, "\n PUT path: ");
170 for (unsigned int i = 0; i < put_path_length; i++) 170 for (unsigned int i = 0; i < put_path_length; i++)
171 fprintf (stdout, "%s%s", (0 == i) ? "" : "-", GNUNET_i2s (&put_path[i])); 171 fprintf(stdout, "%s%s", (0 == i) ? "" : "-", GNUNET_i2s(&put_path[i]));
172 fprintf (stdout, "\n"); 172 fprintf(stdout, "\n");
173 } 173 }
174 result_count++; 174 result_count++;
175} 175}
176 176
@@ -184,47 +184,47 @@ get_result_iterator (void *cls,
184 * @param c configuration 184 * @param c configuration
185 */ 185 */
186static void 186static void
187run (void *cls, 187run(void *cls,
188 char *const *args, 188 char *const *args,
189 const char *cfgfile, 189 const char *cfgfile,
190 const struct GNUNET_CONFIGURATION_Handle *c) 190 const struct GNUNET_CONFIGURATION_Handle *c)
191{ 191{
192 struct GNUNET_HashCode key; 192 struct GNUNET_HashCode key;
193 193
194 cfg = c; 194 cfg = c;
195 if (NULL == query_key) 195 if (NULL == query_key)
196 { 196 {
197 fprintf (stderr, "%s", _ ("Must provide key for DHT GET!\n")); 197 fprintf(stderr, "%s", _("Must provide key for DHT GET!\n"));
198 ret = 1; 198 ret = 1;
199 return; 199 return;
200 } 200 }
201 if (NULL == (dht_handle = GNUNET_DHT_connect (cfg, 1))) 201 if (NULL == (dht_handle = GNUNET_DHT_connect(cfg, 1)))
202 { 202 {
203 fprintf (stderr, "%s", _ ("Failed to connect to DHT service!\n")); 203 fprintf(stderr, "%s", _("Failed to connect to DHT service!\n"));
204 ret = 1; 204 ret = 1;
205 return; 205 return;
206 } 206 }
207 if (query_type == GNUNET_BLOCK_TYPE_ANY) /* Type of data not set */ 207 if (query_type == GNUNET_BLOCK_TYPE_ANY) /* Type of data not set */
208 query_type = GNUNET_BLOCK_TYPE_TEST; 208 query_type = GNUNET_BLOCK_TYPE_TEST;
209 GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key); 209 GNUNET_CRYPTO_hash(query_key, strlen(query_key), &key);
210 if (verbose) 210 if (verbose)
211 fprintf (stderr, 211 fprintf(stderr,
212 "%s `%s' \n", 212 "%s `%s' \n",
213 _ ("Issuing DHT GET with key"), 213 _("Issuing DHT GET with key"),
214 GNUNET_h2s_full (&key)); 214 GNUNET_h2s_full(&key));
215 GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL); 215 GNUNET_SCHEDULER_add_shutdown(&cleanup_task, NULL);
216 tt = GNUNET_SCHEDULER_add_delayed (timeout_request, &timeout_task, NULL); 216 tt = GNUNET_SCHEDULER_add_delayed(timeout_request, &timeout_task, NULL);
217 get_handle = GNUNET_DHT_get_start (dht_handle, 217 get_handle = GNUNET_DHT_get_start(dht_handle,
218 query_type, 218 query_type,
219 &key, 219 &key,
220 replication, 220 replication,
221 (demultixplex_everywhere) 221 (demultixplex_everywhere)
222 ? GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE 222 ? GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE
223 : GNUNET_DHT_RO_NONE, 223 : GNUNET_DHT_RO_NONE,
224 NULL, 224 NULL,
225 0, 225 0,
226 &get_result_iterator, 226 &get_result_iterator,
227 NULL); 227 NULL);
228} 228}
229 229
230 230
@@ -236,54 +236,54 @@ run (void *cls,
236 * @return 0 ok, 1 on error 236 * @return 0 ok, 1 on error
237 */ 237 */
238int 238int
239main (int argc, char *const *argv) 239main(int argc, char *const *argv)
240{ 240{
241 struct GNUNET_GETOPT_CommandLineOption options[] = 241 struct GNUNET_GETOPT_CommandLineOption options[] =
242 {GNUNET_GETOPT_option_string ('k', 242 { GNUNET_GETOPT_option_string('k',
243 "key", 243 "key",
244 "KEY", 244 "KEY",
245 gettext_noop ("the query key"), 245 gettext_noop("the query key"),
246 &query_key), 246 &query_key),
247 GNUNET_GETOPT_option_uint ( 247 GNUNET_GETOPT_option_uint(
248 'r', 248 'r',
249 "replication", 249 "replication",
250 "LEVEL", 250 "LEVEL",
251 gettext_noop ("how many parallel requests (replicas) to create"), 251 gettext_noop("how many parallel requests (replicas) to create"),
252 &replication), 252 &replication),
253 GNUNET_GETOPT_option_uint ('t', 253 GNUNET_GETOPT_option_uint('t',
254 "type", 254 "type",
255 "TYPE", 255 "TYPE",
256 gettext_noop ("the type of data to look for"), 256 gettext_noop("the type of data to look for"),
257 &query_type), 257 &query_type),
258 GNUNET_GETOPT_option_relative_time ( 258 GNUNET_GETOPT_option_relative_time(
259 'T', 259 'T',
260 "timeout", 260 "timeout",
261 "TIMEOUT", 261 "TIMEOUT",
262 gettext_noop ("how long to execute this query before giving up?"), 262 gettext_noop("how long to execute this query before giving up?"),
263 &timeout_request), 263 &timeout_request),
264 GNUNET_GETOPT_option_flag ('x', 264 GNUNET_GETOPT_option_flag('x',
265 "demultiplex", 265 "demultiplex",
266 gettext_noop ( 266 gettext_noop(
267 "use DHT's demultiplex everywhere option"), 267 "use DHT's demultiplex everywhere option"),
268 &demultixplex_everywhere), 268 &demultixplex_everywhere),
269 GNUNET_GETOPT_option_verbose (&verbose), 269 GNUNET_GETOPT_option_verbose(&verbose),
270 GNUNET_GETOPT_OPTION_END}; 270 GNUNET_GETOPT_OPTION_END };
271 271
272 272
273 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 273 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
274 return 2; 274 return 2;
275 return (GNUNET_OK == 275 return (GNUNET_OK ==
276 GNUNET_PROGRAM_run ( 276 GNUNET_PROGRAM_run(
277 argc, 277 argc,
278 argv, 278 argv,
279 "gnunet-dht-get", 279 "gnunet-dht-get",
280 gettext_noop ( 280 gettext_noop(
281 "Issue a GET request to the GNUnet DHT, prints results."), 281 "Issue a GET request to the GNUnet DHT, prints results."),
282 options, 282 options,
283 &run, 283 &run,
284 NULL)) 284 NULL))
285 ? ret 285 ? ret
286 : 1; 286 : 1;
287} 287}
288 288
289/* end of gnunet-dht-get.c */ 289/* end of gnunet-dht-get.c */
diff --git a/src/dht/gnunet-dht-monitor.c b/src/dht/gnunet-dht-monitor.c
index 3787b7cfa..26989467c 100644
--- a/src/dht/gnunet-dht-monitor.c
+++ b/src/dht/gnunet-dht-monitor.c
@@ -11,12 +11,12 @@
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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file dht/gnunet-dht-monitor.c 21 * @file dht/gnunet-dht-monitor.c
22 * @brief search for data in DHT 22 * @brief search for data in DHT
@@ -39,7 +39,7 @@ static char *query_key;
39/** 39/**
40 * User supplied timeout value (in seconds) 40 * User supplied timeout value (in seconds)
41 */ 41 */
42static struct GNUNET_TIME_Relative timeout_request = {60000}; 42static struct GNUNET_TIME_Relative timeout_request = { 60000 };
43 43
44/** 44/**
45 * Be verbose 45 * Be verbose
@@ -47,7 +47,7 @@ static struct GNUNET_TIME_Relative timeout_request = {60000};
47static int verbose; 47static int verbose;
48 48
49/** 49/**
50* Handle to the DHT 50 * Handle to the DHT
51 */ 51 */
52static struct GNUNET_DHT_Handle *dht_handle; 52static struct GNUNET_DHT_Handle *dht_handle;
53 53
@@ -83,25 +83,25 @@ static struct GNUNET_SCHEDULER_Task *tt;
83 * @param cls closure (unused) 83 * @param cls closure (unused)
84 */ 84 */
85static void 85static void
86cleanup_task (void *cls) 86cleanup_task(void *cls)
87{ 87{
88 if (verbose) 88 if (verbose)
89 fprintf (stderr, "%s", "Cleaning up!\n"); 89 fprintf(stderr, "%s", "Cleaning up!\n");
90 if (NULL != monitor_handle) 90 if (NULL != monitor_handle)
91 { 91 {
92 GNUNET_DHT_monitor_stop (monitor_handle); 92 GNUNET_DHT_monitor_stop(monitor_handle);
93 monitor_handle = NULL; 93 monitor_handle = NULL;
94 } 94 }
95 if (NULL != dht_handle) 95 if (NULL != dht_handle)
96 { 96 {
97 GNUNET_DHT_disconnect (dht_handle); 97 GNUNET_DHT_disconnect(dht_handle);
98 dht_handle = NULL; 98 dht_handle = NULL;
99 } 99 }
100 if (NULL != tt) 100 if (NULL != tt)
101 { 101 {
102 GNUNET_SCHEDULER_cancel (tt); 102 GNUNET_SCHEDULER_cancel(tt);
103 tt = NULL; 103 tt = NULL;
104 } 104 }
105} 105}
106 106
107 107
@@ -111,10 +111,10 @@ cleanup_task (void *cls)
111 * @param cls closure (unused) 111 * @param cls closure (unused)
112 */ 112 */
113static void 113static void
114timeout_task (void *cls) 114timeout_task(void *cls)
115{ 115{
116 tt = NULL; 116 tt = NULL;
117 GNUNET_SCHEDULER_shutdown (); 117 GNUNET_SCHEDULER_shutdown();
118} 118}
119 119
120 120
@@ -131,20 +131,20 @@ timeout_task (void *cls)
131 * @param key Key of the requested data. 131 * @param key Key of the requested data.
132 */ 132 */
133static void 133static void
134get_callback (void *cls, 134get_callback(void *cls,
135 enum GNUNET_DHT_RouteOption options, 135 enum GNUNET_DHT_RouteOption options,
136 enum GNUNET_BLOCK_Type type, 136 enum GNUNET_BLOCK_Type type,
137 uint32_t hop_count, 137 uint32_t hop_count,
138 uint32_t desired_replication_level, 138 uint32_t desired_replication_level,
139 unsigned int path_length, 139 unsigned int path_length,
140 const struct GNUNET_PeerIdentity *path, 140 const struct GNUNET_PeerIdentity *path,
141 const struct GNUNET_HashCode *key) 141 const struct GNUNET_HashCode *key)
142{ 142{
143 fprintf (stdout, 143 fprintf(stdout,
144 "GET #%u: type %d, key `%s'\n", 144 "GET #%u: type %d, key `%s'\n",
145 result_count, 145 result_count,
146 (int) type, 146 (int)type,
147 GNUNET_h2s_full (key)); 147 GNUNET_h2s_full(key));
148 result_count++; 148 result_count++;
149} 149}
150 150
@@ -164,27 +164,27 @@ get_callback (void *cls,
164 * @param size Number of bytes in data. 164 * @param size Number of bytes in data.
165 */ 165 */
166static void 166static void
167get_resp_callback (void *cls, 167get_resp_callback(void *cls,
168 enum GNUNET_BLOCK_Type type, 168 enum GNUNET_BLOCK_Type type,
169 const struct GNUNET_PeerIdentity *get_path, 169 const struct GNUNET_PeerIdentity *get_path,
170 unsigned int get_path_length, 170 unsigned int get_path_length,
171 const struct GNUNET_PeerIdentity *put_path, 171 const struct GNUNET_PeerIdentity *put_path,
172 unsigned int put_path_length, 172 unsigned int put_path_length,
173 struct GNUNET_TIME_Absolute exp, 173 struct GNUNET_TIME_Absolute exp,
174 const struct GNUNET_HashCode *key, 174 const struct GNUNET_HashCode *key,
175 const void *data, 175 const void *data,
176 size_t size) 176 size_t size)
177{ 177{
178 fprintf (stdout, 178 fprintf(stdout,
179 (GNUNET_BLOCK_TYPE_TEST == type) 179 (GNUNET_BLOCK_TYPE_TEST == type)
180 ? "RESPONSE #%u (%s): type %d, key `%s', data `%.*s'\n" 180 ? "RESPONSE #%u (%s): type %d, key `%s', data `%.*s'\n"
181 : "RESPONSE #%u (%s): type %d, key `%s'\n", 181 : "RESPONSE #%u (%s): type %d, key `%s'\n",
182 result_count, 182 result_count,
183 GNUNET_STRINGS_absolute_time_to_string (exp), 183 GNUNET_STRINGS_absolute_time_to_string(exp),
184 (int) type, 184 (int)type,
185 GNUNET_h2s_full (key), 185 GNUNET_h2s_full(key),
186 (unsigned int) size, 186 (unsigned int)size,
187 (char *) data); 187 (char *)data);
188 result_count++; 188 result_count++;
189} 189}
190 190
@@ -205,28 +205,28 @@ get_resp_callback (void *cls,
205 * @param size Number of bytes in data. 205 * @param size Number of bytes in data.
206 */ 206 */
207static void 207static void
208put_callback (void *cls, 208put_callback(void *cls,
209 enum GNUNET_DHT_RouteOption options, 209 enum GNUNET_DHT_RouteOption options,
210 enum GNUNET_BLOCK_Type type, 210 enum GNUNET_BLOCK_Type type,
211 uint32_t hop_count, 211 uint32_t hop_count,
212 uint32_t desired_replication_level, 212 uint32_t desired_replication_level,
213 unsigned int path_length, 213 unsigned int path_length,
214 const struct GNUNET_PeerIdentity *path, 214 const struct GNUNET_PeerIdentity *path,
215 struct GNUNET_TIME_Absolute exp, 215 struct GNUNET_TIME_Absolute exp,
216 const struct GNUNET_HashCode *key, 216 const struct GNUNET_HashCode *key,
217 const void *data, 217 const void *data,
218 size_t size) 218 size_t size)
219{ 219{
220 fprintf (stdout, 220 fprintf(stdout,
221 (GNUNET_BLOCK_TYPE_TEST == type) 221 (GNUNET_BLOCK_TYPE_TEST == type)
222 ? "PUT %u (%s): type %d, key `%s', data `%.*s'\n" 222 ? "PUT %u (%s): type %d, key `%s', data `%.*s'\n"
223 : "PUT %u (%s): type %d, key `%s'\n", 223 : "PUT %u (%s): type %d, key `%s'\n",
224 result_count, 224 result_count,
225 GNUNET_STRINGS_absolute_time_to_string (exp), 225 GNUNET_STRINGS_absolute_time_to_string(exp),
226 (int) type, 226 (int)type,
227 GNUNET_h2s_full (key), 227 GNUNET_h2s_full(key),
228 (unsigned int) size, 228 (unsigned int)size,
229 (char *) data); 229 (char *)data);
230 result_count++; 230 result_count++;
231} 231}
232 232
@@ -240,48 +240,48 @@ put_callback (void *cls,
240 * @param c configuration 240 * @param c configuration
241 */ 241 */
242static void 242static void
243run (void *cls, 243run(void *cls,
244 char *const *args, 244 char *const *args,
245 const char *cfgfile, 245 const char *cfgfile,
246 const struct GNUNET_CONFIGURATION_Handle *c) 246 const struct GNUNET_CONFIGURATION_Handle *c)
247{ 247{
248 struct GNUNET_HashCode *key; 248 struct GNUNET_HashCode *key;
249 struct GNUNET_HashCode hc; 249 struct GNUNET_HashCode hc;
250 250
251 cfg = c; 251 cfg = c;
252 252
253 if (NULL == (dht_handle = GNUNET_DHT_connect (cfg, 1))) 253 if (NULL == (dht_handle = GNUNET_DHT_connect(cfg, 1)))
254 { 254 {
255 fprintf (stderr, "%s", _ ("Failed to connect to DHT service!\n")); 255 fprintf(stderr, "%s", _("Failed to connect to DHT service!\n"));
256 ret = 1; 256 ret = 1;
257 return; 257 return;
258 } 258 }
259 if (GNUNET_BLOCK_TYPE_ANY == block_type) /* Type of data not set */ 259 if (GNUNET_BLOCK_TYPE_ANY == block_type) /* Type of data not set */
260 block_type = GNUNET_BLOCK_TYPE_TEST; 260 block_type = GNUNET_BLOCK_TYPE_TEST;
261 if (NULL != query_key) 261 if (NULL != query_key)
262 { 262 {
263 key = &hc; 263 key = &hc;
264 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (query_key, key)) 264 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string(query_key, key))
265 GNUNET_CRYPTO_hash (query_key, strlen (query_key), key); 265 GNUNET_CRYPTO_hash(query_key, strlen(query_key), key);
266 } 266 }
267 else 267 else
268 { 268 {
269 key = NULL; 269 key = NULL;
270 } 270 }
271 if (verbose) 271 if (verbose)
272 fprintf (stderr, 272 fprintf(stderr,
273 "Monitoring for %s\n", 273 "Monitoring for %s\n",
274 GNUNET_STRINGS_relative_time_to_string (timeout_request, 274 GNUNET_STRINGS_relative_time_to_string(timeout_request,
275 GNUNET_NO)); 275 GNUNET_NO));
276 tt = GNUNET_SCHEDULER_add_delayed (timeout_request, &timeout_task, NULL); 276 tt = GNUNET_SCHEDULER_add_delayed(timeout_request, &timeout_task, NULL);
277 GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL); 277 GNUNET_SCHEDULER_add_shutdown(&cleanup_task, NULL);
278 monitor_handle = GNUNET_DHT_monitor_start (dht_handle, 278 monitor_handle = GNUNET_DHT_monitor_start(dht_handle,
279 block_type, 279 block_type,
280 key, 280 key,
281 &get_callback, 281 &get_callback,
282 &get_resp_callback, 282 &get_resp_callback,
283 &put_callback, 283 &put_callback,
284 NULL); 284 NULL);
285} 285}
286 286
287/** 287/**
@@ -292,52 +292,52 @@ run (void *cls,
292 * @return 0 ok, 1 on error 292 * @return 0 ok, 1 on error
293 */ 293 */
294int 294int
295main (int argc, char *const *argv) 295main(int argc, char *const *argv)
296{ 296{
297 struct GNUNET_GETOPT_CommandLineOption options[] = { 297 struct GNUNET_GETOPT_CommandLineOption options[] = {
298 298 GNUNET_GETOPT_option_string('k',
299 GNUNET_GETOPT_option_string ('k', 299 "key",
300 "key", 300 "KEY",
301 "KEY", 301 gettext_noop("the query key"),
302 gettext_noop ("the query key"), 302 &query_key),
303 &query_key), 303
304 304 GNUNET_GETOPT_option_uint('t',
305 GNUNET_GETOPT_option_uint ('t', 305 "type",
306 "type", 306 "TYPE",
307 "TYPE", 307 gettext_noop("the type of data to look for"),
308 gettext_noop ("the type of data to look for"), 308 &block_type),
309 &block_type), 309
310 310 GNUNET_GETOPT_option_relative_time(
311 GNUNET_GETOPT_option_relative_time (
312 'T', 311 'T',
313 "timeout", 312 "timeout",
314 "TIMEOUT", 313 "TIMEOUT",
315 gettext_noop ("how long should the monitor command run"), 314 gettext_noop("how long should the monitor command run"),
316 &timeout_request), 315 &timeout_request),
317 316
318 GNUNET_GETOPT_option_flag ('V', 317 GNUNET_GETOPT_option_flag('V',
319 "verbose", 318 "verbose",
320 gettext_noop ( 319 gettext_noop(
321 "be verbose (print progress information)"), 320 "be verbose (print progress information)"),
322 &verbose), 321 &verbose),
323 322
324 GNUNET_GETOPT_OPTION_END}; 323 GNUNET_GETOPT_OPTION_END
324 };
325 325
326 326
327 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 327 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
328 return 2; 328 return 2;
329 329
330 return (GNUNET_OK == 330 return (GNUNET_OK ==
331 GNUNET_PROGRAM_run (argc, 331 GNUNET_PROGRAM_run(argc,
332 argv, 332 argv,
333 "gnunet-dht-monitor", 333 "gnunet-dht-monitor",
334 gettext_noop ( 334 gettext_noop(
335 "Prints all packets that go through the DHT."), 335 "Prints all packets that go through the DHT."),
336 options, 336 options,
337 &run, 337 &run,
338 NULL)) 338 NULL))
339 ? ret 339 ? ret
340 : 1; 340 : 1;
341} 341}
342 342
343/* end of gnunet-dht-monitor.c */ 343/* end of gnunet-dht-monitor.c */
diff --git a/src/dht/gnunet-dht-put.c b/src/dht/gnunet-dht-put.c
index 0432dc4a0..330b2ac62 100644
--- a/src/dht/gnunet-dht-put.c
+++ b/src/dht/gnunet-dht-put.c
@@ -11,12 +11,12 @@
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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file dht/gnunet-dht-put.c 21 * @file dht/gnunet-dht-put.c
22 * @brief search for data in DHT 22 * @brief search for data in DHT
@@ -89,13 +89,13 @@ static char *data;
89 89
90 90
91static void 91static void
92shutdown_task (void *cls) 92shutdown_task(void *cls)
93{ 93{
94 if (NULL != dht_handle) 94 if (NULL != dht_handle)
95 { 95 {
96 GNUNET_DHT_disconnect (dht_handle); 96 GNUNET_DHT_disconnect(dht_handle);
97 dht_handle = NULL; 97 dht_handle = NULL;
98 } 98 }
99} 99}
100 100
101 101
@@ -105,9 +105,9 @@ shutdown_task (void *cls)
105 * @param cls closure 105 * @param cls closure
106 */ 106 */
107static void 107static void
108message_sent_cont (void *cls) 108message_sent_cont(void *cls)
109{ 109{
110 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 110 GNUNET_SCHEDULER_add_now(&shutdown_task, NULL);
111} 111}
112 112
113 113
@@ -120,52 +120,52 @@ message_sent_cont (void *cls)
120 * @param c configuration 120 * @param c configuration
121 */ 121 */
122static void 122static void
123run (void *cls, 123run(void *cls,
124 char *const *args, 124 char *const *args,
125 const char *cfgfile, 125 const char *cfgfile,
126 const struct GNUNET_CONFIGURATION_Handle *c) 126 const struct GNUNET_CONFIGURATION_Handle *c)
127{ 127{
128 enum GNUNET_DHT_RouteOption ro; 128 enum GNUNET_DHT_RouteOption ro;
129 129
130 cfg = c; 130 cfg = c;
131 if ((NULL == query_key) || (NULL == data)) 131 if ((NULL == query_key) || (NULL == data))
132 { 132 {
133 fprintf (stderr, "%s", _ ("Must provide KEY and DATA for DHT put!\n")); 133 fprintf(stderr, "%s", _("Must provide KEY and DATA for DHT put!\n"));
134 ret = 1; 134 ret = 1;
135 return; 135 return;
136 } 136 }
137 137
138 if (NULL == (dht_handle = GNUNET_DHT_connect (cfg, 1))) 138 if (NULL == (dht_handle = GNUNET_DHT_connect(cfg, 1)))
139 { 139 {
140 fprintf (stderr, _ ("Could not connect to DHT service!\n")); 140 fprintf(stderr, _("Could not connect to DHT service!\n"));
141 ret = 1; 141 ret = 1;
142 return; 142 return;
143 } 143 }
144 if (GNUNET_BLOCK_TYPE_ANY == query_type) /* Type of data not set */ 144 if (GNUNET_BLOCK_TYPE_ANY == query_type) /* Type of data not set */
145 query_type = GNUNET_BLOCK_TYPE_TEST; 145 query_type = GNUNET_BLOCK_TYPE_TEST;
146 146
147 GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key); 147 GNUNET_CRYPTO_hash(query_key, strlen(query_key), &key);
148 148
149 if (verbose) 149 if (verbose)
150 fprintf (stderr, 150 fprintf(stderr,
151 _ ("Issuing put request for `%s' with data `%s'!\n"), 151 _("Issuing put request for `%s' with data `%s'!\n"),
152 query_key, 152 query_key,
153 data); 153 data);
154 ro = GNUNET_DHT_RO_NONE; 154 ro = GNUNET_DHT_RO_NONE;
155 if (demultixplex_everywhere) 155 if (demultixplex_everywhere)
156 ro |= GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE; 156 ro |= GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE;
157 if (record_route) 157 if (record_route)
158 ro |= GNUNET_DHT_RO_RECORD_ROUTE; 158 ro |= GNUNET_DHT_RO_RECORD_ROUTE;
159 GNUNET_DHT_put (dht_handle, 159 GNUNET_DHT_put(dht_handle,
160 &key, 160 &key,
161 replication, 161 replication,
162 ro, 162 ro,
163 query_type, 163 query_type,
164 strlen (data), 164 strlen(data),
165 data, 165 data,
166 GNUNET_TIME_relative_to_absolute (expiration), 166 GNUNET_TIME_relative_to_absolute(expiration),
167 &message_sent_cont, 167 &message_sent_cont,
168 NULL); 168 NULL);
169} 169}
170 170
171/** 171/**
@@ -176,65 +176,64 @@ run (void *cls,
176 * @return 0 ok, 1 on error 176 * @return 0 ok, 1 on error
177 */ 177 */
178int 178int
179main (int argc, char *const *argv) 179main(int argc, char *const *argv)
180{ 180{
181
182 struct GNUNET_GETOPT_CommandLineOption options[] = 181 struct GNUNET_GETOPT_CommandLineOption options[] =
183 {GNUNET_GETOPT_option_string ('d', 182 { GNUNET_GETOPT_option_string('d',
184 "data", 183 "data",
185 "DATA", 184 "DATA",
186 gettext_noop ( 185 gettext_noop(
187 "the data to insert under the key"), 186 "the data to insert under the key"),
188 &data), 187 &data),
189 GNUNET_GETOPT_option_relative_time ( 188 GNUNET_GETOPT_option_relative_time(
190 'e', 189 'e',
191 "expiration", 190 "expiration",
192 "EXPIRATION", 191 "EXPIRATION",
193 gettext_noop ("how long to store this entry in the dht (in seconds)"), 192 gettext_noop("how long to store this entry in the dht (in seconds)"),
194 &expiration), 193 &expiration),
195 GNUNET_GETOPT_option_string ('k', 194 GNUNET_GETOPT_option_string('k',
196 "key", 195 "key",
197 "KEY", 196 "KEY",
198 gettext_noop ("the query key"), 197 gettext_noop("the query key"),
199 &query_key), 198 &query_key),
200 GNUNET_GETOPT_option_flag ('x', 199 GNUNET_GETOPT_option_flag('x',
201 "demultiplex", 200 "demultiplex",
202 gettext_noop ( 201 gettext_noop(
203 "use DHT's demultiplex everywhere option"), 202 "use DHT's demultiplex everywhere option"),
204 &demultixplex_everywhere), 203 &demultixplex_everywhere),
205 GNUNET_GETOPT_option_uint ('r', 204 GNUNET_GETOPT_option_uint('r',
206 "replication", 205 "replication",
207 "LEVEL", 206 "LEVEL",
208 gettext_noop ("how many replicas to create"), 207 gettext_noop("how many replicas to create"),
209 &replication), 208 &replication),
210 GNUNET_GETOPT_option_flag ('R', 209 GNUNET_GETOPT_option_flag('R',
211 "record", 210 "record",
212 gettext_noop ("use DHT's record route option"), 211 gettext_noop("use DHT's record route option"),
213 &record_route), 212 &record_route),
214 GNUNET_GETOPT_option_uint ('t', 213 GNUNET_GETOPT_option_uint('t',
215 "type", 214 "type",
216 "TYPE", 215 "TYPE",
217 gettext_noop ("the type to insert data as"), 216 gettext_noop("the type to insert data as"),
218 &query_type), 217 &query_type),
219 GNUNET_GETOPT_option_verbose (&verbose), 218 GNUNET_GETOPT_option_verbose(&verbose),
220 GNUNET_GETOPT_OPTION_END}; 219 GNUNET_GETOPT_OPTION_END };
221 220
222 221
223 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 222 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
224 return 2; 223 return 2;
225 expiration = GNUNET_TIME_UNIT_HOURS; 224 expiration = GNUNET_TIME_UNIT_HOURS;
226 return (GNUNET_OK == 225 return (GNUNET_OK ==
227 GNUNET_PROGRAM_run ( 226 GNUNET_PROGRAM_run(
228 argc, 227 argc,
229 argv, 228 argv,
230 "gnunet-dht-put", 229 "gnunet-dht-put",
231 gettext_noop ( 230 gettext_noop(
232 "Issue a PUT request to the GNUnet DHT insert DATA under KEY."), 231 "Issue a PUT request to the GNUnet DHT insert DATA under KEY."),
233 options, 232 options,
234 &run, 233 &run,
235 NULL)) 234 NULL))
236 ? ret 235 ? ret
237 : 1; 236 : 1;
238} 237}
239 238
240/* end of gnunet-dht-put.c */ 239/* end of gnunet-dht-put.c */
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c
index 705ffb86c..c1e4c03b0 100644
--- a/src/dht/gnunet-service-dht.c
+++ b/src/dht/gnunet-service-dht.c
@@ -11,12 +11,12 @@
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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file dht/gnunet-service-dht.c 22 * @file dht/gnunet-service-dht.c
@@ -66,14 +66,14 @@ struct GNUNET_TIME_Relative hello_expiration;
66 * @param message HELLO message of peer 66 * @param message HELLO message of peer
67 */ 67 */
68static void 68static void
69process_hello (void *cls, 69process_hello(void *cls,
70 const struct GNUNET_MessageHeader *message) 70 const struct GNUNET_MessageHeader *message)
71{ 71{
72 GNUNET_free_non_null (GDS_my_hello); 72 GNUNET_free_non_null(GDS_my_hello);
73 GDS_my_hello = GNUNET_malloc (ntohs (message->size)); 73 GDS_my_hello = GNUNET_malloc(ntohs(message->size));
74 GNUNET_memcpy (GDS_my_hello, 74 GNUNET_memcpy(GDS_my_hello,
75 message, 75 message,
76 ntohs (message->size)); 76 ntohs(message->size));
77} 77}
78 78
79 79
@@ -83,32 +83,32 @@ process_hello (void *cls,
83 * @param cls unused 83 * @param cls unused
84 */ 84 */
85static void 85static void
86shutdown_task (void *cls) 86shutdown_task(void *cls)
87{ 87{
88 if (NULL != ghh) 88 if (NULL != ghh)
89 { 89 {
90 GNUNET_TRANSPORT_hello_get_cancel (ghh); 90 GNUNET_TRANSPORT_hello_get_cancel(ghh);
91 ghh = NULL; 91 ghh = NULL;
92 } 92 }
93 GDS_NEIGHBOURS_done (); 93 GDS_NEIGHBOURS_done();
94 GDS_DATACACHE_done (); 94 GDS_DATACACHE_done();
95 GDS_ROUTING_done (); 95 GDS_ROUTING_done();
96 GDS_HELLO_done (); 96 GDS_HELLO_done();
97 GDS_NSE_done (); 97 GDS_NSE_done();
98 if (NULL != GDS_block_context) 98 if (NULL != GDS_block_context)
99 { 99 {
100 GNUNET_BLOCK_context_destroy (GDS_block_context); 100 GNUNET_BLOCK_context_destroy(GDS_block_context);
101 GDS_block_context = NULL; 101 GDS_block_context = NULL;
102 } 102 }
103 if (NULL != GDS_stats) 103 if (NULL != GDS_stats)
104 { 104 {
105 GNUNET_STATISTICS_destroy (GDS_stats, 105 GNUNET_STATISTICS_destroy(GDS_stats,
106 GNUNET_YES); 106 GNUNET_YES);
107 GDS_stats = NULL; 107 GDS_stats = NULL;
108 } 108 }
109 GNUNET_free_non_null (GDS_my_hello); 109 GNUNET_free_non_null(GDS_my_hello);
110 GDS_my_hello = NULL; 110 GDS_my_hello = NULL;
111 GDS_CLIENTS_stop (); 111 GDS_CLIENTS_stop();
112} 112}
113 113
114 114
@@ -120,40 +120,40 @@ shutdown_task (void *cls)
120 * @param service the initialized service 120 * @param service the initialized service
121 */ 121 */
122static void 122static void
123run (void *cls, 123run(void *cls,
124 const struct GNUNET_CONFIGURATION_Handle *c, 124 const struct GNUNET_CONFIGURATION_Handle *c,
125 struct GNUNET_SERVICE_Handle *service) 125 struct GNUNET_SERVICE_Handle *service)
126{ 126{
127 GDS_cfg = c; 127 GDS_cfg = c;
128 GDS_service = service; 128 GDS_service = service;
129 if (GNUNET_OK != 129 if (GNUNET_OK !=
130 GNUNET_CONFIGURATION_get_value_time (c, 130 GNUNET_CONFIGURATION_get_value_time(c,
131 "transport", 131 "transport",
132 "HELLO_EXPIRATION", 132 "HELLO_EXPIRATION",
133 &hello_expiration)) 133 &hello_expiration))
134 { 134 {
135 hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION; 135 hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION;
136 } 136 }
137 GDS_block_context = GNUNET_BLOCK_context_create (GDS_cfg); 137 GDS_block_context = GNUNET_BLOCK_context_create(GDS_cfg);
138 GDS_stats = GNUNET_STATISTICS_create ("dht", 138 GDS_stats = GNUNET_STATISTICS_create("dht",
139 GDS_cfg); 139 GDS_cfg);
140 GNUNET_SERVICE_suspend (GDS_service); 140 GNUNET_SERVICE_suspend(GDS_service);
141 GDS_CLIENTS_init (); 141 GDS_CLIENTS_init();
142 GDS_ROUTING_init (); 142 GDS_ROUTING_init();
143 GDS_NSE_init (); 143 GDS_NSE_init();
144 GDS_DATACACHE_init (); 144 GDS_DATACACHE_init();
145 GDS_HELLO_init (); 145 GDS_HELLO_init();
146 if (GNUNET_OK != GDS_NEIGHBOURS_init ()) 146 if (GNUNET_OK != GDS_NEIGHBOURS_init())
147 { 147 {
148 shutdown_task (NULL); 148 shutdown_task(NULL);
149 return; 149 return;
150 } 150 }
151 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 151 GNUNET_SCHEDULER_add_shutdown(&shutdown_task,
152 NULL); 152 NULL);
153 ghh = GNUNET_TRANSPORT_hello_get (GDS_cfg, 153 ghh = GNUNET_TRANSPORT_hello_get(GDS_cfg,
154 GNUNET_TRANSPORT_AC_GLOBAL, 154 GNUNET_TRANSPORT_AC_GLOBAL,
155 &process_hello, 155 &process_hello,
156 NULL); 156 NULL);
157} 157}
158 158
159 159
diff --git a/src/dht/gnunet-service-dht.h b/src/dht/gnunet-service-dht.h
index 8b41c648c..caf9dcbe8 100644
--- a/src/dht/gnunet-service-dht.h
+++ b/src/dht/gnunet-service-dht.h
@@ -11,12 +11,12 @@
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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file dht/gnunet-service-dht.h 22 * @file dht/gnunet-service-dht.h
@@ -76,15 +76,15 @@ extern struct GNUNET_MessageHeader *GDS_my_hello;
76 * @param data application payload data 76 * @param data application payload data
77 */ 77 */
78void 78void
79GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, 79GDS_CLIENTS_handle_reply(struct GNUNET_TIME_Absolute expiration,
80 const struct GNUNET_HashCode *key, 80 const struct GNUNET_HashCode *key,
81 unsigned int get_path_length, 81 unsigned int get_path_length,
82 const struct GNUNET_PeerIdentity *get_path, 82 const struct GNUNET_PeerIdentity *get_path,
83 unsigned int put_path_length, 83 unsigned int put_path_length,
84 const struct GNUNET_PeerIdentity *put_path, 84 const struct GNUNET_PeerIdentity *put_path,
85 enum GNUNET_BLOCK_Type type, 85 enum GNUNET_BLOCK_Type type,
86 size_t data_size, 86 size_t data_size,
87 const void *data); 87 const void *data);
88 88
89 89
90/** 90/**
@@ -100,13 +100,13 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration,
100 * @param key Key of the requested data. 100 * @param key Key of the requested data.
101 */ 101 */
102void 102void
103GDS_CLIENTS_process_get (uint32_t options, 103GDS_CLIENTS_process_get(uint32_t options,
104 enum GNUNET_BLOCK_Type type, 104 enum GNUNET_BLOCK_Type type,
105 uint32_t hop_count, 105 uint32_t hop_count,
106 uint32_t desired_replication_level, 106 uint32_t desired_replication_level,
107 unsigned int path_length, 107 unsigned int path_length,
108 const struct GNUNET_PeerIdentity *path, 108 const struct GNUNET_PeerIdentity *path,
109 const struct GNUNET_HashCode *key); 109 const struct GNUNET_HashCode *key);
110 110
111 111
112/** 112/**
@@ -124,15 +124,15 @@ GDS_CLIENTS_process_get (uint32_t options,
124 * @param size Number of bytes in @a data. 124 * @param size Number of bytes in @a data.
125 */ 125 */
126void 126void
127GDS_CLIENTS_process_get_resp (enum GNUNET_BLOCK_Type type, 127GDS_CLIENTS_process_get_resp(enum GNUNET_BLOCK_Type type,
128 const struct GNUNET_PeerIdentity *get_path, 128 const struct GNUNET_PeerIdentity *get_path,
129 unsigned int get_path_length, 129 unsigned int get_path_length,
130 const struct GNUNET_PeerIdentity *put_path, 130 const struct GNUNET_PeerIdentity *put_path,
131 unsigned int put_path_length, 131 unsigned int put_path_length,
132 struct GNUNET_TIME_Absolute exp, 132 struct GNUNET_TIME_Absolute exp,
133 const struct GNUNET_HashCode * key, 133 const struct GNUNET_HashCode * key,
134 const void *data, 134 const void *data,
135 size_t size); 135 size_t size);
136 136
137 137
138/** 138/**
@@ -151,15 +151,15 @@ GDS_CLIENTS_process_get_resp (enum GNUNET_BLOCK_Type type,
151 * @param size Number of bytes in data. 151 * @param size Number of bytes in data.
152 */ 152 */
153void 153void
154GDS_CLIENTS_process_put (uint32_t options, 154GDS_CLIENTS_process_put(uint32_t options,
155 enum GNUNET_BLOCK_Type type, 155 enum GNUNET_BLOCK_Type type,
156 uint32_t hop_count, 156 uint32_t hop_count,
157 uint32_t desired_replication_level, 157 uint32_t desired_replication_level,
158 unsigned int path_length, 158 unsigned int path_length,
159 const struct GNUNET_PeerIdentity *path, 159 const struct GNUNET_PeerIdentity *path,
160 struct GNUNET_TIME_Absolute exp, 160 struct GNUNET_TIME_Absolute exp,
161 const struct GNUNET_HashCode *key, 161 const struct GNUNET_HashCode *key,
162 const void *data, 162 const void *data,
163 size_t size); 163 size_t size);
164 164
165#endif 165#endif
diff --git a/src/dht/gnunet-service-dht_clients.c b/src/dht/gnunet-service-dht_clients.c
index 7e2440841..48017bfb4 100644
--- a/src/dht/gnunet-service-dht_clients.c
+++ b/src/dht/gnunet-service-dht_clients.c
@@ -11,12 +11,12 @@
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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file dht/gnunet-service-dht_clients.c 22 * @file dht/gnunet-service-dht_clients.c
@@ -38,9 +38,9 @@
38/** 38/**
39 * Should routing details be logged to stderr (for debugging)? 39 * Should routing details be logged to stderr (for debugging)?
40 */ 40 */
41#define LOG_TRAFFIC(kind,...) GNUNET_log_from (kind, "dht-traffic",__VA_ARGS__) 41#define LOG_TRAFFIC(kind, ...) GNUNET_log_from(kind, "dht-traffic", __VA_ARGS__)
42 42
43#define LOG(kind,...) GNUNET_log_from (kind, "dht-clients",__VA_ARGS__) 43#define LOG(kind, ...) GNUNET_log_from(kind, "dht-clients", __VA_ARGS__)
44 44
45 45
46/** 46/**
@@ -54,9 +54,7 @@ struct ClientHandle;
54/** 54/**
55 * Entry in the local forwarding map for a client's GET request. 55 * Entry in the local forwarding map for a client's GET request.
56 */ 56 */
57struct ClientQueryRecord 57struct ClientQueryRecord {
58{
59
60 /** 58 /**
61 * The key this request was about 59 * The key this request was about
62 */ 60 */
@@ -132,16 +130,13 @@ struct ClientQueryRecord
132 * The type for the data for the GET request. 130 * The type for the data for the GET request.
133 */ 131 */
134 enum GNUNET_BLOCK_Type type; 132 enum GNUNET_BLOCK_Type type;
135
136}; 133};
137 134
138 135
139/** 136/**
140 * Struct containing paremeters of monitoring requests. 137 * Struct containing paremeters of monitoring requests.
141 */ 138 */
142struct ClientMonitorRecord 139struct ClientMonitorRecord {
143{
144
145 /** 140 /**
146 * Next element in DLL. 141 * Next element in DLL.
147 */ 142 */
@@ -189,8 +184,7 @@ struct ClientMonitorRecord
189 * handle to connect to it, and any pending messages 184 * handle to connect to it, and any pending messages
190 * that need to be sent to it. 185 * that need to be sent to it.
191 */ 186 */
192struct ClientHandle 187struct ClientHandle {
193{
194 /** 188 /**
195 * Linked list of active queries of this client. 189 * Linked list of active queries of this client.
196 */ 190 */
@@ -210,7 +204,6 @@ struct ClientHandle
210 * The message queue to this client 204 * The message queue to this client
211 */ 205 */
212 struct GNUNET_MQ_Handle *mq; 206 struct GNUNET_MQ_Handle *mq;
213
214}; 207};
215 208
216/** 209/**
@@ -265,23 +258,23 @@ static struct GNUNET_SCHEDULER_Task *retry_task;
265 * @param record record to remove 258 * @param record record to remove
266 */ 259 */
267static void 260static void
268remove_client_record (struct ClientQueryRecord *record) 261remove_client_record(struct ClientQueryRecord *record)
269{ 262{
270 struct ClientHandle *ch = record->ch; 263 struct ClientHandle *ch = record->ch;
271 264
272 GNUNET_CONTAINER_DLL_remove (ch->cqr_head, 265 GNUNET_CONTAINER_DLL_remove(ch->cqr_head,
273 ch->cqr_tail, 266 ch->cqr_tail,
274 record); 267 record);
275 GNUNET_assert (GNUNET_YES == 268 GNUNET_assert(GNUNET_YES ==
276 GNUNET_CONTAINER_multihashmap_remove (forward_map, 269 GNUNET_CONTAINER_multihashmap_remove(forward_map,
277 &record->key, 270 &record->key,
278 record)); 271 record));
279 if (NULL != record->hnode) 272 if (NULL != record->hnode)
280 GNUNET_CONTAINER_heap_remove_node (record->hnode); 273 GNUNET_CONTAINER_heap_remove_node(record->hnode);
281 GNUNET_array_grow (record->seen_replies, 274 GNUNET_array_grow(record->seen_replies,
282 record->seen_replies_count, 275 record->seen_replies_count,
283 0); 276 0);
284 GNUNET_free (record); 277 GNUNET_free(record);
285} 278}
286 279
287 280
@@ -295,13 +288,13 @@ remove_client_record (struct ClientQueryRecord *record)
295 * @return our `struct ClientHandle` for @a client 288 * @return our `struct ClientHandle` for @a client
296 */ 289 */
297static void * 290static void *
298client_connect_cb (void *cls, 291client_connect_cb(void *cls,
299 struct GNUNET_SERVICE_Client *client, 292 struct GNUNET_SERVICE_Client *client,
300 struct GNUNET_MQ_Handle *mq) 293 struct GNUNET_MQ_Handle *mq)
301{ 294{
302 struct ClientHandle *ch; 295 struct ClientHandle *ch;
303 296
304 ch = GNUNET_new (struct ClientHandle); 297 ch = GNUNET_new(struct ClientHandle);
305 ch->client = client; 298 ch->client = client;
306 ch->mq = mq; 299 ch->mq = mq;
307 return ch; 300 return ch;
@@ -317,40 +310,40 @@ client_connect_cb (void *cls,
317 * @param app_ctx our `struct ClientHandle` for @a client 310 * @param app_ctx our `struct ClientHandle` for @a client
318 */ 311 */
319static void 312static void
320client_disconnect_cb (void *cls, 313client_disconnect_cb(void *cls,
321 struct GNUNET_SERVICE_Client *client, 314 struct GNUNET_SERVICE_Client *client,
322 void *app_ctx) 315 void *app_ctx)
323{ 316{
324 struct ClientHandle *ch = app_ctx; 317 struct ClientHandle *ch = app_ctx;
325 struct ClientQueryRecord *cqr; 318 struct ClientQueryRecord *cqr;
326 struct ClientMonitorRecord *monitor; 319 struct ClientMonitorRecord *monitor;
327 320
328 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 321 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
329 "Local client %p disconnects\n", 322 "Local client %p disconnects\n",
330 ch); 323 ch);
331 monitor = monitor_head; 324 monitor = monitor_head;
332 while (NULL != monitor) 325 while (NULL != monitor)
333 {
334 if (monitor->ch == ch)
335 {
336 struct ClientMonitorRecord *next;
337
338 next = monitor->next;
339 GNUNET_free_non_null (monitor->key);
340 GNUNET_CONTAINER_DLL_remove (monitor_head,
341 monitor_tail,
342 monitor);
343 GNUNET_free (monitor);
344 monitor = next;
345 }
346 else
347 { 326 {
348 monitor = monitor->next; 327 if (monitor->ch == ch)
328 {
329 struct ClientMonitorRecord *next;
330
331 next = monitor->next;
332 GNUNET_free_non_null(monitor->key);
333 GNUNET_CONTAINER_DLL_remove(monitor_head,
334 monitor_tail,
335 monitor);
336 GNUNET_free(monitor);
337 monitor = next;
338 }
339 else
340 {
341 monitor = monitor->next;
342 }
349 } 343 }
350 }
351 while (NULL != (cqr = ch->cqr_head)) 344 while (NULL != (cqr = ch->cqr_head))
352 remove_client_record (cqr); 345 remove_client_record(cqr);
353 GNUNET_free (ch); 346 GNUNET_free(ch);
354} 347}
355 348
356 349
@@ -360,52 +353,52 @@ client_disconnect_cb (void *cls,
360 * message and initiating the routing operation. 353 * message and initiating the routing operation.
361 */ 354 */
362static void 355static void
363transmit_request (struct ClientQueryRecord *cqr) 356transmit_request(struct ClientQueryRecord *cqr)
364{ 357{
365 struct GNUNET_BLOCK_Group *bg; 358 struct GNUNET_BLOCK_Group *bg;
366 struct GNUNET_CONTAINER_BloomFilter *peer_bf; 359 struct GNUNET_CONTAINER_BloomFilter *peer_bf;
367 360
368 GNUNET_STATISTICS_update (GDS_stats, 361 GNUNET_STATISTICS_update(GDS_stats,
369 gettext_noop ("# GET requests from clients injected"), 362 gettext_noop("# GET requests from clients injected"),
370 1, 363 1,
371 GNUNET_NO); 364 GNUNET_NO);
372 bg = GNUNET_BLOCK_group_create (GDS_block_context, 365 bg = GNUNET_BLOCK_group_create(GDS_block_context,
373 cqr->type, 366 cqr->type,
374 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 367 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
375 UINT32_MAX), 368 UINT32_MAX),
376 NULL, 369 NULL,
377 0, 370 0,
378 "seen-set-size", 371 "seen-set-size",
379 cqr->seen_replies_count, 372 cqr->seen_replies_count,
380 NULL); 373 NULL);
381 GNUNET_BLOCK_group_set_seen (bg, 374 GNUNET_BLOCK_group_set_seen(bg,
382 cqr->seen_replies, 375 cqr->seen_replies,
383 cqr->seen_replies_count); 376 cqr->seen_replies_count);
384 peer_bf 377 peer_bf
385 = GNUNET_CONTAINER_bloomfilter_init (NULL, 378 = GNUNET_CONTAINER_bloomfilter_init(NULL,
386 DHT_BLOOM_SIZE, 379 DHT_BLOOM_SIZE,
387 GNUNET_CONSTANTS_BLOOMFILTER_K); 380 GNUNET_CONSTANTS_BLOOMFILTER_K);
388 LOG (GNUNET_ERROR_TYPE_DEBUG, 381 LOG(GNUNET_ERROR_TYPE_DEBUG,
389 "Initiating GET for %s, replication %u, already have %u replies\n", 382 "Initiating GET for %s, replication %u, already have %u replies\n",
390 GNUNET_h2s (&cqr->key), 383 GNUNET_h2s(&cqr->key),
391 cqr->replication, 384 cqr->replication,
392 cqr->seen_replies_count); 385 cqr->seen_replies_count);
393 GDS_NEIGHBOURS_handle_get (cqr->type, 386 GDS_NEIGHBOURS_handle_get(cqr->type,
394 cqr->msg_options, 387 cqr->msg_options,
395 cqr->replication, 388 cqr->replication,
396 0 /* hop count */ , 389 0 /* hop count */,
397 &cqr->key, 390 &cqr->key,
398 cqr->xquery, 391 cqr->xquery,
399 cqr->xquery_size, 392 cqr->xquery_size,
400 bg, 393 bg,
401 peer_bf); 394 peer_bf);
402 GNUNET_BLOCK_group_destroy (bg); 395 GNUNET_BLOCK_group_destroy(bg);
403 GNUNET_CONTAINER_bloomfilter_free (peer_bf); 396 GNUNET_CONTAINER_bloomfilter_free(peer_bf);
404 397
405 /* exponential back-off for retries. 398 /* exponential back-off for retries.
406 * max GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD (15 min) */ 399 * max GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD (15 min) */
407 cqr->retry_frequency = GNUNET_TIME_STD_BACKOFF (cqr->retry_frequency); 400 cqr->retry_frequency = GNUNET_TIME_STD_BACKOFF(cqr->retry_frequency);
408 cqr->retry_time = GNUNET_TIME_relative_to_absolute (cqr->retry_frequency); 401 cqr->retry_time = GNUNET_TIME_relative_to_absolute(cqr->retry_frequency);
409} 402}
410 403
411 404
@@ -417,34 +410,34 @@ transmit_request (struct ClientQueryRecord *cqr)
417 * @param cls unused 410 * @param cls unused
418 */ 411 */
419static void 412static void
420transmit_next_request_task (void *cls) 413transmit_next_request_task(void *cls)
421{ 414{
422 struct ClientQueryRecord *cqr; 415 struct ClientQueryRecord *cqr;
423 struct GNUNET_TIME_Relative delay; 416 struct GNUNET_TIME_Relative delay;
424 417
425 retry_task = NULL; 418 retry_task = NULL;
426 while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root (retry_heap))) 419 while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root(retry_heap)))
427 {
428 cqr->hnode = NULL;
429 delay = GNUNET_TIME_absolute_get_remaining (cqr->retry_time);
430 if (delay.rel_value_us > 0)
431 { 420 {
421 cqr->hnode = NULL;
422 delay = GNUNET_TIME_absolute_get_remaining(cqr->retry_time);
423 if (delay.rel_value_us > 0)
424 {
425 cqr->hnode
426 = GNUNET_CONTAINER_heap_insert(retry_heap,
427 cqr,
428 cqr->retry_time.abs_value_us);
429 retry_task
430 = GNUNET_SCHEDULER_add_at(cqr->retry_time,
431 &transmit_next_request_task,
432 NULL);
433 return;
434 }
435 transmit_request(cqr);
432 cqr->hnode 436 cqr->hnode
433 = GNUNET_CONTAINER_heap_insert (retry_heap, 437 = GNUNET_CONTAINER_heap_insert(retry_heap,
434 cqr, 438 cqr,
435 cqr->retry_time.abs_value_us); 439 cqr->retry_time.abs_value_us);
436 retry_task
437 = GNUNET_SCHEDULER_add_at (cqr->retry_time,
438 &transmit_next_request_task,
439 NULL);
440 return;
441 } 440 }
442 transmit_request (cqr);
443 cqr->hnode
444 = GNUNET_CONTAINER_heap_insert (retry_heap,
445 cqr,
446 cqr->retry_time.abs_value_us);
447 }
448} 441}
449 442
450 443
@@ -456,8 +449,8 @@ transmit_next_request_task (void *cls)
456 * @return #GNUNET_OK (always) 449 * @return #GNUNET_OK (always)
457 */ 450 */
458static int 451static int
459check_dht_local_put (void *cls, 452check_dht_local_put(void *cls,
460 const struct GNUNET_DHT_ClientPutMessage *dht_msg) 453 const struct GNUNET_DHT_ClientPutMessage *dht_msg)
461{ 454{
462 /* always well-formed */ 455 /* always well-formed */
463 return GNUNET_OK; 456 return GNUNET_OK;
@@ -471,71 +464,71 @@ check_dht_local_put (void *cls,
471 * @param dht_msg the actual message received 464 * @param dht_msg the actual message received
472 */ 465 */
473static void 466static void
474handle_dht_local_put (void *cls, 467handle_dht_local_put(void *cls,
475 const struct GNUNET_DHT_ClientPutMessage *dht_msg) 468 const struct GNUNET_DHT_ClientPutMessage *dht_msg)
476{ 469{
477 struct ClientHandle *ch = cls; 470 struct ClientHandle *ch = cls;
478 struct GNUNET_CONTAINER_BloomFilter *peer_bf; 471 struct GNUNET_CONTAINER_BloomFilter *peer_bf;
479 uint16_t size; 472 uint16_t size;
480 473
481 size = ntohs (dht_msg->header.size); 474 size = ntohs(dht_msg->header.size);
482 GNUNET_STATISTICS_update (GDS_stats, 475 GNUNET_STATISTICS_update(GDS_stats,
483 gettext_noop ("# PUT requests received from clients"), 476 gettext_noop("# PUT requests received from clients"),
484 1, 477 1,
485 GNUNET_NO); 478 GNUNET_NO);
486 LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, 479 LOG_TRAFFIC(GNUNET_ERROR_TYPE_DEBUG,
487 "CLIENT-PUT %s\n", 480 "CLIENT-PUT %s\n",
488 GNUNET_h2s_full (&dht_msg->key)); 481 GNUNET_h2s_full(&dht_msg->key));
489 /* give to local clients */ 482 /* give to local clients */
490 LOG (GNUNET_ERROR_TYPE_DEBUG, 483 LOG(GNUNET_ERROR_TYPE_DEBUG,
491 "Handling local PUT of %u-bytes for query %s\n", 484 "Handling local PUT of %u-bytes for query %s\n",
492 size - sizeof (struct GNUNET_DHT_ClientPutMessage), 485 size - sizeof(struct GNUNET_DHT_ClientPutMessage),
493 GNUNET_h2s (&dht_msg->key)); 486 GNUNET_h2s(&dht_msg->key));
494 GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (dht_msg->expiration), 487 GDS_CLIENTS_handle_reply(GNUNET_TIME_absolute_ntoh(dht_msg->expiration),
495 &dht_msg->key, 488 &dht_msg->key,
496 0, 489 0,
497 NULL, 490 NULL,
498 0, 491 0,
499 NULL, 492 NULL,
500 ntohl (dht_msg->type), 493 ntohl(dht_msg->type),
501 size - sizeof (struct GNUNET_DHT_ClientPutMessage), 494 size - sizeof(struct GNUNET_DHT_ClientPutMessage),
502 &dht_msg[1]); 495 &dht_msg[1]);
503 /* store locally */ 496 /* store locally */
504 GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (dht_msg->expiration), 497 GDS_DATACACHE_handle_put(GNUNET_TIME_absolute_ntoh(dht_msg->expiration),
498 &dht_msg->key,
499 0,
500 NULL,
501 ntohl(dht_msg->type),
502 size - sizeof(struct GNUNET_DHT_ClientPutMessage),
503 &dht_msg[1]);
504 /* route to other peers */
505 peer_bf
506 = GNUNET_CONTAINER_bloomfilter_init(NULL,
507 DHT_BLOOM_SIZE,
508 GNUNET_CONSTANTS_BLOOMFILTER_K);
509 GDS_NEIGHBOURS_handle_put(ntohl(dht_msg->type),
510 ntohl(dht_msg->options),
511 ntohl(dht_msg->desired_replication_level),
512 GNUNET_TIME_absolute_ntoh(dht_msg->expiration),
513 0 /* hop count */,
514 peer_bf,
505 &dht_msg->key, 515 &dht_msg->key,
506 0, 516 0,
507 NULL, 517 NULL,
508 ntohl (dht_msg->type), 518 &dht_msg[1],
509 size - sizeof (struct GNUNET_DHT_ClientPutMessage), 519 size - sizeof(struct GNUNET_DHT_ClientPutMessage));
510 &dht_msg[1]); 520 GDS_CLIENTS_process_put(ntohl(dht_msg->options),
511 /* route to other peers */ 521 ntohl(dht_msg->type),
512 peer_bf 522 0,
513 = GNUNET_CONTAINER_bloomfilter_init (NULL, 523 ntohl(dht_msg->desired_replication_level),
514 DHT_BLOOM_SIZE, 524 1,
515 GNUNET_CONSTANTS_BLOOMFILTER_K); 525 GDS_NEIGHBOURS_get_id(),
516 GDS_NEIGHBOURS_handle_put (ntohl (dht_msg->type), 526 GNUNET_TIME_absolute_ntoh(dht_msg->expiration),
517 ntohl (dht_msg->options), 527 &dht_msg->key,
518 ntohl (dht_msg->desired_replication_level), 528 &dht_msg[1],
519 GNUNET_TIME_absolute_ntoh (dht_msg->expiration), 529 size - sizeof(struct GNUNET_DHT_ClientPutMessage));
520 0 /* hop count */, 530 GNUNET_CONTAINER_bloomfilter_free(peer_bf);
521 peer_bf, 531 GNUNET_SERVICE_client_continue(ch->client);
522 &dht_msg->key,
523 0,
524 NULL,
525 &dht_msg[1],
526 size - sizeof (struct GNUNET_DHT_ClientPutMessage));
527 GDS_CLIENTS_process_put (ntohl (dht_msg->options),
528 ntohl (dht_msg->type),
529 0,
530 ntohl (dht_msg->desired_replication_level),
531 1,
532 GDS_NEIGHBOURS_get_id(),
533 GNUNET_TIME_absolute_ntoh (dht_msg->expiration),
534 &dht_msg->key,
535 &dht_msg[1],
536 size - sizeof (struct GNUNET_DHT_ClientPutMessage));
537 GNUNET_CONTAINER_bloomfilter_free (peer_bf);
538 GNUNET_SERVICE_client_continue (ch->client);
539} 532}
540 533
541 534
@@ -547,8 +540,8 @@ handle_dht_local_put (void *cls,
547 * @return #GNUNET_OK (always) 540 * @return #GNUNET_OK (always)
548 */ 541 */
549static int 542static int
550check_dht_local_get (void *cls, 543check_dht_local_get(void *cls,
551 const struct GNUNET_DHT_ClientGetMessage *get) 544 const struct GNUNET_DHT_ClientGetMessage *get)
552{ 545{
553 /* always well-formed */ 546 /* always well-formed */
554 return GNUNET_OK; 547 return GNUNET_OK;
@@ -570,25 +563,25 @@ check_dht_local_get (void *cls,
570 * @param data_size number of bytes in @a data 563 * @param data_size number of bytes in @a data
571 */ 564 */
572static void 565static void
573handle_local_result (void *cls, 566handle_local_result(void *cls,
574 enum GNUNET_BLOCK_Type type, 567 enum GNUNET_BLOCK_Type type,
575 struct GNUNET_TIME_Absolute expiration_time, 568 struct GNUNET_TIME_Absolute expiration_time,
576 const struct GNUNET_HashCode *key, 569 const struct GNUNET_HashCode *key,
577 unsigned int put_path_length, 570 unsigned int put_path_length,
578 const struct GNUNET_PeerIdentity *put_path, 571 const struct GNUNET_PeerIdentity *put_path,
579 unsigned int get_path_length, 572 unsigned int get_path_length,
580 const struct GNUNET_PeerIdentity *get_path, 573 const struct GNUNET_PeerIdentity *get_path,
581 const void *data, 574 const void *data,
582 size_t data_size) 575 size_t data_size)
583{ 576{
584 // FIXME: this needs some clean up: inline the function, 577 // FIXME: this needs some clean up: inline the function,
585 // possibly avoid even looking up the client! 578 // possibly avoid even looking up the client!
586 GDS_CLIENTS_handle_reply (expiration_time, 579 GDS_CLIENTS_handle_reply(expiration_time,
587 key, 580 key,
588 0, NULL, 581 0, NULL,
589 put_path_length, put_path, 582 put_path_length, put_path,
590 type, 583 type,
591 data_size, data); 584 data_size, data);
592} 585}
593 586
594 587
@@ -599,8 +592,8 @@ handle_local_result (void *cls,
599 * @param message the actual message received 592 * @param message the actual message received
600 */ 593 */
601static void 594static void
602handle_dht_local_get (void *cls, 595handle_dht_local_get(void *cls,
603 const struct GNUNET_DHT_ClientGetMessage *get) 596 const struct GNUNET_DHT_ClientGetMessage *get)
604{ 597{
605 struct ClientHandle *ch = cls; 598 struct ClientHandle *ch = cls;
606 struct ClientQueryRecord *cqr; 599 struct ClientQueryRecord *cqr;
@@ -608,72 +601,71 @@ handle_dht_local_get (void *cls,
608 const char *xquery; 601 const char *xquery;
609 uint16_t size; 602 uint16_t size;
610 603
611 size = ntohs (get->header.size); 604 size = ntohs(get->header.size);
612 xquery_size = size - sizeof (struct GNUNET_DHT_ClientGetMessage); 605 xquery_size = size - sizeof(struct GNUNET_DHT_ClientGetMessage);
613 xquery = (const char *) &get[1]; 606 xquery = (const char *)&get[1];
614 GNUNET_STATISTICS_update (GDS_stats, 607 GNUNET_STATISTICS_update(GDS_stats,
615 gettext_noop 608 gettext_noop
616 ("# GET requests received from clients"), 1, 609 ("# GET requests received from clients"), 1,
617 GNUNET_NO); 610 GNUNET_NO);
618 LOG (GNUNET_ERROR_TYPE_DEBUG, 611 LOG(GNUNET_ERROR_TYPE_DEBUG,
619 "Received GET request for %s from local client %p, xq: %.*s\n", 612 "Received GET request for %s from local client %p, xq: %.*s\n",
620 GNUNET_h2s (&get->key), 613 GNUNET_h2s(&get->key),
621 ch->client, 614 ch->client,
622 xquery_size, 615 xquery_size,
623 xquery); 616 xquery);
624 LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, 617 LOG_TRAFFIC(GNUNET_ERROR_TYPE_DEBUG,
625 "CLIENT-GET %s\n", 618 "CLIENT-GET %s\n",
626 GNUNET_h2s_full (&get->key)); 619 GNUNET_h2s_full(&get->key));
627 620
628 cqr = GNUNET_malloc (sizeof (struct ClientQueryRecord) + xquery_size); 621 cqr = GNUNET_malloc(sizeof(struct ClientQueryRecord) + xquery_size);
629 cqr->key = get->key; 622 cqr->key = get->key;
630 cqr->ch = ch; 623 cqr->ch = ch;
631 cqr->xquery = (void *) &cqr[1]; 624 cqr->xquery = (void *)&cqr[1];
632 GNUNET_memcpy (&cqr[1], xquery, xquery_size); 625 GNUNET_memcpy(&cqr[1], xquery, xquery_size);
633 cqr->hnode = GNUNET_CONTAINER_heap_insert (retry_heap, cqr, 0); 626 cqr->hnode = GNUNET_CONTAINER_heap_insert(retry_heap, cqr, 0);
634 cqr->retry_frequency = GNUNET_TIME_UNIT_SECONDS; 627 cqr->retry_frequency = GNUNET_TIME_UNIT_SECONDS;
635 cqr->retry_time = GNUNET_TIME_absolute_get (); 628 cqr->retry_time = GNUNET_TIME_absolute_get();
636 cqr->unique_id = get->unique_id; 629 cqr->unique_id = get->unique_id;
637 cqr->xquery_size = xquery_size; 630 cqr->xquery_size = xquery_size;
638 cqr->replication = ntohl (get->desired_replication_level); 631 cqr->replication = ntohl(get->desired_replication_level);
639 cqr->msg_options = ntohl (get->options); 632 cqr->msg_options = ntohl(get->options);
640 cqr->type = ntohl (get->type); 633 cqr->type = ntohl(get->type);
641 GNUNET_CONTAINER_DLL_insert (ch->cqr_head, 634 GNUNET_CONTAINER_DLL_insert(ch->cqr_head,
642 ch->cqr_tail, 635 ch->cqr_tail,
643 cqr); 636 cqr);
644 GNUNET_CONTAINER_multihashmap_put (forward_map, 637 GNUNET_CONTAINER_multihashmap_put(forward_map,
645 &cqr->key, 638 &cqr->key,
646 cqr, 639 cqr,
647 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 640 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
648 GDS_CLIENTS_process_get (ntohl (get->options), 641 GDS_CLIENTS_process_get(ntohl(get->options),
649 ntohl (get->type), 642 ntohl(get->type),
650 0, 643 0,
651 ntohl (get->desired_replication_level), 644 ntohl(get->desired_replication_level),
652 1, 645 1,
653 GDS_NEIGHBOURS_get_id(), 646 GDS_NEIGHBOURS_get_id(),
654 &get->key); 647 &get->key);
655 /* start remote requests */ 648 /* start remote requests */
656 if (NULL != retry_task) 649 if (NULL != retry_task)
657 GNUNET_SCHEDULER_cancel (retry_task); 650 GNUNET_SCHEDULER_cancel(retry_task);
658 retry_task = GNUNET_SCHEDULER_add_now (&transmit_next_request_task, 651 retry_task = GNUNET_SCHEDULER_add_now(&transmit_next_request_task,
659 NULL); 652 NULL);
660 /* perform local lookup */ 653 /* perform local lookup */
661 GDS_DATACACHE_handle_get (&get->key, 654 GDS_DATACACHE_handle_get(&get->key,
662 cqr->type, 655 cqr->type,
663 cqr->xquery, 656 cqr->xquery,
664 xquery_size, 657 xquery_size,
665 NULL, 658 NULL,
666 &handle_local_result, 659 &handle_local_result,
667 ch); 660 ch);
668 GNUNET_SERVICE_client_continue (ch->client); 661 GNUNET_SERVICE_client_continue(ch->client);
669} 662}
670 663
671 664
672/** 665/**
673 * Closure for #find_by_unique_id(). 666 * Closure for #find_by_unique_id().
674 */ 667 */
675struct FindByUniqueIdContext 668struct FindByUniqueIdContext {
676{
677 /** 669 /**
678 * Where to store the result, if found. 670 * Where to store the result, if found.
679 */ 671 */
@@ -694,9 +686,9 @@ struct FindByUniqueIdContext
694 * @return #GNUNET_YES to continue iteration (result not yet found) 686 * @return #GNUNET_YES to continue iteration (result not yet found)
695 */ 687 */
696static int 688static int
697find_by_unique_id (void *cls, 689find_by_unique_id(void *cls,
698 const struct GNUNET_HashCode *key, 690 const struct GNUNET_HashCode *key,
699 void *value) 691 void *value)
700{ 692{
701 struct FindByUniqueIdContext *fui_ctx = cls; 693 struct FindByUniqueIdContext *fui_ctx = cls;
702 struct ClientQueryRecord *cqr = value; 694 struct ClientQueryRecord *cqr = value;
@@ -716,19 +708,19 @@ find_by_unique_id (void *cls,
716 * @return #GNUNET_OK if @a seen is well-formed 708 * @return #GNUNET_OK if @a seen is well-formed
717 */ 709 */
718static int 710static int
719check_dht_local_get_result_seen (void *cls, 711check_dht_local_get_result_seen(void *cls,
720 const struct GNUNET_DHT_ClientGetResultSeenMessage *seen) 712 const struct GNUNET_DHT_ClientGetResultSeenMessage *seen)
721{ 713{
722 uint16_t size; 714 uint16_t size;
723 unsigned int hash_count; 715 unsigned int hash_count;
724 716
725 size = ntohs (seen->header.size); 717 size = ntohs(seen->header.size);
726 hash_count = (size - sizeof (struct GNUNET_DHT_ClientGetResultSeenMessage)) / sizeof (struct GNUNET_HashCode); 718 hash_count = (size - sizeof(struct GNUNET_DHT_ClientGetResultSeenMessage)) / sizeof(struct GNUNET_HashCode);
727 if (size != sizeof (struct GNUNET_DHT_ClientGetResultSeenMessage) + hash_count * sizeof (struct GNUNET_HashCode)) 719 if (size != sizeof(struct GNUNET_DHT_ClientGetResultSeenMessage) + hash_count * sizeof(struct GNUNET_HashCode))
728 { 720 {
729 GNUNET_break (0); 721 GNUNET_break(0);
730 return GNUNET_SYSERR; 722 return GNUNET_SYSERR;
731 } 723 }
732 return GNUNET_OK; 724 return GNUNET_OK;
733} 725}
734 726
@@ -740,8 +732,8 @@ check_dht_local_get_result_seen (void *cls,
740 * @param message the actual message received 732 * @param message the actual message received
741 */ 733 */
742static void 734static void
743handle_dht_local_get_result_seen (void *cls, 735handle_dht_local_get_result_seen(void *cls,
744 const struct GNUNET_DHT_ClientGetResultSeenMessage *seen) 736 const struct GNUNET_DHT_ClientGetResultSeenMessage *seen)
745{ 737{
746 struct ClientHandle *ch = cls; 738 struct ClientHandle *ch = cls;
747 uint16_t size; 739 uint16_t size;
@@ -751,37 +743,36 @@ handle_dht_local_get_result_seen (void *cls,
751 struct FindByUniqueIdContext fui_ctx; 743 struct FindByUniqueIdContext fui_ctx;
752 struct ClientQueryRecord *cqr; 744 struct ClientQueryRecord *cqr;
753 745
754 size = ntohs (seen->header.size); 746 size = ntohs(seen->header.size);
755 hash_count = (size - sizeof (struct GNUNET_DHT_ClientGetResultSeenMessage)) / sizeof (struct GNUNET_HashCode); 747 hash_count = (size - sizeof(struct GNUNET_DHT_ClientGetResultSeenMessage)) / sizeof(struct GNUNET_HashCode);
756 hc = (const struct GNUNET_HashCode*) &seen[1]; 748 hc = (const struct GNUNET_HashCode*)&seen[1];
757 fui_ctx.unique_id = seen->unique_id; 749 fui_ctx.unique_id = seen->unique_id;
758 fui_ctx.cqr = NULL; 750 fui_ctx.cqr = NULL;
759 GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, 751 GNUNET_CONTAINER_multihashmap_get_multiple(forward_map,
760 &seen->key, 752 &seen->key,
761 &find_by_unique_id, 753 &find_by_unique_id,
762 &fui_ctx); 754 &fui_ctx);
763 if (NULL == (cqr = fui_ctx.cqr)) 755 if (NULL == (cqr = fui_ctx.cqr))
764 { 756 {
765 GNUNET_break (0); 757 GNUNET_break(0);
766 GNUNET_SERVICE_client_drop (ch->client); 758 GNUNET_SERVICE_client_drop(ch->client);
767 return; 759 return;
768 } 760 }
769 /* finally, update 'seen' list */ 761 /* finally, update 'seen' list */
770 old_count = cqr->seen_replies_count; 762 old_count = cqr->seen_replies_count;
771 GNUNET_array_grow (cqr->seen_replies, 763 GNUNET_array_grow(cqr->seen_replies,
772 cqr->seen_replies_count, 764 cqr->seen_replies_count,
773 cqr->seen_replies_count + hash_count); 765 cqr->seen_replies_count + hash_count);
774 GNUNET_memcpy (&cqr->seen_replies[old_count], 766 GNUNET_memcpy(&cqr->seen_replies[old_count],
775 hc, 767 hc,
776 sizeof (struct GNUNET_HashCode) * hash_count); 768 sizeof(struct GNUNET_HashCode) * hash_count);
777} 769}
778 770
779 771
780/** 772/**
781 * Closure for #remove_by_unique_id(). 773 * Closure for #remove_by_unique_id().
782 */ 774 */
783struct RemoveByUniqueIdContext 775struct RemoveByUniqueIdContext {
784{
785 /** 776 /**
786 * Client that issued the removal request. 777 * Client that issued the removal request.
787 */ 778 */
@@ -804,20 +795,20 @@ struct RemoveByUniqueIdContext
804 * @return #GNUNET_YES (we should continue to iterate) 795 * @return #GNUNET_YES (we should continue to iterate)
805 */ 796 */
806static int 797static int
807remove_by_unique_id (void *cls, 798remove_by_unique_id(void *cls,
808 const struct GNUNET_HashCode *key, 799 const struct GNUNET_HashCode *key,
809 void *value) 800 void *value)
810{ 801{
811 const struct RemoveByUniqueIdContext *ctx = cls; 802 const struct RemoveByUniqueIdContext *ctx = cls;
812 struct ClientQueryRecord *cqr = value; 803 struct ClientQueryRecord *cqr = value;
813 804
814 if (cqr->unique_id != ctx->unique_id) 805 if (cqr->unique_id != ctx->unique_id)
815 return GNUNET_YES; 806 return GNUNET_YES;
816 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 807 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
817 "Removing client %p's record for key %s (by unique id)\n", 808 "Removing client %p's record for key %s (by unique id)\n",
818 ctx->ch->client, 809 ctx->ch->client,
819 GNUNET_h2s (key)); 810 GNUNET_h2s(key));
820 remove_client_record (cqr); 811 remove_client_record(cqr);
821 return GNUNET_YES; 812 return GNUNET_YES;
822} 813}
823 814
@@ -831,27 +822,27 @@ remove_by_unique_id (void *cls,
831 * 822 *
832 */ 823 */
833static void 824static void
834handle_dht_local_get_stop (void *cls, 825handle_dht_local_get_stop(void *cls,
835 const struct GNUNET_DHT_ClientGetStopMessage *dht_stop_msg) 826 const struct GNUNET_DHT_ClientGetStopMessage *dht_stop_msg)
836{ 827{
837 struct ClientHandle *ch = cls; 828 struct ClientHandle *ch = cls;
838 struct RemoveByUniqueIdContext ctx; 829 struct RemoveByUniqueIdContext ctx;
839 830
840 GNUNET_STATISTICS_update (GDS_stats, 831 GNUNET_STATISTICS_update(GDS_stats,
841 gettext_noop 832 gettext_noop
842 ("# GET STOP requests received from clients"), 1, 833 ("# GET STOP requests received from clients"), 1,
843 GNUNET_NO); 834 GNUNET_NO);
844 LOG (GNUNET_ERROR_TYPE_DEBUG, 835 LOG(GNUNET_ERROR_TYPE_DEBUG,
845 "Received GET STOP request for %s from local client %p\n", 836 "Received GET STOP request for %s from local client %p\n",
846 GNUNET_h2s (&dht_stop_msg->key), 837 GNUNET_h2s(&dht_stop_msg->key),
847 ch->client); 838 ch->client);
848 ctx.ch = ch; 839 ctx.ch = ch;
849 ctx.unique_id = dht_stop_msg->unique_id; 840 ctx.unique_id = dht_stop_msg->unique_id;
850 GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, 841 GNUNET_CONTAINER_multihashmap_get_multiple(forward_map,
851 &dht_stop_msg->key, 842 &dht_stop_msg->key,
852 &remove_by_unique_id, 843 &remove_by_unique_id,
853 &ctx); 844 &ctx);
854 GNUNET_SERVICE_client_continue (ch->client); 845 GNUNET_SERVICE_client_continue(ch->client);
855} 846}
856 847
857 848
@@ -863,33 +854,33 @@ handle_dht_local_get_stop (void *cls,
863 * 854 *
864 */ 855 */
865static void 856static void
866handle_dht_local_monitor (void *cls, 857handle_dht_local_monitor(void *cls,
867 const struct GNUNET_DHT_MonitorStartStopMessage *msg) 858 const struct GNUNET_DHT_MonitorStartStopMessage *msg)
868{ 859{
869 struct ClientHandle *ch = cls; 860 struct ClientHandle *ch = cls;
870 struct ClientMonitorRecord *r; 861 struct ClientMonitorRecord *r;
871 862
872 r = GNUNET_new (struct ClientMonitorRecord); 863 r = GNUNET_new(struct ClientMonitorRecord);
873 r->ch = ch; 864 r->ch = ch;
874 r->type = ntohl (msg->type); 865 r->type = ntohl(msg->type);
875 r->get = ntohs (msg->get); 866 r->get = ntohs(msg->get);
876 r->get_resp = ntohs (msg->get_resp); 867 r->get_resp = ntohs(msg->get_resp);
877 r->put = ntohs (msg->put); 868 r->put = ntohs(msg->put);
878 if (0 == ntohs (msg->filter_key)) 869 if (0 == ntohs(msg->filter_key))
879 { 870 {
880 r->key = NULL; 871 r->key = NULL;
881 } 872 }
882 else 873 else
883 { 874 {
884 r->key = GNUNET_new (struct GNUNET_HashCode); 875 r->key = GNUNET_new(struct GNUNET_HashCode);
885 GNUNET_memcpy (r->key, 876 GNUNET_memcpy(r->key,
886 &msg->key, 877 &msg->key,
887 sizeof (struct GNUNET_HashCode)); 878 sizeof(struct GNUNET_HashCode));
888 } 879 }
889 GNUNET_CONTAINER_DLL_insert (monitor_head, 880 GNUNET_CONTAINER_DLL_insert(monitor_head,
890 monitor_tail, 881 monitor_tail,
891 r); 882 r);
892 GNUNET_SERVICE_client_continue (ch->client); 883 GNUNET_SERVICE_client_continue(ch->client);
893} 884}
894 885
895 886
@@ -900,51 +891,49 @@ handle_dht_local_monitor (void *cls,
900 * @param msg the actual message received 891 * @param msg the actual message received
901 */ 892 */
902static void 893static void
903handle_dht_local_monitor_stop (void *cls, 894handle_dht_local_monitor_stop(void *cls,
904 const struct GNUNET_DHT_MonitorStartStopMessage *msg) 895 const struct GNUNET_DHT_MonitorStartStopMessage *msg)
905{ 896{
906 struct ClientHandle *ch = cls; 897 struct ClientHandle *ch = cls;
907 struct ClientMonitorRecord *r; 898 struct ClientMonitorRecord *r;
908 int keys_match; 899 int keys_match;
909 900
910 GNUNET_SERVICE_client_continue (ch->client); 901 GNUNET_SERVICE_client_continue(ch->client);
911 for (r = monitor_head; NULL != r; r = r->next) 902 for (r = monitor_head; NULL != r; r = r->next)
912 {
913 if (NULL == r->key)
914 { 903 {
915 keys_match = (0 == ntohs(msg->filter_key)); 904 if (NULL == r->key)
905 {
906 keys_match = (0 == ntohs(msg->filter_key));
907 }
908 else
909 {
910 keys_match = ((0 != ntohs(msg->filter_key)) &&
911 (!memcmp(r->key,
912 &msg->key,
913 sizeof(struct GNUNET_HashCode))));
914 }
915 if ((ch == r->ch) &&
916 (ntohl(msg->type) == r->type) &&
917 (r->get == msg->get) &&
918 (r->get_resp == msg->get_resp) &&
919 (r->put == msg->put) &&
920 keys_match)
921 {
922 GNUNET_CONTAINER_DLL_remove(monitor_head,
923 monitor_tail,
924 r);
925 GNUNET_free_non_null(r->key);
926 GNUNET_free(r);
927 return; /* Delete only ONE entry */
928 }
916 } 929 }
917 else
918 {
919 keys_match = ( (0 != ntohs(msg->filter_key)) &&
920 (! memcmp (r->key,
921 &msg->key,
922 sizeof(struct GNUNET_HashCode))) );
923 }
924 if ( (ch == r->ch) &&
925 (ntohl(msg->type) == r->type) &&
926 (r->get == msg->get) &&
927 (r->get_resp == msg->get_resp) &&
928 (r->put == msg->put) &&
929 keys_match )
930 {
931 GNUNET_CONTAINER_DLL_remove (monitor_head,
932 monitor_tail,
933 r);
934 GNUNET_free_non_null (r->key);
935 GNUNET_free (r);
936 return; /* Delete only ONE entry */
937 }
938 }
939} 930}
940 931
941 932
942/** 933/**
943 * Closure for #forward_reply() 934 * Closure for #forward_reply()
944 */ 935 */
945struct ForwardReplyContext 936struct ForwardReplyContext {
946{
947
948 /** 937 /**
949 * Expiration time of the reply. 938 * Expiration time of the reply.
950 */ 939 */
@@ -984,7 +973,6 @@ struct ForwardReplyContext
984 * Type of the data. 973 * Type of the data.
985 */ 974 */
986 enum GNUNET_BLOCK_Type type; 975 enum GNUNET_BLOCK_Type type;
987
988}; 976};
989 977
990 978
@@ -1000,9 +988,9 @@ struct ForwardReplyContext
1000 * if the result is mal-formed, #GNUNET_NO 988 * if the result is mal-formed, #GNUNET_NO
1001 */ 989 */
1002static int 990static int
1003forward_reply (void *cls, 991forward_reply(void *cls,
1004 const struct GNUNET_HashCode *key, 992 const struct GNUNET_HashCode *key,
1005 void *value) 993 void *value)
1006{ 994{
1007 struct ForwardReplyContext *frc = cls; 995 struct ForwardReplyContext *frc = cls;
1008 struct ClientQueryRecord *record = value; 996 struct ClientQueryRecord *record = value;
@@ -1013,116 +1001,124 @@ forward_reply (void *cls,
1013 struct GNUNET_HashCode ch; 1001 struct GNUNET_HashCode ch;
1014 struct GNUNET_PeerIdentity *paths; 1002 struct GNUNET_PeerIdentity *paths;
1015 1003
1016 LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, 1004 LOG_TRAFFIC(GNUNET_ERROR_TYPE_DEBUG,
1017 "CLIENT-RESULT %s\n", 1005 "CLIENT-RESULT %s\n",
1018 GNUNET_h2s_full (key)); 1006 GNUNET_h2s_full(key));
1019 if ( (record->type != GNUNET_BLOCK_TYPE_ANY) && 1007 if ((record->type != GNUNET_BLOCK_TYPE_ANY) &&
1020 (record->type != frc->type)) 1008 (record->type != frc->type))
1021 {
1022 LOG (GNUNET_ERROR_TYPE_DEBUG,
1023 "Record type mismatch, not passing request for key %s to local client\n",
1024 GNUNET_h2s (key));
1025 GNUNET_STATISTICS_update (GDS_stats,
1026 gettext_noop
1027 ("# Key match, type mismatches in REPLY to CLIENT"),
1028 1, GNUNET_NO);
1029 return GNUNET_YES; /* type mismatch */
1030 }
1031 GNUNET_CRYPTO_hash (frc->data, frc->data_size, &ch);
1032 for (unsigned int i = 0; i < record->seen_replies_count; i++)
1033 if (0 == memcmp (&record->seen_replies[i],
1034 &ch,
1035 sizeof (struct GNUNET_HashCode)))
1036 { 1009 {
1037 LOG (GNUNET_ERROR_TYPE_DEBUG, 1010 LOG(GNUNET_ERROR_TYPE_DEBUG,
1038 "Duplicate reply, not passing request for key %s to local client\n", 1011 "Record type mismatch, not passing request for key %s to local client\n",
1039 GNUNET_h2s (key)); 1012 GNUNET_h2s(key));
1040 GNUNET_STATISTICS_update (GDS_stats, 1013 GNUNET_STATISTICS_update(GDS_stats,
1041 gettext_noop 1014 gettext_noop
1042 ("# Duplicate REPLIES to CLIENT request dropped"), 1015 ("# Key match, type mismatches in REPLY to CLIENT"),
1043 1, GNUNET_NO); 1016 1, GNUNET_NO);
1044 return GNUNET_YES; /* duplicate */ 1017 return GNUNET_YES; /* type mismatch */
1045 } 1018 }
1019 GNUNET_CRYPTO_hash(frc->data, frc->data_size, &ch);
1020 for (unsigned int i = 0; i < record->seen_replies_count; i++)
1021 if (0 == memcmp(&record->seen_replies[i],
1022 &ch,
1023 sizeof(struct GNUNET_HashCode)))
1024 {
1025 LOG(GNUNET_ERROR_TYPE_DEBUG,
1026 "Duplicate reply, not passing request for key %s to local client\n",
1027 GNUNET_h2s(key));
1028 GNUNET_STATISTICS_update(GDS_stats,
1029 gettext_noop
1030 ("# Duplicate REPLIES to CLIENT request dropped"),
1031 1, GNUNET_NO);
1032 return GNUNET_YES; /* duplicate */
1033 }
1046 eval 1034 eval
1047 = GNUNET_BLOCK_evaluate (GDS_block_context, 1035 = GNUNET_BLOCK_evaluate(GDS_block_context,
1048 record->type, 1036 record->type,
1049 NULL, 1037 NULL,
1050 GNUNET_BLOCK_EO_NONE, 1038 GNUNET_BLOCK_EO_NONE,
1051 key, 1039 key,
1052 record->xquery, 1040 record->xquery,
1053 record->xquery_size, 1041 record->xquery_size,
1054 frc->data, 1042 frc->data,
1055 frc->data_size); 1043 frc->data_size);
1056 LOG (GNUNET_ERROR_TYPE_DEBUG, 1044 LOG(GNUNET_ERROR_TYPE_DEBUG,
1057 "Evaluation result is %d for key %s for local client's query\n", 1045 "Evaluation result is %d for key %s for local client's query\n",
1058 (int) eval, 1046 (int)eval,
1059 GNUNET_h2s (key)); 1047 GNUNET_h2s(key));
1060 switch (eval) 1048 switch (eval)
1061 { 1049 {
1062 case GNUNET_BLOCK_EVALUATION_OK_LAST: 1050 case GNUNET_BLOCK_EVALUATION_OK_LAST:
1063 do_free = GNUNET_YES; 1051 do_free = GNUNET_YES;
1064 break; 1052 break;
1065 case GNUNET_BLOCK_EVALUATION_OK_MORE: 1053
1066 GNUNET_array_append (record->seen_replies, 1054 case GNUNET_BLOCK_EVALUATION_OK_MORE:
1067 record->seen_replies_count, 1055 GNUNET_array_append(record->seen_replies,
1068 ch); 1056 record->seen_replies_count,
1069 do_free = GNUNET_NO; 1057 ch);
1070 break; 1058 do_free = GNUNET_NO;
1071 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: 1059 break;
1072 /* should be impossible to encounter here */ 1060
1073 GNUNET_break (0); 1061 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
1074 return GNUNET_YES; 1062 /* should be impossible to encounter here */
1075 case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: 1063 GNUNET_break(0);
1076 GNUNET_break_op (0); 1064 return GNUNET_YES;
1077 return GNUNET_NO; 1065
1078 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: 1066 case GNUNET_BLOCK_EVALUATION_RESULT_INVALID:
1079 GNUNET_break (0); 1067 GNUNET_break_op(0);
1080 return GNUNET_NO; 1068 return GNUNET_NO;
1081 case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: 1069
1082 GNUNET_break (0); 1070 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
1083 return GNUNET_NO; 1071 GNUNET_break(0);
1084 case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT: 1072 return GNUNET_NO;
1085 return GNUNET_YES; 1073
1086 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: 1074 case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID:
1087 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1075 GNUNET_break(0);
1088 _("Unsupported block type (%u) in request!\n"), record->type); 1076 return GNUNET_NO;
1089 return GNUNET_NO; 1077
1090 default: 1078 case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT:
1091 GNUNET_break (0); 1079 return GNUNET_YES;
1092 return GNUNET_NO; 1080
1093 } 1081 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
1094 GNUNET_STATISTICS_update (GDS_stats, 1082 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1095 gettext_noop ("# RESULTS queued for clients"), 1083 _("Unsupported block type (%u) in request!\n"), record->type);
1096 1, 1084 return GNUNET_NO;
1097 GNUNET_NO); 1085
1098 env = GNUNET_MQ_msg_extra (reply, 1086 default:
1099 frc->data_size + 1087 GNUNET_break(0);
1100 (frc->get_path_length + frc->put_path_length) * sizeof (struct GNUNET_PeerIdentity), 1088 return GNUNET_NO;
1101 GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT); 1089 }
1102 reply->type = htonl (frc->type); 1090 GNUNET_STATISTICS_update(GDS_stats,
1103 reply->get_path_length = htonl (frc->get_path_length); 1091 gettext_noop("# RESULTS queued for clients"),
1104 reply->put_path_length = htonl (frc->put_path_length); 1092 1,
1093 GNUNET_NO);
1094 env = GNUNET_MQ_msg_extra(reply,
1095 frc->data_size +
1096 (frc->get_path_length + frc->put_path_length) * sizeof(struct GNUNET_PeerIdentity),
1097 GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT);
1098 reply->type = htonl(frc->type);
1099 reply->get_path_length = htonl(frc->get_path_length);
1100 reply->put_path_length = htonl(frc->put_path_length);
1105 reply->unique_id = record->unique_id; 1101 reply->unique_id = record->unique_id;
1106 reply->expiration = GNUNET_TIME_absolute_hton (frc->expiration); 1102 reply->expiration = GNUNET_TIME_absolute_hton(frc->expiration);
1107 reply->key = *key; 1103 reply->key = *key;
1108 paths = (struct GNUNET_PeerIdentity *) &reply[1]; 1104 paths = (struct GNUNET_PeerIdentity *)&reply[1];
1109 GNUNET_memcpy (paths, 1105 GNUNET_memcpy(paths,
1110 frc->put_path, 1106 frc->put_path,
1111 sizeof (struct GNUNET_PeerIdentity) * frc->put_path_length); 1107 sizeof(struct GNUNET_PeerIdentity) * frc->put_path_length);
1112 GNUNET_memcpy (&paths[frc->put_path_length], 1108 GNUNET_memcpy(&paths[frc->put_path_length],
1113 frc->get_path, 1109 frc->get_path,
1114 sizeof (struct GNUNET_PeerIdentity) * frc->get_path_length); 1110 sizeof(struct GNUNET_PeerIdentity) * frc->get_path_length);
1115 GNUNET_memcpy (&paths[frc->get_path_length + frc->put_path_length], 1111 GNUNET_memcpy(&paths[frc->get_path_length + frc->put_path_length],
1116 frc->data, 1112 frc->data,
1117 frc->data_size); 1113 frc->data_size);
1118 LOG (GNUNET_ERROR_TYPE_DEBUG, 1114 LOG(GNUNET_ERROR_TYPE_DEBUG,
1119 "Sending reply to query %s for client %p\n", 1115 "Sending reply to query %s for client %p\n",
1120 GNUNET_h2s (key), 1116 GNUNET_h2s(key),
1121 record->ch->client); 1117 record->ch->client);
1122 GNUNET_MQ_send (record->ch->mq, 1118 GNUNET_MQ_send(record->ch->mq,
1123 env); 1119 env);
1124 if (GNUNET_YES == do_free) 1120 if (GNUNET_YES == do_free)
1125 remove_client_record (record); 1121 remove_client_record(record);
1126 return GNUNET_YES; 1122 return GNUNET_YES;
1127} 1123}
1128 1124
@@ -1143,38 +1139,38 @@ forward_reply (void *cls,
1143 * @param data application payload data 1139 * @param data application payload data
1144 */ 1140 */
1145void 1141void
1146GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, 1142GDS_CLIENTS_handle_reply(struct GNUNET_TIME_Absolute expiration,
1147 const struct GNUNET_HashCode *key, 1143 const struct GNUNET_HashCode *key,
1148 unsigned int get_path_length, 1144 unsigned int get_path_length,
1149 const struct GNUNET_PeerIdentity *get_path, 1145 const struct GNUNET_PeerIdentity *get_path,
1150 unsigned int put_path_length, 1146 unsigned int put_path_length,
1151 const struct GNUNET_PeerIdentity *put_path, 1147 const struct GNUNET_PeerIdentity *put_path,
1152 enum GNUNET_BLOCK_Type type, 1148 enum GNUNET_BLOCK_Type type,
1153 size_t data_size, 1149 size_t data_size,
1154 const void *data) 1150 const void *data)
1155{ 1151{
1156 struct ForwardReplyContext frc; 1152 struct ForwardReplyContext frc;
1157 size_t msize; 1153 size_t msize;
1158 1154
1159 msize = sizeof (struct GNUNET_DHT_ClientResultMessage) + data_size + 1155 msize = sizeof(struct GNUNET_DHT_ClientResultMessage) + data_size +
1160 (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity); 1156 (get_path_length + put_path_length) * sizeof(struct GNUNET_PeerIdentity);
1161 if (msize >= GNUNET_MAX_MESSAGE_SIZE) 1157 if (msize >= GNUNET_MAX_MESSAGE_SIZE)
1162 { 1158 {
1163 GNUNET_break (0); 1159 GNUNET_break(0);
1164 return; 1160 return;
1165 } 1161 }
1166 if (NULL == GNUNET_CONTAINER_multihashmap_get (forward_map, 1162 if (NULL == GNUNET_CONTAINER_multihashmap_get(forward_map,
1167 key)) 1163 key))
1168 { 1164 {
1169 LOG (GNUNET_ERROR_TYPE_DEBUG, 1165 LOG(GNUNET_ERROR_TYPE_DEBUG,
1170 "No matching client for reply for key %s\n", 1166 "No matching client for reply for key %s\n",
1171 GNUNET_h2s (key)); 1167 GNUNET_h2s(key));
1172 GNUNET_STATISTICS_update (GDS_stats, 1168 GNUNET_STATISTICS_update(GDS_stats,
1173 gettext_noop ("# REPLIES ignored for CLIENTS (no match)"), 1169 gettext_noop("# REPLIES ignored for CLIENTS (no match)"),
1174 1, 1170 1,
1175 GNUNET_NO); 1171 GNUNET_NO);
1176 return; /* no matching request, fast exit! */ 1172 return; /* no matching request, fast exit! */
1177 } 1173 }
1178 frc.expiration = expiration; 1174 frc.expiration = expiration;
1179 frc.get_path = get_path; 1175 frc.get_path = get_path;
1180 frc.put_path = put_path; 1176 frc.put_path = put_path;
@@ -1183,14 +1179,13 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration,
1183 frc.get_path_length = get_path_length; 1179 frc.get_path_length = get_path_length;
1184 frc.put_path_length = put_path_length; 1180 frc.put_path_length = put_path_length;
1185 frc.type = type; 1181 frc.type = type;
1186 LOG (GNUNET_ERROR_TYPE_DEBUG, 1182 LOG(GNUNET_ERROR_TYPE_DEBUG,
1187 "Forwarding reply for key %s to client\n", 1183 "Forwarding reply for key %s to client\n",
1188 GNUNET_h2s (key)); 1184 GNUNET_h2s(key));
1189 GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, 1185 GNUNET_CONTAINER_multihashmap_get_multiple(forward_map,
1190 key, 1186 key,
1191 &forward_reply, 1187 &forward_reply,
1192 &frc); 1188 &frc);
1193
1194} 1189}
1195 1190
1196 1191
@@ -1207,13 +1202,13 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration,
1207 * @param key Key of the requested data. 1202 * @param key Key of the requested data.
1208 */ 1203 */
1209void 1204void
1210GDS_CLIENTS_process_get (uint32_t options, 1205GDS_CLIENTS_process_get(uint32_t options,
1211 enum GNUNET_BLOCK_Type type, 1206 enum GNUNET_BLOCK_Type type,
1212 uint32_t hop_count, 1207 uint32_t hop_count,
1213 uint32_t desired_replication_level, 1208 uint32_t desired_replication_level,
1214 unsigned int path_length, 1209 unsigned int path_length,
1215 const struct GNUNET_PeerIdentity *path, 1210 const struct GNUNET_PeerIdentity *path,
1216 const struct GNUNET_HashCode * key) 1211 const struct GNUNET_HashCode * key)
1217{ 1212{
1218 struct ClientMonitorRecord *m; 1213 struct ClientMonitorRecord *m;
1219 struct ClientHandle **cl; 1214 struct ClientHandle **cl;
@@ -1222,49 +1217,49 @@ GDS_CLIENTS_process_get (uint32_t options,
1222 cl = NULL; 1217 cl = NULL;
1223 cl_size = 0; 1218 cl_size = 0;
1224 for (m = monitor_head; NULL != m; m = m->next) 1219 for (m = monitor_head; NULL != m; m = m->next)
1225 {
1226 if ( ( (GNUNET_BLOCK_TYPE_ANY == m->type) ||
1227 (m->type == type) ) &&
1228 ( (NULL == m->key) ||
1229 (0 == memcmp (key,
1230 m->key,
1231 sizeof(struct GNUNET_HashCode))) ) )
1232 { 1220 {
1233 struct GNUNET_MQ_Envelope *env; 1221 if (((GNUNET_BLOCK_TYPE_ANY == m->type) ||
1234 struct GNUNET_DHT_MonitorGetMessage *mmsg; 1222 (m->type == type)) &&
1235 struct GNUNET_PeerIdentity *msg_path; 1223 ((NULL == m->key) ||
1236 size_t msize; 1224 (0 == memcmp(key,
1237 unsigned int i; 1225 m->key,
1238 1226 sizeof(struct GNUNET_HashCode)))))
1239 /* Don't send duplicates */ 1227 {
1240 for (i = 0; i < cl_size; i++) 1228 struct GNUNET_MQ_Envelope *env;
1241 if (cl[i] == m->ch) 1229 struct GNUNET_DHT_MonitorGetMessage *mmsg;
1242 break; 1230 struct GNUNET_PeerIdentity *msg_path;
1243 if (i < cl_size) 1231 size_t msize;
1244 continue; 1232 unsigned int i;
1245 GNUNET_array_append (cl, 1233
1246 cl_size, 1234 /* Don't send duplicates */
1247 m->ch); 1235 for (i = 0; i < cl_size; i++)
1248 1236 if (cl[i] == m->ch)
1249 msize = path_length * sizeof (struct GNUNET_PeerIdentity); 1237 break;
1250 env = GNUNET_MQ_msg_extra (mmsg, 1238 if (i < cl_size)
1251 msize, 1239 continue;
1252 GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET); 1240 GNUNET_array_append(cl,
1253 mmsg->options = htonl(options); 1241 cl_size,
1254 mmsg->type = htonl(type); 1242 m->ch);
1255 mmsg->hop_count = htonl(hop_count); 1243
1256 mmsg->desired_replication_level = htonl(desired_replication_level); 1244 msize = path_length * sizeof(struct GNUNET_PeerIdentity);
1257 mmsg->get_path_length = htonl(path_length); 1245 env = GNUNET_MQ_msg_extra(mmsg,
1258 mmsg->key = *key; 1246 msize,
1259 msg_path = (struct GNUNET_PeerIdentity *) &mmsg[1]; 1247 GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET);
1260 GNUNET_memcpy (msg_path, 1248 mmsg->options = htonl(options);
1261 path, 1249 mmsg->type = htonl(type);
1262 path_length * sizeof (struct GNUNET_PeerIdentity)); 1250 mmsg->hop_count = htonl(hop_count);
1263 GNUNET_MQ_send (m->ch->mq, 1251 mmsg->desired_replication_level = htonl(desired_replication_level);
1264 env); 1252 mmsg->get_path_length = htonl(path_length);
1253 mmsg->key = *key;
1254 msg_path = (struct GNUNET_PeerIdentity *)&mmsg[1];
1255 GNUNET_memcpy(msg_path,
1256 path,
1257 path_length * sizeof(struct GNUNET_PeerIdentity));
1258 GNUNET_MQ_send(m->ch->mq,
1259 env);
1260 }
1265 } 1261 }
1266 } 1262 GNUNET_free_non_null(cl);
1267 GNUNET_free_non_null (cl);
1268} 1263}
1269 1264
1270 1265
@@ -1283,15 +1278,15 @@ GDS_CLIENTS_process_get (uint32_t options,
1283 * @param size Number of bytes in @a data. 1278 * @param size Number of bytes in @a data.
1284 */ 1279 */
1285void 1280void
1286GDS_CLIENTS_process_get_resp (enum GNUNET_BLOCK_Type type, 1281GDS_CLIENTS_process_get_resp(enum GNUNET_BLOCK_Type type,
1287 const struct GNUNET_PeerIdentity *get_path, 1282 const struct GNUNET_PeerIdentity *get_path,
1288 unsigned int get_path_length, 1283 unsigned int get_path_length,
1289 const struct GNUNET_PeerIdentity *put_path, 1284 const struct GNUNET_PeerIdentity *put_path,
1290 unsigned int put_path_length, 1285 unsigned int put_path_length,
1291 struct GNUNET_TIME_Absolute exp, 1286 struct GNUNET_TIME_Absolute exp,
1292 const struct GNUNET_HashCode * key, 1287 const struct GNUNET_HashCode * key,
1293 const void *data, 1288 const void *data,
1294 size_t size) 1289 size_t size)
1295{ 1290{
1296 struct ClientMonitorRecord *m; 1291 struct ClientMonitorRecord *m;
1297 struct ClientHandle **cl; 1292 struct ClientHandle **cl;
@@ -1300,53 +1295,53 @@ GDS_CLIENTS_process_get_resp (enum GNUNET_BLOCK_Type type,
1300 cl = NULL; 1295 cl = NULL;
1301 cl_size = 0; 1296 cl_size = 0;
1302 for (m = monitor_head; NULL != m; m = m->next) 1297 for (m = monitor_head; NULL != m; m = m->next)
1303 {
1304 if ((GNUNET_BLOCK_TYPE_ANY == m->type || m->type == type) &&
1305 (NULL == m->key ||
1306 memcmp (key, m->key, sizeof(struct GNUNET_HashCode)) == 0))
1307 { 1298 {
1308 struct GNUNET_MQ_Envelope *env; 1299 if ((GNUNET_BLOCK_TYPE_ANY == m->type || m->type == type) &&
1309 struct GNUNET_DHT_MonitorGetRespMessage *mmsg; 1300 (NULL == m->key ||
1310 struct GNUNET_PeerIdentity *path; 1301 memcmp(key, m->key, sizeof(struct GNUNET_HashCode)) == 0))
1311 size_t msize; 1302 {
1312 unsigned int i; 1303 struct GNUNET_MQ_Envelope *env;
1313 1304 struct GNUNET_DHT_MonitorGetRespMessage *mmsg;
1314 /* Don't send duplicates */ 1305 struct GNUNET_PeerIdentity *path;
1315 for (i = 0; i < cl_size; i++) 1306 size_t msize;
1316 if (cl[i] == m->ch) 1307 unsigned int i;
1317 break; 1308
1318 if (i < cl_size) 1309 /* Don't send duplicates */
1319 continue; 1310 for (i = 0; i < cl_size; i++)
1320 GNUNET_array_append (cl, 1311 if (cl[i] == m->ch)
1321 cl_size, 1312 break;
1322 m->ch); 1313 if (i < cl_size)
1323 1314 continue;
1324 msize = size; 1315 GNUNET_array_append(cl,
1325 msize += (get_path_length + put_path_length) 1316 cl_size,
1326 * sizeof (struct GNUNET_PeerIdentity); 1317 m->ch);
1327 env = GNUNET_MQ_msg_extra (mmsg, 1318
1328 msize, 1319 msize = size;
1329 GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET_RESP); 1320 msize += (get_path_length + put_path_length)
1330 mmsg->type = htonl(type); 1321 * sizeof(struct GNUNET_PeerIdentity);
1331 mmsg->put_path_length = htonl(put_path_length); 1322 env = GNUNET_MQ_msg_extra(mmsg,
1332 mmsg->get_path_length = htonl(get_path_length); 1323 msize,
1333 mmsg->expiration_time = GNUNET_TIME_absolute_hton(exp); 1324 GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET_RESP);
1334 mmsg->key = *key; 1325 mmsg->type = htonl(type);
1335 path = (struct GNUNET_PeerIdentity *) &mmsg[1]; 1326 mmsg->put_path_length = htonl(put_path_length);
1336 GNUNET_memcpy (path, 1327 mmsg->get_path_length = htonl(get_path_length);
1337 put_path, 1328 mmsg->expiration_time = GNUNET_TIME_absolute_hton(exp);
1338 put_path_length * sizeof (struct GNUNET_PeerIdentity)); 1329 mmsg->key = *key;
1339 GNUNET_memcpy (path, 1330 path = (struct GNUNET_PeerIdentity *)&mmsg[1];
1340 get_path, 1331 GNUNET_memcpy(path,
1341 get_path_length * sizeof (struct GNUNET_PeerIdentity)); 1332 put_path,
1342 GNUNET_memcpy (&path[get_path_length], 1333 put_path_length * sizeof(struct GNUNET_PeerIdentity));
1343 data, 1334 GNUNET_memcpy(path,
1344 size); 1335 get_path,
1345 GNUNET_MQ_send (m->ch->mq, 1336 get_path_length * sizeof(struct GNUNET_PeerIdentity));
1346 env); 1337 GNUNET_memcpy(&path[get_path_length],
1338 data,
1339 size);
1340 GNUNET_MQ_send(m->ch->mq,
1341 env);
1342 }
1347 } 1343 }
1348 } 1344 GNUNET_free_non_null(cl);
1349 GNUNET_free_non_null (cl);
1350} 1345}
1351 1346
1352 1347
@@ -1366,16 +1361,16 @@ GDS_CLIENTS_process_get_resp (enum GNUNET_BLOCK_Type type,
1366 * @param size Number of bytes in data. 1361 * @param size Number of bytes in data.
1367 */ 1362 */
1368void 1363void
1369GDS_CLIENTS_process_put (uint32_t options, 1364GDS_CLIENTS_process_put(uint32_t options,
1370 enum GNUNET_BLOCK_Type type, 1365 enum GNUNET_BLOCK_Type type,
1371 uint32_t hop_count, 1366 uint32_t hop_count,
1372 uint32_t desired_replication_level, 1367 uint32_t desired_replication_level,
1373 unsigned int path_length, 1368 unsigned int path_length,
1374 const struct GNUNET_PeerIdentity *path, 1369 const struct GNUNET_PeerIdentity *path,
1375 struct GNUNET_TIME_Absolute exp, 1370 struct GNUNET_TIME_Absolute exp,
1376 const struct GNUNET_HashCode *key, 1371 const struct GNUNET_HashCode *key,
1377 const void *data, 1372 const void *data,
1378 size_t size) 1373 size_t size)
1379{ 1374{
1380 struct ClientMonitorRecord *m; 1375 struct ClientMonitorRecord *m;
1381 struct ClientHandle **cl; 1376 struct ClientHandle **cl;
@@ -1384,51 +1379,51 @@ GDS_CLIENTS_process_put (uint32_t options,
1384 cl = NULL; 1379 cl = NULL;
1385 cl_size = 0; 1380 cl_size = 0;
1386 for (m = monitor_head; NULL != m; m = m->next) 1381 for (m = monitor_head; NULL != m; m = m->next)
1387 {
1388 if ((GNUNET_BLOCK_TYPE_ANY == m->type || m->type == type) &&
1389 (NULL == m->key ||
1390 memcmp (key, m->key, sizeof(struct GNUNET_HashCode)) == 0))
1391 { 1382 {
1392 struct GNUNET_MQ_Envelope *env; 1383 if ((GNUNET_BLOCK_TYPE_ANY == m->type || m->type == type) &&
1393 struct GNUNET_DHT_MonitorPutMessage *mmsg; 1384 (NULL == m->key ||
1394 struct GNUNET_PeerIdentity *msg_path; 1385 memcmp(key, m->key, sizeof(struct GNUNET_HashCode)) == 0))
1395 size_t msize; 1386 {
1396 unsigned int i; 1387 struct GNUNET_MQ_Envelope *env;
1397 1388 struct GNUNET_DHT_MonitorPutMessage *mmsg;
1398 /* Don't send duplicates */ 1389 struct GNUNET_PeerIdentity *msg_path;
1399 for (i = 0; i < cl_size; i++) 1390 size_t msize;
1400 if (cl[i] == m->ch) 1391 unsigned int i;
1401 break; 1392
1402 if (i < cl_size) 1393 /* Don't send duplicates */
1403 continue; 1394 for (i = 0; i < cl_size; i++)
1404 GNUNET_array_append (cl, 1395 if (cl[i] == m->ch)
1405 cl_size, 1396 break;
1406 m->ch); 1397 if (i < cl_size)
1407 1398 continue;
1408 msize = size; 1399 GNUNET_array_append(cl,
1409 msize += path_length * sizeof (struct GNUNET_PeerIdentity); 1400 cl_size,
1410 env = GNUNET_MQ_msg_extra (mmsg, 1401 m->ch);
1411 msize, 1402
1412 GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT); 1403 msize = size;
1413 mmsg->options = htonl(options); 1404 msize += path_length * sizeof(struct GNUNET_PeerIdentity);
1414 mmsg->type = htonl(type); 1405 env = GNUNET_MQ_msg_extra(mmsg,
1415 mmsg->hop_count = htonl(hop_count); 1406 msize,
1416 mmsg->desired_replication_level = htonl (desired_replication_level); 1407 GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT);
1417 mmsg->put_path_length = htonl (path_length); 1408 mmsg->options = htonl(options);
1418 mmsg->key = *key; 1409 mmsg->type = htonl(type);
1419 mmsg->expiration_time = GNUNET_TIME_absolute_hton (exp); 1410 mmsg->hop_count = htonl(hop_count);
1420 msg_path = (struct GNUNET_PeerIdentity *) &mmsg[1]; 1411 mmsg->desired_replication_level = htonl(desired_replication_level);
1421 GNUNET_memcpy (msg_path, 1412 mmsg->put_path_length = htonl(path_length);
1422 path, 1413 mmsg->key = *key;
1423 path_length * sizeof (struct GNUNET_PeerIdentity)); 1414 mmsg->expiration_time = GNUNET_TIME_absolute_hton(exp);
1424 GNUNET_memcpy (&msg_path[path_length], 1415 msg_path = (struct GNUNET_PeerIdentity *)&mmsg[1];
1425 data, 1416 GNUNET_memcpy(msg_path,
1426 size); 1417 path,
1427 GNUNET_MQ_send (m->ch->mq, 1418 path_length * sizeof(struct GNUNET_PeerIdentity));
1428 env); 1419 GNUNET_memcpy(&msg_path[path_length],
1420 data,
1421 size);
1422 GNUNET_MQ_send(m->ch->mq,
1423 env);
1424 }
1429 } 1425 }
1430 } 1426 GNUNET_free_non_null(cl);
1431 GNUNET_free_non_null (cl);
1432} 1427}
1433 1428
1434 1429
@@ -1438,13 +1433,13 @@ GDS_CLIENTS_process_put (uint32_t options,
1438 * @param server the initialized server 1433 * @param server the initialized server
1439 */ 1434 */
1440static void 1435static void
1441GDS_CLIENTS_init () 1436GDS_CLIENTS_init()
1442{ 1437{
1443 forward_map 1438 forward_map
1444 = GNUNET_CONTAINER_multihashmap_create (1024, 1439 = GNUNET_CONTAINER_multihashmap_create(1024,
1445 GNUNET_YES); 1440 GNUNET_YES);
1446 retry_heap 1441 retry_heap
1447 = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 1442 = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN);
1448} 1443}
1449 1444
1450 1445
@@ -1452,13 +1447,13 @@ GDS_CLIENTS_init ()
1452 * Shutdown client subsystem. 1447 * Shutdown client subsystem.
1453 */ 1448 */
1454static void 1449static void
1455GDS_CLIENTS_stop () 1450GDS_CLIENTS_stop()
1456{ 1451{
1457 if (NULL != retry_task) 1452 if (NULL != retry_task)
1458 { 1453 {
1459 GNUNET_SCHEDULER_cancel (retry_task); 1454 GNUNET_SCHEDULER_cancel(retry_task);
1460 retry_task = NULL; 1455 retry_task = NULL;
1461 } 1456 }
1462} 1457}
1463 1458
1464 1459
@@ -1468,59 +1463,59 @@ GDS_CLIENTS_stop ()
1468 * @param name name of the service, i.e. "dht" or "xdht" 1463 * @param name name of the service, i.e. "dht" or "xdht"
1469 * @param run name of the initializaton method for the service 1464 * @param run name of the initializaton method for the service
1470 */ 1465 */
1471#define GDS_DHT_SERVICE_INIT(name,run) \ 1466#define GDS_DHT_SERVICE_INIT(name, run) \
1472 GNUNET_SERVICE_MAIN \ 1467 GNUNET_SERVICE_MAIN \
1473 (name, \ 1468 (name, \
1474 GNUNET_SERVICE_OPTION_NONE, \ 1469 GNUNET_SERVICE_OPTION_NONE, \
1475 run, \ 1470 run, \
1476 &client_connect_cb, \ 1471 &client_connect_cb, \
1477 &client_disconnect_cb, \ 1472 &client_disconnect_cb, \
1478 NULL, \ 1473 NULL, \
1479 GNUNET_MQ_hd_var_size (dht_local_put, \ 1474 GNUNET_MQ_hd_var_size(dht_local_put, \
1480 GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT, \ 1475 GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT, \
1481 struct GNUNET_DHT_ClientPutMessage, \ 1476 struct GNUNET_DHT_ClientPutMessage, \
1482 NULL), \ 1477 NULL), \
1483 GNUNET_MQ_hd_var_size (dht_local_get, \ 1478 GNUNET_MQ_hd_var_size(dht_local_get, \
1484 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET, \ 1479 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET, \
1485 struct GNUNET_DHT_ClientGetMessage, \ 1480 struct GNUNET_DHT_ClientGetMessage, \
1486 NULL), \
1487 GNUNET_MQ_hd_fixed_size (dht_local_get_stop, \
1488 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP, \
1489 struct GNUNET_DHT_ClientGetStopMessage, \
1490 NULL), \ 1481 NULL), \
1491 GNUNET_MQ_hd_fixed_size (dht_local_monitor, \ 1482 GNUNET_MQ_hd_fixed_size(dht_local_get_stop, \
1492 GNUNET_MESSAGE_TYPE_DHT_MONITOR_START, \ 1483 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP, \
1493 struct GNUNET_DHT_MonitorStartStopMessage, \ 1484 struct GNUNET_DHT_ClientGetStopMessage, \
1494 NULL), \ 1485 NULL), \
1495 GNUNET_MQ_hd_fixed_size (dht_local_monitor_stop, \ 1486 GNUNET_MQ_hd_fixed_size(dht_local_monitor, \
1496 GNUNET_MESSAGE_TYPE_DHT_MONITOR_STOP, \ 1487 GNUNET_MESSAGE_TYPE_DHT_MONITOR_START, \
1497 struct GNUNET_DHT_MonitorStartStopMessage, \ 1488 struct GNUNET_DHT_MonitorStartStopMessage, \
1498 NULL), \ 1489 NULL), \
1499 GNUNET_MQ_hd_var_size (dht_local_get_result_seen, \ 1490 GNUNET_MQ_hd_fixed_size(dht_local_monitor_stop, \
1500 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN, \ 1491 GNUNET_MESSAGE_TYPE_DHT_MONITOR_STOP, \
1501 struct GNUNET_DHT_ClientGetResultSeenMessage , \ 1492 struct GNUNET_DHT_MonitorStartStopMessage, \
1502 NULL), \ 1493 NULL), \
1503 GNUNET_MQ_handler_end ()) 1494 GNUNET_MQ_hd_var_size(dht_local_get_result_seen, \
1495 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN, \
1496 struct GNUNET_DHT_ClientGetResultSeenMessage, \
1497 NULL), \
1498 GNUNET_MQ_handler_end())
1504 1499
1505 1500
1506/** 1501/**
1507 * MINIMIZE heap size (way below 128k) since this process doesn't need much. 1502 * MINIMIZE heap size (way below 128k) since this process doesn't need much.
1508 */ 1503 */
1509void __attribute__ ((destructor)) 1504void __attribute__ ((destructor))
1510GDS_CLIENTS_done () 1505GDS_CLIENTS_done()
1511{ 1506{
1512 if (NULL != retry_heap) 1507 if (NULL != retry_heap)
1513 { 1508 {
1514 GNUNET_assert (0 == GNUNET_CONTAINER_heap_get_size (retry_heap)); 1509 GNUNET_assert(0 == GNUNET_CONTAINER_heap_get_size(retry_heap));
1515 GNUNET_CONTAINER_heap_destroy (retry_heap); 1510 GNUNET_CONTAINER_heap_destroy(retry_heap);
1516 retry_heap = NULL; 1511 retry_heap = NULL;
1517 } 1512 }
1518 if (NULL != forward_map) 1513 if (NULL != forward_map)
1519 { 1514 {
1520 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (forward_map)); 1515 GNUNET_assert(0 == GNUNET_CONTAINER_multihashmap_size(forward_map));
1521 GNUNET_CONTAINER_multihashmap_destroy (forward_map); 1516 GNUNET_CONTAINER_multihashmap_destroy(forward_map);
1522 forward_map = NULL; 1517 forward_map = NULL;
1523 } 1518 }
1524} 1519}
1525 1520
1526/* end of gnunet-service-dht_clients.c */ 1521/* end of gnunet-service-dht_clients.c */
diff --git a/src/dht/gnunet-service-dht_datacache.c b/src/dht/gnunet-service-dht_datacache.c
index da71e3fb7..e52dc27bf 100644
--- a/src/dht/gnunet-service-dht_datacache.c
+++ b/src/dht/gnunet-service-dht_datacache.c
@@ -11,12 +11,12 @@
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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file dht/gnunet-service-dht_datacache.c 21 * @file dht/gnunet-service-dht_datacache.c
22 * @brief GNUnet DHT service's datacache integration 22 * @brief GNUnet DHT service's datacache integration
@@ -30,7 +30,7 @@
30#include "gnunet-service-dht_routing.h" 30#include "gnunet-service-dht_routing.h"
31#include "gnunet-service-dht.h" 31#include "gnunet-service-dht.h"
32 32
33#define LOG(kind,...) GNUNET_log_from (kind, "dht-dhtcache",__VA_ARGS__) 33#define LOG(kind, ...) GNUNET_log_from(kind, "dht-dhtcache", __VA_ARGS__)
34 34
35/** 35/**
36 * How many "closest" results to we return for migration when 36 * How many "closest" results to we return for migration when
@@ -57,56 +57,55 @@ static struct GNUNET_DATACACHE_Handle *datacache;
57 * @param data application payload data 57 * @param data application payload data
58 */ 58 */
59void 59void
60GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration, 60GDS_DATACACHE_handle_put(struct GNUNET_TIME_Absolute expiration,
61 const struct GNUNET_HashCode *key, 61 const struct GNUNET_HashCode *key,
62 unsigned int put_path_length, 62 unsigned int put_path_length,
63 const struct GNUNET_PeerIdentity *put_path, 63 const struct GNUNET_PeerIdentity *put_path,
64 enum GNUNET_BLOCK_Type type, 64 enum GNUNET_BLOCK_Type type,
65 size_t data_size, 65 size_t data_size,
66 const void *data) 66 const void *data)
67{ 67{
68 int r; 68 int r;
69 69
70 if (NULL == datacache) 70 if (NULL == datacache)
71 { 71 {
72 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 72 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
73 _("%s request received, but have no datacache!\n"), "PUT"); 73 _("%s request received, but have no datacache!\n"), "PUT");
74 return; 74 return;
75 } 75 }
76 if (data_size >= GNUNET_MAX_MESSAGE_SIZE) 76 if (data_size >= GNUNET_MAX_MESSAGE_SIZE)
77 { 77 {
78 GNUNET_break (0); 78 GNUNET_break(0);
79 return; 79 return;
80 } 80 }
81 /* Put size is actual data size plus struct overhead plus path length (if any) */ 81 /* Put size is actual data size plus struct overhead plus path length (if any) */
82 GNUNET_STATISTICS_update (GDS_stats, 82 GNUNET_STATISTICS_update(GDS_stats,
83 gettext_noop ("# ITEMS stored in datacache"), 83 gettext_noop("# ITEMS stored in datacache"),
84 1, 84 1,
85 GNUNET_NO); 85 GNUNET_NO);
86 r = GNUNET_DATACACHE_put (datacache, 86 r = GNUNET_DATACACHE_put(datacache,
87 key, 87 key,
88 GNUNET_CRYPTO_hash_matching_bits (key, 88 GNUNET_CRYPTO_hash_matching_bits(key,
89 &my_identity_hash), 89 &my_identity_hash),
90 data_size, 90 data_size,
91 data, 91 data,
92 type, 92 type,
93 expiration, 93 expiration,
94 put_path_length, 94 put_path_length,
95 put_path); 95 put_path);
96 LOG (GNUNET_ERROR_TYPE_DEBUG, 96 LOG(GNUNET_ERROR_TYPE_DEBUG,
97 "DATACACHE PUT for key %s [%u] completed (%d) after %u hops\n", 97 "DATACACHE PUT for key %s [%u] completed (%d) after %u hops\n",
98 GNUNET_h2s (key), 98 GNUNET_h2s(key),
99 data_size, 99 data_size,
100 r, 100 r,
101 put_path_length); 101 put_path_length);
102} 102}
103 103
104 104
105/** 105/**
106 * Context containing information about a GET request. 106 * Context containing information about a GET request.
107 */ 107 */
108struct GetRequestContext 108struct GetRequestContext {
109{
110 /** 109 /**
111 * extended query (see gnunet_block_lib.h). 110 * extended query (see gnunet_block_lib.h).
112 */ 111 */
@@ -141,7 +140,6 @@ struct GetRequestContext
141 * Return value to give back. 140 * Return value to give back.
142 */ 141 */
143 enum GNUNET_BLOCK_EvaluationResult eval; 142 enum GNUNET_BLOCK_EvaluationResult eval;
144
145}; 143};
146 144
147 145
@@ -160,94 +158,100 @@ struct GetRequestContext
160 * to stop iteration. 158 * to stop iteration.
161 */ 159 */
162static int 160static int
163datacache_get_iterator (void *cls, 161datacache_get_iterator(void *cls,
164 const struct GNUNET_HashCode *key, 162 const struct GNUNET_HashCode *key,
165 size_t data_size, 163 size_t data_size,
166 const char *data, 164 const char *data,
167 enum GNUNET_BLOCK_Type type, 165 enum GNUNET_BLOCK_Type type,
168 struct GNUNET_TIME_Absolute exp, 166 struct GNUNET_TIME_Absolute exp,
169 unsigned int put_path_length, 167 unsigned int put_path_length,
170 const struct GNUNET_PeerIdentity *put_path) 168 const struct GNUNET_PeerIdentity *put_path)
171{ 169{
172 static char non_null; 170 static char non_null;
173 struct GetRequestContext *ctx = cls; 171 struct GetRequestContext *ctx = cls;
174 enum GNUNET_BLOCK_EvaluationResult eval; 172 enum GNUNET_BLOCK_EvaluationResult eval;
175 173
176 if (0 == GNUNET_TIME_absolute_get_remaining (exp).rel_value_us) 174 if (0 == GNUNET_TIME_absolute_get_remaining(exp).rel_value_us)
177 { 175 {
178 GNUNET_break (0); /* why does datacache return expired values? */ 176 GNUNET_break(0); /* why does datacache return expired values? */
179 return GNUNET_OK; /* skip expired record */ 177 return GNUNET_OK; /* skip expired record */
180 } 178 }
181 if ( (NULL == data) && 179 if ((NULL == data) &&
182 (0 == data_size) ) 180 (0 == data_size))
183 data = &non_null; /* point anywhere, but not to NULL */ 181 data = &non_null; /* point anywhere, but not to NULL */
184 182
185 eval 183 eval
186 = GNUNET_BLOCK_evaluate (GDS_block_context, 184 = GNUNET_BLOCK_evaluate(GDS_block_context,
187 type, 185 type,
188 ctx->bg, 186 ctx->bg,
189 GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO, 187 GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO,
190 key, 188 key,
191 ctx->xquery, 189 ctx->xquery,
192 ctx->xquery_size, 190 ctx->xquery_size,
193 data, 191 data,
194 data_size); 192 data_size);
195 LOG (GNUNET_ERROR_TYPE_DEBUG, 193 LOG(GNUNET_ERROR_TYPE_DEBUG,
196 "Found reply for query %s in datacache, evaluation result is %d\n", 194 "Found reply for query %s in datacache, evaluation result is %d\n",
197 GNUNET_h2s (key), 195 GNUNET_h2s(key),
198 (int) eval); 196 (int)eval);
199 ctx->eval = eval; 197 ctx->eval = eval;
200 switch (eval) 198 switch (eval)
201 { 199 {
202 case GNUNET_BLOCK_EVALUATION_OK_MORE: 200 case GNUNET_BLOCK_EVALUATION_OK_MORE:
203 case GNUNET_BLOCK_EVALUATION_OK_LAST: 201 case GNUNET_BLOCK_EVALUATION_OK_LAST:
204 /* forward to local clients */ 202 /* forward to local clients */
205 GNUNET_STATISTICS_update (GDS_stats, 203 GNUNET_STATISTICS_update(GDS_stats,
206 gettext_noop 204 gettext_noop
207 ("# Good RESULTS found in datacache"), 1, 205 ("# Good RESULTS found in datacache"), 1,
208 GNUNET_NO); 206 GNUNET_NO);
209 ctx->gc (ctx->gc_cls, 207 ctx->gc(ctx->gc_cls,
210 type, 208 type,
211 exp, 209 exp,
212 key, 210 key,
213 put_path_length, put_path, 211 put_path_length, put_path,
214 0, NULL, 212 0, NULL,
215 data, data_size); 213 data, data_size);
216 break; 214 break;
217 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: 215
218 GNUNET_STATISTICS_update (GDS_stats, 216 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
219 gettext_noop ("# Duplicate RESULTS found in datacache"), 217 GNUNET_STATISTICS_update(GDS_stats,
220 1, 218 gettext_noop("# Duplicate RESULTS found in datacache"),
221 GNUNET_NO); 219 1,
222 break; 220 GNUNET_NO);
223 case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: 221 break;
224 GNUNET_STATISTICS_update (GDS_stats, 222
225 gettext_noop ("# Invalid RESULTS found in datacache"), 223 case GNUNET_BLOCK_EVALUATION_RESULT_INVALID:
226 1, 224 GNUNET_STATISTICS_update(GDS_stats,
227 GNUNET_NO); 225 gettext_noop("# Invalid RESULTS found in datacache"),
228 break; 226 1,
229 case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT: 227 GNUNET_NO);
230 GNUNET_STATISTICS_update (GDS_stats, 228 break;
231 gettext_noop ("# Irrelevant RESULTS found in datacache"), 229
232 1, 230 case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT:
233 GNUNET_NO); 231 GNUNET_STATISTICS_update(GDS_stats,
234 break; 232 gettext_noop("# Irrelevant RESULTS found in datacache"),
235 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: 233 1,
236 GNUNET_break (0); 234 GNUNET_NO);
237 break; 235 break;
238 case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: 236
239 GNUNET_break_op (0); 237 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
240 return GNUNET_SYSERR; 238 GNUNET_break(0);
241 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: 239 break;
242 GNUNET_STATISTICS_update (GDS_stats, 240
243 gettext_noop ("# Unsupported RESULTS found in datacache"), 241 case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID:
244 1, 242 GNUNET_break_op(0);
245 GNUNET_NO); 243 return GNUNET_SYSERR;
246 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 244
247 _("Unsupported block type (%u) in local response!\n"), 245 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
248 type); 246 GNUNET_STATISTICS_update(GDS_stats,
249 break; 247 gettext_noop("# Unsupported RESULTS found in datacache"),
250 } 248 1,
249 GNUNET_NO);
250 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
251 _("Unsupported block type (%u) in local response!\n"),
252 type);
253 break;
254 }
251 return (eval == GNUNET_BLOCK_EVALUATION_OK_LAST) ? GNUNET_NO : GNUNET_OK; 255 return (eval == GNUNET_BLOCK_EVALUATION_OK_LAST) ? GNUNET_NO : GNUNET_OK;
252} 256}
253 257
@@ -265,23 +269,23 @@ datacache_get_iterator (void *cls,
265 * @return evaluation result for the local replies 269 * @return evaluation result for the local replies
266 */ 270 */
267enum GNUNET_BLOCK_EvaluationResult 271enum GNUNET_BLOCK_EvaluationResult
268GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key, 272GDS_DATACACHE_handle_get(const struct GNUNET_HashCode *key,
269 enum GNUNET_BLOCK_Type type, 273 enum GNUNET_BLOCK_Type type,
270 const void *xquery, 274 const void *xquery,
271 size_t xquery_size, 275 size_t xquery_size,
272 struct GNUNET_BLOCK_Group *bg, 276 struct GNUNET_BLOCK_Group *bg,
273 GDS_DATACACHE_GetCallback gc, 277 GDS_DATACACHE_GetCallback gc,
274 void *gc_cls) 278 void *gc_cls)
275{ 279{
276 struct GetRequestContext ctx; 280 struct GetRequestContext ctx;
277 unsigned int r; 281 unsigned int r;
278 282
279 if (NULL == datacache) 283 if (NULL == datacache)
280 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 284 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
281 GNUNET_STATISTICS_update (GDS_stats, 285 GNUNET_STATISTICS_update(GDS_stats,
282 gettext_noop ("# GET requests given to datacache"), 286 gettext_noop("# GET requests given to datacache"),
283 1, 287 1,
284 GNUNET_NO); 288 GNUNET_NO);
285 ctx.eval = GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 289 ctx.eval = GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
286 ctx.key = *key; 290 ctx.key = *key;
287 ctx.xquery = xquery; 291 ctx.xquery = xquery;
@@ -289,16 +293,16 @@ GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key,
289 ctx.bg = bg; 293 ctx.bg = bg;
290 ctx.gc = gc; 294 ctx.gc = gc;
291 ctx.gc_cls = gc_cls; 295 ctx.gc_cls = gc_cls;
292 r = GNUNET_DATACACHE_get (datacache, 296 r = GNUNET_DATACACHE_get(datacache,
293 key, 297 key,
294 type, 298 type,
295 &datacache_get_iterator, 299 &datacache_get_iterator,
296 &ctx); 300 &ctx);
297 LOG (GNUNET_ERROR_TYPE_DEBUG, 301 LOG(GNUNET_ERROR_TYPE_DEBUG,
298 "DATACACHE GET for key %s completed (%d). %u results found.\n", 302 "DATACACHE GET for key %s completed (%d). %u results found.\n",
299 GNUNET_h2s (key), 303 GNUNET_h2s(key),
300 ctx.eval, 304 ctx.eval,
301 r); 305 r);
302 return ctx.eval; 306 return ctx.eval;
303} 307}
304 308
@@ -318,14 +322,14 @@ GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key,
318 * @return #GNUNET_OK to continue iterating, #GNUNET_SYSERR to abort 322 * @return #GNUNET_OK to continue iterating, #GNUNET_SYSERR to abort
319 */ 323 */
320static int 324static int
321datacache_random_iterator (void *cls, 325datacache_random_iterator(void *cls,
322 const struct GNUNET_HashCode *key, 326 const struct GNUNET_HashCode *key,
323 size_t data_size, 327 size_t data_size,
324 const char *data, 328 const char *data,
325 enum GNUNET_BLOCK_Type type, 329 enum GNUNET_BLOCK_Type type,
326 struct GNUNET_TIME_Absolute exp, 330 struct GNUNET_TIME_Absolute exp,
327 unsigned int path_info_len, 331 unsigned int path_info_len,
328 const struct GNUNET_PeerIdentity *path_info) 332 const struct GNUNET_PeerIdentity *path_info)
329{ 333{
330 struct GNUNET_HashCode *dest = cls; 334 struct GNUNET_HashCode *dest = cls;
331 335
@@ -343,18 +347,18 @@ datacache_random_iterator (void *cls,
343 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the datacache is empty 347 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the datacache is empty
344 */ 348 */
345int 349int
346GDS_DATACACHE_get_random_key (struct GNUNET_HashCode *key) 350GDS_DATACACHE_get_random_key(struct GNUNET_HashCode *key)
347{ 351{
348 if (0 == 352 if (0 ==
349 GNUNET_DATACACHE_get_random (datacache, 353 GNUNET_DATACACHE_get_random(datacache,
350 &datacache_random_iterator, 354 &datacache_random_iterator,
351 key)) 355 key))
352 { 356 {
353 /* randomize key in this case */ 357 /* randomize key in this case */
354 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_NONCE, 358 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_NONCE,
355 key); 359 key);
356 return GNUNET_SYSERR; 360 return GNUNET_SYSERR;
357 } 361 }
358 return GNUNET_OK; 362 return GNUNET_OK;
359} 363}
360 364
@@ -362,8 +366,7 @@ GDS_DATACACHE_get_random_key (struct GNUNET_HashCode *key)
362/** 366/**
363 * Closure for #datacache_get_successors_iterator(). 367 * Closure for #datacache_get_successors_iterator().
364 */ 368 */
365struct SuccContext 369struct SuccContext {
366{
367 /** 370 /**
368 * Function to call on the result 371 * Function to call on the result
369 */ 372 */
@@ -391,14 +394,14 @@ struct SuccContext
391 * to stop iteration. 394 * to stop iteration.
392 */ 395 */
393static int 396static int
394datacache_get_successors_iterator (void *cls, 397datacache_get_successors_iterator(void *cls,
395 const struct GNUNET_HashCode *key, 398 const struct GNUNET_HashCode *key,
396 size_t size, 399 size_t size,
397 const char *data, 400 const char *data,
398 enum GNUNET_BLOCK_Type type, 401 enum GNUNET_BLOCK_Type type,
399 struct GNUNET_TIME_Absolute exp, 402 struct GNUNET_TIME_Absolute exp,
400 unsigned int put_path_length, 403 unsigned int put_path_length,
401 const struct GNUNET_PeerIdentity *put_path) 404 const struct GNUNET_PeerIdentity *put_path)
402{ 405{
403 const struct SuccContext *sc = cls; 406 const struct SuccContext *sc = cls;
404 407
@@ -406,14 +409,14 @@ datacache_get_successors_iterator (void *cls,
406 the original 'put', so we don't know the 'correct' option 409 the original 'put', so we don't know the 'correct' option
407 at this point anymore. Thus, we conservatively assume 410 at this point anymore. Thus, we conservatively assume
408 that recording is desired (for now). */ 411 that recording is desired (for now). */
409 sc->cb (sc->cb_cls, 412 sc->cb(sc->cb_cls,
410 GNUNET_DHT_RO_RECORD_ROUTE, 413 GNUNET_DHT_RO_RECORD_ROUTE,
411 key, 414 key,
412 type, 415 type,
413 put_path_length, put_path, 416 put_path_length, put_path,
414 exp, 417 exp,
415 data, 418 data,
416 size); 419 size);
417 return GNUNET_OK; 420 return GNUNET_OK;
418} 421}
419 422
@@ -427,19 +430,19 @@ datacache_get_successors_iterator (void *cls,
427 * @param cb_cls closure for @a cb 430 * @param cb_cls closure for @a cb
428 */ 431 */
429void 432void
430GDS_DATACACHE_get_successors (const struct GNUNET_HashCode *key, 433GDS_DATACACHE_get_successors(const struct GNUNET_HashCode *key,
431 GDS_DATACACHE_SuccessorCallback cb, 434 GDS_DATACACHE_SuccessorCallback cb,
432 void *cb_cls) 435 void *cb_cls)
433{ 436{
434 struct SuccContext sc; 437 struct SuccContext sc;
435 438
436 sc.cb = cb; 439 sc.cb = cb;
437 sc.cb_cls = cb_cls; 440 sc.cb_cls = cb_cls;
438 (void) GNUNET_DATACACHE_get_closest (datacache, 441 (void)GNUNET_DATACACHE_get_closest(datacache,
439 key, 442 key,
440 NUM_CLOSEST, 443 NUM_CLOSEST,
441 &datacache_get_successors_iterator, 444 &datacache_get_successors_iterator,
442 &sc); 445 &sc);
443} 446}
444 447
445 448
@@ -447,9 +450,9 @@ GDS_DATACACHE_get_successors (const struct GNUNET_HashCode *key,
447 * Initialize datacache subsystem. 450 * Initialize datacache subsystem.
448 */ 451 */
449void 452void
450GDS_DATACACHE_init () 453GDS_DATACACHE_init()
451{ 454{
452 datacache = GNUNET_DATACACHE_create (GDS_cfg, "dhtcache"); 455 datacache = GNUNET_DATACACHE_create(GDS_cfg, "dhtcache");
453} 456}
454 457
455 458
@@ -457,13 +460,13 @@ GDS_DATACACHE_init ()
457 * Shutdown datacache subsystem. 460 * Shutdown datacache subsystem.
458 */ 461 */
459void 462void
460GDS_DATACACHE_done () 463GDS_DATACACHE_done()
461{ 464{
462 if (NULL != datacache) 465 if (NULL != datacache)
463 { 466 {
464 GNUNET_DATACACHE_destroy (datacache); 467 GNUNET_DATACACHE_destroy(datacache);
465 datacache = NULL; 468 datacache = NULL;
466 } 469 }
467} 470}
468 471
469 472
diff --git a/src/dht/gnunet-service-dht_datacache.h b/src/dht/gnunet-service-dht_datacache.h
index bbbeb386e..e376aa1c1 100644
--- a/src/dht/gnunet-service-dht_datacache.h
+++ b/src/dht/gnunet-service-dht_datacache.h
@@ -11,12 +11,12 @@
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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file dht/gnunet-service-dht_datacache.h 22 * @file dht/gnunet-service-dht_datacache.h
@@ -44,13 +44,13 @@
44 * @param data application payload data 44 * @param data application payload data
45 */ 45 */
46void 46void
47GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration, 47GDS_DATACACHE_handle_put(struct GNUNET_TIME_Absolute expiration,
48 const struct GNUNET_HashCode *key, 48 const struct GNUNET_HashCode *key,
49 unsigned int put_path_length, 49 unsigned int put_path_length,
50 const struct GNUNET_PeerIdentity *put_path, 50 const struct GNUNET_PeerIdentity *put_path,
51 enum GNUNET_BLOCK_Type type, 51 enum GNUNET_BLOCK_Type type,
52 size_t data_size, 52 size_t data_size,
53 const void *data); 53 const void *data);
54 54
55 55
56/** 56/**
@@ -93,13 +93,13 @@ typedef void
93 * @return evaluation result for the local replies 93 * @return evaluation result for the local replies
94 */ 94 */
95enum GNUNET_BLOCK_EvaluationResult 95enum GNUNET_BLOCK_EvaluationResult
96GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key, 96GDS_DATACACHE_handle_get(const struct GNUNET_HashCode *key,
97 enum GNUNET_BLOCK_Type type, 97 enum GNUNET_BLOCK_Type type,
98 const void *xquery, 98 const void *xquery,
99 size_t xquery_size, 99 size_t xquery_size,
100 struct GNUNET_BLOCK_Group *bg, 100 struct GNUNET_BLOCK_Group *bg,
101 GDS_DATACACHE_GetCallback gc, 101 GDS_DATACACHE_GetCallback gc,
102 void *gc_cls); 102 void *gc_cls);
103 103
104 104
105/** 105/**
@@ -111,7 +111,7 @@ GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key,
111 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the datacache is empty 111 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the datacache is empty
112 */ 112 */
113int 113int
114GDS_DATACACHE_get_random_key (struct GNUNET_HashCode *key); 114GDS_DATACACHE_get_random_key(struct GNUNET_HashCode *key);
115 115
116 116
117/** 117/**
@@ -148,22 +148,22 @@ typedef void
148 * @param cb_cls closure for @a cb 148 * @param cb_cls closure for @a cb
149 */ 149 */
150void 150void
151GDS_DATACACHE_get_successors (const struct GNUNET_HashCode *key, 151GDS_DATACACHE_get_successors(const struct GNUNET_HashCode *key,
152 GDS_DATACACHE_SuccessorCallback cb, 152 GDS_DATACACHE_SuccessorCallback cb,
153 void *cb_cls); 153 void *cb_cls);
154 154
155 155
156/** 156/**
157 * Initialize datacache subsystem. 157 * Initialize datacache subsystem.
158 */ 158 */
159void 159void
160GDS_DATACACHE_init (void); 160GDS_DATACACHE_init(void);
161 161
162 162
163/** 163/**
164 * Shutdown datacache subsystem. 164 * Shutdown datacache subsystem.
165 */ 165 */
166void 166void
167GDS_DATACACHE_done (void); 167GDS_DATACACHE_done(void);
168 168
169#endif 169#endif
diff --git a/src/dht/gnunet-service-dht_hello.c b/src/dht/gnunet-service-dht_hello.c
index fd1003bd2..49641e649 100644
--- a/src/dht/gnunet-service-dht_hello.c
+++ b/src/dht/gnunet-service-dht_hello.c
@@ -11,12 +11,12 @@
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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file dht/gnunet-service-dht_hello.c 22 * @file dht/gnunet-service-dht_hello.c
@@ -50,11 +50,11 @@ static struct GNUNET_CONTAINER_MultiPeerMap *peer_to_hello;
50 * @return HELLO for the given peer 50 * @return HELLO for the given peer
51 */ 51 */
52const struct GNUNET_HELLO_Message * 52const struct GNUNET_HELLO_Message *
53GDS_HELLO_get (const struct GNUNET_PeerIdentity *peer) 53GDS_HELLO_get(const struct GNUNET_PeerIdentity *peer)
54{ 54{
55 if (NULL == peer_to_hello) 55 if (NULL == peer_to_hello)
56 return NULL; 56 return NULL;
57 return GNUNET_CONTAINER_multipeermap_get (peer_to_hello, peer); 57 return GNUNET_CONTAINER_multipeermap_get(peer_to_hello, peer);
58} 58}
59 59
60 60
@@ -69,30 +69,30 @@ GDS_HELLO_get (const struct GNUNET_PeerIdentity *peer)
69 * FIXME this is called once per address. Merge instead of replacing? 69 * FIXME this is called once per address. Merge instead of replacing?
70 */ 70 */
71static void 71static void
72process_hello (void *cls, 72process_hello(void *cls,
73 const struct GNUNET_PeerIdentity *peer, 73 const struct GNUNET_PeerIdentity *peer,
74 const struct GNUNET_HELLO_Message *hello, 74 const struct GNUNET_HELLO_Message *hello,
75 const char *err_msg) 75 const char *err_msg)
76{ 76{
77 struct GNUNET_TIME_Absolute ex; 77 struct GNUNET_TIME_Absolute ex;
78 struct GNUNET_HELLO_Message *hm; 78 struct GNUNET_HELLO_Message *hm;
79 79
80 if (NULL == hello) 80 if (NULL == hello)
81 return; 81 return;
82 ex = GNUNET_HELLO_get_last_expiration (hello); 82 ex = GNUNET_HELLO_get_last_expiration(hello);
83 if (0 == GNUNET_TIME_absolute_get_remaining (ex).rel_value_us) 83 if (0 == GNUNET_TIME_absolute_get_remaining(ex).rel_value_us)
84 return; 84 return;
85 GNUNET_STATISTICS_update (GDS_stats, 85 GNUNET_STATISTICS_update(GDS_stats,
86 gettext_noop ("# HELLOs obtained from peerinfo"), 1, 86 gettext_noop("# HELLOs obtained from peerinfo"), 1,
87 GNUNET_NO); 87 GNUNET_NO);
88 hm = GNUNET_CONTAINER_multipeermap_get (peer_to_hello, peer); 88 hm = GNUNET_CONTAINER_multipeermap_get(peer_to_hello, peer);
89 GNUNET_free_non_null (hm); 89 GNUNET_free_non_null(hm);
90 hm = GNUNET_malloc (GNUNET_HELLO_size (hello)); 90 hm = GNUNET_malloc(GNUNET_HELLO_size(hello));
91 GNUNET_memcpy (hm, hello, GNUNET_HELLO_size (hello)); 91 GNUNET_memcpy(hm, hello, GNUNET_HELLO_size(hello));
92 GNUNET_assert (GNUNET_SYSERR != 92 GNUNET_assert(GNUNET_SYSERR !=
93 GNUNET_CONTAINER_multipeermap_put (peer_to_hello, 93 GNUNET_CONTAINER_multipeermap_put(peer_to_hello,
94 peer, hm, 94 peer, hm,
95 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE)); 95 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
96} 96}
97 97
98 98
@@ -100,14 +100,14 @@ process_hello (void *cls,
100 * Initialize HELLO subsystem. 100 * Initialize HELLO subsystem.
101 */ 101 */
102void 102void
103GDS_HELLO_init () 103GDS_HELLO_init()
104{ 104{
105 pnc = GNUNET_PEERINFO_notify (GDS_cfg, 105 pnc = GNUNET_PEERINFO_notify(GDS_cfg,
106 GNUNET_NO, 106 GNUNET_NO,
107 &process_hello, 107 &process_hello,
108 NULL); 108 NULL);
109 peer_to_hello = GNUNET_CONTAINER_multipeermap_create (256, 109 peer_to_hello = GNUNET_CONTAINER_multipeermap_create(256,
110 GNUNET_NO); 110 GNUNET_NO);
111} 111}
112 112
113 113
@@ -115,11 +115,11 @@ GDS_HELLO_init ()
115 * Free memory occopied by the HELLO. 115 * Free memory occopied by the HELLO.
116 */ 116 */
117static int 117static int
118free_hello (void *cls, 118free_hello(void *cls,
119 const struct GNUNET_PeerIdentity *key, 119 const struct GNUNET_PeerIdentity *key,
120 void *hello) 120 void *hello)
121{ 121{
122 GNUNET_free (hello); 122 GNUNET_free(hello);
123 return GNUNET_OK; 123 return GNUNET_OK;
124} 124}
125 125
@@ -128,20 +128,20 @@ free_hello (void *cls,
128 * Shutdown HELLO subsystem. 128 * Shutdown HELLO subsystem.
129 */ 129 */
130void 130void
131GDS_HELLO_done () 131GDS_HELLO_done()
132{ 132{
133 if (NULL != pnc) 133 if (NULL != pnc)
134 { 134 {
135 GNUNET_PEERINFO_notify_cancel (pnc); 135 GNUNET_PEERINFO_notify_cancel(pnc);
136 pnc = NULL; 136 pnc = NULL;
137 } 137 }
138 if (NULL != peer_to_hello) 138 if (NULL != peer_to_hello)
139 { 139 {
140 GNUNET_CONTAINER_multipeermap_iterate (peer_to_hello, 140 GNUNET_CONTAINER_multipeermap_iterate(peer_to_hello,
141 &free_hello, 141 &free_hello,
142 NULL); 142 NULL);
143 GNUNET_CONTAINER_multipeermap_destroy (peer_to_hello); 143 GNUNET_CONTAINER_multipeermap_destroy(peer_to_hello);
144 } 144 }
145} 145}
146 146
147/* end of gnunet-service-dht_hello.c */ 147/* end of gnunet-service-dht_hello.c */
diff --git a/src/dht/gnunet-service-dht_hello.h b/src/dht/gnunet-service-dht_hello.h
index 0927c89ee..929677839 100644
--- a/src/dht/gnunet-service-dht_hello.h
+++ b/src/dht/gnunet-service-dht_hello.h
@@ -11,12 +11,12 @@
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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file dht/gnunet-service-dht_hello.h 22 * @file dht/gnunet-service-dht_hello.h
@@ -36,20 +36,20 @@
36 * @return HELLO for the given peer 36 * @return HELLO for the given peer
37 */ 37 */
38const struct GNUNET_HELLO_Message * 38const struct GNUNET_HELLO_Message *
39GDS_HELLO_get (const struct GNUNET_PeerIdentity *peer); 39GDS_HELLO_get(const struct GNUNET_PeerIdentity *peer);
40 40
41 41
42/** 42/**
43 * Initialize HELLO subsystem. 43 * Initialize HELLO subsystem.
44 */ 44 */
45void 45void
46GDS_HELLO_init (void); 46GDS_HELLO_init(void);
47 47
48 48
49/** 49/**
50 * Shutdown HELLO subsystem. 50 * Shutdown HELLO subsystem.
51 */ 51 */
52void 52void
53GDS_HELLO_done (void); 53GDS_HELLO_done(void);
54 54
55#endif 55#endif
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c
index 4f040558a..90ef5429f 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -11,12 +11,12 @@
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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file dht/gnunet-service-dht_neighbours.c 22 * @file dht/gnunet-service-dht_neighbours.c
@@ -46,7 +46,7 @@
46#include "gnunet-service-dht_routing.h" 46#include "gnunet-service-dht_routing.h"
47#include "dht.h" 47#include "dht.h"
48 48
49#define LOG_TRAFFIC(kind,...) GNUNET_log_from (kind, "dht-traffic",__VA_ARGS__) 49#define LOG_TRAFFIC(kind, ...) GNUNET_log_from(kind, "dht-traffic", __VA_ARGS__)
50 50
51/** 51/**
52 * Enable slow sanity checks to debug issues. 52 * Enable slow sanity checks to debug issues.
@@ -56,7 +56,7 @@
56/** 56/**
57 * How many buckets will we allow total. 57 * How many buckets will we allow total.
58 */ 58 */
59#define MAX_BUCKETS sizeof (struct GNUNET_HashCode) * 8 59#define MAX_BUCKETS sizeof(struct GNUNET_HashCode) * 8
60 60
61/** 61/**
62 * What is the maximum number of peers in a given bucket. 62 * What is the maximum number of peers in a given bucket.
@@ -104,8 +104,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
104/** 104/**
105 * P2P PUT message 105 * P2P PUT message
106 */ 106 */
107struct PeerPutMessage 107struct PeerPutMessage {
108{
109 /** 108 /**
110 * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_PUT 109 * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_PUT
111 */ 110 */
@@ -154,15 +153,13 @@ struct PeerPutMessage
154 /* put path (if tracked) */ 153 /* put path (if tracked) */
155 154
156 /* Payload */ 155 /* Payload */
157
158}; 156};
159 157
160 158
161/** 159/**
162 * P2P Result message 160 * P2P Result message
163 */ 161 */
164struct PeerResultMessage 162struct PeerResultMessage {
165{
166 /** 163 /**
167 * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT 164 * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT
168 */ 165 */
@@ -198,15 +195,13 @@ struct PeerResultMessage
198 /* get path (if tracked) */ 195 /* get path (if tracked) */
199 196
200 /* Payload */ 197 /* Payload */
201
202}; 198};
203 199
204 200
205/** 201/**
206 * P2P GET message 202 * P2P GET message
207 */ 203 */
208struct PeerGetMessage 204struct PeerGetMessage {
209{
210 /** 205 /**
211 * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_GET 206 * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_GET
212 */ 207 */
@@ -255,7 +250,6 @@ struct PeerGetMessage
255 /* xquery */ 250 /* xquery */
256 251
257 /* result bloomfilter */ 252 /* result bloomfilter */
258
259}; 253};
260GNUNET_NETWORK_STRUCT_END 254GNUNET_NETWORK_STRUCT_END
261 255
@@ -263,8 +257,7 @@ GNUNET_NETWORK_STRUCT_END
263/** 257/**
264 * Entry for a peer in a bucket. 258 * Entry for a peer in a bucket.
265 */ 259 */
266struct PeerInfo 260struct PeerInfo {
267{
268 /** 261 /**
269 * Next peer entry (DLL) 262 * Next peer entry (DLL)
270 */ 263 */
@@ -294,15 +287,13 @@ struct PeerInfo
294 * Which bucket is this peer in? 287 * Which bucket is this peer in?
295 */ 288 */
296 int peer_bucket; 289 int peer_bucket;
297
298}; 290};
299 291
300 292
301/** 293/**
302 * Peers are grouped into buckets. 294 * Peers are grouped into buckets.
303 */ 295 */
304struct PeerBucket 296struct PeerBucket {
305{
306 /** 297 /**
307 * Head of DLL 298 * Head of DLL
308 */ 299 */
@@ -323,9 +314,7 @@ struct PeerBucket
323/** 314/**
324 * Information about a peer that we would like to connect to. 315 * Information about a peer that we would like to connect to.
325 */ 316 */
326struct ConnectInfo 317struct ConnectInfo {
327{
328
329 /** 318 /**
330 * Handle to active HELLO offer operation, or NULL. 319 * Handle to active HELLO offer operation, or NULL.
331 */ 320 */
@@ -425,17 +414,17 @@ static struct GNUNET_ATS_ConnectivityHandle *ats_ch;
425 * on error (same hashcode) 414 * on error (same hashcode)
426 */ 415 */
427static int 416static int
428find_bucket (const struct GNUNET_HashCode *hc) 417find_bucket(const struct GNUNET_HashCode *hc)
429{ 418{
430 unsigned int bits; 419 unsigned int bits;
431 420
432 bits = GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash, hc); 421 bits = GNUNET_CRYPTO_hash_matching_bits(&my_identity_hash, hc);
433 if (bits == MAX_BUCKETS) 422 if (bits == MAX_BUCKETS)
434 { 423 {
435 /* How can all bits match? Got my own ID? */ 424 /* How can all bits match? Got my own ID? */
436 GNUNET_break (0); 425 GNUNET_break(0);
437 return GNUNET_SYSERR; 426 return GNUNET_SYSERR;
438 } 427 }
439 return MAX_BUCKETS - bits - 1; 428 return MAX_BUCKETS - bits - 1;
440} 429}
441 430
@@ -447,7 +436,7 @@ find_bucket (const struct GNUNET_HashCode *hc)
447 * @param cls a `struct ConnectInfo` 436 * @param cls a `struct ConnectInfo`
448 */ 437 */
449static void 438static void
450offer_hello_done (void *cls) 439offer_hello_done(void *cls)
451{ 440{
452 struct ConnectInfo *ci = cls; 441 struct ConnectInfo *ci = cls;
453 442
@@ -464,28 +453,28 @@ offer_hello_done (void *cls)
464 * @return #GNUNET_YES 453 * @return #GNUNET_YES
465 */ 454 */
466static int 455static int
467free_connect_info (void *cls, 456free_connect_info(void *cls,
468 const struct GNUNET_PeerIdentity *peer, 457 const struct GNUNET_PeerIdentity *peer,
469 void *value) 458 void *value)
470{ 459{
471 struct ConnectInfo *ci = value; 460 struct ConnectInfo *ci = value;
472 461
473 (void) cls; 462 (void)cls;
474 GNUNET_assert (GNUNET_YES == 463 GNUNET_assert(GNUNET_YES ==
475 GNUNET_CONTAINER_multipeermap_remove (all_desired_peers, 464 GNUNET_CONTAINER_multipeermap_remove(all_desired_peers,
476 peer, 465 peer,
477 ci)); 466 ci));
478 if (NULL != ci->sh) 467 if (NULL != ci->sh)
479 { 468 {
480 GNUNET_ATS_connectivity_suggest_cancel (ci->sh); 469 GNUNET_ATS_connectivity_suggest_cancel(ci->sh);
481 ci->sh = NULL; 470 ci->sh = NULL;
482 } 471 }
483 if (NULL != ci->oh) 472 if (NULL != ci->oh)
484 { 473 {
485 GNUNET_TRANSPORT_offer_hello_cancel (ci->oh); 474 GNUNET_TRANSPORT_offer_hello_cancel(ci->oh);
486 ci->oh = NULL; 475 ci->oh = NULL;
487 } 476 }
488 GNUNET_free (ci); 477 GNUNET_free(ci);
489 return GNUNET_YES; 478 return GNUNET_YES;
490} 479}
491 480
@@ -499,68 +488,68 @@ free_connect_info (void *cls,
499 * @param h a HELLO message, or NULL 488 * @param h a HELLO message, or NULL
500 */ 489 */
501static void 490static void
502try_connect (const struct GNUNET_PeerIdentity *pid, 491try_connect(const struct GNUNET_PeerIdentity *pid,
503 const struct GNUNET_MessageHeader *h) 492 const struct GNUNET_MessageHeader *h)
504{ 493{
505 int bucket; 494 int bucket;
506 struct GNUNET_HashCode pid_hash; 495 struct GNUNET_HashCode pid_hash;
507 struct ConnectInfo *ci; 496 struct ConnectInfo *ci;
508 uint32_t strength; 497 uint32_t strength;
509 498
510 GNUNET_CRYPTO_hash (pid, 499 GNUNET_CRYPTO_hash(pid,
511 sizeof (struct GNUNET_PeerIdentity), 500 sizeof(struct GNUNET_PeerIdentity),
512 &pid_hash); 501 &pid_hash);
513 bucket = find_bucket (&pid_hash); 502 bucket = find_bucket(&pid_hash);
514 if (bucket < 0) 503 if (bucket < 0)
515 return; /* self? */ 504 return; /* self? */
516 ci = GNUNET_CONTAINER_multipeermap_get (all_desired_peers, 505 ci = GNUNET_CONTAINER_multipeermap_get(all_desired_peers,
517 pid); 506 pid);
518 507
519 if (k_buckets[bucket].peers_size < bucket_size) 508 if (k_buckets[bucket].peers_size < bucket_size)
520 strength = (bucket_size - k_buckets[bucket].peers_size) * bucket; 509 strength = (bucket_size - k_buckets[bucket].peers_size) * bucket;
521 else 510 else
522 strength = bucket; /* minimum value of connectivity */ 511 strength = bucket; /* minimum value of connectivity */
523 if (GNUNET_YES == 512 if (GNUNET_YES ==
524 GNUNET_CONTAINER_multipeermap_contains (all_connected_peers, 513 GNUNET_CONTAINER_multipeermap_contains(all_connected_peers,
525 pid)) 514 pid))
526 strength *= 2; /* double for connected peers */ 515 strength *= 2; /* double for connected peers */
527 else if (k_buckets[bucket].peers_size > bucket_size) 516 else if (k_buckets[bucket].peers_size > bucket_size)
528 strength = 0; /* bucket full, we really do not care about more */ 517 strength = 0; /* bucket full, we really do not care about more */
529 518
530 if ( (0 == strength) && 519 if ((0 == strength) &&
531 (NULL != ci) ) 520 (NULL != ci))
532 { 521 {
533 /* release request */ 522 /* release request */
534 GNUNET_assert (GNUNET_YES == 523 GNUNET_assert(GNUNET_YES ==
535 free_connect_info (NULL, 524 free_connect_info(NULL,
536 pid, 525 pid,
537 ci)); 526 ci));
538 return; 527 return;
539 } 528 }
540 if (NULL == ci) 529 if (NULL == ci)
541 { 530 {
542 ci = GNUNET_new (struct ConnectInfo); 531 ci = GNUNET_new(struct ConnectInfo);
543 GNUNET_assert (GNUNET_OK == 532 GNUNET_assert(GNUNET_OK ==
544 GNUNET_CONTAINER_multipeermap_put (all_desired_peers, 533 GNUNET_CONTAINER_multipeermap_put(all_desired_peers,
545 pid, 534 pid,
546 ci, 535 ci,
547 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 536 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
548 } 537 }
549 if ( (NULL != ci->oh) && 538 if ((NULL != ci->oh) &&
550 (NULL != h) ) 539 (NULL != h))
551 GNUNET_TRANSPORT_offer_hello_cancel (ci->oh); 540 GNUNET_TRANSPORT_offer_hello_cancel(ci->oh);
552 if (NULL != h) 541 if (NULL != h)
553 ci->oh = GNUNET_TRANSPORT_offer_hello (GDS_cfg, 542 ci->oh = GNUNET_TRANSPORT_offer_hello(GDS_cfg,
554 h, 543 h,
555 &offer_hello_done, 544 &offer_hello_done,
556 ci); 545 ci);
557 if ( (NULL != ci->sh) && 546 if ((NULL != ci->sh) &&
558 (ci->strength != strength) ) 547 (ci->strength != strength))
559 GNUNET_ATS_connectivity_suggest_cancel (ci->sh); 548 GNUNET_ATS_connectivity_suggest_cancel(ci->sh);
560 if (ci->strength != strength) 549 if (ci->strength != strength)
561 ci->sh = GNUNET_ATS_connectivity_suggest (ats_ch, 550 ci->sh = GNUNET_ATS_connectivity_suggest(ats_ch,
562 pid, 551 pid,
563 strength); 552 strength);
564 ci->strength = strength; 553 ci->strength = strength;
565} 554}
566 555
@@ -578,14 +567,14 @@ try_connect (const struct GNUNET_PeerIdentity *pid,
578 * @return #GNUNET_YES (continue to iterate) 567 * @return #GNUNET_YES (continue to iterate)
579 */ 568 */
580static int 569static int
581update_desire_strength (void *cls, 570update_desire_strength(void *cls,
582 const struct GNUNET_PeerIdentity *pid, 571 const struct GNUNET_PeerIdentity *pid,
583 void *value) 572 void *value)
584{ 573{
585 (void) cls; 574 (void)cls;
586 (void) value; 575 (void)value;
587 try_connect (pid, 576 try_connect(pid,
588 NULL); 577 NULL);
589 return GNUNET_YES; 578 return GNUNET_YES;
590} 579}
591 580
@@ -597,11 +586,11 @@ update_desire_strength (void *cls,
597 * @param tc scheduler context. 586 * @param tc scheduler context.
598 */ 587 */
599static void 588static void
600update_connect_preferences () 589update_connect_preferences()
601{ 590{
602 GNUNET_CONTAINER_multipeermap_iterate (all_desired_peers, 591 GNUNET_CONTAINER_multipeermap_iterate(all_desired_peers,
603 &update_desire_strength, 592 &update_desire_strength,
604 NULL); 593 NULL);
605} 594}
606 595
607 596
@@ -615,24 +604,24 @@ update_connect_preferences ()
615 * @return #GNUNET_YES (we should continue to iterate) 604 * @return #GNUNET_YES (we should continue to iterate)
616 */ 605 */
617static int 606static int
618add_known_to_bloom (void *cls, 607add_known_to_bloom(void *cls,
619 const struct GNUNET_PeerIdentity *key, 608 const struct GNUNET_PeerIdentity *key,
620 void *value) 609 void *value)
621{ 610{
622 struct GNUNET_BLOCK_Group *bg = cls; 611 struct GNUNET_BLOCK_Group *bg = cls;
623 struct GNUNET_HashCode key_hash; 612 struct GNUNET_HashCode key_hash;
624 613
625 (void) cls; 614 (void)cls;
626 (void) value; 615 (void)value;
627 GNUNET_CRYPTO_hash (key, 616 GNUNET_CRYPTO_hash(key,
628 sizeof (struct GNUNET_PeerIdentity), 617 sizeof(struct GNUNET_PeerIdentity),
629 &key_hash); 618 &key_hash);
630 GNUNET_BLOCK_group_set_seen (bg, 619 GNUNET_BLOCK_group_set_seen(bg,
631 &key_hash, 620 &key_hash,
632 1); 621 1);
633 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 622 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
634 "Adding known peer (%s) to bloomfilter for FIND PEER\n", 623 "Adding known peer (%s) to bloomfilter for FIND PEER\n",
635 GNUNET_i2s (key)); 624 GNUNET_i2s(key));
636 return GNUNET_YES; 625 return GNUNET_YES;
637} 626}
638 627
@@ -645,68 +634,68 @@ add_known_to_bloom (void *cls,
645 * @param cls closure for this task 634 * @param cls closure for this task
646 */ 635 */
647static void 636static void
648send_find_peer_message (void *cls) 637send_find_peer_message(void *cls)
649{ 638{
650 struct GNUNET_TIME_Relative next_send_time; 639 struct GNUNET_TIME_Relative next_send_time;
651 struct GNUNET_BLOCK_Group *bg; 640 struct GNUNET_BLOCK_Group *bg;
652 struct GNUNET_CONTAINER_BloomFilter *peer_bf; 641 struct GNUNET_CONTAINER_BloomFilter *peer_bf;
653 642
654 (void) cls; 643 (void)cls;
655 find_peer_task = NULL; 644 find_peer_task = NULL;
656 if (newly_found_peers > bucket_size) 645 if (newly_found_peers > bucket_size)
657 { 646 {
658 /* If we are finding many peers already, no need to send out our request right now! */ 647 /* If we are finding many peers already, no need to send out our request right now! */
659 find_peer_task = 648 find_peer_task =
660 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 649 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES,
661 &send_find_peer_message, 650 &send_find_peer_message,
662 NULL); 651 NULL);
663 newly_found_peers = 0; 652 newly_found_peers = 0;
664 return; 653 return;
665 } 654 }
666 bg = GNUNET_BLOCK_group_create (GDS_block_context, 655 bg = GNUNET_BLOCK_group_create(GDS_block_context,
667 GNUNET_BLOCK_TYPE_DHT_HELLO, 656 GNUNET_BLOCK_TYPE_DHT_HELLO,
668 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 657 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
669 UINT32_MAX), 658 UINT32_MAX),
670 NULL, 659 NULL,
671 0, 660 0,
672 "filter-size", 661 "filter-size",
673 DHT_BLOOM_SIZE, 662 DHT_BLOOM_SIZE,
674 NULL); 663 NULL);
675 GNUNET_CONTAINER_multipeermap_iterate (all_connected_peers, 664 GNUNET_CONTAINER_multipeermap_iterate(all_connected_peers,
676 &add_known_to_bloom, 665 &add_known_to_bloom,
677 bg); 666 bg);
678 GNUNET_STATISTICS_update (GDS_stats, 667 GNUNET_STATISTICS_update(GDS_stats,
679 gettext_noop ("# FIND PEER messages initiated"), 668 gettext_noop("# FIND PEER messages initiated"),
680 1, 669 1,
681 GNUNET_NO); 670 GNUNET_NO);
682 peer_bf 671 peer_bf
683 = GNUNET_CONTAINER_bloomfilter_init (NULL, 672 = GNUNET_CONTAINER_bloomfilter_init(NULL,
684 DHT_BLOOM_SIZE, 673 DHT_BLOOM_SIZE,
685 GNUNET_CONSTANTS_BLOOMFILTER_K); 674 GNUNET_CONSTANTS_BLOOMFILTER_K);
686 // FIXME: pass priority!? 675 // FIXME: pass priority!?
687 GDS_NEIGHBOURS_handle_get (GNUNET_BLOCK_TYPE_DHT_HELLO, 676 GDS_NEIGHBOURS_handle_get(GNUNET_BLOCK_TYPE_DHT_HELLO,
688 GNUNET_DHT_RO_FIND_PEER | GNUNET_DHT_RO_RECORD_ROUTE, 677 GNUNET_DHT_RO_FIND_PEER | GNUNET_DHT_RO_RECORD_ROUTE,
689 FIND_PEER_REPLICATION_LEVEL, 678 FIND_PEER_REPLICATION_LEVEL,
690 0, 679 0,
691 &my_identity_hash, 680 &my_identity_hash,
692 NULL, 681 NULL,
693 0, 682 0,
694 bg, 683 bg,
695 peer_bf); 684 peer_bf);
696 GNUNET_CONTAINER_bloomfilter_free (peer_bf); 685 GNUNET_CONTAINER_bloomfilter_free(peer_bf);
697 GNUNET_BLOCK_group_destroy (bg); 686 GNUNET_BLOCK_group_destroy(bg);
698 /* schedule next round */ 687 /* schedule next round */
699 next_send_time.rel_value_us = 688 next_send_time.rel_value_us =
700 DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value_us + 689 DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value_us +
701 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 690 GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK,
702 DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value_us / 691 DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value_us /
703 (newly_found_peers + 1)); 692 (newly_found_peers + 1));
704 newly_found_peers = 0; 693 newly_found_peers = 0;
705 GNUNET_assert (NULL == find_peer_task); 694 GNUNET_assert(NULL == find_peer_task);
706 find_peer_task = 695 find_peer_task =
707 GNUNET_SCHEDULER_add_delayed (next_send_time, 696 GNUNET_SCHEDULER_add_delayed(next_send_time,
708 &send_find_peer_message, 697 &send_find_peer_message,
709 NULL); 698 NULL);
710} 699}
711 700
712 701
@@ -719,61 +708,61 @@ send_find_peer_message (void *cls)
719 * @return our `struct PeerInfo` for @a peer 708 * @return our `struct PeerInfo` for @a peer
720 */ 709 */
721static void * 710static void *
722handle_core_connect (void *cls, 711handle_core_connect(void *cls,
723 const struct GNUNET_PeerIdentity *peer, 712 const struct GNUNET_PeerIdentity *peer,
724 struct GNUNET_MQ_Handle *mq) 713 struct GNUNET_MQ_Handle *mq)
725{ 714{
726 struct PeerInfo *pi; 715 struct PeerInfo *pi;
727 716
728 (void) cls; 717 (void)cls;
729 /* Check for connect to self message */ 718 /* Check for connect to self message */
730 if (0 == GNUNET_memcmp (&my_identity, 719 if (0 == GNUNET_memcmp(&my_identity,
731 peer)) 720 peer))
732 return NULL; 721 return NULL;
733 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 722 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
734 "Connected to %s\n", 723 "Connected to %s\n",
735 GNUNET_i2s (peer)); 724 GNUNET_i2s(peer));
736 GNUNET_assert (GNUNET_NO == 725 GNUNET_assert(GNUNET_NO ==
737 GNUNET_CONTAINER_multipeermap_get (all_connected_peers, 726 GNUNET_CONTAINER_multipeermap_get(all_connected_peers,
738 peer)); 727 peer));
739 GNUNET_STATISTICS_update (GDS_stats, 728 GNUNET_STATISTICS_update(GDS_stats,
740 gettext_noop ("# peers connected"), 729 gettext_noop("# peers connected"),
741 1, 730 1,
742 GNUNET_NO); 731 GNUNET_NO);
743 pi = GNUNET_new (struct PeerInfo); 732 pi = GNUNET_new(struct PeerInfo);
744 pi->id = peer; 733 pi->id = peer;
745 pi->mq = mq; 734 pi->mq = mq;
746 GNUNET_CRYPTO_hash (peer, 735 GNUNET_CRYPTO_hash(peer,
747 sizeof (struct GNUNET_PeerIdentity), 736 sizeof(struct GNUNET_PeerIdentity),
748 &pi->phash); 737 &pi->phash);
749 pi->peer_bucket = find_bucket (&pi->phash); 738 pi->peer_bucket = find_bucket(&pi->phash);
750 GNUNET_assert ( (pi->peer_bucket >= 0) && 739 GNUNET_assert((pi->peer_bucket >= 0) &&
751 ((unsigned int) pi->peer_bucket < MAX_BUCKETS) ); 740 ((unsigned int)pi->peer_bucket < MAX_BUCKETS));
752 GNUNET_CONTAINER_DLL_insert_tail (k_buckets[pi->peer_bucket].head, 741 GNUNET_CONTAINER_DLL_insert_tail(k_buckets[pi->peer_bucket].head,
753 k_buckets[pi->peer_bucket].tail, 742 k_buckets[pi->peer_bucket].tail,
754 pi); 743 pi);
755 k_buckets[pi->peer_bucket].peers_size++; 744 k_buckets[pi->peer_bucket].peers_size++;
756 closest_bucket = GNUNET_MAX (closest_bucket, 745 closest_bucket = GNUNET_MAX(closest_bucket,
757 (unsigned int) pi->peer_bucket); 746 (unsigned int)pi->peer_bucket);
758 GNUNET_assert (GNUNET_OK == 747 GNUNET_assert(GNUNET_OK ==
759 GNUNET_CONTAINER_multipeermap_put (all_connected_peers, 748 GNUNET_CONTAINER_multipeermap_put(all_connected_peers,
760 pi->id, 749 pi->id,
761 pi, 750 pi,
762 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 751 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
763 if ( (pi->peer_bucket > 0) && 752 if ((pi->peer_bucket > 0) &&
764 (k_buckets[pi->peer_bucket].peers_size <= bucket_size)) 753 (k_buckets[pi->peer_bucket].peers_size <= bucket_size))
765 { 754 {
766 update_connect_preferences (); 755 update_connect_preferences();
767 newly_found_peers++; 756 newly_found_peers++;
768 } 757 }
769 if ( (1 == GNUNET_CONTAINER_multipeermap_size (all_connected_peers)) && 758 if ((1 == GNUNET_CONTAINER_multipeermap_size(all_connected_peers)) &&
770 (GNUNET_YES != disable_try_connect)) 759 (GNUNET_YES != disable_try_connect))
771 { 760 {
772 /* got a first connection, good time to start with FIND PEER requests... */ 761 /* got a first connection, good time to start with FIND PEER requests... */
773 GNUNET_assert (NULL == find_peer_task); 762 GNUNET_assert(NULL == find_peer_task);
774 find_peer_task = GNUNET_SCHEDULER_add_now (&send_find_peer_message, 763 find_peer_task = GNUNET_SCHEDULER_add_now(&send_find_peer_message,
775 NULL); 764 NULL);
776 } 765 }
777 return pi; 766 return pi;
778} 767}
779 768
@@ -786,45 +775,45 @@ handle_core_connect (void *cls,
786 * @param internal_cls our `struct PeerInfo` for @a peer 775 * @param internal_cls our `struct PeerInfo` for @a peer
787 */ 776 */
788static void 777static void
789handle_core_disconnect (void *cls, 778handle_core_disconnect(void *cls,
790 const struct GNUNET_PeerIdentity *peer, 779 const struct GNUNET_PeerIdentity *peer,
791 void *internal_cls) 780 void *internal_cls)
792{ 781{
793 struct PeerInfo *to_remove = internal_cls; 782 struct PeerInfo *to_remove = internal_cls;
794 783
795 (void) cls; 784 (void)cls;
796 /* Check for disconnect from self message */ 785 /* Check for disconnect from self message */
797 if (NULL == to_remove) 786 if (NULL == to_remove)
798 return; 787 return;
799 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 788 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
800 "Disconnected %s\n", 789 "Disconnected %s\n",
801 GNUNET_i2s (peer)); 790 GNUNET_i2s(peer));
802 GNUNET_STATISTICS_update (GDS_stats, 791 GNUNET_STATISTICS_update(GDS_stats,
803 gettext_noop ("# peers connected"), 792 gettext_noop("# peers connected"),
804 -1, 793 -1,
805 GNUNET_NO); 794 GNUNET_NO);
806 GNUNET_assert (GNUNET_YES == 795 GNUNET_assert(GNUNET_YES ==
807 GNUNET_CONTAINER_multipeermap_remove (all_connected_peers, 796 GNUNET_CONTAINER_multipeermap_remove(all_connected_peers,
808 peer, 797 peer,
809 to_remove)); 798 to_remove));
810 if ( (0 == GNUNET_CONTAINER_multipeermap_size (all_connected_peers)) && 799 if ((0 == GNUNET_CONTAINER_multipeermap_size(all_connected_peers)) &&
811 (GNUNET_YES != disable_try_connect) ) 800 (GNUNET_YES != disable_try_connect))
812 { 801 {
813 GNUNET_SCHEDULER_cancel (find_peer_task); 802 GNUNET_SCHEDULER_cancel(find_peer_task);
814 find_peer_task = NULL; 803 find_peer_task = NULL;
815 } 804 }
816 GNUNET_assert (to_remove->peer_bucket >= 0); 805 GNUNET_assert(to_remove->peer_bucket >= 0);
817 GNUNET_CONTAINER_DLL_remove (k_buckets[to_remove->peer_bucket].head, 806 GNUNET_CONTAINER_DLL_remove(k_buckets[to_remove->peer_bucket].head,
818 k_buckets[to_remove->peer_bucket].tail, 807 k_buckets[to_remove->peer_bucket].tail,
819 to_remove); 808 to_remove);
820 GNUNET_assert (k_buckets[to_remove->peer_bucket].peers_size > 0); 809 GNUNET_assert(k_buckets[to_remove->peer_bucket].peers_size > 0);
821 k_buckets[to_remove->peer_bucket].peers_size--; 810 k_buckets[to_remove->peer_bucket].peers_size--;
822 while ( (closest_bucket > 0) && 811 while ((closest_bucket > 0) &&
823 (0 == k_buckets[to_remove->peer_bucket].peers_size) ) 812 (0 == k_buckets[to_remove->peer_bucket].peers_size))
824 closest_bucket--; 813 closest_bucket--;
825 if (k_buckets[to_remove->peer_bucket].peers_size < bucket_size) 814 if (k_buckets[to_remove->peer_bucket].peers_size < bucket_size)
826 update_connect_preferences (); 815 update_connect_preferences();
827 GNUNET_free (to_remove); 816 GNUNET_free(to_remove);
828} 817}
829 818
830 819
@@ -837,39 +826,39 @@ handle_core_disconnect (void *cls,
837 * @return Some number of peers to forward the message to 826 * @return Some number of peers to forward the message to
838 */ 827 */
839static unsigned int 828static unsigned int
840get_forward_count (uint32_t hop_count, 829get_forward_count(uint32_t hop_count,
841 uint32_t target_replication) 830 uint32_t target_replication)
842{ 831{
843 uint32_t random_value; 832 uint32_t random_value;
844 uint32_t forward_count; 833 uint32_t forward_count;
845 float target_value; 834 float target_value;
846 835
847 if (hop_count > GDS_NSE_get () * 4.0) 836 if (hop_count > GDS_NSE_get() * 4.0)
848 { 837 {
849 /* forcefully terminate */ 838 /* forcefully terminate */
850 GNUNET_STATISTICS_update (GDS_stats, 839 GNUNET_STATISTICS_update(GDS_stats,
851 gettext_noop ("# requests TTL-dropped"), 840 gettext_noop("# requests TTL-dropped"),
852 1, GNUNET_NO); 841 1, GNUNET_NO);
853 return 0; 842 return 0;
854 } 843 }
855 if (hop_count > GDS_NSE_get () * 2.0) 844 if (hop_count > GDS_NSE_get() * 2.0)
856 { 845 {
857 /* Once we have reached our ideal number of hops, only forward to 1 peer */ 846 /* Once we have reached our ideal number of hops, only forward to 1 peer */
858 return 1; 847 return 1;
859 } 848 }
860 /* bound by system-wide maximum */ 849 /* bound by system-wide maximum */
861 target_replication = 850 target_replication =
862 GNUNET_MIN (MAXIMUM_REPLICATION_LEVEL, target_replication); 851 GNUNET_MIN(MAXIMUM_REPLICATION_LEVEL, target_replication);
863 target_value = 852 target_value =
864 1 + (target_replication - 1.0) / (GDS_NSE_get () + 853 1 + (target_replication - 1.0) / (GDS_NSE_get() +
865 ((float) (target_replication - 1.0) * 854 ((float)(target_replication - 1.0) *
866 hop_count)); 855 hop_count));
867 /* Set forward count to floor of target_value */ 856 /* Set forward count to floor of target_value */
868 forward_count = (uint32_t) target_value; 857 forward_count = (uint32_t)target_value;
869 /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */ 858 /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */
870 target_value = target_value - forward_count; 859 target_value = target_value - forward_count;
871 random_value = 860 random_value =
872 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); 861 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
873 if (random_value < (target_value * UINT32_MAX)) 862 if (random_value < (target_value * UINT32_MAX))
874 forward_count++; 863 forward_count++;
875 return forward_count; 864 return forward_count;
@@ -888,8 +877,8 @@ get_forward_count (uint32_t hop_count,
888 * the two hash codes increases 877 * the two hash codes increases
889 */ 878 */
890static unsigned int 879static unsigned int
891get_distance (const struct GNUNET_HashCode *target, 880get_distance(const struct GNUNET_HashCode *target,
892 const struct GNUNET_HashCode *have) 881 const struct GNUNET_HashCode *have)
893{ 882{
894 unsigned int bucket; 883 unsigned int bucket;
895 unsigned int msb; 884 unsigned int msb;
@@ -911,13 +900,13 @@ get_distance (const struct GNUNET_HashCode *target,
911 900
912 /* first, calculate the most significant 9 bits of our 901 /* first, calculate the most significant 9 bits of our
913 * result, aka the number of LSBs */ 902 * result, aka the number of LSBs */
914 bucket = GNUNET_CRYPTO_hash_matching_bits (target, 903 bucket = GNUNET_CRYPTO_hash_matching_bits(target,
915 have); 904 have);
916 /* bucket is now a value between 0 and 512 */ 905 /* bucket is now a value between 0 and 512 */
917 if (bucket == 512) 906 if (bucket == 512)
918 return 0; /* perfect match */ 907 return 0; /* perfect match */
919 if (bucket == 0) 908 if (bucket == 0)
920 return (unsigned int) -1; /* LSB differs; use max (if we did the bit-shifting 909 return (unsigned int)-1; /* LSB differs; use max (if we did the bit-shifting
921 * below, we'd end up with max+1 (overflow)) */ 910 * below, we'd end up with max+1 (overflow)) */
922 911
923 /* calculate the most significant bits of the final result */ 912 /* calculate the most significant bits of the final result */
@@ -927,14 +916,14 @@ get_distance (const struct GNUNET_HashCode *target,
927 * mismatching bit at 'bucket' */ 916 * mismatching bit at 'bucket' */
928 lsb = 0; 917 lsb = 0;
929 for (i = bucket + 1; 918 for (i = bucket + 1;
930 (i < sizeof (struct GNUNET_HashCode) * 8) && (i < bucket + 1 + 32 - 9); i++) 919 (i < sizeof(struct GNUNET_HashCode) * 8) && (i < bucket + 1 + 32 - 9); i++)
931 { 920 {
932 if (GNUNET_CRYPTO_hash_get_bit (target, i) != 921 if (GNUNET_CRYPTO_hash_get_bit(target, i) !=
933 GNUNET_CRYPTO_hash_get_bit (have, i)) 922 GNUNET_CRYPTO_hash_get_bit(have, i))
934 lsb |= (1 << (bucket + 32 - 9 - i)); /* first bit set will be 10, 923 lsb |= (1 << (bucket + 32 - 9 - i)); /* first bit set will be 10,
935 * last bit set will be 31 -- if 924 * last bit set will be 31 -- if
936 * i does not reach 512 first... */ 925 * i does not reach 512 first... */
937 } 926 }
938 return msb | lsb; 927 return msb | lsb;
939} 928}
940 929
@@ -950,40 +939,40 @@ get_distance (const struct GNUNET_HashCode *target,
950 * #GNUNET_NO otherwise. 939 * #GNUNET_NO otherwise.
951 */ 940 */
952int 941int
953GDS_am_closest_peer (const struct GNUNET_HashCode *key, 942GDS_am_closest_peer(const struct GNUNET_HashCode *key,
954 const struct GNUNET_CONTAINER_BloomFilter *bloom) 943 const struct GNUNET_CONTAINER_BloomFilter *bloom)
955{ 944{
956 int bits; 945 int bits;
957 int other_bits; 946 int other_bits;
958 int bucket_num; 947 int bucket_num;
959 struct PeerInfo *pos; 948 struct PeerInfo *pos;
960 949
961 if (0 == GNUNET_memcmp (&my_identity_hash, 950 if (0 == GNUNET_memcmp(&my_identity_hash,
962 key)) 951 key))
963 return GNUNET_YES; 952 return GNUNET_YES;
964 bucket_num = find_bucket (key); 953 bucket_num = find_bucket(key);
965 GNUNET_assert (bucket_num >= 0); 954 GNUNET_assert(bucket_num >= 0);
966 bits = GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash, 955 bits = GNUNET_CRYPTO_hash_matching_bits(&my_identity_hash,
967 key); 956 key);
968 pos = k_buckets[bucket_num].head; 957 pos = k_buckets[bucket_num].head;
969 while (NULL != pos) 958 while (NULL != pos)
970 {
971 if ( (NULL != bloom) &&
972 (GNUNET_YES ==
973 GNUNET_CONTAINER_bloomfilter_test (bloom,
974 &pos->phash)) )
975 { 959 {
960 if ((NULL != bloom) &&
961 (GNUNET_YES ==
962 GNUNET_CONTAINER_bloomfilter_test(bloom,
963 &pos->phash)))
964 {
965 pos = pos->next;
966 continue; /* Skip already checked entries */
967 }
968 other_bits = GNUNET_CRYPTO_hash_matching_bits(&pos->phash,
969 key);
970 if (other_bits > bits)
971 return GNUNET_NO;
972 if (other_bits == bits) /* We match the same number of bits */
973 return GNUNET_YES;
976 pos = pos->next; 974 pos = pos->next;
977 continue; /* Skip already checked entries */
978 } 975 }
979 other_bits = GNUNET_CRYPTO_hash_matching_bits (&pos->phash,
980 key);
981 if (other_bits > bits)
982 return GNUNET_NO;
983 if (other_bits == bits) /* We match the same number of bits */
984 return GNUNET_YES;
985 pos = pos->next;
986 }
987 /* No peers closer, we are the closest! */ 976 /* No peers closer, we are the closest! */
988 return GNUNET_YES; 977 return GNUNET_YES;
989} 978}
@@ -1007,9 +996,9 @@ GDS_am_closest_peer (const struct GNUNET_HashCode *key,
1007 * @return Peer to route to, or NULL on error 996 * @return Peer to route to, or NULL on error
1008 */ 997 */
1009static struct PeerInfo * 998static struct PeerInfo *
1010select_peer (const struct GNUNET_HashCode *key, 999select_peer(const struct GNUNET_HashCode *key,
1011 const struct GNUNET_CONTAINER_BloomFilter *bloom, 1000 const struct GNUNET_CONTAINER_BloomFilter *bloom,
1012 uint32_t hops) 1001 uint32_t hops)
1013{ 1002{
1014 unsigned int bc; 1003 unsigned int bc;
1015 unsigned int count; 1004 unsigned int count;
@@ -1019,126 +1008,126 @@ select_peer (const struct GNUNET_HashCode *key,
1019 unsigned int smallest_distance; 1008 unsigned int smallest_distance;
1020 struct PeerInfo *chosen; 1009 struct PeerInfo *chosen;
1021 1010
1022 if (hops >= GDS_NSE_get ()) 1011 if (hops >= GDS_NSE_get())
1023 {
1024 /* greedy selection (closest peer that is not in bloomfilter) */
1025 smallest_distance = UINT_MAX;
1026 chosen = NULL;
1027 for (bc = 0; bc <= closest_bucket; bc++)
1028 { 1012 {
1029 pos = k_buckets[bc].head; 1013 /* greedy selection (closest peer that is not in bloomfilter) */
1030 count = 0; 1014 smallest_distance = UINT_MAX;
1031 while ((pos != NULL) && (count < bucket_size)) 1015 chosen = NULL;
1032 { 1016 for (bc = 0; bc <= closest_bucket; bc++)
1033 if ( (NULL == bloom) ||
1034 (GNUNET_NO ==
1035 GNUNET_CONTAINER_bloomfilter_test (bloom,
1036 &pos->phash)))
1037 { 1017 {
1038 dist = get_distance (key, 1018 pos = k_buckets[bc].head;
1039 &pos->phash); 1019 count = 0;
1040 if (dist < smallest_distance) 1020 while ((pos != NULL) && (count < bucket_size))
1041 { 1021 {
1042 chosen = pos; 1022 if ((NULL == bloom) ||
1043 smallest_distance = dist; 1023 (GNUNET_NO ==
1044 } 1024 GNUNET_CONTAINER_bloomfilter_test(bloom,
1025 &pos->phash)))
1026 {
1027 dist = get_distance(key,
1028 &pos->phash);
1029 if (dist < smallest_distance)
1030 {
1031 chosen = pos;
1032 smallest_distance = dist;
1033 }
1034 }
1035 else
1036 {
1037 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1038 "Excluded peer `%s' due to BF match in greedy routing for %s\n",
1039 GNUNET_i2s(pos->id),
1040 GNUNET_h2s(key));
1041 GNUNET_STATISTICS_update(GDS_stats,
1042 gettext_noop("# Peers excluded from routing due to Bloomfilter"),
1043 1,
1044 GNUNET_NO);
1045 dist = get_distance(key,
1046 &pos->phash);
1047 if (dist < smallest_distance)
1048 {
1049 chosen = NULL;
1050 smallest_distance = dist;
1051 }
1052 }
1053 count++;
1054 pos = pos->next;
1055 }
1045 } 1056 }
1046 else 1057 if (NULL == chosen)
1047 { 1058 GNUNET_STATISTICS_update(GDS_stats,
1048 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1059 gettext_noop("# Peer selection failed"),
1049 "Excluded peer `%s' due to BF match in greedy routing for %s\n", 1060 1,
1050 GNUNET_i2s (pos->id), 1061 GNUNET_NO);
1051 GNUNET_h2s (key)); 1062 else
1052 GNUNET_STATISTICS_update (GDS_stats, 1063 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1053 gettext_noop ("# Peers excluded from routing due to Bloomfilter"), 1064 "Selected peer `%s' in greedy routing for %s\n",
1054 1, 1065 GNUNET_i2s(chosen->id),
1055 GNUNET_NO); 1066 GNUNET_h2s(key));
1056 dist = get_distance (key, 1067 return chosen;
1057 &pos->phash);
1058 if (dist < smallest_distance)
1059 {
1060 chosen = NULL;
1061 smallest_distance = dist;
1062 }
1063 }
1064 count++;
1065 pos = pos->next;
1066 }
1067 } 1068 }
1068 if (NULL == chosen)
1069 GNUNET_STATISTICS_update (GDS_stats,
1070 gettext_noop ("# Peer selection failed"),
1071 1,
1072 GNUNET_NO);
1073 else
1074 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1075 "Selected peer `%s' in greedy routing for %s\n",
1076 GNUNET_i2s (chosen->id),
1077 GNUNET_h2s (key));
1078 return chosen;
1079 }
1080 1069
1081 /* select "random" peer */ 1070 /* select "random" peer */
1082 /* count number of peers that are available and not filtered */ 1071 /* count number of peers that are available and not filtered */
1083 count = 0; 1072 count = 0;
1084 for (bc = 0; bc <= closest_bucket; bc++) 1073 for (bc = 0; bc <= closest_bucket; bc++)
1085 {
1086 pos = k_buckets[bc].head;
1087 while ( (NULL != pos) && (count < bucket_size) )
1088 { 1074 {
1089 if ( (NULL != bloom) && 1075 pos = k_buckets[bc].head;
1090 (GNUNET_YES == 1076 while ((NULL != pos) && (count < bucket_size))
1091 GNUNET_CONTAINER_bloomfilter_test (bloom, 1077 {
1092 &pos->phash)) ) 1078 if ((NULL != bloom) &&
1093 { 1079 (GNUNET_YES ==
1094 GNUNET_STATISTICS_update (GDS_stats, 1080 GNUNET_CONTAINER_bloomfilter_test(bloom,
1095 gettext_noop 1081 &pos->phash)))
1096 ("# Peers excluded from routing due to Bloomfilter"), 1082 {
1097 1, GNUNET_NO); 1083 GNUNET_STATISTICS_update(GDS_stats,
1098 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1084 gettext_noop
1099 "Excluded peer `%s' due to BF match in random routing for %s\n", 1085 ("# Peers excluded from routing due to Bloomfilter"),
1100 GNUNET_i2s (pos->id), 1086 1, GNUNET_NO);
1101 GNUNET_h2s (key)); 1087 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1102 pos = pos->next; 1088 "Excluded peer `%s' due to BF match in random routing for %s\n",
1103 continue; /* Ignore bloomfiltered peers */ 1089 GNUNET_i2s(pos->id),
1104 } 1090 GNUNET_h2s(key));
1105 count++; 1091 pos = pos->next;
1106 pos = pos->next; 1092 continue; /* Ignore bloomfiltered peers */
1093 }
1094 count++;
1095 pos = pos->next;
1096 }
1107 } 1097 }
1108 }
1109 if (0 == count) /* No peers to select from! */ 1098 if (0 == count) /* No peers to select from! */
1110 { 1099 {
1111 GNUNET_STATISTICS_update (GDS_stats, 1100 GNUNET_STATISTICS_update(GDS_stats,
1112 gettext_noop ("# Peer selection failed"), 1, 1101 gettext_noop("# Peer selection failed"), 1,
1113 GNUNET_NO); 1102 GNUNET_NO);
1114 return NULL; 1103 return NULL;
1115 } 1104 }
1116 /* Now actually choose a peer */ 1105 /* Now actually choose a peer */
1117 selected = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1106 selected = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
1118 count); 1107 count);
1119 count = 0; 1108 count = 0;
1120 for (bc = 0; bc <= closest_bucket; bc++) 1109 for (bc = 0; bc <= closest_bucket; bc++)
1121 {
1122 for (pos = k_buckets[bc].head; ((pos != NULL) && (count < bucket_size)); pos = pos->next)
1123 { 1110 {
1124 if ((bloom != NULL) && 1111 for (pos = k_buckets[bc].head; ((pos != NULL) && (count < bucket_size)); pos = pos->next)
1125 (GNUNET_YES == 1112 {
1126 GNUNET_CONTAINER_bloomfilter_test (bloom, 1113 if ((bloom != NULL) &&
1127 &pos->phash))) 1114 (GNUNET_YES ==
1128 { 1115 GNUNET_CONTAINER_bloomfilter_test(bloom,
1129 continue; /* Ignore bloomfiltered peers */ 1116 &pos->phash)))
1130 } 1117 {
1131 if (0 == selected--) 1118 continue; /* Ignore bloomfiltered peers */
1132 { 1119 }
1133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1120 if (0 == selected--)
1134 "Selected peer `%s' in random routing for %s\n", 1121 {
1135 GNUNET_i2s (pos->id), 1122 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1136 GNUNET_h2s (key)); 1123 "Selected peer `%s' in random routing for %s\n",
1137 return pos; 1124 GNUNET_i2s(pos->id),
1138 } 1125 GNUNET_h2s(key));
1126 return pos;
1127 }
1128 }
1139 } 1129 }
1140 } 1130 GNUNET_break(0);
1141 GNUNET_break (0);
1142 return NULL; 1131 return NULL;
1143} 1132}
1144 1133
@@ -1157,60 +1146,60 @@ select_peer (const struct GNUNET_HashCode *key,
1157 * @return number of peers returned in 'targets'. 1146 * @return number of peers returned in 'targets'.
1158 */ 1147 */
1159static unsigned int 1148static unsigned int
1160get_target_peers (const struct GNUNET_HashCode *key, 1149get_target_peers(const struct GNUNET_HashCode *key,
1161 struct GNUNET_CONTAINER_BloomFilter *bloom, 1150 struct GNUNET_CONTAINER_BloomFilter *bloom,
1162 uint32_t hop_count, 1151 uint32_t hop_count,
1163 uint32_t target_replication, 1152 uint32_t target_replication,
1164 struct PeerInfo ***targets) 1153 struct PeerInfo ***targets)
1165{ 1154{
1166 unsigned int ret; 1155 unsigned int ret;
1167 unsigned int off; 1156 unsigned int off;
1168 struct PeerInfo **rtargets; 1157 struct PeerInfo **rtargets;
1169 struct PeerInfo *nxt; 1158 struct PeerInfo *nxt;
1170 1159
1171 GNUNET_assert (NULL != bloom); 1160 GNUNET_assert(NULL != bloom);
1172 ret = get_forward_count (hop_count, 1161 ret = get_forward_count(hop_count,
1173 target_replication); 1162 target_replication);
1174 if (0 == ret) 1163 if (0 == ret)
1175 { 1164 {
1176 *targets = NULL; 1165 *targets = NULL;
1177 return 0; 1166 return 0;
1178 } 1167 }
1179 rtargets = GNUNET_new_array (ret, 1168 rtargets = GNUNET_new_array(ret,
1180 struct PeerInfo *); 1169 struct PeerInfo *);
1181 for (off = 0; off < ret; off++) 1170 for (off = 0; off < ret; off++)
1182 { 1171 {
1183 nxt = select_peer (key, 1172 nxt = select_peer(key,
1184 bloom, 1173 bloom,
1185 hop_count); 1174 hop_count);
1186 if (NULL == nxt) 1175 if (NULL == nxt)
1187 break; 1176 break;
1188 rtargets[off] = nxt; 1177 rtargets[off] = nxt;
1189 GNUNET_break (GNUNET_NO == 1178 GNUNET_break(GNUNET_NO ==
1190 GNUNET_CONTAINER_bloomfilter_test (bloom, 1179 GNUNET_CONTAINER_bloomfilter_test(bloom,
1191 &nxt->phash)); 1180 &nxt->phash));
1192 GNUNET_CONTAINER_bloomfilter_add (bloom, 1181 GNUNET_CONTAINER_bloomfilter_add(bloom,
1193 &nxt->phash); 1182 &nxt->phash);
1194 } 1183 }
1195 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1184 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1196 "Selected %u/%u peers at hop %u for %s (target was %u)\n", 1185 "Selected %u/%u peers at hop %u for %s (target was %u)\n",
1197 off, 1186 off,
1198 GNUNET_CONTAINER_multipeermap_size (all_connected_peers), 1187 GNUNET_CONTAINER_multipeermap_size(all_connected_peers),
1199 (unsigned int) hop_count, 1188 (unsigned int)hop_count,
1200 GNUNET_h2s (key), 1189 GNUNET_h2s(key),
1201 ret); 1190 ret);
1202 if (0 == off) 1191 if (0 == off)
1203 { 1192 {
1204 GNUNET_free (rtargets); 1193 GNUNET_free(rtargets);
1205 *targets = NULL; 1194 *targets = NULL;
1206 return 0; 1195 return 0;
1207 } 1196 }
1208 *targets = rtargets; 1197 *targets = rtargets;
1209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1198 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1210 "Forwarding query `%s' to %u peers (goal was %u peers)\n", 1199 "Forwarding query `%s' to %u peers (goal was %u peers)\n",
1211 GNUNET_h2s (key), 1200 GNUNET_h2s(key),
1212 off, 1201 off,
1213 ret); 1202 ret);
1214 return off; 1203 return off;
1215} 1204}
1216 1205
@@ -1236,17 +1225,17 @@ get_target_peers (const struct GNUNET_HashCode *key,
1236 * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not 1225 * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not
1237 */ 1226 */
1238int 1227int
1239GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, 1228GDS_NEIGHBOURS_handle_put(enum GNUNET_BLOCK_Type type,
1240 enum GNUNET_DHT_RouteOption options, 1229 enum GNUNET_DHT_RouteOption options,
1241 uint32_t desired_replication_level, 1230 uint32_t desired_replication_level,
1242 struct GNUNET_TIME_Absolute expiration_time, 1231 struct GNUNET_TIME_Absolute expiration_time,
1243 uint32_t hop_count, 1232 uint32_t hop_count,
1244 struct GNUNET_CONTAINER_BloomFilter *bf, 1233 struct GNUNET_CONTAINER_BloomFilter *bf,
1245 const struct GNUNET_HashCode *key, 1234 const struct GNUNET_HashCode *key,
1246 unsigned int put_path_length, 1235 unsigned int put_path_length,
1247 struct GNUNET_PeerIdentity *put_path, 1236 struct GNUNET_PeerIdentity *put_path,
1248 const void *data, 1237 const void *data,
1249 size_t data_size) 1238 size_t data_size)
1250{ 1239{
1251 unsigned int target_count; 1240 unsigned int target_count;
1252 unsigned int i; 1241 unsigned int i;
@@ -1258,97 +1247,97 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
1258 struct GNUNET_PeerIdentity *pp; 1247 struct GNUNET_PeerIdentity *pp;
1259 unsigned int skip_count; 1248 unsigned int skip_count;
1260 1249
1261 GNUNET_assert (NULL != bf); 1250 GNUNET_assert(NULL != bf);
1262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1251 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1263 "Adding myself (%s) to PUT bloomfilter for %s\n", 1252 "Adding myself (%s) to PUT bloomfilter for %s\n",
1264 GNUNET_i2s (&my_identity), 1253 GNUNET_i2s(&my_identity),
1265 GNUNET_h2s (key)); 1254 GNUNET_h2s(key));
1266 GNUNET_CONTAINER_bloomfilter_add (bf, 1255 GNUNET_CONTAINER_bloomfilter_add(bf,
1267 &my_identity_hash); 1256 &my_identity_hash);
1268 GNUNET_STATISTICS_update (GDS_stats, 1257 GNUNET_STATISTICS_update(GDS_stats,
1269 gettext_noop ("# PUT requests routed"), 1258 gettext_noop("# PUT requests routed"),
1270 1, 1259 1,
1271 GNUNET_NO); 1260 GNUNET_NO);
1272 target_count 1261 target_count
1273 = get_target_peers (key, 1262 = get_target_peers(key,
1274 bf, 1263 bf,
1275 hop_count, 1264 hop_count,
1276 desired_replication_level, 1265 desired_replication_level,
1277 &targets); 1266 &targets);
1278 if (0 == target_count) 1267 if (0 == target_count)
1279 { 1268 {
1280 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1269 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1281 "Routing PUT for %s terminates after %u hops at %s\n", 1270 "Routing PUT for %s terminates after %u hops at %s\n",
1282 GNUNET_h2s (key), 1271 GNUNET_h2s(key),
1283 (unsigned int) hop_count, 1272 (unsigned int)hop_count,
1284 GNUNET_i2s (&my_identity)); 1273 GNUNET_i2s(&my_identity));
1285 return GNUNET_NO; 1274 return GNUNET_NO;
1286 } 1275 }
1287 msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size; 1276 msize = put_path_length * sizeof(struct GNUNET_PeerIdentity) + data_size;
1288 if (msize + sizeof (struct PeerPutMessage) 1277 if (msize + sizeof(struct PeerPutMessage)
1289 >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) 1278 >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE)
1290 { 1279 {
1291 put_path_length = 0; 1280 put_path_length = 0;
1292 msize = data_size; 1281 msize = data_size;
1293 } 1282 }
1294 if (msize + sizeof (struct PeerPutMessage) 1283 if (msize + sizeof(struct PeerPutMessage)
1295 >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) 1284 >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE)
1296 { 1285 {
1297 GNUNET_break (0); 1286 GNUNET_break(0);
1298 GNUNET_free (targets); 1287 GNUNET_free(targets);
1299 return GNUNET_NO; 1288 return GNUNET_NO;
1300 } 1289 }
1301 GNUNET_STATISTICS_update (GDS_stats, 1290 GNUNET_STATISTICS_update(GDS_stats,
1302 gettext_noop ("# PUT messages queued for transmission"), 1291 gettext_noop("# PUT messages queued for transmission"),
1303 target_count, 1292 target_count,
1304 GNUNET_NO); 1293 GNUNET_NO);
1305 skip_count = 0; 1294 skip_count = 0;
1306 for (i = 0; i < target_count; i++) 1295 for (i = 0; i < target_count; i++)
1307 {
1308 target = targets[i];
1309 if (GNUNET_MQ_get_length (target->mq) >= MAXIMUM_PENDING_PER_PEER)
1310 { 1296 {
1311 /* skip */ 1297 target = targets[i];
1312 GNUNET_STATISTICS_update (GDS_stats, 1298 if (GNUNET_MQ_get_length(target->mq) >= MAXIMUM_PENDING_PER_PEER)
1313 gettext_noop ("# P2P messages dropped due to full queue"), 1299 {
1314 1, 1300 /* skip */
1315 GNUNET_NO); 1301 GNUNET_STATISTICS_update(GDS_stats,
1316 skip_count++; 1302 gettext_noop("# P2P messages dropped due to full queue"),
1317 continue; 1303 1,
1318 } 1304 GNUNET_NO);
1319 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1305 skip_count++;
1320 "Routing PUT for %s after %u hops to %s\n", 1306 continue;
1321 GNUNET_h2s (key), 1307 }
1322 (unsigned int) hop_count, 1308 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1323 GNUNET_i2s (target->id)); 1309 "Routing PUT for %s after %u hops to %s\n",
1324 env = GNUNET_MQ_msg_extra (ppm, 1310 GNUNET_h2s(key),
1325 msize, 1311 (unsigned int)hop_count,
1326 GNUNET_MESSAGE_TYPE_DHT_P2P_PUT); 1312 GNUNET_i2s(target->id));
1327 ppm->options = htonl (options); 1313 env = GNUNET_MQ_msg_extra(ppm,
1328 ppm->type = htonl (type); 1314 msize,
1329 ppm->hop_count = htonl (hop_count + 1); 1315 GNUNET_MESSAGE_TYPE_DHT_P2P_PUT);
1330 ppm->desired_replication_level = htonl (desired_replication_level); 1316 ppm->options = htonl(options);
1331 ppm->put_path_length = htonl (put_path_length); 1317 ppm->type = htonl(type);
1332 ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); 1318 ppm->hop_count = htonl(hop_count + 1);
1333 GNUNET_break (GNUNET_YES == 1319 ppm->desired_replication_level = htonl(desired_replication_level);
1334 GNUNET_CONTAINER_bloomfilter_test (bf, 1320 ppm->put_path_length = htonl(put_path_length);
1321 ppm->expiration_time = GNUNET_TIME_absolute_hton(expiration_time);
1322 GNUNET_break(GNUNET_YES ==
1323 GNUNET_CONTAINER_bloomfilter_test(bf,
1335 &target->phash)); 1324 &target->phash));
1336 GNUNET_assert (GNUNET_OK == 1325 GNUNET_assert(GNUNET_OK ==
1337 GNUNET_CONTAINER_bloomfilter_get_raw_data (bf, 1326 GNUNET_CONTAINER_bloomfilter_get_raw_data(bf,
1338 ppm->bloomfilter, 1327 ppm->bloomfilter,
1339 DHT_BLOOM_SIZE)); 1328 DHT_BLOOM_SIZE));
1340 ppm->key = *key; 1329 ppm->key = *key;
1341 pp = (struct GNUNET_PeerIdentity *) &ppm[1]; 1330 pp = (struct GNUNET_PeerIdentity *)&ppm[1];
1342 GNUNET_memcpy (pp, 1331 GNUNET_memcpy(pp,
1343 put_path, 1332 put_path,
1344 sizeof (struct GNUNET_PeerIdentity) * put_path_length); 1333 sizeof(struct GNUNET_PeerIdentity) * put_path_length);
1345 GNUNET_memcpy (&pp[put_path_length], 1334 GNUNET_memcpy(&pp[put_path_length],
1346 data, 1335 data,
1347 data_size); 1336 data_size);
1348 GNUNET_MQ_send (target->mq, 1337 GNUNET_MQ_send(target->mq,
1349 env); 1338 env);
1350 } 1339 }
1351 GNUNET_free (targets); 1340 GNUNET_free(targets);
1352 return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO; 1341 return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO;
1353} 1342}
1354 1343
@@ -1371,15 +1360,15 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
1371 * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not 1360 * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not
1372 */ 1361 */
1373int 1362int
1374GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, 1363GDS_NEIGHBOURS_handle_get(enum GNUNET_BLOCK_Type type,
1375 enum GNUNET_DHT_RouteOption options, 1364 enum GNUNET_DHT_RouteOption options,
1376 uint32_t desired_replication_level, 1365 uint32_t desired_replication_level,
1377 uint32_t hop_count, 1366 uint32_t hop_count,
1378 const struct GNUNET_HashCode *key, 1367 const struct GNUNET_HashCode *key,
1379 const void *xquery, 1368 const void *xquery,
1380 size_t xquery_size, 1369 size_t xquery_size,
1381 struct GNUNET_BLOCK_Group *bg, 1370 struct GNUNET_BLOCK_Group *bg,
1382 struct GNUNET_CONTAINER_BloomFilter *peer_bf) 1371 struct GNUNET_CONTAINER_BloomFilter *peer_bf)
1383{ 1372{
1384 unsigned int target_count; 1373 unsigned int target_count;
1385 struct PeerInfo **targets; 1374 struct PeerInfo **targets;
@@ -1393,102 +1382,102 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1393 unsigned int skip_count; 1382 unsigned int skip_count;
1394 uint32_t bf_nonce; 1383 uint32_t bf_nonce;
1395 1384
1396 GNUNET_assert (NULL != peer_bf); 1385 GNUNET_assert(NULL != peer_bf);
1397 GNUNET_STATISTICS_update (GDS_stats, 1386 GNUNET_STATISTICS_update(GDS_stats,
1398 gettext_noop ("# GET requests routed"), 1387 gettext_noop("# GET requests routed"),
1399 1, 1388 1,
1400 GNUNET_NO); 1389 GNUNET_NO);
1401 target_count = get_target_peers (key, 1390 target_count = get_target_peers(key,
1402 peer_bf, 1391 peer_bf,
1403 hop_count, 1392 hop_count,
1404 desired_replication_level, 1393 desired_replication_level,
1405 &targets); 1394 &targets);
1406 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1395 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1407 "Adding myself (%s) to GET bloomfilter for %s\n", 1396 "Adding myself (%s) to GET bloomfilter for %s\n",
1408 GNUNET_i2s (&my_identity), 1397 GNUNET_i2s(&my_identity),
1409 GNUNET_h2s (key)); 1398 GNUNET_h2s(key));
1410 GNUNET_CONTAINER_bloomfilter_add (peer_bf, 1399 GNUNET_CONTAINER_bloomfilter_add(peer_bf,
1411 &my_identity_hash); 1400 &my_identity_hash);
1412 if (0 == target_count) 1401 if (0 == target_count)
1413 { 1402 {
1414 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1403 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1415 "Routing GET for %s terminates after %u hops at %s\n", 1404 "Routing GET for %s terminates after %u hops at %s\n",
1416 GNUNET_h2s (key), 1405 GNUNET_h2s(key),
1417 (unsigned int) hop_count, 1406 (unsigned int)hop_count,
1418 GNUNET_i2s (&my_identity)); 1407 GNUNET_i2s(&my_identity));
1419 return GNUNET_NO; 1408 return GNUNET_NO;
1420 } 1409 }
1421 if (GNUNET_OK != 1410 if (GNUNET_OK !=
1422 GNUNET_BLOCK_group_serialize (bg, 1411 GNUNET_BLOCK_group_serialize(bg,
1423 &bf_nonce, 1412 &bf_nonce,
1424 &reply_bf, 1413 &reply_bf,
1425 &reply_bf_size)) 1414 &reply_bf_size))
1426 { 1415 {
1427 reply_bf = NULL; 1416 reply_bf = NULL;
1428 reply_bf_size = 0; 1417 reply_bf_size = 0;
1429 bf_nonce = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1418 bf_nonce = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
1430 UINT32_MAX); 1419 UINT32_MAX);
1431 } 1420 }
1432 msize = xquery_size + reply_bf_size; 1421 msize = xquery_size + reply_bf_size;
1433 if (msize + sizeof (struct PeerGetMessage) >= GNUNET_MAX_MESSAGE_SIZE) 1422 if (msize + sizeof(struct PeerGetMessage) >= GNUNET_MAX_MESSAGE_SIZE)
1434 { 1423 {
1435 GNUNET_break (0); 1424 GNUNET_break(0);
1436 GNUNET_free_non_null (reply_bf); 1425 GNUNET_free_non_null(reply_bf);
1437 GNUNET_free (targets); 1426 GNUNET_free(targets);
1438 return GNUNET_NO; 1427 return GNUNET_NO;
1439 } 1428 }
1440 GNUNET_STATISTICS_update (GDS_stats, 1429 GNUNET_STATISTICS_update(GDS_stats,
1441 gettext_noop ("# GET messages queued for transmission"), 1430 gettext_noop("# GET messages queued for transmission"),
1442 target_count, 1431 target_count,
1443 GNUNET_NO); 1432 GNUNET_NO);
1444 /* forward request */ 1433 /* forward request */
1445 skip_count = 0; 1434 skip_count = 0;
1446 for (unsigned int i = 0; i < target_count; i++) 1435 for (unsigned int i = 0; i < target_count; i++)
1447 {
1448 target = targets[i];
1449 if (GNUNET_MQ_get_length (target->mq) >= MAXIMUM_PENDING_PER_PEER)
1450 { 1436 {
1451 /* skip */ 1437 target = targets[i];
1452 GNUNET_STATISTICS_update (GDS_stats, 1438 if (GNUNET_MQ_get_length(target->mq) >= MAXIMUM_PENDING_PER_PEER)
1453 gettext_noop ("# P2P messages dropped due to full queue"), 1439 {
1454 1, GNUNET_NO); 1440 /* skip */
1455 skip_count++; 1441 GNUNET_STATISTICS_update(GDS_stats,
1456 continue; 1442 gettext_noop("# P2P messages dropped due to full queue"),
1457 } 1443 1, GNUNET_NO);
1458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1444 skip_count++;
1459 "Routing GET for %s after %u hops to %s\n", 1445 continue;
1460 GNUNET_h2s (key), 1446 }
1461 (unsigned int) hop_count, 1447 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1462 GNUNET_i2s (target->id)); 1448 "Routing GET for %s after %u hops to %s\n",
1463 env = GNUNET_MQ_msg_extra (pgm, 1449 GNUNET_h2s(key),
1464 msize, 1450 (unsigned int)hop_count,
1465 GNUNET_MESSAGE_TYPE_DHT_P2P_GET); 1451 GNUNET_i2s(target->id));
1466 pgm->options = htonl (options); 1452 env = GNUNET_MQ_msg_extra(pgm,
1467 pgm->type = htonl (type); 1453 msize,
1468 pgm->hop_count = htonl (hop_count + 1); 1454 GNUNET_MESSAGE_TYPE_DHT_P2P_GET);
1469 pgm->desired_replication_level = htonl (desired_replication_level); 1455 pgm->options = htonl(options);
1470 pgm->xquery_size = htonl (xquery_size); 1456 pgm->type = htonl(type);
1471 pgm->bf_mutator = bf_nonce; 1457 pgm->hop_count = htonl(hop_count + 1);
1472 GNUNET_break (GNUNET_YES == 1458 pgm->desired_replication_level = htonl(desired_replication_level);
1473 GNUNET_CONTAINER_bloomfilter_test (peer_bf, 1459 pgm->xquery_size = htonl(xquery_size);
1460 pgm->bf_mutator = bf_nonce;
1461 GNUNET_break(GNUNET_YES ==
1462 GNUNET_CONTAINER_bloomfilter_test(peer_bf,
1474 &target->phash)); 1463 &target->phash));
1475 GNUNET_assert (GNUNET_OK == 1464 GNUNET_assert(GNUNET_OK ==
1476 GNUNET_CONTAINER_bloomfilter_get_raw_data (peer_bf, 1465 GNUNET_CONTAINER_bloomfilter_get_raw_data(peer_bf,
1477 pgm->bloomfilter, 1466 pgm->bloomfilter,
1478 DHT_BLOOM_SIZE)); 1467 DHT_BLOOM_SIZE));
1479 pgm->key = *key; 1468 pgm->key = *key;
1480 xq = (char *) &pgm[1]; 1469 xq = (char *)&pgm[1];
1481 GNUNET_memcpy (xq, 1470 GNUNET_memcpy(xq,
1482 xquery, 1471 xquery,
1483 xquery_size); 1472 xquery_size);
1484 GNUNET_memcpy (&xq[xquery_size], 1473 GNUNET_memcpy(&xq[xquery_size],
1485 reply_bf, 1474 reply_bf,
1486 reply_bf_size); 1475 reply_bf_size);
1487 GNUNET_MQ_send (target->mq, 1476 GNUNET_MQ_send(target->mq,
1488 env); 1477 env);
1489 } 1478 }
1490 GNUNET_free (targets); 1479 GNUNET_free(targets);
1491 GNUNET_free_non_null (reply_bf); 1480 GNUNET_free_non_null(reply_bf);
1492 return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO; 1481 return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO;
1493} 1482}
1494 1483
@@ -1510,16 +1499,16 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1510 * @param data_size number of bytes in @a data 1499 * @param data_size number of bytes in @a data
1511 */ 1500 */
1512void 1501void
1513GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, 1502GDS_NEIGHBOURS_handle_reply(const struct GNUNET_PeerIdentity *target,
1514 enum GNUNET_BLOCK_Type type, 1503 enum GNUNET_BLOCK_Type type,
1515 struct GNUNET_TIME_Absolute expiration_time, 1504 struct GNUNET_TIME_Absolute expiration_time,
1516 const struct GNUNET_HashCode *key, 1505 const struct GNUNET_HashCode *key,
1517 unsigned int put_path_length, 1506 unsigned int put_path_length,
1518 const struct GNUNET_PeerIdentity *put_path, 1507 const struct GNUNET_PeerIdentity *put_path,
1519 unsigned int get_path_length, 1508 unsigned int get_path_length,
1520 const struct GNUNET_PeerIdentity *get_path, 1509 const struct GNUNET_PeerIdentity *get_path,
1521 const void *data, 1510 const void *data,
1522 size_t data_size) 1511 size_t data_size)
1523{ 1512{
1524 struct PeerInfo *pi; 1513 struct PeerInfo *pi;
1525 struct GNUNET_MQ_Envelope *env; 1514 struct GNUNET_MQ_Envelope *env;
@@ -1528,68 +1517,68 @@ GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target,
1528 struct GNUNET_PeerIdentity *paths; 1517 struct GNUNET_PeerIdentity *paths;
1529 1518
1530 msize = data_size + (get_path_length + put_path_length) * 1519 msize = data_size + (get_path_length + put_path_length) *
1531 sizeof (struct GNUNET_PeerIdentity); 1520 sizeof(struct GNUNET_PeerIdentity);
1532 if ((msize + sizeof (struct PeerResultMessage) >= GNUNET_MAX_MESSAGE_SIZE) || 1521 if ((msize + sizeof(struct PeerResultMessage) >= GNUNET_MAX_MESSAGE_SIZE) ||
1533 (get_path_length > 1522 (get_path_length >
1534 GNUNET_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || 1523 GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) ||
1535 (put_path_length > 1524 (put_path_length >
1536 GNUNET_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || 1525 GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) ||
1537 (data_size > GNUNET_MAX_MESSAGE_SIZE)) 1526 (data_size > GNUNET_MAX_MESSAGE_SIZE))
1538 { 1527 {
1539 GNUNET_break (0); 1528 GNUNET_break(0);
1540 return; 1529 return;
1541 } 1530 }
1542 pi = GNUNET_CONTAINER_multipeermap_get (all_connected_peers, 1531 pi = GNUNET_CONTAINER_multipeermap_get(all_connected_peers,
1543 target); 1532 target);
1544 if (NULL == pi) 1533 if (NULL == pi)
1545 { 1534 {
1546 /* peer disconnected in the meantime, drop reply */ 1535 /* peer disconnected in the meantime, drop reply */
1547 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1536 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1548 "No matching peer for reply for key %s\n", 1537 "No matching peer for reply for key %s\n",
1549 GNUNET_h2s (key)); 1538 GNUNET_h2s(key));
1550 return; 1539 return;
1551 } 1540 }
1552 if (GNUNET_MQ_get_length (pi->mq) >= MAXIMUM_PENDING_PER_PEER) 1541 if (GNUNET_MQ_get_length(pi->mq) >= MAXIMUM_PENDING_PER_PEER)
1553 { 1542 {
1554 /* skip */ 1543 /* skip */
1555 GNUNET_STATISTICS_update (GDS_stats, 1544 GNUNET_STATISTICS_update(GDS_stats,
1556 gettext_noop ("# P2P messages dropped due to full queue"), 1545 gettext_noop("# P2P messages dropped due to full queue"),
1557 1, 1546 1,
1558 GNUNET_NO); 1547 GNUNET_NO);
1559 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1548 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1560 "Peer queue full, ignoring reply for key %s\n", 1549 "Peer queue full, ignoring reply for key %s\n",
1561 GNUNET_h2s (key)); 1550 GNUNET_h2s(key));
1562 return; 1551 return;
1563 } 1552 }
1564 1553
1565 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1554 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1566 "Forwarding reply for key %s to peer %s\n", 1555 "Forwarding reply for key %s to peer %s\n",
1567 GNUNET_h2s (key), 1556 GNUNET_h2s(key),
1568 GNUNET_i2s (target)); 1557 GNUNET_i2s(target));
1569 GNUNET_STATISTICS_update (GDS_stats, 1558 GNUNET_STATISTICS_update(GDS_stats,
1570 gettext_noop 1559 gettext_noop
1571 ("# RESULT messages queued for transmission"), 1, 1560 ("# RESULT messages queued for transmission"), 1,
1572 GNUNET_NO); 1561 GNUNET_NO);
1573 env = GNUNET_MQ_msg_extra (prm, 1562 env = GNUNET_MQ_msg_extra(prm,
1574 msize, 1563 msize,
1575 GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT); 1564 GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT);
1576 prm->type = htonl (type); 1565 prm->type = htonl(type);
1577 prm->put_path_length = htonl (put_path_length); 1566 prm->put_path_length = htonl(put_path_length);
1578 prm->get_path_length = htonl (get_path_length); 1567 prm->get_path_length = htonl(get_path_length);
1579 prm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); 1568 prm->expiration_time = GNUNET_TIME_absolute_hton(expiration_time);
1580 prm->key = *key; 1569 prm->key = *key;
1581 paths = (struct GNUNET_PeerIdentity *) &prm[1]; 1570 paths = (struct GNUNET_PeerIdentity *)&prm[1];
1582 GNUNET_memcpy (paths, 1571 GNUNET_memcpy(paths,
1583 put_path, 1572 put_path,
1584 put_path_length * sizeof (struct GNUNET_PeerIdentity)); 1573 put_path_length * sizeof(struct GNUNET_PeerIdentity));
1585 GNUNET_memcpy (&paths[put_path_length], 1574 GNUNET_memcpy(&paths[put_path_length],
1586 get_path, 1575 get_path,
1587 get_path_length * sizeof (struct GNUNET_PeerIdentity)); 1576 get_path_length * sizeof(struct GNUNET_PeerIdentity));
1588 GNUNET_memcpy (&paths[put_path_length + get_path_length], 1577 GNUNET_memcpy(&paths[put_path_length + get_path_length],
1589 data, 1578 data,
1590 data_size); 1579 data_size);
1591 GNUNET_MQ_send (pi->mq, 1580 GNUNET_MQ_send(pi->mq,
1592 env); 1581 env);
1593} 1582}
1594 1583
1595 1584
@@ -1600,18 +1589,18 @@ GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target,
1600 * @param identity the public identity of this peer 1589 * @param identity the public identity of this peer
1601 */ 1590 */
1602static void 1591static void
1603core_init (void *cls, 1592core_init(void *cls,
1604 const struct GNUNET_PeerIdentity *identity) 1593 const struct GNUNET_PeerIdentity *identity)
1605{ 1594{
1606 (void) cls; 1595 (void)cls;
1607 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1596 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1608 "CORE called, I am %s\n", 1597 "CORE called, I am %s\n",
1609 GNUNET_i2s (identity)); 1598 GNUNET_i2s(identity));
1610 my_identity = *identity; 1599 my_identity = *identity;
1611 GNUNET_CRYPTO_hash (identity, 1600 GNUNET_CRYPTO_hash(identity,
1612 sizeof (struct GNUNET_PeerIdentity), 1601 sizeof(struct GNUNET_PeerIdentity),
1613 &my_identity_hash); 1602 &my_identity_hash);
1614 GNUNET_SERVICE_resume (GDS_service); 1603 GNUNET_SERVICE_resume(GDS_service);
1615} 1604}
1616 1605
1617 1606
@@ -1623,24 +1612,24 @@ core_init (void *cls,
1623 * @return #GNUNET_OK if the message is valid 1612 * @return #GNUNET_OK if the message is valid
1624 */ 1613 */
1625static int 1614static int
1626check_dht_p2p_put (void *cls, 1615check_dht_p2p_put(void *cls,
1627 const struct PeerPutMessage *put) 1616 const struct PeerPutMessage *put)
1628{ 1617{
1629 uint32_t putlen; 1618 uint32_t putlen;
1630 uint16_t msize; 1619 uint16_t msize;
1631 1620
1632 (void) cls; 1621 (void)cls;
1633 msize = ntohs (put->header.size); 1622 msize = ntohs(put->header.size);
1634 putlen = ntohl (put->put_path_length); 1623 putlen = ntohl(put->put_path_length);
1635 if ((msize < 1624 if ((msize <
1636 sizeof (struct PeerPutMessage) + 1625 sizeof(struct PeerPutMessage) +
1637 putlen * sizeof (struct GNUNET_PeerIdentity)) || 1626 putlen * sizeof(struct GNUNET_PeerIdentity)) ||
1638 (putlen > 1627 (putlen >
1639 GNUNET_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) 1628 GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)))
1640 { 1629 {
1641 GNUNET_break_op (0); 1630 GNUNET_break_op(0);
1642 return GNUNET_SYSERR; 1631 return GNUNET_SYSERR;
1643 } 1632 }
1644 return GNUNET_OK; 1633 return GNUNET_OK;
1645} 1634}
1646 1635
@@ -1652,8 +1641,8 @@ check_dht_p2p_put (void *cls,
1652 * @param message message 1641 * @param message message
1653 */ 1642 */
1654static void 1643static void
1655handle_dht_p2p_put (void *cls, 1644handle_dht_p2p_put(void *cls,
1656 const struct PeerPutMessage *put) 1645 const struct PeerPutMessage *put)
1657{ 1646{
1658 struct PeerInfo *peer = cls; 1647 struct PeerInfo *peer = cls;
1659 const struct GNUNET_PeerIdentity *put_path; 1648 const struct GNUNET_PeerIdentity *put_path;
@@ -1667,196 +1656,198 @@ handle_dht_p2p_put (void *cls,
1667 int forwarded; 1656 int forwarded;
1668 struct GNUNET_TIME_Absolute exp_time; 1657 struct GNUNET_TIME_Absolute exp_time;
1669 1658
1670 exp_time = GNUNET_TIME_absolute_ntoh (put->expiration_time); 1659 exp_time = GNUNET_TIME_absolute_ntoh(put->expiration_time);
1671 if (0 == GNUNET_TIME_absolute_get_remaining (exp_time).rel_value_us) 1660 if (0 == GNUNET_TIME_absolute_get_remaining(exp_time).rel_value_us)
1672 { 1661 {
1673 GNUNET_STATISTICS_update (GDS_stats, 1662 GNUNET_STATISTICS_update(GDS_stats,
1674 gettext_noop ("# Expired PUTs discarded"), 1663 gettext_noop("# Expired PUTs discarded"),
1675 1, 1664 1,
1676 GNUNET_NO); 1665 GNUNET_NO);
1677 return; 1666 return;
1678 } 1667 }
1679 msize = ntohs (put->header.size); 1668 msize = ntohs(put->header.size);
1680 putlen = ntohl (put->put_path_length); 1669 putlen = ntohl(put->put_path_length);
1681 GNUNET_STATISTICS_update (GDS_stats, 1670 GNUNET_STATISTICS_update(GDS_stats,
1682 gettext_noop ("# P2P PUT requests received"), 1671 gettext_noop("# P2P PUT requests received"),
1683 1, 1672 1,
1684 GNUNET_NO); 1673 GNUNET_NO);
1685 GNUNET_STATISTICS_update (GDS_stats, 1674 GNUNET_STATISTICS_update(GDS_stats,
1686 gettext_noop ("# P2P PUT bytes received"), 1675 gettext_noop("# P2P PUT bytes received"),
1687 msize, 1676 msize,
1688 GNUNET_NO); 1677 GNUNET_NO);
1689 put_path = (const struct GNUNET_PeerIdentity *) &put[1]; 1678 put_path = (const struct GNUNET_PeerIdentity *)&put[1];
1690 payload = &put_path[putlen]; 1679 payload = &put_path[putlen];
1691 options = ntohl (put->options); 1680 options = ntohl(put->options);
1692 payload_size = msize - (sizeof (struct PeerPutMessage) + 1681 payload_size = msize - (sizeof(struct PeerPutMessage) +
1693 putlen * sizeof (struct GNUNET_PeerIdentity)); 1682 putlen * sizeof(struct GNUNET_PeerIdentity));
1694 1683
1695 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1684 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1696 "PUT for `%s' from %s\n", 1685 "PUT for `%s' from %s\n",
1697 GNUNET_h2s (&put->key), 1686 GNUNET_h2s(&put->key),
1698 GNUNET_i2s (peer->id)); 1687 GNUNET_i2s(peer->id));
1699 if (GNUNET_YES == log_route_details_stderr) 1688 if (GNUNET_YES == log_route_details_stderr)
1700 { 1689 {
1701 char *tmp; 1690 char *tmp;
1702 char *pp; 1691 char *pp;
1703 1692
1704 pp = GNUNET_STRINGS_pp2s (put_path, 1693 pp = GNUNET_STRINGS_pp2s(put_path,
1705 putlen); 1694 putlen);
1706 tmp = GNUNET_strdup (GNUNET_i2s (&my_identity)); 1695 tmp = GNUNET_strdup(GNUNET_i2s(&my_identity));
1707 LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, 1696 LOG_TRAFFIC(GNUNET_ERROR_TYPE_DEBUG,
1708 "R5N PUT %s: %s->%s (%u, %u=>%u, PP: %s)\n", 1697 "R5N PUT %s: %s->%s (%u, %u=>%u, PP: %s)\n",
1709 GNUNET_h2s (&put->key), 1698 GNUNET_h2s(&put->key),
1710 GNUNET_i2s (peer->id), 1699 GNUNET_i2s(peer->id),
1711 tmp, 1700 tmp,
1712 ntohl(put->hop_count), 1701 ntohl(put->hop_count),
1713 GNUNET_CRYPTO_hash_matching_bits (&peer->phash, 1702 GNUNET_CRYPTO_hash_matching_bits(&peer->phash,
1714 &put->key), 1703 &put->key),
1715 GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash, 1704 GNUNET_CRYPTO_hash_matching_bits(&my_identity_hash,
1716 &put->key), 1705 &put->key),
1717 pp); 1706 pp);
1718 GNUNET_free (pp); 1707 GNUNET_free(pp);
1719 GNUNET_free (tmp); 1708 GNUNET_free(tmp);
1720 }
1721 switch (GNUNET_BLOCK_get_key
1722 (GDS_block_context,
1723 ntohl (put->type),
1724 payload,
1725 payload_size,
1726 &test_key))
1727 {
1728 case GNUNET_YES:
1729 if (0 != memcmp (&test_key,
1730 &put->key,
1731 sizeof (struct GNUNET_HashCode)))
1732 {
1733 char *put_s = GNUNET_strdup (GNUNET_h2s_full (&put->key));
1734
1735 GNUNET_break_op (0);
1736 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1737 "PUT with key `%s' for block with key %s\n",
1738 put_s,
1739 GNUNET_h2s_full (&test_key));
1740 GNUNET_free (put_s);
1741 return;
1742 } 1709 }
1743 break; 1710 switch (GNUNET_BLOCK_get_key
1744 case GNUNET_NO: 1711 (GDS_block_context,
1745 GNUNET_break_op (0); 1712 ntohl(put->type),
1746 return; 1713 payload,
1747 case GNUNET_SYSERR: 1714 payload_size,
1748 /* cannot verify, good luck */ 1715 &test_key))
1749 break;
1750 }
1751 if (ntohl (put->type) == GNUNET_BLOCK_TYPE_REGEX) /* FIXME: do for all tpyes */
1752 {
1753 switch (GNUNET_BLOCK_evaluate (GDS_block_context,
1754 ntohl (put->type),
1755 NULL, /* query group */
1756 GNUNET_BLOCK_EO_NONE,
1757 NULL, /* query */
1758 NULL, 0, /* xquery */
1759 payload,
1760 payload_size))
1761 { 1716 {
1762 case GNUNET_BLOCK_EVALUATION_OK_MORE: 1717 case GNUNET_YES:
1763 case GNUNET_BLOCK_EVALUATION_OK_LAST: 1718 if (0 != memcmp(&test_key,
1719 &put->key,
1720 sizeof(struct GNUNET_HashCode)))
1721 {
1722 char *put_s = GNUNET_strdup(GNUNET_h2s_full(&put->key));
1723
1724 GNUNET_break_op(0);
1725 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1726 "PUT with key `%s' for block with key %s\n",
1727 put_s,
1728 GNUNET_h2s_full(&test_key));
1729 GNUNET_free(put_s);
1730 return;
1731 }
1764 break; 1732 break;
1765 1733
1766 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: 1734 case GNUNET_NO:
1767 case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: 1735 GNUNET_break_op(0);
1768 case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT:
1769 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
1770 case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID:
1771 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
1772 default:
1773 GNUNET_break_op (0);
1774 return; 1736 return;
1737
1738 case GNUNET_SYSERR:
1739 /* cannot verify, good luck */
1740 break;
1741 }
1742 if (ntohl(put->type) == GNUNET_BLOCK_TYPE_REGEX) /* FIXME: do for all tpyes */
1743 {
1744 switch (GNUNET_BLOCK_evaluate(GDS_block_context,
1745 ntohl(put->type),
1746 NULL, /* query group */
1747 GNUNET_BLOCK_EO_NONE,
1748 NULL, /* query */
1749 NULL, 0, /* xquery */
1750 payload,
1751 payload_size))
1752 {
1753 case GNUNET_BLOCK_EVALUATION_OK_MORE:
1754 case GNUNET_BLOCK_EVALUATION_OK_LAST:
1755 break;
1756
1757 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
1758 case GNUNET_BLOCK_EVALUATION_RESULT_INVALID:
1759 case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT:
1760 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
1761 case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID:
1762 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
1763 default:
1764 GNUNET_break_op(0);
1765 return;
1766 }
1775 } 1767 }
1776 }
1777 1768
1778 bf = GNUNET_CONTAINER_bloomfilter_init (put->bloomfilter, 1769 bf = GNUNET_CONTAINER_bloomfilter_init(put->bloomfilter,
1779 DHT_BLOOM_SIZE, 1770 DHT_BLOOM_SIZE,
1780 GNUNET_CONSTANTS_BLOOMFILTER_K); 1771 GNUNET_CONSTANTS_BLOOMFILTER_K);
1781 GNUNET_break_op (GNUNET_YES == 1772 GNUNET_break_op(GNUNET_YES ==
1782 GNUNET_CONTAINER_bloomfilter_test (bf, 1773 GNUNET_CONTAINER_bloomfilter_test(bf,
1783 &peer->phash)); 1774 &peer->phash));
1784 { 1775 {
1785 struct GNUNET_PeerIdentity pp[putlen + 1]; 1776 struct GNUNET_PeerIdentity pp[putlen + 1];
1786 1777
1787 /* extend 'put path' by sender */ 1778 /* extend 'put path' by sender */
1788 if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) 1779 if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE))
1789 {
1790#if SANITY_CHECKS
1791 for (unsigned int i=0;i<=putlen;i++)
1792 { 1780 {
1793 for (unsigned int j=0;j<i;j++) 1781#if SANITY_CHECKS
1794 { 1782 for (unsigned int i = 0; i <= putlen; i++)
1795 GNUNET_break (0 != memcmp (&pp[i], 1783 {
1796 &pp[j], 1784 for (unsigned int j = 0; j < i; j++)
1797 sizeof (struct GNUNET_PeerIdentity))); 1785 {
1798 } 1786 GNUNET_break(0 != memcmp(&pp[i],
1799 GNUNET_break (0 != memcmp (&pp[i], 1787 &pp[j],
1800 peer->id, 1788 sizeof(struct GNUNET_PeerIdentity)));
1801 sizeof (struct GNUNET_PeerIdentity))); 1789 }
1802 } 1790 GNUNET_break(0 != memcmp(&pp[i],
1791 peer->id,
1792 sizeof(struct GNUNET_PeerIdentity)));
1793 }
1803#endif 1794#endif
1804 GNUNET_memcpy (pp, 1795 GNUNET_memcpy(pp,
1805 put_path, 1796 put_path,
1806 putlen * sizeof (struct GNUNET_PeerIdentity)); 1797 putlen * sizeof(struct GNUNET_PeerIdentity));
1807 pp[putlen] = *peer->id; 1798 pp[putlen] = *peer->id;
1808 putlen++; 1799 putlen++;
1809 } 1800 }
1810 else 1801 else
1811 putlen = 0; 1802 putlen = 0;
1812 1803
1813 /* give to local clients */ 1804 /* give to local clients */
1814 GDS_CLIENTS_handle_reply (exp_time, 1805 GDS_CLIENTS_handle_reply(exp_time,
1815 &put->key, 1806 &put->key,
1816 0, 1807 0,
1817 NULL, 1808 NULL,
1818 putlen, 1809 putlen,
1819 pp, 1810 pp,
1820 ntohl (put->type), 1811 ntohl(put->type),
1821 payload_size, 1812 payload_size,
1822 payload); 1813 payload);
1823 /* store locally */ 1814 /* store locally */
1824 if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || 1815 if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) ||
1825 (GDS_am_closest_peer (&put->key, bf))) 1816 (GDS_am_closest_peer(&put->key, bf)))
1826 GDS_DATACACHE_handle_put (exp_time, 1817 GDS_DATACACHE_handle_put(exp_time,
1827 &put->key, 1818 &put->key,
1828 putlen, 1819 putlen,
1829 pp, 1820 pp,
1830 ntohl (put->type), 1821 ntohl(put->type),
1831 payload_size, 1822 payload_size,
1832 payload); 1823 payload);
1833 /* route to other peers */ 1824 /* route to other peers */
1834 forwarded = GDS_NEIGHBOURS_handle_put (ntohl (put->type), 1825 forwarded = GDS_NEIGHBOURS_handle_put(ntohl(put->type),
1835 options, 1826 options,
1836 ntohl (put->desired_replication_level), 1827 ntohl(put->desired_replication_level),
1837 exp_time, 1828 exp_time,
1838 ntohl (put->hop_count), 1829 ntohl(put->hop_count),
1839 bf, 1830 bf,
1840 &put->key, 1831 &put->key,
1841 putlen, 1832 putlen,
1842 pp, 1833 pp,
1843 payload, 1834 payload,
1844 payload_size); 1835 payload_size);
1845 /* notify monitoring clients */ 1836 /* notify monitoring clients */
1846 GDS_CLIENTS_process_put (options 1837 GDS_CLIENTS_process_put(options
1847 | ( (GNUNET_OK == forwarded) 1838 | ((GNUNET_OK == forwarded)
1848 ? GNUNET_DHT_RO_LAST_HOP 1839 ? GNUNET_DHT_RO_LAST_HOP
1849 : 0 ), 1840 : 0),
1850 ntohl (put->type), 1841 ntohl(put->type),
1851 ntohl (put->hop_count), 1842 ntohl(put->hop_count),
1852 ntohl (put->desired_replication_level), 1843 ntohl(put->desired_replication_level),
1853 putlen, pp, 1844 putlen, pp,
1854 exp_time, 1845 exp_time,
1855 &put->key, 1846 &put->key,
1856 payload, 1847 payload,
1857 payload_size); 1848 payload_size);
1858 } 1849 }
1859 GNUNET_CONTAINER_bloomfilter_free (bf); 1850 GNUNET_CONTAINER_bloomfilter_free(bf);
1860} 1851}
1861 1852
1862 1853
@@ -1869,9 +1860,9 @@ handle_dht_p2p_put (void *cls,
1869 * @param bg group for filtering peers 1860 * @param bg group for filtering peers
1870 */ 1861 */
1871static void 1862static void
1872handle_find_peer (const struct GNUNET_PeerIdentity *sender, 1863handle_find_peer(const struct GNUNET_PeerIdentity *sender,
1873 const struct GNUNET_HashCode *key, 1864 const struct GNUNET_HashCode *key,
1874 struct GNUNET_BLOCK_Group *bg) 1865 struct GNUNET_BLOCK_Group *bg)
1875{ 1866{
1876 int bucket_idx; 1867 int bucket_idx;
1877 struct PeerBucket *bucket; 1868 struct PeerBucket *bucket;
@@ -1882,98 +1873,99 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender,
1882 1873
1883 /* first, check about our own HELLO */ 1874 /* first, check about our own HELLO */
1884 if (NULL != GDS_my_hello) 1875 if (NULL != GDS_my_hello)
1885 {
1886 hello_size = GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *) GDS_my_hello);
1887 GNUNET_break (hello_size >= sizeof (struct GNUNET_MessageHeader));
1888 if (GNUNET_BLOCK_EVALUATION_OK_MORE ==
1889 GNUNET_BLOCK_evaluate (GDS_block_context,
1890 GNUNET_BLOCK_TYPE_DHT_HELLO,
1891 bg,
1892 GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO,
1893 &my_identity_hash,
1894 NULL, 0,
1895 GDS_my_hello,
1896 hello_size))
1897 { 1876 {
1898 GDS_NEIGHBOURS_handle_reply (sender, 1877 hello_size = GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)GDS_my_hello);
1899 GNUNET_BLOCK_TYPE_DHT_HELLO, 1878 GNUNET_break(hello_size >= sizeof(struct GNUNET_MessageHeader));
1900 GNUNET_TIME_relative_to_absolute (hello_expiration), 1879 if (GNUNET_BLOCK_EVALUATION_OK_MORE ==
1901 key, 1880 GNUNET_BLOCK_evaluate(GDS_block_context,
1902 0, 1881 GNUNET_BLOCK_TYPE_DHT_HELLO,
1903 NULL, 1882 bg,
1904 0, 1883 GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO,
1905 NULL, 1884 &my_identity_hash,
1906 GDS_my_hello, 1885 NULL, 0,
1907 hello_size); 1886 GDS_my_hello,
1887 hello_size))
1888 {
1889 GDS_NEIGHBOURS_handle_reply(sender,
1890 GNUNET_BLOCK_TYPE_DHT_HELLO,
1891 GNUNET_TIME_relative_to_absolute(hello_expiration),
1892 key,
1893 0,
1894 NULL,
1895 0,
1896 NULL,
1897 GDS_my_hello,
1898 hello_size);
1899 }
1900 else
1901 {
1902 GNUNET_STATISTICS_update(GDS_stats,
1903 gettext_noop("# FIND PEER requests ignored due to Bloomfilter"),
1904 1,
1905 GNUNET_NO);
1906 }
1908 } 1907 }
1909 else 1908 else
1910 { 1909 {
1911 GNUNET_STATISTICS_update (GDS_stats, 1910 GNUNET_STATISTICS_update(GDS_stats,
1912 gettext_noop ("# FIND PEER requests ignored due to Bloomfilter"), 1911 gettext_noop("# FIND PEER requests ignored due to lack of HELLO"),
1913 1, 1912 1,
1914 GNUNET_NO); 1913 GNUNET_NO);
1915 } 1914 }
1916 }
1917 else
1918 {
1919 GNUNET_STATISTICS_update (GDS_stats,
1920 gettext_noop ("# FIND PEER requests ignored due to lack of HELLO"),
1921 1,
1922 GNUNET_NO);
1923 }
1924 1915
1925 /* then, also consider sending a random HELLO from the closest bucket */ 1916 /* then, also consider sending a random HELLO from the closest bucket */
1926 if (0 == memcmp (&my_identity_hash, 1917 if (0 == memcmp(&my_identity_hash,
1927 key, 1918 key,
1928 sizeof (struct GNUNET_HashCode))) 1919 sizeof(struct GNUNET_HashCode)))
1929 bucket_idx = closest_bucket; 1920 bucket_idx = closest_bucket;
1930 else 1921 else
1931 bucket_idx = GNUNET_MIN ((int) closest_bucket, 1922 bucket_idx = GNUNET_MIN((int)closest_bucket,
1932 find_bucket (key)); 1923 find_bucket(key));
1933 if (bucket_idx < 0) 1924 if (bucket_idx < 0)
1934 return; 1925 return;
1935 bucket = &k_buckets[bucket_idx]; 1926 bucket = &k_buckets[bucket_idx];
1936 if (bucket->peers_size == 0) 1927 if (bucket->peers_size == 0)
1937 return; 1928 return;
1938 choice = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1929 choice = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
1939 bucket->peers_size); 1930 bucket->peers_size);
1940 peer = bucket->head; 1931 peer = bucket->head;
1941 while (choice > 0) 1932 while (choice > 0)
1942 { 1933 {
1943 GNUNET_assert (NULL != peer); 1934 GNUNET_assert(NULL != peer);
1944 peer = peer->next; 1935 peer = peer->next;
1945 choice--; 1936 choice--;
1946 } 1937 }
1947 choice = bucket->peers_size; 1938 choice = bucket->peers_size;
1948 do 1939 do
1949 { 1940 {
1950 peer = peer->next; 1941 peer = peer->next;
1951 if (0 == choice--) 1942 if (0 == choice--)
1952 return; /* no non-masked peer available */ 1943 return; /* no non-masked peer available */
1953 if (NULL == peer) 1944 if (NULL == peer)
1954 peer = bucket->head; 1945 peer = bucket->head;
1955 hello = GDS_HELLO_get (peer->id); 1946 hello = GDS_HELLO_get(peer->id);
1956 } while ( (NULL == hello) || 1947 }
1957 (GNUNET_BLOCK_EVALUATION_OK_MORE != 1948 while ((NULL == hello) ||
1958 GNUNET_BLOCK_evaluate (GDS_block_context, 1949 (GNUNET_BLOCK_EVALUATION_OK_MORE !=
1959 GNUNET_BLOCK_TYPE_DHT_HELLO, 1950 GNUNET_BLOCK_evaluate(GDS_block_context,
1960 bg, 1951 GNUNET_BLOCK_TYPE_DHT_HELLO,
1961 GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO, 1952 bg,
1962 &peer->phash, 1953 GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO,
1963 NULL, 0, 1954 &peer->phash,
1964 hello, 1955 NULL, 0,
1965 (hello_size = GNUNET_HELLO_size (hello)))) ); 1956 hello,
1966 GDS_NEIGHBOURS_handle_reply (sender, 1957 (hello_size = GNUNET_HELLO_size(hello)))));
1967 GNUNET_BLOCK_TYPE_DHT_HELLO, 1958 GDS_NEIGHBOURS_handle_reply(sender,
1968 GNUNET_TIME_relative_to_absolute 1959 GNUNET_BLOCK_TYPE_DHT_HELLO,
1969 (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION), 1960 GNUNET_TIME_relative_to_absolute
1970 key, 1961 (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION),
1971 0, 1962 key,
1972 NULL, 1963 0,
1973 0, 1964 NULL,
1974 NULL, 1965 0,
1975 hello, 1966 NULL,
1976 hello_size); 1967 hello,
1968 hello_size);
1977} 1969}
1978 1970
1979 1971
@@ -1992,34 +1984,34 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender,
1992 * @param data_size number of bytes in @a data 1984 * @param data_size number of bytes in @a data
1993 */ 1985 */
1994static void 1986static void
1995handle_local_result (void *cls, 1987handle_local_result(void *cls,
1996 enum GNUNET_BLOCK_Type type, 1988 enum GNUNET_BLOCK_Type type,
1997 struct GNUNET_TIME_Absolute expiration_time, 1989 struct GNUNET_TIME_Absolute expiration_time,
1998 const struct GNUNET_HashCode *key, 1990 const struct GNUNET_HashCode *key,
1999 unsigned int put_path_length, 1991 unsigned int put_path_length,
2000 const struct GNUNET_PeerIdentity *put_path, 1992 const struct GNUNET_PeerIdentity *put_path,
2001 unsigned int get_path_length, 1993 unsigned int get_path_length,
2002 const struct GNUNET_PeerIdentity *get_path, 1994 const struct GNUNET_PeerIdentity *get_path,
2003 const void *data, 1995 const void *data,
2004 size_t data_size) 1996 size_t data_size)
2005{ 1997{
2006 struct PeerInfo *peer = cls; 1998 struct PeerInfo *peer = cls;
2007 char *pp; 1999 char *pp;
2008 2000
2009 pp = GNUNET_STRINGS_pp2s (put_path, 2001 pp = GNUNET_STRINGS_pp2s(put_path,
2010 put_path_length); 2002 put_path_length);
2011 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2003 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2012 "Found local result for %s (PP: %s)\n", 2004 "Found local result for %s (PP: %s)\n",
2013 GNUNET_h2s (key), 2005 GNUNET_h2s(key),
2014 pp); 2006 pp);
2015 GNUNET_free (pp); 2007 GNUNET_free(pp);
2016 GDS_NEIGHBOURS_handle_reply (peer->id, 2008 GDS_NEIGHBOURS_handle_reply(peer->id,
2017 type, 2009 type,
2018 expiration_time, 2010 expiration_time,
2019 key, 2011 key,
2020 put_path_length, put_path, 2012 put_path_length, put_path,
2021 get_path_length, get_path, 2013 get_path_length, get_path,
2022 data, data_size); 2014 data, data_size);
2023} 2015}
2024 2016
2025 2017
@@ -2031,20 +2023,20 @@ handle_local_result (void *cls,
2031 * @return #GNUNET_OK if the message is well-formed 2023 * @return #GNUNET_OK if the message is well-formed
2032 */ 2024 */
2033static int 2025static int
2034check_dht_p2p_get (void *cls, 2026check_dht_p2p_get(void *cls,
2035 const struct PeerGetMessage *get) 2027 const struct PeerGetMessage *get)
2036{ 2028{
2037 uint32_t xquery_size; 2029 uint32_t xquery_size;
2038 uint16_t msize; 2030 uint16_t msize;
2039 2031
2040 (void) cls; 2032 (void)cls;
2041 msize = ntohs (get->header.size); 2033 msize = ntohs(get->header.size);
2042 xquery_size = ntohl (get->xquery_size); 2034 xquery_size = ntohl(get->xquery_size);
2043 if (msize < sizeof (struct PeerGetMessage) + xquery_size) 2035 if (msize < sizeof(struct PeerGetMessage) + xquery_size)
2044 { 2036 {
2045 GNUNET_break_op (0); 2037 GNUNET_break_op(0);
2046 return GNUNET_SYSERR; 2038 return GNUNET_SYSERR;
2047 } 2039 }
2048 return GNUNET_OK; 2040 return GNUNET_OK;
2049} 2041}
2050 2042
@@ -2056,8 +2048,8 @@ check_dht_p2p_get (void *cls,
2056 * @param get the message 2048 * @param get the message
2057 */ 2049 */
2058static void 2050static void
2059handle_dht_p2p_get (void *cls, 2051handle_dht_p2p_get(void *cls,
2060 const struct PeerGetMessage *get) 2052 const struct PeerGetMessage *get)
2061{ 2053{
2062 struct PeerInfo *peer = cls; 2054 struct PeerInfo *peer = cls;
2063 uint32_t xquery_size; 2055 uint32_t xquery_size;
@@ -2072,141 +2064,141 @@ handle_dht_p2p_get (void *cls,
2072 int forwarded; 2064 int forwarded;
2073 2065
2074 /* parse and validate message */ 2066 /* parse and validate message */
2075 msize = ntohs (get->header.size); 2067 msize = ntohs(get->header.size);
2076 xquery_size = ntohl (get->xquery_size); 2068 xquery_size = ntohl(get->xquery_size);
2077 reply_bf_size = msize - (sizeof (struct PeerGetMessage) + xquery_size); 2069 reply_bf_size = msize - (sizeof(struct PeerGetMessage) + xquery_size);
2078 type = ntohl (get->type); 2070 type = ntohl(get->type);
2079 options = ntohl (get->options); 2071 options = ntohl(get->options);
2080 xquery = (const char *) &get[1]; 2072 xquery = (const char *)&get[1];
2081 GNUNET_STATISTICS_update (GDS_stats, 2073 GNUNET_STATISTICS_update(GDS_stats,
2082 gettext_noop ("# P2P GET requests received"), 2074 gettext_noop("# P2P GET requests received"),
2083 1, 2075 1,
2084 GNUNET_NO); 2076 GNUNET_NO);
2085 GNUNET_STATISTICS_update (GDS_stats, 2077 GNUNET_STATISTICS_update(GDS_stats,
2086 gettext_noop ("# P2P GET bytes received"), 2078 gettext_noop("# P2P GET bytes received"),
2087 msize, 2079 msize,
2088 GNUNET_NO); 2080 GNUNET_NO);
2089 if (GNUNET_YES == log_route_details_stderr) 2081 if (GNUNET_YES == log_route_details_stderr)
2090 { 2082 {
2091 char *tmp; 2083 char *tmp;
2092 2084
2093 tmp = GNUNET_strdup (GNUNET_i2s (&my_identity)); 2085 tmp = GNUNET_strdup(GNUNET_i2s(&my_identity));
2094 LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, 2086 LOG_TRAFFIC(GNUNET_ERROR_TYPE_DEBUG,
2095 "R5N GET %s: %s->%s (%u, %u=>%u) xq: %.*s\n", 2087 "R5N GET %s: %s->%s (%u, %u=>%u) xq: %.*s\n",
2096 GNUNET_h2s (&get->key), 2088 GNUNET_h2s(&get->key),
2097 GNUNET_i2s (peer->id), 2089 GNUNET_i2s(peer->id),
2098 tmp, 2090 tmp,
2099 ntohl(get->hop_count), 2091 ntohl(get->hop_count),
2100 GNUNET_CRYPTO_hash_matching_bits (&peer->phash, 2092 GNUNET_CRYPTO_hash_matching_bits(&peer->phash,
2101 &get->key), 2093 &get->key),
2102 GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash, 2094 GNUNET_CRYPTO_hash_matching_bits(&my_identity_hash,
2103 &get->key), 2095 &get->key),
2104 ntohl(get->xquery_size), 2096 ntohl(get->xquery_size),
2105 xquery); 2097 xquery);
2106 GNUNET_free (tmp); 2098 GNUNET_free(tmp);
2107 } 2099 }
2108 eval 2100 eval
2109 = GNUNET_BLOCK_evaluate (GDS_block_context, 2101 = GNUNET_BLOCK_evaluate(GDS_block_context,
2110 type, 2102 type,
2111 NULL, 2103 NULL,
2112 GNUNET_BLOCK_EO_NONE, 2104 GNUNET_BLOCK_EO_NONE,
2113 &get->key, 2105 &get->key,
2114 xquery, 2106 xquery,
2115 xquery_size, 2107 xquery_size,
2116 NULL, 2108 NULL,
2117 0); 2109 0);
2118 if (eval != GNUNET_BLOCK_EVALUATION_REQUEST_VALID) 2110 if (eval != GNUNET_BLOCK_EVALUATION_REQUEST_VALID)
2119 { 2111 {
2120 /* request invalid or block type not supported */ 2112 /* request invalid or block type not supported */
2121 GNUNET_break_op (eval == GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED); 2113 GNUNET_break_op(eval == GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED);
2122 return; 2114 return;
2123 } 2115 }
2124 peer_bf = GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter, 2116 peer_bf = GNUNET_CONTAINER_bloomfilter_init(get->bloomfilter,
2125 DHT_BLOOM_SIZE, 2117 DHT_BLOOM_SIZE,
2126 GNUNET_CONSTANTS_BLOOMFILTER_K); 2118 GNUNET_CONSTANTS_BLOOMFILTER_K);
2127 GNUNET_break_op (GNUNET_YES == 2119 GNUNET_break_op(GNUNET_YES ==
2128 GNUNET_CONTAINER_bloomfilter_test (peer_bf, 2120 GNUNET_CONTAINER_bloomfilter_test(peer_bf,
2129 &peer->phash)); 2121 &peer->phash));
2130 bg = GNUNET_BLOCK_group_create (GDS_block_context, 2122 bg = GNUNET_BLOCK_group_create(GDS_block_context,
2131 type, 2123 type,
2132 get->bf_mutator, 2124 get->bf_mutator,
2133 &xquery[xquery_size], 2125 &xquery[xquery_size],
2134 reply_bf_size, 2126 reply_bf_size,
2135 "filter-size", 2127 "filter-size",
2136 reply_bf_size, 2128 reply_bf_size,
2137 NULL); 2129 NULL);
2138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2130 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2139 "GET for %s at %s after %u hops\n", 2131 "GET for %s at %s after %u hops\n",
2140 GNUNET_h2s (&get->key), 2132 GNUNET_h2s(&get->key),
2141 GNUNET_i2s (&my_identity), 2133 GNUNET_i2s(&my_identity),
2142 (unsigned int) ntohl (get->hop_count)); 2134 (unsigned int)ntohl(get->hop_count));
2143 /* local lookup (this may update the reply_bf) */ 2135 /* local lookup (this may update the reply_bf) */
2144 if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || 2136 if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) ||
2145 (GDS_am_closest_peer (&get->key, 2137 (GDS_am_closest_peer(&get->key,
2146 peer_bf))) 2138 peer_bf)))
2147 {
2148 if ((0 != (options & GNUNET_DHT_RO_FIND_PEER)))
2149 { 2139 {
2150 GNUNET_STATISTICS_update (GDS_stats, 2140 if ((0 != (options & GNUNET_DHT_RO_FIND_PEER)))
2151 gettext_noop ("# P2P FIND PEER requests processed"), 2141 {
2152 1, 2142 GNUNET_STATISTICS_update(GDS_stats,
2153 GNUNET_NO); 2143 gettext_noop("# P2P FIND PEER requests processed"),
2154 handle_find_peer (peer->id, 2144 1,
2155 &get->key, 2145 GNUNET_NO);
2156 bg); 2146 handle_find_peer(peer->id,
2147 &get->key,
2148 bg);
2149 }
2150 else
2151 {
2152 eval = GDS_DATACACHE_handle_get(&get->key,
2153 type,
2154 xquery,
2155 xquery_size,
2156 bg,
2157 &handle_local_result,
2158 peer);
2159 }
2157 } 2160 }
2158 else 2161 else
2159 { 2162 {
2160 eval = GDS_DATACACHE_handle_get (&get->key, 2163 GNUNET_STATISTICS_update(GDS_stats,
2161 type, 2164 gettext_noop("# P2P GET requests ONLY routed"),
2162 xquery, 2165 1,
2163 xquery_size, 2166 GNUNET_NO);
2164 bg,
2165 &handle_local_result,
2166 peer);
2167 } 2167 }
2168 }
2169 else
2170 {
2171 GNUNET_STATISTICS_update (GDS_stats,
2172 gettext_noop ("# P2P GET requests ONLY routed"),
2173 1,
2174 GNUNET_NO);
2175 }
2176 2168
2177 /* remember request for routing replies */ 2169 /* remember request for routing replies */
2178 GDS_ROUTING_add (peer->id, 2170 GDS_ROUTING_add(peer->id,
2179 type, 2171 type,
2180 bg, /* bg now owned by routing, but valid at least until end of this function! */ 2172 bg, /* bg now owned by routing, but valid at least until end of this function! */
2181 options, 2173 options,
2182 &get->key, 2174 &get->key,
2183 xquery, 2175 xquery,
2184 xquery_size); 2176 xquery_size);
2185 2177
2186 /* P2P forwarding */ 2178 /* P2P forwarding */
2187 forwarded = GNUNET_NO; 2179 forwarded = GNUNET_NO;
2188 if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST) 2180 if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST)
2189 forwarded = GDS_NEIGHBOURS_handle_get (type, 2181 forwarded = GDS_NEIGHBOURS_handle_get(type,
2190 options, 2182 options,
2191 ntohl (get->desired_replication_level), 2183 ntohl(get->desired_replication_level),
2192 ntohl (get->hop_count), 2184 ntohl(get->hop_count),
2193 &get->key, 2185 &get->key,
2194 xquery, 2186 xquery,
2195 xquery_size, 2187 xquery_size,
2196 bg, 2188 bg,
2197 peer_bf); 2189 peer_bf);
2198 GDS_CLIENTS_process_get (options 2190 GDS_CLIENTS_process_get(options
2199 | (GNUNET_OK == forwarded) 2191 | (GNUNET_OK == forwarded)
2200 ? GNUNET_DHT_RO_LAST_HOP : 0, 2192 ? GNUNET_DHT_RO_LAST_HOP : 0,
2201 type, 2193 type,
2202 ntohl (get->hop_count), 2194 ntohl(get->hop_count),
2203 ntohl (get->desired_replication_level), 2195 ntohl(get->desired_replication_level),
2204 0, 2196 0,
2205 NULL, 2197 NULL,
2206 &get->key); 2198 &get->key);
2207 2199
2208 /* clean up; note that 'bg' is owned by routing now! */ 2200 /* clean up; note that 'bg' is owned by routing now! */
2209 GNUNET_CONTAINER_bloomfilter_free (peer_bf); 2201 GNUNET_CONTAINER_bloomfilter_free(peer_bf);
2210} 2202}
2211 2203
2212 2204
@@ -2218,29 +2210,29 @@ handle_dht_p2p_get (void *cls,
2218 * @return #GNUNET_YES if the message is well-formed 2210 * @return #GNUNET_YES if the message is well-formed
2219 */ 2211 */
2220static int 2212static int
2221check_dht_p2p_result (void *cls, 2213check_dht_p2p_result(void *cls,
2222 const struct PeerResultMessage *prm) 2214 const struct PeerResultMessage *prm)
2223{ 2215{
2224 uint32_t get_path_length; 2216 uint32_t get_path_length;
2225 uint32_t put_path_length; 2217 uint32_t put_path_length;
2226 uint16_t msize; 2218 uint16_t msize;
2227 2219
2228 (void) cls; 2220 (void)cls;
2229 msize = ntohs (prm->header.size); 2221 msize = ntohs(prm->header.size);
2230 put_path_length = ntohl (prm->put_path_length); 2222 put_path_length = ntohl(prm->put_path_length);
2231 get_path_length = ntohl (prm->get_path_length); 2223 get_path_length = ntohl(prm->get_path_length);
2232 if ((msize < 2224 if ((msize <
2233 sizeof (struct PeerResultMessage) + (get_path_length + 2225 sizeof(struct PeerResultMessage) + (get_path_length +
2234 put_path_length) * 2226 put_path_length) *
2235 sizeof (struct GNUNET_PeerIdentity)) || 2227 sizeof(struct GNUNET_PeerIdentity)) ||
2236 (get_path_length > 2228 (get_path_length >
2237 GNUNET_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || 2229 GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) ||
2238 (put_path_length > 2230 (put_path_length >
2239 GNUNET_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity))) 2231 GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)))
2240 { 2232 {
2241 GNUNET_break_op (0); 2233 GNUNET_break_op(0);
2242 return GNUNET_SYSERR; 2234 return GNUNET_SYSERR;
2243 } 2235 }
2244 return GNUNET_OK; 2236 return GNUNET_OK;
2245} 2237}
2246 2238
@@ -2259,64 +2251,64 @@ check_dht_p2p_result (void *cls,
2259 * @param data payload of the reply 2251 * @param data payload of the reply
2260 */ 2252 */
2261static void 2253static void
2262process_reply_with_path (struct GNUNET_TIME_Absolute expiration_time, 2254process_reply_with_path(struct GNUNET_TIME_Absolute expiration_time,
2263 const struct GNUNET_HashCode *key, 2255 const struct GNUNET_HashCode *key,
2264 unsigned int get_path_length, 2256 unsigned int get_path_length,
2265 const struct GNUNET_PeerIdentity *get_path, 2257 const struct GNUNET_PeerIdentity *get_path,
2266 unsigned int put_path_length, 2258 unsigned int put_path_length,
2267 const struct GNUNET_PeerIdentity *put_path, 2259 const struct GNUNET_PeerIdentity *put_path,
2268 enum GNUNET_BLOCK_Type type, 2260 enum GNUNET_BLOCK_Type type,
2269 size_t data_size, 2261 size_t data_size,
2270 const void *data) 2262 const void *data)
2271{ 2263{
2272 /* forward to local clients */ 2264 /* forward to local clients */
2273 GDS_CLIENTS_handle_reply (expiration_time, 2265 GDS_CLIENTS_handle_reply(expiration_time,
2274 key, 2266 key,
2275 get_path_length, 2267 get_path_length,
2276 get_path, 2268 get_path,
2277 put_path_length, 2269 put_path_length,
2278 put_path, 2270 put_path,
2279 type, 2271 type,
2280 data_size, 2272 data_size,
2281 data); 2273 data);
2282 GDS_CLIENTS_process_get_resp (type, 2274 GDS_CLIENTS_process_get_resp(type,
2283 get_path, 2275 get_path,
2284 get_path_length, 2276 get_path_length,
2285 put_path, 2277 put_path,
2286 put_path_length, 2278 put_path_length,
2287 expiration_time, 2279 expiration_time,
2288 key, 2280 key,
2289 data, 2281 data,
2290 data_size); 2282 data_size);
2291 if (GNUNET_YES == cache_results) 2283 if (GNUNET_YES == cache_results)
2292 { 2284 {
2293 struct GNUNET_PeerIdentity xput_path[get_path_length + 1 + put_path_length]; 2285 struct GNUNET_PeerIdentity xput_path[get_path_length + 1 + put_path_length];
2294 2286
2295 GNUNET_memcpy (xput_path, 2287 GNUNET_memcpy(xput_path,
2296 put_path, 2288 put_path,
2297 put_path_length * sizeof (struct GNUNET_PeerIdentity)); 2289 put_path_length * sizeof(struct GNUNET_PeerIdentity));
2298 GNUNET_memcpy (&xput_path[put_path_length], 2290 GNUNET_memcpy(&xput_path[put_path_length],
2299 get_path, 2291 get_path,
2300 get_path_length * sizeof (struct GNUNET_PeerIdentity)); 2292 get_path_length * sizeof(struct GNUNET_PeerIdentity));
2301 2293
2302 GDS_DATACACHE_handle_put (expiration_time, 2294 GDS_DATACACHE_handle_put(expiration_time,
2303 key, 2295 key,
2304 get_path_length + put_path_length, 2296 get_path_length + put_path_length,
2305 xput_path, 2297 xput_path,
2306 type, 2298 type,
2307 data_size, 2299 data_size,
2308 data); 2300 data);
2309 } 2301 }
2310 /* forward to other peers */ 2302 /* forward to other peers */
2311 GDS_ROUTING_process (type, 2303 GDS_ROUTING_process(type,
2312 expiration_time, 2304 expiration_time,
2313 key, 2305 key,
2314 put_path_length, 2306 put_path_length,
2315 put_path, 2307 put_path,
2316 get_path_length, 2308 get_path_length,
2317 get_path, 2309 get_path,
2318 data, 2310 data,
2319 data_size); 2311 data_size);
2320} 2312}
2321 2313
2322 2314
@@ -2327,8 +2319,8 @@ process_reply_with_path (struct GNUNET_TIME_Absolute expiration_time,
2327 * @param message message 2319 * @param message message
2328 */ 2320 */
2329static void 2321static void
2330handle_dht_p2p_result (void *cls, 2322handle_dht_p2p_result(void *cls,
2331 const struct PeerResultMessage *prm) 2323 const struct PeerResultMessage *prm)
2332{ 2324{
2333 struct PeerInfo *peer = cls; 2325 struct PeerInfo *peer = cls;
2334 const struct GNUNET_PeerIdentity *put_path; 2326 const struct GNUNET_PeerIdentity *put_path;
@@ -2342,125 +2334,125 @@ handle_dht_p2p_result (void *cls,
2342 struct GNUNET_TIME_Absolute exp_time; 2334 struct GNUNET_TIME_Absolute exp_time;
2343 2335
2344 /* parse and validate message */ 2336 /* parse and validate message */
2345 exp_time = GNUNET_TIME_absolute_ntoh (prm->expiration_time); 2337 exp_time = GNUNET_TIME_absolute_ntoh(prm->expiration_time);
2346 if (0 == GNUNET_TIME_absolute_get_remaining (exp_time).rel_value_us) 2338 if (0 == GNUNET_TIME_absolute_get_remaining(exp_time).rel_value_us)
2347 {
2348 GNUNET_STATISTICS_update (GDS_stats,
2349 gettext_noop ("# Expired results discarded"),
2350 1,
2351 GNUNET_NO);
2352 return;
2353 }
2354 msize = ntohs (prm->header.size);
2355 put_path_length = ntohl (prm->put_path_length);
2356 get_path_length = ntohl (prm->get_path_length);
2357 put_path = (const struct GNUNET_PeerIdentity *) &prm[1];
2358 get_path = &put_path[put_path_length];
2359 type = ntohl (prm->type);
2360 data = (const void *) &get_path[get_path_length];
2361 data_size = msize - (sizeof (struct PeerResultMessage) +
2362 (get_path_length +
2363 put_path_length) * sizeof (struct GNUNET_PeerIdentity));
2364 GNUNET_STATISTICS_update (GDS_stats,
2365 gettext_noop ("# P2P RESULTS received"),
2366 1,
2367 GNUNET_NO);
2368 GNUNET_STATISTICS_update (GDS_stats,
2369 gettext_noop ("# P2P RESULT bytes received"),
2370 msize,
2371 GNUNET_NO);
2372 if (GNUNET_YES == log_route_details_stderr)
2373 {
2374 char *tmp;
2375 char *pp;
2376 char *gp;
2377
2378 gp = GNUNET_STRINGS_pp2s (get_path,
2379 get_path_length);
2380 pp = GNUNET_STRINGS_pp2s (put_path,
2381 put_path_length);
2382 tmp = GNUNET_strdup (GNUNET_i2s (&my_identity));
2383 LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG,
2384 "R5N RESULT %s: %s->%s (GP: %s, PP: %s)\n",
2385 GNUNET_h2s (&prm->key),
2386 GNUNET_i2s (peer->id),
2387 tmp,
2388 gp,
2389 pp);
2390 GNUNET_free (gp);
2391 GNUNET_free (pp);
2392 GNUNET_free (tmp);
2393 }
2394 /* if we got a HELLO, consider it for our own routing table */
2395 if (GNUNET_BLOCK_TYPE_DHT_HELLO == type)
2396 {
2397 const struct GNUNET_MessageHeader *h;
2398 struct GNUNET_PeerIdentity pid;
2399
2400 /* Should be a HELLO, validate and consider using it! */
2401 if (data_size < sizeof (struct GNUNET_HELLO_Message))
2402 { 2339 {
2403 GNUNET_break_op (0); 2340 GNUNET_STATISTICS_update(GDS_stats,
2341 gettext_noop("# Expired results discarded"),
2342 1,
2343 GNUNET_NO);
2404 return; 2344 return;
2405 } 2345 }
2406 h = data; 2346 msize = ntohs(prm->header.size);
2407 if (data_size != ntohs (h->size)) 2347 put_path_length = ntohl(prm->put_path_length);
2348 get_path_length = ntohl(prm->get_path_length);
2349 put_path = (const struct GNUNET_PeerIdentity *)&prm[1];
2350 get_path = &put_path[put_path_length];
2351 type = ntohl(prm->type);
2352 data = (const void *)&get_path[get_path_length];
2353 data_size = msize - (sizeof(struct PeerResultMessage) +
2354 (get_path_length +
2355 put_path_length) * sizeof(struct GNUNET_PeerIdentity));
2356 GNUNET_STATISTICS_update(GDS_stats,
2357 gettext_noop("# P2P RESULTS received"),
2358 1,
2359 GNUNET_NO);
2360 GNUNET_STATISTICS_update(GDS_stats,
2361 gettext_noop("# P2P RESULT bytes received"),
2362 msize,
2363 GNUNET_NO);
2364 if (GNUNET_YES == log_route_details_stderr)
2408 { 2365 {
2409 GNUNET_break_op (0); 2366 char *tmp;
2410 return; 2367 char *pp;
2368 char *gp;
2369
2370 gp = GNUNET_STRINGS_pp2s(get_path,
2371 get_path_length);
2372 pp = GNUNET_STRINGS_pp2s(put_path,
2373 put_path_length);
2374 tmp = GNUNET_strdup(GNUNET_i2s(&my_identity));
2375 LOG_TRAFFIC(GNUNET_ERROR_TYPE_DEBUG,
2376 "R5N RESULT %s: %s->%s (GP: %s, PP: %s)\n",
2377 GNUNET_h2s(&prm->key),
2378 GNUNET_i2s(peer->id),
2379 tmp,
2380 gp,
2381 pp);
2382 GNUNET_free(gp);
2383 GNUNET_free(pp);
2384 GNUNET_free(tmp);
2411 } 2385 }
2412 if (GNUNET_OK != 2386 /* if we got a HELLO, consider it for our own routing table */
2413 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) h, 2387 if (GNUNET_BLOCK_TYPE_DHT_HELLO == type)
2414 &pid))
2415 { 2388 {
2416 GNUNET_break_op (0); 2389 const struct GNUNET_MessageHeader *h;
2417 return; 2390 struct GNUNET_PeerIdentity pid;
2418 } 2391
2419 if ( (GNUNET_YES != disable_try_connect) && 2392 /* Should be a HELLO, validate and consider using it! */
2420 (0 != memcmp (&my_identity, 2393 if (data_size < sizeof(struct GNUNET_HELLO_Message))
2394 {
2395 GNUNET_break_op(0);
2396 return;
2397 }
2398 h = data;
2399 if (data_size != ntohs(h->size))
2400 {
2401 GNUNET_break_op(0);
2402 return;
2403 }
2404 if (GNUNET_OK !=
2405 GNUNET_HELLO_get_id((const struct GNUNET_HELLO_Message *)h,
2406 &pid))
2407 {
2408 GNUNET_break_op(0);
2409 return;
2410 }
2411 if ((GNUNET_YES != disable_try_connect) &&
2412 (0 != memcmp(&my_identity,
2421 &pid, 2413 &pid,
2422 sizeof (struct GNUNET_PeerIdentity))) ) 2414 sizeof(struct GNUNET_PeerIdentity))))
2423 try_connect (&pid, 2415 try_connect(&pid,
2424 h); 2416 h);
2425 } 2417 }
2426 2418
2427 /* First, check if 'peer' is already on the path, and if 2419 /* First, check if 'peer' is already on the path, and if
2428 so, truncate it instead of expanding. */ 2420 so, truncate it instead of expanding. */
2429 for (unsigned int i=0;i<=get_path_length;i++) 2421 for (unsigned int i = 0; i <= get_path_length; i++)
2430 if (0 == memcmp (&get_path[i], 2422 if (0 == memcmp(&get_path[i],
2431 peer->id, 2423 peer->id,
2432 sizeof (struct GNUNET_PeerIdentity))) 2424 sizeof(struct GNUNET_PeerIdentity)))
2433 { 2425 {
2434 process_reply_with_path (exp_time, 2426 process_reply_with_path(exp_time,
2435 &prm->key, 2427 &prm->key,
2436 i, 2428 i,
2437 get_path, 2429 get_path,
2438 put_path_length, 2430 put_path_length,
2439 put_path, 2431 put_path,
2440 type, 2432 type,
2441 data_size, 2433 data_size,
2442 data); 2434 data);
2443 return; 2435 return;
2444 } 2436 }
2445 2437
2446 /* Need to append 'peer' to 'get_path' (normal case) */ 2438 /* Need to append 'peer' to 'get_path' (normal case) */
2447 { 2439 {
2448 struct GNUNET_PeerIdentity xget_path[get_path_length + 1]; 2440 struct GNUNET_PeerIdentity xget_path[get_path_length + 1];
2449 2441
2450 GNUNET_memcpy (xget_path, 2442 GNUNET_memcpy(xget_path,
2451 get_path, 2443 get_path,
2452 get_path_length * sizeof (struct GNUNET_PeerIdentity)); 2444 get_path_length * sizeof(struct GNUNET_PeerIdentity));
2453 xget_path[get_path_length] = *peer->id; 2445 xget_path[get_path_length] = *peer->id;
2454 2446
2455 process_reply_with_path (exp_time, 2447 process_reply_with_path(exp_time,
2456 &prm->key, 2448 &prm->key,
2457 get_path_length + 1, 2449 get_path_length + 1,
2458 xget_path, 2450 xget_path,
2459 put_path_length, 2451 put_path_length,
2460 put_path, 2452 put_path,
2461 type, 2453 type,
2462 data_size, 2454 data_size,
2463 data); 2455 data);
2464 } 2456 }
2465} 2457}
2466 2458
@@ -2471,55 +2463,55 @@ handle_dht_p2p_result (void *cls,
2471 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 2463 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
2472 */ 2464 */
2473int 2465int
2474GDS_NEIGHBOURS_init () 2466GDS_NEIGHBOURS_init()
2475{ 2467{
2476 struct GNUNET_MQ_MessageHandler core_handlers[] = { 2468 struct GNUNET_MQ_MessageHandler core_handlers[] = {
2477 GNUNET_MQ_hd_var_size (dht_p2p_get, 2469 GNUNET_MQ_hd_var_size(dht_p2p_get,
2478 GNUNET_MESSAGE_TYPE_DHT_P2P_GET, 2470 GNUNET_MESSAGE_TYPE_DHT_P2P_GET,
2479 struct PeerGetMessage, 2471 struct PeerGetMessage,
2480 NULL), 2472 NULL),
2481 GNUNET_MQ_hd_var_size (dht_p2p_put, 2473 GNUNET_MQ_hd_var_size(dht_p2p_put,
2482 GNUNET_MESSAGE_TYPE_DHT_P2P_PUT, 2474 GNUNET_MESSAGE_TYPE_DHT_P2P_PUT,
2483 struct PeerPutMessage, 2475 struct PeerPutMessage,
2484 NULL), 2476 NULL),
2485 GNUNET_MQ_hd_var_size (dht_p2p_result, 2477 GNUNET_MQ_hd_var_size(dht_p2p_result,
2486 GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT, 2478 GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT,
2487 struct PeerResultMessage, 2479 struct PeerResultMessage,
2488 NULL), 2480 NULL),
2489 GNUNET_MQ_handler_end () 2481 GNUNET_MQ_handler_end()
2490 }; 2482 };
2491 unsigned long long temp_config_num; 2483 unsigned long long temp_config_num;
2492 2484
2493 disable_try_connect 2485 disable_try_connect
2494 = GNUNET_CONFIGURATION_get_value_yesno (GDS_cfg, 2486 = GNUNET_CONFIGURATION_get_value_yesno(GDS_cfg,
2495 "DHT", 2487 "DHT",
2496 "DISABLE_TRY_CONNECT"); 2488 "DISABLE_TRY_CONNECT");
2497 if (GNUNET_OK == 2489 if (GNUNET_OK ==
2498 GNUNET_CONFIGURATION_get_value_number (GDS_cfg, 2490 GNUNET_CONFIGURATION_get_value_number(GDS_cfg,
2499 "DHT", 2491 "DHT",
2500 "bucket_size", 2492 "bucket_size",
2501 &temp_config_num)) 2493 &temp_config_num))
2502 bucket_size = (unsigned int) temp_config_num; 2494 bucket_size = (unsigned int)temp_config_num;
2503 cache_results 2495 cache_results
2504 = GNUNET_CONFIGURATION_get_value_yesno (GDS_cfg, 2496 = GNUNET_CONFIGURATION_get_value_yesno(GDS_cfg,
2505 "DHT", 2497 "DHT",
2506 "CACHE_RESULTS"); 2498 "CACHE_RESULTS");
2507 2499
2508 log_route_details_stderr = 2500 log_route_details_stderr =
2509 (NULL != getenv("GNUNET_DHT_ROUTE_DEBUG")) ? GNUNET_YES : GNUNET_NO; 2501 (NULL != getenv("GNUNET_DHT_ROUTE_DEBUG")) ? GNUNET_YES : GNUNET_NO;
2510 ats_ch = GNUNET_ATS_connectivity_init (GDS_cfg); 2502 ats_ch = GNUNET_ATS_connectivity_init(GDS_cfg);
2511 core_api = GNUNET_CORE_connect (GDS_cfg, 2503 core_api = GNUNET_CORE_connect(GDS_cfg,
2512 NULL, 2504 NULL,
2513 &core_init, 2505 &core_init,
2514 &handle_core_connect, 2506 &handle_core_connect,
2515 &handle_core_disconnect, 2507 &handle_core_disconnect,
2516 core_handlers); 2508 core_handlers);
2517 if (NULL == core_api) 2509 if (NULL == core_api)
2518 return GNUNET_SYSERR; 2510 return GNUNET_SYSERR;
2519 all_connected_peers = GNUNET_CONTAINER_multipeermap_create (256, 2511 all_connected_peers = GNUNET_CONTAINER_multipeermap_create(256,
2520 GNUNET_YES); 2512 GNUNET_YES);
2521 all_desired_peers = GNUNET_CONTAINER_multipeermap_create (256, 2513 all_desired_peers = GNUNET_CONTAINER_multipeermap_create(256,
2522 GNUNET_NO); 2514 GNUNET_NO);
2523 return GNUNET_OK; 2515 return GNUNET_OK;
2524} 2516}
2525 2517
@@ -2528,24 +2520,24 @@ GDS_NEIGHBOURS_init ()
2528 * Shutdown neighbours subsystem. 2520 * Shutdown neighbours subsystem.
2529 */ 2521 */
2530void 2522void
2531GDS_NEIGHBOURS_done () 2523GDS_NEIGHBOURS_done()
2532{ 2524{
2533 if (NULL == core_api) 2525 if (NULL == core_api)
2534 return; 2526 return;
2535 GNUNET_CORE_disconnect (core_api); 2527 GNUNET_CORE_disconnect(core_api);
2536 core_api = NULL; 2528 core_api = NULL;
2537 GNUNET_assert (0 == 2529 GNUNET_assert(0 ==
2538 GNUNET_CONTAINER_multipeermap_size (all_connected_peers)); 2530 GNUNET_CONTAINER_multipeermap_size(all_connected_peers));
2539 GNUNET_CONTAINER_multipeermap_destroy (all_connected_peers); 2531 GNUNET_CONTAINER_multipeermap_destroy(all_connected_peers);
2540 all_connected_peers = NULL; 2532 all_connected_peers = NULL;
2541 GNUNET_CONTAINER_multipeermap_iterate (all_desired_peers, 2533 GNUNET_CONTAINER_multipeermap_iterate(all_desired_peers,
2542 &free_connect_info, 2534 &free_connect_info,
2543 NULL); 2535 NULL);
2544 GNUNET_CONTAINER_multipeermap_destroy (all_desired_peers); 2536 GNUNET_CONTAINER_multipeermap_destroy(all_desired_peers);
2545 all_desired_peers = NULL; 2537 all_desired_peers = NULL;
2546 GNUNET_ATS_connectivity_done (ats_ch); 2538 GNUNET_ATS_connectivity_done(ats_ch);
2547 ats_ch = NULL; 2539 ats_ch = NULL;
2548 GNUNET_assert (NULL == find_peer_task); 2540 GNUNET_assert(NULL == find_peer_task);
2549} 2541}
2550 2542
2551 2543
@@ -2555,7 +2547,7 @@ GDS_NEIGHBOURS_done ()
2555 * @return identity of the local node 2547 * @return identity of the local node
2556 */ 2548 */
2557struct GNUNET_PeerIdentity * 2549struct GNUNET_PeerIdentity *
2558GDS_NEIGHBOURS_get_id () 2550GDS_NEIGHBOURS_get_id()
2559{ 2551{
2560 return &my_identity; 2552 return &my_identity;
2561} 2553}
diff --git a/src/dht/gnunet-service-dht_neighbours.h b/src/dht/gnunet-service-dht_neighbours.h
index dae854fb8..8b7a22422 100644
--- a/src/dht/gnunet-service-dht_neighbours.h
+++ b/src/dht/gnunet-service-dht_neighbours.h
@@ -11,12 +11,12 @@
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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file dht/gnunet-service-dht_neighbours.h 22 * @file dht/gnunet-service-dht_neighbours.h
@@ -58,16 +58,16 @@ extern struct GNUNET_HashCode my_identity_hash;
58 * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not 58 * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not
59 */ 59 */
60int 60int
61GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, 61GDS_NEIGHBOURS_handle_put(enum GNUNET_BLOCK_Type type,
62 enum GNUNET_DHT_RouteOption options, 62 enum GNUNET_DHT_RouteOption options,
63 uint32_t desired_replication_level, 63 uint32_t desired_replication_level,
64 struct GNUNET_TIME_Absolute expiration_time, 64 struct GNUNET_TIME_Absolute expiration_time,
65 uint32_t hop_count, 65 uint32_t hop_count,
66 struct GNUNET_CONTAINER_BloomFilter *bf, 66 struct GNUNET_CONTAINER_BloomFilter *bf,
67 const struct GNUNET_HashCode *key, 67 const struct GNUNET_HashCode *key,
68 unsigned int put_path_length, 68 unsigned int put_path_length,
69 struct GNUNET_PeerIdentity *put_path, 69 struct GNUNET_PeerIdentity *put_path,
70 const void *data, size_t data_size); 70 const void *data, size_t data_size);
71 71
72 72
73/** 73/**
@@ -88,15 +88,15 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
88 * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not 88 * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not
89 */ 89 */
90int 90int
91GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, 91GDS_NEIGHBOURS_handle_get(enum GNUNET_BLOCK_Type type,
92 enum GNUNET_DHT_RouteOption options, 92 enum GNUNET_DHT_RouteOption options,
93 uint32_t desired_replication_level, 93 uint32_t desired_replication_level,
94 uint32_t hop_count, 94 uint32_t hop_count,
95 const struct GNUNET_HashCode *key, 95 const struct GNUNET_HashCode *key,
96 const void *xquery, 96 const void *xquery,
97 size_t xquery_size, 97 size_t xquery_size,
98 struct GNUNET_BLOCK_Group *bg, 98 struct GNUNET_BLOCK_Group *bg,
99 struct GNUNET_CONTAINER_BloomFilter *peer_bf); 99 struct GNUNET_CONTAINER_BloomFilter *peer_bf);
100 100
101 101
102/** 102/**
@@ -116,16 +116,16 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
116 * @param data_size number of bytes in data 116 * @param data_size number of bytes in data
117 */ 117 */
118void 118void
119GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, 119GDS_NEIGHBOURS_handle_reply(const struct GNUNET_PeerIdentity *target,
120 enum GNUNET_BLOCK_Type type, 120 enum GNUNET_BLOCK_Type type,
121 struct GNUNET_TIME_Absolute expiration_time, 121 struct GNUNET_TIME_Absolute expiration_time,
122 const struct GNUNET_HashCode *key, 122 const struct GNUNET_HashCode *key,
123 unsigned int put_path_length, 123 unsigned int put_path_length,
124 const struct GNUNET_PeerIdentity *put_path, 124 const struct GNUNET_PeerIdentity *put_path,
125 unsigned int get_path_length, 125 unsigned int get_path_length,
126 const struct GNUNET_PeerIdentity *get_path, 126 const struct GNUNET_PeerIdentity *get_path,
127 const void *data, 127 const void *data,
128 size_t data_size); 128 size_t data_size);
129 129
130 130
131/** 131/**
@@ -139,8 +139,8 @@ GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target,
139 * #GNUNET_NO otherwise. 139 * #GNUNET_NO otherwise.
140 */ 140 */
141int 141int
142GDS_am_closest_peer (const struct GNUNET_HashCode *key, 142GDS_am_closest_peer(const struct GNUNET_HashCode *key,
143 const struct GNUNET_CONTAINER_BloomFilter *bloom); 143 const struct GNUNET_CONTAINER_BloomFilter *bloom);
144 144
145 145
146 146
@@ -150,14 +150,14 @@ GDS_am_closest_peer (const struct GNUNET_HashCode *key,
150 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 150 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
151 */ 151 */
152int 152int
153GDS_NEIGHBOURS_init (void); 153GDS_NEIGHBOURS_init(void);
154 154
155 155
156/** 156/**
157 * Shutdown neighbours subsystem. 157 * Shutdown neighbours subsystem.
158 */ 158 */
159void 159void
160GDS_NEIGHBOURS_done (void); 160GDS_NEIGHBOURS_done(void);
161 161
162 162
163/** 163/**
@@ -166,7 +166,7 @@ GDS_NEIGHBOURS_done (void);
166 * @return identity of the local node 166 * @return identity of the local node
167 */ 167 */
168struct GNUNET_PeerIdentity * 168struct GNUNET_PeerIdentity *
169GDS_NEIGHBOURS_get_id (void); 169GDS_NEIGHBOURS_get_id(void);
170 170
171 171
172#endif 172#endif
diff --git a/src/dht/gnunet-service-dht_nse.c b/src/dht/gnunet-service-dht_nse.c
index d59d46dd3..07ebb5299 100644
--- a/src/dht/gnunet-service-dht_nse.c
+++ b/src/dht/gnunet-service-dht_nse.c
@@ -11,12 +11,12 @@
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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file dht/gnunet-service-dht_nse.c 22 * @file dht/gnunet-service-dht_nse.c
@@ -52,14 +52,14 @@ static struct GNUNET_NSE_Handle *nse;
52 * 52 *
53 */ 53 */
54static void 54static void
55update_network_size_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp, 55update_network_size_estimate(void *cls, struct GNUNET_TIME_Absolute timestamp,
56 double logestimate, double std_dev) 56 double logestimate, double std_dev)
57{ 57{
58 GNUNET_STATISTICS_update (GDS_stats, 58 GNUNET_STATISTICS_update(GDS_stats,
59 gettext_noop ("# Network size estimates received"), 59 gettext_noop("# Network size estimates received"),
60 1, GNUNET_NO); 60 1, GNUNET_NO);
61 /* do not allow estimates < 0.5 */ 61 /* do not allow estimates < 0.5 */
62 log_of_network_size_estimate = GNUNET_MAX (0.5, logestimate); 62 log_of_network_size_estimate = GNUNET_MAX(0.5, logestimate);
63} 63}
64 64
65 65
@@ -69,7 +69,7 @@ update_network_size_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp,
69 * @return log of NSE 69 * @return log of NSE
70 */ 70 */
71double 71double
72GDS_NSE_get () 72GDS_NSE_get()
73{ 73{
74 return log_of_network_size_estimate; 74 return log_of_network_size_estimate;
75} 75}
@@ -79,24 +79,24 @@ GDS_NSE_get ()
79 * Initialize NSE subsystem. 79 * Initialize NSE subsystem.
80 */ 80 */
81void 81void
82GDS_NSE_init () 82GDS_NSE_init()
83{ 83{
84 unsigned long long hops; 84 unsigned long long hops;
85 85
86 if ( (GNUNET_YES == 86 if ((GNUNET_YES ==
87 GNUNET_CONFIGURATION_have_value (GDS_cfg, 87 GNUNET_CONFIGURATION_have_value(GDS_cfg,
88 "dht", 88 "dht",
89 "FORCE_NSE")) && 89 "FORCE_NSE")) &&
90 (GNUNET_OK == 90 (GNUNET_OK ==
91 GNUNET_CONFIGURATION_get_value_number (GDS_cfg, 91 GNUNET_CONFIGURATION_get_value_number(GDS_cfg,
92 "dht", 92 "dht",
93 "FORCE_NSE", 93 "FORCE_NSE",
94 &hops)) ) 94 &hops)))
95 { 95 {
96 log_of_network_size_estimate = (double) hops; 96 log_of_network_size_estimate = (double)hops;
97 return; 97 return;
98 } 98 }
99 nse = GNUNET_NSE_connect (GDS_cfg, &update_network_size_estimate, NULL); 99 nse = GNUNET_NSE_connect(GDS_cfg, &update_network_size_estimate, NULL);
100} 100}
101 101
102 102
@@ -104,13 +104,13 @@ GDS_NSE_init ()
104 * Shutdown NSE subsystem. 104 * Shutdown NSE subsystem.
105 */ 105 */
106void 106void
107GDS_NSE_done () 107GDS_NSE_done()
108{ 108{
109 if (NULL != nse) 109 if (NULL != nse)
110 { 110 {
111 GNUNET_NSE_disconnect (nse); 111 GNUNET_NSE_disconnect(nse);
112 nse = NULL; 112 nse = NULL;
113 } 113 }
114} 114}
115 115
116/* end of gnunet-service-dht_nse.c */ 116/* end of gnunet-service-dht_nse.c */
diff --git a/src/dht/gnunet-service-dht_nse.h b/src/dht/gnunet-service-dht_nse.h
index 4402bb860..d3cc9f383 100644
--- a/src/dht/gnunet-service-dht_nse.h
+++ b/src/dht/gnunet-service-dht_nse.h
@@ -11,12 +11,12 @@
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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file dht/gnunet-service-dht_nse.h 22 * @file dht/gnunet-service-dht_nse.h
@@ -33,20 +33,20 @@
33 * @return log of NSE 33 * @return log of NSE
34 */ 34 */
35double 35double
36GDS_NSE_get (void); 36GDS_NSE_get(void);
37 37
38 38
39/** 39/**
40 * Initialize NSE subsystem. 40 * Initialize NSE subsystem.
41 */ 41 */
42void 42void
43GDS_NSE_init (void); 43GDS_NSE_init(void);
44 44
45 45
46/** 46/**
47 * Shutdown NSE subsystem. 47 * Shutdown NSE subsystem.
48 */ 48 */
49void 49void
50GDS_NSE_done (void); 50GDS_NSE_done(void);
51 51
52#endif 52#endif
diff --git a/src/dht/gnunet-service-dht_routing.c b/src/dht/gnunet-service-dht_routing.c
index 1cee45a22..99c6b5e4f 100644
--- a/src/dht/gnunet-service-dht_routing.c
+++ b/src/dht/gnunet-service-dht_routing.c
@@ -11,12 +11,12 @@
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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file dht/gnunet-service-dht_routing.c 22 * @file dht/gnunet-service-dht_routing.c
@@ -39,9 +39,7 @@
39 * Information we keep about all recent GET requests 39 * Information we keep about all recent GET requests
40 * so that we can route replies. 40 * so that we can route replies.
41 */ 41 */
42struct RecentRequest 42struct RecentRequest {
43{
44
45 /** 43 /**
46 * The peer this request was received from. 44 * The peer this request was received from.
47 */ 45 */
@@ -82,7 +80,6 @@ struct RecentRequest
82 * Request options. 80 * Request options.
83 */ 81 */
84 enum GNUNET_DHT_RouteOption options; 82 enum GNUNET_DHT_RouteOption options;
85
86}; 83};
87 84
88 85
@@ -100,8 +97,7 @@ static struct GNUNET_CONTAINER_MultiHashMap *recent_map;
100/** 97/**
101 * Closure for the 'process' function. 98 * Closure for the 'process' function.
102 */ 99 */
103struct ProcessContext 100struct ProcessContext {
104{
105 /** 101 /**
106 * Path of the original PUT 102 * Path of the original PUT
107 */ 103 */
@@ -141,7 +137,6 @@ struct ProcessContext
141 * Type of the reply. 137 * Type of the reply.
142 */ 138 */
143 enum GNUNET_BLOCK_Type type; 139 enum GNUNET_BLOCK_Type type;
144
145}; 140};
146 141
147 142
@@ -155,9 +150,9 @@ struct ProcessContext
155 * #GNUNET_SYSERR if the result is malformed or type unsupported 150 * #GNUNET_SYSERR if the result is malformed or type unsupported
156 */ 151 */
157static int 152static int
158process (void *cls, 153process(void *cls,
159 const struct GNUNET_HashCode *key, 154 const struct GNUNET_HashCode *key,
160 void *value) 155 void *value)
161{ 156{
162 struct ProcessContext *pc = cls; 157 struct ProcessContext *pc = cls;
163 struct RecentRequest *rr = value; 158 struct RecentRequest *rr = value;
@@ -167,104 +162,111 @@ process (void *cls,
167 struct GNUNET_HashCode hc; 162 struct GNUNET_HashCode hc;
168 const struct GNUNET_HashCode *eval_key; 163 const struct GNUNET_HashCode *eval_key;
169 164
170 if ( (rr->type != GNUNET_BLOCK_TYPE_ANY) && 165 if ((rr->type != GNUNET_BLOCK_TYPE_ANY) &&
171 (rr->type != pc->type) ) 166 (rr->type != pc->type))
172 return GNUNET_OK; /* type missmatch */ 167 return GNUNET_OK; /* type missmatch */
173 168
174 if (0 != (rr->options & GNUNET_DHT_RO_RECORD_ROUTE)) 169 if (0 != (rr->options & GNUNET_DHT_RO_RECORD_ROUTE))
175 { 170 {
176 gpl = pc->get_path_length; 171 gpl = pc->get_path_length;
177 ppl = pc->put_path_length; 172 ppl = pc->put_path_length;
178 } 173 }
179 else 174 else
180 { 175 {
181 gpl = 0; 176 gpl = 0;
182 ppl = 0; 177 ppl = 0;
183 } 178 }
184 if ( (0 != (rr->options & GNUNET_DHT_RO_FIND_PEER)) && 179 if ((0 != (rr->options & GNUNET_DHT_RO_FIND_PEER)) &&
185 (pc->type == GNUNET_BLOCK_TYPE_DHT_HELLO) ) 180 (pc->type == GNUNET_BLOCK_TYPE_DHT_HELLO))
186 { 181 {
187 /* key may not match HELLO, which is OK since 182 /* key may not match HELLO, which is OK since
188 * the search is approximate. Still, the evaluation 183 * the search is approximate. Still, the evaluation
189 * would fail since the match is not exact. So 184 * would fail since the match is not exact. So
190 * we fake it by changing the key to the actual PID ... */ 185 * we fake it by changing the key to the actual PID ... */
191 GNUNET_BLOCK_get_key (GDS_block_context, 186 GNUNET_BLOCK_get_key(GDS_block_context,
192 GNUNET_BLOCK_TYPE_DHT_HELLO, 187 GNUNET_BLOCK_TYPE_DHT_HELLO,
193 pc->data, 188 pc->data,
194 pc->data_size, 189 pc->data_size,
195 &hc); 190 &hc);
196 eval_key = &hc; 191 eval_key = &hc;
197 } 192 }
198 else 193 else
199 { 194 {
200 eval_key = key; 195 eval_key = key;
201 } 196 }
202 eval 197 eval
203 = GNUNET_BLOCK_evaluate (GDS_block_context, 198 = GNUNET_BLOCK_evaluate(GDS_block_context,
204 pc->type, 199 pc->type,
205 rr->bg, 200 rr->bg,
206 GNUNET_BLOCK_EO_NONE, 201 GNUNET_BLOCK_EO_NONE,
207 eval_key, 202 eval_key,
208 rr->xquery, 203 rr->xquery,
209 rr->xquery_size, 204 rr->xquery_size,
210 pc->data, 205 pc->data,
211 pc->data_size); 206 pc->data_size);
212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 207 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
213 "Result for %s of type %d was evaluated as %d\n", 208 "Result for %s of type %d was evaluated as %d\n",
214 GNUNET_h2s (key), 209 GNUNET_h2s(key),
215 pc->type, 210 pc->type,
216 eval); 211 eval);
217 switch (eval) 212 switch (eval)
218 { 213 {
219 case GNUNET_BLOCK_EVALUATION_OK_MORE: 214 case GNUNET_BLOCK_EVALUATION_OK_MORE:
220 case GNUNET_BLOCK_EVALUATION_OK_LAST: 215 case GNUNET_BLOCK_EVALUATION_OK_LAST:
221 GNUNET_STATISTICS_update (GDS_stats, 216 GNUNET_STATISTICS_update(GDS_stats,
222 gettext_noop 217 gettext_noop
223 ("# Good REPLIES matched against routing table"), 218 ("# Good REPLIES matched against routing table"),
224 1, GNUNET_NO); 219 1, GNUNET_NO);
225 GDS_NEIGHBOURS_handle_reply (&rr->peer, 220 GDS_NEIGHBOURS_handle_reply(&rr->peer,
226 pc->type, 221 pc->type,
227 pc->expiration_time, 222 pc->expiration_time,
228 key, 223 key,
229 ppl, pc->put_path, 224 ppl, pc->put_path,
230 gpl, pc->get_path, 225 gpl, pc->get_path,
231 pc->data, 226 pc->data,
232 pc->data_size); 227 pc->data_size);
233 break; 228 break;
234 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: 229
235 GNUNET_STATISTICS_update (GDS_stats, 230 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
236 gettext_noop 231 GNUNET_STATISTICS_update(GDS_stats,
237 ("# Duplicate REPLIES matched against routing table"), 232 gettext_noop
238 1, GNUNET_NO); 233 ("# Duplicate REPLIES matched against routing table"),
239 return GNUNET_OK; 234 1, GNUNET_NO);
240 case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: 235 return GNUNET_OK;
241 GNUNET_STATISTICS_update (GDS_stats, 236
242 gettext_noop 237 case GNUNET_BLOCK_EVALUATION_RESULT_INVALID:
243 ("# Invalid REPLIES matched against routing table"), 238 GNUNET_STATISTICS_update(GDS_stats,
244 1, GNUNET_NO); 239 gettext_noop
245 return GNUNET_SYSERR; 240 ("# Invalid REPLIES matched against routing table"),
246 case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT: 241 1, GNUNET_NO);
247 GNUNET_STATISTICS_update (GDS_stats, 242 return GNUNET_SYSERR;
248 gettext_noop 243
249 ("# Irrelevant REPLIES matched against routing table"), 244 case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT:
250 1, GNUNET_NO); 245 GNUNET_STATISTICS_update(GDS_stats,
251 return GNUNET_OK; 246 gettext_noop
252 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: 247 ("# Irrelevant REPLIES matched against routing table"),
253 GNUNET_break (0); 248 1, GNUNET_NO);
254 return GNUNET_OK; 249 return GNUNET_OK;
255 case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: 250
256 GNUNET_break (0); 251 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
257 return GNUNET_OK; 252 GNUNET_break(0);
258 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: 253 return GNUNET_OK;
259 GNUNET_STATISTICS_update (GDS_stats, 254
260 gettext_noop 255 case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID:
261 ("# Unsupported REPLIES matched against routing table"), 256 GNUNET_break(0);
262 1, GNUNET_NO); 257 return GNUNET_OK;
263 return GNUNET_SYSERR; 258
264 default: 259 case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED:
265 GNUNET_break (0); 260 GNUNET_STATISTICS_update(GDS_stats,
266 return GNUNET_SYSERR; 261 gettext_noop
267 } 262 ("# Unsupported REPLIES matched against routing table"),
263 1, GNUNET_NO);
264 return GNUNET_SYSERR;
265
266 default:
267 GNUNET_break(0);
268 return GNUNET_SYSERR;
269 }
268 return GNUNET_OK; 270 return GNUNET_OK;
269} 271}
270 272
@@ -287,15 +289,15 @@ process (void *cls,
287 * @param data_size number of bytes in data 289 * @param data_size number of bytes in data
288 */ 290 */
289void 291void
290GDS_ROUTING_process (enum GNUNET_BLOCK_Type type, 292GDS_ROUTING_process(enum GNUNET_BLOCK_Type type,
291 struct GNUNET_TIME_Absolute expiration_time, 293 struct GNUNET_TIME_Absolute expiration_time,
292 const struct GNUNET_HashCode *key, 294 const struct GNUNET_HashCode *key,
293 unsigned int put_path_length, 295 unsigned int put_path_length,
294 const struct GNUNET_PeerIdentity *put_path, 296 const struct GNUNET_PeerIdentity *put_path,
295 unsigned int get_path_length, 297 unsigned int get_path_length,
296 const struct GNUNET_PeerIdentity *get_path, 298 const struct GNUNET_PeerIdentity *get_path,
297 const void *data, 299 const void *data,
298 size_t data_size) 300 size_t data_size)
299{ 301{
300 struct ProcessContext pc; 302 struct ProcessContext pc;
301 303
@@ -308,19 +310,19 @@ GDS_ROUTING_process (enum GNUNET_BLOCK_Type type,
308 pc.data = data; 310 pc.data = data;
309 pc.data_size = data_size; 311 pc.data_size = data_size;
310 if (NULL == data) 312 if (NULL == data)
311 { 313 {
312 /* Some apps might have an 'empty' reply as a valid reply; however, 314 /* Some apps might have an 'empty' reply as a valid reply; however,
313 'process' will call GNUNET_BLOCK_evaluate' which treats a 'NULL' 315 'process' will call GNUNET_BLOCK_evaluate' which treats a 'NULL'
314 reply as request-validation (but we need response-validation). 316 reply as request-validation (but we need response-validation).
315 So we set 'data' to a 0-byte non-NULL value just to be sure */ 317 So we set 'data' to a 0-byte non-NULL value just to be sure */
316 GNUNET_break (0 == data_size); 318 GNUNET_break(0 == data_size);
317 pc.data_size = 0; 319 pc.data_size = 0;
318 pc.data = ""; /* something not null */ 320 pc.data = ""; /* something not null */
319 } 321 }
320 GNUNET_CONTAINER_multihashmap_get_multiple (recent_map, 322 GNUNET_CONTAINER_multihashmap_get_multiple(recent_map,
321 key, 323 key,
322 &process, 324 &process,
323 &pc); 325 &pc);
324} 326}
325 327
326 328
@@ -330,23 +332,23 @@ GDS_ROUTING_process (enum GNUNET_BLOCK_Type type,
330 * in the heap and hashmap. 332 * in the heap and hashmap.
331 */ 333 */
332static void 334static void
333expire_oldest_entry () 335expire_oldest_entry()
334{ 336{
335 struct RecentRequest *recent_req; 337 struct RecentRequest *recent_req;
336 338
337 GNUNET_STATISTICS_update (GDS_stats, 339 GNUNET_STATISTICS_update(GDS_stats,
338 gettext_noop 340 gettext_noop
339 ("# Entries removed from routing table"), 1, 341 ("# Entries removed from routing table"), 1,
340 GNUNET_NO); 342 GNUNET_NO);
341 recent_req = GNUNET_CONTAINER_heap_peek (recent_heap); 343 recent_req = GNUNET_CONTAINER_heap_peek(recent_heap);
342 GNUNET_assert (recent_req != NULL); 344 GNUNET_assert(recent_req != NULL);
343 GNUNET_CONTAINER_heap_remove_node (recent_req->heap_node); 345 GNUNET_CONTAINER_heap_remove_node(recent_req->heap_node);
344 GNUNET_BLOCK_group_destroy (recent_req->bg); 346 GNUNET_BLOCK_group_destroy(recent_req->bg);
345 GNUNET_assert (GNUNET_YES == 347 GNUNET_assert(GNUNET_YES ==
346 GNUNET_CONTAINER_multihashmap_remove (recent_map, 348 GNUNET_CONTAINER_multihashmap_remove(recent_map,
347 &recent_req->key, 349 &recent_req->key,
348 recent_req)); 350 recent_req));
349 GNUNET_free (recent_req); 351 GNUNET_free(recent_req);
350} 352}
351 353
352 354
@@ -361,26 +363,26 @@ expire_oldest_entry ()
361 * #GNUNET_SYSERR if the request was successfully combined 363 * #GNUNET_SYSERR if the request was successfully combined
362 */ 364 */
363static int 365static int
364try_combine_recent (void *cls, 366try_combine_recent(void *cls,
365 const struct GNUNET_HashCode *key, 367 const struct GNUNET_HashCode *key,
366 void *value) 368 void *value)
367{ 369{
368 struct RecentRequest *in = cls; 370 struct RecentRequest *in = cls;
369 struct RecentRequest *rr = value; 371 struct RecentRequest *rr = value;
370 372
371 if ( (0 != GNUNET_memcmp (&in->peer, 373 if ((0 != GNUNET_memcmp(&in->peer,
372 &rr->peer)) || 374 &rr->peer)) ||
373 (in->type != rr->type) || 375 (in->type != rr->type) ||
374 (in->xquery_size != rr->xquery_size) || 376 (in->xquery_size != rr->xquery_size) ||
375 (0 != memcmp (in->xquery, 377 (0 != memcmp(in->xquery,
376 rr->xquery, 378 rr->xquery,
377 in->xquery_size)) ) 379 in->xquery_size)))
378 return GNUNET_OK; 380 return GNUNET_OK;
379 GNUNET_break (GNUNET_SYSERR != 381 GNUNET_break(GNUNET_SYSERR !=
380 GNUNET_BLOCK_group_merge (in->bg, 382 GNUNET_BLOCK_group_merge(in->bg,
381 rr->bg)); 383 rr->bg));
382 rr->bg = in->bg; 384 rr->bg = in->bg;
383 GNUNET_free (in); 385 GNUNET_free(in);
384 return GNUNET_SYSERR; 386 return GNUNET_SYSERR;
385} 387}
386 388
@@ -398,53 +400,53 @@ try_combine_recent (void *cls,
398 * @param reply_bf_mutator mutator for @a reply_bf 400 * @param reply_bf_mutator mutator for @a reply_bf
399 */ 401 */
400void 402void
401GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender, 403GDS_ROUTING_add(const struct GNUNET_PeerIdentity *sender,
402 enum GNUNET_BLOCK_Type type, 404 enum GNUNET_BLOCK_Type type,
403 struct GNUNET_BLOCK_Group *bg, 405 struct GNUNET_BLOCK_Group *bg,
404 enum GNUNET_DHT_RouteOption options, 406 enum GNUNET_DHT_RouteOption options,
405 const struct GNUNET_HashCode *key, 407 const struct GNUNET_HashCode *key,
406 const void *xquery, 408 const void *xquery,
407 size_t xquery_size) 409 size_t xquery_size)
408{ 410{
409 struct RecentRequest *recent_req; 411 struct RecentRequest *recent_req;
410 412
411 while (GNUNET_CONTAINER_heap_get_size (recent_heap) >= DHT_MAX_RECENT) 413 while (GNUNET_CONTAINER_heap_get_size(recent_heap) >= DHT_MAX_RECENT)
412 expire_oldest_entry (); 414 expire_oldest_entry();
413 GNUNET_STATISTICS_update (GDS_stats, 415 GNUNET_STATISTICS_update(GDS_stats,
414 gettext_noop ("# Entries added to routing table"), 416 gettext_noop("# Entries added to routing table"),
415 1, 417 1,
416 GNUNET_NO); 418 GNUNET_NO);
417 recent_req = GNUNET_malloc (sizeof (struct RecentRequest) + xquery_size); 419 recent_req = GNUNET_malloc(sizeof(struct RecentRequest) + xquery_size);
418 recent_req->peer = *sender; 420 recent_req->peer = *sender;
419 recent_req->key = *key; 421 recent_req->key = *key;
420 recent_req->bg = bg; 422 recent_req->bg = bg;
421 recent_req->type = type; 423 recent_req->type = type;
422 recent_req->options = options; 424 recent_req->options = options;
423 recent_req->xquery = &recent_req[1]; 425 recent_req->xquery = &recent_req[1];
424 GNUNET_memcpy (&recent_req[1], 426 GNUNET_memcpy(&recent_req[1],
425 xquery, 427 xquery,
426 xquery_size); 428 xquery_size);
427 recent_req->xquery_size = xquery_size; 429 recent_req->xquery_size = xquery_size;
428 if (GNUNET_SYSERR == 430 if (GNUNET_SYSERR ==
429 GNUNET_CONTAINER_multihashmap_get_multiple (recent_map, 431 GNUNET_CONTAINER_multihashmap_get_multiple(recent_map,
430 key, 432 key,
431 &try_combine_recent, 433 &try_combine_recent,
432 recent_req)) 434 recent_req))
433 { 435 {
434 GNUNET_STATISTICS_update (GDS_stats, 436 GNUNET_STATISTICS_update(GDS_stats,
435 gettext_noop 437 gettext_noop
436 ("# DHT requests combined"), 438 ("# DHT requests combined"),
437 1, GNUNET_NO); 439 1, GNUNET_NO);
438 return; 440 return;
439 } 441 }
440 recent_req->heap_node 442 recent_req->heap_node
441 = GNUNET_CONTAINER_heap_insert (recent_heap, 443 = GNUNET_CONTAINER_heap_insert(recent_heap,
444 recent_req,
445 GNUNET_TIME_absolute_get().abs_value_us);
446 GNUNET_CONTAINER_multihashmap_put(recent_map,
447 key,
442 recent_req, 448 recent_req,
443 GNUNET_TIME_absolute_get ().abs_value_us); 449 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
444 GNUNET_CONTAINER_multihashmap_put (recent_map,
445 key,
446 recent_req,
447 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
448} 450}
449 451
450 452
@@ -452,10 +454,10 @@ GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender,
452 * Initialize routing subsystem. 454 * Initialize routing subsystem.
453 */ 455 */
454void 456void
455GDS_ROUTING_init () 457GDS_ROUTING_init()
456{ 458{
457 recent_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 459 recent_heap = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN);
458 recent_map = GNUNET_CONTAINER_multihashmap_create (DHT_MAX_RECENT * 4 / 3, GNUNET_NO); 460 recent_map = GNUNET_CONTAINER_multihashmap_create(DHT_MAX_RECENT * 4 / 3, GNUNET_NO);
459} 461}
460 462
461 463
@@ -463,15 +465,15 @@ GDS_ROUTING_init ()
463 * Shutdown routing subsystem. 465 * Shutdown routing subsystem.
464 */ 466 */
465void 467void
466GDS_ROUTING_done () 468GDS_ROUTING_done()
467{ 469{
468 while (GNUNET_CONTAINER_heap_get_size (recent_heap) > 0) 470 while (GNUNET_CONTAINER_heap_get_size(recent_heap) > 0)
469 expire_oldest_entry (); 471 expire_oldest_entry();
470 GNUNET_assert (0 == GNUNET_CONTAINER_heap_get_size (recent_heap)); 472 GNUNET_assert(0 == GNUNET_CONTAINER_heap_get_size(recent_heap));
471 GNUNET_CONTAINER_heap_destroy (recent_heap); 473 GNUNET_CONTAINER_heap_destroy(recent_heap);
472 recent_heap = NULL; 474 recent_heap = NULL;
473 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (recent_map)); 475 GNUNET_assert(0 == GNUNET_CONTAINER_multihashmap_size(recent_map));
474 GNUNET_CONTAINER_multihashmap_destroy (recent_map); 476 GNUNET_CONTAINER_multihashmap_destroy(recent_map);
475 recent_map = NULL; 477 recent_map = NULL;
476} 478}
477 479
diff --git a/src/dht/gnunet-service-dht_routing.h b/src/dht/gnunet-service-dht_routing.h
index e7f707296..ace6b9c0c 100644
--- a/src/dht/gnunet-service-dht_routing.h
+++ b/src/dht/gnunet-service-dht_routing.h
@@ -11,12 +11,12 @@
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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file dht/gnunet-service-dht_routing.h 22 * @file dht/gnunet-service-dht_routing.h
@@ -49,15 +49,15 @@
49 * @param data_size number of bytes in @a data 49 * @param data_size number of bytes in @a data
50 */ 50 */
51void 51void
52GDS_ROUTING_process (enum GNUNET_BLOCK_Type type, 52GDS_ROUTING_process(enum GNUNET_BLOCK_Type type,
53 struct GNUNET_TIME_Absolute expiration_time, 53 struct GNUNET_TIME_Absolute expiration_time,
54 const struct GNUNET_HashCode *key, 54 const struct GNUNET_HashCode *key,
55 unsigned int put_path_length, 55 unsigned int put_path_length,
56 const struct GNUNET_PeerIdentity *put_path, 56 const struct GNUNET_PeerIdentity *put_path,
57 unsigned int get_path_length, 57 unsigned int get_path_length,
58 const struct GNUNET_PeerIdentity *get_path, 58 const struct GNUNET_PeerIdentity *get_path,
59 const void *data, 59 const void *data,
60 size_t data_size); 60 size_t data_size);
61 61
62 62
63/** 63/**
@@ -72,26 +72,26 @@ GDS_ROUTING_process (enum GNUNET_BLOCK_Type type,
72 * @param xquery_size number of bytes in @a xquery 72 * @param xquery_size number of bytes in @a xquery
73 */ 73 */
74void 74void
75GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender, 75GDS_ROUTING_add(const struct GNUNET_PeerIdentity *sender,
76 enum GNUNET_BLOCK_Type type, 76 enum GNUNET_BLOCK_Type type,
77 struct GNUNET_BLOCK_Group *bg, 77 struct GNUNET_BLOCK_Group *bg,
78 enum GNUNET_DHT_RouteOption options, 78 enum GNUNET_DHT_RouteOption options,
79 const struct GNUNET_HashCode * key, 79 const struct GNUNET_HashCode * key,
80 const void *xquery, 80 const void *xquery,
81 size_t xquery_size); 81 size_t xquery_size);
82 82
83 83
84/** 84/**
85 * Initialize routing subsystem. 85 * Initialize routing subsystem.
86 */ 86 */
87void 87void
88GDS_ROUTING_init (void); 88GDS_ROUTING_init(void);
89 89
90 90
91/** 91/**
92 * Shutdown routing subsystem. 92 * Shutdown routing subsystem.
93 */ 93 */
94void 94void
95GDS_ROUTING_done (void); 95GDS_ROUTING_done(void);
96 96
97#endif 97#endif
diff --git a/src/dht/gnunet_dht_profiler.c b/src/dht/gnunet_dht_profiler.c
index a8f5a3aca..179f84a11 100644
--- a/src/dht/gnunet_dht_profiler.c
+++ b/src/dht/gnunet_dht_profiler.c
@@ -11,12 +11,12 @@
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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file dht/gnunet_dht_profiler.c 22 * @file dht/gnunet_dht_profiler.c
@@ -32,10 +32,10 @@
32 32
33 33
34#define MESSAGE(...) \ 34#define MESSAGE(...) \
35 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, __VA_ARGS__) 35 GNUNET_log(GNUNET_ERROR_TYPE_MESSAGE, __VA_ARGS__)
36 36
37#define DEBUG(...) \ 37#define DEBUG(...) \
38 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) 38 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
39 39
40/** 40/**
41 * Number of peers which should perform a PUT out of 100 peers 41 * Number of peers which should perform a PUT out of 100 peers
@@ -60,8 +60,7 @@ struct ActiveContext;
60/** 60/**
61 * Context to hold data of peer 61 * Context to hold data of peer
62 */ 62 */
63struct Context 63struct Context {
64{
65 /** 64 /**
66 * The testbed peer this context belongs to 65 * The testbed peer this context belongs to
67 */ 66 */
@@ -76,15 +75,13 @@ struct Context
76 * Active context; NULL if this peer is not an active peer 75 * Active context; NULL if this peer is not an active peer
77 */ 76 */
78 struct ActiveContext *ac; 77 struct ActiveContext *ac;
79
80}; 78};
81 79
82 80
83/** 81/**
84 * Context for a peer which actively does DHT PUT/GET 82 * Context for a peer which actively does DHT PUT/GET
85 */ 83 */
86struct ActiveContext 84struct ActiveContext {
87{
88 /** 85 /**
89 * The linked peer context 86 * The linked peer context
90 */ 87 */
@@ -261,8 +258,7 @@ static int peers_started = 0;
261/** 258/**
262 * Should we do a PUT (mode = 0) or GET (mode = 1); 259 * Should we do a PUT (mode = 0) or GET (mode = 1);
263 */ 260 */
264static enum 261static enum {
265{
266 MODE_PUT = 0, 262 MODE_PUT = 0,
267 263
268 MODE_GET = 1 264 MODE_GET = 1
@@ -279,7 +275,7 @@ static int in_shutdown = 0;
279 * Connect to DHT services of active peers 275 * Connect to DHT services of active peers
280 */ 276 */
281static void 277static void
282start_profiling (void); 278start_profiling(void);
283 279
284 280
285/** 281/**
@@ -288,43 +284,43 @@ start_profiling (void);
288 * @param cls NULL 284 * @param cls NULL
289 */ 285 */
290static void 286static void
291do_shutdown (void *cls) 287do_shutdown(void *cls)
292{ 288{
293 struct ActiveContext *ac; 289 struct ActiveContext *ac;
294 290
295 in_shutdown = GNUNET_YES; 291 in_shutdown = GNUNET_YES;
296 if (NULL != a_ctx) 292 if (NULL != a_ctx)
297 {
298 for (unsigned int cnt=0; cnt < num_peers; cnt++)
299 { 293 {
300 /* Cleanup active context if this peer is an active peer */ 294 for (unsigned int cnt = 0; cnt < num_peers; cnt++)
301 ac = a_ctx[cnt].ac; 295 {
302 if (NULL != ac) 296 /* Cleanup active context if this peer is an active peer */
303 { 297 ac = a_ctx[cnt].ac;
304 if (NULL != ac->delay_task) 298 if (NULL != ac)
305 GNUNET_SCHEDULER_cancel (ac->delay_task); 299 {
306 if (NULL != ac->hash) 300 if (NULL != ac->delay_task)
307 free (ac->hash); 301 GNUNET_SCHEDULER_cancel(ac->delay_task);
308 if (NULL != ac->dht_put) 302 if (NULL != ac->hash)
309 GNUNET_DHT_put_cancel (ac->dht_put); 303 free(ac->hash);
310 if (NULL != ac->dht_get) 304 if (NULL != ac->dht_put)
311 GNUNET_DHT_get_stop (ac->dht_get); 305 GNUNET_DHT_put_cancel(ac->dht_put);
312 } 306 if (NULL != ac->dht_get)
313 /* Cleanup testbed operation handle at the last as this operation may 307 GNUNET_DHT_get_stop(ac->dht_get);
314 contain service connection to DHT */ 308 }
315 if (NULL != a_ctx[cnt].op) 309 /* Cleanup testbed operation handle at the last as this operation may
316 GNUNET_TESTBED_operation_done (a_ctx[cnt].op); 310 contain service connection to DHT */
311 if (NULL != a_ctx[cnt].op)
312 GNUNET_TESTBED_operation_done(a_ctx[cnt].op);
313 }
314 GNUNET_free(a_ctx);
315 a_ctx = NULL;
317 } 316 }
318 GNUNET_free (a_ctx);
319 a_ctx = NULL;
320 }
321 //FIXME: Should we collect stats only for put/get not for other messages. 317 //FIXME: Should we collect stats only for put/get not for other messages.
322 if (NULL != bandwidth_stats_op) 318 if (NULL != bandwidth_stats_op)
323 { 319 {
324 GNUNET_TESTBED_operation_done (bandwidth_stats_op); 320 GNUNET_TESTBED_operation_done(bandwidth_stats_op);
325 bandwidth_stats_op = NULL; 321 bandwidth_stats_op = NULL;
326 } 322 }
327 GNUNET_free_non_null (a_ac); 323 GNUNET_free_non_null(a_ac);
328} 324}
329 325
330 326
@@ -338,18 +334,18 @@ do_shutdown (void *cls)
338 * operation has executed successfully. 334 * operation has executed successfully.
339 */ 335 */
340static void 336static void
341bandwidth_stats_cont (void *cls, 337bandwidth_stats_cont(void *cls,
342 struct GNUNET_TESTBED_Operation *op, 338 struct GNUNET_TESTBED_Operation *op,
343 const char *emsg) 339 const char *emsg)
344{ 340{
345 MESSAGE ("# Outgoing (core) bandwidth: %llu bytes\n", 341 MESSAGE("# Outgoing (core) bandwidth: %llu bytes\n",
346 (unsigned long long) outgoing_bandwidth); 342 (unsigned long long)outgoing_bandwidth);
347 MESSAGE ("# Incoming (core) bandwidth: %llu bytes\n", 343 MESSAGE("# Incoming (core) bandwidth: %llu bytes\n",
348 (unsigned long long) incoming_bandwidth); 344 (unsigned long long)incoming_bandwidth);
349 fprintf (stderr, 345 fprintf(stderr,
350 "Benchmark done. Collect data via gnunet-statistics, then press ENTER to exit.\n"); 346 "Benchmark done. Collect data via gnunet-statistics, then press ENTER to exit.\n");
351 (void) getchar (); 347 (void)getchar();
352 GNUNET_SCHEDULER_shutdown (); 348 GNUNET_SCHEDULER_shutdown();
353} 349}
354 350
355 351
@@ -365,55 +361,55 @@ bandwidth_stats_cont (void *cls,
365 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration 361 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
366 */ 362 */
367static int 363static int
368bandwidth_stats_iterator (void *cls, 364bandwidth_stats_iterator(void *cls,
369 const struct GNUNET_TESTBED_Peer *peer, 365 const struct GNUNET_TESTBED_Peer *peer,
370 const char *subsystem, 366 const char *subsystem,
371 const char *name, 367 const char *name,
372 uint64_t value, 368 uint64_t value,
373 int is_persistent) 369 int is_persistent)
374{ 370{
375 static const char *s_sent = "# bytes encrypted"; 371 static const char *s_sent = "# bytes encrypted";
376 static const char *s_recv = "# bytes decrypted"; 372 static const char *s_recv = "# bytes decrypted";
377 373
378 if (0 == strncmp (s_sent, name, strlen (s_sent))) 374 if (0 == strncmp(s_sent, name, strlen(s_sent)))
379 outgoing_bandwidth = outgoing_bandwidth + value; 375 outgoing_bandwidth = outgoing_bandwidth + value;
380 else if (0 == strncmp(s_recv, name, strlen (s_recv))) 376 else if (0 == strncmp(s_recv, name, strlen(s_recv)))
381 incoming_bandwidth = incoming_bandwidth + value; 377 incoming_bandwidth = incoming_bandwidth + value;
382 return GNUNET_OK; 378 return GNUNET_OK;
383} 379}
384 380
385 381
386static void 382static void
387summarize () 383summarize()
388{ 384{
389 MESSAGE ("# PUTS started: %llu\n", 385 MESSAGE("# PUTS started: %llu\n",
390 n_puts); 386 n_puts);
391 MESSAGE ("# PUTS succeeded: %llu\n", 387 MESSAGE("# PUTS succeeded: %llu\n",
392 n_puts_ok); 388 n_puts_ok);
393 MESSAGE ("# GETS made: %u\n", 389 MESSAGE("# GETS made: %u\n",
394 n_gets); 390 n_gets);
395 MESSAGE ("# GETS succeeded: %u\n", 391 MESSAGE("# GETS succeeded: %u\n",
396 n_gets_ok); 392 n_gets_ok);
397 MESSAGE ("# GETS failed: %u\n", 393 MESSAGE("# GETS failed: %u\n",
398 n_gets_fail); 394 n_gets_fail);
399 MESSAGE ("# average_put_path_length: %f\n", 395 MESSAGE("# average_put_path_length: %f\n",
400 average_put_path_length); 396 average_put_path_length);
401 MESSAGE ("# average_get_path_length: %f\n", 397 MESSAGE("# average_get_path_length: %f\n",
402 average_get_path_length); 398 average_get_path_length);
403 399
404 if (NULL == testbed_handles) 400 if (NULL == testbed_handles)
405 { 401 {
406 MESSAGE ("No peers found\n"); 402 MESSAGE("No peers found\n");
407 return; 403 return;
408 } 404 }
409 /* Collect Stats*/ 405 /* Collect Stats*/
410 bandwidth_stats_op = GNUNET_TESTBED_get_statistics (n_active, 406 bandwidth_stats_op = GNUNET_TESTBED_get_statistics(n_active,
411 testbed_handles, 407 testbed_handles,
412 "core", 408 "core",
413 NULL, 409 NULL,
414 &bandwidth_stats_iterator, 410 &bandwidth_stats_iterator,
415 &bandwidth_stats_cont, 411 &bandwidth_stats_cont,
416 NULL); 412 NULL);
417} 413}
418 414
419 415
@@ -423,27 +419,27 @@ summarize ()
423 * @param cls NULL 419 * @param cls NULL
424 */ 420 */
425static void 421static void
426cancel_get (void *cls) 422cancel_get(void *cls)
427{ 423{
428 struct ActiveContext *ac = cls; 424 struct ActiveContext *ac = cls;
429 struct Context *ctx = ac->ctx; 425 struct Context *ctx = ac->ctx;
430 426
431 ac->delay_task = NULL; 427 ac->delay_task = NULL;
432 GNUNET_assert (NULL != ac->dht_get); 428 GNUNET_assert(NULL != ac->dht_get);
433 GNUNET_DHT_get_stop (ac->dht_get); 429 GNUNET_DHT_get_stop(ac->dht_get);
434 ac->dht_get = NULL; 430 ac->dht_get = NULL;
435 n_gets_fail++; 431 n_gets_fail++;
436 GNUNET_assert (NULL != ctx->op); 432 GNUNET_assert(NULL != ctx->op);
437 GNUNET_TESTBED_operation_done (ctx->op); 433 GNUNET_TESTBED_operation_done(ctx->op);
438 ctx->op = NULL; 434 ctx->op = NULL;
439 435
440 /* If profiling is complete, summarize */ 436 /* If profiling is complete, summarize */
441 if (n_active == n_gets_fail + n_gets_ok) 437 if (n_active == n_gets_fail + n_gets_ok)
442 { 438 {
443 average_put_path_length = (double)total_put_path_length/(double)n_active; 439 average_put_path_length = (double)total_put_path_length / (double)n_active;
444 average_get_path_length = (double)total_get_path_length/(double )n_gets_ok; 440 average_get_path_length = (double)total_get_path_length / (double )n_gets_ok;
445 summarize (); 441 summarize();
446 } 442 }
447} 443}
448 444
449 445
@@ -465,45 +461,45 @@ cancel_get (void *cls)
465 * @param data pointer to the result data 461 * @param data pointer to the result data
466 */ 462 */
467static void 463static void
468get_iter (void *cls, 464get_iter(void *cls,
469 struct GNUNET_TIME_Absolute exp, 465 struct GNUNET_TIME_Absolute exp,
470 const struct GNUNET_HashCode *key, 466 const struct GNUNET_HashCode *key,
471 const struct GNUNET_PeerIdentity *get_path, 467 const struct GNUNET_PeerIdentity *get_path,
472 unsigned int get_path_length, 468 unsigned int get_path_length,
473 const struct GNUNET_PeerIdentity *put_path, 469 const struct GNUNET_PeerIdentity *put_path,
474 unsigned int put_path_length, 470 unsigned int put_path_length,
475 enum GNUNET_BLOCK_Type type, 471 enum GNUNET_BLOCK_Type type,
476 size_t size, const void *data) 472 size_t size, const void *data)
477{ 473{
478 struct ActiveContext *ac = cls; 474 struct ActiveContext *ac = cls;
479 struct ActiveContext *get_ac = ac->get_ac; 475 struct ActiveContext *get_ac = ac->get_ac;
480 struct Context *ctx = ac->ctx; 476 struct Context *ctx = ac->ctx;
481 477
482 /* we found the data we are looking for */ 478 /* we found the data we are looking for */
483 DEBUG ("We found a GET request; %u remaining\n", 479 DEBUG("We found a GET request; %u remaining\n",
484 n_gets - (n_gets_fail + n_gets_ok)); //FIXME: It always prints 1. 480 n_gets - (n_gets_fail + n_gets_ok)); //FIXME: It always prints 1.
485 n_gets_ok++; 481 n_gets_ok++;
486 get_ac->nrefs--; 482 get_ac->nrefs--;
487 GNUNET_DHT_get_stop (ac->dht_get); 483 GNUNET_DHT_get_stop(ac->dht_get);
488 ac->dht_get = NULL; 484 ac->dht_get = NULL;
489 if (ac->delay_task != NULL) 485 if (ac->delay_task != NULL)
490 GNUNET_SCHEDULER_cancel (ac->delay_task); 486 GNUNET_SCHEDULER_cancel(ac->delay_task);
491 ac->delay_task = NULL; 487 ac->delay_task = NULL;
492 GNUNET_assert (NULL != ctx->op); 488 GNUNET_assert(NULL != ctx->op);
493 GNUNET_TESTBED_operation_done (ctx->op); 489 GNUNET_TESTBED_operation_done(ctx->op);
494 ctx->op = NULL; 490 ctx->op = NULL;
495 491
496 total_put_path_length = total_put_path_length + (double)put_path_length; 492 total_put_path_length = total_put_path_length + (double)put_path_length;
497 total_get_path_length = total_get_path_length + (double)get_path_length; 493 total_get_path_length = total_get_path_length + (double)get_path_length;
498 DEBUG ("total_put_path_length = %u,put_path \n", 494 DEBUG("total_put_path_length = %u,put_path \n",
499 total_put_path_length); 495 total_put_path_length);
500 /* Summarize if profiling is complete */ 496 /* Summarize if profiling is complete */
501 if (n_active == n_gets_fail + n_gets_ok) 497 if (n_active == n_gets_fail + n_gets_ok)
502 { 498 {
503 average_put_path_length = (double)total_put_path_length/(double)n_active; 499 average_put_path_length = (double)total_put_path_length / (double)n_active;
504 average_get_path_length = (double)total_get_path_length/(double )n_gets_ok; 500 average_get_path_length = (double)total_get_path_length / (double )n_gets_ok;
505 summarize (); 501 summarize();
506 } 502 }
507} 503}
508 504
509 505
@@ -513,7 +509,7 @@ get_iter (void *cls,
513 * @param cls the active context 509 * @param cls the active context
514 */ 510 */
515static void 511static void
516delayed_get (void *cls) 512delayed_get(void *cls)
517{ 513{
518 struct ActiveContext *ac = cls; 514 struct ActiveContext *ac = cls;
519 struct ActiveContext *get_ac; 515 struct ActiveContext *get_ac;
@@ -522,34 +518,34 @@ delayed_get (void *cls)
522 ac->delay_task = NULL; 518 ac->delay_task = NULL;
523 get_ac = NULL; 519 get_ac = NULL;
524 while (1) 520 while (1)
525 { 521 {
526 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 522 r = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
527 n_active); 523 n_active);
528 get_ac = &a_ac[r]; 524 get_ac = &a_ac[r];
529 if (NULL != get_ac->hash) 525 if (NULL != get_ac->hash)
530 break; 526 break;
531 } 527 }
532 get_ac->nrefs++; 528 get_ac->nrefs++;
533 ac->get_ac = get_ac; 529 ac->get_ac = get_ac;
534 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 530 r = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
535 num_puts_per_peer); 531 num_puts_per_peer);
536 DEBUG ("GET_REQUEST_START key %s \n", 532 DEBUG("GET_REQUEST_START key %s \n",
537 GNUNET_h2s(&get_ac->hash[r])); 533 GNUNET_h2s(&get_ac->hash[r]));
538 ac->dht_get = GNUNET_DHT_get_start (ac->dht, 534 ac->dht_get = GNUNET_DHT_get_start(ac->dht,
539 GNUNET_BLOCK_TYPE_TEST, 535 GNUNET_BLOCK_TYPE_TEST,
540 &get_ac->hash[r], 536 &get_ac->hash[r],
541 1, /* replication level */ 537 1, /* replication level */
542 GNUNET_DHT_RO_NONE, 538 GNUNET_DHT_RO_NONE,
543 NULL, 539 NULL,
544 0, /* extended query and size */ 540 0, /* extended query and size */
545 &get_iter, 541 &get_iter,
546 ac); /* GET iterator and closure */ 542 ac); /* GET iterator and closure */
547 n_gets++; 543 n_gets++;
548 544
549 /* schedule the timeout task for GET */ 545 /* schedule the timeout task for GET */
550 ac->delay_task = GNUNET_SCHEDULER_add_delayed (timeout, 546 ac->delay_task = GNUNET_SCHEDULER_add_delayed(timeout,
551 &cancel_get, 547 &cancel_get,
552 ac); 548 ac);
553} 549}
554 550
555 551
@@ -561,7 +557,7 @@ delayed_get (void *cls)
561 * @param cls the active context 557 * @param cls the active context
562 */ 558 */
563static void 559static void
564delayed_put (void *cls); 560delayed_put(void *cls);
565 561
566 562
567/** 563/**
@@ -571,14 +567,14 @@ delayed_put (void *cls);
571 * @param cls the active context 567 * @param cls the active context
572 */ 568 */
573static void 569static void
574put_cont (void *cls) 570put_cont(void *cls)
575{ 571{
576 struct ActiveContext *ac = cls; 572 struct ActiveContext *ac = cls;
577 573
578 ac->dht_put = NULL; 574 ac->dht_put = NULL;
579 n_puts_ok++; 575 n_puts_ok++;
580 ac->delay_task = GNUNET_SCHEDULER_add_now (&delayed_put, 576 ac->delay_task = GNUNET_SCHEDULER_add_now(&delayed_put,
581 ac); 577 ac);
582} 578}
583 579
584 580
@@ -590,7 +586,7 @@ put_cont (void *cls)
590 * @param cls the active context 586 * @param cls the active context
591 */ 587 */
592static void 588static void
593delayed_put (void *cls) 589delayed_put(void *cls)
594{ 590{
595 struct ActiveContext *ac = cls; 591 struct ActiveContext *ac = cls;
596 char block[65536]; 592 char block[65536];
@@ -598,42 +594,42 @@ delayed_put (void *cls)
598 594
599 ac->delay_task = NULL; 595 ac->delay_task = NULL;
600 if (0 == ac->put_count) 596 if (0 == ac->put_count)
601 { 597 {
602 struct Context *ctx = ac->ctx; 598 struct Context *ctx = ac->ctx;
603 struct GNUNET_TESTBED_Operation *op; 599 struct GNUNET_TESTBED_Operation *op;
604 600
605 GNUNET_assert (NULL != ctx); 601 GNUNET_assert(NULL != ctx);
606 op = ctx->op; 602 op = ctx->op;
607 ctx->op = NULL; 603 ctx->op = NULL;
608 GNUNET_TESTBED_operation_done (op); 604 GNUNET_TESTBED_operation_done(op);
609 return; 605 return;
610 } 606 }
611 607
612 608
613 /* Generate and DHT PUT some random data */ 609 /* Generate and DHT PUT some random data */
614 block_size = 16; /* minimum */ 610 block_size = 16; /* minimum */
615 /* make random payload, reserve 512 - 16 bytes for DHT headers */ 611 /* make random payload, reserve 512 - 16 bytes for DHT headers */
616 block_size += GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 612 block_size += GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
617 GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE - 512); 613 GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE - 512);
618 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, 614 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK,
619 block, 615 block,
620 block_size); 616 block_size);
621 ac->put_count--; 617 ac->put_count--;
622 GNUNET_CRYPTO_hash (block, 618 GNUNET_CRYPTO_hash(block,
623 block_size, 619 block_size,
624 &ac->hash[ac->put_count]); 620 &ac->hash[ac->put_count]);
625 DEBUG ("PUT_REQUEST_START key %s\n", 621 DEBUG("PUT_REQUEST_START key %s\n",
626 GNUNET_h2s (&ac->hash[ac->put_count])); 622 GNUNET_h2s(&ac->hash[ac->put_count]));
627 ac->dht_put = GNUNET_DHT_put (ac->dht, 623 ac->dht_put = GNUNET_DHT_put(ac->dht,
628 &ac->hash[ac->put_count], 624 &ac->hash[ac->put_count],
629 replication, 625 replication,
630 GNUNET_DHT_RO_RECORD_ROUTE, 626 GNUNET_DHT_RO_RECORD_ROUTE,
631 GNUNET_BLOCK_TYPE_TEST, 627 GNUNET_BLOCK_TYPE_TEST,
632 block_size, 628 block_size,
633 block, 629 block,
634 GNUNET_TIME_UNIT_FOREVER_ABS, /* expiration time */ 630 GNUNET_TIME_UNIT_FOREVER_ABS, /* expiration time */
635 &put_cont, 631 &put_cont,
636 ac); /* continuation and its closure */ 632 ac); /* continuation and its closure */
637 n_puts++; 633 n_puts++;
638} 634}
639 635
@@ -648,65 +644,66 @@ delayed_put (void *cls)
648 * operation has executed successfully. 644 * operation has executed successfully.
649 */ 645 */
650static void 646static void
651dht_connected (void *cls, 647dht_connected(void *cls,
652 struct GNUNET_TESTBED_Operation *op, 648 struct GNUNET_TESTBED_Operation *op,
653 void *ca_result, 649 void *ca_result,
654 const char *emsg) 650 const char *emsg)
655{ 651{
656 struct ActiveContext *ac = cls; 652 struct ActiveContext *ac = cls;
657 struct Context *ctx = ac->ctx; 653 struct Context *ctx = ac->ctx;
658 654
659 GNUNET_assert (NULL != ctx); //FIXME: Fails 655 GNUNET_assert(NULL != ctx); //FIXME: Fails
660 GNUNET_assert (NULL != ctx->op); 656 GNUNET_assert(NULL != ctx->op);
661 GNUNET_assert (ctx->op == op); 657 GNUNET_assert(ctx->op == op);
662 ac->dht = (struct GNUNET_DHT_Handle *) ca_result; 658 ac->dht = (struct GNUNET_DHT_Handle *)ca_result;
663 if (NULL != emsg) 659 if (NULL != emsg)
664 { 660 {
665 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 661 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
666 "Connection to DHT service failed: %s\n", 662 "Connection to DHT service failed: %s\n",
667 emsg); 663 emsg);
668 GNUNET_TESTBED_operation_done (ctx->op); /* Calls dht_disconnect() */ 664 GNUNET_TESTBED_operation_done(ctx->op); /* Calls dht_disconnect() */
669 ctx->op = NULL; 665 ctx->op = NULL;
670 return; 666 return;
671 } 667 }
672 switch (mode) 668 switch (mode)
673 { 669 {
674 case MODE_PUT: 670 case MODE_PUT:
675 { 671 {
676 struct GNUNET_TIME_Relative peer_delay_put; 672 struct GNUNET_TIME_Relative peer_delay_put;
677 673
678 peer_delay_put.rel_value_us = 674 peer_delay_put.rel_value_us =
679 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 675 GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK,
680 delay_put.rel_value_us); 676 delay_put.rel_value_us);
681 ac->put_count = num_puts_per_peer; 677 ac->put_count = num_puts_per_peer;
682 ac->hash = calloc (ac->put_count, 678 ac->hash = calloc(ac->put_count,
683 sizeof (struct GNUNET_HashCode)); 679 sizeof(struct GNUNET_HashCode));
684 if (NULL == ac->hash) 680 if (NULL == ac->hash)
685 { 681 {
686 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, 682 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR,
687 "calloc"); 683 "calloc");
688 GNUNET_SCHEDULER_shutdown (); 684 GNUNET_SCHEDULER_shutdown();
689 return; 685 return;
690 } 686 }
691 ac->delay_task = GNUNET_SCHEDULER_add_delayed (peer_delay_put, 687 ac->delay_task = GNUNET_SCHEDULER_add_delayed(peer_delay_put,
692 &delayed_put, 688 &delayed_put,
693 ac); 689 ac);
694 break; 690 break;
695 } 691 }
696 case MODE_GET: 692
693 case MODE_GET:
697 { 694 {
698 struct GNUNET_TIME_Relative peer_delay_get; 695 struct GNUNET_TIME_Relative peer_delay_get;
699 696
700 peer_delay_get.rel_value_us = 697 peer_delay_get.rel_value_us =
701 delay_get.rel_value_us + 698 delay_get.rel_value_us +
702 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 699 GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK,
703 delay_get.rel_value_us); 700 delay_get.rel_value_us);
704 ac->delay_task = GNUNET_SCHEDULER_add_delayed (peer_delay_get, 701 ac->delay_task = GNUNET_SCHEDULER_add_delayed(peer_delay_get,
705 &delayed_get, 702 &delayed_get,
706 ac); 703 ac);
707 break; 704 break;
708 } 705 }
709 } 706 }
710} 707}
711 708
712 709
@@ -720,12 +717,12 @@ dht_connected (void *cls,
720 * @return service handle to return in 'op_result', NULL on error 717 * @return service handle to return in 'op_result', NULL on error
721 */ 718 */
722static void * 719static void *
723dht_connect (void *cls, 720dht_connect(void *cls,
724 const struct GNUNET_CONFIGURATION_Handle *cfg) 721 const struct GNUNET_CONFIGURATION_Handle *cfg)
725{ 722{
726 n_dht++; 723 n_dht++;
727 return GNUNET_DHT_connect (cfg, 724 return GNUNET_DHT_connect(cfg,
728 10); 725 10);
729} 726}
730 727
731 728
@@ -737,14 +734,14 @@ dht_connect (void *cls,
737 * @param op_result service handle returned from the connect adapter 734 * @param op_result service handle returned from the connect adapter
738 */ 735 */
739static void 736static void
740dht_disconnect (void *cls, 737dht_disconnect(void *cls,
741 void *op_result) 738 void *op_result)
742{ 739{
743 struct ActiveContext *ac = cls; 740 struct ActiveContext *ac = cls;
744 741
745 GNUNET_assert (NULL != ac->dht); 742 GNUNET_assert(NULL != ac->dht);
746 GNUNET_assert (ac->dht == op_result); 743 GNUNET_assert(ac->dht == op_result);
747 GNUNET_DHT_disconnect (ac->dht); 744 GNUNET_DHT_disconnect(ac->dht);
748 ac->dht = NULL; 745 ac->dht = NULL;
749 n_dht--; 746 n_dht--;
750 if (0 != n_dht) 747 if (0 != n_dht)
@@ -752,19 +749,20 @@ dht_disconnect (void *cls,
752 if (GNUNET_YES == in_shutdown) 749 if (GNUNET_YES == in_shutdown)
753 return; 750 return;
754 switch (mode) 751 switch (mode)
755 { 752 {
756 case MODE_PUT: 753 case MODE_PUT:
757 if (n_puts_ok != ((unsigned long long) n_active) * num_puts_per_peer) 754 if (n_puts_ok != ((unsigned long long)n_active) * num_puts_per_peer)
758 return; 755 return;
759 /* Start GETs if all PUTs have been made */ 756 /* Start GETs if all PUTs have been made */
760 mode = MODE_GET; 757 mode = MODE_GET;
761 start_profiling (); 758 start_profiling();
762 return;
763 case MODE_GET:
764 if ((n_gets_ok + n_gets_fail) != n_active)
765 return; 759 return;
766 break; 760
767 } 761 case MODE_GET:
762 if ((n_gets_ok + n_gets_fail) != n_active)
763 return;
764 break;
765 }
768} 766}
769 767
770 768
@@ -776,21 +774,21 @@ start_profiling()
776{ 774{
777 struct Context *ctx; 775 struct Context *ctx;
778 776
779 DEBUG ("GNUNET_TESTBED_service_connect\n"); 777 DEBUG("GNUNET_TESTBED_service_connect\n");
780 GNUNET_break (GNUNET_YES != in_shutdown); 778 GNUNET_break(GNUNET_YES != in_shutdown);
781 for (unsigned int i = 0; i < n_active; i++) 779 for (unsigned int i = 0; i < n_active; i++)
782 { 780 {
783 struct ActiveContext *ac = &a_ac[i]; 781 struct ActiveContext *ac = &a_ac[i];
784 GNUNET_assert (NULL != (ctx = ac->ctx)); 782 GNUNET_assert(NULL != (ctx = ac->ctx));
785 GNUNET_assert (NULL == ctx->op); 783 GNUNET_assert(NULL == ctx->op);
786 ctx->op = GNUNET_TESTBED_service_connect (ctx, 784 ctx->op = GNUNET_TESTBED_service_connect(ctx,
787 ctx->peer, 785 ctx->peer,
788 "dht", 786 "dht",
789 &dht_connected, ac, 787 &dht_connected, ac,
790 &dht_connect, 788 &dht_connect,
791 &dht_disconnect, 789 &dht_disconnect,
792 ac); 790 ac);
793 } 791 }
794} 792}
795 793
796 794
@@ -803,22 +801,22 @@ start_profiling()
803 * operation has executed successfully. 801 * operation has executed successfully.
804 */ 802 */
805static void 803static void
806service_started (void *cls, 804service_started(void *cls,
807 struct GNUNET_TESTBED_Operation *op, 805 struct GNUNET_TESTBED_Operation *op,
808 const char *emsg) 806 const char *emsg)
809{ 807{
810 struct Context *ctx = cls; 808 struct Context *ctx = cls;
811 809
812 GNUNET_assert (NULL != ctx); 810 GNUNET_assert(NULL != ctx);
813 GNUNET_assert (NULL != ctx->op); 811 GNUNET_assert(NULL != ctx->op);
814 GNUNET_TESTBED_operation_done (ctx->op); 812 GNUNET_TESTBED_operation_done(ctx->op);
815 ctx->op = NULL; 813 ctx->op = NULL;
816 peers_started++; 814 peers_started++;
817 DEBUG ("Peers Started = %d; num_peers = %d \n", 815 DEBUG("Peers Started = %d; num_peers = %d \n",
818 peers_started, 816 peers_started,
819 num_peers); 817 num_peers);
820 if (peers_started == num_peers) 818 if (peers_started == num_peers)
821 start_profiling (); 819 start_profiling();
822} 820}
823 821
824 822
@@ -834,63 +832,63 @@ service_started (void *cls,
834 * @param links_failed the number of overlay link 832 * @param links_failed the number of overlay link
835 */ 833 */
836static void 834static void
837test_run (void *cls, 835test_run(void *cls,
838 struct GNUNET_TESTBED_RunHandle *h, 836 struct GNUNET_TESTBED_RunHandle *h,
839 unsigned int num_peers, 837 unsigned int num_peers,
840 struct GNUNET_TESTBED_Peer **peers, 838 struct GNUNET_TESTBED_Peer **peers,
841 unsigned int links_succeeded, 839 unsigned int links_succeeded,
842 unsigned int links_failed) 840 unsigned int links_failed)
843{ 841{
844 unsigned int ac_cnt; 842 unsigned int ac_cnt;
845 843
846 testbed_handles = peers; 844 testbed_handles = peers;
847 if (NULL == peers) 845 if (NULL == peers)
848 { 846 {
849 /* exit */ 847 /* exit */
850 GNUNET_assert (0); 848 GNUNET_assert(0);
851 } 849 }
852 MESSAGE ("%u peers started, %u/%u links up\n", 850 MESSAGE("%u peers started, %u/%u links up\n",
853 num_peers, 851 num_peers,
854 links_succeeded, 852 links_succeeded,
855 links_succeeded + links_failed); 853 links_succeeded + links_failed);
856 a_ctx = GNUNET_new_array (num_peers, 854 a_ctx = GNUNET_new_array(num_peers,
857 struct Context); 855 struct Context);
858 /* select the peers which actively participate in profiling */ 856 /* select the peers which actively participate in profiling */
859 n_active = num_peers * put_probability / 100; 857 n_active = num_peers * put_probability / 100;
860 if (0 == n_active) 858 if (0 == n_active)
861 { 859 {
862 GNUNET_SCHEDULER_shutdown (); 860 GNUNET_SCHEDULER_shutdown();
863 GNUNET_free (a_ctx); 861 GNUNET_free(a_ctx);
864 a_ctx = NULL; 862 a_ctx = NULL;
865 return; 863 return;
866 } 864 }
867 865
868 a_ac = GNUNET_new_array (n_active, 866 a_ac = GNUNET_new_array(n_active,
869 struct ActiveContext); 867 struct ActiveContext);
870 ac_cnt = 0; 868 ac_cnt = 0;
871 for (unsigned int cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++) 869 for (unsigned int cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++)
872 { 870 {
873 if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 871 if (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
874 100) >= put_probability) 872 100) >= put_probability)
875 continue; 873 continue;
876 874
877 a_ctx[cnt].ac = &a_ac[ac_cnt]; 875 a_ctx[cnt].ac = &a_ac[ac_cnt];
878 a_ac[ac_cnt].ctx = &a_ctx[cnt]; 876 a_ac[ac_cnt].ctx = &a_ctx[cnt];
879 ac_cnt++; 877 ac_cnt++;
880 } 878 }
881 n_active = ac_cnt; 879 n_active = ac_cnt;
882 880
883 /* start DHT service on all peers */ 881 /* start DHT service on all peers */
884 for (unsigned int cnt = 0; cnt < num_peers; cnt++) 882 for (unsigned int cnt = 0; cnt < num_peers; cnt++)
885 { 883 {
886 a_ctx[cnt].peer = peers[cnt]; 884 a_ctx[cnt].peer = peers[cnt];
887 a_ctx[cnt].op = GNUNET_TESTBED_peer_manage_service (&a_ctx[cnt], 885 a_ctx[cnt].op = GNUNET_TESTBED_peer_manage_service(&a_ctx[cnt],
888 peers[cnt], 886 peers[cnt],
889 "dht", 887 "dht",
890 &service_started, 888 &service_started,
891 &a_ctx[cnt], 889 &a_ctx[cnt],
892 1); 890 1);
893 } 891 }
894} 892}
895 893
896 894
@@ -903,32 +901,32 @@ test_run (void *cls,
903 * @param config configuration 901 * @param config configuration
904 */ 902 */
905static void 903static void
906run (void *cls, 904run(void *cls,
907 char *const *args, 905 char *const *args,
908 const char *cfgfile, 906 const char *cfgfile,
909 const struct GNUNET_CONFIGURATION_Handle *config) 907 const struct GNUNET_CONFIGURATION_Handle *config)
910{ 908{
911 uint64_t event_mask; 909 uint64_t event_mask;
912 910
913 if (0 == num_peers) 911 if (0 == num_peers)
914 { 912 {
915 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 913 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
916 _("Exiting as the number of peers is %u\n"), 914 _("Exiting as the number of peers is %u\n"),
917 num_peers); 915 num_peers);
918 return; 916 return;
919 } 917 }
920 cfg = config; 918 cfg = config;
921 event_mask = 0; 919 event_mask = 0;
922 GNUNET_TESTBED_run (hosts_file, 920 GNUNET_TESTBED_run(hosts_file,
923 cfg, 921 cfg,
924 num_peers, 922 num_peers,
925 event_mask, 923 event_mask,
926 NULL, 924 NULL,
927 NULL, 925 NULL,
928 &test_run, 926 &test_run,
929 NULL); 927 NULL);
930 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 928 GNUNET_SCHEDULER_add_shutdown(&do_shutdown,
931 NULL); 929 NULL);
932} 930}
933 931
934 932
@@ -938,78 +936,78 @@ run (void *cls,
938 * @return 0 on success 936 * @return 0 on success
939 */ 937 */
940int 938int
941main (int argc, 939main(int argc,
942 char *const *argv) 940 char *const *argv)
943{ 941{
944 int rc; 942 int rc;
945 struct GNUNET_GETOPT_CommandLineOption options[] = { 943 struct GNUNET_GETOPT_CommandLineOption options[] = {
946 GNUNET_GETOPT_option_uint ('n', 944 GNUNET_GETOPT_option_uint('n',
947 "peers", 945 "peers",
948 "COUNT", 946 "COUNT",
949 gettext_noop ("number of peers to start"), 947 gettext_noop("number of peers to start"),
950 &num_peers), 948 &num_peers),
951 GNUNET_GETOPT_option_uint ('p', 949 GNUNET_GETOPT_option_uint('p',
952 "peer-put-count", 950 "peer-put-count",
953 "COUNT", 951 "COUNT",
954 gettext_noop ("number of PUTs to perform per peer"), 952 gettext_noop("number of PUTs to perform per peer"),
955 &num_puts_per_peer), 953 &num_puts_per_peer),
956 GNUNET_GETOPT_option_string ('H', 954 GNUNET_GETOPT_option_string('H',
957 "hosts", 955 "hosts",
958 "FILENAME", 956 "FILENAME",
959 gettext_noop ("name of the file with the login information for the testbed"), 957 gettext_noop("name of the file with the login information for the testbed"),
960 &hosts_file), 958 &hosts_file),
961 GNUNET_GETOPT_option_relative_time ('D', 959 GNUNET_GETOPT_option_relative_time('D',
962 "delay", 960 "delay",
963 "DELAY", 961 "DELAY",
964 gettext_noop ("delay between rounds for collecting statistics (default: 30 sec)"), 962 gettext_noop("delay between rounds for collecting statistics (default: 30 sec)"),
965 &delay_stats), 963 &delay_stats),
966 GNUNET_GETOPT_option_relative_time ('P', 964 GNUNET_GETOPT_option_relative_time('P',
967 "PUT-delay", 965 "PUT-delay",
968 "DELAY", 966 "DELAY",
969 gettext_noop ("delay to start doing PUTs (default: 1 sec)"), 967 gettext_noop("delay to start doing PUTs (default: 1 sec)"),
970 &delay_put), 968 &delay_put),
971 GNUNET_GETOPT_option_relative_time ('G', 969 GNUNET_GETOPT_option_relative_time('G',
972 "GET-delay", 970 "GET-delay",
973 "DELAY", 971 "DELAY",
974 gettext_noop ("delay to start doing GETs (default: 5 min)"), 972 gettext_noop("delay to start doing GETs (default: 5 min)"),
975 &delay_get), 973 &delay_get),
976 GNUNET_GETOPT_option_uint ('r', 974 GNUNET_GETOPT_option_uint('r',
977 "replication", 975 "replication",
978 "DEGREE", 976 "DEGREE",
979 gettext_noop ("replication degree for DHT PUTs"), 977 gettext_noop("replication degree for DHT PUTs"),
980 &replication), 978 &replication),
981 GNUNET_GETOPT_option_uint ('R', 979 GNUNET_GETOPT_option_uint('R',
982 "random-chance", 980 "random-chance",
983 "PROBABILITY", 981 "PROBABILITY",
984 gettext_noop ("chance that a peer is selected at random for PUTs"), 982 gettext_noop("chance that a peer is selected at random for PUTs"),
985 &put_probability), 983 &put_probability),
986 GNUNET_GETOPT_option_relative_time ('t', 984 GNUNET_GETOPT_option_relative_time('t',
987 "timeout", 985 "timeout",
988 "TIMEOUT", 986 "TIMEOUT",
989 gettext_noop ("timeout for DHT PUT and GET requests (default: 1 min)"), 987 gettext_noop("timeout for DHT PUT and GET requests (default: 1 min)"),
990 &timeout), 988 &timeout),
991 GNUNET_GETOPT_OPTION_END 989 GNUNET_GETOPT_OPTION_END
992 }; 990 };
993 991
994 if (GNUNET_OK != 992 if (GNUNET_OK !=
995 GNUNET_STRINGS_get_utf8_args (argc, argv, 993 GNUNET_STRINGS_get_utf8_args(argc, argv,
996 &argc, &argv)) 994 &argc, &argv))
997 return 2; 995 return 2;
998 /* set default delays */ 996 /* set default delays */
999 delay_stats = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); 997 delay_stats = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10);
1000 delay_put = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); 998 delay_put = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10);
1001 delay_get = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); 999 delay_get = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10);
1002 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); 1000 timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10);
1003 replication = 1; /* default replication */ 1001 replication = 1; /* default replication */
1004 rc = 0; 1002 rc = 0;
1005 if (GNUNET_OK != 1003 if (GNUNET_OK !=
1006 GNUNET_PROGRAM_run (argc, 1004 GNUNET_PROGRAM_run(argc,
1007 argv, 1005 argv,
1008 "gnunet-dht-profiler", 1006 "gnunet-dht-profiler",
1009 gettext_noop ("Measure quality and performance of the DHT service."), 1007 gettext_noop("Measure quality and performance of the DHT service."),
1010 options, 1008 options,
1011 &run, 1009 &run,
1012 NULL)) 1010 NULL))
1013 rc = 1; 1011 rc = 1;
1014 return rc; 1012 return rc;
1015} 1013}
diff --git a/src/dht/plugin_block_dht.c b/src/dht/plugin_block_dht.c
index 44f4b9226..918a18eb6 100644
--- a/src/dht/plugin_block_dht.c
+++ b/src/dht/plugin_block_dht.c
@@ -11,12 +11,12 @@
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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file dht/plugin_block_dht.c 22 * @file dht/plugin_block_dht.c
@@ -53,38 +53,38 @@
53 * by this @a type of block (this is not an error) 53 * by this @a type of block (this is not an error)
54 */ 54 */
55static struct GNUNET_BLOCK_Group * 55static struct GNUNET_BLOCK_Group *
56block_plugin_dht_create_group (void *cls, 56block_plugin_dht_create_group(void *cls,
57 enum GNUNET_BLOCK_Type type, 57 enum GNUNET_BLOCK_Type type,
58 uint32_t nonce, 58 uint32_t nonce,
59 const void *raw_data, 59 const void *raw_data,
60 size_t raw_data_size, 60 size_t raw_data_size,
61 va_list va) 61 va_list va)
62{ 62{
63 unsigned int bf_size; 63 unsigned int bf_size;
64 const char *guard; 64 const char *guard;
65 65
66 guard = va_arg (va, const char *); 66 guard = va_arg(va, const char *);
67 if (0 == strcmp (guard, 67 if (0 == strcmp(guard,
68 "seen-set-size")) 68 "seen-set-size"))
69 bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, 69 bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size(va_arg(va,
70 unsigned int), 70 unsigned int),
71 BLOOMFILTER_K); 71 BLOOMFILTER_K);
72 else if (0 == strcmp (guard, 72 else if (0 == strcmp(guard,
73 "filter-size")) 73 "filter-size"))
74 bf_size = va_arg (va, unsigned int); 74 bf_size = va_arg(va, unsigned int);
75 else 75 else
76 { 76 {
77 GNUNET_break (0); 77 GNUNET_break(0);
78 bf_size = 8; 78 bf_size = 8;
79 } 79 }
80 GNUNET_break (NULL == va_arg (va, const char *)); 80 GNUNET_break(NULL == va_arg(va, const char *));
81 return GNUNET_BLOCK_GROUP_bf_create (cls, 81 return GNUNET_BLOCK_GROUP_bf_create(cls,
82 bf_size, 82 bf_size,
83 BLOOMFILTER_K, 83 BLOOMFILTER_K,
84 type, 84 type,
85 nonce, 85 nonce,
86 raw_data, 86 raw_data,
87 raw_data_size); 87 raw_data_size);
88} 88}
89 89
90 90
@@ -105,16 +105,16 @@ block_plugin_dht_create_group (void *cls,
105 * @return characterization of result 105 * @return characterization of result
106 */ 106 */
107static enum GNUNET_BLOCK_EvaluationResult 107static enum GNUNET_BLOCK_EvaluationResult
108block_plugin_dht_evaluate (void *cls, 108block_plugin_dht_evaluate(void *cls,
109 struct GNUNET_BLOCK_Context *ctx, 109 struct GNUNET_BLOCK_Context *ctx,
110 enum GNUNET_BLOCK_Type type, 110 enum GNUNET_BLOCK_Type type,
111 struct GNUNET_BLOCK_Group *group, 111 struct GNUNET_BLOCK_Group *group,
112 enum GNUNET_BLOCK_EvaluationOptions eo, 112 enum GNUNET_BLOCK_EvaluationOptions eo,
113 const struct GNUNET_HashCode *query, 113 const struct GNUNET_HashCode *query,
114 const void *xquery, 114 const void *xquery,
115 size_t xquery_size, 115 size_t xquery_size,
116 const void *reply_block, 116 const void *reply_block,
117 size_t reply_block_size) 117 size_t reply_block_size)
118{ 118{
119 const struct GNUNET_HELLO_Message *hello; 119 const struct GNUNET_HELLO_Message *hello;
120 struct GNUNET_PeerIdentity pid; 120 struct GNUNET_PeerIdentity pid;
@@ -124,35 +124,35 @@ block_plugin_dht_evaluate (void *cls,
124 if (type != GNUNET_BLOCK_TYPE_DHT_HELLO) 124 if (type != GNUNET_BLOCK_TYPE_DHT_HELLO)
125 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; 125 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
126 if (0 != xquery_size) 126 if (0 != xquery_size)
127 { 127 {
128 GNUNET_break_op (0); 128 GNUNET_break_op(0);
129 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; 129 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
130 } 130 }
131 if (NULL == reply_block) 131 if (NULL == reply_block)
132 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 132 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
133 if (reply_block_size < sizeof (struct GNUNET_MessageHeader)) 133 if (reply_block_size < sizeof(struct GNUNET_MessageHeader))
134 { 134 {
135 GNUNET_break_op (0); 135 GNUNET_break_op(0);
136 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 136 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
137 } 137 }
138 msg = reply_block; 138 msg = reply_block;
139 if (reply_block_size != ntohs (msg->size)) 139 if (reply_block_size != ntohs(msg->size))
140 { 140 {
141 GNUNET_break_op (0); 141 GNUNET_break_op(0);
142 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 142 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
143 } 143 }
144 hello = reply_block; 144 hello = reply_block;
145 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid)) 145 if (GNUNET_OK != GNUNET_HELLO_get_id(hello, &pid))
146 { 146 {
147 GNUNET_break_op (0); 147 GNUNET_break_op(0);
148 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 148 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
149 } 149 }
150 GNUNET_CRYPTO_hash (&pid, 150 GNUNET_CRYPTO_hash(&pid,
151 sizeof (pid), 151 sizeof(pid),
152 &phash); 152 &phash);
153 if (GNUNET_YES == 153 if (GNUNET_YES ==
154 GNUNET_BLOCK_GROUP_bf_test_and_set (group, 154 GNUNET_BLOCK_GROUP_bf_test_and_set(group,
155 &phash)) 155 &phash))
156 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; 156 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
157 return GNUNET_BLOCK_EVALUATION_OK_MORE; 157 return GNUNET_BLOCK_EVALUATION_OK_MORE;
158} 158}
@@ -170,11 +170,11 @@ block_plugin_dht_evaluate (void *cls,
170 * (or if extracting a key from a block of this type does not work) 170 * (or if extracting a key from a block of this type does not work)
171 */ 171 */
172static int 172static int
173block_plugin_dht_get_key (void *cls, 173block_plugin_dht_get_key(void *cls,
174 enum GNUNET_BLOCK_Type type, 174 enum GNUNET_BLOCK_Type type,
175 const void *block, 175 const void *block,
176 size_t block_size, 176 size_t block_size,
177 struct GNUNET_HashCode *key) 177 struct GNUNET_HashCode *key)
178{ 178{
179 const struct GNUNET_MessageHeader *msg; 179 const struct GNUNET_MessageHeader *msg;
180 const struct GNUNET_HELLO_Message *hello; 180 const struct GNUNET_HELLO_Message *hello;
@@ -182,34 +182,34 @@ block_plugin_dht_get_key (void *cls,
182 182
183 if (type != GNUNET_BLOCK_TYPE_DHT_HELLO) 183 if (type != GNUNET_BLOCK_TYPE_DHT_HELLO)
184 return GNUNET_SYSERR; 184 return GNUNET_SYSERR;
185 if (block_size < sizeof (struct GNUNET_MessageHeader)) 185 if (block_size < sizeof(struct GNUNET_MessageHeader))
186 { 186 {
187 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 187 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR,
188 "block-dht", 188 "block-dht",
189 _("Block not of type %u\n"), 189 _("Block not of type %u\n"),
190 GNUNET_BLOCK_TYPE_DHT_HELLO); 190 GNUNET_BLOCK_TYPE_DHT_HELLO);
191 return GNUNET_NO; 191 return GNUNET_NO;
192 } 192 }
193 msg = block; 193 msg = block;
194 if (block_size != ntohs (msg->size)) 194 if (block_size != ntohs(msg->size))
195 { 195 {
196 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 196 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR,
197 "block-dht", 197 "block-dht",
198 _("Size mismatch for block\n"), 198 _("Size mismatch for block\n"),
199 GNUNET_BLOCK_TYPE_DHT_HELLO); 199 GNUNET_BLOCK_TYPE_DHT_HELLO);
200 return GNUNET_NO; 200 return GNUNET_NO;
201 } 201 }
202 hello = block; 202 hello = block;
203 memset (key, 0, sizeof (*key)); 203 memset(key, 0, sizeof(*key));
204 pid = (struct GNUNET_PeerIdentity *) key; 204 pid = (struct GNUNET_PeerIdentity *)key;
205 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, pid)) 205 if (GNUNET_OK != GNUNET_HELLO_get_id(hello, pid))
206 { 206 {
207 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 207 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR,
208 "block-dht", 208 "block-dht",
209 _("Block of type %u is malformed\n"), 209 _("Block of type %u is malformed\n"),
210 GNUNET_BLOCK_TYPE_DHT_HELLO); 210 GNUNET_BLOCK_TYPE_DHT_HELLO);
211 return GNUNET_NO; 211 return GNUNET_NO;
212 } 212 }
213 return GNUNET_OK; 213 return GNUNET_OK;
214} 214}
215 215
@@ -218,7 +218,7 @@ block_plugin_dht_get_key (void *cls,
218 * Entry point for the plugin. 218 * Entry point for the plugin.
219 */ 219 */
220void * 220void *
221libgnunet_plugin_block_dht_init (void *cls) 221libgnunet_plugin_block_dht_init(void *cls)
222{ 222{
223 static enum GNUNET_BLOCK_Type types[] = 223 static enum GNUNET_BLOCK_Type types[] =
224 { 224 {
@@ -227,7 +227,7 @@ libgnunet_plugin_block_dht_init (void *cls)
227 }; 227 };
228 struct GNUNET_BLOCK_PluginFunctions *api; 228 struct GNUNET_BLOCK_PluginFunctions *api;
229 229
230 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); 230 api = GNUNET_new(struct GNUNET_BLOCK_PluginFunctions);
231 api->evaluate = &block_plugin_dht_evaluate; 231 api->evaluate = &block_plugin_dht_evaluate;
232 api->get_key = &block_plugin_dht_get_key; 232 api->get_key = &block_plugin_dht_get_key;
233 api->create_group = &block_plugin_dht_create_group; 233 api->create_group = &block_plugin_dht_create_group;
@@ -240,11 +240,11 @@ libgnunet_plugin_block_dht_init (void *cls)
240 * Exit point from the plugin. 240 * Exit point from the plugin.
241 */ 241 */
242void * 242void *
243libgnunet_plugin_block_dht_done (void *cls) 243libgnunet_plugin_block_dht_done(void *cls)
244{ 244{
245 struct GNUNET_BLOCK_PluginFunctions *api = cls; 245 struct GNUNET_BLOCK_PluginFunctions *api = cls;
246 246
247 GNUNET_free (api); 247 GNUNET_free(api);
248 return NULL; 248 return NULL;
249} 249}
250 250
diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c
index 7ec6758b7..f4a337ea8 100644
--- a/src/dht/test_dht_api.c
+++ b/src/dht/test_dht_api.c
@@ -11,12 +11,12 @@
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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file dht/test_dht_api.c 21 * @file dht/test_dht_api.c
22 * @brief base test case for dht api 22 * @brief base test case for dht api
@@ -34,7 +34,7 @@
34/** 34/**
35 * How long until we really give up on a particular testcase portion? 35 * How long until we really give up on a particular testcase portion?
36 */ 36 */
37#define TOTAL_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) 37#define TOTAL_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60)
38 38
39static struct GNUNET_DHT_Handle *dht_handle; 39static struct GNUNET_DHT_Handle *dht_handle;
40 40
@@ -48,55 +48,55 @@ static struct GNUNET_SCHEDULER_Task *die_task;
48 48
49 49
50static void 50static void
51do_shutdown (void *cls) 51do_shutdown(void *cls)
52{ 52{
53 if (NULL != die_task) 53 if (NULL != die_task)
54 { 54 {
55 GNUNET_SCHEDULER_cancel (die_task); 55 GNUNET_SCHEDULER_cancel(die_task);
56 die_task = NULL; 56 die_task = NULL;
57 } 57 }
58 if (NULL != put_handle) 58 if (NULL != put_handle)
59 { 59 {
60 GNUNET_DHT_put_cancel (put_handle); 60 GNUNET_DHT_put_cancel(put_handle);
61 put_handle = NULL; 61 put_handle = NULL;
62 } 62 }
63 if (NULL != get_handle) 63 if (NULL != get_handle)
64 { 64 {
65 GNUNET_DHT_get_stop (get_handle); 65 GNUNET_DHT_get_stop(get_handle);
66 get_handle = NULL; 66 get_handle = NULL;
67 } 67 }
68 GNUNET_DHT_disconnect (dht_handle); 68 GNUNET_DHT_disconnect(dht_handle);
69 dht_handle = NULL; 69 dht_handle = NULL;
70} 70}
71 71
72 72
73static void 73static void
74end_badly (void *cls) 74end_badly(void *cls)
75{ 75{
76 die_task = NULL; 76 die_task = NULL;
77 fprintf (stderr, 77 fprintf(stderr,
78 "%s", 78 "%s",
79 "Ending on an unhappy note.\n"); 79 "Ending on an unhappy note.\n");
80 GNUNET_SCHEDULER_shutdown (); 80 GNUNET_SCHEDULER_shutdown();
81 ok = 1; 81 ok = 1;
82} 82}
83 83
84 84
85static void 85static void
86test_get_iterator (void *cls, 86test_get_iterator(void *cls,
87 struct GNUNET_TIME_Absolute exp, 87 struct GNUNET_TIME_Absolute exp,
88 const struct GNUNET_HashCode *key, 88 const struct GNUNET_HashCode *key,
89 const struct GNUNET_PeerIdentity *get_path, 89 const struct GNUNET_PeerIdentity *get_path,
90 unsigned int get_path_length, 90 unsigned int get_path_length,
91 const struct GNUNET_PeerIdentity *put_path, 91 const struct GNUNET_PeerIdentity *put_path,
92 unsigned int put_path_length, 92 unsigned int put_path_length,
93 enum GNUNET_BLOCK_Type type, 93 enum GNUNET_BLOCK_Type type,
94 size_t size, 94 size_t size,
95 const void *data) 95 const void *data)
96{ 96{
97 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 97 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
98 "test_get_iterator called (we got a result), stopping get request!\n"); 98 "test_get_iterator called (we got a result), stopping get request!\n");
99 GNUNET_SCHEDULER_shutdown (); 99 GNUNET_SCHEDULER_shutdown();
100 ok = 0; 100 ok = 0;
101} 101}
102 102
@@ -107,83 +107,83 @@ test_get_iterator (void *cls,
107 * @param cls closure 107 * @param cls closure
108 */ 108 */
109static void 109static void
110test_get (void *cls) 110test_get(void *cls)
111{ 111{
112 struct GNUNET_HashCode hash; 112 struct GNUNET_HashCode hash;
113 113
114 put_handle = NULL; 114 put_handle = NULL;
115 memset (&hash, 115 memset(&hash,
116 42, 116 42,
117 sizeof (struct GNUNET_HashCode)); 117 sizeof(struct GNUNET_HashCode));
118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 118 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
119 "Called test_get!\n"); 119 "Called test_get!\n");
120 GNUNET_assert (dht_handle != NULL); 120 GNUNET_assert(dht_handle != NULL);
121 get_handle = GNUNET_DHT_get_start (dht_handle, 121 get_handle = GNUNET_DHT_get_start(dht_handle,
122 GNUNET_BLOCK_TYPE_TEST, 122 GNUNET_BLOCK_TYPE_TEST,
123 &hash, 123 &hash,
124 1, 124 1,
125 GNUNET_DHT_RO_NONE, 125 GNUNET_DHT_RO_NONE,
126 NULL, 126 NULL,
127 0, 127 0,
128 &test_get_iterator, 128 &test_get_iterator,
129 NULL); 129 NULL);
130 130
131 if (NULL == get_handle) 131 if (NULL == get_handle)
132 { 132 {
133 GNUNET_break (0); 133 GNUNET_break(0);
134 ok = 1; 134 ok = 1;
135 GNUNET_SCHEDULER_shutdown (); 135 GNUNET_SCHEDULER_shutdown();
136 return; 136 return;
137 } 137 }
138} 138}
139 139
140 140
141static void 141static void
142run (void *cls, 142run(void *cls,
143 const struct GNUNET_CONFIGURATION_Handle *cfg, 143 const struct GNUNET_CONFIGURATION_Handle *cfg,
144 struct GNUNET_TESTING_Peer *peer) 144 struct GNUNET_TESTING_Peer *peer)
145{ 145{
146 struct GNUNET_HashCode hash; 146 struct GNUNET_HashCode hash;
147 char *data; 147 char *data;
148 size_t data_size = 42; 148 size_t data_size = 42;
149 149
150 GNUNET_assert (ok == 1); 150 GNUNET_assert(ok == 1);
151 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 151 GNUNET_SCHEDULER_add_shutdown(&do_shutdown,
152 NULL); 152 NULL);
153 die_task = GNUNET_SCHEDULER_add_delayed (TOTAL_TIMEOUT, 153 die_task = GNUNET_SCHEDULER_add_delayed(TOTAL_TIMEOUT,
154 &end_badly, 154 &end_badly,
155 NULL); 155 NULL);
156 memset (&hash, 156 memset(&hash,
157 42, 157 42,
158 sizeof (struct GNUNET_HashCode)); 158 sizeof(struct GNUNET_HashCode));
159 data = GNUNET_malloc (data_size); 159 data = GNUNET_malloc(data_size);
160 memset (data, 43, data_size); 160 memset(data, 43, data_size);
161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 161 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
162 "Called test_put!\n"); 162 "Called test_put!\n");
163 dht_handle = GNUNET_DHT_connect (cfg, 163 dht_handle = GNUNET_DHT_connect(cfg,
164 100); 164 100);
165 GNUNET_assert (NULL != dht_handle); 165 GNUNET_assert(NULL != dht_handle);
166 put_handle = GNUNET_DHT_put (dht_handle, 166 put_handle = GNUNET_DHT_put(dht_handle,
167 &hash, 167 &hash,
168 1, 168 1,
169 GNUNET_DHT_RO_NONE, 169 GNUNET_DHT_RO_NONE,
170 GNUNET_BLOCK_TYPE_TEST, 170 GNUNET_BLOCK_TYPE_TEST,
171 data_size, 171 data_size,
172 data, 172 data,
173 GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT), 173 GNUNET_TIME_relative_to_absolute(TOTAL_TIMEOUT),
174 &test_get, 174 &test_get,
175 NULL); 175 NULL);
176 GNUNET_free (data); 176 GNUNET_free(data);
177} 177}
178 178
179 179
180int 180int
181main (int argc, 181main(int argc,
182 char *argv[]) 182 char *argv[])
183{ 183{
184 if (0 != GNUNET_TESTING_peer_run ("test-dht-api", 184 if (0 != GNUNET_TESTING_peer_run("test-dht-api",
185 "test_dht_api_data.conf", 185 "test_dht_api_data.conf",
186 &run, NULL)) 186 &run, NULL))
187 return 1; 187 return 1;
188 return ok; 188 return ok;
189} 189}
diff --git a/src/dht/test_dht_monitor.c b/src/dht/test_dht_monitor.c
index 9d0462c87..f5586e9bc 100644
--- a/src/dht/test_dht_monitor.c
+++ b/src/dht/test_dht_monitor.c
@@ -11,12 +11,12 @@
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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file dht/test_dht_monitor.c 21 * @file dht/test_dht_monitor.c
22 * @brief Test for the dht monitoring API; checks that we receive "some" monitor events 22 * @brief Test for the dht monitoring API; checks that we receive "some" monitor events
@@ -31,19 +31,18 @@
31/** 31/**
32 * How long do we run the test at most? 32 * How long do we run the test at most?
33 */ 33 */
34#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) 34#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 300)
35 35
36/** 36/**
37 * How often do we run the PUTs? 37 * How often do we run the PUTs?
38 */ 38 */
39#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)
40 40
41 41
42/** 42/**
43 * Information we keep for each GET operation. 43 * Information we keep for each GET operation.
44 */ 44 */
45struct GetOperation 45struct GetOperation {
46{
47 /** 46 /**
48 * DLL. 47 * DLL.
49 */ 48 */
@@ -58,7 +57,6 @@ struct GetOperation
58 * Handle for the operation. 57 * Handle for the operation.
59 */ 58 */
60 struct GNUNET_DHT_GetHandle *get; 59 struct GNUNET_DHT_GetHandle *get;
61
62}; 60};
63 61
64 62
@@ -110,34 +108,34 @@ static unsigned int monitor_counter;
110 * @param cls the `struct GNUNET_DHT_TEST_Context` 108 * @param cls the `struct GNUNET_DHT_TEST_Context`
111 */ 109 */
112static void 110static void
113shutdown_task (void *cls) 111shutdown_task(void *cls)
114{ 112{
115 struct GNUNET_DHT_TEST_Context *ctx = cls; 113 struct GNUNET_DHT_TEST_Context *ctx = cls;
116 unsigned int i; 114 unsigned int i;
117 struct GetOperation *get_op; 115 struct GetOperation *get_op;
118 116
119 ok = (monitor_counter > NUM_PEERS) ? 0 : 2; 117 ok = (monitor_counter > NUM_PEERS) ? 0 : 2;
120 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 118 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
121 "Received %u monitor events\n", 119 "Received %u monitor events\n",
122 monitor_counter); 120 monitor_counter);
123 while (NULL != (get_op = get_tail)) 121 while (NULL != (get_op = get_tail))
124 { 122 {
125 GNUNET_DHT_get_stop (get_op->get); 123 GNUNET_DHT_get_stop(get_op->get);
126 GNUNET_CONTAINER_DLL_remove (get_head, 124 GNUNET_CONTAINER_DLL_remove(get_head,
127 get_tail, 125 get_tail,
128 get_op); 126 get_op);
129 GNUNET_free (get_op); 127 GNUNET_free(get_op);
130 } 128 }
131 for (i=0;i<NUM_PEERS;i++) 129 for (i = 0; i < NUM_PEERS; i++)
132 GNUNET_DHT_monitor_stop (monitors[i]); 130 GNUNET_DHT_monitor_stop(monitors[i]);
133 GNUNET_free (monitors); 131 GNUNET_free(monitors);
134 GNUNET_SCHEDULER_cancel (put_task); 132 GNUNET_SCHEDULER_cancel(put_task);
135 GNUNET_DHT_TEST_cleanup (ctx); 133 GNUNET_DHT_TEST_cleanup(ctx);
136 if (NULL != timeout_task) 134 if (NULL != timeout_task)
137 { 135 {
138 GNUNET_SCHEDULER_cancel (timeout_task); 136 GNUNET_SCHEDULER_cancel(timeout_task);
139 timeout_task = NULL; 137 timeout_task = NULL;
140 } 138 }
141} 139}
142 140
143 141
@@ -149,10 +147,10 @@ shutdown_task (void *cls)
149 * @param cls NULL 147 * @param cls NULL
150 */ 148 */
151static void 149static void
152timeout_task_cb (void *cls) 150timeout_task_cb(void *cls)
153{ 151{
154 timeout_task = NULL; 152 timeout_task = NULL;
155 GNUNET_SCHEDULER_shutdown (); 153 GNUNET_SCHEDULER_shutdown();
156} 154}
157 155
158 156
@@ -172,41 +170,41 @@ timeout_task_cb (void *cls)
172 * @param data pointer to the result data 170 * @param data pointer to the result data
173 */ 171 */
174static void 172static void
175dht_get_handler (void *cls, struct GNUNET_TIME_Absolute exp, 173dht_get_handler(void *cls, struct GNUNET_TIME_Absolute exp,
176 const struct GNUNET_HashCode * key, 174 const struct GNUNET_HashCode * key,
177 const struct GNUNET_PeerIdentity *get_path, 175 const struct GNUNET_PeerIdentity *get_path,
178 unsigned int get_path_length, 176 unsigned int get_path_length,
179 const struct GNUNET_PeerIdentity *put_path, 177 const struct GNUNET_PeerIdentity *put_path,
180 unsigned int put_path_length, 178 unsigned int put_path_length,
181 enum GNUNET_BLOCK_Type type, 179 enum GNUNET_BLOCK_Type type,
182 size_t size, const void *data) 180 size_t size, const void *data)
183{ 181{
184 struct GetOperation *get_op = cls; 182 struct GetOperation *get_op = cls;
185 struct GNUNET_HashCode want; 183 struct GNUNET_HashCode want;
186 184
187 if (sizeof (struct GNUNET_HashCode) != size) 185 if (sizeof(struct GNUNET_HashCode) != size)
188 { 186 {
189 GNUNET_break (0); 187 GNUNET_break(0);
190 return; 188 return;
191 } 189 }
192 GNUNET_CRYPTO_hash (key, sizeof (*key), &want); 190 GNUNET_CRYPTO_hash(key, sizeof(*key), &want);
193 if (0 != memcmp (&want, data, sizeof (want))) 191 if (0 != memcmp(&want, data, sizeof(want)))
194 { 192 {
195 GNUNET_break (0); 193 GNUNET_break(0);
196 return; 194 return;
197 } 195 }
198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 196 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
199 "Get successful\n"); 197 "Get successful\n");
200 GNUNET_DHT_get_stop (get_op->get); 198 GNUNET_DHT_get_stop(get_op->get);
201 GNUNET_CONTAINER_DLL_remove (get_head, 199 GNUNET_CONTAINER_DLL_remove(get_head,
202 get_tail, 200 get_tail,
203 get_op); 201 get_op);
204 GNUNET_free (get_op); 202 GNUNET_free(get_op);
205 if (NULL != get_head) 203 if (NULL != get_head)
206 return; 204 return;
207 /* all DHT GET operations successful; terminate! */ 205 /* all DHT GET operations successful; terminate! */
208 ok = 0; 206 ok = 0;
209 GNUNET_SCHEDULER_shutdown (); 207 GNUNET_SCHEDULER_shutdown();
210} 208}
211 209
212 210
@@ -216,28 +214,28 @@ dht_get_handler (void *cls, struct GNUNET_TIME_Absolute exp,
216 * @param cls array with NUM_PEERS DHT handles 214 * @param cls array with NUM_PEERS DHT handles
217 */ 215 */
218static void 216static void
219do_puts (void *cls) 217do_puts(void *cls)
220{ 218{
221 struct GNUNET_DHT_Handle **hs = cls; 219 struct GNUNET_DHT_Handle **hs = cls;
222 struct GNUNET_HashCode key; 220 struct GNUNET_HashCode key;
223 struct GNUNET_HashCode value; 221 struct GNUNET_HashCode value;
224 222
225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 223 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
226 "Putting values into DHT\n"); 224 "Putting values into DHT\n");
227 for (unsigned int i = 0; i < NUM_PEERS; i++) 225 for (unsigned int i = 0; i < NUM_PEERS; i++)
228 { 226 {
229 GNUNET_CRYPTO_hash (&i, sizeof (i), &key); 227 GNUNET_CRYPTO_hash(&i, sizeof(i), &key);
230 GNUNET_CRYPTO_hash (&key, sizeof (key), &value); 228 GNUNET_CRYPTO_hash(&key, sizeof(key), &value);
231 GNUNET_DHT_put (hs[i], &key, 10U, 229 GNUNET_DHT_put(hs[i], &key, 10U,
232 GNUNET_DHT_RO_RECORD_ROUTE | 230 GNUNET_DHT_RO_RECORD_ROUTE |
233 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 231 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
234 GNUNET_BLOCK_TYPE_TEST, 232 GNUNET_BLOCK_TYPE_TEST,
235 sizeof (value), &value, 233 sizeof(value), &value,
236 GNUNET_TIME_UNIT_FOREVER_ABS, 234 GNUNET_TIME_UNIT_FOREVER_ABS,
237 NULL, NULL); 235 NULL, NULL);
238 } 236 }
239 put_task = GNUNET_SCHEDULER_add_delayed (PUT_FREQUENCY, 237 put_task = GNUNET_SCHEDULER_add_delayed(PUT_FREQUENCY,
240 &do_puts, hs); 238 &do_puts, hs);
241} 239}
242 240
243 241
@@ -255,22 +253,22 @@ do_puts (void *cls)
255 * @param key Key of the requested data. 253 * @param key Key of the requested data.
256 */ 254 */
257static void 255static void
258monitor_get_cb (void *cls, 256monitor_get_cb(void *cls,
259 enum GNUNET_DHT_RouteOption options, 257 enum GNUNET_DHT_RouteOption options,
260 enum GNUNET_BLOCK_Type type, 258 enum GNUNET_BLOCK_Type type,
261 uint32_t hop_count, 259 uint32_t hop_count,
262 uint32_t desired_replication_level, 260 uint32_t desired_replication_level,
263 unsigned int path_length, 261 unsigned int path_length,
264 const struct GNUNET_PeerIdentity *path, 262 const struct GNUNET_PeerIdentity *path,
265 const struct GNUNET_HashCode * key) 263 const struct GNUNET_HashCode * key)
266{ 264{
267 unsigned int i; 265 unsigned int i;
268 266
269 i = (unsigned int) (long) cls; 267 i = (unsigned int)(long)cls;
270 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 268 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
271 "%u got a GET message for key %s\n", 269 "%u got a GET message for key %s\n",
272 i, 270 i,
273 GNUNET_h2s (key)); 271 GNUNET_h2s(key));
274 monitor_counter++; 272 monitor_counter++;
275} 273}
276 274
@@ -292,26 +290,26 @@ monitor_get_cb (void *cls,
292 * @param size Number of bytes in data. 290 * @param size Number of bytes in data.
293 */ 291 */
294static void 292static void
295monitor_put_cb (void *cls, 293monitor_put_cb(void *cls,
296 enum GNUNET_DHT_RouteOption options, 294 enum GNUNET_DHT_RouteOption options,
297 enum GNUNET_BLOCK_Type type, 295 enum GNUNET_BLOCK_Type type,
298 uint32_t hop_count, 296 uint32_t hop_count,
299 uint32_t desired_replication_level, 297 uint32_t desired_replication_level,
300 unsigned int path_length, 298 unsigned int path_length,
301 const struct GNUNET_PeerIdentity *path, 299 const struct GNUNET_PeerIdentity *path,
302 struct GNUNET_TIME_Absolute exp, 300 struct GNUNET_TIME_Absolute exp,
303 const struct GNUNET_HashCode * key, 301 const struct GNUNET_HashCode * key,
304 const void *data, 302 const void *data,
305 size_t size) 303 size_t size)
306{ 304{
307 unsigned int i; 305 unsigned int i;
308 306
309 i = (unsigned int) (long) cls; 307 i = (unsigned int)(long)cls;
310 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 308 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
311 "%u got a PUT message for key %s with %u bytes\n", 309 "%u got a PUT message for key %s with %u bytes\n",
312 i, 310 i,
313 GNUNET_h2s (key), 311 GNUNET_h2s(key),
314 (unsigned int) size); 312 (unsigned int)size);
315 monitor_counter++; 313 monitor_counter++;
316} 314}
317 315
@@ -332,25 +330,25 @@ monitor_put_cb (void *cls,
332 * @param size Number of bytes in data. 330 * @param size Number of bytes in data.
333 */ 331 */
334static void 332static void
335monitor_res_cb (void *cls, 333monitor_res_cb(void *cls,
336 enum GNUNET_BLOCK_Type type, 334 enum GNUNET_BLOCK_Type type,
337 const struct GNUNET_PeerIdentity *get_path, 335 const struct GNUNET_PeerIdentity *get_path,
338 unsigned int get_path_length, 336 unsigned int get_path_length,
339 const struct GNUNET_PeerIdentity *put_path, 337 const struct GNUNET_PeerIdentity *put_path,
340 unsigned int put_path_length, 338 unsigned int put_path_length,
341 struct GNUNET_TIME_Absolute exp, 339 struct GNUNET_TIME_Absolute exp,
342 const struct GNUNET_HashCode * key, 340 const struct GNUNET_HashCode * key,
343 const void *data, 341 const void *data,
344 size_t size) 342 size_t size)
345{ 343{
346 unsigned int i; 344 unsigned int i;
347 345
348 i = (unsigned int) (long) cls; 346 i = (unsigned int)(long)cls;
349 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 347 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
350 "%u got a REPLY message for key %s with %u bytes\n", 348 "%u got a REPLY message for key %s with %u bytes\n",
351 i, 349 i,
352 GNUNET_h2s (key), 350 GNUNET_h2s(key),
353 (unsigned int) size); 351 (unsigned int)size);
354 monitor_counter++; 352 monitor_counter++;
355} 353}
356 354
@@ -365,56 +363,56 @@ monitor_res_cb (void *cls,
365 * @param dhts handle to each of the DHTs of the peers 363 * @param dhts handle to each of the DHTs of the peers
366 */ 364 */
367static void 365static void
368run (void *cls, 366run(void *cls,
369 struct GNUNET_DHT_TEST_Context *ctx, 367 struct GNUNET_DHT_TEST_Context *ctx,
370 unsigned int num_peers, 368 unsigned int num_peers,
371 struct GNUNET_TESTBED_Peer **peers, 369 struct GNUNET_TESTBED_Peer **peers,
372 struct GNUNET_DHT_Handle **dhts) 370 struct GNUNET_DHT_Handle **dhts)
373{ 371{
374 unsigned int i; 372 unsigned int i;
375 unsigned int j; 373 unsigned int j;
376 struct GNUNET_HashCode key; 374 struct GNUNET_HashCode key;
377 struct GetOperation *get_op; 375 struct GetOperation *get_op;
378 376
379 GNUNET_assert (NUM_PEERS == num_peers); 377 GNUNET_assert(NUM_PEERS == num_peers);
380 my_peers = peers; 378 my_peers = peers;
381 monitors = GNUNET_new_array (num_peers, 379 monitors = GNUNET_new_array(num_peers,
382 struct GNUNET_DHT_MonitorHandle *); 380 struct GNUNET_DHT_MonitorHandle *);
381 for (i = 0; i < num_peers; i++)
382 monitors[i] = GNUNET_DHT_monitor_start(dhts[i],
383 GNUNET_BLOCK_TYPE_ANY,
384 NULL,
385 &monitor_get_cb,
386 &monitor_res_cb,
387 &monitor_put_cb,
388 (void *)(long)i);
389 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
390 "Peers setup, starting test\n");
391 put_task = GNUNET_SCHEDULER_add_now(&do_puts, dhts);
383 for (i = 0; i < num_peers; i++) 392 for (i = 0; i < num_peers; i++)
384 monitors[i] = GNUNET_DHT_monitor_start (dhts[i],
385 GNUNET_BLOCK_TYPE_ANY,
386 NULL,
387 &monitor_get_cb,
388 &monitor_res_cb,
389 &monitor_put_cb,
390 (void *)(long)i);
391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
392 "Peers setup, starting test\n");
393 put_task = GNUNET_SCHEDULER_add_now (&do_puts, dhts);
394 for (i=0;i<num_peers;i++)
395 {
396 GNUNET_CRYPTO_hash (&i, sizeof (i), &key);
397 for (j=0;j<num_peers;j++)
398 { 393 {
399 get_op = GNUNET_new (struct GetOperation); 394 GNUNET_CRYPTO_hash(&i, sizeof(i), &key);
400 GNUNET_CONTAINER_DLL_insert (get_head, 395 for (j = 0; j < num_peers; j++)
401 get_tail, 396 {
402 get_op); 397 get_op = GNUNET_new(struct GetOperation);
403 get_op->get = GNUNET_DHT_get_start (dhts[j], 398 GNUNET_CONTAINER_DLL_insert(get_head,
404 GNUNET_BLOCK_TYPE_TEST, /* type */ 399 get_tail,
405 &key, /*key to search */ 400 get_op);
406 4U, /* replication level */ 401 get_op->get = GNUNET_DHT_get_start(dhts[j],
407 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 402 GNUNET_BLOCK_TYPE_TEST, /* type */
408 NULL, /* xquery */ 403 &key, /*key to search */
409 0, /* xquery bits */ 404 4U, /* replication level */
410 &dht_get_handler, get_op); 405 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
406 NULL, /* xquery */
407 0, /* xquery bits */
408 &dht_get_handler, get_op);
409 }
411 } 410 }
412 } 411 timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
413 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 412 &timeout_task_cb,
414 &timeout_task_cb, 413 NULL);
415 NULL); 414 GNUNET_SCHEDULER_add_shutdown(&shutdown_task,
416 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 415 ctx);
417 ctx);
418} 416}
419 417
420 418
@@ -422,12 +420,12 @@ run (void *cls,
422 * Main: start test 420 * Main: start test
423 */ 421 */
424int 422int
425main (int xargc, char *xargv[]) 423main(int xargc, char *xargv[])
426{ 424{
427 GNUNET_DHT_TEST_run ("test-dht-monitor", 425 GNUNET_DHT_TEST_run("test-dht-monitor",
428 "test_dht_monitor.conf", 426 "test_dht_monitor.conf",
429 NUM_PEERS, 427 NUM_PEERS,
430 &run, NULL); 428 &run, NULL);
431 return ok; 429 return ok;
432} 430}
433 431
diff --git a/src/dht/test_dht_topo.c b/src/dht/test_dht_topo.c
index a0d80e52c..32d99152d 100644
--- a/src/dht/test_dht_topo.c
+++ b/src/dht/test_dht_topo.c
@@ -11,12 +11,12 @@
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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file dht/test_dht_topo.c 21 * @file dht/test_dht_topo.c
22 * @author Christian Grothoff 22 * @author Christian Grothoff
@@ -32,19 +32,18 @@
32/** 32/**
33 * How long until we give up on fetching the data? 33 * How long until we give up on fetching the data?
34 */ 34 */
35#define GET_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) 35#define GET_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120)
36 36
37/** 37/**
38 * How frequently do we execute the PUTs? 38 * How frequently do we execute the PUTs?
39 */ 39 */
40#define PUT_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) 40#define PUT_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5)
41 41
42 42
43/** 43/**
44 * Information we keep for each GET operation. 44 * Information we keep for each GET operation.
45 */ 45 */
46struct GetOperation 46struct GetOperation {
47{
48 /** 47 /**
49 * DLL. 48 * DLL.
50 */ 49 */
@@ -59,7 +58,6 @@ struct GetOperation
59 * Handle for the operation. 58 * Handle for the operation.
60 */ 59 */
61 struct GNUNET_DHT_GetHandle *get; 60 struct GNUNET_DHT_GetHandle *get;
62
63}; 61};
64 62
65 63
@@ -107,80 +105,79 @@ static unsigned int NUM_PEERS;
107/** 105/**
108 * Statistics we print out. 106 * Statistics we print out.
109 */ 107 */
110static struct 108static struct {
111{
112 const char *subsystem; 109 const char *subsystem;
113 const char *name; 110 const char *name;
114 unsigned long long total; 111 unsigned long long total;
115} stats[] = { 112} stats[] = {
116 {"core", "# bytes decrypted", 0}, 113 { "core", "# bytes decrypted", 0 },
117 {"core", "# bytes encrypted", 0}, 114 { "core", "# bytes encrypted", 0 },
118 {"core", "# type maps received", 0}, 115 { "core", "# type maps received", 0 },
119 {"core", "# session keys confirmed via PONG", 0}, 116 { "core", "# session keys confirmed via PONG", 0 },
120 {"core", "# peers connected", 0}, 117 { "core", "# peers connected", 0 },
121 {"core", "# key exchanges initiated", 0}, 118 { "core", "# key exchanges initiated", 0 },
122 {"core", "# send requests dropped (disconnected)", 0}, 119 { "core", "# send requests dropped (disconnected)", 0 },
123 {"core", "# transmissions delayed due to corking", 0}, 120 { "core", "# transmissions delayed due to corking", 0 },
124 {"core", "# messages discarded (expired prior to transmission)", 0}, 121 { "core", "# messages discarded (expired prior to transmission)", 0 },
125 {"core", "# messages discarded (disconnected)", 0}, 122 { "core", "# messages discarded (disconnected)", 0 },
126 {"core", "# discarded CORE_SEND requests", 0}, 123 { "core", "# discarded CORE_SEND requests", 0 },
127 {"core", "# discarded lower priority CORE_SEND requests", 0}, 124 { "core", "# discarded lower priority CORE_SEND requests", 0 },
128 {"transport", "# bytes received via TCP", 0}, 125 { "transport", "# bytes received via TCP", 0 },
129 {"transport", "# bytes transmitted via TCP", 0}, 126 { "transport", "# bytes transmitted via TCP", 0 },
130 {"dht", "# PUT messages queued for transmission", 0}, 127 { "dht", "# PUT messages queued for transmission", 0 },
131 {"dht", "# P2P PUT requests received", 0}, 128 { "dht", "# P2P PUT requests received", 0 },
132 {"dht", "# GET messages queued for transmission", 0}, 129 { "dht", "# GET messages queued for transmission", 0 },
133 {"dht", "# P2P GET requests received", 0}, 130 { "dht", "# P2P GET requests received", 0 },
134 {"dht", "# RESULT messages queued for transmission", 0}, 131 { "dht", "# RESULT messages queued for transmission", 0 },
135 {"dht", "# P2P RESULTS received", 0}, 132 { "dht", "# P2P RESULTS received", 0 },
136 {"dht", "# Queued messages discarded (peer disconnected)", 0}, 133 { "dht", "# Queued messages discarded (peer disconnected)", 0 },
137 {"dht", "# Peers excluded from routing due to Bloomfilter", 0}, 134 { "dht", "# Peers excluded from routing due to Bloomfilter", 0 },
138 {"dht", "# Peer selection failed", 0}, 135 { "dht", "# Peer selection failed", 0 },
139 {"dht", "# FIND PEER requests ignored due to Bloomfilter", 0}, 136 { "dht", "# FIND PEER requests ignored due to Bloomfilter", 0 },
140 {"dht", "# FIND PEER requests ignored due to lack of HELLO", 0}, 137 { "dht", "# FIND PEER requests ignored due to lack of HELLO", 0 },
141 {"dht", "# P2P FIND PEER requests processed", 0}, 138 { "dht", "# P2P FIND PEER requests processed", 0 },
142 {"dht", "# P2P GET requests ONLY routed", 0}, 139 { "dht", "# P2P GET requests ONLY routed", 0 },
143 {"dht", "# Preference updates given to core", 0}, 140 { "dht", "# Preference updates given to core", 0 },
144 {"dht", "# REPLIES ignored for CLIENTS (no match)", 0}, 141 { "dht", "# REPLIES ignored for CLIENTS (no match)", 0 },
145 {"dht", "# GET requests from clients injected", 0}, 142 { "dht", "# GET requests from clients injected", 0 },
146 {"dht", "# GET requests received from clients", 0}, 143 { "dht", "# GET requests received from clients", 0 },
147 {"dht", "# GET STOP requests received from clients", 0}, 144 { "dht", "# GET STOP requests received from clients", 0 },
148 {"dht", "# ITEMS stored in datacache", 0}, 145 { "dht", "# ITEMS stored in datacache", 0 },
149 {"dht", "# Good RESULTS found in datacache", 0}, 146 { "dht", "# Good RESULTS found in datacache", 0 },
150 {"dht", "# GET requests given to datacache", 0}, 147 { "dht", "# GET requests given to datacache", 0 },
151 {NULL, NULL, 0} 148 { NULL, NULL, 0 }
152}; 149};
153 150
154 151
155static struct GNUNET_DHT_TEST_Context * 152static struct GNUNET_DHT_TEST_Context *
156stop_ops () 153stop_ops()
157{ 154{
158 struct GetOperation *get_op; 155 struct GetOperation *get_op;
159 struct GNUNET_DHT_TEST_Context *ctx = NULL; 156 struct GNUNET_DHT_TEST_Context *ctx = NULL;
160 157
161 if (NULL != timeout_task) 158 if (NULL != timeout_task)
162 { 159 {
163 ctx = GNUNET_SCHEDULER_cancel (timeout_task); 160 ctx = GNUNET_SCHEDULER_cancel(timeout_task);
164 timeout_task = NULL; 161 timeout_task = NULL;
165 } 162 }
166 if (NULL != put_task) 163 if (NULL != put_task)
167 { 164 {
168 GNUNET_SCHEDULER_cancel (put_task); 165 GNUNET_SCHEDULER_cancel(put_task);
169 put_task = NULL; 166 put_task = NULL;
170 } 167 }
171 if (NULL != get_task) 168 if (NULL != get_task)
172 { 169 {
173 GNUNET_SCHEDULER_cancel (get_task); 170 GNUNET_SCHEDULER_cancel(get_task);
174 get_task = NULL; 171 get_task = NULL;
175 } 172 }
176 while (NULL != (get_op = get_tail)) 173 while (NULL != (get_op = get_tail))
177 { 174 {
178 GNUNET_DHT_get_stop (get_op->get); 175 GNUNET_DHT_get_stop(get_op->get);
179 GNUNET_CONTAINER_DLL_remove (get_head, 176 GNUNET_CONTAINER_DLL_remove(get_head,
180 get_tail, 177 get_tail,
181 get_op); 178 get_op);
182 GNUNET_free (get_op); 179 GNUNET_free(get_op);
183 } 180 }
184 return ctx; 181 return ctx;
185} 182}
186 183
@@ -193,32 +190,32 @@ stop_ops ()
193 * @param emsg error message on failure 190 * @param emsg error message on failure
194 */ 191 */
195static void 192static void
196stats_finished (void *cls, 193stats_finished(void *cls,
197 struct GNUNET_TESTBED_Operation *op, 194 struct GNUNET_TESTBED_Operation *op,
198 const char *emsg) 195 const char *emsg)
199{ 196{
200 struct GNUNET_DHT_TEST_Context *ctx = cls; 197 struct GNUNET_DHT_TEST_Context *ctx = cls;
201 unsigned int i; 198 unsigned int i;
202 199
203 if (NULL != op) 200 if (NULL != op)
204 GNUNET_TESTBED_operation_done (op); 201 GNUNET_TESTBED_operation_done(op);
205 if (NULL != emsg) 202 if (NULL != emsg)
206 { 203 {
207 fprintf (stderr, 204 fprintf(stderr,
208 _("Gathering statistics failed: %s\n"), 205 _("Gathering statistics failed: %s\n"),
209 emsg); 206 emsg);
210 GNUNET_SCHEDULER_cancel (put_task); 207 GNUNET_SCHEDULER_cancel(put_task);
211 GNUNET_DHT_TEST_cleanup (ctx); 208 GNUNET_DHT_TEST_cleanup(ctx);
212 return; 209 return;
213 } 210 }
214 for (i = 0; NULL != stats[i].name; i++) 211 for (i = 0; NULL != stats[i].name; i++)
215 fprintf (stderr, 212 fprintf(stderr,
216 "%6s/%60s = %12llu\n", 213 "%6s/%60s = %12llu\n",
217 stats[i].subsystem, 214 stats[i].subsystem,
218 stats[i].name, 215 stats[i].name,
219 stats[i].total); 216 stats[i].total);
220 GNUNET_DHT_TEST_cleanup (ctx); 217 GNUNET_DHT_TEST_cleanup(ctx);
221 GNUNET_SCHEDULER_shutdown (); 218 GNUNET_SCHEDULER_shutdown();
222} 219}
223 220
224 221
@@ -234,20 +231,20 @@ stats_finished (void *cls,
234 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration 231 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
235 */ 232 */
236static int 233static int
237handle_stats (void *cls, 234handle_stats(void *cls,
238 const struct GNUNET_TESTBED_Peer *peer, 235 const struct GNUNET_TESTBED_Peer *peer,
239 const char *subsystem, 236 const char *subsystem,
240 const char *name, 237 const char *name,
241 uint64_t value, 238 uint64_t value,
242 int is_persistent) 239 int is_persistent)
243{ 240{
244 unsigned int i; 241 unsigned int i;
245 242
246 for (i = 0; NULL != stats[i].name; i++) 243 for (i = 0; NULL != stats[i].name; i++)
247 if ( (0 == strcasecmp (subsystem, 244 if ((0 == strcasecmp(subsystem,
248 stats[i].subsystem)) && 245 stats[i].subsystem)) &&
249 (0 == strcasecmp (name, 246 (0 == strcasecmp(name,
250 stats[i].name)) ) 247 stats[i].name)))
251 stats[i].total += value; 248 stats[i].total += value;
252 return GNUNET_OK; 249 return GNUNET_OK;
253} 250}
@@ -260,9 +257,9 @@ handle_stats (void *cls,
260 * @param cls the 'struct GNUNET_DHT_TestContext' 257 * @param cls the 'struct GNUNET_DHT_TestContext'
261 */ 258 */
262static void 259static void
263shutdown_task (void *cls) 260shutdown_task(void *cls)
264{ 261{
265 (void) stop_ops (); 262 (void)stop_ops();
266} 263}
267 264
268 265
@@ -273,12 +270,12 @@ shutdown_task (void *cls)
273 * @param cls the `struct GNUNET_DHT_TestContext` 270 * @param cls the `struct GNUNET_DHT_TestContext`
274 */ 271 */
275static void 272static void
276timeout_cb (void *cls) 273timeout_cb(void *cls)
277{ 274{
278 timeout_task = NULL; 275 timeout_task = NULL;
279 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 276 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
280 "Timeout\n"); 277 "Timeout\n");
281 GNUNET_SCHEDULER_shutdown (); 278 GNUNET_SCHEDULER_shutdown();
282} 279}
283 280
284 281
@@ -298,75 +295,75 @@ timeout_cb (void *cls)
298 * @param data pointer to the result data 295 * @param data pointer to the result data
299 */ 296 */
300static void 297static void
301dht_get_handler (void *cls, 298dht_get_handler(void *cls,
302 struct GNUNET_TIME_Absolute exp, 299 struct GNUNET_TIME_Absolute exp,
303 const struct GNUNET_HashCode *key, 300 const struct GNUNET_HashCode *key,
304 const struct GNUNET_PeerIdentity *get_path, 301 const struct GNUNET_PeerIdentity *get_path,
305 unsigned int get_path_length, 302 unsigned int get_path_length,
306 const struct GNUNET_PeerIdentity *put_path, 303 const struct GNUNET_PeerIdentity *put_path,
307 unsigned int put_path_length, 304 unsigned int put_path_length,
308 enum GNUNET_BLOCK_Type type, 305 enum GNUNET_BLOCK_Type type,
309 size_t size, 306 size_t size,
310 const void *data) 307 const void *data)
311{ 308{
312 struct GetOperation *get_op = cls; 309 struct GetOperation *get_op = cls;
313 struct GNUNET_HashCode want; 310 struct GNUNET_HashCode want;
314 struct GNUNET_DHT_TEST_Context *ctx; 311 struct GNUNET_DHT_TEST_Context *ctx;
315 312
316 if (sizeof (struct GNUNET_HashCode) != size) 313 if (sizeof(struct GNUNET_HashCode) != size)
317 { 314 {
318 GNUNET_break (0); 315 GNUNET_break(0);
319 return; 316 return;
320 } 317 }
321 GNUNET_CRYPTO_hash (key, 318 GNUNET_CRYPTO_hash(key,
322 sizeof (*key), 319 sizeof(*key),
323 &want); 320 &want);
324 if (0 != memcmp (&want, 321 if (0 != memcmp(&want,
325 data, 322 data,
326 sizeof (want))) 323 sizeof(want)))
327 { 324 {
328 GNUNET_break (0); 325 GNUNET_break(0);
329 return; 326 return;
330 } 327 }
331 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 328 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
332 "Get successful\n"); 329 "Get successful\n");
333#if 0 330#if 0
334 { 331 {
335 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 332 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
336 "PATH: (get %u, put %u)\n", 333 "PATH: (get %u, put %u)\n",
337 get_path_length, 334 get_path_length,
338 put_path_length); 335 put_path_length);
339 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 336 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
340 " LOCAL\n"); 337 " LOCAL\n");
341 for (int i = get_path_length - 1; i >= 0; i--) 338 for (int i = get_path_length - 1; i >= 0; i--)
342 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 339 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
343 " %s\n", 340 " %s\n",
344 GNUNET_i2s (&get_path[i])); 341 GNUNET_i2s(&get_path[i]));
345 for (int i = put_path_length - 1; i >= 0; i--) 342 for (int i = put_path_length - 1; i >= 0; i--)
346 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 343 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
347 " %s\n", 344 " %s\n",
348 GNUNET_i2s (&put_path[i])); 345 GNUNET_i2s(&put_path[i]));
349 } 346 }
350#endif 347#endif
351 GNUNET_DHT_get_stop (get_op->get); 348 GNUNET_DHT_get_stop(get_op->get);
352 GNUNET_CONTAINER_DLL_remove (get_head, 349 GNUNET_CONTAINER_DLL_remove(get_head,
353 get_tail, 350 get_tail,
354 get_op); 351 get_op);
355 GNUNET_free (get_op); 352 GNUNET_free(get_op);
356 if (NULL != get_head) 353 if (NULL != get_head)
357 return; 354 return;
358 /* all DHT GET operations successful; get stats! */ 355 /* all DHT GET operations successful; get stats! */
359 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 356 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
360 "All DHT operations successful. Obtaining stats!\n"); 357 "All DHT operations successful. Obtaining stats!\n");
361 ok = 0; 358 ok = 0;
362 ctx = stop_ops (); 359 ctx = stop_ops();
363 GNUNET_assert (NULL != ctx); 360 GNUNET_assert(NULL != ctx);
364 (void) GNUNET_TESTBED_get_statistics (NUM_PEERS, 361 (void)GNUNET_TESTBED_get_statistics(NUM_PEERS,
365 my_peers, 362 my_peers,
366 NULL, NULL, 363 NULL, NULL,
367 &handle_stats, 364 &handle_stats,
368 &stats_finished, 365 &stats_finished,
369 ctx); 366 ctx);
370} 367}
371 368
372 369
@@ -377,38 +374,38 @@ dht_get_handler (void *cls,
377 * @param tc Task context 374 * @param tc Task context
378 */ 375 */
379static void 376static void
380do_puts (void *cls) 377do_puts(void *cls)
381{ 378{
382 struct GNUNET_DHT_Handle **hs = cls; 379 struct GNUNET_DHT_Handle **hs = cls;
383 struct GNUNET_HashCode key; 380 struct GNUNET_HashCode key;
384 struct GNUNET_HashCode value; 381 struct GNUNET_HashCode value;
385 382
386 put_task = NULL; 383 put_task = NULL;
387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 384 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
388 "Putting values into DHT\n"); 385 "Putting values into DHT\n");
389 for (unsigned int i = 0; i < NUM_PEERS; i++) 386 for (unsigned int i = 0; i < NUM_PEERS; i++)
390 { 387 {
391 GNUNET_CRYPTO_hash (&i, 388 GNUNET_CRYPTO_hash(&i,
392 sizeof (i), 389 sizeof(i),
393 &key); 390 &key);
394 GNUNET_CRYPTO_hash (&key, 391 GNUNET_CRYPTO_hash(&key,
395 sizeof (key), 392 sizeof(key),
396 &value); 393 &value);
397 GNUNET_DHT_put (hs[i], 394 GNUNET_DHT_put(hs[i],
398 &key, 395 &key,
399 10U, 396 10U,
400 GNUNET_DHT_RO_RECORD_ROUTE | 397 GNUNET_DHT_RO_RECORD_ROUTE |
401 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 398 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
402 GNUNET_BLOCK_TYPE_TEST, 399 GNUNET_BLOCK_TYPE_TEST,
403 sizeof (value), 400 sizeof(value),
404 &value, 401 &value,
405 GNUNET_TIME_UNIT_FOREVER_ABS, 402 GNUNET_TIME_UNIT_FOREVER_ABS,
406 NULL, 403 NULL,
407 NULL); 404 NULL);
408 } 405 }
409 put_task = GNUNET_SCHEDULER_add_delayed (PUT_FREQUENCY, 406 put_task = GNUNET_SCHEDULER_add_delayed(PUT_FREQUENCY,
410 &do_puts, 407 &do_puts,
411 hs); 408 hs);
412} 409}
413 410
414 411
@@ -416,7 +413,7 @@ do_puts (void *cls)
416 * Start GET operations. 413 * Start GET operations.
417 */ 414 */
418static void 415static void
419start_get (void *cls) 416start_get(void *cls)
420{ 417{
421 struct GNUNET_DHT_Handle **dhts = cls; 418 struct GNUNET_DHT_Handle **dhts = cls;
422 unsigned int i; 419 unsigned int i;
@@ -425,26 +422,26 @@ start_get (void *cls)
425 struct GetOperation *get_op; 422 struct GetOperation *get_op;
426 423
427 get_task = NULL; 424 get_task = NULL;
428 for (i=0;i<NUM_PEERS;i++) 425 for (i = 0; i < NUM_PEERS; i++)
429 {
430 GNUNET_CRYPTO_hash (&i, sizeof (i), &key);
431 for (j=0;j<NUM_PEERS;j++)
432 { 426 {
433 get_op = GNUNET_new (struct GetOperation); 427 GNUNET_CRYPTO_hash(&i, sizeof(i), &key);
434 GNUNET_CONTAINER_DLL_insert (get_head, 428 for (j = 0; j < NUM_PEERS; j++)
435 get_tail, 429 {
436 get_op); 430 get_op = GNUNET_new(struct GetOperation);
437 get_op->get = GNUNET_DHT_get_start (dhts[j], 431 GNUNET_CONTAINER_DLL_insert(get_head,
438 GNUNET_BLOCK_TYPE_TEST, /* type */ 432 get_tail,
439 &key, /*key to search */ 433 get_op);
440 4U, /* replication level */ 434 get_op->get = GNUNET_DHT_get_start(dhts[j],
441 GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 435 GNUNET_BLOCK_TYPE_TEST, /* type */
442 NULL, /* xquery */ 436 &key, /*key to search */
443 0, /* xquery bits */ 437 4U, /* replication level */
444 &dht_get_handler, 438 GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
445 get_op); 439 NULL, /* xquery */
440 0, /* xquery bits */
441 &dht_get_handler,
442 get_op);
443 }
446 } 444 }
447 }
448} 445}
449 446
450 447
@@ -458,26 +455,26 @@ start_get (void *cls)
458 * @param dhts handle to each of the DHTs of the peers 455 * @param dhts handle to each of the DHTs of the peers
459 */ 456 */
460static void 457static void
461run (void *cls, 458run(void *cls,
462 struct GNUNET_DHT_TEST_Context *ctx, 459 struct GNUNET_DHT_TEST_Context *ctx,
463 unsigned int num_peers, 460 unsigned int num_peers,
464 struct GNUNET_TESTBED_Peer **peers, 461 struct GNUNET_TESTBED_Peer **peers,
465 struct GNUNET_DHT_Handle **dhts) 462 struct GNUNET_DHT_Handle **dhts)
466{ 463{
467 GNUNET_assert (NUM_PEERS == num_peers); 464 GNUNET_assert(NUM_PEERS == num_peers);
468 my_peers = peers; 465 my_peers = peers;
469 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 466 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
470 "Peers setup, starting test\n"); 467 "Peers setup, starting test\n");
471 put_task = GNUNET_SCHEDULER_add_now (&do_puts, 468 put_task = GNUNET_SCHEDULER_add_now(&do_puts,
472 dhts); 469 dhts);
473 get_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 470 get_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
474 &start_get, 471 &start_get,
475 dhts); 472 dhts);
476 timeout_task = GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, 473 timeout_task = GNUNET_SCHEDULER_add_delayed(GET_TIMEOUT,
477 &timeout_cb, 474 &timeout_cb,
478 ctx); 475 ctx);
479 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 476 GNUNET_SCHEDULER_add_shutdown(&shutdown_task,
480 ctx); 477 ctx);
481} 478}
482 479
483 480
@@ -485,44 +482,44 @@ run (void *cls,
485 * Main: start test 482 * Main: start test
486 */ 483 */
487int 484int
488main (int xargc, char *xargv[]) 485main(int xargc, char *xargv[])
489{ 486{
490 const char *cfg_filename; 487 const char *cfg_filename;
491 const char *test_name; 488 const char *test_name;
492 489
493 if (NULL != strstr (xargv[0], "test_dht_2dtorus")) 490 if (NULL != strstr(xargv[0], "test_dht_2dtorus"))
494 { 491 {
495 cfg_filename = "test_dht_2dtorus.conf"; 492 cfg_filename = "test_dht_2dtorus.conf";
496 test_name = "test-dht-2dtorus"; 493 test_name = "test-dht-2dtorus";
497 NUM_PEERS = 16; 494 NUM_PEERS = 16;
498 } 495 }
499 else if (NULL != strstr (xargv[0], "test_dht_line")) 496 else if (NULL != strstr(xargv[0], "test_dht_line"))
500 { 497 {
501 cfg_filename = "test_dht_line.conf"; 498 cfg_filename = "test_dht_line.conf";
502 test_name = "test-dht-line"; 499 test_name = "test-dht-line";
503 NUM_PEERS = 5; 500 NUM_PEERS = 5;
504 } 501 }
505 else if (NULL != strstr (xargv[0], "test_dht_twopeer")) 502 else if (NULL != strstr(xargv[0], "test_dht_twopeer"))
506 { 503 {
507 cfg_filename = "test_dht_line.conf"; 504 cfg_filename = "test_dht_line.conf";
508 test_name = "test-dht-twopeer"; 505 test_name = "test-dht-twopeer";
509 NUM_PEERS = 2; 506 NUM_PEERS = 2;
510 } 507 }
511 else if (NULL != strstr (xargv[0], "test_dht_multipeer")) 508 else if (NULL != strstr(xargv[0], "test_dht_multipeer"))
512 { 509 {
513 cfg_filename = "test_dht_multipeer.conf"; 510 cfg_filename = "test_dht_multipeer.conf";
514 test_name = "test-dht-multipeer"; 511 test_name = "test-dht-multipeer";
515 NUM_PEERS = 10; 512 NUM_PEERS = 10;
516 } 513 }
517 else 514 else
518 { 515 {
519 GNUNET_break (0); 516 GNUNET_break(0);
520 return 1; 517 return 1;
521 } 518 }
522 GNUNET_DHT_TEST_run (test_name, 519 GNUNET_DHT_TEST_run(test_name,
523 cfg_filename, 520 cfg_filename,
524 NUM_PEERS, 521 NUM_PEERS,
525 &run, NULL); 522 &run, NULL);
526 return ok; 523 return ok;
527} 524}
528 525