diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-04-28 19:32:10 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-04-28 19:32:20 +0200 |
commit | 3f945e6798d8d736ceb104b59ea1269a7abdfe8a (patch) | |
tree | b93e3dc99deda0987e85cb256b3903de8bd74853 /src/namestore/namestore_api_monitor.c | |
parent | 1227fc30369a55b82e77d35d8d128090e37dd437 (diff) | |
download | gnunet-3f945e6798d8d736ceb104b59ea1269a7abdfe8a.tar.gz gnunet-3f945e6798d8d736ceb104b59ea1269a7abdfe8a.zip |
towards flow control in TNG
Diffstat (limited to 'src/namestore/namestore_api_monitor.c')
-rw-r--r-- | src/namestore/namestore_api_monitor.c | 95 |
1 files changed, 38 insertions, 57 deletions
diff --git a/src/namestore/namestore_api_monitor.c b/src/namestore/namestore_api_monitor.c index 99e3864c9..2881a28ac 100644 --- a/src/namestore/namestore_api_monitor.c +++ b/src/namestore/namestore_api_monitor.c | |||
@@ -88,7 +88,6 @@ struct GNUNET_NAMESTORE_ZoneMonitor | |||
88 | * Do we first iterate over all existing records? | 88 | * Do we first iterate over all existing records? |
89 | */ | 89 | */ |
90 | int iterate_first; | 90 | int iterate_first; |
91 | |||
92 | }; | 91 | }; |
93 | 92 | ||
94 | 93 | ||
@@ -108,8 +107,7 @@ reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm); | |||
108 | * @param msg the sync message | 107 | * @param msg the sync message |
109 | */ | 108 | */ |
110 | static void | 109 | static void |
111 | handle_sync (void *cls, | 110 | handle_sync (void *cls, const struct GNUNET_MessageHeader *msg) |
112 | const struct GNUNET_MessageHeader *msg) | ||
113 | { | 111 | { |
114 | struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; | 112 | struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; |
115 | 113 | ||
@@ -128,10 +126,8 @@ handle_sync (void *cls, | |||
128 | * @param lrm the message from the service. | 126 | * @param lrm the message from the service. |
129 | */ | 127 | */ |
130 | static int | 128 | static int |
131 | check_result (void *cls, | 129 | check_result (void *cls, const struct RecordResultMessage *lrm) |
132 | const struct RecordResultMessage *lrm) | ||
133 | { | 130 | { |
134 | static struct GNUNET_CRYPTO_EcdsaPrivateKey zero; | ||
135 | struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; | 131 | struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; |
136 | size_t lrm_len; | 132 | size_t lrm_len; |
137 | size_t exp_lrm_len; | 133 | size_t exp_lrm_len; |
@@ -142,9 +138,8 @@ check_result (void *cls, | |||
142 | const char *rd_ser_tmp; | 138 | const char *rd_ser_tmp; |
143 | 139 | ||
144 | (void) cls; | 140 | (void) cls; |
145 | if ( (0 != GNUNET_memcmp (&lrm->private_key, | 141 | if ((0 != GNUNET_memcmp (&lrm->private_key, &zm->zone)) && |
146 | &zm->zone)) && | 142 | (0 != GNUNET_is_zero (&zm->zone))) |
147 | (0 != GNUNET_is_zero (&zm->zone)) ) | ||
148 | { | 143 | { |
149 | GNUNET_break (0); | 144 | GNUNET_break (0); |
150 | return GNUNET_SYSERR; | 145 | return GNUNET_SYSERR; |
@@ -170,7 +165,7 @@ check_result (void *cls, | |||
170 | return GNUNET_SYSERR; | 165 | return GNUNET_SYSERR; |
171 | } | 166 | } |
172 | name_tmp = (const char *) &lrm[1]; | 167 | name_tmp = (const char *) &lrm[1]; |
173 | if (name_tmp[name_len -1] != '\0') | 168 | if (name_tmp[name_len - 1] != '\0') |
174 | { | 169 | { |
175 | GNUNET_break (0); | 170 | GNUNET_break (0); |
176 | return GNUNET_SYSERR; | 171 | return GNUNET_SYSERR; |
@@ -180,10 +175,7 @@ check_result (void *cls, | |||
180 | struct GNUNET_GNSRECORD_Data rd[rd_count]; | 175 | struct GNUNET_GNSRECORD_Data rd[rd_count]; |
181 | 176 | ||
182 | if (GNUNET_OK != | 177 | if (GNUNET_OK != |
183 | GNUNET_GNSRECORD_records_deserialize (rd_len, | 178 | GNUNET_GNSRECORD_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd)) |
184 | rd_ser_tmp, | ||
185 | rd_count, | ||
186 | rd)) | ||
187 | { | 179 | { |
188 | GNUNET_break (0); | 180 | GNUNET_break (0); |
189 | return GNUNET_SYSERR; | 181 | return GNUNET_SYSERR; |
@@ -201,8 +193,7 @@ check_result (void *cls, | |||
201 | * @param lrm the message from the service. | 193 | * @param lrm the message from the service. |
202 | */ | 194 | */ |
203 | static void | 195 | static void |
204 | handle_result (void *cls, | 196 | handle_result (void *cls, const struct RecordResultMessage *lrm) |
205 | const struct RecordResultMessage *lrm) | ||
206 | { | 197 | { |
207 | struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; | 198 | struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; |
208 | size_t name_len; | 199 | size_t name_len; |
@@ -219,16 +210,10 @@ handle_result (void *cls, | |||
219 | { | 210 | { |
220 | struct GNUNET_GNSRECORD_Data rd[rd_count]; | 211 | struct GNUNET_GNSRECORD_Data rd[rd_count]; |
221 | 212 | ||
222 | GNUNET_assert (GNUNET_OK == | 213 | GNUNET_assert ( |
223 | GNUNET_GNSRECORD_records_deserialize (rd_len, | 214 | GNUNET_OK == |
224 | rd_ser_tmp, | 215 | GNUNET_GNSRECORD_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd)); |
225 | rd_count, | 216 | zm->monitor (zm->monitor_cls, &lrm->private_key, name_tmp, rd_count, rd); |
226 | rd)); | ||
227 | zm->monitor (zm->monitor_cls, | ||
228 | &lrm->private_key, | ||
229 | name_tmp, | ||
230 | rd_count, | ||
231 | rd); | ||
232 | } | 217 | } |
233 | } | 218 | } |
234 | 219 | ||
@@ -242,8 +227,7 @@ handle_result (void *cls, | |||
242 | * @param error error code | 227 | * @param error error code |
243 | */ | 228 | */ |
244 | static void | 229 | static void |
245 | mq_error_handler (void *cls, | 230 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
246 | enum GNUNET_MQ_Error error) | ||
247 | { | 231 | { |
248 | struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; | 232 | struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; |
249 | 233 | ||
@@ -260,17 +244,16 @@ mq_error_handler (void *cls, | |||
260 | static void | 244 | static void |
261 | reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm) | 245 | reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm) |
262 | { | 246 | { |
263 | struct GNUNET_MQ_MessageHandler handlers[] = { | 247 | struct GNUNET_MQ_MessageHandler handlers[] = |
264 | GNUNET_MQ_hd_fixed_size (sync, | 248 | {GNUNET_MQ_hd_fixed_size (sync, |
265 | GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC, | 249 | GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC, |
266 | struct GNUNET_MessageHeader, | 250 | struct GNUNET_MessageHeader, |
267 | zm), | 251 | zm), |
268 | GNUNET_MQ_hd_var_size (result, | 252 | GNUNET_MQ_hd_var_size (result, |
269 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT, | 253 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT, |
270 | struct RecordResultMessage, | 254 | struct RecordResultMessage, |
271 | zm), | 255 | zm), |
272 | GNUNET_MQ_handler_end () | 256 | GNUNET_MQ_handler_end ()}; |
273 | }; | ||
274 | struct GNUNET_MQ_Envelope *env; | 257 | struct GNUNET_MQ_Envelope *env; |
275 | struct ZoneMonitorStartMessage *sm; | 258 | struct ZoneMonitorStartMessage *sm; |
276 | 259 | ||
@@ -286,12 +269,10 @@ reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm) | |||
286 | zm); | 269 | zm); |
287 | if (NULL == zm->mq) | 270 | if (NULL == zm->mq) |
288 | return; | 271 | return; |
289 | env = GNUNET_MQ_msg (sm, | 272 | env = GNUNET_MQ_msg (sm, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START); |
290 | GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START); | ||
291 | sm->iterate_first = htonl (zm->iterate_first); | 273 | sm->iterate_first = htonl (zm->iterate_first); |
292 | sm->zone = zm->zone; | 274 | sm->zone = zm->zone; |
293 | GNUNET_MQ_send (zm->mq, | 275 | GNUNET_MQ_send (zm->mq, env); |
294 | env); | ||
295 | } | 276 | } |
296 | 277 | ||
297 | 278 | ||
@@ -304,7 +285,8 @@ reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm) | |||
304 | * @param cfg configuration to use to connect to namestore | 285 | * @param cfg configuration to use to connect to namestore |
305 | * @param zone zone to monitor | 286 | * @param zone zone to monitor |
306 | * @param iterate_first #GNUNET_YES to first iterate over all existing records, | 287 | * @param iterate_first #GNUNET_YES to first iterate over all existing records, |
307 | * #GNUNET_NO to only return changes that happen from now on | 288 | * #GNUNET_NO to only return changes that happen from now |
289 | * on | ||
308 | * @param error_cb function to call on error (i.e. disconnect); note that | 290 | * @param error_cb function to call on error (i.e. disconnect); note that |
309 | * unlike the other error callbacks in this API, a call to this | 291 | * unlike the other error callbacks in this API, a call to this |
310 | * function does NOT destroy the monitor handle, it merely signals | 292 | * function does NOT destroy the monitor handle, it merely signals |
@@ -318,15 +300,16 @@ reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm) | |||
318 | * @return handle to stop monitoring | 300 | * @return handle to stop monitoring |
319 | */ | 301 | */ |
320 | struct GNUNET_NAMESTORE_ZoneMonitor * | 302 | struct GNUNET_NAMESTORE_ZoneMonitor * |
321 | GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | 303 | GNUNET_NAMESTORE_zone_monitor_start ( |
322 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 304 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
323 | int iterate_first, | 305 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
324 | GNUNET_SCHEDULER_TaskCallback error_cb, | 306 | int iterate_first, |
325 | void *error_cb_cls, | 307 | GNUNET_SCHEDULER_TaskCallback error_cb, |
326 | GNUNET_NAMESTORE_RecordMonitor monitor, | 308 | void *error_cb_cls, |
327 | void *monitor_cls, | 309 | GNUNET_NAMESTORE_RecordMonitor monitor, |
328 | GNUNET_SCHEDULER_TaskCallback sync_cb, | 310 | void *monitor_cls, |
329 | void *sync_cb_cls) | 311 | GNUNET_SCHEDULER_TaskCallback sync_cb, |
312 | void *sync_cb_cls) | ||
330 | { | 313 | { |
331 | struct GNUNET_NAMESTORE_ZoneMonitor *zm; | 314 | struct GNUNET_NAMESTORE_ZoneMonitor *zm; |
332 | 315 | ||
@@ -379,11 +362,9 @@ GNUNET_NAMESTORE_zone_monitor_next (struct GNUNET_NAMESTORE_ZoneMonitor *zm, | |||
379 | struct GNUNET_MQ_Envelope *env; | 362 | struct GNUNET_MQ_Envelope *env; |
380 | struct ZoneMonitorNextMessage *nm; | 363 | struct ZoneMonitorNextMessage *nm; |
381 | 364 | ||
382 | env = GNUNET_MQ_msg (nm, | 365 | env = GNUNET_MQ_msg (nm, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT); |
383 | GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT); | ||
384 | nm->limit = GNUNET_htonll (limit); | 366 | nm->limit = GNUNET_htonll (limit); |
385 | GNUNET_MQ_send (zm->mq, | 367 | GNUNET_MQ_send (zm->mq, env); |
386 | env); | ||
387 | } | 368 | } |
388 | 369 | ||
389 | 370 | ||