aboutsummaryrefslogtreecommitdiff
path: root/src/exchange/taler-exchange-httpd_keys.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/exchange/taler-exchange-httpd_keys.c')
-rw-r--r--src/exchange/taler-exchange-httpd_keys.c62
1 files changed, 60 insertions, 2 deletions
diff --git a/src/exchange/taler-exchange-httpd_keys.c b/src/exchange/taler-exchange-httpd_keys.c
index 3b5616345..5d25600c4 100644
--- a/src/exchange/taler-exchange-httpd_keys.c
+++ b/src/exchange/taler-exchange-httpd_keys.c
@@ -21,6 +21,7 @@
21#include "platform.h" 21#include "platform.h"
22#include "taler_json_lib.h" 22#include "taler_json_lib.h"
23#include "taler_mhd_lib.h" 23#include "taler_mhd_lib.h"
24#include "taler_dbevents.h"
24#include "taler-exchange-httpd.h" 25#include "taler-exchange-httpd.h"
25#include "taler-exchange-httpd_keys.h" 26#include "taler-exchange-httpd_keys.h"
26#include "taler-exchange-httpd_responses.h" 27#include "taler-exchange-httpd_responses.h"
@@ -350,6 +351,12 @@ static struct TEH_KeyStateHandle *key_state;
350static uint64_t key_generation; 351static uint64_t key_generation;
351 352
352/** 353/**
354 * Handler listening for wire updates by other exchange
355 * services.
356 */
357static struct GNUNET_DB_EventHandler *keys_eh;
358
359/**
353 * Head of DLL of suspended /keys requests. 360 * Head of DLL of suspended /keys requests.
354 */ 361 */
355static struct SuspendedKeysRequests *skr_head; 362static struct SuspendedKeysRequests *skr_head;
@@ -867,9 +874,35 @@ destroy_key_state (struct TEH_KeyStateHandle *ksh,
867} 874}
868 875
869 876
870int 877/**
878 * Function called whenever another exchange process has updated
879 * the keys data in the database.
880 *
881 * @param cls NULL
882 * @param extra unused
883 * @param extra_size number of bytes in @a extra unused
884 */
885static void
886keys_update_event_cb (void *cls,
887 const void *extra,
888 size_t extra_size)
889{
890 (void) cls;
891 (void) extra;
892 (void) extra_size;
893 key_generation++;
894 TEH_resume_keys_requests (false);
895}
896
897
898enum GNUNET_GenericReturnValue
871TEH_keys_init () 899TEH_keys_init ()
872{ 900{
901 struct GNUNET_DB_EventHeaderP es = {
902 .size = htons (sizeof (es)),
903 .type = htons (TALER_DBEVENT_EXCHANGE_KEYS_UPDATED),
904 };
905
873 if (GNUNET_OK != 906 if (GNUNET_OK !=
874 GNUNET_CONFIGURATION_get_value_time (TEH_cfg, 907 GNUNET_CONFIGURATION_get_value_time (TEH_cfg,
875 "exchange", 908 "exchange",
@@ -881,6 +914,16 @@ TEH_keys_init ()
881 "SIGNKEY_LEGAL_DURATION"); 914 "SIGNKEY_LEGAL_DURATION");
882 return GNUNET_SYSERR; 915 return GNUNET_SYSERR;
883 } 916 }
917 keys_eh = TEH_plugin->event_listen (TEH_plugin->cls,
918 GNUNET_TIME_UNIT_FOREVER_REL,
919 &es,
920 &keys_update_event_cb,
921 NULL);
922 if (NULL == keys_eh)
923 {
924 GNUNET_break (0);
925 return GNUNET_SYSERR;
926 }
884 return GNUNET_OK; 927 return GNUNET_OK;
885} 928}
886 929
@@ -888,12 +931,18 @@ TEH_keys_init ()
888/** 931/**
889 * Fully clean up our state. 932 * Fully clean up our state.
890 */ 933 */
891void __attribute__ ((destructor)) 934void
892TEH_keys_finished () 935TEH_keys_finished ()
893{ 936{
894 if (NULL != key_state) 937 if (NULL != key_state)
895 destroy_key_state (key_state, 938 destroy_key_state (key_state,
896 true); 939 true);
940 if (NULL != keys_eh)
941 {
942 TEH_plugin->event_listen_cancel (TEH_plugin->cls,
943 keys_eh);
944 keys_eh = NULL;
945 }
897} 946}
898 947
899 948
@@ -1719,6 +1768,15 @@ build_key_state (struct HelperState *hs,
1719void 1768void
1720TEH_keys_update_states () 1769TEH_keys_update_states ()
1721{ 1770{
1771 struct GNUNET_DB_EventHeaderP es = {
1772 .size = htons (sizeof (es)),
1773 .type = htons (TALER_DBEVENT_EXCHANGE_KEYS_UPDATED),
1774 };
1775
1776 TEH_plugin->event_notify (TEH_plugin->cls,
1777 &es,
1778 NULL,
1779 0);
1722 key_generation++; 1780 key_generation++;
1723 TEH_resume_keys_requests (false); 1781 TEH_resume_keys_requests (false);
1724} 1782}