diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-02-27 14:26:17 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-02-27 14:26:17 +0000 |
commit | 11e0d70c68bdec7df62a1118ce346fc8ec629c4a (patch) | |
tree | 34bf19338a645af52ec466c7054621f455ccb216 /src/namestore/gnunet-service-namestore.c | |
parent | 506334f0bb9d2b6e9414eb060642b5da6cb5bfcf (diff) | |
download | gnunet-11e0d70c68bdec7df62a1118ce346fc8ec629c4a.tar.gz gnunet-11e0d70c68bdec7df62a1118ce346fc8ec629c4a.zip |
- put record
Diffstat (limited to 'src/namestore/gnunet-service-namestore.c')
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 91 |
1 files changed, 90 insertions, 1 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index e7c03bf21..1700925de 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -287,7 +287,6 @@ handle_lookup_name_it (void *cls, | |||
287 | 287 | ||
288 | if (GNUNET_YES == contains_signature) | 288 | if (GNUNET_YES == contains_signature) |
289 | memcpy (signature_tmp, signature, sizeof (struct GNUNET_CRYPTO_RsaSignature)); | 289 | memcpy (signature_tmp, signature, sizeof (struct GNUNET_CRYPTO_RsaSignature)); |
290 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DONE `%s' message\n", "NAMESTORE_LOOKUP_NAME_RESPONSE"); | ||
291 | GNUNET_SERVER_notification_context_unicast (snc, lnc->nc->client, (const struct GNUNET_MessageHeader *) lnr_msg, GNUNET_NO); | 290 | GNUNET_SERVER_notification_context_unicast (snc, lnc->nc->client, (const struct GNUNET_MessageHeader *) lnr_msg, GNUNET_NO); |
292 | 291 | ||
293 | GNUNET_free (lnr_msg); | 292 | GNUNET_free (lnr_msg); |
@@ -349,6 +348,94 @@ static void handle_lookup_name (void *cls, | |||
349 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 348 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
350 | } | 349 | } |
351 | 350 | ||
351 | static void handle_record_put (void *cls, | ||
352 | struct GNUNET_SERVER_Client * client, | ||
353 | const struct GNUNET_MessageHeader * message) | ||
354 | { | ||
355 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_PUT"); | ||
356 | struct GNUNET_NAMESTORE_Client *nc; | ||
357 | struct GNUNET_TIME_Absolute expire; | ||
358 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key; | ||
359 | struct GNUNET_NAMESTORE_RecordData *rd; | ||
360 | struct GNUNET_CRYPTO_RsaSignature *signature; | ||
361 | struct RecordPutResponseMessage rpr_msg; | ||
362 | size_t name_len; | ||
363 | size_t msg_size; | ||
364 | size_t msg_size_exp; | ||
365 | char * name; | ||
366 | uint32_t id = 0; | ||
367 | uint32_t rd_count; | ||
368 | int res = GNUNET_SYSERR; | ||
369 | |||
370 | if (ntohs (message->size) < sizeof (struct RecordPutMessage)) | ||
371 | { | ||
372 | GNUNET_break_op (0); | ||
373 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
374 | return; | ||
375 | } | ||
376 | |||
377 | nc = client_lookup(client); | ||
378 | if (nc == NULL) | ||
379 | { | ||
380 | GNUNET_break_op (0); | ||
381 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
382 | return; | ||
383 | } | ||
384 | |||
385 | struct RecordPutMessage * rp_msg = (struct RecordPutMessage *) message; | ||
386 | id = ntohl (rp_msg->op_id); | ||
387 | name_len = ntohs (rp_msg->name_len); | ||
388 | rd_count = ntohl(rp_msg->rd_count); | ||
389 | msg_size = ntohs (message->size); | ||
390 | msg_size_exp = sizeof (struct RecordPutMessage) + sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + name_len + rd_count * (sizeof (struct GNUNET_NAMESTORE_RecordData)); | ||
391 | |||
392 | if (msg_size != msg_size_exp) | ||
393 | { | ||
394 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expected message %u size but message size is %u \n", msg_size_exp, msg_size); | ||
395 | GNUNET_break_op (0); | ||
396 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
397 | return; | ||
398 | } | ||
399 | |||
400 | |||
401 | if ((name_len == 0) || (name_len > 256)) | ||
402 | { | ||
403 | GNUNET_break_op (0); | ||
404 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
405 | return; | ||
406 | } | ||
407 | |||
408 | zone_key = (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *) &rp_msg[1]; | ||
409 | name = (char *) &zone_key[1]; | ||
410 | expire = GNUNET_TIME_absolute_ntoh(rp_msg->expire); | ||
411 | signature = (struct GNUNET_CRYPTO_RsaSignature *) &rp_msg->signature; | ||
412 | rd = (struct GNUNET_NAMESTORE_RecordData *) &name[name_len]; | ||
413 | |||
414 | /* Database operation */ | ||
415 | res = GSN_database->put_records(GSN_database->cls, | ||
416 | zone_key, | ||
417 | expire, | ||
418 | name, | ||
419 | rd_count, rd, | ||
420 | signature); | ||
421 | |||
422 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Putting record for name `%s': %s\n", | ||
423 | name, (res == GNUNET_OK) ? "OK" : "FAIL"); | ||
424 | |||
425 | /* Send response */ | ||
426 | |||
427 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "RECORD_PUT_RESPONSE"); | ||
428 | rpr_msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE); | ||
429 | rpr_msg.op_id = rp_msg->op_id; | ||
430 | rpr_msg.header.size = htons (sizeof (struct RecordPutResponseMessage)); | ||
431 | if (GNUNET_OK == res) | ||
432 | rpr_msg.op_result = htons (GNUNET_OK); | ||
433 | else | ||
434 | rpr_msg.op_result = htons (GNUNET_NO); | ||
435 | GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct GNUNET_MessageHeader *) &rpr_msg, GNUNET_NO); | ||
436 | |||
437 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
438 | } | ||
352 | 439 | ||
353 | /** | 440 | /** |
354 | * Process template requests. | 441 | * Process template requests. |
@@ -370,6 +457,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
370 | GNUNET_MESSAGE_TYPE_NAMESTORE_START, sizeof (struct StartMessage)}, | 457 | GNUNET_MESSAGE_TYPE_NAMESTORE_START, sizeof (struct StartMessage)}, |
371 | {&handle_lookup_name, NULL, | 458 | {&handle_lookup_name, NULL, |
372 | GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME, 0}, | 459 | GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME, 0}, |
460 | {&handle_record_put, NULL, | ||
461 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT, 0}, | ||
373 | {NULL, NULL, 0, 0} | 462 | {NULL, NULL, 0, 0} |
374 | }; | 463 | }; |
375 | 464 | ||