aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-10-13 14:40:39 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-10-13 14:40:39 +0000
commit2f983f47bd3c923b7cea0839eba90c1bb77554e0 (patch)
tree7318618cc914533e81996c5f0e08091dd9fb2075
parente35111701eb4dc745372f077c2f0d7c991ac1fac (diff)
downloadgnunet-2f983f47bd3c923b7cea0839eba90c1bb77554e0.tar.gz
gnunet-2f983f47bd3c923b7cea0839eba90c1bb77554e0.zip
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c67
1 files changed, 55 insertions, 12 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 51524556f..a3582d5b5 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -614,6 +614,52 @@ GST_neighbours_stop ()
614 disconnect_notify_cb = NULL; 614 disconnect_notify_cb = NULL;
615} 615}
616 616
617struct AddressContext
618{
619 struct NeighbourMapEntry * n;
620 struct GNUNET_TRANSPORT_ATS_Information * ats;
621 uint32_t ats_count;
622};
623
624void neighbour_send_cb (void *cls, int success)
625{
626 struct AddressContext * ac = cls;
627 struct NeighbourMapEntry * n = ac->n;
628 int was_connected = n->is_connected;
629
630 if (success == GNUNET_YES)
631 {
632 n->is_connected = GNUNET_YES;
633
634 /* was already connected */
635 if (was_connected == GNUNET_YES)
636 {
637 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
638 "Successfully switched to address `%s' for peer `%s' \n",
639 GST_plugins_a2s(n->plugin_name, n->addr, n->addrlen),
640 GNUNET_i2s (&n->id));
641 GNUNET_free (ac);
642 return;
643 }
644
645 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
646 "Successfully connected to peer `%s' with address `%s'\n",
647 GNUNET_i2s (&n->id),
648 GST_plugins_a2s(n->plugin_name, n->addr, n->addrlen));
649
650 neighbours_connected++;
651 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1,
652 GNUNET_NO);
653 connect_notify_cb (callback_cls, &n->id, ac->ats, ac->ats_count);
654 GNUNET_free (ac);
655 return;
656 }
657
658 /* Could not connecte using this address, notifying ATS about bad address */
659 GNUNET_ATS_address_destroyed(GST_ats, &n->id, n->plugin_name, n->addr, n->addrlen, n->session);
660 GNUNET_ATS_suggest_address(GST_ats, &n->id);
661 GNUNET_free (ac);
662}
617 663
618/** 664/**
619 * For an existing neighbour record, set the active connection to 665 * For an existing neighbour record, set the active connection to
@@ -637,7 +683,7 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
637{ 683{
638 struct NeighbourMapEntry *n; 684 struct NeighbourMapEntry *n;
639 struct SessionConnectMessage connect_msg; 685 struct SessionConnectMessage connect_msg;
640 int was_connected; 686 struct AddressContext *ac;
641 687
642 GNUNET_assert (neighbours != NULL); 688 GNUNET_assert (neighbours != NULL);
643 689
@@ -649,12 +695,10 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
649 // GNUNET_break (0); 695 // GNUNET_break (0);
650 return; 696 return;
651 } 697 }
652 was_connected = n->is_connected;
653 n->is_connected = GNUNET_YES;
654 698
655#if DEBUG_TRANSPORT 699#if DEBUG_TRANSPORT
656 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 700 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
657 "SWITCH! Peer `%4s' switches to plugin `%s' address '%s' session %X\n", 701 "Peer `%4s' switches to plugin `%s' address '%s' session %X\n",
658 GNUNET_i2s (peer), plugin_name, 702 GNUNET_i2s (peer), plugin_name,
659 (address_len == 0) ? "<inbound>" : GST_plugins_a2s (plugin_name, 703 (address_len == 0) ? "<inbound>" : GST_plugins_a2s (plugin_name,
660 address, 704 address,
@@ -662,6 +706,12 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
662 session); 706 session);
663#endif 707#endif
664 708
709 ac = GNUNET_malloc(sizeof (struct AddressContext) +
710 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
711 ac->n = n;
712 ac->ats_count = ats_count;
713 memcpy(&ac[1],ats, ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
714
665 GNUNET_free_non_null (n->addr); 715 GNUNET_free_non_null (n->addr);
666 n->addr = GNUNET_malloc (address_len); 716 n->addr = GNUNET_malloc (address_len);
667 memcpy (n->addr, address, address_len); 717 memcpy (n->addr, address, address_len);
@@ -680,17 +730,10 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
680 connect_msg.timestamp = 730 connect_msg.timestamp =
681 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); 731 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
682 GST_neighbours_send (peer, &connect_msg, sizeof (connect_msg), 732 GST_neighbours_send (peer, &connect_msg, sizeof (connect_msg),
683 GNUNET_TIME_UNIT_FOREVER_REL, NULL, NULL); 733 GNUNET_TIME_UNIT_FOREVER_REL, &neighbour_send_cb, ac);
684 734
685 n->keepalive_task = GNUNET_SCHEDULER_add_now (&neighbour_keepalive_task, 735 n->keepalive_task = GNUNET_SCHEDULER_add_now (&neighbour_keepalive_task,
686 n); 736 n);
687 if (GNUNET_YES == was_connected)
688 return;
689 /* First tell clients about connected neighbours...*/
690 neighbours_connected++;
691 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1,
692 GNUNET_NO);
693 connect_notify_cb (callback_cls, peer, ats, ats_count);
694} 737}
695 738
696/** 739/**