aboutsummaryrefslogtreecommitdiff
path: root/src/gns/gnunet-service-gns.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-03-02 09:34:03 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-03-02 09:34:03 +0000
commit01831eef286a4bb435b56ef7a1f5992c29f808f7 (patch)
tree97a66d65f310c0f5db5601016368755487d13eea /src/gns/gnunet-service-gns.c
parentcf506ca2ddfc0d83c99680055cbe4ed20a48a646 (diff)
downloadgnunet-01831eef286a4bb435b56ef7a1f5992c29f808f7.tar.gz
gnunet-01831eef286a4bb435b56ef7a1f5992c29f808f7.zip
-add dht timeout
Diffstat (limited to 'src/gns/gnunet-service-gns.c')
-rw-r--r--src/gns/gnunet-service-gns.c42
1 files changed, 38 insertions, 4 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index 8af37d489..c4593a8d2 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -40,6 +40,7 @@
40#include "gns.h" 40#include "gns.h"
41 41
42#define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) 42#define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
43#define DHT_LOOKUP_TIMEOUT DHT_OPERATION_TIMEOUT
43#define DHT_GNS_REPLICATION_LEVEL 5 44#define DHT_GNS_REPLICATION_LEVEL 5
44 45
45/* Ignore for now not used anyway and probably never will */ 46/* Ignore for now not used anyway and probably never will */
@@ -82,6 +83,9 @@ struct GNUNET_GNS_ResolverHandle
82 /* a handle for dht lookups. should be NULL if no lookups are in progress */ 83 /* a handle for dht lookups. should be NULL if no lookups are in progress */
83 struct GNUNET_DHT_GetHandle *get_handle; 84 struct GNUNET_DHT_GetHandle *get_handle;
84 85
86 /* timeout task for dht lookups */
87 GNUNET_SCHEDULER_TaskIdentifier dht_timeout_task;
88
85}; 89};
86 90
87 91
@@ -190,6 +194,24 @@ on_namestore_record_put_result(void *cls,
190} 194}
191 195
192/** 196/**
197 * Handle timeout for DHT requests
198 *
199 * @param cls the request handle as closure
200 * @param tc the task context
201 */
202static void
203dht_lookup_timeout(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
204{
205 struct GNUNET_GNS_ResolverHandle *rh = cls;
206
207 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
208 "dht lookup for query %s (type=%d) timed out.\n",
209 rh->name, rh->query->type);
210
211 GNUNET_DHT_get_stop (rh->get_handle);
212}
213
214/**
193 * Function called when we get a result from the dht 215 * Function called when we get a result from the dht
194 * for our query 216 * for our query
195 * 217 *
@@ -232,7 +254,9 @@ process_authority_dht_result(void* cls,
232 rh = (struct GNUNET_GNS_ResolverHandle *)cls; 254 rh = (struct GNUNET_GNS_ResolverHandle *)cls;
233 nrb = (struct GNSNameRecordBlock*)data; 255 nrb = (struct GNSNameRecordBlock*)data;
234 256
257 /* stop dht lookup and timeout task */
235 GNUNET_DHT_get_stop (rh->get_handle); 258 GNUNET_DHT_get_stop (rh->get_handle);
259 GNUNET_SCHEDULER_cancel(rh->dht_timeout_task);
236 260
237 rh->get_handle = NULL; 261 rh->get_handle = NULL;
238 num_records = ntohl(nrb->rd_count); 262 num_records = ntohl(nrb->rd_count);
@@ -328,7 +352,9 @@ resolve_authority_dht(struct GNUNET_GNS_ResolverHandle *rh)
328 &name_hash); 352 &name_hash);
329 GNUNET_CRYPTO_hash_xor(&name_hash, &rh->authority, &lookup_key); 353 GNUNET_CRYPTO_hash_xor(&name_hash, &rh->authority, &lookup_key);
330 354
331 355 rh->dht_timeout_task = GNUNET_SCHEDULER_add_delayed (DHT_LOOKUP_TIMEOUT,
356 &dht_lookup_timeout, rh);
357
332 xquery = htonl(GNUNET_GNS_RECORD_PKEY); 358 xquery = htonl(GNUNET_GNS_RECORD_PKEY);
333 //FIXME how long to wait for results? 359 //FIXME how long to wait for results?
334 rh->get_handle = GNUNET_DHT_get_start(dht_handle, 360 rh->get_handle = GNUNET_DHT_get_start(dht_handle,
@@ -388,8 +414,10 @@ process_name_dht_result(void* cls,
388 414
389 rh = (struct GNUNET_GNS_ResolverHandle *)cls; 415 rh = (struct GNUNET_GNS_ResolverHandle *)cls;
390 nrb = (struct GNSNameRecordBlock*)data; 416 nrb = (struct GNSNameRecordBlock*)data;
391 417
418 /* stop lookup and timeout task */
392 GNUNET_DHT_get_stop (rh->get_handle); 419 GNUNET_DHT_get_stop (rh->get_handle);
420 GNUNET_SCHEDULER_cancel(rh->dht_timeout_task);
393 421
394 rh->get_handle = NULL; 422 rh->get_handle = NULL;
395 name = (char*)&nrb[1]; 423 name = (char*)&nrb[1];
@@ -456,6 +484,9 @@ process_name_dht_result(void* cls,
456 484
457} 485}
458 486
487
488
489
459/** 490/**
460 * Start DHT lookup for a (name -> query->record_type) record in 491 * Start DHT lookup for a (name -> query->record_type) record in
461 * query->authority's zone 492 * query->authority's zone
@@ -479,10 +510,13 @@ resolve_name_dht(struct GNUNET_GNS_ResolverHandle *rh, const char* name)
479 "starting dht lookup for %s with key: %s\n", 510 "starting dht lookup for %s with key: %s\n",
480 name, (char*)&lookup_key_string); 511 name, (char*)&lookup_key_string);
481 512
513 rh->dht_timeout_task = GNUNET_SCHEDULER_add_delayed(DHT_LOOKUP_TIMEOUT,
514 &dht_lookup_timeout, rh);
515
482 xquery = htonl(rh->query->type); 516 xquery = htonl(rh->query->type);
483 //FIXME how long to wait for results? 517 //FIXME how long to wait for results?
484 rh->get_handle = GNUNET_DHT_get_start(dht_handle, 518 rh->get_handle = GNUNET_DHT_get_start(dht_handle,
485 DHT_OPERATION_TIMEOUT, 519 DHT_OPERATION_TIMEOUT,
486 GNUNET_BLOCK_TYPE_GNS_NAMERECORD, 520 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
487 &lookup_key, 521 &lookup_key,
488 DHT_GNS_REPLICATION_LEVEL, 522 DHT_GNS_REPLICATION_LEVEL,
@@ -1161,7 +1195,7 @@ put_gns_record(void *cls,
1161 (char*)nrb, 1195 (char*)nrb,
1162 expiration, 1196 expiration,
1163 DHT_OPERATION_TIMEOUT, 1197 DHT_OPERATION_TIMEOUT,
1164 &record_dht_put, //FIXME continuation needed? success check? yes ofc 1198 &record_dht_put,
1165 NULL); //cls for cont 1199 NULL); //cls for cont
1166 1200
1167 num_public_records++; 1201 num_public_records++;