aboutsummaryrefslogtreecommitdiff
path: root/src/dht/dht_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht/dht_api.c')
-rw-r--r--src/dht/dht_api.c919
1 files changed, 462 insertions, 457 deletions
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 */
43struct GNUNET_DHT_PutHandle { 43struct 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 */
78struct GNUNET_DHT_GetHandle { 79struct 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 */
147struct GNUNET_DHT_MonitorHandle { 149struct 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 */
198struct GNUNET_DHT_Handle { 201struct 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 */
259static int 263static int
260try_connect(struct GNUNET_DHT_Handle *h); 264try_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 */
268static void 272static void
269send_get(struct GNUNET_DHT_GetHandle *gh) 273send_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 */
300static void 304static void
301send_get_known_results(struct GNUNET_DHT_GetHandle *gh, 305send_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 */
343static int 347static int
344add_get_request_to_pending(void *cls, 348add_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 */
366static void 370static void
367send_monitor_start(struct GNUNET_DHT_MonitorHandle *mh) 371send_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 */
394static void 398static void
395try_reconnect(void *cls) 399try_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 */
428static void 432static void
429do_disconnect(struct GNUNET_DHT_Handle *h) 433do_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 */
469static void 473static void
470mq_error_handler(void *cls, 474mq_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 */
487static int 491static int
488check_monitor_get(void *cls, 492check_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 */
510static void 514static void
511handle_monitor_get(void *cls, 515handle_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 */
547static int 551static int
548check_monitor_get_resp(void *cls, 552check_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 */
571static void 575static void
572handle_monitor_get_resp(void *cls, 576handle_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 */
615static int 620static int
616check_monitor_put(void *cls, 621check_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 */
639static void 644static void
640handle_monitor_put(void *cls, 645handle_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 */
683static int 688static int
684check_client_result(void *cls, 689check_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 */
715static int 720static int
716process_client_result(void *cls, 721process_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 */
796static void 801static void
797handle_client_result(void *cls, 802handle_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 */
814static void 819static void
815handle_put_cont(void *cls) 820handle_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 */
836static int 841static int
837try_connect(struct GNUNET_DHT_Handle *h) 842try_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 */
884struct GNUNET_DHT_Handle * 889struct GNUNET_DHT_Handle *
885GNUNET_DHT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, 890GNUNET_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 */
912void 917void
913GNUNET_DHT_disconnect(struct GNUNET_DHT_Handle *handle) 918GNUNET_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 */
960struct GNUNET_DHT_PutHandle * 965struct GNUNET_DHT_PutHandle *
961GNUNET_DHT_put(struct GNUNET_DHT_Handle *handle, 966GNUNET_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 */
1029void 1034void
1030GNUNET_DHT_put_cancel(struct GNUNET_DHT_PutHandle *ph) 1035GNUNET_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 */
1061struct GNUNET_DHT_GetHandle * 1066struct GNUNET_DHT_GetHandle *
1062GNUNET_DHT_get_start(struct GNUNET_DHT_Handle *handle, 1067GNUNET_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 */
1120void 1125void
1121GNUNET_DHT_get_filter_known_results(struct GNUNET_DHT_GetHandle *get_handle, 1126GNUNET_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 */
1149void 1154void
1150GNUNET_DHT_get_stop(struct GNUNET_DHT_GetHandle *get_handle) 1155GNUNET_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 */
1194struct GNUNET_DHT_MonitorHandle * 1199struct GNUNET_DHT_MonitorHandle *
1195GNUNET_DHT_monitor_start(struct GNUNET_DHT_Handle *handle, 1200GNUNET_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 */
1233void 1238void
1234GNUNET_DHT_monitor_stop(struct GNUNET_DHT_MonitorHandle *mh) 1239GNUNET_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