diff options
Diffstat (limited to 'src/dht')
25 files changed, 4455 insertions, 4354 deletions
diff --git a/src/dht/dht.h b/src/dht/dht.h index 3d5fc0963..052a60b99 100644 --- a/src/dht/dht.h +++ b/src/dht/dht.h | |||
@@ -40,7 +40,8 @@ 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 | */ |
43 | struct GNUNET_DHT_ClientGetStopMessage { | 43 | struct GNUNET_DHT_ClientGetStopMessage |
44 | { | ||
44 | /** | 45 | /** |
45 | * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP | 46 | * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP |
46 | */ | 47 | */ |
@@ -67,7 +68,8 @@ struct GNUNET_DHT_ClientGetStopMessage { | |||
67 | * DHT GET message sent from clients to service. Indicates that a GET | 68 | * DHT GET message sent from clients to service. Indicates that a GET |
68 | * request should be issued. | 69 | * request should be issued. |
69 | */ | 70 | */ |
70 | struct GNUNET_DHT_ClientGetMessage { | 71 | struct GNUNET_DHT_ClientGetMessage |
72 | { | ||
71 | /** | 73 | /** |
72 | * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET | 74 | * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET |
73 | */ | 75 | */ |
@@ -108,7 +110,8 @@ struct GNUNET_DHT_ClientGetMessage { | |||
108 | * DHT GET RESULTS KNOWN message sent from clients to service. Indicates that a GET | 110 | * DHT GET RESULTS KNOWN message sent from clients to service. Indicates that a GET |
109 | * request should exclude certain results which are already known. | 111 | * request should exclude certain results which are already known. |
110 | */ | 112 | */ |
111 | struct GNUNET_DHT_ClientGetResultSeenMessage { | 113 | struct GNUNET_DHT_ClientGetResultSeenMessage |
114 | { | ||
112 | /** | 115 | /** |
113 | * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN | 116 | * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN |
114 | */ | 117 | */ |
@@ -138,7 +141,8 @@ struct GNUNET_DHT_ClientGetResultSeenMessage { | |||
138 | /** | 141 | /** |
139 | * Reply to a GET send from the service to a client. | 142 | * Reply to a GET send from the service to a client. |
140 | */ | 143 | */ |
141 | struct GNUNET_DHT_ClientResultMessage { | 144 | struct GNUNET_DHT_ClientResultMessage |
145 | { | ||
142 | /** | 146 | /** |
143 | * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT | 147 | * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT |
144 | */ | 148 | */ |
@@ -183,7 +187,8 @@ struct GNUNET_DHT_ClientResultMessage { | |||
183 | /** | 187 | /** |
184 | * Message to insert data into the DHT, sent from clients to DHT service. | 188 | * Message to insert data into the DHT, sent from clients to DHT service. |
185 | */ | 189 | */ |
186 | struct GNUNET_DHT_ClientPutMessage { | 190 | struct GNUNET_DHT_ClientPutMessage |
191 | { | ||
187 | /** | 192 | /** |
188 | * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT | 193 | * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT |
189 | */ | 194 | */ |
@@ -221,7 +226,8 @@ struct GNUNET_DHT_ClientPutMessage { | |||
221 | /** | 226 | /** |
222 | * Message to monitor put requests going through peer, DHT service -> clients. | 227 | * Message to monitor put requests going through peer, DHT service -> clients. |
223 | */ | 228 | */ |
224 | struct GNUNET_DHT_MonitorPutMessage { | 229 | struct GNUNET_DHT_MonitorPutMessage |
230 | { | ||
225 | /** | 231 | /** |
226 | * Type: #GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT | 232 | * Type: #GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT |
227 | */ | 233 | */ |
@@ -272,7 +278,8 @@ struct GNUNET_DHT_MonitorPutMessage { | |||
272 | /** | 278 | /** |
273 | * Message to request monitoring messages, clients -> DHT service. | 279 | * Message to request monitoring messages, clients -> DHT service. |
274 | */ | 280 | */ |
275 | struct GNUNET_DHT_MonitorStartStopMessage { | 281 | struct GNUNET_DHT_MonitorStartStopMessage |
282 | { | ||
276 | /** | 283 | /** |
277 | * Type: #GNUNET_MESSAGE_TYPE_DHT_MONITOR_START or | 284 | * Type: #GNUNET_MESSAGE_TYPE_DHT_MONITOR_START or |
278 | * #GNUNET_MESSAGE_TYPE_DHT_MONITOR_STOP | 285 | * #GNUNET_MESSAGE_TYPE_DHT_MONITOR_STOP |
@@ -314,7 +321,8 @@ struct GNUNET_DHT_MonitorStartStopMessage { | |||
314 | /** | 321 | /** |
315 | * Message to monitor get requests going through peer, DHT service -> clients. | 322 | * Message to monitor get requests going through peer, DHT service -> clients. |
316 | */ | 323 | */ |
317 | struct GNUNET_DHT_MonitorGetMessage { | 324 | struct GNUNET_DHT_MonitorGetMessage |
325 | { | ||
318 | /** | 326 | /** |
319 | * Type: #GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET | 327 | * Type: #GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET |
320 | */ | 328 | */ |
@@ -357,7 +365,8 @@ struct GNUNET_DHT_MonitorGetMessage { | |||
357 | /** | 365 | /** |
358 | * Message to monitor get results going through peer, DHT service -> clients. | 366 | * Message to monitor get results going through peer, DHT service -> clients. |
359 | */ | 367 | */ |
360 | struct GNUNET_DHT_MonitorGetRespMessage { | 368 | struct GNUNET_DHT_MonitorGetRespMessage |
369 | { | ||
361 | /** | 370 | /** |
362 | * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT | 371 | * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT |
363 | */ | 372 | */ |
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c index 516c96479..c6443f102 100644 --- a/src/dht/dht_api.c +++ b/src/dht/dht_api.c | |||
@@ -34,13 +34,14 @@ | |||
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 | */ |
43 | struct GNUNET_DHT_PutHandle { | 43 | struct GNUNET_DHT_PutHandle |
44 | { | ||
44 | /** | 45 | /** |
45 | * Kept in a DLL. | 46 | * Kept in a DLL. |
46 | */ | 47 | */ |
@@ -75,7 +76,8 @@ struct GNUNET_DHT_PutHandle { | |||
75 | /** | 76 | /** |
76 | * Handle to a GET request | 77 | * Handle to a GET request |
77 | */ | 78 | */ |
78 | struct GNUNET_DHT_GetHandle { | 79 | struct GNUNET_DHT_GetHandle |
80 | { | ||
79 | /** | 81 | /** |
80 | * Iterator to call on data receipt | 82 | * Iterator to call on data receipt |
81 | */ | 83 | */ |
@@ -144,7 +146,8 @@ struct GNUNET_DHT_GetHandle { | |||
144 | /** | 146 | /** |
145 | * Handle to a monitoring request. | 147 | * Handle to a monitoring request. |
146 | */ | 148 | */ |
147 | struct GNUNET_DHT_MonitorHandle { | 149 | struct GNUNET_DHT_MonitorHandle |
150 | { | ||
148 | /** | 151 | /** |
149 | * DLL. | 152 | * DLL. |
150 | */ | 153 | */ |
@@ -195,7 +198,8 @@ struct GNUNET_DHT_MonitorHandle { | |||
195 | /** | 198 | /** |
196 | * Connection to the DHT service. | 199 | * Connection to the DHT service. |
197 | */ | 200 | */ |
198 | struct GNUNET_DHT_Handle { | 201 | struct GNUNET_DHT_Handle |
202 | { | ||
199 | /** | 203 | /** |
200 | * Configuration to use. | 204 | * Configuration to use. |
201 | */ | 205 | */ |
@@ -257,7 +261,7 @@ struct GNUNET_DHT_Handle { | |||
257 | * @return #GNUNET_YES on success, #GNUNET_NO on failure. | 261 | * @return #GNUNET_YES on success, #GNUNET_NO on failure. |
258 | */ | 262 | */ |
259 | static int | 263 | static int |
260 | try_connect(struct GNUNET_DHT_Handle *h); | 264 | try_connect (struct GNUNET_DHT_Handle *h); |
261 | 265 | ||
262 | 266 | ||
263 | /** | 267 | /** |
@@ -266,25 +270,25 @@ try_connect(struct GNUNET_DHT_Handle *h); | |||
266 | * @param gh GET to generate messages for. | 270 | * @param gh GET to generate messages for. |
267 | */ | 271 | */ |
268 | static void | 272 | static void |
269 | send_get(struct GNUNET_DHT_GetHandle *gh) | 273 | send_get (struct GNUNET_DHT_GetHandle *gh) |
270 | { | 274 | { |
271 | struct GNUNET_DHT_Handle *h = gh->dht_handle; | 275 | struct GNUNET_DHT_Handle *h = gh->dht_handle; |
272 | struct GNUNET_MQ_Envelope *env; | 276 | struct GNUNET_MQ_Envelope *env; |
273 | struct GNUNET_DHT_ClientGetMessage *get_msg; | 277 | struct GNUNET_DHT_ClientGetMessage *get_msg; |
274 | 278 | ||
275 | env = GNUNET_MQ_msg_extra(get_msg, | 279 | env = GNUNET_MQ_msg_extra (get_msg, |
276 | gh->xquery_size, | 280 | gh->xquery_size, |
277 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET); | 281 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET); |
278 | get_msg->options = htonl((uint32_t)gh->options); | 282 | get_msg->options = htonl ((uint32_t) gh->options); |
279 | get_msg->desired_replication_level = htonl(gh->desired_replication_level); | 283 | get_msg->desired_replication_level = htonl (gh->desired_replication_level); |
280 | get_msg->type = htonl(gh->type); | 284 | get_msg->type = htonl (gh->type); |
281 | get_msg->key = gh->key; | 285 | get_msg->key = gh->key; |
282 | get_msg->unique_id = gh->unique_id; | 286 | get_msg->unique_id = gh->unique_id; |
283 | GNUNET_memcpy(&get_msg[1], | 287 | GNUNET_memcpy (&get_msg[1], |
284 | &gh[1], | 288 | &gh[1], |
285 | gh->xquery_size); | 289 | gh->xquery_size); |
286 | GNUNET_MQ_send(h->mq, | 290 | GNUNET_MQ_send (h->mq, |
287 | env); | 291 | env); |
288 | } | 292 | } |
289 | 293 | ||
290 | 294 | ||
@@ -298,8 +302,8 @@ send_get(struct GNUNET_DHT_GetHandle *gh) | |||
298 | * @param transmission_offset_start at which offset should we start? | 302 | * @param transmission_offset_start at which offset should we start? |
299 | */ | 303 | */ |
300 | static void | 304 | static void |
301 | send_get_known_results(struct GNUNET_DHT_GetHandle *gh, | 305 | send_get_known_results (struct GNUNET_DHT_GetHandle *gh, |
302 | unsigned int transmission_offset_start) | 306 | unsigned int transmission_offset_start) |
303 | { | 307 | { |
304 | struct GNUNET_DHT_Handle *h = gh->dht_handle; | 308 | struct GNUNET_DHT_Handle *h = gh->dht_handle; |
305 | struct GNUNET_MQ_Envelope *env; | 309 | struct GNUNET_MQ_Envelope *env; |
@@ -312,22 +316,22 @@ send_get_known_results(struct GNUNET_DHT_GetHandle *gh, | |||
312 | / sizeof(struct GNUNET_HashCode); | 316 | / sizeof(struct GNUNET_HashCode); |
313 | transmission_offset = transmission_offset_start; | 317 | transmission_offset = transmission_offset_start; |
314 | while (transmission_offset < gh->seen_results_end) | 318 | while (transmission_offset < gh->seen_results_end) |
315 | { | 319 | { |
316 | delta = gh->seen_results_end - transmission_offset; | 320 | delta = gh->seen_results_end - transmission_offset; |
317 | if (delta > max) | 321 | if (delta > max) |
318 | delta = max; | 322 | delta = max; |
319 | env = GNUNET_MQ_msg_extra(msg, | 323 | env = GNUNET_MQ_msg_extra (msg, |
320 | delta * sizeof(struct GNUNET_HashCode), | 324 | delta * sizeof(struct GNUNET_HashCode), |
321 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN); | 325 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN); |
322 | msg->key = gh->key; | 326 | msg->key = gh->key; |
323 | msg->unique_id = gh->unique_id; | 327 | msg->unique_id = gh->unique_id; |
324 | GNUNET_memcpy(&msg[1], | 328 | GNUNET_memcpy (&msg[1], |
325 | &gh->seen_results[transmission_offset], | 329 | &gh->seen_results[transmission_offset], |
326 | sizeof(struct GNUNET_HashCode) * delta); | 330 | sizeof(struct GNUNET_HashCode) * delta); |
327 | GNUNET_MQ_send(h->mq, | 331 | GNUNET_MQ_send (h->mq, |
328 | env); | 332 | env); |
329 | transmission_offset += delta; | 333 | transmission_offset += delta; |
330 | } | 334 | } |
331 | } | 335 | } |
332 | 336 | ||
333 | 337 | ||
@@ -341,19 +345,19 @@ send_get_known_results(struct GNUNET_DHT_GetHandle *gh, | |||
341 | * @return #GNUNET_YES (always) | 345 | * @return #GNUNET_YES (always) |
342 | */ | 346 | */ |
343 | static int | 347 | static int |
344 | add_get_request_to_pending(void *cls, | 348 | add_get_request_to_pending (void *cls, |
345 | const struct GNUNET_HashCode *key, | 349 | const struct GNUNET_HashCode *key, |
346 | void *value) | 350 | void *value) |
347 | { | 351 | { |
348 | struct GNUNET_DHT_Handle *handle = cls; | 352 | struct GNUNET_DHT_Handle *handle = cls; |
349 | struct GNUNET_DHT_GetHandle *gh = value; | 353 | struct GNUNET_DHT_GetHandle *gh = value; |
350 | 354 | ||
351 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 355 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
352 | "Retransmitting request related to %s to DHT %p\n", | 356 | "Retransmitting request related to %s to DHT %p\n", |
353 | GNUNET_h2s(key), | 357 | GNUNET_h2s (key), |
354 | handle); | 358 | handle); |
355 | send_get(gh); | 359 | send_get (gh); |
356 | send_get_known_results(gh, 0); | 360 | send_get_known_results (gh, 0); |
357 | return GNUNET_YES; | 361 | return GNUNET_YES; |
358 | } | 362 | } |
359 | 363 | ||
@@ -364,25 +368,25 @@ add_get_request_to_pending(void *cls, | |||
364 | * @param mh monitor handle to generate start message for | 368 | * @param mh monitor handle to generate start message for |
365 | */ | 369 | */ |
366 | static void | 370 | static void |
367 | send_monitor_start(struct GNUNET_DHT_MonitorHandle *mh) | 371 | send_monitor_start (struct GNUNET_DHT_MonitorHandle *mh) |
368 | { | 372 | { |
369 | struct GNUNET_DHT_Handle *h = mh->dht_handle; | 373 | struct GNUNET_DHT_Handle *h = mh->dht_handle; |
370 | struct GNUNET_MQ_Envelope *env; | 374 | struct GNUNET_MQ_Envelope *env; |
371 | struct GNUNET_DHT_MonitorStartStopMessage *m; | 375 | struct GNUNET_DHT_MonitorStartStopMessage *m; |
372 | 376 | ||
373 | env = GNUNET_MQ_msg(m, | 377 | env = GNUNET_MQ_msg (m, |
374 | GNUNET_MESSAGE_TYPE_DHT_MONITOR_START); | 378 | GNUNET_MESSAGE_TYPE_DHT_MONITOR_START); |
375 | m->type = htonl(mh->type); | 379 | m->type = htonl (mh->type); |
376 | m->get = htons(NULL != mh->get_cb); | 380 | m->get = htons (NULL != mh->get_cb); |
377 | m->get_resp = htons(NULL != mh->get_resp_cb); | 381 | m->get_resp = htons (NULL != mh->get_resp_cb); |
378 | m->put = htons(NULL != mh->put_cb); | 382 | m->put = htons (NULL != mh->put_cb); |
379 | if (NULL != mh->key) | 383 | if (NULL != mh->key) |
380 | { | 384 | { |
381 | m->filter_key = htons(1); | 385 | m->filter_key = htons (1); |
382 | m->key = *mh->key; | 386 | m->key = *mh->key; |
383 | } | 387 | } |
384 | GNUNET_MQ_send(h->mq, | 388 | GNUNET_MQ_send (h->mq, |
385 | env); | 389 | env); |
386 | } | 390 | } |
387 | 391 | ||
388 | 392 | ||
@@ -392,31 +396,31 @@ send_monitor_start(struct GNUNET_DHT_MonitorHandle *mh) | |||
392 | * @param cls a `struct GNUNET_DHT_Handle` | 396 | * @param cls a `struct GNUNET_DHT_Handle` |
393 | */ | 397 | */ |
394 | static void | 398 | static void |
395 | try_reconnect(void *cls) | 399 | try_reconnect (void *cls) |
396 | { | 400 | { |
397 | struct GNUNET_DHT_Handle *h = cls; | 401 | struct GNUNET_DHT_Handle *h = cls; |
398 | struct GNUNET_DHT_MonitorHandle *mh; | 402 | struct GNUNET_DHT_MonitorHandle *mh; |
399 | 403 | ||
400 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 404 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
401 | "Reconnecting with DHT %p\n", | 405 | "Reconnecting with DHT %p\n", |
402 | h); | 406 | h); |
403 | h->retry_time = GNUNET_TIME_STD_BACKOFF(h->retry_time); | 407 | h->retry_time = GNUNET_TIME_STD_BACKOFF (h->retry_time); |
404 | h->reconnect_task = NULL; | 408 | h->reconnect_task = NULL; |
405 | if (GNUNET_YES != try_connect(h)) | 409 | if (GNUNET_YES != try_connect (h)) |
406 | { | 410 | { |
407 | LOG(GNUNET_ERROR_TYPE_WARNING, | 411 | LOG (GNUNET_ERROR_TYPE_WARNING, |
408 | "DHT reconnect failed!\n"); | 412 | "DHT reconnect failed!\n"); |
409 | h->reconnect_task | 413 | h->reconnect_task |
410 | = GNUNET_SCHEDULER_add_delayed(h->retry_time, | 414 | = GNUNET_SCHEDULER_add_delayed (h->retry_time, |
411 | &try_reconnect, | 415 | &try_reconnect, |
412 | h); | 416 | h); |
413 | return; | 417 | return; |
414 | } | 418 | } |
415 | GNUNET_CONTAINER_multihashmap_iterate(h->active_requests, | 419 | GNUNET_CONTAINER_multihashmap_iterate (h->active_requests, |
416 | &add_get_request_to_pending, | 420 | &add_get_request_to_pending, |
417 | h); | 421 | h); |
418 | for (mh = h->monitor_head; NULL != mh; mh = mh->next) | 422 | for (mh = h->monitor_head; NULL != mh; mh = mh->next) |
419 | send_monitor_start(mh); | 423 | send_monitor_start (mh); |
420 | } | 424 | } |
421 | 425 | ||
422 | 426 | ||
@@ -426,7 +430,7 @@ try_reconnect(void *cls) | |||
426 | * @param h handle to dht to (possibly) disconnect and reconnect | 430 | * @param h handle to dht to (possibly) disconnect and reconnect |
427 | */ | 431 | */ |
428 | static void | 432 | static void |
429 | do_disconnect(struct GNUNET_DHT_Handle *h) | 433 | do_disconnect (struct GNUNET_DHT_Handle *h) |
430 | { | 434 | { |
431 | struct GNUNET_DHT_PutHandle *ph; | 435 | struct GNUNET_DHT_PutHandle *ph; |
432 | GNUNET_SCHEDULER_TaskCallback cont; | 436 | GNUNET_SCHEDULER_TaskCallback cont; |
@@ -434,27 +438,27 @@ do_disconnect(struct GNUNET_DHT_Handle *h) | |||
434 | 438 | ||
435 | if (NULL == h->mq) | 439 | if (NULL == h->mq) |
436 | return; | 440 | return; |
437 | GNUNET_MQ_destroy(h->mq); | 441 | GNUNET_MQ_destroy (h->mq); |
438 | h->mq = NULL; | 442 | h->mq = NULL; |
439 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 443 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
440 | "Disconnecting from DHT service, will try to reconnect in %s\n", | 444 | "Disconnecting from DHT service, will try to reconnect in %s\n", |
441 | GNUNET_STRINGS_relative_time_to_string(h->retry_time, | 445 | GNUNET_STRINGS_relative_time_to_string (h->retry_time, |
442 | GNUNET_YES)); | 446 | GNUNET_YES)); |
443 | /* notify client about all PUTs that (may) have failed due to disconnect */ | 447 | /* notify client about all PUTs that (may) have failed due to disconnect */ |
444 | while (NULL != (ph = h->put_head)) | 448 | while (NULL != (ph = h->put_head)) |
445 | { | 449 | { |
446 | cont = ph->cont; | 450 | cont = ph->cont; |
447 | cont_cls = ph->cont_cls; | 451 | cont_cls = ph->cont_cls; |
448 | ph->env = NULL; | 452 | ph->env = NULL; |
449 | GNUNET_DHT_put_cancel(ph); | 453 | GNUNET_DHT_put_cancel (ph); |
450 | if (NULL != cont) | 454 | if (NULL != cont) |
451 | cont(cont_cls); | 455 | cont (cont_cls); |
452 | } | 456 | } |
453 | GNUNET_assert(NULL == h->reconnect_task); | 457 | GNUNET_assert (NULL == h->reconnect_task); |
454 | h->reconnect_task | 458 | h->reconnect_task |
455 | = GNUNET_SCHEDULER_add_delayed(h->retry_time, | 459 | = GNUNET_SCHEDULER_add_delayed (h->retry_time, |
456 | &try_reconnect, | 460 | &try_reconnect, |
457 | h); | 461 | h); |
458 | } | 462 | } |
459 | 463 | ||
460 | 464 | ||
@@ -467,12 +471,12 @@ do_disconnect(struct GNUNET_DHT_Handle *h) | |||
467 | * @param error error code | 471 | * @param error error code |
468 | */ | 472 | */ |
469 | static void | 473 | static void |
470 | mq_error_handler(void *cls, | 474 | mq_error_handler (void *cls, |
471 | enum GNUNET_MQ_Error error) | 475 | enum GNUNET_MQ_Error error) |
472 | { | 476 | { |
473 | struct GNUNET_DHT_Handle *h = cls; | 477 | struct GNUNET_DHT_Handle *h = cls; |
474 | 478 | ||
475 | do_disconnect(h); | 479 | do_disconnect (h); |
476 | } | 480 | } |
477 | 481 | ||
478 | 482 | ||
@@ -485,18 +489,18 @@ mq_error_handler(void *cls, | |||
485 | * #GNUNET_SYSERR if the message is malformed. | 489 | * #GNUNET_SYSERR if the message is malformed. |
486 | */ | 490 | */ |
487 | static int | 491 | static int |
488 | check_monitor_get(void *cls, | 492 | check_monitor_get (void *cls, |
489 | const struct GNUNET_DHT_MonitorGetMessage *msg) | 493 | const struct GNUNET_DHT_MonitorGetMessage *msg) |
490 | { | 494 | { |
491 | uint32_t plen = ntohl(msg->get_path_length); | 495 | uint32_t plen = ntohl (msg->get_path_length); |
492 | uint16_t msize = ntohs(msg->header.size) - sizeof(*msg); | 496 | uint16_t msize = ntohs (msg->header.size) - sizeof(*msg); |
493 | 497 | ||
494 | if ((plen > UINT16_MAX) || | 498 | if ((plen > UINT16_MAX) || |
495 | (plen * sizeof(struct GNUNET_PeerIdentity) != msize)) | 499 | (plen * sizeof(struct GNUNET_PeerIdentity) != msize)) |
496 | { | 500 | { |
497 | GNUNET_break(0); | 501 | GNUNET_break (0); |
498 | return GNUNET_SYSERR; | 502 | return GNUNET_SYSERR; |
499 | } | 503 | } |
500 | return GNUNET_OK; | 504 | return GNUNET_OK; |
501 | } | 505 | } |
502 | 506 | ||
@@ -508,31 +512,31 @@ check_monitor_get(void *cls, | |||
508 | * @param msg Monitor get message from the service. | 512 | * @param msg Monitor get message from the service. |
509 | */ | 513 | */ |
510 | static void | 514 | static void |
511 | handle_monitor_get(void *cls, | 515 | handle_monitor_get (void *cls, |
512 | const struct GNUNET_DHT_MonitorGetMessage *msg) | 516 | const struct GNUNET_DHT_MonitorGetMessage *msg) |
513 | { | 517 | { |
514 | struct GNUNET_DHT_Handle *handle = cls; | 518 | struct GNUNET_DHT_Handle *handle = cls; |
515 | struct GNUNET_DHT_MonitorHandle *mh; | 519 | struct GNUNET_DHT_MonitorHandle *mh; |
516 | 520 | ||
517 | for (mh = handle->monitor_head; NULL != mh; mh = mh->next) | 521 | for (mh = handle->monitor_head; NULL != mh; mh = mh->next) |
518 | { | 522 | { |
519 | if (NULL == mh->get_cb) | 523 | if (NULL == mh->get_cb) |
520 | continue; | 524 | continue; |
521 | if (((GNUNET_BLOCK_TYPE_ANY == mh->type) || | 525 | if (((GNUNET_BLOCK_TYPE_ANY == mh->type) || |
522 | (mh->type == ntohl(msg->type))) && | 526 | (mh->type == ntohl (msg->type))) && |
523 | ((NULL == mh->key) || | 527 | ((NULL == mh->key) || |
524 | (0 == memcmp(mh->key, | 528 | (0 == memcmp (mh->key, |
525 | &msg->key, | 529 | &msg->key, |
526 | sizeof(struct GNUNET_HashCode))))) | 530 | sizeof(struct GNUNET_HashCode))))) |
527 | mh->get_cb(mh->cb_cls, | 531 | mh->get_cb (mh->cb_cls, |
528 | ntohl(msg->options), | 532 | ntohl (msg->options), |
529 | (enum GNUNET_BLOCK_Type)ntohl(msg->type), | 533 | (enum GNUNET_BLOCK_Type) ntohl (msg->type), |
530 | ntohl(msg->hop_count), | 534 | ntohl (msg->hop_count), |
531 | ntohl(msg->desired_replication_level), | 535 | ntohl (msg->desired_replication_level), |
532 | ntohl(msg->get_path_length), | 536 | ntohl (msg->get_path_length), |
533 | (struct GNUNET_PeerIdentity *)&msg[1], | 537 | (struct GNUNET_PeerIdentity *) &msg[1], |
534 | &msg->key); | 538 | &msg->key); |
535 | } | 539 | } |
536 | } | 540 | } |
537 | 541 | ||
538 | 542 | ||
@@ -545,19 +549,19 @@ handle_monitor_get(void *cls, | |||
545 | * #GNUNET_SYSERR if the message is malformed. | 549 | * #GNUNET_SYSERR if the message is malformed. |
546 | */ | 550 | */ |
547 | static int | 551 | static int |
548 | check_monitor_get_resp(void *cls, | 552 | check_monitor_get_resp (void *cls, |
549 | const struct GNUNET_DHT_MonitorGetRespMessage *msg) | 553 | const struct GNUNET_DHT_MonitorGetRespMessage *msg) |
550 | { | 554 | { |
551 | size_t msize = ntohs(msg->header.size) - sizeof(*msg); | 555 | size_t msize = ntohs (msg->header.size) - sizeof(*msg); |
552 | uint32_t getl = ntohl(msg->get_path_length); | 556 | uint32_t getl = ntohl (msg->get_path_length); |
553 | uint32_t putl = ntohl(msg->put_path_length); | 557 | uint32_t putl = ntohl (msg->put_path_length); |
554 | 558 | ||
555 | if ((getl + putl < getl) || | 559 | if ((getl + putl < getl) || |
556 | ((msize / sizeof(struct GNUNET_PeerIdentity)) < getl + putl)) | 560 | ((msize / sizeof(struct GNUNET_PeerIdentity)) < getl + putl)) |
557 | { | 561 | { |
558 | GNUNET_break(0); | 562 | GNUNET_break (0); |
559 | return GNUNET_SYSERR; | 563 | return GNUNET_SYSERR; |
560 | } | 564 | } |
561 | return GNUNET_OK; | 565 | return GNUNET_OK; |
562 | } | 566 | } |
563 | 567 | ||
@@ -569,38 +573,39 @@ check_monitor_get_resp(void *cls, | |||
569 | * @param msg monitor get response message from the service | 573 | * @param msg monitor get response message from the service |
570 | */ | 574 | */ |
571 | static void | 575 | static void |
572 | handle_monitor_get_resp(void *cls, | 576 | handle_monitor_get_resp (void *cls, |
573 | const struct GNUNET_DHT_MonitorGetRespMessage *msg) | 577 | const struct GNUNET_DHT_MonitorGetRespMessage *msg) |
574 | { | 578 | { |
575 | struct GNUNET_DHT_Handle *handle = cls; | 579 | struct GNUNET_DHT_Handle *handle = cls; |
576 | size_t msize = ntohs(msg->header.size) - sizeof(*msg); | 580 | size_t msize = ntohs (msg->header.size) - sizeof(*msg); |
577 | const struct GNUNET_PeerIdentity *path; | 581 | const struct GNUNET_PeerIdentity *path; |
578 | uint32_t getl = ntohl(msg->get_path_length); | 582 | uint32_t getl = ntohl (msg->get_path_length); |
579 | uint32_t putl = ntohl(msg->put_path_length); | 583 | uint32_t putl = ntohl (msg->put_path_length); |
580 | struct GNUNET_DHT_MonitorHandle *mh; | 584 | struct GNUNET_DHT_MonitorHandle *mh; |
581 | 585 | ||
582 | path = (const struct GNUNET_PeerIdentity *)&msg[1]; | 586 | path = (const struct GNUNET_PeerIdentity *) &msg[1]; |
583 | for (mh = handle->monitor_head; NULL != mh; mh = mh->next) | 587 | for (mh = handle->monitor_head; NULL != mh; mh = mh->next) |
584 | { | 588 | { |
585 | if (NULL == mh->get_resp_cb) | 589 | if (NULL == mh->get_resp_cb) |
586 | continue; | 590 | continue; |
587 | if (((GNUNET_BLOCK_TYPE_ANY == mh->type) || | 591 | if (((GNUNET_BLOCK_TYPE_ANY == mh->type) || |
588 | (mh->type == ntohl(msg->type))) && | 592 | (mh->type == ntohl (msg->type))) && |
589 | ((NULL == mh->key) || | 593 | ((NULL == mh->key) || |
590 | (0 == memcmp(mh->key, | 594 | (0 == memcmp (mh->key, |
591 | &msg->key, | 595 | &msg->key, |
592 | sizeof(struct GNUNET_HashCode))))) | 596 | sizeof(struct GNUNET_HashCode))))) |
593 | mh->get_resp_cb(mh->cb_cls, | 597 | mh->get_resp_cb (mh->cb_cls, |
594 | (enum GNUNET_BLOCK_Type)ntohl(msg->type), | 598 | (enum GNUNET_BLOCK_Type) ntohl (msg->type), |
595 | path, | 599 | path, |
596 | getl, | 600 | getl, |
597 | &path[getl], | 601 | &path[getl], |
598 | putl, | 602 | putl, |
599 | GNUNET_TIME_absolute_ntoh(msg->expiration_time), | 603 | GNUNET_TIME_absolute_ntoh (msg->expiration_time), |
600 | &msg->key, | 604 | &msg->key, |
601 | (const void *)&path[getl + putl], | 605 | (const void *) &path[getl + putl], |
602 | msize - sizeof(struct GNUNET_PeerIdentity) * (putl + getl)); | 606 | msize - sizeof(struct GNUNET_PeerIdentity) * (putl |
603 | } | 607 | + getl)); |
608 | } | ||
604 | } | 609 | } |
605 | 610 | ||
606 | 611 | ||
@@ -613,19 +618,19 @@ handle_monitor_get_resp(void *cls, | |||
613 | * #GNUNET_SYSERR if the message is malformed. | 618 | * #GNUNET_SYSERR if the message is malformed. |
614 | */ | 619 | */ |
615 | static int | 620 | static int |
616 | check_monitor_put(void *cls, | 621 | check_monitor_put (void *cls, |
617 | const struct GNUNET_DHT_MonitorPutMessage *msg) | 622 | const struct GNUNET_DHT_MonitorPutMessage *msg) |
618 | { | 623 | { |
619 | size_t msize; | 624 | size_t msize; |
620 | uint32_t putl; | 625 | uint32_t putl; |
621 | 626 | ||
622 | msize = ntohs(msg->header.size) - sizeof(*msg); | 627 | msize = ntohs (msg->header.size) - sizeof(*msg); |
623 | putl = ntohl(msg->put_path_length); | 628 | putl = ntohl (msg->put_path_length); |
624 | if ((msize / sizeof(struct GNUNET_PeerIdentity)) < putl) | 629 | if ((msize / sizeof(struct GNUNET_PeerIdentity)) < putl) |
625 | { | 630 | { |
626 | GNUNET_break(0); | 631 | GNUNET_break (0); |
627 | return GNUNET_SYSERR; | 632 | return GNUNET_SYSERR; |
628 | } | 633 | } |
629 | return GNUNET_OK; | 634 | return GNUNET_OK; |
630 | } | 635 | } |
631 | 636 | ||
@@ -637,38 +642,38 @@ check_monitor_put(void *cls, | |||
637 | * @param msg Monitor put message from the service. | 642 | * @param msg Monitor put message from the service. |
638 | */ | 643 | */ |
639 | static void | 644 | static void |
640 | handle_monitor_put(void *cls, | 645 | handle_monitor_put (void *cls, |
641 | const struct GNUNET_DHT_MonitorPutMessage *msg) | 646 | const struct GNUNET_DHT_MonitorPutMessage *msg) |
642 | { | 647 | { |
643 | struct GNUNET_DHT_Handle *handle = cls; | 648 | struct GNUNET_DHT_Handle *handle = cls; |
644 | size_t msize = ntohs(msg->header.size) - sizeof(*msg); | 649 | size_t msize = ntohs (msg->header.size) - sizeof(*msg); |
645 | uint32_t putl = ntohl(msg->put_path_length); | 650 | uint32_t putl = ntohl (msg->put_path_length); |
646 | const struct GNUNET_PeerIdentity *path; | 651 | const struct GNUNET_PeerIdentity *path; |
647 | struct GNUNET_DHT_MonitorHandle *mh; | 652 | struct GNUNET_DHT_MonitorHandle *mh; |
648 | 653 | ||
649 | path = (const struct GNUNET_PeerIdentity *)&msg[1]; | 654 | path = (const struct GNUNET_PeerIdentity *) &msg[1]; |
650 | for (mh = handle->monitor_head; NULL != mh; mh = mh->next) | 655 | for (mh = handle->monitor_head; NULL != mh; mh = mh->next) |
651 | { | 656 | { |
652 | if (NULL == mh->put_cb) | 657 | if (NULL == mh->put_cb) |
653 | continue; | 658 | continue; |
654 | if (((GNUNET_BLOCK_TYPE_ANY == mh->type) || | 659 | if (((GNUNET_BLOCK_TYPE_ANY == mh->type) || |
655 | (mh->type == ntohl(msg->type))) && | 660 | (mh->type == ntohl (msg->type))) && |
656 | ((NULL == mh->key) || | 661 | ((NULL == mh->key) || |
657 | (0 == memcmp(mh->key, | 662 | (0 == memcmp (mh->key, |
658 | &msg->key, | 663 | &msg->key, |
659 | sizeof(struct GNUNET_HashCode))))) | 664 | sizeof(struct GNUNET_HashCode))))) |
660 | mh->put_cb(mh->cb_cls, | 665 | mh->put_cb (mh->cb_cls, |
661 | ntohl(msg->options), | 666 | ntohl (msg->options), |
662 | (enum GNUNET_BLOCK_Type)ntohl(msg->type), | 667 | (enum GNUNET_BLOCK_Type) ntohl (msg->type), |
663 | ntohl(msg->hop_count), | 668 | ntohl (msg->hop_count), |
664 | ntohl(msg->desired_replication_level), | 669 | ntohl (msg->desired_replication_level), |
665 | putl, | 670 | putl, |
666 | path, | 671 | path, |
667 | GNUNET_TIME_absolute_ntoh(msg->expiration_time), | 672 | GNUNET_TIME_absolute_ntoh (msg->expiration_time), |
668 | &msg->key, | 673 | &msg->key, |
669 | (const void *)&path[putl], | 674 | (const void *) &path[putl], |
670 | msize - sizeof(struct GNUNET_PeerIdentity) * putl); | 675 | msize - sizeof(struct GNUNET_PeerIdentity) * putl); |
671 | } | 676 | } |
672 | } | 677 | } |
673 | 678 | ||
674 | 679 | ||
@@ -681,12 +686,12 @@ handle_monitor_put(void *cls, | |||
681 | * #GNUNET_SYSERR if the message is malformed. | 686 | * #GNUNET_SYSERR if the message is malformed. |
682 | */ | 687 | */ |
683 | static int | 688 | static int |
684 | check_client_result(void *cls, | 689 | check_client_result (void *cls, |
685 | const struct GNUNET_DHT_ClientResultMessage *msg) | 690 | const struct GNUNET_DHT_ClientResultMessage *msg) |
686 | { | 691 | { |
687 | size_t msize = ntohs(msg->header.size) - sizeof(*msg); | 692 | size_t msize = ntohs (msg->header.size) - sizeof(*msg); |
688 | uint32_t put_path_length = ntohl(msg->put_path_length); | 693 | uint32_t put_path_length = ntohl (msg->put_path_length); |
689 | uint32_t get_path_length = ntohl(msg->get_path_length); | 694 | uint32_t get_path_length = ntohl (msg->get_path_length); |
690 | size_t meta_length; | 695 | size_t meta_length; |
691 | 696 | ||
692 | meta_length = | 697 | meta_length = |
@@ -696,10 +701,10 @@ check_client_result(void *cls, | |||
696 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) || | 701 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) || |
697 | (put_path_length > | 702 | (put_path_length > |
698 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity))) | 703 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity))) |
699 | { | 704 | { |
700 | GNUNET_break(0); | 705 | GNUNET_break (0); |
701 | return GNUNET_SYSERR; | 706 | return GNUNET_SYSERR; |
702 | } | 707 | } |
703 | return GNUNET_OK; | 708 | return GNUNET_OK; |
704 | } | 709 | } |
705 | 710 | ||
@@ -713,15 +718,15 @@ check_client_result(void *cls, | |||
713 | * @return #GNUNET_YES to continue to iterate over all results | 718 | * @return #GNUNET_YES to continue to iterate over all results |
714 | */ | 719 | */ |
715 | static int | 720 | static int |
716 | process_client_result(void *cls, | 721 | process_client_result (void *cls, |
717 | const struct GNUNET_HashCode *key, | 722 | const struct GNUNET_HashCode *key, |
718 | void *value) | 723 | void *value) |
719 | { | 724 | { |
720 | const struct GNUNET_DHT_ClientResultMessage *crm = cls; | 725 | const struct GNUNET_DHT_ClientResultMessage *crm = cls; |
721 | struct GNUNET_DHT_GetHandle *get_handle = value; | 726 | struct GNUNET_DHT_GetHandle *get_handle = value; |
722 | size_t msize = ntohs(crm->header.size) - sizeof(*crm); | 727 | size_t msize = ntohs (crm->header.size) - sizeof(*crm); |
723 | uint32_t put_path_length = ntohl(crm->put_path_length); | 728 | uint32_t put_path_length = ntohl (crm->put_path_length); |
724 | uint32_t get_path_length = ntohl(crm->get_path_length); | 729 | uint32_t get_path_length = ntohl (crm->get_path_length); |
725 | const struct GNUNET_PeerIdentity *put_path; | 730 | const struct GNUNET_PeerIdentity *put_path; |
726 | const struct GNUNET_PeerIdentity *get_path; | 731 | const struct GNUNET_PeerIdentity *get_path; |
727 | struct GNUNET_HashCode hc; | 732 | struct GNUNET_HashCode hc; |
@@ -730,59 +735,59 @@ process_client_result(void *cls, | |||
730 | const void *data; | 735 | const void *data; |
731 | 736 | ||
732 | if (crm->unique_id != get_handle->unique_id) | 737 | if (crm->unique_id != get_handle->unique_id) |
733 | { | 738 | { |
734 | /* UID mismatch */ | 739 | /* UID mismatch */ |
735 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 740 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
736 | "Ignoring reply for %s: UID mismatch: %llu/%llu\n", | 741 | "Ignoring reply for %s: UID mismatch: %llu/%llu\n", |
737 | GNUNET_h2s(key), | 742 | GNUNET_h2s (key), |
738 | crm->unique_id, | 743 | crm->unique_id, |
739 | get_handle->unique_id); | 744 | get_handle->unique_id); |
740 | return GNUNET_YES; | 745 | return GNUNET_YES; |
741 | } | 746 | } |
742 | /* FIXME: might want to check that type matches */ | 747 | /* FIXME: might want to check that type matches */ |
743 | meta_length = | 748 | meta_length = |
744 | sizeof(struct GNUNET_PeerIdentity) * (get_path_length + put_path_length); | 749 | sizeof(struct GNUNET_PeerIdentity) * (get_path_length + put_path_length); |
745 | data_length = msize - meta_length; | 750 | data_length = msize - meta_length; |
746 | put_path = (const struct GNUNET_PeerIdentity *)&crm[1]; | 751 | put_path = (const struct GNUNET_PeerIdentity *) &crm[1]; |
747 | get_path = &put_path[put_path_length]; | 752 | get_path = &put_path[put_path_length]; |
748 | { | 753 | { |
749 | char *pp; | 754 | char *pp; |
750 | char *gp; | 755 | char *gp; |
751 | 756 | ||
752 | gp = GNUNET_STRINGS_pp2s(get_path, | 757 | gp = GNUNET_STRINGS_pp2s (get_path, |
753 | get_path_length); | 758 | get_path_length); |
754 | pp = GNUNET_STRINGS_pp2s(put_path, | 759 | pp = GNUNET_STRINGS_pp2s (put_path, |
755 | put_path_length); | 760 | put_path_length); |
756 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 761 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
757 | "Giving %u byte reply for %s to application (GP: %s, PP: %s)\n", | 762 | "Giving %u byte reply for %s to application (GP: %s, PP: %s)\n", |
758 | (unsigned int)data_length, | 763 | (unsigned int) data_length, |
759 | GNUNET_h2s(key), | 764 | GNUNET_h2s (key), |
760 | gp, | 765 | gp, |
761 | pp); | 766 | pp); |
762 | GNUNET_free(gp); | 767 | GNUNET_free (gp); |
763 | GNUNET_free(pp); | 768 | GNUNET_free (pp); |
764 | } | 769 | } |
765 | data = &get_path[get_path_length]; | 770 | data = &get_path[get_path_length]; |
766 | /* remember that we've seen this result */ | 771 | /* remember that we've seen this result */ |
767 | GNUNET_CRYPTO_hash(data, | 772 | GNUNET_CRYPTO_hash (data, |
768 | data_length, | 773 | data_length, |
769 | &hc); | 774 | &hc); |
770 | if (get_handle->seen_results_size == get_handle->seen_results_end) | 775 | if (get_handle->seen_results_size == get_handle->seen_results_end) |
771 | GNUNET_array_grow(get_handle->seen_results, | 776 | GNUNET_array_grow (get_handle->seen_results, |
772 | get_handle->seen_results_size, | 777 | get_handle->seen_results_size, |
773 | get_handle->seen_results_size * 2 + 1); | 778 | get_handle->seen_results_size * 2 + 1); |
774 | get_handle->seen_results[get_handle->seen_results_end++] = hc; | 779 | get_handle->seen_results[get_handle->seen_results_end++] = hc; |
775 | /* no need to block it explicitly, service already knows about it! */ | 780 | /* no need to block it explicitly, service already knows about it! */ |
776 | get_handle->iter(get_handle->iter_cls, | 781 | get_handle->iter (get_handle->iter_cls, |
777 | GNUNET_TIME_absolute_ntoh(crm->expiration), | 782 | GNUNET_TIME_absolute_ntoh (crm->expiration), |
778 | key, | 783 | key, |
779 | get_path, | 784 | get_path, |
780 | get_path_length, | 785 | get_path_length, |
781 | put_path, | 786 | put_path, |
782 | put_path_length, | 787 | put_path_length, |
783 | ntohl(crm->type), | 788 | ntohl (crm->type), |
784 | data_length, | 789 | data_length, |
785 | data); | 790 | data); |
786 | return GNUNET_YES; | 791 | return GNUNET_YES; |
787 | } | 792 | } |
788 | 793 | ||
@@ -794,15 +799,15 @@ process_client_result(void *cls, | |||
794 | * @param msg Monitor put message from the service. | 799 | * @param msg Monitor put message from the service. |
795 | */ | 800 | */ |
796 | static void | 801 | static void |
797 | handle_client_result(void *cls, | 802 | handle_client_result (void *cls, |
798 | const struct GNUNET_DHT_ClientResultMessage *msg) | 803 | const struct GNUNET_DHT_ClientResultMessage *msg) |
799 | { | 804 | { |
800 | struct GNUNET_DHT_Handle *handle = cls; | 805 | struct GNUNET_DHT_Handle *handle = cls; |
801 | 806 | ||
802 | GNUNET_CONTAINER_multihashmap_get_multiple(handle->active_requests, | 807 | GNUNET_CONTAINER_multihashmap_get_multiple (handle->active_requests, |
803 | &msg->key, | 808 | &msg->key, |
804 | &process_client_result, | 809 | &process_client_result, |
805 | (void *)msg); | 810 | (void *) msg); |
806 | } | 811 | } |
807 | 812 | ||
808 | 813 | ||
@@ -812,7 +817,7 @@ handle_client_result(void *cls, | |||
812 | * @param cls The DHT handle. | 817 | * @param cls The DHT handle. |
813 | */ | 818 | */ |
814 | static void | 819 | static void |
815 | handle_put_cont(void *cls) | 820 | handle_put_cont (void *cls) |
816 | { | 821 | { |
817 | struct GNUNET_DHT_PutHandle *ph = cls; | 822 | struct GNUNET_DHT_PutHandle *ph = cls; |
818 | GNUNET_SCHEDULER_TaskCallback cont; | 823 | GNUNET_SCHEDULER_TaskCallback cont; |
@@ -821,9 +826,9 @@ handle_put_cont(void *cls) | |||
821 | cont = ph->cont; | 826 | cont = ph->cont; |
822 | cont_cls = ph->cont_cls; | 827 | cont_cls = ph->cont_cls; |
823 | ph->env = NULL; | 828 | ph->env = NULL; |
824 | GNUNET_DHT_put_cancel(ph); | 829 | GNUNET_DHT_put_cancel (ph); |
825 | if (NULL != cont) | 830 | if (NULL != cont) |
826 | cont(cont_cls); | 831 | cont (cont_cls); |
827 | } | 832 | } |
828 | 833 | ||
829 | 834 | ||
@@ -834,41 +839,41 @@ handle_put_cont(void *cls) | |||
834 | * @return #GNUNET_YES on success, #GNUNET_NO on failure. | 839 | * @return #GNUNET_YES on success, #GNUNET_NO on failure. |
835 | */ | 840 | */ |
836 | static int | 841 | static int |
837 | try_connect(struct GNUNET_DHT_Handle *h) | 842 | try_connect (struct GNUNET_DHT_Handle *h) |
838 | { | 843 | { |
839 | struct GNUNET_MQ_MessageHandler handlers[] = { | 844 | struct GNUNET_MQ_MessageHandler handlers[] = { |
840 | GNUNET_MQ_hd_var_size(monitor_get, | 845 | GNUNET_MQ_hd_var_size (monitor_get, |
841 | GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET, | 846 | GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET, |
842 | struct GNUNET_DHT_MonitorGetMessage, | 847 | struct GNUNET_DHT_MonitorGetMessage, |
843 | h), | 848 | h), |
844 | GNUNET_MQ_hd_var_size(monitor_get_resp, | 849 | GNUNET_MQ_hd_var_size (monitor_get_resp, |
845 | GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET_RESP, | 850 | GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET_RESP, |
846 | struct GNUNET_DHT_MonitorGetRespMessage, | 851 | struct GNUNET_DHT_MonitorGetRespMessage, |
847 | h), | 852 | h), |
848 | GNUNET_MQ_hd_var_size(monitor_put, | 853 | GNUNET_MQ_hd_var_size (monitor_put, |
849 | GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT, | 854 | GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT, |
850 | struct GNUNET_DHT_MonitorPutMessage, | 855 | struct GNUNET_DHT_MonitorPutMessage, |
851 | h), | 856 | h), |
852 | GNUNET_MQ_hd_var_size(client_result, | 857 | GNUNET_MQ_hd_var_size (client_result, |
853 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT, | 858 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT, |
854 | struct GNUNET_DHT_ClientResultMessage, | 859 | struct GNUNET_DHT_ClientResultMessage, |
855 | h), | 860 | h), |
856 | GNUNET_MQ_handler_end() | 861 | GNUNET_MQ_handler_end () |
857 | }; | 862 | }; |
858 | 863 | ||
859 | if (NULL != h->mq) | 864 | if (NULL != h->mq) |
860 | return GNUNET_OK; | 865 | return GNUNET_OK; |
861 | h->mq = GNUNET_CLIENT_connect(h->cfg, | 866 | h->mq = GNUNET_CLIENT_connect (h->cfg, |
862 | "dht", | 867 | "dht", |
863 | handlers, | 868 | handlers, |
864 | &mq_error_handler, | 869 | &mq_error_handler, |
865 | h); | 870 | h); |
866 | if (NULL == h->mq) | 871 | if (NULL == h->mq) |
867 | { | 872 | { |
868 | LOG(GNUNET_ERROR_TYPE_WARNING, | 873 | LOG (GNUNET_ERROR_TYPE_WARNING, |
869 | "Failed to connect to the DHT service!\n"); | 874 | "Failed to connect to the DHT service!\n"); |
870 | return GNUNET_NO; | 875 | return GNUNET_NO; |
871 | } | 876 | } |
872 | return GNUNET_YES; | 877 | return GNUNET_YES; |
873 | } | 878 | } |
874 | 879 | ||
@@ -882,24 +887,24 @@ try_connect(struct GNUNET_DHT_Handle *h) | |||
882 | * @return handle to the DHT service, or NULL on error | 887 | * @return handle to the DHT service, or NULL on error |
883 | */ | 888 | */ |
884 | struct GNUNET_DHT_Handle * | 889 | struct GNUNET_DHT_Handle * |
885 | GNUNET_DHT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, | 890 | GNUNET_DHT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, |
886 | unsigned int ht_len) | 891 | unsigned int ht_len) |
887 | { | 892 | { |
888 | struct GNUNET_DHT_Handle *handle; | 893 | struct GNUNET_DHT_Handle *handle; |
889 | 894 | ||
890 | handle = GNUNET_new(struct GNUNET_DHT_Handle); | 895 | handle = GNUNET_new (struct GNUNET_DHT_Handle); |
891 | handle->cfg = cfg; | 896 | handle->cfg = cfg; |
892 | handle->uid_gen | 897 | handle->uid_gen |
893 | = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, | 898 | = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
894 | UINT64_MAX); | 899 | UINT64_MAX); |
895 | handle->active_requests | 900 | handle->active_requests |
896 | = GNUNET_CONTAINER_multihashmap_create(ht_len, | 901 | = GNUNET_CONTAINER_multihashmap_create (ht_len, |
897 | GNUNET_YES); | 902 | GNUNET_YES); |
898 | if (GNUNET_NO == try_connect(handle)) | 903 | if (GNUNET_NO == try_connect (handle)) |
899 | { | 904 | { |
900 | GNUNET_DHT_disconnect(handle); | 905 | GNUNET_DHT_disconnect (handle); |
901 | return NULL; | 906 | return NULL; |
902 | } | 907 | } |
903 | return handle; | 908 | return handle; |
904 | } | 909 | } |
905 | 910 | ||
@@ -910,30 +915,30 @@ GNUNET_DHT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
910 | * @param handle handle of the DHT connection to stop | 915 | * @param handle handle of the DHT connection to stop |
911 | */ | 916 | */ |
912 | void | 917 | void |
913 | GNUNET_DHT_disconnect(struct GNUNET_DHT_Handle *handle) | 918 | GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle) |
914 | { | 919 | { |
915 | struct GNUNET_DHT_PutHandle *ph; | 920 | struct GNUNET_DHT_PutHandle *ph; |
916 | 921 | ||
917 | GNUNET_assert(0 == | 922 | GNUNET_assert (0 == |
918 | GNUNET_CONTAINER_multihashmap_size(handle->active_requests)); | 923 | GNUNET_CONTAINER_multihashmap_size (handle->active_requests)); |
919 | while (NULL != (ph = handle->put_head)) | 924 | while (NULL != (ph = handle->put_head)) |
920 | { | 925 | { |
921 | if (NULL != ph->cont) | 926 | if (NULL != ph->cont) |
922 | ph->cont(ph->cont_cls); | 927 | ph->cont (ph->cont_cls); |
923 | GNUNET_DHT_put_cancel(ph); | 928 | GNUNET_DHT_put_cancel (ph); |
924 | } | 929 | } |
925 | if (NULL != handle->mq) | 930 | if (NULL != handle->mq) |
926 | { | 931 | { |
927 | GNUNET_MQ_destroy(handle->mq); | 932 | GNUNET_MQ_destroy (handle->mq); |
928 | handle->mq = NULL; | 933 | handle->mq = NULL; |
929 | } | 934 | } |
930 | if (NULL != handle->reconnect_task) | 935 | if (NULL != handle->reconnect_task) |
931 | { | 936 | { |
932 | GNUNET_SCHEDULER_cancel(handle->reconnect_task); | 937 | GNUNET_SCHEDULER_cancel (handle->reconnect_task); |
933 | handle->reconnect_task = NULL; | 938 | handle->reconnect_task = NULL; |
934 | } | 939 | } |
935 | GNUNET_CONTAINER_multihashmap_destroy(handle->active_requests); | 940 | GNUNET_CONTAINER_multihashmap_destroy (handle->active_requests); |
936 | GNUNET_free(handle); | 941 | GNUNET_free (handle); |
937 | } | 942 | } |
938 | 943 | ||
939 | 944 | ||
@@ -958,16 +963,16 @@ GNUNET_DHT_disconnect(struct GNUNET_DHT_Handle *handle) | |||
958 | * @param cont_cls closure for @a cont | 963 | * @param cont_cls closure for @a cont |
959 | */ | 964 | */ |
960 | struct GNUNET_DHT_PutHandle * | 965 | struct GNUNET_DHT_PutHandle * |
961 | GNUNET_DHT_put(struct GNUNET_DHT_Handle *handle, | 966 | GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, |
962 | const struct GNUNET_HashCode *key, | 967 | const struct GNUNET_HashCode *key, |
963 | uint32_t desired_replication_level, | 968 | uint32_t desired_replication_level, |
964 | enum GNUNET_DHT_RouteOption options, | 969 | enum GNUNET_DHT_RouteOption options, |
965 | enum GNUNET_BLOCK_Type type, | 970 | enum GNUNET_BLOCK_Type type, |
966 | size_t size, | 971 | size_t size, |
967 | const void *data, | 972 | const void *data, |
968 | struct GNUNET_TIME_Absolute exp, | 973 | struct GNUNET_TIME_Absolute exp, |
969 | GNUNET_SCHEDULER_TaskCallback cont, | 974 | GNUNET_SCHEDULER_TaskCallback cont, |
970 | void *cont_cls) | 975 | void *cont_cls) |
971 | { | 976 | { |
972 | struct GNUNET_MQ_Envelope *env; | 977 | struct GNUNET_MQ_Envelope *env; |
973 | struct GNUNET_DHT_ClientPutMessage *put_msg; | 978 | struct GNUNET_DHT_ClientPutMessage *put_msg; |
@@ -977,40 +982,40 @@ GNUNET_DHT_put(struct GNUNET_DHT_Handle *handle, | |||
977 | msize = sizeof(struct GNUNET_DHT_ClientPutMessage) + size; | 982 | msize = sizeof(struct GNUNET_DHT_ClientPutMessage) + size; |
978 | if ((msize >= GNUNET_MAX_MESSAGE_SIZE) || | 983 | if ((msize >= GNUNET_MAX_MESSAGE_SIZE) || |
979 | (size >= GNUNET_MAX_MESSAGE_SIZE)) | 984 | (size >= GNUNET_MAX_MESSAGE_SIZE)) |
980 | { | 985 | { |
981 | GNUNET_break(0); | 986 | GNUNET_break (0); |
982 | return NULL; | 987 | return NULL; |
983 | } | 988 | } |
984 | if (NULL == handle->mq) | 989 | if (NULL == handle->mq) |
985 | return NULL; | 990 | return NULL; |
986 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 991 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
987 | "Sending PUT for %s to DHT via %p\n", | 992 | "Sending PUT for %s to DHT via %p\n", |
988 | GNUNET_h2s(key), | 993 | GNUNET_h2s (key), |
989 | handle); | 994 | handle); |
990 | ph = GNUNET_new(struct GNUNET_DHT_PutHandle); | 995 | ph = GNUNET_new (struct GNUNET_DHT_PutHandle); |
991 | ph->dht_handle = handle; | 996 | ph->dht_handle = handle; |
992 | ph->cont = cont; | 997 | ph->cont = cont; |
993 | ph->cont_cls = cont_cls; | 998 | ph->cont_cls = cont_cls; |
994 | GNUNET_CONTAINER_DLL_insert_tail(handle->put_head, | 999 | GNUNET_CONTAINER_DLL_insert_tail (handle->put_head, |
995 | handle->put_tail, | 1000 | handle->put_tail, |
996 | ph); | 1001 | ph); |
997 | env = GNUNET_MQ_msg_extra(put_msg, | 1002 | env = GNUNET_MQ_msg_extra (put_msg, |
998 | size, | 1003 | size, |
999 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT); | 1004 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT); |
1000 | GNUNET_MQ_notify_sent(env, | 1005 | GNUNET_MQ_notify_sent (env, |
1001 | &handle_put_cont, | 1006 | &handle_put_cont, |
1002 | ph); | 1007 | ph); |
1003 | ph->env = env; | 1008 | ph->env = env; |
1004 | put_msg->type = htonl((uint32_t)type); | 1009 | put_msg->type = htonl ((uint32_t) type); |
1005 | put_msg->options = htonl((uint32_t)options); | 1010 | put_msg->options = htonl ((uint32_t) options); |
1006 | put_msg->desired_replication_level = htonl(desired_replication_level); | 1011 | put_msg->desired_replication_level = htonl (desired_replication_level); |
1007 | put_msg->expiration = GNUNET_TIME_absolute_hton(exp); | 1012 | put_msg->expiration = GNUNET_TIME_absolute_hton (exp); |
1008 | put_msg->key = *key; | 1013 | put_msg->key = *key; |
1009 | GNUNET_memcpy(&put_msg[1], | 1014 | GNUNET_memcpy (&put_msg[1], |
1010 | data, | 1015 | data, |
1011 | size); | 1016 | size); |
1012 | GNUNET_MQ_send(handle->mq, | 1017 | GNUNET_MQ_send (handle->mq, |
1013 | env); | 1018 | env); |
1014 | return ph; | 1019 | return ph; |
1015 | } | 1020 | } |
1016 | 1021 | ||
@@ -1027,18 +1032,18 @@ GNUNET_DHT_put(struct GNUNET_DHT_Handle *handle, | |||
1027 | * @param ph put operation to cancel ('cont' will no longer be called) | 1032 | * @param ph put operation to cancel ('cont' will no longer be called) |
1028 | */ | 1033 | */ |
1029 | void | 1034 | void |
1030 | GNUNET_DHT_put_cancel(struct GNUNET_DHT_PutHandle *ph) | 1035 | GNUNET_DHT_put_cancel (struct GNUNET_DHT_PutHandle *ph) |
1031 | { | 1036 | { |
1032 | struct GNUNET_DHT_Handle *handle = ph->dht_handle; | 1037 | struct GNUNET_DHT_Handle *handle = ph->dht_handle; |
1033 | 1038 | ||
1034 | if (NULL != ph->env) | 1039 | if (NULL != ph->env) |
1035 | GNUNET_MQ_notify_sent(ph->env, | 1040 | GNUNET_MQ_notify_sent (ph->env, |
1036 | NULL, | 1041 | NULL, |
1037 | NULL); | 1042 | NULL); |
1038 | GNUNET_CONTAINER_DLL_remove(handle->put_head, | 1043 | GNUNET_CONTAINER_DLL_remove (handle->put_head, |
1039 | handle->put_tail, | 1044 | handle->put_tail, |
1040 | ph); | 1045 | ph); |
1041 | GNUNET_free(ph); | 1046 | GNUNET_free (ph); |
1042 | } | 1047 | } |
1043 | 1048 | ||
1044 | 1049 | ||
@@ -1059,15 +1064,15 @@ GNUNET_DHT_put_cancel(struct GNUNET_DHT_PutHandle *ph) | |||
1059 | * @return handle to stop the async get | 1064 | * @return handle to stop the async get |
1060 | */ | 1065 | */ |
1061 | struct GNUNET_DHT_GetHandle * | 1066 | struct GNUNET_DHT_GetHandle * |
1062 | GNUNET_DHT_get_start(struct GNUNET_DHT_Handle *handle, | 1067 | GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, |
1063 | enum GNUNET_BLOCK_Type type, | 1068 | enum GNUNET_BLOCK_Type type, |
1064 | const struct GNUNET_HashCode *key, | 1069 | const struct GNUNET_HashCode *key, |
1065 | uint32_t desired_replication_level, | 1070 | uint32_t desired_replication_level, |
1066 | enum GNUNET_DHT_RouteOption options, | 1071 | enum GNUNET_DHT_RouteOption options, |
1067 | const void *xquery, | 1072 | const void *xquery, |
1068 | size_t xquery_size, | 1073 | size_t xquery_size, |
1069 | GNUNET_DHT_GetIterator iter, | 1074 | GNUNET_DHT_GetIterator iter, |
1070 | void *iter_cls) | 1075 | void *iter_cls) |
1071 | { | 1076 | { |
1072 | struct GNUNET_DHT_GetHandle *gh; | 1077 | struct GNUNET_DHT_GetHandle *gh; |
1073 | size_t msize; | 1078 | size_t msize; |
@@ -1075,16 +1080,16 @@ GNUNET_DHT_get_start(struct GNUNET_DHT_Handle *handle, | |||
1075 | msize = sizeof(struct GNUNET_DHT_ClientGetMessage) + xquery_size; | 1080 | msize = sizeof(struct GNUNET_DHT_ClientGetMessage) + xquery_size; |
1076 | if ((msize >= GNUNET_MAX_MESSAGE_SIZE) || | 1081 | if ((msize >= GNUNET_MAX_MESSAGE_SIZE) || |
1077 | (xquery_size >= GNUNET_MAX_MESSAGE_SIZE)) | 1082 | (xquery_size >= GNUNET_MAX_MESSAGE_SIZE)) |
1078 | { | 1083 | { |
1079 | GNUNET_break(0); | 1084 | GNUNET_break (0); |
1080 | return NULL; | 1085 | return NULL; |
1081 | } | 1086 | } |
1082 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1087 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1083 | "Sending query for %s to DHT %p\n", | 1088 | "Sending query for %s to DHT %p\n", |
1084 | GNUNET_h2s(key), | 1089 | GNUNET_h2s (key), |
1085 | handle); | 1090 | handle); |
1086 | gh = GNUNET_malloc(sizeof(struct GNUNET_DHT_GetHandle) + | 1091 | gh = GNUNET_malloc (sizeof(struct GNUNET_DHT_GetHandle) |
1087 | xquery_size); | 1092 | + xquery_size); |
1088 | gh->iter = iter; | 1093 | gh->iter = iter; |
1089 | gh->iter_cls = iter_cls; | 1094 | gh->iter_cls = iter_cls; |
1090 | gh->dht_handle = handle; | 1095 | gh->dht_handle = handle; |
@@ -1094,15 +1099,15 @@ GNUNET_DHT_get_start(struct GNUNET_DHT_Handle *handle, | |||
1094 | gh->desired_replication_level = desired_replication_level; | 1099 | gh->desired_replication_level = desired_replication_level; |
1095 | gh->type = type; | 1100 | gh->type = type; |
1096 | gh->options = options; | 1101 | gh->options = options; |
1097 | GNUNET_memcpy(&gh[1], | 1102 | GNUNET_memcpy (&gh[1], |
1098 | xquery, | 1103 | xquery, |
1099 | xquery_size); | 1104 | xquery_size); |
1100 | GNUNET_CONTAINER_multihashmap_put(handle->active_requests, | 1105 | GNUNET_CONTAINER_multihashmap_put (handle->active_requests, |
1101 | &gh->key, | 1106 | &gh->key, |
1102 | gh, | 1107 | gh, |
1103 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 1108 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
1104 | if (NULL != handle->mq) | 1109 | if (NULL != handle->mq) |
1105 | send_get(gh); | 1110 | send_get (gh); |
1106 | return gh; | 1111 | return gh; |
1107 | } | 1112 | } |
1108 | 1113 | ||
@@ -1118,9 +1123,9 @@ GNUNET_DHT_get_start(struct GNUNET_DHT_Handle *handle, | |||
1118 | * to be blocked | 1123 | * to be blocked |
1119 | */ | 1124 | */ |
1120 | void | 1125 | void |
1121 | GNUNET_DHT_get_filter_known_results(struct GNUNET_DHT_GetHandle *get_handle, | 1126 | GNUNET_DHT_get_filter_known_results (struct GNUNET_DHT_GetHandle *get_handle, |
1122 | unsigned int num_results, | 1127 | unsigned int num_results, |
1123 | const struct GNUNET_HashCode *results) | 1128 | const struct GNUNET_HashCode *results) |
1124 | { | 1129 | { |
1125 | unsigned int needed; | 1130 | unsigned int needed; |
1126 | unsigned int had; | 1131 | unsigned int had; |
@@ -1128,16 +1133,16 @@ GNUNET_DHT_get_filter_known_results(struct GNUNET_DHT_GetHandle *get_handle, | |||
1128 | had = get_handle->seen_results_end; | 1133 | had = get_handle->seen_results_end; |
1129 | needed = had + num_results; | 1134 | needed = had + num_results; |
1130 | if (needed > get_handle->seen_results_size) | 1135 | if (needed > get_handle->seen_results_size) |
1131 | GNUNET_array_grow(get_handle->seen_results, | 1136 | GNUNET_array_grow (get_handle->seen_results, |
1132 | get_handle->seen_results_size, | 1137 | get_handle->seen_results_size, |
1133 | needed); | 1138 | needed); |
1134 | GNUNET_memcpy(&get_handle->seen_results[get_handle->seen_results_end], | 1139 | GNUNET_memcpy (&get_handle->seen_results[get_handle->seen_results_end], |
1135 | results, | 1140 | results, |
1136 | num_results * sizeof(struct GNUNET_HashCode)); | 1141 | num_results * sizeof(struct GNUNET_HashCode)); |
1137 | get_handle->seen_results_end += num_results; | 1142 | get_handle->seen_results_end += num_results; |
1138 | if (NULL != get_handle->dht_handle->mq) | 1143 | if (NULL != get_handle->dht_handle->mq) |
1139 | send_get_known_results(get_handle, | 1144 | send_get_known_results (get_handle, |
1140 | had); | 1145 | had); |
1141 | } | 1146 | } |
1142 | 1147 | ||
1143 | 1148 | ||
@@ -1147,35 +1152,35 @@ GNUNET_DHT_get_filter_known_results(struct GNUNET_DHT_GetHandle *get_handle, | |||
1147 | * @param get_handle handle to the GET operation to stop | 1152 | * @param get_handle handle to the GET operation to stop |
1148 | */ | 1153 | */ |
1149 | void | 1154 | void |
1150 | GNUNET_DHT_get_stop(struct GNUNET_DHT_GetHandle *get_handle) | 1155 | GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle) |
1151 | { | 1156 | { |
1152 | struct GNUNET_DHT_Handle *handle = get_handle->dht_handle; | 1157 | struct GNUNET_DHT_Handle *handle = get_handle->dht_handle; |
1153 | 1158 | ||
1154 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1159 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1155 | "Sending STOP for %s to DHT via %p\n", | 1160 | "Sending STOP for %s to DHT via %p\n", |
1156 | GNUNET_h2s(&get_handle->key), | 1161 | GNUNET_h2s (&get_handle->key), |
1157 | handle); | 1162 | handle); |
1158 | if (NULL != handle->mq) | 1163 | if (NULL != handle->mq) |
1159 | { | 1164 | { |
1160 | struct GNUNET_MQ_Envelope *env; | 1165 | struct GNUNET_MQ_Envelope *env; |
1161 | struct GNUNET_DHT_ClientGetStopMessage *stop_msg; | 1166 | struct GNUNET_DHT_ClientGetStopMessage *stop_msg; |
1162 | 1167 | ||
1163 | env = GNUNET_MQ_msg(stop_msg, | 1168 | env = GNUNET_MQ_msg (stop_msg, |
1164 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP); | 1169 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP); |
1165 | stop_msg->reserved = htonl(0); | 1170 | stop_msg->reserved = htonl (0); |
1166 | stop_msg->unique_id = get_handle->unique_id; | 1171 | stop_msg->unique_id = get_handle->unique_id; |
1167 | stop_msg->key = get_handle->key; | 1172 | stop_msg->key = get_handle->key; |
1168 | GNUNET_MQ_send(handle->mq, | 1173 | GNUNET_MQ_send (handle->mq, |
1169 | env); | 1174 | env); |
1170 | } | 1175 | } |
1171 | GNUNET_assert(GNUNET_YES == | 1176 | GNUNET_assert (GNUNET_YES == |
1172 | GNUNET_CONTAINER_multihashmap_remove(handle->active_requests, | 1177 | GNUNET_CONTAINER_multihashmap_remove (handle->active_requests, |
1173 | &get_handle->key, | 1178 | &get_handle->key, |
1174 | get_handle)); | 1179 | get_handle)); |
1175 | GNUNET_array_grow(get_handle->seen_results, | 1180 | GNUNET_array_grow (get_handle->seen_results, |
1176 | get_handle->seen_results_end, | 1181 | get_handle->seen_results_end, |
1177 | 0); | 1182 | 0); |
1178 | GNUNET_free(get_handle); | 1183 | GNUNET_free (get_handle); |
1179 | } | 1184 | } |
1180 | 1185 | ||
1181 | 1186 | ||
@@ -1192,17 +1197,17 @@ GNUNET_DHT_get_stop(struct GNUNET_DHT_GetHandle *get_handle) | |||
1192 | * @return Handle to stop monitoring. | 1197 | * @return Handle to stop monitoring. |
1193 | */ | 1198 | */ |
1194 | struct GNUNET_DHT_MonitorHandle * | 1199 | struct GNUNET_DHT_MonitorHandle * |
1195 | GNUNET_DHT_monitor_start(struct GNUNET_DHT_Handle *handle, | 1200 | GNUNET_DHT_monitor_start (struct GNUNET_DHT_Handle *handle, |
1196 | enum GNUNET_BLOCK_Type type, | 1201 | enum GNUNET_BLOCK_Type type, |
1197 | const struct GNUNET_HashCode *key, | 1202 | const struct GNUNET_HashCode *key, |
1198 | GNUNET_DHT_MonitorGetCB get_cb, | 1203 | GNUNET_DHT_MonitorGetCB get_cb, |
1199 | GNUNET_DHT_MonitorGetRespCB get_resp_cb, | 1204 | GNUNET_DHT_MonitorGetRespCB get_resp_cb, |
1200 | GNUNET_DHT_MonitorPutCB put_cb, | 1205 | GNUNET_DHT_MonitorPutCB put_cb, |
1201 | void *cb_cls) | 1206 | void *cb_cls) |
1202 | { | 1207 | { |
1203 | struct GNUNET_DHT_MonitorHandle *mh; | 1208 | struct GNUNET_DHT_MonitorHandle *mh; |
1204 | 1209 | ||
1205 | mh = GNUNET_new(struct GNUNET_DHT_MonitorHandle); | 1210 | mh = GNUNET_new (struct GNUNET_DHT_MonitorHandle); |
1206 | mh->get_cb = get_cb; | 1211 | mh->get_cb = get_cb; |
1207 | mh->get_resp_cb = get_resp_cb; | 1212 | mh->get_resp_cb = get_resp_cb; |
1208 | mh->put_cb = put_cb; | 1213 | mh->put_cb = put_cb; |
@@ -1210,15 +1215,15 @@ GNUNET_DHT_monitor_start(struct GNUNET_DHT_Handle *handle, | |||
1210 | mh->type = type; | 1215 | mh->type = type; |
1211 | mh->dht_handle = handle; | 1216 | mh->dht_handle = handle; |
1212 | if (NULL != key) | 1217 | if (NULL != key) |
1213 | { | 1218 | { |
1214 | mh->key = GNUNET_new(struct GNUNET_HashCode); | 1219 | mh->key = GNUNET_new (struct GNUNET_HashCode); |
1215 | *mh->key = *key; | 1220 | *mh->key = *key; |
1216 | } | 1221 | } |
1217 | GNUNET_CONTAINER_DLL_insert(handle->monitor_head, | 1222 | GNUNET_CONTAINER_DLL_insert (handle->monitor_head, |
1218 | handle->monitor_tail, | 1223 | handle->monitor_tail, |
1219 | mh); | 1224 | mh); |
1220 | if (NULL != handle->mq) | 1225 | if (NULL != handle->mq) |
1221 | send_monitor_start(mh); | 1226 | send_monitor_start (mh); |
1222 | return mh; | 1227 | return mh; |
1223 | } | 1228 | } |
1224 | 1229 | ||
@@ -1231,30 +1236,30 @@ GNUNET_DHT_monitor_start(struct GNUNET_DHT_Handle *handle, | |||
1231 | * On return get_handle will no longer be valid, caller must not use again!!! | 1236 | * On return get_handle will no longer be valid, caller must not use again!!! |
1232 | */ | 1237 | */ |
1233 | void | 1238 | void |
1234 | GNUNET_DHT_monitor_stop(struct GNUNET_DHT_MonitorHandle *mh) | 1239 | GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *mh) |
1235 | { | 1240 | { |
1236 | struct GNUNET_DHT_Handle *handle = mh->dht_handle; | 1241 | struct GNUNET_DHT_Handle *handle = mh->dht_handle; |
1237 | struct GNUNET_DHT_MonitorStartStopMessage *m; | 1242 | struct GNUNET_DHT_MonitorStartStopMessage *m; |
1238 | struct GNUNET_MQ_Envelope *env; | 1243 | struct GNUNET_MQ_Envelope *env; |
1239 | 1244 | ||
1240 | GNUNET_CONTAINER_DLL_remove(handle->monitor_head, | 1245 | GNUNET_CONTAINER_DLL_remove (handle->monitor_head, |
1241 | handle->monitor_tail, | 1246 | handle->monitor_tail, |
1242 | mh); | 1247 | mh); |
1243 | env = GNUNET_MQ_msg(m, | 1248 | env = GNUNET_MQ_msg (m, |
1244 | GNUNET_MESSAGE_TYPE_DHT_MONITOR_STOP); | 1249 | GNUNET_MESSAGE_TYPE_DHT_MONITOR_STOP); |
1245 | m->type = htonl(mh->type); | 1250 | m->type = htonl (mh->type); |
1246 | m->get = htons(NULL != mh->get_cb); | 1251 | m->get = htons (NULL != mh->get_cb); |
1247 | m->get_resp = htons(NULL != mh->get_resp_cb); | 1252 | m->get_resp = htons (NULL != mh->get_resp_cb); |
1248 | m->put = htons(NULL != mh->put_cb); | 1253 | m->put = htons (NULL != mh->put_cb); |
1249 | if (NULL != mh->key) | 1254 | if (NULL != mh->key) |
1250 | { | 1255 | { |
1251 | m->filter_key = htons(1); | 1256 | m->filter_key = htons (1); |
1252 | m->key = *mh->key; | 1257 | m->key = *mh->key; |
1253 | } | 1258 | } |
1254 | GNUNET_MQ_send(handle->mq, | 1259 | GNUNET_MQ_send (handle->mq, |
1255 | env); | 1260 | env); |
1256 | GNUNET_free_non_null(mh->key); | 1261 | GNUNET_free_non_null (mh->key); |
1257 | GNUNET_free(mh); | 1262 | GNUNET_free (mh); |
1258 | } | 1263 | } |
1259 | 1264 | ||
1260 | 1265 | ||
diff --git a/src/dht/dht_test_lib.c b/src/dht/dht_test_lib.c index 8ce3e98ea..e18d2ab24 100644 --- a/src/dht/dht_test_lib.c +++ b/src/dht/dht_test_lib.c | |||
@@ -28,7 +28,8 @@ | |||
28 | /** | 28 | /** |
29 | * Test context for a DHT Test. | 29 | * Test context for a DHT Test. |
30 | */ | 30 | */ |
31 | struct GNUNET_DHT_TEST_Context { | 31 | struct GNUNET_DHT_TEST_Context |
32 | { | ||
32 | /** | 33 | /** |
33 | * Array of running peers. | 34 | * Array of running peers. |
34 | */ | 35 | */ |
@@ -72,10 +73,10 @@ struct GNUNET_DHT_TEST_Context { | |||
72 | * @return service handle to return in 'op_result', NULL on error | 73 | * @return service handle to return in 'op_result', NULL on error |
73 | */ | 74 | */ |
74 | static void * | 75 | static void * |
75 | dht_connect_adapter(void *cls, | 76 | dht_connect_adapter (void *cls, |
76 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 77 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
77 | { | 78 | { |
78 | return GNUNET_DHT_connect(cfg, 16); | 79 | return GNUNET_DHT_connect (cfg, 16); |
79 | } | 80 | } |
80 | 81 | ||
81 | 82 | ||
@@ -87,12 +88,12 @@ dht_connect_adapter(void *cls, | |||
87 | * @param op_result service handle returned from the connect adapter | 88 | * @param op_result service handle returned from the connect adapter |
88 | */ | 89 | */ |
89 | static void | 90 | static void |
90 | dht_disconnect_adapter(void *cls, | 91 | dht_disconnect_adapter (void *cls, |
91 | void *op_result) | 92 | void *op_result) |
92 | { | 93 | { |
93 | struct GNUNET_DHT_Handle *dht = op_result; | 94 | struct GNUNET_DHT_Handle *dht = op_result; |
94 | 95 | ||
95 | GNUNET_DHT_disconnect(dht); | 96 | GNUNET_DHT_disconnect (dht); |
96 | } | 97 | } |
97 | 98 | ||
98 | 99 | ||
@@ -106,21 +107,21 @@ dht_disconnect_adapter(void *cls, | |||
106 | * operation has executed successfully. | 107 | * operation has executed successfully. |
107 | */ | 108 | */ |
108 | static void | 109 | static void |
109 | dht_connect_cb(void *cls, | 110 | dht_connect_cb (void *cls, |
110 | struct GNUNET_TESTBED_Operation *op, | 111 | struct GNUNET_TESTBED_Operation *op, |
111 | void *ca_result, | 112 | void *ca_result, |
112 | const char *emsg) | 113 | const char *emsg) |
113 | { | 114 | { |
114 | struct GNUNET_DHT_TEST_Context *ctx = cls; | 115 | struct GNUNET_DHT_TEST_Context *ctx = cls; |
115 | 116 | ||
116 | if (NULL != emsg) | 117 | if (NULL != emsg) |
117 | { | 118 | { |
118 | fprintf(stderr, | 119 | fprintf (stderr, |
119 | "Failed to connect to DHT service: %s\n", | 120 | "Failed to connect to DHT service: %s\n", |
120 | emsg); | 121 | emsg); |
121 | GNUNET_SCHEDULER_shutdown(); | 122 | GNUNET_SCHEDULER_shutdown (); |
122 | return; | 123 | return; |
123 | } | 124 | } |
124 | for (unsigned int i = 0; i < ctx->num_peers; i++) | 125 | for (unsigned int i = 0; i < ctx->num_peers; i++) |
125 | if (op == ctx->ops[i]) | 126 | if (op == ctx->ops[i]) |
126 | ctx->dhts[i] = ca_result; | 127 | ctx->dhts[i] = ca_result; |
@@ -129,11 +130,11 @@ dht_connect_cb(void *cls, | |||
129 | return; | 130 | return; |
130 | /* still some DHT connections missing */ | 131 | /* still some DHT connections missing */ |
131 | /* all DHT connections ready! */ | 132 | /* all DHT connections ready! */ |
132 | ctx->app_main(ctx->app_main_cls, | 133 | ctx->app_main (ctx->app_main_cls, |
133 | ctx, | 134 | ctx, |
134 | ctx->num_peers, | 135 | ctx->num_peers, |
135 | ctx->peers, | 136 | ctx->peers, |
136 | ctx->dhts); | 137 | ctx->dhts); |
137 | } | 138 | } |
138 | 139 | ||
139 | 140 | ||
@@ -143,38 +144,38 @@ dht_connect_cb(void *cls, | |||
143 | * @param ctx handle for the testbed | 144 | * @param ctx handle for the testbed |
144 | */ | 145 | */ |
145 | void | 146 | void |
146 | GNUNET_DHT_TEST_cleanup(struct GNUNET_DHT_TEST_Context *ctx) | 147 | GNUNET_DHT_TEST_cleanup (struct GNUNET_DHT_TEST_Context *ctx) |
147 | { | 148 | { |
148 | for (unsigned int i = 0; i < ctx->num_peers; i++) | 149 | for (unsigned int i = 0; i < ctx->num_peers; i++) |
149 | GNUNET_TESTBED_operation_done(ctx->ops[i]); | 150 | GNUNET_TESTBED_operation_done (ctx->ops[i]); |
150 | GNUNET_free(ctx->ops); | 151 | GNUNET_free (ctx->ops); |
151 | GNUNET_free(ctx->dhts); | 152 | GNUNET_free (ctx->dhts); |
152 | GNUNET_free(ctx); | 153 | GNUNET_free (ctx); |
153 | GNUNET_SCHEDULER_shutdown(); | 154 | GNUNET_SCHEDULER_shutdown (); |
154 | } | 155 | } |
155 | 156 | ||
156 | 157 | ||
157 | static void | 158 | static void |
158 | dht_test_run(void *cls, | 159 | dht_test_run (void *cls, |
159 | struct GNUNET_TESTBED_RunHandle *h, | 160 | struct GNUNET_TESTBED_RunHandle *h, |
160 | unsigned int num_peers, | 161 | unsigned int num_peers, |
161 | struct GNUNET_TESTBED_Peer **peers, | 162 | struct GNUNET_TESTBED_Peer **peers, |
162 | unsigned int links_succeeded, | 163 | unsigned int links_succeeded, |
163 | unsigned int links_failed) | 164 | unsigned int links_failed) |
164 | { | 165 | { |
165 | struct GNUNET_DHT_TEST_Context *ctx = cls; | 166 | struct GNUNET_DHT_TEST_Context *ctx = cls; |
166 | 167 | ||
167 | GNUNET_assert(num_peers == ctx->num_peers); | 168 | GNUNET_assert (num_peers == ctx->num_peers); |
168 | ctx->peers = peers; | 169 | ctx->peers = peers; |
169 | for (unsigned int i = 0; i < num_peers; i++) | 170 | for (unsigned int i = 0; i < num_peers; i++) |
170 | ctx->ops[i] = GNUNET_TESTBED_service_connect(ctx, | 171 | ctx->ops[i] = GNUNET_TESTBED_service_connect (ctx, |
171 | peers[i], | 172 | peers[i], |
172 | "dht", | 173 | "dht", |
173 | &dht_connect_cb, | 174 | &dht_connect_cb, |
174 | ctx, | 175 | ctx, |
175 | &dht_connect_adapter, | 176 | &dht_connect_adapter, |
176 | &dht_disconnect_adapter, | 177 | &dht_disconnect_adapter, |
177 | ctx); | 178 | ctx); |
178 | } | 179 | } |
179 | 180 | ||
180 | 181 | ||
@@ -189,27 +190,27 @@ dht_test_run(void *cls, | |||
189 | * @param tmain_cls closure for 'tmain' | 190 | * @param tmain_cls closure for 'tmain' |
190 | */ | 191 | */ |
191 | void | 192 | void |
192 | GNUNET_DHT_TEST_run(const char *testname, | 193 | GNUNET_DHT_TEST_run (const char *testname, |
193 | const char *cfgname, | 194 | const char *cfgname, |
194 | unsigned int num_peers, | 195 | unsigned int num_peers, |
195 | GNUNET_DHT_TEST_AppMain tmain, | 196 | GNUNET_DHT_TEST_AppMain tmain, |
196 | void *tmain_cls) | 197 | void *tmain_cls) |
197 | { | 198 | { |
198 | struct GNUNET_DHT_TEST_Context *ctx; | 199 | struct GNUNET_DHT_TEST_Context *ctx; |
199 | 200 | ||
200 | ctx = GNUNET_new(struct GNUNET_DHT_TEST_Context); | 201 | ctx = GNUNET_new (struct GNUNET_DHT_TEST_Context); |
201 | ctx->num_peers = num_peers; | 202 | ctx->num_peers = num_peers; |
202 | ctx->ops = GNUNET_new_array(num_peers, | 203 | ctx->ops = GNUNET_new_array (num_peers, |
203 | struct GNUNET_TESTBED_Operation *); | 204 | struct GNUNET_TESTBED_Operation *); |
204 | ctx->dhts = GNUNET_new_array(num_peers, | 205 | ctx->dhts = GNUNET_new_array (num_peers, |
205 | struct GNUNET_DHT_Handle *); | 206 | struct GNUNET_DHT_Handle *); |
206 | ctx->app_main = tmain; | 207 | ctx->app_main = tmain; |
207 | ctx->app_main_cls = tmain_cls; | 208 | ctx->app_main_cls = tmain_cls; |
208 | (void)GNUNET_TESTBED_test_run(testname, | 209 | (void) GNUNET_TESTBED_test_run (testname, |
209 | cfgname, | 210 | cfgname, |
210 | num_peers, | 211 | num_peers, |
211 | 0LL, NULL, NULL, | 212 | 0LL, NULL, NULL, |
212 | &dht_test_run, ctx); | 213 | &dht_test_run, ctx); |
213 | } | 214 | } |
214 | 215 | ||
215 | /* end of dht_test_lib.c */ | 216 | /* end of dht_test_lib.c */ |
diff --git a/src/dht/dht_test_lib.h b/src/dht/dht_test_lib.h index 716daaacf..efffc9ef7 100644 --- a/src/dht/dht_test_lib.h +++ b/src/dht/dht_test_lib.h | |||
@@ -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 | */ |
71 | void | 71 | void |
72 | GNUNET_DHT_TEST_run(const char *testname, | 72 | GNUNET_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 | */ |
84 | void | 84 | void |
85 | GNUNET_DHT_TEST_cleanup(struct GNUNET_DHT_TEST_Context *ctx); | 85 | GNUNET_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 901641660..aacd4ac98 100644 --- a/src/dht/gnunet-dht-get.c +++ b/src/dht/gnunet-dht-get.c | |||
@@ -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 | */ |
@@ -94,23 +94,23 @@ static struct GNUNET_SCHEDULER_Task *tt; | |||
94 | * @param cls unused | 94 | * @param cls unused |
95 | */ | 95 | */ |
96 | static void | 96 | static void |
97 | cleanup_task(void *cls) | 97 | cleanup_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 | */ |
122 | static void | 122 | static void |
123 | timeout_task(void *cls) | 123 | timeout_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 | */ |
145 | static void | 145 | static void |
146 | get_result_iterator(void *cls, | 146 | get_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 | */ |
186 | static void | 186 | static void |
187 | run(void *cls, | 187 | run (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,48 +236,48 @@ run(void *cls, | |||
236 | * @return 0 ok, 1 on error | 236 | * @return 0 ok, 1 on error |
237 | */ | 237 | */ |
238 | int | 238 | int |
239 | main(int argc, char *const *argv) | 239 | main (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, |
diff --git a/src/dht/gnunet-dht-monitor.c b/src/dht/gnunet-dht-monitor.c index 26989467c..d0cd4cff1 100644 --- a/src/dht/gnunet-dht-monitor.c +++ b/src/dht/gnunet-dht-monitor.c | |||
@@ -83,25 +83,25 @@ static struct GNUNET_SCHEDULER_Task *tt; | |||
83 | * @param cls closure (unused) | 83 | * @param cls closure (unused) |
84 | */ | 84 | */ |
85 | static void | 85 | static void |
86 | cleanup_task(void *cls) | 86 | cleanup_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 | */ |
113 | static void | 113 | static void |
114 | timeout_task(void *cls) | 114 | timeout_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 | */ |
133 | static void | 133 | static void |
134 | get_callback(void *cls, | 134 | get_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 | */ |
166 | static void | 166 | static void |
167 | get_resp_callback(void *cls, | 167 | get_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 | */ |
207 | static void | 207 | static void |
208 | put_callback(void *cls, | 208 | put_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 | */ |
242 | static void | 242 | static void |
243 | run(void *cls, | 243 | run (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,50 +292,50 @@ run(void *cls, | |||
292 | * @return 0 ok, 1 on error | 292 | * @return 0 ok, 1 on error |
293 | */ | 293 | */ |
294 | int | 294 | int |
295 | main(int argc, char *const *argv) | 295 | main (int argc, char *const *argv) |
296 | { | 296 | { |
297 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 297 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
298 | GNUNET_GETOPT_option_string('k', | 298 | GNUNET_GETOPT_option_string ('k', |
299 | "key", | 299 | "key", |
300 | "KEY", | 300 | "KEY", |
301 | gettext_noop("the query key"), | 301 | gettext_noop ("the query key"), |
302 | &query_key), | 302 | &query_key), |
303 | 303 | ||
304 | GNUNET_GETOPT_option_uint('t', | 304 | GNUNET_GETOPT_option_uint ('t', |
305 | "type", | 305 | "type", |
306 | "TYPE", | 306 | "TYPE", |
307 | gettext_noop("the type of data to look for"), | 307 | gettext_noop ("the type of data to look for"), |
308 | &block_type), | 308 | &block_type), |
309 | 309 | ||
310 | GNUNET_GETOPT_option_relative_time( | 310 | GNUNET_GETOPT_option_relative_time ( |
311 | 'T', | 311 | 'T', |
312 | "timeout", | 312 | "timeout", |
313 | "TIMEOUT", | 313 | "TIMEOUT", |
314 | gettext_noop("how long should the monitor command run"), | 314 | gettext_noop ("how long should the monitor command run"), |
315 | &timeout_request), | 315 | &timeout_request), |
316 | 316 | ||
317 | GNUNET_GETOPT_option_flag('V', | 317 | GNUNET_GETOPT_option_flag ('V', |
318 | "verbose", | 318 | "verbose", |
319 | gettext_noop( | 319 | gettext_noop ( |
320 | "be verbose (print progress information)"), | 320 | "be verbose (print progress information)"), |
321 | &verbose), | 321 | &verbose), |
322 | 322 | ||
323 | GNUNET_GETOPT_OPTION_END | 323 | GNUNET_GETOPT_OPTION_END |
324 | }; | 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 | } |
diff --git a/src/dht/gnunet-dht-put.c b/src/dht/gnunet-dht-put.c index 330b2ac62..d8bffbf37 100644 --- a/src/dht/gnunet-dht-put.c +++ b/src/dht/gnunet-dht-put.c | |||
@@ -89,13 +89,13 @@ static char *data; | |||
89 | 89 | ||
90 | 90 | ||
91 | static void | 91 | static void |
92 | shutdown_task(void *cls) | 92 | shutdown_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 | */ |
107 | static void | 107 | static void |
108 | message_sent_cont(void *cls) | 108 | message_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 | */ |
122 | static void | 122 | static void |
123 | run(void *cls, | 123 | run (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,58 +176,58 @@ run(void *cls, | |||
176 | * @return 0 ok, 1 on error | 176 | * @return 0 ok, 1 on error |
177 | */ | 177 | */ |
178 | int | 178 | int |
179 | main(int argc, char *const *argv) | 179 | main (int argc, char *const *argv) |
180 | { | 180 | { |
181 | struct GNUNET_GETOPT_CommandLineOption options[] = | 181 | struct GNUNET_GETOPT_CommandLineOption options[] = |
182 | { GNUNET_GETOPT_option_string('d', | 182 | { GNUNET_GETOPT_option_string ('d', |
183 | "data", | 183 | "data", |
184 | "DATA", | 184 | "DATA", |
185 | gettext_noop( | 185 | gettext_noop ( |
186 | "the data to insert under the key"), | 186 | "the data to insert under the key"), |
187 | &data), | 187 | &data), |
188 | GNUNET_GETOPT_option_relative_time( | 188 | GNUNET_GETOPT_option_relative_time ( |
189 | 'e', | 189 | 'e', |
190 | "expiration", | 190 | "expiration", |
191 | "EXPIRATION", | 191 | "EXPIRATION", |
192 | 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)"), |
193 | &expiration), | 193 | &expiration), |
194 | GNUNET_GETOPT_option_string('k', | 194 | GNUNET_GETOPT_option_string ('k', |
195 | "key", | 195 | "key", |
196 | "KEY", | 196 | "KEY", |
197 | gettext_noop("the query key"), | 197 | gettext_noop ("the query key"), |
198 | &query_key), | 198 | &query_key), |
199 | GNUNET_GETOPT_option_flag('x', | 199 | GNUNET_GETOPT_option_flag ('x', |
200 | "demultiplex", | 200 | "demultiplex", |
201 | gettext_noop( | 201 | gettext_noop ( |
202 | "use DHT's demultiplex everywhere option"), | 202 | "use DHT's demultiplex everywhere option"), |
203 | &demultixplex_everywhere), | 203 | &demultixplex_everywhere), |
204 | GNUNET_GETOPT_option_uint('r', | 204 | GNUNET_GETOPT_option_uint ('r', |
205 | "replication", | 205 | "replication", |
206 | "LEVEL", | 206 | "LEVEL", |
207 | gettext_noop("how many replicas to create"), | 207 | gettext_noop ("how many replicas to create"), |
208 | &replication), | 208 | &replication), |
209 | GNUNET_GETOPT_option_flag('R', | 209 | GNUNET_GETOPT_option_flag ('R', |
210 | "record", | 210 | "record", |
211 | gettext_noop("use DHT's record route option"), | 211 | gettext_noop ("use DHT's record route option"), |
212 | &record_route), | 212 | &record_route), |
213 | GNUNET_GETOPT_option_uint('t', | 213 | GNUNET_GETOPT_option_uint ('t', |
214 | "type", | 214 | "type", |
215 | "TYPE", | 215 | "TYPE", |
216 | gettext_noop("the type to insert data as"), | 216 | gettext_noop ("the type to insert data as"), |
217 | &query_type), | 217 | &query_type), |
218 | GNUNET_GETOPT_option_verbose(&verbose), | 218 | GNUNET_GETOPT_option_verbose (&verbose), |
219 | GNUNET_GETOPT_OPTION_END }; | 219 | GNUNET_GETOPT_OPTION_END }; |
220 | 220 | ||
221 | 221 | ||
222 | 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)) |
223 | return 2; | 223 | return 2; |
224 | expiration = GNUNET_TIME_UNIT_HOURS; | 224 | expiration = GNUNET_TIME_UNIT_HOURS; |
225 | return (GNUNET_OK == | 225 | return (GNUNET_OK == |
226 | GNUNET_PROGRAM_run( | 226 | GNUNET_PROGRAM_run ( |
227 | argc, | 227 | argc, |
228 | argv, | 228 | argv, |
229 | "gnunet-dht-put", | 229 | "gnunet-dht-put", |
230 | gettext_noop( | 230 | gettext_noop ( |
231 | "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."), |
232 | options, | 232 | options, |
233 | &run, | 233 | &run, |
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index c1e4c03b0..380002deb 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/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 | */ |
68 | static void | 68 | static void |
69 | process_hello(void *cls, | 69 | process_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 | */ |
85 | static void | 85 | static void |
86 | shutdown_task(void *cls) | 86 | shutdown_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,45 +120,45 @@ shutdown_task(void *cls) | |||
120 | * @param service the initialized service | 120 | * @param service the initialized service |
121 | */ | 121 | */ |
122 | static void | 122 | static void |
123 | run(void *cls, | 123 | run (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 | ||
160 | /* Finally, define the main method */ | 160 | /* Finally, define the main method */ |
161 | GDS_DHT_SERVICE_INIT("dht", &run); | 161 | GDS_DHT_SERVICE_INIT ("dht", &run); |
162 | 162 | ||
163 | 163 | ||
164 | 164 | ||
diff --git a/src/dht/gnunet-service-dht.h b/src/dht/gnunet-service-dht.h index caf9dcbe8..2574edc7b 100644 --- a/src/dht/gnunet-service-dht.h +++ b/src/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 | */ |
78 | void | 78 | void |
79 | GDS_CLIENTS_handle_reply(struct GNUNET_TIME_Absolute expiration, | 79 | GDS_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 | */ |
102 | void | 102 | void |
103 | GDS_CLIENTS_process_get(uint32_t options, | 103 | GDS_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 | */ |
126 | void | 126 | void |
127 | GDS_CLIENTS_process_get_resp(enum GNUNET_BLOCK_Type type, | 127 | GDS_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 | */ |
153 | void | 153 | void |
154 | GDS_CLIENTS_process_put(uint32_t options, | 154 | GDS_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 48017bfb4..932b04d9b 100644 --- a/src/dht/gnunet-service-dht_clients.c +++ b/src/dht/gnunet-service-dht_clients.c | |||
@@ -38,9 +38,10 @@ | |||
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", \ |
42 | __VA_ARGS__) | ||
42 | 43 | ||
43 | #define LOG(kind, ...) GNUNET_log_from(kind, "dht-clients", __VA_ARGS__) | 44 | #define LOG(kind, ...) GNUNET_log_from (kind, "dht-clients", __VA_ARGS__) |
44 | 45 | ||
45 | 46 | ||
46 | /** | 47 | /** |
@@ -54,7 +55,8 @@ struct ClientHandle; | |||
54 | /** | 55 | /** |
55 | * Entry in the local forwarding map for a client's GET request. | 56 | * Entry in the local forwarding map for a client's GET request. |
56 | */ | 57 | */ |
57 | struct ClientQueryRecord { | 58 | struct ClientQueryRecord |
59 | { | ||
58 | /** | 60 | /** |
59 | * The key this request was about | 61 | * The key this request was about |
60 | */ | 62 | */ |
@@ -136,7 +138,8 @@ struct ClientQueryRecord { | |||
136 | /** | 138 | /** |
137 | * Struct containing paremeters of monitoring requests. | 139 | * Struct containing paremeters of monitoring requests. |
138 | */ | 140 | */ |
139 | struct ClientMonitorRecord { | 141 | struct ClientMonitorRecord |
142 | { | ||
140 | /** | 143 | /** |
141 | * Next element in DLL. | 144 | * Next element in DLL. |
142 | */ | 145 | */ |
@@ -184,7 +187,8 @@ struct ClientMonitorRecord { | |||
184 | * handle to connect to it, and any pending messages | 187 | * handle to connect to it, and any pending messages |
185 | * that need to be sent to it. | 188 | * that need to be sent to it. |
186 | */ | 189 | */ |
187 | struct ClientHandle { | 190 | struct ClientHandle |
191 | { | ||
188 | /** | 192 | /** |
189 | * Linked list of active queries of this client. | 193 | * Linked list of active queries of this client. |
190 | */ | 194 | */ |
@@ -258,23 +262,23 @@ static struct GNUNET_SCHEDULER_Task *retry_task; | |||
258 | * @param record record to remove | 262 | * @param record record to remove |
259 | */ | 263 | */ |
260 | static void | 264 | static void |
261 | remove_client_record(struct ClientQueryRecord *record) | 265 | remove_client_record (struct ClientQueryRecord *record) |
262 | { | 266 | { |
263 | struct ClientHandle *ch = record->ch; | 267 | struct ClientHandle *ch = record->ch; |
264 | 268 | ||
265 | GNUNET_CONTAINER_DLL_remove(ch->cqr_head, | 269 | GNUNET_CONTAINER_DLL_remove (ch->cqr_head, |
266 | ch->cqr_tail, | 270 | ch->cqr_tail, |
267 | record); | 271 | record); |
268 | GNUNET_assert(GNUNET_YES == | 272 | GNUNET_assert (GNUNET_YES == |
269 | GNUNET_CONTAINER_multihashmap_remove(forward_map, | 273 | GNUNET_CONTAINER_multihashmap_remove (forward_map, |
270 | &record->key, | 274 | &record->key, |
271 | record)); | 275 | record)); |
272 | if (NULL != record->hnode) | 276 | if (NULL != record->hnode) |
273 | GNUNET_CONTAINER_heap_remove_node(record->hnode); | 277 | GNUNET_CONTAINER_heap_remove_node (record->hnode); |
274 | GNUNET_array_grow(record->seen_replies, | 278 | GNUNET_array_grow (record->seen_replies, |
275 | record->seen_replies_count, | 279 | record->seen_replies_count, |
276 | 0); | 280 | 0); |
277 | GNUNET_free(record); | 281 | GNUNET_free (record); |
278 | } | 282 | } |
279 | 283 | ||
280 | 284 | ||
@@ -288,13 +292,13 @@ remove_client_record(struct ClientQueryRecord *record) | |||
288 | * @return our `struct ClientHandle` for @a client | 292 | * @return our `struct ClientHandle` for @a client |
289 | */ | 293 | */ |
290 | static void * | 294 | static void * |
291 | client_connect_cb(void *cls, | 295 | client_connect_cb (void *cls, |
292 | struct GNUNET_SERVICE_Client *client, | 296 | struct GNUNET_SERVICE_Client *client, |
293 | struct GNUNET_MQ_Handle *mq) | 297 | struct GNUNET_MQ_Handle *mq) |
294 | { | 298 | { |
295 | struct ClientHandle *ch; | 299 | struct ClientHandle *ch; |
296 | 300 | ||
297 | ch = GNUNET_new(struct ClientHandle); | 301 | ch = GNUNET_new (struct ClientHandle); |
298 | ch->client = client; | 302 | ch->client = client; |
299 | ch->mq = mq; | 303 | ch->mq = mq; |
300 | return ch; | 304 | return ch; |
@@ -310,40 +314,40 @@ client_connect_cb(void *cls, | |||
310 | * @param app_ctx our `struct ClientHandle` for @a client | 314 | * @param app_ctx our `struct ClientHandle` for @a client |
311 | */ | 315 | */ |
312 | static void | 316 | static void |
313 | client_disconnect_cb(void *cls, | 317 | client_disconnect_cb (void *cls, |
314 | struct GNUNET_SERVICE_Client *client, | 318 | struct GNUNET_SERVICE_Client *client, |
315 | void *app_ctx) | 319 | void *app_ctx) |
316 | { | 320 | { |
317 | struct ClientHandle *ch = app_ctx; | 321 | struct ClientHandle *ch = app_ctx; |
318 | struct ClientQueryRecord *cqr; | 322 | struct ClientQueryRecord *cqr; |
319 | struct ClientMonitorRecord *monitor; | 323 | struct ClientMonitorRecord *monitor; |
320 | 324 | ||
321 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 325 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
322 | "Local client %p disconnects\n", | 326 | "Local client %p disconnects\n", |
323 | ch); | 327 | ch); |
324 | monitor = monitor_head; | 328 | monitor = monitor_head; |
325 | while (NULL != monitor) | 329 | while (NULL != monitor) |
330 | { | ||
331 | if (monitor->ch == ch) | ||
326 | { | 332 | { |
327 | if (monitor->ch == ch) | 333 | struct ClientMonitorRecord *next; |
328 | { | 334 | |
329 | struct ClientMonitorRecord *next; | 335 | next = monitor->next; |
330 | 336 | GNUNET_free_non_null (monitor->key); | |
331 | next = monitor->next; | 337 | GNUNET_CONTAINER_DLL_remove (monitor_head, |
332 | GNUNET_free_non_null(monitor->key); | 338 | monitor_tail, |
333 | GNUNET_CONTAINER_DLL_remove(monitor_head, | 339 | monitor); |
334 | monitor_tail, | 340 | GNUNET_free (monitor); |
335 | monitor); | 341 | monitor = next; |
336 | GNUNET_free(monitor); | ||
337 | monitor = next; | ||
338 | } | ||
339 | else | ||
340 | { | ||
341 | monitor = monitor->next; | ||
342 | } | ||
343 | } | 342 | } |
343 | else | ||
344 | { | ||
345 | monitor = monitor->next; | ||
346 | } | ||
347 | } | ||
344 | while (NULL != (cqr = ch->cqr_head)) | 348 | while (NULL != (cqr = ch->cqr_head)) |
345 | remove_client_record(cqr); | 349 | remove_client_record (cqr); |
346 | GNUNET_free(ch); | 350 | GNUNET_free (ch); |
347 | } | 351 | } |
348 | 352 | ||
349 | 353 | ||
@@ -353,52 +357,54 @@ client_disconnect_cb(void *cls, | |||
353 | * message and initiating the routing operation. | 357 | * message and initiating the routing operation. |
354 | */ | 358 | */ |
355 | static void | 359 | static void |
356 | transmit_request(struct ClientQueryRecord *cqr) | 360 | transmit_request (struct ClientQueryRecord *cqr) |
357 | { | 361 | { |
358 | struct GNUNET_BLOCK_Group *bg; | 362 | struct GNUNET_BLOCK_Group *bg; |
359 | struct GNUNET_CONTAINER_BloomFilter *peer_bf; | 363 | struct GNUNET_CONTAINER_BloomFilter *peer_bf; |
360 | 364 | ||
361 | GNUNET_STATISTICS_update(GDS_stats, | 365 | GNUNET_STATISTICS_update (GDS_stats, |
362 | gettext_noop("# GET requests from clients injected"), | 366 | gettext_noop ( |
363 | 1, | 367 | "# GET requests from clients injected"), |
364 | GNUNET_NO); | 368 | 1, |
365 | bg = GNUNET_BLOCK_group_create(GDS_block_context, | 369 | GNUNET_NO); |
366 | cqr->type, | 370 | bg = GNUNET_BLOCK_group_create (GDS_block_context, |
367 | GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | 371 | cqr->type, |
368 | UINT32_MAX), | 372 | GNUNET_CRYPTO_random_u32 ( |
369 | NULL, | 373 | GNUNET_CRYPTO_QUALITY_WEAK, |
370 | 0, | 374 | UINT32_MAX), |
371 | "seen-set-size", | 375 | NULL, |
372 | cqr->seen_replies_count, | 376 | 0, |
373 | NULL); | 377 | "seen-set-size", |
374 | GNUNET_BLOCK_group_set_seen(bg, | 378 | cqr->seen_replies_count, |
375 | cqr->seen_replies, | 379 | NULL); |
376 | cqr->seen_replies_count); | 380 | GNUNET_BLOCK_group_set_seen (bg, |
381 | cqr->seen_replies, | ||
382 | cqr->seen_replies_count); | ||
377 | peer_bf | 383 | peer_bf |
378 | = GNUNET_CONTAINER_bloomfilter_init(NULL, | 384 | = GNUNET_CONTAINER_bloomfilter_init (NULL, |
379 | DHT_BLOOM_SIZE, | 385 | DHT_BLOOM_SIZE, |
380 | GNUNET_CONSTANTS_BLOOMFILTER_K); | 386 | GNUNET_CONSTANTS_BLOOMFILTER_K); |
381 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 387 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
382 | "Initiating GET for %s, replication %u, already have %u replies\n", | 388 | "Initiating GET for %s, replication %u, already have %u replies\n", |
383 | GNUNET_h2s(&cqr->key), | 389 | GNUNET_h2s (&cqr->key), |
384 | cqr->replication, | 390 | cqr->replication, |
385 | cqr->seen_replies_count); | 391 | cqr->seen_replies_count); |
386 | GDS_NEIGHBOURS_handle_get(cqr->type, | 392 | GDS_NEIGHBOURS_handle_get (cqr->type, |
387 | cqr->msg_options, | 393 | cqr->msg_options, |
388 | cqr->replication, | 394 | cqr->replication, |
389 | 0 /* hop count */, | 395 | 0 /* hop count */, |
390 | &cqr->key, | 396 | &cqr->key, |
391 | cqr->xquery, | 397 | cqr->xquery, |
392 | cqr->xquery_size, | 398 | cqr->xquery_size, |
393 | bg, | 399 | bg, |
394 | peer_bf); | 400 | peer_bf); |
395 | GNUNET_BLOCK_group_destroy(bg); | 401 | GNUNET_BLOCK_group_destroy (bg); |
396 | GNUNET_CONTAINER_bloomfilter_free(peer_bf); | 402 | GNUNET_CONTAINER_bloomfilter_free (peer_bf); |
397 | 403 | ||
398 | /* exponential back-off for retries. | 404 | /* exponential back-off for retries. |
399 | * max GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD (15 min) */ | 405 | * max GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD (15 min) */ |
400 | cqr->retry_frequency = GNUNET_TIME_STD_BACKOFF(cqr->retry_frequency); | 406 | cqr->retry_frequency = GNUNET_TIME_STD_BACKOFF (cqr->retry_frequency); |
401 | cqr->retry_time = GNUNET_TIME_relative_to_absolute(cqr->retry_frequency); | 407 | cqr->retry_time = GNUNET_TIME_relative_to_absolute (cqr->retry_frequency); |
402 | } | 408 | } |
403 | 409 | ||
404 | 410 | ||
@@ -410,34 +416,34 @@ transmit_request(struct ClientQueryRecord *cqr) | |||
410 | * @param cls unused | 416 | * @param cls unused |
411 | */ | 417 | */ |
412 | static void | 418 | static void |
413 | transmit_next_request_task(void *cls) | 419 | transmit_next_request_task (void *cls) |
414 | { | 420 | { |
415 | struct ClientQueryRecord *cqr; | 421 | struct ClientQueryRecord *cqr; |
416 | struct GNUNET_TIME_Relative delay; | 422 | struct GNUNET_TIME_Relative delay; |
417 | 423 | ||
418 | retry_task = NULL; | 424 | retry_task = NULL; |
419 | while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root(retry_heap))) | 425 | while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root (retry_heap))) |
426 | { | ||
427 | cqr->hnode = NULL; | ||
428 | delay = GNUNET_TIME_absolute_get_remaining (cqr->retry_time); | ||
429 | if (delay.rel_value_us > 0) | ||
420 | { | 430 | { |
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); | ||
436 | cqr->hnode | 431 | cqr->hnode |
437 | = GNUNET_CONTAINER_heap_insert(retry_heap, | 432 | = GNUNET_CONTAINER_heap_insert (retry_heap, |
438 | cqr, | 433 | cqr, |
439 | cqr->retry_time.abs_value_us); | 434 | cqr->retry_time.abs_value_us); |
435 | retry_task | ||
436 | = GNUNET_SCHEDULER_add_at (cqr->retry_time, | ||
437 | &transmit_next_request_task, | ||
438 | NULL); | ||
439 | return; | ||
440 | } | 440 | } |
441 | transmit_request (cqr); | ||
442 | cqr->hnode | ||
443 | = GNUNET_CONTAINER_heap_insert (retry_heap, | ||
444 | cqr, | ||
445 | cqr->retry_time.abs_value_us); | ||
446 | } | ||
441 | } | 447 | } |
442 | 448 | ||
443 | 449 | ||
@@ -449,8 +455,8 @@ transmit_next_request_task(void *cls) | |||
449 | * @return #GNUNET_OK (always) | 455 | * @return #GNUNET_OK (always) |
450 | */ | 456 | */ |
451 | static int | 457 | static int |
452 | check_dht_local_put(void *cls, | 458 | check_dht_local_put (void *cls, |
453 | const struct GNUNET_DHT_ClientPutMessage *dht_msg) | 459 | const struct GNUNET_DHT_ClientPutMessage *dht_msg) |
454 | { | 460 | { |
455 | /* always well-formed */ | 461 | /* always well-formed */ |
456 | return GNUNET_OK; | 462 | return GNUNET_OK; |
@@ -464,71 +470,72 @@ check_dht_local_put(void *cls, | |||
464 | * @param dht_msg the actual message received | 470 | * @param dht_msg the actual message received |
465 | */ | 471 | */ |
466 | static void | 472 | static void |
467 | handle_dht_local_put(void *cls, | 473 | handle_dht_local_put (void *cls, |
468 | const struct GNUNET_DHT_ClientPutMessage *dht_msg) | 474 | const struct GNUNET_DHT_ClientPutMessage *dht_msg) |
469 | { | 475 | { |
470 | struct ClientHandle *ch = cls; | 476 | struct ClientHandle *ch = cls; |
471 | struct GNUNET_CONTAINER_BloomFilter *peer_bf; | 477 | struct GNUNET_CONTAINER_BloomFilter *peer_bf; |
472 | uint16_t size; | 478 | uint16_t size; |
473 | 479 | ||
474 | size = ntohs(dht_msg->header.size); | 480 | size = ntohs (dht_msg->header.size); |
475 | GNUNET_STATISTICS_update(GDS_stats, | 481 | GNUNET_STATISTICS_update (GDS_stats, |
476 | gettext_noop("# PUT requests received from clients"), | 482 | gettext_noop ( |
477 | 1, | 483 | "# PUT requests received from clients"), |
478 | GNUNET_NO); | 484 | 1, |
479 | LOG_TRAFFIC(GNUNET_ERROR_TYPE_DEBUG, | 485 | GNUNET_NO); |
480 | "CLIENT-PUT %s\n", | 486 | LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, |
481 | GNUNET_h2s_full(&dht_msg->key)); | 487 | "CLIENT-PUT %s\n", |
488 | GNUNET_h2s_full (&dht_msg->key)); | ||
482 | /* give to local clients */ | 489 | /* give to local clients */ |
483 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 490 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
484 | "Handling local PUT of %u-bytes for query %s\n", | 491 | "Handling local PUT of %u-bytes for query %s\n", |
485 | size - sizeof(struct GNUNET_DHT_ClientPutMessage), | 492 | size - sizeof(struct GNUNET_DHT_ClientPutMessage), |
486 | GNUNET_h2s(&dht_msg->key)); | 493 | GNUNET_h2s (&dht_msg->key)); |
487 | GDS_CLIENTS_handle_reply(GNUNET_TIME_absolute_ntoh(dht_msg->expiration), | 494 | GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (dht_msg->expiration), |
488 | &dht_msg->key, | 495 | &dht_msg->key, |
489 | 0, | 496 | 0, |
490 | NULL, | 497 | NULL, |
491 | 0, | 498 | 0, |
492 | NULL, | 499 | NULL, |
493 | ntohl(dht_msg->type), | 500 | ntohl (dht_msg->type), |
494 | size - sizeof(struct GNUNET_DHT_ClientPutMessage), | 501 | size - sizeof(struct GNUNET_DHT_ClientPutMessage), |
495 | &dht_msg[1]); | 502 | &dht_msg[1]); |
496 | /* store locally */ | 503 | /* store locally */ |
497 | GDS_DATACACHE_handle_put(GNUNET_TIME_absolute_ntoh(dht_msg->expiration), | 504 | 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, | ||
515 | &dht_msg->key, | 505 | &dht_msg->key, |
516 | 0, | 506 | 0, |
517 | NULL, | 507 | NULL, |
518 | &dht_msg[1], | 508 | ntohl (dht_msg->type), |
519 | size - sizeof(struct GNUNET_DHT_ClientPutMessage)); | 509 | size - sizeof(struct GNUNET_DHT_ClientPutMessage), |
520 | GDS_CLIENTS_process_put(ntohl(dht_msg->options), | 510 | &dht_msg[1]); |
521 | ntohl(dht_msg->type), | 511 | /* route to other peers */ |
522 | 0, | 512 | peer_bf |
523 | ntohl(dht_msg->desired_replication_level), | 513 | = GNUNET_CONTAINER_bloomfilter_init (NULL, |
524 | 1, | 514 | DHT_BLOOM_SIZE, |
525 | GDS_NEIGHBOURS_get_id(), | 515 | GNUNET_CONSTANTS_BLOOMFILTER_K); |
526 | GNUNET_TIME_absolute_ntoh(dht_msg->expiration), | 516 | GDS_NEIGHBOURS_handle_put (ntohl (dht_msg->type), |
527 | &dht_msg->key, | 517 | ntohl (dht_msg->options), |
528 | &dht_msg[1], | 518 | ntohl (dht_msg->desired_replication_level), |
529 | size - sizeof(struct GNUNET_DHT_ClientPutMessage)); | 519 | GNUNET_TIME_absolute_ntoh (dht_msg->expiration), |
530 | GNUNET_CONTAINER_bloomfilter_free(peer_bf); | 520 | 0 /* hop count */, |
531 | GNUNET_SERVICE_client_continue(ch->client); | 521 | peer_bf, |
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); | ||
532 | } | 539 | } |
533 | 540 | ||
534 | 541 | ||
@@ -540,8 +547,8 @@ handle_dht_local_put(void *cls, | |||
540 | * @return #GNUNET_OK (always) | 547 | * @return #GNUNET_OK (always) |
541 | */ | 548 | */ |
542 | static int | 549 | static int |
543 | check_dht_local_get(void *cls, | 550 | check_dht_local_get (void *cls, |
544 | const struct GNUNET_DHT_ClientGetMessage *get) | 551 | const struct GNUNET_DHT_ClientGetMessage *get) |
545 | { | 552 | { |
546 | /* always well-formed */ | 553 | /* always well-formed */ |
547 | return GNUNET_OK; | 554 | return GNUNET_OK; |
@@ -563,25 +570,25 @@ check_dht_local_get(void *cls, | |||
563 | * @param data_size number of bytes in @a data | 570 | * @param data_size number of bytes in @a data |
564 | */ | 571 | */ |
565 | static void | 572 | static void |
566 | handle_local_result(void *cls, | 573 | handle_local_result (void *cls, |
567 | enum GNUNET_BLOCK_Type type, | 574 | enum GNUNET_BLOCK_Type type, |
568 | struct GNUNET_TIME_Absolute expiration_time, | 575 | struct GNUNET_TIME_Absolute expiration_time, |
569 | const struct GNUNET_HashCode *key, | 576 | const struct GNUNET_HashCode *key, |
570 | unsigned int put_path_length, | 577 | unsigned int put_path_length, |
571 | const struct GNUNET_PeerIdentity *put_path, | 578 | const struct GNUNET_PeerIdentity *put_path, |
572 | unsigned int get_path_length, | 579 | unsigned int get_path_length, |
573 | const struct GNUNET_PeerIdentity *get_path, | 580 | const struct GNUNET_PeerIdentity *get_path, |
574 | const void *data, | 581 | const void *data, |
575 | size_t data_size) | 582 | size_t data_size) |
576 | { | 583 | { |
577 | // FIXME: this needs some clean up: inline the function, | 584 | // FIXME: this needs some clean up: inline the function, |
578 | // possibly avoid even looking up the client! | 585 | // possibly avoid even looking up the client! |
579 | GDS_CLIENTS_handle_reply(expiration_time, | 586 | GDS_CLIENTS_handle_reply (expiration_time, |
580 | key, | 587 | key, |
581 | 0, NULL, | 588 | 0, NULL, |
582 | put_path_length, put_path, | 589 | put_path_length, put_path, |
583 | type, | 590 | type, |
584 | data_size, data); | 591 | data_size, data); |
585 | } | 592 | } |
586 | 593 | ||
587 | 594 | ||
@@ -592,8 +599,8 @@ handle_local_result(void *cls, | |||
592 | * @param message the actual message received | 599 | * @param message the actual message received |
593 | */ | 600 | */ |
594 | static void | 601 | static void |
595 | handle_dht_local_get(void *cls, | 602 | handle_dht_local_get (void *cls, |
596 | const struct GNUNET_DHT_ClientGetMessage *get) | 603 | const struct GNUNET_DHT_ClientGetMessage *get) |
597 | { | 604 | { |
598 | struct ClientHandle *ch = cls; | 605 | struct ClientHandle *ch = cls; |
599 | struct ClientQueryRecord *cqr; | 606 | struct ClientQueryRecord *cqr; |
@@ -601,71 +608,72 @@ handle_dht_local_get(void *cls, | |||
601 | const char *xquery; | 608 | const char *xquery; |
602 | uint16_t size; | 609 | uint16_t size; |
603 | 610 | ||
604 | size = ntohs(get->header.size); | 611 | size = ntohs (get->header.size); |
605 | xquery_size = size - sizeof(struct GNUNET_DHT_ClientGetMessage); | 612 | xquery_size = size - sizeof(struct GNUNET_DHT_ClientGetMessage); |
606 | xquery = (const char *)&get[1]; | 613 | xquery = (const char *) &get[1]; |
607 | GNUNET_STATISTICS_update(GDS_stats, | 614 | GNUNET_STATISTICS_update (GDS_stats, |
608 | gettext_noop | 615 | gettext_noop |
609 | ("# GET requests received from clients"), 1, | 616 | ("# GET requests received from clients"), 1, |
610 | GNUNET_NO); | 617 | GNUNET_NO); |
611 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 618 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
612 | "Received GET request for %s from local client %p, xq: %.*s\n", | 619 | "Received GET request for %s from local client %p, xq: %.*s\n", |
613 | GNUNET_h2s(&get->key), | 620 | GNUNET_h2s (&get->key), |
614 | ch->client, | 621 | ch->client, |
615 | xquery_size, | 622 | xquery_size, |
616 | xquery); | 623 | xquery); |
617 | LOG_TRAFFIC(GNUNET_ERROR_TYPE_DEBUG, | 624 | LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, |
618 | "CLIENT-GET %s\n", | 625 | "CLIENT-GET %s\n", |
619 | GNUNET_h2s_full(&get->key)); | 626 | GNUNET_h2s_full (&get->key)); |
620 | 627 | ||
621 | cqr = GNUNET_malloc(sizeof(struct ClientQueryRecord) + xquery_size); | 628 | cqr = GNUNET_malloc (sizeof(struct ClientQueryRecord) + xquery_size); |
622 | cqr->key = get->key; | 629 | cqr->key = get->key; |
623 | cqr->ch = ch; | 630 | cqr->ch = ch; |
624 | cqr->xquery = (void *)&cqr[1]; | 631 | cqr->xquery = (void *) &cqr[1]; |
625 | GNUNET_memcpy(&cqr[1], xquery, xquery_size); | 632 | GNUNET_memcpy (&cqr[1], xquery, xquery_size); |
626 | cqr->hnode = GNUNET_CONTAINER_heap_insert(retry_heap, cqr, 0); | 633 | cqr->hnode = GNUNET_CONTAINER_heap_insert (retry_heap, cqr, 0); |
627 | cqr->retry_frequency = GNUNET_TIME_UNIT_SECONDS; | 634 | cqr->retry_frequency = GNUNET_TIME_UNIT_SECONDS; |
628 | cqr->retry_time = GNUNET_TIME_absolute_get(); | 635 | cqr->retry_time = GNUNET_TIME_absolute_get (); |
629 | cqr->unique_id = get->unique_id; | 636 | cqr->unique_id = get->unique_id; |
630 | cqr->xquery_size = xquery_size; | 637 | cqr->xquery_size = xquery_size; |
631 | cqr->replication = ntohl(get->desired_replication_level); | 638 | cqr->replication = ntohl (get->desired_replication_level); |
632 | cqr->msg_options = ntohl(get->options); | 639 | cqr->msg_options = ntohl (get->options); |
633 | cqr->type = ntohl(get->type); | 640 | cqr->type = ntohl (get->type); |
634 | GNUNET_CONTAINER_DLL_insert(ch->cqr_head, | 641 | GNUNET_CONTAINER_DLL_insert (ch->cqr_head, |
635 | ch->cqr_tail, | 642 | ch->cqr_tail, |
636 | cqr); | 643 | cqr); |
637 | GNUNET_CONTAINER_multihashmap_put(forward_map, | 644 | GNUNET_CONTAINER_multihashmap_put (forward_map, |
638 | &cqr->key, | 645 | &cqr->key, |
639 | cqr, | 646 | cqr, |
640 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 647 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
641 | GDS_CLIENTS_process_get(ntohl(get->options), | 648 | GDS_CLIENTS_process_get (ntohl (get->options), |
642 | ntohl(get->type), | 649 | ntohl (get->type), |
643 | 0, | 650 | 0, |
644 | ntohl(get->desired_replication_level), | 651 | ntohl (get->desired_replication_level), |
645 | 1, | 652 | 1, |
646 | GDS_NEIGHBOURS_get_id(), | 653 | GDS_NEIGHBOURS_get_id (), |
647 | &get->key); | 654 | &get->key); |
648 | /* start remote requests */ | 655 | /* start remote requests */ |
649 | if (NULL != retry_task) | 656 | if (NULL != retry_task) |
650 | GNUNET_SCHEDULER_cancel(retry_task); | 657 | GNUNET_SCHEDULER_cancel (retry_task); |
651 | retry_task = GNUNET_SCHEDULER_add_now(&transmit_next_request_task, | 658 | retry_task = GNUNET_SCHEDULER_add_now (&transmit_next_request_task, |
652 | NULL); | 659 | NULL); |
653 | /* perform local lookup */ | 660 | /* perform local lookup */ |
654 | GDS_DATACACHE_handle_get(&get->key, | 661 | GDS_DATACACHE_handle_get (&get->key, |
655 | cqr->type, | 662 | cqr->type, |
656 | cqr->xquery, | 663 | cqr->xquery, |
657 | xquery_size, | 664 | xquery_size, |
658 | NULL, | 665 | NULL, |
659 | &handle_local_result, | 666 | &handle_local_result, |
660 | ch); | 667 | ch); |
661 | GNUNET_SERVICE_client_continue(ch->client); | 668 | GNUNET_SERVICE_client_continue (ch->client); |
662 | } | 669 | } |
663 | 670 | ||
664 | 671 | ||
665 | /** | 672 | /** |
666 | * Closure for #find_by_unique_id(). | 673 | * Closure for #find_by_unique_id(). |
667 | */ | 674 | */ |
668 | struct FindByUniqueIdContext { | 675 | struct FindByUniqueIdContext |
676 | { | ||
669 | /** | 677 | /** |
670 | * Where to store the result, if found. | 678 | * Where to store the result, if found. |
671 | */ | 679 | */ |
@@ -686,9 +694,9 @@ struct FindByUniqueIdContext { | |||
686 | * @return #GNUNET_YES to continue iteration (result not yet found) | 694 | * @return #GNUNET_YES to continue iteration (result not yet found) |
687 | */ | 695 | */ |
688 | static int | 696 | static int |
689 | find_by_unique_id(void *cls, | 697 | find_by_unique_id (void *cls, |
690 | const struct GNUNET_HashCode *key, | 698 | const struct GNUNET_HashCode *key, |
691 | void *value) | 699 | void *value) |
692 | { | 700 | { |
693 | struct FindByUniqueIdContext *fui_ctx = cls; | 701 | struct FindByUniqueIdContext *fui_ctx = cls; |
694 | struct ClientQueryRecord *cqr = value; | 702 | struct ClientQueryRecord *cqr = value; |
@@ -708,19 +716,22 @@ find_by_unique_id(void *cls, | |||
708 | * @return #GNUNET_OK if @a seen is well-formed | 716 | * @return #GNUNET_OK if @a seen is well-formed |
709 | */ | 717 | */ |
710 | static int | 718 | static int |
711 | check_dht_local_get_result_seen(void *cls, | 719 | check_dht_local_get_result_seen (void *cls, |
712 | const struct GNUNET_DHT_ClientGetResultSeenMessage *seen) | 720 | const struct |
721 | GNUNET_DHT_ClientGetResultSeenMessage *seen) | ||
713 | { | 722 | { |
714 | uint16_t size; | 723 | uint16_t size; |
715 | unsigned int hash_count; | 724 | unsigned int hash_count; |
716 | 725 | ||
717 | size = ntohs(seen->header.size); | 726 | size = ntohs (seen->header.size); |
718 | hash_count = (size - sizeof(struct GNUNET_DHT_ClientGetResultSeenMessage)) / sizeof(struct GNUNET_HashCode); | 727 | hash_count = (size - sizeof(struct GNUNET_DHT_ClientGetResultSeenMessage)) |
719 | if (size != sizeof(struct GNUNET_DHT_ClientGetResultSeenMessage) + hash_count * sizeof(struct GNUNET_HashCode)) | 728 | / sizeof(struct GNUNET_HashCode); |
720 | { | 729 | if (size != sizeof(struct GNUNET_DHT_ClientGetResultSeenMessage) |
721 | GNUNET_break(0); | 730 | + hash_count * sizeof(struct GNUNET_HashCode)) |
722 | return GNUNET_SYSERR; | 731 | { |
723 | } | 732 | GNUNET_break (0); |
733 | return GNUNET_SYSERR; | ||
734 | } | ||
724 | return GNUNET_OK; | 735 | return GNUNET_OK; |
725 | } | 736 | } |
726 | 737 | ||
@@ -732,8 +743,9 @@ check_dht_local_get_result_seen(void *cls, | |||
732 | * @param message the actual message received | 743 | * @param message the actual message received |
733 | */ | 744 | */ |
734 | static void | 745 | static void |
735 | handle_dht_local_get_result_seen(void *cls, | 746 | handle_dht_local_get_result_seen (void *cls, |
736 | const struct GNUNET_DHT_ClientGetResultSeenMessage *seen) | 747 | const struct |
748 | GNUNET_DHT_ClientGetResultSeenMessage *seen) | ||
737 | { | 749 | { |
738 | struct ClientHandle *ch = cls; | 750 | struct ClientHandle *ch = cls; |
739 | uint16_t size; | 751 | uint16_t size; |
@@ -743,36 +755,38 @@ handle_dht_local_get_result_seen(void *cls, | |||
743 | struct FindByUniqueIdContext fui_ctx; | 755 | struct FindByUniqueIdContext fui_ctx; |
744 | struct ClientQueryRecord *cqr; | 756 | struct ClientQueryRecord *cqr; |
745 | 757 | ||
746 | size = ntohs(seen->header.size); | 758 | size = ntohs (seen->header.size); |
747 | hash_count = (size - sizeof(struct GNUNET_DHT_ClientGetResultSeenMessage)) / sizeof(struct GNUNET_HashCode); | 759 | hash_count = (size - sizeof(struct GNUNET_DHT_ClientGetResultSeenMessage)) |
748 | hc = (const struct GNUNET_HashCode*)&seen[1]; | 760 | / sizeof(struct GNUNET_HashCode); |
761 | hc = (const struct GNUNET_HashCode*) &seen[1]; | ||
749 | fui_ctx.unique_id = seen->unique_id; | 762 | fui_ctx.unique_id = seen->unique_id; |
750 | fui_ctx.cqr = NULL; | 763 | fui_ctx.cqr = NULL; |
751 | GNUNET_CONTAINER_multihashmap_get_multiple(forward_map, | 764 | GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, |
752 | &seen->key, | 765 | &seen->key, |
753 | &find_by_unique_id, | 766 | &find_by_unique_id, |
754 | &fui_ctx); | 767 | &fui_ctx); |
755 | if (NULL == (cqr = fui_ctx.cqr)) | 768 | if (NULL == (cqr = fui_ctx.cqr)) |
756 | { | 769 | { |
757 | GNUNET_break(0); | 770 | GNUNET_break (0); |
758 | GNUNET_SERVICE_client_drop(ch->client); | 771 | GNUNET_SERVICE_client_drop (ch->client); |
759 | return; | 772 | return; |
760 | } | 773 | } |
761 | /* finally, update 'seen' list */ | 774 | /* finally, update 'seen' list */ |
762 | old_count = cqr->seen_replies_count; | 775 | old_count = cqr->seen_replies_count; |
763 | GNUNET_array_grow(cqr->seen_replies, | 776 | GNUNET_array_grow (cqr->seen_replies, |
764 | cqr->seen_replies_count, | 777 | cqr->seen_replies_count, |
765 | cqr->seen_replies_count + hash_count); | 778 | cqr->seen_replies_count + hash_count); |
766 | GNUNET_memcpy(&cqr->seen_replies[old_count], | 779 | GNUNET_memcpy (&cqr->seen_replies[old_count], |
767 | hc, | 780 | hc, |
768 | sizeof(struct GNUNET_HashCode) * hash_count); | 781 | sizeof(struct GNUNET_HashCode) * hash_count); |
769 | } | 782 | } |
770 | 783 | ||
771 | 784 | ||
772 | /** | 785 | /** |
773 | * Closure for #remove_by_unique_id(). | 786 | * Closure for #remove_by_unique_id(). |
774 | */ | 787 | */ |
775 | struct RemoveByUniqueIdContext { | 788 | struct RemoveByUniqueIdContext |
789 | { | ||
776 | /** | 790 | /** |
777 | * Client that issued the removal request. | 791 | * Client that issued the removal request. |
778 | */ | 792 | */ |
@@ -795,20 +809,20 @@ struct RemoveByUniqueIdContext { | |||
795 | * @return #GNUNET_YES (we should continue to iterate) | 809 | * @return #GNUNET_YES (we should continue to iterate) |
796 | */ | 810 | */ |
797 | static int | 811 | static int |
798 | remove_by_unique_id(void *cls, | 812 | remove_by_unique_id (void *cls, |
799 | const struct GNUNET_HashCode *key, | 813 | const struct GNUNET_HashCode *key, |
800 | void *value) | 814 | void *value) |
801 | { | 815 | { |
802 | const struct RemoveByUniqueIdContext *ctx = cls; | 816 | const struct RemoveByUniqueIdContext *ctx = cls; |
803 | struct ClientQueryRecord *cqr = value; | 817 | struct ClientQueryRecord *cqr = value; |
804 | 818 | ||
805 | if (cqr->unique_id != ctx->unique_id) | 819 | if (cqr->unique_id != ctx->unique_id) |
806 | return GNUNET_YES; | 820 | return GNUNET_YES; |
807 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 821 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
808 | "Removing client %p's record for key %s (by unique id)\n", | 822 | "Removing client %p's record for key %s (by unique id)\n", |
809 | ctx->ch->client, | 823 | ctx->ch->client, |
810 | GNUNET_h2s(key)); | 824 | GNUNET_h2s (key)); |
811 | remove_client_record(cqr); | 825 | remove_client_record (cqr); |
812 | return GNUNET_YES; | 826 | return GNUNET_YES; |
813 | } | 827 | } |
814 | 828 | ||
@@ -822,27 +836,28 @@ remove_by_unique_id(void *cls, | |||
822 | * | 836 | * |
823 | */ | 837 | */ |
824 | static void | 838 | static void |
825 | handle_dht_local_get_stop(void *cls, | 839 | handle_dht_local_get_stop (void *cls, |
826 | const struct GNUNET_DHT_ClientGetStopMessage *dht_stop_msg) | 840 | const struct |
841 | GNUNET_DHT_ClientGetStopMessage *dht_stop_msg) | ||
827 | { | 842 | { |
828 | struct ClientHandle *ch = cls; | 843 | struct ClientHandle *ch = cls; |
829 | struct RemoveByUniqueIdContext ctx; | 844 | struct RemoveByUniqueIdContext ctx; |
830 | 845 | ||
831 | GNUNET_STATISTICS_update(GDS_stats, | 846 | GNUNET_STATISTICS_update (GDS_stats, |
832 | gettext_noop | 847 | gettext_noop |
833 | ("# GET STOP requests received from clients"), 1, | 848 | ("# GET STOP requests received from clients"), 1, |
834 | GNUNET_NO); | 849 | GNUNET_NO); |
835 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 850 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
836 | "Received GET STOP request for %s from local client %p\n", | 851 | "Received GET STOP request for %s from local client %p\n", |
837 | GNUNET_h2s(&dht_stop_msg->key), | 852 | GNUNET_h2s (&dht_stop_msg->key), |
838 | ch->client); | 853 | ch->client); |
839 | ctx.ch = ch; | 854 | ctx.ch = ch; |
840 | ctx.unique_id = dht_stop_msg->unique_id; | 855 | ctx.unique_id = dht_stop_msg->unique_id; |
841 | GNUNET_CONTAINER_multihashmap_get_multiple(forward_map, | 856 | GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, |
842 | &dht_stop_msg->key, | 857 | &dht_stop_msg->key, |
843 | &remove_by_unique_id, | 858 | &remove_by_unique_id, |
844 | &ctx); | 859 | &ctx); |
845 | GNUNET_SERVICE_client_continue(ch->client); | 860 | GNUNET_SERVICE_client_continue (ch->client); |
846 | } | 861 | } |
847 | 862 | ||
848 | 863 | ||
@@ -854,33 +869,33 @@ handle_dht_local_get_stop(void *cls, | |||
854 | * | 869 | * |
855 | */ | 870 | */ |
856 | static void | 871 | static void |
857 | handle_dht_local_monitor(void *cls, | 872 | handle_dht_local_monitor (void *cls, |
858 | const struct GNUNET_DHT_MonitorStartStopMessage *msg) | 873 | const struct GNUNET_DHT_MonitorStartStopMessage *msg) |
859 | { | 874 | { |
860 | struct ClientHandle *ch = cls; | 875 | struct ClientHandle *ch = cls; |
861 | struct ClientMonitorRecord *r; | 876 | struct ClientMonitorRecord *r; |
862 | 877 | ||
863 | r = GNUNET_new(struct ClientMonitorRecord); | 878 | r = GNUNET_new (struct ClientMonitorRecord); |
864 | r->ch = ch; | 879 | r->ch = ch; |
865 | r->type = ntohl(msg->type); | 880 | r->type = ntohl (msg->type); |
866 | r->get = ntohs(msg->get); | 881 | r->get = ntohs (msg->get); |
867 | r->get_resp = ntohs(msg->get_resp); | 882 | r->get_resp = ntohs (msg->get_resp); |
868 | r->put = ntohs(msg->put); | 883 | r->put = ntohs (msg->put); |
869 | if (0 == ntohs(msg->filter_key)) | 884 | if (0 == ntohs (msg->filter_key)) |
870 | { | 885 | { |
871 | r->key = NULL; | 886 | r->key = NULL; |
872 | } | 887 | } |
873 | else | 888 | else |
874 | { | 889 | { |
875 | r->key = GNUNET_new(struct GNUNET_HashCode); | 890 | r->key = GNUNET_new (struct GNUNET_HashCode); |
876 | GNUNET_memcpy(r->key, | 891 | GNUNET_memcpy (r->key, |
877 | &msg->key, | 892 | &msg->key, |
878 | sizeof(struct GNUNET_HashCode)); | 893 | sizeof(struct GNUNET_HashCode)); |
879 | } | 894 | } |
880 | GNUNET_CONTAINER_DLL_insert(monitor_head, | 895 | GNUNET_CONTAINER_DLL_insert (monitor_head, |
881 | monitor_tail, | 896 | monitor_tail, |
882 | r); | 897 | r); |
883 | GNUNET_SERVICE_client_continue(ch->client); | 898 | GNUNET_SERVICE_client_continue (ch->client); |
884 | } | 899 | } |
885 | 900 | ||
886 | 901 | ||
@@ -891,49 +906,51 @@ handle_dht_local_monitor(void *cls, | |||
891 | * @param msg the actual message received | 906 | * @param msg the actual message received |
892 | */ | 907 | */ |
893 | static void | 908 | static void |
894 | handle_dht_local_monitor_stop(void *cls, | 909 | handle_dht_local_monitor_stop (void *cls, |
895 | const struct GNUNET_DHT_MonitorStartStopMessage *msg) | 910 | const struct |
911 | GNUNET_DHT_MonitorStartStopMessage *msg) | ||
896 | { | 912 | { |
897 | struct ClientHandle *ch = cls; | 913 | struct ClientHandle *ch = cls; |
898 | struct ClientMonitorRecord *r; | 914 | struct ClientMonitorRecord *r; |
899 | int keys_match; | 915 | int keys_match; |
900 | 916 | ||
901 | GNUNET_SERVICE_client_continue(ch->client); | 917 | GNUNET_SERVICE_client_continue (ch->client); |
902 | for (r = monitor_head; NULL != r; r = r->next) | 918 | for (r = monitor_head; NULL != r; r = r->next) |
919 | { | ||
920 | if (NULL == r->key) | ||
903 | { | 921 | { |
904 | if (NULL == r->key) | 922 | keys_match = (0 == ntohs (msg->filter_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 | } | ||
929 | } | 923 | } |
924 | else | ||
925 | { | ||
926 | keys_match = ((0 != ntohs (msg->filter_key)) && | ||
927 | (! memcmp (r->key, | ||
928 | &msg->key, | ||
929 | sizeof(struct GNUNET_HashCode)))); | ||
930 | } | ||
931 | if ((ch == r->ch) && | ||
932 | (ntohl (msg->type) == r->type) && | ||
933 | (r->get == msg->get) && | ||
934 | (r->get_resp == msg->get_resp) && | ||
935 | (r->put == msg->put) && | ||
936 | keys_match) | ||
937 | { | ||
938 | GNUNET_CONTAINER_DLL_remove (monitor_head, | ||
939 | monitor_tail, | ||
940 | r); | ||
941 | GNUNET_free_non_null (r->key); | ||
942 | GNUNET_free (r); | ||
943 | return; /* Delete only ONE entry */ | ||
944 | } | ||
945 | } | ||
930 | } | 946 | } |
931 | 947 | ||
932 | 948 | ||
933 | /** | 949 | /** |
934 | * Closure for #forward_reply() | 950 | * Closure for #forward_reply() |
935 | */ | 951 | */ |
936 | struct ForwardReplyContext { | 952 | struct ForwardReplyContext |
953 | { | ||
937 | /** | 954 | /** |
938 | * Expiration time of the reply. | 955 | * Expiration time of the reply. |
939 | */ | 956 | */ |
@@ -988,9 +1005,9 @@ struct ForwardReplyContext { | |||
988 | * if the result is mal-formed, #GNUNET_NO | 1005 | * if the result is mal-formed, #GNUNET_NO |
989 | */ | 1006 | */ |
990 | static int | 1007 | static int |
991 | forward_reply(void *cls, | 1008 | forward_reply (void *cls, |
992 | const struct GNUNET_HashCode *key, | 1009 | const struct GNUNET_HashCode *key, |
993 | void *value) | 1010 | void *value) |
994 | { | 1011 | { |
995 | struct ForwardReplyContext *frc = cls; | 1012 | struct ForwardReplyContext *frc = cls; |
996 | struct ClientQueryRecord *record = value; | 1013 | struct ClientQueryRecord *record = value; |
@@ -1001,124 +1018,127 @@ forward_reply(void *cls, | |||
1001 | struct GNUNET_HashCode ch; | 1018 | struct GNUNET_HashCode ch; |
1002 | struct GNUNET_PeerIdentity *paths; | 1019 | struct GNUNET_PeerIdentity *paths; |
1003 | 1020 | ||
1004 | LOG_TRAFFIC(GNUNET_ERROR_TYPE_DEBUG, | 1021 | LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, |
1005 | "CLIENT-RESULT %s\n", | 1022 | "CLIENT-RESULT %s\n", |
1006 | GNUNET_h2s_full(key)); | 1023 | GNUNET_h2s_full (key)); |
1007 | if ((record->type != GNUNET_BLOCK_TYPE_ANY) && | 1024 | if ((record->type != GNUNET_BLOCK_TYPE_ANY) && |
1008 | (record->type != frc->type)) | 1025 | (record->type != frc->type)) |
1026 | { | ||
1027 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1028 | "Record type mismatch, not passing request for key %s to local client\n", | ||
1029 | GNUNET_h2s (key)); | ||
1030 | GNUNET_STATISTICS_update (GDS_stats, | ||
1031 | gettext_noop | ||
1032 | ( | ||
1033 | "# Key match, type mismatches in REPLY to CLIENT"), | ||
1034 | 1, GNUNET_NO); | ||
1035 | return GNUNET_YES; /* type mismatch */ | ||
1036 | } | ||
1037 | GNUNET_CRYPTO_hash (frc->data, frc->data_size, &ch); | ||
1038 | for (unsigned int i = 0; i < record->seen_replies_count; i++) | ||
1039 | if (0 == memcmp (&record->seen_replies[i], | ||
1040 | &ch, | ||
1041 | sizeof(struct GNUNET_HashCode))) | ||
1009 | { | 1042 | { |
1010 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1043 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1011 | "Record type mismatch, not passing request for key %s to local client\n", | 1044 | "Duplicate reply, not passing request for key %s to local client\n", |
1012 | GNUNET_h2s(key)); | 1045 | GNUNET_h2s (key)); |
1013 | GNUNET_STATISTICS_update(GDS_stats, | 1046 | GNUNET_STATISTICS_update (GDS_stats, |
1014 | gettext_noop | 1047 | gettext_noop |
1015 | ("# Key match, type mismatches in REPLY to CLIENT"), | 1048 | ( |
1016 | 1, GNUNET_NO); | 1049 | "# Duplicate REPLIES to CLIENT request dropped"), |
1017 | return GNUNET_YES; /* type mismatch */ | 1050 | 1, GNUNET_NO); |
1051 | return GNUNET_YES; /* duplicate */ | ||
1018 | } | 1052 | } |
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 | } | ||
1034 | eval | 1053 | eval |
1035 | = GNUNET_BLOCK_evaluate(GDS_block_context, | 1054 | = GNUNET_BLOCK_evaluate (GDS_block_context, |
1036 | record->type, | 1055 | record->type, |
1037 | NULL, | 1056 | NULL, |
1038 | GNUNET_BLOCK_EO_NONE, | 1057 | GNUNET_BLOCK_EO_NONE, |
1039 | key, | 1058 | key, |
1040 | record->xquery, | 1059 | record->xquery, |
1041 | record->xquery_size, | 1060 | record->xquery_size, |
1042 | frc->data, | 1061 | frc->data, |
1043 | frc->data_size); | 1062 | frc->data_size); |
1044 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1063 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1045 | "Evaluation result is %d for key %s for local client's query\n", | 1064 | "Evaluation result is %d for key %s for local client's query\n", |
1046 | (int)eval, | 1065 | (int) eval, |
1047 | GNUNET_h2s(key)); | 1066 | GNUNET_h2s (key)); |
1048 | switch (eval) | 1067 | switch (eval) |
1049 | { | 1068 | { |
1050 | case GNUNET_BLOCK_EVALUATION_OK_LAST: | 1069 | case GNUNET_BLOCK_EVALUATION_OK_LAST: |
1051 | do_free = GNUNET_YES; | 1070 | do_free = GNUNET_YES; |
1052 | break; | 1071 | break; |
1053 | 1072 | ||
1054 | case GNUNET_BLOCK_EVALUATION_OK_MORE: | 1073 | case GNUNET_BLOCK_EVALUATION_OK_MORE: |
1055 | GNUNET_array_append(record->seen_replies, | 1074 | GNUNET_array_append (record->seen_replies, |
1056 | record->seen_replies_count, | 1075 | record->seen_replies_count, |
1057 | ch); | 1076 | ch); |
1058 | do_free = GNUNET_NO; | 1077 | do_free = GNUNET_NO; |
1059 | break; | 1078 | break; |
1060 | 1079 | ||
1061 | case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: | 1080 | case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: |
1062 | /* should be impossible to encounter here */ | 1081 | /* should be impossible to encounter here */ |
1063 | GNUNET_break(0); | 1082 | GNUNET_break (0); |
1064 | return GNUNET_YES; | 1083 | return GNUNET_YES; |
1065 | 1084 | ||
1066 | case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: | 1085 | case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: |
1067 | GNUNET_break_op(0); | 1086 | GNUNET_break_op (0); |
1068 | return GNUNET_NO; | 1087 | return GNUNET_NO; |
1069 | 1088 | ||
1070 | case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: | 1089 | case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: |
1071 | GNUNET_break(0); | 1090 | GNUNET_break (0); |
1072 | return GNUNET_NO; | 1091 | return GNUNET_NO; |
1073 | 1092 | ||
1074 | case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: | 1093 | case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: |
1075 | GNUNET_break(0); | 1094 | GNUNET_break (0); |
1076 | return GNUNET_NO; | 1095 | return GNUNET_NO; |
1077 | 1096 | ||
1078 | case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT: | 1097 | case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT: |
1079 | return GNUNET_YES; | 1098 | return GNUNET_YES; |
1080 | 1099 | ||
1081 | case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: | 1100 | case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: |
1082 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1101 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1083 | _("Unsupported block type (%u) in request!\n"), record->type); | 1102 | _ ("Unsupported block type (%u) in request!\n"), record->type); |
1084 | return GNUNET_NO; | 1103 | return GNUNET_NO; |
1085 | 1104 | ||
1086 | default: | 1105 | default: |
1087 | GNUNET_break(0); | 1106 | GNUNET_break (0); |
1088 | return GNUNET_NO; | 1107 | return GNUNET_NO; |
1089 | } | 1108 | } |
1090 | GNUNET_STATISTICS_update(GDS_stats, | 1109 | GNUNET_STATISTICS_update (GDS_stats, |
1091 | gettext_noop("# RESULTS queued for clients"), | 1110 | gettext_noop ("# RESULTS queued for clients"), |
1092 | 1, | 1111 | 1, |
1093 | GNUNET_NO); | 1112 | GNUNET_NO); |
1094 | env = GNUNET_MQ_msg_extra(reply, | 1113 | env = GNUNET_MQ_msg_extra (reply, |
1095 | frc->data_size + | 1114 | frc->data_size |
1096 | (frc->get_path_length + frc->put_path_length) * sizeof(struct GNUNET_PeerIdentity), | 1115 | + (frc->get_path_length + frc->put_path_length) |
1097 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT); | 1116 | * sizeof(struct GNUNET_PeerIdentity), |
1098 | reply->type = htonl(frc->type); | 1117 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT); |
1099 | reply->get_path_length = htonl(frc->get_path_length); | 1118 | reply->type = htonl (frc->type); |
1100 | reply->put_path_length = htonl(frc->put_path_length); | 1119 | reply->get_path_length = htonl (frc->get_path_length); |
1120 | reply->put_path_length = htonl (frc->put_path_length); | ||
1101 | reply->unique_id = record->unique_id; | 1121 | reply->unique_id = record->unique_id; |
1102 | reply->expiration = GNUNET_TIME_absolute_hton(frc->expiration); | 1122 | reply->expiration = GNUNET_TIME_absolute_hton (frc->expiration); |
1103 | reply->key = *key; | 1123 | reply->key = *key; |
1104 | paths = (struct GNUNET_PeerIdentity *)&reply[1]; | 1124 | paths = (struct GNUNET_PeerIdentity *) &reply[1]; |
1105 | GNUNET_memcpy(paths, | 1125 | GNUNET_memcpy (paths, |
1106 | frc->put_path, | 1126 | frc->put_path, |
1107 | sizeof(struct GNUNET_PeerIdentity) * frc->put_path_length); | 1127 | sizeof(struct GNUNET_PeerIdentity) * frc->put_path_length); |
1108 | GNUNET_memcpy(&paths[frc->put_path_length], | 1128 | GNUNET_memcpy (&paths[frc->put_path_length], |
1109 | frc->get_path, | 1129 | frc->get_path, |
1110 | sizeof(struct GNUNET_PeerIdentity) * frc->get_path_length); | 1130 | sizeof(struct GNUNET_PeerIdentity) * frc->get_path_length); |
1111 | GNUNET_memcpy(&paths[frc->get_path_length + frc->put_path_length], | 1131 | GNUNET_memcpy (&paths[frc->get_path_length + frc->put_path_length], |
1112 | frc->data, | 1132 | frc->data, |
1113 | frc->data_size); | 1133 | frc->data_size); |
1114 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1134 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1115 | "Sending reply to query %s for client %p\n", | 1135 | "Sending reply to query %s for client %p\n", |
1116 | GNUNET_h2s(key), | 1136 | GNUNET_h2s (key), |
1117 | record->ch->client); | 1137 | record->ch->client); |
1118 | GNUNET_MQ_send(record->ch->mq, | 1138 | GNUNET_MQ_send (record->ch->mq, |
1119 | env); | 1139 | env); |
1120 | if (GNUNET_YES == do_free) | 1140 | if (GNUNET_YES == do_free) |
1121 | remove_client_record(record); | 1141 | remove_client_record (record); |
1122 | return GNUNET_YES; | 1142 | return GNUNET_YES; |
1123 | } | 1143 | } |
1124 | 1144 | ||
@@ -1139,38 +1159,40 @@ forward_reply(void *cls, | |||
1139 | * @param data application payload data | 1159 | * @param data application payload data |
1140 | */ | 1160 | */ |
1141 | void | 1161 | void |
1142 | GDS_CLIENTS_handle_reply(struct GNUNET_TIME_Absolute expiration, | 1162 | GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, |
1143 | const struct GNUNET_HashCode *key, | 1163 | const struct GNUNET_HashCode *key, |
1144 | unsigned int get_path_length, | 1164 | unsigned int get_path_length, |
1145 | const struct GNUNET_PeerIdentity *get_path, | 1165 | const struct GNUNET_PeerIdentity *get_path, |
1146 | unsigned int put_path_length, | 1166 | unsigned int put_path_length, |
1147 | const struct GNUNET_PeerIdentity *put_path, | 1167 | const struct GNUNET_PeerIdentity *put_path, |
1148 | enum GNUNET_BLOCK_Type type, | 1168 | enum GNUNET_BLOCK_Type type, |
1149 | size_t data_size, | 1169 | size_t data_size, |
1150 | const void *data) | 1170 | const void *data) |
1151 | { | 1171 | { |
1152 | struct ForwardReplyContext frc; | 1172 | struct ForwardReplyContext frc; |
1153 | size_t msize; | 1173 | size_t msize; |
1154 | 1174 | ||
1155 | msize = sizeof(struct GNUNET_DHT_ClientResultMessage) + data_size + | 1175 | msize = sizeof(struct GNUNET_DHT_ClientResultMessage) + data_size |
1156 | (get_path_length + put_path_length) * sizeof(struct GNUNET_PeerIdentity); | 1176 | + (get_path_length + put_path_length) * sizeof(struct |
1177 | GNUNET_PeerIdentity); | ||
1157 | if (msize >= GNUNET_MAX_MESSAGE_SIZE) | 1178 | if (msize >= GNUNET_MAX_MESSAGE_SIZE) |
1158 | { | 1179 | { |
1159 | GNUNET_break(0); | 1180 | GNUNET_break (0); |
1160 | return; | 1181 | return; |
1161 | } | 1182 | } |
1162 | if (NULL == GNUNET_CONTAINER_multihashmap_get(forward_map, | 1183 | if (NULL == GNUNET_CONTAINER_multihashmap_get (forward_map, |
1163 | key)) | 1184 | key)) |
1164 | { | 1185 | { |
1165 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1186 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1166 | "No matching client for reply for key %s\n", | 1187 | "No matching client for reply for key %s\n", |
1167 | GNUNET_h2s(key)); | 1188 | GNUNET_h2s (key)); |
1168 | GNUNET_STATISTICS_update(GDS_stats, | 1189 | GNUNET_STATISTICS_update (GDS_stats, |
1169 | gettext_noop("# REPLIES ignored for CLIENTS (no match)"), | 1190 | gettext_noop ( |
1170 | 1, | 1191 | "# REPLIES ignored for CLIENTS (no match)"), |
1171 | GNUNET_NO); | 1192 | 1, |
1172 | return; /* no matching request, fast exit! */ | 1193 | GNUNET_NO); |
1173 | } | 1194 | return; /* no matching request, fast exit! */ |
1195 | } | ||
1174 | frc.expiration = expiration; | 1196 | frc.expiration = expiration; |
1175 | frc.get_path = get_path; | 1197 | frc.get_path = get_path; |
1176 | frc.put_path = put_path; | 1198 | frc.put_path = put_path; |
@@ -1179,13 +1201,13 @@ GDS_CLIENTS_handle_reply(struct GNUNET_TIME_Absolute expiration, | |||
1179 | frc.get_path_length = get_path_length; | 1201 | frc.get_path_length = get_path_length; |
1180 | frc.put_path_length = put_path_length; | 1202 | frc.put_path_length = put_path_length; |
1181 | frc.type = type; | 1203 | frc.type = type; |
1182 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1204 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1183 | "Forwarding reply for key %s to client\n", | 1205 | "Forwarding reply for key %s to client\n", |
1184 | GNUNET_h2s(key)); | 1206 | GNUNET_h2s (key)); |
1185 | GNUNET_CONTAINER_multihashmap_get_multiple(forward_map, | 1207 | GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, |
1186 | key, | 1208 | key, |
1187 | &forward_reply, | 1209 | &forward_reply, |
1188 | &frc); | 1210 | &frc); |
1189 | } | 1211 | } |
1190 | 1212 | ||
1191 | 1213 | ||
@@ -1202,13 +1224,13 @@ GDS_CLIENTS_handle_reply(struct GNUNET_TIME_Absolute expiration, | |||
1202 | * @param key Key of the requested data. | 1224 | * @param key Key of the requested data. |
1203 | */ | 1225 | */ |
1204 | void | 1226 | void |
1205 | GDS_CLIENTS_process_get(uint32_t options, | 1227 | GDS_CLIENTS_process_get (uint32_t options, |
1206 | enum GNUNET_BLOCK_Type type, | 1228 | enum GNUNET_BLOCK_Type type, |
1207 | uint32_t hop_count, | 1229 | uint32_t hop_count, |
1208 | uint32_t desired_replication_level, | 1230 | uint32_t desired_replication_level, |
1209 | unsigned int path_length, | 1231 | unsigned int path_length, |
1210 | const struct GNUNET_PeerIdentity *path, | 1232 | const struct GNUNET_PeerIdentity *path, |
1211 | const struct GNUNET_HashCode * key) | 1233 | const struct GNUNET_HashCode *key) |
1212 | { | 1234 | { |
1213 | struct ClientMonitorRecord *m; | 1235 | struct ClientMonitorRecord *m; |
1214 | struct ClientHandle **cl; | 1236 | struct ClientHandle **cl; |
@@ -1217,49 +1239,49 @@ GDS_CLIENTS_process_get(uint32_t options, | |||
1217 | cl = NULL; | 1239 | cl = NULL; |
1218 | cl_size = 0; | 1240 | cl_size = 0; |
1219 | for (m = monitor_head; NULL != m; m = m->next) | 1241 | for (m = monitor_head; NULL != m; m = m->next) |
1242 | { | ||
1243 | if (((GNUNET_BLOCK_TYPE_ANY == m->type) || | ||
1244 | (m->type == type)) && | ||
1245 | ((NULL == m->key) || | ||
1246 | (0 == memcmp (key, | ||
1247 | m->key, | ||
1248 | sizeof(struct GNUNET_HashCode))))) | ||
1220 | { | 1249 | { |
1221 | if (((GNUNET_BLOCK_TYPE_ANY == m->type) || | 1250 | struct GNUNET_MQ_Envelope *env; |
1222 | (m->type == type)) && | 1251 | struct GNUNET_DHT_MonitorGetMessage *mmsg; |
1223 | ((NULL == m->key) || | 1252 | struct GNUNET_PeerIdentity *msg_path; |
1224 | (0 == memcmp(key, | 1253 | size_t msize; |
1225 | m->key, | 1254 | unsigned int i; |
1226 | sizeof(struct GNUNET_HashCode))))) | 1255 | |
1227 | { | 1256 | /* Don't send duplicates */ |
1228 | struct GNUNET_MQ_Envelope *env; | 1257 | for (i = 0; i < cl_size; i++) |
1229 | struct GNUNET_DHT_MonitorGetMessage *mmsg; | 1258 | if (cl[i] == m->ch) |
1230 | struct GNUNET_PeerIdentity *msg_path; | 1259 | break; |
1231 | size_t msize; | 1260 | if (i < cl_size) |
1232 | unsigned int i; | 1261 | continue; |
1233 | 1262 | GNUNET_array_append (cl, | |
1234 | /* Don't send duplicates */ | 1263 | cl_size, |
1235 | for (i = 0; i < cl_size; i++) | 1264 | m->ch); |
1236 | if (cl[i] == m->ch) | 1265 | |
1237 | break; | 1266 | msize = path_length * sizeof(struct GNUNET_PeerIdentity); |
1238 | if (i < cl_size) | 1267 | env = GNUNET_MQ_msg_extra (mmsg, |
1239 | continue; | 1268 | msize, |
1240 | GNUNET_array_append(cl, | 1269 | GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET); |
1241 | cl_size, | 1270 | mmsg->options = htonl (options); |
1242 | m->ch); | 1271 | mmsg->type = htonl (type); |
1243 | 1272 | mmsg->hop_count = htonl (hop_count); | |
1244 | msize = path_length * sizeof(struct GNUNET_PeerIdentity); | 1273 | mmsg->desired_replication_level = htonl (desired_replication_level); |
1245 | env = GNUNET_MQ_msg_extra(mmsg, | 1274 | mmsg->get_path_length = htonl (path_length); |
1246 | msize, | 1275 | mmsg->key = *key; |
1247 | GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET); | 1276 | msg_path = (struct GNUNET_PeerIdentity *) &mmsg[1]; |
1248 | mmsg->options = htonl(options); | 1277 | GNUNET_memcpy (msg_path, |
1249 | mmsg->type = htonl(type); | 1278 | path, |
1250 | mmsg->hop_count = htonl(hop_count); | 1279 | path_length * sizeof(struct GNUNET_PeerIdentity)); |
1251 | mmsg->desired_replication_level = htonl(desired_replication_level); | 1280 | GNUNET_MQ_send (m->ch->mq, |
1252 | mmsg->get_path_length = htonl(path_length); | 1281 | env); |
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 | } | ||
1261 | } | 1282 | } |
1262 | GNUNET_free_non_null(cl); | 1283 | } |
1284 | GNUNET_free_non_null (cl); | ||
1263 | } | 1285 | } |
1264 | 1286 | ||
1265 | 1287 | ||
@@ -1278,15 +1300,15 @@ GDS_CLIENTS_process_get(uint32_t options, | |||
1278 | * @param size Number of bytes in @a data. | 1300 | * @param size Number of bytes in @a data. |
1279 | */ | 1301 | */ |
1280 | void | 1302 | void |
1281 | GDS_CLIENTS_process_get_resp(enum GNUNET_BLOCK_Type type, | 1303 | GDS_CLIENTS_process_get_resp (enum GNUNET_BLOCK_Type type, |
1282 | const struct GNUNET_PeerIdentity *get_path, | 1304 | const struct GNUNET_PeerIdentity *get_path, |
1283 | unsigned int get_path_length, | 1305 | unsigned int get_path_length, |
1284 | const struct GNUNET_PeerIdentity *put_path, | 1306 | const struct GNUNET_PeerIdentity *put_path, |
1285 | unsigned int put_path_length, | 1307 | unsigned int put_path_length, |
1286 | struct GNUNET_TIME_Absolute exp, | 1308 | struct GNUNET_TIME_Absolute exp, |
1287 | const struct GNUNET_HashCode * key, | 1309 | const struct GNUNET_HashCode *key, |
1288 | const void *data, | 1310 | const void *data, |
1289 | size_t size) | 1311 | size_t size) |
1290 | { | 1312 | { |
1291 | struct ClientMonitorRecord *m; | 1313 | struct ClientMonitorRecord *m; |
1292 | struct ClientHandle **cl; | 1314 | struct ClientHandle **cl; |
@@ -1295,53 +1317,53 @@ GDS_CLIENTS_process_get_resp(enum GNUNET_BLOCK_Type type, | |||
1295 | cl = NULL; | 1317 | cl = NULL; |
1296 | cl_size = 0; | 1318 | cl_size = 0; |
1297 | for (m = monitor_head; NULL != m; m = m->next) | 1319 | for (m = monitor_head; NULL != m; m = m->next) |
1320 | { | ||
1321 | if (((GNUNET_BLOCK_TYPE_ANY == m->type) ||(m->type == type) ) && | ||
1322 | ((NULL == m->key) || | ||
1323 | (memcmp (key, m->key, sizeof(struct GNUNET_HashCode)) == 0) )) | ||
1298 | { | 1324 | { |
1299 | if ((GNUNET_BLOCK_TYPE_ANY == m->type || m->type == type) && | 1325 | struct GNUNET_MQ_Envelope *env; |
1300 | (NULL == m->key || | 1326 | struct GNUNET_DHT_MonitorGetRespMessage *mmsg; |
1301 | memcmp(key, m->key, sizeof(struct GNUNET_HashCode)) == 0)) | 1327 | struct GNUNET_PeerIdentity *path; |
1302 | { | 1328 | size_t msize; |
1303 | struct GNUNET_MQ_Envelope *env; | 1329 | unsigned int i; |
1304 | struct GNUNET_DHT_MonitorGetRespMessage *mmsg; | 1330 | |
1305 | struct GNUNET_PeerIdentity *path; | 1331 | /* Don't send duplicates */ |
1306 | size_t msize; | 1332 | for (i = 0; i < cl_size; i++) |
1307 | unsigned int i; | 1333 | if (cl[i] == m->ch) |
1308 | 1334 | break; | |
1309 | /* Don't send duplicates */ | 1335 | if (i < cl_size) |
1310 | for (i = 0; i < cl_size; i++) | 1336 | continue; |
1311 | if (cl[i] == m->ch) | 1337 | GNUNET_array_append (cl, |
1312 | break; | 1338 | cl_size, |
1313 | if (i < cl_size) | 1339 | m->ch); |
1314 | continue; | 1340 | |
1315 | GNUNET_array_append(cl, | 1341 | msize = size; |
1316 | cl_size, | 1342 | msize += (get_path_length + put_path_length) |
1317 | m->ch); | 1343 | * sizeof(struct GNUNET_PeerIdentity); |
1318 | 1344 | env = GNUNET_MQ_msg_extra (mmsg, | |
1319 | msize = size; | 1345 | msize, |
1320 | msize += (get_path_length + put_path_length) | 1346 | GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET_RESP); |
1321 | * sizeof(struct GNUNET_PeerIdentity); | 1347 | mmsg->type = htonl (type); |
1322 | env = GNUNET_MQ_msg_extra(mmsg, | 1348 | mmsg->put_path_length = htonl (put_path_length); |
1323 | msize, | 1349 | mmsg->get_path_length = htonl (get_path_length); |
1324 | GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET_RESP); | 1350 | mmsg->expiration_time = GNUNET_TIME_absolute_hton (exp); |
1325 | mmsg->type = htonl(type); | 1351 | mmsg->key = *key; |
1326 | mmsg->put_path_length = htonl(put_path_length); | 1352 | path = (struct GNUNET_PeerIdentity *) &mmsg[1]; |
1327 | mmsg->get_path_length = htonl(get_path_length); | 1353 | GNUNET_memcpy (path, |
1328 | mmsg->expiration_time = GNUNET_TIME_absolute_hton(exp); | 1354 | put_path, |
1329 | mmsg->key = *key; | 1355 | put_path_length * sizeof(struct GNUNET_PeerIdentity)); |
1330 | path = (struct GNUNET_PeerIdentity *)&mmsg[1]; | 1356 | GNUNET_memcpy (path, |
1331 | GNUNET_memcpy(path, | 1357 | get_path, |
1332 | put_path, | 1358 | get_path_length * sizeof(struct GNUNET_PeerIdentity)); |
1333 | put_path_length * sizeof(struct GNUNET_PeerIdentity)); | 1359 | GNUNET_memcpy (&path[get_path_length], |
1334 | GNUNET_memcpy(path, | 1360 | data, |
1335 | get_path, | 1361 | size); |
1336 | get_path_length * sizeof(struct GNUNET_PeerIdentity)); | 1362 | GNUNET_MQ_send (m->ch->mq, |
1337 | GNUNET_memcpy(&path[get_path_length], | 1363 | env); |
1338 | data, | ||
1339 | size); | ||
1340 | GNUNET_MQ_send(m->ch->mq, | ||
1341 | env); | ||
1342 | } | ||
1343 | } | 1364 | } |
1344 | GNUNET_free_non_null(cl); | 1365 | } |
1366 | GNUNET_free_non_null (cl); | ||
1345 | } | 1367 | } |
1346 | 1368 | ||
1347 | 1369 | ||
@@ -1361,16 +1383,16 @@ GDS_CLIENTS_process_get_resp(enum GNUNET_BLOCK_Type type, | |||
1361 | * @param size Number of bytes in data. | 1383 | * @param size Number of bytes in data. |
1362 | */ | 1384 | */ |
1363 | void | 1385 | void |
1364 | GDS_CLIENTS_process_put(uint32_t options, | 1386 | GDS_CLIENTS_process_put (uint32_t options, |
1365 | enum GNUNET_BLOCK_Type type, | 1387 | enum GNUNET_BLOCK_Type type, |
1366 | uint32_t hop_count, | 1388 | uint32_t hop_count, |
1367 | uint32_t desired_replication_level, | 1389 | uint32_t desired_replication_level, |
1368 | unsigned int path_length, | 1390 | unsigned int path_length, |
1369 | const struct GNUNET_PeerIdentity *path, | 1391 | const struct GNUNET_PeerIdentity *path, |
1370 | struct GNUNET_TIME_Absolute exp, | 1392 | struct GNUNET_TIME_Absolute exp, |
1371 | const struct GNUNET_HashCode *key, | 1393 | const struct GNUNET_HashCode *key, |
1372 | const void *data, | 1394 | const void *data, |
1373 | size_t size) | 1395 | size_t size) |
1374 | { | 1396 | { |
1375 | struct ClientMonitorRecord *m; | 1397 | struct ClientMonitorRecord *m; |
1376 | struct ClientHandle **cl; | 1398 | struct ClientHandle **cl; |
@@ -1379,51 +1401,51 @@ GDS_CLIENTS_process_put(uint32_t options, | |||
1379 | cl = NULL; | 1401 | cl = NULL; |
1380 | cl_size = 0; | 1402 | cl_size = 0; |
1381 | for (m = monitor_head; NULL != m; m = m->next) | 1403 | for (m = monitor_head; NULL != m; m = m->next) |
1404 | { | ||
1405 | if (((GNUNET_BLOCK_TYPE_ANY == m->type) ||(m->type == type) ) && | ||
1406 | ((NULL == m->key) || | ||
1407 | (memcmp (key, m->key, sizeof(struct GNUNET_HashCode)) == 0) )) | ||
1382 | { | 1408 | { |
1383 | if ((GNUNET_BLOCK_TYPE_ANY == m->type || m->type == type) && | 1409 | struct GNUNET_MQ_Envelope *env; |
1384 | (NULL == m->key || | 1410 | struct GNUNET_DHT_MonitorPutMessage *mmsg; |
1385 | memcmp(key, m->key, sizeof(struct GNUNET_HashCode)) == 0)) | 1411 | struct GNUNET_PeerIdentity *msg_path; |
1386 | { | 1412 | size_t msize; |
1387 | struct GNUNET_MQ_Envelope *env; | 1413 | unsigned int i; |
1388 | struct GNUNET_DHT_MonitorPutMessage *mmsg; | 1414 | |
1389 | struct GNUNET_PeerIdentity *msg_path; | 1415 | /* Don't send duplicates */ |
1390 | size_t msize; | 1416 | for (i = 0; i < cl_size; i++) |
1391 | unsigned int i; | 1417 | if (cl[i] == m->ch) |
1392 | 1418 | break; | |
1393 | /* Don't send duplicates */ | 1419 | if (i < cl_size) |
1394 | for (i = 0; i < cl_size; i++) | 1420 | continue; |
1395 | if (cl[i] == m->ch) | 1421 | GNUNET_array_append (cl, |
1396 | break; | 1422 | cl_size, |
1397 | if (i < cl_size) | 1423 | m->ch); |
1398 | continue; | 1424 | |
1399 | GNUNET_array_append(cl, | 1425 | msize = size; |
1400 | cl_size, | 1426 | msize += path_length * sizeof(struct GNUNET_PeerIdentity); |
1401 | m->ch); | 1427 | env = GNUNET_MQ_msg_extra (mmsg, |
1402 | 1428 | msize, | |
1403 | msize = size; | 1429 | GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT); |
1404 | msize += path_length * sizeof(struct GNUNET_PeerIdentity); | 1430 | mmsg->options = htonl (options); |
1405 | env = GNUNET_MQ_msg_extra(mmsg, | 1431 | mmsg->type = htonl (type); |
1406 | msize, | 1432 | mmsg->hop_count = htonl (hop_count); |
1407 | GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT); | 1433 | mmsg->desired_replication_level = htonl (desired_replication_level); |
1408 | mmsg->options = htonl(options); | 1434 | mmsg->put_path_length = htonl (path_length); |
1409 | mmsg->type = htonl(type); | 1435 | mmsg->key = *key; |
1410 | mmsg->hop_count = htonl(hop_count); | 1436 | mmsg->expiration_time = GNUNET_TIME_absolute_hton (exp); |
1411 | mmsg->desired_replication_level = htonl(desired_replication_level); | 1437 | msg_path = (struct GNUNET_PeerIdentity *) &mmsg[1]; |
1412 | mmsg->put_path_length = htonl(path_length); | 1438 | GNUNET_memcpy (msg_path, |
1413 | mmsg->key = *key; | 1439 | path, |
1414 | mmsg->expiration_time = GNUNET_TIME_absolute_hton(exp); | 1440 | path_length * sizeof(struct GNUNET_PeerIdentity)); |
1415 | msg_path = (struct GNUNET_PeerIdentity *)&mmsg[1]; | 1441 | GNUNET_memcpy (&msg_path[path_length], |
1416 | GNUNET_memcpy(msg_path, | 1442 | data, |
1417 | path, | 1443 | size); |
1418 | path_length * sizeof(struct GNUNET_PeerIdentity)); | 1444 | GNUNET_MQ_send (m->ch->mq, |
1419 | GNUNET_memcpy(&msg_path[path_length], | 1445 | env); |
1420 | data, | ||
1421 | size); | ||
1422 | GNUNET_MQ_send(m->ch->mq, | ||
1423 | env); | ||
1424 | } | ||
1425 | } | 1446 | } |
1426 | GNUNET_free_non_null(cl); | 1447 | } |
1448 | GNUNET_free_non_null (cl); | ||
1427 | } | 1449 | } |
1428 | 1450 | ||
1429 | 1451 | ||
@@ -1433,13 +1455,13 @@ GDS_CLIENTS_process_put(uint32_t options, | |||
1433 | * @param server the initialized server | 1455 | * @param server the initialized server |
1434 | */ | 1456 | */ |
1435 | static void | 1457 | static void |
1436 | GDS_CLIENTS_init() | 1458 | GDS_CLIENTS_init () |
1437 | { | 1459 | { |
1438 | forward_map | 1460 | forward_map |
1439 | = GNUNET_CONTAINER_multihashmap_create(1024, | 1461 | = GNUNET_CONTAINER_multihashmap_create (1024, |
1440 | GNUNET_YES); | 1462 | GNUNET_YES); |
1441 | retry_heap | 1463 | retry_heap |
1442 | = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); | 1464 | = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
1443 | } | 1465 | } |
1444 | 1466 | ||
1445 | 1467 | ||
@@ -1447,13 +1469,13 @@ GDS_CLIENTS_init() | |||
1447 | * Shutdown client subsystem. | 1469 | * Shutdown client subsystem. |
1448 | */ | 1470 | */ |
1449 | static void | 1471 | static void |
1450 | GDS_CLIENTS_stop() | 1472 | GDS_CLIENTS_stop () |
1451 | { | 1473 | { |
1452 | if (NULL != retry_task) | 1474 | if (NULL != retry_task) |
1453 | { | 1475 | { |
1454 | GNUNET_SCHEDULER_cancel(retry_task); | 1476 | GNUNET_SCHEDULER_cancel (retry_task); |
1455 | retry_task = NULL; | 1477 | retry_task = NULL; |
1456 | } | 1478 | } |
1457 | } | 1479 | } |
1458 | 1480 | ||
1459 | 1481 | ||
@@ -1471,51 +1493,51 @@ GDS_CLIENTS_stop() | |||
1471 | &client_connect_cb, \ | 1493 | &client_connect_cb, \ |
1472 | &client_disconnect_cb, \ | 1494 | &client_disconnect_cb, \ |
1473 | NULL, \ | 1495 | NULL, \ |
1474 | GNUNET_MQ_hd_var_size(dht_local_put, \ | 1496 | GNUNET_MQ_hd_var_size (dht_local_put, \ |
1475 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT, \ | 1497 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT, \ |
1476 | struct GNUNET_DHT_ClientPutMessage, \ | 1498 | struct GNUNET_DHT_ClientPutMessage, \ |
1477 | NULL), \ | 1499 | NULL), \ |
1478 | GNUNET_MQ_hd_var_size(dht_local_get, \ | 1500 | GNUNET_MQ_hd_var_size (dht_local_get, \ |
1479 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET, \ | 1501 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET, \ |
1480 | struct GNUNET_DHT_ClientGetMessage, \ | 1502 | struct GNUNET_DHT_ClientGetMessage, \ |
1481 | NULL), \ | 1503 | NULL), \ |
1482 | GNUNET_MQ_hd_fixed_size(dht_local_get_stop, \ | 1504 | GNUNET_MQ_hd_fixed_size (dht_local_get_stop, \ |
1483 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP, \ | 1505 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP, \ |
1484 | struct GNUNET_DHT_ClientGetStopMessage, \ | 1506 | struct GNUNET_DHT_ClientGetStopMessage, \ |
1485 | NULL), \ | 1507 | NULL), \ |
1486 | GNUNET_MQ_hd_fixed_size(dht_local_monitor, \ | 1508 | GNUNET_MQ_hd_fixed_size (dht_local_monitor, \ |
1487 | GNUNET_MESSAGE_TYPE_DHT_MONITOR_START, \ | 1509 | GNUNET_MESSAGE_TYPE_DHT_MONITOR_START, \ |
1488 | struct GNUNET_DHT_MonitorStartStopMessage, \ | 1510 | struct GNUNET_DHT_MonitorStartStopMessage, \ |
1489 | NULL), \ | 1511 | NULL), \ |
1490 | GNUNET_MQ_hd_fixed_size(dht_local_monitor_stop, \ | 1512 | GNUNET_MQ_hd_fixed_size (dht_local_monitor_stop, \ |
1491 | GNUNET_MESSAGE_TYPE_DHT_MONITOR_STOP, \ | 1513 | GNUNET_MESSAGE_TYPE_DHT_MONITOR_STOP, \ |
1492 | struct GNUNET_DHT_MonitorStartStopMessage, \ | 1514 | struct GNUNET_DHT_MonitorStartStopMessage, \ |
1493 | NULL), \ | 1515 | NULL), \ |
1494 | GNUNET_MQ_hd_var_size(dht_local_get_result_seen, \ | 1516 | GNUNET_MQ_hd_var_size (dht_local_get_result_seen, \ |
1495 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN, \ | 1517 | GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN, \ |
1496 | struct GNUNET_DHT_ClientGetResultSeenMessage, \ | 1518 | struct GNUNET_DHT_ClientGetResultSeenMessage, \ |
1497 | NULL), \ | 1519 | NULL), \ |
1498 | GNUNET_MQ_handler_end()) | 1520 | GNUNET_MQ_handler_end ()) |
1499 | 1521 | ||
1500 | 1522 | ||
1501 | /** | 1523 | /** |
1502 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. | 1524 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. |
1503 | */ | 1525 | */ |
1504 | void __attribute__ ((destructor)) | 1526 | void __attribute__ ((destructor)) |
1505 | GDS_CLIENTS_done() | 1527 | GDS_CLIENTS_done () |
1506 | { | 1528 | { |
1507 | if (NULL != retry_heap) | 1529 | if (NULL != retry_heap) |
1508 | { | 1530 | { |
1509 | GNUNET_assert(0 == GNUNET_CONTAINER_heap_get_size(retry_heap)); | 1531 | GNUNET_assert (0 == GNUNET_CONTAINER_heap_get_size (retry_heap)); |
1510 | GNUNET_CONTAINER_heap_destroy(retry_heap); | 1532 | GNUNET_CONTAINER_heap_destroy (retry_heap); |
1511 | retry_heap = NULL; | 1533 | retry_heap = NULL; |
1512 | } | 1534 | } |
1513 | if (NULL != forward_map) | 1535 | if (NULL != forward_map) |
1514 | { | 1536 | { |
1515 | GNUNET_assert(0 == GNUNET_CONTAINER_multihashmap_size(forward_map)); | 1537 | GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (forward_map)); |
1516 | GNUNET_CONTAINER_multihashmap_destroy(forward_map); | 1538 | GNUNET_CONTAINER_multihashmap_destroy (forward_map); |
1517 | forward_map = NULL; | 1539 | forward_map = NULL; |
1518 | } | 1540 | } |
1519 | } | 1541 | } |
1520 | 1542 | ||
1521 | /* end of gnunet-service-dht_clients.c */ | 1543 | /* 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 e52dc27bf..41b7a3a2b 100644 --- a/src/dht/gnunet-service-dht_datacache.c +++ b/src/dht/gnunet-service-dht_datacache.c | |||
@@ -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,55 +57,56 @@ static struct GNUNET_DATACACHE_Handle *datacache; | |||
57 | * @param data application payload data | 57 | * @param data application payload data |
58 | */ | 58 | */ |
59 | void | 59 | void |
60 | GDS_DATACACHE_handle_put(struct GNUNET_TIME_Absolute expiration, | 60 | GDS_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 | */ |
108 | struct GetRequestContext { | 108 | struct GetRequestContext |
109 | { | ||
109 | /** | 110 | /** |
110 | * extended query (see gnunet_block_lib.h). | 111 | * extended query (see gnunet_block_lib.h). |
111 | */ | 112 | */ |
@@ -158,100 +159,104 @@ struct GetRequestContext { | |||
158 | * to stop iteration. | 159 | * to stop iteration. |
159 | */ | 160 | */ |
160 | static int | 161 | static int |
161 | datacache_get_iterator(void *cls, | 162 | datacache_get_iterator (void *cls, |
162 | const struct GNUNET_HashCode *key, | 163 | const struct GNUNET_HashCode *key, |
163 | size_t data_size, | 164 | size_t data_size, |
164 | const char *data, | 165 | const char *data, |
165 | enum GNUNET_BLOCK_Type type, | 166 | enum GNUNET_BLOCK_Type type, |
166 | struct GNUNET_TIME_Absolute exp, | 167 | struct GNUNET_TIME_Absolute exp, |
167 | unsigned int put_path_length, | 168 | unsigned int put_path_length, |
168 | const struct GNUNET_PeerIdentity *put_path) | 169 | const struct GNUNET_PeerIdentity *put_path) |
169 | { | 170 | { |
170 | static char non_null; | 171 | static char non_null; |
171 | struct GetRequestContext *ctx = cls; | 172 | struct GetRequestContext *ctx = cls; |
172 | enum GNUNET_BLOCK_EvaluationResult eval; | 173 | enum GNUNET_BLOCK_EvaluationResult eval; |
173 | 174 | ||
174 | if (0 == GNUNET_TIME_absolute_get_remaining(exp).rel_value_us) | 175 | if (0 == GNUNET_TIME_absolute_get_remaining (exp).rel_value_us) |
175 | { | 176 | { |
176 | GNUNET_break(0); /* why does datacache return expired values? */ | 177 | GNUNET_break (0); /* why does datacache return expired values? */ |
177 | return GNUNET_OK; /* skip expired record */ | 178 | return GNUNET_OK; /* skip expired record */ |
178 | } | 179 | } |
179 | if ((NULL == data) && | 180 | if ((NULL == data) && |
180 | (0 == data_size)) | 181 | (0 == data_size)) |
181 | data = &non_null; /* point anywhere, but not to NULL */ | 182 | data = &non_null; /* point anywhere, but not to NULL */ |
182 | 183 | ||
183 | eval | 184 | eval |
184 | = GNUNET_BLOCK_evaluate(GDS_block_context, | 185 | = GNUNET_BLOCK_evaluate (GDS_block_context, |
185 | type, | 186 | type, |
186 | ctx->bg, | 187 | ctx->bg, |
187 | GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO, | 188 | GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO, |
188 | key, | 189 | key, |
189 | ctx->xquery, | 190 | ctx->xquery, |
190 | ctx->xquery_size, | 191 | ctx->xquery_size, |
191 | data, | 192 | data, |
192 | data_size); | 193 | data_size); |
193 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 194 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
194 | "Found reply for query %s in datacache, evaluation result is %d\n", | 195 | "Found reply for query %s in datacache, evaluation result is %d\n", |
195 | GNUNET_h2s(key), | 196 | GNUNET_h2s (key), |
196 | (int)eval); | 197 | (int) eval); |
197 | ctx->eval = eval; | 198 | ctx->eval = eval; |
198 | switch (eval) | 199 | switch (eval) |
199 | { | 200 | { |
200 | case GNUNET_BLOCK_EVALUATION_OK_MORE: | 201 | case GNUNET_BLOCK_EVALUATION_OK_MORE: |
201 | case GNUNET_BLOCK_EVALUATION_OK_LAST: | 202 | case GNUNET_BLOCK_EVALUATION_OK_LAST: |
202 | /* forward to local clients */ | 203 | /* forward to local clients */ |
203 | GNUNET_STATISTICS_update(GDS_stats, | 204 | GNUNET_STATISTICS_update (GDS_stats, |
204 | gettext_noop | 205 | gettext_noop |
205 | ("# Good RESULTS found in datacache"), 1, | 206 | ("# Good RESULTS found in datacache"), 1, |
206 | GNUNET_NO); | 207 | GNUNET_NO); |
207 | ctx->gc(ctx->gc_cls, | 208 | ctx->gc (ctx->gc_cls, |
208 | type, | 209 | type, |
209 | exp, | 210 | exp, |
210 | key, | 211 | key, |
211 | put_path_length, put_path, | 212 | put_path_length, put_path, |
212 | 0, NULL, | 213 | 0, NULL, |
213 | data, data_size); | 214 | data, data_size); |
214 | break; | 215 | break; |
215 | 216 | ||
216 | case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: | 217 | case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: |
217 | GNUNET_STATISTICS_update(GDS_stats, | 218 | GNUNET_STATISTICS_update (GDS_stats, |
218 | gettext_noop("# Duplicate RESULTS found in datacache"), | 219 | gettext_noop ( |
219 | 1, | 220 | "# Duplicate RESULTS found in datacache"), |
220 | GNUNET_NO); | 221 | 1, |
221 | break; | 222 | GNUNET_NO); |
222 | 223 | break; | |
223 | case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: | 224 | |
224 | GNUNET_STATISTICS_update(GDS_stats, | 225 | case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: |
225 | gettext_noop("# Invalid RESULTS found in datacache"), | 226 | GNUNET_STATISTICS_update (GDS_stats, |
226 | 1, | 227 | gettext_noop ( |
227 | GNUNET_NO); | 228 | "# Invalid RESULTS found in datacache"), |
228 | break; | 229 | 1, |
229 | 230 | GNUNET_NO); | |
230 | case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT: | 231 | break; |
231 | GNUNET_STATISTICS_update(GDS_stats, | 232 | |
232 | gettext_noop("# Irrelevant RESULTS found in datacache"), | 233 | case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT: |
233 | 1, | 234 | GNUNET_STATISTICS_update (GDS_stats, |
234 | GNUNET_NO); | 235 | gettext_noop ( |
235 | break; | 236 | "# Irrelevant RESULTS found in datacache"), |
236 | 237 | 1, | |
237 | case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: | 238 | GNUNET_NO); |
238 | GNUNET_break(0); | 239 | break; |
239 | break; | 240 | |
240 | 241 | case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: | |
241 | case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: | 242 | GNUNET_break (0); |
242 | GNUNET_break_op(0); | 243 | break; |
243 | return GNUNET_SYSERR; | 244 | |
244 | 245 | case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: | |
245 | case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: | 246 | GNUNET_break_op (0); |
246 | GNUNET_STATISTICS_update(GDS_stats, | 247 | return GNUNET_SYSERR; |
247 | gettext_noop("# Unsupported RESULTS found in datacache"), | 248 | |
248 | 1, | 249 | case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: |
249 | GNUNET_NO); | 250 | GNUNET_STATISTICS_update (GDS_stats, |
250 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 251 | gettext_noop ( |
251 | _("Unsupported block type (%u) in local response!\n"), | 252 | "# Unsupported RESULTS found in datacache"), |
252 | type); | 253 | 1, |
253 | break; | 254 | GNUNET_NO); |
254 | } | 255 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
256 | _ ("Unsupported block type (%u) in local response!\n"), | ||
257 | type); | ||
258 | break; | ||
259 | } | ||
255 | return (eval == GNUNET_BLOCK_EVALUATION_OK_LAST) ? GNUNET_NO : GNUNET_OK; | 260 | return (eval == GNUNET_BLOCK_EVALUATION_OK_LAST) ? GNUNET_NO : GNUNET_OK; |
256 | } | 261 | } |
257 | 262 | ||
@@ -269,23 +274,23 @@ datacache_get_iterator(void *cls, | |||
269 | * @return evaluation result for the local replies | 274 | * @return evaluation result for the local replies |
270 | */ | 275 | */ |
271 | enum GNUNET_BLOCK_EvaluationResult | 276 | enum GNUNET_BLOCK_EvaluationResult |
272 | GDS_DATACACHE_handle_get(const struct GNUNET_HashCode *key, | 277 | GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key, |
273 | enum GNUNET_BLOCK_Type type, | 278 | enum GNUNET_BLOCK_Type type, |
274 | const void *xquery, | 279 | const void *xquery, |
275 | size_t xquery_size, | 280 | size_t xquery_size, |
276 | struct GNUNET_BLOCK_Group *bg, | 281 | struct GNUNET_BLOCK_Group *bg, |
277 | GDS_DATACACHE_GetCallback gc, | 282 | GDS_DATACACHE_GetCallback gc, |
278 | void *gc_cls) | 283 | void *gc_cls) |
279 | { | 284 | { |
280 | struct GetRequestContext ctx; | 285 | struct GetRequestContext ctx; |
281 | unsigned int r; | 286 | unsigned int r; |
282 | 287 | ||
283 | if (NULL == datacache) | 288 | if (NULL == datacache) |
284 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | 289 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; |
285 | GNUNET_STATISTICS_update(GDS_stats, | 290 | GNUNET_STATISTICS_update (GDS_stats, |
286 | gettext_noop("# GET requests given to datacache"), | 291 | gettext_noop ("# GET requests given to datacache"), |
287 | 1, | 292 | 1, |
288 | GNUNET_NO); | 293 | GNUNET_NO); |
289 | ctx.eval = GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | 294 | ctx.eval = GNUNET_BLOCK_EVALUATION_REQUEST_VALID; |
290 | ctx.key = *key; | 295 | ctx.key = *key; |
291 | ctx.xquery = xquery; | 296 | ctx.xquery = xquery; |
@@ -293,16 +298,16 @@ GDS_DATACACHE_handle_get(const struct GNUNET_HashCode *key, | |||
293 | ctx.bg = bg; | 298 | ctx.bg = bg; |
294 | ctx.gc = gc; | 299 | ctx.gc = gc; |
295 | ctx.gc_cls = gc_cls; | 300 | ctx.gc_cls = gc_cls; |
296 | r = GNUNET_DATACACHE_get(datacache, | 301 | r = GNUNET_DATACACHE_get (datacache, |
297 | key, | 302 | key, |
298 | type, | 303 | type, |
299 | &datacache_get_iterator, | 304 | &datacache_get_iterator, |
300 | &ctx); | 305 | &ctx); |
301 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 306 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
302 | "DATACACHE GET for key %s completed (%d). %u results found.\n", | 307 | "DATACACHE GET for key %s completed (%d). %u results found.\n", |
303 | GNUNET_h2s(key), | 308 | GNUNET_h2s (key), |
304 | ctx.eval, | 309 | ctx.eval, |
305 | r); | 310 | r); |
306 | return ctx.eval; | 311 | return ctx.eval; |
307 | } | 312 | } |
308 | 313 | ||
@@ -322,14 +327,14 @@ GDS_DATACACHE_handle_get(const struct GNUNET_HashCode *key, | |||
322 | * @return #GNUNET_OK to continue iterating, #GNUNET_SYSERR to abort | 327 | * @return #GNUNET_OK to continue iterating, #GNUNET_SYSERR to abort |
323 | */ | 328 | */ |
324 | static int | 329 | static int |
325 | datacache_random_iterator(void *cls, | 330 | datacache_random_iterator (void *cls, |
326 | const struct GNUNET_HashCode *key, | 331 | const struct GNUNET_HashCode *key, |
327 | size_t data_size, | 332 | size_t data_size, |
328 | const char *data, | 333 | const char *data, |
329 | enum GNUNET_BLOCK_Type type, | 334 | enum GNUNET_BLOCK_Type type, |
330 | struct GNUNET_TIME_Absolute exp, | 335 | struct GNUNET_TIME_Absolute exp, |
331 | unsigned int path_info_len, | 336 | unsigned int path_info_len, |
332 | const struct GNUNET_PeerIdentity *path_info) | 337 | const struct GNUNET_PeerIdentity *path_info) |
333 | { | 338 | { |
334 | struct GNUNET_HashCode *dest = cls; | 339 | struct GNUNET_HashCode *dest = cls; |
335 | 340 | ||
@@ -347,18 +352,18 @@ datacache_random_iterator(void *cls, | |||
347 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the datacache is empty | 352 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the datacache is empty |
348 | */ | 353 | */ |
349 | int | 354 | int |
350 | GDS_DATACACHE_get_random_key(struct GNUNET_HashCode *key) | 355 | GDS_DATACACHE_get_random_key (struct GNUNET_HashCode *key) |
351 | { | 356 | { |
352 | if (0 == | 357 | if (0 == |
353 | GNUNET_DATACACHE_get_random(datacache, | 358 | GNUNET_DATACACHE_get_random (datacache, |
354 | &datacache_random_iterator, | 359 | &datacache_random_iterator, |
355 | key)) | 360 | key)) |
356 | { | 361 | { |
357 | /* randomize key in this case */ | 362 | /* randomize key in this case */ |
358 | GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_NONCE, | 363 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_NONCE, |
359 | key); | 364 | key); |
360 | return GNUNET_SYSERR; | 365 | return GNUNET_SYSERR; |
361 | } | 366 | } |
362 | return GNUNET_OK; | 367 | return GNUNET_OK; |
363 | } | 368 | } |
364 | 369 | ||
@@ -366,7 +371,8 @@ GDS_DATACACHE_get_random_key(struct GNUNET_HashCode *key) | |||
366 | /** | 371 | /** |
367 | * Closure for #datacache_get_successors_iterator(). | 372 | * Closure for #datacache_get_successors_iterator(). |
368 | */ | 373 | */ |
369 | struct SuccContext { | 374 | struct SuccContext |
375 | { | ||
370 | /** | 376 | /** |
371 | * Function to call on the result | 377 | * Function to call on the result |
372 | */ | 378 | */ |
@@ -394,14 +400,14 @@ struct SuccContext { | |||
394 | * to stop iteration. | 400 | * to stop iteration. |
395 | */ | 401 | */ |
396 | static int | 402 | static int |
397 | datacache_get_successors_iterator(void *cls, | 403 | datacache_get_successors_iterator (void *cls, |
398 | const struct GNUNET_HashCode *key, | 404 | const struct GNUNET_HashCode *key, |
399 | size_t size, | 405 | size_t size, |
400 | const char *data, | 406 | const char *data, |
401 | enum GNUNET_BLOCK_Type type, | 407 | enum GNUNET_BLOCK_Type type, |
402 | struct GNUNET_TIME_Absolute exp, | 408 | struct GNUNET_TIME_Absolute exp, |
403 | unsigned int put_path_length, | 409 | unsigned int put_path_length, |
404 | const struct GNUNET_PeerIdentity *put_path) | 410 | const struct GNUNET_PeerIdentity *put_path) |
405 | { | 411 | { |
406 | const struct SuccContext *sc = cls; | 412 | const struct SuccContext *sc = cls; |
407 | 413 | ||
@@ -409,14 +415,14 @@ datacache_get_successors_iterator(void *cls, | |||
409 | the original 'put', so we don't know the 'correct' option | 415 | the original 'put', so we don't know the 'correct' option |
410 | at this point anymore. Thus, we conservatively assume | 416 | at this point anymore. Thus, we conservatively assume |
411 | that recording is desired (for now). */ | 417 | that recording is desired (for now). */ |
412 | sc->cb(sc->cb_cls, | 418 | sc->cb (sc->cb_cls, |
413 | GNUNET_DHT_RO_RECORD_ROUTE, | 419 | GNUNET_DHT_RO_RECORD_ROUTE, |
414 | key, | 420 | key, |
415 | type, | 421 | type, |
416 | put_path_length, put_path, | 422 | put_path_length, put_path, |
417 | exp, | 423 | exp, |
418 | data, | 424 | data, |
419 | size); | 425 | size); |
420 | return GNUNET_OK; | 426 | return GNUNET_OK; |
421 | } | 427 | } |
422 | 428 | ||
@@ -430,19 +436,19 @@ datacache_get_successors_iterator(void *cls, | |||
430 | * @param cb_cls closure for @a cb | 436 | * @param cb_cls closure for @a cb |
431 | */ | 437 | */ |
432 | void | 438 | void |
433 | GDS_DATACACHE_get_successors(const struct GNUNET_HashCode *key, | 439 | GDS_DATACACHE_get_successors (const struct GNUNET_HashCode *key, |
434 | GDS_DATACACHE_SuccessorCallback cb, | 440 | GDS_DATACACHE_SuccessorCallback cb, |
435 | void *cb_cls) | 441 | void *cb_cls) |
436 | { | 442 | { |
437 | struct SuccContext sc; | 443 | struct SuccContext sc; |
438 | 444 | ||
439 | sc.cb = cb; | 445 | sc.cb = cb; |
440 | sc.cb_cls = cb_cls; | 446 | sc.cb_cls = cb_cls; |
441 | (void)GNUNET_DATACACHE_get_closest(datacache, | 447 | (void) GNUNET_DATACACHE_get_closest (datacache, |
442 | key, | 448 | key, |
443 | NUM_CLOSEST, | 449 | NUM_CLOSEST, |
444 | &datacache_get_successors_iterator, | 450 | &datacache_get_successors_iterator, |
445 | &sc); | 451 | &sc); |
446 | } | 452 | } |
447 | 453 | ||
448 | 454 | ||
@@ -450,9 +456,9 @@ GDS_DATACACHE_get_successors(const struct GNUNET_HashCode *key, | |||
450 | * Initialize datacache subsystem. | 456 | * Initialize datacache subsystem. |
451 | */ | 457 | */ |
452 | void | 458 | void |
453 | GDS_DATACACHE_init() | 459 | GDS_DATACACHE_init () |
454 | { | 460 | { |
455 | datacache = GNUNET_DATACACHE_create(GDS_cfg, "dhtcache"); | 461 | datacache = GNUNET_DATACACHE_create (GDS_cfg, "dhtcache"); |
456 | } | 462 | } |
457 | 463 | ||
458 | 464 | ||
@@ -460,13 +466,13 @@ GDS_DATACACHE_init() | |||
460 | * Shutdown datacache subsystem. | 466 | * Shutdown datacache subsystem. |
461 | */ | 467 | */ |
462 | void | 468 | void |
463 | GDS_DATACACHE_done() | 469 | GDS_DATACACHE_done () |
464 | { | 470 | { |
465 | if (NULL != datacache) | 471 | if (NULL != datacache) |
466 | { | 472 | { |
467 | GNUNET_DATACACHE_destroy(datacache); | 473 | GNUNET_DATACACHE_destroy (datacache); |
468 | datacache = NULL; | 474 | datacache = NULL; |
469 | } | 475 | } |
470 | } | 476 | } |
471 | 477 | ||
472 | 478 | ||
diff --git a/src/dht/gnunet-service-dht_datacache.h b/src/dht/gnunet-service-dht_datacache.h index e376aa1c1..5be59c90e 100644 --- a/src/dht/gnunet-service-dht_datacache.h +++ b/src/dht/gnunet-service-dht_datacache.h | |||
@@ -44,13 +44,13 @@ | |||
44 | * @param data application payload data | 44 | * @param data application payload data |
45 | */ | 45 | */ |
46 | void | 46 | void |
47 | GDS_DATACACHE_handle_put(struct GNUNET_TIME_Absolute expiration, | 47 | GDS_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 | */ |
95 | enum GNUNET_BLOCK_EvaluationResult | 95 | enum GNUNET_BLOCK_EvaluationResult |
96 | GDS_DATACACHE_handle_get(const struct GNUNET_HashCode *key, | 96 | GDS_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 | */ |
113 | int | 113 | int |
114 | GDS_DATACACHE_get_random_key(struct GNUNET_HashCode *key); | 114 | GDS_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 | */ |
150 | void | 150 | void |
151 | GDS_DATACACHE_get_successors(const struct GNUNET_HashCode *key, | 151 | GDS_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 | */ |
159 | void | 159 | void |
160 | GDS_DATACACHE_init(void); | 160 | GDS_DATACACHE_init (void); |
161 | 161 | ||
162 | 162 | ||
163 | /** | 163 | /** |
164 | * Shutdown datacache subsystem. | 164 | * Shutdown datacache subsystem. |
165 | */ | 165 | */ |
166 | void | 166 | void |
167 | GDS_DATACACHE_done(void); | 167 | GDS_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 49641e649..e57951ab1 100644 --- a/src/dht/gnunet-service-dht_hello.c +++ b/src/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 | */ |
52 | const struct GNUNET_HELLO_Message * | 52 | const struct GNUNET_HELLO_Message * |
53 | GDS_HELLO_get(const struct GNUNET_PeerIdentity *peer) | 53 | GDS_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 | */ |
71 | static void | 71 | static void |
72 | process_hello(void *cls, | 72 | process_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 | */ |
102 | void | 102 | void |
103 | GDS_HELLO_init() | 103 | GDS_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 | */ |
117 | static int | 117 | static int |
118 | free_hello(void *cls, | 118 | free_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 | */ |
130 | void | 130 | void |
131 | GDS_HELLO_done() | 131 | GDS_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 929677839..f8b90862d 100644 --- a/src/dht/gnunet-service-dht_hello.h +++ b/src/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 | */ |
38 | const struct GNUNET_HELLO_Message * | 38 | const struct GNUNET_HELLO_Message * |
39 | GDS_HELLO_get(const struct GNUNET_PeerIdentity *peer); | 39 | GDS_HELLO_get (const struct GNUNET_PeerIdentity *peer); |
40 | 40 | ||
41 | 41 | ||
42 | /** | 42 | /** |
43 | * Initialize HELLO subsystem. | 43 | * Initialize HELLO subsystem. |
44 | */ | 44 | */ |
45 | void | 45 | void |
46 | GDS_HELLO_init(void); | 46 | GDS_HELLO_init (void); |
47 | 47 | ||
48 | 48 | ||
49 | /** | 49 | /** |
50 | * Shutdown HELLO subsystem. | 50 | * Shutdown HELLO subsystem. |
51 | */ | 51 | */ |
52 | void | 52 | void |
53 | GDS_HELLO_done(void); | 53 | GDS_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 90ef5429f..fe9dd3e9c 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c | |||
@@ -46,7 +46,8 @@ | |||
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", \ |
50 | __VA_ARGS__) | ||
50 | 51 | ||
51 | /** | 52 | /** |
52 | * Enable slow sanity checks to debug issues. | 53 | * Enable slow sanity checks to debug issues. |
@@ -81,17 +82,19 @@ | |||
81 | /** | 82 | /** |
82 | * How long at least to wait before sending another find peer request. | 83 | * How long at least to wait before sending another find peer request. |
83 | */ | 84 | */ |
84 | #define DHT_MINIMUM_FIND_PEER_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) | 85 | #define DHT_MINIMUM_FIND_PEER_INTERVAL GNUNET_TIME_relative_multiply ( \ |
86 | GNUNET_TIME_UNIT_SECONDS, 30) | ||
85 | 87 | ||
86 | /** | 88 | /** |
87 | * How long at most to wait before sending another find peer request. | 89 | * How long at most to wait before sending another find peer request. |
88 | */ | 90 | */ |
89 | #define DHT_MAXIMUM_FIND_PEER_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 10) | 91 | #define DHT_MAXIMUM_FIND_PEER_INTERVAL GNUNET_TIME_relative_multiply ( \ |
92 | GNUNET_TIME_UNIT_MINUTES, 10) | ||
90 | 93 | ||
91 | /** | 94 | /** |
92 | * How long at most to wait for transmission of a GET request to another peer? | 95 | * How long at most to wait for transmission of a GET request to another peer? |
93 | */ | 96 | */ |
94 | #define GET_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2) | 97 | #define GET_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2) |
95 | 98 | ||
96 | /** | 99 | /** |
97 | * Hello address expiration | 100 | * Hello address expiration |
@@ -104,7 +107,8 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
104 | /** | 107 | /** |
105 | * P2P PUT message | 108 | * P2P PUT message |
106 | */ | 109 | */ |
107 | struct PeerPutMessage { | 110 | struct PeerPutMessage |
111 | { | ||
108 | /** | 112 | /** |
109 | * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_PUT | 113 | * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_PUT |
110 | */ | 114 | */ |
@@ -159,7 +163,8 @@ struct PeerPutMessage { | |||
159 | /** | 163 | /** |
160 | * P2P Result message | 164 | * P2P Result message |
161 | */ | 165 | */ |
162 | struct PeerResultMessage { | 166 | struct PeerResultMessage |
167 | { | ||
163 | /** | 168 | /** |
164 | * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT | 169 | * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT |
165 | */ | 170 | */ |
@@ -201,7 +206,8 @@ struct PeerResultMessage { | |||
201 | /** | 206 | /** |
202 | * P2P GET message | 207 | * P2P GET message |
203 | */ | 208 | */ |
204 | struct PeerGetMessage { | 209 | struct PeerGetMessage |
210 | { | ||
205 | /** | 211 | /** |
206 | * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_GET | 212 | * Type: #GNUNET_MESSAGE_TYPE_DHT_P2P_GET |
207 | */ | 213 | */ |
@@ -257,7 +263,8 @@ GNUNET_NETWORK_STRUCT_END | |||
257 | /** | 263 | /** |
258 | * Entry for a peer in a bucket. | 264 | * Entry for a peer in a bucket. |
259 | */ | 265 | */ |
260 | struct PeerInfo { | 266 | struct PeerInfo |
267 | { | ||
261 | /** | 268 | /** |
262 | * Next peer entry (DLL) | 269 | * Next peer entry (DLL) |
263 | */ | 270 | */ |
@@ -293,7 +300,8 @@ struct PeerInfo { | |||
293 | /** | 300 | /** |
294 | * Peers are grouped into buckets. | 301 | * Peers are grouped into buckets. |
295 | */ | 302 | */ |
296 | struct PeerBucket { | 303 | struct PeerBucket |
304 | { | ||
297 | /** | 305 | /** |
298 | * Head of DLL | 306 | * Head of DLL |
299 | */ | 307 | */ |
@@ -314,7 +322,8 @@ struct PeerBucket { | |||
314 | /** | 322 | /** |
315 | * Information about a peer that we would like to connect to. | 323 | * Information about a peer that we would like to connect to. |
316 | */ | 324 | */ |
317 | struct ConnectInfo { | 325 | struct ConnectInfo |
326 | { | ||
318 | /** | 327 | /** |
319 | * Handle to active HELLO offer operation, or NULL. | 328 | * Handle to active HELLO offer operation, or NULL. |
320 | */ | 329 | */ |
@@ -414,17 +423,17 @@ static struct GNUNET_ATS_ConnectivityHandle *ats_ch; | |||
414 | * on error (same hashcode) | 423 | * on error (same hashcode) |
415 | */ | 424 | */ |
416 | static int | 425 | static int |
417 | find_bucket(const struct GNUNET_HashCode *hc) | 426 | find_bucket (const struct GNUNET_HashCode *hc) |
418 | { | 427 | { |
419 | unsigned int bits; | 428 | unsigned int bits; |
420 | 429 | ||
421 | bits = GNUNET_CRYPTO_hash_matching_bits(&my_identity_hash, hc); | 430 | bits = GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash, hc); |
422 | if (bits == MAX_BUCKETS) | 431 | if (bits == MAX_BUCKETS) |
423 | { | 432 | { |
424 | /* How can all bits match? Got my own ID? */ | 433 | /* How can all bits match? Got my own ID? */ |
425 | GNUNET_break(0); | 434 | GNUNET_break (0); |
426 | return GNUNET_SYSERR; | 435 | return GNUNET_SYSERR; |
427 | } | 436 | } |
428 | return MAX_BUCKETS - bits - 1; | 437 | return MAX_BUCKETS - bits - 1; |
429 | } | 438 | } |
430 | 439 | ||
@@ -436,7 +445,7 @@ find_bucket(const struct GNUNET_HashCode *hc) | |||
436 | * @param cls a `struct ConnectInfo` | 445 | * @param cls a `struct ConnectInfo` |
437 | */ | 446 | */ |
438 | static void | 447 | static void |
439 | offer_hello_done(void *cls) | 448 | offer_hello_done (void *cls) |
440 | { | 449 | { |
441 | struct ConnectInfo *ci = cls; | 450 | struct ConnectInfo *ci = cls; |
442 | 451 | ||
@@ -453,28 +462,28 @@ offer_hello_done(void *cls) | |||
453 | * @return #GNUNET_YES | 462 | * @return #GNUNET_YES |
454 | */ | 463 | */ |
455 | static int | 464 | static int |
456 | free_connect_info(void *cls, | 465 | free_connect_info (void *cls, |
457 | const struct GNUNET_PeerIdentity *peer, | 466 | const struct GNUNET_PeerIdentity *peer, |
458 | void *value) | 467 | void *value) |
459 | { | 468 | { |
460 | struct ConnectInfo *ci = value; | 469 | struct ConnectInfo *ci = value; |
461 | 470 | ||
462 | (void)cls; | 471 | (void) cls; |
463 | GNUNET_assert(GNUNET_YES == | 472 | GNUNET_assert (GNUNET_YES == |
464 | GNUNET_CONTAINER_multipeermap_remove(all_desired_peers, | 473 | GNUNET_CONTAINER_multipeermap_remove (all_desired_peers, |
465 | peer, | 474 | peer, |
466 | ci)); | 475 | ci)); |
467 | if (NULL != ci->sh) | 476 | if (NULL != ci->sh) |
468 | { | 477 | { |
469 | GNUNET_ATS_connectivity_suggest_cancel(ci->sh); | 478 | GNUNET_ATS_connectivity_suggest_cancel (ci->sh); |
470 | ci->sh = NULL; | 479 | ci->sh = NULL; |
471 | } | 480 | } |
472 | if (NULL != ci->oh) | 481 | if (NULL != ci->oh) |
473 | { | 482 | { |
474 | GNUNET_TRANSPORT_offer_hello_cancel(ci->oh); | 483 | GNUNET_TRANSPORT_offer_hello_cancel (ci->oh); |
475 | ci->oh = NULL; | 484 | ci->oh = NULL; |
476 | } | 485 | } |
477 | GNUNET_free(ci); | 486 | GNUNET_free (ci); |
478 | return GNUNET_YES; | 487 | return GNUNET_YES; |
479 | } | 488 | } |
480 | 489 | ||
@@ -488,68 +497,68 @@ free_connect_info(void *cls, | |||
488 | * @param h a HELLO message, or NULL | 497 | * @param h a HELLO message, or NULL |
489 | */ | 498 | */ |
490 | static void | 499 | static void |
491 | try_connect(const struct GNUNET_PeerIdentity *pid, | 500 | try_connect (const struct GNUNET_PeerIdentity *pid, |
492 | const struct GNUNET_MessageHeader *h) | 501 | const struct GNUNET_MessageHeader *h) |
493 | { | 502 | { |
494 | int bucket; | 503 | int bucket; |
495 | struct GNUNET_HashCode pid_hash; | 504 | struct GNUNET_HashCode pid_hash; |
496 | struct ConnectInfo *ci; | 505 | struct ConnectInfo *ci; |
497 | uint32_t strength; | 506 | uint32_t strength; |
498 | 507 | ||
499 | GNUNET_CRYPTO_hash(pid, | 508 | GNUNET_CRYPTO_hash (pid, |
500 | sizeof(struct GNUNET_PeerIdentity), | 509 | sizeof(struct GNUNET_PeerIdentity), |
501 | &pid_hash); | 510 | &pid_hash); |
502 | bucket = find_bucket(&pid_hash); | 511 | bucket = find_bucket (&pid_hash); |
503 | if (bucket < 0) | 512 | if (bucket < 0) |
504 | return; /* self? */ | 513 | return; /* self? */ |
505 | ci = GNUNET_CONTAINER_multipeermap_get(all_desired_peers, | 514 | ci = GNUNET_CONTAINER_multipeermap_get (all_desired_peers, |
506 | pid); | 515 | pid); |
507 | 516 | ||
508 | if (k_buckets[bucket].peers_size < bucket_size) | 517 | if (k_buckets[bucket].peers_size < bucket_size) |
509 | strength = (bucket_size - k_buckets[bucket].peers_size) * bucket; | 518 | strength = (bucket_size - k_buckets[bucket].peers_size) * bucket; |
510 | else | 519 | else |
511 | strength = bucket; /* minimum value of connectivity */ | 520 | strength = bucket; /* minimum value of connectivity */ |
512 | if (GNUNET_YES == | 521 | if (GNUNET_YES == |
513 | GNUNET_CONTAINER_multipeermap_contains(all_connected_peers, | 522 | GNUNET_CONTAINER_multipeermap_contains (all_connected_peers, |
514 | pid)) | 523 | pid)) |
515 | strength *= 2; /* double for connected peers */ | 524 | strength *= 2; /* double for connected peers */ |
516 | else if (k_buckets[bucket].peers_size > bucket_size) | 525 | else if (k_buckets[bucket].peers_size > bucket_size) |
517 | strength = 0; /* bucket full, we really do not care about more */ | 526 | strength = 0; /* bucket full, we really do not care about more */ |
518 | 527 | ||
519 | if ((0 == strength) && | 528 | if ((0 == strength) && |
520 | (NULL != ci)) | 529 | (NULL != ci)) |
521 | { | 530 | { |
522 | /* release request */ | 531 | /* release request */ |
523 | GNUNET_assert(GNUNET_YES == | 532 | GNUNET_assert (GNUNET_YES == |
524 | free_connect_info(NULL, | 533 | free_connect_info (NULL, |
525 | pid, | 534 | pid, |
526 | ci)); | 535 | ci)); |
527 | return; | 536 | return; |
528 | } | 537 | } |
529 | if (NULL == ci) | 538 | if (NULL == ci) |
530 | { | 539 | { |
531 | ci = GNUNET_new(struct ConnectInfo); | 540 | ci = GNUNET_new (struct ConnectInfo); |
532 | GNUNET_assert(GNUNET_OK == | 541 | GNUNET_assert (GNUNET_OK == |
533 | GNUNET_CONTAINER_multipeermap_put(all_desired_peers, | 542 | GNUNET_CONTAINER_multipeermap_put (all_desired_peers, |
534 | pid, | 543 | pid, |
535 | ci, | 544 | ci, |
536 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 545 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
537 | } | 546 | } |
538 | if ((NULL != ci->oh) && | 547 | if ((NULL != ci->oh) && |
539 | (NULL != h)) | 548 | (NULL != h)) |
540 | GNUNET_TRANSPORT_offer_hello_cancel(ci->oh); | 549 | GNUNET_TRANSPORT_offer_hello_cancel (ci->oh); |
541 | if (NULL != h) | 550 | if (NULL != h) |
542 | ci->oh = GNUNET_TRANSPORT_offer_hello(GDS_cfg, | 551 | ci->oh = GNUNET_TRANSPORT_offer_hello (GDS_cfg, |
543 | h, | 552 | h, |
544 | &offer_hello_done, | 553 | &offer_hello_done, |
545 | ci); | 554 | ci); |
546 | if ((NULL != ci->sh) && | 555 | if ((NULL != ci->sh) && |
547 | (ci->strength != strength)) | 556 | (ci->strength != strength)) |
548 | GNUNET_ATS_connectivity_suggest_cancel(ci->sh); | 557 | GNUNET_ATS_connectivity_suggest_cancel (ci->sh); |
549 | if (ci->strength != strength) | 558 | if (ci->strength != strength) |
550 | ci->sh = GNUNET_ATS_connectivity_suggest(ats_ch, | 559 | ci->sh = GNUNET_ATS_connectivity_suggest (ats_ch, |
551 | pid, | 560 | pid, |
552 | strength); | 561 | strength); |
553 | ci->strength = strength; | 562 | ci->strength = strength; |
554 | } | 563 | } |
555 | 564 | ||
@@ -567,14 +576,14 @@ try_connect(const struct GNUNET_PeerIdentity *pid, | |||
567 | * @return #GNUNET_YES (continue to iterate) | 576 | * @return #GNUNET_YES (continue to iterate) |
568 | */ | 577 | */ |
569 | static int | 578 | static int |
570 | update_desire_strength(void *cls, | 579 | update_desire_strength (void *cls, |
571 | const struct GNUNET_PeerIdentity *pid, | 580 | const struct GNUNET_PeerIdentity *pid, |
572 | void *value) | 581 | void *value) |
573 | { | 582 | { |
574 | (void)cls; | 583 | (void) cls; |
575 | (void)value; | 584 | (void) value; |
576 | try_connect(pid, | 585 | try_connect (pid, |
577 | NULL); | 586 | NULL); |
578 | return GNUNET_YES; | 587 | return GNUNET_YES; |
579 | } | 588 | } |
580 | 589 | ||
@@ -586,11 +595,11 @@ update_desire_strength(void *cls, | |||
586 | * @param tc scheduler context. | 595 | * @param tc scheduler context. |
587 | */ | 596 | */ |
588 | static void | 597 | static void |
589 | update_connect_preferences() | 598 | update_connect_preferences () |
590 | { | 599 | { |
591 | GNUNET_CONTAINER_multipeermap_iterate(all_desired_peers, | 600 | GNUNET_CONTAINER_multipeermap_iterate (all_desired_peers, |
592 | &update_desire_strength, | 601 | &update_desire_strength, |
593 | NULL); | 602 | NULL); |
594 | } | 603 | } |
595 | 604 | ||
596 | 605 | ||
@@ -604,24 +613,24 @@ update_connect_preferences() | |||
604 | * @return #GNUNET_YES (we should continue to iterate) | 613 | * @return #GNUNET_YES (we should continue to iterate) |
605 | */ | 614 | */ |
606 | static int | 615 | static int |
607 | add_known_to_bloom(void *cls, | 616 | add_known_to_bloom (void *cls, |
608 | const struct GNUNET_PeerIdentity *key, | 617 | const struct GNUNET_PeerIdentity *key, |
609 | void *value) | 618 | void *value) |
610 | { | 619 | { |
611 | struct GNUNET_BLOCK_Group *bg = cls; | 620 | struct GNUNET_BLOCK_Group *bg = cls; |
612 | struct GNUNET_HashCode key_hash; | 621 | struct GNUNET_HashCode key_hash; |
613 | 622 | ||
614 | (void)cls; | 623 | (void) cls; |
615 | (void)value; | 624 | (void) value; |
616 | GNUNET_CRYPTO_hash(key, | 625 | GNUNET_CRYPTO_hash (key, |
617 | sizeof(struct GNUNET_PeerIdentity), | 626 | sizeof(struct GNUNET_PeerIdentity), |
618 | &key_hash); | 627 | &key_hash); |
619 | GNUNET_BLOCK_group_set_seen(bg, | 628 | GNUNET_BLOCK_group_set_seen (bg, |
620 | &key_hash, | 629 | &key_hash, |
621 | 1); | 630 | 1); |
622 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 631 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
623 | "Adding known peer (%s) to bloomfilter for FIND PEER\n", | 632 | "Adding known peer (%s) to bloomfilter for FIND PEER\n", |
624 | GNUNET_i2s(key)); | 633 | GNUNET_i2s (key)); |
625 | return GNUNET_YES; | 634 | return GNUNET_YES; |
626 | } | 635 | } |
627 | 636 | ||
@@ -634,68 +643,70 @@ add_known_to_bloom(void *cls, | |||
634 | * @param cls closure for this task | 643 | * @param cls closure for this task |
635 | */ | 644 | */ |
636 | static void | 645 | static void |
637 | send_find_peer_message(void *cls) | 646 | send_find_peer_message (void *cls) |
638 | { | 647 | { |
639 | struct GNUNET_TIME_Relative next_send_time; | 648 | struct GNUNET_TIME_Relative next_send_time; |
640 | struct GNUNET_BLOCK_Group *bg; | 649 | struct GNUNET_BLOCK_Group *bg; |
641 | struct GNUNET_CONTAINER_BloomFilter *peer_bf; | 650 | struct GNUNET_CONTAINER_BloomFilter *peer_bf; |
642 | 651 | ||
643 | (void)cls; | 652 | (void) cls; |
644 | find_peer_task = NULL; | 653 | find_peer_task = NULL; |
645 | if (newly_found_peers > bucket_size) | 654 | if (newly_found_peers > bucket_size) |
646 | { | 655 | { |
647 | /* If we are finding many peers already, no need to send out our request right now! */ | 656 | /* If we are finding many peers already, no need to send out our request right now! */ |
648 | find_peer_task = | 657 | find_peer_task = |
649 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, | 658 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, |
650 | &send_find_peer_message, | 659 | &send_find_peer_message, |
651 | NULL); | 660 | NULL); |
652 | newly_found_peers = 0; | 661 | newly_found_peers = 0; |
653 | return; | 662 | return; |
654 | } | 663 | } |
655 | bg = GNUNET_BLOCK_group_create(GDS_block_context, | 664 | bg = GNUNET_BLOCK_group_create (GDS_block_context, |
656 | GNUNET_BLOCK_TYPE_DHT_HELLO, | 665 | GNUNET_BLOCK_TYPE_DHT_HELLO, |
657 | GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | 666 | GNUNET_CRYPTO_random_u32 ( |
658 | UINT32_MAX), | 667 | GNUNET_CRYPTO_QUALITY_WEAK, |
659 | NULL, | 668 | UINT32_MAX), |
660 | 0, | 669 | NULL, |
661 | "filter-size", | 670 | 0, |
662 | DHT_BLOOM_SIZE, | 671 | "filter-size", |
663 | NULL); | 672 | DHT_BLOOM_SIZE, |
664 | GNUNET_CONTAINER_multipeermap_iterate(all_connected_peers, | 673 | NULL); |
665 | &add_known_to_bloom, | 674 | GNUNET_CONTAINER_multipeermap_iterate (all_connected_peers, |
666 | bg); | 675 | &add_known_to_bloom, |
667 | GNUNET_STATISTICS_update(GDS_stats, | 676 | bg); |
668 | gettext_noop("# FIND PEER messages initiated"), | 677 | GNUNET_STATISTICS_update (GDS_stats, |
669 | 1, | 678 | gettext_noop ("# FIND PEER messages initiated"), |
670 | GNUNET_NO); | 679 | 1, |
680 | GNUNET_NO); | ||
671 | peer_bf | 681 | peer_bf |
672 | = GNUNET_CONTAINER_bloomfilter_init(NULL, | 682 | = GNUNET_CONTAINER_bloomfilter_init (NULL, |
673 | DHT_BLOOM_SIZE, | 683 | DHT_BLOOM_SIZE, |
674 | GNUNET_CONSTANTS_BLOOMFILTER_K); | 684 | GNUNET_CONSTANTS_BLOOMFILTER_K); |
675 | // FIXME: pass priority!? | 685 | // FIXME: pass priority!? |
676 | GDS_NEIGHBOURS_handle_get(GNUNET_BLOCK_TYPE_DHT_HELLO, | 686 | GDS_NEIGHBOURS_handle_get (GNUNET_BLOCK_TYPE_DHT_HELLO, |
677 | GNUNET_DHT_RO_FIND_PEER | GNUNET_DHT_RO_RECORD_ROUTE, | 687 | GNUNET_DHT_RO_FIND_PEER |
678 | FIND_PEER_REPLICATION_LEVEL, | 688 | | GNUNET_DHT_RO_RECORD_ROUTE, |
679 | 0, | 689 | FIND_PEER_REPLICATION_LEVEL, |
680 | &my_identity_hash, | 690 | 0, |
681 | NULL, | 691 | &my_identity_hash, |
682 | 0, | 692 | NULL, |
683 | bg, | 693 | 0, |
684 | peer_bf); | 694 | bg, |
685 | GNUNET_CONTAINER_bloomfilter_free(peer_bf); | 695 | peer_bf); |
686 | GNUNET_BLOCK_group_destroy(bg); | 696 | GNUNET_CONTAINER_bloomfilter_free (peer_bf); |
697 | GNUNET_BLOCK_group_destroy (bg); | ||
687 | /* schedule next round */ | 698 | /* schedule next round */ |
688 | next_send_time.rel_value_us = | 699 | next_send_time.rel_value_us = |
689 | DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value_us + | 700 | DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value_us |
690 | GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, | 701 | + GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
691 | DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value_us / | 702 | DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value_us |
692 | (newly_found_peers + 1)); | 703 | / (newly_found_peers + 1)); |
693 | newly_found_peers = 0; | 704 | newly_found_peers = 0; |
694 | GNUNET_assert(NULL == find_peer_task); | 705 | GNUNET_assert (NULL == find_peer_task); |
695 | find_peer_task = | 706 | find_peer_task = |
696 | GNUNET_SCHEDULER_add_delayed(next_send_time, | 707 | GNUNET_SCHEDULER_add_delayed (next_send_time, |
697 | &send_find_peer_message, | 708 | &send_find_peer_message, |
698 | NULL); | 709 | NULL); |
699 | } | 710 | } |
700 | 711 | ||
701 | 712 | ||
@@ -708,61 +719,61 @@ send_find_peer_message(void *cls) | |||
708 | * @return our `struct PeerInfo` for @a peer | 719 | * @return our `struct PeerInfo` for @a peer |
709 | */ | 720 | */ |
710 | static void * | 721 | static void * |
711 | handle_core_connect(void *cls, | 722 | handle_core_connect (void *cls, |
712 | const struct GNUNET_PeerIdentity *peer, | 723 | const struct GNUNET_PeerIdentity *peer, |
713 | struct GNUNET_MQ_Handle *mq) | 724 | struct GNUNET_MQ_Handle *mq) |
714 | { | 725 | { |
715 | struct PeerInfo *pi; | 726 | struct PeerInfo *pi; |
716 | 727 | ||
717 | (void)cls; | 728 | (void) cls; |
718 | /* Check for connect to self message */ | 729 | /* Check for connect to self message */ |
719 | if (0 == GNUNET_memcmp(&my_identity, | 730 | if (0 == GNUNET_memcmp (&my_identity, |
720 | peer)) | 731 | peer)) |
721 | return NULL; | 732 | return NULL; |
722 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 733 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
723 | "Connected to %s\n", | 734 | "Connected to %s\n", |
724 | GNUNET_i2s(peer)); | 735 | GNUNET_i2s (peer)); |
725 | GNUNET_assert(GNUNET_NO == | 736 | GNUNET_assert (GNUNET_NO == |
726 | GNUNET_CONTAINER_multipeermap_get(all_connected_peers, | 737 | GNUNET_CONTAINER_multipeermap_get (all_connected_peers, |
727 | peer)); | 738 | peer)); |
728 | GNUNET_STATISTICS_update(GDS_stats, | 739 | GNUNET_STATISTICS_update (GDS_stats, |
729 | gettext_noop("# peers connected"), | 740 | gettext_noop ("# peers connected"), |
730 | 1, | 741 | 1, |
731 | GNUNET_NO); | 742 | GNUNET_NO); |
732 | pi = GNUNET_new(struct PeerInfo); | 743 | pi = GNUNET_new (struct PeerInfo); |
733 | pi->id = peer; | 744 | pi->id = peer; |
734 | pi->mq = mq; | 745 | pi->mq = mq; |
735 | GNUNET_CRYPTO_hash(peer, | 746 | GNUNET_CRYPTO_hash (peer, |
736 | sizeof(struct GNUNET_PeerIdentity), | 747 | sizeof(struct GNUNET_PeerIdentity), |
737 | &pi->phash); | 748 | &pi->phash); |
738 | pi->peer_bucket = find_bucket(&pi->phash); | 749 | pi->peer_bucket = find_bucket (&pi->phash); |
739 | GNUNET_assert((pi->peer_bucket >= 0) && | 750 | GNUNET_assert ((pi->peer_bucket >= 0) && |
740 | ((unsigned int)pi->peer_bucket < MAX_BUCKETS)); | 751 | ((unsigned int) pi->peer_bucket < MAX_BUCKETS)); |
741 | GNUNET_CONTAINER_DLL_insert_tail(k_buckets[pi->peer_bucket].head, | 752 | GNUNET_CONTAINER_DLL_insert_tail (k_buckets[pi->peer_bucket].head, |
742 | k_buckets[pi->peer_bucket].tail, | 753 | k_buckets[pi->peer_bucket].tail, |
743 | pi); | 754 | pi); |
744 | k_buckets[pi->peer_bucket].peers_size++; | 755 | k_buckets[pi->peer_bucket].peers_size++; |
745 | closest_bucket = GNUNET_MAX(closest_bucket, | 756 | closest_bucket = GNUNET_MAX (closest_bucket, |
746 | (unsigned int)pi->peer_bucket); | 757 | (unsigned int) pi->peer_bucket); |
747 | GNUNET_assert(GNUNET_OK == | 758 | GNUNET_assert (GNUNET_OK == |
748 | GNUNET_CONTAINER_multipeermap_put(all_connected_peers, | 759 | GNUNET_CONTAINER_multipeermap_put (all_connected_peers, |
749 | pi->id, | 760 | pi->id, |
750 | pi, | 761 | pi, |
751 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 762 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
752 | if ((pi->peer_bucket > 0) && | 763 | if ((pi->peer_bucket > 0) && |
753 | (k_buckets[pi->peer_bucket].peers_size <= bucket_size)) | 764 | (k_buckets[pi->peer_bucket].peers_size <= bucket_size)) |
754 | { | 765 | { |
755 | update_connect_preferences(); | 766 | update_connect_preferences (); |
756 | newly_found_peers++; | 767 | newly_found_peers++; |
757 | } | 768 | } |
758 | if ((1 == GNUNET_CONTAINER_multipeermap_size(all_connected_peers)) && | 769 | if ((1 == GNUNET_CONTAINER_multipeermap_size (all_connected_peers)) && |
759 | (GNUNET_YES != disable_try_connect)) | 770 | (GNUNET_YES != disable_try_connect)) |
760 | { | 771 | { |
761 | /* got a first connection, good time to start with FIND PEER requests... */ | 772 | /* got a first connection, good time to start with FIND PEER requests... */ |
762 | GNUNET_assert(NULL == find_peer_task); | 773 | GNUNET_assert (NULL == find_peer_task); |
763 | find_peer_task = GNUNET_SCHEDULER_add_now(&send_find_peer_message, | 774 | find_peer_task = GNUNET_SCHEDULER_add_now (&send_find_peer_message, |
764 | NULL); | 775 | NULL); |
765 | } | 776 | } |
766 | return pi; | 777 | return pi; |
767 | } | 778 | } |
768 | 779 | ||
@@ -775,45 +786,45 @@ handle_core_connect(void *cls, | |||
775 | * @param internal_cls our `struct PeerInfo` for @a peer | 786 | * @param internal_cls our `struct PeerInfo` for @a peer |
776 | */ | 787 | */ |
777 | static void | 788 | static void |
778 | handle_core_disconnect(void *cls, | 789 | handle_core_disconnect (void *cls, |
779 | const struct GNUNET_PeerIdentity *peer, | 790 | const struct GNUNET_PeerIdentity *peer, |
780 | void *internal_cls) | 791 | void *internal_cls) |
781 | { | 792 | { |
782 | struct PeerInfo *to_remove = internal_cls; | 793 | struct PeerInfo *to_remove = internal_cls; |
783 | 794 | ||
784 | (void)cls; | 795 | (void) cls; |
785 | /* Check for disconnect from self message */ | 796 | /* Check for disconnect from self message */ |
786 | if (NULL == to_remove) | 797 | if (NULL == to_remove) |
787 | return; | 798 | return; |
788 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 799 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
789 | "Disconnected %s\n", | 800 | "Disconnected %s\n", |
790 | GNUNET_i2s(peer)); | 801 | GNUNET_i2s (peer)); |
791 | GNUNET_STATISTICS_update(GDS_stats, | 802 | GNUNET_STATISTICS_update (GDS_stats, |
792 | gettext_noop("# peers connected"), | 803 | gettext_noop ("# peers connected"), |
793 | -1, | 804 | -1, |
794 | GNUNET_NO); | 805 | GNUNET_NO); |
795 | GNUNET_assert(GNUNET_YES == | 806 | GNUNET_assert (GNUNET_YES == |
796 | GNUNET_CONTAINER_multipeermap_remove(all_connected_peers, | 807 | GNUNET_CONTAINER_multipeermap_remove (all_connected_peers, |
797 | peer, | 808 | peer, |
798 | to_remove)); | 809 | to_remove)); |
799 | if ((0 == GNUNET_CONTAINER_multipeermap_size(all_connected_peers)) && | 810 | if ((0 == GNUNET_CONTAINER_multipeermap_size (all_connected_peers)) && |
800 | (GNUNET_YES != disable_try_connect)) | 811 | (GNUNET_YES != disable_try_connect)) |
801 | { | 812 | { |
802 | GNUNET_SCHEDULER_cancel(find_peer_task); | 813 | GNUNET_SCHEDULER_cancel (find_peer_task); |
803 | find_peer_task = NULL; | 814 | find_peer_task = NULL; |
804 | } | 815 | } |
805 | GNUNET_assert(to_remove->peer_bucket >= 0); | 816 | GNUNET_assert (to_remove->peer_bucket >= 0); |
806 | GNUNET_CONTAINER_DLL_remove(k_buckets[to_remove->peer_bucket].head, | 817 | GNUNET_CONTAINER_DLL_remove (k_buckets[to_remove->peer_bucket].head, |
807 | k_buckets[to_remove->peer_bucket].tail, | 818 | k_buckets[to_remove->peer_bucket].tail, |
808 | to_remove); | 819 | to_remove); |
809 | GNUNET_assert(k_buckets[to_remove->peer_bucket].peers_size > 0); | 820 | GNUNET_assert (k_buckets[to_remove->peer_bucket].peers_size > 0); |
810 | k_buckets[to_remove->peer_bucket].peers_size--; | 821 | k_buckets[to_remove->peer_bucket].peers_size--; |
811 | while ((closest_bucket > 0) && | 822 | while ((closest_bucket > 0) && |
812 | (0 == k_buckets[to_remove->peer_bucket].peers_size)) | 823 | (0 == k_buckets[to_remove->peer_bucket].peers_size)) |
813 | closest_bucket--; | 824 | closest_bucket--; |
814 | if (k_buckets[to_remove->peer_bucket].peers_size < bucket_size) | 825 | if (k_buckets[to_remove->peer_bucket].peers_size < bucket_size) |
815 | update_connect_preferences(); | 826 | update_connect_preferences (); |
816 | GNUNET_free(to_remove); | 827 | GNUNET_free (to_remove); |
817 | } | 828 | } |
818 | 829 | ||
819 | 830 | ||
@@ -826,39 +837,39 @@ handle_core_disconnect(void *cls, | |||
826 | * @return Some number of peers to forward the message to | 837 | * @return Some number of peers to forward the message to |
827 | */ | 838 | */ |
828 | static unsigned int | 839 | static unsigned int |
829 | get_forward_count(uint32_t hop_count, | 840 | get_forward_count (uint32_t hop_count, |
830 | uint32_t target_replication) | 841 | uint32_t target_replication) |
831 | { | 842 | { |
832 | uint32_t random_value; | 843 | uint32_t random_value; |
833 | uint32_t forward_count; | 844 | uint32_t forward_count; |
834 | float target_value; | 845 | float target_value; |
835 | 846 | ||
836 | if (hop_count > GDS_NSE_get() * 4.0) | 847 | if (hop_count > GDS_NSE_get () * 4.0) |
837 | { | 848 | { |
838 | /* forcefully terminate */ | 849 | /* forcefully terminate */ |
839 | GNUNET_STATISTICS_update(GDS_stats, | 850 | GNUNET_STATISTICS_update (GDS_stats, |
840 | gettext_noop("# requests TTL-dropped"), | 851 | gettext_noop ("# requests TTL-dropped"), |
841 | 1, GNUNET_NO); | 852 | 1, GNUNET_NO); |
842 | return 0; | 853 | return 0; |
843 | } | 854 | } |
844 | if (hop_count > GDS_NSE_get() * 2.0) | 855 | if (hop_count > GDS_NSE_get () * 2.0) |
845 | { | 856 | { |
846 | /* Once we have reached our ideal number of hops, only forward to 1 peer */ | 857 | /* Once we have reached our ideal number of hops, only forward to 1 peer */ |
847 | return 1; | 858 | return 1; |
848 | } | 859 | } |
849 | /* bound by system-wide maximum */ | 860 | /* bound by system-wide maximum */ |
850 | target_replication = | 861 | target_replication = |
851 | GNUNET_MIN(MAXIMUM_REPLICATION_LEVEL, target_replication); | 862 | GNUNET_MIN (MAXIMUM_REPLICATION_LEVEL, target_replication); |
852 | target_value = | 863 | target_value = |
853 | 1 + (target_replication - 1.0) / (GDS_NSE_get() + | 864 | 1 + (target_replication - 1.0) / (GDS_NSE_get () |
854 | ((float)(target_replication - 1.0) * | 865 | + ((float) (target_replication - 1.0) |
855 | hop_count)); | 866 | * hop_count)); |
856 | /* Set forward count to floor of target_value */ | 867 | /* Set forward count to floor of target_value */ |
857 | forward_count = (uint32_t)target_value; | 868 | forward_count = (uint32_t) target_value; |
858 | /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */ | 869 | /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */ |
859 | target_value = target_value - forward_count; | 870 | target_value = target_value - forward_count; |
860 | random_value = | 871 | random_value = |
861 | GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); | 872 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); |
862 | if (random_value < (target_value * UINT32_MAX)) | 873 | if (random_value < (target_value * UINT32_MAX)) |
863 | forward_count++; | 874 | forward_count++; |
864 | return forward_count; | 875 | return forward_count; |
@@ -877,8 +888,8 @@ get_forward_count(uint32_t hop_count, | |||
877 | * the two hash codes increases | 888 | * the two hash codes increases |
878 | */ | 889 | */ |
879 | static unsigned int | 890 | static unsigned int |
880 | get_distance(const struct GNUNET_HashCode *target, | 891 | get_distance (const struct GNUNET_HashCode *target, |
881 | const struct GNUNET_HashCode *have) | 892 | const struct GNUNET_HashCode *have) |
882 | { | 893 | { |
883 | unsigned int bucket; | 894 | unsigned int bucket; |
884 | unsigned int msb; | 895 | unsigned int msb; |
@@ -900,13 +911,13 @@ get_distance(const struct GNUNET_HashCode *target, | |||
900 | 911 | ||
901 | /* first, calculate the most significant 9 bits of our | 912 | /* first, calculate the most significant 9 bits of our |
902 | * result, aka the number of LSBs */ | 913 | * result, aka the number of LSBs */ |
903 | bucket = GNUNET_CRYPTO_hash_matching_bits(target, | 914 | bucket = GNUNET_CRYPTO_hash_matching_bits (target, |
904 | have); | 915 | have); |
905 | /* bucket is now a value between 0 and 512 */ | 916 | /* bucket is now a value between 0 and 512 */ |
906 | if (bucket == 512) | 917 | if (bucket == 512) |
907 | return 0; /* perfect match */ | 918 | return 0; /* perfect match */ |
908 | if (bucket == 0) | 919 | if (bucket == 0) |
909 | return (unsigned int)-1; /* LSB differs; use max (if we did the bit-shifting | 920 | return (unsigned int) -1; /* LSB differs; use max (if we did the bit-shifting |
910 | * below, we'd end up with max+1 (overflow)) */ | 921 | * below, we'd end up with max+1 (overflow)) */ |
911 | 922 | ||
912 | /* calculate the most significant bits of the final result */ | 923 | /* calculate the most significant bits of the final result */ |
@@ -916,14 +927,15 @@ get_distance(const struct GNUNET_HashCode *target, | |||
916 | * mismatching bit at 'bucket' */ | 927 | * mismatching bit at 'bucket' */ |
917 | lsb = 0; | 928 | lsb = 0; |
918 | for (i = bucket + 1; | 929 | for (i = bucket + 1; |
919 | (i < sizeof(struct GNUNET_HashCode) * 8) && (i < bucket + 1 + 32 - 9); i++) | 930 | (i < sizeof(struct GNUNET_HashCode) * 8) && (i < bucket + 1 + 32 - 9); |
920 | { | 931 | i++) |
921 | if (GNUNET_CRYPTO_hash_get_bit(target, i) != | 932 | { |
922 | GNUNET_CRYPTO_hash_get_bit(have, i)) | 933 | if (GNUNET_CRYPTO_hash_get_bit (target, i) != |
923 | lsb |= (1 << (bucket + 32 - 9 - i)); /* first bit set will be 10, | 934 | GNUNET_CRYPTO_hash_get_bit (have, i)) |
935 | lsb |= (1 << (bucket + 32 - 9 - i)); /* first bit set will be 10, | ||
924 | * last bit set will be 31 -- if | 936 | * last bit set will be 31 -- if |
925 | * i does not reach 512 first... */ | 937 | * i does not reach 512 first... */ |
926 | } | 938 | } |
927 | return msb | lsb; | 939 | return msb | lsb; |
928 | } | 940 | } |
929 | 941 | ||
@@ -939,40 +951,40 @@ get_distance(const struct GNUNET_HashCode *target, | |||
939 | * #GNUNET_NO otherwise. | 951 | * #GNUNET_NO otherwise. |
940 | */ | 952 | */ |
941 | int | 953 | int |
942 | GDS_am_closest_peer(const struct GNUNET_HashCode *key, | 954 | GDS_am_closest_peer (const struct GNUNET_HashCode *key, |
943 | const struct GNUNET_CONTAINER_BloomFilter *bloom) | 955 | const struct GNUNET_CONTAINER_BloomFilter *bloom) |
944 | { | 956 | { |
945 | int bits; | 957 | int bits; |
946 | int other_bits; | 958 | int other_bits; |
947 | int bucket_num; | 959 | int bucket_num; |
948 | struct PeerInfo *pos; | 960 | struct PeerInfo *pos; |
949 | 961 | ||
950 | if (0 == GNUNET_memcmp(&my_identity_hash, | 962 | if (0 == GNUNET_memcmp (&my_identity_hash, |
951 | key)) | 963 | key)) |
952 | return GNUNET_YES; | 964 | return GNUNET_YES; |
953 | bucket_num = find_bucket(key); | 965 | bucket_num = find_bucket (key); |
954 | GNUNET_assert(bucket_num >= 0); | 966 | GNUNET_assert (bucket_num >= 0); |
955 | bits = GNUNET_CRYPTO_hash_matching_bits(&my_identity_hash, | 967 | bits = GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash, |
956 | key); | 968 | key); |
957 | pos = k_buckets[bucket_num].head; | 969 | pos = k_buckets[bucket_num].head; |
958 | while (NULL != pos) | 970 | while (NULL != pos) |
971 | { | ||
972 | if ((NULL != bloom) && | ||
973 | (GNUNET_YES == | ||
974 | GNUNET_CONTAINER_bloomfilter_test (bloom, | ||
975 | &pos->phash))) | ||
959 | { | 976 | { |
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; | ||
974 | pos = pos->next; | 977 | pos = pos->next; |
978 | continue; /* Skip already checked entries */ | ||
975 | } | 979 | } |
980 | other_bits = GNUNET_CRYPTO_hash_matching_bits (&pos->phash, | ||
981 | key); | ||
982 | if (other_bits > bits) | ||
983 | return GNUNET_NO; | ||
984 | if (other_bits == bits) /* We match the same number of bits */ | ||
985 | return GNUNET_YES; | ||
986 | pos = pos->next; | ||
987 | } | ||
976 | /* No peers closer, we are the closest! */ | 988 | /* No peers closer, we are the closest! */ |
977 | return GNUNET_YES; | 989 | return GNUNET_YES; |
978 | } | 990 | } |
@@ -996,9 +1008,9 @@ GDS_am_closest_peer(const struct GNUNET_HashCode *key, | |||
996 | * @return Peer to route to, or NULL on error | 1008 | * @return Peer to route to, or NULL on error |
997 | */ | 1009 | */ |
998 | static struct PeerInfo * | 1010 | static struct PeerInfo * |
999 | select_peer(const struct GNUNET_HashCode *key, | 1011 | select_peer (const struct GNUNET_HashCode *key, |
1000 | const struct GNUNET_CONTAINER_BloomFilter *bloom, | 1012 | const struct GNUNET_CONTAINER_BloomFilter *bloom, |
1001 | uint32_t hops) | 1013 | uint32_t hops) |
1002 | { | 1014 | { |
1003 | unsigned int bc; | 1015 | unsigned int bc; |
1004 | unsigned int count; | 1016 | unsigned int count; |
@@ -1008,126 +1020,129 @@ select_peer(const struct GNUNET_HashCode *key, | |||
1008 | unsigned int smallest_distance; | 1020 | unsigned int smallest_distance; |
1009 | struct PeerInfo *chosen; | 1021 | struct PeerInfo *chosen; |
1010 | 1022 | ||
1011 | if (hops >= GDS_NSE_get()) | 1023 | if (hops >= GDS_NSE_get ()) |
1024 | { | ||
1025 | /* greedy selection (closest peer that is not in bloomfilter) */ | ||
1026 | smallest_distance = UINT_MAX; | ||
1027 | chosen = NULL; | ||
1028 | for (bc = 0; bc <= closest_bucket; bc++) | ||
1012 | { | 1029 | { |
1013 | /* greedy selection (closest peer that is not in bloomfilter) */ | 1030 | pos = k_buckets[bc].head; |
1014 | smallest_distance = UINT_MAX; | 1031 | count = 0; |
1015 | chosen = NULL; | 1032 | while ((pos != NULL) && (count < bucket_size)) |
1016 | for (bc = 0; bc <= closest_bucket; bc++) | 1033 | { |
1034 | if ((NULL == bloom) || | ||
1035 | (GNUNET_NO == | ||
1036 | GNUNET_CONTAINER_bloomfilter_test (bloom, | ||
1037 | &pos->phash))) | ||
1038 | { | ||
1039 | dist = get_distance (key, | ||
1040 | &pos->phash); | ||
1041 | if (dist < smallest_distance) | ||
1042 | { | ||
1043 | chosen = pos; | ||
1044 | smallest_distance = dist; | ||
1045 | } | ||
1046 | } | ||
1047 | else | ||
1017 | { | 1048 | { |
1018 | pos = k_buckets[bc].head; | 1049 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1019 | count = 0; | 1050 | "Excluded peer `%s' due to BF match in greedy routing for %s\n", |
1020 | while ((pos != NULL) && (count < bucket_size)) | 1051 | GNUNET_i2s (pos->id), |
1021 | { | 1052 | GNUNET_h2s (key)); |
1022 | if ((NULL == bloom) || | 1053 | GNUNET_STATISTICS_update (GDS_stats, |
1023 | (GNUNET_NO == | 1054 | gettext_noop ( |
1024 | GNUNET_CONTAINER_bloomfilter_test(bloom, | 1055 | "# Peers excluded from routing due to Bloomfilter"), |
1025 | &pos->phash))) | 1056 | 1, |
1026 | { | 1057 | GNUNET_NO); |
1027 | dist = get_distance(key, | 1058 | dist = get_distance (key, |
1028 | &pos->phash); | 1059 | &pos->phash); |
1029 | if (dist < smallest_distance) | 1060 | if (dist < smallest_distance) |
1030 | { | 1061 | { |
1031 | chosen = pos; | 1062 | chosen = NULL; |
1032 | smallest_distance = dist; | 1063 | smallest_distance = dist; |
1033 | } | 1064 | } |
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 | } | ||
1056 | } | 1065 | } |
1057 | if (NULL == chosen) | 1066 | count++; |
1058 | GNUNET_STATISTICS_update(GDS_stats, | 1067 | pos = pos->next; |
1059 | gettext_noop("# Peer selection failed"), | 1068 | } |
1060 | 1, | ||
1061 | GNUNET_NO); | ||
1062 | else | ||
1063 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1064 | "Selected peer `%s' in greedy routing for %s\n", | ||
1065 | GNUNET_i2s(chosen->id), | ||
1066 | GNUNET_h2s(key)); | ||
1067 | return chosen; | ||
1068 | } | 1069 | } |
1070 | if (NULL == chosen) | ||
1071 | GNUNET_STATISTICS_update (GDS_stats, | ||
1072 | gettext_noop ("# Peer selection failed"), | ||
1073 | 1, | ||
1074 | GNUNET_NO); | ||
1075 | else | ||
1076 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1077 | "Selected peer `%s' in greedy routing for %s\n", | ||
1078 | GNUNET_i2s (chosen->id), | ||
1079 | GNUNET_h2s (key)); | ||
1080 | return chosen; | ||
1081 | } | ||
1069 | 1082 | ||
1070 | /* select "random" peer */ | 1083 | /* select "random" peer */ |
1071 | /* count number of peers that are available and not filtered */ | 1084 | /* count number of peers that are available and not filtered */ |
1072 | count = 0; | 1085 | count = 0; |
1073 | for (bc = 0; bc <= closest_bucket; bc++) | 1086 | for (bc = 0; bc <= closest_bucket; bc++) |
1087 | { | ||
1088 | pos = k_buckets[bc].head; | ||
1089 | while ((NULL != pos) && (count < bucket_size)) | ||
1074 | { | 1090 | { |
1075 | pos = k_buckets[bc].head; | 1091 | if ((NULL != bloom) && |
1076 | while ((NULL != pos) && (count < bucket_size)) | 1092 | (GNUNET_YES == |
1077 | { | 1093 | GNUNET_CONTAINER_bloomfilter_test (bloom, |
1078 | if ((NULL != bloom) && | 1094 | &pos->phash))) |
1079 | (GNUNET_YES == | 1095 | { |
1080 | GNUNET_CONTAINER_bloomfilter_test(bloom, | 1096 | GNUNET_STATISTICS_update (GDS_stats, |
1081 | &pos->phash))) | 1097 | gettext_noop |
1082 | { | 1098 | ( |
1083 | GNUNET_STATISTICS_update(GDS_stats, | 1099 | "# Peers excluded from routing due to Bloomfilter"), |
1084 | gettext_noop | 1100 | 1, GNUNET_NO); |
1085 | ("# Peers excluded from routing due to Bloomfilter"), | 1101 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1086 | 1, GNUNET_NO); | 1102 | "Excluded peer `%s' due to BF match in random routing for %s\n", |
1087 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1103 | GNUNET_i2s (pos->id), |
1088 | "Excluded peer `%s' due to BF match in random routing for %s\n", | 1104 | GNUNET_h2s (key)); |
1089 | GNUNET_i2s(pos->id), | 1105 | pos = pos->next; |
1090 | GNUNET_h2s(key)); | 1106 | continue; /* Ignore bloomfiltered peers */ |
1091 | pos = pos->next; | 1107 | } |
1092 | continue; /* Ignore bloomfiltered peers */ | 1108 | count++; |
1093 | } | 1109 | pos = pos->next; |
1094 | count++; | ||
1095 | pos = pos->next; | ||
1096 | } | ||
1097 | } | 1110 | } |
1111 | } | ||
1098 | if (0 == count) /* No peers to select from! */ | 1112 | if (0 == count) /* No peers to select from! */ |
1099 | { | 1113 | { |
1100 | GNUNET_STATISTICS_update(GDS_stats, | 1114 | GNUNET_STATISTICS_update (GDS_stats, |
1101 | gettext_noop("# Peer selection failed"), 1, | 1115 | gettext_noop ("# Peer selection failed"), 1, |
1102 | GNUNET_NO); | 1116 | GNUNET_NO); |
1103 | return NULL; | 1117 | return NULL; |
1104 | } | 1118 | } |
1105 | /* Now actually choose a peer */ | 1119 | /* Now actually choose a peer */ |
1106 | selected = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | 1120 | selected = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
1107 | count); | 1121 | count); |
1108 | count = 0; | 1122 | count = 0; |
1109 | for (bc = 0; bc <= closest_bucket; bc++) | 1123 | for (bc = 0; bc <= closest_bucket; bc++) |
1124 | { | ||
1125 | for (pos = k_buckets[bc].head; ((pos != NULL) && (count < bucket_size)); | ||
1126 | pos = pos->next) | ||
1110 | { | 1127 | { |
1111 | for (pos = k_buckets[bc].head; ((pos != NULL) && (count < bucket_size)); pos = pos->next) | 1128 | if ((bloom != NULL) && |
1112 | { | 1129 | (GNUNET_YES == |
1113 | if ((bloom != NULL) && | 1130 | GNUNET_CONTAINER_bloomfilter_test (bloom, |
1114 | (GNUNET_YES == | 1131 | &pos->phash))) |
1115 | GNUNET_CONTAINER_bloomfilter_test(bloom, | 1132 | { |
1116 | &pos->phash))) | 1133 | continue; /* Ignore bloomfiltered peers */ |
1117 | { | 1134 | } |
1118 | continue; /* Ignore bloomfiltered peers */ | 1135 | if (0 == selected--) |
1119 | } | 1136 | { |
1120 | if (0 == selected--) | 1137 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1121 | { | 1138 | "Selected peer `%s' in random routing for %s\n", |
1122 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1139 | GNUNET_i2s (pos->id), |
1123 | "Selected peer `%s' in random routing for %s\n", | 1140 | GNUNET_h2s (key)); |
1124 | GNUNET_i2s(pos->id), | 1141 | return pos; |
1125 | GNUNET_h2s(key)); | 1142 | } |
1126 | return pos; | ||
1127 | } | ||
1128 | } | ||
1129 | } | 1143 | } |
1130 | GNUNET_break(0); | 1144 | } |
1145 | GNUNET_break (0); | ||
1131 | return NULL; | 1146 | return NULL; |
1132 | } | 1147 | } |
1133 | 1148 | ||
@@ -1146,60 +1161,60 @@ select_peer(const struct GNUNET_HashCode *key, | |||
1146 | * @return number of peers returned in 'targets'. | 1161 | * @return number of peers returned in 'targets'. |
1147 | */ | 1162 | */ |
1148 | static unsigned int | 1163 | static unsigned int |
1149 | get_target_peers(const struct GNUNET_HashCode *key, | 1164 | get_target_peers (const struct GNUNET_HashCode *key, |
1150 | struct GNUNET_CONTAINER_BloomFilter *bloom, | 1165 | struct GNUNET_CONTAINER_BloomFilter *bloom, |
1151 | uint32_t hop_count, | 1166 | uint32_t hop_count, |
1152 | uint32_t target_replication, | 1167 | uint32_t target_replication, |
1153 | struct PeerInfo ***targets) | 1168 | struct PeerInfo ***targets) |
1154 | { | 1169 | { |
1155 | unsigned int ret; | 1170 | unsigned int ret; |
1156 | unsigned int off; | 1171 | unsigned int off; |
1157 | struct PeerInfo **rtargets; | 1172 | struct PeerInfo **rtargets; |
1158 | struct PeerInfo *nxt; | 1173 | struct PeerInfo *nxt; |
1159 | 1174 | ||
1160 | GNUNET_assert(NULL != bloom); | 1175 | GNUNET_assert (NULL != bloom); |
1161 | ret = get_forward_count(hop_count, | 1176 | ret = get_forward_count (hop_count, |
1162 | target_replication); | 1177 | target_replication); |
1163 | if (0 == ret) | 1178 | if (0 == ret) |
1164 | { | 1179 | { |
1165 | *targets = NULL; | 1180 | *targets = NULL; |
1166 | return 0; | 1181 | return 0; |
1167 | } | 1182 | } |
1168 | rtargets = GNUNET_new_array(ret, | 1183 | rtargets = GNUNET_new_array (ret, |
1169 | struct PeerInfo *); | 1184 | struct PeerInfo *); |
1170 | for (off = 0; off < ret; off++) | 1185 | for (off = 0; off < ret; off++) |
1171 | { | 1186 | { |
1172 | nxt = select_peer(key, | 1187 | nxt = select_peer (key, |
1173 | bloom, | 1188 | bloom, |
1174 | hop_count); | 1189 | hop_count); |
1175 | if (NULL == nxt) | 1190 | if (NULL == nxt) |
1176 | break; | 1191 | break; |
1177 | rtargets[off] = nxt; | 1192 | rtargets[off] = nxt; |
1178 | GNUNET_break(GNUNET_NO == | 1193 | GNUNET_break (GNUNET_NO == |
1179 | GNUNET_CONTAINER_bloomfilter_test(bloom, | 1194 | GNUNET_CONTAINER_bloomfilter_test (bloom, |
1180 | &nxt->phash)); | 1195 | &nxt->phash)); |
1181 | GNUNET_CONTAINER_bloomfilter_add(bloom, | 1196 | GNUNET_CONTAINER_bloomfilter_add (bloom, |
1182 | &nxt->phash); | 1197 | &nxt->phash); |
1183 | } | 1198 | } |
1184 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1185 | "Selected %u/%u peers at hop %u for %s (target was %u)\n", | 1200 | "Selected %u/%u peers at hop %u for %s (target was %u)\n", |
1186 | off, | 1201 | off, |
1187 | GNUNET_CONTAINER_multipeermap_size(all_connected_peers), | 1202 | GNUNET_CONTAINER_multipeermap_size (all_connected_peers), |
1188 | (unsigned int)hop_count, | 1203 | (unsigned int) hop_count, |
1189 | GNUNET_h2s(key), | 1204 | GNUNET_h2s (key), |
1190 | ret); | 1205 | ret); |
1191 | if (0 == off) | 1206 | if (0 == off) |
1192 | { | 1207 | { |
1193 | GNUNET_free(rtargets); | 1208 | GNUNET_free (rtargets); |
1194 | *targets = NULL; | 1209 | *targets = NULL; |
1195 | return 0; | 1210 | return 0; |
1196 | } | 1211 | } |
1197 | *targets = rtargets; | 1212 | *targets = rtargets; |
1198 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1213 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1199 | "Forwarding query `%s' to %u peers (goal was %u peers)\n", | 1214 | "Forwarding query `%s' to %u peers (goal was %u peers)\n", |
1200 | GNUNET_h2s(key), | 1215 | GNUNET_h2s (key), |
1201 | off, | 1216 | off, |
1202 | ret); | 1217 | ret); |
1203 | return off; | 1218 | return off; |
1204 | } | 1219 | } |
1205 | 1220 | ||
@@ -1225,17 +1240,17 @@ get_target_peers(const struct GNUNET_HashCode *key, | |||
1225 | * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not | 1240 | * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not |
1226 | */ | 1241 | */ |
1227 | int | 1242 | int |
1228 | GDS_NEIGHBOURS_handle_put(enum GNUNET_BLOCK_Type type, | 1243 | GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, |
1229 | enum GNUNET_DHT_RouteOption options, | 1244 | enum GNUNET_DHT_RouteOption options, |
1230 | uint32_t desired_replication_level, | 1245 | uint32_t desired_replication_level, |
1231 | struct GNUNET_TIME_Absolute expiration_time, | 1246 | struct GNUNET_TIME_Absolute expiration_time, |
1232 | uint32_t hop_count, | 1247 | uint32_t hop_count, |
1233 | struct GNUNET_CONTAINER_BloomFilter *bf, | 1248 | struct GNUNET_CONTAINER_BloomFilter *bf, |
1234 | const struct GNUNET_HashCode *key, | 1249 | const struct GNUNET_HashCode *key, |
1235 | unsigned int put_path_length, | 1250 | unsigned int put_path_length, |
1236 | struct GNUNET_PeerIdentity *put_path, | 1251 | struct GNUNET_PeerIdentity *put_path, |
1237 | const void *data, | 1252 | const void *data, |
1238 | size_t data_size) | 1253 | size_t data_size) |
1239 | { | 1254 | { |
1240 | unsigned int target_count; | 1255 | unsigned int target_count; |
1241 | unsigned int i; | 1256 | unsigned int i; |
@@ -1247,97 +1262,99 @@ GDS_NEIGHBOURS_handle_put(enum GNUNET_BLOCK_Type type, | |||
1247 | struct GNUNET_PeerIdentity *pp; | 1262 | struct GNUNET_PeerIdentity *pp; |
1248 | unsigned int skip_count; | 1263 | unsigned int skip_count; |
1249 | 1264 | ||
1250 | GNUNET_assert(NULL != bf); | 1265 | GNUNET_assert (NULL != bf); |
1251 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1266 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1252 | "Adding myself (%s) to PUT bloomfilter for %s\n", | 1267 | "Adding myself (%s) to PUT bloomfilter for %s\n", |
1253 | GNUNET_i2s(&my_identity), | 1268 | GNUNET_i2s (&my_identity), |
1254 | GNUNET_h2s(key)); | 1269 | GNUNET_h2s (key)); |
1255 | GNUNET_CONTAINER_bloomfilter_add(bf, | 1270 | GNUNET_CONTAINER_bloomfilter_add (bf, |
1256 | &my_identity_hash); | 1271 | &my_identity_hash); |
1257 | GNUNET_STATISTICS_update(GDS_stats, | 1272 | GNUNET_STATISTICS_update (GDS_stats, |
1258 | gettext_noop("# PUT requests routed"), | 1273 | gettext_noop ("# PUT requests routed"), |
1259 | 1, | 1274 | 1, |
1260 | GNUNET_NO); | 1275 | GNUNET_NO); |
1261 | target_count | 1276 | target_count |
1262 | = get_target_peers(key, | 1277 | = get_target_peers (key, |
1263 | bf, | 1278 | bf, |
1264 | hop_count, | 1279 | hop_count, |
1265 | desired_replication_level, | 1280 | desired_replication_level, |
1266 | &targets); | 1281 | &targets); |
1267 | if (0 == target_count) | 1282 | if (0 == target_count) |
1268 | { | 1283 | { |
1269 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1284 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1270 | "Routing PUT for %s terminates after %u hops at %s\n", | 1285 | "Routing PUT for %s terminates after %u hops at %s\n", |
1271 | GNUNET_h2s(key), | 1286 | GNUNET_h2s (key), |
1272 | (unsigned int)hop_count, | 1287 | (unsigned int) hop_count, |
1273 | GNUNET_i2s(&my_identity)); | 1288 | GNUNET_i2s (&my_identity)); |
1274 | return GNUNET_NO; | 1289 | return GNUNET_NO; |
1275 | } | 1290 | } |
1276 | msize = put_path_length * sizeof(struct GNUNET_PeerIdentity) + data_size; | 1291 | msize = put_path_length * sizeof(struct GNUNET_PeerIdentity) + data_size; |
1277 | if (msize + sizeof(struct PeerPutMessage) | 1292 | if (msize + sizeof(struct PeerPutMessage) |
1278 | >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | 1293 | >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) |
1279 | { | 1294 | { |
1280 | put_path_length = 0; | 1295 | put_path_length = 0; |
1281 | msize = data_size; | 1296 | msize = data_size; |
1282 | } | 1297 | } |
1283 | if (msize + sizeof(struct PeerPutMessage) | 1298 | if (msize + sizeof(struct PeerPutMessage) |
1284 | >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | 1299 | >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) |
1285 | { | 1300 | { |
1286 | GNUNET_break(0); | 1301 | GNUNET_break (0); |
1287 | GNUNET_free(targets); | 1302 | GNUNET_free (targets); |
1288 | return GNUNET_NO; | 1303 | return GNUNET_NO; |
1289 | } | 1304 | } |
1290 | GNUNET_STATISTICS_update(GDS_stats, | 1305 | GNUNET_STATISTICS_update (GDS_stats, |
1291 | gettext_noop("# PUT messages queued for transmission"), | 1306 | gettext_noop ( |
1292 | target_count, | 1307 | "# PUT messages queued for transmission"), |
1293 | GNUNET_NO); | 1308 | target_count, |
1309 | GNUNET_NO); | ||
1294 | skip_count = 0; | 1310 | skip_count = 0; |
1295 | for (i = 0; i < target_count; i++) | 1311 | for (i = 0; i < target_count; i++) |
1312 | { | ||
1313 | target = targets[i]; | ||
1314 | if (GNUNET_MQ_get_length (target->mq) >= MAXIMUM_PENDING_PER_PEER) | ||
1296 | { | 1315 | { |
1297 | target = targets[i]; | 1316 | /* skip */ |
1298 | if (GNUNET_MQ_get_length(target->mq) >= MAXIMUM_PENDING_PER_PEER) | 1317 | GNUNET_STATISTICS_update (GDS_stats, |
1299 | { | 1318 | gettext_noop ( |
1300 | /* skip */ | 1319 | "# P2P messages dropped due to full queue"), |
1301 | GNUNET_STATISTICS_update(GDS_stats, | 1320 | 1, |
1302 | gettext_noop("# P2P messages dropped due to full queue"), | 1321 | GNUNET_NO); |
1303 | 1, | 1322 | skip_count++; |
1304 | GNUNET_NO); | 1323 | continue; |
1305 | skip_count++; | 1324 | } |
1306 | continue; | 1325 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1307 | } | 1326 | "Routing PUT for %s after %u hops to %s\n", |
1308 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1327 | GNUNET_h2s (key), |
1309 | "Routing PUT for %s after %u hops to %s\n", | 1328 | (unsigned int) hop_count, |
1310 | GNUNET_h2s(key), | 1329 | GNUNET_i2s (target->id)); |
1311 | (unsigned int)hop_count, | 1330 | env = GNUNET_MQ_msg_extra (ppm, |
1312 | GNUNET_i2s(target->id)); | 1331 | msize, |
1313 | env = GNUNET_MQ_msg_extra(ppm, | 1332 | GNUNET_MESSAGE_TYPE_DHT_P2P_PUT); |
1314 | msize, | 1333 | ppm->options = htonl (options); |
1315 | GNUNET_MESSAGE_TYPE_DHT_P2P_PUT); | 1334 | ppm->type = htonl (type); |
1316 | ppm->options = htonl(options); | 1335 | ppm->hop_count = htonl (hop_count + 1); |
1317 | ppm->type = htonl(type); | 1336 | ppm->desired_replication_level = htonl (desired_replication_level); |
1318 | ppm->hop_count = htonl(hop_count + 1); | 1337 | ppm->put_path_length = htonl (put_path_length); |
1319 | ppm->desired_replication_level = htonl(desired_replication_level); | 1338 | ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); |
1320 | ppm->put_path_length = htonl(put_path_length); | 1339 | GNUNET_break (GNUNET_YES == |
1321 | ppm->expiration_time = GNUNET_TIME_absolute_hton(expiration_time); | 1340 | GNUNET_CONTAINER_bloomfilter_test (bf, |
1322 | GNUNET_break(GNUNET_YES == | ||
1323 | GNUNET_CONTAINER_bloomfilter_test(bf, | ||
1324 | &target->phash)); | 1341 | &target->phash)); |
1325 | GNUNET_assert(GNUNET_OK == | 1342 | GNUNET_assert (GNUNET_OK == |
1326 | GNUNET_CONTAINER_bloomfilter_get_raw_data(bf, | 1343 | GNUNET_CONTAINER_bloomfilter_get_raw_data (bf, |
1327 | ppm->bloomfilter, | 1344 | ppm->bloomfilter, |
1328 | DHT_BLOOM_SIZE)); | 1345 | DHT_BLOOM_SIZE)); |
1329 | ppm->key = *key; | 1346 | ppm->key = *key; |
1330 | pp = (struct GNUNET_PeerIdentity *)&ppm[1]; | 1347 | pp = (struct GNUNET_PeerIdentity *) &ppm[1]; |
1331 | GNUNET_memcpy(pp, | 1348 | GNUNET_memcpy (pp, |
1332 | put_path, | 1349 | put_path, |
1333 | sizeof(struct GNUNET_PeerIdentity) * put_path_length); | 1350 | sizeof(struct GNUNET_PeerIdentity) * put_path_length); |
1334 | GNUNET_memcpy(&pp[put_path_length], | 1351 | GNUNET_memcpy (&pp[put_path_length], |
1335 | data, | 1352 | data, |
1336 | data_size); | 1353 | data_size); |
1337 | GNUNET_MQ_send(target->mq, | 1354 | GNUNET_MQ_send (target->mq, |
1338 | env); | 1355 | env); |
1339 | } | 1356 | } |
1340 | GNUNET_free(targets); | 1357 | GNUNET_free (targets); |
1341 | return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO; | 1358 | return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO; |
1342 | } | 1359 | } |
1343 | 1360 | ||
@@ -1360,15 +1377,15 @@ GDS_NEIGHBOURS_handle_put(enum GNUNET_BLOCK_Type type, | |||
1360 | * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not | 1377 | * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not |
1361 | */ | 1378 | */ |
1362 | int | 1379 | int |
1363 | GDS_NEIGHBOURS_handle_get(enum GNUNET_BLOCK_Type type, | 1380 | GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, |
1364 | enum GNUNET_DHT_RouteOption options, | 1381 | enum GNUNET_DHT_RouteOption options, |
1365 | uint32_t desired_replication_level, | 1382 | uint32_t desired_replication_level, |
1366 | uint32_t hop_count, | 1383 | uint32_t hop_count, |
1367 | const struct GNUNET_HashCode *key, | 1384 | const struct GNUNET_HashCode *key, |
1368 | const void *xquery, | 1385 | const void *xquery, |
1369 | size_t xquery_size, | 1386 | size_t xquery_size, |
1370 | struct GNUNET_BLOCK_Group *bg, | 1387 | struct GNUNET_BLOCK_Group *bg, |
1371 | struct GNUNET_CONTAINER_BloomFilter *peer_bf) | 1388 | struct GNUNET_CONTAINER_BloomFilter *peer_bf) |
1372 | { | 1389 | { |
1373 | unsigned int target_count; | 1390 | unsigned int target_count; |
1374 | struct PeerInfo **targets; | 1391 | struct PeerInfo **targets; |
@@ -1382,102 +1399,104 @@ GDS_NEIGHBOURS_handle_get(enum GNUNET_BLOCK_Type type, | |||
1382 | unsigned int skip_count; | 1399 | unsigned int skip_count; |
1383 | uint32_t bf_nonce; | 1400 | uint32_t bf_nonce; |
1384 | 1401 | ||
1385 | GNUNET_assert(NULL != peer_bf); | 1402 | GNUNET_assert (NULL != peer_bf); |
1386 | GNUNET_STATISTICS_update(GDS_stats, | 1403 | GNUNET_STATISTICS_update (GDS_stats, |
1387 | gettext_noop("# GET requests routed"), | 1404 | gettext_noop ("# GET requests routed"), |
1388 | 1, | 1405 | 1, |
1389 | GNUNET_NO); | 1406 | GNUNET_NO); |
1390 | target_count = get_target_peers(key, | 1407 | target_count = get_target_peers (key, |
1391 | peer_bf, | 1408 | peer_bf, |
1392 | hop_count, | 1409 | hop_count, |
1393 | desired_replication_level, | 1410 | desired_replication_level, |
1394 | &targets); | 1411 | &targets); |
1395 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1412 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1396 | "Adding myself (%s) to GET bloomfilter for %s\n", | 1413 | "Adding myself (%s) to GET bloomfilter for %s\n", |
1397 | GNUNET_i2s(&my_identity), | 1414 | GNUNET_i2s (&my_identity), |
1398 | GNUNET_h2s(key)); | 1415 | GNUNET_h2s (key)); |
1399 | GNUNET_CONTAINER_bloomfilter_add(peer_bf, | 1416 | GNUNET_CONTAINER_bloomfilter_add (peer_bf, |
1400 | &my_identity_hash); | 1417 | &my_identity_hash); |
1401 | if (0 == target_count) | 1418 | if (0 == target_count) |
1402 | { | 1419 | { |
1403 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1420 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1404 | "Routing GET for %s terminates after %u hops at %s\n", | 1421 | "Routing GET for %s terminates after %u hops at %s\n", |
1405 | GNUNET_h2s(key), | 1422 | GNUNET_h2s (key), |
1406 | (unsigned int)hop_count, | 1423 | (unsigned int) hop_count, |
1407 | GNUNET_i2s(&my_identity)); | 1424 | GNUNET_i2s (&my_identity)); |
1408 | return GNUNET_NO; | 1425 | return GNUNET_NO; |
1409 | } | 1426 | } |
1410 | if (GNUNET_OK != | 1427 | if (GNUNET_OK != |
1411 | GNUNET_BLOCK_group_serialize(bg, | 1428 | GNUNET_BLOCK_group_serialize (bg, |
1412 | &bf_nonce, | 1429 | &bf_nonce, |
1413 | &reply_bf, | 1430 | &reply_bf, |
1414 | &reply_bf_size)) | 1431 | &reply_bf_size)) |
1415 | { | 1432 | { |
1416 | reply_bf = NULL; | 1433 | reply_bf = NULL; |
1417 | reply_bf_size = 0; | 1434 | reply_bf_size = 0; |
1418 | bf_nonce = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | 1435 | bf_nonce = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
1419 | UINT32_MAX); | 1436 | UINT32_MAX); |
1420 | } | 1437 | } |
1421 | msize = xquery_size + reply_bf_size; | 1438 | msize = xquery_size + reply_bf_size; |
1422 | if (msize + sizeof(struct PeerGetMessage) >= GNUNET_MAX_MESSAGE_SIZE) | 1439 | if (msize + sizeof(struct PeerGetMessage) >= GNUNET_MAX_MESSAGE_SIZE) |
1423 | { | 1440 | { |
1424 | GNUNET_break(0); | 1441 | GNUNET_break (0); |
1425 | GNUNET_free_non_null(reply_bf); | 1442 | GNUNET_free_non_null (reply_bf); |
1426 | GNUNET_free(targets); | 1443 | GNUNET_free (targets); |
1427 | return GNUNET_NO; | 1444 | return GNUNET_NO; |
1428 | } | 1445 | } |
1429 | GNUNET_STATISTICS_update(GDS_stats, | 1446 | GNUNET_STATISTICS_update (GDS_stats, |
1430 | gettext_noop("# GET messages queued for transmission"), | 1447 | gettext_noop ( |
1431 | target_count, | 1448 | "# GET messages queued for transmission"), |
1432 | GNUNET_NO); | 1449 | target_count, |
1450 | GNUNET_NO); | ||
1433 | /* forward request */ | 1451 | /* forward request */ |
1434 | skip_count = 0; | 1452 | skip_count = 0; |
1435 | for (unsigned int i = 0; i < target_count; i++) | 1453 | for (unsigned int i = 0; i < target_count; i++) |
1454 | { | ||
1455 | target = targets[i]; | ||
1456 | if (GNUNET_MQ_get_length (target->mq) >= MAXIMUM_PENDING_PER_PEER) | ||
1436 | { | 1457 | { |
1437 | target = targets[i]; | 1458 | /* skip */ |
1438 | if (GNUNET_MQ_get_length(target->mq) >= MAXIMUM_PENDING_PER_PEER) | 1459 | GNUNET_STATISTICS_update (GDS_stats, |
1439 | { | 1460 | gettext_noop ( |
1440 | /* skip */ | 1461 | "# P2P messages dropped due to full queue"), |
1441 | GNUNET_STATISTICS_update(GDS_stats, | 1462 | 1, GNUNET_NO); |
1442 | gettext_noop("# P2P messages dropped due to full queue"), | 1463 | skip_count++; |
1443 | 1, GNUNET_NO); | 1464 | continue; |
1444 | skip_count++; | 1465 | } |
1445 | continue; | 1466 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1446 | } | 1467 | "Routing GET for %s after %u hops to %s\n", |
1447 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1468 | GNUNET_h2s (key), |
1448 | "Routing GET for %s after %u hops to %s\n", | 1469 | (unsigned int) hop_count, |
1449 | GNUNET_h2s(key), | 1470 | GNUNET_i2s (target->id)); |
1450 | (unsigned int)hop_count, | 1471 | env = GNUNET_MQ_msg_extra (pgm, |
1451 | GNUNET_i2s(target->id)); | 1472 | msize, |
1452 | env = GNUNET_MQ_msg_extra(pgm, | 1473 | GNUNET_MESSAGE_TYPE_DHT_P2P_GET); |
1453 | msize, | 1474 | pgm->options = htonl (options); |
1454 | GNUNET_MESSAGE_TYPE_DHT_P2P_GET); | 1475 | pgm->type = htonl (type); |
1455 | pgm->options = htonl(options); | 1476 | pgm->hop_count = htonl (hop_count + 1); |
1456 | pgm->type = htonl(type); | 1477 | pgm->desired_replication_level = htonl (desired_replication_level); |
1457 | pgm->hop_count = htonl(hop_count + 1); | 1478 | pgm->xquery_size = htonl (xquery_size); |
1458 | pgm->desired_replication_level = htonl(desired_replication_level); | 1479 | pgm->bf_mutator = bf_nonce; |
1459 | pgm->xquery_size = htonl(xquery_size); | 1480 | GNUNET_break (GNUNET_YES == |
1460 | pgm->bf_mutator = bf_nonce; | 1481 | GNUNET_CONTAINER_bloomfilter_test (peer_bf, |
1461 | GNUNET_break(GNUNET_YES == | ||
1462 | GNUNET_CONTAINER_bloomfilter_test(peer_bf, | ||
1463 | &target->phash)); | 1482 | &target->phash)); |
1464 | GNUNET_assert(GNUNET_OK == | 1483 | GNUNET_assert (GNUNET_OK == |
1465 | GNUNET_CONTAINER_bloomfilter_get_raw_data(peer_bf, | 1484 | GNUNET_CONTAINER_bloomfilter_get_raw_data (peer_bf, |
1466 | pgm->bloomfilter, | 1485 | pgm->bloomfilter, |
1467 | DHT_BLOOM_SIZE)); | 1486 | DHT_BLOOM_SIZE)); |
1468 | pgm->key = *key; | 1487 | pgm->key = *key; |
1469 | xq = (char *)&pgm[1]; | 1488 | xq = (char *) &pgm[1]; |
1470 | GNUNET_memcpy(xq, | 1489 | GNUNET_memcpy (xq, |
1471 | xquery, | 1490 | xquery, |
1472 | xquery_size); | 1491 | xquery_size); |
1473 | GNUNET_memcpy(&xq[xquery_size], | 1492 | GNUNET_memcpy (&xq[xquery_size], |
1474 | reply_bf, | 1493 | reply_bf, |
1475 | reply_bf_size); | 1494 | reply_bf_size); |
1476 | GNUNET_MQ_send(target->mq, | 1495 | GNUNET_MQ_send (target->mq, |
1477 | env); | 1496 | env); |
1478 | } | 1497 | } |
1479 | GNUNET_free(targets); | 1498 | GNUNET_free (targets); |
1480 | GNUNET_free_non_null(reply_bf); | 1499 | GNUNET_free_non_null (reply_bf); |
1481 | return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO; | 1500 | return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO; |
1482 | } | 1501 | } |
1483 | 1502 | ||
@@ -1499,16 +1518,16 @@ GDS_NEIGHBOURS_handle_get(enum GNUNET_BLOCK_Type type, | |||
1499 | * @param data_size number of bytes in @a data | 1518 | * @param data_size number of bytes in @a data |
1500 | */ | 1519 | */ |
1501 | void | 1520 | void |
1502 | GDS_NEIGHBOURS_handle_reply(const struct GNUNET_PeerIdentity *target, | 1521 | GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, |
1503 | enum GNUNET_BLOCK_Type type, | 1522 | enum GNUNET_BLOCK_Type type, |
1504 | struct GNUNET_TIME_Absolute expiration_time, | 1523 | struct GNUNET_TIME_Absolute expiration_time, |
1505 | const struct GNUNET_HashCode *key, | 1524 | const struct GNUNET_HashCode *key, |
1506 | unsigned int put_path_length, | 1525 | unsigned int put_path_length, |
1507 | const struct GNUNET_PeerIdentity *put_path, | 1526 | const struct GNUNET_PeerIdentity *put_path, |
1508 | unsigned int get_path_length, | 1527 | unsigned int get_path_length, |
1509 | const struct GNUNET_PeerIdentity *get_path, | 1528 | const struct GNUNET_PeerIdentity *get_path, |
1510 | const void *data, | 1529 | const void *data, |
1511 | size_t data_size) | 1530 | size_t data_size) |
1512 | { | 1531 | { |
1513 | struct PeerInfo *pi; | 1532 | struct PeerInfo *pi; |
1514 | struct GNUNET_MQ_Envelope *env; | 1533 | struct GNUNET_MQ_Envelope *env; |
@@ -1516,69 +1535,70 @@ GDS_NEIGHBOURS_handle_reply(const struct GNUNET_PeerIdentity *target, | |||
1516 | struct PeerResultMessage *prm; | 1535 | struct PeerResultMessage *prm; |
1517 | struct GNUNET_PeerIdentity *paths; | 1536 | struct GNUNET_PeerIdentity *paths; |
1518 | 1537 | ||
1519 | msize = data_size + (get_path_length + put_path_length) * | 1538 | msize = data_size + (get_path_length + put_path_length) |
1520 | sizeof(struct GNUNET_PeerIdentity); | 1539 | * sizeof(struct GNUNET_PeerIdentity); |
1521 | if ((msize + sizeof(struct PeerResultMessage) >= GNUNET_MAX_MESSAGE_SIZE) || | 1540 | if ((msize + sizeof(struct PeerResultMessage) >= GNUNET_MAX_MESSAGE_SIZE) || |
1522 | (get_path_length > | 1541 | (get_path_length > |
1523 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) || | 1542 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) || |
1524 | (put_path_length > | 1543 | (put_path_length > |
1525 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) || | 1544 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) || |
1526 | (data_size > GNUNET_MAX_MESSAGE_SIZE)) | 1545 | (data_size > GNUNET_MAX_MESSAGE_SIZE)) |
1527 | { | 1546 | { |
1528 | GNUNET_break(0); | 1547 | GNUNET_break (0); |
1529 | return; | 1548 | return; |
1530 | } | 1549 | } |
1531 | pi = GNUNET_CONTAINER_multipeermap_get(all_connected_peers, | 1550 | pi = GNUNET_CONTAINER_multipeermap_get (all_connected_peers, |
1532 | target); | 1551 | target); |
1533 | if (NULL == pi) | 1552 | if (NULL == pi) |
1534 | { | 1553 | { |
1535 | /* peer disconnected in the meantime, drop reply */ | 1554 | /* peer disconnected in the meantime, drop reply */ |
1536 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1555 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1537 | "No matching peer for reply for key %s\n", | 1556 | "No matching peer for reply for key %s\n", |
1538 | GNUNET_h2s(key)); | 1557 | GNUNET_h2s (key)); |
1539 | return; | 1558 | return; |
1540 | } | 1559 | } |
1541 | if (GNUNET_MQ_get_length(pi->mq) >= MAXIMUM_PENDING_PER_PEER) | 1560 | if (GNUNET_MQ_get_length (pi->mq) >= MAXIMUM_PENDING_PER_PEER) |
1542 | { | 1561 | { |
1543 | /* skip */ | 1562 | /* skip */ |
1544 | GNUNET_STATISTICS_update(GDS_stats, | 1563 | GNUNET_STATISTICS_update (GDS_stats, |
1545 | gettext_noop("# P2P messages dropped due to full queue"), | 1564 | gettext_noop ( |
1546 | 1, | 1565 | "# P2P messages dropped due to full queue"), |
1547 | GNUNET_NO); | 1566 | 1, |
1548 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1567 | GNUNET_NO); |
1549 | "Peer queue full, ignoring reply for key %s\n", | 1568 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1550 | GNUNET_h2s(key)); | 1569 | "Peer queue full, ignoring reply for key %s\n", |
1551 | return; | 1570 | GNUNET_h2s (key)); |
1552 | } | 1571 | return; |
1572 | } | ||
1553 | 1573 | ||
1554 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1574 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1555 | "Forwarding reply for key %s to peer %s\n", | 1575 | "Forwarding reply for key %s to peer %s\n", |
1556 | GNUNET_h2s(key), | 1576 | GNUNET_h2s (key), |
1557 | GNUNET_i2s(target)); | 1577 | GNUNET_i2s (target)); |
1558 | GNUNET_STATISTICS_update(GDS_stats, | 1578 | GNUNET_STATISTICS_update (GDS_stats, |
1559 | gettext_noop | 1579 | gettext_noop |
1560 | ("# RESULT messages queued for transmission"), 1, | 1580 | ("# RESULT messages queued for transmission"), 1, |
1561 | GNUNET_NO); | 1581 | GNUNET_NO); |
1562 | env = GNUNET_MQ_msg_extra(prm, | 1582 | env = GNUNET_MQ_msg_extra (prm, |
1563 | msize, | 1583 | msize, |
1564 | GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT); | 1584 | GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT); |
1565 | prm->type = htonl(type); | 1585 | prm->type = htonl (type); |
1566 | prm->put_path_length = htonl(put_path_length); | 1586 | prm->put_path_length = htonl (put_path_length); |
1567 | prm->get_path_length = htonl(get_path_length); | 1587 | prm->get_path_length = htonl (get_path_length); |
1568 | prm->expiration_time = GNUNET_TIME_absolute_hton(expiration_time); | 1588 | prm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); |
1569 | prm->key = *key; | 1589 | prm->key = *key; |
1570 | paths = (struct GNUNET_PeerIdentity *)&prm[1]; | 1590 | paths = (struct GNUNET_PeerIdentity *) &prm[1]; |
1571 | GNUNET_memcpy(paths, | 1591 | GNUNET_memcpy (paths, |
1572 | put_path, | 1592 | put_path, |
1573 | put_path_length * sizeof(struct GNUNET_PeerIdentity)); | 1593 | put_path_length * sizeof(struct GNUNET_PeerIdentity)); |
1574 | GNUNET_memcpy(&paths[put_path_length], | 1594 | GNUNET_memcpy (&paths[put_path_length], |
1575 | get_path, | 1595 | get_path, |
1576 | get_path_length * sizeof(struct GNUNET_PeerIdentity)); | 1596 | get_path_length * sizeof(struct GNUNET_PeerIdentity)); |
1577 | GNUNET_memcpy(&paths[put_path_length + get_path_length], | 1597 | GNUNET_memcpy (&paths[put_path_length + get_path_length], |
1578 | data, | 1598 | data, |
1579 | data_size); | 1599 | data_size); |
1580 | GNUNET_MQ_send(pi->mq, | 1600 | GNUNET_MQ_send (pi->mq, |
1581 | env); | 1601 | env); |
1582 | } | 1602 | } |
1583 | 1603 | ||
1584 | 1604 | ||
@@ -1589,18 +1609,18 @@ GDS_NEIGHBOURS_handle_reply(const struct GNUNET_PeerIdentity *target, | |||
1589 | * @param identity the public identity of this peer | 1609 | * @param identity the public identity of this peer |
1590 | */ | 1610 | */ |
1591 | static void | 1611 | static void |
1592 | core_init(void *cls, | 1612 | core_init (void *cls, |
1593 | const struct GNUNET_PeerIdentity *identity) | 1613 | const struct GNUNET_PeerIdentity *identity) |
1594 | { | 1614 | { |
1595 | (void)cls; | 1615 | (void) cls; |
1596 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1616 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1597 | "CORE called, I am %s\n", | 1617 | "CORE called, I am %s\n", |
1598 | GNUNET_i2s(identity)); | 1618 | GNUNET_i2s (identity)); |
1599 | my_identity = *identity; | 1619 | my_identity = *identity; |
1600 | GNUNET_CRYPTO_hash(identity, | 1620 | GNUNET_CRYPTO_hash (identity, |
1601 | sizeof(struct GNUNET_PeerIdentity), | 1621 | sizeof(struct GNUNET_PeerIdentity), |
1602 | &my_identity_hash); | 1622 | &my_identity_hash); |
1603 | GNUNET_SERVICE_resume(GDS_service); | 1623 | GNUNET_SERVICE_resume (GDS_service); |
1604 | } | 1624 | } |
1605 | 1625 | ||
1606 | 1626 | ||
@@ -1612,24 +1632,24 @@ core_init(void *cls, | |||
1612 | * @return #GNUNET_OK if the message is valid | 1632 | * @return #GNUNET_OK if the message is valid |
1613 | */ | 1633 | */ |
1614 | static int | 1634 | static int |
1615 | check_dht_p2p_put(void *cls, | 1635 | check_dht_p2p_put (void *cls, |
1616 | const struct PeerPutMessage *put) | 1636 | const struct PeerPutMessage *put) |
1617 | { | 1637 | { |
1618 | uint32_t putlen; | 1638 | uint32_t putlen; |
1619 | uint16_t msize; | 1639 | uint16_t msize; |
1620 | 1640 | ||
1621 | (void)cls; | 1641 | (void) cls; |
1622 | msize = ntohs(put->header.size); | 1642 | msize = ntohs (put->header.size); |
1623 | putlen = ntohl(put->put_path_length); | 1643 | putlen = ntohl (put->put_path_length); |
1624 | if ((msize < | 1644 | if ((msize < |
1625 | sizeof(struct PeerPutMessage) + | 1645 | sizeof(struct PeerPutMessage) |
1626 | putlen * sizeof(struct GNUNET_PeerIdentity)) || | 1646 | + putlen * sizeof(struct GNUNET_PeerIdentity)) || |
1627 | (putlen > | 1647 | (putlen > |
1628 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity))) | 1648 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity))) |
1629 | { | 1649 | { |
1630 | GNUNET_break_op(0); | 1650 | GNUNET_break_op (0); |
1631 | return GNUNET_SYSERR; | 1651 | return GNUNET_SYSERR; |
1632 | } | 1652 | } |
1633 | return GNUNET_OK; | 1653 | return GNUNET_OK; |
1634 | } | 1654 | } |
1635 | 1655 | ||
@@ -1641,8 +1661,8 @@ check_dht_p2p_put(void *cls, | |||
1641 | * @param message message | 1661 | * @param message message |
1642 | */ | 1662 | */ |
1643 | static void | 1663 | static void |
1644 | handle_dht_p2p_put(void *cls, | 1664 | handle_dht_p2p_put (void *cls, |
1645 | const struct PeerPutMessage *put) | 1665 | const struct PeerPutMessage *put) |
1646 | { | 1666 | { |
1647 | struct PeerInfo *peer = cls; | 1667 | struct PeerInfo *peer = cls; |
1648 | const struct GNUNET_PeerIdentity *put_path; | 1668 | const struct GNUNET_PeerIdentity *put_path; |
@@ -1656,198 +1676,199 @@ handle_dht_p2p_put(void *cls, | |||
1656 | int forwarded; | 1676 | int forwarded; |
1657 | struct GNUNET_TIME_Absolute exp_time; | 1677 | struct GNUNET_TIME_Absolute exp_time; |
1658 | 1678 | ||
1659 | exp_time = GNUNET_TIME_absolute_ntoh(put->expiration_time); | 1679 | exp_time = GNUNET_TIME_absolute_ntoh (put->expiration_time); |
1660 | if (0 == GNUNET_TIME_absolute_get_remaining(exp_time).rel_value_us) | 1680 | if (0 == GNUNET_TIME_absolute_get_remaining (exp_time).rel_value_us) |
1661 | { | 1681 | { |
1662 | GNUNET_STATISTICS_update(GDS_stats, | 1682 | GNUNET_STATISTICS_update (GDS_stats, |
1663 | gettext_noop("# Expired PUTs discarded"), | 1683 | gettext_noop ("# Expired PUTs discarded"), |
1664 | 1, | 1684 | 1, |
1665 | GNUNET_NO); | 1685 | GNUNET_NO); |
1666 | return; | 1686 | return; |
1667 | } | 1687 | } |
1668 | msize = ntohs(put->header.size); | 1688 | msize = ntohs (put->header.size); |
1669 | putlen = ntohl(put->put_path_length); | 1689 | putlen = ntohl (put->put_path_length); |
1670 | GNUNET_STATISTICS_update(GDS_stats, | 1690 | GNUNET_STATISTICS_update (GDS_stats, |
1671 | gettext_noop("# P2P PUT requests received"), | 1691 | gettext_noop ("# P2P PUT requests received"), |
1672 | 1, | 1692 | 1, |
1673 | GNUNET_NO); | 1693 | GNUNET_NO); |
1674 | GNUNET_STATISTICS_update(GDS_stats, | 1694 | GNUNET_STATISTICS_update (GDS_stats, |
1675 | gettext_noop("# P2P PUT bytes received"), | 1695 | gettext_noop ("# P2P PUT bytes received"), |
1676 | msize, | 1696 | msize, |
1677 | GNUNET_NO); | 1697 | GNUNET_NO); |
1678 | put_path = (const struct GNUNET_PeerIdentity *)&put[1]; | 1698 | put_path = (const struct GNUNET_PeerIdentity *) &put[1]; |
1679 | payload = &put_path[putlen]; | 1699 | payload = &put_path[putlen]; |
1680 | options = ntohl(put->options); | 1700 | options = ntohl (put->options); |
1681 | payload_size = msize - (sizeof(struct PeerPutMessage) + | 1701 | payload_size = msize - (sizeof(struct PeerPutMessage) |
1682 | putlen * sizeof(struct GNUNET_PeerIdentity)); | 1702 | + putlen * sizeof(struct GNUNET_PeerIdentity)); |
1683 | 1703 | ||
1684 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1704 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1685 | "PUT for `%s' from %s\n", | 1705 | "PUT for `%s' from %s\n", |
1686 | GNUNET_h2s(&put->key), | 1706 | GNUNET_h2s (&put->key), |
1687 | GNUNET_i2s(peer->id)); | 1707 | GNUNET_i2s (peer->id)); |
1688 | if (GNUNET_YES == log_route_details_stderr) | 1708 | if (GNUNET_YES == log_route_details_stderr) |
1689 | { | 1709 | { |
1690 | char *tmp; | 1710 | char *tmp; |
1691 | char *pp; | 1711 | char *pp; |
1692 | 1712 | ||
1693 | pp = GNUNET_STRINGS_pp2s(put_path, | 1713 | pp = GNUNET_STRINGS_pp2s (put_path, |
1694 | putlen); | 1714 | putlen); |
1695 | tmp = GNUNET_strdup(GNUNET_i2s(&my_identity)); | 1715 | tmp = GNUNET_strdup (GNUNET_i2s (&my_identity)); |
1696 | LOG_TRAFFIC(GNUNET_ERROR_TYPE_DEBUG, | 1716 | LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, |
1697 | "R5N PUT %s: %s->%s (%u, %u=>%u, PP: %s)\n", | 1717 | "R5N PUT %s: %s->%s (%u, %u=>%u, PP: %s)\n", |
1698 | GNUNET_h2s(&put->key), | 1718 | GNUNET_h2s (&put->key), |
1699 | GNUNET_i2s(peer->id), | 1719 | GNUNET_i2s (peer->id), |
1700 | tmp, | 1720 | tmp, |
1701 | ntohl(put->hop_count), | 1721 | ntohl (put->hop_count), |
1702 | GNUNET_CRYPTO_hash_matching_bits(&peer->phash, | 1722 | GNUNET_CRYPTO_hash_matching_bits (&peer->phash, |
1703 | &put->key), | 1723 | &put->key), |
1704 | GNUNET_CRYPTO_hash_matching_bits(&my_identity_hash, | 1724 | GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash, |
1705 | &put->key), | 1725 | &put->key), |
1706 | pp); | 1726 | pp); |
1707 | GNUNET_free(pp); | 1727 | GNUNET_free (pp); |
1708 | GNUNET_free(tmp); | 1728 | GNUNET_free (tmp); |
1709 | } | 1729 | } |
1710 | switch (GNUNET_BLOCK_get_key | 1730 | switch (GNUNET_BLOCK_get_key |
1711 | (GDS_block_context, | 1731 | (GDS_block_context, |
1712 | ntohl(put->type), | 1732 | ntohl (put->type), |
1713 | payload, | 1733 | payload, |
1714 | payload_size, | 1734 | payload_size, |
1715 | &test_key)) | 1735 | &test_key)) |
1736 | { | ||
1737 | case GNUNET_YES: | ||
1738 | if (0 != memcmp (&test_key, | ||
1739 | &put->key, | ||
1740 | sizeof(struct GNUNET_HashCode))) | ||
1716 | { | 1741 | { |
1717 | case GNUNET_YES: | 1742 | char *put_s = GNUNET_strdup (GNUNET_h2s_full (&put->key)); |
1718 | if (0 != memcmp(&test_key, | 1743 | |
1719 | &put->key, | 1744 | GNUNET_break_op (0); |
1720 | sizeof(struct GNUNET_HashCode))) | 1745 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1721 | { | 1746 | "PUT with key `%s' for block with key %s\n", |
1722 | char *put_s = GNUNET_strdup(GNUNET_h2s_full(&put->key)); | 1747 | put_s, |
1723 | 1748 | GNUNET_h2s_full (&test_key)); | |
1724 | GNUNET_break_op(0); | 1749 | GNUNET_free (put_s); |
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 | } | ||
1732 | break; | ||
1733 | |||
1734 | case GNUNET_NO: | ||
1735 | GNUNET_break_op(0); | ||
1736 | return; | 1750 | return; |
1737 | |||
1738 | case GNUNET_SYSERR: | ||
1739 | /* cannot verify, good luck */ | ||
1740 | break; | ||
1741 | } | 1751 | } |
1742 | if (ntohl(put->type) == GNUNET_BLOCK_TYPE_REGEX) /* FIXME: do for all tpyes */ | 1752 | break; |
1753 | |||
1754 | case GNUNET_NO: | ||
1755 | GNUNET_break_op (0); | ||
1756 | return; | ||
1757 | |||
1758 | case GNUNET_SYSERR: | ||
1759 | /* cannot verify, good luck */ | ||
1760 | break; | ||
1761 | } | ||
1762 | if (ntohl (put->type) == GNUNET_BLOCK_TYPE_REGEX) /* FIXME: do for all tpyes */ | ||
1763 | { | ||
1764 | switch (GNUNET_BLOCK_evaluate (GDS_block_context, | ||
1765 | ntohl (put->type), | ||
1766 | NULL, /* query group */ | ||
1767 | GNUNET_BLOCK_EO_NONE, | ||
1768 | NULL, /* query */ | ||
1769 | NULL, 0, /* xquery */ | ||
1770 | payload, | ||
1771 | payload_size)) | ||
1743 | { | 1772 | { |
1744 | switch (GNUNET_BLOCK_evaluate(GDS_block_context, | 1773 | case GNUNET_BLOCK_EVALUATION_OK_MORE: |
1745 | ntohl(put->type), | 1774 | case GNUNET_BLOCK_EVALUATION_OK_LAST: |
1746 | NULL, /* query group */ | 1775 | break; |
1747 | GNUNET_BLOCK_EO_NONE, | 1776 | |
1748 | NULL, /* query */ | 1777 | case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: |
1749 | NULL, 0, /* xquery */ | 1778 | case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: |
1750 | payload, | 1779 | case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT: |
1751 | payload_size)) | 1780 | case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: |
1752 | { | 1781 | case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: |
1753 | case GNUNET_BLOCK_EVALUATION_OK_MORE: | 1782 | case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: |
1754 | case GNUNET_BLOCK_EVALUATION_OK_LAST: | 1783 | default: |
1755 | break; | 1784 | GNUNET_break_op (0); |
1756 | 1785 | return; | |
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 | } | ||
1767 | } | 1786 | } |
1787 | } | ||
1768 | 1788 | ||
1769 | bf = GNUNET_CONTAINER_bloomfilter_init(put->bloomfilter, | 1789 | bf = GNUNET_CONTAINER_bloomfilter_init (put->bloomfilter, |
1770 | DHT_BLOOM_SIZE, | 1790 | DHT_BLOOM_SIZE, |
1771 | GNUNET_CONSTANTS_BLOOMFILTER_K); | 1791 | GNUNET_CONSTANTS_BLOOMFILTER_K); |
1772 | GNUNET_break_op(GNUNET_YES == | 1792 | GNUNET_break_op (GNUNET_YES == |
1773 | GNUNET_CONTAINER_bloomfilter_test(bf, | 1793 | GNUNET_CONTAINER_bloomfilter_test (bf, |
1774 | &peer->phash)); | 1794 | &peer->phash)); |
1775 | { | 1795 | { |
1776 | struct GNUNET_PeerIdentity pp[putlen + 1]; | 1796 | struct GNUNET_PeerIdentity pp[putlen + 1]; |
1777 | 1797 | ||
1778 | /* extend 'put path' by sender */ | 1798 | /* extend 'put path' by sender */ |
1779 | if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) | 1799 | if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) |
1780 | { | 1800 | { |
1781 | #if SANITY_CHECKS | 1801 | #if SANITY_CHECKS |
1782 | for (unsigned int i = 0; i <= putlen; i++) | 1802 | for (unsigned int i = 0; i <= putlen; i++) |
1783 | { | 1803 | { |
1784 | for (unsigned int j = 0; j < i; j++) | 1804 | for (unsigned int j = 0; j < i; j++) |
1785 | { | 1805 | { |
1786 | GNUNET_break(0 != memcmp(&pp[i], | 1806 | GNUNET_break (0 != memcmp (&pp[i], |
1787 | &pp[j], | 1807 | &pp[j], |
1788 | sizeof(struct GNUNET_PeerIdentity))); | ||
1789 | } | ||
1790 | GNUNET_break(0 != memcmp(&pp[i], | ||
1791 | peer->id, | ||
1792 | sizeof(struct GNUNET_PeerIdentity))); | 1808 | sizeof(struct GNUNET_PeerIdentity))); |
1793 | } | 1809 | } |
1794 | #endif | 1810 | GNUNET_break (0 != memcmp (&pp[i], |
1795 | GNUNET_memcpy(pp, | 1811 | peer->id, |
1796 | put_path, | 1812 | sizeof(struct GNUNET_PeerIdentity))); |
1797 | putlen * sizeof(struct GNUNET_PeerIdentity)); | ||
1798 | pp[putlen] = *peer->id; | ||
1799 | putlen++; | ||
1800 | } | 1813 | } |
1814 | #endif | ||
1815 | GNUNET_memcpy (pp, | ||
1816 | put_path, | ||
1817 | putlen * sizeof(struct GNUNET_PeerIdentity)); | ||
1818 | pp[putlen] = *peer->id; | ||
1819 | putlen++; | ||
1820 | } | ||
1801 | else | 1821 | else |
1802 | putlen = 0; | 1822 | putlen = 0; |
1803 | 1823 | ||
1804 | /* give to local clients */ | 1824 | /* give to local clients */ |
1805 | GDS_CLIENTS_handle_reply(exp_time, | 1825 | GDS_CLIENTS_handle_reply (exp_time, |
1806 | &put->key, | 1826 | &put->key, |
1807 | 0, | 1827 | 0, |
1808 | NULL, | 1828 | NULL, |
1809 | putlen, | 1829 | putlen, |
1810 | pp, | 1830 | pp, |
1811 | ntohl(put->type), | 1831 | ntohl (put->type), |
1812 | payload_size, | 1832 | payload_size, |
1813 | payload); | 1833 | payload); |
1814 | /* store locally */ | 1834 | /* store locally */ |
1815 | if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || | 1835 | if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || |
1816 | (GDS_am_closest_peer(&put->key, bf))) | 1836 | (GDS_am_closest_peer (&put->key, bf))) |
1817 | GDS_DATACACHE_handle_put(exp_time, | 1837 | GDS_DATACACHE_handle_put (exp_time, |
1818 | &put->key, | 1838 | &put->key, |
1819 | putlen, | 1839 | putlen, |
1820 | pp, | 1840 | pp, |
1821 | ntohl(put->type), | 1841 | ntohl (put->type), |
1822 | payload_size, | 1842 | payload_size, |
1823 | payload); | 1843 | payload); |
1824 | /* route to other peers */ | 1844 | /* route to other peers */ |
1825 | forwarded = GDS_NEIGHBOURS_handle_put(ntohl(put->type), | 1845 | forwarded = GDS_NEIGHBOURS_handle_put (ntohl (put->type), |
1826 | options, | 1846 | options, |
1827 | ntohl(put->desired_replication_level), | 1847 | ntohl ( |
1828 | exp_time, | 1848 | put->desired_replication_level), |
1829 | ntohl(put->hop_count), | 1849 | exp_time, |
1830 | bf, | 1850 | ntohl (put->hop_count), |
1831 | &put->key, | 1851 | bf, |
1832 | putlen, | 1852 | &put->key, |
1833 | pp, | 1853 | putlen, |
1834 | payload, | 1854 | pp, |
1835 | payload_size); | 1855 | payload, |
1856 | payload_size); | ||
1836 | /* notify monitoring clients */ | 1857 | /* notify monitoring clients */ |
1837 | GDS_CLIENTS_process_put(options | 1858 | GDS_CLIENTS_process_put (options |
1838 | | ((GNUNET_OK == forwarded) | 1859 | | ((GNUNET_OK == forwarded) |
1839 | ? GNUNET_DHT_RO_LAST_HOP | 1860 | ? GNUNET_DHT_RO_LAST_HOP |
1840 | : 0), | 1861 | : 0), |
1841 | ntohl(put->type), | 1862 | ntohl (put->type), |
1842 | ntohl(put->hop_count), | 1863 | ntohl (put->hop_count), |
1843 | ntohl(put->desired_replication_level), | 1864 | ntohl (put->desired_replication_level), |
1844 | putlen, pp, | 1865 | putlen, pp, |
1845 | exp_time, | 1866 | exp_time, |
1846 | &put->key, | 1867 | &put->key, |
1847 | payload, | 1868 | payload, |
1848 | payload_size); | 1869 | payload_size); |
1849 | } | 1870 | } |
1850 | GNUNET_CONTAINER_bloomfilter_free(bf); | 1871 | GNUNET_CONTAINER_bloomfilter_free (bf); |
1851 | } | 1872 | } |
1852 | 1873 | ||
1853 | 1874 | ||
@@ -1860,9 +1881,9 @@ handle_dht_p2p_put(void *cls, | |||
1860 | * @param bg group for filtering peers | 1881 | * @param bg group for filtering peers |
1861 | */ | 1882 | */ |
1862 | static void | 1883 | static void |
1863 | handle_find_peer(const struct GNUNET_PeerIdentity *sender, | 1884 | handle_find_peer (const struct GNUNET_PeerIdentity *sender, |
1864 | const struct GNUNET_HashCode *key, | 1885 | const struct GNUNET_HashCode *key, |
1865 | struct GNUNET_BLOCK_Group *bg) | 1886 | struct GNUNET_BLOCK_Group *bg) |
1866 | { | 1887 | { |
1867 | int bucket_idx; | 1888 | int bucket_idx; |
1868 | struct PeerBucket *bucket; | 1889 | struct PeerBucket *bucket; |
@@ -1873,99 +1894,103 @@ handle_find_peer(const struct GNUNET_PeerIdentity *sender, | |||
1873 | 1894 | ||
1874 | /* first, check about our own HELLO */ | 1895 | /* first, check about our own HELLO */ |
1875 | if (NULL != GDS_my_hello) | 1896 | if (NULL != GDS_my_hello) |
1897 | { | ||
1898 | hello_size = GNUNET_HELLO_size ((const struct | ||
1899 | GNUNET_HELLO_Message *) GDS_my_hello); | ||
1900 | GNUNET_break (hello_size >= sizeof(struct GNUNET_MessageHeader)); | ||
1901 | if (GNUNET_BLOCK_EVALUATION_OK_MORE == | ||
1902 | GNUNET_BLOCK_evaluate (GDS_block_context, | ||
1903 | GNUNET_BLOCK_TYPE_DHT_HELLO, | ||
1904 | bg, | ||
1905 | GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO, | ||
1906 | &my_identity_hash, | ||
1907 | NULL, 0, | ||
1908 | GDS_my_hello, | ||
1909 | hello_size)) | ||
1876 | { | 1910 | { |
1877 | hello_size = GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)GDS_my_hello); | 1911 | GDS_NEIGHBOURS_handle_reply (sender, |
1878 | GNUNET_break(hello_size >= sizeof(struct GNUNET_MessageHeader)); | 1912 | GNUNET_BLOCK_TYPE_DHT_HELLO, |
1879 | if (GNUNET_BLOCK_EVALUATION_OK_MORE == | 1913 | GNUNET_TIME_relative_to_absolute ( |
1880 | GNUNET_BLOCK_evaluate(GDS_block_context, | 1914 | hello_expiration), |
1881 | GNUNET_BLOCK_TYPE_DHT_HELLO, | 1915 | key, |
1882 | bg, | 1916 | 0, |
1883 | GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO, | 1917 | NULL, |
1884 | &my_identity_hash, | 1918 | 0, |
1885 | NULL, 0, | 1919 | NULL, |
1886 | GDS_my_hello, | 1920 | GDS_my_hello, |
1887 | hello_size)) | 1921 | 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 | } | ||
1907 | } | 1922 | } |
1908 | else | 1923 | else |
1909 | { | 1924 | { |
1910 | GNUNET_STATISTICS_update(GDS_stats, | 1925 | GNUNET_STATISTICS_update (GDS_stats, |
1911 | gettext_noop("# FIND PEER requests ignored due to lack of HELLO"), | 1926 | gettext_noop ( |
1912 | 1, | 1927 | "# FIND PEER requests ignored due to Bloomfilter"), |
1913 | GNUNET_NO); | 1928 | 1, |
1929 | GNUNET_NO); | ||
1914 | } | 1930 | } |
1931 | } | ||
1932 | else | ||
1933 | { | ||
1934 | GNUNET_STATISTICS_update (GDS_stats, | ||
1935 | gettext_noop ( | ||
1936 | "# FIND PEER requests ignored due to lack of HELLO"), | ||
1937 | 1, | ||
1938 | GNUNET_NO); | ||
1939 | } | ||
1915 | 1940 | ||
1916 | /* then, also consider sending a random HELLO from the closest bucket */ | 1941 | /* then, also consider sending a random HELLO from the closest bucket */ |
1917 | if (0 == memcmp(&my_identity_hash, | 1942 | if (0 == memcmp (&my_identity_hash, |
1918 | key, | 1943 | key, |
1919 | sizeof(struct GNUNET_HashCode))) | 1944 | sizeof(struct GNUNET_HashCode))) |
1920 | bucket_idx = closest_bucket; | 1945 | bucket_idx = closest_bucket; |
1921 | else | 1946 | else |
1922 | bucket_idx = GNUNET_MIN((int)closest_bucket, | 1947 | bucket_idx = GNUNET_MIN ((int) closest_bucket, |
1923 | find_bucket(key)); | 1948 | find_bucket (key)); |
1924 | if (bucket_idx < 0) | 1949 | if (bucket_idx < 0) |
1925 | return; | 1950 | return; |
1926 | bucket = &k_buckets[bucket_idx]; | 1951 | bucket = &k_buckets[bucket_idx]; |
1927 | if (bucket->peers_size == 0) | 1952 | if (bucket->peers_size == 0) |
1928 | return; | 1953 | return; |
1929 | choice = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | 1954 | choice = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
1930 | bucket->peers_size); | 1955 | bucket->peers_size); |
1931 | peer = bucket->head; | 1956 | peer = bucket->head; |
1932 | while (choice > 0) | 1957 | while (choice > 0) |
1933 | { | 1958 | { |
1934 | GNUNET_assert(NULL != peer); | 1959 | GNUNET_assert (NULL != peer); |
1935 | peer = peer->next; | 1960 | peer = peer->next; |
1936 | choice--; | 1961 | choice--; |
1937 | } | 1962 | } |
1938 | choice = bucket->peers_size; | 1963 | choice = bucket->peers_size; |
1939 | do | 1964 | do |
1940 | { | 1965 | { |
1941 | peer = peer->next; | 1966 | peer = peer->next; |
1942 | if (0 == choice--) | 1967 | if (0 == choice--) |
1943 | return; /* no non-masked peer available */ | 1968 | return; /* no non-masked peer available */ |
1944 | if (NULL == peer) | 1969 | if (NULL == peer) |
1945 | peer = bucket->head; | 1970 | peer = bucket->head; |
1946 | hello = GDS_HELLO_get(peer->id); | 1971 | hello = GDS_HELLO_get (peer->id); |
1947 | } | 1972 | } |
1948 | while ((NULL == hello) || | 1973 | while ((NULL == hello) || |
1949 | (GNUNET_BLOCK_EVALUATION_OK_MORE != | 1974 | (GNUNET_BLOCK_EVALUATION_OK_MORE != |
1950 | GNUNET_BLOCK_evaluate(GDS_block_context, | 1975 | GNUNET_BLOCK_evaluate (GDS_block_context, |
1951 | GNUNET_BLOCK_TYPE_DHT_HELLO, | 1976 | GNUNET_BLOCK_TYPE_DHT_HELLO, |
1952 | bg, | 1977 | bg, |
1953 | GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO, | 1978 | GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO, |
1954 | &peer->phash, | 1979 | &peer->phash, |
1955 | NULL, 0, | 1980 | NULL, 0, |
1956 | hello, | 1981 | hello, |
1957 | (hello_size = GNUNET_HELLO_size(hello))))); | 1982 | (hello_size = GNUNET_HELLO_size (hello))))); |
1958 | GDS_NEIGHBOURS_handle_reply(sender, | 1983 | GDS_NEIGHBOURS_handle_reply (sender, |
1959 | GNUNET_BLOCK_TYPE_DHT_HELLO, | 1984 | GNUNET_BLOCK_TYPE_DHT_HELLO, |
1960 | GNUNET_TIME_relative_to_absolute | 1985 | GNUNET_TIME_relative_to_absolute |
1961 | (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION), | 1986 | (GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION), |
1962 | key, | 1987 | key, |
1963 | 0, | 1988 | 0, |
1964 | NULL, | 1989 | NULL, |
1965 | 0, | 1990 | 0, |
1966 | NULL, | 1991 | NULL, |
1967 | hello, | 1992 | hello, |
1968 | hello_size); | 1993 | hello_size); |
1969 | } | 1994 | } |
1970 | 1995 | ||
1971 | 1996 | ||
@@ -1984,34 +2009,34 @@ handle_find_peer(const struct GNUNET_PeerIdentity *sender, | |||
1984 | * @param data_size number of bytes in @a data | 2009 | * @param data_size number of bytes in @a data |
1985 | */ | 2010 | */ |
1986 | static void | 2011 | static void |
1987 | handle_local_result(void *cls, | 2012 | handle_local_result (void *cls, |
1988 | enum GNUNET_BLOCK_Type type, | 2013 | enum GNUNET_BLOCK_Type type, |
1989 | struct GNUNET_TIME_Absolute expiration_time, | 2014 | struct GNUNET_TIME_Absolute expiration_time, |
1990 | const struct GNUNET_HashCode *key, | 2015 | const struct GNUNET_HashCode *key, |
1991 | unsigned int put_path_length, | 2016 | unsigned int put_path_length, |
1992 | const struct GNUNET_PeerIdentity *put_path, | 2017 | const struct GNUNET_PeerIdentity *put_path, |
1993 | unsigned int get_path_length, | 2018 | unsigned int get_path_length, |
1994 | const struct GNUNET_PeerIdentity *get_path, | 2019 | const struct GNUNET_PeerIdentity *get_path, |
1995 | const void *data, | 2020 | const void *data, |
1996 | size_t data_size) | 2021 | size_t data_size) |
1997 | { | 2022 | { |
1998 | struct PeerInfo *peer = cls; | 2023 | struct PeerInfo *peer = cls; |
1999 | char *pp; | 2024 | char *pp; |
2000 | 2025 | ||
2001 | pp = GNUNET_STRINGS_pp2s(put_path, | 2026 | pp = GNUNET_STRINGS_pp2s (put_path, |
2002 | put_path_length); | 2027 | put_path_length); |
2003 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2028 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2004 | "Found local result for %s (PP: %s)\n", | 2029 | "Found local result for %s (PP: %s)\n", |
2005 | GNUNET_h2s(key), | 2030 | GNUNET_h2s (key), |
2006 | pp); | 2031 | pp); |
2007 | GNUNET_free(pp); | 2032 | GNUNET_free (pp); |
2008 | GDS_NEIGHBOURS_handle_reply(peer->id, | 2033 | GDS_NEIGHBOURS_handle_reply (peer->id, |
2009 | type, | 2034 | type, |
2010 | expiration_time, | 2035 | expiration_time, |
2011 | key, | 2036 | key, |
2012 | put_path_length, put_path, | 2037 | put_path_length, put_path, |
2013 | get_path_length, get_path, | 2038 | get_path_length, get_path, |
2014 | data, data_size); | 2039 | data, data_size); |
2015 | } | 2040 | } |
2016 | 2041 | ||
2017 | 2042 | ||
@@ -2023,20 +2048,20 @@ handle_local_result(void *cls, | |||
2023 | * @return #GNUNET_OK if the message is well-formed | 2048 | * @return #GNUNET_OK if the message is well-formed |
2024 | */ | 2049 | */ |
2025 | static int | 2050 | static int |
2026 | check_dht_p2p_get(void *cls, | 2051 | check_dht_p2p_get (void *cls, |
2027 | const struct PeerGetMessage *get) | 2052 | const struct PeerGetMessage *get) |
2028 | { | 2053 | { |
2029 | uint32_t xquery_size; | 2054 | uint32_t xquery_size; |
2030 | uint16_t msize; | 2055 | uint16_t msize; |
2031 | 2056 | ||
2032 | (void)cls; | 2057 | (void) cls; |
2033 | msize = ntohs(get->header.size); | 2058 | msize = ntohs (get->header.size); |
2034 | xquery_size = ntohl(get->xquery_size); | 2059 | xquery_size = ntohl (get->xquery_size); |
2035 | if (msize < sizeof(struct PeerGetMessage) + xquery_size) | 2060 | if (msize < sizeof(struct PeerGetMessage) + xquery_size) |
2036 | { | 2061 | { |
2037 | GNUNET_break_op(0); | 2062 | GNUNET_break_op (0); |
2038 | return GNUNET_SYSERR; | 2063 | return GNUNET_SYSERR; |
2039 | } | 2064 | } |
2040 | return GNUNET_OK; | 2065 | return GNUNET_OK; |
2041 | } | 2066 | } |
2042 | 2067 | ||
@@ -2048,8 +2073,8 @@ check_dht_p2p_get(void *cls, | |||
2048 | * @param get the message | 2073 | * @param get the message |
2049 | */ | 2074 | */ |
2050 | static void | 2075 | static void |
2051 | handle_dht_p2p_get(void *cls, | 2076 | handle_dht_p2p_get (void *cls, |
2052 | const struct PeerGetMessage *get) | 2077 | const struct PeerGetMessage *get) |
2053 | { | 2078 | { |
2054 | struct PeerInfo *peer = cls; | 2079 | struct PeerInfo *peer = cls; |
2055 | uint32_t xquery_size; | 2080 | uint32_t xquery_size; |
@@ -2064,141 +2089,143 @@ handle_dht_p2p_get(void *cls, | |||
2064 | int forwarded; | 2089 | int forwarded; |
2065 | 2090 | ||
2066 | /* parse and validate message */ | 2091 | /* parse and validate message */ |
2067 | msize = ntohs(get->header.size); | 2092 | msize = ntohs (get->header.size); |
2068 | xquery_size = ntohl(get->xquery_size); | 2093 | xquery_size = ntohl (get->xquery_size); |
2069 | reply_bf_size = msize - (sizeof(struct PeerGetMessage) + xquery_size); | 2094 | reply_bf_size = msize - (sizeof(struct PeerGetMessage) + xquery_size); |
2070 | type = ntohl(get->type); | 2095 | type = ntohl (get->type); |
2071 | options = ntohl(get->options); | 2096 | options = ntohl (get->options); |
2072 | xquery = (const char *)&get[1]; | 2097 | xquery = (const char *) &get[1]; |
2073 | GNUNET_STATISTICS_update(GDS_stats, | 2098 | GNUNET_STATISTICS_update (GDS_stats, |
2074 | gettext_noop("# P2P GET requests received"), | 2099 | gettext_noop ("# P2P GET requests received"), |
2075 | 1, | 2100 | 1, |
2076 | GNUNET_NO); | 2101 | GNUNET_NO); |
2077 | GNUNET_STATISTICS_update(GDS_stats, | 2102 | GNUNET_STATISTICS_update (GDS_stats, |
2078 | gettext_noop("# P2P GET bytes received"), | 2103 | gettext_noop ("# P2P GET bytes received"), |
2079 | msize, | 2104 | msize, |
2080 | GNUNET_NO); | 2105 | GNUNET_NO); |
2081 | if (GNUNET_YES == log_route_details_stderr) | 2106 | if (GNUNET_YES == log_route_details_stderr) |
2082 | { | 2107 | { |
2083 | char *tmp; | 2108 | char *tmp; |
2084 | 2109 | ||
2085 | tmp = GNUNET_strdup(GNUNET_i2s(&my_identity)); | 2110 | tmp = GNUNET_strdup (GNUNET_i2s (&my_identity)); |
2086 | LOG_TRAFFIC(GNUNET_ERROR_TYPE_DEBUG, | 2111 | LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, |
2087 | "R5N GET %s: %s->%s (%u, %u=>%u) xq: %.*s\n", | 2112 | "R5N GET %s: %s->%s (%u, %u=>%u) xq: %.*s\n", |
2088 | GNUNET_h2s(&get->key), | 2113 | GNUNET_h2s (&get->key), |
2089 | GNUNET_i2s(peer->id), | 2114 | GNUNET_i2s (peer->id), |
2090 | tmp, | 2115 | tmp, |
2091 | ntohl(get->hop_count), | 2116 | ntohl (get->hop_count), |
2092 | GNUNET_CRYPTO_hash_matching_bits(&peer->phash, | 2117 | GNUNET_CRYPTO_hash_matching_bits (&peer->phash, |
2093 | &get->key), | 2118 | &get->key), |
2094 | GNUNET_CRYPTO_hash_matching_bits(&my_identity_hash, | 2119 | GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash, |
2095 | &get->key), | 2120 | &get->key), |
2096 | ntohl(get->xquery_size), | 2121 | ntohl (get->xquery_size), |
2097 | xquery); | 2122 | xquery); |
2098 | GNUNET_free(tmp); | 2123 | GNUNET_free (tmp); |
2099 | } | 2124 | } |
2100 | eval | 2125 | eval |
2101 | = GNUNET_BLOCK_evaluate(GDS_block_context, | 2126 | = GNUNET_BLOCK_evaluate (GDS_block_context, |
2102 | type, | 2127 | type, |
2103 | NULL, | 2128 | NULL, |
2104 | GNUNET_BLOCK_EO_NONE, | 2129 | GNUNET_BLOCK_EO_NONE, |
2105 | &get->key, | 2130 | &get->key, |
2106 | xquery, | 2131 | xquery, |
2107 | xquery_size, | 2132 | xquery_size, |
2108 | NULL, | 2133 | NULL, |
2109 | 0); | 2134 | 0); |
2110 | if (eval != GNUNET_BLOCK_EVALUATION_REQUEST_VALID) | 2135 | if (eval != GNUNET_BLOCK_EVALUATION_REQUEST_VALID) |
2111 | { | 2136 | { |
2112 | /* request invalid or block type not supported */ | 2137 | /* request invalid or block type not supported */ |
2113 | GNUNET_break_op(eval == GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED); | 2138 | GNUNET_break_op (eval == GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED); |
2114 | return; | 2139 | return; |
2115 | } | 2140 | } |
2116 | peer_bf = GNUNET_CONTAINER_bloomfilter_init(get->bloomfilter, | 2141 | peer_bf = GNUNET_CONTAINER_bloomfilter_init (get->bloomfilter, |
2117 | DHT_BLOOM_SIZE, | 2142 | DHT_BLOOM_SIZE, |
2118 | GNUNET_CONSTANTS_BLOOMFILTER_K); | 2143 | GNUNET_CONSTANTS_BLOOMFILTER_K); |
2119 | GNUNET_break_op(GNUNET_YES == | 2144 | GNUNET_break_op (GNUNET_YES == |
2120 | GNUNET_CONTAINER_bloomfilter_test(peer_bf, | 2145 | GNUNET_CONTAINER_bloomfilter_test (peer_bf, |
2121 | &peer->phash)); | 2146 | &peer->phash)); |
2122 | bg = GNUNET_BLOCK_group_create(GDS_block_context, | 2147 | bg = GNUNET_BLOCK_group_create (GDS_block_context, |
2123 | type, | 2148 | type, |
2124 | get->bf_mutator, | 2149 | get->bf_mutator, |
2125 | &xquery[xquery_size], | 2150 | &xquery[xquery_size], |
2126 | reply_bf_size, | 2151 | reply_bf_size, |
2127 | "filter-size", | 2152 | "filter-size", |
2128 | reply_bf_size, | 2153 | reply_bf_size, |
2129 | NULL); | 2154 | NULL); |
2130 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2155 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2131 | "GET for %s at %s after %u hops\n", | 2156 | "GET for %s at %s after %u hops\n", |
2132 | GNUNET_h2s(&get->key), | 2157 | GNUNET_h2s (&get->key), |
2133 | GNUNET_i2s(&my_identity), | 2158 | GNUNET_i2s (&my_identity), |
2134 | (unsigned int)ntohl(get->hop_count)); | 2159 | (unsigned int) ntohl (get->hop_count)); |
2135 | /* local lookup (this may update the reply_bf) */ | 2160 | /* local lookup (this may update the reply_bf) */ |
2136 | if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || | 2161 | if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || |
2137 | (GDS_am_closest_peer(&get->key, | 2162 | (GDS_am_closest_peer (&get->key, |
2138 | peer_bf))) | 2163 | peer_bf))) |
2164 | { | ||
2165 | if ((0 != (options & GNUNET_DHT_RO_FIND_PEER))) | ||
2139 | { | 2166 | { |
2140 | if ((0 != (options & GNUNET_DHT_RO_FIND_PEER))) | 2167 | GNUNET_STATISTICS_update (GDS_stats, |
2141 | { | 2168 | gettext_noop ( |
2142 | GNUNET_STATISTICS_update(GDS_stats, | 2169 | "# P2P FIND PEER requests processed"), |
2143 | gettext_noop("# P2P FIND PEER requests processed"), | 2170 | 1, |
2144 | 1, | 2171 | GNUNET_NO); |
2145 | GNUNET_NO); | 2172 | handle_find_peer (peer->id, |
2146 | handle_find_peer(peer->id, | 2173 | &get->key, |
2147 | &get->key, | 2174 | bg); |
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 | } | ||
2160 | } | 2175 | } |
2161 | else | 2176 | else |
2162 | { | 2177 | { |
2163 | GNUNET_STATISTICS_update(GDS_stats, | 2178 | eval = GDS_DATACACHE_handle_get (&get->key, |
2164 | gettext_noop("# P2P GET requests ONLY routed"), | 2179 | type, |
2165 | 1, | 2180 | xquery, |
2166 | GNUNET_NO); | 2181 | xquery_size, |
2182 | bg, | ||
2183 | &handle_local_result, | ||
2184 | peer); | ||
2167 | } | 2185 | } |
2186 | } | ||
2187 | else | ||
2188 | { | ||
2189 | GNUNET_STATISTICS_update (GDS_stats, | ||
2190 | gettext_noop ("# P2P GET requests ONLY routed"), | ||
2191 | 1, | ||
2192 | GNUNET_NO); | ||
2193 | } | ||
2168 | 2194 | ||
2169 | /* remember request for routing replies */ | 2195 | /* remember request for routing replies */ |
2170 | GDS_ROUTING_add(peer->id, | 2196 | GDS_ROUTING_add (peer->id, |
2171 | type, | 2197 | type, |
2172 | bg, /* bg now owned by routing, but valid at least until end of this function! */ | 2198 | bg, /* bg now owned by routing, but valid at least until end of this function! */ |
2173 | options, | 2199 | options, |
2174 | &get->key, | 2200 | &get->key, |
2175 | xquery, | 2201 | xquery, |
2176 | xquery_size); | 2202 | xquery_size); |
2177 | 2203 | ||
2178 | /* P2P forwarding */ | 2204 | /* P2P forwarding */ |
2179 | forwarded = GNUNET_NO; | 2205 | forwarded = GNUNET_NO; |
2180 | if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST) | 2206 | if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST) |
2181 | forwarded = GDS_NEIGHBOURS_handle_get(type, | 2207 | forwarded = GDS_NEIGHBOURS_handle_get (type, |
2182 | options, | 2208 | options, |
2183 | ntohl(get->desired_replication_level), | 2209 | ntohl ( |
2184 | ntohl(get->hop_count), | 2210 | get->desired_replication_level), |
2185 | &get->key, | 2211 | ntohl (get->hop_count), |
2186 | xquery, | 2212 | &get->key, |
2187 | xquery_size, | 2213 | xquery, |
2188 | bg, | 2214 | xquery_size, |
2189 | peer_bf); | 2215 | bg, |
2190 | GDS_CLIENTS_process_get(options | 2216 | peer_bf); |
2191 | | (GNUNET_OK == forwarded) | 2217 | GDS_CLIENTS_process_get (options |
2192 | ? GNUNET_DHT_RO_LAST_HOP : 0, | 2218 | | (GNUNET_OK == forwarded) |
2193 | type, | 2219 | ? GNUNET_DHT_RO_LAST_HOP : 0, |
2194 | ntohl(get->hop_count), | 2220 | type, |
2195 | ntohl(get->desired_replication_level), | 2221 | ntohl (get->hop_count), |
2196 | 0, | 2222 | ntohl (get->desired_replication_level), |
2197 | NULL, | 2223 | 0, |
2198 | &get->key); | 2224 | NULL, |
2225 | &get->key); | ||
2199 | 2226 | ||
2200 | /* clean up; note that 'bg' is owned by routing now! */ | 2227 | /* clean up; note that 'bg' is owned by routing now! */ |
2201 | GNUNET_CONTAINER_bloomfilter_free(peer_bf); | 2228 | GNUNET_CONTAINER_bloomfilter_free (peer_bf); |
2202 | } | 2229 | } |
2203 | 2230 | ||
2204 | 2231 | ||
@@ -2210,29 +2237,29 @@ handle_dht_p2p_get(void *cls, | |||
2210 | * @return #GNUNET_YES if the message is well-formed | 2237 | * @return #GNUNET_YES if the message is well-formed |
2211 | */ | 2238 | */ |
2212 | static int | 2239 | static int |
2213 | check_dht_p2p_result(void *cls, | 2240 | check_dht_p2p_result (void *cls, |
2214 | const struct PeerResultMessage *prm) | 2241 | const struct PeerResultMessage *prm) |
2215 | { | 2242 | { |
2216 | uint32_t get_path_length; | 2243 | uint32_t get_path_length; |
2217 | uint32_t put_path_length; | 2244 | uint32_t put_path_length; |
2218 | uint16_t msize; | 2245 | uint16_t msize; |
2219 | 2246 | ||
2220 | (void)cls; | 2247 | (void) cls; |
2221 | msize = ntohs(prm->header.size); | 2248 | msize = ntohs (prm->header.size); |
2222 | put_path_length = ntohl(prm->put_path_length); | 2249 | put_path_length = ntohl (prm->put_path_length); |
2223 | get_path_length = ntohl(prm->get_path_length); | 2250 | get_path_length = ntohl (prm->get_path_length); |
2224 | if ((msize < | 2251 | if ((msize < |
2225 | sizeof(struct PeerResultMessage) + (get_path_length + | 2252 | sizeof(struct PeerResultMessage) + (get_path_length |
2226 | put_path_length) * | 2253 | + put_path_length) |
2227 | sizeof(struct GNUNET_PeerIdentity)) || | 2254 | * sizeof(struct GNUNET_PeerIdentity)) || |
2228 | (get_path_length > | 2255 | (get_path_length > |
2229 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) || | 2256 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) || |
2230 | (put_path_length > | 2257 | (put_path_length > |
2231 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity))) | 2258 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity))) |
2232 | { | 2259 | { |
2233 | GNUNET_break_op(0); | 2260 | GNUNET_break_op (0); |
2234 | return GNUNET_SYSERR; | 2261 | return GNUNET_SYSERR; |
2235 | } | 2262 | } |
2236 | return GNUNET_OK; | 2263 | return GNUNET_OK; |
2237 | } | 2264 | } |
2238 | 2265 | ||
@@ -2251,64 +2278,64 @@ check_dht_p2p_result(void *cls, | |||
2251 | * @param data payload of the reply | 2278 | * @param data payload of the reply |
2252 | */ | 2279 | */ |
2253 | static void | 2280 | static void |
2254 | process_reply_with_path(struct GNUNET_TIME_Absolute expiration_time, | 2281 | process_reply_with_path (struct GNUNET_TIME_Absolute expiration_time, |
2255 | const struct GNUNET_HashCode *key, | 2282 | const struct GNUNET_HashCode *key, |
2256 | unsigned int get_path_length, | 2283 | unsigned int get_path_length, |
2257 | const struct GNUNET_PeerIdentity *get_path, | 2284 | const struct GNUNET_PeerIdentity *get_path, |
2258 | unsigned int put_path_length, | 2285 | unsigned int put_path_length, |
2259 | const struct GNUNET_PeerIdentity *put_path, | 2286 | const struct GNUNET_PeerIdentity *put_path, |
2260 | enum GNUNET_BLOCK_Type type, | 2287 | enum GNUNET_BLOCK_Type type, |
2261 | size_t data_size, | 2288 | size_t data_size, |
2262 | const void *data) | 2289 | const void *data) |
2263 | { | 2290 | { |
2264 | /* forward to local clients */ | 2291 | /* forward to local clients */ |
2265 | GDS_CLIENTS_handle_reply(expiration_time, | 2292 | GDS_CLIENTS_handle_reply (expiration_time, |
2266 | key, | 2293 | key, |
2267 | get_path_length, | 2294 | get_path_length, |
2268 | get_path, | 2295 | get_path, |
2269 | put_path_length, | 2296 | put_path_length, |
2270 | put_path, | 2297 | put_path, |
2271 | type, | 2298 | type, |
2272 | data_size, | 2299 | data_size, |
2273 | data); | 2300 | data); |
2274 | GDS_CLIENTS_process_get_resp(type, | 2301 | GDS_CLIENTS_process_get_resp (type, |
2275 | get_path, | 2302 | get_path, |
2276 | get_path_length, | 2303 | get_path_length, |
2277 | put_path, | 2304 | put_path, |
2278 | put_path_length, | 2305 | put_path_length, |
2279 | expiration_time, | 2306 | expiration_time, |
2280 | key, | 2307 | key, |
2281 | data, | 2308 | data, |
2282 | data_size); | 2309 | data_size); |
2283 | if (GNUNET_YES == cache_results) | 2310 | if (GNUNET_YES == cache_results) |
2284 | { | 2311 | { |
2285 | struct GNUNET_PeerIdentity xput_path[get_path_length + 1 + put_path_length]; | 2312 | struct GNUNET_PeerIdentity xput_path[get_path_length + 1 + put_path_length]; |
2286 | 2313 | ||
2287 | GNUNET_memcpy(xput_path, | 2314 | GNUNET_memcpy (xput_path, |
2288 | put_path, | 2315 | put_path, |
2289 | put_path_length * sizeof(struct GNUNET_PeerIdentity)); | 2316 | put_path_length * sizeof(struct GNUNET_PeerIdentity)); |
2290 | GNUNET_memcpy(&xput_path[put_path_length], | 2317 | GNUNET_memcpy (&xput_path[put_path_length], |
2291 | get_path, | 2318 | get_path, |
2292 | get_path_length * sizeof(struct GNUNET_PeerIdentity)); | 2319 | get_path_length * sizeof(struct GNUNET_PeerIdentity)); |
2293 | 2320 | ||
2294 | GDS_DATACACHE_handle_put(expiration_time, | 2321 | GDS_DATACACHE_handle_put (expiration_time, |
2295 | key, | 2322 | key, |
2296 | get_path_length + put_path_length, | 2323 | get_path_length + put_path_length, |
2297 | xput_path, | 2324 | xput_path, |
2298 | type, | 2325 | type, |
2299 | data_size, | 2326 | data_size, |
2300 | data); | 2327 | data); |
2301 | } | 2328 | } |
2302 | /* forward to other peers */ | 2329 | /* forward to other peers */ |
2303 | GDS_ROUTING_process(type, | 2330 | GDS_ROUTING_process (type, |
2304 | expiration_time, | 2331 | expiration_time, |
2305 | key, | 2332 | key, |
2306 | put_path_length, | 2333 | put_path_length, |
2307 | put_path, | 2334 | put_path, |
2308 | get_path_length, | 2335 | get_path_length, |
2309 | get_path, | 2336 | get_path, |
2310 | data, | 2337 | data, |
2311 | data_size); | 2338 | data_size); |
2312 | } | 2339 | } |
2313 | 2340 | ||
2314 | 2341 | ||
@@ -2319,8 +2346,8 @@ process_reply_with_path(struct GNUNET_TIME_Absolute expiration_time, | |||
2319 | * @param message message | 2346 | * @param message message |
2320 | */ | 2347 | */ |
2321 | static void | 2348 | static void |
2322 | handle_dht_p2p_result(void *cls, | 2349 | handle_dht_p2p_result (void *cls, |
2323 | const struct PeerResultMessage *prm) | 2350 | const struct PeerResultMessage *prm) |
2324 | { | 2351 | { |
2325 | struct PeerInfo *peer = cls; | 2352 | struct PeerInfo *peer = cls; |
2326 | const struct GNUNET_PeerIdentity *put_path; | 2353 | const struct GNUNET_PeerIdentity *put_path; |
@@ -2334,125 +2361,126 @@ handle_dht_p2p_result(void *cls, | |||
2334 | struct GNUNET_TIME_Absolute exp_time; | 2361 | struct GNUNET_TIME_Absolute exp_time; |
2335 | 2362 | ||
2336 | /* parse and validate message */ | 2363 | /* parse and validate message */ |
2337 | exp_time = GNUNET_TIME_absolute_ntoh(prm->expiration_time); | 2364 | exp_time = GNUNET_TIME_absolute_ntoh (prm->expiration_time); |
2338 | if (0 == GNUNET_TIME_absolute_get_remaining(exp_time).rel_value_us) | 2365 | if (0 == GNUNET_TIME_absolute_get_remaining (exp_time).rel_value_us) |
2366 | { | ||
2367 | GNUNET_STATISTICS_update (GDS_stats, | ||
2368 | gettext_noop ("# Expired results discarded"), | ||
2369 | 1, | ||
2370 | GNUNET_NO); | ||
2371 | return; | ||
2372 | } | ||
2373 | msize = ntohs (prm->header.size); | ||
2374 | put_path_length = ntohl (prm->put_path_length); | ||
2375 | get_path_length = ntohl (prm->get_path_length); | ||
2376 | put_path = (const struct GNUNET_PeerIdentity *) &prm[1]; | ||
2377 | get_path = &put_path[put_path_length]; | ||
2378 | type = ntohl (prm->type); | ||
2379 | data = (const void *) &get_path[get_path_length]; | ||
2380 | data_size = msize - (sizeof(struct PeerResultMessage) | ||
2381 | + (get_path_length | ||
2382 | + put_path_length) * sizeof(struct | ||
2383 | GNUNET_PeerIdentity)); | ||
2384 | GNUNET_STATISTICS_update (GDS_stats, | ||
2385 | gettext_noop ("# P2P RESULTS received"), | ||
2386 | 1, | ||
2387 | GNUNET_NO); | ||
2388 | GNUNET_STATISTICS_update (GDS_stats, | ||
2389 | gettext_noop ("# P2P RESULT bytes received"), | ||
2390 | msize, | ||
2391 | GNUNET_NO); | ||
2392 | if (GNUNET_YES == log_route_details_stderr) | ||
2393 | { | ||
2394 | char *tmp; | ||
2395 | char *pp; | ||
2396 | char *gp; | ||
2397 | |||
2398 | gp = GNUNET_STRINGS_pp2s (get_path, | ||
2399 | get_path_length); | ||
2400 | pp = GNUNET_STRINGS_pp2s (put_path, | ||
2401 | put_path_length); | ||
2402 | tmp = GNUNET_strdup (GNUNET_i2s (&my_identity)); | ||
2403 | LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, | ||
2404 | "R5N RESULT %s: %s->%s (GP: %s, PP: %s)\n", | ||
2405 | GNUNET_h2s (&prm->key), | ||
2406 | GNUNET_i2s (peer->id), | ||
2407 | tmp, | ||
2408 | gp, | ||
2409 | pp); | ||
2410 | GNUNET_free (gp); | ||
2411 | GNUNET_free (pp); | ||
2412 | GNUNET_free (tmp); | ||
2413 | } | ||
2414 | /* if we got a HELLO, consider it for our own routing table */ | ||
2415 | if (GNUNET_BLOCK_TYPE_DHT_HELLO == type) | ||
2416 | { | ||
2417 | const struct GNUNET_MessageHeader *h; | ||
2418 | struct GNUNET_PeerIdentity pid; | ||
2419 | |||
2420 | /* Should be a HELLO, validate and consider using it! */ | ||
2421 | if (data_size < sizeof(struct GNUNET_HELLO_Message)) | ||
2339 | { | 2422 | { |
2340 | GNUNET_STATISTICS_update(GDS_stats, | 2423 | GNUNET_break_op (0); |
2341 | gettext_noop("# Expired results discarded"), | ||
2342 | 1, | ||
2343 | GNUNET_NO); | ||
2344 | return; | 2424 | return; |
2345 | } | 2425 | } |
2346 | msize = ntohs(prm->header.size); | 2426 | h = data; |
2347 | put_path_length = ntohl(prm->put_path_length); | 2427 | if (data_size != ntohs (h->size)) |
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) | ||
2365 | { | 2428 | { |
2366 | char *tmp; | 2429 | GNUNET_break_op (0); |
2367 | char *pp; | 2430 | return; |
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); | ||
2385 | } | 2431 | } |
2386 | /* if we got a HELLO, consider it for our own routing table */ | 2432 | if (GNUNET_OK != |
2387 | if (GNUNET_BLOCK_TYPE_DHT_HELLO == type) | 2433 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) h, |
2434 | &pid)) | ||
2388 | { | 2435 | { |
2389 | const struct GNUNET_MessageHeader *h; | 2436 | GNUNET_break_op (0); |
2390 | struct GNUNET_PeerIdentity pid; | 2437 | return; |
2391 | |||
2392 | /* Should be a HELLO, validate and consider using it! */ | ||
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, | ||
2413 | &pid, | ||
2414 | sizeof(struct GNUNET_PeerIdentity)))) | ||
2415 | try_connect(&pid, | ||
2416 | h); | ||
2417 | } | 2438 | } |
2439 | if ((GNUNET_YES != disable_try_connect) && | ||
2440 | (0 != memcmp (&my_identity, | ||
2441 | &pid, | ||
2442 | sizeof(struct GNUNET_PeerIdentity)))) | ||
2443 | try_connect (&pid, | ||
2444 | h); | ||
2445 | } | ||
2418 | 2446 | ||
2419 | /* First, check if 'peer' is already on the path, and if | 2447 | /* First, check if 'peer' is already on the path, and if |
2420 | so, truncate it instead of expanding. */ | 2448 | so, truncate it instead of expanding. */ |
2421 | for (unsigned int i = 0; i <= get_path_length; i++) | 2449 | for (unsigned int i = 0; i <= get_path_length; i++) |
2422 | if (0 == memcmp(&get_path[i], | 2450 | if (0 == memcmp (&get_path[i], |
2423 | peer->id, | 2451 | peer->id, |
2424 | sizeof(struct GNUNET_PeerIdentity))) | 2452 | sizeof(struct GNUNET_PeerIdentity))) |
2425 | { | 2453 | { |
2426 | process_reply_with_path(exp_time, | 2454 | process_reply_with_path (exp_time, |
2427 | &prm->key, | 2455 | &prm->key, |
2428 | i, | 2456 | i, |
2429 | get_path, | 2457 | get_path, |
2430 | put_path_length, | 2458 | put_path_length, |
2431 | put_path, | 2459 | put_path, |
2432 | type, | 2460 | type, |
2433 | data_size, | 2461 | data_size, |
2434 | data); | 2462 | data); |
2435 | return; | 2463 | return; |
2436 | } | 2464 | } |
2437 | 2465 | ||
2438 | /* Need to append 'peer' to 'get_path' (normal case) */ | 2466 | /* Need to append 'peer' to 'get_path' (normal case) */ |
2439 | { | 2467 | { |
2440 | struct GNUNET_PeerIdentity xget_path[get_path_length + 1]; | 2468 | struct GNUNET_PeerIdentity xget_path[get_path_length + 1]; |
2441 | 2469 | ||
2442 | GNUNET_memcpy(xget_path, | 2470 | GNUNET_memcpy (xget_path, |
2443 | get_path, | 2471 | get_path, |
2444 | get_path_length * sizeof(struct GNUNET_PeerIdentity)); | 2472 | get_path_length * sizeof(struct GNUNET_PeerIdentity)); |
2445 | xget_path[get_path_length] = *peer->id; | 2473 | xget_path[get_path_length] = *peer->id; |
2446 | 2474 | ||
2447 | process_reply_with_path(exp_time, | 2475 | process_reply_with_path (exp_time, |
2448 | &prm->key, | 2476 | &prm->key, |
2449 | get_path_length + 1, | 2477 | get_path_length + 1, |
2450 | xget_path, | 2478 | xget_path, |
2451 | put_path_length, | 2479 | put_path_length, |
2452 | put_path, | 2480 | put_path, |
2453 | type, | 2481 | type, |
2454 | data_size, | 2482 | data_size, |
2455 | data); | 2483 | data); |
2456 | } | 2484 | } |
2457 | } | 2485 | } |
2458 | 2486 | ||
@@ -2463,55 +2491,55 @@ handle_dht_p2p_result(void *cls, | |||
2463 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 2491 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
2464 | */ | 2492 | */ |
2465 | int | 2493 | int |
2466 | GDS_NEIGHBOURS_init() | 2494 | GDS_NEIGHBOURS_init () |
2467 | { | 2495 | { |
2468 | struct GNUNET_MQ_MessageHandler core_handlers[] = { | 2496 | struct GNUNET_MQ_MessageHandler core_handlers[] = { |
2469 | GNUNET_MQ_hd_var_size(dht_p2p_get, | 2497 | GNUNET_MQ_hd_var_size (dht_p2p_get, |
2470 | GNUNET_MESSAGE_TYPE_DHT_P2P_GET, | 2498 | GNUNET_MESSAGE_TYPE_DHT_P2P_GET, |
2471 | struct PeerGetMessage, | 2499 | struct PeerGetMessage, |
2472 | NULL), | 2500 | NULL), |
2473 | GNUNET_MQ_hd_var_size(dht_p2p_put, | 2501 | GNUNET_MQ_hd_var_size (dht_p2p_put, |
2474 | GNUNET_MESSAGE_TYPE_DHT_P2P_PUT, | 2502 | GNUNET_MESSAGE_TYPE_DHT_P2P_PUT, |
2475 | struct PeerPutMessage, | 2503 | struct PeerPutMessage, |
2476 | NULL), | 2504 | NULL), |
2477 | GNUNET_MQ_hd_var_size(dht_p2p_result, | 2505 | GNUNET_MQ_hd_var_size (dht_p2p_result, |
2478 | GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT, | 2506 | GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT, |
2479 | struct PeerResultMessage, | 2507 | struct PeerResultMessage, |
2480 | NULL), | 2508 | NULL), |
2481 | GNUNET_MQ_handler_end() | 2509 | GNUNET_MQ_handler_end () |
2482 | }; | 2510 | }; |
2483 | unsigned long long temp_config_num; | 2511 | unsigned long long temp_config_num; |
2484 | 2512 | ||
2485 | disable_try_connect | 2513 | disable_try_connect |
2486 | = GNUNET_CONFIGURATION_get_value_yesno(GDS_cfg, | 2514 | = GNUNET_CONFIGURATION_get_value_yesno (GDS_cfg, |
2487 | "DHT", | ||
2488 | "DISABLE_TRY_CONNECT"); | ||
2489 | if (GNUNET_OK == | ||
2490 | GNUNET_CONFIGURATION_get_value_number(GDS_cfg, | ||
2491 | "DHT", | 2515 | "DHT", |
2492 | "bucket_size", | 2516 | "DISABLE_TRY_CONNECT"); |
2493 | &temp_config_num)) | 2517 | if (GNUNET_OK == |
2494 | bucket_size = (unsigned int)temp_config_num; | 2518 | GNUNET_CONFIGURATION_get_value_number (GDS_cfg, |
2519 | "DHT", | ||
2520 | "bucket_size", | ||
2521 | &temp_config_num)) | ||
2522 | bucket_size = (unsigned int) temp_config_num; | ||
2495 | cache_results | 2523 | cache_results |
2496 | = GNUNET_CONFIGURATION_get_value_yesno(GDS_cfg, | 2524 | = GNUNET_CONFIGURATION_get_value_yesno (GDS_cfg, |
2497 | "DHT", | 2525 | "DHT", |
2498 | "CACHE_RESULTS"); | 2526 | "CACHE_RESULTS"); |
2499 | 2527 | ||
2500 | log_route_details_stderr = | 2528 | log_route_details_stderr = |
2501 | (NULL != getenv("GNUNET_DHT_ROUTE_DEBUG")) ? GNUNET_YES : GNUNET_NO; | 2529 | (NULL != getenv ("GNUNET_DHT_ROUTE_DEBUG")) ? GNUNET_YES : GNUNET_NO; |
2502 | ats_ch = GNUNET_ATS_connectivity_init(GDS_cfg); | 2530 | ats_ch = GNUNET_ATS_connectivity_init (GDS_cfg); |
2503 | core_api = GNUNET_CORE_connect(GDS_cfg, | 2531 | core_api = GNUNET_CORE_connect (GDS_cfg, |
2504 | NULL, | 2532 | NULL, |
2505 | &core_init, | 2533 | &core_init, |
2506 | &handle_core_connect, | 2534 | &handle_core_connect, |
2507 | &handle_core_disconnect, | 2535 | &handle_core_disconnect, |
2508 | core_handlers); | 2536 | core_handlers); |
2509 | if (NULL == core_api) | 2537 | if (NULL == core_api) |
2510 | return GNUNET_SYSERR; | 2538 | return GNUNET_SYSERR; |
2511 | all_connected_peers = GNUNET_CONTAINER_multipeermap_create(256, | 2539 | all_connected_peers = GNUNET_CONTAINER_multipeermap_create (256, |
2512 | GNUNET_YES); | 2540 | GNUNET_YES); |
2513 | all_desired_peers = GNUNET_CONTAINER_multipeermap_create(256, | 2541 | all_desired_peers = GNUNET_CONTAINER_multipeermap_create (256, |
2514 | GNUNET_NO); | 2542 | GNUNET_NO); |
2515 | return GNUNET_OK; | 2543 | return GNUNET_OK; |
2516 | } | 2544 | } |
2517 | 2545 | ||
@@ -2520,24 +2548,24 @@ GDS_NEIGHBOURS_init() | |||
2520 | * Shutdown neighbours subsystem. | 2548 | * Shutdown neighbours subsystem. |
2521 | */ | 2549 | */ |
2522 | void | 2550 | void |
2523 | GDS_NEIGHBOURS_done() | 2551 | GDS_NEIGHBOURS_done () |
2524 | { | 2552 | { |
2525 | if (NULL == core_api) | 2553 | if (NULL == core_api) |
2526 | return; | 2554 | return; |
2527 | GNUNET_CORE_disconnect(core_api); | 2555 | GNUNET_CORE_disconnect (core_api); |
2528 | core_api = NULL; | 2556 | core_api = NULL; |
2529 | GNUNET_assert(0 == | 2557 | GNUNET_assert (0 == |
2530 | GNUNET_CONTAINER_multipeermap_size(all_connected_peers)); | 2558 | GNUNET_CONTAINER_multipeermap_size (all_connected_peers)); |
2531 | GNUNET_CONTAINER_multipeermap_destroy(all_connected_peers); | 2559 | GNUNET_CONTAINER_multipeermap_destroy (all_connected_peers); |
2532 | all_connected_peers = NULL; | 2560 | all_connected_peers = NULL; |
2533 | GNUNET_CONTAINER_multipeermap_iterate(all_desired_peers, | 2561 | GNUNET_CONTAINER_multipeermap_iterate (all_desired_peers, |
2534 | &free_connect_info, | 2562 | &free_connect_info, |
2535 | NULL); | 2563 | NULL); |
2536 | GNUNET_CONTAINER_multipeermap_destroy(all_desired_peers); | 2564 | GNUNET_CONTAINER_multipeermap_destroy (all_desired_peers); |
2537 | all_desired_peers = NULL; | 2565 | all_desired_peers = NULL; |
2538 | GNUNET_ATS_connectivity_done(ats_ch); | 2566 | GNUNET_ATS_connectivity_done (ats_ch); |
2539 | ats_ch = NULL; | 2567 | ats_ch = NULL; |
2540 | GNUNET_assert(NULL == find_peer_task); | 2568 | GNUNET_assert (NULL == find_peer_task); |
2541 | } | 2569 | } |
2542 | 2570 | ||
2543 | 2571 | ||
@@ -2547,7 +2575,7 @@ GDS_NEIGHBOURS_done() | |||
2547 | * @return identity of the local node | 2575 | * @return identity of the local node |
2548 | */ | 2576 | */ |
2549 | struct GNUNET_PeerIdentity * | 2577 | struct GNUNET_PeerIdentity * |
2550 | GDS_NEIGHBOURS_get_id() | 2578 | GDS_NEIGHBOURS_get_id () |
2551 | { | 2579 | { |
2552 | return &my_identity; | 2580 | return &my_identity; |
2553 | } | 2581 | } |
diff --git a/src/dht/gnunet-service-dht_neighbours.h b/src/dht/gnunet-service-dht_neighbours.h index 8b7a22422..cdcf30b01 100644 --- a/src/dht/gnunet-service-dht_neighbours.h +++ b/src/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 | */ |
60 | int | 60 | int |
61 | GDS_NEIGHBOURS_handle_put(enum GNUNET_BLOCK_Type type, | 61 | GDS_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 | */ |
90 | int | 90 | int |
91 | GDS_NEIGHBOURS_handle_get(enum GNUNET_BLOCK_Type type, | 91 | GDS_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 | */ |
118 | void | 118 | void |
119 | GDS_NEIGHBOURS_handle_reply(const struct GNUNET_PeerIdentity *target, | 119 | GDS_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 | */ |
141 | int | 141 | int |
142 | GDS_am_closest_peer(const struct GNUNET_HashCode *key, | 142 | GDS_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 | */ |
152 | int | 152 | int |
153 | GDS_NEIGHBOURS_init(void); | 153 | GDS_NEIGHBOURS_init (void); |
154 | 154 | ||
155 | 155 | ||
156 | /** | 156 | /** |
157 | * Shutdown neighbours subsystem. | 157 | * Shutdown neighbours subsystem. |
158 | */ | 158 | */ |
159 | void | 159 | void |
160 | GDS_NEIGHBOURS_done(void); | 160 | GDS_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 | */ |
168 | struct GNUNET_PeerIdentity * | 168 | struct GNUNET_PeerIdentity * |
169 | GDS_NEIGHBOURS_get_id(void); | 169 | GDS_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 07ebb5299..89107be16 100644 --- a/src/dht/gnunet-service-dht_nse.c +++ b/src/dht/gnunet-service-dht_nse.c | |||
@@ -52,14 +52,14 @@ static struct GNUNET_NSE_Handle *nse; | |||
52 | * | 52 | * |
53 | */ | 53 | */ |
54 | static void | 54 | static void |
55 | update_network_size_estimate(void *cls, struct GNUNET_TIME_Absolute timestamp, | 55 | update_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 | */ |
71 | double | 71 | double |
72 | GDS_NSE_get() | 72 | GDS_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 | */ |
81 | void | 81 | void |
82 | GDS_NSE_init() | 82 | GDS_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 | */ |
106 | void | 106 | void |
107 | GDS_NSE_done() | 107 | GDS_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 d3cc9f383..e99389e74 100644 --- a/src/dht/gnunet-service-dht_nse.h +++ b/src/dht/gnunet-service-dht_nse.h | |||
@@ -33,20 +33,20 @@ | |||
33 | * @return log of NSE | 33 | * @return log of NSE |
34 | */ | 34 | */ |
35 | double | 35 | double |
36 | GDS_NSE_get(void); | 36 | GDS_NSE_get (void); |
37 | 37 | ||
38 | 38 | ||
39 | /** | 39 | /** |
40 | * Initialize NSE subsystem. | 40 | * Initialize NSE subsystem. |
41 | */ | 41 | */ |
42 | void | 42 | void |
43 | GDS_NSE_init(void); | 43 | GDS_NSE_init (void); |
44 | 44 | ||
45 | 45 | ||
46 | /** | 46 | /** |
47 | * Shutdown NSE subsystem. | 47 | * Shutdown NSE subsystem. |
48 | */ | 48 | */ |
49 | void | 49 | void |
50 | GDS_NSE_done(void); | 50 | GDS_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 99c6b5e4f..3454c1acb 100644 --- a/src/dht/gnunet-service-dht_routing.c +++ b/src/dht/gnunet-service-dht_routing.c | |||
@@ -39,7 +39,8 @@ | |||
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 | */ |
42 | struct RecentRequest { | 42 | struct RecentRequest |
43 | { | ||
43 | /** | 44 | /** |
44 | * The peer this request was received from. | 45 | * The peer this request was received from. |
45 | */ | 46 | */ |
@@ -97,7 +98,8 @@ static struct GNUNET_CONTAINER_MultiHashMap *recent_map; | |||
97 | /** | 98 | /** |
98 | * Closure for the 'process' function. | 99 | * Closure for the 'process' function. |
99 | */ | 100 | */ |
100 | struct ProcessContext { | 101 | struct ProcessContext |
102 | { | ||
101 | /** | 103 | /** |
102 | * Path of the original PUT | 104 | * Path of the original PUT |
103 | */ | 105 | */ |
@@ -150,9 +152,9 @@ struct ProcessContext { | |||
150 | * #GNUNET_SYSERR if the result is malformed or type unsupported | 152 | * #GNUNET_SYSERR if the result is malformed or type unsupported |
151 | */ | 153 | */ |
152 | static int | 154 | static int |
153 | process(void *cls, | 155 | process (void *cls, |
154 | const struct GNUNET_HashCode *key, | 156 | const struct GNUNET_HashCode *key, |
155 | void *value) | 157 | void *value) |
156 | { | 158 | { |
157 | struct ProcessContext *pc = cls; | 159 | struct ProcessContext *pc = cls; |
158 | struct RecentRequest *rr = value; | 160 | struct RecentRequest *rr = value; |
@@ -167,106 +169,110 @@ process(void *cls, | |||
167 | return GNUNET_OK; /* type missmatch */ | 169 | return GNUNET_OK; /* type missmatch */ |
168 | 170 | ||
169 | if (0 != (rr->options & GNUNET_DHT_RO_RECORD_ROUTE)) | 171 | if (0 != (rr->options & GNUNET_DHT_RO_RECORD_ROUTE)) |
170 | { | 172 | { |
171 | gpl = pc->get_path_length; | 173 | gpl = pc->get_path_length; |
172 | ppl = pc->put_path_length; | 174 | ppl = pc->put_path_length; |
173 | } | 175 | } |
174 | else | 176 | else |
175 | { | 177 | { |
176 | gpl = 0; | 178 | gpl = 0; |
177 | ppl = 0; | 179 | ppl = 0; |
178 | } | 180 | } |
179 | if ((0 != (rr->options & GNUNET_DHT_RO_FIND_PEER)) && | 181 | if ((0 != (rr->options & GNUNET_DHT_RO_FIND_PEER)) && |
180 | (pc->type == GNUNET_BLOCK_TYPE_DHT_HELLO)) | 182 | (pc->type == GNUNET_BLOCK_TYPE_DHT_HELLO)) |
181 | { | 183 | { |
182 | /* key may not match HELLO, which is OK since | 184 | /* key may not match HELLO, which is OK since |
183 | * the search is approximate. Still, the evaluation | 185 | * the search is approximate. Still, the evaluation |
184 | * would fail since the match is not exact. So | 186 | * would fail since the match is not exact. So |
185 | * we fake it by changing the key to the actual PID ... */ | 187 | * we fake it by changing the key to the actual PID ... */ |
186 | GNUNET_BLOCK_get_key(GDS_block_context, | 188 | GNUNET_BLOCK_get_key (GDS_block_context, |
187 | GNUNET_BLOCK_TYPE_DHT_HELLO, | 189 | GNUNET_BLOCK_TYPE_DHT_HELLO, |
188 | pc->data, | 190 | pc->data, |
189 | pc->data_size, | 191 | pc->data_size, |
190 | &hc); | 192 | &hc); |
191 | eval_key = &hc; | 193 | eval_key = &hc; |
192 | } | 194 | } |
193 | else | 195 | else |
194 | { | 196 | { |
195 | eval_key = key; | 197 | eval_key = key; |
196 | } | 198 | } |
197 | eval | 199 | eval |
198 | = GNUNET_BLOCK_evaluate(GDS_block_context, | 200 | = GNUNET_BLOCK_evaluate (GDS_block_context, |
199 | pc->type, | 201 | pc->type, |
200 | rr->bg, | 202 | rr->bg, |
201 | GNUNET_BLOCK_EO_NONE, | 203 | GNUNET_BLOCK_EO_NONE, |
202 | eval_key, | 204 | eval_key, |
203 | rr->xquery, | 205 | rr->xquery, |
204 | rr->xquery_size, | 206 | rr->xquery_size, |
205 | pc->data, | 207 | pc->data, |
206 | pc->data_size); | 208 | pc->data_size); |
207 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 209 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
208 | "Result for %s of type %d was evaluated as %d\n", | 210 | "Result for %s of type %d was evaluated as %d\n", |
209 | GNUNET_h2s(key), | 211 | GNUNET_h2s (key), |
210 | pc->type, | 212 | pc->type, |
211 | eval); | 213 | eval); |
212 | switch (eval) | 214 | switch (eval) |
213 | { | 215 | { |
214 | case GNUNET_BLOCK_EVALUATION_OK_MORE: | 216 | case GNUNET_BLOCK_EVALUATION_OK_MORE: |
215 | case GNUNET_BLOCK_EVALUATION_OK_LAST: | 217 | case GNUNET_BLOCK_EVALUATION_OK_LAST: |
216 | GNUNET_STATISTICS_update(GDS_stats, | 218 | GNUNET_STATISTICS_update (GDS_stats, |
217 | gettext_noop | 219 | gettext_noop |
218 | ("# Good REPLIES matched against routing table"), | 220 | ("# Good REPLIES matched against routing table"), |
219 | 1, GNUNET_NO); | 221 | 1, GNUNET_NO); |
220 | GDS_NEIGHBOURS_handle_reply(&rr->peer, | 222 | GDS_NEIGHBOURS_handle_reply (&rr->peer, |
221 | pc->type, | 223 | pc->type, |
222 | pc->expiration_time, | 224 | pc->expiration_time, |
223 | key, | 225 | key, |
224 | ppl, pc->put_path, | 226 | ppl, pc->put_path, |
225 | gpl, pc->get_path, | 227 | gpl, pc->get_path, |
226 | pc->data, | 228 | pc->data, |
227 | pc->data_size); | 229 | pc->data_size); |
228 | break; | 230 | break; |
229 | 231 | ||
230 | case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: | 232 | case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: |
231 | GNUNET_STATISTICS_update(GDS_stats, | 233 | GNUNET_STATISTICS_update (GDS_stats, |
232 | gettext_noop | 234 | gettext_noop |
233 | ("# Duplicate REPLIES matched against routing table"), | 235 | ( |
234 | 1, GNUNET_NO); | 236 | "# Duplicate REPLIES matched against routing table"), |
235 | return GNUNET_OK; | 237 | 1, GNUNET_NO); |
236 | 238 | return GNUNET_OK; | |
237 | case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: | 239 | |
238 | GNUNET_STATISTICS_update(GDS_stats, | 240 | case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: |
239 | gettext_noop | 241 | GNUNET_STATISTICS_update (GDS_stats, |
240 | ("# Invalid REPLIES matched against routing table"), | 242 | gettext_noop |
241 | 1, GNUNET_NO); | 243 | ( |
242 | return GNUNET_SYSERR; | 244 | "# Invalid REPLIES matched against routing table"), |
243 | 245 | 1, GNUNET_NO); | |
244 | case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT: | 246 | return GNUNET_SYSERR; |
245 | GNUNET_STATISTICS_update(GDS_stats, | 247 | |
246 | gettext_noop | 248 | case GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT: |
247 | ("# Irrelevant REPLIES matched against routing table"), | 249 | GNUNET_STATISTICS_update (GDS_stats, |
248 | 1, GNUNET_NO); | 250 | gettext_noop |
249 | return GNUNET_OK; | 251 | ( |
250 | 252 | "# Irrelevant REPLIES matched against routing table"), | |
251 | case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: | 253 | 1, GNUNET_NO); |
252 | GNUNET_break(0); | 254 | return GNUNET_OK; |
253 | return GNUNET_OK; | 255 | |
254 | 256 | case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: | |
255 | case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: | 257 | GNUNET_break (0); |
256 | GNUNET_break(0); | 258 | return GNUNET_OK; |
257 | return GNUNET_OK; | 259 | |
258 | 260 | case GNUNET_BLOCK_EVALUATION_REQUEST_INVALID: | |
259 | case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: | 261 | GNUNET_break (0); |
260 | GNUNET_STATISTICS_update(GDS_stats, | 262 | return GNUNET_OK; |
261 | gettext_noop | 263 | |
262 | ("# Unsupported REPLIES matched against routing table"), | 264 | case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: |
263 | 1, GNUNET_NO); | 265 | GNUNET_STATISTICS_update (GDS_stats, |
264 | return GNUNET_SYSERR; | 266 | gettext_noop |
265 | 267 | ( | |
266 | default: | 268 | "# Unsupported REPLIES matched against routing table"), |
267 | GNUNET_break(0); | 269 | 1, GNUNET_NO); |
268 | return GNUNET_SYSERR; | 270 | return GNUNET_SYSERR; |
269 | } | 271 | |
272 | default: | ||
273 | GNUNET_break (0); | ||
274 | return GNUNET_SYSERR; | ||
275 | } | ||
270 | return GNUNET_OK; | 276 | return GNUNET_OK; |
271 | } | 277 | } |
272 | 278 | ||
@@ -289,15 +295,15 @@ process(void *cls, | |||
289 | * @param data_size number of bytes in data | 295 | * @param data_size number of bytes in data |
290 | */ | 296 | */ |
291 | void | 297 | void |
292 | GDS_ROUTING_process(enum GNUNET_BLOCK_Type type, | 298 | GDS_ROUTING_process (enum GNUNET_BLOCK_Type type, |
293 | struct GNUNET_TIME_Absolute expiration_time, | 299 | struct GNUNET_TIME_Absolute expiration_time, |
294 | const struct GNUNET_HashCode *key, | 300 | const struct GNUNET_HashCode *key, |
295 | unsigned int put_path_length, | 301 | unsigned int put_path_length, |
296 | const struct GNUNET_PeerIdentity *put_path, | 302 | const struct GNUNET_PeerIdentity *put_path, |
297 | unsigned int get_path_length, | 303 | unsigned int get_path_length, |
298 | const struct GNUNET_PeerIdentity *get_path, | 304 | const struct GNUNET_PeerIdentity *get_path, |
299 | const void *data, | 305 | const void *data, |
300 | size_t data_size) | 306 | size_t data_size) |
301 | { | 307 | { |
302 | struct ProcessContext pc; | 308 | struct ProcessContext pc; |
303 | 309 | ||
@@ -310,19 +316,19 @@ GDS_ROUTING_process(enum GNUNET_BLOCK_Type type, | |||
310 | pc.data = data; | 316 | pc.data = data; |
311 | pc.data_size = data_size; | 317 | pc.data_size = data_size; |
312 | if (NULL == data) | 318 | if (NULL == data) |
313 | { | 319 | { |
314 | /* Some apps might have an 'empty' reply as a valid reply; however, | 320 | /* Some apps might have an 'empty' reply as a valid reply; however, |
315 | 'process' will call GNUNET_BLOCK_evaluate' which treats a 'NULL' | 321 | 'process' will call GNUNET_BLOCK_evaluate' which treats a 'NULL' |
316 | reply as request-validation (but we need response-validation). | 322 | reply as request-validation (but we need response-validation). |
317 | So we set 'data' to a 0-byte non-NULL value just to be sure */ | 323 | So we set 'data' to a 0-byte non-NULL value just to be sure */ |
318 | GNUNET_break(0 == data_size); | 324 | GNUNET_break (0 == data_size); |
319 | pc.data_size = 0; | 325 | pc.data_size = 0; |
320 | pc.data = ""; /* something not null */ | 326 | pc.data = ""; /* something not null */ |
321 | } | 327 | } |
322 | GNUNET_CONTAINER_multihashmap_get_multiple(recent_map, | 328 | GNUNET_CONTAINER_multihashmap_get_multiple (recent_map, |
323 | key, | 329 | key, |
324 | &process, | 330 | &process, |
325 | &pc); | 331 | &pc); |
326 | } | 332 | } |
327 | 333 | ||
328 | 334 | ||
@@ -332,23 +338,23 @@ GDS_ROUTING_process(enum GNUNET_BLOCK_Type type, | |||
332 | * in the heap and hashmap. | 338 | * in the heap and hashmap. |
333 | */ | 339 | */ |
334 | static void | 340 | static void |
335 | expire_oldest_entry() | 341 | expire_oldest_entry () |
336 | { | 342 | { |
337 | struct RecentRequest *recent_req; | 343 | struct RecentRequest *recent_req; |
338 | 344 | ||
339 | GNUNET_STATISTICS_update(GDS_stats, | 345 | GNUNET_STATISTICS_update (GDS_stats, |
340 | gettext_noop | 346 | gettext_noop |
341 | ("# Entries removed from routing table"), 1, | 347 | ("# Entries removed from routing table"), 1, |
342 | GNUNET_NO); | 348 | GNUNET_NO); |
343 | recent_req = GNUNET_CONTAINER_heap_peek(recent_heap); | 349 | recent_req = GNUNET_CONTAINER_heap_peek (recent_heap); |
344 | GNUNET_assert(recent_req != NULL); | 350 | GNUNET_assert (recent_req != NULL); |
345 | GNUNET_CONTAINER_heap_remove_node(recent_req->heap_node); | 351 | GNUNET_CONTAINER_heap_remove_node (recent_req->heap_node); |
346 | GNUNET_BLOCK_group_destroy(recent_req->bg); | 352 | GNUNET_BLOCK_group_destroy (recent_req->bg); |
347 | GNUNET_assert(GNUNET_YES == | 353 | GNUNET_assert (GNUNET_YES == |
348 | GNUNET_CONTAINER_multihashmap_remove(recent_map, | 354 | GNUNET_CONTAINER_multihashmap_remove (recent_map, |
349 | &recent_req->key, | 355 | &recent_req->key, |
350 | recent_req)); | 356 | recent_req)); |
351 | GNUNET_free(recent_req); | 357 | GNUNET_free (recent_req); |
352 | } | 358 | } |
353 | 359 | ||
354 | 360 | ||
@@ -363,26 +369,26 @@ expire_oldest_entry() | |||
363 | * #GNUNET_SYSERR if the request was successfully combined | 369 | * #GNUNET_SYSERR if the request was successfully combined |
364 | */ | 370 | */ |
365 | static int | 371 | static int |
366 | try_combine_recent(void *cls, | 372 | try_combine_recent (void *cls, |
367 | const struct GNUNET_HashCode *key, | 373 | const struct GNUNET_HashCode *key, |
368 | void *value) | 374 | void *value) |
369 | { | 375 | { |
370 | struct RecentRequest *in = cls; | 376 | struct RecentRequest *in = cls; |
371 | struct RecentRequest *rr = value; | 377 | struct RecentRequest *rr = value; |
372 | 378 | ||
373 | if ((0 != GNUNET_memcmp(&in->peer, | 379 | if ((0 != GNUNET_memcmp (&in->peer, |
374 | &rr->peer)) || | 380 | &rr->peer)) || |
375 | (in->type != rr->type) || | 381 | (in->type != rr->type) || |
376 | (in->xquery_size != rr->xquery_size) || | 382 | (in->xquery_size != rr->xquery_size) || |
377 | (0 != memcmp(in->xquery, | 383 | (0 != memcmp (in->xquery, |
378 | rr->xquery, | 384 | rr->xquery, |
379 | in->xquery_size))) | 385 | in->xquery_size))) |
380 | return GNUNET_OK; | 386 | return GNUNET_OK; |
381 | GNUNET_break(GNUNET_SYSERR != | 387 | GNUNET_break (GNUNET_SYSERR != |
382 | GNUNET_BLOCK_group_merge(in->bg, | 388 | GNUNET_BLOCK_group_merge (in->bg, |
383 | rr->bg)); | 389 | rr->bg)); |
384 | rr->bg = in->bg; | 390 | rr->bg = in->bg; |
385 | GNUNET_free(in); | 391 | GNUNET_free (in); |
386 | return GNUNET_SYSERR; | 392 | return GNUNET_SYSERR; |
387 | } | 393 | } |
388 | 394 | ||
@@ -400,53 +406,53 @@ try_combine_recent(void *cls, | |||
400 | * @param reply_bf_mutator mutator for @a reply_bf | 406 | * @param reply_bf_mutator mutator for @a reply_bf |
401 | */ | 407 | */ |
402 | void | 408 | void |
403 | GDS_ROUTING_add(const struct GNUNET_PeerIdentity *sender, | 409 | GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender, |
404 | enum GNUNET_BLOCK_Type type, | 410 | enum GNUNET_BLOCK_Type type, |
405 | struct GNUNET_BLOCK_Group *bg, | 411 | struct GNUNET_BLOCK_Group *bg, |
406 | enum GNUNET_DHT_RouteOption options, | 412 | enum GNUNET_DHT_RouteOption options, |
407 | const struct GNUNET_HashCode *key, | 413 | const struct GNUNET_HashCode *key, |
408 | const void *xquery, | 414 | const void *xquery, |
409 | size_t xquery_size) | 415 | size_t xquery_size) |
410 | { | 416 | { |
411 | struct RecentRequest *recent_req; | 417 | struct RecentRequest *recent_req; |
412 | 418 | ||
413 | while (GNUNET_CONTAINER_heap_get_size(recent_heap) >= DHT_MAX_RECENT) | 419 | while (GNUNET_CONTAINER_heap_get_size (recent_heap) >= DHT_MAX_RECENT) |
414 | expire_oldest_entry(); | 420 | expire_oldest_entry (); |
415 | GNUNET_STATISTICS_update(GDS_stats, | 421 | GNUNET_STATISTICS_update (GDS_stats, |
416 | gettext_noop("# Entries added to routing table"), | 422 | gettext_noop ("# Entries added to routing table"), |
417 | 1, | 423 | 1, |
418 | GNUNET_NO); | 424 | GNUNET_NO); |
419 | recent_req = GNUNET_malloc(sizeof(struct RecentRequest) + xquery_size); | 425 | recent_req = GNUNET_malloc (sizeof(struct RecentRequest) + xquery_size); |
420 | recent_req->peer = *sender; | 426 | recent_req->peer = *sender; |
421 | recent_req->key = *key; | 427 | recent_req->key = *key; |
422 | recent_req->bg = bg; | 428 | recent_req->bg = bg; |
423 | recent_req->type = type; | 429 | recent_req->type = type; |
424 | recent_req->options = options; | 430 | recent_req->options = options; |
425 | recent_req->xquery = &recent_req[1]; | 431 | recent_req->xquery = &recent_req[1]; |
426 | GNUNET_memcpy(&recent_req[1], | 432 | GNUNET_memcpy (&recent_req[1], |
427 | xquery, | 433 | xquery, |
428 | xquery_size); | 434 | xquery_size); |
429 | recent_req->xquery_size = xquery_size; | 435 | recent_req->xquery_size = xquery_size; |
430 | if (GNUNET_SYSERR == | 436 | if (GNUNET_SYSERR == |
431 | GNUNET_CONTAINER_multihashmap_get_multiple(recent_map, | 437 | GNUNET_CONTAINER_multihashmap_get_multiple (recent_map, |
432 | key, | 438 | key, |
433 | &try_combine_recent, | 439 | &try_combine_recent, |
434 | recent_req)) | 440 | recent_req)) |
435 | { | 441 | { |
436 | GNUNET_STATISTICS_update(GDS_stats, | 442 | GNUNET_STATISTICS_update (GDS_stats, |
437 | gettext_noop | 443 | gettext_noop |
438 | ("# DHT requests combined"), | 444 | ("# DHT requests combined"), |
439 | 1, GNUNET_NO); | 445 | 1, GNUNET_NO); |
440 | return; | 446 | return; |
441 | } | 447 | } |
442 | recent_req->heap_node | 448 | recent_req->heap_node |
443 | = GNUNET_CONTAINER_heap_insert(recent_heap, | 449 | = 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, | ||
448 | recent_req, | 450 | recent_req, |
449 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 451 | GNUNET_TIME_absolute_get ().abs_value_us); |
452 | GNUNET_CONTAINER_multihashmap_put (recent_map, | ||
453 | key, | ||
454 | recent_req, | ||
455 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
450 | } | 456 | } |
451 | 457 | ||
452 | 458 | ||
@@ -454,10 +460,11 @@ GDS_ROUTING_add(const struct GNUNET_PeerIdentity *sender, | |||
454 | * Initialize routing subsystem. | 460 | * Initialize routing subsystem. |
455 | */ | 461 | */ |
456 | void | 462 | void |
457 | GDS_ROUTING_init() | 463 | GDS_ROUTING_init () |
458 | { | 464 | { |
459 | recent_heap = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); | 465 | recent_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
460 | recent_map = GNUNET_CONTAINER_multihashmap_create(DHT_MAX_RECENT * 4 / 3, GNUNET_NO); | 466 | recent_map = GNUNET_CONTAINER_multihashmap_create (DHT_MAX_RECENT * 4 / 3, |
467 | GNUNET_NO); | ||
461 | } | 468 | } |
462 | 469 | ||
463 | 470 | ||
@@ -465,15 +472,15 @@ GDS_ROUTING_init() | |||
465 | * Shutdown routing subsystem. | 472 | * Shutdown routing subsystem. |
466 | */ | 473 | */ |
467 | void | 474 | void |
468 | GDS_ROUTING_done() | 475 | GDS_ROUTING_done () |
469 | { | 476 | { |
470 | while (GNUNET_CONTAINER_heap_get_size(recent_heap) > 0) | 477 | while (GNUNET_CONTAINER_heap_get_size (recent_heap) > 0) |
471 | expire_oldest_entry(); | 478 | expire_oldest_entry (); |
472 | GNUNET_assert(0 == GNUNET_CONTAINER_heap_get_size(recent_heap)); | 479 | GNUNET_assert (0 == GNUNET_CONTAINER_heap_get_size (recent_heap)); |
473 | GNUNET_CONTAINER_heap_destroy(recent_heap); | 480 | GNUNET_CONTAINER_heap_destroy (recent_heap); |
474 | recent_heap = NULL; | 481 | recent_heap = NULL; |
475 | GNUNET_assert(0 == GNUNET_CONTAINER_multihashmap_size(recent_map)); | 482 | GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (recent_map)); |
476 | GNUNET_CONTAINER_multihashmap_destroy(recent_map); | 483 | GNUNET_CONTAINER_multihashmap_destroy (recent_map); |
477 | recent_map = NULL; | 484 | recent_map = NULL; |
478 | } | 485 | } |
479 | 486 | ||
diff --git a/src/dht/gnunet-service-dht_routing.h b/src/dht/gnunet-service-dht_routing.h index ace6b9c0c..7fea01bae 100644 --- a/src/dht/gnunet-service-dht_routing.h +++ b/src/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 | */ |
51 | void | 51 | void |
52 | GDS_ROUTING_process(enum GNUNET_BLOCK_Type type, | 52 | GDS_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 | */ |
74 | void | 74 | void |
75 | GDS_ROUTING_add(const struct GNUNET_PeerIdentity *sender, | 75 | GDS_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 | */ |
87 | void | 87 | void |
88 | GDS_ROUTING_init(void); | 88 | GDS_ROUTING_init (void); |
89 | 89 | ||
90 | 90 | ||
91 | /** | 91 | /** |
92 | * Shutdown routing subsystem. | 92 | * Shutdown routing subsystem. |
93 | */ | 93 | */ |
94 | void | 94 | void |
95 | GDS_ROUTING_done(void); | 95 | GDS_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 179f84a11..5a73880be 100644 --- a/src/dht/gnunet_dht_profiler.c +++ b/src/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,7 +60,8 @@ struct ActiveContext; | |||
60 | /** | 60 | /** |
61 | * Context to hold data of peer | 61 | * Context to hold data of peer |
62 | */ | 62 | */ |
63 | struct Context { | 63 | struct Context |
64 | { | ||
64 | /** | 65 | /** |
65 | * The testbed peer this context belongs to | 66 | * The testbed peer this context belongs to |
66 | */ | 67 | */ |
@@ -81,7 +82,8 @@ struct Context { | |||
81 | /** | 82 | /** |
82 | * Context for a peer which actively does DHT PUT/GET | 83 | * Context for a peer which actively does DHT PUT/GET |
83 | */ | 84 | */ |
84 | struct ActiveContext { | 85 | struct ActiveContext |
86 | { | ||
85 | /** | 87 | /** |
86 | * The linked peer context | 88 | * The linked peer context |
87 | */ | 89 | */ |
@@ -258,7 +260,8 @@ static int peers_started = 0; | |||
258 | /** | 260 | /** |
259 | * Should we do a PUT (mode = 0) or GET (mode = 1); | 261 | * Should we do a PUT (mode = 0) or GET (mode = 1); |
260 | */ | 262 | */ |
261 | static enum { | 263 | static enum |
264 | { | ||
262 | MODE_PUT = 0, | 265 | MODE_PUT = 0, |
263 | 266 | ||
264 | MODE_GET = 1 | 267 | MODE_GET = 1 |
@@ -275,7 +278,7 @@ static int in_shutdown = 0; | |||
275 | * Connect to DHT services of active peers | 278 | * Connect to DHT services of active peers |
276 | */ | 279 | */ |
277 | static void | 280 | static void |
278 | start_profiling(void); | 281 | start_profiling (void); |
279 | 282 | ||
280 | 283 | ||
281 | /** | 284 | /** |
@@ -284,43 +287,43 @@ start_profiling(void); | |||
284 | * @param cls NULL | 287 | * @param cls NULL |
285 | */ | 288 | */ |
286 | static void | 289 | static void |
287 | do_shutdown(void *cls) | 290 | do_shutdown (void *cls) |
288 | { | 291 | { |
289 | struct ActiveContext *ac; | 292 | struct ActiveContext *ac; |
290 | 293 | ||
291 | in_shutdown = GNUNET_YES; | 294 | in_shutdown = GNUNET_YES; |
292 | if (NULL != a_ctx) | 295 | if (NULL != a_ctx) |
296 | { | ||
297 | for (unsigned int cnt = 0; cnt < num_peers; cnt++) | ||
293 | { | 298 | { |
294 | for (unsigned int cnt = 0; cnt < num_peers; cnt++) | 299 | /* Cleanup active context if this peer is an active peer */ |
295 | { | 300 | ac = a_ctx[cnt].ac; |
296 | /* Cleanup active context if this peer is an active peer */ | 301 | if (NULL != ac) |
297 | ac = a_ctx[cnt].ac; | 302 | { |
298 | if (NULL != ac) | 303 | if (NULL != ac->delay_task) |
299 | { | 304 | GNUNET_SCHEDULER_cancel (ac->delay_task); |
300 | if (NULL != ac->delay_task) | 305 | if (NULL != ac->hash) |
301 | GNUNET_SCHEDULER_cancel(ac->delay_task); | 306 | free (ac->hash); |
302 | if (NULL != ac->hash) | 307 | if (NULL != ac->dht_put) |
303 | free(ac->hash); | 308 | GNUNET_DHT_put_cancel (ac->dht_put); |
304 | if (NULL != ac->dht_put) | 309 | if (NULL != ac->dht_get) |
305 | GNUNET_DHT_put_cancel(ac->dht_put); | 310 | GNUNET_DHT_get_stop (ac->dht_get); |
306 | if (NULL != ac->dht_get) | 311 | } |
307 | GNUNET_DHT_get_stop(ac->dht_get); | 312 | /* Cleanup testbed operation handle at the last as this operation may |
308 | } | 313 | contain service connection to DHT */ |
309 | /* Cleanup testbed operation handle at the last as this operation may | 314 | if (NULL != a_ctx[cnt].op) |
310 | contain service connection to DHT */ | 315 | GNUNET_TESTBED_operation_done (a_ctx[cnt].op); |
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; | ||
316 | } | 316 | } |
317 | //FIXME: Should we collect stats only for put/get not for other messages. | 317 | GNUNET_free (a_ctx); |
318 | a_ctx = NULL; | ||
319 | } | ||
320 | // FIXME: Should we collect stats only for put/get not for other messages. | ||
318 | if (NULL != bandwidth_stats_op) | 321 | if (NULL != bandwidth_stats_op) |
319 | { | 322 | { |
320 | GNUNET_TESTBED_operation_done(bandwidth_stats_op); | 323 | GNUNET_TESTBED_operation_done (bandwidth_stats_op); |
321 | bandwidth_stats_op = NULL; | 324 | bandwidth_stats_op = NULL; |
322 | } | 325 | } |
323 | GNUNET_free_non_null(a_ac); | 326 | GNUNET_free_non_null (a_ac); |
324 | } | 327 | } |
325 | 328 | ||
326 | 329 | ||
@@ -334,18 +337,18 @@ do_shutdown(void *cls) | |||
334 | * operation has executed successfully. | 337 | * operation has executed successfully. |
335 | */ | 338 | */ |
336 | static void | 339 | static void |
337 | bandwidth_stats_cont(void *cls, | 340 | bandwidth_stats_cont (void *cls, |
338 | struct GNUNET_TESTBED_Operation *op, | 341 | struct GNUNET_TESTBED_Operation *op, |
339 | const char *emsg) | 342 | const char *emsg) |
340 | { | 343 | { |
341 | MESSAGE("# Outgoing (core) bandwidth: %llu bytes\n", | 344 | MESSAGE ("# Outgoing (core) bandwidth: %llu bytes\n", |
342 | (unsigned long long)outgoing_bandwidth); | 345 | (unsigned long long) outgoing_bandwidth); |
343 | MESSAGE("# Incoming (core) bandwidth: %llu bytes\n", | 346 | MESSAGE ("# Incoming (core) bandwidth: %llu bytes\n", |
344 | (unsigned long long)incoming_bandwidth); | 347 | (unsigned long long) incoming_bandwidth); |
345 | fprintf(stderr, | 348 | fprintf (stderr, |
346 | "Benchmark done. Collect data via gnunet-statistics, then press ENTER to exit.\n"); | 349 | "Benchmark done. Collect data via gnunet-statistics, then press ENTER to exit.\n"); |
347 | (void)getchar(); | 350 | (void) getchar (); |
348 | GNUNET_SCHEDULER_shutdown(); | 351 | GNUNET_SCHEDULER_shutdown (); |
349 | } | 352 | } |
350 | 353 | ||
351 | 354 | ||
@@ -361,55 +364,55 @@ bandwidth_stats_cont(void *cls, | |||
361 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration | 364 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration |
362 | */ | 365 | */ |
363 | static int | 366 | static int |
364 | bandwidth_stats_iterator(void *cls, | 367 | bandwidth_stats_iterator (void *cls, |
365 | const struct GNUNET_TESTBED_Peer *peer, | 368 | const struct GNUNET_TESTBED_Peer *peer, |
366 | const char *subsystem, | 369 | const char *subsystem, |
367 | const char *name, | 370 | const char *name, |
368 | uint64_t value, | 371 | uint64_t value, |
369 | int is_persistent) | 372 | int is_persistent) |
370 | { | 373 | { |
371 | static const char *s_sent = "# bytes encrypted"; | 374 | static const char *s_sent = "# bytes encrypted"; |
372 | static const char *s_recv = "# bytes decrypted"; | 375 | static const char *s_recv = "# bytes decrypted"; |
373 | 376 | ||
374 | if (0 == strncmp(s_sent, name, strlen(s_sent))) | 377 | if (0 == strncmp (s_sent, name, strlen (s_sent))) |
375 | outgoing_bandwidth = outgoing_bandwidth + value; | 378 | outgoing_bandwidth = outgoing_bandwidth + value; |
376 | else if (0 == strncmp(s_recv, name, strlen(s_recv))) | 379 | else if (0 == strncmp (s_recv, name, strlen (s_recv))) |
377 | incoming_bandwidth = incoming_bandwidth + value; | 380 | incoming_bandwidth = incoming_bandwidth + value; |
378 | return GNUNET_OK; | 381 | return GNUNET_OK; |
379 | } | 382 | } |
380 | 383 | ||
381 | 384 | ||
382 | static void | 385 | static void |
383 | summarize() | 386 | summarize () |
384 | { | 387 | { |
385 | MESSAGE("# PUTS started: %llu\n", | 388 | MESSAGE ("# PUTS started: %llu\n", |
386 | n_puts); | 389 | n_puts); |
387 | MESSAGE("# PUTS succeeded: %llu\n", | 390 | MESSAGE ("# PUTS succeeded: %llu\n", |
388 | n_puts_ok); | 391 | n_puts_ok); |
389 | MESSAGE("# GETS made: %u\n", | 392 | MESSAGE ("# GETS made: %u\n", |
390 | n_gets); | 393 | n_gets); |
391 | MESSAGE("# GETS succeeded: %u\n", | 394 | MESSAGE ("# GETS succeeded: %u\n", |
392 | n_gets_ok); | 395 | n_gets_ok); |
393 | MESSAGE("# GETS failed: %u\n", | 396 | MESSAGE ("# GETS failed: %u\n", |
394 | n_gets_fail); | 397 | n_gets_fail); |
395 | MESSAGE("# average_put_path_length: %f\n", | 398 | MESSAGE ("# average_put_path_length: %f\n", |
396 | average_put_path_length); | 399 | average_put_path_length); |
397 | MESSAGE("# average_get_path_length: %f\n", | 400 | MESSAGE ("# average_get_path_length: %f\n", |
398 | average_get_path_length); | 401 | average_get_path_length); |
399 | 402 | ||
400 | if (NULL == testbed_handles) | 403 | if (NULL == testbed_handles) |
401 | { | 404 | { |
402 | MESSAGE("No peers found\n"); | 405 | MESSAGE ("No peers found\n"); |
403 | return; | 406 | return; |
404 | } | 407 | } |
405 | /* Collect Stats*/ | 408 | /* Collect Stats*/ |
406 | bandwidth_stats_op = GNUNET_TESTBED_get_statistics(n_active, | 409 | bandwidth_stats_op = GNUNET_TESTBED_get_statistics (n_active, |
407 | testbed_handles, | 410 | testbed_handles, |
408 | "core", | 411 | "core", |
409 | NULL, | 412 | NULL, |
410 | &bandwidth_stats_iterator, | 413 | &bandwidth_stats_iterator, |
411 | &bandwidth_stats_cont, | 414 | &bandwidth_stats_cont, |
412 | NULL); | 415 | NULL); |
413 | } | 416 | } |
414 | 417 | ||
415 | 418 | ||
@@ -419,27 +422,29 @@ summarize() | |||
419 | * @param cls NULL | 422 | * @param cls NULL |
420 | */ | 423 | */ |
421 | static void | 424 | static void |
422 | cancel_get(void *cls) | 425 | cancel_get (void *cls) |
423 | { | 426 | { |
424 | struct ActiveContext *ac = cls; | 427 | struct ActiveContext *ac = cls; |
425 | struct Context *ctx = ac->ctx; | 428 | struct Context *ctx = ac->ctx; |
426 | 429 | ||
427 | ac->delay_task = NULL; | 430 | ac->delay_task = NULL; |
428 | GNUNET_assert(NULL != ac->dht_get); | 431 | GNUNET_assert (NULL != ac->dht_get); |
429 | GNUNET_DHT_get_stop(ac->dht_get); | 432 | GNUNET_DHT_get_stop (ac->dht_get); |
430 | ac->dht_get = NULL; | 433 | ac->dht_get = NULL; |
431 | n_gets_fail++; | 434 | n_gets_fail++; |
432 | GNUNET_assert(NULL != ctx->op); | 435 | GNUNET_assert (NULL != ctx->op); |
433 | GNUNET_TESTBED_operation_done(ctx->op); | 436 | GNUNET_TESTBED_operation_done (ctx->op); |
434 | ctx->op = NULL; | 437 | ctx->op = NULL; |
435 | 438 | ||
436 | /* If profiling is complete, summarize */ | 439 | /* If profiling is complete, summarize */ |
437 | if (n_active == n_gets_fail + n_gets_ok) | 440 | if (n_active == n_gets_fail + n_gets_ok) |
438 | { | 441 | { |
439 | average_put_path_length = (double)total_put_path_length / (double)n_active; | 442 | average_put_path_length = (double) total_put_path_length |
440 | average_get_path_length = (double)total_get_path_length / (double )n_gets_ok; | 443 | / (double) n_active; |
441 | summarize(); | 444 | average_get_path_length = (double) total_get_path_length |
442 | } | 445 | / (double ) n_gets_ok; |
446 | summarize (); | ||
447 | } | ||
443 | } | 448 | } |
444 | 449 | ||
445 | 450 | ||
@@ -461,45 +466,47 @@ cancel_get(void *cls) | |||
461 | * @param data pointer to the result data | 466 | * @param data pointer to the result data |
462 | */ | 467 | */ |
463 | static void | 468 | static void |
464 | get_iter(void *cls, | 469 | get_iter (void *cls, |
465 | struct GNUNET_TIME_Absolute exp, | 470 | struct GNUNET_TIME_Absolute exp, |
466 | const struct GNUNET_HashCode *key, | 471 | const struct GNUNET_HashCode *key, |
467 | const struct GNUNET_PeerIdentity *get_path, | 472 | const struct GNUNET_PeerIdentity *get_path, |
468 | unsigned int get_path_length, | 473 | unsigned int get_path_length, |
469 | const struct GNUNET_PeerIdentity *put_path, | 474 | const struct GNUNET_PeerIdentity *put_path, |
470 | unsigned int put_path_length, | 475 | unsigned int put_path_length, |
471 | enum GNUNET_BLOCK_Type type, | 476 | enum GNUNET_BLOCK_Type type, |
472 | size_t size, const void *data) | 477 | size_t size, const void *data) |
473 | { | 478 | { |
474 | struct ActiveContext *ac = cls; | 479 | struct ActiveContext *ac = cls; |
475 | struct ActiveContext *get_ac = ac->get_ac; | 480 | struct ActiveContext *get_ac = ac->get_ac; |
476 | struct Context *ctx = ac->ctx; | 481 | struct Context *ctx = ac->ctx; |
477 | 482 | ||
478 | /* we found the data we are looking for */ | 483 | /* we found the data we are looking for */ |
479 | DEBUG("We found a GET request; %u remaining\n", | 484 | DEBUG ("We found a GET request; %u remaining\n", |
480 | n_gets - (n_gets_fail + n_gets_ok)); //FIXME: It always prints 1. | 485 | n_gets - (n_gets_fail + n_gets_ok)); // FIXME: It always prints 1. |
481 | n_gets_ok++; | 486 | n_gets_ok++; |
482 | get_ac->nrefs--; | 487 | get_ac->nrefs--; |
483 | GNUNET_DHT_get_stop(ac->dht_get); | 488 | GNUNET_DHT_get_stop (ac->dht_get); |
484 | ac->dht_get = NULL; | 489 | ac->dht_get = NULL; |
485 | if (ac->delay_task != NULL) | 490 | if (ac->delay_task != NULL) |
486 | GNUNET_SCHEDULER_cancel(ac->delay_task); | 491 | GNUNET_SCHEDULER_cancel (ac->delay_task); |
487 | ac->delay_task = NULL; | 492 | ac->delay_task = NULL; |
488 | GNUNET_assert(NULL != ctx->op); | 493 | GNUNET_assert (NULL != ctx->op); |
489 | GNUNET_TESTBED_operation_done(ctx->op); | 494 | GNUNET_TESTBED_operation_done (ctx->op); |
490 | ctx->op = NULL; | 495 | ctx->op = NULL; |
491 | 496 | ||
492 | total_put_path_length = total_put_path_length + (double)put_path_length; | 497 | total_put_path_length = total_put_path_length + (double) put_path_length; |
493 | total_get_path_length = total_get_path_length + (double)get_path_length; | 498 | total_get_path_length = total_get_path_length + (double) get_path_length; |
494 | DEBUG("total_put_path_length = %u,put_path \n", | 499 | DEBUG ("total_put_path_length = %u,put_path \n", |
495 | total_put_path_length); | 500 | total_put_path_length); |
496 | /* Summarize if profiling is complete */ | 501 | /* Summarize if profiling is complete */ |
497 | if (n_active == n_gets_fail + n_gets_ok) | 502 | if (n_active == n_gets_fail + n_gets_ok) |
498 | { | 503 | { |
499 | average_put_path_length = (double)total_put_path_length / (double)n_active; | 504 | average_put_path_length = (double) total_put_path_length |
500 | average_get_path_length = (double)total_get_path_length / (double )n_gets_ok; | 505 | / (double) n_active; |
501 | summarize(); | 506 | average_get_path_length = (double) total_get_path_length |
502 | } | 507 | / (double ) n_gets_ok; |
508 | summarize (); | ||
509 | } | ||
503 | } | 510 | } |
504 | 511 | ||
505 | 512 | ||
@@ -509,7 +516,7 @@ get_iter(void *cls, | |||
509 | * @param cls the active context | 516 | * @param cls the active context |
510 | */ | 517 | */ |
511 | static void | 518 | static void |
512 | delayed_get(void *cls) | 519 | delayed_get (void *cls) |
513 | { | 520 | { |
514 | struct ActiveContext *ac = cls; | 521 | struct ActiveContext *ac = cls; |
515 | struct ActiveContext *get_ac; | 522 | struct ActiveContext *get_ac; |
@@ -518,34 +525,34 @@ delayed_get(void *cls) | |||
518 | ac->delay_task = NULL; | 525 | ac->delay_task = NULL; |
519 | get_ac = NULL; | 526 | get_ac = NULL; |
520 | while (1) | 527 | while (1) |
521 | { | 528 | { |
522 | r = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | 529 | r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
523 | n_active); | 530 | n_active); |
524 | get_ac = &a_ac[r]; | 531 | get_ac = &a_ac[r]; |
525 | if (NULL != get_ac->hash) | 532 | if (NULL != get_ac->hash) |
526 | break; | 533 | break; |
527 | } | 534 | } |
528 | get_ac->nrefs++; | 535 | get_ac->nrefs++; |
529 | ac->get_ac = get_ac; | 536 | ac->get_ac = get_ac; |
530 | r = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | 537 | r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
531 | num_puts_per_peer); | 538 | num_puts_per_peer); |
532 | DEBUG("GET_REQUEST_START key %s \n", | 539 | DEBUG ("GET_REQUEST_START key %s \n", |
533 | GNUNET_h2s(&get_ac->hash[r])); | 540 | GNUNET_h2s (&get_ac->hash[r])); |
534 | ac->dht_get = GNUNET_DHT_get_start(ac->dht, | 541 | ac->dht_get = GNUNET_DHT_get_start (ac->dht, |
535 | GNUNET_BLOCK_TYPE_TEST, | 542 | GNUNET_BLOCK_TYPE_TEST, |
536 | &get_ac->hash[r], | 543 | &get_ac->hash[r], |
537 | 1, /* replication level */ | 544 | 1, /* replication level */ |
538 | GNUNET_DHT_RO_NONE, | 545 | GNUNET_DHT_RO_NONE, |
539 | NULL, | 546 | NULL, |
540 | 0, /* extended query and size */ | 547 | 0, /* extended query and size */ |
541 | &get_iter, | 548 | &get_iter, |
542 | ac); /* GET iterator and closure */ | 549 | ac); /* GET iterator and closure */ |
543 | n_gets++; | 550 | n_gets++; |
544 | 551 | ||
545 | /* schedule the timeout task for GET */ | 552 | /* schedule the timeout task for GET */ |
546 | ac->delay_task = GNUNET_SCHEDULER_add_delayed(timeout, | 553 | ac->delay_task = GNUNET_SCHEDULER_add_delayed (timeout, |
547 | &cancel_get, | 554 | &cancel_get, |
548 | ac); | 555 | ac); |
549 | } | 556 | } |
550 | 557 | ||
551 | 558 | ||
@@ -557,7 +564,7 @@ delayed_get(void *cls) | |||
557 | * @param cls the active context | 564 | * @param cls the active context |
558 | */ | 565 | */ |
559 | static void | 566 | static void |
560 | delayed_put(void *cls); | 567 | delayed_put (void *cls); |
561 | 568 | ||
562 | 569 | ||
563 | /** | 570 | /** |
@@ -567,14 +574,14 @@ delayed_put(void *cls); | |||
567 | * @param cls the active context | 574 | * @param cls the active context |
568 | */ | 575 | */ |
569 | static void | 576 | static void |
570 | put_cont(void *cls) | 577 | put_cont (void *cls) |
571 | { | 578 | { |
572 | struct ActiveContext *ac = cls; | 579 | struct ActiveContext *ac = cls; |
573 | 580 | ||
574 | ac->dht_put = NULL; | 581 | ac->dht_put = NULL; |
575 | n_puts_ok++; | 582 | n_puts_ok++; |
576 | ac->delay_task = GNUNET_SCHEDULER_add_now(&delayed_put, | 583 | ac->delay_task = GNUNET_SCHEDULER_add_now (&delayed_put, |
577 | ac); | 584 | ac); |
578 | } | 585 | } |
579 | 586 | ||
580 | 587 | ||
@@ -586,7 +593,7 @@ put_cont(void *cls) | |||
586 | * @param cls the active context | 593 | * @param cls the active context |
587 | */ | 594 | */ |
588 | static void | 595 | static void |
589 | delayed_put(void *cls) | 596 | delayed_put (void *cls) |
590 | { | 597 | { |
591 | struct ActiveContext *ac = cls; | 598 | struct ActiveContext *ac = cls; |
592 | char block[65536]; | 599 | char block[65536]; |
@@ -594,42 +601,43 @@ delayed_put(void *cls) | |||
594 | 601 | ||
595 | ac->delay_task = NULL; | 602 | ac->delay_task = NULL; |
596 | if (0 == ac->put_count) | 603 | if (0 == ac->put_count) |
597 | { | 604 | { |
598 | struct Context *ctx = ac->ctx; | 605 | struct Context *ctx = ac->ctx; |
599 | struct GNUNET_TESTBED_Operation *op; | 606 | struct GNUNET_TESTBED_Operation *op; |
600 | 607 | ||
601 | GNUNET_assert(NULL != ctx); | 608 | GNUNET_assert (NULL != ctx); |
602 | op = ctx->op; | 609 | op = ctx->op; |
603 | ctx->op = NULL; | 610 | ctx->op = NULL; |
604 | GNUNET_TESTBED_operation_done(op); | 611 | GNUNET_TESTBED_operation_done (op); |
605 | return; | 612 | return; |
606 | } | 613 | } |
607 | 614 | ||
608 | 615 | ||
609 | /* Generate and DHT PUT some random data */ | 616 | /* Generate and DHT PUT some random data */ |
610 | block_size = 16; /* minimum */ | 617 | block_size = 16; /* minimum */ |
611 | /* make random payload, reserve 512 - 16 bytes for DHT headers */ | 618 | /* make random payload, reserve 512 - 16 bytes for DHT headers */ |
612 | block_size += GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | 619 | block_size += GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
613 | GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE - 512); | 620 | GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE |
614 | GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, | 621 | - 512); |
615 | block, | 622 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, |
616 | block_size); | 623 | block, |
624 | block_size); | ||
617 | ac->put_count--; | 625 | ac->put_count--; |
618 | GNUNET_CRYPTO_hash(block, | 626 | GNUNET_CRYPTO_hash (block, |
619 | block_size, | 627 | block_size, |
620 | &ac->hash[ac->put_count]); | 628 | &ac->hash[ac->put_count]); |
621 | DEBUG("PUT_REQUEST_START key %s\n", | 629 | DEBUG ("PUT_REQUEST_START key %s\n", |
622 | GNUNET_h2s(&ac->hash[ac->put_count])); | 630 | GNUNET_h2s (&ac->hash[ac->put_count])); |
623 | ac->dht_put = GNUNET_DHT_put(ac->dht, | 631 | ac->dht_put = GNUNET_DHT_put (ac->dht, |
624 | &ac->hash[ac->put_count], | 632 | &ac->hash[ac->put_count], |
625 | replication, | 633 | replication, |
626 | GNUNET_DHT_RO_RECORD_ROUTE, | 634 | GNUNET_DHT_RO_RECORD_ROUTE, |
627 | GNUNET_BLOCK_TYPE_TEST, | 635 | GNUNET_BLOCK_TYPE_TEST, |
628 | block_size, | 636 | block_size, |
629 | block, | 637 | block, |
630 | GNUNET_TIME_UNIT_FOREVER_ABS, /* expiration time */ | 638 | GNUNET_TIME_UNIT_FOREVER_ABS, /* expiration time */ |
631 | &put_cont, | 639 | &put_cont, |
632 | ac); /* continuation and its closure */ | 640 | ac); /* continuation and its closure */ |
633 | n_puts++; | 641 | n_puts++; |
634 | } | 642 | } |
635 | 643 | ||
@@ -644,66 +652,66 @@ delayed_put(void *cls) | |||
644 | * operation has executed successfully. | 652 | * operation has executed successfully. |
645 | */ | 653 | */ |
646 | static void | 654 | static void |
647 | dht_connected(void *cls, | 655 | dht_connected (void *cls, |
648 | struct GNUNET_TESTBED_Operation *op, | 656 | struct GNUNET_TESTBED_Operation *op, |
649 | void *ca_result, | 657 | void *ca_result, |
650 | const char *emsg) | 658 | const char *emsg) |
651 | { | 659 | { |
652 | struct ActiveContext *ac = cls; | 660 | struct ActiveContext *ac = cls; |
653 | struct Context *ctx = ac->ctx; | 661 | struct Context *ctx = ac->ctx; |
654 | 662 | ||
655 | GNUNET_assert(NULL != ctx); //FIXME: Fails | 663 | GNUNET_assert (NULL != ctx); // FIXME: Fails |
656 | GNUNET_assert(NULL != ctx->op); | 664 | GNUNET_assert (NULL != ctx->op); |
657 | GNUNET_assert(ctx->op == op); | 665 | GNUNET_assert (ctx->op == op); |
658 | ac->dht = (struct GNUNET_DHT_Handle *)ca_result; | 666 | ac->dht = (struct GNUNET_DHT_Handle *) ca_result; |
659 | if (NULL != emsg) | 667 | if (NULL != emsg) |
660 | { | 668 | { |
661 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 669 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
662 | "Connection to DHT service failed: %s\n", | 670 | "Connection to DHT service failed: %s\n", |
663 | emsg); | 671 | emsg); |
664 | GNUNET_TESTBED_operation_done(ctx->op); /* Calls dht_disconnect() */ | 672 | GNUNET_TESTBED_operation_done (ctx->op); /* Calls dht_disconnect() */ |
665 | ctx->op = NULL; | 673 | ctx->op = NULL; |
666 | return; | 674 | return; |
667 | } | 675 | } |
668 | switch (mode) | 676 | switch (mode) |
669 | { | 677 | { |
670 | case MODE_PUT: | 678 | case MODE_PUT: |
671 | { | 679 | { |
672 | struct GNUNET_TIME_Relative peer_delay_put; | 680 | struct GNUNET_TIME_Relative peer_delay_put; |
673 | 681 | ||
674 | peer_delay_put.rel_value_us = | 682 | peer_delay_put.rel_value_us = |
675 | GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, | 683 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
676 | delay_put.rel_value_us); | 684 | delay_put.rel_value_us); |
677 | ac->put_count = num_puts_per_peer; | 685 | ac->put_count = num_puts_per_peer; |
678 | ac->hash = calloc(ac->put_count, | 686 | ac->hash = calloc (ac->put_count, |
679 | sizeof(struct GNUNET_HashCode)); | 687 | sizeof(struct GNUNET_HashCode)); |
680 | if (NULL == ac->hash) | 688 | if (NULL == ac->hash) |
681 | { | 689 | { |
682 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, | 690 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, |
683 | "calloc"); | 691 | "calloc"); |
684 | GNUNET_SCHEDULER_shutdown(); | 692 | GNUNET_SCHEDULER_shutdown (); |
685 | return; | 693 | return; |
686 | } | 694 | } |
687 | ac->delay_task = GNUNET_SCHEDULER_add_delayed(peer_delay_put, | 695 | ac->delay_task = GNUNET_SCHEDULER_add_delayed (peer_delay_put, |
688 | &delayed_put, | 696 | &delayed_put, |
689 | ac); | 697 | ac); |
690 | break; | 698 | break; |
691 | } | 699 | } |
692 | 700 | ||
693 | case MODE_GET: | 701 | case MODE_GET: |
694 | { | 702 | { |
695 | struct GNUNET_TIME_Relative peer_delay_get; | 703 | struct GNUNET_TIME_Relative peer_delay_get; |
696 | 704 | ||
697 | peer_delay_get.rel_value_us = | 705 | peer_delay_get.rel_value_us = |
698 | delay_get.rel_value_us + | 706 | delay_get.rel_value_us |
699 | GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, | 707 | + GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
700 | delay_get.rel_value_us); | 708 | delay_get.rel_value_us); |
701 | ac->delay_task = GNUNET_SCHEDULER_add_delayed(peer_delay_get, | 709 | ac->delay_task = GNUNET_SCHEDULER_add_delayed (peer_delay_get, |
702 | &delayed_get, | 710 | &delayed_get, |
703 | ac); | 711 | ac); |
704 | break; | 712 | break; |
705 | } | 713 | } |
706 | } | 714 | } |
707 | } | 715 | } |
708 | 716 | ||
709 | 717 | ||
@@ -717,12 +725,12 @@ dht_connected(void *cls, | |||
717 | * @return service handle to return in 'op_result', NULL on error | 725 | * @return service handle to return in 'op_result', NULL on error |
718 | */ | 726 | */ |
719 | static void * | 727 | static void * |
720 | dht_connect(void *cls, | 728 | dht_connect (void *cls, |
721 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 729 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
722 | { | 730 | { |
723 | n_dht++; | 731 | n_dht++; |
724 | return GNUNET_DHT_connect(cfg, | 732 | return GNUNET_DHT_connect (cfg, |
725 | 10); | 733 | 10); |
726 | } | 734 | } |
727 | 735 | ||
728 | 736 | ||
@@ -734,14 +742,14 @@ dht_connect(void *cls, | |||
734 | * @param op_result service handle returned from the connect adapter | 742 | * @param op_result service handle returned from the connect adapter |
735 | */ | 743 | */ |
736 | static void | 744 | static void |
737 | dht_disconnect(void *cls, | 745 | dht_disconnect (void *cls, |
738 | void *op_result) | 746 | void *op_result) |
739 | { | 747 | { |
740 | struct ActiveContext *ac = cls; | 748 | struct ActiveContext *ac = cls; |
741 | 749 | ||
742 | GNUNET_assert(NULL != ac->dht); | 750 | GNUNET_assert (NULL != ac->dht); |
743 | GNUNET_assert(ac->dht == op_result); | 751 | GNUNET_assert (ac->dht == op_result); |
744 | GNUNET_DHT_disconnect(ac->dht); | 752 | GNUNET_DHT_disconnect (ac->dht); |
745 | ac->dht = NULL; | 753 | ac->dht = NULL; |
746 | n_dht--; | 754 | n_dht--; |
747 | if (0 != n_dht) | 755 | if (0 != n_dht) |
@@ -749,20 +757,20 @@ dht_disconnect(void *cls, | |||
749 | if (GNUNET_YES == in_shutdown) | 757 | if (GNUNET_YES == in_shutdown) |
750 | return; | 758 | return; |
751 | switch (mode) | 759 | switch (mode) |
752 | { | 760 | { |
753 | case MODE_PUT: | 761 | case MODE_PUT: |
754 | if (n_puts_ok != ((unsigned long long)n_active) * num_puts_per_peer) | 762 | if (n_puts_ok != ((unsigned long long) n_active) * num_puts_per_peer) |
755 | return; | ||
756 | /* Start GETs if all PUTs have been made */ | ||
757 | mode = MODE_GET; | ||
758 | start_profiling(); | ||
759 | return; | 763 | return; |
764 | /* Start GETs if all PUTs have been made */ | ||
765 | mode = MODE_GET; | ||
766 | start_profiling (); | ||
767 | return; | ||
760 | 768 | ||
761 | case MODE_GET: | 769 | case MODE_GET: |
762 | if ((n_gets_ok + n_gets_fail) != n_active) | 770 | if ((n_gets_ok + n_gets_fail) != n_active) |
763 | return; | 771 | return; |
764 | break; | 772 | break; |
765 | } | 773 | } |
766 | } | 774 | } |
767 | 775 | ||
768 | 776 | ||
@@ -770,25 +778,25 @@ dht_disconnect(void *cls, | |||
770 | * Connect to DHT services of active peers | 778 | * Connect to DHT services of active peers |
771 | */ | 779 | */ |
772 | static void | 780 | static void |
773 | start_profiling() | 781 | start_profiling () |
774 | { | 782 | { |
775 | struct Context *ctx; | 783 | struct Context *ctx; |
776 | 784 | ||
777 | DEBUG("GNUNET_TESTBED_service_connect\n"); | 785 | DEBUG ("GNUNET_TESTBED_service_connect\n"); |
778 | GNUNET_break(GNUNET_YES != in_shutdown); | 786 | GNUNET_break (GNUNET_YES != in_shutdown); |
779 | for (unsigned int i = 0; i < n_active; i++) | 787 | for (unsigned int i = 0; i < n_active; i++) |
780 | { | 788 | { |
781 | struct ActiveContext *ac = &a_ac[i]; | 789 | struct ActiveContext *ac = &a_ac[i]; |
782 | GNUNET_assert(NULL != (ctx = ac->ctx)); | 790 | GNUNET_assert (NULL != (ctx = ac->ctx)); |
783 | GNUNET_assert(NULL == ctx->op); | 791 | GNUNET_assert (NULL == ctx->op); |
784 | ctx->op = GNUNET_TESTBED_service_connect(ctx, | 792 | ctx->op = GNUNET_TESTBED_service_connect (ctx, |
785 | ctx->peer, | 793 | ctx->peer, |
786 | "dht", | 794 | "dht", |
787 | &dht_connected, ac, | 795 | &dht_connected, ac, |
788 | &dht_connect, | 796 | &dht_connect, |
789 | &dht_disconnect, | 797 | &dht_disconnect, |
790 | ac); | 798 | ac); |
791 | } | 799 | } |
792 | } | 800 | } |
793 | 801 | ||
794 | 802 | ||
@@ -801,22 +809,22 @@ start_profiling() | |||
801 | * operation has executed successfully. | 809 | * operation has executed successfully. |
802 | */ | 810 | */ |
803 | static void | 811 | static void |
804 | service_started(void *cls, | 812 | service_started (void *cls, |
805 | struct GNUNET_TESTBED_Operation *op, | 813 | struct GNUNET_TESTBED_Operation *op, |
806 | const char *emsg) | 814 | const char *emsg) |
807 | { | 815 | { |
808 | struct Context *ctx = cls; | 816 | struct Context *ctx = cls; |
809 | 817 | ||
810 | GNUNET_assert(NULL != ctx); | 818 | GNUNET_assert (NULL != ctx); |
811 | GNUNET_assert(NULL != ctx->op); | 819 | GNUNET_assert (NULL != ctx->op); |
812 | GNUNET_TESTBED_operation_done(ctx->op); | 820 | GNUNET_TESTBED_operation_done (ctx->op); |
813 | ctx->op = NULL; | 821 | ctx->op = NULL; |
814 | peers_started++; | 822 | peers_started++; |
815 | DEBUG("Peers Started = %d; num_peers = %d \n", | 823 | DEBUG ("Peers Started = %d; num_peers = %d \n", |
816 | peers_started, | 824 | peers_started, |
817 | num_peers); | 825 | num_peers); |
818 | if (peers_started == num_peers) | 826 | if (peers_started == num_peers) |
819 | start_profiling(); | 827 | start_profiling (); |
820 | } | 828 | } |
821 | 829 | ||
822 | 830 | ||
@@ -832,63 +840,63 @@ service_started(void *cls, | |||
832 | * @param links_failed the number of overlay link | 840 | * @param links_failed the number of overlay link |
833 | */ | 841 | */ |
834 | static void | 842 | static void |
835 | test_run(void *cls, | 843 | test_run (void *cls, |
836 | struct GNUNET_TESTBED_RunHandle *h, | 844 | struct GNUNET_TESTBED_RunHandle *h, |
837 | unsigned int num_peers, | 845 | unsigned int num_peers, |
838 | struct GNUNET_TESTBED_Peer **peers, | 846 | struct GNUNET_TESTBED_Peer **peers, |
839 | unsigned int links_succeeded, | 847 | unsigned int links_succeeded, |
840 | unsigned int links_failed) | 848 | unsigned int links_failed) |
841 | { | 849 | { |
842 | unsigned int ac_cnt; | 850 | unsigned int ac_cnt; |
843 | 851 | ||
844 | testbed_handles = peers; | 852 | testbed_handles = peers; |
845 | if (NULL == peers) | 853 | if (NULL == peers) |
846 | { | 854 | { |
847 | /* exit */ | 855 | /* exit */ |
848 | GNUNET_assert(0); | 856 | GNUNET_assert (0); |
849 | } | 857 | } |
850 | MESSAGE("%u peers started, %u/%u links up\n", | 858 | MESSAGE ("%u peers started, %u/%u links up\n", |
851 | num_peers, | 859 | num_peers, |
852 | links_succeeded, | 860 | links_succeeded, |
853 | links_succeeded + links_failed); | 861 | links_succeeded + links_failed); |
854 | a_ctx = GNUNET_new_array(num_peers, | 862 | a_ctx = GNUNET_new_array (num_peers, |
855 | struct Context); | 863 | struct Context); |
856 | /* select the peers which actively participate in profiling */ | 864 | /* select the peers which actively participate in profiling */ |
857 | n_active = num_peers * put_probability / 100; | 865 | n_active = num_peers * put_probability / 100; |
858 | if (0 == n_active) | 866 | if (0 == n_active) |
859 | { | 867 | { |
860 | GNUNET_SCHEDULER_shutdown(); | 868 | GNUNET_SCHEDULER_shutdown (); |
861 | GNUNET_free(a_ctx); | 869 | GNUNET_free (a_ctx); |
862 | a_ctx = NULL; | 870 | a_ctx = NULL; |
863 | return; | 871 | return; |
864 | } | 872 | } |
865 | 873 | ||
866 | a_ac = GNUNET_new_array(n_active, | 874 | a_ac = GNUNET_new_array (n_active, |
867 | struct ActiveContext); | 875 | struct ActiveContext); |
868 | ac_cnt = 0; | 876 | ac_cnt = 0; |
869 | for (unsigned int cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++) | 877 | for (unsigned int cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++) |
870 | { | 878 | { |
871 | if (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | 879 | if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
872 | 100) >= put_probability) | 880 | 100) >= put_probability) |
873 | continue; | 881 | continue; |
874 | 882 | ||
875 | a_ctx[cnt].ac = &a_ac[ac_cnt]; | 883 | a_ctx[cnt].ac = &a_ac[ac_cnt]; |
876 | a_ac[ac_cnt].ctx = &a_ctx[cnt]; | 884 | a_ac[ac_cnt].ctx = &a_ctx[cnt]; |
877 | ac_cnt++; | 885 | ac_cnt++; |
878 | } | 886 | } |
879 | n_active = ac_cnt; | 887 | n_active = ac_cnt; |
880 | 888 | ||
881 | /* start DHT service on all peers */ | 889 | /* start DHT service on all peers */ |
882 | for (unsigned int cnt = 0; cnt < num_peers; cnt++) | 890 | for (unsigned int cnt = 0; cnt < num_peers; cnt++) |
883 | { | 891 | { |
884 | a_ctx[cnt].peer = peers[cnt]; | 892 | a_ctx[cnt].peer = peers[cnt]; |
885 | a_ctx[cnt].op = GNUNET_TESTBED_peer_manage_service(&a_ctx[cnt], | 893 | a_ctx[cnt].op = GNUNET_TESTBED_peer_manage_service (&a_ctx[cnt], |
886 | peers[cnt], | 894 | peers[cnt], |
887 | "dht", | 895 | "dht", |
888 | &service_started, | 896 | &service_started, |
889 | &a_ctx[cnt], | 897 | &a_ctx[cnt], |
890 | 1); | 898 | 1); |
891 | } | 899 | } |
892 | } | 900 | } |
893 | 901 | ||
894 | 902 | ||
@@ -901,32 +909,32 @@ test_run(void *cls, | |||
901 | * @param config configuration | 909 | * @param config configuration |
902 | */ | 910 | */ |
903 | static void | 911 | static void |
904 | run(void *cls, | 912 | run (void *cls, |
905 | char *const *args, | 913 | char *const *args, |
906 | const char *cfgfile, | 914 | const char *cfgfile, |
907 | const struct GNUNET_CONFIGURATION_Handle *config) | 915 | const struct GNUNET_CONFIGURATION_Handle *config) |
908 | { | 916 | { |
909 | uint64_t event_mask; | 917 | uint64_t event_mask; |
910 | 918 | ||
911 | if (0 == num_peers) | 919 | if (0 == num_peers) |
912 | { | 920 | { |
913 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 921 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
914 | _("Exiting as the number of peers is %u\n"), | 922 | _ ("Exiting as the number of peers is %u\n"), |
915 | num_peers); | 923 | num_peers); |
916 | return; | 924 | return; |
917 | } | 925 | } |
918 | cfg = config; | 926 | cfg = config; |
919 | event_mask = 0; | 927 | event_mask = 0; |
920 | GNUNET_TESTBED_run(hosts_file, | 928 | GNUNET_TESTBED_run (hosts_file, |
921 | cfg, | 929 | cfg, |
922 | num_peers, | 930 | num_peers, |
923 | event_mask, | 931 | event_mask, |
924 | NULL, | 932 | NULL, |
925 | NULL, | 933 | NULL, |
926 | &test_run, | 934 | &test_run, |
927 | NULL); | 935 | NULL); |
928 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, | 936 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, |
929 | NULL); | 937 | NULL); |
930 | } | 938 | } |
931 | 939 | ||
932 | 940 | ||
@@ -936,78 +944,86 @@ run(void *cls, | |||
936 | * @return 0 on success | 944 | * @return 0 on success |
937 | */ | 945 | */ |
938 | int | 946 | int |
939 | main(int argc, | 947 | main (int argc, |
940 | char *const *argv) | 948 | char *const *argv) |
941 | { | 949 | { |
942 | int rc; | 950 | int rc; |
943 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 951 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
944 | GNUNET_GETOPT_option_uint('n', | 952 | GNUNET_GETOPT_option_uint ('n', |
945 | "peers", | 953 | "peers", |
946 | "COUNT", | 954 | "COUNT", |
947 | gettext_noop("number of peers to start"), | 955 | gettext_noop ("number of peers to start"), |
948 | &num_peers), | 956 | &num_peers), |
949 | GNUNET_GETOPT_option_uint('p', | 957 | GNUNET_GETOPT_option_uint ('p', |
950 | "peer-put-count", | 958 | "peer-put-count", |
951 | "COUNT", | 959 | "COUNT", |
952 | gettext_noop("number of PUTs to perform per peer"), | 960 | gettext_noop ( |
953 | &num_puts_per_peer), | 961 | "number of PUTs to perform per peer"), |
954 | GNUNET_GETOPT_option_string('H', | 962 | &num_puts_per_peer), |
955 | "hosts", | 963 | GNUNET_GETOPT_option_string ('H', |
956 | "FILENAME", | 964 | "hosts", |
957 | gettext_noop("name of the file with the login information for the testbed"), | 965 | "FILENAME", |
958 | &hosts_file), | 966 | gettext_noop ( |
959 | GNUNET_GETOPT_option_relative_time('D', | 967 | "name of the file with the login information for the testbed"), |
960 | "delay", | 968 | &hosts_file), |
961 | "DELAY", | 969 | GNUNET_GETOPT_option_relative_time ('D', |
962 | gettext_noop("delay between rounds for collecting statistics (default: 30 sec)"), | 970 | "delay", |
963 | &delay_stats), | 971 | "DELAY", |
964 | GNUNET_GETOPT_option_relative_time('P', | 972 | gettext_noop ( |
965 | "PUT-delay", | 973 | "delay between rounds for collecting statistics (default: 30 sec)"), |
966 | "DELAY", | 974 | &delay_stats), |
967 | gettext_noop("delay to start doing PUTs (default: 1 sec)"), | 975 | GNUNET_GETOPT_option_relative_time ('P', |
968 | &delay_put), | 976 | "PUT-delay", |
969 | GNUNET_GETOPT_option_relative_time('G', | 977 | "DELAY", |
970 | "GET-delay", | 978 | gettext_noop ( |
971 | "DELAY", | 979 | "delay to start doing PUTs (default: 1 sec)"), |
972 | gettext_noop("delay to start doing GETs (default: 5 min)"), | 980 | &delay_put), |
973 | &delay_get), | 981 | GNUNET_GETOPT_option_relative_time ('G', |
974 | GNUNET_GETOPT_option_uint('r', | 982 | "GET-delay", |
975 | "replication", | 983 | "DELAY", |
976 | "DEGREE", | 984 | gettext_noop ( |
977 | gettext_noop("replication degree for DHT PUTs"), | 985 | "delay to start doing GETs (default: 5 min)"), |
978 | &replication), | 986 | &delay_get), |
979 | GNUNET_GETOPT_option_uint('R', | 987 | GNUNET_GETOPT_option_uint ('r', |
980 | "random-chance", | 988 | "replication", |
981 | "PROBABILITY", | 989 | "DEGREE", |
982 | gettext_noop("chance that a peer is selected at random for PUTs"), | 990 | gettext_noop ("replication degree for DHT PUTs"), |
983 | &put_probability), | 991 | &replication), |
984 | GNUNET_GETOPT_option_relative_time('t', | 992 | GNUNET_GETOPT_option_uint ('R', |
985 | "timeout", | 993 | "random-chance", |
986 | "TIMEOUT", | 994 | "PROBABILITY", |
987 | gettext_noop("timeout for DHT PUT and GET requests (default: 1 min)"), | 995 | gettext_noop ( |
988 | &timeout), | 996 | "chance that a peer is selected at random for PUTs"), |
997 | &put_probability), | ||
998 | GNUNET_GETOPT_option_relative_time ('t', | ||
999 | "timeout", | ||
1000 | "TIMEOUT", | ||
1001 | gettext_noop ( | ||
1002 | "timeout for DHT PUT and GET requests (default: 1 min)"), | ||
1003 | &timeout), | ||
989 | GNUNET_GETOPT_OPTION_END | 1004 | GNUNET_GETOPT_OPTION_END |
990 | }; | 1005 | }; |
991 | 1006 | ||
992 | if (GNUNET_OK != | 1007 | if (GNUNET_OK != |
993 | GNUNET_STRINGS_get_utf8_args(argc, argv, | 1008 | GNUNET_STRINGS_get_utf8_args (argc, argv, |
994 | &argc, &argv)) | 1009 | &argc, &argv)) |
995 | return 2; | 1010 | return 2; |
996 | /* set default delays */ | 1011 | /* set default delays */ |
997 | delay_stats = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10); | 1012 | delay_stats = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); |
998 | delay_put = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10); | 1013 | delay_put = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); |
999 | delay_get = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10); | 1014 | delay_get = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); |
1000 | timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10); | 1015 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); |
1001 | replication = 1; /* default replication */ | 1016 | replication = 1; /* default replication */ |
1002 | rc = 0; | 1017 | rc = 0; |
1003 | if (GNUNET_OK != | 1018 | if (GNUNET_OK != |
1004 | GNUNET_PROGRAM_run(argc, | 1019 | GNUNET_PROGRAM_run (argc, |
1005 | argv, | 1020 | argv, |
1006 | "gnunet-dht-profiler", | 1021 | "gnunet-dht-profiler", |
1007 | gettext_noop("Measure quality and performance of the DHT service."), | 1022 | gettext_noop ( |
1008 | options, | 1023 | "Measure quality and performance of the DHT service."), |
1009 | &run, | 1024 | options, |
1010 | NULL)) | 1025 | &run, |
1026 | NULL)) | ||
1011 | rc = 1; | 1027 | rc = 1; |
1012 | return rc; | 1028 | return rc; |
1013 | } | 1029 | } |
diff --git a/src/dht/plugin_block_dht.c b/src/dht/plugin_block_dht.c index 918a18eb6..084384146 100644 --- a/src/dht/plugin_block_dht.c +++ b/src/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 | */ |
55 | static struct GNUNET_BLOCK_Group * | 55 | static struct GNUNET_BLOCK_Group * |
56 | block_plugin_dht_create_group(void *cls, | 56 | block_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 | */ |
107 | static enum GNUNET_BLOCK_EvaluationResult | 107 | static enum GNUNET_BLOCK_EvaluationResult |
108 | block_plugin_dht_evaluate(void *cls, | 108 | block_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 | */ |
172 | static int | 172 | static int |
173 | block_plugin_dht_get_key(void *cls, | 173 | block_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; |
@@ -183,33 +183,33 @@ block_plugin_dht_get_key(void *cls, | |||
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,16 +218,15 @@ block_plugin_dht_get_key(void *cls, | |||
218 | * Entry point for the plugin. | 218 | * Entry point for the plugin. |
219 | */ | 219 | */ |
220 | void * | 220 | void * |
221 | libgnunet_plugin_block_dht_init(void *cls) | 221 | libgnunet_plugin_block_dht_init (void *cls) |
222 | { | 222 | { |
223 | static enum GNUNET_BLOCK_Type types[] = | 223 | static enum GNUNET_BLOCK_Type types[] = { |
224 | { | ||
225 | GNUNET_BLOCK_TYPE_DHT_HELLO, | 224 | GNUNET_BLOCK_TYPE_DHT_HELLO, |
226 | GNUNET_BLOCK_TYPE_ANY /* end of list */ | 225 | GNUNET_BLOCK_TYPE_ANY /* end of list */ |
227 | }; | 226 | }; |
228 | struct GNUNET_BLOCK_PluginFunctions *api; | 227 | struct GNUNET_BLOCK_PluginFunctions *api; |
229 | 228 | ||
230 | api = GNUNET_new(struct GNUNET_BLOCK_PluginFunctions); | 229 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
231 | api->evaluate = &block_plugin_dht_evaluate; | 230 | api->evaluate = &block_plugin_dht_evaluate; |
232 | api->get_key = &block_plugin_dht_get_key; | 231 | api->get_key = &block_plugin_dht_get_key; |
233 | api->create_group = &block_plugin_dht_create_group; | 232 | api->create_group = &block_plugin_dht_create_group; |
@@ -240,11 +239,11 @@ libgnunet_plugin_block_dht_init(void *cls) | |||
240 | * Exit point from the plugin. | 239 | * Exit point from the plugin. |
241 | */ | 240 | */ |
242 | void * | 241 | void * |
243 | libgnunet_plugin_block_dht_done(void *cls) | 242 | libgnunet_plugin_block_dht_done (void *cls) |
244 | { | 243 | { |
245 | struct GNUNET_BLOCK_PluginFunctions *api = cls; | 244 | struct GNUNET_BLOCK_PluginFunctions *api = cls; |
246 | 245 | ||
247 | GNUNET_free(api); | 246 | GNUNET_free (api); |
248 | return NULL; | 247 | return NULL; |
249 | } | 248 | } |
250 | 249 | ||
diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c index f4a337ea8..a62ee9668 100644 --- a/src/dht/test_dht_api.c +++ b/src/dht/test_dht_api.c | |||
@@ -34,7 +34,8 @@ | |||
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, \ |
38 | 60) | ||
38 | 39 | ||
39 | static struct GNUNET_DHT_Handle *dht_handle; | 40 | static struct GNUNET_DHT_Handle *dht_handle; |
40 | 41 | ||
@@ -48,55 +49,55 @@ static struct GNUNET_SCHEDULER_Task *die_task; | |||
48 | 49 | ||
49 | 50 | ||
50 | static void | 51 | static void |
51 | do_shutdown(void *cls) | 52 | do_shutdown (void *cls) |
52 | { | 53 | { |
53 | if (NULL != die_task) | 54 | if (NULL != die_task) |
54 | { | 55 | { |
55 | GNUNET_SCHEDULER_cancel(die_task); | 56 | GNUNET_SCHEDULER_cancel (die_task); |
56 | die_task = NULL; | 57 | die_task = NULL; |
57 | } | 58 | } |
58 | if (NULL != put_handle) | 59 | if (NULL != put_handle) |
59 | { | 60 | { |
60 | GNUNET_DHT_put_cancel(put_handle); | 61 | GNUNET_DHT_put_cancel (put_handle); |
61 | put_handle = NULL; | 62 | put_handle = NULL; |
62 | } | 63 | } |
63 | if (NULL != get_handle) | 64 | if (NULL != get_handle) |
64 | { | 65 | { |
65 | GNUNET_DHT_get_stop(get_handle); | 66 | GNUNET_DHT_get_stop (get_handle); |
66 | get_handle = NULL; | 67 | get_handle = NULL; |
67 | } | 68 | } |
68 | GNUNET_DHT_disconnect(dht_handle); | 69 | GNUNET_DHT_disconnect (dht_handle); |
69 | dht_handle = NULL; | 70 | dht_handle = NULL; |
70 | } | 71 | } |
71 | 72 | ||
72 | 73 | ||
73 | static void | 74 | static void |
74 | end_badly(void *cls) | 75 | end_badly (void *cls) |
75 | { | 76 | { |
76 | die_task = NULL; | 77 | die_task = NULL; |
77 | fprintf(stderr, | 78 | fprintf (stderr, |
78 | "%s", | 79 | "%s", |
79 | "Ending on an unhappy note.\n"); | 80 | "Ending on an unhappy note.\n"); |
80 | GNUNET_SCHEDULER_shutdown(); | 81 | GNUNET_SCHEDULER_shutdown (); |
81 | ok = 1; | 82 | ok = 1; |
82 | } | 83 | } |
83 | 84 | ||
84 | 85 | ||
85 | static void | 86 | static void |
86 | test_get_iterator(void *cls, | 87 | test_get_iterator (void *cls, |
87 | struct GNUNET_TIME_Absolute exp, | 88 | struct GNUNET_TIME_Absolute exp, |
88 | const struct GNUNET_HashCode *key, | 89 | const struct GNUNET_HashCode *key, |
89 | const struct GNUNET_PeerIdentity *get_path, | 90 | const struct GNUNET_PeerIdentity *get_path, |
90 | unsigned int get_path_length, | 91 | unsigned int get_path_length, |
91 | const struct GNUNET_PeerIdentity *put_path, | 92 | const struct GNUNET_PeerIdentity *put_path, |
92 | unsigned int put_path_length, | 93 | unsigned int put_path_length, |
93 | enum GNUNET_BLOCK_Type type, | 94 | enum GNUNET_BLOCK_Type type, |
94 | size_t size, | 95 | size_t size, |
95 | const void *data) | 96 | const void *data) |
96 | { | 97 | { |
97 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 98 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
98 | "test_get_iterator called (we got a result), stopping get request!\n"); | 99 | "test_get_iterator called (we got a result), stopping get request!\n"); |
99 | GNUNET_SCHEDULER_shutdown(); | 100 | GNUNET_SCHEDULER_shutdown (); |
100 | ok = 0; | 101 | ok = 0; |
101 | } | 102 | } |
102 | 103 | ||
@@ -107,83 +108,83 @@ test_get_iterator(void *cls, | |||
107 | * @param cls closure | 108 | * @param cls closure |
108 | */ | 109 | */ |
109 | static void | 110 | static void |
110 | test_get(void *cls) | 111 | test_get (void *cls) |
111 | { | 112 | { |
112 | struct GNUNET_HashCode hash; | 113 | struct GNUNET_HashCode hash; |
113 | 114 | ||
114 | put_handle = NULL; | 115 | put_handle = NULL; |
115 | memset(&hash, | 116 | memset (&hash, |
116 | 42, | 117 | 42, |
117 | sizeof(struct GNUNET_HashCode)); | 118 | sizeof(struct GNUNET_HashCode)); |
118 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 119 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
119 | "Called test_get!\n"); | 120 | "Called test_get!\n"); |
120 | GNUNET_assert(dht_handle != NULL); | 121 | GNUNET_assert (dht_handle != NULL); |
121 | get_handle = GNUNET_DHT_get_start(dht_handle, | 122 | get_handle = GNUNET_DHT_get_start (dht_handle, |
122 | GNUNET_BLOCK_TYPE_TEST, | 123 | GNUNET_BLOCK_TYPE_TEST, |
123 | &hash, | 124 | &hash, |
124 | 1, | 125 | 1, |
125 | GNUNET_DHT_RO_NONE, | 126 | GNUNET_DHT_RO_NONE, |
126 | NULL, | 127 | NULL, |
127 | 0, | 128 | 0, |
128 | &test_get_iterator, | 129 | &test_get_iterator, |
129 | NULL); | 130 | NULL); |
130 | 131 | ||
131 | if (NULL == get_handle) | 132 | if (NULL == get_handle) |
132 | { | 133 | { |
133 | GNUNET_break(0); | 134 | GNUNET_break (0); |
134 | ok = 1; | 135 | ok = 1; |
135 | GNUNET_SCHEDULER_shutdown(); | 136 | GNUNET_SCHEDULER_shutdown (); |
136 | return; | 137 | return; |
137 | } | 138 | } |
138 | } | 139 | } |
139 | 140 | ||
140 | 141 | ||
141 | static void | 142 | static void |
142 | run(void *cls, | 143 | run (void *cls, |
143 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 144 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
144 | struct GNUNET_TESTING_Peer *peer) | 145 | struct GNUNET_TESTING_Peer *peer) |
145 | { | 146 | { |
146 | struct GNUNET_HashCode hash; | 147 | struct GNUNET_HashCode hash; |
147 | char *data; | 148 | char *data; |
148 | size_t data_size = 42; | 149 | size_t data_size = 42; |
149 | 150 | ||
150 | GNUNET_assert(ok == 1); | 151 | GNUNET_assert (ok == 1); |
151 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, | 152 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, |
152 | NULL); | 153 | NULL); |
153 | die_task = GNUNET_SCHEDULER_add_delayed(TOTAL_TIMEOUT, | 154 | die_task = GNUNET_SCHEDULER_add_delayed (TOTAL_TIMEOUT, |
154 | &end_badly, | 155 | &end_badly, |
155 | NULL); | 156 | NULL); |
156 | memset(&hash, | 157 | memset (&hash, |
157 | 42, | 158 | 42, |
158 | sizeof(struct GNUNET_HashCode)); | 159 | sizeof(struct GNUNET_HashCode)); |
159 | data = GNUNET_malloc(data_size); | 160 | data = GNUNET_malloc (data_size); |
160 | memset(data, 43, data_size); | 161 | memset (data, 43, data_size); |
161 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
162 | "Called test_put!\n"); | 163 | "Called test_put!\n"); |
163 | dht_handle = GNUNET_DHT_connect(cfg, | 164 | dht_handle = GNUNET_DHT_connect (cfg, |
164 | 100); | 165 | 100); |
165 | GNUNET_assert(NULL != dht_handle); | 166 | GNUNET_assert (NULL != dht_handle); |
166 | put_handle = GNUNET_DHT_put(dht_handle, | 167 | put_handle = GNUNET_DHT_put (dht_handle, |
167 | &hash, | 168 | &hash, |
168 | 1, | 169 | 1, |
169 | GNUNET_DHT_RO_NONE, | 170 | GNUNET_DHT_RO_NONE, |
170 | GNUNET_BLOCK_TYPE_TEST, | 171 | GNUNET_BLOCK_TYPE_TEST, |
171 | data_size, | 172 | data_size, |
172 | data, | 173 | data, |
173 | GNUNET_TIME_relative_to_absolute(TOTAL_TIMEOUT), | 174 | GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT), |
174 | &test_get, | 175 | &test_get, |
175 | NULL); | 176 | NULL); |
176 | GNUNET_free(data); | 177 | GNUNET_free (data); |
177 | } | 178 | } |
178 | 179 | ||
179 | 180 | ||
180 | int | 181 | int |
181 | main(int argc, | 182 | main (int argc, |
182 | char *argv[]) | 183 | char *argv[]) |
183 | { | 184 | { |
184 | if (0 != GNUNET_TESTING_peer_run("test-dht-api", | 185 | if (0 != GNUNET_TESTING_peer_run ("test-dht-api", |
185 | "test_dht_api_data.conf", | 186 | "test_dht_api_data.conf", |
186 | &run, NULL)) | 187 | &run, NULL)) |
187 | return 1; | 188 | return 1; |
188 | return ok; | 189 | return ok; |
189 | } | 190 | } |
diff --git a/src/dht/test_dht_monitor.c b/src/dht/test_dht_monitor.c index f5586e9bc..95fb37bcd 100644 --- a/src/dht/test_dht_monitor.c +++ b/src/dht/test_dht_monitor.c | |||
@@ -31,18 +31,20 @@ | |||
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, \ |
40 | 10) | ||
40 | 41 | ||
41 | 42 | ||
42 | /** | 43 | /** |
43 | * Information we keep for each GET operation. | 44 | * Information we keep for each GET operation. |
44 | */ | 45 | */ |
45 | struct GetOperation { | 46 | struct GetOperation |
47 | { | ||
46 | /** | 48 | /** |
47 | * DLL. | 49 | * DLL. |
48 | */ | 50 | */ |
@@ -93,7 +95,7 @@ static struct GNUNET_SCHEDULER_Task *timeout_task; | |||
93 | /** | 95 | /** |
94 | * Task to do DHT_puts | 96 | * Task to do DHT_puts |
95 | */ | 97 | */ |
96 | static struct GNUNET_SCHEDULER_Task * put_task; | 98 | static struct GNUNET_SCHEDULER_Task *put_task; |
97 | 99 | ||
98 | static struct GNUNET_DHT_MonitorHandle **monitors; | 100 | static struct GNUNET_DHT_MonitorHandle **monitors; |
99 | 101 | ||
@@ -108,34 +110,34 @@ static unsigned int monitor_counter; | |||
108 | * @param cls the `struct GNUNET_DHT_TEST_Context` | 110 | * @param cls the `struct GNUNET_DHT_TEST_Context` |
109 | */ | 111 | */ |
110 | static void | 112 | static void |
111 | shutdown_task(void *cls) | 113 | shutdown_task (void *cls) |
112 | { | 114 | { |
113 | struct GNUNET_DHT_TEST_Context *ctx = cls; | 115 | struct GNUNET_DHT_TEST_Context *ctx = cls; |
114 | unsigned int i; | 116 | unsigned int i; |
115 | struct GetOperation *get_op; | 117 | struct GetOperation *get_op; |
116 | 118 | ||
117 | ok = (monitor_counter > NUM_PEERS) ? 0 : 2; | 119 | ok = (monitor_counter > NUM_PEERS) ? 0 : 2; |
118 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 120 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
119 | "Received %u monitor events\n", | 121 | "Received %u monitor events\n", |
120 | monitor_counter); | 122 | monitor_counter); |
121 | while (NULL != (get_op = get_tail)) | 123 | while (NULL != (get_op = get_tail)) |
122 | { | 124 | { |
123 | GNUNET_DHT_get_stop(get_op->get); | 125 | GNUNET_DHT_get_stop (get_op->get); |
124 | GNUNET_CONTAINER_DLL_remove(get_head, | 126 | GNUNET_CONTAINER_DLL_remove (get_head, |
125 | get_tail, | 127 | get_tail, |
126 | get_op); | 128 | get_op); |
127 | GNUNET_free(get_op); | 129 | GNUNET_free (get_op); |
128 | } | 130 | } |
129 | for (i = 0; i < NUM_PEERS; i++) | 131 | for (i = 0; i < NUM_PEERS; i++) |
130 | GNUNET_DHT_monitor_stop(monitors[i]); | 132 | GNUNET_DHT_monitor_stop (monitors[i]); |
131 | GNUNET_free(monitors); | 133 | GNUNET_free (monitors); |
132 | GNUNET_SCHEDULER_cancel(put_task); | 134 | GNUNET_SCHEDULER_cancel (put_task); |
133 | GNUNET_DHT_TEST_cleanup(ctx); | 135 | GNUNET_DHT_TEST_cleanup (ctx); |
134 | if (NULL != timeout_task) | 136 | if (NULL != timeout_task) |
135 | { | 137 | { |
136 | GNUNET_SCHEDULER_cancel(timeout_task); | 138 | GNUNET_SCHEDULER_cancel (timeout_task); |
137 | timeout_task = NULL; | 139 | timeout_task = NULL; |
138 | } | 140 | } |
139 | } | 141 | } |
140 | 142 | ||
141 | 143 | ||
@@ -147,10 +149,10 @@ shutdown_task(void *cls) | |||
147 | * @param cls NULL | 149 | * @param cls NULL |
148 | */ | 150 | */ |
149 | static void | 151 | static void |
150 | timeout_task_cb(void *cls) | 152 | timeout_task_cb (void *cls) |
151 | { | 153 | { |
152 | timeout_task = NULL; | 154 | timeout_task = NULL; |
153 | GNUNET_SCHEDULER_shutdown(); | 155 | GNUNET_SCHEDULER_shutdown (); |
154 | } | 156 | } |
155 | 157 | ||
156 | 158 | ||
@@ -170,41 +172,41 @@ timeout_task_cb(void *cls) | |||
170 | * @param data pointer to the result data | 172 | * @param data pointer to the result data |
171 | */ | 173 | */ |
172 | static void | 174 | static void |
173 | dht_get_handler(void *cls, struct GNUNET_TIME_Absolute exp, | 175 | dht_get_handler (void *cls, struct GNUNET_TIME_Absolute exp, |
174 | const struct GNUNET_HashCode * key, | 176 | const struct GNUNET_HashCode *key, |
175 | const struct GNUNET_PeerIdentity *get_path, | 177 | const struct GNUNET_PeerIdentity *get_path, |
176 | unsigned int get_path_length, | 178 | unsigned int get_path_length, |
177 | const struct GNUNET_PeerIdentity *put_path, | 179 | const struct GNUNET_PeerIdentity *put_path, |
178 | unsigned int put_path_length, | 180 | unsigned int put_path_length, |
179 | enum GNUNET_BLOCK_Type type, | 181 | enum GNUNET_BLOCK_Type type, |
180 | size_t size, const void *data) | 182 | size_t size, const void *data) |
181 | { | 183 | { |
182 | struct GetOperation *get_op = cls; | 184 | struct GetOperation *get_op = cls; |
183 | struct GNUNET_HashCode want; | 185 | struct GNUNET_HashCode want; |
184 | 186 | ||
185 | if (sizeof(struct GNUNET_HashCode) != size) | 187 | if (sizeof(struct GNUNET_HashCode) != size) |
186 | { | 188 | { |
187 | GNUNET_break(0); | 189 | GNUNET_break (0); |
188 | return; | 190 | return; |
189 | } | 191 | } |
190 | GNUNET_CRYPTO_hash(key, sizeof(*key), &want); | 192 | GNUNET_CRYPTO_hash (key, sizeof(*key), &want); |
191 | if (0 != memcmp(&want, data, sizeof(want))) | 193 | if (0 != memcmp (&want, data, sizeof(want))) |
192 | { | 194 | { |
193 | GNUNET_break(0); | 195 | GNUNET_break (0); |
194 | return; | 196 | return; |
195 | } | 197 | } |
196 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 198 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
197 | "Get successful\n"); | 199 | "Get successful\n"); |
198 | GNUNET_DHT_get_stop(get_op->get); | 200 | GNUNET_DHT_get_stop (get_op->get); |
199 | GNUNET_CONTAINER_DLL_remove(get_head, | 201 | GNUNET_CONTAINER_DLL_remove (get_head, |
200 | get_tail, | 202 | get_tail, |
201 | get_op); | 203 | get_op); |
202 | GNUNET_free(get_op); | 204 | GNUNET_free (get_op); |
203 | if (NULL != get_head) | 205 | if (NULL != get_head) |
204 | return; | 206 | return; |
205 | /* all DHT GET operations successful; terminate! */ | 207 | /* all DHT GET operations successful; terminate! */ |
206 | ok = 0; | 208 | ok = 0; |
207 | GNUNET_SCHEDULER_shutdown(); | 209 | GNUNET_SCHEDULER_shutdown (); |
208 | } | 210 | } |
209 | 211 | ||
210 | 212 | ||
@@ -214,28 +216,28 @@ dht_get_handler(void *cls, struct GNUNET_TIME_Absolute exp, | |||
214 | * @param cls array with NUM_PEERS DHT handles | 216 | * @param cls array with NUM_PEERS DHT handles |
215 | */ | 217 | */ |
216 | static void | 218 | static void |
217 | do_puts(void *cls) | 219 | do_puts (void *cls) |
218 | { | 220 | { |
219 | struct GNUNET_DHT_Handle **hs = cls; | 221 | struct GNUNET_DHT_Handle **hs = cls; |
220 | struct GNUNET_HashCode key; | 222 | struct GNUNET_HashCode key; |
221 | struct GNUNET_HashCode value; | 223 | struct GNUNET_HashCode value; |
222 | 224 | ||
223 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
224 | "Putting values into DHT\n"); | 226 | "Putting values into DHT\n"); |
225 | for (unsigned int i = 0; i < NUM_PEERS; i++) | 227 | for (unsigned int i = 0; i < NUM_PEERS; i++) |
226 | { | 228 | { |
227 | GNUNET_CRYPTO_hash(&i, sizeof(i), &key); | 229 | GNUNET_CRYPTO_hash (&i, sizeof(i), &key); |
228 | GNUNET_CRYPTO_hash(&key, sizeof(key), &value); | 230 | GNUNET_CRYPTO_hash (&key, sizeof(key), &value); |
229 | GNUNET_DHT_put(hs[i], &key, 10U, | 231 | GNUNET_DHT_put (hs[i], &key, 10U, |
230 | GNUNET_DHT_RO_RECORD_ROUTE | | 232 | GNUNET_DHT_RO_RECORD_ROUTE |
231 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | 233 | | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, |
232 | GNUNET_BLOCK_TYPE_TEST, | 234 | GNUNET_BLOCK_TYPE_TEST, |
233 | sizeof(value), &value, | 235 | sizeof(value), &value, |
234 | GNUNET_TIME_UNIT_FOREVER_ABS, | 236 | GNUNET_TIME_UNIT_FOREVER_ABS, |
235 | NULL, NULL); | 237 | NULL, NULL); |
236 | } | 238 | } |
237 | put_task = GNUNET_SCHEDULER_add_delayed(PUT_FREQUENCY, | 239 | put_task = GNUNET_SCHEDULER_add_delayed (PUT_FREQUENCY, |
238 | &do_puts, hs); | 240 | &do_puts, hs); |
239 | } | 241 | } |
240 | 242 | ||
241 | 243 | ||
@@ -253,22 +255,22 @@ do_puts(void *cls) | |||
253 | * @param key Key of the requested data. | 255 | * @param key Key of the requested data. |
254 | */ | 256 | */ |
255 | static void | 257 | static void |
256 | monitor_get_cb(void *cls, | 258 | monitor_get_cb (void *cls, |
257 | enum GNUNET_DHT_RouteOption options, | 259 | enum GNUNET_DHT_RouteOption options, |
258 | enum GNUNET_BLOCK_Type type, | 260 | enum GNUNET_BLOCK_Type type, |
259 | uint32_t hop_count, | 261 | uint32_t hop_count, |
260 | uint32_t desired_replication_level, | 262 | uint32_t desired_replication_level, |
261 | unsigned int path_length, | 263 | unsigned int path_length, |
262 | const struct GNUNET_PeerIdentity *path, | 264 | const struct GNUNET_PeerIdentity *path, |
263 | const struct GNUNET_HashCode * key) | 265 | const struct GNUNET_HashCode *key) |
264 | { | 266 | { |
265 | unsigned int i; | 267 | unsigned int i; |
266 | 268 | ||
267 | i = (unsigned int)(long)cls; | 269 | i = (unsigned int) (long) cls; |
268 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 270 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
269 | "%u got a GET message for key %s\n", | 271 | "%u got a GET message for key %s\n", |
270 | i, | 272 | i, |
271 | GNUNET_h2s(key)); | 273 | GNUNET_h2s (key)); |
272 | monitor_counter++; | 274 | monitor_counter++; |
273 | } | 275 | } |
274 | 276 | ||
@@ -290,26 +292,26 @@ monitor_get_cb(void *cls, | |||
290 | * @param size Number of bytes in data. | 292 | * @param size Number of bytes in data. |
291 | */ | 293 | */ |
292 | static void | 294 | static void |
293 | monitor_put_cb(void *cls, | 295 | monitor_put_cb (void *cls, |
294 | enum GNUNET_DHT_RouteOption options, | 296 | enum GNUNET_DHT_RouteOption options, |
295 | enum GNUNET_BLOCK_Type type, | 297 | enum GNUNET_BLOCK_Type type, |
296 | uint32_t hop_count, | 298 | uint32_t hop_count, |
297 | uint32_t desired_replication_level, | 299 | uint32_t desired_replication_level, |
298 | unsigned int path_length, | 300 | unsigned int path_length, |
299 | const struct GNUNET_PeerIdentity *path, | 301 | const struct GNUNET_PeerIdentity *path, |
300 | struct GNUNET_TIME_Absolute exp, | 302 | struct GNUNET_TIME_Absolute exp, |
301 | const struct GNUNET_HashCode * key, | 303 | const struct GNUNET_HashCode *key, |
302 | const void *data, | 304 | const void *data, |
303 | size_t size) | 305 | size_t size) |
304 | { | 306 | { |
305 | unsigned int i; | 307 | unsigned int i; |
306 | 308 | ||
307 | i = (unsigned int)(long)cls; | 309 | i = (unsigned int) (long) cls; |
308 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 310 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
309 | "%u got a PUT message for key %s with %u bytes\n", | 311 | "%u got a PUT message for key %s with %u bytes\n", |
310 | i, | 312 | i, |
311 | GNUNET_h2s(key), | 313 | GNUNET_h2s (key), |
312 | (unsigned int)size); | 314 | (unsigned int) size); |
313 | monitor_counter++; | 315 | monitor_counter++; |
314 | } | 316 | } |
315 | 317 | ||
@@ -330,25 +332,25 @@ monitor_put_cb(void *cls, | |||
330 | * @param size Number of bytes in data. | 332 | * @param size Number of bytes in data. |
331 | */ | 333 | */ |
332 | static void | 334 | static void |
333 | monitor_res_cb(void *cls, | 335 | monitor_res_cb (void *cls, |
334 | enum GNUNET_BLOCK_Type type, | 336 | enum GNUNET_BLOCK_Type type, |
335 | const struct GNUNET_PeerIdentity *get_path, | 337 | const struct GNUNET_PeerIdentity *get_path, |
336 | unsigned int get_path_length, | 338 | unsigned int get_path_length, |
337 | const struct GNUNET_PeerIdentity *put_path, | 339 | const struct GNUNET_PeerIdentity *put_path, |
338 | unsigned int put_path_length, | 340 | unsigned int put_path_length, |
339 | struct GNUNET_TIME_Absolute exp, | 341 | struct GNUNET_TIME_Absolute exp, |
340 | const struct GNUNET_HashCode * key, | 342 | const struct GNUNET_HashCode *key, |
341 | const void *data, | 343 | const void *data, |
342 | size_t size) | 344 | size_t size) |
343 | { | 345 | { |
344 | unsigned int i; | 346 | unsigned int i; |
345 | 347 | ||
346 | i = (unsigned int)(long)cls; | 348 | i = (unsigned int) (long) cls; |
347 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 349 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
348 | "%u got a REPLY message for key %s with %u bytes\n", | 350 | "%u got a REPLY message for key %s with %u bytes\n", |
349 | i, | 351 | i, |
350 | GNUNET_h2s(key), | 352 | GNUNET_h2s (key), |
351 | (unsigned int)size); | 353 | (unsigned int) size); |
352 | monitor_counter++; | 354 | monitor_counter++; |
353 | } | 355 | } |
354 | 356 | ||
@@ -363,56 +365,56 @@ monitor_res_cb(void *cls, | |||
363 | * @param dhts handle to each of the DHTs of the peers | 365 | * @param dhts handle to each of the DHTs of the peers |
364 | */ | 366 | */ |
365 | static void | 367 | static void |
366 | run(void *cls, | 368 | run (void *cls, |
367 | struct GNUNET_DHT_TEST_Context *ctx, | 369 | struct GNUNET_DHT_TEST_Context *ctx, |
368 | unsigned int num_peers, | 370 | unsigned int num_peers, |
369 | struct GNUNET_TESTBED_Peer **peers, | 371 | struct GNUNET_TESTBED_Peer **peers, |
370 | struct GNUNET_DHT_Handle **dhts) | 372 | struct GNUNET_DHT_Handle **dhts) |
371 | { | 373 | { |
372 | unsigned int i; | 374 | unsigned int i; |
373 | unsigned int j; | 375 | unsigned int j; |
374 | struct GNUNET_HashCode key; | 376 | struct GNUNET_HashCode key; |
375 | struct GetOperation *get_op; | 377 | struct GetOperation *get_op; |
376 | 378 | ||
377 | GNUNET_assert(NUM_PEERS == num_peers); | 379 | GNUNET_assert (NUM_PEERS == num_peers); |
378 | my_peers = peers; | 380 | my_peers = peers; |
379 | monitors = GNUNET_new_array(num_peers, | 381 | monitors = GNUNET_new_array (num_peers, |
380 | struct GNUNET_DHT_MonitorHandle *); | 382 | struct GNUNET_DHT_MonitorHandle *); |
381 | for (i = 0; i < num_peers; i++) | 383 | for (i = 0; i < num_peers; i++) |
382 | monitors[i] = GNUNET_DHT_monitor_start(dhts[i], | 384 | monitors[i] = GNUNET_DHT_monitor_start (dhts[i], |
383 | GNUNET_BLOCK_TYPE_ANY, | 385 | GNUNET_BLOCK_TYPE_ANY, |
384 | NULL, | 386 | NULL, |
385 | &monitor_get_cb, | 387 | &monitor_get_cb, |
386 | &monitor_res_cb, | 388 | &monitor_res_cb, |
387 | &monitor_put_cb, | 389 | &monitor_put_cb, |
388 | (void *)(long)i); | 390 | (void *) (long) i); |
389 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 391 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
390 | "Peers setup, starting test\n"); | 392 | "Peers setup, starting test\n"); |
391 | put_task = GNUNET_SCHEDULER_add_now(&do_puts, dhts); | 393 | put_task = GNUNET_SCHEDULER_add_now (&do_puts, dhts); |
392 | for (i = 0; i < num_peers; i++) | 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++) | ||
393 | { | 398 | { |
394 | GNUNET_CRYPTO_hash(&i, sizeof(i), &key); | 399 | get_op = GNUNET_new (struct GetOperation); |
395 | for (j = 0; j < num_peers; j++) | 400 | GNUNET_CONTAINER_DLL_insert (get_head, |
396 | { | 401 | get_tail, |
397 | get_op = GNUNET_new(struct GetOperation); | 402 | get_op); |
398 | GNUNET_CONTAINER_DLL_insert(get_head, | 403 | get_op->get = GNUNET_DHT_get_start (dhts[j], |
399 | get_tail, | 404 | GNUNET_BLOCK_TYPE_TEST, /* type */ |
400 | get_op); | 405 | &key, /*key to search */ |
401 | get_op->get = GNUNET_DHT_get_start(dhts[j], | 406 | 4U, /* replication level */ |
402 | GNUNET_BLOCK_TYPE_TEST, /* type */ | 407 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, |
403 | &key, /*key to search */ | 408 | NULL, /* xquery */ |
404 | 4U, /* replication level */ | 409 | 0, /* xquery bits */ |
405 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | 410 | &dht_get_handler, get_op); |
406 | NULL, /* xquery */ | ||
407 | 0, /* xquery bits */ | ||
408 | &dht_get_handler, get_op); | ||
409 | } | ||
410 | } | 411 | } |
411 | timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, | 412 | } |
412 | &timeout_task_cb, | 413 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
413 | NULL); | 414 | &timeout_task_cb, |
414 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, | 415 | NULL); |
415 | ctx); | 416 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
417 | ctx); | ||
416 | } | 418 | } |
417 | 419 | ||
418 | 420 | ||
@@ -420,12 +422,12 @@ run(void *cls, | |||
420 | * Main: start test | 422 | * Main: start test |
421 | */ | 423 | */ |
422 | int | 424 | int |
423 | main(int xargc, char *xargv[]) | 425 | main (int xargc, char *xargv[]) |
424 | { | 426 | { |
425 | GNUNET_DHT_TEST_run("test-dht-monitor", | 427 | GNUNET_DHT_TEST_run ("test-dht-monitor", |
426 | "test_dht_monitor.conf", | 428 | "test_dht_monitor.conf", |
427 | NUM_PEERS, | 429 | NUM_PEERS, |
428 | &run, NULL); | 430 | &run, NULL); |
429 | return ok; | 431 | return ok; |
430 | } | 432 | } |
431 | 433 | ||
diff --git a/src/dht/test_dht_topo.c b/src/dht/test_dht_topo.c index 32d99152d..d92095cc6 100644 --- a/src/dht/test_dht_topo.c +++ b/src/dht/test_dht_topo.c | |||
@@ -32,18 +32,21 @@ | |||
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, \ |
36 | 120) | ||
36 | 37 | ||
37 | /** | 38 | /** |
38 | * How frequently do we execute the PUTs? | 39 | * How frequently do we execute the PUTs? |
39 | */ | 40 | */ |
40 | #define PUT_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) | 41 | #define PUT_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ |
42 | 5) | ||
41 | 43 | ||
42 | 44 | ||
43 | /** | 45 | /** |
44 | * Information we keep for each GET operation. | 46 | * Information we keep for each GET operation. |
45 | */ | 47 | */ |
46 | struct GetOperation { | 48 | struct GetOperation |
49 | { | ||
47 | /** | 50 | /** |
48 | * DLL. | 51 | * DLL. |
49 | */ | 52 | */ |
@@ -105,7 +108,8 @@ static unsigned int NUM_PEERS; | |||
105 | /** | 108 | /** |
106 | * Statistics we print out. | 109 | * Statistics we print out. |
107 | */ | 110 | */ |
108 | static struct { | 111 | static struct |
112 | { | ||
109 | const char *subsystem; | 113 | const char *subsystem; |
110 | const char *name; | 114 | const char *name; |
111 | unsigned long long total; | 115 | unsigned long long total; |
@@ -150,34 +154,34 @@ static struct { | |||
150 | 154 | ||
151 | 155 | ||
152 | static struct GNUNET_DHT_TEST_Context * | 156 | static struct GNUNET_DHT_TEST_Context * |
153 | stop_ops() | 157 | stop_ops () |
154 | { | 158 | { |
155 | struct GetOperation *get_op; | 159 | struct GetOperation *get_op; |
156 | struct GNUNET_DHT_TEST_Context *ctx = NULL; | 160 | struct GNUNET_DHT_TEST_Context *ctx = NULL; |
157 | 161 | ||
158 | if (NULL != timeout_task) | 162 | if (NULL != timeout_task) |
159 | { | 163 | { |
160 | ctx = GNUNET_SCHEDULER_cancel(timeout_task); | 164 | ctx = GNUNET_SCHEDULER_cancel (timeout_task); |
161 | timeout_task = NULL; | 165 | timeout_task = NULL; |
162 | } | 166 | } |
163 | if (NULL != put_task) | 167 | if (NULL != put_task) |
164 | { | 168 | { |
165 | GNUNET_SCHEDULER_cancel(put_task); | 169 | GNUNET_SCHEDULER_cancel (put_task); |
166 | put_task = NULL; | 170 | put_task = NULL; |
167 | } | 171 | } |
168 | if (NULL != get_task) | 172 | if (NULL != get_task) |
169 | { | 173 | { |
170 | GNUNET_SCHEDULER_cancel(get_task); | 174 | GNUNET_SCHEDULER_cancel (get_task); |
171 | get_task = NULL; | 175 | get_task = NULL; |
172 | } | 176 | } |
173 | while (NULL != (get_op = get_tail)) | 177 | while (NULL != (get_op = get_tail)) |
174 | { | 178 | { |
175 | GNUNET_DHT_get_stop(get_op->get); | 179 | GNUNET_DHT_get_stop (get_op->get); |
176 | GNUNET_CONTAINER_DLL_remove(get_head, | 180 | GNUNET_CONTAINER_DLL_remove (get_head, |
177 | get_tail, | 181 | get_tail, |
178 | get_op); | 182 | get_op); |
179 | GNUNET_free(get_op); | 183 | GNUNET_free (get_op); |
180 | } | 184 | } |
181 | return ctx; | 185 | return ctx; |
182 | } | 186 | } |
183 | 187 | ||
@@ -190,32 +194,32 @@ stop_ops() | |||
190 | * @param emsg error message on failure | 194 | * @param emsg error message on failure |
191 | */ | 195 | */ |
192 | static void | 196 | static void |
193 | stats_finished(void *cls, | 197 | stats_finished (void *cls, |
194 | struct GNUNET_TESTBED_Operation *op, | 198 | struct GNUNET_TESTBED_Operation *op, |
195 | const char *emsg) | 199 | const char *emsg) |
196 | { | 200 | { |
197 | struct GNUNET_DHT_TEST_Context *ctx = cls; | 201 | struct GNUNET_DHT_TEST_Context *ctx = cls; |
198 | unsigned int i; | 202 | unsigned int i; |
199 | 203 | ||
200 | if (NULL != op) | 204 | if (NULL != op) |
201 | GNUNET_TESTBED_operation_done(op); | 205 | GNUNET_TESTBED_operation_done (op); |
202 | if (NULL != emsg) | 206 | if (NULL != emsg) |
203 | { | 207 | { |
204 | fprintf(stderr, | 208 | fprintf (stderr, |
205 | _("Gathering statistics failed: %s\n"), | 209 | _ ("Gathering statistics failed: %s\n"), |
206 | emsg); | 210 | emsg); |
207 | GNUNET_SCHEDULER_cancel(put_task); | 211 | GNUNET_SCHEDULER_cancel (put_task); |
208 | GNUNET_DHT_TEST_cleanup(ctx); | 212 | GNUNET_DHT_TEST_cleanup (ctx); |
209 | return; | 213 | return; |
210 | } | 214 | } |
211 | for (i = 0; NULL != stats[i].name; i++) | 215 | for (i = 0; NULL != stats[i].name; i++) |
212 | fprintf(stderr, | 216 | fprintf (stderr, |
213 | "%6s/%60s = %12llu\n", | 217 | "%6s/%60s = %12llu\n", |
214 | stats[i].subsystem, | 218 | stats[i].subsystem, |
215 | stats[i].name, | 219 | stats[i].name, |
216 | stats[i].total); | 220 | stats[i].total); |
217 | GNUNET_DHT_TEST_cleanup(ctx); | 221 | GNUNET_DHT_TEST_cleanup (ctx); |
218 | GNUNET_SCHEDULER_shutdown(); | 222 | GNUNET_SCHEDULER_shutdown (); |
219 | } | 223 | } |
220 | 224 | ||
221 | 225 | ||
@@ -231,20 +235,20 @@ stats_finished(void *cls, | |||
231 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration | 235 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration |
232 | */ | 236 | */ |
233 | static int | 237 | static int |
234 | handle_stats(void *cls, | 238 | handle_stats (void *cls, |
235 | const struct GNUNET_TESTBED_Peer *peer, | 239 | const struct GNUNET_TESTBED_Peer *peer, |
236 | const char *subsystem, | 240 | const char *subsystem, |
237 | const char *name, | 241 | const char *name, |
238 | uint64_t value, | 242 | uint64_t value, |
239 | int is_persistent) | 243 | int is_persistent) |
240 | { | 244 | { |
241 | unsigned int i; | 245 | unsigned int i; |
242 | 246 | ||
243 | for (i = 0; NULL != stats[i].name; i++) | 247 | for (i = 0; NULL != stats[i].name; i++) |
244 | if ((0 == strcasecmp(subsystem, | 248 | if ((0 == strcasecmp (subsystem, |
245 | stats[i].subsystem)) && | 249 | stats[i].subsystem)) && |
246 | (0 == strcasecmp(name, | 250 | (0 == strcasecmp (name, |
247 | stats[i].name))) | 251 | stats[i].name))) |
248 | stats[i].total += value; | 252 | stats[i].total += value; |
249 | return GNUNET_OK; | 253 | return GNUNET_OK; |
250 | } | 254 | } |
@@ -257,9 +261,9 @@ handle_stats(void *cls, | |||
257 | * @param cls the 'struct GNUNET_DHT_TestContext' | 261 | * @param cls the 'struct GNUNET_DHT_TestContext' |
258 | */ | 262 | */ |
259 | static void | 263 | static void |
260 | shutdown_task(void *cls) | 264 | shutdown_task (void *cls) |
261 | { | 265 | { |
262 | (void)stop_ops(); | 266 | (void) stop_ops (); |
263 | } | 267 | } |
264 | 268 | ||
265 | 269 | ||
@@ -270,12 +274,12 @@ shutdown_task(void *cls) | |||
270 | * @param cls the `struct GNUNET_DHT_TestContext` | 274 | * @param cls the `struct GNUNET_DHT_TestContext` |
271 | */ | 275 | */ |
272 | static void | 276 | static void |
273 | timeout_cb(void *cls) | 277 | timeout_cb (void *cls) |
274 | { | 278 | { |
275 | timeout_task = NULL; | 279 | timeout_task = NULL; |
276 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 280 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
277 | "Timeout\n"); | 281 | "Timeout\n"); |
278 | GNUNET_SCHEDULER_shutdown(); | 282 | GNUNET_SCHEDULER_shutdown (); |
279 | } | 283 | } |
280 | 284 | ||
281 | 285 | ||
@@ -295,75 +299,75 @@ timeout_cb(void *cls) | |||
295 | * @param data pointer to the result data | 299 | * @param data pointer to the result data |
296 | */ | 300 | */ |
297 | static void | 301 | static void |
298 | dht_get_handler(void *cls, | 302 | dht_get_handler (void *cls, |
299 | struct GNUNET_TIME_Absolute exp, | 303 | struct GNUNET_TIME_Absolute exp, |
300 | const struct GNUNET_HashCode *key, | 304 | const struct GNUNET_HashCode *key, |
301 | const struct GNUNET_PeerIdentity *get_path, | 305 | const struct GNUNET_PeerIdentity *get_path, |
302 | unsigned int get_path_length, | 306 | unsigned int get_path_length, |
303 | const struct GNUNET_PeerIdentity *put_path, | 307 | const struct GNUNET_PeerIdentity *put_path, |
304 | unsigned int put_path_length, | 308 | unsigned int put_path_length, |
305 | enum GNUNET_BLOCK_Type type, | 309 | enum GNUNET_BLOCK_Type type, |
306 | size_t size, | 310 | size_t size, |
307 | const void *data) | 311 | const void *data) |
308 | { | 312 | { |
309 | struct GetOperation *get_op = cls; | 313 | struct GetOperation *get_op = cls; |
310 | struct GNUNET_HashCode want; | 314 | struct GNUNET_HashCode want; |
311 | struct GNUNET_DHT_TEST_Context *ctx; | 315 | struct GNUNET_DHT_TEST_Context *ctx; |
312 | 316 | ||
313 | if (sizeof(struct GNUNET_HashCode) != size) | 317 | if (sizeof(struct GNUNET_HashCode) != size) |
314 | { | 318 | { |
315 | GNUNET_break(0); | 319 | GNUNET_break (0); |
316 | return; | 320 | return; |
317 | } | 321 | } |
318 | GNUNET_CRYPTO_hash(key, | 322 | GNUNET_CRYPTO_hash (key, |
319 | sizeof(*key), | 323 | sizeof(*key), |
320 | &want); | 324 | &want); |
321 | if (0 != memcmp(&want, | 325 | if (0 != memcmp (&want, |
322 | data, | 326 | data, |
323 | sizeof(want))) | 327 | sizeof(want))) |
324 | { | 328 | { |
325 | GNUNET_break(0); | 329 | GNUNET_break (0); |
326 | return; | 330 | return; |
327 | } | 331 | } |
328 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 332 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
329 | "Get successful\n"); | 333 | "Get successful\n"); |
330 | #if 0 | 334 | #if 0 |
331 | { | 335 | { |
332 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 336 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
333 | "PATH: (get %u, put %u)\n", | 337 | "PATH: (get %u, put %u)\n", |
334 | get_path_length, | 338 | get_path_length, |
335 | put_path_length); | 339 | put_path_length); |
336 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 340 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
337 | " LOCAL\n"); | 341 | " LOCAL\n"); |
338 | for (int i = get_path_length - 1; i >= 0; i--) | 342 | for (int i = get_path_length - 1; i >= 0; i--) |
339 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 343 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
340 | " %s\n", | 344 | " %s\n", |
341 | GNUNET_i2s(&get_path[i])); | 345 | GNUNET_i2s (&get_path[i])); |
342 | for (int i = put_path_length - 1; i >= 0; i--) | 346 | for (int i = put_path_length - 1; i >= 0; i--) |
343 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 347 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
344 | " %s\n", | 348 | " %s\n", |
345 | GNUNET_i2s(&put_path[i])); | 349 | GNUNET_i2s (&put_path[i])); |
346 | } | 350 | } |
347 | #endif | 351 | #endif |
348 | GNUNET_DHT_get_stop(get_op->get); | 352 | GNUNET_DHT_get_stop (get_op->get); |
349 | GNUNET_CONTAINER_DLL_remove(get_head, | 353 | GNUNET_CONTAINER_DLL_remove (get_head, |
350 | get_tail, | 354 | get_tail, |
351 | get_op); | 355 | get_op); |
352 | GNUNET_free(get_op); | 356 | GNUNET_free (get_op); |
353 | if (NULL != get_head) | 357 | if (NULL != get_head) |
354 | return; | 358 | return; |
355 | /* all DHT GET operations successful; get stats! */ | 359 | /* all DHT GET operations successful; get stats! */ |
356 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 360 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
357 | "All DHT operations successful. Obtaining stats!\n"); | 361 | "All DHT operations successful. Obtaining stats!\n"); |
358 | ok = 0; | 362 | ok = 0; |
359 | ctx = stop_ops(); | 363 | ctx = stop_ops (); |
360 | GNUNET_assert(NULL != ctx); | 364 | GNUNET_assert (NULL != ctx); |
361 | (void)GNUNET_TESTBED_get_statistics(NUM_PEERS, | 365 | (void) GNUNET_TESTBED_get_statistics (NUM_PEERS, |
362 | my_peers, | 366 | my_peers, |
363 | NULL, NULL, | 367 | NULL, NULL, |
364 | &handle_stats, | 368 | &handle_stats, |
365 | &stats_finished, | 369 | &stats_finished, |
366 | ctx); | 370 | ctx); |
367 | } | 371 | } |
368 | 372 | ||
369 | 373 | ||
@@ -374,38 +378,38 @@ dht_get_handler(void *cls, | |||
374 | * @param tc Task context | 378 | * @param tc Task context |
375 | */ | 379 | */ |
376 | static void | 380 | static void |
377 | do_puts(void *cls) | 381 | do_puts (void *cls) |
378 | { | 382 | { |
379 | struct GNUNET_DHT_Handle **hs = cls; | 383 | struct GNUNET_DHT_Handle **hs = cls; |
380 | struct GNUNET_HashCode key; | 384 | struct GNUNET_HashCode key; |
381 | struct GNUNET_HashCode value; | 385 | struct GNUNET_HashCode value; |
382 | 386 | ||
383 | put_task = NULL; | 387 | put_task = NULL; |
384 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 388 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
385 | "Putting values into DHT\n"); | 389 | "Putting values into DHT\n"); |
386 | for (unsigned int i = 0; i < NUM_PEERS; i++) | 390 | for (unsigned int i = 0; i < NUM_PEERS; i++) |
387 | { | 391 | { |
388 | GNUNET_CRYPTO_hash(&i, | 392 | GNUNET_CRYPTO_hash (&i, |
389 | sizeof(i), | 393 | sizeof(i), |
390 | &key); | 394 | &key); |
391 | GNUNET_CRYPTO_hash(&key, | 395 | GNUNET_CRYPTO_hash (&key, |
392 | sizeof(key), | 396 | sizeof(key), |
393 | &value); | 397 | &value); |
394 | GNUNET_DHT_put(hs[i], | 398 | GNUNET_DHT_put (hs[i], |
395 | &key, | 399 | &key, |
396 | 10U, | 400 | 10U, |
397 | GNUNET_DHT_RO_RECORD_ROUTE | | 401 | GNUNET_DHT_RO_RECORD_ROUTE |
398 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | 402 | | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, |
399 | GNUNET_BLOCK_TYPE_TEST, | 403 | GNUNET_BLOCK_TYPE_TEST, |
400 | sizeof(value), | 404 | sizeof(value), |
401 | &value, | 405 | &value, |
402 | GNUNET_TIME_UNIT_FOREVER_ABS, | 406 | GNUNET_TIME_UNIT_FOREVER_ABS, |
403 | NULL, | 407 | NULL, |
404 | NULL); | 408 | NULL); |
405 | } | 409 | } |
406 | put_task = GNUNET_SCHEDULER_add_delayed(PUT_FREQUENCY, | 410 | put_task = GNUNET_SCHEDULER_add_delayed (PUT_FREQUENCY, |
407 | &do_puts, | 411 | &do_puts, |
408 | hs); | 412 | hs); |
409 | } | 413 | } |
410 | 414 | ||
411 | 415 | ||
@@ -413,7 +417,7 @@ do_puts(void *cls) | |||
413 | * Start GET operations. | 417 | * Start GET operations. |
414 | */ | 418 | */ |
415 | static void | 419 | static void |
416 | start_get(void *cls) | 420 | start_get (void *cls) |
417 | { | 421 | { |
418 | struct GNUNET_DHT_Handle **dhts = cls; | 422 | struct GNUNET_DHT_Handle **dhts = cls; |
419 | unsigned int i; | 423 | unsigned int i; |
@@ -423,25 +427,26 @@ start_get(void *cls) | |||
423 | 427 | ||
424 | get_task = NULL; | 428 | get_task = NULL; |
425 | for (i = 0; i < NUM_PEERS; i++) | 429 | for (i = 0; i < NUM_PEERS; i++) |
430 | { | ||
431 | GNUNET_CRYPTO_hash (&i, sizeof(i), &key); | ||
432 | for (j = 0; j < NUM_PEERS; j++) | ||
426 | { | 433 | { |
427 | GNUNET_CRYPTO_hash(&i, sizeof(i), &key); | 434 | get_op = GNUNET_new (struct GetOperation); |
428 | for (j = 0; j < NUM_PEERS; j++) | 435 | GNUNET_CONTAINER_DLL_insert (get_head, |
429 | { | 436 | get_tail, |
430 | get_op = GNUNET_new(struct GetOperation); | 437 | get_op); |
431 | GNUNET_CONTAINER_DLL_insert(get_head, | 438 | get_op->get = GNUNET_DHT_get_start (dhts[j], |
432 | get_tail, | 439 | GNUNET_BLOCK_TYPE_TEST, /* type */ |
433 | get_op); | 440 | &key, /*key to search */ |
434 | get_op->get = GNUNET_DHT_get_start(dhts[j], | 441 | 4U, /* replication level */ |
435 | GNUNET_BLOCK_TYPE_TEST, /* type */ | 442 | GNUNET_DHT_RO_RECORD_ROUTE |
436 | &key, /*key to search */ | 443 | | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, |
437 | 4U, /* replication level */ | 444 | NULL, /* xquery */ |
438 | GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | 445 | 0, /* xquery bits */ |
439 | NULL, /* xquery */ | 446 | &dht_get_handler, |
440 | 0, /* xquery bits */ | 447 | get_op); |
441 | &dht_get_handler, | ||
442 | get_op); | ||
443 | } | ||
444 | } | 448 | } |
449 | } | ||
445 | } | 450 | } |
446 | 451 | ||
447 | 452 | ||
@@ -455,26 +460,26 @@ start_get(void *cls) | |||
455 | * @param dhts handle to each of the DHTs of the peers | 460 | * @param dhts handle to each of the DHTs of the peers |
456 | */ | 461 | */ |
457 | static void | 462 | static void |
458 | run(void *cls, | 463 | run (void *cls, |
459 | struct GNUNET_DHT_TEST_Context *ctx, | 464 | struct GNUNET_DHT_TEST_Context *ctx, |
460 | unsigned int num_peers, | 465 | unsigned int num_peers, |
461 | struct GNUNET_TESTBED_Peer **peers, | 466 | struct GNUNET_TESTBED_Peer **peers, |
462 | struct GNUNET_DHT_Handle **dhts) | 467 | struct GNUNET_DHT_Handle **dhts) |
463 | { | 468 | { |
464 | GNUNET_assert(NUM_PEERS == num_peers); | 469 | GNUNET_assert (NUM_PEERS == num_peers); |
465 | my_peers = peers; | 470 | my_peers = peers; |
466 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 471 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
467 | "Peers setup, starting test\n"); | 472 | "Peers setup, starting test\n"); |
468 | put_task = GNUNET_SCHEDULER_add_now(&do_puts, | 473 | put_task = GNUNET_SCHEDULER_add_now (&do_puts, |
469 | dhts); | 474 | dhts); |
470 | get_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, | 475 | get_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
471 | &start_get, | 476 | &start_get, |
472 | dhts); | 477 | dhts); |
473 | timeout_task = GNUNET_SCHEDULER_add_delayed(GET_TIMEOUT, | 478 | timeout_task = GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, |
474 | &timeout_cb, | 479 | &timeout_cb, |
475 | ctx); | 480 | ctx); |
476 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, | 481 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
477 | ctx); | 482 | ctx); |
478 | } | 483 | } |
479 | 484 | ||
480 | 485 | ||
@@ -482,44 +487,44 @@ run(void *cls, | |||
482 | * Main: start test | 487 | * Main: start test |
483 | */ | 488 | */ |
484 | int | 489 | int |
485 | main(int xargc, char *xargv[]) | 490 | main (int xargc, char *xargv[]) |
486 | { | 491 | { |
487 | const char *cfg_filename; | 492 | const char *cfg_filename; |
488 | const char *test_name; | 493 | const char *test_name; |
489 | 494 | ||
490 | if (NULL != strstr(xargv[0], "test_dht_2dtorus")) | 495 | if (NULL != strstr (xargv[0], "test_dht_2dtorus")) |
491 | { | 496 | { |
492 | cfg_filename = "test_dht_2dtorus.conf"; | 497 | cfg_filename = "test_dht_2dtorus.conf"; |
493 | test_name = "test-dht-2dtorus"; | 498 | test_name = "test-dht-2dtorus"; |
494 | NUM_PEERS = 16; | 499 | NUM_PEERS = 16; |
495 | } | 500 | } |
496 | else if (NULL != strstr(xargv[0], "test_dht_line")) | 501 | else if (NULL != strstr (xargv[0], "test_dht_line")) |
497 | { | 502 | { |
498 | cfg_filename = "test_dht_line.conf"; | 503 | cfg_filename = "test_dht_line.conf"; |
499 | test_name = "test-dht-line"; | 504 | test_name = "test-dht-line"; |
500 | NUM_PEERS = 5; | 505 | NUM_PEERS = 5; |
501 | } | 506 | } |
502 | else if (NULL != strstr(xargv[0], "test_dht_twopeer")) | 507 | else if (NULL != strstr (xargv[0], "test_dht_twopeer")) |
503 | { | 508 | { |
504 | cfg_filename = "test_dht_line.conf"; | 509 | cfg_filename = "test_dht_line.conf"; |
505 | test_name = "test-dht-twopeer"; | 510 | test_name = "test-dht-twopeer"; |
506 | NUM_PEERS = 2; | 511 | NUM_PEERS = 2; |
507 | } | 512 | } |
508 | else if (NULL != strstr(xargv[0], "test_dht_multipeer")) | 513 | else if (NULL != strstr (xargv[0], "test_dht_multipeer")) |
509 | { | 514 | { |
510 | cfg_filename = "test_dht_multipeer.conf"; | 515 | cfg_filename = "test_dht_multipeer.conf"; |
511 | test_name = "test-dht-multipeer"; | 516 | test_name = "test-dht-multipeer"; |
512 | NUM_PEERS = 10; | 517 | NUM_PEERS = 10; |
513 | } | 518 | } |
514 | else | 519 | else |
515 | { | 520 | { |
516 | GNUNET_break(0); | 521 | GNUNET_break (0); |
517 | return 1; | 522 | return 1; |
518 | } | 523 | } |
519 | GNUNET_DHT_TEST_run(test_name, | 524 | GNUNET_DHT_TEST_run (test_name, |
520 | cfg_filename, | 525 | cfg_filename, |
521 | NUM_PEERS, | 526 | NUM_PEERS, |
522 | &run, NULL); | 527 | &run, NULL); |
523 | return ok; | 528 | return ok; |
524 | } | 529 | } |
525 | 530 | ||