aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/Makefile.am6
-rw-r--r--src/transport/gnunet-service-transport.c155
-rw-r--r--src/transport/gnunet-service-transport_ats.c206
-rw-r--r--src/transport/gnunet-service-transport_ats.h43
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c908
-rw-r--r--src/transport/gnunet-service-transport_validation.c53
-rw-r--r--src/transport/gnunet-service-transport_validation.h9
-rw-r--r--src/transport/plugin_transport_http_server.c5
-rw-r--r--src/transport/plugin_transport_tcp.c4
-rw-r--r--src/transport/test_transport_address_switch.c122
-rw-r--r--src/transport/test_transport_api_restart_2peers.c7
-rw-r--r--src/transport/transport_api.c12
12 files changed, 838 insertions, 692 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index 749550657..7beec3118 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -416,6 +416,9 @@ libgnunet_plugin_transport_https_server_la_CFLAGS = \
416 416
417if HAVE_TESTING 417if HAVE_TESTING
418check_PROGRAMS = \ 418check_PROGRAMS = \
419 test_transport_api_restart_2peers \
420 test_transport_address_switch_tcp \
421 test_transport_address_switch_udp \
419 test_transport_testing_startstop \ 422 test_transport_testing_startstop \
420 test_transport_testing_restart \ 423 test_transport_testing_restart \
421 test_transport_testing \ 424 test_transport_testing \
@@ -435,14 +438,11 @@ check_PROGRAMS = \
435 test_transport_api_bidirectional_connect \ 438 test_transport_api_bidirectional_connect \
436 test_transport_api_tcp \ 439 test_transport_api_tcp \
437 test_transport_api_restart_1peer \ 440 test_transport_api_restart_1peer \
438 test_transport_api_restart_2peers \
439 test_transport_api_timeout_tcp \ 441 test_transport_api_timeout_tcp \
440 test_transport_address_switch_tcp \
441 test_transport_api_limited_sockets_tcp \ 442 test_transport_api_limited_sockets_tcp \
442 test_transport_api_tcp_nat \ 443 test_transport_api_tcp_nat \
443 test_transport_api_udp \ 444 test_transport_api_udp \
444 test_transport_api_timeout_udp \ 445 test_transport_api_timeout_udp \
445 test_transport_address_switch_udp \
446 $(UNIX_PLUGIN_TEST) \ 446 $(UNIX_PLUGIN_TEST) \
447 $(UNIX_PLUGIN_TIMEOUT_TEST) \ 447 $(UNIX_PLUGIN_TIMEOUT_TEST) \
448 $(UNIX_API_ABSTRACT_TEST) \ 448 $(UNIX_API_ABSTRACT_TEST) \
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index e3bbf7167..f317e924f 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -17,7 +17,6 @@
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19 */ 19 */
20
21/** 20/**
22 * @file transport/gnunet-service-transport.c 21 * @file transport/gnunet-service-transport.c
23 * @brief main for gnunet-service-transport 22 * @brief main for gnunet-service-transport
@@ -41,6 +40,7 @@
41#include "gnunet-service-transport_manipulation.h" 40#include "gnunet-service-transport_manipulation.h"
42#include "transport.h" 41#include "transport.h"
43 42
43
44/** 44/**
45 * Information we need for an asynchronous session kill. 45 * Information we need for an asynchronous session kill.
46 */ 46 */
@@ -73,18 +73,45 @@ struct SessionKiller
73}; 73};
74 74
75 75
76/**
77 * We track active blacklist checks in a DLL so we can cancel them if
78 * necessary. We typically check against the blacklist a few times
79 * during connection setup, as the check is asynchronous and the
80 * blacklist may change its mind before the connection goes fully up.
81 * Similarly, the session may die during the asynchronous check, so
82 * we use this list to then cancel ongoing checks.
83 */
76struct BlacklistCheckContext 84struct BlacklistCheckContext
77{ 85{
86 /**
87 * We keep these in a DLL.
88 */
78 struct BlacklistCheckContext *prev; 89 struct BlacklistCheckContext *prev;
79 90
91 /**
92 * We keep these in a DLL.
93 */
80 struct BlacklistCheckContext *next; 94 struct BlacklistCheckContext *next;
81 95
96 /**
97 * Handle with the blacklist subsystem.
98 */
82 struct GST_BlacklistCheck *blc; 99 struct GST_BlacklistCheck *blc;
83 100
101 /**
102 * The address we are checking.
103 */
84 struct GNUNET_HELLO_Address *address; 104 struct GNUNET_HELLO_Address *address;
85 105
106 /**
107 * Session associated with the address (or NULL).
108 */
86 struct Session *session; 109 struct Session *session;
87 110
111 /**
112 * Message to process in the continuation if the
113 * blacklist check is ok, can be NULL.
114 */
88 struct GNUNET_MessageHeader *msg; 115 struct GNUNET_MessageHeader *msg;
89 116
90}; 117};
@@ -152,12 +179,16 @@ static struct SessionKiller *sk_tail;
152static struct GNUNET_ATS_InterfaceScanner *is; 179static struct GNUNET_ATS_InterfaceScanner *is;
153 180
154/** 181/**
155 * FIXME 182 * Head of DLL of blacklist checks we have pending for
183 * incoming sessions and/or SYN requests. We may
184 * want to move this into the blacklist-logic at some
185 * point.
156 */ 186 */
157struct BlacklistCheckContext *bc_head; 187struct BlacklistCheckContext *bc_head;
158 188
159/** 189/**
160 * FIXME 190 * Tail of DLL of blacklist checks we have pending for
191 * incoming sessions and/or SYN requests.
161 */ 192 */
162struct BlacklistCheckContext *bc_tail; 193struct BlacklistCheckContext *bc_tail;
163 194
@@ -202,7 +233,8 @@ transmit_our_hello (void *cls,
202 * @param hello new HELLO 233 * @param hello new HELLO
203 */ 234 */
204static void 235static void
205process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello) 236process_hello_update (void *cls,
237 const struct GNUNET_MessageHeader *hello)
206{ 238{
207 GST_clients_broadcast (hello, GNUNET_NO); 239 GST_clients_broadcast (hello, GNUNET_NO);
208 GST_neighbours_iterate (&transmit_our_hello, (void *) hello); 240 GST_neighbours_iterate (&transmit_our_hello, (void *) hello);
@@ -268,20 +300,24 @@ process_payload (const struct GNUNET_HELLO_Address *address,
268 * @param tc scheduler context 300 * @param tc scheduler context
269 */ 301 */
270static void 302static void
271kill_session_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 303kill_session_task (void *cls,
304 const struct GNUNET_SCHEDULER_TaskContext *tc)
272{ 305{
273 struct SessionKiller *sk = cls; 306 struct SessionKiller *sk = cls;
274 307
275 sk->task = NULL; 308 sk->task = NULL;
276 GNUNET_CONTAINER_DLL_remove(sk_head, sk_tail, sk); 309 GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk);
277 sk->plugin->disconnect_session (sk->plugin->cls, sk->session); 310 sk->plugin->disconnect_session (sk->plugin->cls, sk->session);
278 GNUNET_free(sk); 311 GNUNET_free(sk);
279} 312}
280 313
281 314
282/** 315/**
283 * FIXME. Also, consider moving the "bc_*" logic into 316 * Cancel all blacklist checks that are pending for the given address and session.
284 * blacklist.h? 317 * NOTE: Consider moving the "bc_*" logic into blacklist.h?
318 *
319 * @param address address to remove from check
320 * @param sesssion session that must match to remove for check
285 */ 321 */
286static void 322static void
287cancel_pending_blacklist_checks (const struct GNUNET_HELLO_Address *address, 323cancel_pending_blacklist_checks (const struct GNUNET_HELLO_Address *address,
@@ -298,7 +334,9 @@ cancel_pending_blacklist_checks (const struct GNUNET_HELLO_Address *address,
298 (0 == GNUNET_HELLO_address_cmp(blctx->address, address)) && 334 (0 == GNUNET_HELLO_address_cmp(blctx->address, address)) &&
299 (blctx->session == session)) 335 (blctx->session == session))
300 { 336 {
301 GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, blctx); 337 GNUNET_CONTAINER_DLL_remove (bc_head,
338 bc_tail,
339 blctx);
302 if (NULL != blctx->blc) 340 if (NULL != blctx->blc)
303 { 341 {
304 GST_blacklist_test_cancel (blctx->blc); 342 GST_blacklist_test_cancel (blctx->blc);
@@ -361,35 +399,37 @@ connect_bl_check_cont (void *cls,
361{ 399{
362 struct BlacklistCheckContext *blctx = cls; 400 struct BlacklistCheckContext *blctx = cls;
363 401
364 GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, blctx); 402 GNUNET_CONTAINER_DLL_remove (bc_head,
403 bc_tail,
404 blctx);
365 blctx->blc = NULL; 405 blctx->blc = NULL;
366
367 if (GNUNET_OK == result) 406 if (GNUNET_OK == result)
368 { 407 {
369 /* Blacklist allows to speak to this peer, forward SYN to neighbours */ 408 /* Blacklist allows to speak to this peer, forward SYN to neighbours */
370 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 409 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
371 "Received SYN message from peer `%s' with `%s' %p\n", 410 "Received SYN message from peer `%s' at `%s'\n",
372 GNUNET_i2s (peer), 411 GNUNET_i2s (peer),
373 GST_plugins_a2s (blctx->address), 412 GST_plugins_a2s (blctx->address));
374 blctx->session);
375
376 if (GNUNET_OK != 413 if (GNUNET_OK !=
377 GST_neighbours_handle_session_syn (blctx->msg, 414 GST_neighbours_handle_session_syn (blctx->msg,
378 &blctx->address->peer)) 415 &blctx->address->peer))
379 { 416 {
380 cancel_pending_blacklist_checks (blctx->address, blctx->session); 417 cancel_pending_blacklist_checks (blctx->address,
381 kill_session (blctx->address->transport_name, blctx->session); 418 blctx->session);
419 kill_session (blctx->address->transport_name,
420 blctx->session);
382 } 421 }
383 } 422 }
384 else 423 else
385 { 424 {
386 /* Blacklist denies to speak to this peer */ 425 /* Blacklist denies to speak to this peer */
387 426 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
388 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 427 "Discarding SYN message from `%s' due to denied blacklist check\n",
389 "Discarding SYN message from `%s' due to denied blacklist check\n", 428 GNUNET_i2s (peer));
390 GNUNET_i2s (peer)); 429 cancel_pending_blacklist_checks (blctx->address,
391 cancel_pending_blacklist_checks (blctx->address, blctx->session); 430 blctx->session);
392 kill_session (blctx->address->transport_name, blctx->session); 431 kill_session (blctx->address->transport_name,
432 blctx->session);
393 } 433 }
394 434
395 if (NULL != blctx->address) 435 if (NULL != blctx->address)
@@ -429,7 +469,7 @@ GST_receive_callback (void *cls,
429 goto end; 469 goto end;
430 type = ntohs (message->type); 470 type = ntohs (message->type);
431 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
432 "Received Message with type %u from peer `%s'\n", 472 "Received message with type %u from peer `%s'\n",
433 type, 473 type,
434 GNUNET_i2s (&address->peer)); 474 GNUNET_i2s (&address->peer));
435 475
@@ -485,11 +525,17 @@ GST_receive_callback (void *cls,
485 blctx->address = GNUNET_HELLO_address_copy (address); 525 blctx->address = GNUNET_HELLO_address_copy (address);
486 blctx->session = session; 526 blctx->session = session;
487 blctx->msg = GNUNET_malloc (ntohs(message->size)); 527 blctx->msg = GNUNET_malloc (ntohs(message->size));
488 memcpy (blctx->msg, message, ntohs(message->size)); 528 memcpy (blctx->msg,
489 GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, blctx); 529 message,
490 if (NULL != (blc = GST_blacklist_test_allowed (&address->peer, NULL, 530 ntohs (message->size));
491 &connect_bl_check_cont, 531 GNUNET_CONTAINER_DLL_insert (bc_head,
492 blctx))) 532 bc_tail,
533 blctx);
534 if (NULL !=
535 (blc = GST_blacklist_test_allowed (&address->peer,
536 NULL,
537 &connect_bl_check_cont,
538 blctx)))
493 { 539 {
494 blctx->blc = blc; 540 blctx->blc = blc;
495 } 541 }
@@ -619,11 +665,8 @@ plugin_env_session_end (void *cls,
619 } 665 }
620 GNUNET_assert (strlen (address->transport_name) > 0); 666 GNUNET_assert (strlen (address->transport_name) > 0);
621 667
622 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 668 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
623 "Notification from plugin `%s' about terminated %s session %p from peer `%s' address `%s'\n", 669 "Notification from plugin about terminated session %p from peer `%s' address `%s'\n",
624 address->transport_name,
625 GNUNET_HELLO_address_check_option (address,
626 GNUNET_HELLO_ADDRESS_INFO_INBOUND) ? "inbound" : "outbound",
627 session, 670 session,
628 GNUNET_i2s (&address->peer), 671 GNUNET_i2s (&address->peer),
629 GST_plugins_a2s (address)); 672 GST_plugins_a2s (address));
@@ -719,6 +762,15 @@ plugin_env_session_start_bl_check_cont (void *cls,
719 kill_session (blctx->address->transport_name, 762 kill_session (blctx->address->transport_name,
720 blctx->session); 763 blctx->session);
721 } 764 }
765 else if (GNUNET_YES !=
766 GNUNET_HELLO_address_check_option (blctx->address,
767 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
768 {
769 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
770 "Informing verifier about inbound session's address `%s'\n",
771 GST_plugins_a2s (blctx->address));
772 GST_validation_handle_address (blctx->address);
773 }
722 GNUNET_HELLO_address_free (blctx->address); 774 GNUNET_HELLO_address_free (blctx->address);
723 GNUNET_free (blctx); 775 GNUNET_free (blctx);
724} 776}
@@ -754,35 +806,34 @@ plugin_env_session_start (void *cls,
754 return; 806 return;
755 } 807 }
756 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 808 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
757 "Notification from plugin `%s' about new %s session %p from peer `%s' address `%s'\n", 809 "Notification from plugin `%s' about new session %p from peer `%s' address `%s'\n",
758 address->transport_name, 810 address->transport_name,
759 GNUNET_HELLO_address_check_option (address,
760 GNUNET_HELLO_ADDRESS_INFO_INBOUND) ? "inbound" : "outbound",
761 session, 811 session,
762 GNUNET_i2s (&address->peer), 812 GNUNET_i2s (&address->peer),
763 GST_plugins_a2s (address)); 813 GST_plugins_a2s (address));
764 if ( (GNUNET_YES == 814 if (GNUNET_YES ==
765 GNUNET_HELLO_address_check_option (address, 815 GNUNET_HELLO_address_check_option (address,
766 GNUNET_HELLO_ADDRESS_INFO_INBOUND)) || 816 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
767 (GNUNET_NO ==
768 GST_ats_is_known (address, NULL) ) )
769 { 817 {
770 /* inbound is always new, but outbound MAY already be known, but 818 /* inbound is always new, but outbound MAY already be known, but
771 for example for UNIX, we have symmetric connections and thus we 819 for example for UNIX, we have symmetric connections and thus we
772 may not know the address yet; add if necessary! */ 820 may not know the address yet; add if necessary! */
773 GST_ats_add_address (address, 821 GST_ats_add_inbound_address (address,
774 session, 822 session,
775 ats, 823 ats,
776 ats_count); 824 ats_count);
777 } 825 }
778 else 826 else
779 { 827 {
780 GST_ats_new_session (address, 828 if (GNUNET_YES ==
781 session); 829 GST_ats_is_known (address,
782 GST_ats_update_metrics (address, 830 session))
783 session, 831 {
784 ats, 832 GST_ats_update_metrics (address,
785 ats_count); 833 session,
834 ats,
835 ats_count);
836 }
786 } 837 }
787 /* Do blacklist check if communication with this peer is allowed */ 838 /* Do blacklist check if communication with this peer is allowed */
788 blctx = GNUNET_new (struct BlacklistCheckContext); 839 blctx = GNUNET_new (struct BlacklistCheckContext);
diff --git a/src/transport/gnunet-service-transport_ats.c b/src/transport/gnunet-service-transport_ats.c
index 0b864f3fb..c3f52de91 100644
--- a/src/transport/gnunet-service-transport_ats.c
+++ b/src/transport/gnunet-service-transport_ats.c
@@ -256,6 +256,10 @@ unblock_address (void *cls,
256 struct AddressInfo *ai = cls; 256 struct AddressInfo *ai = cls;
257 257
258 ai->unblock_task = NULL; 258 ai->unblock_task = NULL;
259 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
260 "Unblocking address %s of peer %s\n",
261 GST_plugins_a2s (ai->address),
262 GNUNET_i2s (&ai->address->peer));
259 ai->ar = GNUNET_ATS_address_add (GST_ats, 263 ai->ar = GNUNET_ATS_address_add (GST_ats,
260 ai->address, 264 ai->address,
261 ai->session, 265 ai->session,
@@ -291,8 +295,26 @@ GST_ats_block_address (const struct GNUNET_HELLO_Address *address,
291 GNUNET_break (0); 295 GNUNET_break (0);
292 return; 296 return;
293 } 297 }
294 GNUNET_ATS_address_destroy (ai->ar); 298 if (GNUNET_YES ==
299 GNUNET_HELLO_address_check_option (address,
300 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
302 "Removing address %s of peer %s from use (inbound died)\n",
303 GST_plugins_a2s (address),
304 GNUNET_i2s (&address->peer));
305 else
306 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
307 "Blocking address %s of peer %s from use for a while\n",
308 GST_plugins_a2s (address),
309 GNUNET_i2s (&address->peer));
310 /* destroy session and address */
311 if ( (NULL == session) ||
312 (GNUNET_NO ==
313 GNUNET_ATS_address_del_session (ai->ar, session)) )
314 GNUNET_ATS_address_destroy (ai->ar);
295 ai->ar = NULL; 315 ai->ar = NULL;
316
317 /* determine when the address should come back to life */
296 ai->back_off = GNUNET_TIME_STD_BACKOFF (ai->back_off); 318 ai->back_off = GNUNET_TIME_STD_BACKOFF (ai->back_off);
297 ai->blocked = GNUNET_TIME_relative_to_absolute (ai->back_off); 319 ai->blocked = GNUNET_TIME_relative_to_absolute (ai->back_off);
298 ai->unblock_task = GNUNET_SCHEDULER_add_delayed (ai->back_off, 320 ai->unblock_task = GNUNET_SCHEDULER_add_delayed (ai->back_off,
@@ -302,8 +324,10 @@ GST_ats_block_address (const struct GNUNET_HELLO_Address *address,
302 324
303 325
304/** 326/**
305 * Notify ATS about the new address including the network this address is 327 * Notify ATS about the a new inbound address. We may already
306 * located in. 328 * know the address (as this is called each time we receive
329 * a message from an inbound connection). If the address is
330 * indeed new, make it available to ATS.
307 * 331 *
308 * @param address the address 332 * @param address the address
309 * @param session the session 333 * @param session the session
@@ -311,10 +335,10 @@ GST_ats_block_address (const struct GNUNET_HELLO_Address *address,
311 * @param ats_count number of @a ats information 335 * @param ats_count number of @a ats information
312 */ 336 */
313void 337void
314GST_ats_add_address (const struct GNUNET_HELLO_Address *address, 338GST_ats_add_inbound_address (const struct GNUNET_HELLO_Address *address,
315 struct Session *session, 339 struct Session *session,
316 const struct GNUNET_ATS_Information *ats, 340 const struct GNUNET_ATS_Information *ats,
317 uint32_t ats_count) 341 uint32_t ats_count)
318{ 342{
319 struct GNUNET_TRANSPORT_PluginFunctions *papi; 343 struct GNUNET_TRANSPORT_PluginFunctions *papi;
320 struct GNUNET_ATS_Information ats2[ats_count + 1]; 344 struct GNUNET_ATS_Information ats2[ats_count + 1];
@@ -328,55 +352,37 @@ GST_ats_add_address (const struct GNUNET_HELLO_Address *address,
328 GNUNET_break(0); 352 GNUNET_break(0);
329 return; 353 return;
330 } 354 }
331 if (GNUNET_YES == 355 GNUNET_assert (GNUNET_YES ==
332 GNUNET_HELLO_address_check_option (address, 356 GNUNET_HELLO_address_check_option (address,
333 GNUNET_HELLO_ADDRESS_INFO_INBOUND)) 357 GNUNET_HELLO_ADDRESS_INFO_INBOUND));
334 { 358 GNUNET_assert (NULL != session);
335 GNUNET_break (NULL != session); 359 ai = find_ai (address, session);
336 }
337 ai = (NULL == session)
338 ? find_ai_no_session (address)
339 : find_ai (address, session);
340 if (NULL != ai) 360 if (NULL != ai)
341 return;
342 if (NULL != session)
343 {
344 /* in this case, we must not find an existing
345 session-less address, as the caller should
346 have checked for this case if it were possible. */
347 ai = find_ai (address, NULL);
348 if (NULL != ai)
349 {
350 GNUNET_assert (0);
351 return;
352 }
353 }
354 if (NULL == (papi = GST_plugins_find (address->transport_name)))
355 { 361 {
356 /* we don't have the plugin for this address */ 362 /* This should only be called for new sessions, and thus
357 GNUNET_assert (0); 363 we should not already have the address */
364 GNUNET_break (0);
358 return; 365 return;
359 } 366 }
360 if (NULL != session) 367 papi = GST_plugins_find (address->transport_name);
368 GNUNET_assert (NULL != papi);
369 net = papi->get_network (papi->cls, session);
370 if (GNUNET_ATS_NET_UNSPECIFIED == net)
361 { 371 {
362 net = papi->get_network (papi->cls, session); 372 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
363 if (GNUNET_ATS_NET_UNSPECIFIED == net) 373 _("Could not obtain a valid network for `%s' %s (%s)\n"),
364 { 374 GNUNET_i2s (&address->peer),
365 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 375 GST_plugins_a2s (address),
366 _ ("Could not obtain a valid network for `%s' %s (%s)\n"), 376 address->transport_name);
367 GNUNET_i2s (&address->peer), 377 return;
368 GST_plugins_a2s (address),
369 address->transport_name);
370 return;
371 }
372 ats2[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
373 ats2[0].value = htonl (net);
374 memcpy (&ats2[1],
375 ats,
376 sizeof(struct GNUNET_ATS_Information) * ats_count);
377 } 378 }
378 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 379 ats2[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
379 "Notifying ATS about peer `%s''s new address `%s' session %p in network %s\n", 380 ats2[0].value = htonl (net);
381 memcpy (&ats2[1],
382 ats,
383 sizeof(struct GNUNET_ATS_Information) * ats_count);
384 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
385 "Notifying ATS about peer `%s''s new inbound address `%s' session %p in network %s\n",
380 GNUNET_i2s (&address->peer), 386 GNUNET_i2s (&address->peer),
381 (0 == address->address_length) 387 (0 == address->address_length)
382 ? "<inbound>" 388 ? "<inbound>"
@@ -401,6 +407,55 @@ GST_ats_add_address (const struct GNUNET_HELLO_Address *address,
401 407
402 408
403/** 409/**
410 * Notify ATS about the new address including the network this address is
411 * located in. The address must NOT be inbound and must be new to ATS.
412 *
413 * @param address the address
414 * @param ats ats information
415 * @param ats_count number of @a ats information
416 */
417void
418GST_ats_add_address (const struct GNUNET_HELLO_Address *address,
419 const struct GNUNET_ATS_Information *ats,
420 uint32_t ats_count)
421{
422 struct GNUNET_ATS_AddressRecord *ar;
423 struct AddressInfo *ai;
424
425 /* valid new address, let ATS know! */
426 if (NULL == address->transport_name)
427 {
428 GNUNET_break(0);
429 return;
430 }
431 GNUNET_assert (GNUNET_YES !=
432 GNUNET_HELLO_address_check_option (address,
433 GNUNET_HELLO_ADDRESS_INFO_INBOUND));
434 ai = find_ai_no_session (address);
435 GNUNET_assert (NULL == ai);
436 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
437 "Notifying ATS about peer `%s''s new address `%s'\n",
438 GNUNET_i2s (&address->peer),
439 (0 == address->address_length)
440 ? "<inbound>"
441 : GST_plugins_a2s (address));
442 ar = GNUNET_ATS_address_add (GST_ats,
443 address,
444 NULL,
445 ats,
446 ats_count);
447 ai = GNUNET_new (struct AddressInfo);
448 ai->address = GNUNET_HELLO_address_copy (address);
449 ai->ar = ar;
450 (void) GNUNET_CONTAINER_multipeermap_put (p2a,
451 &ai->address->peer,
452 ai,
453 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
454 publish_p2a_stat_update ();
455}
456
457
458/**
404 * Notify ATS about a new session now existing for the given 459 * Notify ATS about a new session now existing for the given
405 * address. 460 * address.
406 * 461 *
@@ -477,7 +532,14 @@ GST_ats_del_session (const struct GNUNET_HELLO_Address *address,
477 GNUNET_i2s (&address->peer)); 532 GNUNET_i2s (&address->peer));
478 if (NULL == ai->ar) 533 if (NULL == ai->ar)
479 { 534 {
480 GST_ats_expire_address (address); 535 /* If ATS doesn't know about the address/session, and this
536 was an inbound session that expired, then we must forget
537 about the address as well. Otherwise, we are done as
538 we have set `ai->session` to NULL already. */
539 if (GNUNET_YES ==
540 GNUNET_HELLO_address_check_option (address,
541 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
542 GST_ats_expire_address (address);
481 return; 543 return;
482 } 544 }
483 if (GNUNET_YES == 545 if (GNUNET_YES ==
@@ -516,7 +578,6 @@ GST_ats_update_metrics (const struct GNUNET_HELLO_Address *address,
516 GNUNET_assert (GNUNET_YES != 578 GNUNET_assert (GNUNET_YES !=
517 GNUNET_HELLO_address_check_option (address, 579 GNUNET_HELLO_address_check_option (address,
518 GNUNET_HELLO_ADDRESS_INFO_INBOUND)); 580 GNUNET_HELLO_ADDRESS_INFO_INBOUND));
519
520 return; 581 return;
521 } 582 }
522 /* Call to manipulation to manipulate ATS information */ 583 /* Call to manipulation to manipulate ATS information */
@@ -541,31 +602,6 @@ GST_ats_update_metrics (const struct GNUNET_HELLO_Address *address,
541 602
542 603
543/** 604/**
544 * Notify ATS about a new session now being in use (or not).
545 *
546 * @param address the address
547 * @param session the session
548 * @param in_use #GNUNET_YES or #GNUNET_NO
549 */
550void
551GST_ats_set_in_use (const struct GNUNET_HELLO_Address *address,
552 struct Session *session,
553 int in_use)
554{
555 struct AddressInfo *ai;
556
557 ai = find_ai (address, session);
558 if (NULL == ai)
559 {
560 GNUNET_break (0);
561 return;
562 }
563 GNUNET_assert (NULL != ai->ar);
564 GNUNET_ATS_address_set_in_use (ai->ar, in_use);
565}
566
567
568/**
569 * Notify ATS that the address has expired and thus cannot 605 * Notify ATS that the address has expired and thus cannot
570 * be used any longer. This function must only be called 606 * be used any longer. This function must only be called
571 * if the corresponding session is already gone. 607 * if the corresponding session is already gone.
@@ -577,7 +613,11 @@ GST_ats_expire_address (const struct GNUNET_HELLO_Address *address)
577{ 613{
578 struct AddressInfo *ai; 614 struct AddressInfo *ai;
579 615
580 ai = find_ai (address, NULL); 616 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
617 "Address %s of peer %s expired\n",
618 GST_plugins_a2s (address),
619 GNUNET_i2s (&address->peer));
620 ai = find_ai_no_session (address);
581 if (NULL == ai) 621 if (NULL == ai)
582 { 622 {
583 GNUNET_assert (0); 623 GNUNET_assert (0);
@@ -595,7 +635,15 @@ GST_ats_expire_address (const struct GNUNET_HELLO_Address *address)
595 GNUNET_i2s (&address->peer)); 635 GNUNET_i2s (&address->peer));
596 if (NULL != ai->ar) 636 if (NULL != ai->ar)
597 { 637 {
598 GNUNET_ATS_address_destroy (ai->ar); 638 /* We usually should not have a session here when we
639 expire an address, but during shutdown a session
640 may be active while validation causes the address
641 to 'expire'. So clean up both if necessary. */
642 if ( (NULL == ai->session) ||
643 (GNUNET_NO ==
644 GNUNET_ATS_address_del_session (ai->ar,
645 ai->session)) )
646 GNUNET_ATS_address_destroy (ai->ar);
599 ai->ar = NULL; 647 ai->ar = NULL;
600 } 648 }
601 if (NULL != ai->unblock_task) 649 if (NULL != ai->unblock_task)
diff --git a/src/transport/gnunet-service-transport_ats.h b/src/transport/gnunet-service-transport_ats.h
index 53c4caa68..e2f829898 100644
--- a/src/transport/gnunet-service-transport_ats.h
+++ b/src/transport/gnunet-service-transport_ats.h
@@ -21,11 +21,6 @@
21 * @file transport/gnunet-service-transport_ats.h 21 * @file transport/gnunet-service-transport_ats.h
22 * @brief interfacing between transport and ATS service 22 * @brief interfacing between transport and ATS service
23 * @author Christian Grothoff 23 * @author Christian Grothoff
24 *
25 * FIXME:
26 * - add API to give ATS feedback about an address that was
27 * suggested but did not work out (without fully 'deleting'
28 * it forever)
29 */ 24 */
30#ifndef GNUNET_SERVICE_TRANSPORT_ATS_H 25#ifndef GNUNET_SERVICE_TRANSPORT_ATS_H
31#define GNUNET_SERVICE_TRANSPORT_ATS_H 26#define GNUNET_SERVICE_TRANSPORT_ATS_H
@@ -72,9 +67,14 @@ GST_ats_block_address (const struct GNUNET_HELLO_Address *address,
72 struct Session *session); 67 struct Session *session);
73 68
74 69
70/* FIXME: might want to add a function to reset the
71 back-off from blocking */
72
75/** 73/**
76 * Notify ATS about the new address including the network this address is 74 * Notify ATS about the a new inbound address. We may already
77 * located in. 75 * know the address (as this is called each time we receive
76 * a message from an inbound connection). If the address is
77 * indeed new, make it available to ATS.
78 * 78 *
79 * @param address the address 79 * @param address the address
80 * @param session the session 80 * @param session the session
@@ -82,35 +82,36 @@ GST_ats_block_address (const struct GNUNET_HELLO_Address *address,
82 * @param ats_count number of @a ats information 82 * @param ats_count number of @a ats information
83 */ 83 */
84void 84void
85GST_ats_add_address (const struct GNUNET_HELLO_Address *address, 85GST_ats_add_inbound_address (const struct GNUNET_HELLO_Address *address,
86 struct Session *session, 86 struct Session *session,
87 const struct GNUNET_ATS_Information *ats, 87 const struct GNUNET_ATS_Information *ats,
88 uint32_t ats_count); 88 uint32_t ats_count);
89 89
90 90
91/** 91/**
92 * Notify ATS about a new session now existing for the given 92 * Notify ATS about the new address including the network this address is
93 * address. 93 * located in. The address must NOT be inbound and must be new to ATS.
94 * 94 *
95 * @param address the address 95 * @param address the address
96 * @param session the session 96 * @param ats ats information
97 * @param ats_count number of @a ats information
97 */ 98 */
98void 99void
99GST_ats_new_session (const struct GNUNET_HELLO_Address *address, 100GST_ats_add_address (const struct GNUNET_HELLO_Address *address,
100 struct Session *session); 101 const struct GNUNET_ATS_Information *ats,
102 uint32_t ats_count);
101 103
102 104
103/** 105/**
104 * Notify ATS about a new session now being in use (or not). 106 * Notify ATS about a new session now existing for the given
107 * address.
105 * 108 *
106 * @param address the address 109 * @param address the address
107 * @param session the session 110 * @param session the session
108 * @param in_use #GNUNET_YES or #GNUNET_NO
109 */ 111 */
110void 112void
111GST_ats_set_in_use (const struct GNUNET_HELLO_Address *address, 113GST_ats_new_session (const struct GNUNET_HELLO_Address *address,
112 struct Session *session, 114 struct Session *session);
113 int in_use);
114 115
115 116
116/** 117/**
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index bd9257db3..ca4fa7824 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -38,7 +38,6 @@
38#include "transport.h" 38#include "transport.h"
39 39
40 40
41
42/** 41/**
43 * Size of the neighbour hash map. 42 * Size of the neighbour hash map.
44 */ 43 */
@@ -509,11 +508,14 @@ static unsigned long long bytes_in_send_queue;
509/** 508/**
510 * Task transmitting utilization data 509 * Task transmitting utilization data
511 */ 510 */
512static struct GNUNET_SCHEDULER_Task * util_transmission_tk; 511static struct GNUNET_SCHEDULER_Task *util_transmission_tk;
513 512
514 513
515/** 514/**
516 * FIXME 515 * Convert the given ACK state to a string.
516 *
517 * @param s state
518 * @return corresponding human-readable string
517 */ 519 */
518static char * 520static char *
519print_ack_state (enum GST_ACK_State s) 521print_ack_state (enum GST_ACK_State s)
@@ -617,7 +619,6 @@ neighbours_changed_notification (const struct GNUNET_PeerIdentity *peer,
617} 619}
618 620
619 621
620
621/** 622/**
622 * Lookup a neighbour entry in the neighbours hash map. 623 * Lookup a neighbour entry in the neighbours hash map.
623 * 624 *
@@ -662,7 +663,8 @@ send_outbound_quota (const struct GNUNET_PeerIdentity *target,
662 663
663 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 664 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
664 "Sending outbound quota of %u Bps for peer `%s' to all clients\n", 665 "Sending outbound quota of %u Bps for peer `%s' to all clients\n",
665 ntohl (quota.value__), GNUNET_i2s (target)); 666 ntohl (quota.value__),
667 GNUNET_i2s (target));
666 q_msg.header.size = htons (sizeof (struct QuotaSetMessage)); 668 q_msg.header.size = htons (sizeof (struct QuotaSetMessage));
667 q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA); 669 q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA);
668 q_msg.quota = quota; 670 q_msg.quota = quota;
@@ -682,49 +684,34 @@ static void
682free_address (struct NeighbourAddress *na) 684free_address (struct NeighbourAddress *na)
683{ 685{
684 if (GNUNET_YES == na->ats_active) 686 if (GNUNET_YES == na->ats_active)
685 {
686 GST_validation_set_address_use (na->address, 687 GST_validation_set_address_use (na->address,
687 GNUNET_NO); 688 GNUNET_NO);
688 GST_ats_set_in_use (na->address,
689 na->session,
690 GNUNET_NO);
691 }
692
693 na->bandwidth_in = GNUNET_BANDWIDTH_value_init (0);
694 na->bandwidth_out = GNUNET_BANDWIDTH_value_init (0);
695 na->ats_active = GNUNET_NO;
696 na->keep_alive_nonce = 0;
697 if (NULL != na->address) 689 if (NULL != na->address)
698 { 690 {
691 GST_ats_block_address (na->address,
692 na->session);
699 GNUNET_HELLO_address_free (na->address); 693 GNUNET_HELLO_address_free (na->address);
700 na->address = NULL; 694 na->address = NULL;
701 } 695 }
696 na->bandwidth_in = GNUNET_BANDWIDTH_value_init (0);
697 na->bandwidth_out = GNUNET_BANDWIDTH_value_init (0);
698 na->ats_active = GNUNET_NO;
699 na->keep_alive_nonce = 0;
702 na->session = NULL; 700 na->session = NULL;
703} 701}
704 702
705 703
706/** 704/**
707 * Set net state for this neighbour and notify monitoring 705 * Master task run for every neighbour. Performs all of the time-related
706 * activities (keep alive, send next message, disconnect if idle, finish
707 * clean up after disconnect).
708 * 708 *
709 * @param n the respective neighbour 709 * @param cls the `struct NeighbourMapEntry` for which we are running
710 * @param s the new state 710 * @param tc scheduler context (unused)
711 */ 711 */
712static void 712static void
713set_state (struct NeighbourMapEntry *n, 713master_task (void *cls,
714 enum GNUNET_TRANSPORT_PeerState s) 714 const struct GNUNET_SCHEDULER_TaskContext *tc);
715{
716 n->state = s;
717 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
718 "Neighbour `%s' changed state to %s\n",
719 GNUNET_i2s (&n->id),
720 GNUNET_TRANSPORT_ps2s(s));
721 neighbours_changed_notification (&n->id,
722 n->primary_address.address,
723 n->state,
724 n->timeout,
725 n->primary_address.bandwidth_in,
726 n->primary_address.bandwidth_out);
727}
728 715
729 716
730/** 717/**
@@ -739,7 +726,36 @@ set_state_and_timeout (struct NeighbourMapEntry *n,
739 enum GNUNET_TRANSPORT_PeerState s, 726 enum GNUNET_TRANSPORT_PeerState s,
740 struct GNUNET_TIME_Absolute timeout) 727 struct GNUNET_TIME_Absolute timeout)
741{ 728{
729 if (GNUNET_TRANSPORT_is_connected (s) &&
730 ! GNUNET_TRANSPORT_is_connected (n->state) )
731 {
732 neighbours_connect_notification (&n->id,
733 n->primary_address.bandwidth_in,
734 n->primary_address.bandwidth_out);
735 GNUNET_STATISTICS_set (GST_stats,
736 gettext_noop ("# peers connected"),
737 ++neighbours_connected,
738 GNUNET_NO);
739 }
740 if (! GNUNET_TRANSPORT_is_connected (s) &&
741 GNUNET_TRANSPORT_is_connected (n->state) )
742 {
743 GNUNET_STATISTICS_set (GST_stats,
744 gettext_noop ("# peers connected"),
745 --neighbours_connected,
746 GNUNET_NO);
747 neighbours_disconnect_notification (&n->id);
748 }
742 n->state = s; 749 n->state = s;
750 if ( (timeout.abs_value_us < n->timeout.abs_value_us) &&
751 (NULL != n->task ) )
752 {
753 /* new timeout is earlier, reschedule master task */
754 GNUNET_SCHEDULER_cancel (n->task);
755 n->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (timeout),
756 &master_task,
757 n);
758 }
743 n->timeout = timeout; 759 n->timeout = timeout;
744 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 760 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
745 "Neighbour `%s' changed state to %s with timeout %s\n", 761 "Neighbour `%s' changed state to %s with timeout %s\n",
@@ -756,29 +772,6 @@ set_state_and_timeout (struct NeighbourMapEntry *n,
756 772
757 773
758/** 774/**
759 * Set new state timeout for this neighbour and notify monitoring
760 *
761 * @param n the respective neighbour
762 * @param timeout the new timeout
763 */
764static void
765set_timeout (struct NeighbourMapEntry *n,
766 struct GNUNET_TIME_Absolute timeout)
767{
768 n->timeout = timeout;
769 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
770 "Neighbour `%s' changed timeout %s\n",
771 GNUNET_i2s (&n->id),
772 GNUNET_STRINGS_absolute_time_to_string (timeout));
773 neighbours_changed_notification (&n->id,
774 n->primary_address.address,
775 n->state, n->timeout,
776 n->primary_address.bandwidth_in,
777 n->primary_address.bandwidth_out);
778}
779
780
781/**
782 * Initialize the alternative address of a neighbour 775 * Initialize the alternative address of a neighbour
783 * 776 *
784 * @param n the neighbour 777 * @param n the neighbour
@@ -809,9 +802,15 @@ set_alternative_address (struct NeighbourMapEntry *n,
809 n->alternative_address.bandwidth_out = bandwidth_out; 802 n->alternative_address.bandwidth_out = bandwidth_out;
810 return; 803 return;
811 } 804 }
812 free_address (&n->alternative_address); 805 if (NULL != n->alternative_address.address)
806 {
807 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
808 "Replacing existing alternative address with another one\n");
809 free_address (&n->alternative_address);
810 }
813 if (NULL == session) 811 if (NULL == session)
814 session = papi->get_session (papi->cls, address); 812 session = papi->get_session (papi->cls,
813 address);
815 if (NULL == session) 814 if (NULL == session)
816 { 815 {
817 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 816 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -824,7 +823,8 @@ set_alternative_address (struct NeighbourMapEntry *n,
824 GNUNET_NO); 823 GNUNET_NO);
825 return; 824 return;
826 } 825 }
827 GST_ats_new_session (address, session); 826 GST_ats_new_session (address,
827 session);
828 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 828 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
829 "Neighbour `%s' configured alternative address %s\n", 829 "Neighbour `%s' configured alternative address %s\n",
830 GNUNET_i2s (&n->id), 830 GNUNET_i2s (&n->id),
@@ -859,48 +859,50 @@ set_primary_address (struct NeighbourMapEntry *n,
859 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 859 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
860 int is_active) 860 int is_active)
861{ 861{
862 struct GNUNET_TRANSPORT_PluginFunctions *papi;
863
864 if (NULL == (papi = GST_plugins_find (address->transport_name)))
865 {
866 GNUNET_break (0);
867 return;
868 }
869 if (session == n->primary_address.session) 862 if (session == n->primary_address.session)
870 { 863 {
871 n->primary_address.bandwidth_in = bandwidth_in;
872 n->primary_address.bandwidth_out = bandwidth_out;
873 if (is_active != n->primary_address.ats_active) 864 if (is_active != n->primary_address.ats_active)
874 { 865 {
875 n->primary_address.ats_active = is_active; 866 n->primary_address.ats_active = is_active;
876 GST_ats_set_in_use (n->primary_address.address,
877 n->primary_address.session,
878 is_active);
879 GST_validation_set_address_use (n->primary_address.address, 867 GST_validation_set_address_use (n->primary_address.address,
880 is_active); 868 is_active);
881 } 869 }
882 if (GNUNET_YES == is_active) 870 if (GNUNET_YES == is_active)
883 { 871 {
884 GST_neighbours_set_incoming_quota (&address->peer, bandwidth_in); 872 if (n->primary_address.bandwidth_in.value__ != bandwidth_in.value__)
885 send_outbound_quota (&address->peer, bandwidth_out); 873 {
874 n->primary_address.bandwidth_in = bandwidth_in;
875 GST_neighbours_set_incoming_quota (&address->peer, bandwidth_in);
876 }
877 if (n->primary_address.bandwidth_out.value__ != bandwidth_out.value__)
878 {
879 n->primary_address.bandwidth_out = bandwidth_out;
880 send_outbound_quota (&address->peer,
881 bandwidth_out);
882 }
886 } 883 }
887 return; 884 return;
888 } 885 }
889 free_address (&n->primary_address); 886 if ( (NULL != n->primary_address.address) &&
890 if (NULL == session) 887 (0 == GNUNET_HELLO_address_cmp (address,
891 session = papi->get_session (papi->cls, address); 888 n->primary_address.address)) )
889 {
890 GNUNET_break (0);
891 return;
892 }
892 if (NULL == session) 893 if (NULL == session)
893 { 894 {
894 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 895 GNUNET_break (0);
895 "Failed to obtain new session for peer `%s' and address '%s'\n", 896 GST_ats_block_address (address,
896 GNUNET_i2s (&address->peer), GST_plugins_a2s (address)); 897 session);
897 GNUNET_STATISTICS_update (GST_stats,
898 gettext_noop ("# session creation failed"),
899 1,
900 GNUNET_NO);
901 return; 898 return;
902 } 899 }
903 GST_ats_new_session (address, session); 900 if (NULL != n->primary_address.address)
901 {
902 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
903 "Replacing existing primary address with another one\n");
904 free_address (&n->primary_address);
905 }
904 n->primary_address.address = GNUNET_HELLO_address_copy (address); 906 n->primary_address.address = GNUNET_HELLO_address_copy (address);
905 n->primary_address.bandwidth_in = bandwidth_in; 907 n->primary_address.bandwidth_in = bandwidth_in;
906 n->primary_address.bandwidth_out = bandwidth_out; 908 n->primary_address.bandwidth_out = bandwidth_out;
@@ -909,14 +911,12 @@ set_primary_address (struct NeighbourMapEntry *n,
909 n->primary_address.keep_alive_nonce = 0; 911 n->primary_address.keep_alive_nonce = 0;
910 if (GNUNET_YES == is_active) 912 if (GNUNET_YES == is_active)
911 { 913 {
912 /* Telling ATS about new session */ 914 /* subsystems about address use */
913 GST_ats_set_in_use (n->primary_address.address,
914 n->primary_address.session,
915 GNUNET_YES);
916 GST_validation_set_address_use (n->primary_address.address, 915 GST_validation_set_address_use (n->primary_address.address,
917 GNUNET_YES); 916 GNUNET_YES);
918 GST_neighbours_set_incoming_quota (&address->peer, bandwidth_in); 917 GST_neighbours_set_incoming_quota (&address->peer, bandwidth_in);
919 send_outbound_quota (&address->peer, bandwidth_out); 918 send_outbound_quota (&address->peer,
919 bandwidth_out);
920 } 920 }
921 921
922 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 922 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -943,32 +943,21 @@ static void
943unset_primary_address (struct NeighbourMapEntry *n) 943unset_primary_address (struct NeighbourMapEntry *n)
944{ 944{
945 /* Notify monitoring about change */ 945 /* Notify monitoring about change */
946 if (NULL == n->primary_address.address)
947 return;
948 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
949 "Disabling primary address\n");
946 neighbours_changed_notification (&n->id, 950 neighbours_changed_notification (&n->id,
947 n->primary_address.address, 951 n->primary_address.address,
948 n->state, 952 n->state,
949 n->timeout, 953 n->timeout,
950 GNUNET_BANDWIDTH_value_init (0), 954 GNUNET_BANDWIDTH_value_init (0),
951 GNUNET_BANDWIDTH_value_init (0)); 955 GNUNET_BANDWIDTH_value_init (0));
952 /* Unset primary address */
953 free_address (&n->primary_address); 956 free_address (&n->primary_address);
954} 957}
955 958
956 959
957/** 960/**
958 * Clear the alternative address of a neighbour since this address is not
959 * valid anymore
960 *
961 * @param n the neighbour
962 */
963static void
964unset_alternative_address (struct NeighbourMapEntry *n)
965{
966 /* Unset primary address */
967 free_address (&n->alternative_address);
968}
969
970
971/**
972 * Free a neighbour map entry. 961 * Free a neighbour map entry.
973 * 962 *
974 * @param n entry to free 963 * @param n entry to free
@@ -986,29 +975,29 @@ free_neighbour (struct NeighbourMapEntry *n)
986 /* fail messages currently in the queue */ 975 /* fail messages currently in the queue */
987 while (NULL != (mq = n->messages_head)) 976 while (NULL != (mq = n->messages_head))
988 { 977 {
989 GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq); 978 GNUNET_CONTAINER_DLL_remove (n->messages_head,
979 n->messages_tail,
980 mq);
990 if (NULL != mq->cont) 981 if (NULL != mq->cont)
991 mq->cont (mq->cont_cls, GNUNET_SYSERR, mq->message_buf_size, 0); 982 mq->cont (mq->cont_cls,
983 GNUNET_SYSERR,
984 mq->message_buf_size,
985 0);
992 GNUNET_free (mq); 986 GNUNET_free (mq);
993 } 987 }
994 /* It is too late to send other peer disconnect notifications, but at
995 least internally we need to get clean... */
996 if (GNUNET_YES == test_connected (n))
997 {
998 GNUNET_STATISTICS_set (GST_stats,
999 gettext_noop ("# peers connected"),
1000 --neighbours_connected,
1001 GNUNET_NO);
1002 neighbours_disconnect_notification (&n->id);
1003 }
1004
1005 /* Mark peer as disconnected */ 988 /* Mark peer as disconnected */
1006 set_state (n, GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED); 989 set_state_and_timeout (n,
1007 990 GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED,
991 GNUNET_TIME_UNIT_FOREVER_ABS);
1008 /* free addresses and mark as unused */ 992 /* free addresses and mark as unused */
1009 unset_primary_address (n); 993 unset_primary_address (n);
1010 free_address (&n->alternative_address);
1011 994
995 if (NULL != n->alternative_address.address)
996 {
997 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
998 "Cleaning up alternative address\n");
999 free_address (&n->alternative_address);
1000 }
1012 GNUNET_assert (GNUNET_YES == 1001 GNUNET_assert (GNUNET_YES ==
1013 GNUNET_CONTAINER_multipeermap_remove (neighbours, 1002 GNUNET_CONTAINER_multipeermap_remove (neighbours,
1014 &n->id, n)); 1003 &n->id, n));
@@ -1056,7 +1045,8 @@ free_neighbour (struct NeighbourMapEntry *n)
1056 */ 1045 */
1057static struct GNUNET_TIME_Relative 1046static struct GNUNET_TIME_Relative
1058send_with_session (struct NeighbourMapEntry *n, 1047send_with_session (struct NeighbourMapEntry *n,
1059 const char *msgbuf, size_t msgbuf_size, 1048 const void *msgbuf,
1049 size_t msgbuf_size,
1060 uint32_t priority, 1050 uint32_t priority,
1061 struct GNUNET_TIME_Relative timeout, 1051 struct GNUNET_TIME_Relative timeout,
1062 unsigned int use_keepalive_timeout, 1052 unsigned int use_keepalive_timeout,
@@ -1070,14 +1060,20 @@ send_with_session (struct NeighbourMapEntry *n,
1070 if ( ((NULL == (papi = GST_plugins_find (n->primary_address.address->transport_name)) || 1060 if ( ((NULL == (papi = GST_plugins_find (n->primary_address.address->transport_name)) ||
1071 (-1 == papi->send (papi->cls, 1061 (-1 == papi->send (papi->cls,
1072 n->primary_address.session, 1062 n->primary_address.session,
1073 msgbuf, msgbuf_size, 1063 msgbuf,
1064 msgbuf_size,
1074 priority, 1065 priority,
1075 (result = (GNUNET_NO == use_keepalive_timeout) ? timeout : 1066 (result = (GNUNET_NO == use_keepalive_timeout) ? timeout :
1076 GNUNET_TIME_relative_divide (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 1067 GNUNET_TIME_relative_divide (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1077 papi->query_keepalive_factor (papi->cls))), 1068 papi->query_keepalive_factor (papi->cls))),
1078 cont, cont_cls)))) && 1069 cont,
1070 cont_cls)))) &&
1079 (NULL != cont)) 1071 (NULL != cont))
1080 cont (cont_cls, &n->id, GNUNET_SYSERR, msgbuf_size, 0); 1072 cont (cont_cls,
1073 &n->id,
1074 GNUNET_SYSERR,
1075 msgbuf_size,
1076 0);
1081 GST_neighbours_notify_data_sent (n->primary_address.address, 1077 GST_neighbours_notify_data_sent (n->primary_address.address,
1082 n->primary_address.session, 1078 n->primary_address.session,
1083 msgbuf_size); 1079 msgbuf_size);
@@ -1087,19 +1083,6 @@ send_with_session (struct NeighbourMapEntry *n,
1087 1083
1088 1084
1089/** 1085/**
1090 * Master task run for every neighbour. Performs all of the time-related
1091 * activities (keep alive, send next message, disconnect if idle, finish
1092 * clean up after disconnect).
1093 *
1094 * @param cls the `struct NeighbourMapEntry` for which we are running
1095 * @param tc scheduler context (unused)
1096 */
1097static void
1098master_task (void *cls,
1099 const struct GNUNET_SCHEDULER_TaskContext *tc);
1100
1101
1102/**
1103 * Function called when the 'DISCONNECT' message has been sent by the 1086 * Function called when the 'DISCONNECT' message has been sent by the
1104 * plugin. Frees the neighbour --- if the entry still exists. 1087 * plugin. Frees the neighbour --- if the entry still exists.
1105 * 1088 *
@@ -1107,11 +1090,14 @@ master_task (void *cls,
1107 * @param target identity of the neighbour that was disconnected 1090 * @param target identity of the neighbour that was disconnected
1108 * @param result #GNUNET_OK if the disconnect got out successfully 1091 * @param result #GNUNET_OK if the disconnect got out successfully
1109 * @param payload bytes payload 1092 * @param payload bytes payload
1110 * @param physical bytes physical 1093 * @param physical bytes on wire
1111 */ 1094 */
1112static void 1095static void
1113send_disconnect_cont (void *cls, const struct GNUNET_PeerIdentity *target, 1096send_disconnect_cont (void *cls,
1114 int result, size_t payload, size_t physical) 1097 const struct GNUNET_PeerIdentity *target,
1098 int result,
1099 size_t payload,
1100 size_t physical)
1115{ 1101{
1116 struct NeighbourMapEntry *n; 1102 struct NeighbourMapEntry *n;
1117 1103
@@ -1157,12 +1143,17 @@ send_disconnect (struct NeighbourMapEntry *n)
1157 &disconnect_msg.purpose, 1143 &disconnect_msg.purpose,
1158 &disconnect_msg.signature)); 1144 &disconnect_msg.signature));
1159 1145
1160 (void) send_with_session (n, (const char *) &disconnect_msg, 1146 (void) send_with_session (n,
1161 sizeof (disconnect_msg), UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, 1147 &disconnect_msg,
1162 GNUNET_NO, &send_disconnect_cont, NULL ); 1148 sizeof (disconnect_msg),
1149 UINT32_MAX,
1150 GNUNET_TIME_UNIT_FOREVER_REL,
1151 GNUNET_NO,
1152 &send_disconnect_cont,
1153 NULL);
1163 GNUNET_STATISTICS_update (GST_stats, 1154 GNUNET_STATISTICS_update (GST_stats,
1164 gettext_noop 1155 gettext_noop ("# DISCONNECT messages sent"),
1165 ("# DISCONNECT messages sent"), 1, 1156 1,
1166 GNUNET_NO); 1157 GNUNET_NO);
1167} 1158}
1168 1159
@@ -1190,7 +1181,9 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
1190 return; 1181 return;
1191 case GNUNET_TRANSPORT_PS_SYN_SENT: 1182 case GNUNET_TRANSPORT_PS_SYN_SENT:
1192 send_disconnect (n); 1183 send_disconnect (n);
1193 set_state (n, GNUNET_TRANSPORT_PS_DISCONNECT); 1184 set_state_and_timeout (n,
1185 GNUNET_TRANSPORT_PS_DISCONNECT,
1186 GNUNET_TIME_UNIT_FOREVER_ABS);
1194 break; 1187 break;
1195 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: 1188 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
1196 /* we never ACK'ed the other peer's request, no need to send DISCONNECT */ 1189 /* we never ACK'ed the other peer's request, no need to send DISCONNECT */
@@ -1199,7 +1192,9 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
1199 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: 1192 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
1200 /* we DID ACK the other peer's request, must send DISCONNECT */ 1193 /* we DID ACK the other peer's request, must send DISCONNECT */
1201 send_disconnect (n); 1194 send_disconnect (n);
1202 set_state (n, GNUNET_TRANSPORT_PS_DISCONNECT); 1195 set_state_and_timeout (n,
1196 GNUNET_TRANSPORT_PS_DISCONNECT,
1197 GNUNET_TIME_UNIT_FOREVER_ABS);
1203 break; 1198 break;
1204 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: 1199 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
1205 case GNUNET_TRANSPORT_PS_CONNECTED: 1200 case GNUNET_TRANSPORT_PS_CONNECTED:
@@ -1207,12 +1202,9 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
1207 /* we are currently connected, need to send disconnect and do 1202 /* we are currently connected, need to send disconnect and do
1208 internal notifications and update statistics */ 1203 internal notifications and update statistics */
1209 send_disconnect (n); 1204 send_disconnect (n);
1210 GNUNET_STATISTICS_set (GST_stats, 1205 set_state_and_timeout (n,
1211 gettext_noop ("# peers connected"), 1206 GNUNET_TRANSPORT_PS_DISCONNECT,
1212 --neighbours_connected, 1207 GNUNET_TIME_UNIT_FOREVER_ABS);
1213 GNUNET_NO);
1214 neighbours_disconnect_notification (&n->id);
1215 set_state (n, GNUNET_TRANSPORT_PS_DISCONNECT);
1216 break; 1208 break;
1217 case GNUNET_TRANSPORT_PS_RECONNECT_ATS: 1209 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
1218 /* Disconnecting while waiting for an ATS address to reconnect, 1210 /* Disconnecting while waiting for an ATS address to reconnect,
@@ -1237,7 +1229,8 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
1237 if (NULL != n->task) 1229 if (NULL != n->task)
1238 GNUNET_SCHEDULER_cancel (n->task); 1230 GNUNET_SCHEDULER_cancel (n->task);
1239 n->task = GNUNET_SCHEDULER_add_delayed (DISCONNECT_SENT_TIMEOUT, 1231 n->task = GNUNET_SCHEDULER_add_delayed (DISCONNECT_SENT_TIMEOUT,
1240 &master_task, n); 1232 &master_task,
1233 n);
1241} 1234}
1242 1235
1243 1236
@@ -1276,9 +1269,11 @@ transmit_send_continuation (void *cls,
1276 { 1269 {
1277 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1270 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1278 "Bytes_in_send_queue `%u', Message_size %u, result: %s, payload %u, on wire %u\n", 1271 "Bytes_in_send_queue `%u', Message_size %u, result: %s, payload %u, on wire %u\n",
1279 bytes_in_send_queue, mq->message_buf_size, 1272 bytes_in_send_queue,
1273 mq->message_buf_size,
1280 (GNUNET_OK == success) ? "OK" : "FAIL", 1274 (GNUNET_OK == success) ? "OK" : "FAIL",
1281 size_payload, physical); 1275 size_payload,
1276 physical);
1282 GNUNET_break (0); 1277 GNUNET_break (0);
1283 } 1278 }
1284 1279
@@ -1357,28 +1352,35 @@ try_transmission_to_peer (struct NeighbourMapEntry *n)
1357 gettext_noop 1352 gettext_noop
1358 ("# messages timed out while in transport queue"), 1353 ("# messages timed out while in transport queue"),
1359 1, GNUNET_NO); 1354 1, GNUNET_NO);
1360 GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq); 1355 GNUNET_CONTAINER_DLL_remove (n->messages_head,
1356 n->messages_tail,
1357 mq);
1361 n->is_active = mq; 1358 n->is_active = mq;
1362 transmit_send_continuation (mq, &n->id, 1359 transmit_send_continuation (mq,
1360 &n->id,
1363 GNUNET_SYSERR, 1361 GNUNET_SYSERR,
1364 mq->message_buf_size, 0); /* timeout */ 1362 mq->message_buf_size,
1363 0); /* timeout */
1365 } 1364 }
1366 if (NULL == mq) 1365 if (NULL == mq)
1367 return; /* no more messages */ 1366 return; /* no more messages */
1368 GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq); 1367 GNUNET_CONTAINER_DLL_remove (n->messages_head,
1368 n->messages_tail,
1369 mq);
1369 n->is_active = mq; 1370 n->is_active = mq;
1370 1371
1371 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1372 "Giving message with %u bytes to plugin session %p\n", 1373 "Giving message with %u bytes to plugin session %p\n",
1373 mq->message_buf_size, n->primary_address.session); 1374 mq->message_buf_size,
1374 1375 n->primary_address.session);
1375 (void) send_with_session (n, 1376 (void) send_with_session (n,
1376 mq->message_buf, 1377 mq->message_buf,
1377 mq->message_buf_size, 1378 mq->message_buf_size,
1378 0 /* priority */, 1379 0 /* priority */,
1379 timeout, 1380 timeout,
1380 GNUNET_NO, 1381 GNUNET_NO,
1381 &transmit_send_continuation, mq); 1382 &transmit_send_continuation,
1383 mq);
1382} 1384}
1383 1385
1384 1386
@@ -1398,7 +1400,7 @@ send_keepalive (struct NeighbourMapEntry *n)
1398 uint32_t nonce; 1400 uint32_t nonce;
1399 1401
1400 GNUNET_assert ((GNUNET_TRANSPORT_PS_CONNECTED == n->state) || 1402 GNUNET_assert ((GNUNET_TRANSPORT_PS_CONNECTED == n->state) ||
1401 (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT)); 1403 (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state));
1402 if (GNUNET_TIME_absolute_get_remaining (n->keep_alive_time).rel_value_us > 0) 1404 if (GNUNET_TIME_absolute_get_remaining (n->keep_alive_time).rel_value_us > 0)
1403 return; /* no keepalive needed at this time */ 1405 return; /* no keepalive needed at this time */
1404 1406
@@ -1407,25 +1409,28 @@ send_keepalive (struct NeighbourMapEntry *n)
1407 nonce = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); 1409 nonce = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
1408 1410
1409 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1411 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1410 "Sending keep alive to peer `%s' with nonce %u\n", 1412 "Sending keep alive to peer `%s' with nonce %u\n",
1411 GNUNET_i2s (&n->id), nonce); 1413 GNUNET_i2s (&n->id),
1412 1414 nonce);
1413 m.header.size = htons (sizeof (struct SessionKeepAliveMessage)); 1415 m.header.size = htons (sizeof (struct SessionKeepAliveMessage));
1414 m.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE); 1416 m.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE);
1415 m.nonce = htonl (nonce); 1417 m.nonce = htonl (nonce);
1416 1418
1417 timeout = send_with_session (n, 1419 timeout = send_with_session (n,
1418 (const void *) &m, sizeof (m), 1420 &m,
1421 sizeof (m),
1419 UINT32_MAX /* priority */, 1422 UINT32_MAX /* priority */,
1420 GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, 1423 GNUNET_TIME_UNIT_FOREVER_REL,
1424 GNUNET_YES,
1421 NULL, NULL); 1425 NULL, NULL);
1422 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# keepalives sent"), 1, 1426 GNUNET_STATISTICS_update (GST_stats,
1427 gettext_noop ("# keepalives sent"),
1428 1,
1423 GNUNET_NO); 1429 GNUNET_NO);
1424 n->primary_address.keep_alive_nonce = nonce; 1430 n->primary_address.keep_alive_nonce = nonce;
1425 n->expect_latency_response = GNUNET_YES; 1431 n->expect_latency_response = GNUNET_YES;
1426 n->last_keep_alive_time = GNUNET_TIME_absolute_get (); 1432 n->last_keep_alive_time = GNUNET_TIME_absolute_get ();
1427 n->keep_alive_time = GNUNET_TIME_relative_to_absolute (timeout); 1433 n->keep_alive_time = GNUNET_TIME_relative_to_absolute (timeout);
1428
1429} 1434}
1430 1435
1431 1436
@@ -1473,11 +1478,13 @@ GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour,
1473 msg.header.size = htons (sizeof (struct SessionKeepAliveMessage)); 1478 msg.header.size = htons (sizeof (struct SessionKeepAliveMessage));
1474 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE); 1479 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE);
1475 msg.nonce = msg_in->nonce; 1480 msg.nonce = msg_in->nonce;
1476 (void) send_with_session(n, 1481 (void) send_with_session (n,
1477 (const void *) &msg, sizeof (struct SessionKeepAliveMessage), 1482 &msg,
1478 UINT32_MAX /* priority */, 1483 sizeof (struct SessionKeepAliveMessage),
1479 GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, 1484 UINT32_MAX /* priority */,
1480 NULL, NULL); 1485 GNUNET_TIME_UNIT_FOREVER_REL,
1486 GNUNET_YES,
1487 NULL, NULL);
1481} 1488}
1482 1489
1483 1490
@@ -1559,7 +1566,9 @@ GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour,
1559 1566
1560 n->primary_address.keep_alive_nonce = 0; 1567 n->primary_address.keep_alive_nonce = 0;
1561 n->expect_latency_response = GNUNET_NO; 1568 n->expect_latency_response = GNUNET_NO;
1562 set_timeout (n, GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); 1569 set_state_and_timeout (n,
1570 n->state,
1571 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
1563 1572
1564 latency = GNUNET_TIME_absolute_get_duration (n->last_keep_alive_time); 1573 latency = GNUNET_TIME_absolute_get_duration (n->last_keep_alive_time);
1565 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1574 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1653,9 +1662,8 @@ GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity
1653 if (ret.rel_value_us > 0) 1662 if (ret.rel_value_us > 0)
1654 { 1663 {
1655 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1664 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1656 "Throttling read (%llu bytes excess at %u b/s), waiting %s before reading more.\n", 1665 "Throttling read (%lld bytes excess at %u b/s), waiting %s before reading more.\n",
1657 (unsigned long long) n->in_tracker. 1666 (long long) n->in_tracker.consumption_since_last_update__,
1658 consumption_since_last_update__,
1659 (unsigned int) n->in_tracker.available_bytes_per_s__, 1667 (unsigned int) n->in_tracker.available_bytes_per_s__,
1660 GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES)); 1668 GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES));
1661 GNUNET_STATISTICS_update (GST_stats, 1669 GNUNET_STATISTICS_update (GST_stats,
@@ -1728,14 +1736,23 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
1728 1736
1729 1737
1730/** 1738/**
1731 * FIXME 1739 * Continuation called from our attempt to transmitted our
1740 * #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN to the specified @a
1741 * target. Continue processing based on the @a result. Specifically,
1742 * if we failed to transmit, discard the address we used.
1743 *
1744 * @param cls NULL
1745 * @param target which peer received the transmission
1746 * @param result #GNUNET_OK if sending worked
1747 * @param size_payload how many bytes of payload were sent (ignored)
1748 * @param size_on_wire how much bandwidth was consumed on the wire (ignored)
1732 */ 1749 */
1733static void 1750static void
1734send_session_connect_cont (void *cls, 1751send_session_syn_cont (void *cls,
1735 const struct GNUNET_PeerIdentity *target, 1752 const struct GNUNET_PeerIdentity *target,
1736 int result, 1753 int result,
1737 size_t size_payload, 1754 size_t size_payload,
1738 size_t size_on_wire) 1755 size_t size_on_wire)
1739{ 1756{
1740 struct NeighbourMapEntry *n; 1757 struct NeighbourMapEntry *n;
1741 1758
@@ -1761,31 +1778,35 @@ send_session_connect_cont (void *cls,
1761 return; 1778 return;
1762 1779
1763 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1780 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1764 _("Failed to send SYN message to peer `%s' using address `%s' session %p\n"), 1781 _("Failed to send SYN message to peer `%s'\n"),
1765 GNUNET_i2s (target), 1782 GNUNET_i2s (target));
1766 GST_plugins_a2s (n->primary_address.address),
1767 n->primary_address.session);
1768
1769 switch (n->state) { 1783 switch (n->state) {
1770 case GNUNET_TRANSPORT_PS_SYN_SENT: 1784 case GNUNET_TRANSPORT_PS_SYN_SENT:
1771 /* Remove address and request an additional one */ 1785 /* Remove address and request an additional one */
1772 unset_primary_address (n); 1786 unset_primary_address (n);
1773 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_INIT_ATS, 1787 set_state_and_timeout (n,
1788 GNUNET_TRANSPORT_PS_INIT_ATS,
1774 GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT)); 1789 GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT));
1775 break; 1790 break;
1776 case GNUNET_TRANSPORT_PS_RECONNECT_SENT: 1791 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
1777 /* Remove address and request an additional one */ 1792 /* Remove address and request an additional one */
1778 unset_primary_address (n); 1793 unset_primary_address (n);
1779 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_ATS, 1794 set_state_and_timeout (n,
1780 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); 1795 GNUNET_TRANSPORT_PS_RECONNECT_ATS,
1796 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
1781 break; 1797 break;
1782 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: 1798 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
1783 /* Remove address and request and go back to primary address */ 1799 /* Remove address and request and go back to primary address */
1784 GNUNET_STATISTICS_update (GST_stats, gettext_noop 1800 GNUNET_STATISTICS_update (GST_stats,
1785 ("# Failed attempts to switch addresses (failed to send SYN CONT)"), 1, GNUNET_NO); 1801 gettext_noop ("# Failed attempts to switch addresses (failed to send SYN CONT)"),
1786 unset_alternative_address (n); 1802 1,
1787 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_CONNECTED, 1803 GNUNET_NO);
1788 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); 1804 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1805 "Switch failed, cleaning up alternative address\n");
1806 free_address (&n->alternative_address);
1807 set_state_and_timeout (n,
1808 GNUNET_TRANSPORT_PS_CONNECTED,
1809 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
1789 break; 1810 break;
1790 default: 1811 default:
1791 disconnect_neighbour (n); 1812 disconnect_neighbour (n);
@@ -1793,6 +1814,7 @@ send_session_connect_cont (void *cls,
1793 } 1814 }
1794} 1815}
1795 1816
1817
1796/** 1818/**
1797 * Send a SYN message via the given address. 1819 * Send a SYN message via the given address.
1798 * 1820 *
@@ -1805,24 +1827,14 @@ send_syn (struct NeighbourAddress *na)
1805 struct TransportSynMessage connect_msg; 1827 struct TransportSynMessage connect_msg;
1806 struct NeighbourMapEntry *n; 1828 struct NeighbourMapEntry *n;
1807 1829
1830 GNUNET_assert (NULL != na->session);
1808 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1831 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1809 "Sending SYN message to peer `%s'\n", 1832 "Sending SYN message to peer `%s' at %s\n",
1810 GNUNET_i2s (&na->address->peer)); 1833 GNUNET_i2s (&na->address->peer),
1834 GST_plugins_a2s (na->address));
1811 1835
1812 if (NULL == (papi = GST_plugins_find (na->address->transport_name))) 1836 papi = GST_plugins_find (na->address->transport_name);
1813 { 1837 GNUNET_assert (NULL != papi);
1814 GNUNET_break (0);
1815 return;
1816 }
1817 if (NULL == na->session)
1818 na->session = papi->get_session (papi->cls, na->address);
1819 if (NULL == na->session)
1820 {
1821 GNUNET_break (0);
1822 return;
1823 }
1824 GST_ats_new_session (na->address,
1825 na->session);
1826 GNUNET_STATISTICS_update (GST_stats, 1838 GNUNET_STATISTICS_update (GST_stats,
1827 gettext_noop 1839 gettext_noop
1828 ("# SYN messages sent"), 1840 ("# SYN messages sent"),
@@ -1835,46 +1847,56 @@ send_syn (struct NeighbourAddress *na)
1835 if (-1 == 1847 if (-1 ==
1836 papi->send (papi->cls, 1848 papi->send (papi->cls,
1837 na->session, 1849 na->session,
1838 (const char *) &connect_msg, sizeof (struct TransportSynMessage), 1850 (const char *) &connect_msg,
1851 sizeof (struct TransportSynMessage),
1839 UINT_MAX, 1852 UINT_MAX,
1840 SETUP_CONNECTION_TIMEOUT, 1853 SETUP_CONNECTION_TIMEOUT,
1841 send_session_connect_cont, NULL)) 1854 &send_session_syn_cont, NULL))
1842 { 1855 {
1843 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1856 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1844 _("Failed to transmit SYN message via plugin to %s\n"), 1857 _("Failed to transmit SYN message to %s\n"),
1845 GST_plugins_a2s (na->address)); 1858 GST_plugins_a2s (na->address));
1846
1847 n = lookup_neighbour (&na->address->peer); 1859 n = lookup_neighbour (&na->address->peer);
1848 if (NULL == n) 1860 if (NULL == n)
1849 { 1861 {
1850 GNUNET_break (0); 1862 GNUNET_break (0);
1851 return; 1863 return;
1852 } 1864 }
1853
1854 switch (n->state) { 1865 switch (n->state) {
1855 case GNUNET_TRANSPORT_PS_SYN_SENT: 1866 case GNUNET_TRANSPORT_PS_SYN_SENT:
1856 /* Remove address and request and additional one */ 1867 /* Remove address and request and additional one */
1868 GNUNET_assert (na == &n->primary_address);
1857 unset_primary_address (n); 1869 unset_primary_address (n);
1858 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_INIT_ATS, 1870 set_state_and_timeout (n,
1859 GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT)); 1871 GNUNET_TRANSPORT_PS_INIT_ATS,
1872 GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT));
1860 /* Hard failure to send the SYN message with this address: 1873 /* Hard failure to send the SYN message with this address:
1861 Destroy address and session */ 1874 Destroy address and session */
1862 break; 1875 break;
1863 case GNUNET_TRANSPORT_PS_RECONNECT_SENT: 1876 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
1864 /* Remove address and request an additional one */ 1877 /* Remove address and request an additional one */
1878 GNUNET_assert (na == &n->primary_address);
1865 unset_primary_address (n); 1879 unset_primary_address (n);
1866 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_ATS, 1880 set_state_and_timeout (n,
1867 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); 1881 GNUNET_TRANSPORT_PS_RECONNECT_ATS,
1882 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
1868 break; 1883 break;
1869 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: 1884 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
1870 GNUNET_STATISTICS_update (GST_stats, gettext_noop 1885 GNUNET_assert (na == &n->alternative_address);
1871 ("# Failed attempts to switch addresses (failed to send SYN)"), 1, GNUNET_NO); 1886 GNUNET_STATISTICS_update (GST_stats,
1887 gettext_noop ("# Failed attempts to switch addresses (failed to send SYN)"),
1888 1,
1889 GNUNET_NO);
1872 /* Remove address and request an additional one */ 1890 /* Remove address and request an additional one */
1873 unset_alternative_address (n); 1891 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1874 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_CONNECTED, 1892 "Switch failed, cleaning up alternative address\n");
1875 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); 1893 free_address (&n->alternative_address);
1894 set_state_and_timeout (n,
1895 GNUNET_TRANSPORT_PS_CONNECTED,
1896 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
1876 break; 1897 break;
1877 default: 1898 default:
1899 GNUNET_break (0);
1878 disconnect_neighbour (n); 1900 disconnect_neighbour (n);
1879 break; 1901 break;
1880 } 1902 }
@@ -1886,14 +1908,23 @@ send_syn (struct NeighbourAddress *na)
1886 1908
1887 1909
1888/** 1910/**
1889 * FIXME. 1911 * Continuation called from our attempt to transmitted our
1912 * #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK to the specified @a
1913 * target. Continue processing based on the @a result. Specifically,
1914 * if we failed to transmit, discard the address we used.
1915 *
1916 * @param cls NULL
1917 * @param target which peer received the transmission
1918 * @param result #GNUNET_OK if sending worked
1919 * @param size_payload how many bytes of payload were sent (ignored)
1920 * @param size_on_wire how much bandwidth was consumed on the wire (ignored)
1890 */ 1921 */
1891static void 1922static void
1892send_session_connect_ack_cont (void *cls, 1923send_session_syn_ack_cont (void *cls,
1893 const struct GNUNET_PeerIdentity *target, 1924 const struct GNUNET_PeerIdentity *target,
1894 int result, 1925 int result,
1895 size_t size_payload, 1926 size_t size_payload,
1896 size_t size_on_wire) 1927 size_t size_on_wire)
1897{ 1928{
1898 struct NeighbourMapEntry *n; 1929 struct NeighbourMapEntry *n;
1899 1930
@@ -1917,33 +1948,35 @@ send_session_connect_ack_cont (void *cls,
1917 return; 1948 return;
1918 1949
1919 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1950 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1920 _("Failed to send SYN_ACK message to peer `%s' using address `%s' session %p\n"), 1951 _("Failed to send SYN_ACK message to peer `%s' using address `%s'\n"),
1921 GNUNET_i2s (target), 1952 GNUNET_i2s (target),
1922 GST_plugins_a2s (n->primary_address.address), 1953 GST_plugins_a2s (n->primary_address.address));
1923 n->primary_address.session);
1924 1954
1925 /* Remove address and request and additional one */ 1955 /* Remove address and request and additional one */
1956 /* FIXME: what if the neighbour's primary address
1957 changed in the meantime? Might want to instead
1958 pass "something" around in closure to be sure. */
1926 unset_primary_address (n); 1959 unset_primary_address (n);
1927 n->ack_state = ACK_SEND_SYN_ACK; 1960 n->ack_state = ACK_SEND_SYN_ACK;
1928 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_SYN_RECV_ATS, 1961 set_state_and_timeout (n,
1962 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
1929 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); 1963 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
1930 return;
1931} 1964}
1932 1965
1933 1966
1934/** 1967/**
1935 * Send a SYN_ACK message via the given address. 1968 * Send a SYN_ACK message via the given address.
1936 * 1969 *
1937 * @param address address to use 1970 * @param na address and session to use
1938 * @param session session to use
1939 * @param timestamp timestamp to use for the ACK message 1971 * @param timestamp timestamp to use for the ACK message
1940 * @return GNUNET_SYSERR if sending immediately failed, GNUNET_OK otherwise 1972 * @return #GNUNET_SYSERR if sending immediately failed, #GNUNET_OK otherwise
1941 */ 1973 */
1942static void 1974static void
1943send_connect_ack_message (const struct GNUNET_HELLO_Address *address, 1975send_syn_ack_message (struct NeighbourAddress *na,
1944 struct Session *session, 1976 struct GNUNET_TIME_Absolute timestamp)
1945 struct GNUNET_TIME_Absolute timestamp)
1946{ 1977{
1978 const struct GNUNET_HELLO_Address *address = na->address;
1979 struct Session *session = na->session;
1947 struct GNUNET_TRANSPORT_PluginFunctions *papi; 1980 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1948 struct TransportSynMessage connect_msg; 1981 struct TransportSynMessage connect_msg;
1949 struct NeighbourMapEntry *n; 1982 struct NeighbourMapEntry *n;
@@ -1958,13 +1991,15 @@ send_connect_ack_message (const struct GNUNET_HELLO_Address *address,
1958 return; 1991 return;
1959 } 1992 }
1960 if (NULL == session) 1993 if (NULL == session)
1961 session = papi->get_session (papi->cls, address); 1994 session = papi->get_session (papi->cls,
1995 address);
1962 if (NULL == session) 1996 if (NULL == session)
1963 { 1997 {
1964 GNUNET_break (0); 1998 GNUNET_break (0);
1965 return; 1999 return;
1966 } 2000 }
1967 GST_ats_new_session (address, session); 2001 GST_ats_new_session (address,
2002 session);
1968 GNUNET_STATISTICS_update (GST_stats, 2003 GNUNET_STATISTICS_update (GST_stats,
1969 gettext_noop 2004 gettext_noop
1970 ("# SYN_ACK messages sent"), 2005 ("# SYN_ACK messages sent"),
@@ -1974,15 +2009,17 @@ send_connect_ack_message (const struct GNUNET_HELLO_Address *address,
1974 connect_msg.reserved = htonl (0); 2009 connect_msg.reserved = htonl (0);
1975 connect_msg.timestamp = GNUNET_TIME_absolute_hton (timestamp); 2010 connect_msg.timestamp = GNUNET_TIME_absolute_hton (timestamp);
1976 2011
1977 if (GNUNET_SYSERR == papi->send (papi->cls, 2012 if (GNUNET_SYSERR ==
1978 session, 2013 papi->send (papi->cls,
1979 (const char *) &connect_msg, sizeof (struct TransportSynMessage), 2014 session,
1980 UINT_MAX, 2015 (const char *) &connect_msg,
1981 GNUNET_TIME_UNIT_FOREVER_REL, 2016 sizeof (struct TransportSynMessage),
1982 send_session_connect_ack_cont, NULL)) 2017 UINT_MAX,
2018 GNUNET_TIME_UNIT_FOREVER_REL,
2019 &send_session_syn_ack_cont, NULL))
1983 { 2020 {
1984 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2021 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1985 _("Failed to transmit SYN_ACK message via plugin to %s\n"), 2022 _("Failed to transmit SYN_ACK message to %s\n"),
1986 GST_plugins_a2s (address)); 2023 GST_plugins_a2s (address));
1987 2024
1988 n = lookup_neighbour (&address->peer); 2025 n = lookup_neighbour (&address->peer);
@@ -1994,11 +2031,11 @@ send_connect_ack_message (const struct GNUNET_HELLO_Address *address,
1994 /* Remove address and request and additional one */ 2031 /* Remove address and request and additional one */
1995 unset_primary_address (n); 2032 unset_primary_address (n);
1996 n->ack_state = ACK_SEND_SYN_ACK; 2033 n->ack_state = ACK_SEND_SYN_ACK;
1997 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_SYN_RECV_ATS, 2034 set_state_and_timeout (n,
1998 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); 2035 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
2036 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
1999 return; 2037 return;
2000 } 2038 }
2001
2002} 2039}
2003 2040
2004 2041
@@ -2056,10 +2093,6 @@ setup_neighbour (const struct GNUNET_PeerIdentity *peer)
2056 n->id = *peer; 2093 n->id = *peer;
2057 n->ack_state = ACK_UNDEFINED; 2094 n->ack_state = ACK_UNDEFINED;
2058 n->last_util_transmission = GNUNET_TIME_absolute_get(); 2095 n->last_util_transmission = GNUNET_TIME_absolute_get();
2059 n->util_payload_bytes_recv = 0;
2060 n->util_payload_bytes_sent = 0;
2061 n->util_total_bytes_recv = 0;
2062 n->util_total_bytes_sent = 0;
2063 GNUNET_BANDWIDTH_tracker_init (&n->in_tracker, 2096 GNUNET_BANDWIDTH_tracker_init (&n->in_tracker,
2064 &inbound_bw_tracker_update, 2097 &inbound_bw_tracker_update,
2065 n, 2098 n,
@@ -2073,6 +2106,9 @@ setup_neighbour (const struct GNUNET_PeerIdentity *peer)
2073 GNUNET_CONTAINER_multipeermap_put (neighbours, 2106 GNUNET_CONTAINER_multipeermap_put (neighbours,
2074 &n->id, n, 2107 &n->id, n,
2075 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 2108 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
2109 n->suggest_handle = GNUNET_ATS_connectivity_suggest (GST_ats_connect,
2110 peer);
2111
2076 return n; 2112 return n;
2077} 2113}
2078 2114
@@ -2157,10 +2193,6 @@ try_connect_bl_check_cont (void *cls,
2157 set_state_and_timeout (n, 2193 set_state_and_timeout (n,
2158 GNUNET_TRANSPORT_PS_INIT_ATS, 2194 GNUNET_TRANSPORT_PS_INIT_ATS,
2159 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); 2195 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
2160 GNUNET_ATS_reset_backoff (GST_ats, peer);
2161 GNUNET_assert (NULL == n->suggest_handle);
2162 n->suggest_handle = GNUNET_ATS_connectivity_suggest (GST_ats_connect,
2163 peer);
2164} 2196}
2165 2197
2166 2198
@@ -2304,17 +2336,16 @@ GST_neighbours_handle_session_syn (const struct GNUNET_MessageHeader *message,
2304 { 2336 {
2305 case GNUNET_TRANSPORT_PS_NOT_CONNECTED: 2337 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
2306 /* Request an address from ATS to send SYN_ACK to this peer */ 2338 /* Request an address from ATS to send SYN_ACK to this peer */
2307 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_SYN_RECV_ATS, 2339 set_state_and_timeout (n,
2308 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); 2340 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
2309 if (NULL == n->suggest_handle) 2341 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
2310 n->suggest_handle = GNUNET_ATS_connectivity_suggest (GST_ats_connect,
2311 peer);
2312 break; 2342 break;
2313 case GNUNET_TRANSPORT_PS_INIT_ATS: 2343 case GNUNET_TRANSPORT_PS_INIT_ATS:
2314 /* SYN message takes priority over us asking ATS for address: 2344 /* SYN message takes priority over us asking ATS for address:
2315 * Wait for ATS to suggest an address and send SYN_ACK */ 2345 * Wait for ATS to suggest an address and send SYN_ACK */
2316 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_SYN_RECV_ATS, 2346 set_state_and_timeout (n,
2317 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); 2347 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
2348 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
2318 break; 2349 break;
2319 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: 2350 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
2320 /* We already wait for an address to send an SYN_ACK */ 2351 /* We already wait for an address to send an SYN_ACK */
@@ -2323,16 +2354,16 @@ GST_neighbours_handle_session_syn (const struct GNUNET_MessageHeader *message,
2323 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: 2354 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
2324 /* Send ACK immediately */ 2355 /* Send ACK immediately */
2325 n->ack_state = ACK_SEND_ACK; 2356 n->ack_state = ACK_SEND_ACK;
2326 send_connect_ack_message (n->primary_address.address, 2357 send_syn_ack_message (&n->primary_address,
2327 n->primary_address.session, ts); 2358 ts);
2328 break; 2359 break;
2329 case GNUNET_TRANSPORT_PS_CONNECTED: 2360 case GNUNET_TRANSPORT_PS_CONNECTED:
2330 /* we are already connected and can thus send the ACK immediately */ 2361 /* we are already connected and can thus send the ACK immediately */
2331 GNUNET_assert (NULL != n->primary_address.address); 2362 GNUNET_assert (NULL != n->primary_address.address);
2332 GNUNET_assert (NULL != n->primary_address.session); 2363 GNUNET_assert (NULL != n->primary_address.session);
2333 n->ack_state = ACK_SEND_ACK; 2364 n->ack_state = ACK_SEND_ACK;
2334 send_connect_ack_message (n->primary_address.address, 2365 send_syn_ack_message (&n->primary_address,
2335 n->primary_address.session, ts); 2366 ts);
2336 break; 2367 break;
2337 case GNUNET_TRANSPORT_PS_RECONNECT_ATS: 2368 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
2338 /* We wait for ATS address suggestion */ 2369 /* We wait for ATS address suggestion */
@@ -2341,8 +2372,8 @@ GST_neighbours_handle_session_syn (const struct GNUNET_MessageHeader *message,
2341 /* We received a SYN message while waiting for a SYN_ACK in fast 2372 /* We received a SYN message while waiting for a SYN_ACK in fast
2342 * reconnect. Send SYN_ACK immediately */ 2373 * reconnect. Send SYN_ACK immediately */
2343 n->ack_state = ACK_SEND_ACK; 2374 n->ack_state = ACK_SEND_ACK;
2344 send_connect_ack_message (n->primary_address.address, 2375 send_syn_ack_message (&n->primary_address,
2345 n->primary_address.session, n->connect_ack_timestamp); 2376 n->connect_ack_timestamp);
2346 break; 2377 break;
2347 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: 2378 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
2348 /* We are already connected and can thus send the ACK immediately; 2379 /* We are already connected and can thus send the ACK immediately;
@@ -2351,8 +2382,8 @@ GST_neighbours_handle_session_syn (const struct GNUNET_MessageHeader *message,
2351 GNUNET_assert (NULL != n->primary_address.address); 2382 GNUNET_assert (NULL != n->primary_address.address);
2352 GNUNET_assert (NULL != n->primary_address.session); 2383 GNUNET_assert (NULL != n->primary_address.session);
2353 n->ack_state = ACK_SEND_ACK; 2384 n->ack_state = ACK_SEND_ACK;
2354 send_connect_ack_message (n->primary_address.address, 2385 send_syn_ack_message (&n->primary_address,
2355 n->primary_address.session, ts); 2386 ts);
2356 break; 2387 break;
2357 case GNUNET_TRANSPORT_PS_DISCONNECT: 2388 case GNUNET_TRANSPORT_PS_DISCONNECT:
2358 /* Get rid of remains and re-try */ 2389 /* Get rid of remains and re-try */
@@ -2362,10 +2393,9 @@ GST_neighbours_handle_session_syn (const struct GNUNET_MessageHeader *message,
2362 n->ack_state = ACK_SEND_SYN_ACK; 2393 n->ack_state = ACK_SEND_SYN_ACK;
2363 n->connect_ack_timestamp = ts; 2394 n->connect_ack_timestamp = ts;
2364 /* Request an address for the peer */ 2395 /* Request an address for the peer */
2365 n->suggest_handle = GNUNET_ATS_connectivity_suggest (GST_ats_connect, 2396 set_state_and_timeout (n,
2366 peer); 2397 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
2367 GNUNET_ATS_reset_backoff (GST_ats, peer); 2398 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
2368 set_state (n, GNUNET_TRANSPORT_PS_SYN_RECV_ATS);
2369 break; 2399 break;
2370 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: 2400 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
2371 /* should not be possible */ 2401 /* should not be possible */
@@ -2405,7 +2435,6 @@ try_run_fast_ats_update (const struct GNUNET_HELLO_Address *address,
2405 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 2435 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
2406{ 2436{
2407 struct NeighbourMapEntry *n; 2437 struct NeighbourMapEntry *n;
2408 int connected;
2409 2438
2410 n = lookup_neighbour (&address->peer); 2439 n = lookup_neighbour (&address->peer);
2411 if ( (NULL == n) || 2440 if ( (NULL == n) ||
@@ -2419,16 +2448,7 @@ try_run_fast_ats_update (const struct GNUNET_HELLO_Address *address,
2419 { 2448 {
2420 /* switch to a different session, but keeping same address; could 2449 /* switch to a different session, but keeping same address; could
2421 happen if there is a 2nd inbound connection */ 2450 happen if there is a 2nd inbound connection */
2422 connected = GNUNET_TRANSPORT_is_connected (n->state);
2423 if (GNUNET_YES == connected)
2424 GST_ats_set_in_use (n->primary_address.address,
2425 n->primary_address.session,
2426 GNUNET_NO);
2427 n->primary_address.session = session; 2451 n->primary_address.session = session;
2428 if (GNUNET_YES == connected)
2429 GST_ats_set_in_use (n->primary_address.address,
2430 n->primary_address.session,
2431 GNUNET_YES);
2432 } 2452 }
2433 n->primary_address.bandwidth_in = bandwidth_in; 2453 n->primary_address.bandwidth_in = bandwidth_in;
2434 n->primary_address.bandwidth_out = bandwidth_out; 2454 n->primary_address.bandwidth_out = bandwidth_out;
@@ -2470,8 +2490,10 @@ switch_address_bl_check_cont (void *cls,
2470 "# ATS suggestions ignored (blacklist denied)", 2490 "# ATS suggestions ignored (blacklist denied)",
2471 1, 2491 1,
2472 GNUNET_NO); 2492 GNUNET_NO);
2473 /* FIXME: tell plugin to force killing session here and now! */ 2493 /* FIXME: tell plugin to force killing session here and now
2474 /* FIXME: Let ATS know that the suggested address did not work! */ 2494 (note: _proper_ plugin API for this does not yet exist) */
2495 GST_ats_block_address (blc_ctx->address,
2496 blc_ctx->session);
2475 goto cleanup; 2497 goto cleanup;
2476 } 2498 }
2477 2499
@@ -2501,10 +2523,11 @@ switch_address_bl_check_cont (void *cls,
2501 GNUNET_NO); 2523 GNUNET_NO);
2502 /* No session could be obtained, remove blacklist check and clean up */ 2524 /* No session could be obtained, remove blacklist check and clean up */
2503 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2525 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2504 "Failed to obtain new session for peer `%s' and address '%s'\n", 2526 "Failed to obtain new session for peer `%s' and address '%s'\n",
2505 GNUNET_i2s (&blc_ctx->address->peer), 2527 GNUNET_i2s (&blc_ctx->address->peer),
2506 GST_plugins_a2s (blc_ctx->address)); 2528 GST_plugins_a2s (blc_ctx->address));
2507 /* FIXME: Let ATS know that the suggested address did not work! */ 2529 GST_ats_block_address (blc_ctx->address,
2530 blc_ctx->session);
2508 goto cleanup; 2531 goto cleanup;
2509 } 2532 }
2510 2533
@@ -2526,15 +2549,16 @@ switch_address_bl_check_cont (void *cls,
2526 } 2549 }
2527 2550
2528 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2551 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2529 "Peer `%s' switches to address `%s' session %p\n", 2552 "Peer `%s' switches to address `%s'\n",
2530 GNUNET_i2s (&blc_ctx->address->peer), 2553 GNUNET_i2s (&blc_ctx->address->peer),
2531 GST_plugins_a2s (blc_ctx->address), 2554 GST_plugins_a2s (blc_ctx->address));
2532 blc_ctx->session);
2533 2555
2534 switch (n->state) 2556 switch (n->state)
2535 { 2557 {
2536 case GNUNET_TRANSPORT_PS_NOT_CONNECTED: 2558 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
2537 GNUNET_break (0); 2559 GNUNET_break (0);
2560 GST_ats_block_address (blc_ctx->address,
2561 blc_ctx->session);
2538 free_neighbour (n); 2562 free_neighbour (n);
2539 return; 2563 return;
2540 case GNUNET_TRANSPORT_PS_INIT_ATS: 2564 case GNUNET_TRANSPORT_PS_INIT_ATS:
@@ -2550,9 +2574,8 @@ switch_address_bl_check_cont (void *cls,
2550 { 2574 {
2551 /* Send pending SYN_ACK message */ 2575 /* Send pending SYN_ACK message */
2552 n->ack_state = ACK_SEND_ACK; 2576 n->ack_state = ACK_SEND_ACK;
2553 send_connect_ack_message (n->primary_address.address, 2577 send_syn_ack_message (&n->primary_address,
2554 n->primary_address.session, 2578 n->connect_ack_timestamp);
2555 n->connect_ack_timestamp);
2556 } 2579 }
2557 set_state_and_timeout (n, 2580 set_state_and_timeout (n,
2558 GNUNET_TRANSPORT_PS_SYN_SENT, 2581 GNUNET_TRANSPORT_PS_SYN_SENT,
@@ -2573,9 +2596,8 @@ switch_address_bl_check_cont (void *cls,
2573 { 2596 {
2574 /* Send pending SYN_ACK message */ 2597 /* Send pending SYN_ACK message */
2575 n->ack_state = ACK_SEND_ACK; 2598 n->ack_state = ACK_SEND_ACK;
2576 send_connect_ack_message (n->primary_address.address, 2599 send_syn_ack_message (&n->primary_address,
2577 n->primary_address.session, 2600 n->connect_ack_timestamp);
2578 n->connect_ack_timestamp);
2579 } 2601 }
2580 set_state_and_timeout (n, 2602 set_state_and_timeout (n,
2581 GNUNET_TRANSPORT_PS_SYN_SENT, 2603 GNUNET_TRANSPORT_PS_SYN_SENT,
@@ -2595,9 +2617,8 @@ switch_address_bl_check_cont (void *cls,
2595 set_state_and_timeout (n, 2617 set_state_and_timeout (n,
2596 GNUNET_TRANSPORT_PS_SYN_RECV_ACK, 2618 GNUNET_TRANSPORT_PS_SYN_RECV_ACK,
2597 GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT)); 2619 GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT));
2598 send_connect_ack_message (n->primary_address.address, 2620 send_syn_ack_message (&n->primary_address,
2599 n->primary_address.session, 2621 n->connect_ack_timestamp);
2600 n->connect_ack_timestamp);
2601 if ( (ACK_SEND_SYN_ACK == n->ack_state) || 2622 if ( (ACK_SEND_SYN_ACK == n->ack_state) ||
2602 (ACK_UNDEFINED == n->ack_state) ) 2623 (ACK_UNDEFINED == n->ack_state) )
2603 n->ack_state = ACK_SEND_ACK; 2624 n->ack_state = ACK_SEND_ACK;
@@ -2608,9 +2629,8 @@ switch_address_bl_check_cont (void *cls,
2608 if ( (ACK_SEND_SYN_ACK == n->ack_state) ) 2629 if ( (ACK_SEND_SYN_ACK == n->ack_state) )
2609 { 2630 {
2610 n->ack_state = ACK_SEND_ACK; 2631 n->ack_state = ACK_SEND_ACK;
2611 send_connect_ack_message (n->primary_address.address, 2632 send_syn_ack_message (&n->primary_address,
2612 n->primary_address.session, 2633 n->connect_ack_timestamp);
2613 n->connect_ack_timestamp);
2614 } 2634 }
2615 set_primary_address (n, 2635 set_primary_address (n,
2616 blc_ctx->address, 2636 blc_ctx->address,
@@ -2625,18 +2645,7 @@ switch_address_bl_check_cont (void *cls,
2625 case GNUNET_TRANSPORT_PS_CONNECTED: 2645 case GNUNET_TRANSPORT_PS_CONNECTED:
2626 GNUNET_assert (NULL != n->primary_address.address); 2646 GNUNET_assert (NULL != n->primary_address.address);
2627 GNUNET_assert (NULL != n->primary_address.session); 2647 GNUNET_assert (NULL != n->primary_address.session);
2628 if (n->primary_address.session == blc_ctx->session) 2648 GNUNET_break (n->primary_address.session != blc_ctx->session);
2629 {
2630 /* not an address change, just a quota change */
2631 // FIXME: this case should have been caught above!
2632 set_primary_address (n,
2633 blc_ctx->address,
2634 blc_ctx->session,
2635 blc_ctx->bandwidth_in,
2636 blc_ctx->bandwidth_out,
2637 GNUNET_YES);
2638 break;
2639 }
2640 /* ATS asks us to switch a life connection; see if we can get 2649 /* ATS asks us to switch a life connection; see if we can get
2641 a SYN_ACK on it before we actually do this! */ 2650 a SYN_ACK on it before we actually do this! */
2642 set_alternative_address (n, 2651 set_alternative_address (n,
@@ -2644,7 +2653,8 @@ switch_address_bl_check_cont (void *cls,
2644 blc_ctx->session, 2653 blc_ctx->session,
2645 blc_ctx->bandwidth_in, 2654 blc_ctx->bandwidth_in,
2646 blc_ctx->bandwidth_out); 2655 blc_ctx->bandwidth_out);
2647 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT, 2656 set_state_and_timeout (n,
2657 GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT,
2648 GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT)); 2658 GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT));
2649 GNUNET_STATISTICS_update (GST_stats, 2659 GNUNET_STATISTICS_update (GST_stats,
2650 gettext_noop ("# Attempts to switch addresses"), 2660 gettext_noop ("# Attempts to switch addresses"),
@@ -2663,9 +2673,8 @@ switch_address_bl_check_cont (void *cls,
2663 { 2673 {
2664 /* Send pending SYN_ACK message */ 2674 /* Send pending SYN_ACK message */
2665 n->ack_state = ACK_SEND_ACK; 2675 n->ack_state = ACK_SEND_ACK;
2666 send_connect_ack_message (n->primary_address.address, 2676 send_syn_ack_message (&n->primary_address,
2667 n->primary_address.session, 2677 n->connect_ack_timestamp);
2668 n->connect_ack_timestamp);
2669 } 2678 }
2670 set_state_and_timeout (n, 2679 set_state_and_timeout (n,
2671 GNUNET_TRANSPORT_PS_RECONNECT_SENT, 2680 GNUNET_TRANSPORT_PS_RECONNECT_SENT,
@@ -2687,13 +2696,17 @@ switch_address_bl_check_cont (void *cls,
2687 send_syn (&n->primary_address); 2696 send_syn (&n->primary_address);
2688 break; 2697 break;
2689 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: 2698 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
2690 if ( (0 == GNUNET_HELLO_address_cmp(n->primary_address.address, 2699 if ( (0 == GNUNET_HELLO_address_cmp (n->primary_address.address,
2691 blc_ctx->address)) && 2700 blc_ctx->address)) &&
2692 (n->primary_address.session == blc_ctx->session) ) 2701 (n->primary_address.session == blc_ctx->session) )
2693 { 2702 {
2694 /* ATS switches back to still-active session */ 2703 /* ATS switches back to still-active session */
2704 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2705 "ATS double-switched, cleaning up alternative address\n");
2695 free_address (&n->alternative_address); 2706 free_address (&n->alternative_address);
2696 set_state (n, GNUNET_TRANSPORT_PS_CONNECTED); 2707 set_state_and_timeout (n,
2708 GNUNET_TRANSPORT_PS_CONNECTED,
2709 n->timeout);
2697 break; 2710 break;
2698 } 2711 }
2699 /* ATS asks us to switch a life connection, send */ 2712 /* ATS asks us to switch a life connection, send */
@@ -2737,7 +2750,11 @@ switch_address_bl_check_cont (void *cls,
2737 * For the given peer, switch to this address. 2750 * For the given peer, switch to this address.
2738 * 2751 *
2739 * Before accepting this addresses and actively using it, a blacklist check 2752 * Before accepting this addresses and actively using it, a blacklist check
2740 * is performed. If this blacklist check fails the address will be destroyed. 2753 * is performed.
2754 *
2755 * If any check fails or the suggestion can somehow not be followed, we
2756 * MUST call #GST_ats_block_address() to tell ATS that the suggestion
2757 * could not be satisfied and force ATS to do something else.
2741 * 2758 *
2742 * @param address address of the other peer, 2759 * @param address address of the other peer,
2743 * @param session session to use or NULL if transport should initiate a session 2760 * @param session session to use or NULL if transport should initiate a session
@@ -2755,9 +2772,6 @@ GST_neighbours_switch_to_address (const struct GNUNET_HELLO_Address *address,
2755 struct GST_BlacklistCheck *blc; 2772 struct GST_BlacklistCheck *blc;
2756 struct BlacklistCheckSwitchContext *blc_ctx; 2773 struct BlacklistCheckSwitchContext *blc_ctx;
2757 2774
2758 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2759 "ATS has decided on an address for peer %s\n",
2760 GNUNET_i2s (&address->peer));
2761 GNUNET_assert (NULL != address->transport_name); 2775 GNUNET_assert (NULL != address->transport_name);
2762 if (GNUNET_OK == 2776 if (GNUNET_OK ==
2763 try_run_fast_ats_update (address, 2777 try_run_fast_ats_update (address,
@@ -2771,6 +2785,8 @@ GST_neighbours_switch_to_address (const struct GNUNET_HELLO_Address *address,
2771 { 2785 {
2772 /* we don't have the plugin for this address */ 2786 /* we don't have the plugin for this address */
2773 GNUNET_break (0); 2787 GNUNET_break (0);
2788 GST_ats_block_address (address,
2789 session);
2774 return; 2790 return;
2775 } 2791 }
2776 if ((NULL == session) && 2792 if ((NULL == session) &&
@@ -2779,14 +2795,13 @@ GST_neighbours_switch_to_address (const struct GNUNET_HELLO_Address *address,
2779 { 2795 {
2780 /* This is a inbound address and we do not have a session to use! */ 2796 /* This is a inbound address and we do not have a session to use! */
2781 GNUNET_break (0); 2797 GNUNET_break (0);
2798 GST_ats_block_address (address,
2799 session);
2782 return; 2800 return;
2783 } 2801 }
2784 2802
2785 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2803 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2786 "ATS suggests %s address '%s' for peer `%s'\n", 2804 "ATS suggests address '%s' for peer `%s'\n",
2787 GNUNET_HELLO_address_check_option (address,
2788 GNUNET_HELLO_ADDRESS_INFO_INBOUND)
2789 ? "inbound" : "outbound",
2790 GST_plugins_a2s (address), 2805 GST_plugins_a2s (address),
2791 GNUNET_i2s (&address->peer)); 2806 GNUNET_i2s (&address->peer));
2792 2807
@@ -2831,7 +2846,7 @@ send_utilization_data (void *cls,
2831 uint32_t bps_out; 2846 uint32_t bps_out;
2832 struct GNUNET_TIME_Relative delta; 2847 struct GNUNET_TIME_Relative delta;
2833 2848
2834 if (GNUNET_TRANSPORT_PS_CONNECTED != n->state) 2849 if (GNUNET_YES != test_connected (n))
2835 return GNUNET_OK; 2850 return GNUNET_OK;
2836 delta = GNUNET_TIME_absolute_get_difference (n->last_util_transmission, 2851 delta = GNUNET_TIME_absolute_get_difference (n->last_util_transmission,
2837 GNUNET_TIME_absolute_get ()); 2852 GNUNET_TIME_absolute_get ());
@@ -2894,13 +2909,13 @@ utilization_transmission (void *cls,
2894 const struct GNUNET_SCHEDULER_TaskContext *tc) 2909 const struct GNUNET_SCHEDULER_TaskContext *tc)
2895{ 2910{
2896 util_transmission_tk = NULL; 2911 util_transmission_tk = NULL;
2897 2912 GNUNET_CONTAINER_multipeermap_iterate (neighbours,
2898 if (0 < GNUNET_CONTAINER_multipeermap_size (neighbours)) 2913 &send_utilization_data,
2899 GNUNET_CONTAINER_multipeermap_iterate (neighbours, send_utilization_data, NULL); 2914 NULL);
2900 2915 util_transmission_tk
2901 util_transmission_tk = GNUNET_SCHEDULER_add_delayed (UTIL_TRANSMISSION_INTERVAL, 2916 = GNUNET_SCHEDULER_add_delayed (UTIL_TRANSMISSION_INTERVAL,
2902 utilization_transmission, NULL); 2917 &utilization_transmission,
2903 2918 NULL);
2904} 2919}
2905 2920
2906 2921
@@ -3040,8 +3055,9 @@ master_task (void *cls,
3040 GNUNET_i2s (&n->id)); 3055 GNUNET_i2s (&n->id));
3041 /* Remove address and request and additional one */ 3056 /* Remove address and request and additional one */
3042 unset_primary_address (n); 3057 unset_primary_address (n);
3043 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_INIT_ATS, 3058 set_state_and_timeout (n,
3044 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); 3059 GNUNET_TRANSPORT_PS_INIT_ATS,
3060 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
3045 return; 3061 return;
3046 } 3062 }
3047 break; 3063 break;
@@ -3100,15 +3116,12 @@ master_task (void *cls,
3100 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: 3116 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
3101 if (0 == delay.rel_value_us) 3117 if (0 == delay.rel_value_us)
3102 { 3118 {
3103 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 3119 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3104 "Connection to `%s' timed out, missing KEEPALIVE_RESPONSEs (after trying to SYN on alternative address)\n", 3120 "Switch failed, cleaning up alternative address\n");
3105 GNUNET_i2s (&n->id)); 3121 free_address (&n->alternative_address);
3106 GNUNET_STATISTICS_update (GST_stats, 3122 set_state_and_timeout (n,
3107 gettext_noop ("# Failed attempts to switch addresses (no response)"), 3123 GNUNET_TRANSPORT_PS_CONNECTED,
3108 1, 3124 GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT));
3109 GNUNET_NO);
3110 disconnect_neighbour (n);
3111 return;
3112 } 3125 }
3113 try_transmission_to_peer (n); 3126 try_transmission_to_peer (n);
3114 send_keepalive (n); 3127 send_keepalive (n);
@@ -3130,6 +3143,7 @@ master_task (void *cls,
3130 GNUNET_break (0); 3143 GNUNET_break (0);
3131 break; 3144 break;
3132 } 3145 }
3146 delay = GNUNET_TIME_absolute_get_remaining (n->timeout);
3133 if ( (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state) || 3147 if ( (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state) ||
3134 (GNUNET_TRANSPORT_PS_CONNECTED == n->state) ) 3148 (GNUNET_TRANSPORT_PS_CONNECTED == n->state) )
3135 { 3149 {
@@ -3157,15 +3171,19 @@ send_session_ack_message (struct NeighbourMapEntry *n)
3157{ 3171{
3158 struct GNUNET_MessageHeader msg; 3172 struct GNUNET_MessageHeader msg;
3159 3173
3160 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Sending ACK message to peer `%s'\n", 3174 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3175 "Sending ACK message to peer `%s'\n",
3161 GNUNET_i2s (&n->id)); 3176 GNUNET_i2s (&n->id));
3162 3177
3163 msg.size = htons (sizeof (struct GNUNET_MessageHeader)); 3178 msg.size = htons (sizeof (struct GNUNET_MessageHeader));
3164 msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK); 3179 msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK);
3165 (void) send_with_session(n, 3180 (void) send_with_session (n,
3166 (const char *) &msg, sizeof (struct GNUNET_MessageHeader), 3181 &msg,
3167 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_NO, 3182 sizeof (struct GNUNET_MessageHeader),
3168 NULL, NULL); 3183 UINT32_MAX,
3184 GNUNET_TIME_UNIT_FOREVER_REL,
3185 GNUNET_NO,
3186 NULL, NULL);
3169} 3187}
3170 3188
3171 3189
@@ -3173,7 +3191,7 @@ send_session_ack_message (struct NeighbourMapEntry *n)
3173 * We received a 'SESSION_SYN_ACK' message from the other peer. 3191 * We received a 'SESSION_SYN_ACK' message from the other peer.
3174 * Consider switching to it. 3192 * Consider switching to it.
3175 * 3193 *
3176 * @param message possibly a 'struct SessionConnectMessage' (check format) 3194 * @param message possibly a `struct SessionConnectMessage` (check format)
3177 * @param peer identity of the peer to switch the address for 3195 * @param peer identity of the peer to switch the address for
3178 * @param address address of the other peer, NULL if other peer 3196 * @param address address of the other peer, NULL if other peer
3179 * connected to us 3197 * connected to us
@@ -3189,10 +3207,6 @@ GST_neighbours_handle_session_syn_ack (const struct GNUNET_MessageHeader *messag
3189 struct GNUNET_TIME_Absolute ts; 3207 struct GNUNET_TIME_Absolute ts;
3190 struct NeighbourMapEntry *n; 3208 struct NeighbourMapEntry *n;
3191 3209
3192 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3193 "Received SYN_ACK message from peer `%s'\n",
3194 GNUNET_i2s (&address->peer));
3195
3196 if (ntohs (message->size) != sizeof (struct TransportSynMessage)) 3210 if (ntohs (message->size) != sizeof (struct TransportSynMessage))
3197 { 3211 {
3198 GNUNET_break_op (0); 3212 GNUNET_break_op (0);
@@ -3212,6 +3226,11 @@ GST_neighbours_handle_session_syn_ack (const struct GNUNET_MessageHeader *messag
3212 1, GNUNET_NO); 3226 1, GNUNET_NO);
3213 return GNUNET_SYSERR; 3227 return GNUNET_SYSERR;
3214 } 3228 }
3229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3230 "Received SYN_ACK message from peer `%s' in state %s/%s\n",
3231 GNUNET_i2s (&address->peer),
3232 GNUNET_TRANSPORT_ps2s (n->state),
3233 print_ack_state (n->ack_state));
3215 ts = GNUNET_TIME_absolute_ntoh (scm->timestamp); 3234 ts = GNUNET_TIME_absolute_ntoh (scm->timestamp);
3216 switch (n->state) 3235 switch (n->state)
3217 { 3236 {
@@ -3221,9 +3240,9 @@ GST_neighbours_handle_session_syn_ack (const struct GNUNET_MessageHeader *messag
3221 return GNUNET_SYSERR; 3240 return GNUNET_SYSERR;
3222 case GNUNET_TRANSPORT_PS_INIT_ATS: 3241 case GNUNET_TRANSPORT_PS_INIT_ATS:
3223 GNUNET_STATISTICS_update (GST_stats, 3242 GNUNET_STATISTICS_update (GST_stats,
3224 gettext_noop 3243 gettext_noop ("# unexpected SYN_ACK messages (not ready)"),
3225 ("# unexpected SYN_ACK messages (not ready)"), 3244 1,
3226 1, GNUNET_NO); 3245 GNUNET_NO);
3227 break; 3246 break;
3228 case GNUNET_TRANSPORT_PS_SYN_SENT: 3247 case GNUNET_TRANSPORT_PS_SYN_SENT:
3229 if (ts.abs_value_us != n->primary_address.connect_timestamp.abs_value_us) 3248 if (ts.abs_value_us != n->primary_address.connect_timestamp.abs_value_us)
@@ -3232,16 +3251,9 @@ GST_neighbours_handle_session_syn_ack (const struct GNUNET_MessageHeader *messag
3232 "SYN_ACK ignored as the timestamp does not match our SYN request\n"); 3251 "SYN_ACK ignored as the timestamp does not match our SYN request\n");
3233 return GNUNET_OK; 3252 return GNUNET_OK;
3234 } 3253 }
3235 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_CONNECTED, 3254 set_state_and_timeout (n,
3236 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); 3255 GNUNET_TRANSPORT_PS_CONNECTED,
3237 GNUNET_STATISTICS_set (GST_stats, 3256 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
3238 gettext_noop ("# peers connected"),
3239 ++neighbours_connected,
3240 GNUNET_NO);
3241 neighbours_connect_notification (&n->id,
3242 n->primary_address.bandwidth_in,
3243 n->primary_address.bandwidth_out);
3244 /* Tell ATS that the outbound session we created to send SYN was successful */
3245 set_primary_address (n, 3257 set_primary_address (n,
3246 n->primary_address.address, 3258 n->primary_address.address,
3247 n->primary_address.session, 3259 n->primary_address.session,
@@ -3253,9 +3265,9 @@ GST_neighbours_handle_session_syn_ack (const struct GNUNET_MessageHeader *messag
3253 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: 3265 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
3254 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: 3266 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
3255 GNUNET_STATISTICS_update (GST_stats, 3267 GNUNET_STATISTICS_update (GST_stats,
3256 gettext_noop 3268 gettext_noop ("# unexpected SYN_ACK messages (not ready)"),
3257 ("# unexpected SYN_ACK messages (not ready)"), 3269 1,
3258 1, GNUNET_NO); 3270 GNUNET_NO);
3259 break; 3271 break;
3260 case GNUNET_TRANSPORT_PS_CONNECTED: 3272 case GNUNET_TRANSPORT_PS_CONNECTED:
3261 /* duplicate SYN_ACK, let's answer by duplicate ACK just in case */ 3273 /* duplicate SYN_ACK, let's answer by duplicate ACK just in case */
@@ -3265,30 +3277,40 @@ GST_neighbours_handle_session_syn_ack (const struct GNUNET_MessageHeader *messag
3265 /* we didn't expect any SYN_ACK, as we are waiting for ATS 3277 /* we didn't expect any SYN_ACK, as we are waiting for ATS
3266 to give us a new address... */ 3278 to give us a new address... */
3267 GNUNET_STATISTICS_update (GST_stats, 3279 GNUNET_STATISTICS_update (GST_stats,
3268 gettext_noop 3280 gettext_noop ("# unexpected SYN_ACK messages (waiting on ATS)"),
3269 ("# unexpected SYN_ACK messages (waiting on ATS)"), 3281 1,
3270 1, GNUNET_NO); 3282 GNUNET_NO);
3271 break; 3283 break;
3272 case GNUNET_TRANSPORT_PS_RECONNECT_SENT: 3284 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
3273 /* Reconnecting with new address address worked; go back to connected! */ 3285 /* Reconnecting with new address address worked; go back to connected! */
3274 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_CONNECTED, 3286 set_state_and_timeout (n,
3275 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); 3287 GNUNET_TRANSPORT_PS_CONNECTED,
3288 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
3276 send_session_ack_message (n); 3289 send_session_ack_message (n);
3277 break; 3290 break;
3278 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: 3291 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
3279 /* new address worked; adopt it and go back to connected! */ 3292 /* new address worked; adopt it and go back to connected! */
3280 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_CONNECTED, 3293 set_state_and_timeout (n,
3294 GNUNET_TRANSPORT_PS_CONNECTED,
3281 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); 3295 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
3282 GNUNET_break (GNUNET_NO == n->alternative_address.ats_active); 3296 GNUNET_break (GNUNET_NO == n->alternative_address.ats_active);
3283 3297
3284 /* Set primary addresses */ 3298 /* Set primary addresses */
3285 set_primary_address (n, n->alternative_address.address, 3299 set_primary_address (n,
3286 n->alternative_address.session, n->alternative_address.bandwidth_in, 3300 n->alternative_address.address,
3287 n->alternative_address.bandwidth_out, GNUNET_YES); 3301 n->alternative_address.session,
3288 GNUNET_STATISTICS_update (GST_stats, gettext_noop 3302 n->alternative_address.bandwidth_in,
3289 ("# Successful attempts to switch addresses"), 1, GNUNET_NO); 3303 n->alternative_address.bandwidth_out,
3304 GNUNET_YES);
3305 GNUNET_STATISTICS_update (GST_stats,
3306 gettext_noop ("# Successful attempts to switch addresses"),
3307 1,
3308 GNUNET_NO);
3290 3309
3291 free_address (&n->alternative_address); 3310 GNUNET_HELLO_address_free (n->alternative_address.address);
3311 memset (&n->alternative_address,
3312 0,
3313 sizeof (n->alternative_address));
3292 send_session_ack_message (n); 3314 send_session_ack_message (n);
3293 break; 3315 break;
3294 case GNUNET_TRANSPORT_PS_DISCONNECT: 3316 case GNUNET_TRANSPORT_PS_DISCONNECT:
@@ -3351,8 +3373,12 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
3351 /* Free alternative address */ 3373 /* Free alternative address */
3352 if (session == n->alternative_address.session) 3374 if (session == n->alternative_address.session)
3353 { 3375 {
3354 if ( (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state) ) 3376 if (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state)
3355 set_state (n, GNUNET_TRANSPORT_PS_CONNECTED); 3377 set_state_and_timeout (n,
3378 GNUNET_TRANSPORT_PS_CONNECTED,
3379 n->timeout);
3380 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3381 "Session died, cleaning up alternative address\n");
3356 free_address (&n->alternative_address); 3382 free_address (&n->alternative_address);
3357 } 3383 }
3358 return GNUNET_NO; /* doesn't affect us further */ 3384 return GNUNET_NO; /* doesn't affect us further */
@@ -3382,20 +3408,21 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
3382 3408
3383 /* Destroy the address since it cannot be used */ 3409 /* Destroy the address since it cannot be used */
3384 unset_primary_address (n); 3410 unset_primary_address (n);
3385 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_INIT_ATS, 3411 set_state_and_timeout (n,
3386 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); 3412 GNUNET_TRANSPORT_PS_INIT_ATS,
3413 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
3387 break; 3414 break;
3388 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: 3415 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
3389 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: 3416 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
3390 /* error on inbound session; free neighbour entirely */ 3417 /* error on inbound session; free neighbour entirely */
3391 free_address (&n->primary_address);
3392 free_neighbour (n); 3418 free_neighbour (n);
3393 return GNUNET_YES; 3419 return GNUNET_YES;
3394 case GNUNET_TRANSPORT_PS_CONNECTED: 3420 case GNUNET_TRANSPORT_PS_CONNECTED:
3395 /* Our primary connection died, try a fast reconnect */ 3421 /* Our primary connection died, try a fast reconnect */
3396 unset_primary_address (n); 3422 unset_primary_address (n);
3397 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_ATS, 3423 set_state_and_timeout (n,
3398 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); 3424 GNUNET_TRANSPORT_PS_RECONNECT_ATS,
3425 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
3399 break; 3426 break;
3400 case GNUNET_TRANSPORT_PS_RECONNECT_ATS: 3427 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
3401 /* we don't have an address, how can it go down? */ 3428 /* we don't have an address, how can it go down? */
@@ -3410,36 +3437,39 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
3410 GNUNET_i2s (peer)); 3437 GNUNET_i2s (peer));
3411 /* Destroy the address since it cannot be used */ 3438 /* Destroy the address since it cannot be used */
3412 unset_primary_address (n); 3439 unset_primary_address (n);
3413 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_ATS, 3440 set_state_and_timeout (n,
3414 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); 3441 GNUNET_TRANSPORT_PS_RECONNECT_ATS,
3442 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
3415 break; 3443 break;
3416 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: 3444 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
3417 /* primary went down while we were waiting for SYN_ACK on secondary; 3445 /* primary went down while we were waiting for SYN_ACK on secondary;
3418 secondary as primary */ 3446 secondary as primary */
3419 3447
3420 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 3448 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3421 "Connection `%s' %p to peer `%s' was terminated while switching, " 3449 "Connection `%s' %p to peer `%s' was terminated while switching, "
3422 "switching to alternative address `%s' %p\n", 3450 "switching to alternative address `%s' %p\n",
3423 GST_plugins_a2s (n->primary_address.address), 3451 GST_plugins_a2s (n->primary_address.address),
3424 n->primary_address.session, 3452 n->primary_address.session,
3425 GNUNET_i2s (peer), 3453 GNUNET_i2s (peer),
3426 GST_plugins_a2s (n->alternative_address.address), 3454 GST_plugins_a2s (n->alternative_address.address),
3427 n->alternative_address.session); 3455 n->alternative_address.session);
3428 3456
3429 /* Destroy the inbound address since it cannot be used */ 3457 /* Destroy the inbound address since it cannot be used */
3430 free_address (&n->primary_address); 3458 free_address (&n->primary_address);
3431 n->primary_address = n->alternative_address; 3459 n->primary_address = n->alternative_address;
3432 memset (&n->alternative_address, 0, sizeof (struct NeighbourAddress)); 3460 memset (&n->alternative_address,
3433 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_SENT, 3461 0,
3434 GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT)); 3462 sizeof (struct NeighbourAddress));
3463 set_state_and_timeout (n,
3464 GNUNET_TRANSPORT_PS_RECONNECT_SENT,
3465 GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT));
3435 break; 3466 break;
3436 case GNUNET_TRANSPORT_PS_DISCONNECT: 3467 case GNUNET_TRANSPORT_PS_DISCONNECT:
3437 free_address (&n->primary_address); 3468 unset_primary_address (n);
3438 break; 3469 break;
3439 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: 3470 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
3440 /* neighbour was freed and plugins told to terminate session */ 3471 /* neighbour was freed and plugins told to terminate session */
3441 return GNUNET_NO; 3472 return GNUNET_NO;
3442 break;
3443 default: 3473 default:
3444 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 3474 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3445 "Unhandled state `%s'\n", 3475 "Unhandled state `%s'\n",
@@ -3471,9 +3501,6 @@ GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
3471{ 3501{
3472 struct NeighbourMapEntry *n; 3502 struct NeighbourMapEntry *n;
3473 3503
3474 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3475 "Received ACK message from peer `%s'\n",
3476 GNUNET_i2s (&address->peer));
3477 if (ntohs (message->size) != sizeof (struct GNUNET_MessageHeader)) 3504 if (ntohs (message->size) != sizeof (struct GNUNET_MessageHeader))
3478 { 3505 {
3479 GNUNET_break_op (0); 3506 GNUNET_break_op (0);
@@ -3488,10 +3515,8 @@ GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
3488 GNUNET_break_op (0); 3515 GNUNET_break_op (0);
3489 return GNUNET_SYSERR; 3516 return GNUNET_SYSERR;
3490 } 3517 }
3491 3518 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3492 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 3519 "Received ACK for peer `%s' in state %s/%s\n",
3493 "Received %s for peer `%s' in state %s/%s\n",
3494 "ACK",
3495 GNUNET_i2s (&address->peer), 3520 GNUNET_i2s (&address->peer),
3496 GNUNET_TRANSPORT_ps2s (n->state), 3521 GNUNET_TRANSPORT_ps2s (n->state),
3497 print_ack_state (n->ack_state)); 3522 print_ack_state (n->ack_state));
@@ -3521,20 +3546,6 @@ GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
3521 GNUNET_NO); 3546 GNUNET_NO);
3522 return GNUNET_OK; 3547 return GNUNET_OK;
3523 } 3548 }
3524
3525 /* We are connected */
3526 if (GNUNET_NO == GST_neighbours_test_connected(&n->id))
3527 {
3528 /* Notify about connection */
3529 neighbours_connect_notification (&n->id,
3530 n->primary_address.bandwidth_in,
3531 n->primary_address.bandwidth_out);
3532 GNUNET_STATISTICS_set (GST_stats,
3533 gettext_noop ("# peers connected"),
3534 ++neighbours_connected,
3535 GNUNET_NO);
3536 }
3537
3538 if (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state) 3549 if (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state)
3539 { 3550 {
3540 /* We tried to switch addresses while being connect. We explicitly wait 3551 /* We tried to switch addresses while being connect. We explicitly wait
@@ -3542,9 +3553,9 @@ GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
3542 * so we do not want to set the address as in use! */ 3553 * so we do not want to set the address as in use! */
3543 return GNUNET_OK; 3554 return GNUNET_OK;
3544 } 3555 }
3545 3556 set_state_and_timeout (n,
3546 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_CONNECTED, 3557 GNUNET_TRANSPORT_PS_CONNECTED,
3547 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); 3558 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
3548 3559
3549 /* Set primary address to used */ 3560 /* Set primary address to used */
3550 set_primary_address (n, 3561 set_primary_address (n,
@@ -3880,7 +3891,7 @@ GST_neighbours_stop ()
3880 &disconnect_all_neighbours, 3891 &disconnect_all_neighbours,
3881 NULL); 3892 NULL);
3882 GNUNET_CONTAINER_multipeermap_destroy (neighbours); 3893 GNUNET_CONTAINER_multipeermap_destroy (neighbours);
3883 3894 neighbours = NULL;
3884 next = pending_bc_head; 3895 next = pending_bc_head;
3885 for (cur = next; NULL != cur; cur = next) 3896 for (cur = next; NULL != cur; cur = next)
3886 { 3897 {
@@ -3898,7 +3909,6 @@ GST_neighbours_stop ()
3898 GNUNET_HELLO_address_free (cur->address); 3909 GNUNET_HELLO_address_free (cur->address);
3899 GNUNET_free (cur); 3910 GNUNET_free (cur);
3900 } 3911 }
3901 neighbours = NULL;
3902} 3912}
3903 3913
3904 3914
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c
index fb2791eba..746a99f9f 100644
--- a/src/transport/gnunet-service-transport_validation.c
+++ b/src/transport/gnunet-service-transport_validation.c
@@ -450,7 +450,7 @@ cleanup_validation_entry (void *cls,
450 validations_running, 450 validations_running,
451 GNUNET_NO); 451 GNUNET_NO);
452 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 452 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
453 "Validation finished, %u validation processes running\n", 453 "Validation aborted, %u validation processes running\n",
454 validations_running); 454 validations_running);
455 } 455 }
456 GNUNET_free (ve); 456 GNUNET_free (ve);
@@ -830,7 +830,7 @@ add_valid_address (void *cls,
830 if (GNUNET_YES != ve->known_to_ats) 830 if (GNUNET_YES != ve->known_to_ats)
831 { 831 {
832 ve->known_to_ats = GNUNET_YES; 832 ve->known_to_ats = GNUNET_YES;
833 GST_ats_add_address (address, NULL, &ats, 1); 833 GST_ats_add_address (address, &ats, 1);
834 } 834 }
835 return GNUNET_OK; 835 return GNUNET_OK;
836} 836}
@@ -1230,6 +1230,35 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
1230 1230
1231 1231
1232/** 1232/**
1233 * Validate an individual address.
1234 *
1235 * @param address address we should try to validate
1236 */
1237void
1238GST_validation_handle_address (const struct GNUNET_HELLO_Address *address)
1239{
1240 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1241 struct ValidationEntry *ve;
1242
1243 papi = GST_plugins_find (address->transport_name);
1244 if (NULL == papi)
1245 {
1246 /* This plugin is currently unvailable ... ignore */
1247 return;
1248 }
1249 ve = find_validation_entry (address);
1250 if (NULL == ve->revalidation_task)
1251 {
1252 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1253 "Validation process started for fresh address `%s' of %s\n",
1254 GST_plugins_a2s (ve->address),
1255 GNUNET_i2s (&ve->address->peer));
1256 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve);
1257 }
1258}
1259
1260
1261/**
1233 * Iterator callback to go over all addresses and try to validate them 1262 * Iterator callback to go over all addresses and try to validate them
1234 * (unless blocked or already validated). 1263 * (unless blocked or already validated).
1235 * 1264 *
@@ -1243,29 +1272,13 @@ validate_address_iterator (void *cls,
1243 const struct GNUNET_HELLO_Address *address, 1272 const struct GNUNET_HELLO_Address *address,
1244 struct GNUNET_TIME_Absolute expiration) 1273 struct GNUNET_TIME_Absolute expiration)
1245{ 1274{
1246 struct GNUNET_TRANSPORT_PluginFunctions * papi;
1247 struct ValidationEntry *ve;
1248
1249 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) 1275 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
1250 { 1276 {
1251 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1277 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1252 "Skipping expired address from HELLO\n"); 1278 "Skipping expired address from HELLO\n");
1253 return GNUNET_OK; /* expired */ 1279 return GNUNET_OK; /* expired */
1254 } 1280 }
1255 papi = GST_plugins_find (address->transport_name); 1281 GST_validation_handle_address (address);
1256 if (NULL == papi)
1257 {
1258 /* This plugin is currently unvailable ... ignore */
1259 return GNUNET_OK;
1260 }
1261 ve = find_validation_entry (address);
1262 if (NULL == ve->revalidation_task)
1263 {
1264 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1265 "Validation process started for fresh address `%s'\n",
1266 GST_plugins_a2s (ve->address));
1267 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve);
1268 }
1269 return GNUNET_OK; 1282 return GNUNET_OK;
1270} 1283}
1271 1284
@@ -1457,7 +1470,7 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1457 else 1470 else
1458 { 1471 {
1459 ve->known_to_ats = GNUNET_YES; 1472 ve->known_to_ats = GNUNET_YES;
1460 GST_ats_add_address (ve->address, NULL, ats, 2); 1473 GST_ats_add_address (ve->address, ats, 2);
1461 } 1474 }
1462 } 1475 }
1463 if (validations_running > 0) 1476 if (validations_running > 0)
diff --git a/src/transport/gnunet-service-transport_validation.h b/src/transport/gnunet-service-transport_validation.h
index a14937022..f292c1df6 100644
--- a/src/transport/gnunet-service-transport_validation.h
+++ b/src/transport/gnunet-service-transport_validation.h
@@ -132,6 +132,15 @@ GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello);
132 132
133 133
134/** 134/**
135 * Validate an individual address.
136 *
137 * @param address address we should try to validate
138 */
139void
140GST_validation_handle_address (const struct GNUNET_HELLO_Address *address);
141
142
143/**
135 * Function called for each address (or address status change) that 144 * Function called for each address (or address status change) that
136 * the validation module is aware of (for the given target). 145 * the validation module is aware of (for the given target).
137 * 146 *
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c
index c7c145328..fc35b08fb 100644
--- a/src/transport/plugin_transport_http_server.c
+++ b/src/transport/plugin_transport_http_server.c
@@ -604,6 +604,7 @@ server_delete_session (struct Session *s)
604 plugin->env->session_end (plugin->env->cls, 604 plugin->env->session_end (plugin->env->cls,
605 s->address, 605 s->address,
606 s); 606 s);
607 s->known_to_service = GNUNET_NO;
607 } 608 }
608 if (NULL != s->msg_tk) 609 if (NULL != s->msg_tk)
609 { 610 {
@@ -1522,7 +1523,7 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin,
1522 notify_session_monitor (plugin, 1523 notify_session_monitor (plugin,
1523 s, 1524 s,
1524 GNUNET_TRANSPORT_SS_UP); 1525 GNUNET_TRANSPORT_SS_UP);
1525 plugin->env->session_start (NULL, 1526 plugin->env->session_start (plugin->env->cls,
1526 s->address, 1527 s->address,
1527 s, 1528 s,
1528 NULL, 0); 1529 NULL, 0);
@@ -1670,7 +1671,7 @@ server_receive_mst_cb (void *cls,
1670 if (GNUNET_NO == s->known_to_service) 1671 if (GNUNET_NO == s->known_to_service)
1671 { 1672 {
1672 s->known_to_service = GNUNET_YES; 1673 s->known_to_service = GNUNET_YES;
1673 plugin->env->session_start (NULL, 1674 plugin->env->session_start (plugin->env->cls,
1674 s->address, 1675 s->address,
1675 s, 1676 s,
1676 NULL, 1677 NULL,
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index a070fdfc0..882cc4a44 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -1523,7 +1523,9 @@ tcp_plugin_get_session (void *cls,
1523 addrlen = address->address_length; 1523 addrlen = address->address_length;
1524 LOG (GNUNET_ERROR_TYPE_DEBUG, 1524 LOG (GNUNET_ERROR_TYPE_DEBUG,
1525 "Trying to get session for `%s' address of peer `%s'\n", 1525 "Trying to get session for `%s' address of peer `%s'\n",
1526 tcp_plugin_address_to_string(NULL, address->address, address->address_length), 1526 tcp_plugin_address_to_string (NULL,
1527 address->address,
1528 address->address_length),
1527 GNUNET_i2s (&address->peer)); 1529 GNUNET_i2s (&address->peer));
1528 1530
1529 if (GNUNET_HELLO_address_check_option (address, 1531 if (GNUNET_HELLO_address_check_option (address,
diff --git a/src/transport/test_transport_address_switch.c b/src/transport/test_transport_address_switch.c
index 5ecbaa9ed..d07005b56 100644
--- a/src/transport/test_transport_address_switch.c
+++ b/src/transport/test_transport_address_switch.c
@@ -76,7 +76,7 @@ GNUNET_NETWORK_STRUCT_END
76#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) 76#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
77 77
78#define DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 78#define DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
79#define DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) 79
80 80
81/** 81/**
82 * Timeout task to send messages 82 * Timeout task to send messages
@@ -140,9 +140,6 @@ static unsigned int p2_addresses_avail;
140static unsigned long long bytes_sent_after_switch; 140static unsigned long long bytes_sent_after_switch;
141static unsigned long long bytes_recv_after_switch; 141static unsigned long long bytes_recv_after_switch;
142 142
143/*
144 * END Testcase specific declarations
145 */
146 143
147#if VERBOSE 144#if VERBOSE
148#define OKPP do { ok++; FPRINTF (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) 145#define OKPP do { ok++; FPRINTF (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0)
@@ -150,8 +147,6 @@ static unsigned long long bytes_recv_after_switch;
150#define OKPP do { ok++; } while (0) 147#define OKPP do { ok++; } while (0)
151#endif 148#endif
152 149
153static void end ();
154
155 150
156static int 151static int
157stat_start_attempt_cb (void *cls, 152stat_start_attempt_cb (void *cls,
@@ -346,8 +341,11 @@ end ()
346 FPRINTF (stderr, "\n"); 341 FPRINTF (stderr, "\n");
347 if (p1_switch_attempts > 0) 342 if (p1_switch_attempts > 0)
348 { 343 {
349 FPRINTF (stderr, "Peer 1 tried %u times to switch and succeeded %u times, failed %u times\n", 344 FPRINTF (stderr,
350 p1_switch_attempts, p1_switch_success, p1_switch_fail); 345 "Peer 1 tried %u times to switch and succeeded %u times, failed %u times\n",
346 p1_switch_attempts,
347 p1_switch_success,
348 p1_switch_fail);
351 if (p1_switch_success != p1_switch_attempts) 349 if (p1_switch_success != p1_switch_attempts)
352 { 350 {
353 GNUNET_break (0); 351 GNUNET_break (0);
@@ -356,13 +354,17 @@ end ()
356 } 354 }
357 else if (p1_addresses_avail > 1) 355 else if (p1_addresses_avail > 1)
358 { 356 {
359 FPRINTF (stderr, "Peer 1 had %u addresses available, but did not try to switch\n", 357 FPRINTF (stderr,
360 p1_addresses_avail); 358 "Peer 1 had %u addresses available, but did not try to switch\n",
359 p1_addresses_avail);
361 } 360 }
362 if (p2_switch_attempts > 0) 361 if (p2_switch_attempts > 0)
363 { 362 {
364 FPRINTF (stderr, "Peer 2 tried %u times to switch and succeeded %u times, failed %u times\n", 363 FPRINTF (stderr,
365 p2_switch_attempts, p2_switch_success, p2_switch_fail); 364 "Peer 2 tried %u times to switch and succeeded %u times, failed %u times\n",
365 p2_switch_attempts,
366 p2_switch_success,
367 p2_switch_fail);
366 if (p2_switch_success != p2_switch_attempts) 368 if (p2_switch_success != p2_switch_attempts)
367 { 369 {
368 GNUNET_break (0); 370 GNUNET_break (0);
@@ -371,8 +373,9 @@ end ()
371 } 373 }
372 else if (p2_addresses_avail > 1) 374 else if (p2_addresses_avail > 1)
373 { 375 {
374 FPRINTF (stderr, "Peer 2 had %u addresses available, but did not try to switch\n", 376 FPRINTF (stderr,
375 p2_addresses_avail); 377 "Peer 2 had %u addresses available, but did not try to switch\n",
378 p2_addresses_avail);
376 } 379 }
377 380
378 if ( ((p1_switch_attempts > 0) || (p2_switch_attempts > 0)) && 381 if ( ((p1_switch_attempts > 0) || (p2_switch_attempts > 0)) &&
@@ -400,15 +403,14 @@ static void
400end_badly () 403end_badly ()
401{ 404{
402 die_task = NULL; 405 die_task = NULL;
403 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 406 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
404 "Fail! Stopping peers\n"); 407 "Fail (timeout)! Stopping peers\n");
405
406 if (test_connected == GNUNET_YES) 408 if (test_connected == GNUNET_YES)
407 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 409 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
408 "Peers got connected\n"); 410 "Peers got connected\n");
409 else 411 else
410 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 412 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
411 "Peers got NOT connected\n"); 413 "Peers got NOT EVEN connected\n");
412 clean_up(); 414 clean_up();
413 res = GNUNET_YES; 415 res = GNUNET_YES;
414} 416}
@@ -428,11 +430,11 @@ notify_receive (void *cls,
428 struct PeerContext *p = cls; 430 struct PeerContext *p = cls;
429 char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); 431 char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
430 432
431 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 433 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
432 "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", p->no, ps, 434 "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", p->no, ps,
433 ntohl (hdr->num), 435 ntohl (hdr->num),
434 ntohs (message->size), 436 ntohs (message->size),
435 GNUNET_i2s (peer)); 437 GNUNET_i2s (peer));
436 if ( ((p1_switch_attempts >= 1) || (p2_switch_attempts >= 1)) && 438 if ( ((p1_switch_attempts >= 1) || (p2_switch_attempts >= 1)) &&
437 (p1_switch_attempts == p1_switch_fail + p1_switch_success) && 439 (p1_switch_attempts == p1_switch_fail + p1_switch_success) &&
438 (p2_switch_attempts == p2_switch_fail + p2_switch_success) ) 440 (p2_switch_attempts == p2_switch_fail + p2_switch_success) )
@@ -464,7 +466,7 @@ notify_ready (void *cls, size_t size, void *buf)
464 "Timeout occurred while waiting for transmit_ready for message\n"); 466 "Timeout occurred while waiting for transmit_ready for message\n");
465 if (NULL != die_task) 467 if (NULL != die_task)
466 GNUNET_SCHEDULER_cancel (die_task); 468 GNUNET_SCHEDULER_cancel (die_task);
467 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL ); 469 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
468 res = 1; 470 res = 1;
469 return 0; 471 return 0;
470 } 472 }
@@ -479,18 +481,16 @@ notify_ready (void *cls, size_t size, void *buf)
479 memcpy (&cbuf[0], &hdr, sizeof(struct TestMessage)); 481 memcpy (&cbuf[0], &hdr, sizeof(struct TestMessage));
480 memset (&cbuf[sizeof(struct TestMessage)], '0', MSIZE - sizeof(struct TestMessage)); 482 memset (&cbuf[sizeof(struct TestMessage)], '0', MSIZE - sizeof(struct TestMessage));
481 483
482#if VERBOSE
483 char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id)); 484 char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id));
484 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 485 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
485 "Sending message %u of size %u from peer %u (`%4s') -> peer %u (`%s') !\n", 486 "Sending message %u of size %u from peer %u (`%4s') -> peer %u (`%s') !\n",
486 (unsigned int) (counter - 1), 487 (unsigned int) (counter - 1),
487 s, 488 MSIZE,
488 sender->no, 489 sender->no,
489 GNUNET_i2s (&sender->id), 490 GNUNET_i2s (&sender->id),
490 receiver->no, 491 receiver->no,
491 receiver_s); 492 receiver_s);
492 GNUNET_free(receiver_s); 493 GNUNET_free(receiver_s);
493#endif
494 494
495 if (th == NULL) 495 if (th == NULL)
496 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, 496 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th,
@@ -510,9 +510,11 @@ notify_ready (void *cls, size_t size, void *buf)
510 510
511 511
512static void 512static void
513notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) 513notify_connect (void *cls,
514 const struct GNUNET_PeerIdentity *peer)
514{ 515{
515 struct PeerContext *p = cls; 516 struct PeerContext *p = cls;
517
516 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 518 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
517 "Peer %u (`%4s') connected to us!\n", 519 "Peer %u (`%4s') connected to us!\n",
518 p->no, 520 p->no,
@@ -526,14 +528,19 @@ notify_disconnect (void *cls,
526{ 528{
527 struct PeerContext *p = cls; 529 struct PeerContext *p = cls;
528 530
529 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 531 if (NULL != p1)
530 "Peer %u (`%4s') disconnected!\n", 532 {
531 p->no, 533 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
532 GNUNET_i2s (peer)); 534 "Peer %u (`%4s') disconnected early!\n",
533 if (th != NULL) 535 p->no,
536 GNUNET_i2s (peer));
537 GNUNET_SCHEDULER_shutdown ();
538 }
539 if (NULL != th)
540 {
534 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); 541 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
535 th = NULL; 542 th = NULL;
536 543 }
537} 544}
538 545
539 546
@@ -570,14 +577,16 @@ progress_indicator (void *cls,
570 577
571 578
572static void 579static void
573testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) 580testing_connect_cb (struct PeerContext *p1,
581 struct PeerContext *p2,
582 void *cls)
574{ 583{
575 char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); 584 char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id));
576 585
577 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 586 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
578 "Peers connected: %u (%s) <-> %u (%s)\n", 587 "Peers connected: %u (%s) <-> %u (%s)\n",
579 p1->no, p1_c, p2->no, 588 p1->no, p1_c, p2->no,
580 GNUNET_i2s (&p2->id)); 589 GNUNET_i2s (&p2->id));
581 GNUNET_free (p1_c); 590 GNUNET_free (p1_c);
582 591
583 cc = NULL; 592 cc = NULL;
@@ -613,10 +622,12 @@ start_cb (struct PeerContext *p, void *cls)
613 receiver = p1; 622 receiver = p1;
614 623
615 char *sender_c = GNUNET_strdup (GNUNET_i2s (&sender->id)); 624 char *sender_c = GNUNET_strdup (GNUNET_i2s (&sender->id));
616 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 625 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
617 "Test tries to send from %u (%s) -> peer %u (%s)\n", 626 "Test tries to send from %u (%s) -> peer %u (%s)\n",
618 sender->no, sender_c, 627 sender->no,
619 receiver->no, GNUNET_i2s (&receiver->id)); 628 sender_c,
629 receiver->no,
630 GNUNET_i2s (&receiver->id));
620 GNUNET_free (sender_c); 631 GNUNET_free (sender_c);
621 632
622 /* Connect the peers */ 633 /* Connect the peers */
@@ -632,20 +643,18 @@ run (void *cls,
632 const char *cfgfile, 643 const char *cfgfile,
633 const struct GNUNET_CONFIGURATION_Handle *cfg) 644 const struct GNUNET_CONFIGURATION_Handle *cfg)
634{ 645{
635 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL ); 646 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
636 647
637 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, 648 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
638 &notify_receive, &notify_connect, &notify_disconnect, &start_cb, NULL ); 649 &notify_receive, &notify_connect, &notify_disconnect, &start_cb, NULL);
639 650
640 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, 651 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2,
641 &notify_receive, &notify_connect, &notify_disconnect, &start_cb, NULL ); 652 &notify_receive, &notify_connect, &notify_disconnect, &start_cb, NULL);
642 653
643 if ((p1 == NULL )|| (p2 == NULL)) 654 if ((p1 == NULL )|| (p2 == NULL))
644 { 655 {
645 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n"); 656 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n");
646 if (die_task != NULL) 657 GNUNET_SCHEDULER_shutdown ();
647 GNUNET_SCHEDULER_cancel (die_task);
648 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
649 return; 658 return;
650 } 659 }
651 660
@@ -693,10 +702,9 @@ run (void *cls,
693 702
694 if ((p1_stat == NULL )|| (p2_stat == NULL)) 703 if ((p1_stat == NULL )|| (p2_stat == NULL))
695 { 704 {
696 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not create statistics for peers!\n"); 705 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
697 if (die_task != NULL) 706 "Fail! Could not create statistics for peers!\n");
698 GNUNET_SCHEDULER_cancel (die_task); 707 GNUNET_SCHEDULER_shutdown ();
699 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
700 return; 708 return;
701 } 709 }
702} 710}
diff --git a/src/transport/test_transport_api_restart_2peers.c b/src/transport/test_transport_api_restart_2peers.c
index 25054b536..e593b08fa 100644
--- a/src/transport/test_transport_api_restart_2peers.c
+++ b/src/transport/test_transport_api_restart_2peers.c
@@ -23,7 +23,6 @@
23 * 23 *
24 * This test case starts 2 peers, connects and exchanges a message 24 * This test case starts 2 peers, connects and exchanges a message
25 * boths peer are restarted and tested if peers reconnect 25 * boths peer are restarted and tested if peers reconnect
26 * C code apparently.
27 */ 26 */
28#include "platform.h" 27#include "platform.h"
29#include "gnunet_transport_service.h" 28#include "gnunet_transport_service.h"
@@ -32,7 +31,7 @@
32/** 31/**
33 * How long until we give up on transmitting the message? 32 * How long until we give up on transmitting the message?
34 */ 33 */
35#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90) 34#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 900)
36 35
37/** 36/**
38 * How long until we give up on transmitting the message? 37 * How long until we give up on transmitting the message?
@@ -163,7 +162,9 @@ static void
163restart (struct PeerContext *p, char *cfg_file) 162restart (struct PeerContext *p, char *cfg_file)
164{ 163{
165 GNUNET_assert (p != NULL); 164 GNUNET_assert (p != NULL);
166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Restarting peer %u (`%4s')\n", p->no, 165 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
166 "Restarting peer %u (`%4s')\n",
167 p->no,
167 GNUNET_i2s (&p->id)); 168 GNUNET_i2s (&p->id));
168 GNUNET_TRANSPORT_TESTING_restart_peer (tth, p, cfg_file, &restart_cb, p); 169 GNUNET_TRANSPORT_TESTING_restart_peer (tth, p, cfg_file, &restart_cb, p);
169} 170}
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c
index fd352a1e5..a2649db8f 100644
--- a/src/transport/transport_api.c
+++ b/src/transport/transport_api.c
@@ -512,7 +512,7 @@ outbound_bw_tracker_update (void *cls)
512 if (NULL == n->hn) 512 if (NULL == n->hn)
513 return; 513 return;
514 delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, 514 delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker,
515 n->th->notify_size + n->traffic_overhead); 515 n->th->notify_size + n->traffic_overhead);
516 LOG (GNUNET_ERROR_TYPE_DEBUG, 516 LOG (GNUNET_ERROR_TYPE_DEBUG,
517 "New outbound delay %llu us\n", 517 "New outbound delay %llu us\n",
518 GNUNET_STRINGS_relative_time_to_string (delay, 518 GNUNET_STRINGS_relative_time_to_string (delay,
@@ -703,7 +703,8 @@ demultiplexer (void *cls,
703 "CONNECT", 703 "CONNECT",
704 GNUNET_i2s (&cim->id), 704 GNUNET_i2s (&cim->id),
705 ntohl (cim->quota_out.value__)); 705 ntohl (cim->quota_out.value__));
706 GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, cim->quota_out); 706 GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker,
707 cim->quota_out);
707 if (h->nc_cb != NULL) 708 if (h->nc_cb != NULL)
708 h->nc_cb (h->cls, &n->id); 709 h->nc_cb (h->cls, &n->id);
709 break; 710 break;
@@ -745,9 +746,10 @@ demultiplexer (void *cls,
745 746
746 if (bytes_physical >= bytes_msg) 747 if (bytes_physical >= bytes_msg)
747 { 748 {
748 LOG (GNUNET_ERROR_TYPE_DEBUG, 749 LOG (GNUNET_ERROR_TYPE_DEBUG,
749 "Overhead for %u byte message: %u\n", 750 "Overhead for %u byte message: %u\n",
750 bytes_msg, bytes_physical - bytes_msg); 751 bytes_msg,
752 bytes_physical - bytes_msg);
751 n->traffic_overhead += bytes_physical - bytes_msg; 753 n->traffic_overhead += bytes_physical - bytes_msg;
752 } 754 }
753 GNUNET_break (GNUNET_NO == n->is_ready); 755 GNUNET_break (GNUNET_NO == n->is_ready);