aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/namestore_api_monitor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore/namestore_api_monitor.c')
-rw-r--r--src/namestore/namestore_api_monitor.c187
1 files changed, 94 insertions, 93 deletions
diff --git a/src/namestore/namestore_api_monitor.c b/src/namestore/namestore_api_monitor.c
index d87a76eed..a7046c940 100644
--- a/src/namestore/namestore_api_monitor.c
+++ b/src/namestore/namestore_api_monitor.c
@@ -37,7 +37,8 @@
37/** 37/**
38 * Handle for a monitoring activity. 38 * Handle for a monitoring activity.
39 */ 39 */
40struct GNUNET_NAMESTORE_ZoneMonitor { 40struct GNUNET_NAMESTORE_ZoneMonitor
41{
41 /** 42 /**
42 * Configuration (to reconnect). 43 * Configuration (to reconnect).
43 */ 44 */
@@ -96,7 +97,7 @@ struct GNUNET_NAMESTORE_ZoneMonitor {
96 * @param zm monitor to reconnect 97 * @param zm monitor to reconnect
97 */ 98 */
98static void 99static void
99reconnect(struct GNUNET_NAMESTORE_ZoneMonitor *zm); 100reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm);
100 101
101 102
102/** 103/**
@@ -106,14 +107,14 @@ reconnect(struct GNUNET_NAMESTORE_ZoneMonitor *zm);
106 * @param msg the sync message 107 * @param msg the sync message
107 */ 108 */
108static void 109static void
109handle_sync(void *cls, const struct GNUNET_MessageHeader *msg) 110handle_sync (void *cls, const struct GNUNET_MessageHeader *msg)
110{ 111{
111 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; 112 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls;
112 113
113 (void)cls; 114 (void) cls;
114 (void)msg; 115 (void) msg;
115 if (NULL != zm->sync_cb) 116 if (NULL != zm->sync_cb)
116 zm->sync_cb(zm->sync_cb_cls); 117 zm->sync_cb (zm->sync_cb_cls);
117} 118}
118 119
119 120
@@ -125,7 +126,7 @@ handle_sync(void *cls, const struct GNUNET_MessageHeader *msg)
125 * @param lrm the message from the service. 126 * @param lrm the message from the service.
126 */ 127 */
127static int 128static int
128check_result(void *cls, const struct RecordResultMessage *lrm) 129check_result (void *cls, const struct RecordResultMessage *lrm)
129{ 130{
130 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; 131 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls;
131 size_t lrm_len; 132 size_t lrm_len;
@@ -136,49 +137,49 @@ check_result(void *cls, const struct RecordResultMessage *lrm)
136 const char *name_tmp; 137 const char *name_tmp;
137 const char *rd_ser_tmp; 138 const char *rd_ser_tmp;
138 139
139 (void)cls; 140 (void) cls;
140 if ((0 != GNUNET_memcmp(&lrm->private_key, &zm->zone)) && 141 if ((0 != GNUNET_memcmp (&lrm->private_key, &zm->zone)) &&
141 (0 != GNUNET_is_zero(&zm->zone))) 142 (0 != GNUNET_is_zero (&zm->zone)))
142 { 143 {
143 GNUNET_break(0); 144 GNUNET_break (0);
144 return GNUNET_SYSERR; 145 return GNUNET_SYSERR;
145 } 146 }
146 lrm_len = ntohs(lrm->gns_header.header.size); 147 lrm_len = ntohs (lrm->gns_header.header.size);
147 rd_len = ntohs(lrm->rd_len); 148 rd_len = ntohs (lrm->rd_len);
148 rd_count = ntohs(lrm->rd_count); 149 rd_count = ntohs (lrm->rd_count);
149 name_len = ntohs(lrm->name_len); 150 name_len = ntohs (lrm->name_len);
150 if (name_len > MAX_NAME_LEN) 151 if (name_len > MAX_NAME_LEN)
151 { 152 {
152 GNUNET_break(0); 153 GNUNET_break (0);
153 return GNUNET_SYSERR; 154 return GNUNET_SYSERR;
154 } 155 }
155 exp_lrm_len = sizeof(struct RecordResultMessage) + name_len + rd_len; 156 exp_lrm_len = sizeof(struct RecordResultMessage) + name_len + rd_len;
156 if (lrm_len != exp_lrm_len) 157 if (lrm_len != exp_lrm_len)
157 { 158 {
158 GNUNET_break(0); 159 GNUNET_break (0);
159 return GNUNET_SYSERR; 160 return GNUNET_SYSERR;
160 } 161 }
161 if (0 == name_len) 162 if (0 == name_len)
162 { 163 {
163 GNUNET_break(0); 164 GNUNET_break (0);
164 return GNUNET_SYSERR; 165 return GNUNET_SYSERR;
165 } 166 }
166 name_tmp = (const char *)&lrm[1]; 167 name_tmp = (const char *) &lrm[1];
167 if (name_tmp[name_len - 1] != '\0') 168 if (name_tmp[name_len - 1] != '\0')
168 { 169 {
169 GNUNET_break(0); 170 GNUNET_break (0);
170 return GNUNET_SYSERR; 171 return GNUNET_SYSERR;
171 } 172 }
172 rd_ser_tmp = (const char *)&name_tmp[name_len]; 173 rd_ser_tmp = (const char *) &name_tmp[name_len];
173 { 174 {
174 struct GNUNET_GNSRECORD_Data rd[rd_count]; 175 struct GNUNET_GNSRECORD_Data rd[rd_count];
175 176
176 if (GNUNET_OK != 177 if (GNUNET_OK !=
177 GNUNET_GNSRECORD_records_deserialize(rd_len, rd_ser_tmp, rd_count, rd)) 178 GNUNET_GNSRECORD_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd))
178 { 179 {
179 GNUNET_break(0); 180 GNUNET_break (0);
180 return GNUNET_SYSERR; 181 return GNUNET_SYSERR;
181 } 182 }
182 } 183 }
183 return GNUNET_OK; 184 return GNUNET_OK;
184} 185}
@@ -192,7 +193,7 @@ check_result(void *cls, const struct RecordResultMessage *lrm)
192 * @param lrm the message from the service. 193 * @param lrm the message from the service.
193 */ 194 */
194static void 195static void
195handle_result(void *cls, const struct RecordResultMessage *lrm) 196handle_result (void *cls, const struct RecordResultMessage *lrm)
196{ 197{
197 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; 198 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls;
198 size_t name_len; 199 size_t name_len;
@@ -201,18 +202,18 @@ handle_result(void *cls, const struct RecordResultMessage *lrm)
201 const char *name_tmp; 202 const char *name_tmp;
202 const char *rd_ser_tmp; 203 const char *rd_ser_tmp;
203 204
204 rd_len = ntohs(lrm->rd_len); 205 rd_len = ntohs (lrm->rd_len);
205 rd_count = ntohs(lrm->rd_count); 206 rd_count = ntohs (lrm->rd_count);
206 name_len = ntohs(lrm->name_len); 207 name_len = ntohs (lrm->name_len);
207 name_tmp = (const char *)&lrm[1]; 208 name_tmp = (const char *) &lrm[1];
208 rd_ser_tmp = (const char *)&name_tmp[name_len]; 209 rd_ser_tmp = (const char *) &name_tmp[name_len];
209 { 210 {
210 struct GNUNET_GNSRECORD_Data rd[rd_count]; 211 struct GNUNET_GNSRECORD_Data rd[rd_count];
211 212
212 GNUNET_assert( 213 GNUNET_assert (
213 GNUNET_OK == 214 GNUNET_OK ==
214 GNUNET_GNSRECORD_records_deserialize(rd_len, rd_ser_tmp, rd_count, rd)); 215 GNUNET_GNSRECORD_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd));
215 zm->monitor(zm->monitor_cls, &lrm->private_key, name_tmp, rd_count, rd); 216 zm->monitor (zm->monitor_cls, &lrm->private_key, name_tmp, rd_count, rd);
216 } 217 }
217} 218}
218 219
@@ -226,12 +227,12 @@ handle_result(void *cls, const struct RecordResultMessage *lrm)
226 * @param error error code 227 * @param error error code
227 */ 228 */
228static void 229static void
229mq_error_handler(void *cls, enum GNUNET_MQ_Error error) 230mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
230{ 231{
231 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; 232 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls;
232 233
233 (void)error; 234 (void) error;
234 reconnect(zm); 235 reconnect (zm);
235} 236}
236 237
237 238
@@ -241,37 +242,37 @@ mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
241 * @param zm monitor to reconnect 242 * @param zm monitor to reconnect
242 */ 243 */
243static void 244static void
244reconnect(struct GNUNET_NAMESTORE_ZoneMonitor *zm) 245reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm)
245{ 246{
246 struct GNUNET_MQ_MessageHandler handlers[] = 247 struct GNUNET_MQ_MessageHandler handlers[] =
247 { GNUNET_MQ_hd_fixed_size(sync, 248 { GNUNET_MQ_hd_fixed_size (sync,
248 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC, 249 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC,
249 struct GNUNET_MessageHeader, 250 struct GNUNET_MessageHeader,
250 zm), 251 zm),
251 GNUNET_MQ_hd_var_size(result, 252 GNUNET_MQ_hd_var_size (result,
252 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT, 253 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT,
253 struct RecordResultMessage, 254 struct RecordResultMessage,
254 zm), 255 zm),
255 GNUNET_MQ_handler_end() }; 256 GNUNET_MQ_handler_end () };
256 struct GNUNET_MQ_Envelope *env; 257 struct GNUNET_MQ_Envelope *env;
257 struct ZoneMonitorStartMessage *sm; 258 struct ZoneMonitorStartMessage *sm;
258 259
259 if (NULL != zm->mq) 260 if (NULL != zm->mq)
260 { 261 {
261 GNUNET_MQ_destroy(zm->mq); 262 GNUNET_MQ_destroy (zm->mq);
262 zm->error_cb(zm->error_cb_cls); 263 zm->error_cb (zm->error_cb_cls);
263 } 264 }
264 zm->mq = GNUNET_CLIENT_connect(zm->cfg, 265 zm->mq = GNUNET_CLIENT_connect (zm->cfg,
265 "namestore", 266 "namestore",
266 handlers, 267 handlers,
267 &mq_error_handler, 268 &mq_error_handler,
268 zm); 269 zm);
269 if (NULL == zm->mq) 270 if (NULL == zm->mq)
270 return; 271 return;
271 env = GNUNET_MQ_msg(sm, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START); 272 env = GNUNET_MQ_msg (sm, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START);
272 sm->iterate_first = htonl(zm->iterate_first); 273 sm->iterate_first = htonl (zm->iterate_first);
273 sm->zone = zm->zone; 274 sm->zone = zm->zone;
274 GNUNET_MQ_send(zm->mq, env); 275 GNUNET_MQ_send (zm->mq, env);
275} 276}
276 277
277 278
@@ -299,7 +300,7 @@ reconnect(struct GNUNET_NAMESTORE_ZoneMonitor *zm)
299 * @return handle to stop monitoring 300 * @return handle to stop monitoring
300 */ 301 */
301struct GNUNET_NAMESTORE_ZoneMonitor * 302struct GNUNET_NAMESTORE_ZoneMonitor *
302GNUNET_NAMESTORE_zone_monitor_start( 303GNUNET_NAMESTORE_zone_monitor_start (
303 const struct GNUNET_CONFIGURATION_Handle *cfg, 304 const struct GNUNET_CONFIGURATION_Handle *cfg,
304 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 305 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
305 int iterate_first, 306 int iterate_first,
@@ -312,7 +313,7 @@ GNUNET_NAMESTORE_zone_monitor_start(
312{ 313{
313 struct GNUNET_NAMESTORE_ZoneMonitor *zm; 314 struct GNUNET_NAMESTORE_ZoneMonitor *zm;
314 315
315 zm = GNUNET_new(struct GNUNET_NAMESTORE_ZoneMonitor); 316 zm = GNUNET_new (struct GNUNET_NAMESTORE_ZoneMonitor);
316 if (NULL != zone) 317 if (NULL != zone)
317 zm->zone = *zone; 318 zm->zone = *zone;
318 zm->iterate_first = iterate_first; 319 zm->iterate_first = iterate_first;
@@ -323,12 +324,12 @@ GNUNET_NAMESTORE_zone_monitor_start(
323 zm->sync_cb = sync_cb; 324 zm->sync_cb = sync_cb;
324 zm->sync_cb_cls = sync_cb_cls; 325 zm->sync_cb_cls = sync_cb_cls;
325 zm->cfg = cfg; 326 zm->cfg = cfg;
326 reconnect(zm); 327 reconnect (zm);
327 if (NULL == zm->mq) 328 if (NULL == zm->mq)
328 { 329 {
329 GNUNET_free(zm); 330 GNUNET_free (zm);
330 return NULL; 331 return NULL;
331 } 332 }
332 return zm; 333 return zm;
333} 334}
334 335
@@ -355,15 +356,15 @@ GNUNET_NAMESTORE_zone_monitor_start(
355 * (before #GNUNET_NAMESTORE_zone_monitor_next is to be called again) 356 * (before #GNUNET_NAMESTORE_zone_monitor_next is to be called again)
356 */ 357 */
357void 358void
358GNUNET_NAMESTORE_zone_monitor_next(struct GNUNET_NAMESTORE_ZoneMonitor *zm, 359GNUNET_NAMESTORE_zone_monitor_next (struct GNUNET_NAMESTORE_ZoneMonitor *zm,
359 uint64_t limit) 360 uint64_t limit)
360{ 361{
361 struct GNUNET_MQ_Envelope *env; 362 struct GNUNET_MQ_Envelope *env;
362 struct ZoneMonitorNextMessage *nm; 363 struct ZoneMonitorNextMessage *nm;
363 364
364 env = GNUNET_MQ_msg(nm, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT); 365 env = GNUNET_MQ_msg (nm, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT);
365 nm->limit = GNUNET_htonll(limit); 366 nm->limit = GNUNET_htonll (limit);
366 GNUNET_MQ_send(zm->mq, env); 367 GNUNET_MQ_send (zm->mq, env);
367} 368}
368 369
369 370
@@ -373,14 +374,14 @@ GNUNET_NAMESTORE_zone_monitor_next(struct GNUNET_NAMESTORE_ZoneMonitor *zm,
373 * @param zm handle to the monitor activity to stop 374 * @param zm handle to the monitor activity to stop
374 */ 375 */
375void 376void
376GNUNET_NAMESTORE_zone_monitor_stop(struct GNUNET_NAMESTORE_ZoneMonitor *zm) 377GNUNET_NAMESTORE_zone_monitor_stop (struct GNUNET_NAMESTORE_ZoneMonitor *zm)
377{ 378{
378 if (NULL != zm->mq) 379 if (NULL != zm->mq)
379 { 380 {
380 GNUNET_MQ_destroy(zm->mq); 381 GNUNET_MQ_destroy (zm->mq);
381 zm->mq = NULL; 382 zm->mq = NULL;
382 } 383 }
383 GNUNET_free(zm); 384 GNUNET_free (zm);
384} 385}
385 386
386/* end of namestore_api_monitor.c */ 387/* end of namestore_api_monitor.c */