diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-06-27 20:29:34 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-06-27 20:29:34 +0000 |
commit | de17ce8c248ed8d2334736e7c0013d55475625f1 (patch) | |
tree | 7f4dea9b2cb750ec833564772d8a1df63e921d48 /src/namestore/gnunet-service-namestore.c | |
parent | 5e0c21e1204115258a743bc3c03b8308af6a7c48 (diff) | |
download | gnunet-de17ce8c248ed8d2334736e7c0013d55475625f1.tar.gz gnunet-de17ce8c248ed8d2334736e7c0013d55475625f1.zip |
-more namestore code cleanup
Diffstat (limited to 'src/namestore/gnunet-service-namestore.c')
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 689 |
1 files changed, 336 insertions, 353 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 740ab6e87..25af987b5 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -76,7 +76,6 @@ struct GNUNET_NAMESTORE_ZoneIteration | |||
76 | * | 76 | * |
77 | * Initialy set to 0 in handle_iteration_start | 77 | * Initialy set to 0 in handle_iteration_start |
78 | * Incremented with by every call to handle_iteration_next | 78 | * Incremented with by every call to handle_iteration_next |
79 | * | ||
80 | */ | 79 | */ |
81 | uint32_t offset; | 80 | uint32_t offset; |
82 | 81 | ||
@@ -156,12 +155,12 @@ struct GNUNET_NAMESTORE_CryptoContainer | |||
156 | /** | 155 | /** |
157 | * Configuration handle. | 156 | * Configuration handle. |
158 | */ | 157 | */ |
159 | const struct GNUNET_CONFIGURATION_Handle *GSN_cfg; | 158 | static const struct GNUNET_CONFIGURATION_Handle *GSN_cfg; |
160 | 159 | ||
161 | /** | 160 | /** |
162 | * Database handle | 161 | * Database handle |
163 | */ | 162 | */ |
164 | struct GNUNET_NAMESTORE_PluginFunctions *GSN_database; | 163 | static struct GNUNET_NAMESTORE_PluginFunctions *GSN_database; |
165 | 164 | ||
166 | /** | 165 | /** |
167 | * Zonefile directory | 166 | * Zonefile directory |
@@ -194,7 +193,7 @@ static struct GNUNET_NAMESTORE_Client *client_tail; | |||
194 | * Keys are the GNUNET_CRYPTO_HashCode of the GNUNET_CRYPTO_ShortHashCode | 193 | * Keys are the GNUNET_CRYPTO_HashCode of the GNUNET_CRYPTO_ShortHashCode |
195 | * The values are 'struct GNUNET_NAMESTORE_CryptoContainer *' | 194 | * The values are 'struct GNUNET_NAMESTORE_CryptoContainer *' |
196 | */ | 195 | */ |
197 | struct GNUNET_CONTAINER_MultiHashMap *zonekeys; | 196 | static struct GNUNET_CONTAINER_MultiHashMap *zonekeys; |
198 | 197 | ||
199 | 198 | ||
200 | /** | 199 | /** |
@@ -202,81 +201,67 @@ struct GNUNET_CONTAINER_MultiHashMap *zonekeys; | |||
202 | * | 201 | * |
203 | * @param filename where to store the zone | 202 | * @param filename where to store the zone |
204 | * @param c the crypto container containing private key of the zone | 203 | * @param c the crypto container containing private key of the zone |
205 | * @return GNUNET_OK on success, GNUNET_SYSERR on fail | 204 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure |
206 | */ | 205 | */ |
207 | static int | 206 | static int |
208 | write_key_to_file (const char *filename, struct GNUNET_NAMESTORE_CryptoContainer *c) | 207 | write_key_to_file (const char *filename, |
208 | struct GNUNET_NAMESTORE_CryptoContainer *c) | ||
209 | { | 209 | { |
210 | struct GNUNET_CRYPTO_RsaPrivateKey *ret = c->privkey; | 210 | struct GNUNET_CRYPTO_RsaPrivateKey *ret = c->privkey; |
211 | struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *enc; | 211 | struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *enc; |
212 | struct GNUNET_DISK_FileHandle *fd; | 212 | struct GNUNET_DISK_FileHandle *fd; |
213 | struct GNUNET_CRYPTO_ShortHashCode zone; | ||
214 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; | ||
215 | struct GNUNET_CRYPTO_RsaPrivateKey *privkey; | ||
213 | 216 | ||
214 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) | 217 | fd = GNUNET_DISK_file_open (filename, |
218 | GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_FAILIFEXISTS, | ||
219 | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); | ||
220 | if ( (NULL == fd) && (EEXIST == errno) ) | ||
215 | { | 221 | { |
216 | struct GNUNET_CRYPTO_ShortHashCode zone; | 222 | privkey = GNUNET_CRYPTO_rsa_key_create_from_file (filename); |
217 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; | 223 | if (NULL == privkey) |
218 | struct GNUNET_CRYPTO_RsaPrivateKey *privkey; | ||
219 | |||
220 | privkey = GNUNET_CRYPTO_rsa_key_create_from_file(filename); | ||
221 | if (privkey == NULL) | ||
222 | { | 224 | { |
223 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 225 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
224 | _("File zone `%s' but corrupt content already exists, failed to write! \n"), | 226 | _("Failed to write zone key to file `%s': %s\n"), |
225 | GNUNET_short_h2s (&zone)); | 227 | filename, |
228 | _("file exists but reading key failed")); | ||
226 | return GNUNET_SYSERR; | 229 | return GNUNET_SYSERR; |
227 | } | 230 | } |
228 | |||
229 | GNUNET_CRYPTO_rsa_key_get_public (privkey, &pubkey); | 231 | GNUNET_CRYPTO_rsa_key_get_public (privkey, &pubkey); |
230 | GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone); | 232 | GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone); |
231 | GNUNET_CRYPTO_rsa_key_free (privkey); | 233 | GNUNET_CRYPTO_rsa_key_free (privkey); |
232 | |||
233 | if (0 == memcmp (&zone, &c->zone, sizeof(zone))) | 234 | if (0 == memcmp (&zone, &c->zone, sizeof(zone))) |
234 | { | 235 | { |
235 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 236 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
236 | _("File zone `%s' containing this key already exists\n"), GNUNET_short_h2s (&zone)); | 237 | "File zone `%s' containing this key already exists\n", |
237 | return GNUNET_OK; | ||
238 | } | ||
239 | else | ||
240 | { | ||
241 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
242 | _("File zone `%s' but different zone key already exists, failed to write! \n"), | ||
243 | GNUNET_short_h2s (&zone)); | 238 | GNUNET_short_h2s (&zone)); |
244 | return GNUNET_OK; | 239 | return GNUNET_OK; |
245 | } | 240 | } |
241 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
242 | _("Failed to write zone key to file `%s': %s\n"), | ||
243 | filename, | ||
244 | _("file exists with different key")); | ||
245 | return GNUNET_OK; | ||
246 | } | 246 | } |
247 | fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_FAILIFEXISTS, GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); | ||
248 | if (NULL == fd) | 247 | if (NULL == fd) |
249 | { | 248 | { |
250 | if (errno == EEXIST) | ||
251 | { | ||
252 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) | ||
253 | { | ||
254 | /* must exist but not be accessible, fail for good! */ | ||
255 | if (0 != ACCESS (filename, R_OK)) | ||
256 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", filename); | ||
257 | else | ||
258 | GNUNET_break (0); /* what is going on!? */ | ||
259 | return GNUNET_SYSERR; | ||
260 | } | ||
261 | } | ||
262 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename); | 249 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename); |
263 | return GNUNET_SYSERR; | 250 | return GNUNET_SYSERR; |
264 | } | 251 | } |
265 | |||
266 | if (GNUNET_YES != GNUNET_DISK_file_lock (fd, 0, sizeof (struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded), GNUNET_YES)) | 252 | if (GNUNET_YES != GNUNET_DISK_file_lock (fd, 0, sizeof (struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded), GNUNET_YES)) |
267 | { | 253 | { |
268 | GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); | 254 | GNUNET_break (GNUNET_YES == GNUNET_DISK_file_close (fd)); |
269 | return GNUNET_SYSERR; | 255 | return GNUNET_SYSERR; |
270 | } | 256 | } |
271 | enc = GNUNET_CRYPTO_rsa_encode_key (ret); | 257 | enc = GNUNET_CRYPTO_rsa_encode_key (ret); |
272 | GNUNET_assert (enc != NULL); | 258 | GNUNET_assert (NULL != enc); |
273 | GNUNET_assert (ntohs (enc->len) == GNUNET_DISK_file_write (fd, enc, ntohs (enc->len))); | 259 | GNUNET_assert (ntohs (enc->len) == GNUNET_DISK_file_write (fd, enc, ntohs (enc->len))); |
274 | GNUNET_free (enc); | 260 | GNUNET_free (enc); |
275 | GNUNET_DISK_file_sync (fd); | 261 | GNUNET_DISK_file_sync (fd); |
276 | if (GNUNET_YES != GNUNET_DISK_file_unlock (fd, 0, sizeof (struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded))) | 262 | if (GNUNET_YES != GNUNET_DISK_file_unlock (fd, 0, sizeof (struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded))) |
277 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); | 263 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); |
278 | GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); | 264 | GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); |
279 | |||
280 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 265 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
281 | "Stored zonekey for zone `%s' in file `%s'\n", | 266 | "Stored zonekey for zone `%s' in file `%s'\n", |
282 | GNUNET_short_h2s(&c->zone), c->filename); | 267 | GNUNET_short_h2s(&c->zone), c->filename); |
@@ -285,8 +270,8 @@ write_key_to_file (const char *filename, struct GNUNET_NAMESTORE_CryptoContainer | |||
285 | 270 | ||
286 | 271 | ||
287 | /** | 272 | /** |
288 | * Write all zone keys to disk. | 273 | * Write allthe given zone key to disk and then removes the entry from the |
289 | * Iterates over all entries of the hashmap 'zonekeys' | 274 | * 'zonekeys' hash map. |
290 | * | 275 | * |
291 | * @param cls unused | 276 | * @param cls unused |
292 | * @param key zone key | 277 | * @param key zone key |
@@ -300,28 +285,26 @@ zone_to_disk_it (void *cls, | |||
300 | void *value) | 285 | void *value) |
301 | { | 286 | { |
302 | struct GNUNET_NAMESTORE_CryptoContainer *c = value; | 287 | struct GNUNET_NAMESTORE_CryptoContainer *c = value; |
303 | if (c->filename != NULL) | ||
304 | write_key_to_file(c->filename, c); | ||
305 | else | ||
306 | { | ||
307 | GNUNET_asprintf(&c->filename, "%s/%s.zkey", zonefile_directory, GNUNET_short_h2s (&c->zone)); | ||
308 | write_key_to_file(c->filename, c); | ||
309 | } | ||
310 | 288 | ||
289 | if (NULL == c->filename) | ||
290 | GNUNET_asprintf(&c->filename, | ||
291 | "%s/%s.zkey", | ||
292 | zonefile_directory, | ||
293 | GNUNET_short_h2s (&c->zone)); | ||
294 | (void) write_key_to_file(c->filename, c); | ||
311 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (zonekeys, key, value)); | 295 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (zonekeys, key, value)); |
312 | GNUNET_CRYPTO_rsa_key_free (c->privkey); | 296 | GNUNET_CRYPTO_rsa_key_free (c->privkey); |
313 | GNUNET_free (c->pubkey); | 297 | GNUNET_free (c->pubkey); |
314 | GNUNET_free (c->filename); | 298 | GNUNET_free (c->filename); |
315 | GNUNET_free (c); | 299 | GNUNET_free (c); |
316 | |||
317 | return GNUNET_OK; | 300 | return GNUNET_OK; |
318 | } | 301 | } |
319 | 302 | ||
320 | 303 | ||
321 | /** | 304 | /** |
322 | * Returns the expiration time of the given block of records | 305 | * Returns the expiration time of the given block of records. The block |
323 | * The block expiration time is the expiration time of the block with smallest | 306 | * expiration time is the expiration time of the block with smallest |
324 | * expiration time | 307 | * expiration time. |
325 | * | 308 | * |
326 | * @param rd_count number of records given in 'rd' | 309 | * @param rd_count number of records given in 'rd' |
327 | * @param rd array of records | 310 | * @param rd array of records |
@@ -331,12 +314,13 @@ static struct GNUNET_TIME_Absolute | |||
331 | get_block_expiration_time (unsigned int rd_count, const struct GNUNET_NAMESTORE_RecordData *rd) | 314 | get_block_expiration_time (unsigned int rd_count, const struct GNUNET_NAMESTORE_RecordData *rd) |
332 | { | 315 | { |
333 | unsigned int c; | 316 | unsigned int c; |
334 | struct GNUNET_TIME_Absolute expire = GNUNET_TIME_UNIT_FOREVER_ABS; | 317 | struct GNUNET_TIME_Absolute expire; |
335 | struct GNUNET_TIME_Absolute at; | 318 | struct GNUNET_TIME_Absolute at; |
336 | struct GNUNET_TIME_Relative rt; | 319 | struct GNUNET_TIME_Relative rt; |
337 | 320 | ||
338 | if (NULL == rd) | 321 | if (NULL == rd) |
339 | return GNUNET_TIME_UNIT_ZERO_ABS; | 322 | return GNUNET_TIME_UNIT_ZERO_ABS; |
323 | expire = GNUNET_TIME_UNIT_FOREVER_ABS; | ||
340 | for (c = 0; c < rd_count; c++) | 324 | for (c = 0; c < rd_count; c++) |
341 | { | 325 | { |
342 | if (0 != (rd[c].flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION)) | 326 | if (0 != (rd[c].flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION)) |
@@ -353,6 +337,7 @@ get_block_expiration_time (unsigned int rd_count, const struct GNUNET_NAMESTORE_ | |||
353 | return expire; | 337 | return expire; |
354 | } | 338 | } |
355 | 339 | ||
340 | |||
356 | /** | 341 | /** |
357 | * Task run during shutdown. | 342 | * Task run during shutdown. |
358 | * | 343 | * |
@@ -362,52 +347,54 @@ get_block_expiration_time (unsigned int rd_count, const struct GNUNET_NAMESTORE_ | |||
362 | static void | 347 | static void |
363 | cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 348 | cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
364 | { | 349 | { |
365 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping namestore service\n"); | ||
366 | struct GNUNET_NAMESTORE_ZoneIteration *no; | 350 | struct GNUNET_NAMESTORE_ZoneIteration *no; |
367 | struct GNUNET_NAMESTORE_ZoneIteration *tmp; | ||
368 | struct GNUNET_NAMESTORE_Client *nc; | 351 | struct GNUNET_NAMESTORE_Client *nc; |
369 | struct GNUNET_NAMESTORE_Client *next; | ||
370 | 352 | ||
353 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping namestore service\n"); | ||
371 | if (NULL != snc) | 354 | if (NULL != snc) |
372 | { | 355 | { |
373 | GNUNET_SERVER_notification_context_destroy (snc); | 356 | GNUNET_SERVER_notification_context_destroy (snc); |
374 | snc = NULL; | 357 | snc = NULL; |
375 | } | 358 | } |
376 | GNUNET_CONTAINER_multihashmap_iterate(zonekeys, &zone_to_disk_it, NULL); | 359 | GNUNET_CONTAINER_multihashmap_iterate (zonekeys, &zone_to_disk_it, NULL); |
377 | GNUNET_CONTAINER_multihashmap_destroy(zonekeys); | 360 | GNUNET_CONTAINER_multihashmap_destroy (zonekeys); |
378 | 361 | zonekeys = NULL; | |
379 | for (nc = client_head; nc != NULL; nc = next) | 362 | while (NULL != (nc = client_head)) |
380 | { | 363 | { |
381 | next = nc->next; | 364 | while (NULL != (no = nc->op_head)) |
382 | for (no = nc->op_head; no != NULL; no = tmp) | ||
383 | { | 365 | { |
384 | GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, no); | 366 | GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, no); |
385 | tmp = no->next; | ||
386 | GNUNET_free (no); | 367 | GNUNET_free (no); |
387 | } | 368 | } |
388 | GNUNET_SERVER_client_drop(nc->client); | 369 | GNUNET_SERVER_client_drop(nc->client); |
389 | GNUNET_CONTAINER_DLL_remove (client_head, client_tail, nc); | 370 | GNUNET_CONTAINER_DLL_remove (client_head, client_tail, nc); |
390 | GNUNET_free (nc); | 371 | GNUNET_free (nc); |
391 | } | 372 | } |
392 | |||
393 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, GSN_database)); | 373 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, GSN_database)); |
394 | GNUNET_free (db_lib_name); | 374 | GNUNET_free (db_lib_name); |
395 | GNUNET_free_non_null(zonefile_directory); | 375 | db_lib_name = NULL; |
376 | GNUNET_free_non_null (zonefile_directory); | ||
377 | zonefile_directory = NULL; | ||
396 | } | 378 | } |
397 | 379 | ||
380 | |||
381 | /** | ||
382 | * Lookup our internal data structure for a given client. | ||
383 | * | ||
384 | * @param client server client handle to use for the lookup | ||
385 | * @return our internal structure for the client, NULL if | ||
386 | * we do not have any yet | ||
387 | */ | ||
398 | static struct GNUNET_NAMESTORE_Client * | 388 | static struct GNUNET_NAMESTORE_Client * |
399 | client_lookup (struct GNUNET_SERVER_Client *client) | 389 | client_lookup (struct GNUNET_SERVER_Client *client) |
400 | { | 390 | { |
401 | struct GNUNET_NAMESTORE_Client *nc; | 391 | struct GNUNET_NAMESTORE_Client *nc; |
402 | 392 | ||
403 | GNUNET_assert (NULL != client); | 393 | GNUNET_assert (NULL != client); |
404 | 394 | for (nc = client_head; NULL != nc; nc = nc->next) | |
405 | for (nc = client_head; nc != NULL; nc = nc->next) | ||
406 | { | ||
407 | if (client == nc->client) | 395 | if (client == nc->client) |
408 | break; | 396 | return nc; |
409 | } | 397 | return NULL; |
410 | return nc; | ||
411 | } | 398 | } |
412 | 399 | ||
413 | 400 | ||
@@ -419,32 +406,28 @@ client_lookup (struct GNUNET_SERVER_Client *client) | |||
419 | * @param client identification of the client | 406 | * @param client identification of the client |
420 | */ | 407 | */ |
421 | static void | 408 | static void |
422 | client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client) | 409 | client_disconnect_notification (void *cls, |
410 | struct GNUNET_SERVER_Client *client) | ||
423 | { | 411 | { |
424 | struct GNUNET_NAMESTORE_ZoneIteration *no; | 412 | struct GNUNET_NAMESTORE_ZoneIteration *no; |
425 | struct GNUNET_NAMESTORE_Client *nc; | 413 | struct GNUNET_NAMESTORE_Client *nc; |
414 | |||
426 | if (NULL == client) | 415 | if (NULL == client) |
427 | return; | 416 | return; |
428 | 417 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | |
429 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected \n", client); | 418 | "Client %p disconnected\n", |
430 | 419 | client); | |
431 | nc = client_lookup (client); | 420 | nc = client_lookup (client); |
432 | 421 | if (NULL == nc) | |
433 | if ((NULL == client) || (NULL == nc)) | ||
434 | return; | 422 | return; |
435 | 423 | while (NULL != (no = nc->op_head)) | |
436 | no = nc->op_head; | ||
437 | while (NULL != no) | ||
438 | { | 424 | { |
439 | GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, no); | 425 | GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, no); |
440 | GNUNET_free (no); | 426 | GNUNET_free (no); |
441 | no = nc->op_head; | ||
442 | } | 427 | } |
443 | 428 | GNUNET_SERVER_client_drop (nc->client); | |
444 | GNUNET_SERVER_client_drop(nc->client); | ||
445 | GNUNET_CONTAINER_DLL_remove (client_head, client_tail, nc); | 429 | GNUNET_CONTAINER_DLL_remove (client_head, client_tail, nc); |
446 | GNUNET_free (nc); | 430 | GNUNET_free (nc); |
447 | nc = NULL; | ||
448 | } | 431 | } |
449 | 432 | ||
450 | 433 | ||
@@ -460,20 +443,26 @@ handle_start (void *cls, | |||
460 | struct GNUNET_SERVER_Client *client, | 443 | struct GNUNET_SERVER_Client *client, |
461 | const struct GNUNET_MessageHeader *message) | 444 | const struct GNUNET_MessageHeader *message) |
462 | { | 445 | { |
463 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client); | 446 | struct GNUNET_NAMESTORE_Client *nc; |
464 | 447 | ||
465 | struct GNUNET_NAMESTORE_Client *nc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_Client)); | 448 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
449 | "Client %p connected\n", client); | ||
450 | if (NULL != client_lookup (client)) | ||
451 | { | ||
452 | GNUNET_break (0); | ||
453 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
454 | return; | ||
455 | } | ||
456 | nc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_Client)); | ||
466 | nc->client = client; | 457 | nc->client = client; |
467 | GNUNET_SERVER_notification_context_add (snc, client); | 458 | GNUNET_SERVER_notification_context_add (snc, client); |
468 | GNUNET_CONTAINER_DLL_insert(client_head, client_tail, nc); | 459 | GNUNET_CONTAINER_DLL_insert (client_head, client_tail, nc); |
469 | GNUNET_SERVER_client_keep (client); | 460 | GNUNET_SERVER_client_keep (client); |
470 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 461 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
471 | } | 462 | } |
472 | 463 | ||
473 | 464 | ||
474 | /** | 465 | /** |
475 | * LookupNameContext | ||
476 | * | ||
477 | * Context for name lookups passed from 'handle_lookup_name' to | 466 | * Context for name lookups passed from 'handle_lookup_name' to |
478 | * 'handle_lookup_name_it' as closure | 467 | * 'handle_lookup_name_it' as closure |
479 | */ | 468 | */ |
@@ -485,24 +474,24 @@ struct LookupNameContext | |||
485 | struct GNUNET_NAMESTORE_Client *nc; | 474 | struct GNUNET_NAMESTORE_Client *nc; |
486 | 475 | ||
487 | /** | 476 | /** |
488 | * Operation id for the name lookup | 477 | * Requested zone |
489 | */ | 478 | */ |
490 | uint32_t request_id; | 479 | const struct GNUNET_CRYPTO_ShortHashCode *zone; |
491 | 480 | ||
492 | /** | 481 | /** |
493 | * Requested specific record type | 482 | * Requested name |
494 | */ | 483 | */ |
495 | uint32_t record_type; | 484 | const char *name; |
496 | 485 | ||
497 | /** | 486 | /** |
498 | * Requested zone | 487 | * Operation id for the name lookup |
499 | */ | 488 | */ |
500 | struct GNUNET_CRYPTO_ShortHashCode *zone; | 489 | uint32_t request_id; |
501 | 490 | ||
502 | /** | 491 | /** |
503 | * Requested name | 492 | * Requested specific record type |
504 | */ | 493 | */ |
505 | char *name; | 494 | uint32_t record_type; |
506 | }; | 495 | }; |
507 | 496 | ||
508 | 497 | ||
@@ -519,109 +508,109 @@ struct LookupNameContext | |||
519 | */ | 508 | */ |
520 | static void | 509 | static void |
521 | handle_lookup_name_it (void *cls, | 510 | handle_lookup_name_it (void *cls, |
522 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, | 511 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, |
523 | struct GNUNET_TIME_Absolute expire, | 512 | struct GNUNET_TIME_Absolute expire, |
524 | const char *name, | 513 | const char *name, |
525 | unsigned int rd_count, | 514 | unsigned int rd_count, |
526 | const struct GNUNET_NAMESTORE_RecordData *rd, | 515 | const struct GNUNET_NAMESTORE_RecordData *rd, |
527 | const struct GNUNET_CRYPTO_RsaSignature *signature) | 516 | const struct GNUNET_CRYPTO_RsaSignature *signature) |
528 | { | 517 | { |
529 | /* send response */ | ||
530 | struct LookupNameContext *lnc = cls; | 518 | struct LookupNameContext *lnc = cls; |
531 | struct LookupNameResponseMessage *lnr_msg; | 519 | struct LookupNameResponseMessage *lnr_msg; |
532 | struct GNUNET_NAMESTORE_RecordData *rd_selected = NULL; | 520 | struct GNUNET_NAMESTORE_RecordData *rd_selected; |
533 | struct GNUNET_NAMESTORE_CryptoContainer *cc; | 521 | struct GNUNET_NAMESTORE_CryptoContainer *cc; |
534 | struct GNUNET_CRYPTO_RsaSignature *signature_new = NULL; | 522 | struct GNUNET_CRYPTO_RsaSignature *signature_new; |
535 | struct GNUNET_TIME_Absolute e; | 523 | struct GNUNET_TIME_Absolute e; |
536 | struct GNUNET_CRYPTO_ShortHashCode zone_key_hash; | 524 | struct GNUNET_CRYPTO_ShortHashCode zone_key_hash; |
537 | struct GNUNET_HashCode long_hash; | 525 | struct GNUNET_HashCode long_hash; |
538 | char *rd_tmp; | 526 | char *rd_tmp; |
539 | char *name_tmp; | 527 | char *name_tmp; |
540 | size_t rd_ser_len; | 528 | size_t rd_ser_len; |
541 | size_t r_size = 0; | 529 | size_t r_size; |
542 | size_t name_len = 0; | 530 | size_t name_len; |
543 | 531 | int copied_elements; | |
544 | int copied_elements = 0; | 532 | int contains_signature; |
545 | int contains_signature = GNUNET_NO; | 533 | int authoritative; |
546 | int authoritative = GNUNET_NO; | ||
547 | int c; | 534 | int c; |
548 | 535 | ||
549 | if (NULL != name) | 536 | name_len = (NULL == name) ? 0 : strlen(name) + 1; |
550 | name_len = strlen(name) + 1; | 537 | copied_elements = 0; |
551 | 538 | rd_selected = NULL; | |
552 | /* count records to copy */ | 539 | /* count records to copy */ |
553 | if (rd_count != 0) | 540 | if (0 != lnc->record_type) |
554 | { | 541 | { |
555 | if (lnc->record_type != 0) | 542 | /* special record type needed */ |
543 | for (c = 0; c < rd_count; c++) | ||
544 | if (rd[c].record_type == lnc->record_type) | ||
545 | copied_elements++; /* found matching record */ | ||
546 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
547 | "Found %u records with type %u for name `%s' in zone `%s'\n", | ||
548 | copied_elements, | ||
549 | lnc->record_type, | ||
550 | lnc->name, | ||
551 | GNUNET_short_h2s(lnc->zone)); | ||
552 | if (copied_elements > 0) | ||
556 | { | 553 | { |
557 | /* special record type needed */ | ||
558 | for (c = 0; c < rd_count; c ++) | ||
559 | if (rd[c].record_type == lnc->record_type) | ||
560 | copied_elements++; /* found matching record */ | ||
561 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u records with type %u for name `%s' in zone `%s'\n", | ||
562 | copied_elements, lnc->record_type, lnc->name, GNUNET_short_h2s(lnc->zone)); | ||
563 | rd_selected = GNUNET_malloc (copied_elements * sizeof (struct GNUNET_NAMESTORE_RecordData)); | 554 | rd_selected = GNUNET_malloc (copied_elements * sizeof (struct GNUNET_NAMESTORE_RecordData)); |
564 | copied_elements = 0; | 555 | copied_elements = 0; |
565 | for (c = 0; c < rd_count; c ++) | 556 | for (c = 0; c < rd_count; c++) |
566 | { | 557 | { |
567 | if (rd[c].record_type == lnc->record_type) | 558 | if (rd[c].record_type == lnc->record_type) |
568 | { | 559 | { |
569 | /* found matching record */ | 560 | /* found matching record */ |
570 | memcpy (&rd_selected[copied_elements], &rd[c], sizeof (struct GNUNET_NAMESTORE_RecordData)); | 561 | rd_selected[copied_elements] = rd[c]; /* shallow copy! */ |
571 | copied_elements++; | 562 | copied_elements++; |
572 | } | 563 | } |
573 | } | 564 | } |
574 | } | 565 | } |
575 | else | ||
576 | { | ||
577 | copied_elements = rd_count; | ||
578 | rd_selected = (struct GNUNET_NAMESTORE_RecordData *) rd; | ||
579 | } | ||
580 | } | 566 | } |
581 | else | 567 | else |
582 | { | 568 | { |
583 | /* No results */ | 569 | copied_elements = rd_count; |
584 | copied_elements = 0; | 570 | rd_selected = (struct GNUNET_NAMESTORE_RecordData *) rd; |
585 | rd_selected = NULL; | ||
586 | expire = GNUNET_TIME_UNIT_ZERO_ABS; | ||
587 | } | 571 | } |
588 | 572 | // FIXME: need to adjust 'rd' from relative to absolute times! | |
589 | rd_ser_len = GNUNET_NAMESTORE_records_get_size(copied_elements, rd_selected); | 573 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
590 | char rd_ser[rd_ser_len]; | 574 | "Found %u records for name `%s' in zone `%s'\n", |
591 | GNUNET_NAMESTORE_records_serialize(copied_elements, rd_selected, rd_ser_len, rd_ser); | 575 | copied_elements, |
592 | 576 | lnc->name, | |
593 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u records for name `%s' in zone `%s'\n", | 577 | GNUNET_short_h2s (lnc->zone)); |
594 | copied_elements, lnc->name, GNUNET_short_h2s(lnc->zone)); | ||
595 | 578 | ||
596 | if ((copied_elements == rd_count) && (NULL != signature)) | 579 | if ((copied_elements == rd_count) && (NULL != signature)) |
597 | contains_signature = GNUNET_YES; /* returning all records, so include signature */ | 580 | contains_signature = GNUNET_YES; /* returning all records, so include signature */ |
598 | else | 581 | else |
599 | contains_signature = GNUNET_NO; /* returning not all records, so do not include signature */ | 582 | contains_signature = GNUNET_NO; /* returning not all records, so do not include signature */ |
600 | 583 | ||
601 | 584 | authoritative = GNUNET_NO; | |
585 | signature_new = NULL; | ||
602 | if ((NULL != zone_key) && (copied_elements == rd_count)) | 586 | if ((NULL != zone_key) && (copied_elements == rd_count)) |
603 | { | 587 | { |
604 | GNUNET_CRYPTO_short_hash(zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone_key_hash); | 588 | GNUNET_CRYPTO_short_hash (zone_key, |
589 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | ||
590 | &zone_key_hash); | ||
605 | GNUNET_CRYPTO_short_hash_double (&zone_key_hash, &long_hash); | 591 | GNUNET_CRYPTO_short_hash_double (&zone_key_hash, &long_hash); |
606 | if (GNUNET_CONTAINER_multihashmap_contains(zonekeys, &long_hash)) | 592 | if (NULL != (cc = GNUNET_CONTAINER_multihashmap_get(zonekeys, &long_hash))) |
607 | { | 593 | { |
608 | cc = GNUNET_CONTAINER_multihashmap_get(zonekeys, &long_hash); | 594 | e = get_block_expiration_time (rd_count, rd); |
609 | e = get_block_expiration_time(rd_count, rd); | 595 | signature_new = GNUNET_NAMESTORE_create_signature (cc->privkey, e, name, rd, rd_count); |
610 | signature_new = GNUNET_NAMESTORE_create_signature(cc->privkey, e, name, rd, rd_count); | 596 | GNUNET_assert (NULL != signature_new); |
611 | GNUNET_assert (signature_new != NULL); | 597 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
612 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating signature for name `%s' with %u records in zone `%s'\n",name, copied_elements, GNUNET_short_h2s(&zone_key_hash)); | 598 | "Creating signature for name `%s' with %u records in zone `%s'\n", |
599 | name, | ||
600 | copied_elements, | ||
601 | GNUNET_short_h2s(&zone_key_hash)); | ||
613 | authoritative = GNUNET_YES; | 602 | authoritative = GNUNET_YES; |
614 | } | 603 | } |
615 | else | ||
616 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I am not authoritative for name `%s' in zone `%s'\n",name, GNUNET_short_h2s(&zone_key_hash)); | ||
617 | } | 604 | } |
618 | 605 | ||
606 | rd_ser_len = GNUNET_NAMESTORE_records_get_size (copied_elements, rd_selected); | ||
619 | r_size = sizeof (struct LookupNameResponseMessage) + | 607 | r_size = sizeof (struct LookupNameResponseMessage) + |
620 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + | 608 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + |
621 | name_len + | 609 | name_len + |
622 | rd_ser_len; | 610 | rd_ser_len; |
623 | 611 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | |
624 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "NAMESTORE_LOOKUP_NAME_RESPONSE"); | 612 | "Sending `%s' message\n", |
613 | "NAMESTORE_LOOKUP_NAME_RESPONSE"); | ||
625 | lnr_msg = GNUNET_malloc (r_size); | 614 | lnr_msg = GNUNET_malloc (r_size); |
626 | lnr_msg->gns_header.header.type = ntohs (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE); | 615 | lnr_msg->gns_header.header.type = ntohs (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE); |
627 | lnr_msg->gns_header.header.size = ntohs (r_size); | 616 | lnr_msg->gns_header.header.size = ntohs (r_size); |
@@ -629,20 +618,23 @@ handle_lookup_name_it (void *cls, | |||
629 | lnr_msg->rd_count = htons (copied_elements); | 618 | lnr_msg->rd_count = htons (copied_elements); |
630 | lnr_msg->rd_len = htons (rd_ser_len); | 619 | lnr_msg->rd_len = htons (rd_ser_len); |
631 | lnr_msg->name_len = htons (name_len); | 620 | lnr_msg->name_len = htons (name_len); |
632 | lnr_msg->expire = GNUNET_TIME_absolute_hton(get_block_expiration_time(copied_elements, rd_selected)); | 621 | lnr_msg->expire = GNUNET_TIME_absolute_hton (get_block_expiration_time (copied_elements, |
622 | rd_selected)); | ||
623 | name_tmp = (char *) &lnr_msg[1]; | ||
624 | memcpy (name_tmp, name, name_len); | ||
625 | rd_tmp = &name_tmp[name_len]; | ||
626 | GNUNET_NAMESTORE_records_serialize (copied_elements, rd_selected, rd_ser_len, rd_tmp); | ||
633 | 627 | ||
634 | if (rd_selected != rd) | 628 | if (rd_selected != rd) |
635 | GNUNET_free (rd_selected); | 629 | GNUNET_free_non_null (rd_selected); |
636 | |||
637 | if (zone_key != NULL) | ||
638 | lnr_msg->public_key = (*zone_key); | ||
639 | else | ||
640 | memset(&lnr_msg->public_key, '\0', sizeof (lnr_msg->public_key)); | ||
641 | 630 | ||
631 | if (NULL != zone_key) | ||
632 | lnr_msg->public_key = *zone_key; | ||
642 | if (GNUNET_YES == authoritative) | 633 | if (GNUNET_YES == authoritative) |
643 | { /* use new created signature */ | 634 | { |
635 | /* use new created signature */ | ||
644 | lnr_msg->contains_sig = htons (GNUNET_YES); | 636 | lnr_msg->contains_sig = htons (GNUNET_YES); |
645 | GNUNET_assert (signature_new != NULL); | 637 | GNUNET_assert (NULL != signature_new); |
646 | lnr_msg->signature = *signature_new; | 638 | lnr_msg->signature = *signature_new; |
647 | GNUNET_free (signature_new); | 639 | GNUNET_free (signature_new); |
648 | } | 640 | } |
@@ -650,25 +642,16 @@ handle_lookup_name_it (void *cls, | |||
650 | { | 642 | { |
651 | /* use existing signature */ | 643 | /* use existing signature */ |
652 | lnr_msg->contains_sig = htons (GNUNET_YES); | 644 | lnr_msg->contains_sig = htons (GNUNET_YES); |
653 | GNUNET_assert (signature != NULL); | 645 | GNUNET_assert (NULL != signature); |
654 | lnr_msg->signature = *signature; | 646 | lnr_msg->signature = *signature; |
655 | } | 647 | } |
656 | else | 648 | GNUNET_SERVER_notification_context_unicast (snc, lnc->nc->client, |
657 | { | 649 | &lnr_msg->gns_header.header, |
658 | /* use no signature */ | 650 | GNUNET_NO); |
659 | memset (&lnr_msg->signature, '\0', sizeof (lnr_msg->signature)); | ||
660 | } | ||
661 | |||
662 | name_tmp = (char *) &lnr_msg[1]; | ||
663 | rd_tmp = &name_tmp[name_len]; | ||
664 | |||
665 | memcpy (name_tmp, name, name_len); | ||
666 | memcpy (rd_tmp, rd_ser, rd_ser_len); | ||
667 | |||
668 | GNUNET_SERVER_notification_context_unicast (snc, lnc->nc->client, (const struct GNUNET_MessageHeader *) lnr_msg, GNUNET_NO); | ||
669 | GNUNET_free (lnr_msg); | 651 | GNUNET_free (lnr_msg); |
670 | } | 652 | } |
671 | 653 | ||
654 | |||
672 | /** | 655 | /** |
673 | * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME' message | 656 | * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME' message |
674 | * | 657 | * |
@@ -681,53 +664,56 @@ handle_lookup_name (void *cls, | |||
681 | struct GNUNET_SERVER_Client *client, | 664 | struct GNUNET_SERVER_Client *client, |
682 | const struct GNUNET_MessageHeader *message) | 665 | const struct GNUNET_MessageHeader *message) |
683 | { | 666 | { |
684 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_LOOKUP_NAME"); | 667 | const struct LookupNameMessage *ln_msg; |
685 | struct LookupNameContext lnc; | 668 | struct LookupNameContext lnc; |
686 | struct GNUNET_NAMESTORE_Client *nc; | 669 | struct GNUNET_NAMESTORE_Client *nc; |
687 | size_t name_len; | 670 | size_t name_len; |
688 | char *name; | 671 | const char *name; |
689 | uint32_t rid = 0; | 672 | uint32_t rid; |
690 | uint32_t type = 0; | 673 | uint32_t type; |
691 | 674 | ||
675 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
676 | "Received `%s' message\n", | ||
677 | "NAMESTORE_LOOKUP_NAME"); | ||
692 | if (ntohs (message->size) < sizeof (struct LookupNameMessage)) | 678 | if (ntohs (message->size) < sizeof (struct LookupNameMessage)) |
693 | { | 679 | { |
694 | GNUNET_break_op (0); | 680 | GNUNET_break (0); |
695 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 681 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
696 | return; | 682 | return; |
697 | } | 683 | } |
698 | 684 | if (NULL == (nc = client_lookup(client))) | |
699 | nc = client_lookup(client); | ||
700 | if (nc == NULL) | ||
701 | { | 685 | { |
702 | GNUNET_break_op (0); | 686 | GNUNET_break (0); |
703 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 687 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
704 | return; | 688 | return; |
705 | } | 689 | } |
706 | 690 | ln_msg = (const struct LookupNameMessage *) message; | |
707 | struct LookupNameMessage *ln_msg = (struct LookupNameMessage *) message; | ||
708 | rid = ntohl (ln_msg->gns_header.r_id); | 691 | rid = ntohl (ln_msg->gns_header.r_id); |
709 | name_len = ntohl (ln_msg->name_len); | 692 | name_len = ntohl (ln_msg->name_len); |
710 | type = ntohl (ln_msg->record_type); | 693 | type = ntohl (ln_msg->record_type); |
711 | 694 | if ((0 == name_len) || (name_len > MAX_NAME_LEN)) | |
712 | if ((name_len == 0) || (name_len > 256)) | ||
713 | { | 695 | { |
714 | GNUNET_break_op (0); | 696 | GNUNET_break (0); |
715 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 697 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
716 | return; | 698 | return; |
717 | } | 699 | } |
718 | 700 | name = (const char *) &ln_msg[1]; | |
719 | name = (char *) &ln_msg[1]; | ||
720 | if (name[name_len -1] != '\0') | 701 | if (name[name_len -1] != '\0') |
721 | { | 702 | { |
722 | GNUNET_break_op (0); | 703 | GNUNET_break (0); |
723 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 704 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
724 | return; | 705 | return; |
725 | } | 706 | } |
726 | 707 | if (GNUNET_NAMESTORE_TYPE_ANY == type) | |
727 | if (0 == type) | 708 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
728 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up all records for name `%s' in zone `%s'\n", name, GNUNET_short_h2s(&ln_msg->zone)); | 709 | "Looking up all records for name `%s' in zone `%s'\n", |
710 | name, | ||
711 | GNUNET_short_h2s(&ln_msg->zone)); | ||
729 | else | 712 | else |
730 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up records with type %u for name `%s' in zone `%s'\n", type, name, GNUNET_short_h2s(&ln_msg->zone)); | 713 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
714 | "Looking up records with type %u for name `%s' in zone `%s'\n", | ||
715 | type, name, | ||
716 | GNUNET_short_h2s(&ln_msg->zone)); | ||
731 | 717 | ||
732 | /* do the actual lookup */ | 718 | /* do the actual lookup */ |
733 | lnc.request_id = rid; | 719 | lnc.request_id = rid; |
@@ -735,8 +721,18 @@ handle_lookup_name (void *cls, | |||
735 | lnc.record_type = type; | 721 | lnc.record_type = type; |
736 | lnc.name = name; | 722 | lnc.name = name; |
737 | lnc.zone = &ln_msg->zone; | 723 | lnc.zone = &ln_msg->zone; |
738 | GSN_database->iterate_records(GSN_database->cls, &ln_msg->zone, name, 0, &handle_lookup_name_it, &lnc); | 724 | if (GNUNET_SYSERR == |
739 | 725 | GSN_database->iterate_records (GSN_database->cls, | |
726 | &ln_msg->zone, name, 0 /* offset */, | ||
727 | &handle_lookup_name_it, &lnc)) | ||
728 | { | ||
729 | /* internal error (in database plugin); might be best to just hang up on | ||
730 | plugin rather than to signal that there are 'no' results, which | ||
731 | might also be false... */ | ||
732 | GNUNET_break (0); | ||
733 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
734 | return; | ||
735 | } | ||
740 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 736 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
741 | } | 737 | } |
742 | 738 | ||
@@ -753,125 +749,113 @@ handle_record_put (void *cls, | |||
753 | struct GNUNET_SERVER_Client *client, | 749 | struct GNUNET_SERVER_Client *client, |
754 | const struct GNUNET_MessageHeader *message) | 750 | const struct GNUNET_MessageHeader *message) |
755 | { | 751 | { |
756 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_PUT"); | ||
757 | struct GNUNET_NAMESTORE_Client *nc; | 752 | struct GNUNET_NAMESTORE_Client *nc; |
758 | struct RecordPutMessage *rp_msg; | 753 | const struct RecordPutMessage *rp_msg; |
759 | struct GNUNET_TIME_Absolute expire; | 754 | struct GNUNET_TIME_Absolute expire; |
760 | struct GNUNET_CRYPTO_RsaSignature *signature; | 755 | const struct GNUNET_CRYPTO_RsaSignature *signature; |
761 | struct RecordPutResponseMessage rpr_msg; | 756 | struct RecordPutResponseMessage rpr_msg; |
762 | struct GNUNET_CRYPTO_ShortHashCode zone_hash; | 757 | struct GNUNET_CRYPTO_ShortHashCode zone_hash; |
763 | size_t name_len; | 758 | size_t name_len; |
764 | size_t msg_size; | 759 | size_t msg_size; |
765 | size_t msg_size_exp; | 760 | size_t msg_size_exp; |
766 | char *name; | 761 | const char *name; |
767 | char *rd_ser; | 762 | const char *rd_ser; |
768 | uint32_t rid = 0; | 763 | uint32_t rid; |
769 | uint32_t rd_ser_len; | 764 | uint32_t rd_ser_len; |
770 | uint32_t rd_count; | 765 | uint32_t rd_count; |
771 | int res = GNUNET_SYSERR; | 766 | int res; |
772 | 767 | ||
768 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
769 | "Received `%s' message\n", | ||
770 | "NAMESTORE_RECORD_PUT"); | ||
773 | if (ntohs (message->size) < sizeof (struct RecordPutMessage)) | 771 | if (ntohs (message->size) < sizeof (struct RecordPutMessage)) |
774 | { | 772 | { |
775 | GNUNET_break_op (0); | 773 | GNUNET_break (0); |
776 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 774 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
777 | return; | 775 | return; |
778 | } | 776 | } |
779 | 777 | if (NULL == (nc = client_lookup (client))) | |
780 | nc = client_lookup (client); | ||
781 | if (nc == NULL) | ||
782 | { | 778 | { |
783 | GNUNET_break_op (0); | 779 | GNUNET_break (0); |
784 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 780 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
785 | return; | 781 | return; |
786 | } | 782 | } |
787 | 783 | rp_msg = (const struct RecordPutMessage *) message; | |
788 | rp_msg = (struct RecordPutMessage *) message; | ||
789 | rid = ntohl (rp_msg->gns_header.r_id); | 784 | rid = ntohl (rp_msg->gns_header.r_id); |
790 | msg_size = ntohs (rp_msg->gns_header.header.size); | 785 | msg_size = ntohs (rp_msg->gns_header.header.size); |
791 | name_len = ntohs (rp_msg->name_len); | 786 | name_len = ntohs (rp_msg->name_len); |
792 | rd_count = ntohs (rp_msg->rd_count); | 787 | rd_count = ntohs (rp_msg->rd_count); |
793 | rd_ser_len = ntohs(rp_msg->rd_len); | 788 | rd_ser_len = ntohs (rp_msg->rd_len); |
794 | 789 | if ((rd_count < 1) || (rd_ser_len < 1) || (name_len >= MAX_NAME_LEN) || (0 == name_len)) | |
795 | if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE) | ||
796 | { | ||
797 | GNUNET_break_op (0); | ||
798 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
799 | return; | ||
800 | } | ||
801 | |||
802 | if ((rd_count < 1) || (rd_ser_len < 1) || (name_len >=256) || (name_len == 0)) | ||
803 | { | 790 | { |
804 | GNUNET_break_op (0); | 791 | GNUNET_break (0); |
805 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 792 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
806 | return; | 793 | return; |
807 | } | 794 | } |
808 | 795 | msg_size_exp = sizeof (struct RecordPutMessage) + name_len + rd_ser_len; | |
809 | msg_size_exp = sizeof (struct RecordPutMessage) + name_len + rd_ser_len; | ||
810 | if (msg_size != msg_size_exp) | 796 | if (msg_size != msg_size_exp) |
811 | { | 797 | { |
812 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expected message %u size but message size is %u \n", msg_size_exp, msg_size); | 798 | GNUNET_break (0); |
813 | GNUNET_break_op (0); | 799 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
814 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
815 | return; | ||
816 | } | ||
817 | if ((name_len == 0) || (name_len > 256)) | ||
818 | { | ||
819 | GNUNET_break_op (0); | ||
820 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
821 | return; | 800 | return; |
822 | } | 801 | } |
823 | 802 | name = (const char *) &rp_msg[1]; | |
824 | name = (char *) &rp_msg[1]; | 803 | if ('\0' != name[name_len -1]) |
825 | |||
826 | if (name[name_len -1] != '\0') | ||
827 | { | 804 | { |
828 | GNUNET_break_op (0); | 805 | GNUNET_break (0); |
829 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 806 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
830 | return; | 807 | return; |
831 | } | 808 | } |
832 | 809 | expire = GNUNET_TIME_absolute_ntoh (rp_msg->expire); | |
833 | expire = GNUNET_TIME_absolute_ntoh(rp_msg->expire); | 810 | signature = &rp_msg->signature; |
834 | signature = (struct GNUNET_CRYPTO_RsaSignature *) &rp_msg->signature; | ||
835 | |||
836 | rd_ser = &name[name_len]; | 811 | rd_ser = &name[name_len]; |
837 | struct GNUNET_NAMESTORE_RecordData rd[rd_count]; | ||
838 | res = GNUNET_NAMESTORE_records_deserialize(rd_ser_len, rd_ser, rd_count, rd); | ||
839 | if (res != GNUNET_OK) | ||
840 | { | 812 | { |
841 | GNUNET_break_op (0); | 813 | struct GNUNET_NAMESTORE_RecordData rd[rd_count]; |
842 | goto send; | ||
843 | } | ||
844 | |||
845 | GNUNET_CRYPTO_short_hash (&rp_msg->public_key, sizeof (rp_msg->public_key), &zone_hash); | ||
846 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Putting %u record for name `%s' in zone `%s'\n", rd_count, name, GNUNET_short_h2s(&zone_hash)); | ||
847 | |||
848 | /* Database operation */ | ||
849 | res = GSN_database->put_records(GSN_database->cls, | ||
850 | &rp_msg->public_key, | ||
851 | expire, | ||
852 | name, | ||
853 | rd_count, rd, | ||
854 | signature); | ||
855 | 814 | ||
856 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Putting record for name `%s': %s\n", | 815 | if (GNUNET_OK != |
857 | name, (res == GNUNET_OK) ? "OK" : "FAIL"); | 816 | GNUNET_NAMESTORE_records_deserialize(rd_ser_len, rd_ser, rd_count, rd)) |
858 | 817 | { | |
859 | /* Send response */ | 818 | GNUNET_break (0); |
860 | send: | 819 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
861 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "RECORD_PUT_RESPONSE"); | 820 | return; |
821 | } | ||
822 | GNUNET_CRYPTO_short_hash (&rp_msg->public_key, | ||
823 | sizeof (rp_msg->public_key), | ||
824 | &zone_hash); | ||
825 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
826 | "Putting %u records under name `%s' in zone `%s'\n", | ||
827 | rd_count, name, | ||
828 | GNUNET_short_h2s (&zone_hash)); | ||
829 | res = GSN_database->put_records(GSN_database->cls, | ||
830 | &rp_msg->public_key, | ||
831 | expire, | ||
832 | name, | ||
833 | rd_count, rd, | ||
834 | signature); | ||
835 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
836 | "Putting record for name `%s': %s\n", | ||
837 | name, | ||
838 | (res == GNUNET_OK) ? "OK" : "FAILED"); | ||
839 | } | ||
840 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
841 | "Sending `%s' message\n", | ||
842 | "RECORD_PUT_RESPONSE"); | ||
862 | rpr_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE); | 843 | rpr_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE); |
863 | rpr_msg.gns_header.header.size = htons (sizeof (struct RecordPutResponseMessage)); | 844 | rpr_msg.gns_header.header.size = htons (sizeof (struct RecordPutResponseMessage)); |
864 | rpr_msg.gns_header.r_id = htonl (rid); | 845 | rpr_msg.gns_header.r_id = htonl (rid); |
865 | rpr_msg.op_result = htonl (res); | 846 | rpr_msg.op_result = htonl (res); |
866 | GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct GNUNET_MessageHeader *) &rpr_msg, GNUNET_NO); | 847 | GNUNET_SERVER_notification_context_unicast (snc, |
867 | 848 | nc->client, | |
849 | &rpr_msg.gns_header.header, | ||
850 | GNUNET_NO); | ||
868 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 851 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
869 | } | 852 | } |
870 | 853 | ||
871 | 854 | ||
855 | ///////////////////////////////////////////////////////////// | ||
856 | |||
857 | |||
872 | /** | 858 | /** |
873 | * CreateRecordContext | ||
874 | * | ||
875 | * Context for record create operations passed from 'handle_record_create' to | 859 | * Context for record create operations passed from 'handle_record_create' to |
876 | * 'handle_create_record_it' as closure | 860 | * 'handle_create_record_it' as closure |
877 | */ | 861 | */ |
@@ -880,27 +864,27 @@ struct CreateRecordContext | |||
880 | /** | 864 | /** |
881 | * Record data | 865 | * Record data |
882 | */ | 866 | */ |
883 | struct GNUNET_NAMESTORE_RecordData *rd; | 867 | const struct GNUNET_NAMESTORE_RecordData *rd; |
884 | 868 | ||
885 | /** | 869 | /** |
886 | * Zone's private key | 870 | * Zone's private key |
887 | */ | 871 | */ |
888 | struct GNUNET_CRYPTO_RsaPrivateKey *pkey; | 872 | const struct GNUNET_CRYPTO_RsaPrivateKey *pkey; |
889 | 873 | ||
890 | /** | 874 | /** |
891 | * Zone's public key | 875 | * Zone's public key |
892 | */ | 876 | */ |
893 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pubkey; | 877 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pubkey; |
894 | 878 | ||
895 | /** | 879 | /** |
896 | * Record expiration time | 880 | * Name for the record to create |
897 | */ | 881 | */ |
898 | struct GNUNET_TIME_Absolute expire; | 882 | const char *name; |
899 | 883 | ||
900 | /** | 884 | /** |
901 | * Name for the record to create | 885 | * Record expiration time |
902 | */ | 886 | */ |
903 | char *name; | 887 | struct GNUNET_TIME_Absolute expire; |
904 | 888 | ||
905 | /** | 889 | /** |
906 | * result returned from 'handle_create_record_it' | 890 | * result returned from 'handle_create_record_it' |
@@ -943,7 +927,9 @@ handle_create_record_it (void *cls, | |||
943 | int c; | 927 | int c; |
944 | int rd_count_new = 0; | 928 | int rd_count_new = 0; |
945 | 929 | ||
946 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u existing records for `%s'\n", rd_count, crc->name); | 930 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
931 | "Found %u existing records for `%s'\n", | ||
932 | rd_count, crc->name); | ||
947 | for (c = 0; c < rd_count; c++) | 933 | for (c = 0; c < rd_count; c++) |
948 | { | 934 | { |
949 | if ( (crc->rd->record_type == GNUNET_NAMESTORE_TYPE_PKEY) && | 935 | if ( (crc->rd->record_type == GNUNET_NAMESTORE_TYPE_PKEY) && |
@@ -1137,7 +1123,7 @@ handle_record_create (void *cls, | |||
1137 | return; | 1123 | return; |
1138 | } | 1124 | } |
1139 | 1125 | ||
1140 | if ((name_len == 0) || (name_len > 256)) | 1126 | if ((name_len == 0) || (name_len > MAX_NAME_LEN)) |
1141 | { | 1127 | { |
1142 | GNUNET_break_op (0); | 1128 | GNUNET_break_op (0); |
1143 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1129 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
@@ -1427,7 +1413,7 @@ handle_record_remove (void *cls, | |||
1427 | return; | 1413 | return; |
1428 | } | 1414 | } |
1429 | 1415 | ||
1430 | if ((name_len >=256) || (name_len == 0)) | 1416 | if ((name_len >=MAX_NAME_LEN) || (name_len == 0)) |
1431 | { | 1417 | { |
1432 | GNUNET_break_op (0); | 1418 | GNUNET_break_op (0); |
1433 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1419 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
@@ -1448,7 +1434,7 @@ handle_record_remove (void *cls, | |||
1448 | rd_ser = &name_tmp[name_len]; | 1434 | rd_ser = &name_tmp[name_len]; |
1449 | 1435 | ||
1450 | 1436 | ||
1451 | if ((name_len == 0) || (name_len > 256)) | 1437 | if ((name_len == 0) || (name_len > MAX_NAME_LEN)) |
1452 | { | 1438 | { |
1453 | GNUNET_break_op (0); | 1439 | GNUNET_break_op (0); |
1454 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1440 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
@@ -1930,27 +1916,29 @@ zone_iteraterate_proc (void *cls, | |||
1930 | return; | 1916 | return; |
1931 | } | 1917 | } |
1932 | } | 1918 | } |
1919 | ///////////////////////////////////////////////////////////// | ||
1933 | 1920 | ||
1934 | 1921 | ||
1935 | /** | 1922 | /** |
1936 | * Find next zone iteration result in database | 1923 | * Find next zone iteration result in database |
1937 | * @param proc the zone iteration processing to use | 1924 | * |
1925 | * @param proc the zone iteration processing to use | ||
1938 | */ | 1926 | */ |
1939 | static void | 1927 | static void |
1940 | find_next_zone_iteration_result (struct ZoneIterationProcResult *proc) | 1928 | find_next_zone_iteration_result (struct ZoneIterationProcResult *proc) |
1941 | { | 1929 | { |
1942 | |||
1943 | struct GNUNET_CRYPTO_ShortHashCode *zone; | 1930 | struct GNUNET_CRYPTO_ShortHashCode *zone; |
1944 | 1931 | ||
1945 | if (GNUNET_YES == proc->zi->has_zone) | 1932 | if (GNUNET_YES == proc->zi->has_zone) |
1946 | zone = &proc->zi->zone; | 1933 | zone = &proc->zi->zone; |
1947 | else | 1934 | else |
1948 | zone = NULL; | 1935 | zone = NULL; |
1949 | |||
1950 | do | 1936 | do |
1951 | { | 1937 | { |
1952 | if (GNUNET_SYSERR == | 1938 | if (GNUNET_SYSERR == |
1953 | GSN_database->iterate_records (GSN_database->cls, zone, NULL, proc->zi->offset, &zone_iteraterate_proc, proc)) | 1939 | GSN_database->iterate_records (GSN_database->cls, zone, NULL, |
1940 | proc->zi->offset, | ||
1941 | &zone_iteraterate_proc, proc)) | ||
1954 | { | 1942 | { |
1955 | GNUNET_break (0); | 1943 | GNUNET_break (0); |
1956 | break; | 1944 | break; |
@@ -1963,63 +1951,56 @@ find_next_zone_iteration_result (struct ZoneIterationProcResult *proc) | |||
1963 | 1951 | ||
1964 | /** | 1952 | /** |
1965 | * Send zone iteration result to client | 1953 | * Send zone iteration result to client |
1954 | * | ||
1966 | * @param proc the zone iteration processing result to send | 1955 | * @param proc the zone iteration processing result to send |
1967 | */ | 1956 | */ |
1968 | static void | 1957 | static void |
1969 | send_zone_iteration_result (struct ZoneIterationProcResult *proc) | 1958 | send_zone_iteration_result (struct ZoneIterationProcResult *proc) |
1970 | { | 1959 | { |
1971 | struct GNUNET_NAMESTORE_ZoneIteration *zi = proc->zi; | 1960 | struct GNUNET_NAMESTORE_ZoneIteration *zi = proc->zi; |
1961 | struct ZoneIterationResponseMessage zir_end; | ||
1962 | struct ZoneIterationResponseMessage *zir_msg; | ||
1963 | size_t name_len; | ||
1964 | size_t rd_ser_len; | ||
1965 | size_t msg_size; | ||
1966 | char *name_tmp; | ||
1967 | char *rd_ser; | ||
1972 | 1968 | ||
1973 | if (GNUNET_YES == proc->res_iteration_finished) | 1969 | if (GNUNET_YES == proc->res_iteration_finished) |
1974 | { | 1970 | { |
1975 | struct ZoneIterationResponseMessage zir_msg; | ||
1976 | if (zi->has_zone == GNUNET_YES) | 1971 | if (zi->has_zone == GNUNET_YES) |
1977 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No more results for zone `%s'\n", GNUNET_short_h2s(&zi->zone)); | 1972 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1973 | "No more results for zone `%s'\n", | ||
1974 | GNUNET_short_h2s(&zi->zone)); | ||
1978 | else | 1975 | else |
1979 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No more results for all zones\n"); | 1976 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1980 | 1977 | "No more results for all zones\n"); | |
1981 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending empty `%s' message\n", "ZONE_ITERATION_RESPONSE"); | 1978 | memset (&zir_end, 0, sizeof (zir_end)); |
1982 | zir_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE); | 1979 | zir_end.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE); |
1983 | zir_msg.gns_header.header.size = htons (sizeof (struct ZoneIterationResponseMessage)); | 1980 | zir_end.gns_header.header.size = htons (sizeof (struct ZoneIterationResponseMessage)); |
1984 | zir_msg.gns_header.r_id = htonl(zi->request_id); | 1981 | zir_end.gns_header.r_id = htonl(zi->request_id); |
1985 | zir_msg.expire = GNUNET_TIME_absolute_hton(GNUNET_TIME_UNIT_ZERO_ABS); | 1982 | GNUNET_SERVER_notification_context_unicast (snc, |
1986 | zir_msg.name_len = htons (0); | 1983 | zi->client->client, |
1987 | zir_msg.reserved = htons (0); | 1984 | &zir_end.gns_header.header, GNUNET_NO); |
1988 | zir_msg.rd_count = htons (0); | ||
1989 | zir_msg.rd_len = htons (0); | ||
1990 | memset (&zir_msg.public_key, '\0', sizeof (zir_msg.public_key)); | ||
1991 | memset (&zir_msg.signature, '\0', sizeof (zir_msg.signature)); | ||
1992 | GNUNET_SERVER_notification_context_unicast (snc, zi->client->client, (const struct GNUNET_MessageHeader *) &zir_msg, GNUNET_NO); | ||
1993 | |||
1994 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing zone iterator\n"); | 1985 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing zone iterator\n"); |
1995 | GNUNET_CONTAINER_DLL_remove (zi->client->op_head, zi->client->op_tail, zi); | 1986 | GNUNET_CONTAINER_DLL_remove (zi->client->op_head, zi->client->op_tail, zi); |
1996 | GNUNET_free (zi); | 1987 | GNUNET_free (zi); |
1997 | return; | 1988 | return; |
1998 | } | 1989 | } |
1999 | |||
2000 | GNUNET_assert (proc->records_included > 0); | 1990 | GNUNET_assert (proc->records_included > 0); |
2001 | 1991 | if (GNUNET_YES == zi->has_zone) | |
2002 | struct ZoneIterationResponseMessage *zir_msg; | 1992 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2003 | size_t name_len; | 1993 | "Sending name `%s' for iteration over zone `%s'\n", |
2004 | size_t rd_ser_len; | ||
2005 | size_t msg_size; | ||
2006 | char *name_tmp; | ||
2007 | char *rd_tmp; | ||
2008 | |||
2009 | if (zi->has_zone == GNUNET_YES) | ||
2010 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending name `%s' for iteration over zone `%s'\n", | ||
2011 | proc->name, GNUNET_short_h2s(&zi->zone)); | 1994 | proc->name, GNUNET_short_h2s(&zi->zone)); |
2012 | if (zi->has_zone == GNUNET_NO) | 1995 | else |
2013 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending name `%s' for iteration over all zones\n", | 1996 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1997 | "Sending name `%s' for iteration over all zones\n", | ||
2014 | proc->name); | 1998 | proc->name); |
2015 | name_len = strlen (proc->name) +1; | 1999 | name_len = strlen (proc->name) + 1; |
2016 | rd_ser_len = GNUNET_NAMESTORE_records_get_size(proc->records_included, proc->rd); | 2000 | rd_ser_len = GNUNET_NAMESTORE_records_get_size(proc->records_included, proc->rd); |
2017 | char rd_ser[rd_ser_len]; | ||
2018 | GNUNET_NAMESTORE_records_serialize(proc->records_included, proc->rd, rd_ser_len, rd_ser); | ||
2019 | msg_size = sizeof (struct ZoneIterationResponseMessage) + name_len + rd_ser_len; | 2001 | msg_size = sizeof (struct ZoneIterationResponseMessage) + name_len + rd_ser_len; |
2002 | |||
2020 | zir_msg = GNUNET_malloc(msg_size); | 2003 | zir_msg = GNUNET_malloc(msg_size); |
2021 | name_tmp = (char *) &zir_msg[1]; | ||
2022 | rd_tmp = &name_tmp[name_len]; | ||
2023 | zir_msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE); | 2004 | zir_msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE); |
2024 | zir_msg->gns_header.header.size = htons (msg_size); | 2005 | zir_msg->gns_header.header.size = htons (msg_size); |
2025 | zir_msg->gns_header.r_id = htonl(zi->request_id); | 2006 | zir_msg->gns_header.r_id = htonl(zi->request_id); |
@@ -2030,11 +2011,14 @@ send_zone_iteration_result (struct ZoneIterationProcResult *proc) | |||
2030 | zir_msg->rd_len = htons (rd_ser_len); | 2011 | zir_msg->rd_len = htons (rd_ser_len); |
2031 | zir_msg->signature = proc->signature; | 2012 | zir_msg->signature = proc->signature; |
2032 | zir_msg->public_key = proc->zone_key; | 2013 | zir_msg->public_key = proc->zone_key; |
2014 | name_tmp = (char *) &zir_msg[1]; | ||
2033 | memcpy (name_tmp, proc->name, name_len); | 2015 | memcpy (name_tmp, proc->name, name_len); |
2034 | memcpy (rd_tmp, rd_ser, rd_ser_len); | 2016 | rd_ser = &name_tmp[name_len]; |
2035 | 2017 | GNUNET_NAMESTORE_records_serialize (proc->records_included, proc->rd, rd_ser_len, rd_ser); | |
2036 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2018 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2037 | "Sending `%s' message with size %u\n", "ZONE_ITERATION_RESPONSE", msg_size); | 2019 | "Sending `%s' message with size %u\n", |
2020 | "ZONE_ITERATION_RESPONSE", | ||
2021 | msg_size); | ||
2038 | GNUNET_SERVER_notification_context_unicast (snc, zi->client->client, | 2022 | GNUNET_SERVER_notification_context_unicast (snc, zi->client->client, |
2039 | (const struct GNUNET_MessageHeader *) zir_msg, | 2023 | (const struct GNUNET_MessageHeader *) zir_msg, |
2040 | GNUNET_NO); | 2024 | GNUNET_NO); |
@@ -2052,13 +2036,12 @@ clean_up_zone_iteration_result (struct ZoneIterationProcResult *proc) | |||
2052 | unsigned int c; | 2036 | unsigned int c; |
2053 | 2037 | ||
2054 | GNUNET_free_non_null (proc->name); | 2038 | GNUNET_free_non_null (proc->name); |
2055 | for (c = 0; c < proc->records_included; c++) | ||
2056 | { | ||
2057 | GNUNET_free ((void *) proc->rd[c].data); | ||
2058 | } | ||
2059 | GNUNET_free_non_null (proc->rd); | ||
2060 | proc->name = NULL; | 2039 | proc->name = NULL; |
2040 | for (c = 0; c < proc->records_included; c++) | ||
2041 | GNUNET_free ((void *) proc->rd[c].data); | ||
2042 | GNUNET_free_non_null (proc->rd); | ||
2061 | proc->rd = NULL; | 2043 | proc->rd = NULL; |
2044 | proc->records_included = 0; | ||
2062 | } | 2045 | } |
2063 | 2046 | ||
2064 | 2047 | ||
@@ -2083,7 +2066,7 @@ run_zone_iteration_round (struct GNUNET_NAMESTORE_ZoneIteration *zi) | |||
2083 | else if (0 != proc.records_included) | 2066 | else if (0 != proc.records_included) |
2084 | { | 2067 | { |
2085 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2068 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2086 | "Zone iteration return %u records\n", | 2069 | "Zone iteration returns %u records\n", |
2087 | proc.records_included); | 2070 | proc.records_included); |
2088 | } | 2071 | } |
2089 | send_zone_iteration_result (&proc); | 2072 | send_zone_iteration_result (&proc); |
@@ -2132,7 +2115,7 @@ handle_iteration_start (void *cls, | |||
2132 | else | 2115 | else |
2133 | { | 2116 | { |
2134 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2117 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2135 | "Starting to iterate over zone `%s'\n", GNUNET_short_h2s (&zis_msg->zone)); | 2118 | "Starting to iterate over zone `%s'\n", GNUNET_short_h2s (&zis_msg->zone)); |
2136 | zi->zone = zis_msg->zone; | 2119 | zi->zone = zis_msg->zone; |
2137 | zi->has_zone = GNUNET_YES; | 2120 | zi->has_zone = GNUNET_YES; |
2138 | } | 2121 | } |
@@ -2156,7 +2139,7 @@ handle_iteration_stop (void *cls, | |||
2156 | { | 2139 | { |
2157 | struct GNUNET_NAMESTORE_Client *nc; | 2140 | struct GNUNET_NAMESTORE_Client *nc; |
2158 | struct GNUNET_NAMESTORE_ZoneIteration *zi; | 2141 | struct GNUNET_NAMESTORE_ZoneIteration *zi; |
2159 | struct ZoneIterationStopMessage *zis_msg; | 2142 | const struct ZoneIterationStopMessage *zis_msg; |
2160 | uint32_t rid; | 2143 | uint32_t rid; |
2161 | 2144 | ||
2162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -2169,7 +2152,7 @@ handle_iteration_stop (void *cls, | |||
2169 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2152 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2170 | return; | 2153 | return; |
2171 | } | 2154 | } |
2172 | zis_msg = (struct ZoneIterationStopMessage *) message; | 2155 | zis_msg = (const struct ZoneIterationStopMessage *) message; |
2173 | rid = ntohl (zis_msg->gns_header.r_id); | 2156 | rid = ntohl (zis_msg->gns_header.r_id); |
2174 | for (zi = nc->op_head; NULL != zi; zi = zi->next) | 2157 | for (zi = nc->op_head; NULL != zi; zi = zi->next) |
2175 | if (zi->request_id == rid) | 2158 | if (zi->request_id == rid) |
@@ -2303,11 +2286,11 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
2303 | {&handle_zone_to_name, NULL, | 2286 | {&handle_zone_to_name, NULL, |
2304 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME, 0}, | 2287 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME, 0}, |
2305 | {&handle_iteration_start, NULL, | 2288 | {&handle_iteration_start, NULL, |
2306 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START, sizeof (struct ZoneIterationStartMessage)}, | 2289 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START, sizeof (struct ZoneIterationStartMessage) }, |
2307 | {&handle_iteration_next, NULL, | 2290 | {&handle_iteration_next, NULL, |
2308 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT, 0}, | 2291 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT, sizeof (struct ZoneIterationNextMessage) }, |
2309 | {&handle_iteration_stop, NULL, | 2292 | {&handle_iteration_stop, NULL, |
2310 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP, 0}, | 2293 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP, sizeof (struct ZoneIterationStopMessage) }, |
2311 | {NULL, NULL, 0, 0} | 2294 | {NULL, NULL, 0, 0} |
2312 | }; | 2295 | }; |
2313 | char *database; | 2296 | char *database; |