diff options
Diffstat (limited to 'src/peerstore/gnunet-service-peerstore.c')
-rw-r--r-- | src/peerstore/gnunet-service-peerstore.c | 444 |
1 files changed, 222 insertions, 222 deletions
diff --git a/src/peerstore/gnunet-service-peerstore.c b/src/peerstore/gnunet-service-peerstore.c index 02ac03e01..c92e4d3f0 100644 --- a/src/peerstore/gnunet-service-peerstore.c +++ b/src/peerstore/gnunet-service-peerstore.c | |||
@@ -75,25 +75,25 @@ static unsigned int num_clients; | |||
75 | * Perform the actual shutdown operations | 75 | * Perform the actual shutdown operations |
76 | */ | 76 | */ |
77 | static void | 77 | static void |
78 | do_shutdown() | 78 | do_shutdown () |
79 | { | 79 | { |
80 | if (NULL != db_lib_name) | 80 | if (NULL != db_lib_name) |
81 | { | 81 | { |
82 | GNUNET_break(NULL == GNUNET_PLUGIN_unload(db_lib_name, db)); | 82 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, db)); |
83 | GNUNET_free(db_lib_name); | 83 | GNUNET_free (db_lib_name); |
84 | db_lib_name = NULL; | 84 | db_lib_name = NULL; |
85 | } | 85 | } |
86 | if (NULL != watchers) | 86 | if (NULL != watchers) |
87 | { | 87 | { |
88 | GNUNET_CONTAINER_multihashmap_destroy(watchers); | 88 | GNUNET_CONTAINER_multihashmap_destroy (watchers); |
89 | watchers = NULL; | 89 | watchers = NULL; |
90 | } | 90 | } |
91 | if (NULL != expire_task) | 91 | if (NULL != expire_task) |
92 | { | 92 | { |
93 | GNUNET_SCHEDULER_cancel(expire_task); | 93 | GNUNET_SCHEDULER_cancel (expire_task); |
94 | expire_task = NULL; | 94 | expire_task = NULL; |
95 | } | 95 | } |
96 | GNUNET_SCHEDULER_shutdown(); | 96 | GNUNET_SCHEDULER_shutdown (); |
97 | } | 97 | } |
98 | 98 | ||
99 | 99 | ||
@@ -103,42 +103,42 @@ do_shutdown() | |||
103 | * @param cls unused | 103 | * @param cls unused |
104 | */ | 104 | */ |
105 | static void | 105 | static void |
106 | shutdown_task(void *cls) | 106 | shutdown_task (void *cls) |
107 | { | 107 | { |
108 | in_shutdown = GNUNET_YES; | 108 | in_shutdown = GNUNET_YES; |
109 | if (0 == num_clients) /* Only when no connected clients. */ | 109 | if (0 == num_clients) /* Only when no connected clients. */ |
110 | do_shutdown(); | 110 | do_shutdown (); |
111 | } | 111 | } |
112 | 112 | ||
113 | 113 | ||
114 | /* Forward declaration */ | 114 | /* Forward declaration */ |
115 | static void | 115 | static void |
116 | expire_records_continuation(void *cls, int success); | 116 | expire_records_continuation (void *cls, int success); |
117 | 117 | ||
118 | 118 | ||
119 | /** | 119 | /** |
120 | * Deletes any expired records from storage | 120 | * Deletes any expired records from storage |
121 | */ | 121 | */ |
122 | static void | 122 | static void |
123 | cleanup_expired_records(void *cls) | 123 | cleanup_expired_records (void *cls) |
124 | { | 124 | { |
125 | int ret; | 125 | int ret; |
126 | 126 | ||
127 | expire_task = NULL; | 127 | expire_task = NULL; |
128 | GNUNET_assert(NULL != db); | 128 | GNUNET_assert (NULL != db); |
129 | ret = db->expire_records(db->cls, | 129 | ret = db->expire_records (db->cls, |
130 | GNUNET_TIME_absolute_get(), | 130 | GNUNET_TIME_absolute_get (), |
131 | &expire_records_continuation, | 131 | &expire_records_continuation, |
132 | NULL); | 132 | NULL); |
133 | if (GNUNET_OK != ret) | 133 | if (GNUNET_OK != ret) |
134 | { | 134 | { |
135 | GNUNET_assert(NULL == expire_task); | 135 | GNUNET_assert (NULL == expire_task); |
136 | expire_task = GNUNET_SCHEDULER_add_delayed( | 136 | expire_task = GNUNET_SCHEDULER_add_delayed ( |
137 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, | 137 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, |
138 | EXPIRED_RECORDS_CLEANUP_INTERVAL), | 138 | EXPIRED_RECORDS_CLEANUP_INTERVAL), |
139 | &cleanup_expired_records, | 139 | &cleanup_expired_records, |
140 | NULL); | 140 | NULL); |
141 | } | 141 | } |
142 | } | 142 | } |
143 | 143 | ||
144 | 144 | ||
@@ -149,14 +149,14 @@ cleanup_expired_records(void *cls) | |||
149 | * @param success count of records deleted or #GNUNET_SYSERR | 149 | * @param success count of records deleted or #GNUNET_SYSERR |
150 | */ | 150 | */ |
151 | static void | 151 | static void |
152 | expire_records_continuation(void *cls, int success) | 152 | expire_records_continuation (void *cls, int success) |
153 | { | 153 | { |
154 | if (success > 0) | 154 | if (success > 0) |
155 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "%d records expired.\n", success); | 155 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%d records expired.\n", success); |
156 | GNUNET_assert(NULL == expire_task); | 156 | GNUNET_assert (NULL == expire_task); |
157 | expire_task = GNUNET_SCHEDULER_add_delayed( | 157 | expire_task = GNUNET_SCHEDULER_add_delayed ( |
158 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, | 158 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, |
159 | EXPIRED_RECORDS_CLEANUP_INTERVAL), | 159 | EXPIRED_RECORDS_CLEANUP_INTERVAL), |
160 | &cleanup_expired_records, | 160 | &cleanup_expired_records, |
161 | NULL); | 161 | NULL); |
162 | } | 162 | } |
@@ -171,9 +171,9 @@ expire_records_continuation(void *cls, int success) | |||
171 | * @return | 171 | * @return |
172 | */ | 172 | */ |
173 | static void * | 173 | static void * |
174 | client_connect_cb(void *cls, | 174 | client_connect_cb (void *cls, |
175 | struct GNUNET_SERVICE_Client *client, | 175 | struct GNUNET_SERVICE_Client *client, |
176 | struct GNUNET_MQ_Handle *mq) | 176 | struct GNUNET_MQ_Handle *mq) |
177 | { | 177 | { |
178 | num_clients++; | 178 | num_clients++; |
179 | return client; | 179 | return client; |
@@ -189,14 +189,14 @@ client_connect_cb(void *cls, | |||
189 | * @return #GNUNET_OK to continue iterating | 189 | * @return #GNUNET_OK to continue iterating |
190 | */ | 190 | */ |
191 | static int | 191 | static int |
192 | client_disconnect_it(void *cls, const struct GNUNET_HashCode *key, void *value) | 192 | client_disconnect_it (void *cls, const struct GNUNET_HashCode *key, void *value) |
193 | { | 193 | { |
194 | if (value == cls) | 194 | if (value == cls) |
195 | { | 195 | { |
196 | GNUNET_assert(GNUNET_YES == | 196 | GNUNET_assert (GNUNET_YES == |
197 | GNUNET_CONTAINER_multihashmap_remove(watchers, key, value)); | 197 | GNUNET_CONTAINER_multihashmap_remove (watchers, key, value)); |
198 | num_clients++; | 198 | num_clients++; |
199 | } | 199 | } |
200 | return GNUNET_OK; | 200 | return GNUNET_OK; |
201 | } | 201 | } |
202 | 202 | ||
@@ -208,18 +208,18 @@ client_disconnect_it(void *cls, const struct GNUNET_HashCode *key, void *value) | |||
208 | * @param client identification of the client | 208 | * @param client identification of the client |
209 | */ | 209 | */ |
210 | static void | 210 | static void |
211 | client_disconnect_cb(void *cls, | 211 | client_disconnect_cb (void *cls, |
212 | struct GNUNET_SERVICE_Client *client, | 212 | struct GNUNET_SERVICE_Client *client, |
213 | void *app_cls) | 213 | void *app_cls) |
214 | { | 214 | { |
215 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "A client disconnected, cleaning up.\n"); | 215 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "A client disconnected, cleaning up.\n"); |
216 | if (NULL != watchers) | 216 | if (NULL != watchers) |
217 | GNUNET_CONTAINER_multihashmap_iterate(watchers, | 217 | GNUNET_CONTAINER_multihashmap_iterate (watchers, |
218 | &client_disconnect_it, | 218 | &client_disconnect_it, |
219 | client); | 219 | client); |
220 | num_clients--; | 220 | num_clients--; |
221 | if ((0 == num_clients) && in_shutdown) | 221 | if ((0 == num_clients) && in_shutdown) |
222 | do_shutdown(); | 222 | do_shutdown (); |
223 | } | 223 | } |
224 | 224 | ||
225 | 225 | ||
@@ -232,35 +232,35 @@ client_disconnect_cb(void *cls, | |||
232 | * @return #GNUNET_YES to continue iteration | 232 | * @return #GNUNET_YES to continue iteration |
233 | */ | 233 | */ |
234 | static void | 234 | static void |
235 | record_iterator(void *cls, | 235 | record_iterator (void *cls, |
236 | const struct GNUNET_PEERSTORE_Record *record, | 236 | const struct GNUNET_PEERSTORE_Record *record, |
237 | const char *emsg) | 237 | const char *emsg) |
238 | { | 238 | { |
239 | struct GNUNET_PEERSTORE_Record *cls_record = cls; | 239 | struct GNUNET_PEERSTORE_Record *cls_record = cls; |
240 | struct GNUNET_MQ_Envelope *env; | 240 | struct GNUNET_MQ_Envelope *env; |
241 | 241 | ||
242 | if (NULL == record) | 242 | if (NULL == record) |
243 | { | ||
244 | /* No more records */ | ||
245 | struct GNUNET_MessageHeader *endmsg; | ||
246 | |||
247 | env = GNUNET_MQ_msg (endmsg, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END); | ||
248 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cls_record->client), env); | ||
249 | if (NULL == emsg) | ||
243 | { | 250 | { |
244 | /* No more records */ | 251 | GNUNET_SERVICE_client_continue (cls_record->client); |
245 | struct GNUNET_MessageHeader *endmsg; | ||
246 | |||
247 | env = GNUNET_MQ_msg(endmsg, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END); | ||
248 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(cls_record->client), env); | ||
249 | if (NULL == emsg) | ||
250 | { | ||
251 | GNUNET_SERVICE_client_continue(cls_record->client); | ||
252 | } | ||
253 | else | ||
254 | { | ||
255 | GNUNET_break(0); | ||
256 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to iterate: %s\n", emsg); | ||
257 | GNUNET_SERVICE_client_drop(cls_record->client); | ||
258 | } | ||
259 | PEERSTORE_destroy_record(cls_record); | ||
260 | return; | ||
261 | } | 252 | } |
253 | else | ||
254 | { | ||
255 | GNUNET_break (0); | ||
256 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to iterate: %s\n", emsg); | ||
257 | GNUNET_SERVICE_client_drop (cls_record->client); | ||
258 | } | ||
259 | PEERSTORE_destroy_record (cls_record); | ||
260 | return; | ||
261 | } | ||
262 | 262 | ||
263 | env = PEERSTORE_create_record_mq_envelope( | 263 | env = PEERSTORE_create_record_mq_envelope ( |
264 | record->sub_system, | 264 | record->sub_system, |
265 | &record->peer, | 265 | &record->peer, |
266 | record->key, | 266 | record->key, |
@@ -269,7 +269,7 @@ record_iterator(void *cls, | |||
269 | record->expiry, | 269 | record->expiry, |
270 | 0, | 270 | 0, |
271 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD); | 271 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD); |
272 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(cls_record->client), env); | 272 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cls_record->client), env); |
273 | } | 273 | } |
274 | 274 | ||
275 | 275 | ||
@@ -283,14 +283,14 @@ record_iterator(void *cls, | |||
283 | * @return #GNUNET_YES to continue iterating | 283 | * @return #GNUNET_YES to continue iterating |
284 | */ | 284 | */ |
285 | static int | 285 | static int |
286 | watch_notifier_it(void *cls, const struct GNUNET_HashCode *key, void *value) | 286 | watch_notifier_it (void *cls, const struct GNUNET_HashCode *key, void *value) |
287 | { | 287 | { |
288 | struct GNUNET_PEERSTORE_Record *record = cls; | 288 | struct GNUNET_PEERSTORE_Record *record = cls; |
289 | struct GNUNET_SERVICE_Client *client = value; | 289 | struct GNUNET_SERVICE_Client *client = value; |
290 | struct GNUNET_MQ_Envelope *env; | 290 | struct GNUNET_MQ_Envelope *env; |
291 | 291 | ||
292 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found a watcher to update.\n"); | 292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found a watcher to update.\n"); |
293 | env = PEERSTORE_create_record_mq_envelope( | 293 | env = PEERSTORE_create_record_mq_envelope ( |
294 | record->sub_system, | 294 | record->sub_system, |
295 | &record->peer, | 295 | &record->peer, |
296 | record->key, | 296 | record->key, |
@@ -299,7 +299,7 @@ watch_notifier_it(void *cls, const struct GNUNET_HashCode *key, void *value) | |||
299 | record->expiry, | 299 | record->expiry, |
300 | 0, | 300 | 0, |
301 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD); | 301 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD); |
302 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); | 302 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); |
303 | return GNUNET_YES; | 303 | return GNUNET_YES; |
304 | } | 304 | } |
305 | 305 | ||
@@ -310,15 +310,15 @@ watch_notifier_it(void *cls, const struct GNUNET_HashCode *key, void *value) | |||
310 | * @param record changed record to update watchers with | 310 | * @param record changed record to update watchers with |
311 | */ | 311 | */ |
312 | static void | 312 | static void |
313 | watch_notifier(struct GNUNET_PEERSTORE_Record *record) | 313 | watch_notifier (struct GNUNET_PEERSTORE_Record *record) |
314 | { | 314 | { |
315 | struct GNUNET_HashCode keyhash; | 315 | struct GNUNET_HashCode keyhash; |
316 | 316 | ||
317 | PEERSTORE_hash_key(record->sub_system, &record->peer, record->key, &keyhash); | 317 | PEERSTORE_hash_key (record->sub_system, &record->peer, record->key, &keyhash); |
318 | GNUNET_CONTAINER_multihashmap_get_multiple(watchers, | 318 | GNUNET_CONTAINER_multihashmap_get_multiple (watchers, |
319 | &keyhash, | 319 | &keyhash, |
320 | &watch_notifier_it, | 320 | &watch_notifier_it, |
321 | record); | 321 | record); |
322 | } | 322 | } |
323 | 323 | ||
324 | 324 | ||
@@ -329,20 +329,20 @@ watch_notifier(struct GNUNET_PEERSTORE_Record *record) | |||
329 | * @param hm the actual message | 329 | * @param hm the actual message |
330 | */ | 330 | */ |
331 | static void | 331 | static void |
332 | handle_watch_cancel(void *cls, const struct StoreKeyHashMessage *hm) | 332 | handle_watch_cancel (void *cls, const struct StoreKeyHashMessage *hm) |
333 | { | 333 | { |
334 | struct GNUNET_SERVICE_Client *client = cls; | 334 | struct GNUNET_SERVICE_Client *client = cls; |
335 | 335 | ||
336 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received a watch cancel request.\n"); | 336 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a watch cancel request.\n"); |
337 | if (GNUNET_OK != | 337 | if (GNUNET_OK != |
338 | GNUNET_CONTAINER_multihashmap_remove(watchers, &hm->keyhash, client)) | 338 | GNUNET_CONTAINER_multihashmap_remove (watchers, &hm->keyhash, client)) |
339 | { | 339 | { |
340 | GNUNET_break(0); | 340 | GNUNET_break (0); |
341 | GNUNET_SERVICE_client_drop(client); | 341 | GNUNET_SERVICE_client_drop (client); |
342 | return; | 342 | return; |
343 | } | 343 | } |
344 | num_clients++; | 344 | num_clients++; |
345 | GNUNET_SERVICE_client_continue(client); | 345 | GNUNET_SERVICE_client_continue (client); |
346 | } | 346 | } |
347 | 347 | ||
348 | 348 | ||
@@ -353,18 +353,18 @@ handle_watch_cancel(void *cls, const struct StoreKeyHashMessage *hm) | |||
353 | * @param hm the actual message | 353 | * @param hm the actual message |
354 | */ | 354 | */ |
355 | static void | 355 | static void |
356 | handle_watch(void *cls, const struct StoreKeyHashMessage *hm) | 356 | handle_watch (void *cls, const struct StoreKeyHashMessage *hm) |
357 | { | 357 | { |
358 | struct GNUNET_SERVICE_Client *client = cls; | 358 | struct GNUNET_SERVICE_Client *client = cls; |
359 | 359 | ||
360 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received a watch request.\n"); | 360 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a watch request.\n"); |
361 | num_clients--; /* do not count watchers */ | 361 | num_clients--; /* do not count watchers */ |
362 | GNUNET_SERVICE_client_mark_monitor(client); | 362 | GNUNET_SERVICE_client_mark_monitor (client); |
363 | GNUNET_CONTAINER_multihashmap_put(watchers, | 363 | GNUNET_CONTAINER_multihashmap_put (watchers, |
364 | &hm->keyhash, | 364 | &hm->keyhash, |
365 | client, | 365 | client, |
366 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 366 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
367 | GNUNET_SERVICE_client_continue(client); | 367 | GNUNET_SERVICE_client_continue (client); |
368 | } | 368 | } |
369 | 369 | ||
370 | 370 | ||
@@ -376,23 +376,23 @@ handle_watch(void *cls, const struct StoreKeyHashMessage *hm) | |||
376 | * @return #GNUNET_OK if @a srm is well-formed | 376 | * @return #GNUNET_OK if @a srm is well-formed |
377 | */ | 377 | */ |
378 | static int | 378 | static int |
379 | check_iterate(void *cls, const struct StoreRecordMessage *srm) | 379 | check_iterate (void *cls, const struct StoreRecordMessage *srm) |
380 | { | 380 | { |
381 | struct GNUNET_PEERSTORE_Record *record; | 381 | struct GNUNET_PEERSTORE_Record *record; |
382 | 382 | ||
383 | record = PEERSTORE_parse_record_message(srm); | 383 | record = PEERSTORE_parse_record_message (srm); |
384 | if (NULL == record) | 384 | if (NULL == record) |
385 | { | 385 | { |
386 | GNUNET_break(0); | 386 | GNUNET_break (0); |
387 | return GNUNET_SYSERR; | 387 | return GNUNET_SYSERR; |
388 | } | 388 | } |
389 | if (NULL == record->sub_system) | 389 | if (NULL == record->sub_system) |
390 | { | 390 | { |
391 | GNUNET_break(0); | 391 | GNUNET_break (0); |
392 | PEERSTORE_destroy_record(record); | 392 | PEERSTORE_destroy_record (record); |
393 | return GNUNET_SYSERR; | 393 | return GNUNET_SYSERR; |
394 | } | 394 | } |
395 | PEERSTORE_destroy_record(record); | 395 | PEERSTORE_destroy_record (record); |
396 | return GNUNET_OK; | 396 | return GNUNET_OK; |
397 | } | 397 | } |
398 | 398 | ||
@@ -404,30 +404,30 @@ check_iterate(void *cls, const struct StoreRecordMessage *srm) | |||
404 | * @param srm the actual message | 404 | * @param srm the actual message |
405 | */ | 405 | */ |
406 | static void | 406 | static void |
407 | handle_iterate(void *cls, const struct StoreRecordMessage *srm) | 407 | handle_iterate (void *cls, const struct StoreRecordMessage *srm) |
408 | { | 408 | { |
409 | struct GNUNET_SERVICE_Client *client = cls; | 409 | struct GNUNET_SERVICE_Client *client = cls; |
410 | struct GNUNET_PEERSTORE_Record *record; | 410 | struct GNUNET_PEERSTORE_Record *record; |
411 | 411 | ||
412 | record = PEERSTORE_parse_record_message(srm); | 412 | record = PEERSTORE_parse_record_message (srm); |
413 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 413 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
414 | "Iterate request: ss `%s', peer `%s', key `%s'\n", | 414 | "Iterate request: ss `%s', peer `%s', key `%s'\n", |
415 | record->sub_system, | 415 | record->sub_system, |
416 | GNUNET_i2s(&record->peer), | 416 | GNUNET_i2s (&record->peer), |
417 | (NULL == record->key) ? "NULL" : record->key); | 417 | (NULL == record->key) ? "NULL" : record->key); |
418 | record->client = client; | 418 | record->client = client; |
419 | if (GNUNET_OK != | 419 | if (GNUNET_OK != |
420 | db->iterate_records(db->cls, | 420 | db->iterate_records (db->cls, |
421 | record->sub_system, | 421 | record->sub_system, |
422 | (ntohs(srm->peer_set)) ? &record->peer : NULL, | 422 | (ntohs (srm->peer_set)) ? &record->peer : NULL, |
423 | record->key, | 423 | record->key, |
424 | &record_iterator, | 424 | &record_iterator, |
425 | record)) | 425 | record)) |
426 | { | 426 | { |
427 | GNUNET_break(0); | 427 | GNUNET_break (0); |
428 | GNUNET_SERVICE_client_drop(client); | 428 | GNUNET_SERVICE_client_drop (client); |
429 | PEERSTORE_destroy_record(record); | 429 | PEERSTORE_destroy_record (record); |
430 | } | 430 | } |
431 | } | 431 | } |
432 | 432 | ||
433 | 433 | ||
@@ -438,21 +438,21 @@ handle_iterate(void *cls, const struct StoreRecordMessage *srm) | |||
438 | * @param success result | 438 | * @param success result |
439 | */ | 439 | */ |
440 | static void | 440 | static void |
441 | store_record_continuation(void *cls, int success) | 441 | store_record_continuation (void *cls, int success) |
442 | { | 442 | { |
443 | struct GNUNET_PEERSTORE_Record *record = cls; | 443 | struct GNUNET_PEERSTORE_Record *record = cls; |
444 | 444 | ||
445 | if (GNUNET_OK == success) | 445 | if (GNUNET_OK == success) |
446 | { | 446 | { |
447 | watch_notifier(record); | 447 | watch_notifier (record); |
448 | GNUNET_SERVICE_client_continue(record->client); | 448 | GNUNET_SERVICE_client_continue (record->client); |
449 | } | 449 | } |
450 | else | 450 | else |
451 | { | 451 | { |
452 | GNUNET_break(0); | 452 | GNUNET_break (0); |
453 | GNUNET_SERVICE_client_drop(record->client); | 453 | GNUNET_SERVICE_client_drop (record->client); |
454 | } | 454 | } |
455 | PEERSTORE_destroy_record(record); | 455 | PEERSTORE_destroy_record (record); |
456 | } | 456 | } |
457 | 457 | ||
458 | 458 | ||
@@ -464,23 +464,23 @@ store_record_continuation(void *cls, int success) | |||
464 | * @return #GNUNET_OK if @a srm is well-formed | 464 | * @return #GNUNET_OK if @a srm is well-formed |
465 | */ | 465 | */ |
466 | static int | 466 | static int |
467 | check_store(void *cls, const struct StoreRecordMessage *srm) | 467 | check_store (void *cls, const struct StoreRecordMessage *srm) |
468 | { | 468 | { |
469 | struct GNUNET_PEERSTORE_Record *record; | 469 | struct GNUNET_PEERSTORE_Record *record; |
470 | 470 | ||
471 | record = PEERSTORE_parse_record_message(srm); | 471 | record = PEERSTORE_parse_record_message (srm); |
472 | if (NULL == record) | 472 | if (NULL == record) |
473 | { | 473 | { |
474 | GNUNET_break(0); | 474 | GNUNET_break (0); |
475 | return GNUNET_SYSERR; | 475 | return GNUNET_SYSERR; |
476 | } | 476 | } |
477 | if ((NULL == record->sub_system) || (NULL == record->key)) | 477 | if ((NULL == record->sub_system) || (NULL == record->key)) |
478 | { | 478 | { |
479 | GNUNET_break(0); | 479 | GNUNET_break (0); |
480 | PEERSTORE_destroy_record(record); | 480 | PEERSTORE_destroy_record (record); |
481 | return GNUNET_SYSERR; | 481 | return GNUNET_SYSERR; |
482 | } | 482 | } |
483 | PEERSTORE_destroy_record(record); | 483 | PEERSTORE_destroy_record (record); |
484 | return GNUNET_OK; | 484 | return GNUNET_OK; |
485 | } | 485 | } |
486 | 486 | ||
@@ -492,36 +492,36 @@ check_store(void *cls, const struct StoreRecordMessage *srm) | |||
492 | * @param srm the actual message | 492 | * @param srm the actual message |
493 | */ | 493 | */ |
494 | static void | 494 | static void |
495 | handle_store(void *cls, const struct StoreRecordMessage *srm) | 495 | handle_store (void *cls, const struct StoreRecordMessage *srm) |
496 | { | 496 | { |
497 | struct GNUNET_SERVICE_Client *client = cls; | 497 | struct GNUNET_SERVICE_Client *client = cls; |
498 | struct GNUNET_PEERSTORE_Record *record; | 498 | struct GNUNET_PEERSTORE_Record *record; |
499 | 499 | ||
500 | record = PEERSTORE_parse_record_message(srm); | 500 | record = PEERSTORE_parse_record_message (srm); |
501 | GNUNET_log( | 501 | GNUNET_log ( |
502 | GNUNET_ERROR_TYPE_INFO, | 502 | GNUNET_ERROR_TYPE_INFO, |
503 | "Received a store request. Sub system `%s' Peer `%s Key `%s' Options: %u.\n", | 503 | "Received a store request. Sub system `%s' Peer `%s Key `%s' Options: %u.\n", |
504 | record->sub_system, | 504 | record->sub_system, |
505 | GNUNET_i2s(&record->peer), | 505 | GNUNET_i2s (&record->peer), |
506 | record->key, | 506 | record->key, |
507 | (uint32_t)ntohl(srm->options)); | 507 | (uint32_t) ntohl (srm->options)); |
508 | record->client = client; | 508 | record->client = client; |
509 | if (GNUNET_OK != db->store_record(db->cls, | 509 | if (GNUNET_OK != db->store_record (db->cls, |
510 | record->sub_system, | 510 | record->sub_system, |
511 | &record->peer, | 511 | &record->peer, |
512 | record->key, | 512 | record->key, |
513 | record->value, | 513 | record->value, |
514 | record->value_size, | 514 | record->value_size, |
515 | record->expiry, | 515 | record->expiry, |
516 | ntohl(srm->options), | 516 | ntohl (srm->options), |
517 | &store_record_continuation, | 517 | &store_record_continuation, |
518 | record)) | 518 | record)) |
519 | { | 519 | { |
520 | GNUNET_break(0); | 520 | GNUNET_break (0); |
521 | PEERSTORE_destroy_record(record); | 521 | PEERSTORE_destroy_record (record); |
522 | GNUNET_SERVICE_client_drop(client); | 522 | GNUNET_SERVICE_client_drop (client); |
523 | return; | 523 | return; |
524 | } | 524 | } |
525 | } | 525 | } |
526 | 526 | ||
527 | 527 | ||
@@ -533,69 +533,69 @@ handle_store(void *cls, const struct StoreRecordMessage *srm) | |||
533 | * @param service the initialized service | 533 | * @param service the initialized service |
534 | */ | 534 | */ |
535 | static void | 535 | static void |
536 | run(void *cls, | 536 | run (void *cls, |
537 | const struct GNUNET_CONFIGURATION_Handle *c, | 537 | const struct GNUNET_CONFIGURATION_Handle *c, |
538 | struct GNUNET_SERVICE_Handle *service) | 538 | struct GNUNET_SERVICE_Handle *service) |
539 | { | 539 | { |
540 | char *database; | 540 | char *database; |
541 | 541 | ||
542 | in_shutdown = GNUNET_NO; | 542 | in_shutdown = GNUNET_NO; |
543 | cfg = c; | 543 | cfg = c; |
544 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, | 544 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, |
545 | "peerstore", | 545 | "peerstore", |
546 | "DATABASE", | 546 | "DATABASE", |
547 | &database)) | 547 | &database)) |
548 | { | 548 | { |
549 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, | 549 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
550 | "peerstore", | 550 | "peerstore", |
551 | "DATABASE"); | 551 | "DATABASE"); |
552 | GNUNET_SCHEDULER_shutdown(); | 552 | GNUNET_SCHEDULER_shutdown (); |
553 | return; | 553 | return; |
554 | } | 554 | } |
555 | GNUNET_asprintf(&db_lib_name, "libgnunet_plugin_peerstore_%s", database); | 555 | GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_peerstore_%s", database); |
556 | db = GNUNET_PLUGIN_load(db_lib_name, (void *)cfg); | 556 | db = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg); |
557 | GNUNET_free(database); | 557 | GNUNET_free (database); |
558 | if (NULL == db) | 558 | if (NULL == db) |
559 | { | 559 | { |
560 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 560 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
561 | _("Could not load database backend `%s'\n"), | 561 | _ ("Could not load database backend `%s'\n"), |
562 | db_lib_name); | 562 | db_lib_name); |
563 | GNUNET_SCHEDULER_shutdown(); | 563 | GNUNET_SCHEDULER_shutdown (); |
564 | return; | 564 | return; |
565 | } | 565 | } |
566 | watchers = GNUNET_CONTAINER_multihashmap_create(10, GNUNET_NO); | 566 | watchers = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); |
567 | expire_task = GNUNET_SCHEDULER_add_now(&cleanup_expired_records, NULL); | 567 | expire_task = GNUNET_SCHEDULER_add_now (&cleanup_expired_records, NULL); |
568 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); | 568 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
569 | } | 569 | } |
570 | 570 | ||
571 | 571 | ||
572 | /** | 572 | /** |
573 | * Define "main" method using service macro. | 573 | * Define "main" method using service macro. |
574 | */ | 574 | */ |
575 | GNUNET_SERVICE_MAIN( | 575 | GNUNET_SERVICE_MAIN ( |
576 | "peerstore", | 576 | "peerstore", |
577 | GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, | 577 | GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, |
578 | &run, | 578 | &run, |
579 | &client_connect_cb, | 579 | &client_connect_cb, |
580 | &client_disconnect_cb, | 580 | &client_disconnect_cb, |
581 | NULL, | 581 | NULL, |
582 | GNUNET_MQ_hd_var_size(store, | 582 | GNUNET_MQ_hd_var_size (store, |
583 | GNUNET_MESSAGE_TYPE_PEERSTORE_STORE, | 583 | GNUNET_MESSAGE_TYPE_PEERSTORE_STORE, |
584 | struct StoreRecordMessage, | 584 | struct StoreRecordMessage, |
585 | NULL), | 585 | NULL), |
586 | GNUNET_MQ_hd_var_size(iterate, | 586 | GNUNET_MQ_hd_var_size (iterate, |
587 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE, | 587 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE, |
588 | struct StoreRecordMessage, | 588 | struct StoreRecordMessage, |
589 | NULL), | 589 | NULL), |
590 | GNUNET_MQ_hd_fixed_size(watch, | 590 | GNUNET_MQ_hd_fixed_size (watch, |
591 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH, | 591 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH, |
592 | struct StoreKeyHashMessage, | 592 | struct StoreKeyHashMessage, |
593 | NULL), | 593 | NULL), |
594 | GNUNET_MQ_hd_fixed_size(watch_cancel, | 594 | GNUNET_MQ_hd_fixed_size (watch_cancel, |
595 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL, | 595 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL, |
596 | struct StoreKeyHashMessage, | 596 | struct StoreKeyHashMessage, |
597 | NULL), | 597 | NULL), |
598 | GNUNET_MQ_handler_end()); | 598 | GNUNET_MQ_handler_end ()); |
599 | 599 | ||
600 | 600 | ||
601 | /* end of gnunet-service-peerstore.c */ | 601 | /* end of gnunet-service-peerstore.c */ |