diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-31 15:42:37 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-31 15:42:37 +0000 |
commit | 406c7d2d2d126c994a1fff13470b1f96439c6f9d (patch) | |
tree | dc5e7c62a706d03cee32734a19e183b9eddf88e2 /src/revocation | |
parent | 8b2a3260e6aafc2ad31c8b7bff5f7d25b57bfc14 (diff) | |
download | gnunet-406c7d2d2d126c994a1fff13470b1f96439c6f9d.tar.gz gnunet-406c7d2d2d126c994a1fff13470b1f96439c6f9d.zip |
convering more services to new core MQ API
Diffstat (limited to 'src/revocation')
-rw-r--r-- | src/revocation/gnunet-service-revocation.c | 142 | ||||
-rw-r--r-- | src/revocation/test_revocation.c | 17 |
2 files changed, 74 insertions, 85 deletions
diff --git a/src/revocation/gnunet-service-revocation.c b/src/revocation/gnunet-service-revocation.c index 9f3162690..0f67977a1 100644 --- a/src/revocation/gnunet-service-revocation.c +++ b/src/revocation/gnunet-service-revocation.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2013, 2014 GNUnet e.V. | 3 | Copyright (C) 2013, 2014, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public Licerevocation as published | 6 | it under the terms of the GNU General Public Licerevocation as published |
@@ -68,7 +68,7 @@ struct PeerEntry | |||
68 | /** | 68 | /** |
69 | * Tasked used to trigger the set union operation. | 69 | * Tasked used to trigger the set union operation. |
70 | */ | 70 | */ |
71 | struct GNUNET_SCHEDULER_Task * transmit_task; | 71 | struct GNUNET_SCHEDULER_Task *transmit_task; |
72 | 72 | ||
73 | /** | 73 | /** |
74 | * Handle to active set union operation (over revocation sets). | 74 | * Handle to active set union operation (over revocation sets). |
@@ -164,44 +164,11 @@ new_peer_entry(const struct GNUNET_PeerIdentity *peer) | |||
164 | &peer_entry->id, | 164 | &peer_entry->id, |
165 | peer_entry, | 165 | peer_entry, |
166 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 166 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
167 | peer_entry->mq = GNUNET_CORE_mq_create (core_api, peer); | ||
168 | return peer_entry; | 167 | return peer_entry; |
169 | } | 168 | } |
170 | 169 | ||
171 | 170 | ||
172 | /** | 171 | /** |
173 | * Delete a PeerEntry for the given peer | ||
174 | * | ||
175 | * @param peer the identity of the peer to delete | ||
176 | */ | ||
177 | static void | ||
178 | delete_peer_entry(const struct GNUNET_PeerIdentity *peer) | ||
179 | { | ||
180 | struct PeerEntry *peer_entry; | ||
181 | |||
182 | peer_entry = GNUNET_CONTAINER_multipeermap_get (peers, | ||
183 | peer); | ||
184 | GNUNET_assert (NULL != peer_entry); | ||
185 | GNUNET_assert (GNUNET_YES == | ||
186 | GNUNET_CONTAINER_multipeermap_remove (peers, | ||
187 | peer, | ||
188 | peer_entry)); | ||
189 | GNUNET_MQ_destroy (peer_entry->mq); | ||
190 | if (NULL != peer_entry->transmit_task) | ||
191 | { | ||
192 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); | ||
193 | peer_entry->transmit_task = NULL; | ||
194 | } | ||
195 | if (NULL != peer_entry->so) | ||
196 | { | ||
197 | GNUNET_SET_operation_cancel (peer_entry->so); | ||
198 | peer_entry->so = NULL; | ||
199 | } | ||
200 | GNUNET_free (peer_entry); | ||
201 | } | ||
202 | |||
203 | |||
204 | /** | ||
205 | * An revoke message has been received, check that it is well-formed. | 172 | * An revoke message has been received, check that it is well-formed. |
206 | * | 173 | * |
207 | * @param rm the message to verify | 174 | * @param rm the message to verify |
@@ -293,6 +260,10 @@ do_flood (void *cls, | |||
293 | struct GNUNET_MQ_Envelope *e; | 260 | struct GNUNET_MQ_Envelope *e; |
294 | struct RevokeMessage *cp; | 261 | struct RevokeMessage *cp; |
295 | 262 | ||
263 | if (NULL == pe->mq) | ||
264 | return GNUNET_OK; /* peer connected to us via SET, | ||
265 | but we have no direct CORE | ||
266 | connection for flooding */ | ||
296 | e = GNUNET_MQ_msg (cp, | 267 | e = GNUNET_MQ_msg (cp, |
297 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE); | 268 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE); |
298 | *cp = *rm; | 269 | *cp = *rm; |
@@ -432,21 +403,16 @@ handle_revoke_message (void *cls, | |||
432 | * Core handler for flooded revocation messages. | 403 | * Core handler for flooded revocation messages. |
433 | * | 404 | * |
434 | * @param cls closure unused | 405 | * @param cls closure unused |
435 | * @param message message | 406 | * @param rm revocation message |
436 | * @param peer peer identity this message is from (ignored) | ||
437 | */ | 407 | */ |
438 | static int | 408 | static void |
439 | handle_p2p_revoke_message (void *cls, | 409 | handle_p2p_revoke (void *cls, |
440 | const struct GNUNET_PeerIdentity *peer, | 410 | const struct RevokeMessage *rm) |
441 | const struct GNUNET_MessageHeader *message) | ||
442 | { | 411 | { |
443 | const struct RevokeMessage *rm; | ||
444 | |||
445 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 412 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
446 | "Received REVOKE message from peer\n"); | 413 | "Received REVOKE message\n"); |
447 | rm = (const struct RevokeMessage *) message; | 414 | GNUNET_break_op (GNUNET_SYSERR != |
448 | GNUNET_break_op (GNUNET_SYSERR != publicize_rm (rm)); | 415 | publicize_rm (rm)); |
449 | return GNUNET_OK; | ||
450 | } | 416 | } |
451 | 417 | ||
452 | 418 | ||
@@ -483,9 +449,8 @@ add_revocation (void *cls, | |||
483 | return; | 449 | return; |
484 | } | 450 | } |
485 | rm = element->data; | 451 | rm = element->data; |
486 | (void) handle_p2p_revoke_message (NULL, | 452 | (void) handle_p2p_revoke (NULL, |
487 | &peer_entry->id, | 453 | rm); |
488 | &rm->header); | ||
489 | GNUNET_STATISTICS_update (stats, | 454 | GNUNET_STATISTICS_update (stats, |
490 | gettext_noop ("# revocation messages received via set union"), | 455 | gettext_noop ("# revocation messages received via set union"), |
491 | 1, GNUNET_NO); | 456 | 1, GNUNET_NO); |
@@ -556,9 +521,10 @@ transmit_task_cb (void *cls) | |||
556 | * @param cls closure | 521 | * @param cls closure |
557 | * @param peer peer identity this notification is about | 522 | * @param peer peer identity this notification is about |
558 | */ | 523 | */ |
559 | static void | 524 | static void * |
560 | handle_core_connect (void *cls, | 525 | handle_core_connect (void *cls, |
561 | const struct GNUNET_PeerIdentity *peer) | 526 | const struct GNUNET_PeerIdentity *peer, |
527 | struct GNUNET_MQ_Handle *mq) | ||
562 | { | 528 | { |
563 | struct PeerEntry *peer_entry; | 529 | struct PeerEntry *peer_entry; |
564 | struct GNUNET_HashCode my_hash; | 530 | struct GNUNET_HashCode my_hash; |
@@ -568,7 +534,7 @@ handle_core_connect (void *cls, | |||
568 | &my_identity, | 534 | &my_identity, |
569 | sizeof (my_identity))) | 535 | sizeof (my_identity))) |
570 | { | 536 | { |
571 | return; | 537 | return NULL; |
572 | } | 538 | } |
573 | 539 | ||
574 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 540 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -586,9 +552,11 @@ handle_core_connect (void *cls, | |||
586 | and CADET+SET were faster and already produced a | 552 | and CADET+SET were faster and already produced a |
587 | #handle_revocation_union_request() for us to deal | 553 | #handle_revocation_union_request() for us to deal |
588 | with. This should be rare, but isn't impossible. */ | 554 | with. This should be rare, but isn't impossible. */ |
589 | return; | 555 | peer_entry->mq = mq; |
556 | return peer_entry; | ||
590 | } | 557 | } |
591 | peer_entry = new_peer_entry(peer); | 558 | peer_entry = new_peer_entry (peer); |
559 | peer_entry->mq = mq; | ||
592 | GNUNET_CRYPTO_hash (&my_identity, | 560 | GNUNET_CRYPTO_hash (&my_identity, |
593 | sizeof (my_identity), | 561 | sizeof (my_identity), |
594 | &my_hash); | 562 | &my_hash); |
@@ -606,6 +574,7 @@ handle_core_connect (void *cls, | |||
606 | &transmit_task_cb, | 574 | &transmit_task_cb, |
607 | peer_entry); | 575 | peer_entry); |
608 | } | 576 | } |
577 | return peer_entry; | ||
609 | } | 578 | } |
610 | 579 | ||
611 | 580 | ||
@@ -615,22 +584,38 @@ handle_core_connect (void *cls, | |||
615 | * | 584 | * |
616 | * @param cls closure | 585 | * @param cls closure |
617 | * @param peer peer identity this notification is about | 586 | * @param peer peer identity this notification is about |
587 | * @param internal_cls our `struct PeerEntry` for this peer | ||
618 | */ | 588 | */ |
619 | static void | 589 | static void |
620 | handle_core_disconnect (void *cls, | 590 | handle_core_disconnect (void *cls, |
621 | const struct GNUNET_PeerIdentity *peer) | 591 | const struct GNUNET_PeerIdentity *peer, |
592 | void *internal_cls) | ||
622 | { | 593 | { |
594 | struct PeerEntry *peer_entry = internal_cls; | ||
595 | |||
623 | if (0 == memcmp (peer, | 596 | if (0 == memcmp (peer, |
624 | &my_identity, | 597 | &my_identity, |
625 | sizeof (my_identity))) | 598 | sizeof (my_identity))) |
626 | { | ||
627 | return; | 599 | return; |
628 | } | 600 | GNUNET_assert (NULL != peer_entry); |
629 | |||
630 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 601 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
631 | "Peer `%s' disconnected from us\n", | 602 | "Peer `%s' disconnected from us\n", |
632 | GNUNET_i2s (peer)); | 603 | GNUNET_i2s (peer)); |
633 | delete_peer_entry(peer); | 604 | GNUNET_assert (GNUNET_YES == |
605 | GNUNET_CONTAINER_multipeermap_remove (peers, | ||
606 | peer, | ||
607 | peer_entry)); | ||
608 | if (NULL != peer_entry->transmit_task) | ||
609 | { | ||
610 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); | ||
611 | peer_entry->transmit_task = NULL; | ||
612 | } | ||
613 | if (NULL != peer_entry->so) | ||
614 | { | ||
615 | GNUNET_SET_operation_cancel (peer_entry->so); | ||
616 | peer_entry->so = NULL; | ||
617 | } | ||
618 | GNUNET_free (peer_entry); | ||
634 | GNUNET_STATISTICS_update (stats, | 619 | GNUNET_STATISTICS_update (stats, |
635 | "# peers connected", | 620 | "# peers connected", |
636 | -1, | 621 | -1, |
@@ -676,7 +661,7 @@ shutdown_task (void *cls) | |||
676 | } | 661 | } |
677 | if (NULL != core_api) | 662 | if (NULL != core_api) |
678 | { | 663 | { |
679 | GNUNET_CORE_disconnect (core_api); | 664 | GNUNET_CORE_disconnecT (core_api); |
680 | core_api = NULL; | 665 | core_api = NULL; |
681 | } | 666 | } |
682 | if (NULL != stats) | 667 | if (NULL != stats) |
@@ -762,7 +747,7 @@ handle_revocation_union_request (void *cls, | |||
762 | other_peer); | 747 | other_peer); |
763 | if (NULL == peer_entry) | 748 | if (NULL == peer_entry) |
764 | { | 749 | { |
765 | peer_entry = new_peer_entry(other_peer); | 750 | peer_entry = new_peer_entry (other_peer); |
766 | } | 751 | } |
767 | peer_entry->so = GNUNET_SET_accept (request, | 752 | peer_entry->so = GNUNET_SET_accept (request, |
768 | GNUNET_SET_RESULT_ADDED, | 753 | GNUNET_SET_RESULT_ADDED, |
@@ -792,6 +777,9 @@ run (void *cls, | |||
792 | struct GNUNET_SERVER_Handle *server, | 777 | struct GNUNET_SERVER_Handle *server, |
793 | const struct GNUNET_CONFIGURATION_Handle *c) | 778 | const struct GNUNET_CONFIGURATION_Handle *c) |
794 | { | 779 | { |
780 | GNUNET_MQ_hd_fixed_size (p2p_revoke, | ||
781 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE, | ||
782 | struct RevokeMessage); | ||
795 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 783 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
796 | {&handle_query_message, NULL, GNUNET_MESSAGE_TYPE_REVOCATION_QUERY, | 784 | {&handle_query_message, NULL, GNUNET_MESSAGE_TYPE_REVOCATION_QUERY, |
797 | sizeof (struct QueryMessage)}, | 785 | sizeof (struct QueryMessage)}, |
@@ -799,10 +787,9 @@ run (void *cls, | |||
799 | sizeof (struct RevokeMessage)}, | 787 | sizeof (struct RevokeMessage)}, |
800 | {NULL, NULL, 0, 0} | 788 | {NULL, NULL, 0, 0} |
801 | }; | 789 | }; |
802 | static const struct GNUNET_CORE_MessageHandler core_handlers[] = { | 790 | struct GNUNET_MQ_MessageHandler core_handlers[] = { |
803 | {&handle_p2p_revoke_message, GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE, | 791 | make_p2p_revoke_handler (NULL), |
804 | sizeof (struct RevokeMessage)}, | 792 | GNUNET_MQ_handler_end () |
805 | {NULL, 0, 0} | ||
806 | }; | 793 | }; |
807 | char *fn; | 794 | char *fn; |
808 | uint64_t left; | 795 | uint64_t left; |
@@ -823,10 +810,13 @@ run (void *cls, | |||
823 | } | 810 | } |
824 | cfg = c; | 811 | cfg = c; |
825 | srv = server; | 812 | srv = server; |
826 | revocation_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_NO); | 813 | revocation_map = GNUNET_CONTAINER_multihashmap_create (16, |
814 | GNUNET_NO); | ||
827 | nc = GNUNET_SERVER_notification_context_create (server, 1); | 815 | nc = GNUNET_SERVER_notification_context_create (server, 1); |
828 | if (GNUNET_OK != | 816 | if (GNUNET_OK != |
829 | GNUNET_CONFIGURATION_get_value_number (cfg, "REVOCATION", "WORKBITS", | 817 | GNUNET_CONFIGURATION_get_value_number (cfg, |
818 | "REVOCATION", | ||
819 | "WORKBITS", | ||
830 | &revocation_work_required)) | 820 | &revocation_work_required)) |
831 | { | 821 | { |
832 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 822 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
@@ -907,16 +897,12 @@ run (void *cls, | |||
907 | GNUNET_YES); | 897 | GNUNET_YES); |
908 | GNUNET_SERVER_add_handlers (srv, handlers); | 898 | GNUNET_SERVER_add_handlers (srv, handlers); |
909 | /* Connect to core service and register core handlers */ | 899 | /* Connect to core service and register core handlers */ |
910 | core_api = GNUNET_CORE_connect (cfg, /* Main configuration */ | 900 | core_api = GNUNET_CORE_connecT (cfg, /* Main configuration */ |
911 | NULL, /* Closure passed to functions */ | 901 | NULL, /* Closure passed to functions */ |
912 | &core_init, /* Call core_init once connected */ | 902 | &core_init, /* Call core_init once connected */ |
913 | &handle_core_connect, /* Handle connects */ | 903 | &handle_core_connect, /* Handle connects */ |
914 | &handle_core_disconnect, /* Handle disconnects */ | 904 | &handle_core_disconnect, /* Handle disconnects */ |
915 | NULL, /* Don't want notified about all incoming messages */ | 905 | core_handlers); /* Register these handlers */ |
916 | GNUNET_NO, /* For header only inbound notification */ | ||
917 | NULL, /* Don't want notified about all outbound messages */ | ||
918 | GNUNET_NO, /* For header only outbound notification */ | ||
919 | core_handlers); /* Register these handlers */ | ||
920 | if (NULL == core_api) | 906 | if (NULL == core_api) |
921 | { | 907 | { |
922 | GNUNET_SCHEDULER_shutdown (); | 908 | GNUNET_SCHEDULER_shutdown (); |
diff --git a/src/revocation/test_revocation.c b/src/revocation/test_revocation.c index e63486c8d..ba659d9d8 100644 --- a/src/revocation/test_revocation.c +++ b/src/revocation/test_revocation.c | |||
@@ -280,9 +280,10 @@ identity_disconnect_adapter (void *cls, | |||
280 | } | 280 | } |
281 | 281 | ||
282 | 282 | ||
283 | static void | 283 | static void * |
284 | connect_cb (void *cls, | 284 | connect_cb (void *cls, |
285 | const struct GNUNET_PeerIdentity *peer) | 285 | const struct GNUNET_PeerIdentity *peer, |
286 | struct GNUNET_MQ_Handle *mq) | ||
286 | { | 287 | { |
287 | static int connects = 0; | 288 | static int connects = 0; |
288 | 289 | ||
@@ -308,6 +309,7 @@ connect_cb (void *cls, | |||
308 | &identity_disconnect_adapter, | 309 | &identity_disconnect_adapter, |
309 | &testpeers[1]); | 310 | &testpeers[1]); |
310 | } | 311 | } |
312 | return NULL; | ||
311 | } | 313 | } |
312 | 314 | ||
313 | 315 | ||
@@ -335,10 +337,11 @@ core_connect_adapter (void *cls, | |||
335 | struct TestPeer *me = cls; | 337 | struct TestPeer *me = cls; |
336 | 338 | ||
337 | me->cfg = cfg; | 339 | me->cfg = cfg; |
338 | me->ch = GNUNET_CORE_connect (cfg, me, NULL, | 340 | me->ch = GNUNET_CORE_connecT (cfg, |
339 | &connect_cb, NULL, | 341 | me, |
340 | NULL, GNUNET_NO, | 342 | NULL, |
341 | NULL, GNUNET_NO, | 343 | &connect_cb, |
344 | NULL, | ||
342 | NULL); | 345 | NULL); |
343 | if (NULL == me->ch) | 346 | if (NULL == me->ch) |
344 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 347 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
@@ -353,7 +356,7 @@ core_disconnect_adapter (void *cls, | |||
353 | { | 356 | { |
354 | struct TestPeer *me = cls; | 357 | struct TestPeer *me = cls; |
355 | 358 | ||
356 | GNUNET_CORE_disconnect (me->ch); | 359 | GNUNET_CORE_disconnecT (me->ch); |
357 | me->ch = NULL; | 360 | me->ch = NULL; |
358 | } | 361 | } |
359 | 362 | ||