aboutsummaryrefslogtreecommitdiff
path: root/src/peerstore
diff options
context:
space:
mode:
Diffstat (limited to 'src/peerstore')
-rw-r--r--src/peerstore/gnunet-service-peerstore.c15
-rw-r--r--src/peerstore/peerstore_api.c5
-rw-r--r--src/peerstore/test_peerstore_api_sync.c87
3 files changed, 88 insertions, 19 deletions
diff --git a/src/peerstore/gnunet-service-peerstore.c b/src/peerstore/gnunet-service-peerstore.c
index c92e4d3f0..959d088f9 100644
--- a/src/peerstore/gnunet-service-peerstore.c
+++ b/src/peerstore/gnunet-service-peerstore.c
@@ -77,6 +77,8 @@ static unsigned int num_clients;
77static void 77static void
78do_shutdown () 78do_shutdown ()
79{ 79{
80 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
81 "Shutting down peerstore, bye.\n");
80 if (NULL != db_lib_name) 82 if (NULL != db_lib_name)
81 { 83 {
82 GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, db)); 84 GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, db));
@@ -105,6 +107,8 @@ do_shutdown ()
105static void 107static void
106shutdown_task (void *cls) 108shutdown_task (void *cls)
107{ 109{
110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
111 "Priming PEERSTORE for shutdown.\n");
108 in_shutdown = GNUNET_YES; 112 in_shutdown = GNUNET_YES;
109 if (0 == num_clients) /* Only when no connected clients. */ 113 if (0 == num_clients) /* Only when no connected clients. */
110 do_shutdown (); 114 do_shutdown ();
@@ -176,6 +180,8 @@ client_connect_cb (void *cls,
176 struct GNUNET_MQ_Handle *mq) 180 struct GNUNET_MQ_Handle *mq)
177{ 181{
178 num_clients++; 182 num_clients++;
183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
184 "A client connected (now %u)\n", num_clients);
179 return client; 185 return client;
180} 186}
181 187
@@ -195,7 +201,7 @@ client_disconnect_it (void *cls, const struct GNUNET_HashCode *key, void *value)
195 { 201 {
196 GNUNET_assert (GNUNET_YES == 202 GNUNET_assert (GNUNET_YES ==
197 GNUNET_CONTAINER_multihashmap_remove (watchers, key, value)); 203 GNUNET_CONTAINER_multihashmap_remove (watchers, key, value));
198 num_clients++; 204 num_clients++; /* Watchers do not count */
199 } 205 }
200 return GNUNET_OK; 206 return GNUNET_OK;
201} 207}
@@ -212,12 +218,14 @@ client_disconnect_cb (void *cls,
212 struct GNUNET_SERVICE_Client *client, 218 struct GNUNET_SERVICE_Client *client,
213 void *app_cls) 219 void *app_cls)
214{ 220{
215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "A client disconnected, cleaning up.\n"); 221 num_clients--;
216 if (NULL != watchers) 222 if (NULL != watchers)
217 GNUNET_CONTAINER_multihashmap_iterate (watchers, 223 GNUNET_CONTAINER_multihashmap_iterate (watchers,
218 &client_disconnect_it, 224 &client_disconnect_it,
219 client); 225 client);
220 num_clients--; 226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
227 "A client disconnected (%u remaining).\n",
228 num_clients);
221 if ((0 == num_clients) && in_shutdown) 229 if ((0 == num_clients) && in_shutdown)
222 do_shutdown (); 230 do_shutdown ();
223} 231}
@@ -540,6 +548,7 @@ run (void *cls,
540 char *database; 548 char *database;
541 549
542 in_shutdown = GNUNET_NO; 550 in_shutdown = GNUNET_NO;
551 num_clients = 0;
543 cfg = c; 552 cfg = c;
544 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, 553 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
545 "peerstore", 554 "peerstore",
diff --git a/src/peerstore/peerstore_api.c b/src/peerstore/peerstore_api.c
index db5aee0d5..196d44faa 100644
--- a/src/peerstore/peerstore_api.c
+++ b/src/peerstore/peerstore_api.c
@@ -823,7 +823,12 @@ reconnect (void *cls)
823 &handle_client_error, 823 &handle_client_error,
824 h); 824 h);
825 if (NULL == h->mq) 825 if (NULL == h->mq)
826 {
827 h->reconnect_task =
828 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
829 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
826 return; 830 return;
831 }
827 LOG (GNUNET_ERROR_TYPE_DEBUG, 832 LOG (GNUNET_ERROR_TYPE_DEBUG,
828 "Resending pending requests after reconnect.\n"); 833 "Resending pending requests after reconnect.\n");
829 if (NULL != h->watches) 834 if (NULL != h->watches)
diff --git a/src/peerstore/test_peerstore_api_sync.c b/src/peerstore/test_peerstore_api_sync.c
index 4c826c654..5057c98b5 100644
--- a/src/peerstore/test_peerstore_api_sync.c
+++ b/src/peerstore/test_peerstore_api_sync.c
@@ -67,6 +67,24 @@ static const char *val = "test_peerstore_api_store_val";
67 67
68 68
69/** 69/**
70 * Timeout
71 */
72#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
73
74/**
75 * Timeout task
76 */
77static struct GNUNET_SCHEDULER_Task *to;
78
79/**
80 * Iterate handle
81 */
82static struct GNUNET_PEERSTORE_IterateContext *it;
83
84static void
85test_cont (void *cls);
86
87/**
70 * Function that should be called with the result of the 88 * Function that should be called with the result of the
71 * lookup, and finally once with NULL to signal the end 89 * lookup, and finally once with NULL to signal the end
72 * of the iteration. 90 * of the iteration.
@@ -89,9 +107,24 @@ iterate_cb (void *cls,
89 GNUNET_break (NULL == emsg); 107 GNUNET_break (NULL == emsg);
90 if (NULL == record) 108 if (NULL == record)
91 { 109 {
92 GNUNET_PEERSTORE_disconnect (h, 110 it = NULL;
93 GNUNET_NO); 111 if (0 == ok)
94 GNUNET_SCHEDULER_shutdown (); 112 {
113 GNUNET_PEERSTORE_disconnect (h,
114 GNUNET_NO);
115 if (NULL != to)
116 {
117 GNUNET_SCHEDULER_cancel (to);
118 to = NULL;
119 }
120 GNUNET_SCHEDULER_shutdown ();
121 return;
122 }
123 /**
124 * Try again
125 */
126 GNUNET_SCHEDULER_add_now (&test_cont,
127 NULL);
95 return; 128 return;
96 } 129 }
97 rec_val = record->value; 130 rec_val = record->value;
@@ -100,6 +133,22 @@ iterate_cb (void *cls,
100} 133}
101 134
102 135
136static void
137timeout_task (void *cls)
138{
139 to = NULL;
140 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
141 "Timeout reached\n");
142 if (NULL != it)
143 GNUNET_PEERSTORE_iterate_cancel (it);
144 it = NULL;
145 GNUNET_PEERSTORE_disconnect (h,
146 GNUNET_NO);
147 GNUNET_SCHEDULER_shutdown ();
148 return;
149}
150
151
103/** 152/**
104 * Run the 2nd stage of the test where we fetch the 153 * Run the 2nd stage of the test where we fetch the
105 * data that should have been stored. 154 * data that should have been stored.
@@ -109,12 +158,11 @@ iterate_cb (void *cls,
109static void 158static void
110test_cont (void *cls) 159test_cont (void *cls)
111{ 160{
112 h = GNUNET_PEERSTORE_connect (cfg); 161 it = GNUNET_PEERSTORE_iterate (h,
113 GNUNET_PEERSTORE_iterate (h, 162 subsystem,
114 subsystem, 163 &pid, key,
115 &pid, key, 164 &iterate_cb,
116 &iterate_cb, 165 NULL);
117 NULL);
118} 166}
119 167
120 168
@@ -122,10 +170,9 @@ static void
122disc_cont (void *cls) 170disc_cont (void *cls)
123{ 171{
124 GNUNET_PEERSTORE_disconnect (h, GNUNET_YES); 172 GNUNET_PEERSTORE_disconnect (h, GNUNET_YES);
125 h = NULL; 173 h = GNUNET_PEERSTORE_connect (cfg);
126 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 174 GNUNET_SCHEDULER_add_now (&test_cont,
127 &test_cont, 175 NULL);
128 NULL);
129} 176}
130 177
131 178
@@ -133,12 +180,17 @@ static void
133store_cont (void *cls, int success) 180store_cont (void *cls, int success)
134{ 181{
135 ok = success; 182 ok = success;
183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
184 "Success: %s\n",
185 (GNUNET_SYSERR == ok) ? "no" : "yes");
136 /* We need to wait a little bit to give the disconnect 186 /* We need to wait a little bit to give the disconnect
137 a chance to actually finish the operation; otherwise, 187 a chance to actually finish the operation; otherwise,
138 the test may fail non-deterministically if the new 188 the test may fail non-deterministically if the new
139 connection is faster than the cleanup routine of the 189 connection is faster than the cleanup routine of the
140 old one. */GNUNET_SCHEDULER_add_now (&disc_cont, 190 old one. */
141 NULL); 191 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
192 &disc_cont,
193 NULL);
142} 194}
143 195
144 196
@@ -174,7 +226,10 @@ run (void *cls,
174{ 226{
175 cfg = c; 227 cfg = c;
176 memset (&pid, 1, sizeof(pid)); 228 memset (&pid, 1, sizeof(pid));
177 test1 (); 229 to = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
230 &timeout_task,
231 NULL);
232 GNUNET_SCHEDULER_add_now (&test1, NULL);
178} 233}
179 234
180 235