diff options
author | Omar Tarabai <tarabai@devegypt.com> | 2014-08-04 11:06:52 +0000 |
---|---|---|
committer | Omar Tarabai <tarabai@devegypt.com> | 2014-08-04 11:06:52 +0000 |
commit | 4371b0fcd9b50f78ca27ac48adf2f4663b2dfc9b (patch) | |
tree | 05c40696267088fa94cdb0a94b3c079b38ea8ed2 /src/peerstore/gnunet-service-peerstore.c | |
parent | ef494e57d189e2b7c038104e44398d11026ff6a6 (diff) | |
download | gnunet-4371b0fcd9b50f78ca27ac48adf2f4663b2dfc9b.tar.gz gnunet-4371b0fcd9b50f78ca27ac48adf2f4663b2dfc9b.zip |
peerstore: indentation
Diffstat (limited to 'src/peerstore/gnunet-service-peerstore.c')
-rw-r--r-- | src/peerstore/gnunet-service-peerstore.c | 337 |
1 files changed, 167 insertions, 170 deletions
diff --git a/src/peerstore/gnunet-service-peerstore.c b/src/peerstore/gnunet-service-peerstore.c index c93d2cc95..c674d3c11 100644 --- a/src/peerstore/gnunet-service-peerstore.c +++ b/src/peerstore/gnunet-service-peerstore.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) | 3 | (C) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -53,7 +53,7 @@ struct ClientEntry | |||
53 | /** | 53 | /** |
54 | * Interval for expired records cleanup (in seconds) | 54 | * Interval for expired records cleanup (in seconds) |
55 | */ | 55 | */ |
56 | #define EXPIRED_RECORDS_CLEANUP_INTERVAL 300 /* 5mins */ | 56 | #define EXPIRED_RECORDS_CLEANUP_INTERVAL 300 /* 5mins */ |
57 | 57 | ||
58 | /** | 58 | /** |
59 | * Our configuration. | 59 | * Our configuration. |
@@ -98,27 +98,29 @@ int in_shutdown; | |||
98 | /** | 98 | /** |
99 | * Perform the actual shutdown operations | 99 | * Perform the actual shutdown operations |
100 | */ | 100 | */ |
101 | void do_shutdown () | 101 | void |
102 | do_shutdown () | ||
102 | { | 103 | { |
103 | if(NULL != db_lib_name) | 104 | if (NULL != db_lib_name) |
104 | { | 105 | { |
105 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, db)); | 106 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, db)); |
106 | GNUNET_free (db_lib_name); | 107 | GNUNET_free (db_lib_name); |
107 | db_lib_name = NULL; | 108 | db_lib_name = NULL; |
108 | } | 109 | } |
109 | if(NULL != nc) | 110 | if (NULL != nc) |
110 | { | 111 | { |
111 | GNUNET_SERVER_notification_context_destroy(nc); | 112 | GNUNET_SERVER_notification_context_destroy (nc); |
112 | nc = NULL; | 113 | nc = NULL; |
113 | } | 114 | } |
114 | if(NULL != watchers) | 115 | if (NULL != watchers) |
115 | { | 116 | { |
116 | GNUNET_CONTAINER_multihashmap_destroy(watchers); | 117 | GNUNET_CONTAINER_multihashmap_destroy (watchers); |
117 | watchers = NULL; | 118 | watchers = NULL; |
118 | } | 119 | } |
119 | GNUNET_SCHEDULER_shutdown(); | 120 | GNUNET_SCHEDULER_shutdown (); |
120 | } | 121 | } |
121 | 122 | ||
123 | |||
122 | /** | 124 | /** |
123 | * Task run during shutdown. | 125 | * Task run during shutdown. |
124 | * | 126 | * |
@@ -126,34 +128,36 @@ void do_shutdown () | |||
126 | * @param tc unused | 128 | * @param tc unused |
127 | */ | 129 | */ |
128 | static void | 130 | static void |
129 | shutdown_task (void *cls, | 131 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
130 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
131 | { | 132 | { |
132 | in_shutdown = GNUNET_YES; | 133 | in_shutdown = GNUNET_YES; |
133 | if (NULL == client_head) /* Only when no connected clients. */ | 134 | if (NULL == client_head) /* Only when no connected clients. */ |
134 | do_shutdown (); | 135 | do_shutdown (); |
135 | } | 136 | } |
136 | 137 | ||
138 | |||
137 | /** | 139 | /** |
138 | * Deletes any expired records from storage | 140 | * Deletes any expired records from storage |
139 | */ | 141 | */ |
140 | static void | 142 | static void |
141 | cleanup_expired_records(void *cls, | 143 | cleanup_expired_records (void *cls, |
142 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 144 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
143 | { | 145 | { |
144 | int deleted; | 146 | int deleted; |
145 | 147 | ||
146 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 148 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
147 | return; | 149 | return; |
148 | GNUNET_assert(NULL != db); | 150 | GNUNET_assert (NULL != db); |
149 | deleted = db->expire_records(db->cls, GNUNET_TIME_absolute_get()); | 151 | deleted = db->expire_records (db->cls, GNUNET_TIME_absolute_get ()); |
150 | if (deleted > 0) | 152 | if (deleted > 0) |
151 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "%d records expired.\n", deleted); | 153 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%d records expired.\n", deleted); |
152 | GNUNET_SCHEDULER_add_delayed( | 154 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
153 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, EXPIRED_RECORDS_CLEANUP_INTERVAL), | 155 | (GNUNET_TIME_UNIT_SECONDS, |
154 | &cleanup_expired_records, NULL); | 156 | EXPIRED_RECORDS_CLEANUP_INTERVAL), |
157 | &cleanup_expired_records, NULL); | ||
155 | } | 158 | } |
156 | 159 | ||
160 | |||
157 | /** | 161 | /** |
158 | * Search for a disconnected client and remove it | 162 | * Search for a disconnected client and remove it |
159 | * | 163 | * |
@@ -162,15 +166,15 @@ cleanup_expired_records(void *cls, | |||
162 | * @param value the watcher client, a 'struct GNUNET_SERVER_Client *' | 166 | * @param value the watcher client, a 'struct GNUNET_SERVER_Client *' |
163 | * @return #GNUNET_OK to continue iterating | 167 | * @return #GNUNET_OK to continue iterating |
164 | */ | 168 | */ |
165 | static int client_disconnect_it(void *cls, | 169 | static int |
166 | const struct GNUNET_HashCode *key, | 170 | client_disconnect_it (void *cls, const struct GNUNET_HashCode *key, void *value) |
167 | void *value) | ||
168 | { | 171 | { |
169 | if(cls == value) | 172 | if (cls == value) |
170 | GNUNET_CONTAINER_multihashmap_remove(watchers, key, value); | 173 | GNUNET_CONTAINER_multihashmap_remove (watchers, key, value); |
171 | return GNUNET_OK; | 174 | return GNUNET_OK; |
172 | } | 175 | } |
173 | 176 | ||
177 | |||
174 | /** | 178 | /** |
175 | * A client disconnected. Remove all of its data structure entries. | 179 | * A client disconnected. Remove all of its data structure entries. |
176 | * | 180 | * |
@@ -178,16 +182,14 @@ static int client_disconnect_it(void *cls, | |||
178 | * @param client identification of the client | 182 | * @param client identification of the client |
179 | */ | 183 | */ |
180 | static void | 184 | static void |
181 | handle_client_disconnect (void *cls, | 185 | handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) |
182 | struct GNUNET_SERVER_Client | ||
183 | * client) | ||
184 | { | 186 | { |
185 | struct ClientEntry *ce; | 187 | struct ClientEntry *ce; |
186 | 188 | ||
187 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "A client disconnected, cleaning up.\n"); | 189 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "A client disconnected, cleaning up.\n"); |
188 | if(NULL != watchers) | 190 | if (NULL != watchers) |
189 | GNUNET_CONTAINER_multihashmap_iterate(watchers, | 191 | GNUNET_CONTAINER_multihashmap_iterate (watchers, &client_disconnect_it, |
190 | &client_disconnect_it, client); | 192 | client); |
191 | ce = client_head; | 193 | ce = client_head; |
192 | while (ce != NULL) | 194 | while (ce != NULL) |
193 | { | 195 | { |
@@ -203,6 +205,7 @@ handle_client_disconnect (void *cls, | |||
203 | do_shutdown (); | 205 | do_shutdown (); |
204 | } | 206 | } |
205 | 207 | ||
208 | |||
206 | /** | 209 | /** |
207 | * Function called by for each matching record. | 210 | * Function called by for each matching record. |
208 | * | 211 | * |
@@ -212,28 +215,24 @@ handle_client_disconnect (void *cls, | |||
212 | * @return #GNUNET_YES to continue iteration | 215 | * @return #GNUNET_YES to continue iteration |
213 | */ | 216 | */ |
214 | static int | 217 | static int |
215 | record_iterator (void *cls, | 218 | record_iterator (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) |
216 | struct GNUNET_PEERSTORE_Record *record, | ||
217 | char *emsg) | ||
218 | { | 219 | { |
219 | struct GNUNET_SERVER_Client *client = cls; | 220 | struct GNUNET_SERVER_Client *client = cls; |
220 | struct StoreRecordMessage *srm; | 221 | struct StoreRecordMessage *srm; |
221 | 222 | ||
222 | srm = | 223 | srm = |
223 | PEERSTORE_create_record_message(record->sub_system, | 224 | PEERSTORE_create_record_message (record->sub_system, record->peer, |
224 | record->peer, | 225 | record->key, record->value, |
225 | record->key, | 226 | record->value_size, record->expiry, |
226 | record->value, | 227 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD); |
227 | record->value_size, | ||
228 | record->expiry, | ||
229 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD); | ||
230 | GNUNET_SERVER_notification_context_unicast (nc, client, | 228 | GNUNET_SERVER_notification_context_unicast (nc, client, |
231 | (struct GNUNET_MessageHeader *)srm, | 229 | (struct GNUNET_MessageHeader *) |
232 | GNUNET_NO); | 230 | srm, GNUNET_NO); |
233 | GNUNET_free(srm); | 231 | GNUNET_free (srm); |
234 | return GNUNET_YES; | 232 | return GNUNET_YES; |
235 | } | 233 | } |
236 | 234 | ||
235 | |||
237 | /** | 236 | /** |
238 | * Iterator over all watcher clients | 237 | * Iterator over all watcher clients |
239 | * to notify them of a new record | 238 | * to notify them of a new record |
@@ -243,44 +242,43 @@ record_iterator (void *cls, | |||
243 | * @param value the watcher client, a 'struct GNUNET_SERVER_Client *' | 242 | * @param value the watcher client, a 'struct GNUNET_SERVER_Client *' |
244 | * @return #GNUNET_YES to continue iterating | 243 | * @return #GNUNET_YES to continue iterating |
245 | */ | 244 | */ |
246 | static int watch_notifier_it(void *cls, | 245 | static int |
247 | const struct GNUNET_HashCode *key, | 246 | watch_notifier_it (void *cls, const struct GNUNET_HashCode *key, void *value) |
248 | void *value) | ||
249 | { | 247 | { |
250 | struct GNUNET_PEERSTORE_Record *record = cls; | 248 | struct GNUNET_PEERSTORE_Record *record = cls; |
251 | struct GNUNET_SERVER_Client *client = value; | 249 | struct GNUNET_SERVER_Client *client = value; |
252 | struct StoreRecordMessage *srm; | 250 | struct StoreRecordMessage *srm; |
253 | 251 | ||
254 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found a watcher to update.\n"); | 252 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found a watcher to update.\n"); |
255 | srm = PEERSTORE_create_record_message(record->sub_system, | 253 | srm = |
256 | record->peer, | 254 | PEERSTORE_create_record_message (record->sub_system, record->peer, |
257 | record->key, | 255 | record->key, record->value, |
258 | record->value, | 256 | record->value_size, record->expiry, |
259 | record->value_size, | 257 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD); |
260 | record->expiry, | 258 | GNUNET_SERVER_notification_context_unicast (nc, client, |
261 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD); | 259 | (const struct GNUNET_MessageHeader |
262 | GNUNET_SERVER_notification_context_unicast(nc, client, | 260 | *) srm, GNUNET_NO); |
263 | (const struct GNUNET_MessageHeader *)srm, GNUNET_NO); | 261 | GNUNET_free (srm); |
264 | GNUNET_free(srm); | ||
265 | return GNUNET_YES; | 262 | return GNUNET_YES; |
266 | } | 263 | } |
267 | 264 | ||
265 | |||
268 | /** | 266 | /** |
269 | * Given a new record, notifies watchers | 267 | * Given a new record, notifies watchers |
270 | * | 268 | * |
271 | * @param record changed record to update watchers with | 269 | * @param record changed record to update watchers with |
272 | */ | 270 | */ |
273 | static void watch_notifier (struct GNUNET_PEERSTORE_Record *record) | 271 | static void |
272 | watch_notifier (struct GNUNET_PEERSTORE_Record *record) | ||
274 | { | 273 | { |
275 | struct GNUNET_HashCode keyhash; | 274 | struct GNUNET_HashCode keyhash; |
276 | 275 | ||
277 | PEERSTORE_hash_key(record->sub_system, | 276 | PEERSTORE_hash_key (record->sub_system, record->peer, record->key, &keyhash); |
278 | record->peer, | 277 | GNUNET_CONTAINER_multihashmap_get_multiple (watchers, &keyhash, |
279 | record->key, | 278 | &watch_notifier_it, record); |
280 | &keyhash); | ||
281 | GNUNET_CONTAINER_multihashmap_get_multiple(watchers, &keyhash, &watch_notifier_it, record); | ||
282 | } | 279 | } |
283 | 280 | ||
281 | |||
284 | /** | 282 | /** |
285 | * Handle a watch cancel request from client | 283 | * Handle a watch cancel request from client |
286 | * | 284 | * |
@@ -288,18 +286,19 @@ static void watch_notifier (struct GNUNET_PEERSTORE_Record *record) | |||
288 | * @param client identification of the client | 286 | * @param client identification of the client |
289 | * @param message the actual message | 287 | * @param message the actual message |
290 | */ | 288 | */ |
291 | static void handle_watch_cancel (void *cls, | 289 | static void |
292 | struct GNUNET_SERVER_Client *client, | 290 | handle_watch_cancel (void *cls, struct GNUNET_SERVER_Client *client, |
293 | const struct GNUNET_MessageHeader *message) | 291 | const struct GNUNET_MessageHeader *message) |
294 | { | 292 | { |
295 | struct StoreKeyHashMessage *hm; | 293 | struct StoreKeyHashMessage *hm; |
296 | 294 | ||
297 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received a watch cancel request.\n"); | 295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a watch cancel request.\n"); |
298 | hm = (struct StoreKeyHashMessage *) message; | 296 | hm = (struct StoreKeyHashMessage *) message; |
299 | GNUNET_CONTAINER_multihashmap_remove(watchers, &hm->keyhash, client); | 297 | GNUNET_CONTAINER_multihashmap_remove (watchers, &hm->keyhash, client); |
300 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 298 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
301 | } | 299 | } |
302 | 300 | ||
301 | |||
303 | /** | 302 | /** |
304 | * Handle a watch request from client | 303 | * Handle a watch request from client |
305 | * | 304 | * |
@@ -307,21 +306,22 @@ static void handle_watch_cancel (void *cls, | |||
307 | * @param client identification of the client | 306 | * @param client identification of the client |
308 | * @param message the actual message | 307 | * @param message the actual message |
309 | */ | 308 | */ |
310 | static void handle_watch (void *cls, | 309 | static void |
311 | struct GNUNET_SERVER_Client *client, | 310 | handle_watch (void *cls, struct GNUNET_SERVER_Client *client, |
312 | const struct GNUNET_MessageHeader *message) | 311 | const struct GNUNET_MessageHeader *message) |
313 | { | 312 | { |
314 | struct StoreKeyHashMessage *hm; | 313 | struct StoreKeyHashMessage *hm; |
315 | 314 | ||
316 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received a watch request.\n"); | 315 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a watch request.\n"); |
317 | hm = (struct StoreKeyHashMessage *) message; | 316 | hm = (struct StoreKeyHashMessage *) message; |
318 | GNUNET_SERVER_client_mark_monitor(client); | 317 | GNUNET_SERVER_client_mark_monitor (client); |
319 | GNUNET_SERVER_notification_context_add(nc, client); | 318 | GNUNET_SERVER_notification_context_add (nc, client); |
320 | GNUNET_CONTAINER_multihashmap_put(watchers, &hm->keyhash, | 319 | GNUNET_CONTAINER_multihashmap_put (watchers, &hm->keyhash, client, |
321 | client, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 320 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
322 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 321 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
323 | } | 322 | } |
324 | 323 | ||
324 | |||
325 | /** | 325 | /** |
326 | * Handle an iterate request from client | 326 | * Handle an iterate request from client |
327 | * | 327 | * |
@@ -329,55 +329,54 @@ static void handle_watch (void *cls, | |||
329 | * @param client identification of the client | 329 | * @param client identification of the client |
330 | * @param message the actual message | 330 | * @param message the actual message |
331 | */ | 331 | */ |
332 | static void handle_iterate (void *cls, | 332 | static void |
333 | struct GNUNET_SERVER_Client *client, | 333 | handle_iterate (void *cls, struct GNUNET_SERVER_Client *client, |
334 | const struct GNUNET_MessageHeader *message) | 334 | const struct GNUNET_MessageHeader *message) |
335 | { | 335 | { |
336 | struct GNUNET_PEERSTORE_Record *record; | 336 | struct GNUNET_PEERSTORE_Record *record; |
337 | struct GNUNET_MessageHeader *endmsg; | 337 | struct GNUNET_MessageHeader *endmsg; |
338 | 338 | ||
339 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received an iterate request.\n"); | 339 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received an iterate request.\n"); |
340 | record = PEERSTORE_parse_record_message(message); | 340 | record = PEERSTORE_parse_record_message (message); |
341 | if(NULL == record) | 341 | if (NULL == record) |
342 | { | 342 | { |
343 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Malformed iterate request.\n")); | 343 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Malformed iterate request.\n")); |
344 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 344 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
345 | return; | 345 | return; |
346 | } | 346 | } |
347 | if(NULL == record->sub_system) | 347 | if (NULL == record->sub_system) |
348 | { | 348 | { |
349 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 349 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
350 | _("Sub system not supplied in client iterate request.\n")); | 350 | _("Sub system not supplied in client iterate request.\n")); |
351 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 351 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
352 | return; | 352 | return; |
353 | } | 353 | } |
354 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 354 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
355 | "Iterate request: ss `%s', peer `%s', key `%s'\n", | 355 | "Iterate request: ss `%s', peer `%s', key `%s'\n", |
356 | record->sub_system, | 356 | record->sub_system, |
357 | (NULL == record->peer) ? "NULL" : GNUNET_i2s(record->peer), | 357 | (NULL == record->peer) ? "NULL" : GNUNET_i2s (record->peer), |
358 | (NULL == record->key) ? "NULL" : record->key); | 358 | (NULL == record->key) ? "NULL" : record->key); |
359 | GNUNET_SERVER_notification_context_add(nc, client); | 359 | GNUNET_SERVER_notification_context_add (nc, client); |
360 | if(GNUNET_OK == db->iterate_records(db->cls, | 360 | if (GNUNET_OK == |
361 | record->sub_system, | 361 | db->iterate_records (db->cls, record->sub_system, record->peer, |
362 | record->peer, | 362 | record->key, &record_iterator, client)) |
363 | record->key, | ||
364 | &record_iterator, | ||
365 | client)) | ||
366 | { | 363 | { |
367 | endmsg = GNUNET_new(struct GNUNET_MessageHeader); | 364 | endmsg = GNUNET_new (struct GNUNET_MessageHeader); |
368 | endmsg->size = htons(sizeof(struct GNUNET_MessageHeader)); | 365 | |
369 | endmsg->type = htons(GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END); | 366 | endmsg->size = htons (sizeof (struct GNUNET_MessageHeader)); |
370 | GNUNET_SERVER_notification_context_unicast(nc, client, endmsg, GNUNET_NO); | 367 | endmsg->type = htons (GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END); |
371 | GNUNET_free(endmsg); | 368 | GNUNET_SERVER_notification_context_unicast (nc, client, endmsg, GNUNET_NO); |
372 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 369 | GNUNET_free (endmsg); |
370 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
373 | } | 371 | } |
374 | else | 372 | else |
375 | { | 373 | { |
376 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 374 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
377 | } | 375 | } |
378 | PEERSTORE_destroy_record(record); | 376 | PEERSTORE_destroy_record (record); |
379 | } | 377 | } |
380 | 378 | ||
379 | |||
381 | /** | 380 | /** |
382 | * Handle a store request from client | 381 | * Handle a store request from client |
383 | * | 382 | * |
@@ -385,54 +384,51 @@ static void handle_iterate (void *cls, | |||
385 | * @param client identification of the client | 384 | * @param client identification of the client |
386 | * @param message the actual message | 385 | * @param message the actual message |
387 | */ | 386 | */ |
388 | static void handle_store (void *cls, | 387 | static void |
389 | struct GNUNET_SERVER_Client *client, | 388 | handle_store (void *cls, struct GNUNET_SERVER_Client *client, |
390 | const struct GNUNET_MessageHeader *message) | 389 | const struct GNUNET_MessageHeader *message) |
391 | { | 390 | { |
392 | struct GNUNET_PEERSTORE_Record *record; | 391 | struct GNUNET_PEERSTORE_Record *record; |
393 | struct StoreRecordMessage *srm; | 392 | struct StoreRecordMessage *srm; |
394 | 393 | ||
395 | record = PEERSTORE_parse_record_message(message); | 394 | record = PEERSTORE_parse_record_message (message); |
396 | if(NULL == record) | 395 | if (NULL == record) |
397 | { | 396 | { |
398 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Malformed store request from client\n")); | 397 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
399 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 398 | _("Malformed store request from client\n")); |
399 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
400 | return; | 400 | return; |
401 | } | 401 | } |
402 | srm = (struct StoreRecordMessage *)message; | 402 | srm = (struct StoreRecordMessage *) message; |
403 | if(NULL == record->sub_system | 403 | if (NULL == record->sub_system || NULL == record->peer || NULL == record->key) |
404 | || NULL == record->peer | ||
405 | || NULL == record->key) | ||
406 | { | 404 | { |
407 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Full key not supplied in client store request\n")); | 405 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
408 | PEERSTORE_destroy_record(record); | 406 | _("Full key not supplied in client store request\n")); |
409 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 407 | PEERSTORE_destroy_record (record); |
408 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
410 | return; | 409 | return; |
411 | } | 410 | } |
412 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received a store request (size: %lu) for sub system `%s', peer `%s', key `%s'\n", | 411 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
413 | record->value_size, | 412 | "Received a store request (size: %lu) for sub system `%s', peer `%s', key `%s'\n", |
414 | record->sub_system, | 413 | record->value_size, record->sub_system, GNUNET_i2s (record->peer), |
415 | GNUNET_i2s (record->peer), | 414 | record->key); |
416 | record->key); | 415 | if (GNUNET_OK != |
417 | if(GNUNET_OK != db->store_record(db->cls, | 416 | db->store_record (db->cls, record->sub_system, record->peer, record->key, |
418 | record->sub_system, | 417 | record->value, record->value_size, *record->expiry, |
419 | record->peer, | 418 | srm->options)) |
420 | record->key, | ||
421 | record->value, | ||
422 | record->value_size, | ||
423 | *record->expiry, | ||
424 | srm->options)) | ||
425 | { | 419 | { |
426 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Failed to store requested value, sqlite database error.")); | 420 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
427 | PEERSTORE_destroy_record(record); | 421 | _("Failed to store requested value, sqlite database error.")); |
428 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 422 | PEERSTORE_destroy_record (record); |
423 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
429 | return; | 424 | return; |
430 | } | 425 | } |
431 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 426 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
432 | watch_notifier(record); | 427 | watch_notifier (record); |
433 | PEERSTORE_destroy_record(record); | 428 | PEERSTORE_destroy_record (record); |
434 | } | 429 | } |
435 | 430 | ||
431 | |||
436 | /** | 432 | /** |
437 | * Creates an entry for a new client or returns it if it already exists. | 433 | * Creates an entry for a new client or returns it if it already exists. |
438 | * | 434 | * |
@@ -462,6 +458,7 @@ make_client_entry (struct GNUNET_SERVER_Client *client) | |||
462 | return ce; | 458 | return ce; |
463 | } | 459 | } |
464 | 460 | ||
461 | |||
465 | /** | 462 | /** |
466 | * Callback on a new client connection | 463 | * Callback on a new client connection |
467 | * | 464 | * |
@@ -475,6 +472,7 @@ handle_client_connect (void *cls, struct GNUNET_SERVER_Client *client) | |||
475 | make_client_entry (client); | 472 | make_client_entry (client); |
476 | } | 473 | } |
477 | 474 | ||
475 | |||
478 | /** | 476 | /** |
479 | * Peerstore service runner. | 477 | * Peerstore service runner. |
480 | * | 478 | * |
@@ -483,47 +481,48 @@ handle_client_connect (void *cls, struct GNUNET_SERVER_Client *client) | |||
483 | * @param c configuration to use | 481 | * @param c configuration to use |
484 | */ | 482 | */ |
485 | static void | 483 | static void |
486 | run (void *cls, | 484 | run (void *cls, struct GNUNET_SERVER_Handle *server, |
487 | struct GNUNET_SERVER_Handle *server, | ||
488 | const struct GNUNET_CONFIGURATION_Handle *c) | 485 | const struct GNUNET_CONFIGURATION_Handle *c) |
489 | { | 486 | { |
490 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 487 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
491 | {&handle_store, NULL, GNUNET_MESSAGE_TYPE_PEERSTORE_STORE, 0}, | 488 | {&handle_store, NULL, GNUNET_MESSAGE_TYPE_PEERSTORE_STORE, 0}, |
492 | {&handle_iterate, NULL, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE, 0}, | 489 | {&handle_iterate, NULL, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE, 0}, |
493 | {&handle_watch, NULL, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH, sizeof(struct StoreKeyHashMessage)}, | 490 | {&handle_watch, NULL, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH, |
494 | {&handle_watch_cancel, NULL, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL, sizeof(struct StoreKeyHashMessage)}, | 491 | sizeof (struct StoreKeyHashMessage)}, |
495 | {NULL, NULL, 0, 0} | 492 | {&handle_watch_cancel, NULL, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL, |
493 | sizeof (struct StoreKeyHashMessage)}, | ||
494 | {NULL, NULL, 0, 0} | ||
496 | }; | 495 | }; |
497 | char *database; | 496 | char *database; |
498 | 497 | ||
499 | in_shutdown = GNUNET_NO; | 498 | in_shutdown = GNUNET_NO; |
500 | cfg = c; | 499 | cfg = c; |
501 | if (GNUNET_OK != | 500 | if (GNUNET_OK != |
502 | GNUNET_CONFIGURATION_get_value_string (cfg, "peerstore", "DATABASE", | 501 | GNUNET_CONFIGURATION_get_value_string (cfg, "peerstore", "DATABASE", |
503 | &database)) | 502 | &database)) |
504 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("No database backend configured\n")); | 503 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("No database backend configured\n")); |
505 | 504 | ||
506 | else | 505 | else |
507 | { | 506 | { |
508 | GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_peerstore_%s", database); | 507 | GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_peerstore_%s", database); |
509 | db = GNUNET_PLUGIN_load(db_lib_name, (void *) cfg); | 508 | db = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg); |
510 | GNUNET_free(database); | 509 | GNUNET_free (database); |
511 | } | 510 | } |
512 | if(NULL == db) | 511 | if (NULL == db) |
513 | { | 512 | { |
514 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Could not load database backend `%s'\n"), db_lib_name); | 513 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
515 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | 514 | _("Could not load database backend `%s'\n"), db_lib_name); |
516 | return; | 515 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); |
516 | return; | ||
517 | } | 517 | } |
518 | nc = GNUNET_SERVER_notification_context_create (server, 16); | 518 | nc = GNUNET_SERVER_notification_context_create (server, 16); |
519 | watchers = GNUNET_CONTAINER_multihashmap_create(10, GNUNET_NO); | 519 | watchers = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); |
520 | GNUNET_SCHEDULER_add_now(&cleanup_expired_records, NULL); | 520 | GNUNET_SCHEDULER_add_now (&cleanup_expired_records, NULL); |
521 | GNUNET_SERVER_add_handlers (server, handlers); | 521 | GNUNET_SERVER_add_handlers (server, handlers); |
522 | GNUNET_SERVER_connect_notify (server, &handle_client_connect, NULL); | 522 | GNUNET_SERVER_connect_notify (server, &handle_client_connect, NULL); |
523 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); | 523 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); |
524 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 524 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, |
525 | &shutdown_task, | 525 | NULL); |
526 | NULL); | ||
527 | } | 526 | } |
528 | 527 | ||
529 | 528 | ||
@@ -538,11 +537,9 @@ int | |||
538 | main (int argc, char *const *argv) | 537 | main (int argc, char *const *argv) |
539 | { | 538 | { |
540 | return (GNUNET_OK == | 539 | return (GNUNET_OK == |
541 | GNUNET_SERVICE_run (argc, | 540 | GNUNET_SERVICE_run (argc, argv, "peerstore", |
542 | argv, | 541 | GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, &run, |
543 | "peerstore", | 542 | NULL)) ? 0 : 1; |
544 | GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, | ||
545 | &run, NULL)) ? 0 : 1; | ||
546 | } | 543 | } |
547 | 544 | ||
548 | /* end of gnunet-service-peerstore.c */ | 545 | /* end of gnunet-service-peerstore.c */ |