aboutsummaryrefslogtreecommitdiff
path: root/src/dht/dht_api.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-03-17 17:19:30 +0000
committerNathan S. Evans <evans@in.tum.de>2010-03-17 17:19:30 +0000
commita48e8f508403c9d8641a0c9eb47d88f98cb47f28 (patch)
tree4f4f5f09a6aa89c60ba1798d507e1cb0cab0a6b9 /src/dht/dht_api.c
parentb571e5a4ed7fb2ef6f203c540e82675cf38bfcf8 (diff)
downloadgnunet-a48e8f508403c9d8641a0c9eb47d88f98cb47f28.tar.gz
gnunet-a48e8f508403c9d8641a0c9eb47d88f98cb47f28.zip
beginning of changes
Diffstat (limited to 'src/dht/dht_api.c')
-rw-r--r--src/dht/dht_api.c58
1 files changed, 40 insertions, 18 deletions
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c
index db25379fa..a55508b07 100644
--- a/src/dht/dht_api.c
+++ b/src/dht/dht_api.c
@@ -135,11 +135,14 @@ void service_message_handler (void *cls,
135 * 135 *
136 * @param cfg configuration to use 136 * @param cfg configuration to use
137 * @param sched scheduler to use 137 * @param sched scheduler to use
138 * @param ht_len size of the internal hash table to use for
139 * processing multiple GET/FIND requests in parallel
138 * @return NULL on error 140 * @return NULL on error
139 */ 141 */
140struct GNUNET_DHT_Handle * 142struct GNUNET_DHT_Handle *
141GNUNET_DHT_connect (struct GNUNET_SCHEDULER_Handle *sched, 143GNUNET_DHT_connect (struct GNUNET_SCHEDULER_Handle *sched,
142 const struct GNUNET_CONFIGURATION_Handle *cfg) 144 const struct GNUNET_CONFIGURATION_Handle *cfg,
145 unsigned int ht_len)
143{ 146{
144 struct GNUNET_DHT_Handle *handle; 147 struct GNUNET_DHT_Handle *handle;
145 148
@@ -233,6 +236,11 @@ struct GNUNET_DHT_GetHandle
233 * Closure for the iterator callback 236 * Closure for the iterator callback
234 */ 237 */
235 void *iter_cls; 238 void *iter_cls;
239
240 /**
241 * Main handle to this DHT api
242 */
243 struct GNUNET_DHT_Handle *dht_handle;
236}; 244};
237 245
238/** 246/**
@@ -303,7 +311,6 @@ static size_t
303transmit_pending (void *cls, size_t size, void *buf) 311transmit_pending (void *cls, size_t size, void *buf)
304{ 312{
305 struct GNUNET_DHT_Handle *handle = cls; 313 struct GNUNET_DHT_Handle *handle = cls;
306 size_t ret;
307 size_t tsize; 314 size_t tsize;
308 315
309 if (buf == NULL) 316 if (buf == NULL)
@@ -318,7 +325,6 @@ transmit_pending (void *cls, size_t size, void *buf)
318 } 325 }
319 326
320 handle->th = NULL; 327 handle->th = NULL;
321 ret = 0;
322 328
323 if (handle->current != NULL) 329 if (handle->current != NULL)
324 { 330 {
@@ -330,14 +336,15 @@ transmit_pending (void *cls, size_t size, void *buf)
330 "`%s': Sending message size %d\n", "DHT API", tsize); 336 "`%s': Sending message size %d\n", "DHT API", tsize);
331#endif 337#endif
332 memcpy(buf, handle->current->msg, tsize); 338 memcpy(buf, handle->current->msg, tsize);
339 return tsize;
333 } 340 }
334 else 341 else
335 { 342 {
336 return ret; 343 return 0;
337 } 344 }
338 } 345 }
339 346 /* Have no pending request */
340 return ret; 347 return 0;
341} 348}
342 349
343 350
@@ -483,6 +490,10 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle,
483 get_handle->iter = iter; 490 get_handle->iter = iter;
484 get_handle->iter_cls = iter_cls; 491 get_handle->iter_cls = iter_cls;
485 492
493#if DEBUG_DHT_API
494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
495 "`%s': Inserting pending get request with key %s\n", "DHT API", GNUNET_h2s(key));
496#endif
486 GNUNET_CONTAINER_multihashmap_put(handle->outstanding_get_requests, key, get_handle, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 497 GNUNET_CONTAINER_multihashmap_put(handle->outstanding_get_requests, key, get_handle, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
487 498
488 get_msg = GNUNET_malloc(sizeof(struct GNUNET_DHT_GetMessage)); 499 get_msg = GNUNET_malloc(sizeof(struct GNUNET_DHT_GetMessage));
@@ -503,9 +514,10 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle,
503 * @param record GET operation to stop. 514 * @param record GET operation to stop.
504 */ 515 */
505void 516void
506GNUNET_DHT_get_stop (struct GNUNET_DHT_Handle *handle, struct GNUNET_DHT_GetHandle *get_handle) 517GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle)
507{ 518{
508 struct GNUNET_DHT_GetMessage *get_msg; 519 struct GNUNET_DHT_GetMessage *get_msg;
520 struct GNUNET_DHT_Handle *handle;
509 521
510 if (handle->do_destroy == GNUNET_NO) 522 if (handle->do_destroy == GNUNET_NO)
511 { 523 {
@@ -517,7 +529,10 @@ GNUNET_DHT_get_stop (struct GNUNET_DHT_Handle *handle, struct GNUNET_DHT_GetHand
517 529
518 add_pending(handle, &get_msg->header); 530 add_pending(handle, &get_msg->header);
519 } 531 }
520 532#if DEBUG_DHT_API
533 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
534 "`%s': Removing pending get request with key %s\n", "DHT API", GNUNET_h2s(&get_handle->key));
535#endif
521 GNUNET_assert(GNUNET_CONTAINER_multihashmap_remove(handle->outstanding_get_requests, &get_handle->key, get_handle) == GNUNET_YES); 536 GNUNET_assert(GNUNET_CONTAINER_multihashmap_remove(handle->outstanding_get_requests, &get_handle->key, get_handle) == GNUNET_YES);
522 GNUNET_free(get_handle); 537 GNUNET_free(get_handle);
523} 538}
@@ -539,14 +554,16 @@ GNUNET_DHT_get_stop (struct GNUNET_DHT_Handle *handle, struct GNUNET_DHT_GetHand
539 * 554 *
540 * @return GNUNET_YES if put message is queued for transmission 555 * @return GNUNET_YES if put message is queued for transmission
541 */ 556 */
542int GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, 557void
543 const GNUNET_HashCode * key, 558GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
544 uint32_t type, 559 const GNUNET_HashCode * key,
545 uint32_t size, 560 uint32_t type,
546 const char *data, 561 uint32_t size,
547 struct GNUNET_TIME_Relative exp, 562 const char *data,
548 GNUNET_SCHEDULER_Task cont, 563 struct GNUNET_TIME_Absolute exp,
549 void *cont_cls) 564 struct GNUNET_TIME_Relative timeout,
565 GNUNET_SCHEDULER_Task cont,
566 void *cont_cls)
550{ 567{
551 struct GNUNET_DHT_PutMessage *put_msg; 568 struct GNUNET_DHT_PutMessage *put_msg;
552 struct GNUNET_DHT_PutHandle *put_handle; 569 struct GNUNET_DHT_PutHandle *put_handle;
@@ -560,13 +577,18 @@ int GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
560 * A put has been previously queued, but not yet sent. 577 * A put has been previously queued, but not yet sent.
561 * FIXME: change the continuation function and callback or something? 578 * FIXME: change the continuation function and callback or something?
562 */ 579 */
563 return GNUNET_NO; 580 return;
564 } 581 }
565 582
566 put_handle = GNUNET_malloc(sizeof(struct GNUNET_DHT_PutHandle)); 583 put_handle = GNUNET_malloc(sizeof(struct GNUNET_DHT_PutHandle));
567 put_handle->type = type; 584 put_handle->type = type;
568 memcpy(&put_handle->key, key, sizeof(GNUNET_HashCode)); 585 memcpy(&put_handle->key, key, sizeof(GNUNET_HashCode));
569 586
587#if DEBUG_DHT_API
588 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
589 "`%s': Inserting pending put request with key %s\n", "DHT API", GNUNET_h2s(key));
590#endif
591
570 GNUNET_CONTAINER_multihashmap_put(handle->outstanding_put_requests, key, put_handle, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 592 GNUNET_CONTAINER_multihashmap_put(handle->outstanding_put_requests, key, put_handle, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
571 593
572 msize = sizeof(struct GNUNET_DHT_PutMessage) + size; 594 msize = sizeof(struct GNUNET_DHT_PutMessage) + size;
@@ -579,5 +601,5 @@ int GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
579 601
580 add_pending(handle, &put_msg->header); 602 add_pending(handle, &put_msg->header);
581 603
582 return GNUNET_YES; 604 return;
583} 605}