summaryrefslogtreecommitdiff
path: root/src/gns/gnunet-service-gns.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-09-18 13:29:39 +0000
committerChristian Grothoff <christian@grothoff.org>2012-09-18 13:29:39 +0000
commita0b1e4ae909d99bacac9ecaa52449d6c940d5947 (patch)
treebb538c35d95c456f46d8008cbb4ad437ebb57f0b /src/gns/gnunet-service-gns.c
parentdd663a8d291aa5cd0a1235856ba60b71c4c3d344 (diff)
downloadgnunet-a0b1e4ae909d99bacac9ecaa52449d6c940d5947.tar.gz
gnunet-a0b1e4ae909d99bacac9ecaa52449d6c940d5947.zip
-code review, breaking build a bit
Diffstat (limited to 'src/gns/gnunet-service-gns.c')
-rw-r--r--src/gns/gnunet-service-gns.c204
1 files changed, 83 insertions, 121 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index 4194a1658..d3f7ffabf 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -181,6 +181,9 @@ static unsigned long long num_public_records;
181 */ 181 */
182static unsigned long long last_num_public_records; 182static unsigned long long last_num_public_records;
183 183
184/**
185 * FIXME!
186 */
184static struct GNUNET_TIME_Relative zone_iteration_interval; 187static struct GNUNET_TIME_Relative zone_iteration_interval;
185 188
186/* dht update interval FIXME define? */ 189/* dht update interval FIXME define? */
@@ -213,30 +216,6 @@ static struct ClientShortenHandle *csh_tail;
213/* Statistics handle */ 216/* Statistics handle */
214static struct GNUNET_STATISTICS_Handle *statistics; 217static struct GNUNET_STATISTICS_Handle *statistics;
215 218
216/**
217 * Send shorten response back to client
218 *
219 * @param cls the closure containing a client shorten handle
220 * @param name the shortened name result or NULL if cannot be shortened
221 */
222static void
223send_shorten_response(void* cls, const char* name);
224
225
226/**
227 * Continue shutdown
228 */
229static void
230on_resolver_cleanup(void)
231{
232 if (NULL != statistics)
233 GNUNET_STATISTICS_destroy (statistics, GNUNET_NO);
234
235 if (NULL != namestore_iter)
236 GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
237 GNUNET_NAMESTORE_disconnect(namestore_handle);
238 GNUNET_DHT_disconnect(dht_handle);
239}
240 219
241/** 220/**
242 * Task run during shutdown. 221 * Task run during shutdown.
@@ -247,30 +226,31 @@ on_resolver_cleanup(void)
247static void 226static void
248shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 227shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
249{ 228{
250 struct ClientShortenHandle *csh_tmp = csh_head; 229 struct ClientShortenHandle *csh_tmp;
251 230
252 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 231 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
253 "Shutting down!"); 232 "Shutting down!");
254 233 while (NULL != (csh_tmp = csh_head))
255 while (csh_tmp != NULL)
256 { 234 {
257 GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh_tmp); 235 GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh_tmp);
258 send_shorten_response (csh_tmp, csh_tmp->name); 236 GNUNET_free(csh_tmp);
259 } 237 }
260 238 GNUNET_SERVER_notification_context_destroy (nc);
261 GNUNET_SERVER_notification_context_destroy (nc); 239 gns_interceptor_stop ();
262 240 gns_resolver_cleanup ();
263 gns_interceptor_stop(); 241 if (NULL != statistics)
264 gns_resolver_cleanup(&on_resolver_cleanup); 242 GNUNET_STATISTICS_destroy (statistics, GNUNET_NO);
265 /* Kill zone task for it may make the scheduler hang */
266 if (zone_update_taskid != GNUNET_SCHEDULER_NO_TASK) 243 if (zone_update_taskid != GNUNET_SCHEDULER_NO_TASK)
267 GNUNET_SCHEDULER_cancel(zone_update_taskid); 244 GNUNET_SCHEDULER_cancel (zone_update_taskid);
245 if (NULL != namestore_iter)
246 GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
247 GNUNET_NAMESTORE_disconnect(namestore_handle);
248 GNUNET_DHT_disconnect(dht_handle);
268} 249}
269 250
270 251
271/** 252/**
272 * Method called periodicattluy that triggers 253 * Method called periodically that triggers iteration over authoritative records
273 * iteration over root zone
274 * 254 *
275 * @param cls closure 255 * @param cls closure
276 * @param tc task context 256 * @param tc task context
@@ -282,6 +262,7 @@ update_zone_dht_next(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
282 GNUNET_NAMESTORE_zone_iterator_next (namestore_iter); 262 GNUNET_NAMESTORE_zone_iterator_next (namestore_iter);
283} 263}
284 264
265
285/** 266/**
286 * Continuation for DHT put 267 * Continuation for DHT put
287 * 268 *
@@ -295,9 +276,10 @@ update_zone_dht_next(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
295static void 276static void
296record_dht_put(void *cls, int success) 277record_dht_put(void *cls, int success)
297{ 278{
298 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "put request transmitted\n"); 279 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "put request transmitted\n");
299} 280}
300 281
282
301/* prototype */ 283/* prototype */
302static void 284static void
303update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 285update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
@@ -321,8 +303,7 @@ put_gns_record(void *cls,
321 unsigned int rd_count, 303 unsigned int rd_count,
322 const struct GNUNET_NAMESTORE_RecordData *rd, 304 const struct GNUNET_NAMESTORE_RecordData *rd,
323 const struct GNUNET_CRYPTO_RsaSignature *signature) 305 const struct GNUNET_CRYPTO_RsaSignature *signature)
324{ 306{
325
326 struct GNSNameRecordBlock *nrb; 307 struct GNSNameRecordBlock *nrb;
327 struct GNUNET_CRYPTO_ShortHashCode name_hash; 308 struct GNUNET_CRYPTO_ShortHashCode name_hash;
328 struct GNUNET_CRYPTO_ShortHashCode zhash; 309 struct GNUNET_CRYPTO_ShortHashCode zhash;
@@ -332,9 +313,7 @@ put_gns_record(void *cls,
332 uint32_t rd_payload_length; 313 uint32_t rd_payload_length;
333 char* nrb_data = NULL; 314 char* nrb_data = NULL;
334 size_t namelen; 315 size_t namelen;
335 struct GNUNET_TIME_Relative next_put_interval; 316 struct GNUNET_TIME_Relative next_put_interval;
336
337
338 317
339 /* we're done */ 318 /* we're done */
340 if (NULL == name) 319 if (NULL == name)
@@ -362,9 +341,9 @@ put_gns_record(void *cls,
362 zone_iteration_interval = GNUNET_TIME_relative_max (MINIMUM_ZONE_ITERATION_INTERVAL, 341 zone_iteration_interval = GNUNET_TIME_relative_max (MINIMUM_ZONE_ITERATION_INTERVAL,
363 zone_iteration_interval); 342 zone_iteration_interval);
364 343
365 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
366 "Adjusted zone iteration interval to %llus!\n", 345 "Adjusted zone iteration interval to %s\n",
367 zone_iteration_interval.rel_value); 346 GNUNET_STRINGS_relative_time_to_string (zone_iteration_interval, GNUNET_YES));
368 GNUNET_STATISTICS_set (statistics, 347 GNUNET_STATISTICS_set (statistics,
369 "Current zone iteration interval [msec]", 348 "Current zone iteration interval [msec]",
370 zone_iteration_interval.rel_value, 349 zone_iteration_interval.rel_value,
@@ -392,98 +371,84 @@ put_gns_record(void *cls,
392 } 371 }
393 372
394 namelen = strlen(name) + 1; 373 namelen = strlen(name) + 1;
395
396 if (rd_count == 0) 374 if (rd_count == 0)
397 { 375 {
398 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 376 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
399 "No records given for name %s! Skipping...\n", 377 "No records for name `%s'! Skipping.\n",
400 name); 378 name);
401 zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_next, 379 zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_next,
402 NULL); 380 NULL);
403 return; 381 return;
404 } 382 }
405
406 if (signature == NULL) 383 if (signature == NULL)
407 { 384 {
408 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 385 GNUNET_break (0);
409 "No signature for %s record data provided! Skipping...\n",
410 name);
411 zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_next, 386 zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_next,
412 NULL); 387 NULL);
413 return; 388 return;
414
415 } 389 }
416 390
417 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
418 "Putting records for %s into the DHT\n", name); 392 "Putting records for `%s' into the DHT\n", name);
419
420 rd_payload_length = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
421 393
394 rd_payload_length = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
422 nrb = GNUNET_malloc(rd_payload_length + namelen 395 nrb = GNUNET_malloc(rd_payload_length + namelen
423 + sizeof(struct GNSNameRecordBlock)); 396 + sizeof(struct GNSNameRecordBlock));
424
425 nrb->signature = *signature; 397 nrb->signature = *signature;
426
427 nrb->public_key = *key; 398 nrb->public_key = *key;
428
429 nrb->rd_count = htonl(rd_count); 399 nrb->rd_count = htonl(rd_count);
430
431 memcpy(&nrb[1], name, namelen); 400 memcpy(&nrb[1], name, namelen);
432 401 nrb_data = (char *) &nrb[1];
433 nrb_data = (char*)&nrb[1];
434 nrb_data += namelen; 402 nrb_data += namelen;
435
436 rd_payload_length += sizeof(struct GNSNameRecordBlock) + namelen; 403 rd_payload_length += sizeof(struct GNSNameRecordBlock) + namelen;
437 404 GNUNET_CRYPTO_short_hash (key,
405 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
406 &zhash);
438 if (-1 == GNUNET_NAMESTORE_records_serialize (rd_count, 407 if (-1 == GNUNET_NAMESTORE_records_serialize (rd_count,
439 rd, 408 rd,
440 rd_payload_length, 409 rd_payload_length,
441 nrb_data)) 410 nrb_data))
442 { 411 {
443 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 412 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
444 "Record serialization failed! Skipping...\n"); 413 _("Records for name `%s' in zone %s too large to fit into DHT"),
414 name,
415 GNUNET_h2s (&zhash) /* FIXME: write converter for short hash... */);
445 GNUNET_free(nrb); 416 GNUNET_free(nrb);
446 zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_next, 417 zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_next,
447 NULL); 418 NULL);
448 return; 419 return;
449 } 420 }
450 421
451
452 /* 422 /*
453 * calculate DHT key: H(name) xor H(pubkey) 423 * calculate DHT key: H(name) xor H(pubkey)
454 */ 424 */
455 GNUNET_CRYPTO_short_hash(key,
456 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
457 &zhash);
458 GNUNET_CRYPTO_short_hash(name, strlen(name), &name_hash); 425 GNUNET_CRYPTO_short_hash(name, strlen(name), &name_hash);
459 GNUNET_CRYPTO_short_hash_double (&name_hash, &name_hash_double); 426 GNUNET_CRYPTO_short_hash_double (&name_hash, &name_hash_double);
460 GNUNET_CRYPTO_short_hash_double (&zhash, &zone_hash_double); 427 GNUNET_CRYPTO_short_hash_double (&zhash, &zone_hash_double);
461 GNUNET_CRYPTO_hash_xor(&zone_hash_double, &name_hash_double, &xor_hash); 428 GNUNET_CRYPTO_hash_xor(&zone_hash_double, &name_hash_double, &xor_hash);
462 429
463 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 430 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
464 "zone identity: %s\n", GNUNET_h2s (&zone_hash_double)); 431 "putting %u records from zone %s for `%s' under key: %s with size %u and timeout %s\n",
465 432 rd_count,
466 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 433 GNUNET_h2s (&zone_hash_double) /* FIXME: write converter for short hash... */,
467 "putting %d records for %s under key: %s with size %d\n", 434 name,
468 rd_count, name, GNUNET_h2s (&xor_hash), rd_payload_length); 435 GNUNET_h2s (&xor_hash),
436 (unsigned int) rd_payload_length,
437 GNUNET_STRINGS_relative_time_to_string (DHT_OPERATION_TIMEOUT, GNUNET_YES));
469 438
470 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
471 "DHT req to %d\n", DHT_OPERATION_TIMEOUT.rel_value);
472
473 GNUNET_STATISTICS_update (statistics, 439 GNUNET_STATISTICS_update (statistics,
474 "Record bytes put into DHT", rd_payload_length, GNUNET_NO); 440 "Record bytes put into DHT", rd_payload_length, GNUNET_NO);
475 441
476 /* FIXME: keep return value to possibly cancel? */ 442 (void) GNUNET_DHT_put (dht_handle, &xor_hash,
477 GNUNET_DHT_put (dht_handle, &xor_hash, 443 DHT_GNS_REPLICATION_LEVEL,
478 DHT_GNS_REPLICATION_LEVEL, 444 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
479 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 445 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
480 GNUNET_BLOCK_TYPE_GNS_NAMERECORD, 446 rd_payload_length,
481 rd_payload_length, 447 (char*)nrb,
482 (char*)nrb, 448 expiration,
483 expiration, 449 DHT_OPERATION_TIMEOUT,
484 DHT_OPERATION_TIMEOUT, 450 &record_dht_put,
485 &record_dht_put, 451 NULL);
486 NULL); //cls for cont
487 452
488 num_public_records++; 453 num_public_records++;
489 454
@@ -514,9 +479,9 @@ put_gns_record(void *cls,
514 NULL); 479 NULL);
515 480
516 GNUNET_free(nrb); 481 GNUNET_free(nrb);
517
518} 482}
519 483
484
520/** 485/**
521 * Periodically iterate over our zone and store everything in dht 486 * Periodically iterate over our zone and store everything in dht
522 * 487 *
@@ -551,41 +516,37 @@ update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
551static void 516static void
552send_shorten_response(void* cls, const char* name) 517send_shorten_response(void* cls, const char* name)
553{ 518{
554 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message with %s\n", 519 struct ClientShortenHandle *csh = cls;
555 "SHORTEN_RESULT", name);
556 struct GNUNET_GNS_ClientShortenResultMessage *rmsg; 520 struct GNUNET_GNS_ClientShortenResultMessage *rmsg;
557 struct ClientShortenHandle *csh = (struct ClientShortenHandle *)cls; 521 size_t name_len;
558 522
559 if (name == NULL) 523 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message with %s\n",
560 { 524 "SHORTEN_RESULT", name);
561 name = ""; 525 if (NULL == name)
562 } 526 name_len = 0;
563 527 else
528 name_len = strlen (name) + 1;
564 GNUNET_STATISTICS_update (statistics, 529 GNUNET_STATISTICS_update (statistics,
565 "Name shorten results", 1, GNUNET_NO); 530 "Name shorten results", 1, GNUNET_NO);
566 531
567 rmsg = GNUNET_malloc(sizeof(struct GNUNET_GNS_ClientShortenResultMessage) 532 rmsg = GNUNET_malloc(sizeof(struct GNUNET_GNS_ClientShortenResultMessage) +
568 + strlen(name) + 1); 533 name_len);
569 534
570 rmsg->id = csh->unique_id; 535 rmsg->id = csh->unique_id;
571 rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT); 536 rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT);
572 rmsg->header.size = 537 rmsg->header.size =
573 htons(sizeof(struct GNUNET_GNS_ClientShortenResultMessage) + 538 htons(sizeof(struct GNUNET_GNS_ClientShortenResultMessage) +
574 strlen(name) + 1); 539 name_len);
575 540 memcpy (&rmsg[1], name, name_len);
576 strcpy((char*)&rmsg[1], name);
577 541
578 GNUNET_SERVER_notification_context_unicast (nc, csh->client, 542 GNUNET_SERVER_notification_context_unicast (nc, csh->client,
579 (const struct GNUNET_MessageHeader *) rmsg, 543 &rmsg->header,
580 GNUNET_NO); 544 GNUNET_NO);
581 GNUNET_SERVER_receive_done (csh->client, GNUNET_OK); 545 GNUNET_SERVER_receive_done (csh->client, GNUNET_OK);
582
583 if (NULL != csh->namestore_task) 546 if (NULL != csh->namestore_task)
584 GNUNET_NAMESTORE_cancel (csh->namestore_task); 547 GNUNET_NAMESTORE_cancel (csh->namestore_task);
585 548 GNUNET_free (rmsg);
586 GNUNET_free(rmsg); 549 GNUNET_free (csh);
587 GNUNET_free(csh);
588
589} 550}
590 551
591 552
@@ -792,13 +753,14 @@ start_shorten_name (struct ClientShortenHandle *csh)
792/** 753/**
793 * Handle a shorten message from the api 754 * Handle a shorten message from the api
794 * 755 *
795 * @param cls the closure 756 * @param cls the closure (unused)
796 * @param client the client 757 * @param client the client
797 * @param message the message 758 * @param message the message
798 */ 759 */
799static void handle_shorten (void *cls, 760static void
800 struct GNUNET_SERVER_Client * client, 761handle_shorten (void *cls,
801 const struct GNUNET_MessageHeader * message) 762 struct GNUNET_SERVER_Client * client,
763 const struct GNUNET_MessageHeader * message)
802{ 764{
803 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "SHORTEN"); 765 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "SHORTEN");
804 766
@@ -919,8 +881,8 @@ send_get_auth_response(void *cls, const char* name)
919 strcpy((char*)&rmsg[1], name); 881 strcpy((char*)&rmsg[1], name);
920 882
921 GNUNET_SERVER_notification_context_unicast (nc, cah->client, 883 GNUNET_SERVER_notification_context_unicast (nc, cah->client,
922 (const struct GNUNET_MessageHeader *) rmsg, 884 &rmsg->header,
923 GNUNET_NO); 885 GNUNET_NO);
924 GNUNET_SERVER_receive_done (cah->client, GNUNET_OK); 886 GNUNET_SERVER_receive_done (cah->client, GNUNET_OK);
925 887
926 GNUNET_free(rmsg); 888 GNUNET_free(rmsg);