summaryrefslogtreecommitdiff
path: root/src/gns/gns_api.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-02-16 20:05:40 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-02-16 20:05:40 +0000
commitf49e139a6fbcde654b2130e78665e48712713612 (patch)
tree7bfa44d2ade2420938cff9b8ca7c1be92265e00a /src/gns/gns_api.c
parent18805673bf25fb6924280a54754e240a1402f46f (diff)
downloadgnunet-f49e139a6fbcde654b2130e78665e48712713612.tar.gz
gnunet-f49e139a6fbcde654b2130e78665e48712713612.zip
- commit after up, ty!
Diffstat (limited to 'src/gns/gns_api.c')
-rw-r--r--src/gns/gns_api.c56
1 files changed, 47 insertions, 9 deletions
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c
index ed0b447a7..14c1220c9 100644
--- a/src/gns/gns_api.c
+++ b/src/gns/gns_api.c
@@ -231,6 +231,35 @@ try_connect (struct GNUNET_GNS_Handle *handle)
231} 231}
232 232
233/** 233/**
234 * Add the request corresponding to the given handle
235 * to the pending queue (if it is not already in there).
236 *
237 * @param cls the 'struct GNUNET_GNS_Handle*'
238 * @param key key for the request (not used)
239 * @param value the 'struct GNUNET_GNS_LookupHandle*'
240 * @return GNUNET_YES (always)
241 */
242static int
243add_request_to_pending (void *cls, const GNUNET_HashCode * key, void *value)
244{
245 struct GNUNET_GNS_Handle *handle = cls;
246 struct GNUNET_GNS_LookupHandle *rh = value;
247
248 if (GNUNET_NO == rh->message->in_pending_queue)
249 {
250#if DEBUG_DHT
251 LOG (GNUNET_ERROR_TYPE_DEBUG,
252 "Retransmitting request related to %s to GNS %p\n", GNUNET_h2s(key),
253 handle);
254#endif
255 GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail,
256 rh->message);
257 rh->message->in_pending_queue = GNUNET_YES;
258 }
259 return GNUNET_YES;
260}
261
262/**
234 * Try reconnecting to the GNS service. 263 * Try reconnecting to the GNS service.
235 * 264 *
236 * @param cls GNUNET_GNS_Handle 265 * @param cls GNUNET_GNS_Handle
@@ -349,10 +378,8 @@ transmit_pending (void *cls, size_t size, void *buf)
349 handle->th = NULL; 378 handle->th = NULL;
350 if (buf == NULL) 379 if (buf == NULL)
351 { 380 {
352#if DEBUG_GNS 381 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
353 LOG (GNUNET_ERROR_TYPE_DEBUG,
354 "Transmission to GNS service failed! Reconnecting!\n"); 382 "Transmission to GNS service failed! Reconnecting!\n");
355#endif
356 do_disconnect (handle); 383 do_disconnect (handle);
357 return 0; 384 return 0;
358 } 385 }
@@ -562,6 +589,7 @@ GNUNET_GNS_add_record (struct GNUNET_GNS_Handle *handle,
562 589
563/** 590/**
564 * Perform an asynchronous Lookup operation on the GNS. 591 * Perform an asynchronous Lookup operation on the GNS.
592 * TODO: Still not sure what we query for... "names" it is for now
565 * 593 *
566 * @param handle handle to the GNS service 594 * @param handle handle to the GNS service
567 * @param timeout how long to wait for transmission of this request to the service 595 * @param timeout how long to wait for transmission of this request to the service
@@ -572,18 +600,26 @@ GNUNET_GNS_add_record (struct GNUNET_GNS_Handle *handle,
572 */ 600 */
573struct GNUNET_GNS_LookupHandle * 601struct GNUNET_GNS_LookupHandle *
574GNUNET_GNS_lookup_start (struct GNUNET_GNS_Handle *handle, 602GNUNET_GNS_lookup_start (struct GNUNET_GNS_Handle *handle,
575 struct GNUNET_TIME_Relative timeout, 603 struct GNUNET_TIME_Relative timeout,
576 const char * name, 604 const char * name,
577 enum GNUNET_GNS_RecordType type, 605 enum GNUNET_GNS_RecordType type,
578 GNUNET_GNS_LookupIterator iter, 606 GNUNET_GNS_LookupIterator iter,
579 void *iter_cls) 607 void *iter_cls)
580{ 608{
581 /* IPC to look for local entries, start dht lookup, return lookup_handle */ 609 /* IPC to look for local entries, start dht lookup, return lookup_handle */
582 struct GNUNET_GNS_ClientLookupMessage *lookup_msg; 610 struct GNUNET_GNS_ClientLookupMessage *lookup_msg;
583 struct GNUNET_GNS_LookupHandle *lookup_handle; 611 struct GNUNET_GNS_LookupHandle *lookup_handle;
612 GNUNET_HashCode key;
584 size_t msize; 613 size_t msize;
585 struct PendingMessage *pending; 614 struct PendingMessage *pending;
586 615
616 if (NULL == name)
617 {
618 return NULL;
619 }
620
621 GNUNET_CRYPTO_hash (name, strlen(name), &key);
622
587 msize = sizeof (struct GNUNET_GNS_ClientLookupMessage) + strlen(name); 623 msize = sizeof (struct GNUNET_GNS_ClientLookupMessage) + strlen(name);
588#if DEBUG_GNS 624#if DEBUG_GNS
589 LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting lookup for %s in GNS %p\n", 625 LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting lookup for %s in GNS %p\n",
@@ -597,6 +633,7 @@ GNUNET_GNS_lookup_start (struct GNUNET_GNS_Handle *handle,
597 lookup_msg->header.size = htons (msize); 633 lookup_msg->header.size = htons (msize);
598 lookup_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_CLIENT_LOOKUP); 634 lookup_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_CLIENT_LOOKUP);
599 lookup_msg->namelen = strlen(name); 635 lookup_msg->namelen = strlen(name);
636 lookup_msg->key = key;
600 memcpy(&lookup_msg[1], name, strlen(name)); 637 memcpy(&lookup_msg[1], name, strlen(name));
601 handle->uid_gen++; 638 handle->uid_gen++;
602 lookup_msg->unique_id = handle->uid_gen; 639 lookup_msg->unique_id = handle->uid_gen;
@@ -608,7 +645,8 @@ GNUNET_GNS_lookup_start (struct GNUNET_GNS_Handle *handle,
608 lookup_handle->iter_cls = iter_cls; 645 lookup_handle->iter_cls = iter_cls;
609 lookup_handle->message = pending; 646 lookup_handle->message = pending;
610 lookup_handle->unique_id = lookup_msg->unique_id; 647 lookup_handle->unique_id = lookup_msg->unique_id;
611 GNUNET_CONTAINER_multihashmap_put (handle->active_requests, key, lookup_handle, 648 GNUNET_CONTAINER_multihashmap_put (handle->active_requests, &lookup_msg->key,
649 lookup_handle,
612 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 650 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
613 process_pending_messages (handle); 651 process_pending_messages (handle);
614 return lookup_handle; 652 return lookup_handle;