diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-09-20 09:11:10 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-09-20 09:11:10 +0000 |
commit | 08edde13e140fe0fa7c4b00f6669ee396e00c2f5 (patch) | |
tree | 1676285d08b2b06047d8b0141ed9ab8b90579073 /src/revocation | |
parent | 6a131ab255bb3419eb0e59a24879556d5b1c75d3 (diff) | |
download | gnunet-08edde13e140fe0fa7c4b00f6669ee396e00c2f5.tar.gz gnunet-08edde13e140fe0fa7c4b00f6669ee396e00c2f5.zip |
converting nse to new service api
Diffstat (limited to 'src/revocation')
-rw-r--r-- | src/revocation/gnunet-service-revocation.c | 174 |
1 files changed, 85 insertions, 89 deletions
diff --git a/src/revocation/gnunet-service-revocation.c b/src/revocation/gnunet-service-revocation.c index 706432ece..ad3253548 100644 --- a/src/revocation/gnunet-service-revocation.c +++ b/src/revocation/gnunet-service-revocation.c | |||
@@ -115,16 +115,6 @@ static struct GNUNET_CONTAINER_MultiPeerMap *peers; | |||
115 | static struct GNUNET_PeerIdentity my_identity; | 115 | static struct GNUNET_PeerIdentity my_identity; |
116 | 116 | ||
117 | /** | 117 | /** |
118 | * Handle to this serivce's server. | ||
119 | */ | ||
120 | static struct GNUNET_SERVER_Handle *srv; | ||
121 | |||
122 | /** | ||
123 | * Notification context for convenient sending of replies to the clients. | ||
124 | */ | ||
125 | static struct GNUNET_SERVER_NotificationContext *nc; | ||
126 | |||
127 | /** | ||
128 | * File handle for the revocation database. | 118 | * File handle for the revocation database. |
129 | */ | 119 | */ |
130 | static struct GNUNET_DISK_FileHandle *revocation_db; | 120 | static struct GNUNET_DISK_FileHandle *revocation_db; |
@@ -202,19 +192,51 @@ verify_revoke_message (const struct RevokeMessage *rm) | |||
202 | 192 | ||
203 | 193 | ||
204 | /** | 194 | /** |
195 | * Handle client connecting to the service. | ||
196 | * | ||
197 | * @param cls NULL | ||
198 | * @param client the new client | ||
199 | * @param mq the message queue of @a client | ||
200 | * @return @a client | ||
201 | */ | ||
202 | static void * | ||
203 | client_connect_cb (void *cls, | ||
204 | struct GNUNET_SERVICE_Client *client, | ||
205 | struct GNUNET_MQ_Handle *mq) | ||
206 | { | ||
207 | return client; | ||
208 | } | ||
209 | |||
210 | |||
211 | /** | ||
212 | * Handle client connecting to the service. | ||
213 | * | ||
214 | * @param cls NULL | ||
215 | * @param client the new client | ||
216 | * @param app_cls must alias @a client | ||
217 | */ | ||
218 | static void | ||
219 | client_disconnect_cb (void *cls, | ||
220 | struct GNUNET_SERVICE_Client *client, | ||
221 | void *app_cls) | ||
222 | { | ||
223 | GNUNET_assert (client == app_cls); | ||
224 | } | ||
225 | |||
226 | |||
227 | /** | ||
205 | * Handle QUERY message from client. | 228 | * Handle QUERY message from client. |
206 | * | 229 | * |
207 | * @param cls unused | 230 | * @param cls client who sent the message |
208 | * @param client who sent the message | 231 | * @param qm the message received |
209 | * @param message the message received | ||
210 | */ | 232 | */ |
211 | static void | 233 | static void |
212 | handle_query_message (void *cls, | 234 | handle_query_message (void *cls, |
213 | struct GNUNET_SERVER_Client *client, | 235 | const struct QueryMessage *qm) |
214 | const struct GNUNET_MessageHeader *message) | ||
215 | { | 236 | { |
216 | const struct QueryMessage *qm = (const struct QueryMessage *) message; | 237 | struct GNUNET_SERVICE_Client *client = cls; |
217 | struct QueryResponseMessage qrm; | 238 | struct GNUNET_MQ_Envelope *env; |
239 | struct QueryResponseMessage *qrm; | ||
218 | struct GNUNET_HashCode hc; | 240 | struct GNUNET_HashCode hc; |
219 | int res; | 241 | int res; |
220 | 242 | ||
@@ -228,17 +250,12 @@ handle_query_message (void *cls, | |||
228 | ? "Received revocation check for valid key `%s' from client\n" | 250 | ? "Received revocation check for valid key `%s' from client\n" |
229 | : "Received revocation check for revoked key `%s' from client\n", | 251 | : "Received revocation check for revoked key `%s' from client\n", |
230 | GNUNET_h2s (&hc)); | 252 | GNUNET_h2s (&hc)); |
231 | qrm.header.size = htons (sizeof (struct QueryResponseMessage)); | 253 | env = GNUNET_MQ_msg (qrm, |
232 | qrm.header.type = htons (GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE); | 254 | GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE); |
233 | qrm.is_valid = htonl ((GNUNET_YES == res) ? GNUNET_NO : GNUNET_YES); | 255 | qrm->is_valid = htonl ((GNUNET_YES == res) ? GNUNET_NO : GNUNET_YES); |
234 | GNUNET_SERVER_notification_context_add (nc, | 256 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), |
235 | client); | 257 | env); |
236 | GNUNET_SERVER_notification_context_unicast (nc, | 258 | GNUNET_SERVICE_client_continue (client); |
237 | client, | ||
238 | &qrm.header, | ||
239 | GNUNET_NO); | ||
240 | GNUNET_SERVER_receive_done (client, | ||
241 | GNUNET_OK); | ||
242 | } | 259 | } |
243 | 260 | ||
244 | 261 | ||
@@ -362,40 +379,32 @@ publicize_rm (const struct RevokeMessage *rm) | |||
362 | /** | 379 | /** |
363 | * Handle REVOKE message from client. | 380 | * Handle REVOKE message from client. |
364 | * | 381 | * |
365 | * @param cls unused | 382 | * @param cls client who sent the message |
366 | * @param client who sent the message | 383 | * @param rm the message received |
367 | * @param message the message received | ||
368 | */ | 384 | */ |
369 | static void | 385 | static void |
370 | handle_revoke_message (void *cls, | 386 | handle_revoke_message (void *cls, |
371 | struct GNUNET_SERVER_Client *client, | 387 | const struct RevokeMessage *rm) |
372 | const struct GNUNET_MessageHeader *message) | ||
373 | { | 388 | { |
374 | const struct RevokeMessage *rm; | 389 | struct GNUNET_SERVICE_Client *client = cls; |
375 | struct RevocationResponseMessage rrm; | 390 | struct GNUNET_MQ_Envelope *env; |
391 | struct RevocationResponseMessage *rrm; | ||
376 | int ret; | 392 | int ret; |
377 | 393 | ||
378 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 394 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
379 | "Received REVOKE message from client\n"); | 395 | "Received REVOKE message from client\n"); |
380 | rm = (const struct RevokeMessage *) message; | ||
381 | if (GNUNET_SYSERR == (ret = publicize_rm (rm))) | 396 | if (GNUNET_SYSERR == (ret = publicize_rm (rm))) |
382 | { | 397 | { |
383 | GNUNET_break_op (0); | 398 | GNUNET_break_op (0); |
384 | GNUNET_SERVER_receive_done (client, | 399 | GNUNET_SERVICE_client_drop (client); |
385 | GNUNET_SYSERR); | ||
386 | return; | 400 | return; |
387 | } | 401 | } |
388 | rrm.header.size = htons (sizeof (struct RevocationResponseMessage)); | 402 | env = GNUNET_MQ_msg (rrm, |
389 | rrm.header.type = htons (GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE); | 403 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE); |
390 | rrm.is_valid = htonl ((GNUNET_OK == ret) ? GNUNET_NO : GNUNET_YES); | 404 | rrm->is_valid = htonl ((GNUNET_OK == ret) ? GNUNET_NO : GNUNET_YES); |
391 | GNUNET_SERVER_notification_context_add (nc, | 405 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), |
392 | client); | 406 | env); |
393 | GNUNET_SERVER_notification_context_unicast (nc, | 407 | GNUNET_SERVICE_client_continue (client); |
394 | client, | ||
395 | &rrm.header, | ||
396 | GNUNET_NO); | ||
397 | GNUNET_SERVER_receive_done (client, | ||
398 | GNUNET_OK); | ||
399 | } | 408 | } |
400 | 409 | ||
401 | 410 | ||
@@ -674,11 +683,6 @@ shutdown_task (void *cls) | |||
674 | GNUNET_CONTAINER_multipeermap_destroy (peers); | 683 | GNUNET_CONTAINER_multipeermap_destroy (peers); |
675 | peers = NULL; | 684 | peers = NULL; |
676 | } | 685 | } |
677 | if (NULL != nc) | ||
678 | { | ||
679 | GNUNET_SERVER_notification_context_destroy (nc); | ||
680 | nc = NULL; | ||
681 | } | ||
682 | if (NULL != revocation_db) | 686 | if (NULL != revocation_db) |
683 | { | 687 | { |
684 | GNUNET_DISK_file_close (revocation_db); | 688 | GNUNET_DISK_file_close (revocation_db); |
@@ -774,16 +778,9 @@ handle_revocation_union_request (void *cls, | |||
774 | */ | 778 | */ |
775 | static void | 779 | static void |
776 | run (void *cls, | 780 | run (void *cls, |
777 | struct GNUNET_SERVER_Handle *server, | 781 | const struct GNUNET_CONFIGURATION_Handle *c, |
778 | const struct GNUNET_CONFIGURATION_Handle *c) | 782 | struct GNUNET_SERVICE_Handle *service) |
779 | { | 783 | { |
780 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | ||
781 | {&handle_query_message, NULL, GNUNET_MESSAGE_TYPE_REVOCATION_QUERY, | ||
782 | sizeof (struct QueryMessage)}, | ||
783 | {&handle_revoke_message, NULL, GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE, | ||
784 | sizeof (struct RevokeMessage)}, | ||
785 | {NULL, NULL, 0, 0} | ||
786 | }; | ||
787 | struct GNUNET_MQ_MessageHandler core_handlers[] = { | 784 | struct GNUNET_MQ_MessageHandler core_handlers[] = { |
788 | GNUNET_MQ_hd_fixed_size (p2p_revoke, | 785 | GNUNET_MQ_hd_fixed_size (p2p_revoke, |
789 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE, | 786 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE, |
@@ -796,6 +793,9 @@ run (void *cls, | |||
796 | struct RevokeMessage *rm; | 793 | struct RevokeMessage *rm; |
797 | struct GNUNET_HashCode hc; | 794 | struct GNUNET_HashCode hc; |
798 | 795 | ||
796 | GNUNET_CRYPTO_hash ("revocation-set-union-application-id", | ||
797 | strlen ("revocation-set-union-application-id"), | ||
798 | &revocation_set_union_app_id); | ||
799 | if (GNUNET_OK != | 799 | if (GNUNET_OK != |
800 | GNUNET_CONFIGURATION_get_value_filename (c, | 800 | GNUNET_CONFIGURATION_get_value_filename (c, |
801 | "REVOCATION", | 801 | "REVOCATION", |
@@ -809,10 +809,8 @@ run (void *cls, | |||
809 | return; | 809 | return; |
810 | } | 810 | } |
811 | cfg = c; | 811 | cfg = c; |
812 | srv = server; | ||
813 | revocation_map = GNUNET_CONTAINER_multihashmap_create (16, | 812 | revocation_map = GNUNET_CONTAINER_multihashmap_create (16, |
814 | GNUNET_NO); | 813 | GNUNET_NO); |
815 | nc = GNUNET_SERVER_notification_context_create (server, 1); | ||
816 | if (GNUNET_OK != | 814 | if (GNUNET_OK != |
817 | GNUNET_CONFIGURATION_get_value_number (cfg, | 815 | GNUNET_CONFIGURATION_get_value_number (cfg, |
818 | "REVOCATION", | 816 | "REVOCATION", |
@@ -895,8 +893,7 @@ run (void *cls, | |||
895 | NULL); | 893 | NULL); |
896 | peers = GNUNET_CONTAINER_multipeermap_create (128, | 894 | peers = GNUNET_CONTAINER_multipeermap_create (128, |
897 | GNUNET_YES); | 895 | GNUNET_YES); |
898 | GNUNET_SERVER_add_handlers (srv, handlers); | 896 | /* Connect to core service and register core handlers */ |
899 | /* Connect to core service and register core handlers */ | ||
900 | core_api = GNUNET_CORE_connecT (cfg, /* Main configuration */ | 897 | core_api = GNUNET_CORE_connecT (cfg, /* Main configuration */ |
901 | NULL, /* Closure passed to functions */ | 898 | NULL, /* Closure passed to functions */ |
902 | &core_init, /* Call core_init once connected */ | 899 | &core_init, /* Call core_init once connected */ |
@@ -908,47 +905,46 @@ run (void *cls, | |||
908 | GNUNET_SCHEDULER_shutdown (); | 905 | GNUNET_SCHEDULER_shutdown (); |
909 | return; | 906 | return; |
910 | } | 907 | } |
911 | stats = GNUNET_STATISTICS_create ("revocation", cfg); | 908 | stats = GNUNET_STATISTICS_create ("revocation", |
909 | cfg); | ||
912 | } | 910 | } |
913 | 911 | ||
914 | 912 | ||
915 | /** | 913 | /** |
916 | * The main function for the network size estimation service. | 914 | * Define "main" method using service macro. |
917 | * | ||
918 | * @param argc number of arguments from the command line | ||
919 | * @param argv command line arguments | ||
920 | * @return 0 ok, 1 on error | ||
921 | */ | 915 | */ |
922 | int | 916 | GNUNET_SERVICE_MAIN |
923 | main (int argc, | 917 | ("revocation", |
924 | char *const *argv) | 918 | GNUNET_SERVICE_OPTION_NONE, |
925 | { | 919 | &run, |
926 | GNUNET_CRYPTO_hash ("revocation-set-union-application-id", | 920 | &client_connect_cb, |
927 | strlen ("revocation-set-union-application-id"), | 921 | &client_disconnect_cb, |
928 | &revocation_set_union_app_id); | 922 | NULL, |
929 | return (GNUNET_OK == | 923 | GNUNET_MQ_hd_fixed_size (query_message, |
930 | GNUNET_SERVICE_run (argc, | 924 | GNUNET_MESSAGE_TYPE_REVOCATION_QUERY, |
931 | argv, | 925 | struct QueryMessage, |
932 | "revocation", | 926 | NULL), |
933 | GNUNET_SERVICE_OPTION_NONE, | 927 | GNUNET_MQ_hd_fixed_size (revoke_message, |
934 | &run, NULL)) ? 0 : 1; | 928 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE, |
935 | } | 929 | struct RevokeMessage, |
930 | NULL), | ||
931 | GNUNET_MQ_handler_end ()); | ||
936 | 932 | ||
937 | 933 | ||
938 | #if defined(LINUX) && defined(__GLIBC__) | 934 | #if defined(LINUX) && defined(__GLIBC__) |
939 | #include <malloc.h> | 935 | #include <malloc.h> |
940 | 936 | ||
941 | |||
942 | /** | 937 | /** |
943 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. | 938 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. |
944 | */ | 939 | */ |
945 | void __attribute__ ((constructor)) | 940 | void __attribute__ ((constructor)) |
946 | GNUNET_ARM_memory_init () | 941 | GNUNET_REVOCATION_memory_init () |
947 | { | 942 | { |
948 | mallopt (M_TRIM_THRESHOLD, 4 * 1024); | 943 | mallopt (M_TRIM_THRESHOLD, 4 * 1024); |
949 | mallopt (M_TOP_PAD, 1 * 1024); | 944 | mallopt (M_TOP_PAD, 1 * 1024); |
950 | malloc_trim (0); | 945 | malloc_trim (0); |
951 | } | 946 | } |
947 | |||
952 | #endif | 948 | #endif |
953 | 949 | ||
954 | 950 | ||