aboutsummaryrefslogtreecommitdiff
path: root/src/datastore
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-10-24 21:45:44 +0000
committerChristian Grothoff <christian@grothoff.org>2009-10-24 21:45:44 +0000
commit47d7779091557516cda70ab9038dc2d460b0b3bb (patch)
tree2c8a334a40268d8b3717332a9d7278909830fab7 /src/datastore
parent267b8b5e0e264627f334a18ae1bf3f3a88ff2e32 (diff)
downloadgnunet-47d7779091557516cda70ab9038dc2d460b0b3bb.tar.gz
gnunet-47d7779091557516cda70ab9038dc2d460b0b3bb.zip
giving client API option for auto-retry, making more often use of transmit_and_get_response API and removing auto-retry code where enhanced client API can be used for it
Diffstat (limited to 'src/datastore')
-rw-r--r--src/datastore/Makefile.am1
-rw-r--r--src/datastore/datastore_api.c132
-rw-r--r--src/datastore/perf_datastore_api.c4
-rw-r--r--src/datastore/test_datastore_api.c4
-rw-r--r--src/datastore/test_datastore_api_data.conf17
-rw-r--r--src/datastore/test_datastore_api_management.c4
6 files changed, 47 insertions, 115 deletions
diff --git a/src/datastore/Makefile.am b/src/datastore/Makefile.am
index e4de8fcfa..b9d8ec38f 100644
--- a/src/datastore/Makefile.am
+++ b/src/datastore/Makefile.am
@@ -18,6 +18,7 @@ lib_LTLIBRARIES = \
18libgnunetdatastore_la_SOURCES = \ 18libgnunetdatastore_la_SOURCES = \
19 datastore_api.c datastore.h plugin_datastore.h 19 datastore_api.c datastore.h plugin_datastore.h
20libgnunetdatastore_la_LIBADD = \ 20libgnunetdatastore_la_LIBADD = \
21 $(top_builddir)/src/arm/libgnunetarm.la \
21 $(top_builddir)/src/util/libgnunetutil.la \ 22 $(top_builddir)/src/util/libgnunetutil.la \
22 $(GN_LIBINTL) 23 $(GN_LIBINTL)
23libgnunetdatastore_la_LDFLAGS = \ 24libgnunetdatastore_la_LDFLAGS = \
diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c
index f6d7480de..a9058fa04 100644
--- a/src/datastore/datastore_api.c
+++ b/src/datastore/datastore_api.c
@@ -24,6 +24,7 @@
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_arm_service.h"
27#include "gnunet_datastore_service.h" 28#include "gnunet_datastore_service.h"
28#include "datastore.h" 29#include "datastore.h"
29 30
@@ -75,6 +76,7 @@ struct GNUNET_DATASTORE_Handle
75}; 76};
76 77
77 78
79
78/** 80/**
79 * Connect to the datastore service. 81 * Connect to the datastore service.
80 * 82 *
@@ -95,6 +97,7 @@ struct GNUNET_DATASTORE_Handle *GNUNET_DATASTORE_connect (const struct
95 c = GNUNET_CLIENT_connect (sched, "datastore", cfg); 97 c = GNUNET_CLIENT_connect (sched, "datastore", cfg);
96 if (c == NULL) 98 if (c == NULL)
97 return NULL; /* oops */ 99 return NULL; /* oops */
100 GNUNET_ARM_start_services (cfg, sched, "datastore", NULL);
98 h = GNUNET_malloc (sizeof(struct GNUNET_DATASTORE_Handle) + 101 h = GNUNET_malloc (sizeof(struct GNUNET_DATASTORE_Handle) +
99 GNUNET_SERVER_MAX_MESSAGE_SIZE); 102 GNUNET_SERVER_MAX_MESSAGE_SIZE);
100 h->client = c; 103 h->client = c;
@@ -149,6 +152,7 @@ void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
149 GNUNET_CLIENT_notify_transmit_ready (h->client, 152 GNUNET_CLIENT_notify_transmit_ready (h->client,
150 sizeof(struct GNUNET_MessageHeader), 153 sizeof(struct GNUNET_MessageHeader),
151 GNUNET_TIME_UNIT_MINUTES, 154 GNUNET_TIME_UNIT_MINUTES,
155 GNUNET_YES,
152 &transmit_drop, 156 &transmit_drop,
153 h)) 157 h))
154 return; 158 return;
@@ -156,6 +160,7 @@ void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
156 } 160 }
157 if (h->client != NULL) 161 if (h->client != NULL)
158 GNUNET_CLIENT_disconnect (h->client); 162 GNUNET_CLIENT_disconnect (h->client);
163 GNUNET_ARM_stop_services (h->cfg, h->sched, "datastore", NULL);
159 GNUNET_free (h); 164 GNUNET_free (h);
160} 165}
161 166
@@ -233,51 +238,6 @@ with_status_response_handler (void *cls,
233 238
234 239
235/** 240/**
236 * Transmit message to datastore service and then
237 * read a status message.
238 *
239 * @param cls closure with handle to datastore
240 * @param size number of bytes we can transmit at most
241 * @param buf where to write transmission, NULL on
242 * timeout
243 * @return number of bytes copied to buf
244 */
245static size_t
246transmit_get_status (void *cls,
247 size_t size,
248 void *buf)
249{
250 struct GNUNET_DATASTORE_Handle *h = cls;
251 GNUNET_DATASTORE_ContinuationWithStatus cont = h->response_proc;
252 uint16_t msize;
253
254 if (buf == NULL)
255 {
256 h->message_size = 0;
257 h->response_proc = NULL;
258 cont (h->response_proc_cls,
259 GNUNET_SYSERR,
260 _("Error transmitting message to datastore service."));
261 return 0;
262 }
263 msize = h->message_size;
264 GNUNET_assert (msize <= size);
265 memcpy (buf, &h[1], msize);
266#if DEBUG_DATASTORE
267 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
268 "Transmitted %u byte message to datastore service, now waiting for status.\n",
269 msize);
270#endif
271 h->message_size = 0;
272 GNUNET_CLIENT_receive (h->client,
273 &with_status_response_handler,
274 h,
275 GNUNET_TIME_absolute_get_remaining (h->timeout));
276 return msize;
277}
278
279
280/**
281 * Helper function that will initiate the 241 * Helper function that will initiate the
282 * transmission of a message to the datastore 242 * transmission of a message to the datastore
283 * service. The message must already be prepared 243 * service. The message must already be prepared
@@ -313,11 +273,13 @@ transmit_for_status (struct GNUNET_DATASTORE_Handle *h,
313 h->response_proc_cls = cont_cls; 273 h->response_proc_cls = cont_cls;
314 h->timeout = GNUNET_TIME_relative_to_absolute (timeout); 274 h->timeout = GNUNET_TIME_relative_to_absolute (timeout);
315 h->message_size = msize; 275 h->message_size = msize;
316 if (NULL == GNUNET_CLIENT_notify_transmit_ready (h->client, 276 if (GNUNET_OK !=
317 msize, 277 GNUNET_CLIENT_transmit_and_get_response (h->client,
318 timeout, 278 hdr,
319 &transmit_get_status, 279 timeout,
320 h)) 280 GNUNET_YES,
281 &with_status_response_handler,
282 h))
321 { 283 {
322 GNUNET_break (0); 284 GNUNET_break (0);
323 h->response_proc = NULL; 285 h->response_proc = NULL;
@@ -571,54 +533,6 @@ with_result_response_handler (void *cls,
571 533
572 534
573/** 535/**
574 * Transmit message to datastore service and then
575 * read a result message.
576 *
577 * @param cls closure with handle to datastore
578 * @param size number of bytes we can transmit at most
579 * @param buf where to write transmission, NULL on
580 * timeout
581 * @return number of bytes copied to buf
582 */
583static size_t
584transmit_get_result (void *cls,
585 size_t size,
586 void *buf)
587{
588 struct GNUNET_DATASTORE_Handle *h = cls;
589 GNUNET_DATASTORE_Iterator cont = h->response_proc;
590 uint16_t msize;
591
592 if (buf == NULL)
593 {
594 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
595 _("Error transmitting message to datastore service.\n"));
596 h->response_proc = NULL;
597 h->message_size = 0;
598 cont (h->response_proc_cls,
599 NULL, 0, NULL, 0, 0, 0,
600 GNUNET_TIME_UNIT_ZERO_ABS, 0);
601 return 0;
602 }
603 msize = h->message_size;
604 GNUNET_assert (msize <= size);
605 memcpy (buf, &h[1], msize);
606#if DEBUG_DATASTORE
607 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
608 "Transmitted %u byte message to datastore service, now waiting for result.\n",
609 msize);
610#endif
611 h->message_size = 0;
612 GNUNET_CLIENT_receive (h->client,
613 &with_result_response_handler,
614 h,
615 GNUNET_TIME_absolute_get_remaining (h->timeout));
616 return msize;
617}
618
619
620
621/**
622 * Function called to trigger obtaining the next result 536 * Function called to trigger obtaining the next result
623 * from the datastore. 537 * from the datastore.
624 * 538 *
@@ -651,12 +565,10 @@ GNUNET_DATASTORE_get_next (struct GNUNET_DATASTORE_Handle *h,
651 565
652 566
653/** 567/**
654 * Helper function that will initiate the 568 * Helper function that will initiate the transmission of a message to
655 * transmission of a message to the datastore 569 * the datastore service. The message must already be prepared and
656 * service. The message must already be prepared 570 * stored in the buffer at the end of the handle. The message must be
657 * and stored in the buffer at the end of the 571 * of a type that expects a "DataMessage" in response.
658 * handle. The message must be of a type that
659 * expects a "DataMessage" in response.
660 * 572 *
661 * @param h handle to the service with prepared message 573 * @param h handle to the service with prepared message
662 * @param cont function to call with result 574 * @param cont function to call with result
@@ -686,11 +598,13 @@ transmit_for_result (struct GNUNET_DATASTORE_Handle *h,
686 h->response_proc_cls = cont_cls; 598 h->response_proc_cls = cont_cls;
687 h->timeout = GNUNET_TIME_relative_to_absolute (timeout); 599 h->timeout = GNUNET_TIME_relative_to_absolute (timeout);
688 h->message_size = msize; 600 h->message_size = msize;
689 if (NULL == GNUNET_CLIENT_notify_transmit_ready (h->client, 601 if (GNUNET_OK !=
690 msize, 602 GNUNET_CLIENT_transmit_and_get_response (h->client,
691 timeout, 603 hdr,
692 &transmit_get_result, 604 timeout,
693 h)) 605 GNUNET_YES,
606 &with_result_response_handler,
607 h))
694 { 608 {
695 GNUNET_break (0); 609 GNUNET_break (0);
696 h->response_proc = NULL; 610 h->response_proc = NULL;
diff --git a/src/datastore/perf_datastore_api.c b/src/datastore/perf_datastore_api.c
index 1bee3ee57..e454e69f0 100644
--- a/src/datastore/perf_datastore_api.c
+++ b/src/datastore/perf_datastore_api.c
@@ -358,8 +358,8 @@ check ()
358 struct GNUNET_GETOPT_CommandLineOption options[] = { 358 struct GNUNET_GETOPT_CommandLineOption options[] = {
359 GNUNET_GETOPT_OPTION_END 359 GNUNET_GETOPT_OPTION_END
360 }; 360 };
361 pid = GNUNET_OS_start_process ("gnunet-service-datastore", 361 pid = GNUNET_OS_start_process ("gnunet-service-arm",
362 "gnunet-service-datastore", 362 "gnunet-service-arm",
363#if VERBOSE 363#if VERBOSE
364 "-L", "DEBUG", 364 "-L", "DEBUG",
365#endif 365#endif
diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c
index a63f0425f..6a63e8e26 100644
--- a/src/datastore/test_datastore_api.c
+++ b/src/datastore/test_datastore_api.c
@@ -567,8 +567,8 @@ check ()
567 struct GNUNET_GETOPT_CommandLineOption options[] = { 567 struct GNUNET_GETOPT_CommandLineOption options[] = {
568 GNUNET_GETOPT_OPTION_END 568 GNUNET_GETOPT_OPTION_END
569 }; 569 };
570 pid = GNUNET_OS_start_process ("gnunet-service-datastore", 570 pid = GNUNET_OS_start_process ("gnunet-service-arm",
571 "gnunet-service-datastore", 571 "gnunet-service-arm",
572#if VERBOSE 572#if VERBOSE
573 "-L", "DEBUG", 573 "-L", "DEBUG",
574#endif 574#endif
diff --git a/src/datastore/test_datastore_api_data.conf b/src/datastore/test_datastore_api_data.conf
index 815bce0b8..a09bfae0e 100644
--- a/src/datastore/test_datastore_api_data.conf
+++ b/src/datastore/test_datastore_api_data.conf
@@ -1,5 +1,15 @@
1[PATHS] 1[PATHS]
2SERVICEHOME = /tmp/test-gnunetd-datastore/ 2SERVICEHOME = /tmp/test-gnunetd-datastore/
3DEFAULTCONFIG = test_datastore_api_data.conf
4
5[arm]
6DEFAULTSERVICES = resolver
7PORT = 42466
8HOSTNAME = localhost
9
10[resolver]
11PORT = 42464
12HOSTNAME = localhost
3 13
4[datastore] 14[datastore]
5PORT = 22654 15PORT = 22654
@@ -21,3 +31,10 @@ DATABASE = sqlite
21# REJECT_FROM = 31# REJECT_FROM =
22# REJECT_FROM6 = 32# REJECT_FROM6 =
23# PREFIX = 33# PREFIX =
34
35[statistics]
36PORT = 22667
37HOSTNAME = localhost
38
39[testing]
40WEAKRANDOM = YES
diff --git a/src/datastore/test_datastore_api_management.c b/src/datastore/test_datastore_api_management.c
index 22d4aff25..c9fc9c8c5 100644
--- a/src/datastore/test_datastore_api_management.c
+++ b/src/datastore/test_datastore_api_management.c
@@ -335,8 +335,8 @@ check ()
335 struct GNUNET_GETOPT_CommandLineOption options[] = { 335 struct GNUNET_GETOPT_CommandLineOption options[] = {
336 GNUNET_GETOPT_OPTION_END 336 GNUNET_GETOPT_OPTION_END
337 }; 337 };
338 pid = GNUNET_OS_start_process ("gnunet-service-datastore", 338 pid = GNUNET_OS_start_process ("gnunet-service-arm",
339 "gnunet-service-datastore", 339 "gnunet-service-arm",
340#if VERBOSE 340#if VERBOSE
341 "-L", "DEBUG", 341 "-L", "DEBUG",
342#endif 342#endif