aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2021-03-28 16:15:25 +0200
committerMartin Schanzenbach <mschanzenbach@posteo.de>2021-03-28 16:15:25 +0200
commit3515b8cb39b2c240a6d4af298d83862fb7a502d0 (patch)
tree01301314ea7183166a78bbc45b8b2c33392da98f
parentb001bc189b7cb51aa8b41a2b9493530395e6a909 (diff)
downloadgnunet-3515b8cb39b2c240a6d4af298d83862fb7a502d0.tar.gz
gnunet-3515b8cb39b2c240a6d4af298d83862fb7a502d0.zip
-fix peerstore api and tests
-rw-r--r--src/peerstore/peerstore_api.c5
-rw-r--r--src/peerstore/test_peerstore_api_sync.c87
2 files changed, 76 insertions, 16 deletions
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