aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim/gnunet-service-reclaim.c
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2019-04-12 16:34:16 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2019-04-14 10:01:23 +0200
commitdfe11b6b541b47c85cdf56e55ebb816d6793db31 (patch)
treeb1c05be186902b4e510ab803e489094402b8149a /src/reclaim/gnunet-service-reclaim.c
parenta12b8c2c4cbf952c8c305cde193bb25c13a0912b (diff)
downloadgnunet-dfe11b6b541b47c85cdf56e55ebb816d6793db31.tar.gz
gnunet-dfe11b6b541b47c85cdf56e55ebb816d6793db31.zip
RECLAIM: Towards -sql
Diffstat (limited to 'src/reclaim/gnunet-service-reclaim.c')
-rw-r--r--src/reclaim/gnunet-service-reclaim.c168
1 files changed, 26 insertions, 142 deletions
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c
index b963b0a9b..634de0dfe 100644
--- a/src/reclaim/gnunet-service-reclaim.c
+++ b/src/reclaim/gnunet-service-reclaim.c
@@ -135,29 +135,14 @@ struct TicketIteration
135 struct IdpClient *client; 135 struct IdpClient *client;
136 136
137 /** 137 /**
138 * Key of the identity we are iterating over.
139 */
140 struct GNUNET_CRYPTO_EcdsaPublicKey identity;
141
142 /**
143 * Identity is audience
144 */
145 uint32_t is_audience;
146
147 /**
148 * The operation id fot the iteration in the response for the client 138 * The operation id fot the iteration in the response for the client
149 */ 139 */
150 uint32_t r_id; 140 uint32_t r_id;
151 141
152 /** 142 /**
153 * Offset of the iteration used to address next result of the 143 * The ticket iterator
154 * iteration in the store
155 *
156 * Initialy set to 0 in handle_iteration_start
157 * Incremented with by every call to handle_iteration_next
158 */ 144 */
159 uint32_t offset; 145 struct RECLAIM_TICKETS_Iterator *iter;
160
161}; 146};
162 147
163 148
@@ -592,6 +577,7 @@ cleanup()
592 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
593 "Cleaning up\n"); 578 "Cleaning up\n");
594 579
580 RECLAIM_TICKETS_deinit ();
595 if (NULL != stats) 581 if (NULL != stats)
596 { 582 {
597 GNUNET_STATISTICS_destroy (stats, GNUNET_NO); 583 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
@@ -1870,134 +1856,32 @@ handle_iteration_next (void *cls,
1870 GNUNET_SERVICE_client_continue (idp->client); 1856 GNUNET_SERVICE_client_continue (idp->client);
1871} 1857}
1872 1858
1873/**
1874 * Ticket iteration processor result
1875 */
1876enum ZoneIterationResult
1877{
1878 /**
1879 * Iteration start.
1880 */
1881 IT_START = 0,
1882
1883 /**
1884 * Found tickets,
1885 * Continue to iterate with next iteration_next call
1886 */
1887 IT_SUCCESS_MORE_AVAILABLE = 1,
1888
1889 /**
1890 * Iteration complete
1891 */
1892 IT_SUCCESS_NOT_MORE_RESULTS_AVAILABLE = 2
1893};
1894
1895
1896/**
1897 * Context for ticket iteration
1898 */
1899struct TicketIterationProcResult
1900{
1901 /**
1902 * The ticket iteration handle
1903 */
1904 struct TicketIteration *ti;
1905
1906 /**
1907 * Iteration result: iteration done?
1908 * #IT_SUCCESS_MORE_AVAILABLE: if there may be more results overall but
1909 * we got one for now and have sent it to the client
1910 * #IT_SUCCESS_NOT_MORE_RESULTS_AVAILABLE: if there are no further results,
1911 * #IT_START: if we are still trying to find a result.
1912 */
1913 int res_iteration_finished;
1914
1915};
1916
1917static void 1859static void
1918cleanup_ticket_iter_handle (struct TicketIteration *ti) 1860ticket_iter_cb (void *cls,
1861 struct GNUNET_RECLAIM_Ticket *ticket)
1919{ 1862{
1920 GNUNET_free (ti); 1863 struct TicketIteration *ti = cls;
1921}
1922
1923/**
1924 * Process ticket from database
1925 *
1926 * @param cls struct TicketIterationProcResult
1927 * @param ticket the ticket
1928 * @param attrs the attributes
1929 */
1930static void
1931ticket_iterate_proc (void *cls,
1932 const struct GNUNET_RECLAIM_Ticket *ticket,
1933 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs)
1934{
1935 struct TicketIterationProcResult *proc = cls;
1936
1937 if (NULL == ticket)
1938 {
1939 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1940 "Iteration done\n");
1941 proc->res_iteration_finished = IT_SUCCESS_NOT_MORE_RESULTS_AVAILABLE;
1942 return;
1943 }
1944 proc->res_iteration_finished = IT_SUCCESS_MORE_AVAILABLE;
1945 send_ticket_result (proc->ti->client,
1946 proc->ti->r_id,
1947 ticket,
1948 GNUNET_OK);
1949
1950}
1951
1952/**
1953 * Perform ticket iteration step
1954 *
1955 * @param ti ticket iterator to process
1956 */
1957static void
1958run_ticket_iteration_round (struct TicketIteration *ti)
1959{
1960 struct TicketIterationProcResult proc;
1961 struct GNUNET_MQ_Envelope *env; 1864 struct GNUNET_MQ_Envelope *env;
1962 struct TicketResultMessage *trm; 1865 struct TicketResultMessage *trm;
1963 int ret;
1964 1866
1965 memset (&proc, 0, sizeof (proc)); 1867 if (NULL == ticket)
1966 proc.ti = ti;
1967 proc.res_iteration_finished = IT_START;
1968 while (IT_START == proc.res_iteration_finished)
1969 {
1970 if (GNUNET_SYSERR ==
1971 (ret = TKT_database->iterate_tickets (TKT_database->cls,
1972 &ti->identity,
1973 ti->is_audience,
1974 ti->offset,
1975 &ticket_iterate_proc,
1976 &proc)))
1977 {
1978 GNUNET_break (0);
1979 break;
1980 }
1981 if (GNUNET_NO == ret)
1982 proc.res_iteration_finished = IT_SUCCESS_NOT_MORE_RESULTS_AVAILABLE;
1983 ti->offset++;
1984 }
1985 if (IT_SUCCESS_MORE_AVAILABLE == proc.res_iteration_finished)
1986 { 1868 {
1987 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1869 /* send empty response to indicate end of list */
1988 "More results available\n"); 1870 env = GNUNET_MQ_msg (trm,
1989 return; /* more later */ 1871 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT);
1872 GNUNET_CONTAINER_DLL_remove (ti->client->ticket_iter_head,
1873 ti->client->ticket_iter_tail,
1874 ti);
1875 } else {
1876 env = GNUNET_MQ_msg_extra (trm,
1877 sizeof (struct GNUNET_RECLAIM_Ticket),
1878 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT);
1990 } 1879 }
1991 /* send empty response to indicate end of list */
1992 env = GNUNET_MQ_msg (trm,
1993 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT);
1994 trm->id = htonl (ti->r_id); 1880 trm->id = htonl (ti->r_id);
1995 GNUNET_MQ_send (ti->client->mq, 1881 GNUNET_MQ_send (ti->client->mq,
1996 env); 1882 env);
1997 GNUNET_CONTAINER_DLL_remove (ti->client->ticket_iter_head, 1883 if (NULL == ticket)
1998 ti->client->ticket_iter_tail, 1884 GNUNET_free (ti);
1999 ti);
2000 cleanup_ticket_iter_handle (ti);
2001} 1885}
2002 1886
2003static void 1887static void
@@ -2011,15 +1895,14 @@ handle_ticket_iteration_start (void *cls,
2011 "Received TICKET_ITERATION_START message\n"); 1895 "Received TICKET_ITERATION_START message\n");
2012 ti = GNUNET_new (struct TicketIteration); 1896 ti = GNUNET_new (struct TicketIteration);
2013 ti->r_id = ntohl (tis_msg->id); 1897 ti->r_id = ntohl (tis_msg->id);
2014 ti->offset = 0;
2015 ti->client = client; 1898 ti->client = client;
2016 ti->identity = tis_msg->identity;
2017 ti->is_audience = ntohl (tis_msg->is_audience);
2018 1899
2019 GNUNET_CONTAINER_DLL_insert (client->ticket_iter_head, 1900 GNUNET_CONTAINER_DLL_insert (client->ticket_iter_head,
2020 client->ticket_iter_tail, 1901 client->ticket_iter_tail,
2021 ti); 1902 ti);
2022 run_ticket_iteration_round (ti); 1903 ti->iter = RECLAIM_TICKETS_iteration_start (&tis_msg->identity,
1904 &ticket_iter_cb,
1905 ti);
2023 GNUNET_SERVICE_client_continue (client->client); 1906 GNUNET_SERVICE_client_continue (client->client);
2024} 1907}
2025 1908
@@ -2045,10 +1928,11 @@ handle_ticket_iteration_stop (void *cls,
2045 GNUNET_SERVICE_client_drop (client->client); 1928 GNUNET_SERVICE_client_drop (client->client);
2046 return; 1929 return;
2047 } 1930 }
1931 RECLAIM_TICKETS_iteration_stop (ti->iter);
2048 GNUNET_CONTAINER_DLL_remove (client->ticket_iter_head, 1932 GNUNET_CONTAINER_DLL_remove (client->ticket_iter_head,
2049 client->ticket_iter_tail, 1933 client->ticket_iter_tail,
2050 ti); 1934 ti);
2051 cleanup_ticket_iter_handle (ti); 1935 GNUNET_free (ti);
2052 GNUNET_SERVICE_client_continue (client->client); 1936 GNUNET_SERVICE_client_continue (client->client);
2053} 1937}
2054 1938
@@ -2073,7 +1957,7 @@ handle_ticket_iteration_next (void *cls,
2073 GNUNET_SERVICE_client_drop (client->client); 1957 GNUNET_SERVICE_client_drop (client->client);
2074 return; 1958 return;
2075 } 1959 }
2076 run_ticket_iteration_round (ti); 1960 RECLAIM_TICKETS_iteration_next (ti->iter);
2077 GNUNET_SERVICE_client_continue (client->client); 1961 GNUNET_SERVICE_client_continue (client->client);
2078} 1962}
2079 1963
@@ -2226,7 +2110,7 @@ client_disconnect_cb (void *cls,
2226 GNUNET_CONTAINER_DLL_remove (idp->ticket_iter_head, 2110 GNUNET_CONTAINER_DLL_remove (idp->ticket_iter_head,
2227 idp->ticket_iter_tail, 2111 idp->ticket_iter_tail,
2228 ti); 2112 ti);
2229 cleanup_ticket_iter_handle (ti); 2113 GNUNET_free (ti);
2230 } 2114 }
2231 GNUNET_free (idp); 2115 GNUNET_free (idp);
2232} 2116}