diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2016-09-25 18:29:08 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2016-09-25 18:29:08 +0000 |
commit | ca1cea453795dd8aa1b68dfb8f311bda85102a8c (patch) | |
tree | e239916b784d980a599fef3b14c40202bc1460c9 | |
parent | 0f498b21da0314edd8d35b419ea10ca25128bc83 (diff) | |
download | gnunet-ca1cea453795dd8aa1b68dfb8f311bda85102a8c.tar.gz gnunet-ca1cea453795dd8aa1b68dfb8f311bda85102a8c.zip |
- move to new MQ API
-rw-r--r-- | src/gns/gns.h | 4 | ||||
-rw-r--r-- | src/gns/gns_api.c | 8 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns.c | 362 |
3 files changed, 208 insertions, 166 deletions
diff --git a/src/gns/gns.h b/src/gns/gns.h index 73aee7d19..476cb0fd2 100644 --- a/src/gns/gns.h +++ b/src/gns/gns.h | |||
@@ -48,7 +48,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
48 | /** | 48 | /** |
49 | * Message from client to GNS service to lookup records. | 49 | * Message from client to GNS service to lookup records. |
50 | */ | 50 | */ |
51 | struct GNUNET_GNS_ClientLookupMessage | 51 | struct LookupMessage |
52 | { | 52 | { |
53 | /** | 53 | /** |
54 | * Header of type #GNUNET_MESSAGE_TYPE_GNS_LOOKUP | 54 | * Header of type #GNUNET_MESSAGE_TYPE_GNS_LOOKUP |
@@ -93,7 +93,7 @@ struct GNUNET_GNS_ClientLookupMessage | |||
93 | /** | 93 | /** |
94 | * Message from GNS service to client: new results. | 94 | * Message from GNS service to client: new results. |
95 | */ | 95 | */ |
96 | struct GNUNET_GNS_ClientLookupResultMessage | 96 | struct LookupResultMessage |
97 | { | 97 | { |
98 | /** | 98 | /** |
99 | * Header of type #GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT | 99 | * Header of type #GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT |
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c index 475d5b5cd..b9b95b7c2 100644 --- a/src/gns/gns_api.c +++ b/src/gns/gns_api.c | |||
@@ -193,7 +193,7 @@ mq_error_handler (void *cls, | |||
193 | */ | 193 | */ |
194 | static int | 194 | static int |
195 | check_result (void *cls, | 195 | check_result (void *cls, |
196 | const struct GNUNET_GNS_ClientLookupResultMessage *lookup_msg) | 196 | const struct LookupResultMessage *lookup_msg) |
197 | { | 197 | { |
198 | size_t mlen = ntohs (lookup_msg->header.size) - sizeof (*lookup_msg); | 198 | size_t mlen = ntohs (lookup_msg->header.size) - sizeof (*lookup_msg); |
199 | uint32_t rd_count = ntohl (lookup_msg->rd_count); | 199 | uint32_t rd_count = ntohl (lookup_msg->rd_count); |
@@ -220,7 +220,7 @@ check_result (void *cls, | |||
220 | */ | 220 | */ |
221 | static void | 221 | static void |
222 | handle_result (void *cls, | 222 | handle_result (void *cls, |
223 | const struct GNUNET_GNS_ClientLookupResultMessage *lookup_msg) | 223 | const struct LookupResultMessage *lookup_msg) |
224 | { | 224 | { |
225 | struct GNUNET_GNS_Handle *handle = cls; | 225 | struct GNUNET_GNS_Handle *handle = cls; |
226 | size_t mlen = ntohs (lookup_msg->header.size) - sizeof (*lookup_msg); | 226 | size_t mlen = ntohs (lookup_msg->header.size) - sizeof (*lookup_msg); |
@@ -267,7 +267,7 @@ reconnect (struct GNUNET_GNS_Handle *handle) | |||
267 | struct GNUNET_MQ_MessageHandler handlers[] = { | 267 | struct GNUNET_MQ_MessageHandler handlers[] = { |
268 | GNUNET_MQ_hd_var_size (result, | 268 | GNUNET_MQ_hd_var_size (result, |
269 | GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT, | 269 | GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT, |
270 | struct GNUNET_GNS_ClientLookupResultMessage, | 270 | struct LookupResultMessage, |
271 | handle), | 271 | handle), |
272 | GNUNET_MQ_handler_end () | 272 | GNUNET_MQ_handler_end () |
273 | }; | 273 | }; |
@@ -377,7 +377,7 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, | |||
377 | void *proc_cls) | 377 | void *proc_cls) |
378 | { | 378 | { |
379 | /* IPC to shorten gns names, return shorten_handle */ | 379 | /* IPC to shorten gns names, return shorten_handle */ |
380 | struct GNUNET_GNS_ClientLookupMessage *lookup_msg; | 380 | struct LookupMessage *lookup_msg; |
381 | struct GNUNET_GNS_LookupRequest *lr; | 381 | struct GNUNET_GNS_LookupRequest *lr; |
382 | size_t nlen; | 382 | size_t nlen; |
383 | 383 | ||
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index ea271e9dd..149efc82d 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c | |||
@@ -77,6 +77,10 @@ | |||
77 | */ | 77 | */ |
78 | #define DHT_GNS_REPLICATION_LEVEL 5 | 78 | #define DHT_GNS_REPLICATION_LEVEL 5 |
79 | 79 | ||
80 | /** | ||
81 | * GnsClient prototype | ||
82 | */ | ||
83 | struct GnsClient; | ||
80 | 84 | ||
81 | /** | 85 | /** |
82 | * Handle to a lookup operation from api | 86 | * Handle to a lookup operation from api |
@@ -93,11 +97,11 @@ struct ClientLookupHandle | |||
93 | * We keep these in a DLL. | 97 | * We keep these in a DLL. |
94 | */ | 98 | */ |
95 | struct ClientLookupHandle *prev; | 99 | struct ClientLookupHandle *prev; |
96 | 100 | ||
97 | /** | 101 | /** |
98 | * Handle to the requesting client | 102 | * Client handle |
99 | */ | 103 | */ |
100 | struct GNUNET_SERVER_Client *client; | 104 | struct GnsClient *gc; |
101 | 105 | ||
102 | /** | 106 | /** |
103 | * Active handle for the lookup. | 107 | * Active handle for the lookup. |
@@ -111,6 +115,29 @@ struct ClientLookupHandle | |||
111 | 115 | ||
112 | }; | 116 | }; |
113 | 117 | ||
118 | struct GnsClient | ||
119 | { | ||
120 | /** | ||
121 | * The client | ||
122 | */ | ||
123 | struct GNUNET_SERVICE_Client *client; | ||
124 | |||
125 | /** | ||
126 | * The MQ | ||
127 | */ | ||
128 | struct GNUNET_MQ_Handle *mq; | ||
129 | |||
130 | /** | ||
131 | * Head of the DLL. | ||
132 | */ | ||
133 | struct ClientLookupHandle *clh_head; | ||
134 | |||
135 | /** | ||
136 | * Tail of the DLL. | ||
137 | */ | ||
138 | struct ClientLookupHandle *clh_tail; | ||
139 | }; | ||
140 | |||
114 | 141 | ||
115 | /** | 142 | /** |
116 | * Handle for DHT PUT activity triggered from the namestore monitor. | 143 | * Handle for DHT PUT activity triggered from the namestore monitor. |
@@ -176,21 +203,6 @@ static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter; | |||
176 | static struct GNUNET_NAMESTORE_ZoneMonitor *zmon; | 203 | static struct GNUNET_NAMESTORE_ZoneMonitor *zmon; |
177 | 204 | ||
178 | /** | 205 | /** |
179 | * Our notification context. | ||
180 | */ | ||
181 | static struct GNUNET_SERVER_NotificationContext *nc; | ||
182 | |||
183 | /** | ||
184 | * Head of the DLL. | ||
185 | */ | ||
186 | static struct ClientLookupHandle *clh_head; | ||
187 | |||
188 | /** | ||
189 | * Tail of the DLL. | ||
190 | */ | ||
191 | static struct ClientLookupHandle *clh_tail; | ||
192 | |||
193 | /** | ||
194 | * Head of monitor activities; kept in a DLL. | 206 | * Head of monitor activities; kept in a DLL. |
195 | */ | 207 | */ |
196 | static struct MonitorActivity *ma_head; | 208 | static struct MonitorActivity *ma_head; |
@@ -267,27 +279,10 @@ static struct GNUNET_STATISTICS_Handle *statistics; | |||
267 | static void | 279 | static void |
268 | shutdown_task (void *cls) | 280 | shutdown_task (void *cls) |
269 | { | 281 | { |
270 | struct ClientLookupHandle *clh; | ||
271 | struct MonitorActivity *ma; | 282 | struct MonitorActivity *ma; |
272 | 283 | ||
273 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 284 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
274 | "Shutting down!\n"); | 285 | "Shutting down!\n"); |
275 | if (NULL != nc) | ||
276 | { | ||
277 | GNUNET_SERVER_notification_context_destroy (nc); | ||
278 | nc = NULL; | ||
279 | } | ||
280 | while (NULL != (clh = clh_head)) | ||
281 | { | ||
282 | GNUNET_SERVER_client_set_user_context (clh->client, | ||
283 | NULL); | ||
284 | GNS_resolver_lookup_cancel (clh->lookup); | ||
285 | GNUNET_CONTAINER_DLL_remove (clh_head, | ||
286 | clh_tail, | ||
287 | clh); | ||
288 | GNUNET_free (clh); | ||
289 | } | ||
290 | |||
291 | GNS_interceptor_done (); | 286 | GNS_interceptor_done (); |
292 | if (NULL != identity_op) | 287 | if (NULL != identity_op) |
293 | { | 288 | { |
@@ -352,6 +347,60 @@ shutdown_task (void *cls) | |||
352 | } | 347 | } |
353 | } | 348 | } |
354 | 349 | ||
350 | /** | ||
351 | * Called whenever a client is disconnected. | ||
352 | * | ||
353 | * @param cls closure | ||
354 | * @param client identification of the client | ||
355 | * @param app_ctx @a client | ||
356 | */ | ||
357 | static void | ||
358 | client_disconnect_cb (void *cls, | ||
359 | struct GNUNET_SERVICE_Client *client, | ||
360 | void *app_ctx) | ||
361 | { | ||
362 | struct ClientLookupHandle *clh; | ||
363 | struct GnsClient *gc = cls; | ||
364 | |||
365 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
366 | "Client %p disconnected\n", | ||
367 | client); | ||
368 | while (NULL != (clh = gc->clh_head)) | ||
369 | { | ||
370 | GNS_resolver_lookup_cancel (clh->lookup); | ||
371 | GNUNET_CONTAINER_DLL_remove (gc->clh_head, | ||
372 | gc->clh_tail, | ||
373 | clh); | ||
374 | GNUNET_free (clh); | ||
375 | } | ||
376 | |||
377 | GNUNET_free (gc); | ||
378 | } | ||
379 | |||
380 | |||
381 | /** | ||
382 | * Add a client to our list of active clients. | ||
383 | * | ||
384 | * @param cls NULL | ||
385 | * @param client client to add | ||
386 | * @param mq message queue for @a client | ||
387 | * @return internal namestore client structure for this client | ||
388 | */ | ||
389 | static void * | ||
390 | client_connect_cb (void *cls, | ||
391 | struct GNUNET_SERVICE_Client *client, | ||
392 | struct GNUNET_MQ_Handle *mq) | ||
393 | { | ||
394 | struct GnsClient *gc; | ||
395 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
396 | "Client %p connected\n", | ||
397 | client); | ||
398 | gc = GNUNET_new (struct GnsClient); | ||
399 | gc->client = client; | ||
400 | gc->mq = mq; | ||
401 | return gc; | ||
402 | } | ||
403 | |||
355 | 404 | ||
356 | /** | 405 | /** |
357 | * Method called periodically that triggers iteration over authoritative records | 406 | * Method called periodically that triggers iteration over authoritative records |
@@ -385,7 +434,7 @@ publish_zone_dht_start (void *cls); | |||
385 | */ | 434 | */ |
386 | static void | 435 | static void |
387 | dht_put_continuation (void *cls, | 436 | dht_put_continuation (void *cls, |
388 | int success) | 437 | int success) |
389 | { | 438 | { |
390 | struct MonitorActivity *ma = cls; | 439 | struct MonitorActivity *ma = cls; |
391 | struct GNUNET_TIME_Relative next_put_interval; | 440 | struct GNUNET_TIME_Relative next_put_interval; |
@@ -500,20 +549,20 @@ perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | |||
500 | struct GNUNET_DHT_PutHandle *ret; | 549 | struct GNUNET_DHT_PutHandle *ret; |
501 | 550 | ||
502 | expire = GNUNET_GNSRECORD_record_get_expiration_time (rd_public_count, | 551 | expire = GNUNET_GNSRECORD_record_get_expiration_time (rd_public_count, |
503 | rd_public); | 552 | rd_public); |
504 | block = GNUNET_GNSRECORD_block_create (key, | 553 | block = GNUNET_GNSRECORD_block_create (key, |
505 | expire, | 554 | expire, |
506 | label, | 555 | label, |
507 | rd_public, | 556 | rd_public, |
508 | rd_public_count); | 557 | rd_public_count); |
509 | if (NULL == block) | 558 | if (NULL == block) |
510 | return NULL; /* whoops */ | 559 | return NULL; /* whoops */ |
511 | block_size = ntohl (block->purpose.size) | 560 | block_size = ntohl (block->purpose.size) |
512 | + sizeof (struct GNUNET_CRYPTO_EcdsaSignature) | 561 | + sizeof (struct GNUNET_CRYPTO_EcdsaSignature) |
513 | + sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey); | 562 | + sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey); |
514 | GNUNET_GNSRECORD_query_from_private_key (key, | 563 | GNUNET_GNSRECORD_query_from_private_key (key, |
515 | label, | 564 | label, |
516 | &query); | 565 | &query); |
517 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 566 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
518 | "Storing %u record(s) for label `%s' in DHT with expiration `%s' under key %s\n", | 567 | "Storing %u record(s) for label `%s' in DHT with expiration `%s' under key %s\n", |
519 | rd_public_count, | 568 | rd_public_count, |
@@ -686,7 +735,7 @@ publish_zone_dht_start (void *cls) | |||
686 | zone_publish_task = NULL; | 735 | zone_publish_task = NULL; |
687 | 736 | ||
688 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 737 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
689 | "Starting DHT zone update!\n"); | 738 | "Starting DHT zone update!\n"); |
690 | /* start counting again */ | 739 | /* start counting again */ |
691 | num_public_records = 0; | 740 | num_public_records = 0; |
692 | GNUNET_assert (NULL == namestore_iter); | 741 | GNUNET_assert (NULL == namestore_iter); |
@@ -764,44 +813,71 @@ handle_monitor_event (void *cls, | |||
764 | */ | 813 | */ |
765 | static void | 814 | static void |
766 | send_lookup_response (void* cls, | 815 | send_lookup_response (void* cls, |
767 | uint32_t rd_count, | 816 | uint32_t rd_count, |
768 | const struct GNUNET_GNSRECORD_Data *rd) | 817 | const struct GNUNET_GNSRECORD_Data *rd) |
769 | { | 818 | { |
770 | struct ClientLookupHandle *clh = cls; | 819 | struct ClientLookupHandle *clh = cls; |
771 | struct GNUNET_GNS_ClientLookupResultMessage *rmsg; | 820 | struct GNUNET_MQ_Envelope *env; |
821 | struct LookupResultMessage *rmsg; | ||
772 | size_t len; | 822 | size_t len; |
773 | 823 | ||
774 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 824 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
775 | "Sending LOOKUP_RESULT message with %u results\n", | 825 | "Sending LOOKUP_RESULT message with %u results\n", |
776 | (unsigned int) rd_count); | 826 | (unsigned int) rd_count); |
777 | 827 | ||
778 | len = GNUNET_GNSRECORD_records_get_size (rd_count, rd); | 828 | len = GNUNET_GNSRECORD_records_get_size (rd_count, rd); |
779 | rmsg = GNUNET_malloc (len + sizeof (struct GNUNET_GNS_ClientLookupResultMessage)); | 829 | env = GNUNET_MQ_msg_extra (rmsg, |
780 | rmsg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT); | 830 | len, |
781 | rmsg->header.size = htons (len + sizeof(struct GNUNET_GNS_ClientLookupResultMessage)); | 831 | GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT); |
782 | rmsg->id = clh->request_id; | 832 | rmsg->id = clh->request_id; |
783 | rmsg->rd_count = htonl (rd_count); | 833 | rmsg->rd_count = htonl (rd_count); |
784 | GNUNET_GNSRECORD_records_serialize (rd_count, rd, len, | 834 | GNUNET_GNSRECORD_records_serialize (rd_count, rd, len, |
785 | (char*) &rmsg[1]); | 835 | (char*) &rmsg[1]); |
786 | GNUNET_SERVER_notification_context_unicast (nc, | 836 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq(clh->gc->client), |
787 | clh->client, | 837 | env); |
788 | &rmsg->header, | 838 | GNUNET_CONTAINER_DLL_remove (clh->gc->clh_head, clh->gc->clh_tail, clh); |
789 | GNUNET_NO); | ||
790 | GNUNET_free (rmsg); | ||
791 | GNUNET_CONTAINER_DLL_remove (clh_head, clh_tail, clh); | ||
792 | GNUNET_SERVER_client_set_user_context (clh->client, NULL); | ||
793 | GNUNET_free (clh); | 839 | GNUNET_free (clh); |
794 | GNUNET_STATISTICS_update (statistics, | 840 | GNUNET_STATISTICS_update (statistics, |
795 | "Completed lookups", 1, | 841 | "Completed lookups", 1, |
796 | GNUNET_NO); | 842 | GNUNET_NO); |
797 | GNUNET_STATISTICS_update (statistics, | 843 | GNUNET_STATISTICS_update (statistics, |
798 | "Records resolved", | 844 | "Records resolved", |
799 | rd_count, | 845 | rd_count, |
800 | GNUNET_NO); | 846 | GNUNET_NO); |
801 | } | 847 | } |
802 | 848 | ||
803 | 849 | ||
804 | /** | 850 | /** |
851 | * Checks a #GNUNET_MESSAGE_TYPE_GNS_LOOKUP message | ||
852 | * | ||
853 | * @param cls client sending the message | ||
854 | * @param l_msg message of type `struct LookupMessage` | ||
855 | * @return #GNUNET_OK if @a l_msg is well-formed | ||
856 | */ | ||
857 | static int | ||
858 | check_lookup (void *cls, | ||
859 | const struct LookupMessage *l_msg) | ||
860 | { | ||
861 | size_t msg_size; | ||
862 | const char* name; | ||
863 | |||
864 | msg_size = ntohs (l_msg->header.size); | ||
865 | if (msg_size < sizeof (struct LookupMessage)) | ||
866 | { | ||
867 | GNUNET_break (0); | ||
868 | return GNUNET_SYSERR; | ||
869 | } | ||
870 | name = (const char *) &l_msg[1]; | ||
871 | if ( ('\0' != name[l_msg->header.size - sizeof (struct LookupMessage) - 1]) || | ||
872 | (strlen (name) > GNUNET_DNSPARSER_MAX_NAME_LENGTH) ) | ||
873 | { | ||
874 | GNUNET_break (0); | ||
875 | return GNUNET_SYSERR; | ||
876 | } | ||
877 | return GNUNET_OK; | ||
878 | } | ||
879 | |||
880 | /** | ||
805 | * Handle lookup requests from client | 881 | * Handle lookup requests from client |
806 | * | 882 | * |
807 | * @param cls the closure | 883 | * @param cls the closure |
@@ -810,53 +886,34 @@ send_lookup_response (void* cls, | |||
810 | */ | 886 | */ |
811 | static void | 887 | static void |
812 | handle_lookup (void *cls, | 888 | handle_lookup (void *cls, |
813 | struct GNUNET_SERVER_Client *client, | 889 | const struct LookupMessage *sh_msg) |
814 | const struct GNUNET_MessageHeader *message) | ||
815 | { | 890 | { |
891 | struct GnsClient *gc = cls; | ||
816 | char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH + 1]; | 892 | char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH + 1]; |
817 | struct ClientLookupHandle *clh; | 893 | struct ClientLookupHandle *clh; |
818 | char *nameptr = name; | 894 | char *nameptr = name; |
819 | const char *utf_in; | 895 | const char *utf_in; |
820 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *key; | 896 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *key; |
821 | uint16_t msg_size; | ||
822 | const struct GNUNET_GNS_ClientLookupMessage *sh_msg; | ||
823 | 897 | ||
824 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 898 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
825 | "Received LOOKUP message\n"); | 899 | "Received LOOKUP message\n"); |
826 | msg_size = ntohs (message->size); | 900 | GNUNET_SERVICE_client_continue (gc->client); |
827 | if (msg_size < sizeof (struct GNUNET_GNS_ClientLookupMessage)) | ||
828 | { | ||
829 | GNUNET_break (0); | ||
830 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
831 | return; | ||
832 | } | ||
833 | sh_msg = (const struct GNUNET_GNS_ClientLookupMessage *) message; | ||
834 | GNUNET_SERVER_notification_context_add (nc, client); | ||
835 | if (GNUNET_YES == ntohs (sh_msg->have_key)) | 901 | if (GNUNET_YES == ntohs (sh_msg->have_key)) |
836 | key = &sh_msg->shorten_key; | 902 | key = &sh_msg->shorten_key; |
837 | else | 903 | else |
838 | key = NULL; | 904 | key = NULL; |
839 | utf_in = (const char *) &sh_msg[1]; | 905 | utf_in = (const char *) &sh_msg[1]; |
840 | if ( ('\0' != utf_in[msg_size - sizeof (struct GNUNET_GNS_ClientLookupMessage) - 1]) || | ||
841 | (strlen (utf_in) > GNUNET_DNSPARSER_MAX_NAME_LENGTH) ) | ||
842 | { | ||
843 | GNUNET_break (0); | ||
844 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
845 | return; | ||
846 | } | ||
847 | GNUNET_STRINGS_utf8_tolower (utf_in, nameptr); | 906 | GNUNET_STRINGS_utf8_tolower (utf_in, nameptr); |
848 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
849 | 907 | ||
850 | clh = GNUNET_new (struct ClientLookupHandle); | 908 | clh = GNUNET_new (struct ClientLookupHandle); |
851 | GNUNET_SERVER_client_set_user_context (client, clh); | 909 | GNUNET_CONTAINER_DLL_insert (gc->clh_head, gc->clh_tail, clh); |
852 | GNUNET_CONTAINER_DLL_insert (clh_head, clh_tail, clh); | 910 | clh->gc = gc; |
853 | clh->client = client; | ||
854 | clh->request_id = sh_msg->id; | 911 | clh->request_id = sh_msg->id; |
855 | if ( (GNUNET_DNSPARSER_TYPE_A == ntohl (sh_msg->type)) && | 912 | if ( (GNUNET_DNSPARSER_TYPE_A == ntohl (sh_msg->type)) && |
856 | (GNUNET_OK != v4_enabled) ) | 913 | (GNUNET_OK != v4_enabled) ) |
857 | { | 914 | { |
858 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 915 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
859 | "LOOKUP: Query for A record but AF_INET not supported!"); | 916 | "LOOKUP: Query for A record but AF_INET not supported!"); |
860 | send_lookup_response (clh, 0, NULL); | 917 | send_lookup_response (clh, 0, NULL); |
861 | return; | 918 | return; |
862 | } | 919 | } |
@@ -869,37 +926,14 @@ handle_lookup (void *cls, | |||
869 | return; | 926 | return; |
870 | } | 927 | } |
871 | clh->lookup = GNS_resolver_lookup (&sh_msg->zone, | 928 | clh->lookup = GNS_resolver_lookup (&sh_msg->zone, |
872 | ntohl (sh_msg->type), | 929 | ntohl (sh_msg->type), |
873 | name, | 930 | name, |
874 | key, | 931 | key, |
875 | (enum GNUNET_GNS_LocalOptions) ntohs (sh_msg->options), | 932 | (enum GNUNET_GNS_LocalOptions) ntohs (sh_msg->options), |
876 | &send_lookup_response, clh); | 933 | &send_lookup_response, clh); |
877 | GNUNET_STATISTICS_update (statistics, | 934 | GNUNET_STATISTICS_update (statistics, |
878 | "Lookup attempts", | 935 | "Lookup attempts", |
879 | 1, GNUNET_NO); | 936 | 1, GNUNET_NO); |
880 | } | ||
881 | |||
882 | |||
883 | /** | ||
884 | * One of our clients disconnected, clean up after it. | ||
885 | * | ||
886 | * @param cls NULL | ||
887 | * @param client the client that disconnected | ||
888 | */ | ||
889 | static void | ||
890 | notify_client_disconnect (void *cls, | ||
891 | struct GNUNET_SERVER_Client *client) | ||
892 | { | ||
893 | struct ClientLookupHandle *clh; | ||
894 | |||
895 | if (NULL == client) | ||
896 | return; | ||
897 | clh = GNUNET_SERVER_client_get_user_context (client, struct ClientLookupHandle); | ||
898 | if (NULL == clh) | ||
899 | return; | ||
900 | GNS_resolver_lookup_cancel (clh->lookup); | ||
901 | GNUNET_CONTAINER_DLL_remove (clh_head, clh_tail, clh); | ||
902 | GNUNET_free (clh); | ||
903 | } | 937 | } |
904 | 938 | ||
905 | 939 | ||
@@ -914,7 +948,7 @@ monitor_sync_event (void *cls) | |||
914 | { | 948 | { |
915 | GNUNET_assert (NULL == zone_publish_task); | 949 | GNUNET_assert (NULL == zone_publish_task); |
916 | zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start, | 950 | zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start, |
917 | NULL); | 951 | NULL); |
918 | } | 952 | } |
919 | 953 | ||
920 | 954 | ||
@@ -943,7 +977,7 @@ handle_monitor_error (void *cls) | |||
943 | active_put = NULL; | 977 | active_put = NULL; |
944 | } | 978 | } |
945 | zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start, | 979 | zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start, |
946 | NULL); | 980 | NULL); |
947 | } | 981 | } |
948 | 982 | ||
949 | 983 | ||
@@ -977,12 +1011,12 @@ identity_intercept_cb (void *cls, | |||
977 | if (NULL == ego) | 1011 | if (NULL == ego) |
978 | { | 1012 | { |
979 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1013 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
980 | _("No ego configured for `%s`\n"), | 1014 | _("No ego configured for `%s`\n"), |
981 | "gns-intercept"); | 1015 | "gns-intercept"); |
982 | return; | 1016 | return; |
983 | } | 1017 | } |
984 | GNUNET_IDENTITY_ego_get_public_key (ego, | 1018 | GNUNET_IDENTITY_ego_get_public_key (ego, |
985 | &dns_root); | 1019 | &dns_root); |
986 | if (GNUNET_SYSERR == | 1020 | if (GNUNET_SYSERR == |
987 | GNS_interceptor_init (&dns_root, cfg)) | 1021 | GNS_interceptor_init (&dns_root, cfg)) |
988 | { | 1022 | { |
@@ -1002,13 +1036,9 @@ identity_intercept_cb (void *cls, | |||
1002 | */ | 1036 | */ |
1003 | static void | 1037 | static void |
1004 | run (void *cls, | 1038 | run (void *cls, |
1005 | struct GNUNET_SERVER_Handle *server, | 1039 | const struct GNUNET_CONFIGURATION_Handle *c, |
1006 | const struct GNUNET_CONFIGURATION_Handle *c) | 1040 | struct GNUNET_SERVICE_Handle *service) |
1007 | { | 1041 | { |
1008 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | ||
1009 | { &handle_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_LOOKUP, 0}, | ||
1010 | {NULL, NULL, 0, 0} | ||
1011 | }; | ||
1012 | unsigned long long max_parallel_bg_queries = 0; | 1042 | unsigned long long max_parallel_bg_queries = 0; |
1013 | 1043 | ||
1014 | v6_enabled = GNUNET_NETWORK_test_pf (PF_INET6); | 1044 | v6_enabled = GNUNET_NETWORK_test_pf (PF_INET6); |
@@ -1018,7 +1048,7 @@ run (void *cls, | |||
1018 | if (NULL == namestore_handle) | 1048 | if (NULL == namestore_handle) |
1019 | { | 1049 | { |
1020 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1050 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1021 | _("Failed to connect to the namestore!\n")); | 1051 | _("Failed to connect to the namestore!\n")); |
1022 | GNUNET_SCHEDULER_shutdown (); | 1052 | GNUNET_SCHEDULER_shutdown (); |
1023 | return; | 1053 | return; |
1024 | } | 1054 | } |
@@ -1026,7 +1056,7 @@ run (void *cls, | |||
1026 | if (NULL == namecache_handle) | 1056 | if (NULL == namecache_handle) |
1027 | { | 1057 | { |
1028 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1058 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1029 | _("Failed to connect to the namecache!\n")); | 1059 | _("Failed to connect to the namecache!\n")); |
1030 | GNUNET_SCHEDULER_shutdown (); | 1060 | GNUNET_SCHEDULER_shutdown (); |
1031 | return; | 1061 | return; |
1032 | } | 1062 | } |
@@ -1035,31 +1065,31 @@ run (void *cls, | |||
1035 | zone_publish_time_window_default = DEFAULT_ZONE_PUBLISH_TIME_WINDOW; | 1065 | zone_publish_time_window_default = DEFAULT_ZONE_PUBLISH_TIME_WINDOW; |
1036 | if (GNUNET_OK == | 1066 | if (GNUNET_OK == |
1037 | GNUNET_CONFIGURATION_get_value_time (c, "gns", | 1067 | GNUNET_CONFIGURATION_get_value_time (c, "gns", |
1038 | "ZONE_PUBLISH_TIME_WINDOW", | 1068 | "ZONE_PUBLISH_TIME_WINDOW", |
1039 | &zone_publish_time_window_default)) | 1069 | &zone_publish_time_window_default)) |
1040 | { | 1070 | { |
1041 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1071 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1042 | "Time window for zone iteration: %s\n", | 1072 | "Time window for zone iteration: %s\n", |
1043 | GNUNET_STRINGS_relative_time_to_string (zone_publish_time_window, | 1073 | GNUNET_STRINGS_relative_time_to_string (zone_publish_time_window, |
1044 | GNUNET_YES)); | 1074 | GNUNET_YES)); |
1045 | } | 1075 | } |
1046 | zone_publish_time_window = zone_publish_time_window_default; | 1076 | zone_publish_time_window = zone_publish_time_window_default; |
1047 | if (GNUNET_OK == | 1077 | if (GNUNET_OK == |
1048 | GNUNET_CONFIGURATION_get_value_number (c, "gns", | 1078 | GNUNET_CONFIGURATION_get_value_number (c, "gns", |
1049 | "MAX_PARALLEL_BACKGROUND_QUERIES", | 1079 | "MAX_PARALLEL_BACKGROUND_QUERIES", |
1050 | &max_parallel_bg_queries)) | 1080 | &max_parallel_bg_queries)) |
1051 | { | 1081 | { |
1052 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1082 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1053 | "Number of allowed parallel background queries: %llu\n", | 1083 | "Number of allowed parallel background queries: %llu\n", |
1054 | max_parallel_bg_queries); | 1084 | max_parallel_bg_queries); |
1055 | } | 1085 | } |
1056 | 1086 | ||
1057 | dht_handle = GNUNET_DHT_connect (c, | 1087 | dht_handle = GNUNET_DHT_connect (c, |
1058 | (unsigned int) max_parallel_bg_queries); | 1088 | (unsigned int) max_parallel_bg_queries); |
1059 | if (NULL == dht_handle) | 1089 | if (NULL == dht_handle) |
1060 | { | 1090 | { |
1061 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1091 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1062 | _("Could not connect to DHT!\n")); | 1092 | _("Could not connect to DHT!\n")); |
1063 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | 1093 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); |
1064 | return; | 1094 | return; |
1065 | } | 1095 | } |
@@ -1070,12 +1100,12 @@ run (void *cls, | |||
1070 | if (NULL == identity_handle) | 1100 | if (NULL == identity_handle) |
1071 | { | 1101 | { |
1072 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1102 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1073 | "Could not connect to identity service!\n"); | 1103 | "Could not connect to identity service!\n"); |
1074 | } | 1104 | } |
1075 | else | 1105 | else |
1076 | { | 1106 | { |
1077 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1107 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1078 | "Looking for gns-intercept ego\n"); | 1108 | "Looking for gns-intercept ego\n"); |
1079 | identity_op = GNUNET_IDENTITY_get (identity_handle, | 1109 | identity_op = GNUNET_IDENTITY_get (identity_handle, |
1080 | "gns-intercept", | 1110 | "gns-intercept", |
1081 | &identity_intercept_cb, | 1111 | &identity_intercept_cb, |
@@ -1083,19 +1113,14 @@ run (void *cls, | |||
1083 | } | 1113 | } |
1084 | GNS_resolver_init (namecache_handle, | 1114 | GNS_resolver_init (namecache_handle, |
1085 | dht_handle, | 1115 | dht_handle, |
1086 | c, | 1116 | c, |
1087 | max_parallel_bg_queries); | 1117 | max_parallel_bg_queries); |
1088 | GNS_shorten_init (namestore_handle, | 1118 | GNS_shorten_init (namestore_handle, |
1089 | namecache_handle, | 1119 | namecache_handle, |
1090 | dht_handle); | 1120 | dht_handle); |
1091 | GNUNET_SERVER_disconnect_notify (server, | ||
1092 | ¬ify_client_disconnect, | ||
1093 | NULL); | ||
1094 | /* Schedule periodic put for our records. */ | 1121 | /* Schedule periodic put for our records. */ |
1095 | first_zone_iteration = GNUNET_YES; | 1122 | first_zone_iteration = GNUNET_YES; |
1096 | GNUNET_SERVER_add_handlers (server, handlers); | ||
1097 | statistics = GNUNET_STATISTICS_create ("gns", c); | 1123 | statistics = GNUNET_STATISTICS_create ("gns", c); |
1098 | nc = GNUNET_SERVER_notification_context_create (server, 1); | ||
1099 | zmon = GNUNET_NAMESTORE_zone_monitor_start (c, | 1124 | zmon = GNUNET_NAMESTORE_zone_monitor_start (c, |
1100 | NULL, | 1125 | NULL, |
1101 | GNUNET_NO, | 1126 | GNUNET_NO, |
@@ -1110,23 +1135,40 @@ run (void *cls, | |||
1110 | } | 1135 | } |
1111 | 1136 | ||
1112 | 1137 | ||
1113 | /** | 1138 | /** TODO delete |
1114 | * The main function for the GNS service. | 1139 | * The main function for the GNS service. |
1115 | * | 1140 | * |
1116 | * @param argc number of arguments from the command line | 1141 | * @param argc number of arguments from the command line |
1117 | * @param argv command line arguments | 1142 | * @param argv command line arguments |
1118 | * @return 0 ok, 1 on error | 1143 | * @return 0 ok, 1 on error |
1119 | */ | 1144 | */ |
1120 | int | 1145 | /*int |
1121 | main (int argc, char *const *argv) | 1146 | main (int argc, char *const *argv) |
1122 | { | 1147 | { |
1123 | int ret; | 1148 | int ret; |
1124 | 1149 | ||
1125 | ret = | 1150 | ret = |
1126 | (GNUNET_OK == | 1151 | (GNUNET_OK == |
1127 | GNUNET_SERVICE_run (argc, argv, "gns", GNUNET_SERVICE_OPTION_NONE, &run, | 1152 | GNUNET_SERVICE_run (argc, argv, "gns", GNUNET_SERVICE_OPTION_NONE, &run, |
1128 | NULL)) ? 0 : 1; | 1153 | NULL)) ? 0 : 1; |
1129 | return ret; | 1154 | return ret; |
1130 | } | 1155 | }*/ |
1156 | |||
1157 | /** | ||
1158 | * Define "main" method using service macro. | ||
1159 | */ | ||
1160 | GNUNET_SERVICE_MAIN | ||
1161 | ("gns", | ||
1162 | GNUNET_SERVICE_OPTION_NONE, | ||
1163 | &run, | ||
1164 | &client_connect_cb, | ||
1165 | &client_disconnect_cb, | ||
1166 | NULL, | ||
1167 | GNUNET_MQ_hd_var_size (lookup, | ||
1168 | GNUNET_MESSAGE_TYPE_GNS_LOOKUP, | ||
1169 | struct LookupMessage, | ||
1170 | NULL), | ||
1171 | GNUNET_MQ_handler_end()); | ||
1172 | |||
1131 | 1173 | ||
1132 | /* end of gnunet-service-gns.c */ | 1174 | /* end of gnunet-service-gns.c */ |