diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-06-14 12:50:27 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-06-14 12:50:27 +0000 |
commit | c18fcd88d8897d0645900a1b6f527232d0153f88 (patch) | |
tree | 445441c0ac27a28e747757d7d347c8f44e1df72f /src/ats/gnunet-service-ats_addresses.c | |
parent | 21f92c1b07d8361c270fa08f9f41d78a3e8e18b3 (diff) | |
download | gnunet-c18fcd88d8897d0645900a1b6f527232d0153f88.tar.gz gnunet-c18fcd88d8897d0645900a1b6f527232d0153f88.zip |
- adding GNUNET_ATS_address_add functionality .. no changes to scheduling API yet
Diffstat (limited to 'src/ats/gnunet-service-ats_addresses.c')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 71 |
1 files changed, 70 insertions, 1 deletions
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 97475ad19..854716dc7 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -330,6 +330,70 @@ find_exact_address (const struct GNUNET_PeerIdentity *peer, | |||
330 | 330 | ||
331 | 331 | ||
332 | void | 332 | void |
333 | GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, | ||
334 | const char *plugin_name, const void *plugin_addr, | ||
335 | size_t plugin_addr_len, uint32_t session_id, | ||
336 | const struct GNUNET_ATS_Information *atsi, | ||
337 | uint32_t atsi_count) | ||
338 | { | ||
339 | struct ATS_Address *aa; | ||
340 | struct ATS_Address *old; | ||
341 | |||
342 | if (GNUNET_NO == running) | ||
343 | return; | ||
344 | |||
345 | GNUNET_assert (NULL != addresses); | ||
346 | |||
347 | aa = create_address (peer, | ||
348 | plugin_name, | ||
349 | plugin_addr, plugin_addr_len, | ||
350 | session_id); | ||
351 | |||
352 | aa->mlp_information = NULL; | ||
353 | aa->ats = GNUNET_malloc (atsi_count * sizeof (struct GNUNET_ATS_Information)); | ||
354 | aa->ats_count = atsi_count; | ||
355 | memcpy (aa->ats, atsi, atsi_count * sizeof (struct GNUNET_ATS_Information)); | ||
356 | |||
357 | /* Get existing address or address with session == 0 */ | ||
358 | old = find_address (peer, aa); | ||
359 | if (old == NULL) | ||
360 | { | ||
361 | /* We have a new address */ | ||
362 | GNUNET_assert (GNUNET_OK == | ||
363 | GNUNET_CONTAINER_multihashmap_put (addresses, | ||
364 | &peer->hashPubKey, aa, | ||
365 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | ||
366 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added new address for peer `%s' %p\n", | ||
367 | GNUNET_i2s (peer), aa); | ||
368 | return; | ||
369 | } | ||
370 | |||
371 | if (old->session_id == 0) | ||
372 | { | ||
373 | /* We have a base address with out an session, update this address */ | ||
374 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
375 | "Updated existing address for peer `%s' %p with new session %u\n", | ||
376 | GNUNET_i2s (peer), old, session_id); | ||
377 | GNUNET_free_non_null (old->ats); | ||
378 | old->session_id = session_id; | ||
379 | old->ats = NULL; | ||
380 | old->ats_count = 0; | ||
381 | old->ats = aa->ats; | ||
382 | old->ats_count = aa->ats_count; | ||
383 | GNUNET_free (aa->plugin); | ||
384 | GNUNET_free (aa); | ||
385 | return; | ||
386 | } | ||
387 | |||
388 | /* This address and session is already existing */ | ||
389 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
390 | "Added already existing address for peer `%s' `%s' %p with new session %u\n", | ||
391 | GNUNET_i2s (peer), plugin_name, session_id); | ||
392 | GNUNET_break (0); | ||
393 | } | ||
394 | |||
395 | |||
396 | void | ||
333 | GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, | 397 | GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, |
334 | const char *plugin_name, const void *plugin_addr, | 398 | const char *plugin_name, const void *plugin_addr, |
335 | size_t plugin_addr_len, uint32_t session_id, | 399 | size_t plugin_addr_len, uint32_t session_id, |
@@ -368,7 +432,7 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, | |||
368 | &peer->hashPubKey, aa, | 432 | &peer->hashPubKey, aa, |
369 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 433 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
370 | #if DEBUG_ATS | 434 | #if DEBUG_ATS |
371 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added new address for peer `%s' %X\n", | 435 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added new address for peer `%s' %p\n", |
372 | GNUNET_i2s (peer), aa); | 436 | GNUNET_i2s (peer), aa); |
373 | #endif | 437 | #endif |
374 | old = aa; | 438 | old = aa; |
@@ -640,6 +704,11 @@ GAS_addresses_in_use (const struct GNUNET_PeerIdentity *peer, | |||
640 | 704 | ||
641 | if (NULL == old) | 705 | if (NULL == old) |
642 | { | 706 | { |
707 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
708 | "Unknown address `%s', %s %u %s \n", | ||
709 | GNUNET_i2s (peer), | ||
710 | plugin_name, session_id, | ||
711 | (GNUNET_NO == in_use) ? "NO" : "YES"); | ||
643 | GNUNET_break (0); | 712 | GNUNET_break (0); |
644 | return GNUNET_SYSERR; | 713 | return GNUNET_SYSERR; |
645 | } | 714 | } |